public DescPropPopup() { super("Descriptor Properties"); v = new JCheckBoxMenuItem("Valid"); v.addActionListener(new ValidAction()); p = new JCheckBoxMenuItem("Propagating"); p.addActionListener(new PropAction()); delete = new JMenuItem("Delete"); delete.addActionListener(new DeleteAction()); duplicate = new JMenuItem("Duplicate"); duplicate.addActionListener(new DuplicateAction()); interp = new JMenuItem("Interpolate..."); interp.addActionListener(new InterpAction()); interpToMark = new JMenu("Interpolate to Mark"); interpToMark.setEnabled(false); itmAction = new InterpToMarkAction(); shift = new JMenuItem("Shift..."); shift.addActionListener(new ShiftAction()); shiftToMark = new JMenu("Shift to Mark"); shiftToMark.setEnabled(false); stmAction = new ShiftToMarkAction(); occlusions = new JMenuItem("Occlusions..."); occAction = new OccAction(); occlusions.addActionListener(occAction); occSeparator = new JSeparator(); wrt = new JCheckBoxMenuItem("Display with Respect To", false); wrt.addActionListener(new WithRespectToAction()); add(occlusions); add(occSeparator); add(v); add(p); add(occSeparator); add(delete); add(duplicate); add(occSeparator); add(interp); add(interpToMark); add(occSeparator); add(shift); add(shiftToMark); add(occSeparator); add(wrt); }
public void show(Component invoker, int x, int y) { ViperViewMediator mediator = getMediator(); Point pnt = new Point(x, y); EnhancedTable tab = getTable(); int row = tab.rowAtPoint(pnt); desc = getCurrentModel().getDescriptorAtRow(row); int col = tab.columnAtPoint(pnt); Object cellValue = tab.getValueAt(row, col); if (cellValue instanceof Attribute) { attr = (Attribute) cellValue; // hide the "Occlusions..." option when we're not dealing with a Textline object boolean isTextline = attr.getAttrConfig().getAttrType().endsWith("textline"); occlusions.setVisible(isTextline); occSeparator.setVisible(isTextline); Instant now = mediator.getCurrentFrame(); if (now == null) { mediator.getDisplayWRTManager().setAttribute(null, null); wrt.setEnabled(false); wrt.setSelected(false); } else { boolean isDwrt = attr == mediator.getDisplayWRTManager().getAttribute(); boolean dwrtable = (attr.getAttrValueAtInstant(now) instanceof HasCentroid && attr.getDescriptor().getValidRange().contains(now)); wrt.setEnabled(dwrtable); wrt.setSelected(isDwrt); } } else { attr = null; wrt.setEnabled(false); wrt.setSelected(false); } if (null != desc) { PropagateInterpolateModule proper = getMediator().getPropagator(); p.setSelected(proper.isPropagatingThis(desc)); v.setSelected(mediator.isThisValidNow(desc)); resetMarks(); super.show(invoker, x, y); } }
public static void makeMenuBar(JFrame frame, final AirspaceBuilderController controller) { JMenuBar menuBar = new JMenuBar(); final JCheckBoxMenuItem resizeNewShapesItem; final JCheckBoxMenuItem enableEditItem; JMenu menu = new JMenu("File"); { JMenuItem item = new JMenuItem("Open..."); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(OPEN); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Open URL..."); item.setActionCommand(OPEN_URL); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Save..."); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(SAVE); item.addActionListener(controller); menu.add(item); menu.addSeparator(); item = new JMenuItem("Load Demo Shapes"); item.setActionCommand(OPEN_DEMO_AIRSPACES); item.addActionListener(controller); menu.add(item); } menuBar.add(menu); menu = new JMenu("Shape"); { JMenu subMenu = new JMenu("New"); for (final AirspaceFactory factory : defaultAirspaceFactories) { JMenuItem item = new JMenuItem(factory.toString()); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.createNewEntry(factory); } }); subMenu.add(item); } menu.add(subMenu); resizeNewShapesItem = new JCheckBoxMenuItem("Fit new shapes to viewport"); resizeNewShapesItem.setActionCommand(SIZE_NEW_SHAPES_TO_VIEWPORT); resizeNewShapesItem.addActionListener(controller); resizeNewShapesItem.setState(controller.isResizeNewShapesToViewport()); menu.add(resizeNewShapesItem); enableEditItem = new JCheckBoxMenuItem("Enable shape editing"); enableEditItem.setActionCommand(ENABLE_EDIT); enableEditItem.addActionListener(controller); enableEditItem.setState(controller.isEnableEdit()); menu.add(enableEditItem); } menuBar.add(menu); menu = new JMenu("Selection"); { JMenuItem item = new JMenuItem("Deselect"); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(CLEAR_SELECTION); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Delete"); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); item.setActionCommand(REMOVE_SELECTED); item.addActionListener(controller); menu.add(item); } menuBar.add(menu); frame.setJMenuBar(menuBar); controller.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals((e.getPropertyName()))) { resizeNewShapesItem.setSelected(controller.isResizeNewShapesToViewport()); } else if (ENABLE_EDIT.equals(e.getPropertyName())) { enableEditItem.setSelected(controller.isEnableEdit()); } } }); }
/** * Set up the menu bar. * * @return The JMenuBar we set up. */ private JMenuBar setupMenuBar() { JMenuBar menuBar = new JMenuBar(); /* File */ JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); /* File -> Open CSV */ JMenuItem miFileOpenCSV = new JMenuItem( new AbstractAction("Open CSV") { @Override public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD); fd.setVisible(true); File file; if (fd.getDirectory() != null) { file = new File(fd.getDirectory(), fd.getFile()); } else if (fd.getFile() != null) { file = new File(fd.getFile()); } else { return; } // Clear out old file. loadFile(null); // SwingWorker MAGIC! new MainFrameWorker("loading file '" + file + "'", file) { @Override protected Object doInBackground() throws Exception { System.err.println("Loading file: " + input); loadFile((File) input, DarwinCSV.FILE_CSV_DELIMITED); return null; } }.execute(); } }); fileMenu.add(miFileOpenCSV); /* File -> Open CSV without UI */ JMenuItem miFileOpenCSVnoUI = new JMenuItem( new AbstractAction("Open CSV without UI") { @Override public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD); fd.setVisible(true); File file; if (fd.getDirectory() != null) { file = new File(fd.getDirectory(), fd.getFile()); } else if (fd.getFile() != null) { file = new File(fd.getFile()); } else { return; } // Clear out old file loadFile(null); loadFile(file, DarwinCSV.FILE_CSV_DELIMITED); } }); fileMenu.add(miFileOpenCSVnoUI); /* File -> Open tab-delimited */ JMenuItem miFileOpenTab = new JMenuItem( new AbstractAction("Open tab-delimited") { @Override public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog( mainFrame, "Open Darwin tab-delimited file ...", FileDialog.LOAD); fd.setVisible(true); File file; if (fd.getDirectory() != null) { file = new File(fd.getDirectory(), fd.getFile()); } else if (fd.getFile() != null) { file = new File(fd.getFile()); } else { return; } // Clear out old file loadFile(null); // SwingWorker MAGIC! new MainFrameWorker("loading file '" + file + "'", file) { @Override protected Object doInBackground() throws Exception { loadFile((File) input, DarwinCSV.FILE_TAB_DELIMITED); return null; } }.execute(); } }); fileMenu.add(miFileOpenTab); /* File -> Save CSV */ JMenuItem miFileSave = new JMenuItem( new AbstractAction("Save as CSV") { @Override public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(mainFrame, "Save Darwin CSV file ...", FileDialog.SAVE); fd.setVisible(true); File file; if (fd.getDirectory() != null) { file = new File(fd.getDirectory(), fd.getFile()); } else if (fd.getFile() != null) { file = new File(fd.getFile()); } else { return; } // SwingWorker MAGIC! new MainFrameWorker("saving CSV file '" + file + "'", file) { @Override protected Object doInBackground() throws Exception { currentCSV.saveToFile((File) input, DarwinCSV.FILE_CSV_DELIMITED); return null; } }.execute(); } }); fileMenu.add(miFileSave); /* File -> Exit */ JMenuItem miFileExit = new JMenuItem( new AbstractAction("Exit") { @Override public void actionPerformed(ActionEvent e) { mainFrame.setVisible(false); mainFrame.dispose(); } }); fileMenu.add(miFileExit); /* Match */ JMenu matchMenu = new JMenu("Match"); menuBar.add(matchMenu); /* Match -> Against CSV */ JMenuItem miMatchCSV = new JMenuItem( new AbstractAction("Match against CSV") { @Override public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog( mainFrame, "Open Darwin CSV file for matching ...", FileDialog.LOAD); fd.setVisible(true); if (fd.getFile() == null) return; File file = new File(fd.getFile()); if (fd.getDirectory() != null) { file = new File(fd.getDirectory(), fd.getFile()); } // Clear out old match against. matchAgainst(null); // SwingWorker MAGIC! new MainFrameWorker("matching against file '" + file + "'", file) { @Override protected Object doInBackground() throws Exception { matchAgainst(new DarwinCSV((File) input, DarwinCSV.FILE_CSV_DELIMITED)); return null; } }.execute(); } }); matchMenu.add(miMatchCSV); /* Match -> Against ITIS */ JMenuItem miMatchITIS = new JMenuItem( new AbstractAction("Match against ITIS") { @Override public void actionPerformed(ActionEvent e) { DarwinCSV csv = DownloadITIS.getIt(mainFrame); matchAgainst(csv); table.repaint(); } }); matchMenu.add(miMatchITIS); /* TaxonID */ JMenu taxonIDMenu = new JMenu("TaxonIDs"); menuBar.add(taxonIDMenu); /* TaxonID -> Treat TaxonIDs as ... */ JMenu treatTaxonIDsAs = new JMenu("Treat TaxonIDs as ..."); taxonIDMenu.add(treatTaxonIDsAs); /* TaxonID -> Treat -> ITIS TSNs */ JCheckBoxMenuItem miITIS_TSNs = new JCheckBoxMenuItem( new AbstractAction("ITIS TSNs") { @Override public void actionPerformed(ActionEvent e) { // Don't let the user unselect this. ((JCheckBoxMenuItem) e.getSource()).setSelected(true); } }); miITIS_TSNs.setSelected(true); treatTaxonIDsAs.add(miITIS_TSNs); /* TaxonID -> Create family column */ JMenuItem miTaxonID_createFamily = new JMenuItem( new AbstractAction("Create family column") { @Override public void actionPerformed(ActionEvent e) { /* if(currentCSV == null) return; if(currentMatch == null) return; int col = getJTable().getSelectedColumn(); if(col == -1) return; RowIndex rowIndex = currentCSV.getRowIndex(); String colName = rowIndex.getColumnName(col); if(rowIndex.hasColumn(colName + "_family")) { // TODO MessageBox return; } if(Name.class.isAssignableFrom(currentCSV.getRowIndex().getColumnClass(col))) { // A name class! Make a new column! currentCSV.getRowIndex().setColumnClass(colName + "_family", String.class); currentCSV.getRowIndex().createNewColumn(colName + "_family", col + 1, colName, new MapOperation() { @Override public Object mapTo(Object value) { return "family"; } }); // Repaint the table. getJTable().repaint(); } */ } }); taxonIDMenu.add(miTaxonID_createFamily); /* Help */ JMenu helpMenu = new JMenu("Help"); menuBar.add(helpMenu); /* Help -> Memory information */ JMenuItem miHelpMemory = new JMenuItem( new AbstractAction("Memory information") { @Override public void actionPerformed(ActionEvent e) { System.gc(); MessageBox.messageBox( mainFrame, "Memory information", "Maximum memory: " + Runtime.getRuntime().maxMemory() / (1024 * 1024) + " MB\n" + "Total memory: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + " MB\n" + "Used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024) + " MB\n" + "Free memory: " + Runtime.getRuntime().freeMemory() / (1024 * 1024) + " MB\n" + "Available memory: " + (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory()) / (1024 * 1024) + " MB"); } }); helpMenu.add(miHelpMemory); return menuBar; }