Home » openjdk-7 » java » awt » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package java.awt;
   19   
   20   import java.awt.datatransfer.Clipboard;
   21   import java.awt.dnd.DragGestureEvent;
   22   import java.awt.dnd.InvalidDnDOperationException;
   23   import java.awt.dnd.peer.DragSourceContextPeer;
   24   import java.awt.im.InputMethodHighlight;
   25   import java.awt.image.ColorModel;
   26   import java.awt.image.ImageObserver;
   27   import java.awt.image.ImageProducer;
   28   import java.awt.peer;
   29   import java.io.Serializable;
   30   import java.net.URL;
   31   import java.util.Hashtable;
   32   import java.util.Map;
   33   import java.util.Properties;
   34   import org.apache.harmony.awt.gl.font.FontMetricsImpl;
   35   import org.apache.harmony.awt.datatransfer.DTK;
   36   import org.apache.harmony.awt.gl;
   37   import org.apache.harmony.awt.gl.image;
   38   import java.awt.datatransfer.StringSelection;
   39   
   40   class ToolkitImpl extends Toolkit {
   41       static final Hashtable<Serializable, Image> imageCache = new Hashtable<Serializable, Image>();
   42   
   43       static final FontMetrics cacheFM[] =  new FontMetrics[10];
   44   
   45       @Override
   46       public void sync() {
   47           lockAWT();
   48           try {
   49           } finally {
   50               unlockAWT();
   51           }
   52       }
   53   
   54       @Override
   55       protected TextAreaPeer createTextArea(TextArea a0) {
   56           lockAWT();
   57           try {
   58               return null;
   59           } finally {
   60               unlockAWT();
   61           }
   62       }
   63   
   64       @Override
   65       public int checkImage(Image image, int width, int height, ImageObserver observer) {
   66           lockAWT();
   67           try {
   68               if (width == 0 || height == 0) {
   69                   return ImageObserver.ALLBITS;
   70               }
   71               if (!(image instanceof OffscreenImage)) {
   72                   return ImageObserver.ALLBITS;
   73               }
   74               OffscreenImage oi = (OffscreenImage) image;
   75               return oi.checkImage(observer);
   76           } finally {
   77               unlockAWT();
   78           }
   79       }
   80   
   81       @Override
   82       public Image createImage(ImageProducer producer) {
   83           lockAWT();
   84           try {
   85               return new OffscreenImage(producer);
   86           } finally {
   87               unlockAWT();
   88           }
   89       }
   90   
   91       @Override
   92       public Image createImage(byte[] imagedata, int imageoffset, int imagelength) {
   93           lockAWT();
   94           try {
   95               return new OffscreenImage(new ByteArrayDecodingImageSource(imagedata, imageoffset,
   96                       imagelength));
   97           } finally {
   98               unlockAWT();
   99           }
  100       }
  101   
  102       @Override
  103       public Image createImage(URL url) {
  104           lockAWT();
  105           try {
  106               return new OffscreenImage(new URLDecodingImageSource(url));
  107           } finally {
  108               unlockAWT();
  109           }
  110       }
  111   
  112       @Override
  113       public Image createImage(String filename) {
  114           lockAWT();
  115           try {
  116               return new OffscreenImage(new FileDecodingImageSource(filename));
  117           } finally {
  118               unlockAWT();
  119           }
  120       }
  121   
  122       @Override
  123       public ColorModel getColorModel() {
  124           lockAWT();
  125           try {
  126               return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
  127                       .getDefaultConfiguration().getColorModel();
  128           } finally {
  129               unlockAWT();
  130           }
  131       }
  132   
  133       /**
  134        * Returns FontMetrics object that keeps metrics of the specified font.
  135        * 
  136        * @param font specified Font
  137        * @return FontMetrics object corresponding to the specified Font object
  138        */
  139       @Override
  140       @Deprecated
  141       public FontMetrics getFontMetrics(Font font) {
  142           lockAWT();
  143           try {
  144               FontMetrics fm;
  145               for (FontMetrics element : cacheFM) {
  146                   fm = element;
  147                   if (fm == null){
  148                       break;
  149                   }
  150   
  151                   if (fm.getFont().equals(font)){
  152                       return fm;
  153                   }
  154               }
  155               fm = new FontMetricsImpl(font);
  156   
  157               System.arraycopy(cacheFM, 0, cacheFM, 1, cacheFM.length -1);
  158               cacheFM[0] = fm;
  159   
  160               return fm;
  161   
  162   //            return getGraphicsFactory().getFontMetrics(font);
  163           } finally {
  164               unlockAWT();
  165           }
  166       }
  167   
  168       @Override
  169       public boolean prepareImage(Image image, int width, int height, ImageObserver observer) {
  170           lockAWT();
  171           try {
  172               if (width == 0 || height == 0) {
  173                   return true;
  174               }
  175               if (!(image instanceof OffscreenImage)) {
  176                   return true;
  177               }
  178               OffscreenImage oi = (OffscreenImage) image;
  179               return oi.prepareImage(observer);
  180           } finally {
  181               unlockAWT();
  182           }
  183       }
  184   
  185       @Override
  186       public void beep() {
  187           lockAWT();
  188           try {
  189           } finally {
  190               unlockAWT();
  191           }
  192       }
  193   
  194       @Override
  195       protected ButtonPeer createButton(Button a0) {
  196           lockAWT();
  197           try {
  198               return null;
  199           } finally {
  200               unlockAWT();
  201           }
  202       }
  203   
  204       @Override
  205       protected CanvasPeer createCanvas(Canvas a0) {
  206           lockAWT();
  207           try {
  208               return null;
  209           } finally {
  210               unlockAWT();
  211           }
  212       }
  213   
  214       @Override
  215       protected CheckboxPeer createCheckbox(Checkbox a0) {
  216           lockAWT();
  217           try {
  218               return null;
  219           } finally {
  220               unlockAWT();
  221           }
  222       }
  223   
  224       @Override
  225       protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem a0)
  226               throws HeadlessException {
  227           lockAWT();
  228           try {
  229               return null;
  230           } finally {
  231               unlockAWT();
  232           }
  233       }
  234   
  235       @Override
  236       protected ChoicePeer createChoice(Choice a0) {
  237           lockAWT();
  238           try {
  239               return null;
  240           } finally {
  241               unlockAWT();
  242           }
  243       }
  244   
  245       @Override
  246       protected DialogPeer createDialog(Dialog a0) {
  247           lockAWT();
  248           try {
  249               return null;
  250           } finally {
  251               unlockAWT();
  252           }
  253       }
  254   
  255       @Override
  256       public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
  257               throws InvalidDnDOperationException {
  258           return dtk.createDragSourceContextPeer(dge);
  259       }
  260   
  261       @Override
  262       protected FileDialogPeer createFileDialog(FileDialog a0) {
  263           lockAWT();
  264           try {
  265               return null;
  266           } finally {
  267               unlockAWT();
  268           }
  269       }
  270   
  271       @Override
  272       protected FramePeer createFrame(Frame a0) {
  273           lockAWT();
  274           try {
  275               return null;
  276           } finally {
  277               unlockAWT();
  278           }
  279       }
  280   
  281       @Override
  282       protected LabelPeer createLabel(Label a0) {
  283           lockAWT();
  284           try {
  285               return null;
  286           } finally {
  287               unlockAWT();
  288           }
  289       }
  290   
  291       @Override
  292       protected ListPeer createList(List a0) {
  293           lockAWT();
  294           try {
  295               return null;
  296           } finally {
  297               unlockAWT();
  298           }
  299       }
  300   
  301       @Override
  302       protected MenuPeer createMenu(Menu a0) {
  303           lockAWT();
  304           try {
  305               return null;
  306           } finally {
  307               unlockAWT();
  308           }
  309       }
  310   
  311       @Override
  312       protected MenuBarPeer createMenuBar(MenuBar a0) {
  313           lockAWT();
  314           try {
  315               return null;
  316           } finally {
  317               unlockAWT();
  318           }
  319       }
  320   
  321       @Override
  322       protected MenuItemPeer createMenuItem(MenuItem a0) {
  323           lockAWT();
  324           try {
  325               return null;
  326           } finally {
  327               unlockAWT();
  328           }
  329       }
  330   
  331       @Override
  332       protected PanelPeer createPanel(Panel a0) {
  333           lockAWT();
  334           try {
  335               return null;
  336           } finally {
  337               unlockAWT();
  338           }
  339       }
  340   
  341       @Override
  342       protected PopupMenuPeer createPopupMenu(PopupMenu a0) {
  343           lockAWT();
  344           try {
  345               return null;
  346           } finally {
  347               unlockAWT();
  348           }
  349       }
  350   
  351       @Override
  352       protected ScrollPanePeer createScrollPane(ScrollPane a0) {
  353           lockAWT();
  354           try {
  355               return null;
  356           } finally {
  357               unlockAWT();
  358           }
  359       }
  360   
  361       @Override
  362       protected ScrollbarPeer createScrollbar(Scrollbar a0) {
  363           lockAWT();
  364           try {
  365               return null;
  366           } finally {
  367               unlockAWT();
  368           }
  369       }
  370   
  371       @Override
  372       protected TextFieldPeer createTextField(TextField a0) {
  373           lockAWT();
  374           try {
  375               return null;
  376           } finally {
  377               unlockAWT();
  378           }
  379       }
  380   
  381       @Override
  382       protected WindowPeer createWindow(Window a0) {
  383           lockAWT();
  384           try {
  385               return null;
  386           } finally {
  387               unlockAWT();
  388           }
  389       }
  390   
  391       @Override
  392       @Deprecated
  393       public String[] getFontList() {
  394           lockAWT();
  395           try {
  396           } finally {
  397               unlockAWT();
  398           }
  399           return null;
  400       }
  401   
  402       @Override
  403       @Deprecated
  404       protected FontPeer getFontPeer(String a0, int a1) {
  405           lockAWT();
  406           try {
  407               return null;
  408           } finally {
  409               unlockAWT();
  410           }
  411       }
  412   
  413       @Override
  414       public Image getImage(String filename) {
  415           return getImage(filename, this);
  416       }
  417   
  418       static Image getImage(String filename, Toolkit toolkit) {
  419           synchronized (imageCache) {
  420               Image im = (filename == null ? null : imageCache.get(filename));
  421   
  422               if (im == null) {
  423                   try {
  424                       im = toolkit.createImage(filename);
  425                       imageCache.put(filename, im);
  426                   } catch (Exception e) {
  427                   }
  428               }
  429   
  430               return im;
  431           }
  432       }
  433   
  434       @Override
  435       public Image getImage(URL url) {
  436           return getImage(url, this);
  437       }
  438   
  439       static Image getImage(URL url, Toolkit toolkit) {
  440           synchronized (imageCache) {
  441               Image im = imageCache.get(url);
  442               if (im == null) {
  443                   try {
  444                       im = toolkit.createImage(url);
  445                       imageCache.put(url, im);
  446                   } catch (Exception e) {
  447                   }
  448               }
  449               return im;
  450           }
  451       }
  452   
  453       @Override
  454       public PrintJob getPrintJob(Frame a0, String a1, Properties a2) {
  455           lockAWT();
  456           try {
  457           } finally {
  458               unlockAWT();
  459           }
  460           return null;
  461       }
  462   
  463       @Override
  464       public int getScreenResolution() throws HeadlessException {
  465           lockAWT();
  466           try {
  467               return ((GLGraphicsDevice) GraphicsEnvironment.getLocalGraphicsEnvironment()
  468                       .getDefaultScreenDevice()).getResolution().width;
  469           } finally {
  470               unlockAWT();
  471           }
  472       }
  473   
  474       @Override
  475       public Dimension getScreenSize() {
  476           lockAWT();
  477           try {
  478               DisplayMode dm = GraphicsEnvironment.getLocalGraphicsEnvironment()
  479                       .getDefaultScreenDevice().getDisplayMode();
  480               return new Dimension(dm.getWidth(), dm.getHeight());
  481           } finally {
  482               unlockAWT();
  483           }
  484       }
  485   
  486       @Override
  487       public Clipboard getSystemClipboard() {
  488           lockAWT();
  489           try {
  490               SecurityManager security = System.getSecurityManager();
  491               if (security != null) {
  492                   security.checkSystemClipboardAccess();
  493               }
  494               if (systemClipboard == null) {
  495                   systemClipboard = DTK.getDTK().getNativeClipboard();
  496               }
  497               if (systemClipboard.getContents(null) == null) {
  498                   systemClipboard.setContents ( new StringSelection("") , null);
  499               }
  500               return systemClipboard;
  501           } finally {
  502               unlockAWT();
  503           }
  504       }
  505   
  506       @Override
  507       public Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
  508               InputMethodHighlight highlight) throws HeadlessException {
  509           lockAWT();
  510           try {
  511               return mapInputMethodHighlightImpl(highlight);
  512           } finally {
  513               unlockAWT();
  514           }
  515       }
  516   
  517       @Override
  518       protected EventQueue getSystemEventQueueImpl() {
  519           return getSystemEventQueueCore().getActiveEventQueue();
  520       }
  521   }

Home » openjdk-7 » java » awt » [javadoc | source]