[1] | 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 | import javax.swing.tree.TreePath;
|
---|
| 12 |
|
---|
| 13 | import org.jdesktop.application.Action;
|
---|
| 14 | import org.jdesktop.application.FrameView;
|
---|
| 15 | import org.jdesktop.application.SingleFrameApplication;
|
---|
| 16 |
|
---|
| 17 | import genius.core.DomainImpl;
|
---|
| 18 | import genius.core.repository.DomainRepItem;
|
---|
| 19 | import genius.core.repository.ProfileRepItem;
|
---|
| 20 | import genius.core.repository.RepItem;
|
---|
| 21 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 22 | import genius.gui.boaframework.BOARepositoryUI;
|
---|
| 23 | import genius.gui.boaparties.BoaPartiesPanel;
|
---|
| 24 | import genius.gui.domainrepository.DomainRepositoryUI;
|
---|
| 25 | import genius.gui.domainrepository.MyTreeNode;
|
---|
| 26 | import genius.gui.panels.tab.CloseListener;
|
---|
| 27 | import genius.gui.panels.tab.CloseTabbedPane;
|
---|
| 28 | import genius.gui.repository.PartyRepositoryUI;
|
---|
| 29 | import genius.gui.session.SessionPanel;
|
---|
| 30 | import genius.gui.tournament.MultiTournamentPanel;
|
---|
| 31 | import genius.gui.tree.TreeFrame;
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * The application's main frame.
|
---|
| 35 | */
|
---|
| 36 | public class NegoGUIView extends FrameView {
|
---|
| 37 |
|
---|
| 38 | // Variables declaration - do not modify//GEN-BEGIN:variables
|
---|
| 39 | private genius.gui.panels.tab.CloseTabbedPane closeTabbedPane1;
|
---|
| 40 | private javax.swing.JMenuItem newMultilateralMenuItem;
|
---|
| 41 | private javax.swing.JMenuItem newMultilateralTournamentMenuItem;
|
---|
| 42 | private javax.swing.JPanel jPanel1;
|
---|
| 43 | private javax.swing.JScrollPane jScrollPane2;
|
---|
| 44 | private javax.swing.JScrollPane jScrollPane3;
|
---|
| 45 | private javax.swing.JSplitPane jSplitPane1;
|
---|
| 46 | private javax.swing.JTabbedPane jTabbedPane1;
|
---|
| 47 | private javax.swing.JPanel mainPanel;
|
---|
| 48 | private javax.swing.JMenuBar menuBar;
|
---|
| 49 | private javax.swing.JMenuItem manualMenuItem;
|
---|
| 50 | private javax.swing.JMenuItem classDocumentationMenuItem;
|
---|
| 51 | private javax.swing.JMenuItem aboutMenuItem;
|
---|
| 52 | private javax.swing.JTable tableBOAcomponents;
|
---|
| 53 | private javax.swing.JTree treeDomains;
|
---|
| 54 |
|
---|
| 55 | public NegoGUIView(SingleFrameApplication app) {
|
---|
| 56 | super(app);
|
---|
[9] | 57 | treeDomains = new DomainRepositoryUI(this);
|
---|
[1] | 58 | initComponents();
|
---|
| 59 | try {
|
---|
| 60 | new BOARepositoryUI(tableBOAcomponents);
|
---|
| 61 |
|
---|
| 62 | } catch (Exception e) {
|
---|
| 63 | e.printStackTrace();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | jTabbedPane1.addTab("Parties", new PartyRepositoryUI());
|
---|
| 67 |
|
---|
| 68 | jTabbedPane1.addTab("Boa Parties", new BoaPartiesPanel());
|
---|
| 69 |
|
---|
| 70 | CloseListener cl = new CloseListener() {
|
---|
[9] | 71 | @Override
|
---|
[1] | 72 | public void closeOperation(MouseEvent e, int overTabIndex) {
|
---|
| 73 | closeTabbedPane1.remove(overTabIndex);
|
---|
| 74 | }
|
---|
| 75 | };
|
---|
| 76 | closeTabbedPane1.addCloseListener(cl);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | /**
|
---|
| 80 | * @param filename
|
---|
| 81 | * @return part of filename following the last slash, or full filename if
|
---|
| 82 | * there is no slash.
|
---|
| 83 | */
|
---|
| 84 | public String GetPlainFileName(String filename) {
|
---|
| 85 | int i = filename.lastIndexOf('/');
|
---|
| 86 | if (i == -1)
|
---|
| 87 | return filename;
|
---|
| 88 | return filename.substring(i + 1);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /**
|
---|
| 92 | * @param filename
|
---|
| 93 | * @return filename stripped of its extension (the part after the last dot).
|
---|
| 94 | */
|
---|
| 95 | public String StripExtension(String filename) {
|
---|
| 96 | int i = filename.lastIndexOf('.');
|
---|
| 97 | if (i == -1)
|
---|
| 98 | return filename;
|
---|
| 99 | return filename.substring(0, i);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | public void replaceTab(String title, Component oldComp, Component newComp) {
|
---|
| 103 | closeTabbedPane1.remove(oldComp);
|
---|
| 104 | addTab(title, newComp);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[9] | 107 | /**
|
---|
| 108 | * Open a new tab in the right half area
|
---|
| 109 | *
|
---|
| 110 | * @param title
|
---|
| 111 | * title for the new tab
|
---|
| 112 | * @param comp
|
---|
| 113 | * the component to show there
|
---|
| 114 | */
|
---|
[1] | 115 | public void addTab(String title, Component comp) {
|
---|
| 116 | closeTabbedPane1.addTab(title, comp);
|
---|
| 117 | closeTabbedPane1.setSelectedComponent(comp);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | private void initComponents() {
|
---|
| 121 | mainPanel = new javax.swing.JPanel();
|
---|
| 122 | jSplitPane1 = new javax.swing.JSplitPane();
|
---|
| 123 | jPanel1 = new javax.swing.JPanel();
|
---|
| 124 | jTabbedPane1 = new javax.swing.JTabbedPane();
|
---|
| 125 | jScrollPane2 = new javax.swing.JScrollPane();
|
---|
| 126 | jScrollPane3 = new javax.swing.JScrollPane();
|
---|
| 127 | jScrollPane3 = new javax.swing.JScrollPane();
|
---|
| 128 | tableBOAcomponents = new javax.swing.JTable();
|
---|
| 129 | closeTabbedPane1 = new genius.gui.panels.tab.CloseTabbedPane();
|
---|
| 130 |
|
---|
| 131 | menuBar = new javax.swing.JMenuBar();
|
---|
| 132 | JMenu startMenu = new javax.swing.JMenu();
|
---|
| 133 | newMultilateralMenuItem = new javax.swing.JMenuItem();
|
---|
| 134 | newMultilateralTournamentMenuItem = new javax.swing.JMenuItem();
|
---|
| 135 |
|
---|
| 136 | JMenu helpMenu = new javax.swing.JMenu();
|
---|
| 137 | manualMenuItem = new javax.swing.JMenuItem();
|
---|
| 138 | classDocumentationMenuItem = new javax.swing.JMenuItem();
|
---|
| 139 | aboutMenuItem = new javax.swing.JMenuItem();
|
---|
| 140 |
|
---|
| 141 | mainPanel.setName("mainPanel"); // NOI18N
|
---|
| 142 |
|
---|
| 143 | jSplitPane1.setName("jSplitPane1"); // NOI18N
|
---|
| 144 |
|
---|
| 145 | jPanel1.setName("jPanel1"); // NOI18N
|
---|
| 146 |
|
---|
| 147 | jTabbedPane1.setName("jTabbedPane1"); // NOI18N
|
---|
| 148 |
|
---|
| 149 | jScrollPane2.setName("jScrollPane2"); // NOI18N
|
---|
| 150 |
|
---|
| 151 | treeDomains.addMouseListener(new java.awt.event.MouseAdapter() {
|
---|
[9] | 152 | @Override
|
---|
[1] | 153 | public void mouseClicked(java.awt.event.MouseEvent evt) {
|
---|
| 154 | treeDomainsMouseClicked(evt);
|
---|
| 155 | }
|
---|
| 156 | });
|
---|
| 157 | jScrollPane2.setViewportView(treeDomains);
|
---|
| 158 |
|
---|
[9] | 159 | org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application
|
---|
| 160 | .getInstance().getContext().getResourceMap(NegoGUIView.class);
|
---|
| 161 | jTabbedPane1.addTab(
|
---|
| 162 | resourceMap.getString("jScrollPane2.TabConstraints.tabTitle"),
|
---|
| 163 | jScrollPane2); // NOI18N
|
---|
[1] | 164 |
|
---|
[9] | 165 | org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
|
---|
| 166 | jPanel1);
|
---|
[1] | 167 | jPanel1.setLayout(jPanel1Layout);
|
---|
[9] | 168 | jPanel1Layout.setHorizontalGroup(jPanel1Layout
|
---|
| 169 | .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
| 170 | .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
|
---|
| 171 | 298, Short.MAX_VALUE));
|
---|
| 172 | jPanel1Layout.setVerticalGroup(jPanel1Layout
|
---|
| 173 | .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
| 174 | .add(jTabbedPane1,
|
---|
| 175 | org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49,
|
---|
| 176 | Short.MAX_VALUE));
|
---|
[1] | 177 |
|
---|
| 178 | jSplitPane1.setLeftComponent(jPanel1);
|
---|
| 179 |
|
---|
| 180 | jScrollPane3.setViewportView(tableBOAcomponents);
|
---|
| 181 | jTabbedPane1.addTab("BOA components", jScrollPane3);
|
---|
| 182 |
|
---|
| 183 | closeTabbedPane1.setName("closeTabbedPane1"); // NOI18N
|
---|
| 184 | jSplitPane1.setRightComponent(closeTabbedPane1);
|
---|
| 185 |
|
---|
[9] | 186 | org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(
|
---|
| 187 | mainPanel);
|
---|
[1] | 188 | mainPanel.setLayout(mainPanelLayout);
|
---|
[9] | 189 | mainPanelLayout.setHorizontalGroup(mainPanelLayout
|
---|
| 190 | .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
[1] | 191 | .add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1,
|
---|
[9] | 192 | org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 605,
|
---|
| 193 | Short.MAX_VALUE)
|
---|
[1] | 194 |
|
---|
| 195 | );
|
---|
[9] | 196 | mainPanelLayout.setVerticalGroup(mainPanelLayout
|
---|
| 197 | .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
[1] | 198 | .add(org.jdesktop.layout.GroupLayout.TRAILING,
|
---|
| 199 | mainPanelLayout.createSequentialGroup().add(jSplitPane1,
|
---|
[9] | 200 | org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
|
---|
| 201 | 665, Short.MAX_VALUE))
|
---|
| 202 | .add(mainPanelLayout
|
---|
| 203 | .createParallelGroup(
|
---|
| 204 | org.jdesktop.layout.GroupLayout.LEADING)
|
---|
[1] | 205 | .add(mainPanelLayout.createSequentialGroup())));
|
---|
| 206 |
|
---|
| 207 | menuBar.setName("menuBar"); // NOI18N
|
---|
| 208 |
|
---|
| 209 | startMenu.setText("Start");
|
---|
| 210 | startMenu.setName("startMenu"); // NOI18N
|
---|
| 211 |
|
---|
[9] | 212 | javax.swing.ActionMap actionMap = org.jdesktop.application.Application
|
---|
| 213 | .getInstance().getContext()
|
---|
[1] | 214 | .getActionMap(NegoGUIView.class, this);
|
---|
| 215 |
|
---|
| 216 | // Add a new menu item for multi-agent negotiation tournament
|
---|
[9] | 217 | newMultilateralTournamentMenuItem
|
---|
| 218 | .setAction(actionMap.get("newMultiAgentTournamentTab")); // NOI18N
|
---|
[1] | 219 | newMultilateralTournamentMenuItem.setName("newMultilateralMenuItem"); // NOI18N
|
---|
| 220 | startMenu.add(newMultilateralTournamentMenuItem);
|
---|
| 221 |
|
---|
| 222 | newMultilateralMenuItem.setAction(actionMap.get("newMultiNegoSession")); // NOI18N
|
---|
| 223 | newMultilateralMenuItem.setName("newMultilateralMenuItem"); // NOI18N
|
---|
| 224 | startMenu.add(newMultilateralMenuItem);
|
---|
| 225 |
|
---|
| 226 | menuBar.add(startMenu);
|
---|
| 227 | menuBar.add(helpMenu);
|
---|
| 228 |
|
---|
| 229 | helpMenu.setText(resourceMap.getString("helpMenu.text"));
|
---|
| 230 |
|
---|
| 231 | manualMenuItem.setAction(actionMap.get("openManual")); // NOI18N
|
---|
| 232 | helpMenu.add(manualMenuItem);
|
---|
| 233 |
|
---|
[9] | 234 | classDocumentationMenuItem
|
---|
| 235 | .setAction(actionMap.get("openDocumentation")); // NOI18N
|
---|
[1] | 236 | helpMenu.add(classDocumentationMenuItem);
|
---|
| 237 |
|
---|
| 238 | aboutMenuItem.setAction(actionMap.get("openAbout")); // NOI18N
|
---|
| 239 | helpMenu.add(aboutMenuItem);
|
---|
| 240 |
|
---|
| 241 | setComponent(mainPanel);
|
---|
| 242 | setMenuBar(menuBar);
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | private void treeDomainsMouseClicked(java.awt.event.MouseEvent evt) {
|
---|
| 246 | int selRow = treeDomains.getRowForLocation(evt.getX(), evt.getY());
|
---|
[9] | 247 | TreePath selPath = treeDomains.getPathForLocation(evt.getX(),
|
---|
| 248 | evt.getY());
|
---|
[1] | 249 | if (selRow != -1) {
|
---|
| 250 | if (evt.getClickCount() == 2) {
|
---|
| 251 | if (selPath != null) {
|
---|
[9] | 252 | MyTreeNode node = (MyTreeNode) (selPath
|
---|
| 253 | .getLastPathComponent());
|
---|
[1] | 254 | RepItem repItem = node.getRepositoryItem();
|
---|
| 255 | showRepositoryItemInTab(repItem, node);
|
---|
| 256 | }
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | public void showRepositoryItemInTab(RepItem repItem, MyTreeNode node) {
|
---|
| 262 | TreeFrame tf;
|
---|
| 263 | if (repItem instanceof DomainRepItem) {
|
---|
| 264 | try {
|
---|
[9] | 265 | boolean hasNoProfiles = ((DomainRepItem) repItem).getProfiles()
|
---|
| 266 | .size() == 0;
|
---|
[1] | 267 | String filename = ((DomainRepItem) repItem).getURL().getFile();
|
---|
| 268 | DomainImpl domain = new DomainImpl(filename);
|
---|
| 269 | tf = new TreeFrame(domain, hasNoProfiles);
|
---|
| 270 | addTab(StripExtension(GetPlainFileName(filename)), tf);
|
---|
| 271 | } catch (Exception e) {
|
---|
| 272 | e.printStackTrace();
|
---|
| 273 | }
|
---|
| 274 | } else if (repItem instanceof ProfileRepItem) {
|
---|
| 275 | try {
|
---|
| 276 | MyTreeNode parentNode = (MyTreeNode) (node.getParent());
|
---|
| 277 | String filename = ((ProfileRepItem) repItem).getURL().getFile();
|
---|
| 278 |
|
---|
| 279 | DomainImpl domain = new DomainImpl(
|
---|
[9] | 280 | ((DomainRepItem) (parentNode.getRepositoryItem()))
|
---|
| 281 | .getURL().getFile());
|
---|
[1] | 282 |
|
---|
| 283 | // we can handle only AdditiveUtilitySpace in TreeFrame anyway
|
---|
| 284 | // so we guess it's that...
|
---|
[9] | 285 | AdditiveUtilitySpace utilitySpace = new AdditiveUtilitySpace(
|
---|
| 286 | domain, filename);
|
---|
[1] | 287 |
|
---|
| 288 | tf = new TreeFrame(domain, utilitySpace);
|
---|
| 289 | addTab(StripExtension(GetPlainFileName(filename)), tf);
|
---|
| 290 | } catch (Exception e) {
|
---|
| 291 | e.printStackTrace();
|
---|
| 292 |
|
---|
| 293 | }
|
---|
| 294 | }
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | /**
|
---|
| 298 | * Adds a tab to the GUI's start-menu for opening a multi-agent negotiation
|
---|
| 299 | * tab.
|
---|
| 300 | */
|
---|
| 301 | @Action
|
---|
| 302 | public void newMultiAgentTournamentTab() {
|
---|
| 303 | try {
|
---|
| 304 | addTab("Tournament", new MultiTournamentPanel());
|
---|
| 305 | } catch (Exception e) {
|
---|
| 306 | e.printStackTrace();
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | @Action
|
---|
| 311 | public void newMultiNegoSession() {
|
---|
| 312 | try {
|
---|
| 313 | addTab("Session", new SessionPanel());
|
---|
| 314 | } catch (Exception e) {
|
---|
| 315 | e.printStackTrace();
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | @Action
|
---|
| 320 | public void openManual() {
|
---|
| 321 | if (Desktop.isDesktopSupported()) {
|
---|
| 322 | try {
|
---|
| 323 | File myFile = new File("doc/userguide.pdf");
|
---|
| 324 | Desktop.getDesktop().open(myFile);
|
---|
| 325 | } catch (IOException ex) {
|
---|
[9] | 326 | JOptionPane.showMessageDialog(this.getComponent(),
|
---|
| 327 | "There is no program registered to open PDF files.");
|
---|
[1] | 328 | }
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | @Action
|
---|
| 333 | public void openDocumentation() {
|
---|
| 334 | if (Desktop.isDesktopSupported()) {
|
---|
| 335 | try {
|
---|
| 336 | File myFile = new File("javadoc/index.html");
|
---|
| 337 | Desktop.getDesktop().open(myFile);
|
---|
| 338 | } catch (IOException ex) {
|
---|
| 339 | JOptionPane.showMessageDialog(this.getComponent(),
|
---|
| 340 | "There is no program registered to open HTML files.");
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | @Action
|
---|
| 346 | public void openAbout() {
|
---|
| 347 | About about = new About();
|
---|
| 348 | about.setVisible(true);
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | public CloseTabbedPane getMainTabbedPane() {
|
---|
| 352 | return closeTabbedPane1;
|
---|
| 353 | }
|
---|
| 354 | }
|
---|