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:EditorPaneExample4.java

public EditorPaneExample4() {
    super("JEditorPane Example 4");

    pane = new JEditorPane();
    pane.setEditable(false); // Read-only
    getContentPane().add(new JScrollPane(pane), "Center");

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;/*from   w ww .  ja  v  a 2 s  .  c o  m*/
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);

    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = 1;
    c.weightx = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;

    textField = new JTextField(32);
    panel.add(textField, c);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);

    getContentPane().add(panel, "South");

    // Change page based on text field
    textField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String url = textField.getText();

            try {
                // Check if the new page and the old
                // page are the same.
                URL newURL = new URL(url);
                URL loadedURL = pane.getPage();
                if (loadedURL != null && loadedURL.sameFile(newURL)) {
                    return;
                }

                // Try to display the page
                textField.setEnabled(false); // Disable input
                textField.paintImmediately(0, 0, textField.getSize().width, textField.getSize().height);
                setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                // Busy cursor
                loadingState.setText("Loading...");
                loadingState.paintImmediately(0, 0, loadingState.getSize().width,
                        loadingState.getSize().height);
                loadedType.setText("");
                loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height);
                pane.setPage(url);

                loadedType.setText(pane.getContentType());
            } catch (Exception e) {
                System.out.println(e);
                JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url },
                        "File Open Error", JOptionPane.ERROR_MESSAGE);
                loadingState.setText("Failed");
                textField.setEnabled(true);
                setCursor(Cursor.getDefaultCursor());
            }
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadingState.setText("Page loaded.");
                textField.setEnabled(true); // Allow entry of new URL
                setCursor(Cursor.getDefaultCursor());
            }
        }
    });
}

From source file:com.kstenschke.copypastestack.ToolWindow.java

private void initSplitPane() {
    Integer dividerLocation = Preferences.getSplitPaneDividerLocation();
    if (dividerLocation != null) {
        this.form.splitPaneToolContent.setDividerLocation(dividerLocation);
    }/*from w w w.  j  a va 2s  .  c  om*/

    this.form.splitPaneToolContent.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Integer location = form.splitPaneToolContent.getDividerLocation();
            Preferences.saveSplitPaneDividerLocation(location);
        }
    });
}

From source file:uk.ac.lkl.cram.ui.chart.LearningTypeChartMaker.java

/**
 * Create a dataset from the module// w  w  w  . ja  v  a  2s  .c  o m
 *
 * @return a pie dataset that is used to produce a pie chart
 */
@Override
protected Dataset createDataSet() {
    //Create the dataset to hold the data
    final DefaultPieDataset pieDataset = new DefaultPieDataset();
    //Populate the dataset with the data
    populateDataset(pieDataset, module);
    //Create a listener, which repopulates the dataset when anything changes
    final PropertyChangeListener learningTypeListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent pce) {
            //LOGGER.info("property change: " + pce);
            populateDataset(pieDataset, module);
        }
    };

    //Add the listener to each of the module's tlaLineItems, as well as to each
    //tlaLineItem's activity
    //This means that whenever a tlaLineItem changes, or its activity changes, the listener is triggered
    //Causing the dataset to be repopulated
    for (TLALineItem lineItem : module.getTLALineItems()) {
        //LOGGER.info("adding listeners to : " + lineItem.getName());
        lineItem.getActivity().getLearningType().addPropertyChangeListener(learningTypeListener);
        lineItem.addPropertyChangeListener(learningTypeListener);
    }
    //Add a listener to the module, listening for changes where a tlaLineItem is added or removed
    module.addPropertyChangeListener(Module.PROP_TLA_LINEITEM, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent pce) {
            //A tlaLineItem has been added or removed
            if (pce instanceof IndexedPropertyChangeEvent) {
                //LOGGER.info("indexed change: " + pce);
                if (pce.getOldValue() != null) {
                    //This has been removed
                    TLALineItem lineItem = (TLALineItem) pce.getOldValue();
                    //So remove the listener from it and its activity
                    //LOGGER.info("removing listeners from: " + lineItem.getName());
                    lineItem.getActivity().getLearningType().removePropertyChangeListener(learningTypeListener);
                    lineItem.removePropertyChangeListener(learningTypeListener);
                }
                if (pce.getNewValue() != null) {
                    //This has been added
                    TLALineItem lineItem = (TLALineItem) pce.getNewValue();
                    //So add a listener to it and its activity
                    //LOGGER.info("adding listeners to: " + lineItem);
                    lineItem.getActivity().getLearningType().addPropertyChangeListener(learningTypeListener);
                    lineItem.addPropertyChangeListener(learningTypeListener);
                }
            }
            //Assume the dataset is now out of date, so repopulate it
            populateDataset(pieDataset, module);
        }
    });

    return pieDataset;
}

