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