下面列出了java.beans.PropertyChangeEvent#getOldValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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);
}
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);
}
}
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);
}
}
}
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);
}
}
}
@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);
}
}
}
/**
* 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));
}
}
@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);
}
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);
}
}
}
/**
* {@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());
}
}
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);
}
}
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);
}
}
}
/**
* {@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());
}
}
/**
* {@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());
}
}
/**
* 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));
}
}
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);
}
}
}
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);
}
}
}
}
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());
// ---------------------------------------------------------------------------------------------------
}
}
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();
}
}
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;
}