KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > taskblocks > app > ManConfigDialog


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.graph.TaskGraphComponent;
26 import taskblocks.modelimpl.ManImpl;
27 import taskblocks.modelimpl.TaskModelImpl;
28
29 public class ManConfigDialog extends ConfigDialogStub {
30     
31     ManImpl _man;
32     TaskModelImpl _model;
33     ManConfigPanel _cfgPanel;
34     TaskGraphComponent _graph;
35     
36     public ManConfigDialog(JFrame JavaDoc owner, ManImpl man, TaskModelImpl model, TaskGraphComponent graph, boolean isCreating) {
37         super(owner, isCreating);
38         _man = man;
39         _model = model;
40         _graph = graph;
41         init();
42     }
43
44     public static boolean openDialog(JFrame JavaDoc owner, ManImpl man, TaskModelImpl model, TaskGraphComponent graph, boolean isCreating) {
45         ManConfigDialog d = new ManConfigDialog(owner, man, model, graph, isCreating);
46         d.pack();
47         d.setLocationRelativeTo(owner);
48         d.setVisible(true);
49         return d._applied;
50     }
51
52     @Override JavaDoc
53     JPanel JavaDoc createMainPanel() {
54         
55         if(_isCreating) {
56             setTitle("New Worker");
57             _man = new ManImpl();
58         } else {
59             setTitle("Worker " + _man.getName());
60         }
61
62         _cfgPanel = new ManConfigPanel(_man, _model);
63         return _cfgPanel;
64     }
65
66     @Override JavaDoc
67     void doApply() {
68         if(isCreating()) {
69             addMan();
70         } else {
71             updateMan();
72         }
73     }
74
75     private void updateMan() {
76         throw new IllegalArgumentException JavaDoc("Not yet implemented");
77     }
78
79     private void addMan() {
80         _graph.getGraphRepresentation().updateModel();
81         ManImpl man = new ManImpl();
82         man.setName(_cfgPanel.nameTF.getText());
83         _model.addMan(man);
84         
85         _graph.setModel(_model);
86         _graph.getGraphRepresentation().setDirty();
87         _graph.repaint();
88         
89         _cfgPanel.nameTF.setSelectionStart(0);
90         _cfgPanel.nameTF.setSelectionEnd(_cfgPanel.nameTF.getText().length());
91         _cfgPanel.nameTF.requestFocus();
92     }
93 }
94
Popular Tags