List of usage examples for java.awt.event WindowEvent getID
public int getID()
From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java
/** * @throws HeadlessException//from ww w . j a va2s . c o m */ public AgentDebuggerFrame(final boolean isStandalone, String serviceUrl) throws HeadlessException { super("Intuit Tank Agent Debugger"); workingDir = PanelBuilder.createWorkingDir(this, serviceUrl); setSize(new Dimension(1024, 800)); setBounds(new Rectangle(getSize())); setPreferredSize(getSize()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setLayout(new BorderLayout()); this.standalone = isStandalone; addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { quit(); } }); errorIcon = ActionProducer.getIcon("bullet_error.png", IconSize.SMALL); modifiedIcon = ActionProducer.getIcon("bullet_code_change.png", IconSize.SMALL); skippedIcon = ActionProducer.getIcon("skip.png", IconSize.SMALL); this.glassPane = new InfiniteProgressPanel(); setGlassPane(glassPane); debuggerActions = new ActionProducer(this, serviceUrl); requestResponsePanel = new RequestResponsePanel(this); requestResponsePanel.init(); testPlanChooser = new JComboBox(); testPlanChooser.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (event.getItem() != null) { HDTestPlan selected = (HDTestPlan) event.getItem(); if (!selected.equals(currentTestPlan)) { setCurrentTestPlan(selected); } } } }); tankClientChooser = new JComboBox<TankClientChoice>(); debuggerActions.setChoiceComboBoxOptions(tankClientChooser); actionComponents = new ActionComponents(standalone, testPlanChooser, tankClientChooser, debuggerActions); addScriptChangedListener(actionComponents); setJMenuBar(actionComponents.getMenuBar()); Component topPanel = PanelBuilder.createTopPanel(actionComponents); Component bottomPanel = PanelBuilder.createBottomPanel(this); Component contentPanel = PanelBuilder.createContentPanel(this); final JPopupMenu popup = actionComponents.getPopupMenu(); scriptEditorTA.setPopupMenu(null); scriptEditorTA.addMouseListener(new MouseAdapter() { int lastHash; @Override public void mousePressed(MouseEvent e) { maybeShow(e); } @Override public void mouseReleased(MouseEvent e) { maybeShow(e); } private void maybeShow(MouseEvent e) { if (lastHash == getHash(e)) { return; } if (e.isPopupTrigger()) { // select the line try { int offset = scriptEditorTA.viewToModel(e.getPoint()); Rectangle modelToView = scriptEditorTA.modelToView(offset); Point point = new Point(modelToView.x + 1, e.getPoint().y); if (modelToView.contains(point)) { if (!multiSelect) { int line = scriptEditorTA.getLineOfOffset(offset); scriptEditorTA.setCurrentLine(line); } popup.show(e.getComponent(), e.getX(), e.getY()); } } catch (BadLocationException e1) { e1.printStackTrace(); } } else if (e.isShiftDown()) { int line = scriptEditorTA.getCaretLineNumber(); int start = Math.min(line, lastLine); int end = Math.max(line, lastLine); multiSelect = end - start > 1; if (multiSelect) { multiSelectStart = start; multiSelectEnd = end; try { scriptEditorTA.setEnabled(true); scriptEditorTA.select(scriptEditorTA.getLineStartOffset(start), scriptEditorTA.getLineEndOffset(end)); scriptEditorTA.setEnabled(false); } catch (BadLocationException e1) { e1.printStackTrace(); multiSelect = false; } } } else { multiSelect = false; lastLine = scriptEditorTA.getCaretLineNumber(); } lastHash = getHash(e); } private int getHash(MouseEvent e) { return new HashCodeBuilder().append(e.getButton()).append(e.getSource().hashCode()) .append(e.getPoint()).toHashCode(); } }); JSplitPane mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT); mainSplit.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); mainSplit.setTopComponent(contentPanel); mainSplit.setBottomComponent(bottomPanel); mainSplit.setDividerLocation(600); mainSplit.setResizeWeight(0.8D); mainSplit.setDividerSize(5); add(topPanel, BorderLayout.NORTH); add(mainSplit, BorderLayout.CENTER); WindowUtil.centerOnScreen(this); pack(); KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { handleKeyEvent(e); } return false; } }); }
From source file:org.pegadi.client.LoginDialog.java
protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0);/*from w ww . ja v a 2 s . com*/ } }
From source file:studio.ui.Studio.java
@Override protected void processWindowEvent(WindowEvent event) { switch (event.getID()) { case WindowEvent.WINDOW_CLOSING: if (tabEditors != null && tabEditors.getTabCount() > 0) { int current = tabEditors.getSelectedIndex(); boolean close = true; for (int count = 0; close & count < tabEditors.getTabCount(); count++) { Editor editor = tabEditors.getEditor(count); if (editor != null) { if (editor.getFile() != null) { editor.getFile().setActive(count == current); }/* ww w. ja va2 s .c om*/ if (editor.isModified() && !editor.isEmpty()) { tabEditors.setSelectedIndex(count); close &= tabEditors.closeEditor(editor); } } } if (!close) { tabEditors.setSelectedIndex(current); tabEditors.getEditor(current).requestFocus(); return; } else { for (int count = 0; count < tabEditors.getTabCount(); count++) { if (tabEditors.getEditor(count) != null) { tabEditors.getEditor(count).setModified(false); } } } } java.util.List<EditorFile> files = tabEditors.saveFiles(); if (files == null) { return; } try { studioConfig.setLastFiles(files); } catch (ConfigException ex) { ex.printStackTrace(); } super.processWindowEvent(event); System.exit(0); break; case WindowEvent.WINDOW_ACTIVATED: if (tabEditors != null && tabEditors.getTabCount() > 0 && tabEditors.getEditor() != null) { tabEditors.getEditor().requestFocusInWindow(); } break; } super.processWindowEvent(event); }
From source file:studio.ui.Studio.java
public void windowStateChanged(WindowEvent event) { if (event.getID() == WindowEvent.WINDOW_STATE_CHANGED) { try {/*w w w . java 2 s . c o m*/ studioConfig.setMaximized((event.getNewState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH); } catch (ConfigException ignored) { } } }
From source file:uk.co.modularaudio.componentdesigner.ComponentDesigner.java
public void registerCloseAction() throws DatastoreException { mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); mainFrame.addWindowListener(new WindowListener() { @Override//from w w w . j a v a 2s .co m public void windowClosed(final WindowEvent e) { log.debug("Window closed event received"); } @Override public void windowOpened(final WindowEvent e) { try { log.debug("Window opening event received - setting thread to lowest priority."); ThreadUtils.setCurrentThreadPriority(MAThreadPriority.APPLICATION); if (log.isDebugEnabled()) { log.debug("Now set to " + MAThreadPriority.APPLICATION); } } catch (final Exception ie) { final String msg = "Exception caught setting gui thread priority: " + ie.toString(); log.error(msg, ie); } } @Override public void windowClosing(final WindowEvent e) { log.debug("Window closing event received."); final Action exitAction = mainFrameActions.getExitAction(); final ActionEvent exitActionEvent = new ActionEvent(e.getSource(), e.getID(), ""); exitAction.actionPerformed(exitActionEvent); } @Override public void windowIconified(final WindowEvent e) { } @Override public void windowDeiconified(final WindowEvent e) { } @Override public void windowActivated(final WindowEvent e) { } @Override public void windowDeactivated(final WindowEvent e) { } }); }