Java Code Examples for java.beans.PropertyChangeListener

The following examples show how to use java.beans.PropertyChangeListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
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);
    }
}
 
Example 2
public void addHubPropertyChangeListener() {

        if (hubModel == null) {
            logger.debug("Cannot add property change listener to null model.");
            return;
        }

        addListener(hubModel.getClass().getCanonicalName(), hubModel.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(@NonNull PropertyChangeEvent event) {
                if (event.getPropertyName().equals(HubConnection.ATTR_LASTCHANGE)) {
                    if (isPresenting()) {
                        getPresentedView().setHubLastChangedTime(getHubLastChangedTime());
                    }
                }
            }
        }));
    }
 
Example 3
Source Project: jdk1.8-source-analysis   Source File: BasicLookAndFeel.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
public void showDataset() throws IOException {
  if (fmrcInv == null)
    return;
  if (dialog == null) {
    dialog = new Fmrc2Dialog(null);
    dialog.pack();
    dialog.addPropertyChangeListener("OK", new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent evt) {
        Fmrc2Dialog.Data data = (Fmrc2Dialog.Data) evt.getNewValue();
        if ((data.type == null) || (data.where == null))
          return;
        try {
          processDialog(data);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    });
  }
  dialog.setFmrc(fmrc);
  dialog.setVisible(true);
}
 
Example 5
Source Project: openjdk-jdk8u   Source File: bug6994419.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {

            JLayer<JComponent> l = new JLayer<JComponent>(new JButton());

            l.removeAll();

            l.addPropertyChangeListener(new PropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent evt) {
                    throw new RuntimeException("Property change event was unexpectedly fired");
                }
            });

            l.removeAll();
        }
    });
}
 
Example 6
/**
 * Gets the PropertyChangeListener
 * (if any) of the specified child
 * @param child the specified child
 * @return the PropertyChangeListener (if any) of the specified child
 */
protected static final PropertyChangeListener getChildPropertyChangeListener(Object child) {
    try {
        return (PropertyChangeListener)child;
    } catch (ClassCastException cce) {
        return null;
    }
}
 
Example 7
public Map<String, Object> getReferences() {
    ObservableMap map = new ObservableMap(getProject().getReferences());
    map.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            getProject().addReference(event.getPropertyName(), event.getNewValue());
        }
    });

    @SuppressWarnings("unchecked") Map<String, Object> castMap = (Map<String, Object>) map;
    return castMap;
}
 
Example 8
private static void addPropertyChangeListenerIfNecessary() {
    if (AppContext.getAppContext().get(PROPERTY_CHANGE_LISTENER_KEY) ==
        null) {
        PropertyChangeListener focusListener =
            new FocusPropertyChangeListener();

        AppContext.getAppContext().put(PROPERTY_CHANGE_LISTENER_KEY,
            focusListener);

        KeyboardFocusManager.getCurrentKeyboardFocusManager().
            addPropertyChangeListener(focusListener);
    }
}
 
Example 9
Source Project: JsDroidCmd   Source File: Context.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private void firePropertyChangeImpl(Object listeners, String property,
                                    Object oldValue, Object newValue)
{
    for (int i = 0; ; ++i) {
        Object l = Kit.getListener(listeners, i);
        if (l == null)
            break;
        if (l instanceof PropertyChangeListener) {
            PropertyChangeListener pcl = (PropertyChangeListener)l;
            pcl.propertyChange(new PropertyChangeEvent(
                this, property, oldValue, newValue));
        }
    }
}
 
Example 10
Source Project: CXTouch   Source File: RowHeaderList.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new row header list.
 */
JList getRowHeadList() {
    int tableRowCount = getModel().getSize();
    final PrivateList rowHeader = new PrivateList(tableRowCount);

    rowHeader.setFixedCellHeight(getFixedCellHeight());

    RowHeaderRenderer cellRender = new RowHeaderRenderer(this);
    rowHeader.setCellRenderer(cellRender);
    int width = 10;
    if (tableRowCount > 0) {
        width = (int) cellRender.getListCellRendererComponent(rowHeader, null, tableRowCount - 1, false, false)
                .getPreferredSize().getWidth() + 16;
    }
    rowHeader.setFixedCellWidth(width);

    addPropertyChangeListener(new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
              if (evt.getPropertyName().equals("fixedCellHeight")) {
                  rowHeader.setFixedCellHeight(getFixedCellHeight());
              }

          }

      }
    );

    return rowHeader;
}
 
Example 11
private static void check(PropertyChangeListener listener, int index) {
    if (!(listener instanceof TestSerialization))
        throw new Error("Unexpected listener: " + listener);

    TestSerialization object = (TestSerialization)listener;
    if (index != object.index)
        throw new Error("Unexpected index: " + index + " != " + object.index);
}
 
