List of usage examples for java.awt Window removeWindowListener
public synchronized void removeWindowListener(WindowListener l)
From source file:com.diversityarrays.kdxplore.vistool.VisToolbarFactory.java
static public VisToolToolBar create(final String title, final JComponent comp, final Closure<File> snapshotter, final VisToolDataProvider visToolDataProvider, boolean floatable, final String[] imageSuffixes) { Window window = GuiUtil.getOwnerWindow(comp); boolean anyButtons = false; final JCheckBox keepOnTop; if (window == null) { keepOnTop = null;//from w ww . ja v a2 s.c o m } else { anyButtons = true; keepOnTop = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true); keepOnTop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.setAlwaysOnTop(keepOnTop.isSelected()); } }); window.setAlwaysOnTop(keepOnTop.isSelected()); // buttons.add(keepOnTop); final PropertyChangeListener alwaysOnTopListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { keepOnTop.setSelected(window.isAlwaysOnTop()); } }; window.addPropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); window.removePropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); } }); } final JButton cameraButton; if (snapshotter == null) { cameraButton = null; } else { Action cameraAction = new AbstractAction(Msg.ACTION_SNAPSHOT()) { @Override public void actionPerformed(ActionEvent e) { if (chooser == null) { chooser = new JFileChooser(); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (!f.isFile()) { return true; } String loname = f.getName().toLowerCase(); for (String sfx : imageSuffixes) { if (loname.endsWith(sfx)) { return true; } } return false; } @Override public String getDescription() { return Msg.DESC_IMAGE_FILE(); } }); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); } if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(comp)) { File file = chooser.getSelectedFile(); snapshotter.execute(file); } } }; ImageIcon icon = loadIcon("camera-24.png"); //$NON-NLS-1$ if (icon != null) { cameraAction.putValue(Action.SMALL_ICON, icon); cameraAction.putValue(Action.NAME, null); } anyButtons = true; cameraButton = new JButton(cameraAction); } final JButton refreshButton; if (visToolDataProvider == null) { refreshButton = null; } else { anyButtons = true; refreshButton = new JButton(Msg.ACTION_REFRESH()); ImageIcon icon = loadIcon("refresh-24.png"); //$NON-NLS-1$ if (icon != null) { refreshButton.setIcon(icon); // don't remove the name } refreshButton.setForeground(Color.RED); refreshButton.setEnabled(false); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (visToolDataProvider.refreshData()) { refreshButton.setEnabled(false); } } }); visToolDataProvider.addVisToolDataChangedListener(new VisToolDataChangedListener() { @Override public void visToolDataChanged(Object source) { refreshButton.setEnabled(true); } }); } VisToolToolBar toolBar = null; if (anyButtons) { toolBar = new VisToolToolBar(keepOnTop, cameraButton, refreshButton); toolBar.setFloatable(floatable); } return toolBar; }
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);/* 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); } }); }