Search in sources :

Example 31 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project processing by processing.

the class WebFrame method requestContentHeight.

/*
  // Why this doesn't work inline above is beyond me
  static int getContentHeight(int width, String content) {
    JEditorPane dummy = new JEditorPane("text/html", content);
    dummy.setSize(width, Short.MAX_VALUE);
    return dummy.getPreferredSize().height;
  }
  */
// Unlike the static version above that uses an (already loaded) String for
// the content, using setPage() makes things run asynchronously, causing
// getContentHeight() to fail because it returns zero. Instead we make
// things 10x more complicated so that images will work.
void requestContentHeight(final int width, final URL url) {
    new Thread(new Runnable() {

        public void run() {
            final JEditorPane dummy = new JEditorPane();
            dummy.addPropertyChangeListener("page", new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    int high = dummy.getPreferredSize().height;
                    editorPane.setPreferredSize(new Dimension(width, high));
                    pack();
                    setLocationRelativeTo(null);
                    ready = true;
                }
            });
            try {
                dummy.setPage(url);
            } catch (IOException e) {
                e.printStackTrace();
            }
            dummy.setSize(width, Short.MAX_VALUE);
        }
    }).start();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) Dimension(java.awt.Dimension) IOException(java.io.IOException)

Example 32 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project robovm by robovm.

the class PropertyChangeSupportTest method testOldAndNewAreBothNull.

public void testOldAndNewAreBothNull() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog listener = new EventLog();
    support.addPropertyChangeListener(listener);
    PropertyChangeEvent nullToNull = new PropertyChangeEvent(bean, "a", null, null);
    support.firePropertyChange(nullToNull);
    assertEquals(Arrays.<PropertyChangeEvent>asList(nullToNull), listener.log);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeSupport(java.beans.PropertyChangeSupport)

Example 33 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project robovm by robovm.

the class PropertyChangeSupportTest method testAddingAListenerActuallyAddsAProxy.

public void testAddingAListenerActuallyAddsAProxy() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    PropertyChangeListener listener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
        }
    };
    support.addPropertyChangeListener("a", listener);
    PropertyChangeListenerProxy p1 = (PropertyChangeListenerProxy) support.getPropertyChangeListeners()[0];
    assertEquals(PropertyChangeListenerProxy.class, p1.getClass());
    // weird but consistent with the RI
    assertTrue(p1 != listener);
    assertEquals("a", p1.getPropertyName());
    assertEquals(listener, p1.getListener());
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeSupport(java.beans.PropertyChangeSupport) PropertyChangeListenerProxy(java.beans.PropertyChangeListenerProxy)

Example 34 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project robovm by robovm.

the class PropertyChangeSupportTest method testOldAndNewAreTheSame.

public void testOldAndNewAreTheSame() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog listener = new EventLog();
    support.addPropertyChangeListener(listener);
    PropertyChangeEvent xToX = new PropertyChangeEvent(bean, "a", "x", new String("x"));
    support.firePropertyChange(xToX);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), listener.log);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeSupport(java.beans.PropertyChangeSupport)

Example 35 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project frostwire by frostwire.

the class BaseFileChooserUI method installComponents.

