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

The following examples show how to use java.beans.PropertyChangeEvent#getOldValue() . 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: DescriptorListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean processAsChangeNameEvent(PropertyChangeEvent deleteEvent, PropertyChangeEvent createEvent) {
    boolean result = false;
    // swap old bean pointer for new bean.
    // change name field.
    CommonDDBean newBean = (CommonDDBean) createEvent.getNewValue();
    NameVisitor nameVisitor = getNameVisitor(newBean);
    if(nameVisitor != null) {
        CommonDDBean oldBean = (CommonDDBean) deleteEvent.getOldValue();
        String oldName = nameVisitor.getName(oldBean);
        String newName = nameVisitor.getName(newBean);
        
        // If names are not the same, assume this is a name change event.
        if(!Utils.strEquals(oldName, newName)) {
            PropertyChangeEvent changeEvent = new PropertyChangeEvent(newBean, createEvent.getPropertyName() + nameVisitor.getNameProperty(), oldName, newName);

            Logger.getLogger("glassfish-eecommon").log(Level.FINE, "processing delete/create sequence as change name event.");
            processEvent(changeEvent);
            result = true;
        }
    } else {
        Logger.getLogger("glassfish-eecommon").log(Level.FINE, "No support for delete/create sequence from type " + newBean.getClass().getSimpleName());
    }
    
    return result;
}
 
Example 2
Source File: ContextTopicChangeListener.java    From AliceBot with Apache License 2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent event)
{
  Object oldTopic = event.getOldValue();
  Object newTopic = event.getNewValue();
  Context context = (Context) event.getSource();
  Transformations transformations = context.getTransformations();
  
  if (oldTopic == null ? newTopic == null : oldTopic.equals(newTopic))
    return;
  
  String input = newTopic.toString().trim();
  if ("".equals(input) || "*".equals(input))
    context.setTopic(ASTERISK);
  else
  {
    Sentence topic = new Sentence(input);
    transformations.normalization(topic);
    context.setTopic(topic);
  }
}
 
Example 3
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 4
Source File: AncestorNotifier.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    String s = evt.getPropertyName();

    if (s!=null && (s.equals("parent") || s.equals("ancestor"))) {
        JComponent component = (JComponent)evt.getSource();

        if (evt.getNewValue() != null) {
            if (component == firstInvisibleAncestor) {
                addListeners(component, false);
                if (firstInvisibleAncestor == null) {
                    fireAncestorAdded(root, AncestorEvent.ANCESTOR_ADDED,
                                      component, component.getParent());
                }
            }
        } else {
            boolean needsNotify = firstInvisibleAncestor == null;
            Container oldParent = (Container)evt.getOldValue();

            removeListeners(oldParent);
            firstInvisibleAncestor = component;
            if (needsNotify) {
                fireAncestorRemoved(root, AncestorEvent.ANCESTOR_REMOVED,
                                    component, oldParent);
            }
        }
    }
}
 
Example 5
Source File: FilePane.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
        if (viewType == -1) {
            setViewType(VIEWTYPE_LIST);
        }

    String s = e.getPropertyName();
    if (s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
        doSelectedFileChanged(e);
    } else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
        doSelectedFilesChanged(e);
    } else if (s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
        doDirectoryChanged(e);
    } else if (s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
        doFilterChanged(e);
    } else if (s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
        doFileSelectionModeChanged(e);
    } else if (s.equals(JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY)) {
        doMultiSelectionChanged(e);
    } else if (s.equals(JFileChooser.CANCEL_SELECTION)) {
        applyEdit();
    } else if (s.equals("busy")) {
        setCursor((Boolean)e.getNewValue() ? waitCursor : null);
    } else if (s.equals("componentOrientation")) {
        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);
        }
    }
}
 
Example 6
Source File: FilePane.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
        if (viewType == -1) {
            setViewType(VIEWTYPE_LIST);
        }

    String s = e.getPropertyName();
    if (s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
        doSelectedFileChanged(e);
    } else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
        doSelectedFilesChanged(e);
    } else if (s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
        doDirectoryChanged(e);
    } else if (s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
        doFilterChanged(e);
    } else if (s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
        doFileSelectionModeChanged(e);
    } else if (s.equals(JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY)) {
        doMultiSelectionChanged(e);
    } else if (s.equals(JFileChooser.CANCEL_SELECTION)) {
        applyEdit();
    } else if (s.equals("busy")) {
        setCursor((Boolean)e.getNewValue() ? waitCursor : null);
    } else if (s.equals("componentOrientation")) {
        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);
        }
    }
}
 
