Java Code Examples for java.beans.PropertyChangeEvent#getNewValue()

The following examples show how to use java.beans.PropertyChangeEvent#getNewValue() . 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 check out the related API usage on the sidebar.
Example 1
Source File: EditorContextDispatcher.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    String propertyName = evt.getPropertyName();
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("EditorRegistryListener.propertyChange("+propertyName+": "+evt.getOldValue()+" => "+evt.getNewValue()+")");
    }
    if (propertyName.equals(EditorRegistry.FOCUS_LOST_PROPERTY)) {
        Object newFocused = evt.getNewValue();
        if (newFocused instanceof JRootPane) {
            JRootPane root = (JRootPane) newFocused;
            if (root.isAncestorOf((Component) evt.getOldValue())) {
                logger.fine("Focused root.");
                root.addFocusListener(this);
                return;
            }
        }
    }
    if (propertyName.equals(EditorRegistry.FOCUS_GAINED_PROPERTY) ||
        propertyName.equals(EditorRegistry.FOCUS_LOST_PROPERTY) ||
        propertyName.equals(EditorRegistry.FOCUSED_DOCUMENT_PROPERTY)) {
        
        update(true);
    }
}
 
Example 2
Source File: DefinitionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void assertEvent(String propertyName, Object old, Object now) {
    for (PropertyChangeEvent e : events) {
        if (propertyName.equals(e.getPropertyName())) {
            if (old != null && ! old.equals(e.getOldValue()) ||
                old == null && e.getOldValue() != null) {
                continue;
            }
            if (now != null && ! now.equals(e.getNewValue()) ||
                now == null && e.getNewValue() != null) {
                continue;
            }
            return; //matched
        }
    }
    assertTrue("Expect property change event on "+propertyName+" with "+old+" and "+now, false);
}
 
Example 3
Source File: EmbeddedFrame.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Needed to track which KeyboardFocusManager is current. We want to avoid memory
 * leaks, so when KFM stops being current, we remove ourselves as listeners.
 */
public void propertyChange(PropertyChangeEvent evt) {
    // We don't handle any other properties. Skip it.
    if (!evt.getPropertyName().equals("managingFocus")) {
        return;
    }

    // We only do it if it stops being current. Technically, we should
    // never get an event about KFM starting being current.
    if (evt.getNewValue() == Boolean.TRUE) {
        return;
    }

    // should be the same as appletKFM
    removeTraversingOutListeners((KeyboardFocusManager)evt.getSource());

    appletKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (isVisible()) {
        addTraversingOutListeners(appletKFM);
    }
}
 
Example 4
Source File: DarkFormattedTextFieldUI.java    From darklaf with MIT License 5 votes vote down vote up
@Override
public void propertyChange(final PropertyChangeEvent evt) {
    super.propertyChange(evt);
    if (PropertyKey.DOCUMENT.equals(evt.getPropertyName())) {
        Object oldDoc = evt.getOldValue();
        Object newDoc = evt.getNewValue();
        if (oldDoc instanceof Document) {
            ((Document) oldDoc).removeDocumentListener(this);
        }
        if (newDoc instanceof Document) {
            ((Document) newDoc).addDocumentListener(this);
        }
    }
}
 
Example 5
Source File: BasicInternalFrameTitlePane.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    String prop = evt.getPropertyName();

    if (prop == JInternalFrame.IS_SELECTED_PROPERTY) {
        repaint();
        return;
    }

    if (prop == JInternalFrame.IS_ICON_PROPERTY ||
            prop == JInternalFrame.IS_MAXIMUM_PROPERTY) {
        setButtonIcons();
        enableActions();
        return;
    }

    if ("closable" == prop) {
        if (evt.getNewValue() == Boolean.TRUE) {
            add(closeButton);
        } else {
            remove(closeButton);
        }
    } else if ("maximizable" == prop) {
        if (evt.getNewValue() == Boolean.TRUE) {
            add(maxButton);
        } else {
            remove(maxButton);
        }
    } else if ("iconable" == prop) {
        if (evt.getNewValue() == Boolean.TRUE) {
            add(iconButton);
        } else {
            remove(iconButton);
        }
    }
    enableActions();

    revalidate();
    repaint();
}
 
