1 /* Copyright (C) 2002-2012 The JSpecView Development Team 2 * 3 * Contact: robert.lancashire@uwimona.edu.jm 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 // CHANGES to 'mainFrame.java' - Main Application GUI 21 // University of the West Indies, Mona Campus 22 // 23 // 20-06-2005 kab - Implemented exporting JPG and PNG image files from the application 24 // - Need to sort out JSpecViewFileFilters for Save dialog to include image file extensions 25 // 21-06-2005 kab - Adjusted export to not prompt for spectrum when exporting JPG/PNG 26 // 24-06-2005 rjl - Added JPG, PNG file filters to dialog 27 // 30-09-2005 kab - Added command-line support 28 // 30-09-2005 kab - Implementing Drag and Drop interface (new class) 29 // 10-03-2006 rjl - Added Locale overwrite to allow decimal points to be recognised correctly in Europe 30 // 25-06-2007 rjl - Close file now checks to see if any remaining files still open 31 // - if not, then remove a number of menu options 32 // 05-07-2007 cw - check menu options when changing the focus of panels 33 // 06-07-2007 rjl - close imported file closes spectrum and source and updates directory tree 34 // 06-11-2007 rjl - bug in reading displayschemes if folder name has a space in it 35 // use a default scheme if the file can't be found or read properly, 36 // but there will still be a problem if an attempt is made to 37 // write out a new scheme under these circumstances! 38 // 23-07-2011 jak - altered code to support drawing scales and units separately 39 // 21-02-2012 rmh - lots of additions - integrated into Jmol 40 41 package jspecview.application; 42 43 import java.awt.event.ActionEvent; 44 import java.awt.event.ActionListener; 45 import java.awt.event.InputEvent; 46 import java.awt.event.ItemEvent; 47 import java.awt.event.ItemListener; 48 import java.util.EventListener; 49 50 import javajs.util.Lst; 51 52 import javax.swing.JCheckBoxMenuItem; 53 import javax.swing.JComponent; 54 import javax.swing.JMenu; 55 import javax.swing.JMenuBar; 56 import javax.swing.JMenuItem; 57 import javax.swing.event.MenuEvent; 58 import javax.swing.event.MenuListener; 59 60 61 import jspecview.api.JSVPanel; 62 import jspecview.common.Spectrum; 63 import jspecview.common.JSVFileManager; 64 import jspecview.common.PanelNode; 65 import jspecview.common.JSViewer; 66 import jspecview.common.PanelData; 67 import jspecview.common.ScriptToken; 68 import jspecview.source.JDXSource; 69 70 /** 71 * The Main Class or Entry point of the JSpecView Application. 72 * 73 * @author Debbie-Ann Facey 74 * @author Khari A. Bryan 75 * @author Prof Robert J. Lancashire 76 */ 77 public class ApplicationMenu extends JMenuBar { 78 79 private static final long serialVersionUID = 1L; 80 protected MainFrame mainFrame; 81 protected JSViewer viewer; 82 ApplicationMenu(MainFrame si)83 public ApplicationMenu(MainFrame si) throws Exception { 84 this.mainFrame = si; 85 viewer = si.vwr; 86 jbInit(); 87 } 88 89 // the only really necessary as fields: 90 private JMenu processingMenu; 91 private JMenu displayMenu; 92 private JMenu exportAsMenu; 93 private JMenu openRecentMenu; 94 private JMenu saveAsMenu; 95 private JMenu saveAsJDXMenu; 96 97 private JMenuItem closeMenuItem; 98 private JMenuItem closeAllMenuItem; 99 private JMenuItem errorLogMenuItem; 100 private JMenuItem printMenuItem; 101 private JMenuItem sourceMenuItem; 102 private JMenuItem integrationMenuItem; 103 private JMenuItem overlayKeyMenuItem; 104 private JMenuItem transmittanceMenuItem; 105 private JMenuItem solutionColorMenuItem; 106 107 private JCheckBoxMenuItem gridCheckBoxMenuItem = new JCheckBoxMenuItem(); 108 private JCheckBoxMenuItem coordsCheckBoxMenuItem = new JCheckBoxMenuItem(); 109 private JCheckBoxMenuItem pointsOnlyCheckBoxMenuItem = new JCheckBoxMenuItem(); 110 private JCheckBoxMenuItem revPlotCheckBoxMenuItem = new JCheckBoxMenuItem(); 111 private JCheckBoxMenuItem scaleXCheckBoxMenuItem = new JCheckBoxMenuItem(); 112 private JCheckBoxMenuItem scaleYCheckBoxMenuItem = new JCheckBoxMenuItem(); 113 private JCheckBoxMenuItem toolbarCheckBoxMenuItem = new JCheckBoxMenuItem(); 114 private JCheckBoxMenuItem sidePanelCheckBoxMenuItem = new JCheckBoxMenuItem(); 115 private JCheckBoxMenuItem statusCheckBoxMenuItem = new JCheckBoxMenuItem(); 116 117 118 /** 119 * Initializes GUI components 120 * 121 * @throws Exception 122 */ jbInit()123 private void jbInit() throws Exception { 124 125 JMenuItem openFileMenuItem = setMenuItem(null, 'F', "Add File...", 70, 126 InputEvent.CTRL_MASK, new ActionListener() { 127 @Override 128 public void actionPerformed(ActionEvent e) { 129 viewer.openFileFromDialog(true, false, null, null); 130 } 131 }); 132 JMenuItem openSimulationH1MenuItem = setMenuItem(null, 'H', "Add H1 Simulation...", 72, 133 InputEvent.CTRL_MASK, new ActionListener() { 134 @Override 135 public void actionPerformed(ActionEvent e) { 136 viewer.openFileFromDialog(true, false, "H1", null); 137 } 138 }); 139 JMenuItem openSimulationC13MenuItem = setMenuItem(null, 'C', "Add C13 Simulation...", 67, 140 InputEvent.CTRL_MASK, new ActionListener() { 141 @Override 142 public void actionPerformed(ActionEvent e) { 143 viewer.openFileFromDialog(true, false, "C13", null); 144 } 145 }); 146 JMenuItem openURLMenuItem = setMenuItem(null, 'U', "Add URL...", 85, 147 InputEvent.CTRL_MASK, new ActionListener() { 148 @Override 149 public void actionPerformed(ActionEvent e) { 150 viewer.openFileFromDialog(true, true, null, null); 151 } 152 }); 153 154 printMenuItem = setMenuItem(null, 'P', "Print...", 80, 155 InputEvent.CTRL_MASK, new ActionListener() { 156 @Override 157 public void actionPerformed(ActionEvent e) { 158 viewer.runScript("print"); 159 } 160 }); 161 closeMenuItem = setMenuItem(null, 'C', "Close", 115, 162 InputEvent.CTRL_MASK, new ActionListener() { 163 @Override 164 public void actionPerformed(ActionEvent e) { 165 viewer.runScript("CLOSE"); 166 } 167 }); 168 closeAllMenuItem = setMenuItem(null, 'L', "Close All", 0, 169 InputEvent.CTRL_MASK, new ActionListener() { 170 @Override 171 public void actionPerformed(ActionEvent e) { 172 viewer.runScript("CLOSE ALL"); 173 } 174 }); 175 JMenuItem scriptMenuItem = setMenuItem(null, 'T', "Script...", 83, 176 InputEvent.ALT_MASK, new ActionListener() { 177 @Override 178 public void actionPerformed(ActionEvent e) { 179 viewer.runScript("script INLINE"); 180 } 181 }); 182 183 JMenuItem exitMenuItem = setMenuItem(null, 'X', "Exit", 115, 184 InputEvent.ALT_MASK, new ActionListener() { 185 @Override 186 public void actionPerformed(ActionEvent e) { 187 mainFrame.exitJSpecView(false); 188 } 189 }); 190 191 setMenuItem(gridCheckBoxMenuItem, 'G', "Grid", 71, 192 InputEvent.CTRL_MASK, new ItemListener() { 193 @Override 194 public void itemStateChanged(ItemEvent e) { 195 setBoolean(ScriptToken.GRIDON, e); 196 } 197 }); 198 setMenuItem(coordsCheckBoxMenuItem, 'C', "Coordinates", 199 67, InputEvent.CTRL_MASK, new ItemListener() { 200 @Override 201 public void itemStateChanged(ItemEvent e) { 202 setBoolean(ScriptToken.COORDINATESON, e); 203 } 204 }); 205 setMenuItem(pointsOnlyCheckBoxMenuItem, 'P', "Points Only", 206 80, InputEvent.CTRL_MASK, new ItemListener() { 207 @Override 208 public void itemStateChanged(ItemEvent e) { 209 setBoolean(ScriptToken.POINTSONLY, e); 210 } 211 }); 212 setMenuItem(revPlotCheckBoxMenuItem, 'R', "Reverse Plot", 213 82, InputEvent.CTRL_MASK, new ItemListener() { 214 @Override 215 public void itemStateChanged(ItemEvent e) { 216 setBoolean(ScriptToken.REVERSEPLOT, e); 217 } 218 }); 219 setMenuItem(scaleXCheckBoxMenuItem, 'X', "X Scale", 88, 220 InputEvent.CTRL_MASK, new ItemListener() { 221 @Override 222 public void itemStateChanged(ItemEvent e) { 223 setBoolean(ScriptToken.XSCALEON, e); 224 } 225 }); 226 setMenuItem(scaleYCheckBoxMenuItem, 'Y', "Y Scale", 89, 227 InputEvent.CTRL_MASK, new ItemListener() { 228 @Override 229 public void itemStateChanged(ItemEvent e) { 230 setBoolean(ScriptToken.YSCALEON, e); 231 } 232 }); 233 JMenuItem nextZoomMenuItem = setMenuItem(null, 'N', "Next View", 78, 234 InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, new ActionListener() { 235 @Override 236 public void actionPerformed(ActionEvent e) { 237 viewer.runScript("zoom next"); 238 } 239 }); 240 JMenuItem prevZoomMenuItem = setMenuItem(null, 'P', "Previous View", 80, 241 InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, new ActionListener() { 242 @Override 243 public void actionPerformed(ActionEvent e) { 244 viewer.runScript("zoom previous"); 245 } 246 }); 247 JMenuItem fullZoomMenuItem = setMenuItem(null, 'F', "Full View", 70, 248 InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, new ActionListener() { 249 @Override 250 public void actionPerformed(ActionEvent e) { 251 viewer.runScript("zoom out"); 252 } 253 }); 254 JMenuItem clearZoomMenuItem = setMenuItem(null, 'C', "Clear Views", 67, 255 InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, new ActionListener() { 256 @Override 257 public void actionPerformed(ActionEvent e) { 258 viewer.runScript("zoom clear"); 259 } 260 }); 261 JMenuItem userZoomMenuItem = setMenuItem(null, 'Z', "Set Zoom...", 90, 262 InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, new ActionListener() { 263 @Override 264 public void actionPerformed(ActionEvent e) { 265 viewer.runScript("zoom ?"); 266 } 267 }); 268 JMenuItem viewAllMenuItem = setMenuItem(null, 'A', "All Spectra", 65, 269 InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, new ActionListener() { 270 @Override 271 public void actionPerformed(ActionEvent e) { 272 viewer.runScript("view all"); 273 } 274 }); 275 JMenuItem spectraMenuItem = setMenuItem(null, 'S', "Selected Spectra...", 83, 276 InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, new ActionListener() { 277 @Override 278 public void actionPerformed(ActionEvent e) { 279 viewer.runScript("view"); 280 } 281 }); 282 JMenuItem overlayStackOffsetYMenuItem = setMenuItem(null, 'y', "Overlay Offset...", 0, 283 0, new ActionListener() { 284 @Override 285 public void actionPerformed(ActionEvent e) { 286 viewer.runScript("stackOffsetY ?"); 287 } 288 }); 289 sourceMenuItem = setMenuItem(null, 'S', "Source ...", 83, 290 InputEvent.CTRL_MASK, new ActionListener() { 291 @Override 292 public void actionPerformed(ActionEvent e) { 293 viewer.runScript("showSource"); 294 } 295 }); 296 errorLogMenuItem = setMenuItem(null, '\0', "Error Log ...", 0, 297 0, new ActionListener() { 298 @Override 299 public void actionPerformed(ActionEvent e) { 300 viewer.runScript("showErrors"); 301 } 302 }); 303 304 305 JMenuItem propertiesMenuItem = setMenuItem(null, 'P', "Properties", 72, 306 InputEvent.CTRL_MASK, new ActionListener() { 307 @Override 308 public void actionPerformed(ActionEvent e) { 309 viewer.runScript("showProperties"); 310 } 311 }); 312 overlayKeyMenuItem = setMenuItem(null, '\0', "Overlay Key", 0, 313 0, new ActionListener() { 314 @Override 315 public void actionPerformed(ActionEvent e) { 316 viewer.runScript("showKey toggle"); 317 } 318 }); 319 320 JMenuItem preferencesMenuItem = setMenuItem(null, 'P', "Preferences...", 321 0, 0, new ActionListener() { 322 @Override 323 public void actionPerformed(ActionEvent e) { 324 showPreferencesDialog(); 325 } 326 }); 327 JMenuItem aboutMenuItem = setMenuItem(null, '\0', "About", 0, 0, 328 new ActionListener() { 329 @Override 330 public void actionPerformed(ActionEvent e) { 331 new AboutDialog(mainFrame); 332 } 333 }); 334 setMenuItem(toolbarCheckBoxMenuItem, 'T', "Toolbar", 84, 335 InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, new ItemListener() { 336 @Override 337 public void itemStateChanged(ItemEvent e) { 338 mainFrame.enableToolbar(e.getStateChange() == ItemEvent.SELECTED); 339 } 340 }); 341 342 setMenuItem(sidePanelCheckBoxMenuItem, 'S', "Side Panel", 343 83, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, new ItemListener() { 344 @Override 345 public void itemStateChanged(ItemEvent e) { 346 mainFrame.setSplitPane(e.getStateChange() == ItemEvent.SELECTED); 347 } 348 }); 349 350 setMenuItem(statusCheckBoxMenuItem, 'B', "Status Bar", 351 66, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, new ItemListener() { 352 @Override 353 public void itemStateChanged(ItemEvent e) { 354 mainFrame.enableStatus(e.getStateChange() == ItemEvent.SELECTED); 355 } 356 }); 357 358 JMenu fileMenu = new JMenu(); 359 fileMenu.setMnemonic('F'); 360 fileMenu.setText("File"); 361 362 JMenu helpMenu = new JMenu(); 363 helpMenu.setMnemonic('H'); 364 helpMenu.setText("Help"); 365 366 JMenu optionsMenu = new JMenu(); 367 optionsMenu.setMnemonic('O'); 368 optionsMenu.setText("Options"); 369 370 displayMenu = new JMenu(); 371 displayMenu.setMnemonic('D'); 372 displayMenu.setText("Display"); 373 displayMenu.addMenuListener(new MenuListener() { 374 @Override 375 public void menuSelected(MenuEvent e) { 376 doMenuSelected(); 377 } 378 379 @Override 380 public void menuDeselected(MenuEvent e) { 381 } 382 383 @Override 384 public void menuCanceled(MenuEvent e) { 385 } 386 }); 387 388 JMenu zoomMenu = new JMenu(); 389 zoomMenu.setMnemonic('Z'); 390 zoomMenu.setText("Zoom"); 391 392 openRecentMenu = new JMenu(); 393 openRecentMenu.setActionCommand("OpenRecent"); 394 openRecentMenu.setMnemonic('R'); 395 openRecentMenu.setText("Add Recent"); 396 397 saveAsMenu = new JMenu(); 398 saveAsMenu.setMnemonic('A'); 399 400 saveAsJDXMenu = new JMenu(); 401 saveAsJDXMenu.setMnemonic('J'); 402 403 exportAsMenu = new JMenu(); 404 exportAsMenu.setMnemonic('E'); 405 406 processingMenu = new JMenu(); 407 processingMenu.setMnemonic('P'); 408 processingMenu.setText("Processing"); 409 processingMenu.addMenuListener(new MenuListener() { 410 @Override 411 public void menuSelected(MenuEvent e) { 412 //jsvpPopupMenu.setEnables(mainFrame.viewer.selectedPanel); 413 } 414 415 @Override 416 public void menuDeselected(MenuEvent e) { 417 } 418 419 @Override 420 public void menuCanceled(MenuEvent e) { 421 } 422 }); 423 setProcessingMenu(processingMenu); 424 425 fileMenu.add(openFileMenuItem); 426 fileMenu.add(openSimulationH1MenuItem); 427 fileMenu.add(openSimulationC13MenuItem); 428 fileMenu.add(openURLMenuItem); 429 fileMenu.add(openRecentMenu); 430 // application does not need append 431 fileMenu.addSeparator(); 432 fileMenu.add(closeMenuItem).setEnabled(false); 433 fileMenu.add(closeAllMenuItem).setEnabled(false); 434 fileMenu.addSeparator(); 435 fileMenu.add(scriptMenuItem); 436 fileMenu.addSeparator(); 437 fileMenu.add(saveAsMenu).setEnabled(false); 438 fileMenu.add(exportAsMenu).setEnabled(false); 439 fileMenu.addSeparator(); 440 fileMenu.add(printMenuItem).setEnabled(false); 441 fileMenu.addSeparator(); 442 fileMenu.add(exitMenuItem); 443 displayMenu.add(viewAllMenuItem); 444 displayMenu.add(spectraMenuItem); 445 displayMenu.add(overlayStackOffsetYMenuItem); 446 displayMenu.add(overlayKeyMenuItem).setEnabled(false); 447 displayMenu.addSeparator(); 448 displayMenu.add(gridCheckBoxMenuItem); 449 displayMenu.add(coordsCheckBoxMenuItem); 450 displayMenu.add(scaleXCheckBoxMenuItem); 451 displayMenu.add(scaleYCheckBoxMenuItem); 452 displayMenu.add(revPlotCheckBoxMenuItem); 453 displayMenu.add(pointsOnlyCheckBoxMenuItem); 454 displayMenu.addSeparator(); 455 displayMenu.add(zoomMenu); 456 displayMenu.addSeparator(); 457 displayMenu.add(sourceMenuItem).setEnabled(false); 458 displayMenu.add(errorLogMenuItem).setEnabled(false); 459 displayMenu.add(propertiesMenuItem); 460 zoomMenu.add(nextZoomMenuItem); 461 zoomMenu.add(prevZoomMenuItem); 462 zoomMenu.add(fullZoomMenuItem); 463 zoomMenu.add(clearZoomMenuItem); 464 zoomMenu.add(userZoomMenuItem); 465 optionsMenu.add(preferencesMenuItem); 466 optionsMenu.addSeparator(); 467 optionsMenu.add(toolbarCheckBoxMenuItem); 468 optionsMenu.add(sidePanelCheckBoxMenuItem); 469 optionsMenu.add(statusCheckBoxMenuItem); 470 helpMenu.add(aboutMenuItem); 471 472 add(fileMenu); 473 add(displayMenu).setEnabled(false); 474 add(optionsMenu); 475 add(processingMenu).setEnabled(false); 476 add(helpMenu); 477 478 setMenus(saveAsMenu, saveAsJDXMenu, exportAsMenu, 479 (new ActionListener() { 480 @Override 481 public void actionPerformed(ActionEvent e) { 482 mainFrame.exportSpectrumViaMenu(e.getActionCommand()); 483 } 484 })); 485 486 toolbarCheckBoxMenuItem.setSelected(true); 487 sidePanelCheckBoxMenuItem.setSelected(true); 488 statusCheckBoxMenuItem.setSelected(true); 489 490 } 491 doMenuSelected()492 protected void doMenuSelected() { 493 PanelData pd = mainFrame.vwr.pd(); 494 gridCheckBoxMenuItem.setSelected(pd != null && pd.getBoolean(ScriptToken.GRIDON)); 495 coordsCheckBoxMenuItem.setSelected(pd != null && pd.getBoolean(ScriptToken.COORDINATESON)); 496 pointsOnlyCheckBoxMenuItem.setSelected(pd != null && pd.getBoolean(ScriptToken.POINTSONLY)); 497 revPlotCheckBoxMenuItem.setSelected(pd != null && pd.getBoolean(ScriptToken.REVERSEPLOT)); 498 } 499 setProcessingMenu(JComponent menu)500 public void setProcessingMenu(JComponent menu) { 501 menu.add(integrationMenuItem = setMenuItem(null, 'I', "Integration", 0, 0, 502 new ActionListener() { 503 @Override 504 public void actionPerformed(ActionEvent e) { 505 viewer.runScript("showIntegration"); 506 } 507 })); 508 menu.add(setMenuItem(null, 'M', "Measurements", 0, 0, 509 new ActionListener() { 510 @Override 511 public void actionPerformed(ActionEvent e) { 512 viewer.runScript("showMeasurements"); 513 } 514 })); 515 menu.add(setMenuItem(null, 'P', "Peaks", 0, 0, 516 new ActionListener() { 517 @Override 518 public void actionPerformed(ActionEvent e) { 519 viewer.runScript("showPeakList"); 520 } 521 })); 522 menu.add(transmittanceMenuItem = setMenuItem(null, '\0', "Transmittance/Absorbance", 0, 0, 523 new ActionListener() { 524 @Override 525 public void actionPerformed(ActionEvent e) { 526 viewer.runScript("IRMODE IMPLIED"); 527 } 528 })); 529 menu.add(solutionColorMenuItem = setMenuItem(null, 'C', "Predicted Solution Colour", 0, 0, 530 new ActionListener() { 531 @Override 532 public void actionPerformed(ActionEvent e) { 533 viewer.runScript("GETSOLUTIONCOLOR"); 534 } 535 })); 536 } 537 setBoolean(ScriptToken st, ItemEvent e)538 protected void setBoolean(ScriptToken st, ItemEvent e) { 539 boolean isOn = (e.getStateChange() == ItemEvent.SELECTED); 540 viewer.runScript(st + " " + isOn); 541 } 542 setSourceEnabled(boolean b)543 public void setSourceEnabled(boolean b) { 544 closeAllMenuItem.setEnabled(b); 545 displayMenu.setEnabled(b); 546 processingMenu.setEnabled(b); 547 exportAsMenu.setEnabled(b); 548 saveAsMenu.setEnabled(b); 549 550 printMenuItem.setEnabled(b); 551 sourceMenuItem.setEnabled(b); 552 errorLogMenuItem.setEnabled(b); 553 } 554 setCloseMenuItem(String fileName)555 void setCloseMenuItem(String fileName) { 556 closeMenuItem.setEnabled(fileName != null); 557 closeMenuItem.setText(fileName == null ? "Close" : "Close " + fileName); 558 } 559 560 /** 561 * @param isError 562 * @param isWarningOnly 563 */ setError(boolean isError, boolean isWarningOnly)564 void setError(boolean isError, boolean isWarningOnly) { 565 errorLogMenuItem.setEnabled(isError); 566 } 567 setMenuEnables(PanelNode node)568 public void setMenuEnables(PanelNode node) { 569 if (node == null) { 570 setCloseMenuItem(null); 571 setSourceEnabled(false); 572 } else { 573 setSourceEnabled(true); 574 PanelData pd = node.pd(); 575 Spectrum spec = pd.getSpectrum(); 576 setCheckBoxes(pd); 577 overlayKeyMenuItem.setEnabled(pd.getNumberOfGraphSets() > 1); 578 setCloseMenuItem(JSVFileManager.getTagName(node.source.getFilePath())); 579 exportAsMenu.setEnabled(true); 580 saveAsMenu.setEnabled(true); 581 saveAsJDXMenu.setEnabled(spec.canSaveAsJDX()); 582 integrationMenuItem.setEnabled(spec.canIntegrate()); 583 transmittanceMenuItem.setEnabled(spec.isAbsorbance() || spec.isTransmittance()); 584 solutionColorMenuItem.setEnabled(spec.canShowSolutionColor()); 585 } 586 587 } 588 toggleOverlayKeyMenuItem()589 public boolean toggleOverlayKeyMenuItem() { 590 overlayKeyMenuItem.setSelected(overlayKeyMenuItem.isSelected()); 591 return overlayKeyMenuItem.isSelected(); 592 } 593 594 ////////// MENU ACTIONS /////////// 595 596 /** 597 * Shows the preferences dialog 598 * 599 */ showPreferencesDialog()600 void showPreferencesDialog() { 601 mainFrame.showPreferences(); 602 } 603 setSelections(boolean sidePanelOn, boolean toolbarOn, boolean statusbarOn, JSVPanel jsvp)604 public void setSelections(boolean sidePanelOn, boolean toolbarOn, 605 boolean statusbarOn, JSVPanel jsvp) { 606 // hide side panel if sidePanelOn property is false 607 sidePanelCheckBoxMenuItem.setSelected(sidePanelOn); 608 toolbarCheckBoxMenuItem.setSelected(toolbarOn); 609 statusCheckBoxMenuItem.setSelected(statusbarOn); 610 if (jsvp != null) 611 setCheckBoxes(jsvp.getPanelData()); 612 } 613 setCheckBoxes(PanelData pd)614 private void setCheckBoxes(PanelData pd) { 615 gridCheckBoxMenuItem.setSelected(pd.getBoolean(ScriptToken.GRIDON)); 616 coordsCheckBoxMenuItem.setSelected(pd.getBoolean(ScriptToken.COORDINATESON)); 617 revPlotCheckBoxMenuItem.setSelected(pd.getBoolean(ScriptToken.REVERSEPLOT)); 618 scaleXCheckBoxMenuItem.setSelected(pd.getBoolean(ScriptToken.XSCALEON)); 619 scaleYCheckBoxMenuItem.setSelected(pd.getBoolean(ScriptToken.YSCALEON)); 620 } 621 setRecentMenu(Lst<String> recentFilePaths)622 public void setRecentMenu(Lst<String> recentFilePaths) { 623 openRecentMenu.removeAll(); 624 for (int i = 0; i < recentFilePaths.size(); i++) { 625 String path = recentFilePaths.get(i); 626 JMenuItem menuItem; 627 menuItem = new JMenuItem(path); 628 openRecentMenu.add(menuItem); 629 menuItem.addActionListener(new ActionListener() { 630 @Override 631 public void actionPerformed(ActionEvent e) { 632 viewer.openFile(((JMenuItem) e.getSource()).getText(), false); 633 } 634 }); 635 } 636 } 637 updateRecentMenus(Lst<String> recentFilePaths)638 public void updateRecentMenus(Lst<String> recentFilePaths) { 639 JMenuItem menuItem; 640 openRecentMenu.removeAll(); 641 for (int i = 0; i < recentFilePaths.size(); i++) { 642 String path = recentFilePaths.get(i); 643 menuItem = new JMenuItem(path); 644 openRecentMenu.add(menuItem); 645 menuItem.addActionListener(new ActionListener() { 646 @Override 647 public void actionPerformed(ActionEvent e) { 648 viewer.openFile(((JMenuItem) e.getSource()).getText(), true); 649 } 650 }); 651 } 652 } 653 clearSourceMenu(JDXSource source)654 public void clearSourceMenu(JDXSource source) { 655 if (source == null) { 656 setMenuEnables(null); 657 } else { 658 saveAsJDXMenu.setEnabled(true); 659 saveAsMenu.setEnabled(true); 660 } 661 //setCloseMenuItem(null); 662 663 } 664 addMenuItem(JMenu m, String key, char keyChar, ActionListener actionListener)665 public static void addMenuItem(JMenu m, String key, char keyChar, 666 ActionListener actionListener) { 667 JMenuItem jmi = new JMenuItem(); 668 jmi.setMnemonic(keyChar == '\0' ? key.charAt(0) : keyChar); 669 jmi.setText(key); 670 jmi.addActionListener(actionListener); 671 m.add(jmi); 672 } 673 setMenus(JMenu saveAsMenu, JMenu saveAsJDXMenu, JMenu exportAsMenu, ActionListener actionListener)674 public static void setMenus(JMenu saveAsMenu, JMenu saveAsJDXMenu, 675 JMenu exportAsMenu, ActionListener actionListener) { 676 saveAsMenu.setText("Save As"); 677 addMenuItem(saveAsMenu, JSViewer.sourceLabel, '\0', actionListener); 678 saveAsJDXMenu.setText("JDX"); 679 addMenuItem(saveAsJDXMenu, "XY", '\0', actionListener); 680 addMenuItem(saveAsJDXMenu, "DIF", '\0', actionListener); 681 addMenuItem(saveAsJDXMenu, "DIFDUP", 'U', actionListener); 682 addMenuItem(saveAsJDXMenu, "FIX", '\0', actionListener); 683 addMenuItem(saveAsJDXMenu, "PAC", '\0', actionListener); 684 addMenuItem(saveAsJDXMenu, "SQZ", '\0', actionListener); 685 saveAsMenu.add(saveAsJDXMenu); 686 addMenuItem(saveAsMenu, "CML", '\0', actionListener); 687 addMenuItem(saveAsMenu, "XML (AnIML)", '\0', actionListener); 688 if (exportAsMenu != null) { 689 exportAsMenu.setText("Export As"); 690 addMenuItem(exportAsMenu, "JPG", '\0', actionListener); 691 addMenuItem(exportAsMenu, "PNG", 'N', actionListener); 692 addMenuItem(exportAsMenu, "SVG", '\0', actionListener); 693 addMenuItem(exportAsMenu, "PDF", '\0', actionListener); 694 } 695 } 696 setMenuItem(JMenuItem item, char c, String text, int accel, int mask, EventListener el)697 public static JMenuItem setMenuItem(JMenuItem item, char c, String text, 698 int accel, int mask, EventListener el) { 699 if (item == null) 700 item = new JMenuItem(); 701 if (c != '\0') 702 item.setMnemonic(c); 703 item.setText(text); 704 if (accel > 0) 705 item.setAccelerator(javax.swing.KeyStroke.getKeyStroke(accel, 706 mask, false)); 707 if (el instanceof ActionListener) 708 item.addActionListener((ActionListener) el); 709 else if (el instanceof ItemListener) 710 item.addItemListener((ItemListener) el); 711 return item; 712 } 713 714 715 } 716