MiorView.java
3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package mior.view;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import mior.controler.AutoLiveAction;
import mior.controler.ClearAction;
import mior.controler.ConfigureAssociationsAction;
import mior.controler.ConfigureRadiusAction;
import mior.controler.ConfigureRandomAction;
import mior.controler.LiveAction;
import mior.controler.ResetAction;
import mior.controler.TopoAction;
import mior.model.IMiorModel;
import mior.model.MiorWorld;
import mior.model.OCLMiorModel;
public class MiorView {
private IMiorModel model;
private final JFrame frame;
private final MiorCanvas canvas;
private final MiorGraph graph;
public MiorView(IMiorModel model) {
this(model, "");
}
public MiorView(IMiorModel model, String suppl) {
this.frame = new JFrame("MiorCL - 0.2 [" + suppl + "]");
this.model = model;
this.canvas = new MiorCanvas(model);
model.addUpdateListener(canvas);
this.graph = new MiorGraph();
model.addUpdateListener(graph);
buildUI();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
}
public void setModel(IMiorModel model) {
if (model != this.model) {
model.addUpdateListener(canvas);
model.addUpdateListener(graph);
}
this.model = model;
}
public JFrame getFrame() {
return frame;
}
private void buildUI() {
final JPanel mainPanel = new JPanel(new BorderLayout());
frame.setContentPane(mainPanel);
mainPanel.add(canvas, BorderLayout.CENTER);
mainPanel.add(graph, BorderLayout.EAST);
final JPanel buttonPanel = new JPanel();
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
final JButton resetButton = new JButton(new ResetAction(model));
buttonPanel.add(resetButton);
final JButton topoButton = new JButton(new TopoAction(model));
buttonPanel.add(topoButton);
final JButton liveButton = new JButton(new LiveAction(model));
buttonPanel.add(liveButton);
final JButton autoButton = new JButton(new AutoLiveAction(model));
buttonPanel.add(autoButton);
final JButton clearButton = new JButton(new ClearAction(graph));
buttonPanel.add(clearButton);
final JCheckBox assocCheckbox = new JCheckBox(new ConfigureAssociationsAction(canvas));
assocCheckbox.setSelected(canvas.isAssociationsVisible());
buttonPanel.add(assocCheckbox);
final JCheckBox radiusCheckbox = new JCheckBox(new ConfigureRadiusAction(canvas));
radiusCheckbox.setSelected(canvas.isRadiusVisible());
buttonPanel.add(radiusCheckbox);
final JCheckBox randomCheckBox = new JCheckBox(new ConfigureRandomAction(model));
randomCheckBox.setSelected(model.isRandomEnabled());
buttonPanel.add(randomCheckBox);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
} catch (final Exception e) {
e.printStackTrace();
}
final MiorWorld world = new MiorWorld(1);
final IMiorModel model = new OCLMiorModel(world);
new MiorView(model);
}
});
}
}