// Sort void sortTasks(ArrayList<String> ids) { String[] array = new String[ids.size()]; for (int i = 0; i < array.length; i++) { array[i] = ids.get(i); } CurrentProject.getProcessList().getProcess(processId).setTaskOrder(array); CurrentStorage.get().storeProcessList(CurrentProject.getProcessList(), CurrentProject.get()); this.getContentPane().remove(taskPanel); drawTaskPanel(); pack(); }
// Tasks UI void drawTaskPanel() { if (processId != null) { Collection<Task> tasks = CurrentProject.getProcessList().getProcess(processId).getTasks(); taskIds = new ArrayList<>(); List<Task> taskList = new ArrayList<>(tasks); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); GridBagConstraints gc = new GridBagConstraints(); gc.ipadx = 3; gc.ipady = 3; gc.gridy = 0; gc.weightx = 1; gc.weighty = 1; gc.anchor = GridBagConstraints.WEST; taskInnerPanel = new JPanel(new GridBagLayout()); { JLabel title = new JLabel(Local.getString("Task")); JLabel status = new JLabel(Local.getString("Status")); JLabel priority = new JLabel(Local.getString("Priority")); gc.gridx = 1; taskInnerPanel.add(title, gc); gc.gridx = 2; taskInnerPanel.add(status, gc); gc.gridx = 3; taskInnerPanel.add(priority, gc); } for (Task task : taskList) { Util.debug("Adding task: " + task.getText()); BasicArrowButton up = new BasicArrowButton(BasicArrowButton.NORTH); BasicArrowButton dn = new BasicArrowButton(BasicArrowButton.SOUTH); JLabel title = new JLabel(task.getText()); JLabel status = new JLabel(task.getStatusString()); JLabel priority = new JLabel(task.getPriorityString()); gc.gridy = gc.gridy + 1; gc.gridx = 0; gc.gridx = 1; gc.anchor = GridBagConstraints.WEST; taskInnerPanel.add(title, gc); gc.gridx = 2; taskInnerPanel.add(status, gc); gc.gridx = 3; taskInnerPanel.add(priority, gc); gc.gridx = 4; gc.anchor = GridBagConstraints.CENTER; taskInnerPanel.add(up, gc); gc.gridx = 5; gc.anchor = GridBagConstraints.CENTER; taskInnerPanel.add(dn, gc); up.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent action) { int index = taskList.indexOf(task); if (index > 0) { Collections.swap(taskList, index, index - 1); Collections.swap(taskIds, index, index - 1); sortTasks(taskIds); } } }); dn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent action) { int index = taskList.indexOf(task); if (index < taskList.size() - 1) { Collections.swap(taskList, index, index + 1); Collections.swap(taskIds, index, index + 1); sortTasks(taskIds); } } }); taskIds.add(task.getID()); } taskScrollPane = new JScrollPane(taskInnerPanel); taskPanel = new JPanel(new BorderLayout()); taskPanel.setPreferredSize(new Dimension(400, 300)); taskPanel.setBorder(defaultBorder); taskPanel.add(taskScrollPane, BorderLayout.CENTER); this.getContentPane().add(taskPanel, BorderLayout.CENTER); } }