Example 7
Source File: JList.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Property Change Listener change method. Used to track changes
 * to the DataModel and ListSelectionModel, in order to re-set
 * listeners to those for reporting changes there via the Accessibility
 * PropertyChange mechanism.
 *
 * @param e PropertyChangeEvent
 */
public void propertyChange(PropertyChangeEvent e) {
    String name = e.getPropertyName();
    Object oldValue = e.getOldValue();
    Object newValue = e.getNewValue();

        // re-set listData listeners
    if (name.compareTo("model") == 0) {

        if (oldValue != null && oldValue instanceof ListModel) {
            ((ListModel) oldValue).removeListDataListener(this);
        }
        if (newValue != null && newValue instanceof ListModel) {
            ((ListModel) newValue).addListDataListener(this);
        }

        // re-set listSelectionModel listeners
    } else if (name.compareTo("selectionModel") == 0) {

        if (oldValue != null && oldValue instanceof ListSelectionModel) {
            ((ListSelectionModel) oldValue).removeListSelectionListener(this);
        }
        if (newValue != null && newValue instanceof ListSelectionModel) {
            ((ListSelectionModel) newValue).addListSelectionListener(this);
        }

        firePropertyChange(
            AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
            Boolean.valueOf(false), Boolean.valueOf(true));
    }
}
 
Example 8
Source File: SynthTreeUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent event) {
    if (SynthLookAndFeel.shouldUpdateStyle(event)) {
        updateStyle((JTree)event.getSource());
    }

    if ("dropLocation" == event.getPropertyName()) {
        JTree.DropLocation oldValue = (JTree.DropLocation)event.getOldValue();
        repaintDropLocation(oldValue);
        repaintDropLocation(tree.getDropLocation());
    }
}
 
Example 9
Source File: SynthTreeUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent event) {
    if (SynthLookAndFeel.shouldUpdateStyle(event)) {
        updateStyle((JTree)event.getSource());
    }

    if ("dropLocation" == event.getPropertyName()) {
        JTree.DropLocation oldValue = (JTree.DropLocation)event.getOldValue();
        repaintDropLocation(oldValue);
        repaintDropLocation(tree.getDropLocation());
    }
}
 
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: JPDABreakpoint.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void enginePropertyChange(PropertyChangeEvent evt) {
    if (DebuggerEngine.class.getName().equals(evt.getPropertyName())) {
        DebuggerEngine oldEngine = (DebuggerEngine) evt.getOldValue();
        DebuggerEngine newEngine = (DebuggerEngine) evt.getNewValue();
        if (oldEngine != null) {
            engines.remove(oldEngine);
        }
        if (newEngine != null) {
            engines.add(newEngine);
        }
        firePropertyChange(PROP_GROUP_PROPERTIES, null, null);
    }
}
 
Example 12
Source File: SynthTreeUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent event) {
    if (SynthLookAndFeel.shouldUpdateStyle(event)) {
        updateStyle((JTree)event.getSource());
    }

    if ("dropLocation" == event.getPropertyName()) {
        JTree.DropLocation oldValue = (JTree.DropLocation)event.getOldValue();
        repaintDropLocation(oldValue);
        repaintDropLocation(tree.getDropLocation());
    }
}
 
Example 13
Source File: BasicScrollPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void sbPropertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();
    Object source = e.getSource();

    if ("model" == propertyName) {
        JScrollBar sb = scrollpane.getVerticalScrollBar();
        BoundedRangeModel oldModel = (BoundedRangeModel)e.
                             getOldValue();
        ChangeListener cl = null;

        if (source == sb) {
            cl = vsbChangeListener;
        }
        else if (source == scrollpane.getHorizontalScrollBar()) {
            sb = scrollpane.getHorizontalScrollBar();
            cl = hsbChangeListener;
        }
        if (cl != null) {
            if (oldModel != null) {
                oldModel.removeChangeListener(cl);
            }
            if (sb.getModel() != null) {
                sb.getModel().addChangeListener(cl);
            }
        }
    }
    else if ("componentOrientation" == propertyName) {
        if (source == scrollpane.getHorizontalScrollBar()) {
            JScrollBar hsb = scrollpane.getHorizontalScrollBar();
            JViewport viewport = scrollpane.getViewport();
            Point p = viewport.getViewPosition();
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
                p.x = hsb.getValue();
            } else {
                p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue();
            }
            viewport.setViewPosition(p);
        }
    }
}
 
