1 19 20 package taskblocks.app; 21 22 import javax.swing.JFrame ; 23 import javax.swing.JPanel ; 24 25 import taskblocks.Utils; 26 import taskblocks.graph.TaskGraphComponent; 27 import taskblocks.modelimpl.ColorLabel; 28 import taskblocks.modelimpl.ManImpl; 29 import taskblocks.modelimpl.TaskImpl; 30 import taskblocks.modelimpl.TaskModelImpl; 31 32 public class TaskConfigDialog extends ConfigDialogStub { 33 34 TaskImpl _task; 35 TaskModelImpl _model; 36 TaskGraphComponent _graph; 37 boolean _applied; 38 39 TaskConfigPanel _cfgPanel; 40 41 public TaskConfigDialog(JFrame owner, TaskImpl task, TaskModelImpl model, TaskGraphComponent graph, boolean isCreating) { 42 super(owner, isCreating); 43 _task = task; 44 _model = model; 45 _graph = graph; 46 init(); 47 } 48 49 public void updateTask(TaskImpl task) { 50 task.setDuration(((Integer )_cfgPanel.durationSP.getValue()).intValue()); 51 task.setName(_cfgPanel.nameTF.getText()); 52 task.setMan(((ManImpl)_cfgPanel.manCB.getSelectedItem())); 53 task.setColorLabel((ColorLabel)_cfgPanel._colorLabelCB.getSelectedItem()); 54 _applied = true; 55 } 56 57 public void addTask() { 58 59 _graph.getGraphRepresentation().updateModel(); 60 61 TaskImpl t = new TaskImpl(); 62 63 updateTask(t); 64 68 long lastFinishTime = 0; 70 for(TaskImpl tmpTask: _model._tasks) { 71 if(t.getMan() == tmpTask.getMan()) { 72 long finish = Utils.countFinishTime(Utils.repairStartTime(tmpTask.geSstartTime()), tmpTask.getDuration()); 73 if(lastFinishTime < finish) { 74 lastFinishTime = finish; 75 } 76 } 77 } 78 if(lastFinishTime == 0) { 79 lastFinishTime = System.currentTimeMillis()/Utils.MILLISECONDS_PER_DAY; 80 } 81 82 t.setStartTime(lastFinishTime); 83 _model.addTask(t); 84 85 _graph.setModel(_model); 86 _graph.getGraphRepresentation().setDirty(); _graph.repaint(); 88 _graph.scrollToTaskVisible(t); 89 90 _cfgPanel.nameTF.setSelectionStart(0); 92 _cfgPanel.nameTF.setSelectionEnd(_cfgPanel.nameTF.getText().length()); 93 _cfgPanel.nameTF.requestFocus(); 94 } 95 96 @Override 97 JPanel createMainPanel() { 98 if(_isCreating) { 99 setTitle("New Task"); 100 _task = new TaskImpl(); 101 _task.setPredecessors(new TaskImpl[0]); 102 _task.setMan(_model._mans[0]); 103 _task.setDuration(5); 104 } else { 105 setTitle("Task " + _task.getName()); 106 } 107 return _cfgPanel = new TaskConfigPanel(_task, _model); 108 } 109 110 @Override 111 void doApply() { 112 if(isCreating()) { 113 addTask(); 114 } else { 115 updateTask(_task); 116 } 117 } 118 119 public static boolean openDialog(JFrame owner, TaskImpl task, TaskModelImpl model, TaskGraphComponent graph, boolean isCreating) { 120 TaskConfigDialog d = new TaskConfigDialog(owner, task, model, graph, isCreating); 121 d.pack(); 122 d.setLocationRelativeTo(owner); 123 d.setVisible(true); 124 return d._applied; 125 } 126 127 } 128 | Popular Tags |