Example 12
Source Project: JDKSourceCode1.8   Source File: Toolkit.java    License: MIT License 5 votes vote down vote up
@Override
public synchronized PropertyChangeListener[] getPropertyChangeListeners()
{
    PropertyChangeSupport pcs = (PropertyChangeSupport)
            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
    if (null != pcs) {
        return pcs.getPropertyChangeListeners();
    } else {
        return new PropertyChangeListener[0];
    }
}
 
Example 13
Source Project: jdk8u60   Source File: Toolkit.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void removePropertyChangeListener(
        String propertyName,
        PropertyChangeListener listener)
{
    PropertyChangeSupport pcs = (PropertyChangeSupport)
            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
    if (null != pcs) {
        pcs.removePropertyChangeListener(propertyName, listener);
    }
}
 
Example 14
private Component createCenterPanel() {
    splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    splitter.setTopComponent(createMainGradlePanel());
    splitter.setBottomComponent(outputPanelLord.getMainPanel());

    splitter.setContinuousLayout(true);

    //This little bit of tedium is so we can set our size based on window's size. This listens
    //for when the window is actually shown. It then adds a listen to store the location.
    splitter.addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if (HierarchyEvent.SHOWING_CHANGED == (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)) {
                splitter.removeHierarchyListener(this); //we only want the first one of these, so remove ourselves as a listener.
                Window window = SwingUtilities.getWindowAncestor(splitter);
                if (window != null) {
                    Dimension dimension = window.getSize();
                    int halfHeight = dimension.height / 2; //we'll just make ourselves half the height of the window
                    splitter.setDividerLocation(halfHeight);
                }
                PreferencesAssistant.restoreSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);

                //Now that we're visible, this is so we save the location when the splitter is moved.
                splitter.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        if (JSplitPane.DIVIDER_LOCATION_PROPERTY.equals(evt.getPropertyName())) {
                            PreferencesAssistant.saveSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);
                        }
                    }
                });
            }
        }
    });

    splitter.setResizeWeight(1);   //this keeps the bottom the same size when resizing the window. Extra space is added/removed from the top.

    return splitter;
}
 
Example 15
Source Project: TencentKona-8   Source File: TestListeners.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    PropertyChangeSupport pcs = new PropertyChangeSupport(TestListeners.class);
    pcs.addPropertyChangeListener(new TestListeners(0));
    pcs.addPropertyChangeListener(NAME, new TestListeners(2));
    pcs.addPropertyChangeListener(new TestListeners(1));
    pcs.addPropertyChangeListener(NAME, new PropertyChangeListenerProxy(NAME, new TestListeners(3)));


    current = 0;
    pcs.firePropertyChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);

    current = 0;
    pcs.firePropertyChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);


    PropertyChangeListener[] all = pcs.getPropertyChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    PropertyChangeListener[] named = pcs.getPropertyChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    PropertyChangeListener[] other = pcs.getPropertyChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);

    pcs.removePropertyChangeListener(new TestListeners(0));
    pcs.removePropertyChangeListener(new TestListeners(1));
    pcs.removePropertyChangeListener(NAME, new TestListeners(2));
    pcs.removePropertyChangeListener(NAME, new PropertyChangeListenerProxy(NAME, new TestListeners(3)));

    all = pcs.getPropertyChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    named = pcs.getPropertyChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    other = pcs.getPropertyChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}
 
Example 16
Source Project: Tomcat8-Source-Read   Source File: FailedContext.java    License: MIT License 4 votes vote down vote up
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) { /* NO-OP */ }
 
Example 17
protected PropertyChangeListener createPropertyChangeListener() {
    return getHandler();
}
 
Example 18
Source Project: blog-codes   Source File: EditorActions.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 
 */
public TogglePropertyItem(final Object target, String name,
		final String fieldname, final boolean refresh,
		ActionListener listener)
{
	super(name);

	// Since action listeners are processed last to first we add the given
	// listener here which means it will be processed after the one below
	if (listener != null)
	{
		addActionListener(listener);
	}

	addActionListener(new ActionListener()
	{
		/**
		 * 
		 */
		public void actionPerformed(ActionEvent e)
		{
			execute(target, fieldname, refresh);
		}
	});

	PropertyChangeListener propertyChangeListener = new PropertyChangeListener()
	{

		/*
		 * (non-Javadoc)
		 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
		 */
		public void propertyChange(PropertyChangeEvent evt)
		{
			if (evt.getPropertyName().equalsIgnoreCase(fieldname))
			{
				update(target, fieldname);
			}
		}
	};

	if (target instanceof mxGraphComponent)
	{
		((mxGraphComponent) target)
				.addPropertyChangeListener(propertyChangeListener);
	}
	else if (target instanceof mxGraph)
	{
		((mxGraph) target)
				.addPropertyChangeListener(propertyChangeListener);
	}

	update(target, fieldname);
}
 
Example 19
/**
 * Constructs a new, initially invisible {@code JLightweightFrame}
 * instance.
 */