Example 14
Source File: Properties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    String propertyName = evt.getPropertyName();
    if (propertyName.length() <= rl || !propertyName.startsWith(r)) {
        // not a listener in this root
        return ;
    }
    PropertyChangeEvent delegateEvt = new PropertyChangeEvent(
            DelegatingProperties.this,
            evt.getPropertyName().substring(rl),
            evt.getOldValue(),
            evt.getNewValue());
    delegateEvt.setPropagationId(evt.getPropagationId());
    delegate.propertyChange(delegateEvt);
}
 
Example 15
Source File: JList.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Property Change Listener change method. Used to track changes
 * to the DataModel and ListSelectionModel, in order to re-set
 * listeners to those for reporting changes there via the Accessibility
 * PropertyChange mechanism.
 *
 * @param e PropertyChangeEvent
 */
public void propertyChange(PropertyChangeEvent e) {
    String name = e.getPropertyName();
    Object oldValue = e.getOldValue();
    Object newValue = e.getNewValue();

        // re-set listData listeners
    if (name.compareTo("model") == 0) {

        if (oldValue != null && oldValue instanceof ListModel) {
            ((ListModel) oldValue).removeListDataListener(this);
        }
        if (newValue != null && newValue instanceof ListModel) {
            ((ListModel) newValue).addListDataListener(this);
        }

        // re-set listSelectionModel listeners
    } else if (name.compareTo("selectionModel") == 0) {

        if (oldValue != null && oldValue instanceof ListSelectionModel) {
            ((ListSelectionModel) oldValue).removeListSelectionListener(this);
        }
        if (newValue != null && newValue instanceof ListSelectionModel) {
            ((ListSelectionModel) newValue).addListSelectionListener(this);
        }

        firePropertyChange(
            AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
            Boolean.valueOf(false), Boolean.valueOf(true));
    }
}
 
Example 16
Source File: Toolkit.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void firePropertyChange(final PropertyChangeEvent evt) {
    Object oldValue = evt.getOldValue();
    Object newValue = evt.getNewValue();
    String propertyName = evt.getPropertyName();
    if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
        return;
    }
    Runnable updater = new Runnable() {
        public void run() {
            PropertyChangeSupport pcs = (PropertyChangeSupport)
                    AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
            if (null != pcs) {
                pcs.firePropertyChange(evt);
            }
        }
    };
    final AppContext currentAppContext = AppContext.getAppContext();
    for (AppContext appContext : AppContext.getAppContexts()) {
        if (null == appContext || appContext.isDisposed()) {
            continue;
        }
        if (currentAppContext == appContext) {
            updater.run();
        } else {
            final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT);
            SunToolkit.postEvent(appContext, e);
        }
    }
}
 
Example 17
Source File: BasicScrollPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void sbPropertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();
    Object source = e.getSource();

    if ("model" == propertyName) {
        JScrollBar sb = scrollpane.getVerticalScrollBar();
        BoundedRangeModel oldModel = (BoundedRangeModel)e.
                             getOldValue();
        ChangeListener cl = null;

        if (source == sb) {
            cl = vsbChangeListener;
        }
        else if (source == scrollpane.getHorizontalScrollBar()) {
            sb = scrollpane.getHorizontalScrollBar();
            cl = hsbChangeListener;
        }
        if (cl != null) {
            if (oldModel != null) {
                oldModel.removeChangeListener(cl);
            }
            if (sb.getModel() != null) {
                sb.getModel().addChangeListener(cl);
            }
        }
    }
    else if ("componentOrientation" == propertyName) {
        if (source == scrollpane.getHorizontalScrollBar()) {
            JScrollBar hsb = scrollpane.getHorizontalScrollBar();
            JViewport viewport = scrollpane.getViewport();
            Point p = viewport.getViewPosition();
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
                p.x = hsb.getValue();
            } else {
                p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue();
            }
            viewport.setViewPosition(p);
        }
    }
}
 
