[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);
|
---|
| 57 | initComponents();
|
---|
| 58 |
|
---|
| 59 | try {
|
---|
| 60 | new DomainRepositoryUI(treeDomains, this);
|
---|
| 61 | new BOARepositoryUI(tableBOAcomponents);
|
---|
| 62 |
|
---|
| 63 | } catch (Exception e) {
|
---|
| 64 | e.printStackTrace();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | jTabbedPane1.addTab("Parties", new PartyRepositoryUI());
|
---|
| 68 |
|
---|
| 69 | jTabbedPane1.addTab("Boa Parties", new BoaPartiesPanel());
|
---|
| 70 |
|
---|
| 71 | CloseListener cl = new CloseListener() {
|
---|
| 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 |
|
---|
| 107 | public void addTab(String title, Component comp) {
|
---|
| 108 | closeTabbedPane1.addTab(title, comp);
|
---|
| 109 | closeTabbedPane1.setSelectedComponent(comp);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | private void initComponents() {
|
---|
| 113 | mainPanel = new javax.swing.JPanel();
|
---|
| 114 | jSplitPane1 = new javax.swing.JSplitPane();
|
---|
| 115 | jPanel1 = new javax.swing.JPanel();
|
---|
| 116 | jTabbedPane1 = new javax.swing.JTabbedPane();
|
---|
| 117 | jScrollPane2 = new javax.swing.JScrollPane();
|
---|
| 118 | jScrollPane3 = new javax.swing.JScrollPane();
|
---|
| 119 | treeDomains = new javax.swing.JTree();
|
---|
| 120 | jScrollPane3 = new javax.swing.JScrollPane();
|
---|
| 121 | tableBOAcomponents = new javax.swing.JTable();
|
---|
| 122 | closeTabbedPane1 = new genius.gui.panels.tab.CloseTabbedPane();
|
---|
| 123 |
|
---|
| 124 | menuBar = new javax.swing.JMenuBar();
|
---|
| 125 | JMenu startMenu = new javax.swing.JMenu();
|
---|
| 126 | newMultilateralMenuItem = new javax.swing.JMenuItem();
|
---|
| 127 | newMultilateralTournamentMenuItem = new javax.swing.JMenuItem();
|
---|
| 128 |
|
---|
| 129 | JMenu helpMenu = new javax.swing.JMenu();
|
---|
| 130 | manualMenuItem = new javax.swing.JMenuItem();
|
---|
| 131 | classDocumentationMenuItem = new javax.swing.JMenuItem();
|
---|
| 132 | aboutMenuItem = new javax.swing.JMenuItem();
|
---|
| 133 |
|
---|
| 134 | mainPanel.setName("mainPanel"); // NOI18N
|
---|
| 135 |
|
---|
| 136 | jSplitPane1.setName("jSplitPane1"); // NOI18N
|
---|
| 137 |
|
---|
| 138 | jPanel1.setName("jPanel1"); // NOI18N
|
---|
| 139 |
|
---|
| 140 | jTabbedPane1.setName("jTabbedPane1"); // NOI18N
|
---|
| 141 |
|
---|
| 142 | jScrollPane2.setName("jScrollPane2"); // NOI18N
|
---|
| 143 |
|
---|
| 144 | treeDomains.setMinimumSize(new java.awt.Dimension(100, 100));
|
---|
| 145 | treeDomains.setName("treeDomains"); // NOI18N
|
---|
| 146 | treeDomains.addMouseListener(new java.awt.event.MouseAdapter() {
|
---|
| 147 | public void mouseClicked(java.awt.event.MouseEvent evt) {
|
---|
| 148 | treeDomainsMouseClicked(evt);
|
---|
| 149 | }
|
---|
| 150 | });
|
---|
| 151 | jScrollPane2.setViewportView(treeDomains);
|
---|
| 152 |
|
---|
| 153 | org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance()
|
---|
| 154 | .getContext().getResourceMap(NegoGUIView.class);
|
---|
| 155 | jTabbedPane1.addTab(resourceMap.getString("jScrollPane2.TabConstraints.tabTitle"), jScrollPane2); // NOI18N
|
---|
| 156 |
|
---|
| 157 | org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
|
---|
| 158 | jPanel1.setLayout(jPanel1Layout);
|
---|
| 159 | jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
| 160 | .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE));
|
---|
| 161 | jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
| 162 | .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49, Short.MAX_VALUE));
|
---|
| 163 |
|
---|
| 164 | jSplitPane1.setLeftComponent(jPanel1);
|
---|
| 165 |
|
---|
| 166 | jScrollPane3.setViewportView(tableBOAcomponents);
|
---|
| 167 | jTabbedPane1.addTab("BOA components", jScrollPane3);
|
---|
| 168 |
|
---|
| 169 | closeTabbedPane1.setName("closeTabbedPane1"); // NOI18N
|
---|
| 170 | jSplitPane1.setRightComponent(closeTabbedPane1);
|
---|
| 171 |
|
---|
| 172 | org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
|
---|
| 173 | mainPanel.setLayout(mainPanelLayout);
|
---|
| 174 | mainPanelLayout.setHorizontalGroup(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
| 175 | .add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1,
|
---|
| 176 | org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 605, Short.MAX_VALUE)
|
---|
| 177 |
|
---|
| 178 | );
|
---|
| 179 | mainPanelLayout.setVerticalGroup(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
| 180 | .add(org.jdesktop.layout.GroupLayout.TRAILING,
|
---|
| 181 | mainPanelLayout.createSequentialGroup().add(jSplitPane1,
|
---|
| 182 | org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 665, Short.MAX_VALUE))
|
---|
| 183 | .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
---|
| 184 | .add(mainPanelLayout.createSequentialGroup())));
|
---|
| 185 |
|
---|
| 186 | menuBar.setName("menuBar"); // NOI18N
|
---|
| 187 |
|
---|
| 188 | startMenu.setText("Start");
|
---|
| 189 | startMenu.setName("startMenu"); // NOI18N
|
---|
| 190 |
|
---|
| 191 | javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext()
|
---|
| 192 | .getActionMap(NegoGUIView.class, this);
|
---|
| 193 |
|
---|
| 194 | // Add a new menu item for multi-agent negotiation tournament
|
---|
| 195 | newMultilateralTournamentMenuItem.setAction(actionMap.get("newMultiAgentTournamentTab")); // NOI18N
|
---|
| 196 | newMultilateralTournamentMenuItem.setName("newMultilateralMenuItem"); // NOI18N
|
---|
| 197 | startMenu.add(newMultilateralTournamentMenuItem);
|
---|
| 198 |
|
---|
| 199 | newMultilateralMenuItem.setAction(actionMap.get("newMultiNegoSession")); // NOI18N
|
---|
| 200 | newMultilateralMenuItem.setName("newMultilateralMenuItem"); // NOI18N
|
---|
| 201 | startMenu.add(newMultilateralMenuItem);
|
---|
| 202 |
|
---|
| 203 | menuBar.add(startMenu);
|
---|
| 204 | menuBar.add(helpMenu);
|
---|
| 205 |
|
---|
| 206 | helpMenu.setText(resourceMap.getString("helpMenu.text"));
|
---|
| 207 |
|
---|
| 208 | manualMenuItem.setAction(actionMap.get("openManual")); // NOI18N
|
---|
| 209 | helpMenu.add(manualMenuItem);
|
---|
| 210 |
|
---|
| 211 | classDocumentationMenuItem.setAction(actionMap.get("openDocumentation")); // NOI18N
|
---|
| 212 | helpMenu.add(classDocumentationMenuItem);
|
---|
| 213 |
|
---|
| 214 | aboutMenuItem.setAction(actionMap.get("openAbout")); // NOI18N
|
---|
| 215 | helpMenu.add(aboutMenuItem);
|
---|
| 216 |
|
---|
| 217 | setComponent(mainPanel);
|
---|
| 218 | setMenuBar(menuBar);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | private void treeDomainsMouseClicked(java.awt.event.MouseEvent evt) {
|
---|
| 222 | int selRow = treeDomains.getRowForLocation(evt.getX(), evt.getY());
|
---|
| 223 | TreePath selPath = treeDomains.getPathForLocation(evt.getX(), evt.getY());
|
---|
| 224 | if (selRow != -1) {
|
---|
| 225 | if (evt.getClickCount() == 2) {
|
---|
| 226 | if (selPath != null) {
|
---|
| 227 | MyTreeNode node = (MyTreeNode) (selPath.getLastPathComponent());
|
---|
| 228 | RepItem repItem = node.getRepositoryItem();
|
---|
| 229 | showRepositoryItemInTab(repItem, node);
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | public void showRepositoryItemInTab(RepItem repItem, MyTreeNode node) {
|
---|
| 236 | TreeFrame tf;
|
---|
| 237 | if (repItem instanceof DomainRepItem) {
|
---|
| 238 | try {
|
---|
| 239 | boolean hasNoProfiles = ((DomainRepItem) repItem).getProfiles().size() == 0;
|
---|
| 240 | String filename = ((DomainRepItem) repItem).getURL().getFile();
|
---|
| 241 | DomainImpl domain = new DomainImpl(filename);
|
---|
| 242 | tf = new TreeFrame(domain, hasNoProfiles);
|
---|
| 243 | addTab(StripExtension(GetPlainFileName(filename)), tf);
|
---|
| 244 | } catch (Exception e) {
|
---|
| 245 | e.printStackTrace();
|
---|
| 246 | }
|
---|
| 247 | } else if (repItem instanceof ProfileRepItem) {
|
---|
| 248 | try {
|
---|
| 249 | MyTreeNode parentNode = (MyTreeNode) (node.getParent());
|
---|
| 250 | String filename = ((ProfileRepItem) repItem).getURL().getFile();
|
---|
| 251 |
|
---|
| 252 | DomainImpl domain = new DomainImpl(
|
---|
| 253 | ((DomainRepItem) (parentNode.getRepositoryItem())).getURL().getFile());
|
---|
| 254 |
|
---|
| 255 | // we can handle only AdditiveUtilitySpace in TreeFrame anyway
|
---|
| 256 | // so we guess it's that...
|
---|
| 257 | AdditiveUtilitySpace utilitySpace = new AdditiveUtilitySpace(domain, filename);
|
---|
| 258 |
|
---|
| 259 | tf = new TreeFrame(domain, utilitySpace);
|
---|
| 260 | addTab(StripExtension(GetPlainFileName(filename)), tf);
|
---|
| 261 | } catch (Exception e) {
|
---|
| 262 | e.printStackTrace();
|
---|
| 263 |
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | /**
|
---|
| 269 | * Adds a tab to the GUI's start-menu for opening a multi-agent negotiation
|
---|
| 270 | * tab.
|
---|
| 271 | */
|
---|
| 272 | @Action
|
---|
| 273 | public void newMultiAgentTournamentTab() {
|
---|
| 274 | try {
|
---|
| 275 | addTab("Tournament", new MultiTournamentPanel());
|
---|
| 276 | } catch (Exception e) {
|
---|
| 277 | e.printStackTrace();
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | @Action
|
---|
| 282 | public void newMultiNegoSession() {
|
---|
| 283 | try {
|
---|
| 284 | addTab("Session", new SessionPanel());
|
---|
| 285 | } catch (Exception e) {
|
---|
| 286 | e.printStackTrace();
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | @Action
|
---|
| 291 | public void openManual() {
|
---|
| 292 | if (Desktop.isDesktopSupported()) {
|
---|
| 293 | try {
|
---|
| 294 | File myFile = new File("doc/userguide.pdf");
|
---|
| 295 | Desktop.getDesktop().open(myFile);
|
---|
| 296 | } catch (IOException ex) {
|
---|
| 297 | JOptionPane.showMessageDialog(this.getComponent(), "There is no program registered to open PDF files.");
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | @Action
|
---|
| 303 | public void openDocumentation() {
|
---|
| 304 | if (Desktop.isDesktopSupported()) {
|
---|
| 305 | try {
|
---|
| 306 | File myFile = new File("javadoc/index.html");
|
---|
| 307 | Desktop.getDesktop().open(myFile);
|
---|
| 308 | } catch (IOException ex) {
|
---|
| 309 | JOptionPane.showMessageDialog(this.getComponent(),
|
---|
| 310 | "There is no program registered to open HTML files.");
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | @Action
|
---|
| 316 | public void openAbout() {
|
---|
| 317 | About about = new About();
|
---|
| 318 | about.setVisible(true);
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | public CloseTabbedPane getMainTabbedPane() {
|
---|
| 322 | return closeTabbedPane1;
|
---|
| 323 | }
|
---|
| 324 | }
|
---|