Search in sources :

Example 51 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.

the class JOptionPane method createInternalFrame.

/**
     * Creates and returns an instance of <code>JInternalFrame</code>.
     * The internal frame is created with the specified title,
     * and wrapping the <code>JOptionPane</code>.
     * The returned <code>JInternalFrame</code> is
     * added to the <code>JDesktopPane</code> ancestor of
     * <code>parentComponent</code>, or components
     * parent if one its ancestors isn't a <code>JDesktopPane</code>,
     * or if <code>parentComponent</code>
     * doesn't have a parent then a <code>RuntimeException</code> is thrown.
     *
     * @param parentComponent  the parent <code>Component</code> for
     *          the internal frame
     * @param title    the <code>String</code> to display in the
     *          frame's title bar
     * @return a <code>JInternalFrame</code> containing a
     *          <code>JOptionPane</code>
     * @exception RuntimeException if <code>parentComponent</code> does
     *          not have a valid parent
     */
public JInternalFrame createInternalFrame(Component parentComponent, String title) {
    Container parent = JOptionPane.getDesktopPaneForComponent(parentComponent);
    if (parent == null && (parentComponent == null || (parent = parentComponent.getParent()) == null)) {
        throw new RuntimeException("JOptionPane: parentComponent does " + "not have a valid parent");
    }
    // Option dialogs should be closable only
    final JInternalFrame iFrame = new JInternalFrame(title, false, true, false, false);
    iFrame.putClientProperty("JInternalFrame.frameType", "optionDialog");
    iFrame.putClientProperty("JInternalFrame.messageType", Integer.valueOf(getMessageType()));
    iFrame.addInternalFrameListener(new InternalFrameAdapter() {

        public void internalFrameClosing(InternalFrameEvent e) {
            if (getValue() == UNINITIALIZED_VALUE) {
                setValue(null);
            }
        }
    });
    addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            // (newValue = null in that case).  Otherwise, close the dialog.
            if (iFrame.isVisible() && event.getSource() == JOptionPane.this && event.getPropertyName().equals(VALUE_PROPERTY)) {
                // Use reflection to get Container.stopLWModal().
                try {
                    Method method = AccessController.doPrivileged(new ModalPrivilegedAction(Container.class, "stopLWModal"));
                    if (method != null) {
                        method.invoke(iFrame, (Object[]) null);
                    }
                } catch (IllegalAccessException ex) {
                } catch (IllegalArgumentException ex) {
                } catch (InvocationTargetException ex) {
                }
                try {
                    iFrame.setClosed(true);
                } catch (java.beans.PropertyVetoException e) {
                }
                iFrame.setVisible(false);
            }
        }
    });
    iFrame.getContentPane().add(this, BorderLayout.CENTER);
    if (parent instanceof JDesktopPane) {
        parent.add(iFrame, JLayeredPane.MODAL_LAYER);
    } else {
        parent.add(iFrame, BorderLayout.CENTER);
    }
    Dimension iFrameSize = iFrame.getPreferredSize();
    Dimension rootSize = parent.getSize();
    Dimension parentSize = parentComponent.getSize();
    iFrame.setBounds((rootSize.width - iFrameSize.width) / 2, (rootSize.height - iFrameSize.height) / 2, iFrameSize.width, iFrameSize.height);
    // We want dialog centered relative to its parent component
    Point iFrameCoord = SwingUtilities.convertPoint(parentComponent, 0, 0, parent);
    int x = (parentSize.width - iFrameSize.width) / 2 + iFrameCoord.x;
    int y = (parentSize.height - iFrameSize.height) / 2 + iFrameCoord.y;
    // If possible, dialog should be fully visible
    int ovrx = x + iFrameSize.width - rootSize.width;
    int ovry = y + iFrameSize.height - rootSize.height;
    x = Math.max((ovrx > 0 ? x - ovrx : x), 0);
    y = Math.max((ovry > 0 ? y - ovry : y), 0);
    iFrame.setBounds(x, y, iFrameSize.width, iFrameSize.height);
    parent.validate();
    try {
        iFrame.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {
    }
    return iFrame;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) InternalFrameEvent(javax.swing.event.InternalFrameEvent) Method(java.lang.reflect.Method) Dimension(java.awt.Dimension) Point(java.awt.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) Point(java.awt.Point) Container(java.awt.Container) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter)

Example 52 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.

the class JOptionPane method initDialog.