From source file:ui.panel.UIBucketSelect.java

public void runBucketSelect() {
    Panel p = new Panel();
    Button b = new Button();
    Label l = new Label();

    setLayout(new BorderLayout());

    JPanel pnlInstruction = p.createPanel(Layouts.flow);
    JLabel lblInstruction = l.createLabel("Bucket List");
    pnlInstruction.setBackground(CustomColor.LightBlue.returnColor());
    lblInstruction.setForeground(Color.white);
    lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18));
    pnlInstruction.add(lblInstruction);// w w  w .  ja  va 2 s  .co  m

    JPanel pnlBucketList = p.createPanel(Layouts.border);

    listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scrollBucket = new JScrollPane(listBucket);
    scrollBucket.setPreferredSize(new Dimension(300, 150));
    pnlBucketList.add(scrollBucket, BorderLayout.CENTER);

    JPanel pnlButtons = p.createPanel(Layouts.flow);
    JButton btnBack = b.createButton("Back");
    JButton btnSelectElements = b.createButton("Next");
    JButton btnRefresh = b.createButton("Refresh Bucket List");

    pnlButtons.add(btnBack);
    pnlButtons.add(btnRefresh);
    pnlButtons.add(btnSelectElements);

    add(pnlInstruction, BorderLayout.NORTH);
    add(pnlBucketList, BorderLayout.CENTER);
    add(pnlButtons, BorderLayout.SOUTH);
    setVisible(true);

    btnRefresh.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getBucketData();
        }
    });
    btnSelectElements.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() {
                @Override
                protected Void doInBackground() throws Exception {

                    int selected = listBucket.getSelectedRow();
                    if (selected == -1) {
                        JOptionPane.showMessageDialog(Data.mainFrame, "Please Select a Bucket", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        Data.bucketID = (int) listBucket.getModel().getValueAt(selected, 0);
                        Data.mainFrame.addPanel(Data.mainFrame.uiLicenseDetail = new UILicenseDetail(),
                                "license");
                        Data.mainFrame.pack();
                        Data.mainFrame.showPanel("license");
                    }
                    return null;
                }
            };

            Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource());
            final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL);

            mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (evt.getPropertyName().equals("state")) {
                        if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
                            dialog.dispose();
                        }
                    }
                }
            });
            mySwingWorker.execute();

            JProgressBar progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(progressBar, BorderLayout.CENTER);
            panel.add(new JLabel("Retrieving Licenses......."), BorderLayout.PAGE_START);
            dialog.add(panel);
            dialog.pack();
            dialog.setBounds(50, 50, 300, 100);
            dialog.setLocationRelativeTo(Data.mainFrame);
            dialog.setVisible(true);
        }
    });
    btnBack.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            Data.mainFrame.showPanel("inventory");
        }
    });
}

From source file:edu.ku.brc.specify.tasks.WebSearchTask.java

/**
 * // w  ww. j a  v  a 2  s. co m
 */
public void createAndSendBackup() {
    BackupServiceFactory.getInstance().doBackUp(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("Done")) {
                startCompression((String) evt.getNewValue());
            }
        }
    });
}

From source file:org.pentaho.aggdes.ui.form.model.AggModel.java