public JLightweightFrame() {
    super();
    copyBufferEnabled = "true".equals(AccessController.
        doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true")));

    add(rootPane, BorderLayout.CENTER);
    setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
    if (getGraphicsConfiguration().isTranslucencyCapable()) {
        setBackground(new Color(0, 0, 0, 0));
    }

    layoutSizeListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent e) {
            Dimension d = (Dimension)e.getNewValue();

            if ("preferredSize".equals(e.getPropertyName())) {
                content.preferredSizeChanged(d.width, d.height);

            } else if ("maximumSize".equals(e.getPropertyName())) {
                content.maximumSizeChanged(d.width, d.height);

            } else if ("minimumSize".equals(e.getPropertyName())) {
                content.minimumSizeChanged(d.width, d.height);
            }
        }
    };

    repaintListener = (JComponent c, int x, int y, int w, int h) -> {
        Window jlf = SwingUtilities.getWindowAncestor(c);
        if (jlf != JLightweightFrame.this) {
            return;
        }
        Point p = SwingUtilities.convertPoint(c, x, y, jlf);
        Rectangle r = new Rectangle(p.x, p.y, w, h).intersection(
                new Rectangle(0, 0, bbImage.getWidth() / scaleFactor,
                              bbImage.getHeight() / scaleFactor));

        if (!r.isEmpty()) {
            notifyImageUpdated(r.x, r.y, r.width, r.height);
        }
    };

    SwingAccessor.getRepaintManagerAccessor().addRepaintListener(
        RepaintManager.currentManager(this), repaintListener);
}
 
Example 20
protected PropertyChangeListener createPropertyChangeListener() {
    return new PropertyHandler();
}
 
Example 21
@Override
protected PropertyChangeListener createPropertyChangeListener(JSlider slider) {
	return new CSUIPropertyChangeHandler();
}
 
Example 22
Source Project: TencentKona-8   Source File: Test4682386.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void removePropertyChangeListener(PropertyChangeListener listener) {
    this.pcs.removePropertyChangeListener(listener);
}
 
Example 23
Source Project: ghidra   Source File: AnalysisOptionsEditor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setOptionsPropertyChangeListener(PropertyChangeListener listener) {
	this.listener = listener;
}
 
Example 24
Source Project: jdk1.8-source-analysis   Source File: BasicToolTipUI.java    License: Apache License 2.0 4 votes vote down vote up
private PropertyChangeListener createPropertyChangeListener(JComponent c) {
    if (sharedPropertyChangedListener == null) {
        sharedPropertyChangedListener = new PropertyChangeHandler();
    }
    return sharedPropertyChangedListener;
}
 
Example 25
Source Project: openjdk-jdk8u   Source File: Test4353056.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void addPropertyChangeListener(PropertyChangeListener listener) {
    this.pcs.addPropertyChangeListener(listener);
}
 
Example 26
public void removePropertyChangeListener(PropertyChangeListener listener) {
	propertyChangeSupport.removePropertyChangeListener(listener);
}
 
Example 27
Source Project: darklaf   Source File: WindowsTitlePane.java    License: MIT License 4 votes vote down vote up
private PropertyChangeListener createWindowPropertyChangeListener() {
    return new PropertyChangeHandler();
}
 
Example 28
/**
 * Constructor
 */
public ImageFileChooser() {
    super();
    dpiCB = new JComboBox();
    DefaultComboBoxModel cbm = new DefaultComboBoxModel();
    cbm.addElement("Default");
    cbm.addElement("150");
    cbm.addElement("300");
    cbm.addElement("600");
    cbm.addElement("900");
    cbm.addElement("1200");
    dpiCB.setModel(cbm);
    dpiCB.setEditable(true);
    panel = new JPanel(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = new Insets(5, 10, 0, 0);
    constraints.gridx = 0;
    constraints.gridy = 0;
    panel.add(new JLabel("DPI:"), constraints);
    constraints.gridy = 1;
    panel.add(dpiCB, constraints);    
    setAccessory(panel);
    //panel.setVisible(false);

    this.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent pce) {
            String prop = pce.getPropertyName();

            //If a file became selected, find out which one.
            if (JFileChooser.FILE_FILTER_CHANGED_PROPERTY.equals(prop)) {
                GenericFileFilter filter = (GenericFileFilter) pce.getNewValue();                    
                if (filter != null){
                    switch (filter.getFileExtent().toLowerCase()) {
                        case "png":
                        case "jpg":
                        case "bmp":
                        case "gif":
                            panel.setVisible(true);
                            break;
                        default:
                            panel.setVisible(false);
                            break;
                    }
                    repaint();
                }
            }
        }
    });
}
 
Example 29
protected PropertyChangeListener createPropertyChangeListener() {
    return new MetalPropertyChangeHandler();
}
 
Example 30
Source Project: TencentKona-8   Source File: AbstractButton.java    License: GNU General Public License v2.0 4 votes vote down vote up
PropertyChangeListener createActionPropertyChangeListener0(Action a) {
    return new ButtonActionPropertyChangeListener(this, a);
}