source: src/main/java/genius/gui/NegoGUIView.java@ 12

Last change on this file since 12 was 11, checked in by Wouter Pasman, 7 years ago

#5 more refactoring, removed NegoGUIApp.negoGUIView. ref

File size: 8.7 KB
Line 
1package genius.gui;
2
3import java.awt.Component;
4import java.awt.Desktop;
5import java.awt.Frame;
6import java.awt.event.MouseEvent;
7import java.io.File;
8import java.io.IOException;
9
10import javax.swing.JMenu;
11import javax.swing.JOptionPane;
12
13import org.jdesktop.application.Action;
14import org.jdesktop.application.FrameView;
15import org.jdesktop.application.SingleFrameApplication;
16
17import genius.gui.boaframework.BOARepositoryUI;
18import genius.gui.boaparties.BoaPartiesPanel;
19import genius.gui.domainrepository.DomainRepositoryUI;
20import genius.gui.panels.tab.CloseListener;
21import genius.gui.panels.tab.CloseTabbedPane;
22import genius.gui.repository.PartyRepositoryUI;
23import genius.gui.session.SessionPanel;
24import genius.gui.tournament.MultiTournamentPanel;
25
26/**
27 * The application's main frame.
28 */
29public class NegoGUIView extends FrameView implements MainPanelInterface {
30
31 // Variables declaration - do not modify//GEN-BEGIN:variables
32 private genius.gui.panels.tab.CloseTabbedPane closeTabbedPane1;
33 private javax.swing.JMenuItem newMultilateralMenuItem;
34 private javax.swing.JMenuItem newMultilateralTournamentMenuItem;
35 private javax.swing.JPanel jPanel1;
36 private javax.swing.JScrollPane jScrollPane2;
37 private javax.swing.JScrollPane jScrollPane3;
38 private javax.swing.JSplitPane jSplitPane1;
39 private javax.swing.JTabbedPane jTabbedPane1;
40 private javax.swing.JPanel mainPanel;
41 private javax.swing.JMenuBar menuBar;
42 private javax.swing.JMenuItem manualMenuItem;
43 private javax.swing.JMenuItem classDocumentationMenuItem;
44 private javax.swing.JMenuItem aboutMenuItem;
45 private javax.swing.JTable tableBOAcomponents;
46 private javax.swing.JTree treeDomains;
47
48 public NegoGUIView(SingleFrameApplication app) {
49 super(app);
50 treeDomains = new DomainRepositoryUI(this);
51
52 initComponents();
53 try {
54 new BOARepositoryUI(tableBOAcomponents);
55
56 } catch (Exception e) {
57 e.printStackTrace();
58 }
59
60 jTabbedPane1.addTab("Parties", new PartyRepositoryUI());
61
62 jTabbedPane1.addTab("Boa Parties", new BoaPartiesPanel());
63
64 CloseListener cl = new CloseListener() {
65 @Override
66 public void closeOperation(MouseEvent e, int overTabIndex) {
67 closeTabbedPane1.remove(overTabIndex);
68 }
69 };
70 closeTabbedPane1.addCloseListener(cl);
71 }
72
73 /**
74 * @param filename
75 * @return part of filename following the last slash, or full filename if
76 * there is no slash.
77 */
78 public String GetPlainFileName(String filename) {
79 int i = filename.lastIndexOf('/');
80 if (i == -1)
81 return filename;
82 return filename.substring(i + 1);
83 }
84
85 /**
86 * @param filename
87 * @return filename stripped of its extension (the part after the last dot).
88 */
89 public String StripExtension(String filename) {
90 int i = filename.lastIndexOf('.');
91 if (i == -1)
92 return filename;
93 return filename.substring(0, i);
94 }
95
96 public void replaceTab(String title, Component oldComp, Component newComp) {
97 closeTabbedPane1.remove(oldComp);
98 addTab(title, newComp);
99 }
100
101 @Override
102 public void addTab(String title, Component comp) {
103 closeTabbedPane1.addTab(title, comp);
104 closeTabbedPane1.setSelectedComponent(comp);
105 }
106
107 private void initComponents() {
108 mainPanel = new javax.swing.JPanel();
109 jSplitPane1 = new javax.swing.JSplitPane();
110 jPanel1 = new javax.swing.JPanel();
111 jTabbedPane1 = new javax.swing.JTabbedPane();
112 jScrollPane2 = new javax.swing.JScrollPane();
113 jScrollPane3 = new javax.swing.JScrollPane();
114 jScrollPane3 = new javax.swing.JScrollPane();
115 tableBOAcomponents = new javax.swing.JTable();
116 closeTabbedPane1 = new genius.gui.panels.tab.CloseTabbedPane();
117
118 menuBar = new javax.swing.JMenuBar();
119 JMenu startMenu = new javax.swing.JMenu();
120 newMultilateralMenuItem = new javax.swing.JMenuItem();
121 newMultilateralTournamentMenuItem = new javax.swing.JMenuItem();
122
123 JMenu helpMenu = new javax.swing.JMenu();
124 manualMenuItem = new javax.swing.JMenuItem();
125 classDocumentationMenuItem = new javax.swing.JMenuItem();
126 aboutMenuItem = new javax.swing.JMenuItem();
127
128 mainPanel.setName("mainPanel"); // NOI18N
129
130 jSplitPane1.setName("jSplitPane1"); // NOI18N
131
132 jPanel1.setName("jPanel1"); // NOI18N
133
134 jTabbedPane1.setName("jTabbedPane1"); // NOI18N
135
136 jScrollPane2.setName("jScrollPane2"); // NOI18N
137
138 jScrollPane2.setViewportView(treeDomains);
139
140 org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application
141 .getInstance().getContext().getResourceMap(NegoGUIView.class);
142 jTabbedPane1.addTab(
143 resourceMap.getString("jScrollPane2.TabConstraints.tabTitle"),
144 jScrollPane2); // NOI18N
145
146 org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
147 jPanel1);
148 jPanel1.setLayout(jPanel1Layout);
149 jPanel1Layout.setHorizontalGroup(jPanel1Layout
150 .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
151 .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
152 298, Short.MAX_VALUE));
153 jPanel1Layout.setVerticalGroup(jPanel1Layout
154 .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
155 .add(jTabbedPane1,
156 org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49,
157 Short.MAX_VALUE));
158
159 jSplitPane1.setLeftComponent(jPanel1);
160
161 jScrollPane3.setViewportView(tableBOAcomponents);
162 jTabbedPane1.addTab("BOA components", jScrollPane3);
163
164 closeTabbedPane1.setName("closeTabbedPane1"); // NOI18N
165 jSplitPane1.setRightComponent(closeTabbedPane1);
166
167 org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(
168 mainPanel);
169 mainPanel.setLayout(mainPanelLayout);
170 mainPanelLayout.setHorizontalGroup(mainPanelLayout
171 .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
172 .add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1,
173 org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 605,
174 Short.MAX_VALUE)
175
176 );
177 mainPanelLayout.setVerticalGroup(mainPanelLayout
178 .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
179 .add(org.jdesktop.layout.GroupLayout.TRAILING,
180 mainPanelLayout.createSequentialGroup().add(jSplitPane1,
181 org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
182 665, Short.MAX_VALUE))
183 .add(mainPanelLayout
184 .createParallelGroup(
185 org.jdesktop.layout.GroupLayout.LEADING)
186 .add(mainPanelLayout.createSequentialGroup())));
187
188 menuBar.setName("menuBar"); // NOI18N
189
190 startMenu.setText("Start");
191 startMenu.setName("startMenu"); // NOI18N
192
193 javax.swing.ActionMap actionMap = org.jdesktop.application.Application
194 .getInstance().getContext()
195 .getActionMap(NegoGUIView.class, this);
196
197 // Add a new menu item for multi-agent negotiation tournament
198 newMultilateralTournamentMenuItem
199 .setAction(actionMap.get("newMultiAgentTournamentTab")); // NOI18N
200 newMultilateralTournamentMenuItem.setName("newMultilateralMenuItem"); // NOI18N
201 startMenu.add(newMultilateralTournamentMenuItem);
202
203 newMultilateralMenuItem.setAction(actionMap.get("newMultiNegoSession")); // NOI18N
204 newMultilateralMenuItem.setName("newMultilateralMenuItem"); // NOI18N
205 startMenu.add(newMultilateralMenuItem);
206
207 menuBar.add(startMenu);
208 menuBar.add(helpMenu);
209
210 helpMenu.setText(resourceMap.getString("helpMenu.text"));
211
212 manualMenuItem.setAction(actionMap.get("openManual")); // NOI18N
213 helpMenu.add(manualMenuItem);
214
215 classDocumentationMenuItem
216 .setAction(actionMap.get("openDocumentation")); // NOI18N
217 helpMenu.add(classDocumentationMenuItem);
218
219 aboutMenuItem.setAction(actionMap.get("openAbout")); // NOI18N
220 helpMenu.add(aboutMenuItem);
221
222 setComponent(mainPanel);
223 setMenuBar(menuBar);
224 }
225
226 /**
227 * Adds a tab to the GUI's start-menu for opening a multi-agent negotiation
228 * tab.
229 */
230 @Action
231 public void newMultiAgentTournamentTab() {
232 try {
233 addTab("Tournament", new MultiTournamentPanel());
234 } catch (Exception e) {
235 e.printStackTrace();
236 }
237 }
238
239 @Action
240 public void newMultiNegoSession() {
241 try {
242 addTab("Session", new SessionPanel());
243 } catch (Exception e) {
244 e.printStackTrace();
245 }
246 }
247
248 @Action
249 public void openManual() {
250 if (Desktop.isDesktopSupported()) {
251 try {
252 File myFile = new File("doc/userguide.pdf");
253 Desktop.getDesktop().open(myFile);
254 } catch (IOException ex) {
255 JOptionPane.showMessageDialog(this.getComponent(),
256 "There is no program registered to open PDF files.");
257 }
258 }
259 }
260
261 @Action
262 public void openDocumentation() {
263 if (Desktop.isDesktopSupported()) {
264 try {
265 File myFile = new File("javadoc/index.html");
266 Desktop.getDesktop().open(myFile);
267 } catch (IOException ex) {
268 JOptionPane.showMessageDialog(this.getComponent(),
269 "There is no program registered to open HTML files.");
270 }
271 }
272 }
273
274 @Action
275 public void openAbout() {
276 About about = new About();
277 about.setVisible(true);
278 }
279
280 public CloseTabbedPane getMainTabbedPane() {
281 return closeTabbedPane1;
282 }
283
284 @Override
285 public Frame getMainFrame() {
286 return this.getFrame();
287 }
288}
Note: See TracBrowser for help on using the repository browser.