1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package unbbayes.gui;
22
23 import java.awt.BorderLayout;
24 import java.awt.GridLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.util.ResourceBundle;
28
29 import javax.swing.JButton;
30 import javax.swing.JPanel;
31 import javax.swing.JSplitPane;
32 import javax.swing.JToolBar;
33
34 import unbbayes.controller.IconController;
35 import unbbayes.controller.NetworkController;
36
37
38
39
40
41
42
43
44
45
46
47 public class EditNet extends JPanel {
48
49
50 private static final long serialVersionUID = 0;
51
52 private final NetworkWindow netWindow;
53
54 private final NetworkController controller;
55 private final IconController iconController = IconController.getInstance();
56 private final JSplitPane centerPanel;
57
58 private final JPanel topPanel;
59 private final JToolBar jtbEdition;
60
61 private final JButton compile;
62 private final JButton arc;
63 private final JButton printNet;
64 private final JButton previewNet;
65 private final JButton saveNetImage;
66
67
68 private static ResourceBundle resource = unbbayes.util.ResourceController.newInstance().getBundle(
69 unbbayes.gui.resources.GuiResources.class.getName());
70
71 public EditNet(NetworkWindow _netWindow,
72 NetworkController _controller) {
73 super();
74 this.netWindow = _netWindow;
75 this.controller = _controller;
76 this.setLayout(new BorderLayout());
77
78 topPanel = new JPanel(new GridLayout(0,1));
79 jtbEdition = new JToolBar();
80 centerPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
81
82
83
84 compile = new JButton(iconController.getCompileIcon());
85 arc = new JButton(iconController.getEdgeIcon());
86 printNet = new JButton(iconController.getPrintNetIcon());
87 previewNet = new JButton(iconController.getPrintPreviewNetIcon());
88 saveNetImage = new JButton(iconController.getSaveNetIcon());
89
90
91
92 compile.setToolTipText(resource.getString("compileToolTip"));
93 arc.setToolTipText(resource.getString("arcToolTip"));
94 printNet.setToolTipText(resource.getString("printNetToolTip"));
95 previewNet.setToolTipText(resource.getString("previewNetToolTip"));
96 saveNetImage.setToolTipText(resource.getString("saveNetImageToolTip"));
97
98
99
100
101 compile.addActionListener(new ActionListener() {
102 public void actionPerformed(ActionEvent ae) {
103 System.out.println("i came to edit net \n");
104 if (! controller.compileNetwork()) {
105 return;
106 }
107 netWindow.changeToPNCompilationPane();
108 }
109 });
110
111
112
113 arc.addActionListener(new ActionListener() {
114 public void actionPerformed(ActionEvent ae) {
115
116
117 netWindow.getGraphPane().setAction(GraphAction.CREATE_EDGE);
118 }
119 });
120
121
122 printNet.addActionListener(new ActionListener() {
123 public void actionPerformed(ActionEvent ae) {
124 controller.printNet(netWindow.getGraphPane(), controller.calculateNetRectangle());
125 }
126 });
127
128
129 previewNet.addActionListener(new ActionListener() {
130 public void actionPerformed(ActionEvent ae) {
131 controller.previewPrintNet(netWindow.getGraphPane(), controller.calculateNetRectangle());
132 }
133 });
134
135
136 saveNetImage.addActionListener(new ActionListener() {
137 public void actionPerformed(ActionEvent e) {
138 controller.saveNetImage();
139 }
140 });
141
142
143
144 jtbEdition.add(printNet);
145 jtbEdition.add(previewNet);
146 jtbEdition.add(saveNetImage);
147
148 jtbEdition.addSeparator();
149
150 jtbEdition.add(arc);
151 jtbEdition.add(compile);
152
153 topPanel.add(jtbEdition);
154
155
156 centerPanel.resetToPreferredSizes();
157
158
159 this.add(topPanel, BorderLayout.NORTH);
160 this.add(centerPanel, BorderLayout.CENTER);
161 setVisible(true);
162
163 }
164
165
166
167
168
169
170
171 public JSplitPane getCenterPanel() {
172 return this.centerPanel;
173 }
174
175 public JButton getArc() {
176 return this.arc;
177 }
178
179 public JButton getCompile() {
180 return this.compile;
181 }
182
183 public JButton getPreviewNet() {
184 return this.previewNet;
185 }
186
187 public JButton getPrintNet() {
188 return this.printNet;
189 }
190
191 public JButton getSaveNetImage() {
192 return this.saveNetImage;
193 }
194 }