public void setThinAgg(UIAggregate thinAgg) {

    // if thinAgg is null, clear form.
    if (thinAgg == null) {
        clearForm();// ww w.  j  av  a 2s . c om
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug("setThinAgg(" + thinAgg + ")");
        logger.debug("       agg name: " + thinAgg.getName());
        logger.debug("agg description: " + thinAgg.getName());
        logger.debug("       agg type: " + (thinAgg.isAlgoAgg() ? Messages.getString("agg_type_advisor")
                : Messages.getString("agg_type_custom")));
        logger.debug("     attributes:");
        for (Attribute attrib : thinAgg.getAttributes()) {
            logger.debug("                " + attrib.getLabel());
        }
    }

    ArrayList<DimensionRowModel> newDimensionRowModels = new ArrayList<DimensionRowModel>();
    this.thinAgg = thinAgg;
    setName(thinAgg.getName());
    setDesc(thinAgg.getDescription());

    //ensure that these get fired by sending null as previous
    firePropertyChange("name", null, name);
    firePropertyChange("desc", null, desc);

    if (connectionModel.getSchema() != null) {
        for (Dimension dim : connectionModel.getSchema().getDimensions()) {

            DimensionRowModel rowModel = new DimensionRowModel();
            rowModel.setDimension(dim);
            newDimensionRowModels.add(rowModel);

            //setup listener to mark model dirty when a user changes the level selection
            rowModel.addPropertyChangeListener("selectedIndex", new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    setModified(true);
                }
            });

            rowModel.initSelected(thinAgg.getAttributes());
        }
        logger.debug("calling setDimensionRowModels with " + newDimensionRowModels);
        setDimensionRowModels(newDimensionRowModels);
    }
    setModified(false);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopButton.java

@Override
public void setAction(Action action) {
    if (action != this.action) {
        if (this.action != null) {
            this.action.removeOwner(this);
            this.action.removePropertyChangeListener(actionPropertyChangeListener);
        }//from  ww  w.  j  a  v a2s .com

        this.action = action;

        if (action != null) {
            String caption = action.getCaption();
            if (caption != null && getCaption() == null) {
                setCaption(caption);
            }

            String description = action.getDescription();
            if (description == null && action.getShortcutCombination() != null) {
                description = action.getShortcutCombination().format();
            }
            if (description != null && getDescription() == null) {
                setDescription(description);
            }

            setEnabled(action.isEnabled());
            setVisible(action.isVisible());

            if (action.getIcon() != null && getIcon() == null) {
                setIcon(action.getIcon());
            }

            action.addOwner(this);

            actionPropertyChangeListener = new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (Action.PROP_ICON.equals(evt.getPropertyName())) {
                        setIcon(DesktopButton.this.action.getIcon());
                    } else if (Action.PROP_CAPTION.equals(evt.getPropertyName())) {
                        setCaption(DesktopButton.this.action.getCaption());
                    } else if (Action.PROP_DESCRIPTION.equals(evt.getPropertyName())) {
                        setDescription(DesktopButton.this.action.getDescription());
                    } else if (Action.PROP_ENABLED.equals(evt.getPropertyName())) {
                        setEnabled(DesktopButton.this.action.isEnabled());
                    } else if (Action.PROP_VISIBLE.equals(evt.getPropertyName())) {
                        setVisible(DesktopButton.this.action.isVisible());
                    }
                }
            };
            action.addPropertyChangeListener(actionPropertyChangeListener);

            assignAutoDebugId();
        }
    }
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.actions.DownloadAction.java

/**
 * Downloads the selected files.//from w ww . ja  v  a2 s.  c  o  m
 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
 */
public void actionPerformed(ActionEvent e) {
    ImageDisplay node = model.getBrowser().getLastSelectedDisplay();
    if (node == null)
        return;

    JFrame f = DataBrowserAgent.getRegistry().getTaskBar().getFrame();

    int type = FileChooser.FOLDER_CHOOSER;

    FileChooser chooser = new FileChooser(f, type, FileChooser.DOWNLOAD_TEXT, FileChooser.DOWNLOAD_DESCRIPTION);

    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.DOWNLOAD_48));
    chooser.setApproveButtonText(FileChooser.DOWNLOAD_TEXT);
    chooser.setCheckOverride(true);
    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            FileChooser src = (FileChooser) evt.getSource();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
                String path = (String) evt.getNewValue();
                EventBus bus = DataBrowserAgent.getRegistry().getEventBus();
                bus.post(new DownloadEvent(new File(path), src.isOverride()));
            }
        }
    });
    chooser.centerDialog();
}

From source file:net.sf.jsignpdf.VisibleSignatureDialog.java

