下面列出了怎么用sun.awt.PeerEvent的API类实例代码及写法,或者点击链接到github查看源代码。
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
@Override
protected void eventPosted(final SunDropTargetEvent e) {
if (e.getID() != SunDropTargetEvent.MOUSE_DROPPED) {
Runnable runnable = new Runnable() {
@Override
public void run() {
e.getDispatcher().unregisterAllEvents();
}
};
// NOTE: this PeerEvent must be a NORM_PRIORITY event to be
// dispatched after this SunDropTargetEvent, but before the next
// one, so we should pass zero flags.
PeerEvent peerEvent = new PeerEvent(e.getSource(), runnable, 0);
SunToolkit.executeOnEventHandlerThread(peerEvent);
}
}
@Override
protected void eventPosted(final SunDropTargetEvent e) {
if (e.getID() != SunDropTargetEvent.MOUSE_DROPPED) {
Runnable runnable = new Runnable() {
@Override
public void run() {
e.getDispatcher().unregisterAllEvents();
}
};
// NOTE: this PeerEvent must be a NORM_PRIORITY event to be
// dispatched after this SunDropTargetEvent, but before the next
// one, so we should pass zero flags.
PeerEvent peerEvent = new PeerEvent(e.getSource(), runnable, 0);
SunToolkit.executeOnEventHandlerThread(peerEvent);
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private static int getPriority(AWTEvent theEvent) {
if (theEvent instanceof PeerEvent) {
PeerEvent peerEvent = (PeerEvent)theEvent;
if ((peerEvent.getFlags() & PeerEvent.ULTIMATE_PRIORITY_EVENT) != 0) {
return ULTIMATE_PRIORITY;
}
if ((peerEvent.getFlags() & PeerEvent.PRIORITY_EVENT) != 0) {
return HIGH_PRIORITY;
}
if ((peerEvent.getFlags() & PeerEvent.LOW_PRIORITY_EVENT) != 0) {
return LOW_PRIORITY;
}
}
int id = theEvent.getID();
if ((id >= PaintEvent.PAINT_FIRST) && (id <= PaintEvent.PAINT_LAST)) {
return LOW_PRIORITY;
}
return NORM_PRIORITY;
}
@Override
protected void eventPosted(final SunDropTargetEvent e) {
if (e.getID() != SunDropTargetEvent.MOUSE_DROPPED) {
Runnable runnable = new Runnable() {
@Override
public void run() {
e.getDispatcher().unregisterAllEvents();
}
};
// NOTE: this PeerEvent must be a NORM_PRIORITY event to be
// dispatched after this SunDropTargetEvent, but before the next
// one, so we should pass zero flags.
PeerEvent peerEvent = new PeerEvent(e.getSource(), runnable, 0);
SunToolkit.executeOnEventHandlerThread(peerEvent);
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
@Override
protected void eventPosted(final SunDropTargetEvent e) {
if (e.getID() != SunDropTargetEvent.MOUSE_DROPPED) {
Runnable runnable = new Runnable() {
@Override
public void run() {
e.getDispatcher().unregisterAllEvents();
}
};
// NOTE: this PeerEvent must be a NORM_PRIORITY event to be
// dispatched after this SunDropTargetEvent, but before the next
// one, so we should pass zero flags.
PeerEvent peerEvent = new PeerEvent(e.getSource(), runnable, 0);
SunToolkit.executeOnEventHandlerThread(peerEvent);
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private boolean coalescePeerEvent(PeerEvent e) {
EventQueueItem[] cache = ((Component)e.getSource()).eventCache;
if (cache == null) {
return false;
}
int index = eventToCacheIndex(e);
if (index != -1 && cache[index] != null) {
e = e.coalesceEvents((PeerEvent)cache[index].event);
if (e != null) {
cache[index].event = e;
return true;
} else {
cache[index] = null;
}
}
return false;
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
@Override
protected void eventPosted(final SunDropTargetEvent e) {
if (e.getID() != SunDropTargetEvent.MOUSE_DROPPED) {
Runnable runnable = new Runnable() {
@Override
public void run() {
e.getDispatcher().unregisterAllEvents();
}
};
// NOTE: this PeerEvent must be a NORM_PRIORITY event to be
// dispatched after this SunDropTargetEvent, but before the next
// one, so we should pass zero flags.
PeerEvent peerEvent = new PeerEvent(e.getSource(), runnable, 0);
SunToolkit.executeOnEventHandlerThread(peerEvent);
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
@Override
protected void eventPosted(final SunDropTargetEvent e) {
if (e.getID() != SunDropTargetEvent.MOUSE_DROPPED) {
Runnable runnable = new Runnable() {
@Override
public void run() {
e.getDispatcher().unregisterAllEvents();
}
};
// NOTE: this PeerEvent must be a NORM_PRIORITY event to be
// dispatched after this SunDropTargetEvent, but before the next
// one, so we should pass zero flags.
PeerEvent peerEvent = new PeerEvent(e.getSource(), runnable, 0);
SunToolkit.executeOnEventHandlerThread(peerEvent);
}
}
private void stopLWModal() {
synchronized (getTreeLock()) {
if (modalAppContext != null) {
Container nativeContainer = getHeavyweightContainer();
if(nativeContainer != null) {
if (this.modalComp != null) {
nativeContainer.modalComp = this.modalComp;
this.modalComp = null;
return;
}
else {
nativeContainer.modalComp = null;
}
}
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(modalAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
private void wakeupEDT() {
if (log.isLoggable(PlatformLogger.Level.FINEST)) {
log.finest("wakeupEDT(): EDT == " + dispatchThread);
}
EventQueue eq = dispatchThread.getEventQueue();
eq.postEvent(new PeerEvent(this, wakingRunnable, PeerEvent.PRIORITY_EVENT));
}
@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);
}
}
}
private void wakeupEDT() {
if (log.isLoggable(PlatformLogger.Level.FINEST)) {
log.finest("wakeupEDT(): EDT == " + dispatchThread);
}
EventQueue eq = dispatchThread.getEventQueue();
eq.postEvent(new PeerEvent(this, wakingRunnable, PeerEvent.PRIORITY_EVENT));
}
@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);
}
}
}
private void wakeupEDT() {
if (log.isLoggable(PlatformLogger.Level.FINEST)) {
log.finest("wakeupEDT(): EDT == " + dispatchThread);
}
EventQueue eq = dispatchThread.getEventQueue();
eq.postEvent(new PeerEvent(this, wakingRunnable, PeerEvent.PRIORITY_EVENT));
}
@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);
}
}
}
@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);
}
}
}
@Override
public PeerEvent coalesceEvents(PeerEvent newEvent) {
if (log.isLoggable(PlatformLogger.Level.FINEST)) {
log.finest("ScrollEvent coalesced: " + newEvent);
}
if (newEvent instanceof ScrollEvent) {
return newEvent;
}
return null;
}