public void installComponents(JFileChooser fc) {
    FileSystemView fsv = fc.getFileSystemView();
    fc.setBorder(new EmptyBorder(12, 12, 11, 11));
    fc.setLayout(new BorderLayout(0, 11));
    filePane = new FilePaneEx(new MetalFileChooserUIAccessor());
    fc.addPropertyChangeListener(filePane);
    updateUseShellFolder();
    // ********************************* //
    // **** Construct the top panel **** //
    // ********************************* //
    // Directory manipulation buttons
    JPanel topPanel = new JPanel(new BorderLayout(11, 0));
    JPanel topButtonPanel = new JPanel();
    topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS));
    topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS);
    // Add the top panel to the fileChooser
    fc.add(topPanel, BorderLayout.NORTH);
    // ComboBox Label
    lookInLabel = new JLabel(lookInLabelText);
    lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
    topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
    // CurrentDir ComboBox
    directoryComboBox = new JComboBox<Object>() {

        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            // Must be small enough to not affect total width.
            d.width = 150;
            return d;
        }
    };
    directoryComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, lookInLabelText);
    directoryComboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    lookInLabel.setLabelFor(directoryComboBox);
    directoryComboBoxModel = createDirectoryComboBoxModel(fc);
    directoryComboBox.setModel(directoryComboBoxModel);
    directoryComboBox.addActionListener(directoryComboBoxAction);
    directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
    directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
    directoryComboBox.setMaximumRowCount(8);
    topPanel.add(directoryComboBox, BorderLayout.CENTER);
    // Up Button
    JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
    upFolderButton.setText(null);
    upFolderButton.setIcon(upFolderIcon);
    upFolderButton.setToolTipText(upFolderToolTipText);
    upFolderButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, upFolderAccessibleName);
    upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    upFolderButton.setMargin(shrinkwrap);
    topButtonPanel.add(upFolderButton);
    topButtonPanel.add(Box.createRigidArea(hstrut5));
    // Home Button
    File homeDir = fsv.getHomeDirectory();
    String toolTipText = homeFolderToolTipText;
    if (fsv.isRoot(homeDir)) {
        // Probably "Desktop".
        toolTipText = getFileView(fc).getName(homeDir);
    }
    JButton b = new JButton(homeFolderIcon);
    b.setToolTipText(toolTipText);
    b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, homeFolderAccessibleName);
    b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    b.setMargin(shrinkwrap);
    b.addActionListener(getGoHomeAction());
    topButtonPanel.add(b);
    topButtonPanel.add(Box.createRigidArea(hstrut5));
    // New Directory Button
    if (!UIManager.getBoolean("FileChooser.readOnly")) {
        b = new JButton(filePane.getNewFolderAction());
        b.setText(null);
        b.setIcon(newFolderIcon);
        b.setToolTipText(newFolderToolTipText);
        b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, newFolderAccessibleName);
        b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
        b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
        b.setMargin(shrinkwrap);
    }
    topButtonPanel.add(b);
    topButtonPanel.add(Box.createRigidArea(hstrut5));
    // View button group
    ButtonGroup viewButtonGroup = new ButtonGroup();
    // List Button
    listViewButton = new JToggleButton(listViewIcon);
    listViewButton.setToolTipText(listViewButtonToolTipText);
    listViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, listViewButtonAccessibleName);
    listViewButton.setSelected(true);
    listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    listViewButton.setMargin(shrinkwrap);
    listViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
    topButtonPanel.add(listViewButton);
    viewButtonGroup.add(listViewButton);
    // Details Button
    detailsViewButton = new JToggleButton(detailsViewIcon);
    detailsViewButton.setToolTipText(detailsViewButtonToolTipText);
    detailsViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, detailsViewButtonAccessibleName);
    detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
    detailsViewButton.setMargin(shrinkwrap);
    detailsViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
    topButtonPanel.add(detailsViewButton);
    viewButtonGroup.add(detailsViewButton);
    filePane.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent e) {
            if ("viewType".equals(e.getPropertyName())) {
                int viewType = filePane.getViewType();
                switch(viewType) {
                    case FilePane.VIEWTYPE_LIST:
                        listViewButton.setSelected(true);
                        break;
                    case FilePane.VIEWTYPE_DETAILS:
                        detailsViewButton.setSelected(true);
                        break;
                }
            }
        }
    });
    // ************************************** //
    // ******* Add the directory pane ******* //
    // ************************************** //
    fc.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS);
    JComponent accessory = fc.getAccessory();
    if (accessory != null) {
        getAccessoryPanel().add(accessory);
    }
    filePane.setPreferredSize(LIST_PREF_SIZE);
    fc.add(filePane, BorderLayout.CENTER);
    // ********************************** //
    // **** Construct the bottom panel ** //
    // ********************************** //
    JPanel bottomPanel = getBottomPanel();
    bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
    fc.add(bottomPanel, BorderLayout.SOUTH);
    // FileName label and textfield
    JPanel fileNamePanel = new JPanel();
    fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
    bottomPanel.add(fileNamePanel);
    bottomPanel.add(Box.createRigidArea(vstrut5));
    fileNameLabel = new AlignedLabel();
    populateFileNameLabel();
    fileNamePanel.add(fileNameLabel);
    fileNameTextField = new JTextField(35) {

        /**
         */
        private static final long serialVersionUID = -8830541272140418635L;

        public Dimension getMaximumSize() {
            return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
        }
    };
    fileNamePanel.add(fileNameTextField);
    fileNameLabel.setLabelFor(fileNameTextField);
    fileNameTextField.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            if (!getFileChooser().isMultiSelectionEnabled()) {
                filePane.clearSelection();
            }
        }
    });
    if (fc.isMultiSelectionEnabled()) {
        setFileName(fileNameString(fc.getSelectedFiles()));
    } else {
        setFileName(fileNameString(fc.getSelectedFile()));
    }
    // Filetype label and combobox
    JPanel filesOfTypePanel = new JPanel();
    filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS));
    bottomPanel.add(filesOfTypePanel);
    AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText);
    filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
    filesOfTypePanel.add(filesOfTypeLabel);
    filterComboBoxModel = createFilterComboBoxModel();
    fc.addPropertyChangeListener(filterComboBoxModel);
    filterComboBox = new JComboBox<Object>(filterComboBoxModel);
    filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, filesOfTypeLabelText);
    filesOfTypeLabel.setLabelFor(filterComboBox);
    filterComboBox.setRenderer(createFilterComboBoxRenderer());
    filesOfTypePanel.add(filterComboBox);
    // buttons
    getButtonPanel().setLayout(new ButtonAreaLayout());
    approveButton = new JButton(getApproveButtonText(fc));
    // Note: Metal does not use mnemonics for approve and cancel
    approveButton.addActionListener(getApproveSelectionAction());
    approveButton.setToolTipText(getApproveButtonToolTipText(fc));
    getButtonPanel().add(approveButton);
    cancelButton = new JButton(cancelButtonText);
    cancelButton.setToolTipText(cancelButtonToolTipText);
    cancelButton.addActionListener(getCancelSelectionAction());
    getButtonPanel().add(cancelButton);
    if (fc.getControlButtonsAreShown()) {
        addControlButtons();
    }
    groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
}
Also used : FileSystemView(javax.swing.filechooser.FileSystemView) PropertyChangeListener(java.beans.PropertyChangeListener) EmptyBorder(javax.swing.border.EmptyBorder) PropertyChangeEvent(java.beans.PropertyChangeEvent) File(java.io.File)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)574 PropertyChangeListener (java.beans.PropertyChangeListener)349 ActionEvent (java.awt.event.ActionEvent)42 JPanel (javax.swing.JPanel)36 ActionListener (java.awt.event.ActionListener)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)31 PropertyVetoException (java.beans.PropertyVetoException)24 JLabel (javax.swing.JLabel)24 File (java.io.File)23 BorderLayout (java.awt.BorderLayout)22 List (java.util.List)21 IOException (java.io.IOException)19 Dimension (java.awt.Dimension)16 ChangeEvent (javax.swing.event.ChangeEvent)15 PropertyChangeSupport (java.beans.PropertyChangeSupport)13 ChangeListener (javax.swing.event.ChangeListener)13 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)13 JScrollPane (javax.swing.JScrollPane)12 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)12