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