Method from sun.awt.SunToolkit Detail: |
public void addModalityListener(ModalityListener listener) {
modalityListeners.add(listener);
}
|
public static final void awtLock() {
AWT_LOCK.lock();
}
|
public static final void awtLockNotify() {
AWT_LOCK_COND.signal();
}
|
public static final void awtLockNotifyAll() {
AWT_LOCK_COND.signalAll();
}
|
public static final void awtLockWait() throws InterruptedException {
AWT_LOCK_COND.await();
}
|
public static final void awtLockWait(long timeout) throws InterruptedException {
AWT_LOCK_COND.await(timeout, TimeUnit.MILLISECONDS);
}
|
public static final boolean awtTryLock() {
return AWT_LOCK.tryLock();
}
|
public static final void awtUnlock() {
AWT_LOCK.unlock();
}
|
public static void checkAndSetPolicy(Container cont,
boolean isSwingCont) {
FocusTraversalPolicy defaultPolicy = KeyboardFocusManager
.getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy();
String toolkitName = Toolkit.getDefaultToolkit().getClass().getName();
// if this is not XAWT then use default policy
// because Swing change it
if (!"sun.awt.X11.XToolkit".equals(toolkitName)) {
cont.setFocusTraversalPolicy(defaultPolicy);
return;
}
String policyName = defaultPolicy.getClass().getName();
if (DefaultFocusTraversalPolicy.class != defaultPolicy.getClass()) {
// Policy was changed
// Check if it is awt policy or swing policy
// If it is Swing policy we shouldn't use it in AWT frames
// If it is AWT policy we shouldn't use it in Swing frames
// Otherwise we should use this policy
if (policyName.startsWith("java.awt.")) {
// AWT
if (isSwingCont) {
// Can't use AWT policy in Swing windows - should use Swing's one.
defaultPolicy = createLayoutPolicy();
} else {
// New awt policy.
}
} else if (policyName.startsWith("javax.swing.")) {
if (isSwingCont) {
// New Swing's policy
} else {
defaultPolicy = new DefaultFocusTraversalPolicy();
}
}
} else {
// Policy is default, use different default policy for swing
if (isSwingCont) {
defaultPolicy = createLayoutPolicy();
}
}
cont.setFocusTraversalPolicy(defaultPolicy);
}
|
public int checkImage(Image img,
int w,
int h,
ImageObserver o) {
if (!(img instanceof ToolkitImage)) {
return ImageObserver.ALLBITS;
}
ToolkitImage tkimg = (ToolkitImage)img;
int repbits;
if (w == 0 || h == 0) {
repbits = ImageObserver.ALLBITS;
} else {
repbits = tkimg.getImageRep().check(o);
}
return tkimg.check(o) | repbits;
}
|
public static native void closeSplashScreen()
Locates the splash screen library in a platform dependent way and closes
the splash screen. Should be invoked on first top-level frame display. |
public static synchronized void consumeNextKeyTyped(KeyEvent keyEvent) {
if (consumeNextKeyTypedMethod == null) {
consumeNextKeyTypedMethod = getMethod(DefaultKeyboardFocusManager.class,
"consumeNextKeyTyped",
new Class[] {KeyEvent.class});
}
try {
consumeNextKeyTypedMethod.invoke(KeyboardFocusManager.getCurrentKeyboardFocusManager(),
keyEvent);
} catch (IllegalAccessException iae) {
iae.printStackTrace();
} catch (InvocationTargetException ite) {
ite.printStackTrace();
}
}
|
abstract public ButtonPeer createButton(Button target) throws HeadlessException
|
public CanvasPeer createCanvas(Canvas target) {
return (CanvasPeer)createComponent(target);
}
|
abstract public CheckboxPeer createCheckbox(Checkbox target) throws HeadlessException
|
abstract public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) throws HeadlessException
|
abstract public ChoicePeer createChoice(Choice target) throws HeadlessException
|
abstract public DialogPeer createDialog(Dialog target) throws HeadlessException
|
abstract public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException
|
abstract public FileDialogPeer createFileDialog(FileDialog target) throws HeadlessException
|
abstract public FramePeer createFrame(Frame target) throws HeadlessException
|
public Image createImage(String filename) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(filename);
}
return createImage(new FileImageSource(filename));
}
|
public Image createImage(URL url) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
java.security.Permission perm =
url.openConnection().getPermission();
if (perm != null) {
try {
sm.checkPermission(perm);
} catch (SecurityException se) {
// fallback to checkRead/checkConnect for pre 1.2
// security managers
if ((perm instanceof java.io.FilePermission) &&
perm.getActions().indexOf("read") != -1) {
sm.checkRead(perm.getName());
} else if ((perm instanceof
java.net.SocketPermission) &&
perm.getActions().indexOf("connect") != -1) {
sm.checkConnect(url.getHost(), url.getPort());
} else {
throw se;
}
}
}
} catch (java.io.IOException ioe) {
sm.checkConnect(url.getHost(), url.getPort());
}
}
return createImage(new URLImageSource(url));
}
|
public Image createImage(ImageProducer producer) {
return new ToolkitImage(producer);
}
|
public Image createImage(byte[] data,
int offset,
int length) {
return createImage(new ByteArrayImageSource(data, offset, length));
}
|
public Window createInputMethodWindow(String title,
InputContext context) {
return new sun.awt.im.SimpleInputMethodWindow(title, context);
}
|
abstract public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) throws HeadlessException
|
abstract public LabelPeer createLabel(Label target) throws HeadlessException
|
abstract public ListPeer createList(List target) throws HeadlessException
|
abstract public MenuPeer createMenu(Menu target) throws HeadlessException
|
abstract public MenuBarPeer createMenuBar(MenuBar target) throws HeadlessException
|
abstract public MenuItemPeer createMenuItem(MenuItem target) throws HeadlessException
|
public static AppContext createNewAppContext() {
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
// Create appContext before initialization of EventQueue, so all
// the calls to AppContext.getAppContext() from EventQueue ctor
// return correct values
AppContext appContext = new AppContext(threadGroup);
EventQueue eventQueue;
String eqName = System.getProperty("AWT.EventQueueClass",
"java.awt.EventQueue");
try {
eventQueue = (EventQueue)Class.forName(eqName).newInstance();
} catch (Exception e) {
System.err.println("Failed loading " + eqName + ": " + e);
eventQueue = new EventQueue();
}
appContext.put(AppContext.EVENT_QUEUE_KEY, eventQueue);
PostEventQueue postEventQueue = new PostEventQueue(eventQueue);
appContext.put(POST_EVENT_QUEUE_KEY, postEventQueue);
return appContext;
}
|
public PanelPeer createPanel(Panel target) {
return (PanelPeer)createComponent(target);
}
|
abstract public PopupMenuPeer createPopupMenu(PopupMenu target) throws HeadlessException
|
abstract public RobotPeer createRobot(Robot target,
GraphicsDevice screen) throws AWTException
|
abstract public ScrollPanePeer createScrollPane(ScrollPane target) throws HeadlessException
|
abstract public ScrollbarPeer createScrollbar(Scrollbar target) throws HeadlessException
|
abstract public SystemTrayPeer createSystemTray(SystemTray target)
|
abstract public TextAreaPeer createTextArea(TextArea target) throws HeadlessException
|
abstract public TextFieldPeer createTextField(TextField target) throws HeadlessException
|
abstract public TrayIconPeer createTrayIcon(TrayIcon target) throws HeadlessException, AWTException
|
abstract public WindowPeer createWindow(Window target) throws HeadlessException
|
public void disableBackgroundErase(Canvas canvas) {
disableBackgroundEraseImpl(canvas);
}
Disables erasing of background on the canvas before painting if
this is supported by the current toolkit. It is recommended to
call this method early, before the Canvas becomes displayable,
because some Toolkit implementations do not support changing
this property once the Canvas becomes displayable. |
public void disableBackgroundErase(Component component) {
disableBackgroundEraseImpl(component);
}
Disables the native erasing of the background on the given
component before painting if this is supported by the current
toolkit. This only has an effect for certain components such as
Canvas, Panel and Window. It is recommended to call this method
early, before the Component becomes displayable, because some
Toolkit implementations do not support changing this property
once the Component becomes displayable. |
protected static void dumpPeers(PlatformLogger aLog) {
AWTAutoShutdown.getInstance().dumpPeers(aLog);
}
|
public boolean enableInputMethodsForTextComponent() {
return false;
}
Returns whether enableInputMethods should be set to true for peered
TextComponent instances on this platform. False by default. |
public static void executeOnEDTAndWait(Object target,
Runnable runnable) throws InterruptedException, InvocationTargetException {
if (EventQueue.isDispatchThread()) {
throw new Error("Cannot call executeOnEDTAndWait from any event dispatcher thread");
}
class AWTInvocationLock {}
Object lock = new AWTInvocationLock();
PeerEvent event = new PeerEvent(target, runnable, lock, true, PeerEvent.PRIORITY_EVENT);
synchronized (lock) {
executeOnEventHandlerThread(event);
while(!event.isDispatched()) {
lock.wait();
}
}
Throwable eventThrowable = event.getThrowable();
if (eventThrowable != null) {
throw new InvocationTargetException(eventThrowable);
}
}
|
public static void executeOnEventHandlerThread(PeerEvent peerEvent) {
postEvent(targetToAppContext(peerEvent.getSource()), peerEvent);
}
|
public static void executeOnEventHandlerThread(Object target,
Runnable runnable) {
executeOnEventHandlerThread(new PeerEvent(target, runnable, PeerEvent.PRIORITY_EVENT));
}
|
public static void executeOnEventHandlerThread(Object target,
Runnable runnable,
long when) {
executeOnEventHandlerThread(new PeerEvent(target, runnable, PeerEvent.PRIORITY_EVENT){
public long getWhen(){
return when;
}
});
}
|
public static void flushPendingEvents() {
flushLock.lock();
try {
// Don't call flushPendingEvents() recursively
if (!isFlushingPendingEvents) {
isFlushingPendingEvents = true;
AppContext appContext = AppContext.getAppContext();
PostEventQueue postEventQueue =
(PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
if (postEventQueue != null) {
postEventQueue.flush();
}
}
} finally {
isFlushingPendingEvents = false;
flushLock.unlock();
}
}
|
protected static Boolean getBooleanSystemProperty(String key) {
return Boolean.valueOf(AccessController.
doPrivileged(new GetBooleanAction(key)));
}
Returns the boolean value of the system property indicated by the specified key. |
public static Window getContainingWindow(Component comp) {
while (comp != null && !(comp instanceof Window)) {
comp = comp.getParent();
}
return (Window)comp;
}
Returns the Window ancestor of the component comp . |
public static String getDataTransfererClassName() {
if (dataTransfererClassName == null) {
Toolkit.getDefaultToolkit(); // transferer set during toolkit init
}
return dataTransfererClassName;
}
|
public Locale getDefaultKeyboardLocale() {
return getStartupLocale();
}
Returns the default keyboard locale of the underlying operating system |
protected RenderingHints getDesktopAAHints() {
return null;
}
|
public static RenderingHints getDesktopFontHints() {
if (useSystemAAFontSettings()) {
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
Object map = ((SunToolkit)tk).getDesktopAAHints();
return (RenderingHints)map;
} else { /* Headless Toolkit */
return null;
}
} else if (desktopFontHints != null) {
/* cloning not necessary as the return value is cloned later, but
* its harmless.
*/
return (RenderingHints)(desktopFontHints.clone());
} else {
return null;
}
}
|
public static Field getField(Class klass,
String fieldName) {
return AccessController.doPrivileged(new PrivilegedAction< Field >() {
public Field run() {
try {
Field field = klass.getDeclaredField(fieldName);
assert (field != null);
field.setAccessible(true);
return field;
} catch (SecurityException e) {
assert false;
} catch (NoSuchFieldException e) {
assert false;
}
return null;
}//run
});
}
|
public String[] getFontList() {
String[] hardwiredFontList = {
Font.DIALOG, Font.SANS_SERIF, Font.SERIF, Font.MONOSPACED,
Font.DIALOG_INPUT
// -- Obsolete font names from 1.0.2. It was decided that
// -- getFontList should not return these old names:
// "Helvetica", "TimesRoman", "Courier", "ZapfDingbats"
};
return hardwiredFontList;
}
|
public FontMetrics getFontMetrics(Font font) {
return FontDesignMetrics.getMetrics(font);
}
|
abstract public FontPeer getFontPeer(String name,
int style)
|
public static Component getHeavyweightComponent(Component c) {
while (c != null && AWTAccessor.getComponentAccessor().isLightweight(c)) {
c = AWTAccessor.getComponentAccessor().getParent(c);
}
return c;
}
Gives native peers the ability to query the closest HW component.
If the given component is heavyweight, then it returns this. Otherwise,
it goes one level up in the hierarchy and tests next component. |
public Image getImage(String filename) {
return getImageFromHash(this, filename);
}
|
public Image getImage(URL url) {
return getImageFromHash(this, url);
}
|
static Image getImageFromHash(Toolkit tk,
URL url) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
java.security.Permission perm =
url.openConnection().getPermission();
if (perm != null) {
try {
sm.checkPermission(perm);
} catch (SecurityException se) {
// fallback to checkRead/checkConnect for pre 1.2
// security managers
if ((perm instanceof java.io.FilePermission) &&
perm.getActions().indexOf("read") != -1) {
sm.checkRead(perm.getName());
} else if ((perm instanceof
java.net.SocketPermission) &&
perm.getActions().indexOf("connect") != -1) {
sm.checkConnect(url.getHost(), url.getPort());
} else {
throw se;
}
}
}
} catch (java.io.IOException ioe) {
sm.checkConnect(url.getHost(), url.getPort());
}
}
synchronized (imgCache) {
Image img = (Image)imgCache.get(url);
if (img == null) {
try {
img = tk.createImage(new URLImageSource(url));
imgCache.put(url, img);
} catch (Exception e) {
}
}
return img;
}
}
|
static Image getImageFromHash(Toolkit tk,
String filename) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(filename);
}
synchronized (imgCache) {
Image img = (Image)imgCache.get(filename);
if (img == null) {
try {
img = tk.createImage(new FileImageSource(filename));
imgCache.put(filename, img);
} catch (Exception e) {
}
}
return img;
}
}
|
public static Method getMethod(Class clz,
String methodName,
Class[] params) {
Method res = null;
try {
res = AccessController.doPrivileged(new PrivilegedExceptionAction< Method >() {
public Method run() throws Exception {
Method m = clz.getDeclaredMethod(methodName, params);
m.setAccessible(true);
return m;
}
});
} catch (PrivilegedActionException ex) {
ex.printStackTrace();
}
return res;
}
|
protected synchronized MouseInfoPeer getMouseInfoPeer() {
if (mPeer == null) {
mPeer = new DefaultMouseInfoPeer();
}
return mPeer;
}
|
public static Container getNativeContainer(Component c) {
return Toolkit.getNativeContainer(c);
}
Give native peers the ability to query the native container
given a native component (eg the direct parent may be lightweight). |
public int getNumberOfButtons() {
return 3;
}
Descendants of the SunToolkit should override and put their own logic here. |
public static DataBufferInt getScaledIconData(List<Image> imageList,
int width,
int height) {
BufferedImage bimage = getScaledIconImage(imageList, width, height);
if (bimage == null) {
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("SunToolkit.getScaledIconData: " +
"Perhaps the image passed into Java is broken. Skipping this icon.");
}
return null;
}
Raster raster = bimage.getRaster();
DataBuffer buffer = raster.getDataBuffer();
return (DataBufferInt)buffer;
}
|
public static BufferedImage getScaledIconImage(List<Image> imageList,
int width,
int height) {
if (width == 0 || height == 0) {
return null;
}
Image bestImage = null;
int bestWidth = 0;
int bestHeight = 0;
double bestSimilarity = 3; //Impossibly high value
double bestScaleFactor = 0;
for (Iterator< Image > i = imageList.iterator();i.hasNext();) {
//Iterate imageList looking for best matching image.
//'Similarity' measure is defined as good scale factor and small insets.
//best possible similarity is 0 (no scale, no insets).
//It's found while the experiments that good-looking result is achieved
//with scale factors x1, x3/4, x2/3, xN, x1/N.
Image im = i.next();
if (im == null) {
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("SunToolkit.getScaledIconImage: " +
"Skipping the image passed into Java because it's null.");
}
continue;
}
if (im instanceof ToolkitImage) {
ImageRepresentation ir = ((ToolkitImage)im).getImageRep();
ir.reconstruct(ImageObserver.ALLBITS);
}
int iw;
int ih;
try {
iw = im.getWidth(null);
ih = im.getHeight(null);
} catch (Exception e){
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("SunToolkit.getScaledIconImage: " +
"Perhaps the image passed into Java is broken. Skipping this icon.");
}
continue;
}
if (iw > 0 && ih > 0) {
//Calc scale factor
double scaleFactor = Math.min((double)width / (double)iw,
(double)height / (double)ih);
//Calculate scaled image dimensions
//adjusting scale factor to nearest "good" value
int adjw = 0;
int adjh = 0;
double scaleMeasure = 1; //0 - best (no) scale, 1 - impossibly bad
if (scaleFactor >= 2) {
//Need to enlarge image more than twice
//Round down scale factor to multiply by integer value
scaleFactor = Math.floor(scaleFactor);
adjw = iw * (int)scaleFactor;
adjh = ih * (int)scaleFactor;
scaleMeasure = 1.0 - 0.5 / scaleFactor;
} else if (scaleFactor >= 1) {
//Don't scale
scaleFactor = 1.0;
adjw = iw;
adjh = ih;
scaleMeasure = 0;
} else if (scaleFactor >= 0.75) {
//Multiply by 3/4
scaleFactor = 0.75;
adjw = iw * 3 / 4;
adjh = ih * 3 / 4;
scaleMeasure = 0.3;
} else if (scaleFactor >= 0.6666) {
//Multiply by 2/3
scaleFactor = 0.6666;
adjw = iw * 2 / 3;
adjh = ih * 2 / 3;
scaleMeasure = 0.33;
} else {
//Multiply size by 1/scaleDivider
//where scaleDivider is minimum possible integer
//larger than 1/scaleFactor
double scaleDivider = Math.ceil(1.0 / scaleFactor);
scaleFactor = 1.0 / scaleDivider;
adjw = (int)Math.round((double)iw / scaleDivider);
adjh = (int)Math.round((double)ih / scaleDivider);
scaleMeasure = 1.0 - 1.0 / scaleDivider;
}
double similarity = ((double)width - (double)adjw) / (double)width +
((double)height - (double)adjh) / (double)height + //Large padding is bad
scaleMeasure; //Large rescale is bad
if (similarity < bestSimilarity) {
bestSimilarity = similarity;
bestScaleFactor = scaleFactor;
bestImage = im;
bestWidth = adjw;
bestHeight = adjh;
}
if (similarity == 0) break;
}
}
if (bestImage == null) {
//No images were found, possibly all are broken
return null;
}
BufferedImage bimage =
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bimage.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
try {
int x = (width - bestWidth) / 2;
int y = (height - bestHeight) / 2;
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("WWindowPeer.getScaledIconData() result : " +
"w : " + width + " h : " + height +
" iW : " + bestImage.getWidth(null) + " iH : " + bestImage.getHeight(null) +
" sim : " + bestSimilarity + " sf : " + bestScaleFactor +
" adjW : " + bestWidth + " adjH : " + bestHeight +
" x : " + x + " y : " + y);
}
g.drawImage(bestImage, x, y, bestWidth, bestHeight, null);
} finally {
g.dispose();
}
return bimage;
}
Scans {@code imageList} for best-looking image of specified dimensions.
Image can be scaled and/or padded with transparency. |
abstract protected int getScreenHeight()
|
public Dimension getScreenSize() {
return new Dimension(getScreenWidth(), getScreenHeight());
}
|
abstract protected int getScreenWidth()
|
public static Locale getStartupLocale() {
if (startupLocale == null) {
String language, region, country, variant;
language = (String) AccessController.doPrivileged(
new GetPropertyAction("user.language", "en"));
// for compatibility, check for old user.region property
region = (String) AccessController.doPrivileged(
new GetPropertyAction("user.region"));
if (region != null) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
if (i >= 0) {
country = region.substring(0, i);
variant = region.substring(i + 1);
} else {
country = region;
variant = "";
}
} else {
country = (String) AccessController.doPrivileged(
new GetPropertyAction("user.country", ""));
variant = (String) AccessController.doPrivileged(
new GetPropertyAction("user.variant", ""));
}
startupLocale = new Locale(language, country, variant);
}
return startupLocale;
}
Returns the locale in which the runtime was started. |
public static synchronized boolean getSunAwtDisableMixing() {
if (sunAwtDisableMixing == null) {
sunAwtDisableMixing = getBooleanSystemProperty("sun.awt.disableMixing");
}
return sunAwtDisableMixing.booleanValue();
}
Returns the value of "sun.awt.disableMixing" property. Default
value is {@code false}. |
public static boolean getSunAwtErasebackgroundonresize() {
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.erasebackgroundonresize"));
}
Returns the value of "sun.awt.erasebackgroundonresize" property. Default
value is {@code false}. |
public static boolean getSunAwtNoerasebackground() {
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.noerasebackground"));
}
Returns the value of "sun.awt.noerasebackground" property. Default
value is {@code false}. |
protected EventQueue getSystemEventQueueImpl() {
return getSystemEventQueueImplPP();
}
|
static EventQueue getSystemEventQueueImplPP() {
return getSystemEventQueueImplPP(AppContext.getAppContext());
}
|
public static EventQueue getSystemEventQueueImplPP(AppContext appContext) {
EventQueue theEventQueue =
(EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
return theEventQueue;
}
|
public static String getSystemProperty(String key) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(key);
}
});
}
Returns the value of the system property indicated by the specified key. |
public WindowClosingListener getWindowClosingListener() {
return windowClosingListener;
}
|
abstract public void grab(Window w)
Grabs the mouse input for the given window. The window must be
visible. The window or its children do not receive any
additional mouse events besides those targeted to them. All
other events will be dispatched as before - to the respective
targets. This Window will receive UngrabEvent when automatic
ungrab is about to happen. The event can be listened to by
installing AWTEventListener with WINDOW_EVENT_MASK. See
UngrabEvent class for the list of conditions when ungrab is
about to happen. |
public static void insertTargetMapping(Object target,
AppContext appContext) {
if (!GraphicsEnvironment.isHeadless()) {
if (!setAppContext(target, appContext)) {
// Target is not a Component/MenuComponent, use the private Map
// instead.
appContextMap.put(target, appContext);
}
}
}
|
public static void invokeLaterOnAppContext(AppContext appContext,
Runnable dispatcher) {
postEvent(appContext,
new PeerEvent(Toolkit.getDefaultToolkit(), dispatcher,
PeerEvent.PRIORITY_EVENT));
}
|
public static final boolean isAWTLockHeldByCurrentThread() {
return AWT_LOCK.isHeldByCurrentThread();
}
|
public static boolean isContainingTopLevelOpaque(Component c) {
Window w = getContainingWindow(c);
return w != null && w.isOpaque();
}
Returns whether or not a containing top level window for the passed
component is
PERPIXEL_TRANSLUCENT . |
public static boolean isContainingTopLevelTranslucent(Component c) {
Window w = getContainingWindow(c);
return w != null && ((Window)w).getOpacity() < 1.0f;
}
Returns whether or not a containing top level window for the passed
component is
TRANSLUCENT . |
abstract public boolean isDesktopSupported()
|
public static boolean isDispatchThreadForAppContext(Object target) {
AppContext appContext = targetToAppContext(target);
EventQueue eq = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
AWTAccessor.EventQueueAccessor accessor = AWTAccessor.getEventQueueAccessor();
return accessor.isDispatchThreadImpl(eq);
}
|
public static boolean isInstanceOf(Object obj,
String type) {
if (obj == null) return false;
if (type == null) return false;
return isInstanceOf(obj.getClass(), type);
}
Checks that the given object implements/extends the given
interface/class.
Note that using the instanceof operator causes a class to be loaded.
Using this method doesn't load a class and it can be used instead of
the instanceof operator for performance reasons. |
public static boolean isLightweightOrUnknown(Component comp) {
if (comp.isLightweight()
|| !(getDefaultToolkit() instanceof SunToolkit))
{
return true;
}
return !(comp instanceof Button
|| comp instanceof Canvas
|| comp instanceof Checkbox
|| comp instanceof Choice
|| comp instanceof Label
|| comp instanceof java.awt.List
|| comp instanceof Panel
|| comp instanceof Scrollbar
|| comp instanceof ScrollPane
|| comp instanceof TextArea
|| comp instanceof TextField
|| comp instanceof Window);
}
|
public static boolean isModalExcluded(Window window) {
if (DEFAULT_MODAL_EXCLUSION_TYPE == null) {
DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE;
}
return window.getModalExclusionType().compareTo(DEFAULT_MODAL_EXCLUSION_TYPE) >= 0;
}
|
public static boolean isModalExcludedSupported() {
Toolkit tk = Toolkit.getDefaultToolkit();
return tk.isModalExclusionTypeSupported(DEFAULT_MODAL_EXCLUSION_TYPE);
}
Returns whether the modal exclusion API is supported by the current toolkit.
When it isn't supported, calling setModalExcluded has no
effect, and isModalExcluded returns false for all windows. |
protected boolean isModalExcludedSupportedImpl() {
return false;
}
|
public boolean isModalExclusionTypeSupported(ModalExclusionType exclusionType) {
return (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE);
}
Overridden in XToolkit and WToolkit |
public boolean isModalityTypeSupported(ModalityType modalityType) {
return (modalityType == Dialog.ModalityType.MODELESS) ||
(modalityType == Dialog.ModalityType.APPLICATION_MODAL);
}
Overridden in XToolkit and WToolkit |
public boolean isNativeGTKAvailable() {
return false;
}
Returns true if the native GTK libraries are available. The
default implementation returns false, but UNIXToolkit overrides this
method to provide a more specific answer. |
public static boolean isPostEventQueueEmpty() {
AppContext appContext = AppContext.getAppContext();
PostEventQueue postEventQueue =
(PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
if (postEventQueue != null) {
return postEventQueue.noEvents();
} else {
return true;
}
}
|
public static boolean isSystemGenerated(AWTEvent e) {
return AWTAccessor.getAWTEventAccessor().isSystemGenerated(e);
}
|
public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
return false;
}
|
abstract public boolean isTraySupported()
|
public boolean isWindowOpacitySupported() {
return false;
}
|
public boolean isWindowShapingSupported() {
return false;
}
|
public boolean isWindowTranslucencySupported() {
return false;
}
|
protected final boolean isXEmbedServerRequested() {
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembedserver"));
}
Returns whether the XEmbed server feature is requested by
developer. If true, Toolkit should return an
XEmbed-server-enabled CanvasPeer instead of the ordinary CanvasPeer. |
public boolean needUpdateWindow() {
return false;
}
Returns whether the native system requires using the peer.updateWindow()
method to update the contents of a non-opaque window, or if usual
painting procedures are sufficient. The default return value covers
the X11 systems. On MS Windows this method is overriden in WToolkit
to return true. |
public static boolean needsXEmbed() {
String noxembed = (String) AccessController.
doPrivileged(new GetPropertyAction("sun.awt.noxembed", "false"));
if ("true".equals(noxembed)) {
return false;
}
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
// SunToolkit descendants should override this method to specify
// concrete behavior
return ((SunToolkit)tk).needsXEmbedImpl();
} else {
// Non-SunToolkit doubtly might support XEmbed
return false;
}
}
Returns whether default toolkit needs the support of the xembed
from embedding host(if any). |
protected boolean needsXEmbedImpl() {
return false;
}
Returns whether this toolkit needs the support of the xembed
from embedding host(if any). |
final void notifyModalityChange(int id,
Dialog source) {
ModalityEvent ev = new ModalityEvent(source, modalityListeners, id);
ev.dispatch();
}
|
public void notifyModalityPopped(Dialog dialog) {
notifyModalityChange(ModalityEvent.MODALITY_POPPED, dialog);
}
|
public void notifyModalityPushed(Dialog dialog) {
notifyModalityChange(ModalityEvent.MODALITY_PUSHED, dialog);
}
|
public static void postEvent(AppContext appContext,
AWTEvent event) {
if (event == null) {
throw new NullPointerException();
}
// All events posted via this method are system-generated.
// Placing the following call here reduces considerably the
// number of places throughout the toolkit that would
// otherwise have to be modified to precisely identify
// system-generated events.
setSystemGenerated(event);
AppContext eventContext = targetToAppContext(event.getSource());
if (eventContext != null && !eventContext.equals(appContext)) {
log.fine("Event posted on wrong app context : " + event);
}
PostEventQueue postEventQueue =
(PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
if (postEventQueue != null) {
postEventQueue.postEvent(event);
}
}
|
public static void postPriorityEvent(AWTEvent e) {
PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() {
public void run() {
AWTAccessor.getAWTEventAccessor().setPosted(e);
((Component)e.getSource()).dispatchEvent(e);
}
}, PeerEvent.ULTIMATE_PRIORITY_EVENT);
postEvent(targetToAppContext(e.getSource()), pe);
}
|
public boolean prepareImage(Image img,
int w,
int h,
ImageObserver o) {
if (w == 0 || h == 0) {
return true;
}
// Must be a ToolkitImage
if (!(img instanceof ToolkitImage)) {
return true;
}
ToolkitImage tkimg = (ToolkitImage)img;
if (tkimg.hasError()) {
if (o != null) {
o.imageUpdate(img, ImageObserver.ERROR|ImageObserver.ABORT,
-1, -1, -1, -1);
}
return false;
}
ImageRepresentation ir = tkimg.getImageRep();
return ir.prepare(o);
}
|
public void realSync() throws OperationTimedOut, InfiniteLoop {
realSync(DEFAULT_WAIT_TIME);
}
Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME). |
public void realSync(long timeout) throws OperationTimedOut, InfiniteLoop {
if (EventQueue.isDispatchThread()) {
throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT).");
}
int bigLoop = 0;
do {
// Let's do sync first
sync();
// During the wait process, when we were processing incoming
// events, we could have made some new request, which can
// generate new events. Example: MapNotify/XSetInputFocus.
// Therefore, we dispatch them as long as there is something
// to dispatch.
int iters = 0;
while (iters < MIN_ITERS) {
syncNativeQueue(timeout);
iters++;
}
while (syncNativeQueue(timeout) && iters < MAX_ITERS) {
iters++;
}
if (iters >= MAX_ITERS) {
throw new InfiniteLoop();
}
// native requests were dispatched by X/Window Manager or Windows
// Moreover, we processed them all on Toolkit thread
// Now wait while EDT processes them.
//
// During processing of some events (focus, for example),
// some other events could have been generated. So, after
// waitForIdle, we may end up with full EventQueue
iters = 0;
while (iters < MIN_ITERS) {
waitForIdle(timeout);
iters++;
}
while (waitForIdle(timeout) && iters < MAX_ITERS) {
iters++;
}
if (iters >= MAX_ITERS) {
throw new InfiniteLoop();
}
bigLoop++;
// Again, for Java events, it was simple to check for new Java
// events by checking event queue, but what if Java events
// resulted in native requests? Therefor, check native events again.
} while ((syncNativeQueue(timeout) || waitForIdle(timeout)) && bigLoop < MAX_ITERS);
}
Forces toolkit to synchronize with the native windowing
sub-system, flushing all pending work and waiting for all the
events to be processed. This method guarantees that after
return no additional Java events will be generated, unless
cause by user. Obviously, the method cannot be used on the
event dispatch thread (EDT). In case it nevertheless gets
invoked on this thread, the method throws the
IllegalThreadException runtime exception.
This method allows to write tests without explicit timeouts
or wait for some event. Example:
Frame f = ...;
f.setVisible(true);
((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
After realSync, f will be completely visible
on the screen, its getLocationOnScreen will be returning the
right result and it will be the focus owner.
Another example:
b.requestFocus();
((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
After realSync, b will be focus owner.
Notice that realSync isn't guaranteed to work if recurring
actions occur, such as if during processing of some event
another request which may generate some events occurs. By
default, sync tries to perform as much as {@value MAX_ITERS}
cycles of event processing, allowing for roughly {@value
MAX_ITERS} additional requests.
For example, requestFocus() generates native request, which
generates one or two Java focus events, which then generate a
serie of paint events, a serie of Java focus events, which then
generate a serie of paint events which then are processed -
three cycles, minimum. |
public void removeModalityListener(ModalityListener listener) {
modalityListeners.remove(listener);
}
|
public static void setAAFontSettingsCondition(boolean extraCondition) {
if (extraCondition != lastExtraCondition) {
lastExtraCondition = extraCondition;
if (checkedSystemAAFontSettings) {
/* Someone already asked for this info, under a different
* condition.
* We'll force re-evaluation instead of replicating the
* logic, then notify any listeners of any change.
*/
checkedSystemAAFontSettings = false;
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
((SunToolkit)tk).fireDesktopFontPropertyChanges();
}
}
}
}
|
protected static void setDataTransfererClassName(String className) {
dataTransfererClassName = className;
}
|
public static void setLWRequestStatus(Window changed,
boolean status) {
AWTAccessor.getWindowAccessor().setLWRequestStatus(changed, status);
}
Sets the synchronous status of focus requests on lightweight
components in the specified window to the specified value.
If the boolean parameter is true then the focus
requests on lightweight components will be performed
synchronously, if it is false , then asynchronously.
By default, all windows have their lightweight request status
set to asynchronous.
The application can only set the status of lightweight focus
requests to synchronous for any of its windows if it doesn't
perform focus transfers between different heavyweight containers.
In this case the observable focus behaviour is the same as with
asynchronous status.
If the application performs focus transfer between different
heavyweight containers and sets the lightweight focus request
status to synchronous for any of its windows, then further focus
behaviour is unspecified.
|
public static void setModalExcluded(Window window) {
if (DEFAULT_MODAL_EXCLUSION_TYPE == null) {
DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE;
}
window.setModalExclusionType(DEFAULT_MODAL_EXCLUSION_TYPE);
}
|
public static void setSystemGenerated(AWTEvent e) {
AWTAccessor.getAWTEventAccessor().setSystemGenerated(e);
}
|
public void setWindowClosingListener(WindowClosingListener wcl) {
windowClosingListener = wcl;
}
|
abstract protected boolean syncNativeQueue(long timeout)
Platform toolkits need to implement this method to perform the
sync of the native queue. The method should wait until native
requests are processed, all native events are processed and
corresponding Java events are generated. Should return
true if some events were processed,
false otherwise. |
protected static void targetCreatedPeer(Object target,
Object peer) {
if (target != null && peer != null &&
!GraphicsEnvironment.isHeadless())
{
AWTAutoShutdown.getInstance().registerPeer(target, peer);
}
}
|
protected static void targetDisposedPeer(Object target,
Object peer) {
if (target != null && peer != null &&
!GraphicsEnvironment.isHeadless())
{
AWTAutoShutdown.getInstance().unregisterPeer(target, peer);
}
}
|
public static AppContext targetToAppContext(Object target) {
if (target == null || GraphicsEnvironment.isHeadless()) {
return null;
}
AppContext context = getAppContext(target);
if (context == null) {
// target is not a Component/MenuComponent, try the
// appContextMap.
context = (AppContext)appContextMap.get(target);
}
return context;
}
|
protected static Object targetToPeer(Object target) {
if (target != null && !GraphicsEnvironment.isHeadless()) {
return AWTAutoShutdown.getInstance().getPeer(target);
}
return null;
}
|
abstract public void ungrab(Window w)
Forces ungrab. No event will be sent. |
public boolean useBufferPerWindow() {
return false;
}
|
protected final boolean waitForIdle(long timeout) {
flushPendingEvents();
boolean queueWasEmpty = isEQEmpty();
queueEmpty = false;
eventDispatched = false;
synchronized(waitLock) {
postEvent(AppContext.getAppContext(),
new PeerEvent(getSystemEventQueueImpl(), null, PeerEvent.LOW_PRIORITY_EVENT) {
public void dispatch() {
// Here we block EDT. It could have some
// events, it should have dispatched them by
// now. So native requests could have been
// generated. First, dispatch them. Then,
// flush Java events again.
int iters = 0;
while (iters < MIN_ITERS) {
syncNativeQueue(timeout);
iters++;
}
while (syncNativeQueue(timeout) && iters < MAX_ITERS) {
iters++;
}
flushPendingEvents();
synchronized(waitLock) {
queueEmpty = isEQEmpty();
eventDispatched = true;
waitLock.notifyAll();
}
}
});
try {
while (!eventDispatched) {
waitLock.wait();
}
} catch (InterruptedException ie) {
return false;
}
}
try {
Thread.sleep(MINIMAL_EDELAY);
} catch (InterruptedException ie) {
throw new RuntimeException("Interrupted");
}
flushPendingEvents();
// Lock to force write-cache flush for queueEmpty.
synchronized (waitLock) {
return !(queueEmpty && isEQEmpty() && queueWasEmpty);
}
}
Waits for the Java event queue to empty. Ensures that all
events are processed (including paint events), and that if
recursive events were generated, they are also processed.
Should return true if more processing is
necessary, false otherwise. |
static void wakeupEventQueue(EventQueue q,
boolean isShutdown) {
if (wakeupMethod == null){
wakeupMethod = (Method)AccessController.doPrivileged(new PrivilegedAction(){
public Object run(){
try {
Method method = EventQueue.class.getDeclaredMethod("wakeup",new Class [] {Boolean.TYPE} );
if (method != null) {
method.setAccessible(true);
}
return method;
} catch (NoSuchMethodException e) {
assert false;
} catch (SecurityException e) {
assert false;
}
return null;
}//run
});
}
try{
if (wakeupMethod != null){
wakeupMethod.invoke(q, new Object[]{Boolean.valueOf(isShutdown)});
}
} catch (InvocationTargetException e){
assert false;
} catch (IllegalAccessException e) {
assert false;
}
}
|
public RuntimeException windowClosingDelivered(WindowEvent event) {
if (windowClosingListener != null) {
return windowClosingListener.windowClosingDelivered(event);
} else {
return null;
}
}
|
public RuntimeException windowClosingNotify(WindowEvent event) {
if (windowClosingListener != null) {
return windowClosingListener.windowClosingNotify(event);
} else {
return null;
}
}
|