Example 6
Source File: DarkSpinnerListener.java    From darklaf with MIT License 5 votes vote down vote up
@Override
public void propertyChange(final PropertyChangeEvent evt) {
    String key = evt.getPropertyName();
    Component editorComponent = ui.getEditorComponent();
    JComponent editor = ui.getEditor();
    if (PropertyKey.OPAQUE.equals(key)) {
        boolean val = Boolean.TRUE.equals(evt.getNewValue());
        spinner.getEditor().setOpaque(val);
        if (editorComponent instanceof JComponent) {
            ((JComponent) editorComponent).setOpaque(val);
        }
    } else if (KEY_IS_TABLE_EDITOR.equals(key)) {
        if (Boolean.FALSE.equals(evt.getNewValue())) {
            if (editor instanceof JSpinner.DefaultEditor) {
                // if editor alignment isn't set in LAF, we get 0 (CENTER) here
                int alignment = UIManager.getInt("Spinner.editorAlignment");
                JTextField text = ((JSpinner.DefaultEditor) editor).getTextField();
                text.setHorizontalAlignment(alignment);
            }
        }
        spinner.revalidate();
        spinner.repaint();
    } else if (KEY_EDITOR_ALIGNMENT.equals(key) && SpinnerConstants.isTableCellEditor(spinner)) {
        if (editorComponent instanceof JTextField && evt.getNewValue() instanceof Integer) {
            ((JTextField) editorComponent).setHorizontalAlignment((Integer) evt.getNewValue());
        }
        spinner.revalidate();
    } else if (KEY_VARIANT.equals(key)) {
        spinner.repaint();
    } else if (KEY_IS_TREE_EDITOR.equals(key)) {
        spinner.revalidate();
        spinner.repaint();
    }
}
 
Example 7
Source File: ServerManagerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
        Node[] nodes = (Node[]) evt.getNewValue();
        if (nodes.length != 1) {
            selectServer(null);
        } else {
            selectServer(nodes[0]);
        }
    }
}
 
Example 8
Source File: ToggleActionPropertyChangeListener.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt)
{
    String propertyName = evt.getPropertyName();
    if(propertyName.equals("selected"))
    {
        Boolean selected = (Boolean)evt.getNewValue();
        button.setSelected(selected.booleanValue());
    }
}
 
Example 9
Source File: DarkFileChooserUIBridge.java    From darklaf with MIT License 5 votes vote down vote up
protected void doSelectedFilesChanged(final PropertyChangeEvent e) {
    File[] files = (File[]) e.getNewValue();
    JFileChooser fc = getFileChooser();
    if (files != null
        && files.length > 0
        && (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
        setFileName(fileNameString(files));
    }
}
 
Example 10
Source File: MultiDiffPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean affectsView(PropertyChangeEvent event) {
    FileStatusCache.ChangedEvent changedEvent = (FileStatusCache.ChangedEvent) event.getNewValue();
    File file = changedEvent.getFile();
    FileInformation oldInfo = changedEvent.getOldInfo();
    FileInformation newInfo = changedEvent.getNewInfo();
    if (oldInfo == null) {
        if ((newInfo.getStatus() & displayStatuses) == 0) return false;
    } else {
        if ((oldInfo.getStatus() & displayStatuses) + (newInfo.getStatus() & displayStatuses) == 0) return false;
    }
    return isLocal() && containsFile(file);
}
 
Example 11
Source File: ImportDialog.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update the progress bar.
 * <p/>
 * @param evt the property change event.
 */
@Override
public void propertyChange(PropertyChangeEvent evt) {
	String strPropertyName = evt.getPropertyName();
	if ("progress".equals(strPropertyName) && statusPanel != null) {
		int progress = (Integer) evt.getNewValue();
		statusPanel.getProgressBar().setProgress(progress);
	}
}
 
Example 12
Source File: ASTViewManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (JPDADebugger.PROP_CURRENT_CALL_STACK_FRAME.equals(evt.getPropertyName())) {
        CallStackFrame frame = (CallStackFrame) evt.getNewValue();
        if (frame != null) {
            CurrentPCInfo currentPCInfo = TruffleAccess.getCurrentPCInfo(frame.getThread());
            isAtTruffleLocation = currentPCInfo != null;
            openIfCan();
        } else {
            isAtTruffleLocation = false;
        }
    }
}
 
Example 13
Source File: DebuggerStateChangeListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    int state = ((Integer) evt.getNewValue());
    if (JPDADebugger.STATE_DISCONNECTED == state ||
        JPDADebugger.STATE_RUNNING == state) {
        SwingUtilities.invokeLater(this);
    }
}
 
Example 14
Source File: BasicScrollPaneUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Updates row header.
 *
 * @param e the property change event
 */
