List of usage examples for java.awt Window addWindowListener
public synchronized void addWindowListener(WindowListener l)
From source file:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java
@SuppressWarnings("unchecked") public OverviewDialog(Window window, String title, @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData, Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider, FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) { super(window, title, ModalityType.MODELESS); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setAlwaysOnTop(true);//from w w w.j a v a 2 s . c o m this.fieldViewSelectionModel = fvsm; @SuppressWarnings({ "rawtypes" }) JComboBox activeTiCombo = new JComboBox(comboBoxModel); TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer( curationData.getTraitColorProvider(), tiNameProvider); activeTiCombo.setRenderer(tiCellRenderer); JLabel infoLabel = new JLabel(" "); infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED)); final JFrame[] helpDialog = new JFrame[1]; Action helpAction = new AbstractAction("?") { @Override public void actionPerformed(ActionEvent e) { if (helpDialog[0] != null) { GuiUtil.restoreFrame(helpDialog[0]); } else { JFrame f = new JFrame("Overview Help"); helpDialog[0] = f; f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setAlwaysOnTop(true); f.setLocationRelativeTo(overview); String html = Overview.getOverviewHelpHtml(); JLabel label = new JLabel(html); label.setBorder(new EmptyBorder(0, 10, 0, 10)); f.setContentPane(label); f.pack(); f.setVisible(true); } } }; // Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this); if (window != null) { if (window instanceof JFrame) { System.out.println("Found window: " + ((JFrame) window).getTitle()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); if (helpDialog[0] != null) { helpDialog[0].dispose(); } } }); } KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview"); Box top = Box.createHorizontalBox(); top.add(activeTiCombo); top.add(new JButton(helpAction)); overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel); overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true)); Container cp = getContentPane(); cp.add(top, BorderLayout.NORTH); // cp.add(traitLabel, BorderLayout.NORTH); cp.add(infoLabel, BorderLayout.SOUTH); cp.add(overview, BorderLayout.CENTER); pack(); // setResizable(false); // setLocationRelativeTo(showOverviewButton); // DEFAULT POSITION is "out of the way" setVisible(true); this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { toFront(); } @Override public void windowClosed(WindowEvent e) { fieldViewSelectionModel.removeListSelectionListener(listSelectionListener); removeWindowListener(this); } }); }
From source file:net.pms.newgui.components.WindowProperties.java
/** * Creates a new instance using the specified parameters. * * @param window the {@link Window} whose properties to keep track of. * @param standardSize the standard size of {@code window}. * @param mimimumSize the minimum size of {@code window}. * @param windowConfiguration the {@link WindowPropertiesConfiguration} * instance for reading and writing the window properties. *///from w w w . j av a 2s . c o m public WindowProperties(@Nonnull Window window, @Nullable Dimension standardSize, @Nullable Dimension mimimumSize, @Nullable WindowPropertiesConfiguration windowConfiguration) { if (window == null) { throw new IllegalArgumentException("window cannot be null"); } this.window = window; this.minimumSize = mimimumSize; if (mimimumSize != null) { window.setMinimumSize(mimimumSize); } this.windowConfiguration = windowConfiguration; if (windowConfiguration != null) { getConfiguration(); GraphicsConfiguration windowGraphicsConfiguration = window.getGraphicsConfiguration(); if (windowBounds != null && effectiveScreenBounds != null && graphicsDevice != null && graphicsDevice.equals(windowGraphicsConfiguration.getDevice().getIDstring()) && screenBounds != null && screenBounds.equals(windowGraphicsConfiguration.getBounds())) { setWindowBounds(); } else { Rectangle screen = effectiveScreenBounds != null ? effectiveScreenBounds : windowGraphicsConfiguration.getBounds(); if (standardSize != null && screen.width >= standardSize.width && screen.height >= standardSize.height) { window.setSize(standardSize); } else if (mimimumSize != null && (window.getWidth() < mimimumSize.width || window.getHeight() < mimimumSize.getHeight())) { window.setSize(mimimumSize); } window.setLocationByPlatform(true); } if (window instanceof Frame) { // Set maximized state int maximizedState = windowState & Frame.MAXIMIZED_BOTH; if (maximizedState != 0) { ((Frame) window).setExtendedState(((Frame) window).getExtendedState() | maximizedState); } } } window.addWindowListener(this); window.addComponentListener(this); }
From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java
/** * register a window listener to <code>window</code>.<br> deregistering happens in * <code>WindowClosingListener.windowClosed()</code>. * @param window the window to register to *//*from w ww. j a v a 2 s. com*/ private void registerAsWindowListener(final Window window) { Runnable registrationRunnable = new Runnable() { public void run() { if (log.isInfoEnabled()) { log.info("registering window listener to window " //$NON-NLS-1$ + window); } WindowListener[] listener = window.getWindowListeners(); for (int i = 0; i < listener.length; i++) { if (listener[i] instanceof WindowClosingListener) { return; } } window.addWindowListener(new WindowClosingListener()); } }; registerListener(registrationRunnable); }