From 365fbe893aa7baf707acf4db149cfc0351232c3a Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 19 Nov 2014 00:32:04 -0500 Subject: [PATCH] Truncate long titles, implement line wrap --- .../taskmanager/view/tasks/TaskCard.java | 24 +++++++----- .../view/taskstatus/TaskStatusView.java | 37 ++++++++++--------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/tasks/TaskCard.java b/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/tasks/TaskCard.java index 73361599..d688877b 100644 --- a/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/tasks/TaskCard.java +++ b/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/tasks/TaskCard.java @@ -30,18 +30,24 @@ public class TaskCard extends JPanel { * Create the panel. */ public TaskCard(String nameData, String dateData, String userNameData) { - setBorder(new LineBorder(Color.black)); - setLayout(new MigLayout("", "[grow,fill]", "[grow][bottom]")); + this.setBorder(new LineBorder(Color.black)); + this.setLayout(new MigLayout("", "[grow,fill]", "[grow][bottom]")); - taskName.setText(nameData); - taskName.setFont(new Font("Tahoma", Font.BOLD, 14)); - taskName.setEditable(false); - taskName.setBackground(UIManager.getColor("Button.background")); - add(taskName, "cell 0 0,alignx center,aligny center"); + // truncates the displayed task title if it's longer than 25 characters. if + if (nameData.length() > 45) { + this.taskName.setToolTipText(nameData); + nameData = nameData.substring(0, 45).concat("..."); + } + + this.taskName.setText(nameData); + this.taskName.setFont(new Font("Tahoma", Font.BOLD, 14)); + this.taskName.setEditable(false); + this.taskName.setBackground(UIManager.getColor("Button.background")); + this.add(this.taskName, "cell 0 0,alignx center,aligny center"); JPanel infoPanel = new JPanel(); - add(infoPanel, "cell 0 1,grow"); + this.add(infoPanel, "cell 0 1,grow"); infoPanel.setLayout(new MigLayout("", "[grow][grow]", "[grow]")); JLabel date = new JLabel(dateData); @@ -54,7 +60,7 @@ public TaskCard(String nameData, String dateData, String userNameData) { } public Task getTaskObj() { - return taskObj; + return this.taskObj; } public void setTaskObj(Task taskObj) { diff --git a/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/taskstatus/TaskStatusView.java b/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/taskstatus/TaskStatusView.java index 0e8fd726..7db63be4 100644 --- a/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/taskstatus/TaskStatusView.java +++ b/TaskManager/src/main/java/edu/wpi/cs/wpisuitetng/modules/taskmanager/view/taskstatus/TaskStatusView.java @@ -59,11 +59,11 @@ public class TaskStatusView extends JPanel { */ public TaskStatusView(String title, String statusType) { - initialized = false; + this.initialized = false; this.title = title; - setLayout(new MigLayout("", "[236px,grow]", "[26px][200px,grow 500]")); - taskStatusObj = new TaskStatus(statusType); + this.setLayout(new MigLayout("", "[236px,grow]", "[26px][200px,grow 500]")); + this.taskStatusObj = new TaskStatus(statusType); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportBorder(null); @@ -85,10 +85,10 @@ public TaskStatusView(String title, String statusType) { txtpnTitle.setFont(txtpnTitle.getFont().deriveFont(20f)); txtpnTitle.setText(this.title); this.add(txtpnTitle, "cell 0 0,alignx center,aligny center"); - panel.setBackground(Color.WHITE); + this.panel.setBackground(Color.WHITE); - scrollPane.setViewportView(panel); - panel.setLayout(new MigLayout("", "[grow,fill]", "[]")); + scrollPane.setViewportView(this.panel); + this.panel.setLayout(new MigLayout("", "[236px,grow,fill]", "[]")); } @@ -101,24 +101,25 @@ public void requestTasksFromDb() { } public void fillTaskList(Task[] taskArray) { - taskStatusObj.setTaskList(new ArrayList()); + this.taskStatusObj.setTaskList(new ArrayList()); for (Task t : taskArray) { - if (t.getStatus() != null && taskStatusObj.getName().equals(t.getStatus().getName())) { - taskStatusObj.addTask(t); + if (t.getStatus() != null + && this.taskStatusObj.getName().equals(t.getStatus().getName())) { + this.taskStatusObj.addTask(t); } } - populateTaskStatusViewCards(); + this.populateTaskStatusViewCards(); } public void populateTaskStatusViewCards() { - List taskList = taskStatusObj.getTaskList(); - panel.removeAll(); + List taskList = this.taskStatusObj.getTaskList(); + this.panel.removeAll(); for (Task t : taskList) { - String dateString = formateDate(t); + String dateString = this.formateDate(t); TaskCard card = new TaskCard(t.getTitle(), dateString, t.getUserForTaskCard()); - panel.add(card, "newline"); + this.panel.add(card, "newline"); } - revalidate(); + this.revalidate(); } @@ -139,9 +140,9 @@ private String formateDate(Task t) { @Override public void paintComponent(Graphics g) { - if (!initialized) { - requestTasksFromDb(); - initialized = true; + if (!this.initialized) { + this.requestTasksFromDb(); + this.initialized = true; } super.paintComponent(g); }