KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > taskblocks > app > TaskConfigDialog


1 /*
2  * Copyright (C) Jakub Neubauer, 2007
3  *
4  * This file is part of TaskBlocks
5  *
6  * TaskBlocks is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * TaskBlocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */

19
20 package taskblocks.app;
21
22 import javax.swing.JFrame JavaDoc;
23 import javax.swing.JPanel JavaDoc;
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 JavaDoc 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 JavaDoc)_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 // t.setDuration(((Integer)_cfgPanel.durationSP.getValue()).intValue());
65
// t.setName(_cfgPanel.nameTF.getText());
66
// t.setMan(((ManImpl)_cfgPanel.manCB.getSelectedItem()));
67

68         // count the last finish time of all the man's tasks
69
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(); // the model->GUI resetted the dirty flag
87
_graph.repaint();
88         _graph.scrollToTaskVisible(t);
89         
90         // now focus to name and set text field selection
91
_cfgPanel.nameTF.setSelectionStart(0);
92         _cfgPanel.nameTF.setSelectionEnd(_cfgPanel.nameTF.getText().length());
93         _cfgPanel.nameTF.requestFocus();
94     }
95
96     @Override JavaDoc
97     JPanel JavaDoc 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 JavaDoc
111     void doApply() {
112         if(isCreating()) {
113             addTask();
114         } else {
115             updateTask(_task);
116         }
117     }
118     
119     public static boolean openDialog(JFrame JavaDoc 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