Example usage for java.beans PropertyChangeListener PropertyChangeListener

List of usage examples for java.beans PropertyChangeListener PropertyChangeListener

Introduction

In this page you can find the example usage for java.beans PropertyChangeListener PropertyChangeListener.

Prototype

PropertyChangeListener

Source Link

Usage

From source file:org.yccheok.jstock.gui.Utils.java

public static FileEx promptSavePortfolioCSVAndExcelJFileChooser(final String suggestedFileName) {
    final JStockOptions jStockOptions = JStock.instance().getJStockOptions();
    final JFileChooser chooser = new JFileChooser(jStockOptions.getLastFileIODirectory());
    final FileNameExtensionFilter csvFilter = new FileNameExtensionFilter("CSV Documents (*.csv)", "csv");
    final FileNameExtensionFilter xlsFilter = new FileNameExtensionFilter("Microsoft Excel (*.xls)", "xls");
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.addChoosableFileFilter(csvFilter);
    chooser.addChoosableFileFilter(xlsFilter);

    final org.yccheok.jstock.gui.file.PortfolioSelectionJPanel portfolioSelectionJPanel = new org.yccheok.jstock.gui.file.PortfolioSelectionJPanel();
    chooser.setAccessory(portfolioSelectionJPanel);
    chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override//from  ww  w.  ja  va  2s .c o  m
        public void propertyChange(PropertyChangeEvent evt) {
            final boolean flag = ((FileNameExtensionFilter) evt.getNewValue()).equals(csvFilter);
            portfolioSelectionJPanel.setEnabled(flag);
            chooser.setSelectedFile(chooser.getFileFilter().getDescription().equals(csvFilter.getDescription())
                    ? new File(portfolioSelectionJPanel.getSuggestedFileName())
                    : new File(suggestedFileName));
        }

    });
    portfolioSelectionJPanel.addJRadioButtonsActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            chooser.setSelectedFile(new File(portfolioSelectionJPanel.getSuggestedFileName()));
        }

    });
    final java.util.Map<String, FileNameExtensionFilter> map = new HashMap<String, FileNameExtensionFilter>();
    map.put(csvFilter.getDescription(), csvFilter);
    map.put(xlsFilter.getDescription(), xlsFilter);

    final FileNameExtensionFilter filter = map.get(jStockOptions.getLastSavedFileNameExtensionDescription());
    if (filter != null) {
        chooser.setFileFilter(filter);
    }

    // Only enable portfolioSelectionJPanel, if CSV is being selected.
    portfolioSelectionJPanel
            .setEnabled(chooser.getFileFilter().getDescription().equals(csvFilter.getDescription()));
    chooser.setSelectedFile(chooser.getFileFilter().getDescription().equals(csvFilter.getDescription())
            ? new File(portfolioSelectionJPanel.getSuggestedFileName())
            : new File(suggestedFileName));

    while (true) {
        final int returnVal = chooser.showSaveDialog(JStock.instance());
        if (returnVal != JFileChooser.APPROVE_OPTION) {
            return null;
        }

        File file = chooser.getSelectedFile();
        if (file == null) {
            return null;
        }

        // Ensure the saved file is in correct extension. If user provide correct
        // file extension explicitly, leave it as is. If not, mutate the filename.
        final String extension = Utils.getFileExtension(file);
        if (extension.equals("csv") == false && extension.equals("xls") == false) {
            if (chooser.getFileFilter().getDescription().equals(csvFilter.getDescription())) {
                file = new File(file.getAbsolutePath() + ".csv");
            } else if (chooser.getFileFilter().getDescription().equals(xlsFilter.getDescription())) {
                file = new File(file.getAbsolutePath() + ".xls");
            } else {
                // Impossible.
                return null;
            }
        }

        if (file.exists()) {
            final String output = MessageFormat
                    .format(MessagesBundle.getString("question_message_replace_old_template"), file.getName());

            final int result = javax.swing.JOptionPane.showConfirmDialog(JStock.instance(), output,
                    MessagesBundle.getString("question_title_replace_old"),
                    javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE);
            if (result != javax.swing.JOptionPane.YES_OPTION) {
                continue;
            }
        }

        final String parent = chooser.getSelectedFile().getParent();
        if (parent != null) {
            jStockOptions.setLastFileIODirectory(parent);
        }

        if (Utils.getFileExtension(file).equals("csv")) {
            jStockOptions.setLastFileNameExtensionDescription(csvFilter.getDescription());
        } else if (Utils.getFileExtension(file).equals("xls")) {
            jStockOptions.setLastFileNameExtensionDescription(xlsFilter.getDescription());
        } else {
            // Impossible.
            return null;
        }

        return new FileEx(file, portfolioSelectionJPanel.getType());
    }
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** 
 * Shows the plane information./*from   w w  w  .  ja  v  a 2 s.  c  o  m*/
 * 
 * @param show    Pass <code>true</code> to show the dialog, 
 *             <code>false</code> to hide it.
 * @param comp The component to show.
 */
