Search in sources :

Example 16 with PropertyChangeEvent

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

the class ListenersWithSM method main.

@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
    boolean granted = args[0].equals("grant");
    // need to get reference to LogManager before setting SecurityManager
    LogManager logman = LogManager.getLogManager();
    // set policy and enable security manager
    if (granted) {
        String testSrc = System.getProperty("test.src");
        if (testSrc == null)
            testSrc = ".";
        System.setProperty("java.security.policy", Paths.get(testSrc).resolve("java.policy").toString());
    }
    System.setSecurityManager(new SecurityManager());
    PropertyChangeListener listener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
        }
    };
    if (granted) {
        // permission granted, no security exception expected
        logman.addPropertyChangeListener(listener);
        logman.removePropertyChangeListener(listener);
    } else {
        // denied
        try {
            logman.addPropertyChangeListener(listener);
            throw new RuntimeException("SecurityException expected");
        } catch (SecurityException expected) {
        }
        try {
            logman.removePropertyChangeListener(listener);
            throw new RuntimeException("SecurityException expected");
        } catch (SecurityException expected) {
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) LogManager(java.util.logging.LogManager)

Example 17 with PropertyChangeEvent

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

the class TestPropertyChangeSupport method test.

private static void test(int step, int listeners, int attempts) {
    TestPropertyChangeSupport test = new TestPropertyChangeSupport();
    PropertyChangeSupport pcs = new PropertyChangeSupport(test);
    PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);
    PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);
    long time1 = System.currentTimeMillis();
    for (int i = 0; i < listeners; i++) {
        pcs.addPropertyChangeListener(test);
        pcs.addPropertyChangeListener(NAME, test);
    }
    long time2 = System.currentTimeMillis();
    for (int i = 0; i < attempts; i++) {
        pcs.firePropertyChange(eventNull);
        pcs.firePropertyChange(eventName);
    }
    long time3 = System.currentTimeMillis();
    // time of adding the listeners
    time1 = time2 - time1;
    // time of firing the events
    time2 = time3 - time2;
    System.out.println("Step: " + step + "; Listeners: " + listeners + "; Attempts: " + attempts + "; Time (ms): " + time1 + "/" + time2);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeSupport(java.beans.PropertyChangeSupport)

Example 18 with PropertyChangeEvent

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

the class TestVetoableChangeSupport method test.

private static void test(int step, int listeners, int attempts) throws PropertyVetoException {
    TestVetoableChangeSupport test = new TestVetoableChangeSupport();
    VetoableChangeSupport vcs = new VetoableChangeSupport(test);
    PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);
    PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);
    long time1 = System.currentTimeMillis();
    for (int i = 0; i < listeners; i++) {
        vcs.addVetoableChangeListener(test);
        vcs.addVetoableChangeListener(NAME, test);
    }
    long time2 = System.currentTimeMillis();
    for (int i = 0; i < attempts; i++) {
        vcs.fireVetoableChange(eventNull);
        vcs.fireVetoableChange(eventName);
    }
    long time3 = System.currentTimeMillis();
    // time of adding the listeners
    time1 = time2 - time1;
    // time of firing the events
    time2 = time3 - time2;
    System.out.println("Step: " + step + "; Listeners: " + listeners + "; Attempts: " + attempts + "; Time (ms): " + time1 + "/" + time2);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VetoableChangeSupport(java.beans.VetoableChangeSupport)

Example 19 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project azure-tools-for-java by Microsoft.

the class SparkSubmissionContentPanel method addSparkClustersLineItem.

private void addSparkClustersLineItem() {
    JLabel sparkClusterLabel = new JLabel("Spark clusters(Linux only)");
    sparkClusterLabel.setToolTipText("The HDInsight Spark cluster you want to submit your application to. Only Linux cluster is supported.");
    GridBagConstraints c11 = new GridBagConstraints();
    c11.gridx = 0;
    c11.gridy = 0;
    c11.insets = new Insets(margin, margin, 0, margin);
    add(sparkClusterLabel, new GridBagConstraints(0, displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin, margin, 0, margin), 0, 0));
    clustersListComboBox = new ComboboxWithBrowseButton();
    clustersListComboBox.setButtonIcon(StreamUtil.getImageResourceFile(REFRESH_BUTTON_PATH));
    clustersListComboBox.getButton().setToolTipText("Refresh");
    clustersListComboBox.getButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Cursor cursor = getCursor();
            setCursor(new Cursor(Cursor.WAIT_CURSOR));
            List<IClusterDetail> clusterDetails = ClusterManagerEx.getInstance().getClusterDetails(submitModel.getProject());
            setCursor(cursor);
            submitModel.setClusterComboBoxModel(clusterDetails);
        }
    });
    clustersListComboBox.getComboBox().setToolTipText("The HDInsight Spark cluster you want to submit your application to. Only Linux cluster is supported.");
    clustersListComboBox.getComboBox().addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName() == "model" && evt.getNewValue() instanceof DefaultComboBoxModel) {
                int size = ((DefaultComboBoxModel) evt.getNewValue()).getSize();
                setVisibleForFixedErrorMessageLabel(ErrorMessageLabelTag.ClusterName.ordinal(), size <= 0);
            }
        }
    });
    add(clustersListComboBox, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(margin, margin, 0, margin), 0, 0));
    errorMessageLabels[ErrorMessageLabelTag.ClusterName.ordinal()] = new JLabel("Cluster Name Should not be null");
    errorMessageLabels[ErrorMessageLabelTag.ClusterName.ordinal()].setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
    clustersListComboBox.getComboBox().addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setVisibleForFixedErrorMessageLabel(0, clustersListComboBox.getComboBox().getItemCount() == 0);
        }
    });
    add(errorMessageLabels[ErrorMessageLabelTag.ClusterName.ordinal()], new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) ItemEvent(java.awt.event.ItemEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) ActionListener(java.awt.event.ActionListener) ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) ArrayList(java.util.ArrayList) List(java.util.List) ItemListener(java.awt.event.ItemListener)

Example 20 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project intellij-community by JetBrains.

the class LafManagerImpl method initComponent.

@Override
public void initComponent() {
    if (myCurrentLaf != null) {
        final UIManager.LookAndFeelInfo laf = findLaf(myCurrentLaf.getClassName());
        if (laf != null) {
            boolean needUninstall = UIUtil.isUnderDarcula();
            // setup default LAF or one specified by readExternal.
            setCurrentLookAndFeel(laf);
            updateWizardLAF(needUninstall);
        }
    }
    updateUI();
    if (SystemInfo.isXWindow) {
        PropertyChangeListener themeChangeListener = new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent evt) {
                //noinspection SSBasedInspection
                SwingUtilities.invokeLater(() -> {
                    fixGtkPopupStyle();
                    patchGtkDefaults(UIManager.getLookAndFeelDefaults());
                });
            }
        };
        Toolkit.getDefaultToolkit().addPropertyChangeListener(GNOME_THEME_PROPERTY_NAME, themeChangeListener);
        Disposer.register(this, new Disposable() {

            @Override
            public void dispose() {
                Toolkit.getDefaultToolkit().removePropertyChangeListener(GNOME_THEME_PROPERTY_NAME, themeChangeListener);
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

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