1 import java.awt.event.ActionEvent;
2 import java.awt.event.ActionListener;
5 import javax.swing.JFileChooser;
6 import javax.swing.JPanel;
7 import javax.swing.JToggleButton;
8 import javax.swing.JSlider;
9 import javax.swing.JButton;
10 import net.miginfocom.swing.MigLayout;
11 import javax.swing.ButtonGroup;
12 import javax.swing.filechooser.FileNameExtensionFilter;
13 import javax.swing.JRadioButton;
14 import javax.swing.BoxLayout;
15 import javax.swing.JLabel;
25 private boolean bundlingActive;
26 private final ButtonGroup drawModeGroup =
new ButtonGroup();
28 private JFileChooser fc;
29 private JToggleButton tglbtnNode;
30 private JToggleButton tglbtnEdge;
31 private JToggleButton tglbtnDelete;
32 private JButton btnLoad;
33 private JButton btnSave;
34 private JToggleButton btnBundle;
35 private JToggleButton btnUnbundle;
36 private JSlider slider;
37 private final ButtonGroup bundleGroup =
new ButtonGroup();
38 private JRadioButton rdbtnGraph;
39 private JRadioButton rdbtnMesh;
40 private final ButtonGroup graphMeshGroup =
new ButtonGroup();
41 private JButton btnConnectAll;
42 private JButton btnClearAll;
43 private JButton btnAutoMesh;
44 private JButton btnClearMesh;
46 private JLabel lblCellSize;
53 fc =
new JFileChooser();
54 fc.setFileFilter(
new FileNameExtensionFilter(
"GraphDraw File",
"gdf"));
55 fc.setCurrentDirectory(
new File(
"./"));
57 setLayout(
new MigLayout(
"",
"[100.00][100.00][77.00][]",
"[grow][][][][][][-14.00][][][][][][]"));
60 add(panel,
"cell 0 0 1 3,alignx center,aligny center");
61 panel.setLayout(
new BoxLayout(panel, BoxLayout.Y_AXIS));
63 rdbtnGraph =
new JRadioButton(
"Graph");
64 panel.add(rdbtnGraph);
65 rdbtnGraph.setSelected(
true);
66 graphMeshGroup.add(rdbtnGraph);
68 rdbtnMesh =
new JRadioButton(
"Mesh");
70 graphMeshGroup.add(rdbtnMesh);
72 tglbtnNode =
new JToggleButton(
"Node");
73 drawModeGroup.add(tglbtnNode);
74 add(tglbtnNode,
"cell 1 0,growx");
76 tglbtnEdge =
new JToggleButton(
"Edge");
77 drawModeGroup.add(tglbtnEdge);
78 add(tglbtnEdge,
"cell 1 1,growx");
80 tglbtnDelete =
new JToggleButton(
"Delete");
81 drawModeGroup.add(tglbtnDelete);
82 add(tglbtnDelete,
"flowy,cell 1 2,growx");
84 btnConnectAll =
new JButton(
"Connect All");
85 add(btnConnectAll,
"cell 0 3,growx");
87 btnClearAll =
new JButton(
"Clear All");
88 add(btnClearAll,
"cell 1 3,growx");
90 btnAutoMesh =
new JButton(
"Auto Mesh");
91 btnAutoMesh.setEnabled(
false);
92 add(btnAutoMesh,
"cell 0 7,growx");
94 btnClearMesh =
new JButton(
"Clear Mesh");
95 btnClearMesh.setEnabled(
false);
96 add(btnClearMesh,
"cell 1 7,growx");
98 lblCellSize =
new JLabel(
"Cell Size:");
99 add(lblCellSize,
"cell 0 5");
101 slider =
new JSlider();
102 slider.setPaintTicks(
true);
103 slider.setPaintLabels(
true);
104 slider.setMaximum(80);
105 slider.setMinimum(20);
106 slider.setMajorTickSpacing(10);
107 slider.setSnapToTicks(
true);
109 add(slider,
"cell 0 6 2 1,growx");
111 btnLoad =
new JButton(
"Load");
112 add(btnLoad,
"cell 0 9,growx");
114 btnSave =
new JButton(
"Save");
115 add(btnSave,
"cell 1 9,growx");
117 btnBundle =
new JToggleButton(
"Bundle");
118 bundleGroup.add(btnBundle);
119 add(btnBundle,
"cell 0 10,growx");
121 btnUnbundle =
new JToggleButton(
"Unbundle");
122 btnUnbundle.setSelected(
true);
123 bundlingActive =
false;
124 bundleGroup.add(btnUnbundle);
125 add(btnUnbundle,
"cell 1 10,growx");
135 return rdbtnMesh.isSelected();
142 rdbtnGraph.addActionListener(
new ActionListener() {
145 public void actionPerformed(ActionEvent e) {
146 if(tglbtnNode.isSelected())
148 else if(tglbtnEdge.isSelected())
150 else if(tglbtnDelete.isSelected())
152 btnClearAll.setEnabled(
true);
153 btnConnectAll.setEnabled(
true);
154 btnAutoMesh.setEnabled(
false);
155 btnClearMesh.setEnabled(
false);
160 rdbtnMesh.addActionListener(
new ActionListener() {
163 public void actionPerformed(ActionEvent e) {
164 if(tglbtnNode.isSelected())
166 else if(tglbtnEdge.isSelected())
168 else if(tglbtnDelete.isSelected())
170 btnClearAll.setEnabled(
false);
171 btnConnectAll.setEnabled(
false);
172 btnAutoMesh.setEnabled(
true);
173 btnClearMesh.setEnabled(
true);
178 tglbtnNode.addActionListener(
new ActionListener() {
181 public void actionPerformed(ActionEvent e) {
182 if(rdbtnMesh.isSelected())
189 tglbtnEdge.addActionListener(
new ActionListener() {
192 public void actionPerformed(ActionEvent e) {
193 if(rdbtnMesh.isSelected())
200 tglbtnDelete.addActionListener(
new ActionListener() {
203 public void actionPerformed(ActionEvent e) {
204 if(rdbtnMesh.isSelected())
211 btnLoad.addActionListener(
new ActionListener() {
214 public void actionPerformed(ActionEvent e) {
215 int returnVal = fc.showOpenDialog(window.
getFrame());
216 if (returnVal == JFileChooser.APPROVE_OPTION){
217 btnUnbundle.setSelected(
true);
219 bundlingActive =
false;
225 btnSave.addActionListener(
new ActionListener() {
228 public void actionPerformed(ActionEvent e) {
229 int returnVal = fc.showSaveDialog(window.
getFrame());
230 if (returnVal == JFileChooser.APPROVE_OPTION)
235 btnConnectAll.addActionListener(
new ActionListener() {
238 public void actionPerformed(ActionEvent e) {
240 btnUnbundle.setSelected(
true);
245 btnClearAll.addActionListener(
new ActionListener() {
248 public void actionPerformed(ActionEvent e) {
250 btnUnbundle.setSelected(
true);
255 btnAutoMesh.addActionListener(
new ActionListener() {
258 public void actionPerformed(ActionEvent e) {
260 btnUnbundle.setSelected(
true);
261 bundlingActive =
false;
262 window.
autoMesh(slider.getValue(), slider.getValue());
267 btnClearMesh.addActionListener(
new ActionListener() {
270 public void actionPerformed(ActionEvent e) {
272 btnUnbundle.setSelected(
true);
273 bundlingActive =
false;
278 btnBundle.addActionListener(
new ActionListener() {
281 public void actionPerformed(ActionEvent e) {
283 tglbtnNode.setEnabled(
false);
284 tglbtnEdge.setEnabled(
false);
285 tglbtnDelete.setEnabled(
false);
286 btnLoad.setEnabled(
false);
287 btnSave.setEnabled(
false);
288 btnBundle.setEnabled(
false);
289 btnUnbundle.setEnabled(
false);
290 slider.setEnabled(
false);
291 btnConnectAll.setEnabled(
false);
292 btnClearAll.setEnabled(
false);
293 btnAutoMesh.setEnabled(
false);
294 btnClearMesh.setEnabled(
false);
297 bundlingActive =
true;
299 tglbtnNode.setEnabled(
true);
300 tglbtnEdge.setEnabled(
true);
301 tglbtnDelete.setEnabled(
true);
302 btnLoad.setEnabled(
true);
303 btnSave.setEnabled(
true);
304 btnBundle.setEnabled(
true);
305 btnUnbundle.setEnabled(
true);
306 slider.setEnabled(
true);
307 if(rdbtnGraph.isSelected()){
308 btnConnectAll.setEnabled(
true);
309 btnClearAll.setEnabled(
true);
311 if(rdbtnMesh.isSelected()){
312 btnAutoMesh.setEnabled(
true);
313 btnClearMesh.setEnabled(
true);
319 btnUnbundle.addActionListener(
new ActionListener() {
322 public void actionPerformed(ActionEvent e) {
325 bundlingActive =
false;