List of usage examples for java.awt.event WindowEvent WindowEvent
public WindowEvent(Window source, int id)
From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java
/** * On any menu item click./* w w w . j a v a 2 s .c om*/ */ @Override public void actionPerformed(ActionEvent arg0) { State.print(arg0.getActionCommand()); switch (arg0.getActionCommand()) { case "new": //Try to save work, open new show try { newShow(); } catch (InterruptedException e) { e.printStackTrace(); } break; case "open": //Try to save work, get new show openShow(); break; case "save": Main.save(); break; case "saveas": try { saveAs(); } catch (InterruptedException e) { e.printStackTrace(); } break; case "printpage": try { desktop.setCursor(new Cursor(Cursor.WAIT_CURSOR)); desktop.printCurrentPageToPdf(); desktop.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } catch (IOException e) { e.printStackTrace(); } break; case "printshow": try { desktop.setCursor(new Cursor(Cursor.WAIT_CURSOR)); desktop.printAllPagesToPdf(); desktop.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } catch (IOException e) { e.printStackTrace(); } break; case "printdotsheets": try { desktop.setCursor(new Cursor(Cursor.WAIT_CURSOR)); new DotSheetMaker().printDotSheets(); desktop.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } catch (InterruptedException e) { e.printStackTrace(); } break; case "togglegrid": Main.getState().getSettings().setShowGrid(!Main.getState().getSettings().shouldShowGrid()); ((JMenu) getComponent(2)).getMenuComponent(0) .setForeground(Main.getState().getSettings().shouldShowGrid() ? Color.BLACK : Color.RED); break; case "togglenames": Main.getState().getSettings().setShowNames(!Main.getState().getSettings().shouldShowNames()); ((JMenu) getComponent(2)).getMenuComponent(1) .setForeground(Main.getState().getSettings().shouldShowNames() ? Color.BLACK : Color.RED); break; case "toggletext": Main.getState().getSettings().setShowText(!Main.getState().getSettings().shouldShowText()); ((JMenu) getComponent(2)).getMenuComponent(2) .setForeground(Main.getState().getSettings().shouldShowText() ? Color.BLACK : Color.RED); break; case "colordots": Main.getState().getSettings().setColorDots(!Main.getState().getSettings().shouldColorDots()); ((JMenu) getComponent(2)).getMenuComponent(3) .setForeground(Main.getState().getSettings().shouldColorDots() ? Color.BLACK : Color.RED); break; case "changehash": Main.getState().getSettings().setCollegeHashes(!Main.getState().getSettings().useCollegeHashes()); ((JMenuItem) (((JMenu) getComponent(2)).getMenuComponent(4))) .setText(Main.getState().getSettings().useCollegeHashes() ? "Change to High School Hashes" : "Change to College Hashes"); try { desktop.getImage(); } catch (IOException e) { e.printStackTrace(); } desktop.getDotDataFrame().updatePosition(); break; case "fontsize": changeFontSize(); break; case "play": play(); break; case "undo": Main.getState().undo(); desktop.getIO().clearActivePoints(); desktop.getDotDataFrame().updateAll(desktop.getActivePoints()); break; case "redo": Main.getState().redo(); desktop.getIO().clearActivePoints(); desktop.getDotDataFrame().updateAll(desktop.getActivePoints()); break; case "help": help(); break; case "about": about(); break; case "quit": default: gr.dispatchEvent(new WindowEvent(gr, WindowEvent.WINDOW_CLOSING)); } desktop.getIO().fixControl(); }
From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java
private JMenu createMenuFile() { final JMenu menuFile = new JMenu(Messages.getString("Menu.file")); //$NON-NLS-1$ final JMenuItem menuFileOpen = new JMenuItem(Messages.getString("Menu.fileOpen")); //$NON-NLS-1$ menuFileOpen.setMnemonic(KeyEvent.VK_O); menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_MASK)); menuFileOpen.addActionListener(new ActionListener() { @Override// ww w.j av a 2s . c o m public void actionPerformed(final ActionEvent e) { openFile(); } }); menuFile.add(menuFileOpen); menuFile.add(menuFileRecent); final JMenuItem menuFileReload = new JMenuItem(Messages.getString("Menu.fileReload")); //$NON-NLS-1$ menuFileReload.setMnemonic(KeyEvent.VK_R); menuFileReload.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK)); menuFileReload.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { reloadDefinition(); } }); menuFile.add(menuFileReload); final JMenuItem menuFileClose = new JMenuItem(Messages.getString("Menu.fileClose")); //$NON-NLS-1$ menuFileClose.setMnemonic(KeyEvent.VK_C); menuFileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK)); menuFileClose.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { closeSource(); } }); menuFile.add(menuFileClose); menuFile.addSeparator(); final JMenuItem menuFileProperties = new JMenuItem(Messages.getString("Menu.properties")); //$NON-NLS-1$ menuFileProperties.setMnemonic(KeyEvent.VK_P); menuFileProperties.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK)); menuFileProperties.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { showPropertiesDialog(); } }); menuFile.add(menuFileProperties); menuFile.addSeparator(); final JMenuItem menuFileExport = createMenuFileExport(); menuFile.add(menuFileExport); menuFile.addSeparator(); final JMenuItem menuFilePreferences = new JMenuItem(Messages.getString("Menu.preferences")); //$NON-NLS-1$ menuFilePreferences.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { showPreferencesDialog(); } }); menuFile.add(menuFilePreferences); menuFile.addSeparator(); final JMenuItem menuFileExit = new JMenuItem(Messages.getString("Menu.exit")); //$NON-NLS-1$ menuFileExit.setMnemonic(KeyEvent.VK_E); menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK)); menuFileExit.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { for (Frame frame : getFrames()) { if (frame.isActive()) { frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); } } } }); menuFile.add(menuFileExit); menuFile.addMenuListener(new MenuListener() { @Override public void menuSelected(final MenuEvent e) { menuFileReload.setEnabled(isSourceOpen() && currentSource.canReopen()); menuFileClose.setEnabled(isSourceOpen()); menuFileProperties.setEnabled(isDefinitionOpen()); menuFileExport.setEnabled(isDefinitionOpen()); } @Override public void menuDeselected(final MenuEvent e) { } @Override public void menuCanceled(final MenuEvent e) { } }); return menuFile; }
From source file:pcgen.gui2.tools.Utility.java
/** * Add a keyboard shortcut to allow ESC to close the dialog. * * @param dialog The dialog to be updated. *///from ww w.j a v a 2 s.co m public static void installEscapeCloseOperation(final JDialog dialog) { JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey); Action dispatchClosing = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); } }; root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing); }
From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java
public static void installEscapeCloseOperation(final JDialog dialog) { Action dispatchClosing = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }/*w ww. j ava2 s . c o m*/ }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey); root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing); }
From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java
@Override public void actionPerformed(final ActionEvent e) { if (e.getSource() == applyButton) { addNode();//from w w w. ja va2s. c o m } else if (e.getSource() == clearButton) { clearForm(); } else if (e.getSource() == deleteButton) { removeNode(); } else if (e.getSource() == updateButton) { netAddNode(); } else if (e.getSource() == securityCombo) { changeNode(); } else if (e.getSource() == closeButton) { dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Returns (possibly constructing) the ESC action. *///from ww w . j av a 2 s . c o m public static Action getDisposeAction() { if (ACTION_DISPOSE == null) { ACTION_DISPOSE = new AbstractAction() { /** * */ private static final long serialVersionUID = 3219036624812939826L; public void actionPerformed(ActionEvent ae) { Window parent; if (ae.getSource() instanceof Window) parent = (Window) ae.getSource(); else parent = SwingUtilities.getWindowAncestor((Component) ae.getSource()); if (parent != null) parent.dispatchEvent(new WindowEvent(parent, WindowEvent.WINDOW_CLOSING)); } }; } return ACTION_DISPOSE; }
From source file:com.sldeditor.test.unit.tool.vector.VectorToolTest.java
/** * Test method for {@link com.sldeditor.tool.vector.VectorTool#VectorTool(com.sldeditor.common.SLDEditorInterface)}. *//*from w w w . j av a2 s .c om*/ @Test public void testVectorToolFileDataSource() { TestMissingSLDAttributes testAttribute = new TestMissingSLDAttributes(); List<CheckAttributeInterface> checkList = new ArrayList<CheckAttributeInterface>(); checkList.add(testAttribute); CheckAttributeFactory.setOverideCheckList(checkList); String testsldfile = "/polygon/sld/polygon_polygonwithdefaultlabel.sld"; TestSLDEditor testSLDEditor = null; try { testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null); } catch (Exception e) { e.printStackTrace(); } InputStream inputStream = VectorToolTest.class.getResourceAsStream(testsldfile); if (inputStream == null) { Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream); } else { File f = null; try { f = stream2file(inputStream); try { testSLDEditor.openFile(f.toURI().toURL()); } catch (NullPointerException nullException) { nullException.printStackTrace(); StackTraceElement[] stackTraceElements = nullException.getStackTrace(); System.out.println(stackTraceElements[0].getMethodName()); } f.delete(); } catch (IOException e1) { e1.printStackTrace(); } } // Fields extracted from the SLD file DataSourceInterface dataSource = DataSourceFactory.createDataSource(null); Collection<PropertyDescriptor> propertyList = dataSource.getPropertyDescriptorList(); assertEquals(2, propertyList.size()); Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } AttributeDescriptor name = (AttributeDescriptor) map.get("name"); assertNotNull(name); GeometryDescriptor geometry = (GeometryDescriptor) map.get("geom"); assertNotNull(geometry); File tempFolder = Files.createTempDir(); TestVectorTool vectorTool = new TestVectorTool(testSLDEditor); try { // Set a shape file as a data source - that matches the SLD File matchingShpFile = extractShapeFile(tempFolder, "/test/sld_cookbook_polygon.zip"); FileTreeNode fileTreeNode = new FileTreeNode(matchingShpFile.getParentFile(), matchingShpFile.getName()); vectorTool.testSetDataSource(fileTreeNode); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(3, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNotNull(name); geometry = (GeometryDescriptor) map.get("the_geom"); assertNotNull(geometry); AttributeDescriptor pop = (AttributeDescriptor) map.get("pop"); assertNotNull(pop); // Set a shape file as a data source - that does not match the SLD File nonMatchingShpFile = extractShapeFile(tempFolder, "/test/states.zip"); FileTreeNode fileTreeNode2 = new FileTreeNode(nonMatchingShpFile.getParentFile(), nonMatchingShpFile.getName()); vectorTool.testSetDataSource(fileTreeNode2); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(23, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNull(name); geometry = (GeometryDescriptor) map.get("the_geom"); assertNotNull(geometry); pop = (AttributeDescriptor) map.get("pop"); assertNull(pop); assertEquals(1, testAttribute.getMissingFieldList().size()); assertEquals("name", testAttribute.getMissingFieldList().get(0)); // Create SLD from shape file vectorTool.testImportFile(fileTreeNode); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(3, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNotNull(name); geometry = (GeometryDescriptor) map.get("the_geom"); assertNotNull(geometry); pop = (AttributeDescriptor) map.get("pop"); assertNotNull(pop); // Release locks dataSource.reset(); } catch (IOException e) { e.printStackTrace(); fail(); } // Tidy up so the remaining unit tests are ok JFrame frame = testSLDEditor.getApplicationFrame(); frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); testSLDEditor = null; clearDown(); // Delete the shape files we extracted purgeDirectory(tempFolder); }
From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java
private void closeDialog() { dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); }
From source file:se.trixon.jota.client.ui.MainFrame.java
private void quit() { dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); }
From source file:org.nuxeo.launcher.gui.NuxeoFrame.java
/** * @since 5.6//from w ww .j a v a 2s .c om */ public void close() { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Toolkit.getDefaultToolkit().getSystemEventQueue() .postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); }