src/java.desktop/share/classes/sun/awt/SunToolkit.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -24,41 +24,55 @@
  */
 
 package sun.awt;
 
 import java.awt.*;
-import static java.awt.RenderingHints.*;
-import java.awt.dnd.*;
-import java.awt.dnd.peer.DragSourceContextPeer;
-import java.awt.peer.*;
-import java.awt.event.WindowEvent;
-import java.awt.event.KeyEvent;
-import java.awt.image.*;
-import java.awt.TrayIcon;
-import java.awt.SystemTray;
 import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferInt;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.awt.image.Raster;
+import java.awt.peer.FramePeer;
+import java.awt.peer.KeyboardFocusManagerPeer;
+import java.awt.peer.MouseInfoPeer;
+import java.awt.peer.SystemTrayPeer;
+import java.awt.peer.TrayIconPeer;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
-import java.security.PrivilegedAction;
-import java.util.*;
+import java.security.AccessController;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Vector;
+import java.util.WeakHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import sun.awt.datatransfer.DataTransferer;
-import sun.util.logging.PlatformLogger;
-import sun.misc.SoftCache;
-import sun.font.FontDesignMetrics;
 import sun.awt.im.InputContext;
-import sun.awt.image.*;
-import sun.security.action.GetPropertyAction;
+import sun.awt.image.ByteArrayImageSource;
+import sun.awt.image.FileImageSource;
+import sun.awt.image.ImageRepresentation;
+import sun.awt.image.MultiResolutionImage;
+import sun.awt.image.MultiResolutionToolkitImage;
+import sun.awt.image.ToolkitImage;
+import sun.awt.image.URLImageSource;
+import sun.font.FontDesignMetrics;
+import sun.misc.SoftCache;
 import sun.security.action.GetBooleanAction;
