/[classpath]/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java
ViewVC logotype

Diff of /classpath/gnu/java/awt/peer/gtk/GtkToolkit.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.55 by mkoch, Sat Oct 2 07:53:48 2004 UTC revision 1.56 by mkoch, Fri Oct 8 21:41:41 2004 UTC
# Line 42  import gnu.classpath.Configuration; Line 42  import gnu.classpath.Configuration;
42  import gnu.java.awt.EmbeddedWindow;  import gnu.java.awt.EmbeddedWindow;
43  import gnu.java.awt.EmbeddedWindowSupport;  import gnu.java.awt.EmbeddedWindowSupport;
44  import gnu.java.awt.peer.ClasspathFontPeer;  import gnu.java.awt.peer.ClasspathFontPeer;
45    import gnu.java.awt.peer.ClasspathTextLayoutPeer;
46  import gnu.java.awt.peer.EmbeddedWindowPeer;  import gnu.java.awt.peer.EmbeddedWindowPeer;
47  import gnu.java.awt.peer.gtk.GdkPixbufDecoder;  import gnu.java.awt.peer.gtk.GdkPixbufDecoder;
48    
# Line 49  import java.awt.*; Line 50  import java.awt.*;
50  import java.awt.datatransfer.Clipboard;  import java.awt.datatransfer.Clipboard;
51  import java.awt.dnd.DragGestureEvent;  import java.awt.dnd.DragGestureEvent;
52  import java.awt.dnd.peer.DragSourceContextPeer;  import java.awt.dnd.peer.DragSourceContextPeer;
53    import java.awt.font.FontRenderContext;
54  import java.awt.font.TextAttribute;  import java.awt.font.TextAttribute;
55  import java.awt.im.InputMethodHighlight;  import java.awt.im.InputMethodHighlight;
56  import java.awt.image.BufferedImage;  import java.awt.image.BufferedImage;
# Line 58  import java.awt.image.ImageObserver; Line 60  import java.awt.image.ImageObserver;
60  import java.awt.image.ImageProducer;  import java.awt.image.ImageProducer;
61  import java.awt.peer.*;  import java.awt.peer.*;
62  import java.net.URL;  import java.net.URL;
63    import java.text.AttributedString;
64    import java.util.HashMap;
65  import java.util.HashSet;  import java.util.HashSet;
66  import java.util.Hashtable;  import java.util.Hashtable;
67  import java.util.Iterator;  import java.util.Iterator;
# Line 302  public class GtkToolkit extends gnu.java Line 306  public class GtkToolkit extends gnu.java
306                             "SansSerif" });                             "SansSerif" });
307    }    }
308    
309      private class LRUCache extends java.util.LinkedHashMap
310      {    
311        int max_entries;
312        public LRUCache(int max)
313        {
314          super(max, 0.75f, true);
315          max_entries = max;
316        }
317        protected boolean removeEldestEntry(Map.Entry eldest)
318        {
319          return size() > max_entries;
320        }
321      }
322    
323      private LRUCache fontCache = new LRUCache(50);
324      private LRUCache metricsCache = new LRUCache(50);
325      private LRUCache imageCache = new LRUCache(50);
326    
327    public FontMetrics getFontMetrics (Font font)    public FontMetrics getFontMetrics (Font font)
328    {    {
329      if (useGraphics2D())      if (metricsCache.containsKey(font))
330        return new GdkClasspathFontPeerMetrics (font);        return (FontMetrics) metricsCache.get(font);
331      else      else
332        return new GdkFontMetrics (font);        {
333            FontMetrics m;
334            m = new GdkFontMetrics (font);
335            metricsCache.put(font, m);
336            return m;
337          }    
338    }    }
339    
340    public Image getImage (String filename)    public Image getImage (String filename)
341    {    {
342      return createImage (filename);      if (imageCache.containsKey(filename))
343          return (Image) imageCache.get(filename);
344        else
345          {
346            Image im = createImage(filename);
347            imageCache.put(filename, im);
348            return im;
349          }
350    }    }
351    
352    public Image getImage (URL url)    public Image getImage (URL url)
353    {    {
354      return createImage (url);      if (imageCache.containsKey(url))
355          return (Image) imageCache.get(url);
356        else
357          {
358            Image im = createImage(url);
359            imageCache.put(url, im);
360            return im;
361          }
362    }    }
363    
364    public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props)    public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props)
# Line 508  public class GtkToolkit extends gnu.java Line 549  public class GtkToolkit extends gnu.java
549     */     */
550    private FontPeer getFontPeer (String name, int style, int size)    private FontPeer getFontPeer (String name, int style, int size)
551    {    {
552      GtkFontPeer fp = new GtkFontPeer (name, style, size);      Map attrs = new HashMap ();
553      return fp;      ClasspathFontPeer.copyStyleToAttrs (style, attrs);
554        ClasspathFontPeer.copySizeToAttrs (size, attrs);
555        return getClasspathFontPeer (name, attrs);
556    }    }
557    
558    /**    /**
# Line 520  public class GtkToolkit extends gnu.java Line 563  public class GtkToolkit extends gnu.java
563    
564    public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)    public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
565    {    {
566      if (useGraphics2D())      Map keyMap = new HashMap (attrs);
567        return new GdkClasspathFontPeer (name, attrs);      // We don't know what kind of "name" the user requested (logical, face,
568        // family), and we don't actually *need* to know here. The worst case
569        // involves failure to consolidate fonts with the same backend in our
570        // cache. This is harmless.
571        keyMap.put ("GtkToolkit.RequestedFontName", name);
572        if (fontCache.containsKey (keyMap))
573          return (ClasspathFontPeer) fontCache.get (keyMap);
574      else      else
575        {        {
576          // Default values          ClasspathFontPeer newPeer = new GdkFontPeer (name, attrs);
577          int size = 12;          fontCache.put (keyMap, newPeer);
578          int style = Font.PLAIN;          return newPeer;
         if (name == null)  
           name = "Default";  
   
         if (attrs.containsKey (TextAttribute.WEIGHT))  
           {  
             Float weight = (Float) attrs.get (TextAttribute.WEIGHT);  
             if (weight.floatValue () >= TextAttribute.WEIGHT_BOLD.floatValue ())  
               style += Font.BOLD;  
579            }            }
           
         if (attrs.containsKey (TextAttribute.POSTURE))  
           {  
             Float posture = (Float) attrs.get (TextAttribute.POSTURE);  
             if (posture.floatValue () >= TextAttribute.POSTURE_OBLIQUE.floatValue ())  
               style += Font.ITALIC;  
580            }            }
581                    
582          if (attrs.containsKey (TextAttribute.SIZE))    public ClasspathTextLayoutPeer getClasspathTextLayoutPeer (AttributedString str,
583                                                                 FontRenderContext frc)
584            {            {
585              Float fsize = (Float) attrs.get (TextAttribute.SIZE);      return new GdkTextLayout(str, frc);
             size = fsize.intValue();  
           }  
   
         return (ClasspathFontPeer) this.getFontPeer (name, style, size);  
       }  
586    }    }
587    
588    protected EventQueue getSystemEventQueueImpl()    protected EventQueue getSystemEventQueueImpl()

Legend:
Removed from v.1.55  
changed lines
  Added in v.1.56

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26