List of usage examples for java.awt.event WindowAdapter WindowAdapter
WindowAdapter
From source file:DateTimeEditor.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0);/*from w ww. j a va 2s . c o m*/ } }); JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(new EmptyBorder(5, 5, 5, 5)); frame.setContentPane(panel); final DateTimeEditor field = new DateTimeEditor(DateTimeEditor.DATETIME, DateFormat.FULL); panel.add(field, "North"); JPanel buttonBox = new JPanel(new GridLayout(2, 2)); JButton showDateButton = new JButton("Show Date"); buttonBox.add(showDateButton); final JComboBox timeDateChoice = new JComboBox(); timeDateChoice.addItem("Time"); timeDateChoice.addItem("Date"); timeDateChoice.addItem("Date/Time"); timeDateChoice.setSelectedIndex(2); timeDateChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setTimeOrDateType(timeDateChoice.getSelectedIndex()); } }); buttonBox.add(timeDateChoice); JButton toggleButton = new JButton("Toggle Enable"); buttonBox.add(toggleButton); showDateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println(field.getDate()); } }); toggleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setEnabled(!field.isEnabled()); } }); panel.add(buttonBox, "South"); final JComboBox lengthStyleChoice = new JComboBox(); lengthStyleChoice.addItem("Full"); lengthStyleChoice.addItem("Long"); lengthStyleChoice.addItem("Medium"); lengthStyleChoice.addItem("Short"); lengthStyleChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setLengthStyle(lengthStyleChoice.getSelectedIndex()); } }); buttonBox.add(lengthStyleChoice); frame.pack(); Dimension dim = frame.getToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2); frame.show(); }
From source file:com.sshtools.common.ui.SshToolsApplicationFrame.java
/** * * * @param application/* ww w . j a va 2 s .c o m*/ * @param panel * * @throws SshToolsApplicationException */ public void init(final SshToolsApplication application, SshToolsApplicationPanel panel) throws SshToolsApplicationException { this.panel = panel; this.application = application; if (application != null) { setTitle(ConfigurationLoader.getVersionString(application.getApplicationName(), application.getApplicationVersion())); // + " " + application.getApplicationVersion()); } setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Register the File menu panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0)); // Register the Exit action if (showExitAction && application != null) { panel.registerAction(exitAction = new ExitAction(application, this)); // Register the New Window Action } if (showNewWindowAction && application != null) { panel.registerAction(newWindowAction = new NewWindowAction(application)); // Register the Help menu } panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 99)); // Register the About box action if (showAboutBox && application != null) { panel.registerAction(aboutAction = new AboutAction(this, application)); } // Register the Changelog box action if (showChangelogBox && application != null) { panel.registerAction(changelogAction = new ChangelogAction(this, application)); } panel.registerAction(faqAction = new FAQAction()); panel.registerAction(beginnerAction = new BeginnerAction()); panel.registerAction(advancedAction = new AdvancedAction()); getApplicationPanel().rebuildActionComponents(); JPanel p = new JPanel(new BorderLayout()); if (panel.getJMenuBar() != null) { setJMenuBar(panel.getJMenuBar()); } if (panel.getToolBar() != null) { JPanel t = new JPanel(new BorderLayout()); t.add(panel.getToolBar(), BorderLayout.NORTH); t.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH); toolSeparator.setVisible(panel.getToolBar().isVisible()); final SshToolsApplicationPanel pnl = panel; panel.getToolBar().addComponentListener(new ComponentAdapter() { public void componentHidden(ComponentEvent evt) { log.debug("Tool separator is now " + pnl.getToolBar().isVisible()); toolSeparator.setVisible(pnl.getToolBar().isVisible()); } }); p.add(t, BorderLayout.NORTH); } p.add(panel, BorderLayout.CENTER); if (panel.getStatusBar() != null) { p.add(panel.getStatusBar(), BorderLayout.SOUTH); } getContentPane().setLayout(new GridLayout(1, 1)); getContentPane().add(p); // Watch for the frame closing setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { if (application != null) { application.closeContainer(SshToolsApplicationFrame.this); } else { int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this, "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == 0) { hide(); } } } }); // If this is the first frame, center the window on the screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); boolean found = false; if (application != null && application.getContainerCount() != 0) { for (int i = 0; (i < application.getContainerCount()) && !found; i++) { SshToolsApplicationContainer c = application.getContainerAt(i); if (c instanceof SshToolsApplicationFrame) { SshToolsApplicationFrame f = (SshToolsApplicationFrame) c; setSize(f.getSize()); Point newLocation = new Point(f.getX(), f.getY()); newLocation.x += 48; newLocation.y += 48; if (newLocation.x > (screenSize.getWidth() - 64)) { newLocation.x = 0; } if (newLocation.y > (screenSize.getHeight() - 64)) { newLocation.y = 0; } setLocation(newLocation); found = true; } } } if (!found) { // Is there a previous stored geometry we can use? if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) { setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds())); } else { pack(); UIUtil.positionComponent(SwingConstants.CENTER, this); } } }
From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java
/** * @throws HeadlessException//ww w . j a va 2s. co 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:mergedoc.ui.MergeDocFrame.java
/** * ????/* w w w.j av a2s . c o m*/ */ private void initListener() { // ? buttonBar.setRunListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mergeExecutor.submit(new Runnable() { @Override public void run() { execute(); } }); } }); // ? buttonBar.setCancelListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { buttonBar.setEnabled(false); mergeManager.getWorkingState().cancel(); } }); // ? buttonBar.setBackListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { back(); } }); // ? buttonBar.setEndListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { end(); } }); // ?? mergeManager.setChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { WorkingState state = mergeManager.getWorkingState(); progressPanel.addListText(state.getWorkingText()); setTitle(progressPanel.getBarText()); } }); // ? addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { persistent(); } }); // ? addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { end(); } }); }
From source file:TableCellRenderTest.java
public ColorTableCellEditor() { panel = new JPanel(); // prepare color dialog colorChooser = new JColorChooser(); colorDialog = JColorChooser.createDialog(null, "Planet Color", false, colorChooser, new ActionListener() // OK button listener {/*from ww w . j a va 2 s . com*/ public void actionPerformed(ActionEvent event) { stopCellEditing(); } }, new ActionListener() // Cancel button listener { public void actionPerformed(ActionEvent event) { cancelCellEditing(); } }); colorDialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { cancelCellEditing(); } }); }
From source file:org.jfree.chart.demo.JFreeChartDemo.java
/** * Constructs a demonstration application for the JFreeChart Class Library. *//*from w w w . j ava 2s .c o m*/ public JFreeChartDemo() { super(JFreeChart.INFO.getName() + " " + JFreeChart.INFO.getVersion() + " Demo"); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { dispose(); System.exit(0); } }); this.resources = DEMO.getResources(); // set up the menu final JMenuBar menuBar = createMenuBar(this.resources); setJMenuBar(menuBar); final JPanel content = new JPanel(new BorderLayout()); content.add(createTabbedPane(this.resources)); setContentPane(content); }
From source file:org.keyboardplaying.xtt.ui.UIController.java
/** Builds and shows the main window. */ public void showMainWindow() { /* Create UI. */ JPanel pane = new JPanel(new GridBagLayout()); /* Arrange the components */ GridBagConstraints c;/*w ww. j a v a 2s. c o m*/ c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; pane.add(makeProjectActionButton("action.construct", "action-construct", ImageSize.W_16, constructAction), c); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; pane.add(makeProjectActionButton("action.deconstruct", "action-deconstruct", ImageSize.W_16, deconstructAction), c); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 0; c.gridheight = 2; c.fill = GridBagConstraints.BOTH; pane.add(makeActionButton(null, "icon-settings", ImageSize.W_32, settingsAction), c); Window window = makeWindow("app.name", "icon-timetracker", pane); window.addWindowListener(new WindowAdapter() { /* * (non-Javadoc) * * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event. WindowEvent) */ @Override public void windowClosing(WindowEvent e) { super.windowClosing(e); Frame[] windows = JFrame.getFrames(); for (Frame w : windows) { w.dispose(); } } }); window.setVisible(true); }
From source file:EditorPaneExample15.java
public static void main(String[] args) { try {//from w ww . ja v a2 s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new EditorPaneExample15(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(500, 400); f.setVisible(true); }
From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
private MindRaiderMainWindow() { super(MindRaider.getTitle(), Gfx.getGraphicsConfiguration()); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from w w w. j a va 2s .com } }); // catch resize addComponentListener(this); configuration = new ConfigurationBean(); // drag & drop registration DropTarget dropTarget = new DropTarget(this, (DropTargetListener) this); this.setDropTarget(dropTarget); // warn on different java version // checkJavaVersion(); singleton = this; setIconImage(IconsRegistry.getImage("programIcon.gif")); SplashScreen splash = new SplashScreen(this, false); splash.showSplashScreen(); // kernel init MindRaider.preSetProfiles(); // message in here because of locales logger.debug(Messages.getString("MindRaiderJFrame.bootingKernel")); // master control panel MindRaider.setMasterToolBar(new MasterToolBar()); getContentPane().add(MindRaider.masterToolBar, BorderLayout.NORTH); // status bar getContentPane().add(StatusBar.getStatusBar(), BorderLayout.SOUTH); // build menu buildMenu(MindRaider.spidersGraph); // profile MindRaider.setProfiles(); // left sidebar: folder/notebooks hierarchy, taxonomies, ... final JTabbedPane leftSidebar = new JTabbedPane(SwingConstants.BOTTOM); leftSidebar.setTabPlacement(SwingConstants.TOP); // TODO add icons to tabs leftSidebar.addTab(Messages.getString("MindRaiderJFrame.explorer"), ExplorerJPanel.getInstance()); // TODO just blank panel //leftSidebar.addTab("Tags",new OutlookBarMain()); leftSidebar.addTab( Messages.getString("MindRaiderJFrame.trash"), /* IconsRegistry.getImageIcon("trashFull.png"), */ TrashJPanel.getInstance()); leftSidebar.setSelectedIndex(0); leftSidebar.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (arg0.getSource() instanceof JTabbedPane) { if (leftSidebar.getSelectedIndex() == 1) { // refresh trash TrashJPanel.getInstance().refresh(); } } } }); // main panel: (notebook outline & RDF Navigator) + Control panel JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); mainPanel.add(OutlineJPanel.getInstance(), BorderLayout.CENTER); // split: left sidebar/main panel leftSidebarSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSidebar, mainPanel); leftSidebarSplitPane.setOneTouchExpandable(true); leftSidebarSplitPane.setDividerLocation(200); leftSidebarSplitPane.setLastDividerLocation(200); leftSidebarSplitPane.setDividerSize(6); leftSidebarSplitPane.setContinuousLayout(true); getContentPane().add(leftSidebarSplitPane, BorderLayout.CENTER); Gfx.centerAndShowWindow(this, 1024, 768); MindRaider.postSetProfiles(); if (!configuration.isShowSpidersTagSnailPane()) { OutlineJPanel.getInstance().hideSpiders(); } splash.hideSplash(); }
From source file:es.emergya.ui.gis.popups.GPSDialog.java
public GPSDialog(Recurso r) { super();/*from ww w . java2 s. com*/ setAlwaysOnTop(true); setResizable(false); iconTransparente = LogicConstants.getIcon("48x48_transparente"); iconEnviando = LogicConstants.getIcon("anim_actualizando"); target = r; setDefaultCloseOperation(DISPOSE_ON_CLOSE); setPreferredSize(new Dimension(400, 150)); setTitle(i18n.getString("window.gps.titleBar") + " " + target.getIdentificador()); try { setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getIconImage()); } catch (Throwable e) { LOG.error("There is no icon image", e); } JPanel base = new JPanel(); base.setBackground(Color.WHITE); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); // Icono del titulo JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING)); final JLabel titleLabel = new JLabel(i18n.getString("window.gps.title"), LogicConstants.getIcon("tittleventana_icon_actualizargps"), JLabel.LEFT); titleLabel.setFont(LogicConstants.deriveBoldFont(12f)); title.add(titleLabel); title.setOpaque(false); base.add(title); // Area para mensajes JPanel notificationArea = new JPanel(); notificationArea.setOpaque(false); notification = new JLabel("PLACEHOLDER"); notification.setForeground(Color.WHITE); notificationArea.add(notification); base.add(notificationArea); JPanel buttons = new JPanel(); buttons.setOpaque(false); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); actualizar = new JButton(i18n.getString("window.gps.button.actualizar"), LogicConstants.getIcon("ventanacontextual_button_solicitargps")); actualizar.addActionListener(this); buttons.add(actualizar); buttons.add(Box.createHorizontalGlue()); progressIcon = new JLabel(iconTransparente); buttons.add(progressIcon); buttons.add(Box.createHorizontalGlue()); JButton cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel")); cancel.addActionListener(this); buttons.add(cancel); base.add(buttons); getContentPane().add(base); pack(); int x; int y; Container myParent; try { myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getContentPane(); java.awt.Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = getSize(); if (parentSize.width > mySize.width) x = ((parentSize.width - mySize.width) / 2) + topLeft.x; else x = topLeft.x; if (parentSize.height > mySize.height) y = ((parentSize.height - mySize.height) / 2) + topLeft.y; else y = topLeft.y; setLocation(x, y); } catch (Throwable e1) { LOG.error("There is no basic window!", e1); } this.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent arg0) { deleteErrorMessage(); } @Override public void windowClosed(WindowEvent arg0) { deleteErrorMessage(); } @Override public void windowClosing(WindowEvent arg0) { deleteErrorMessage(); } private void deleteErrorMessage() { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { if (last_bandejaSalida != null) { MessageGenerator.remove(last_bandejaSalida.getId()); } return null; } @Override protected void done() { super.done(); GPSDialog.this.progressIcon.setIcon(iconTransparente); GPSDialog.this.progressIcon.repaint(); last_bandejaSalida = null; GPSDialog.this.notification.setText(""); GPSDialog.this.notification.repaint(); } }; sw.execute(); } }); }