-import java.lang.reflect.InvocationTargetException;
-import java.security.AccessController;
+import sun.security.action.GetPropertyAction;
+import sun.util.logging.PlatformLogger;
+
+import static java.awt.RenderingHints.*;
 
 public abstract class SunToolkit extends Toolkit
     implements ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider {
 
     // 8014718: logging has been removed from SunToolkit

@@ -132,85 +146,21 @@
 
     public boolean useBufferPerWindow() {
         return false;
     }
 
-    public abstract WindowPeer createWindow(Window target)
-        throws HeadlessException;
-
-    public abstract FramePeer createFrame(Frame target)
-        throws HeadlessException;
-
     public abstract FramePeer createLightweightFrame(LightweightFrame target)
         throws HeadlessException;
 
-    public abstract DialogPeer createDialog(Dialog target)
-        throws HeadlessException;
-
-    public abstract ButtonPeer createButton(Button target)
-        throws HeadlessException;
-
-    public abstract TextFieldPeer createTextField(TextField target)
-        throws HeadlessException;
-
-    public abstract ChoicePeer createChoice(Choice target)
-        throws HeadlessException;
-
-    public abstract LabelPeer createLabel(Label target)
-        throws HeadlessException;
-
-    public abstract ListPeer createList(java.awt.List target)
-        throws HeadlessException;
-
-    public abstract CheckboxPeer createCheckbox(Checkbox target)
-        throws HeadlessException;
-
-    public abstract ScrollbarPeer createScrollbar(Scrollbar target)
-        throws HeadlessException;
-
-    public abstract ScrollPanePeer createScrollPane(ScrollPane target)
-        throws HeadlessException;
-
-    public abstract TextAreaPeer createTextArea(TextArea target)
-        throws HeadlessException;
-
-    public abstract FileDialogPeer createFileDialog(FileDialog target)
-        throws HeadlessException;
-
-    public abstract MenuBarPeer createMenuBar(MenuBar target)
-        throws HeadlessException;
-
-    public abstract MenuPeer createMenu(Menu target)
-        throws HeadlessException;
-
-    public abstract PopupMenuPeer createPopupMenu(PopupMenu target)
-        throws HeadlessException;
-
-    public abstract MenuItemPeer createMenuItem(MenuItem target)
-        throws HeadlessException;
-
-    public abstract CheckboxMenuItemPeer createCheckboxMenuItem(
-        CheckboxMenuItem target)
-        throws HeadlessException;
-
-    public abstract DragSourceContextPeer createDragSourceContextPeer(
-        DragGestureEvent dge)
-        throws InvalidDnDOperationException;
-
     public abstract TrayIconPeer createTrayIcon(TrayIcon target)
         throws HeadlessException, AWTException;
 
     public abstract SystemTrayPeer createSystemTray(SystemTray target);
 
     public abstract boolean isTraySupported();
 
-    @SuppressWarnings("deprecation")
-    public abstract FontPeer getFontPeer(String name, int style);
-
-    public abstract RobotPeer createRobot(Robot target, GraphicsDevice screen)
-        throws AWTException;
-
+    @Override
     public abstract KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
         throws HeadlessException;
 
     /**
      * The AWT lock is typically only used on Unix platforms to synchronize

@@ -509,10 +459,11 @@
     /*
      * Post AWTEvent of high priority.
      */
     public static void postPriorityEvent(final AWTEvent e) {
         PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() {
+                @Override
                 public void run() {
                     AWTAccessor.getAWTEventAccessor().setPosted(e);
                     ((Component)e.getSource()).dispatchEvent(e);
                 }
             }, PeerEvent.ULTIMATE_PRIORITY_EVENT);

@@ -559,10 +510,11 @@
     public static void executeOnEventHandlerThread(Object target,
                                                    Runnable runnable,
                                                    final long when) {
         executeOnEventHandlerThread(
             new PeerEvent(target, runnable, PeerEvent.PRIORITY_EVENT) {
+                @Override
                 public long getWhen() {
                     return when;
                 }
             });
     }

@@ -634,21 +586,24 @@
 
         AWTAccessor.EventQueueAccessor accessor = AWTAccessor.getEventQueueAccessor();
         return accessor.isDispatchThreadImpl(eq);
     }
 
+    @Override
     public Dimension getScreenSize() {
         return new Dimension(getScreenWidth(), getScreenHeight());
     }
     protected abstract int getScreenWidth();
     protected abstract int getScreenHeight();
 
+    @Override
     @SuppressWarnings("deprecation")
     public FontMetrics getFontMetrics(Font font) {
         return FontDesignMetrics.getMetrics(font);
     }
 
+    @Override
     @SuppressWarnings("deprecation")
     public String[] getFontList() {
         String[] hardwiredFontList = {
             Font.DIALOG, Font.SANS_SERIF, Font.SERIF, Font.MONOSPACED,
             Font.DIALOG_INPUT

@@ -658,18 +613,10 @@
             //    "Helvetica", "TimesRoman", "Courier", "ZapfDingbats"
         };
         return hardwiredFontList;
     }
 