void showPlaneInfoDetails(PlaneInfoComponent comp) {
    if (comp == null)
        return;
    if (channelDialog != null) {
        JComponent c = channelDialog.getCanvas();
        channelDialog.closeWindow();
        hideAnimation();
        channelDialog = null;
        if (c == comp.getContent())
            return;
    }
    if (infoDialog != null) {
        infoDialog.closeWindow();
        hideAnimation();
        infoDialog = null;
    }
    channelDialog = new TinyDialog(this, comp.getContent(), TinyDialog.CLOSE_ONLY);
    channelDialog.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (TinyDialog.CLOSED_PROPERTY.equals(evt.getPropertyName())) {
                channelDialog.closeWindow();
                hideAnimation();
                channelDialog = null;
            }
        }
    });
    channelDialog.pack();
    Point p;
    JPanel glass = (JPanel) getGlassPane();
    if (glass.getLayout() == null) {
        Dimension d = channelDialog.getPreferredSize();
        d = new Dimension(d.width + 20, d.height);
        channelDialog.setSize(d);
        channelDialog.setPreferredSize(d);
        p = new Point(0, statusBar.getPreferredSize().height);
    } else {
        p = new Point(0, 2 * statusBar.getPreferredSize().height);
    }
    //setCloseAfter(true);
    showJDialogAsSheet(channelDialog, p, UP_MIDDLE);
}

From source file:org.apache.log4j.chainsaw.LogUI.java