protected void updateRowHeader(PropertyChangeEvent e)
{
    JViewport newRowHead = (JViewport)(e.getNewValue());
    if (newRowHead != null) {
        JViewport viewport = scrollpane.getViewport();
        Point p = newRowHead.getViewPosition();
        p.y = (viewport != null) ? viewport.getViewPosition().y : 0;
        newRowHead.setViewPosition(p);
    }
}
 
Example 15
Source File: T1_Close_Test.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testVisibilityNotification() {
if (!IONotifier.isSupported(io))
    return;

PropertyChangeListener pcl = new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
	if (evt.getPropertyName().equals(IOVisibility.PROP_VISIBILITY)) {
	    assertTrue("property change not on EDT", SwingUtilities.isEventDispatchThread());
	    assertTrue("Got event '" + evt.getPropertyName() + "' instead of PROP_VISIBILITY",
		evt.getPropertyName().equals(IOVisibility.PROP_VISIBILITY));
	    visible = (Boolean) evt.getNewValue();
	} else if (evt.getPropertyName().equals(IOResizable.PROP_SIZE)) {
	} else {
	    System.out.printf("Unexpected event '%s'\n", evt.getPropertyName());
	}
    }
};
IONotifier.addPropertyChangeListener(io, pcl);

// setUp() calls select() so the terminal should be initially visible

try {
    // make it invisible
    IOVisibility.setVisible(io, false);
    sleep(1);
    assertTrue("no visibility property change", visible == false);

    // make it visible again
    IOVisibility.setVisible(io, true);
    sleep(1);
    assertTrue("no visibility property change", visible == true);

    // make it invisible again
    IOVisibility.setVisible(io, false);
    sleep(1);
    assertTrue("no visibility property change", visible == false);

    // make it visible again
    IOVisibility.setVisible(io, true);
    sleep(1);
    assertTrue("no visibility property change", visible == true);
} finally {
    IONotifier.removePropertyChangeListener(io, pcl);
}
   }
 
Example 16
Source File: CAccessible.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent e) {
    String name = e.getPropertyName();
    if ( ptr != 0 ) {
        Object newValue = e.getNewValue();
        Object oldValue = e.getOldValue();
        if (name.compareTo(ACCESSIBLE_CARET_PROPERTY) == 0) {
            selectedTextChanged(ptr);
        } else if (name.compareTo(ACCESSIBLE_TEXT_PROPERTY) == 0 ) {
            valueChanged(ptr);
        } else if (name.compareTo(ACCESSIBLE_SELECTION_PROPERTY) == 0 ) {
            selectionChanged(ptr);
        } else if (name.compareTo(ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY) == 0 ) {
            if (newValue instanceof AccessibleContext) {
                activeDescendant = (AccessibleContext)newValue;
            }
        } else if (name.compareTo(ACCESSIBLE_STATE_PROPERTY) == 0) {
            AccessibleContext thisAC = accessible.getAccessibleContext();
            AccessibleRole thisRole = thisAC.getAccessibleRole();
            Accessible parentAccessible = thisAC.getAccessibleParent();
            AccessibleRole parentRole = null;
            if (parentAccessible != null) {
                parentRole = parentAccessible.getAccessibleContext().getAccessibleRole();
            }
            // At least for now don't handle combo box menu state changes.
            // This may change when later fixing issues which currently
            // exist for combo boxes, but for now the following is only
            // for JPopupMenus, not for combobox menus.
            if (parentRole != AccessibleRole.COMBO_BOX) {
                if (thisRole == AccessibleRole.POPUP_MENU) {
                    if ( newValue != null &&
                         ((AccessibleState)newValue) == AccessibleState.VISIBLE ) {
                            menuOpened(ptr);
                    } else if ( oldValue != null &&
                                ((AccessibleState)oldValue) == AccessibleState.VISIBLE ) {
                        menuClosed(ptr);
                    }
                } else if (thisRole == AccessibleRole.MENU_ITEM) {
                    if ( newValue != null &&
                         ((AccessibleState)newValue) == AccessibleState.FOCUSED ) {
                        menuItemSelected(ptr);
                    }
                }
            }
        }
    }
}
 
