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.JProgressBar;
14 import javax.swing.BoxLayout;
15 import java.awt.Component;
16 import javax.swing.JLabel;
17 import javax.swing.JCheckBox;
27 private boolean bundlingActive;
28 private final ButtonGroup buttonGroup =
new ButtonGroup();
30 private JFileChooser fc;
31 private JToggleButton tglbtnNode;
32 private JToggleButton tglbtnEdge;
33 private JToggleButton tglbtnDelete;
34 private JButton btnLoad;
35 private JButton btnSave;
36 private JButton btnClearAll;
37 private JButton btnConnectAll;
38 private JToggleButton btnBundle;
39 private JToggleButton btnUnbundle;
40 private JSlider slider;
41 private final ButtonGroup buttonGroup_1 =
new ButtonGroup();
42 private JProgressBar progressBar;
43 private JLabel lblStiffness;
44 private JCheckBox chckbxAnimation;
51 fc =
new JFileChooser();
52 fc.setFileFilter(
new FileNameExtensionFilter(
"GraphDraw File",
"gdf"));
53 fc.setCurrentDirectory(
new File(
"./"));
55 setLayout(
new MigLayout(
"",
"[90.00][]",
"[][][][][][][][]"));
57 tglbtnNode =
new JToggleButton(
"Node");
58 buttonGroup.add(tglbtnNode);
59 add(tglbtnNode,
"cell 0 0,growx");
61 btnConnectAll =
new JButton(
"Connect All");
62 add(btnConnectAll,
"cell 1 0,growx");
63 btnConnectAll.setAlignmentX(Component.CENTER_ALIGNMENT);
65 tglbtnEdge =
new JToggleButton(
"Edge");
66 buttonGroup.add(tglbtnEdge);
67 add(tglbtnEdge,
"cell 0 1,growx");
69 btnClearAll =
new JButton(
"Clear All");
70 add(btnClearAll,
"cell 1 1,growx");
71 btnClearAll.setAlignmentX(Component.CENTER_ALIGNMENT);
73 tglbtnDelete =
new JToggleButton(
"Delete");
74 buttonGroup.add(tglbtnDelete);
75 add(tglbtnDelete,
"flowy,cell 0 2,growx");
76 bundlingActive =
false;
78 chckbxAnimation =
new JCheckBox(
"Animation");
79 add(chckbxAnimation,
"cell 1 2,alignx center");
81 lblStiffness =
new JLabel(
"Stiffness:");
82 add(lblStiffness,
"cell 0 3");
84 slider =
new JSlider();
85 slider.setPaintLabels(
true);
86 slider.setPaintTicks(
true);
87 slider.setMaximum(10);
89 slider.setMajorTickSpacing(1);
90 slider.setSnapToTicks(
true);
92 add(slider,
"cell 0 4 2 1,growx");
94 btnLoad =
new JButton(
"Load");
95 add(btnLoad,
"cell 0 5,growx");
97 btnSave =
new JButton(
"Save");
98 add(btnSave,
"cell 1 5,growx");
100 btnBundle =
new JToggleButton(
"Bundle");
101 buttonGroup_1.add(btnBundle);
102 add(btnBundle,
"cell 0 6,growx");
104 btnUnbundle =
new JToggleButton(
"Unbundle");
105 btnUnbundle.setSelected(
true);
106 buttonGroup_1.add(btnUnbundle);
107 add(btnUnbundle,
"cell 1 6,growx");
109 progressBar =
new JProgressBar();
110 add(progressBar,
"cell 0 7 2 1,growx");
120 progressBar.setValue(progress);
121 progressBar.update(progressBar.getGraphics());
128 tglbtnNode.addActionListener(
new ActionListener() {
131 public void actionPerformed(ActionEvent e) {
136 tglbtnEdge.addActionListener(
new ActionListener() {
139 public void actionPerformed(ActionEvent e) {
144 tglbtnDelete.addActionListener(
new ActionListener() {
147 public void actionPerformed(ActionEvent e) {
152 btnLoad.addActionListener(
new ActionListener() {
155 public void actionPerformed(ActionEvent e) {
156 int returnVal = fc.showOpenDialog(window.
getFrame());
157 if (returnVal == JFileChooser.APPROVE_OPTION){
158 btnUnbundle.setSelected(
true);
159 tglbtnNode.setEnabled(
true);
160 tglbtnEdge.setEnabled(
true);
161 tglbtnDelete.setEnabled(
true);
162 tglbtnNode.setSelected(
false);
163 tglbtnEdge.setSelected(
false);
164 tglbtnDelete.setSelected(
false);
165 btnConnectAll.setEnabled(
true);
166 btnClearAll.setEnabled(
true);
167 chckbxAnimation.setEnabled(
true);
169 bundlingActive =
false;
175 btnSave.addActionListener(
new ActionListener() {
178 public void actionPerformed(ActionEvent e) {
179 int returnVal = fc.showSaveDialog(window.
getFrame());
180 if (returnVal == JFileChooser.APPROVE_OPTION)
185 btnConnectAll.addActionListener(
new ActionListener() {
188 public void actionPerformed(ActionEvent e) {
193 btnClearAll.addActionListener(
new ActionListener() {
196 public void actionPerformed(ActionEvent e) {
201 btnBundle.addActionListener(
new ActionListener() {
204 public void actionPerformed(ActionEvent e) {
207 tglbtnNode.setEnabled(
false);
208 tglbtnEdge.setEnabled(
false);
209 tglbtnDelete.setEnabled(
false);
210 btnConnectAll.setEnabled(
false);
211 btnClearAll.setEnabled(
false);
212 chckbxAnimation.setEnabled(
false);
213 btnLoad.setEnabled(
false);
214 btnSave.setEnabled(
false);
215 btnBundle.setEnabled(
false);
216 btnUnbundle.setEnabled(
false);
217 slider.setEnabled(
false);
218 update(getGraphics());
220 window.
bundleEdges(slider.getValue(), chckbxAnimation.isSelected());
221 bundlingActive =
true;
223 btnLoad.setEnabled(
true);
224 btnSave.setEnabled(
true);
225 btnBundle.setEnabled(
true);
226 btnUnbundle.setEnabled(
true);
227 slider.setEnabled(
true);
232 btnUnbundle.addActionListener(
new ActionListener() {
235 public void actionPerformed(ActionEvent e) {
238 bundlingActive =
false;
239 tglbtnNode.setEnabled(
true);
240 tglbtnEdge.setEnabled(
true);
241 tglbtnDelete.setEnabled(
true);
242 btnConnectAll.setEnabled(
true);
243 btnClearAll.setEnabled(
true);
244 chckbxAnimation.setEnabled(
true);