private void buildLogPanel(boolean customExpression, final String ident, final List events)
        throws IllegalArgumentException {
    final LogPanel thisPanel = new LogPanel(getStatusBar(), ident, cyclicBufferSize, allColorizers,
            applicationPreferenceModel);

    getSettingsManager().addSettingsListener(thisPanel);
    getSettingsManager().configure(thisPanel);

    /**/*from  ww w .java  2 s.  c  o m*/
       * Now add the panel as a batch listener so it can handle it's own
       * batchs
       */
    if (customExpression) {
        handler.addCustomEventBatchListener(ident, thisPanel);
    } else {
        identifierPanels.add(thisPanel);
        handler.addEventBatchListener(thisPanel);
    }

    TabIconHandler iconHandler = new TabIconHandler(ident);
    thisPanel.addEventCountListener(iconHandler);

    tabbedPane.addChangeListener(iconHandler);

    PropertyChangeListener toolbarMenuUpdateListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            tbms.stateChange();
        }
    };

    thisPanel.addPropertyChangeListener(toolbarMenuUpdateListener);
    thisPanel.addPreferencePropertyChangeListener(toolbarMenuUpdateListener);

    thisPanel.addPropertyChangeListener("docked", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            LogPanel logPanel = (LogPanel) evt.getSource();

            if (logPanel.isDocked()) {
                getPanelMap().put(logPanel.getIdentifier(), logPanel);
                getTabbedPane().addANewTab(logPanel.getIdentifier(), logPanel, null);
                getTabbedPane().setSelectedTab(getTabbedPane().indexOfTab(logPanel.getIdentifier()));
            } else {
                getTabbedPane().remove(logPanel);
            }
        }
    });

    logger.debug("adding logpanel to tabbed pane: " + ident);

    //NOTE: tab addition is a very fragile process - if you modify this code,
    //verify the frames in the individual log panels initialize to their
    //correct sizes
    getTabbedPane().add(ident, thisPanel);
    getPanelMap().put(ident, thisPanel);

    /**
       * Let the new LogPanel receive this batch
       */

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            getTabbedPane().addANewTab(ident, thisPanel, new ImageIcon(ChainsawIcons.ANIM_RADIO_TOWER));
            thisPanel.layoutComponents();
            thisPanel.receiveEventBatch(ident, events);
            if (!getTabbedPane().tabSetting.isChainsawLog()) {
                displayPanel("chainsaw-log", false);
            }
        }
    });

    String msg = "added tab " + ident;
    MessageCenter.getInstance().getLogger().debug(msg);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** 
 * Displays information about the image.
 * /*w  w w  .ja v  a  2 s  . c  o m*/
 * @param comp
 */
void showImageInfo(JComponent comp) {
    if (comp == null)
        return;
    if (infoDialog != null) {
        infoDialog.closeWindow();
        hideAnimation();
        infoDialog = null;
        return;
    }
    if (channelDialog != null) {
        channelDialog.closeWindow();
        hideAnimation();
        channelDialog = null;
    }
    infoDialog = new TinyDialog(this, comp, TinyDialog.CLOSE_ONLY);
    infoDialog.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (TinyDialog.CLOSED_PROPERTY.equals(evt.getPropertyName())) {
                infoDialog.closeWindow();
                hideAnimation();
                infoDialog = null;
            }
        }
    });
    infoDialog.pack();
    Point p;
    JPanel glass = (JPanel) getGlassPane();
    if (glass.getLayout() == null) {
        Dimension d = infoDialog.getPreferredSize();
        d = new Dimension(d.width, d.height + 20);
        infoDialog.setSize(d);
        infoDialog.setPreferredSize(d);
        p = new Point(0, statusBar.getPreferredSize().height);
    } else {
        p = new Point(0, 2 * statusBar.getPreferredSize().height);

    }
    //setCloseAfter(true);
    showJDialogAsSheet(infoDialog, p, UP_LEFT);
}

From source file:org.gtdfree.GTDFree.java

public GTDFreeEngine getEngine() {
    if (engine == null) {
        try {/*from w ww  . j av a 2 s.  co m*/
            engine = new GTDFreeEngine();
            engine.addPropertyChangeListener("aborting", new PropertyChangeListener() { //$NON-NLS-1$

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    aborting();
                }
            });
        } catch (Exception e) {
            Logger.getLogger(this.getClass()).fatal("Initialization failed.", e); //$NON-NLS-1$
            close(true);
        }
    }
    return engine;
}

From source file:org.gtdfree.GTDFree.java

private JCheckBoxMenuItem getShowAllActionsMenuItem() {
    if (showAllActions == null) {
        showAllActions = new JCheckBoxMenuItem(getActionMap().get(GlobalProperties.SHOW_ALL_ACTIONS));
        showAllActions//from w w  w .  j  a  v  a2  s. c  o  m
                .setSelected(getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_ALL_ACTIONS));
        getEngine().getGlobalProperties().addPropertyChangeListener(GlobalProperties.SHOW_ALL_ACTIONS,
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        showAllActions.setSelected(getEngine().getGlobalProperties()
                                .getBoolean(GlobalProperties.SHOW_ALL_ACTIONS));
                    }
                });
    }
    return showAllActions;
}