Example 18
Source File: ListPane.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();

    if (propertyName.equals("model")) { // NOI18N

        ListModel oldModel = (ListModel) e.getOldValue();
        ListModel newModel = (ListModel) e.getNewValue();

        if (oldModel != null) {
            oldModel.removeListDataListener(dataL);
        }

        if (newModel != null) {
            newModel.addListDataListener(dataL);
            updateLayoutStateNeeded = true;
            repaint();
        }
    } else if (propertyName.equals("selectionModel")) { // NOI18N

        ListSelectionModel oldModelS = (ListSelectionModel) e.getOldValue();
        ListSelectionModel newModelS = (ListSelectionModel) e.getNewValue();

        if (oldModelS != null) {
            oldModelS.removeListSelectionListener(selectionL);
        }

        if (newModelS != null) {
            newModelS.addListSelectionListener(selectionL);
        }

        updateLayoutStateNeeded = true;
        repaint();
    } else if (
        propertyName.equals("cellRenderer") || // NOI18N
            propertyName.equals("font") || // NOI18N
            propertyName.equals("fixedCellHeight") || // NOI18N
            propertyName.equals("fixedCellWidth")
    ) { // NOI18N
        updateLayoutStateNeeded = true;
        repaint();
    }
}
 
Example 19
Source File: ProfilingPointsManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getSource() instanceof Line && Line.PROP_LINE_NUMBER.equals(evt.getPropertyName())) {
            final Line line = (Line) evt.getSource();
            processor().post(new Runnable() {
                    public void run() {
                        for (ProfilingPoint pp : profilingPoints) {
                            if (pp instanceof CodeProfilingPoint) {
                                CodeProfilingPoint cpp = (CodeProfilingPoint) pp;

                                for (CodeProfilingPoint.Annotation cppa : cpp.getAnnotations()) {
                                    if (line.equals(cppa.getAttachedAnnotatable())) {
                                        cpp.internalUpdateLocation(cppa, line.getLineNumber() + 1); // Line is 0-based, needs to be 1-based for CodeProfilingPoint.Location
                                    }
                                }

                                dirtyProfilingPoints.add(cpp);
                            }
                        }
                    }
                });
        } else if (evt.getSource() instanceof ProfilingPoint) {
            ProfilingPoint profilingPoint = (ProfilingPoint) evt.getSource();
            if (!evt.getPropertyName().equals(ProfilingPoint.PROPERTY_RESULTS))
                storeProfilingPoints(new ProfilingPoint[] { profilingPoint });

            if (isAnnotationChange(evt)) {
                ProfilingPointAnnotator.get().annotationChanged(evt);
            }

            if (isLocationChange(evt)) {
                ProfilingPointAnnotator.get().locationChanged(evt);
                
                CodeProfilingPoint.Location oldLocation = (CodeProfilingPoint.Location)evt.getOldValue();
                if (oldLocation != null && !CodeProfilingPoint.Location.EMPTY.equals(oldLocation))
                    removeFileWatch(new File(oldLocation.getFile()));
                
                CodeProfilingPoint.Location newLocation = (CodeProfilingPoint.Location)evt.getNewValue();
                if (newLocation != null && !CodeProfilingPoint.Location.EMPTY.equals(newLocation))
                    addFileWatch(new File(newLocation.getFile()));
            }
                
            if (isAppearanceChange(evt)) {
                ProfilingPointAnnotator.get().appearanceChanged(evt);
                firePropertyChanged(PROPERTY_PROFILING_POINTS_CHANGED);
            }
//        } else if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName())) {
//            processor().post(new Runnable() {
//                    public void run() {
//                        processOpenedProjectsChanged();
//                    }
//                });

            // --- Code for saving dirty profiling points on document save instead of IDE closing ----------------
            //    } else if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) {
            //      System.err.println(">>> Changed " + evt.getPropertyName() + " from " + evt.getOldValue() + " to " + evt.getNewValue() + ", origin: "+ evt.getSource());
            // ---------------------------------------------------------------------------------------------------
        }
    }
 
Example 20
Source File: TableHelper.java    From CodenameOne with GNU General Public License v2.0 votes vote down vote up
public static PropertyChangeListener addModelTracker(JTable p_Table,
      final TableModelListener p_Listener) {
    PropertyChangeListener propListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent event) {
        TableModel oldModel = (TableModel) event.getOldValue();
        TableModel newModel = (TableModel) event.getNewValue();
        if (oldModel != null)
          oldModel.removeTableModelListener(p_Listener);
        if (newModel != null)
          newModel.addTableModelListener(p_Listener);
      }
    };
    p_Table.addPropertyChangeListener("model", propListener);
    p_Table.getModel().addTableModelListener(p_Listener);
    return propListener;
  }