Example 17
Source File: DarkFilePaneUIBridge.java    From darklaf with MIT License 4 votes vote down vote up
public void propertyChange(final PropertyChangeEvent e) {
    if (viewType == -1) {
        setViewType(VIEWTYPE_LIST);
    }

    String s = e.getPropertyName();
    switch (s) {
        case JFileChooser.SELECTED_FILE_CHANGED_PROPERTY :
            doSelectedFileChanged(e);
            break;
        case JFileChooser.SELECTED_FILES_CHANGED_PROPERTY :
            doSelectedFilesChanged(e);
            break;
        case JFileChooser.DIRECTORY_CHANGED_PROPERTY :
            doDirectoryChanged(e);
            break;
        case JFileChooser.FILE_FILTER_CHANGED_PROPERTY :
            doFilterChanged(e);
            break;
        case JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY :
            doFileSelectionModeChanged(e);
            break;
        case JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY :
            doMultiSelectionChanged(e);
            break;
        case JFileChooser.CANCEL_SELECTION :
            applyEdit();
            break;
        case "busy" :
            setCursor((Boolean) e.getNewValue() ? waitCursor : null);
            break;
        case PropertyKey.COMPONENT_ORIENTATION :
            ComponentOrientation o = (ComponentOrientation) e.getNewValue();
            JFileChooser cc = (JFileChooser) e.getSource();
            if (o != e.getOldValue()) {
                cc.applyComponentOrientation(o);
            }
            if (detailsTable != null) {
                detailsTable.setComponentOrientation(o);
                detailsTable.getParent().getParent().setComponentOrientation(o);
            }
            break;
    }
}
 
Example 18
Source File: BasicRibbonBandUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Installs listeners on the associated ribbon band.
 */
protected void installListeners() {
    // without this empty adapter, the global listener never
    // gets mouse entered events on the ribbon band
    this.mouseListener = new MouseAdapter() {
    };
    this.ribbonBand.addMouseListener(this.mouseListener);

    this.propertyChangeListener = (PropertyChangeEvent evt) -> {
        if ("title".equals(evt.getPropertyName()))
            ribbonBand.repaint();
        if ("expandButtonKeyTip".equals(evt.getPropertyName())) {
            if (expandButton != null) {
                expandButton.setActionKeyTip((String) evt.getNewValue());
            }
        }
        if ("expandButtonRichTooltip".equals(evt.getPropertyName())) {
            if (expandCommand != null) {
                expandCommand.setActionRichTooltip((RichTooltip) evt.getNewValue());
            }
        }
        if ("collapsedStateKeyTip".equals(evt.getPropertyName())) {
            if (collapsedButton != null) {
                collapsedButton.setPopupKeyTip((String) evt.getNewValue());
            }
        }
        if ("expandCommandListener".equals(evt.getPropertyName())) {
            CommandAction oldListener = (CommandAction) evt.getOldValue();
            CommandAction newListener = (CommandAction) evt.getNewValue();

            if ((oldListener != null) && (newListener == null)) {
                // need to remove
                ribbonBand.remove(expandButton);
                expandButton = null;
                ribbonBand.revalidate();
            }
            if ((oldListener == null) && (newListener != null)) {
                // need to add
                expandCommand = createExpandCommand();
                expandButton = createExpandButton();
                ribbonBand.add(expandButton);
                ribbonBand.revalidate();
            }
            if ((oldListener != null) && (newListener != null)) {
                // need to reconfigure
                expandCommand.setAction(newListener);
            }
        }
        if ("componentOrientation".equals(evt.getPropertyName())) {
            if (expandButton != null) {
                syncExpandButtonIcon();
            }
        }
    };
    this.ribbonBand.addPropertyChangeListener(this.propertyChangeListener);
}
 
Example 19
Source File: AnimationController.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public synchronized void propertyChange(PropertyChangeEvent e) {
    if ("lookAndFeel" == e.getPropertyName()
        && ! (e.getNewValue() instanceof WindowsLookAndFeel) ) {
        dispose();
    }
}
 
Example 20
Source File: VetoableChangeMulticaster.java    From gemfirexd-oss with Apache License 2.0 3 votes vote down vote up
/**
 * Report a vetoable property update to any registered listeners. 
 * Notifications are sent serially (although in no particular order)
 * to the list of listeners,
 * aborting if one throws PropertyVetoException. Upon this exception,
 * fire a new event reverting this
 * change to all listeners that have already been notified
 * (ignoring any further vetos), 
 * suppress notifications to all other listeners, and
 * then rethrow the PropertyVetoException.
 * <p>
 * No event is fired if old and new are equal and non-null.
 *
 * equal and non-null.
 * @param evt  The PropertyChangeEvent object.
 * @exception PropertyVetoException if the recipient wishes the property
 *              change to be rolled back.
 */
public void fireVetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
  Object oldValue = evt.getOldValue();
  Object newValue = evt.getNewValue();
  if (oldValue == null || newValue == null || !oldValue.equals(newValue)) 
    multicast(evt);
}