From source file:org.gtdfree.GTDFree.java

private JCheckBoxMenuItem getShowClosedFoldersMenuItem() {
    if (showClosedFolders == null) {
        showClosedFolders = new JCheckBoxMenuItem(getActionMap().get(GlobalProperties.SHOW_CLOSED_FOLDERS));
        showClosedFolders.setSelected(//from w  ww  .  jav  a 2  s.  c  om
                getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_CLOSED_FOLDERS));
        getEngine().getGlobalProperties().addPropertyChangeListener(GlobalProperties.SHOW_CLOSED_FOLDERS,
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        showClosedFolders.setSelected(getEngine().getGlobalProperties()
                                .getBoolean(GlobalProperties.SHOW_CLOSED_FOLDERS));
                    }
                });
    }
    return showClosedFolders;
}

From source file:org.gtdfree.GTDFree.java

private JCheckBoxMenuItem getShowEmptyFoldersMenuItem() {
    if (showEmptyFolders == null) {
        showEmptyFolders = new JCheckBoxMenuItem(getActionMap().get(GlobalProperties.SHOW_EMPTY_FOLDERS));
        showEmptyFolders.setSelected(// w w  w .  j av a 2s. c om
                getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_EMPTY_FOLDERS, true));
        getEngine().getGlobalProperties().addPropertyChangeListener(GlobalProperties.SHOW_EMPTY_FOLDERS,
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        showEmptyFolders.setSelected(getEngine().getGlobalProperties()
                                .getBoolean(GlobalProperties.SHOW_EMPTY_FOLDERS, true));
                    }
                });
    }
    return showEmptyFolders;
}

From source file:org.gtdfree.GTDFree.java

private JCheckBoxMenuItem getShowOverviewTabMenuItem() {
    if (showOverviewTab == null) {
        showOverviewTab = new JCheckBoxMenuItem(getActionMap().get(GlobalProperties.SHOW_OVERVIEW_TAB));
        showOverviewTab.setSelected(//from www .ja  v a 2  s . c o m
                getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_OVERVIEW_TAB, true));
        getEngine().getGlobalProperties().addPropertyChangeListener(GlobalProperties.SHOW_OVERVIEW_TAB,
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        showOverviewTab.setSelected(getEngine().getGlobalProperties()
                                .getBoolean(GlobalProperties.SHOW_OVERVIEW_TAB));

                        if (getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_OVERVIEW_TAB)) {
                            if (tabbedPane.getComponentAt(0) != getOverviewPane()) {
                                tabbedPane.insertTab(Messages.getString("GTDFree.Overview"), //$NON-NLS-1$
                                        ApplicationHelper.getIcon(ApplicationHelper.icon_name_small_overview),
                                        getOverviewPane(), "", 0); //$NON-NLS-1$
                            }
                        } else {
                            if (tabbedPane.getComponentAt(0) == getOverviewPane()) {
                                tabbedPane.remove(0);
                            }
                        }
                    }
                });
    }
    return showOverviewTab;
}

From source file:org.gtdfree.GTDFree.java

private JCheckBoxMenuItem getShowQuickCollectBarMenuItem() {
    if (showQuickCollectBar == null) {
        showQuickCollectBar = new JCheckBoxMenuItem(getActionMap().get(GlobalProperties.SHOW_QUICK_COLLECT));
        showQuickCollectBar/* w  ww  .  j a v  a  2 s.  c  om*/
                .setSelected(getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_QUICK_COLLECT));
        getEngine().getGlobalProperties().addPropertyChangeListener(GlobalProperties.SHOW_QUICK_COLLECT,
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        showQuickCollectBar.setSelected(getEngine().getGlobalProperties()
                                .getBoolean(GlobalProperties.SHOW_QUICK_COLLECT));
                        enableQuickCollectPanel();
                    }
                });
    }
    return showQuickCollectBar;
}