private void initDialog(final JDialog dialog, int style, Component parentComponent) {
    dialog.setComponentOrientation(this.getComponentOrientation());
    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(this, BorderLayout.CENTER);
    dialog.setResizable(false);
    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.setUndecorated(true);
            getRootPane().setWindowDecorationStyle(style);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parentComponent);
    final PropertyChangeListener listener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            // (newValue = null in that case).  Otherwise, close the dialog.
            if (dialog.isVisible() && event.getSource() == JOptionPane.this && (event.getPropertyName().equals(VALUE_PROPERTY)) && event.getNewValue() != null && event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
                dialog.setVisible(false);
            }
        }
    };
    WindowAdapter adapter = new WindowAdapter() {

        private boolean gotFocus = false;

        public void windowClosing(WindowEvent we) {
            setValue(null);
        }

        public void windowClosed(WindowEvent e) {
            removePropertyChangeListener(listener);
            dialog.getContentPane().removeAll();
        }

        public void windowGainedFocus(WindowEvent we) {
            // Once window gets focus, set initial focus
            if (!gotFocus) {
                selectInitialValue();
                gotFocus = true;
            }
        }
    };
    dialog.addWindowListener(adapter);
    dialog.addWindowFocusListener(adapter);
    dialog.addComponentListener(new ComponentAdapter() {

        public void componentShown(ComponentEvent ce) {
            // reset value to ensure closing works properly
            setValue(JOptionPane.UNINITIALIZED_VALUE);
        }
    });
    addPropertyChangeListener(listener);
}
Also used : Container(java.awt.Container) PropertyChangeEvent(java.beans.PropertyChangeEvent) BorderLayout(java.awt.BorderLayout) PropertyChangeListener(java.beans.PropertyChangeListener) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 53 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.

the class BasicLookAndFeel method installAWTEventListener.

void installAWTEventListener() {
    if (invocator == null) {
        invocator = new AWTEventHelper();
        needsEventHelper = true;
        // Add a PropertyChangeListener to our AppContext so we're alerted
        // when the AppContext is disposed(), at which time this laf should
        // be uninitialize()d.
        disposer = new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent prpChg) {
                uninitialize();
            }
        };
        AppContext.getAppContext().addPropertyChangeListener(AppContext.GUI_DISPOSED, disposer);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 54 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.

the class EnumEditor method setValue.

public void setValue(Object value) {
    if ((value != null) && !this.type.isInstance(value)) {
        throw new IllegalArgumentException("Unsupported value: " + value);
    }
    Object oldValue;
    PropertyChangeListener[] listeners;
    synchronized (this.listeners) {
        oldValue = this.value;
        this.value = value;
        if ((value == null) ? oldValue == null : value.equals(oldValue)) {
            // do not fire event if value is not changed
            return;
        }
        int size = this.listeners.size();
        if (size == 0) {
            // do not fire event if there are no any listener
            return;
        }
        listeners = this.listeners.toArray(new PropertyChangeListener[size]);
    }
    PropertyChangeEvent event = new PropertyChangeEvent(this, null, oldValue, value);
    for (PropertyChangeListener listener : listeners) {
        listener.propertyChange(event);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 55 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project intellij-plugins by JetBrains.

the class JstdServerSettingsTab method listenForChanges.

private void listenForChanges() {
    myPortField.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            update();
        }
    });
    myBrowserTimeoutSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            update();
        }
    });
    myRunnerModeComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            update();
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Aggregations

PropertyChangeListener (java.beans.PropertyChangeListener)228 PropertyChangeEvent (java.beans.PropertyChangeEvent)197 ActionEvent (java.awt.event.ActionEvent)27 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)27 ActionListener (java.awt.event.ActionListener)26 IFigure (org.eclipse.draw2d.IFigure)25 JPanel (javax.swing.JPanel)21 ArrayList (java.util.ArrayList)16 JLabel (javax.swing.JLabel)13 BorderLayout (java.awt.BorderLayout)12 Dimension (java.awt.Dimension)12 JButton (javax.swing.JButton)12 BoxLayout (javax.swing.BoxLayout)10 GridData (org.eclipse.swt.layout.GridData)10 GridLayout (org.eclipse.swt.layout.GridLayout)10 File (java.io.File)9 Composite (org.eclipse.swt.widgets.Composite)9 Test (org.junit.Test)9 IOException (java.io.IOException)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8