/** Creates new form VisibleSignatureDialog */
public VisibleSignatureDialog(java.awt.Frame parent, boolean modal, final BasicSignerOptions anOptions,
        final SignerFileChooser aFC) {
    super(parent, modal);
    options = anOptions;//from   w  ww  . j av  a  2s.c o  m
    fc = aFC;
    p2i = new Pdf2Image(options);
    initComponents();
    translateLabels();
    tfPage.getDocument().addDocumentListener(new PageNrDocumentListener());
    selectionImage.getRelRect().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (previewListenerDisabled)
                return;
            final RelRect tmpRect = selectionImage.getRelRect();
            if (pdfPageInfo == null || !tmpRect.isValid()) {
                return;
            }
            Float[] coords = tmpRect.getCoords();
            tfPosLLX.setText(String.valueOf(coords[0] * pdfPageInfo.getWidth()));
            tfPosLLY.setText(String.valueOf(coords[1] * pdfPageInfo.getHeight()));
            tfPosURX.setText(String.valueOf(coords[2] * pdfPageInfo.getWidth()));
            tfPosURY.setText(String.valueOf(coords[3] * pdfPageInfo.getHeight()));
        }
    });
    cbDisplayMode.setModel(new DefaultComboBoxModel(RenderMode.values()));
    extraInfo = new PdfExtraInfo(anOptions);
    previewDialog.add(selectionImage, java.awt.BorderLayout.CENTER);
    previewDialog.setModal(true);
    previewDialog.getRootPane().setDefaultButton(btnPreviewClose);
    GuiUtils.resizeAndCenter(previewDialog);
    getRootPane().setDefaultButton(btnClose);
}

From source file:com.totsp.sotu.app.ScreenAreaWatcher.java

/** Creates a new instance of ScreenWatcher */
public ScreenAreaWatcher(final Configuration config) throws AWTException {
    super();//from  w  w w. j a va2s .  c  o m
    this.config = config;
    System.out.println(config.getWidth() + "x" + config.getHeight());
    JPanel jp = null;

    JWindow top = new JWindow();
    top.setBackground(GREEN);
    top.setLocation(0, 0);
    top.setAlwaysOnTop(true);
    jp = new JPanel();
    jp.setBackground(GREEN);
    top.add(jp);
    top.pack();
    top.setSize(config.getWidth(), config.getBorderSize());

    JWindow bottom = new JWindow();
    bottom.setBackground(GREEN);
    bottom.setLocation(0, config.getHeight() - config.getBorderSize());
    bottom.setAlwaysOnTop(true);
    jp = new JPanel();
    jp.setBackground(GREEN);
    bottom.add(jp);
    bottom.pack();
    bottom.setSize(config.getWidth(), config.getBorderSize());

    JWindow left = new JWindow();
    left.setBackground(GREEN);
    left.setLocation(0, 0);
    left.setAlwaysOnTop(true);
    jp = new JPanel();
    jp.setBackground(GREEN);
    left.add(jp);
    left.pack();
    left.setSize(config.getBorderSize(), config.getHeight());

    JWindow right = new JWindow();
    right.setLocation(config.getWidth() - config.getBorderSize(), 0);
    right.setAlwaysOnTop(true);
    jp = new JPanel();
    jp.setBackground(GREEN);
    right.add(jp);
    right.pack();
    right.setSize(config.getBorderSize(), config.getHeight());

    top.setVisible(true);
    bottom.setVisible(true);
    left.setVisible(true);
    right.setVisible(true);

    windows = new JWindow[4];
    windows[0] = top;
    windows[1] = bottom;
    windows[2] = left;
    windows[3] = right;

    MouseInputAdapter adapter = new Adapter(windows);

    top.addMouseListener(adapter);
    top.addMouseMotionListener(adapter);
    bottom.addMouseListener(adapter);
    bottom.addMouseMotionListener(adapter);
    left.addMouseListener(adapter);
    left.addMouseMotionListener(adapter);
    right.addMouseListener(adapter);
    right.addMouseMotionListener(adapter);

    timer.schedule(new ImageUpdateTimerTask(this), 0, config.getMaxUpdateInterval());

    this.addPropertyChangeListener("image", new PropertyChangeListener() {
        HttpClient client = new HttpClient();

        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            BufferedImage img = (BufferedImage) propertyChangeEvent.getNewValue();
            try {
                File outputFile = File.createTempFile("save-" + System.currentTimeMillis(), ".png");
                JAI.create("filestore", img, outputFile.getCanonicalPath(), "PNG", null);
                System.out.println("Temp File:  " + outputFile.getCanonicalPath());
                MultipartPostMethod method = new MultipartPostMethod(
                        config.getServerUrl() + "/ImagePublishingServlet");
                method.addParameter("adminPassword", config.getAdminPassword());
                method.addParameter("conversation", config.getConversationName());
                method.addParameter("image", outputFile);
                client.executeMethod(method);

            } catch (Exception e) {
                System.err.println("Error handling image");
                e.printStackTrace();
            }
        }

    });
}