-    public PanelPeer createPanel(Panel target) {
-        return (PanelPeer)createComponent(target);
-    }
-
-    public CanvasPeer createCanvas(Canvas target) {
-        return (CanvasPeer)createComponent(target);
-    }
-
     /**
      * 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

@@ -745,14 +692,16 @@
             }
             return img;
         }
     }
 
+    @Override
     public Image getImage(String filename) {
         return getImageFromHash(this, filename);
     }
 
+    @Override
     public Image getImage(URL url) {
         return getImageFromHash(this, url);
     }
 
     protected Image getImageWithResolutionVariant(String fileName,

@@ -782,33 +731,38 @@
             return image;
         }
     }
 
 
+    @Override
     public Image createImage(String filename) {
         checkPermissions(filename);
         return createImage(new FileImageSource(filename));
     }
 
+    @Override
     public Image createImage(URL url) {
         checkPermissions(url);
         return createImage(new URLImageSource(url));
     }
 
+    @Override
     public Image createImage(byte[] data, int offset, int length) {
         return createImage(new ByteArrayImageSource(data, offset, length));
     }
 
+    @Override
     public Image createImage(ImageProducer producer) {
         return new ToolkitImage(producer);
     }
 
     public static Image createImageWithResolutionVariant(Image image,
             Image resolutionVariant) {
         return new MultiResolutionToolkitImage(image, resolutionVariant);
     }
 
+    @Override
     public int checkImage(Image img, int w, int h, ImageObserver o) {
         if (!(img instanceof ToolkitImage)) {
             return ImageObserver.ALLBITS;
         }
 

@@ -820,10 +774,11 @@
             repbits = tkimg.getImageRep().check(o);
         }
         return (tkimg.check(o) | repbits) & checkResolutionVariant(img, w, h, o);
     }
 
+    @Override
     public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
         if (w == 0 || h == 0) {
             return true;
         }
 

@@ -1061,10 +1016,11 @@
         Raster raster = bimage.getRaster();
         DataBuffer buffer = raster.getDataBuffer();
         return (DataBufferInt)buffer;
     }
 
+    @Override
     protected EventQueue getSystemEventQueueImpl() {
         return getSystemEventQueueImplPP();
     }
 
     // Package private implementation

@@ -1142,18 +1098,20 @@
      * sun.awt.im.InputMethodWindow.
      * <p>
      * SunToolkit subclasses can override this method to return better input
      * method windows.
      */
+    @Override
     public Window createInputMethodWindow(String title, InputContext context) {
         return new sun.awt.im.SimpleInputMethodWindow(title, context);
     }
 
     /**
      * Returns whether enableInputMethods should be set to true for peered
      * TextComponent instances on this platform. False by default.
      */
+    @Override
     public boolean enableInputMethodsForTextComponent() {
         return false;
     }
 
     private static Locale startupLocale = null;

@@ -1191,17 +1149,19 @@
     }
 
     /**
      * Returns the default keyboard locale of the underlying operating system
      */
+    @Override
     public Locale getDefaultKeyboardLocale() {
         return getStartupLocale();
     }
 
     private static DefaultMouseInfoPeer mPeer = null;
 
-    protected synchronized MouseInfoPeer getMouseInfoPeer() {
+    @Override
+    public synchronized MouseInfoPeer getMouseInfoPeer() {
         if (mPeer == null) {
             mPeer = new DefaultMouseInfoPeer();
         }
         return mPeer;
     }

@@ -1329,18 +1289,20 @@
     }
 
     /**
      * Overridden in XToolkit and WToolkit
      */
+    @Override
     public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
         return (modalityType == Dialog.ModalityType.MODELESS) ||
                (modalityType == Dialog.ModalityType.APPLICATION_MODAL);
     }
 
     /**
      * Overridden in XToolkit and WToolkit
      */
+    @Override
     public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
         return (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE);
     }
 
     ///////////////////////////////////////////////////////////////////////////

@@ -1384,17 +1346,19 @@
 
         void remove(ModalityListener listener) {
             listeners.removeElement(listener);
         }
 
+        @Override
         public void modalityPushed(ModalityEvent ev) {
             Iterator<ModalityListener> it = listeners.iterator();
             while (it.hasNext()) {
                 it.next().modalityPushed(ev);
             }
         }
 
+        @Override
         public void modalityPopped(ModalityEvent ev) {
             Iterator<ModalityListener> it = listeners.iterator();
             while (it.hasNext()) {
                 it.next().modalityPopped(ev);
             }

@@ -1590,10 +1554,11 @@
         queueEmpty = false;
         eventDispatched = false;
         synchronized(waitLock) {
             postEvent(AppContext.getAppContext(),
                       new PeerEvent(getSystemEventQueueImpl(), null, PeerEvent.LOW_PRIORITY_EVENT) {
+                          @Override
                           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,