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

The following examples show how to use java.beans.PropertyChangeEvent#getSource() . 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: NimbusLookAndFeel.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Overridden to return {@code true} when one of the following
 * properties change:
 * <ul>
 *   <li>{@code "Nimbus.Overrides"}
 *   <li>{@code "Nimbus.Overrides.InheritDefaults"}
 *   <li>{@code "JComponent.sizeVariant"}
 * </ul>
 *
 * @since 1.7
 */
@Override
protected boolean shouldUpdateStyleOnEvent(PropertyChangeEvent ev) {
    String eName = ev.getPropertyName();

    // These properties affect style cached inside NimbusDefaults (6860433)
    if ("name" == eName ||
        "ancestor" == eName ||
        "Nimbus.Overrides" == eName ||
        "Nimbus.Overrides.InheritDefaults" == eName ||
        "JComponent.sizeVariant" == eName) {

        JComponent c = (JComponent) ev.getSource();
        defaults.clearOverridesCache(c);
        return true;
    }

    return super.shouldUpdateStyleOnEvent(ev);
}
 
Example 2
Source File: NimbusLookAndFeel.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Overridden to return {@code true} when one of the following
 * properties change:
 * <ul>
 *   <li>{@code "Nimbus.Overrides"}
 *   <li>{@code "Nimbus.Overrides.InheritDefaults"}
 *   <li>{@code "JComponent.sizeVariant"}
 * </ul>
 *
 * @since 1.7
 */
@Override
protected boolean shouldUpdateStyleOnEvent(PropertyChangeEvent ev) {
    String eName = ev.getPropertyName();

    // These properties affect style cached inside NimbusDefaults (6860433)
    if ("name" == eName ||
        "ancestor" == eName ||
        "Nimbus.Overrides" == eName ||
        "Nimbus.Overrides.InheritDefaults" == eName ||
        "JComponent.sizeVariant" == eName) {

        JComponent c = (JComponent) ev.getSource();
        defaults.clearOverridesCache(c);
        return true;
    }

    return super.shouldUpdateStyleOnEvent(ev);
}
 
Example 3
Source File: BasicMenuItemUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
    String name = e.getPropertyName();

    if (name == "labelFor" || name == "displayedMnemonic" ||
        name == "accelerator") {
        updateAcceleratorBinding();
    } else if (name == "text" || "font" == name ||
               "foreground" == name) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JMenuItem lbl = ((JMenuItem) e.getSource());
        String text = lbl.getText();
        BasicHTML.updateRenderer(lbl, text);
    } else if (name  == "iconTextGap") {
        defaultTextIconGap = ((Number)e.getNewValue()).intValue();
    } else if (name == "horizontalTextPosition") {
        updateCheckIcon();
    }
}
 
Example 4
Source File: NamingContextListener.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Process property change events.
 *
 * @param event The property change event that has occurred
 */
@Override
public void propertyChange(PropertyChangeEvent event) {

    if (!initialized)
        return;

    Object source = event.getSource();
    if (source == namingResources) {

        // Setting the context in read/write mode
        ContextAccessController.setWritable(getName(), container);

        processGlobalResourcesChange(event.getPropertyName(),
                                     event.getOldValue(),
                                     event.getNewValue());

        // Setting the context in read only mode
        ContextAccessController.setReadOnly(getName());

    }

}
 
Example 5
Source File: ElementTreePanel.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked when a property changes. We are only interested in when the
 * Document changes to reset the DocumentListener.
 */
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() == getEditor() && e.getPropertyName().equals(
            "document")) {
        Document oldDoc = (Document) e.getOldValue();
        Document newDoc = (Document) e.getNewValue();

        // Reset the DocumentListener
        oldDoc.removeDocumentListener(this);
        newDoc.addDocumentListener(this);

        // Recreate the TreeModel.
        treeModel = new ElementTreeModel(newDoc);
        tree.setModel(treeModel);
    }
}
 
Example 6
Source File: FeatureEditor.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent event) {
    if ("value".equals(event.getPropertyName())) {
        EditorField   field = (EditorField) event.getSource();
        LeveledAmount amt   = (LeveledAmount) field.getClientProperty(LeveledAmount.class);
        if (amt != null) {
            if (amt.isIntegerOnly()) {
                amt.setAmount(((Integer) field.getValue()).intValue());
            } else {
                amt.setAmount(((Double) field.getValue()).doubleValue());
            }
            notifyActionListeners();
        } else {
            super.propertyChange(event);
        }
    } else {
        super.propertyChange(event);
    }
}
 
Example 7
Source File: MotifInternalFrameTitlePane.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    String prop = evt.getPropertyName();
    JInternalFrame f = (JInternalFrame)evt.getSource();
    boolean value = false;
    if (JInternalFrame.IS_SELECTED_PROPERTY.equals(prop)) {
        repaint();
    } else if (prop.equals("maximizable")) {
        if ((Boolean)evt.getNewValue() == Boolean.TRUE)
            add(maximizeButton);
        else
            remove(maximizeButton);
        revalidate();
        repaint();
    } else if (prop.equals("iconable")) {
        if ((Boolean)evt.getNewValue() == Boolean.TRUE)
            add(minimizeButton);
        else
            remove(minimizeButton);
        revalidate();
        repaint();
    } else if (prop.equals(JInternalFrame.TITLE_PROPERTY)) {
        repaint();
    }
    enableActions();
}
 
Example 8
Source File: BasicScrollPaneUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() == scrollpane) {
        scrollPanePropertyChange(e);
    }
    else {
        sbPropertyChange(e);
    }
}
 
Example 9
Source File: ContextRandomSeedChangeListener.java    From AliceBot with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent event)
{
  Context context = (Context) event.getSource();
  Object oldSeed = event.getOldValue();
  Object newSeed = event.getNewValue();
  
  if (oldSeed == null ? newSeed == null : oldSeed.equals(newSeed))
    return;
  
  long seed = Long.parseLong(newSeed.toString());
  context.random(seed);
}
 
Example 10
Source File: Schema2BeansUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    Object oldValue = evt.getOldValue();
    Object newValue = evt.getNewValue();
    if (oldValue == null && newValue != null) {
        String path = evt.getPropertyName();
        BaseBean bean = (BaseBean) evt.getSource();
        Node node = findNode(bean, path);
        if (node != null) {
            reindentNode(node);
        }
    }
}
 
Example 11
Source File: BasicScrollPaneUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() == scrollpane) {
        scrollPanePropertyChange(e);
    }
    else {
        sbPropertyChange(e);
    }
}
 
Example 12
Source File: TruffleAccess.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    JPDAThreadImpl t = (JPDAThreadImpl) evt.getSource();
    if (!(Boolean) evt.getNewValue() && !t.isMethodInvoking()) { // not suspended, resumed
        synchronized (currentPCInfos) {
            ThreadInfo info = currentPCInfos.get(t);
            if (info != null) {
                info.cpi = null;
            }
        }
    }
}
 
Example 13
Source File: StartManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    final DatabaseServer server = (DatabaseServer)evt.getSource();
    if ((MySQLOptions.PROP_START_ARGS.equals(evt.getPropertyName()) ||
            MySQLOptions.PROP_START_PATH.equals(evt.getPropertyName())) && (startRequested.get())) {
        start(server);
    }
}
 
Example 14
Source File: StyledEditorKit.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    Object newValue = evt.getNewValue();
    Object source = evt.getSource();

    if ((source instanceof JTextComponent) &&
        (newValue instanceof Document)) {
        // New document will have changed selection to 0,0.
        updateInputAttributes(0, 0, (JTextComponent)source);
    }
}
 
Example 15
Source File: SynthInternalFrameTitlePane.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getSource() == this) {
        if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
            updateStyle(this);
        }
    }
    else {
        // Changes for the internal frame
        if (evt.getPropertyName() == JInternalFrame.FRAME_ICON_PROPERTY) {
            updateMenuIcon();
        }
    }
}
 
Example 16
Source File: EditorCaret.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            JTextComponent c = component;
            if ("document".equals(propName)) { // NOI18N
                if (c != null) {
                    modelChanged(activeDoc, c.getDocument());
                }

            } else if (EditorUtilities.CARET_OVERWRITE_MODE_PROPERTY.equals(propName)) {
                Boolean b = (Boolean) evt.getNewValue();
                overwriteMode = (b != null) ? b : false;
                updateOverwriteModeLayer(true);
                updateType();

            } else if ("ancestor".equals(propName) && evt.getSource() == component) { // NOI18N
                // The following code ensures that when the width of the line views
                // gets computed on background after the file gets opened
                // (so the horizontal scrollbar gets added after several seconds
                // for larger files) that the suddenly added horizontal scrollbar
                // will not hide the caret laying on the last line of the viewport.
                // A component listener gets installed into horizontal scrollbar
                // and if it's fired the caret's bounds will be checked whether
                // they intersect with the horizontal scrollbar
                // and if so the view will be scrolled.
                final JViewport viewport = getViewport();
                if (viewport != null) {
                    Component parent = viewport.getParent();
                    if (parent instanceof JScrollPane) {
                        JScrollPane scrollPane = (JScrollPane) parent;
                        JScrollBar hScrollBar = scrollPane.getHorizontalScrollBar();
                        if (hScrollBar != null) {
                            // Add weak listener so that editor pane could be removed
                            // from scrollpane without being held by scrollbar
                            hScrollBar.addComponentListener(
                                    (ComponentListener) WeakListeners.create(
                                            ComponentListener.class, listenerImpl, hScrollBar));
                        }
                    }
                }
            } else if ("enabled".equals(propName)) {
                Boolean enabled = (Boolean) evt.getNewValue();
                if (component.isFocusOwner()) {
                    if (enabled == Boolean.TRUE) {
                        if (component.isEditable()) {
                            setVisible(true);
                        }
                        setSelectionVisible(true);
                    } else {
                        setVisible(false);
                        setSelectionVisible(false);
                    }
                }
            } else if (RECTANGULAR_SELECTION_PROPERTY.equals(propName)) {
                boolean origRectangularSelection = rectangularSelection;
                rectangularSelection = Boolean.TRUE.equals(component.getClientProperty(RECTANGULAR_SELECTION_PROPERTY));
                if (rectangularSelection != origRectangularSelection) {
                    if (rectangularSelection) {
                        setRectangularSelectionToDotAndMark();
//                        RectangularSelectionTransferHandler.install(component);

                    } else { // No rectangular selection
//                        RectangularSelectionTransferHandler.uninstall(component);
                    }
                    fireStateChanged(null);
                }
            }
        }
 
Example 17
Source File: CustomDialog.java    From darklaf with MIT License 4 votes vote down vote up
/**
 * This method reacts to state changes in the option pane.
 */
public void propertyChange(final PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop) ||
            JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
        Object value = optionPane.getValue();

        if (value == JOptionPane.UNINITIALIZED_VALUE) {
            // ignore reset
            return;
        }

        // Reset the JOptionPane's value.
        // If you don't do this, then if the user
        // presses the same button next time, no
        // property change event will be fired.
        optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

        if (btnString1.equals(value)) {
            typedText = textField.getText();
            String ucText = typedText.toUpperCase();
            if (magicWord.equals(ucText)) {
                // we're done; clear and dismiss the dialog
                clearAndHide();
            } else {
                // text was invalid
                textField.selectAll();
                JOptionPane.showMessageDialog(CustomDialog.this,
                                              "Sorry, \"" + typedText + "\" " + "isn't a valid response.\n"
                                                                 + "Please enter " + magicWord + ".",
                                              "Try again", JOptionPane.ERROR_MESSAGE);
                typedText = null;
                textField.requestFocusInWindow();
            }
        } else { // user closed dialog or clicked cancel
            dd.setLabel("It's OK.   We won't force you to type " + magicWord + ".");
            typedText = null;
            clearAndHide();
        }
    }
}
 
Example 18
Source File: SummaryView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void propertyChange (PropertyChangeEvent evt) {
    if (RepositoryRevision.PROP_EVENTS_CHANGED.equals(evt.getPropertyName()) && revision == evt.getSource()) {
        refreshEvents();
    }
}
 
Example 19
Source File: DarkToolTipUI.java    From darklaf with MIT License 4 votes vote down vote up
@Override
public void propertyChange(final PropertyChangeEvent evt) {
    String key = evt.getPropertyName();
    if (evt.getSource() instanceof JToolTip) {
        JToolTip tooltip = (JToolTip) evt.getSource();
        if (tooltip.getBorder() instanceof AlignableTooltipBorder) {
            AlignableTooltipBorder b = (AlignableTooltipBorder) tooltip.getBorder();
            Object newVal = evt.getNewValue();
            if (KEY_POINTER_LOCATION.equals(key)) {
                if (newVal instanceof Alignment) {
                    b.setPointerLocation((Alignment) newVal, pointerEnabled());
                } else {
                    b.setPointerLocation(Alignment.CENTER, pointerEnabled());
                }
                updateSize();
            }

            if (b instanceof DarkTooltipBorder) {
                DarkTooltipBorder border = (DarkTooltipBorder) tooltip.getBorder();
                if (pointerEnabled() && KEY_POINTER_HEIGHT.equals(key)) {
                    if (newVal instanceof Integer) {
                        border.setPointerHeight((Integer) newVal);
                    }
                    updateSize();
                } else if (pointerEnabled() && KEY_POINTER_WIDTH.equals(key)) {
                    if (newVal instanceof Integer) {
                        border.setPointerWidth((Integer) newVal);
                    }
                    updateSize();
                } else if (KEY_INSETS.equals(key)) {
                    updateSize();
                }
            }
        }
        if (PropertyKey.COMPONENT.equals(key)) {
            Object oldComp = evt.getOldValue();
            if (oldComp instanceof Component) {
                ((Component) oldComp).removeMouseListener(mouseListener);
                ((Component) oldComp).removePropertyChangeListener(componentPropertyChaneListener);
            }
            Object newComp = evt.getNewValue();
            if (newComp instanceof Component) {
                ((Component) newComp).addMouseListener(mouseListener);
                ((Component) newComp).addPropertyChangeListener(componentPropertyChaneListener);
            }
            updateStyle();
        } else if (TIP_TEXT_PROPERTY.equals(key)) {
            updateTipText(tooltip);
            updateSize();
        } else if (PropertyKey.ANCESTOR.equals(key)) {
            if (evt.getOldValue() == null) {
                // Added to hierarchy. Schedule animation start.
                scheduleAnimation();
                ToolTipUtil.applyContext(toolTip);
            }
            if (evt.getNewValue() == null) {
                alpha = 0;
            }
        }
    }
}
 
Example 20
Source File: bug6800513.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.toString().contains("visible") && ((Boolean) evt.getNewValue() == true)) {
        popupMenu = (JPopupMenu) evt.getSource();
    }
}