8035165: Expose internal representation in sun.awt.X11
authorserb
Sat, 26 Jul 2014 04:02:56 +0400
changeset 26007 dba8f49653ce
parent 26006 da0572ecab20
child 26008 ccab11700f07
8035165: Expose internal representation in sun.awt.X11 Reviewed-by: pchelko, prr
jdk/src/macosx/classes/sun/font/CFontManager.java
jdk/src/share/classes/sun/font/SunFontManager.java
jdk/src/solaris/classes/sun/awt/X11/ListHelper.java
jdk/src/solaris/classes/sun/awt/X11/XSelection.java
jdk/src/solaris/classes/sun/awt/X11FontManager.java
jdk/src/windows/classes/sun/awt/Win32FontManager.java
--- a/jdk/src/macosx/classes/sun/font/CFontManager.java	Sat Jul 26 03:18:05 2014 +0400
+++ b/jdk/src/macosx/classes/sun/font/CFontManager.java	Sat Jul 26 04:02:56 2014 +0400
@@ -43,7 +43,7 @@
 import sun.awt.util.ThreadGroupUtils;
 import sun.lwawt.macosx.*;
 
-public class CFontManager extends SunFontManager {
+public final class CFontManager extends SunFontManager {
     private FontConfigManager fcManager = null;
     private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
 
@@ -61,20 +61,14 @@
         return new CFontConfiguration(this, preferLocaleFonts, preferPropFonts);
     }
 
-    private static String[] defaultPlatformFont = null;
-
     /*
      * Returns an array of two strings. The first element is the
      * name of the font. The second element is the file name.
      */
     @Override
-    public synchronized String[] getDefaultPlatformFont() {
-        if (defaultPlatformFont == null) {
-            defaultPlatformFont = new String[2];
-            defaultPlatformFont[0] = "Lucida Grande";
-            defaultPlatformFont[1] = "/System/Library/Fonts/LucidaGrande.ttc";
-        }
-        return defaultPlatformFont;
+    protected String[] getDefaultPlatformFont() {
+        return new String[]{"Lucida Grande",
+                            "/System/Library/Fonts/LucidaGrande.ttc"};
     }
 
     // This is a way to register any kind of Font2D, not just files and composites.
--- a/jdk/src/share/classes/sun/font/SunFontManager.java	Sat Jul 26 03:18:05 2014 +0400
+++ b/jdk/src/share/classes/sun/font/SunFontManager.java	Sat Jul 26 04:02:56 2014 +0400
@@ -3198,7 +3198,7 @@
      * Returns an array of two strings. The first element is the
      * name of the font. The second element is the file name.
      */
-    public abstract String[] getDefaultPlatformFont();
+    protected abstract String[] getDefaultPlatformFont();
 
     // Begin: Refactored from SunGraphicsEnviroment.
 
--- a/jdk/src/solaris/classes/sun/awt/X11/ListHelper.java	Sat Jul 26 03:18:05 2014 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/ListHelper.java	Sat Jul 26 04:02:56 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -40,7 +40,7 @@
  * For now, this class manages the list of items and painting thereof, but not
  * posting of Item or ActionEvents
  */
-public class ListHelper implements XScrollbarClient {
+final class ListHelper implements XScrollbarClient {
     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.ListHelper");
 
     private final int FOCUS_INSET = 1;
@@ -79,24 +79,16 @@
     // Holds the true if mouse is dragging outside of the area of the list
     // The flag is used at the moment of the dragging and releasing mouse
     // See 6243382 for more information
-    boolean mouseDraggedOutVertically = false;
+    private boolean mouseDraggedOutVertically = false;
     private volatile boolean vsbVisibilityChanged = false;
 
     /*
      * Comment
      */
-    public ListHelper(XWindow peer,
-                      Color[] colors,
-                      int initialSize,
-                      boolean multiSelect,
-                      boolean scrollVert,
-                      boolean scrollHoriz,
-                      Font font,
-                      int maxVisItems,
-                      int SPACE,
-                      int MARGIN,
-                      int BORDER,
-                      int SCROLLBAR) {
+    ListHelper(XWindow peer, Color[] colors, int initialSize,
+               boolean multiSelect, boolean scrollVert, boolean scrollHoriz,
+               Font font, int maxVisItems, int SPACE, int MARGIN, int BORDER,
+               int SCROLLBAR) {
         this.peer = peer;
         this.colors = colors;
         this.multiSelect = multiSelect;
@@ -121,6 +113,7 @@
         SCROLLBAR_WIDTH = SCROLLBAR;
     }
 
+    @Override
     public Component getEventSource() {
         return peer.getEventSource();
     }
@@ -129,36 +122,36 @@
     /* List management methods                                            */
     /**********************************************************************/
 
-    public void add(String item) {
+    void add(String item) {
         items.add(item);
         updateScrollbars();
     }
 
-    public void add(String item, int index) {
+    void add(String item, int index) {
         items.add(index, item);
         updateScrollbars();
     }
 
-    public void remove(String item) {
+    void remove(String item) {
         // FIXME: need to clean up select list, too?
         items.remove(item);
         updateScrollbars();
         // Is vsb visible now?
     }
 
-    public void remove(int index) {
+    void remove(int index) {
         // FIXME: need to clean up select list, too?
         items.remove(index);
         updateScrollbars();
         // Is vsb visible now?
     }
 
-    public void removeAll() {
+    void removeAll() {
         items.removeAll(items);
         updateScrollbars();
     }
 
-    public void setMultiSelect(boolean ms) {
+    void setMultiSelect(boolean ms) {
         multiSelect = ms;
     }
 
@@ -167,7 +160,7 @@
      * merely keeps internal track of which items are selected for painting
      * dealing with target Components happens elsewhere
      */
-    public void select(int index) {
+    void select(int index) {
         if (index > getItemCount() - 1) {
             index = (isEmpty() ? -1 : 0);
         }
@@ -182,13 +175,13 @@
     }
 
     /* docs */
-    public void deselect(int index) {
+    void deselect(int index) {
         assert(false);
     }
 
     /* docs */
     /* if called for multiselect, return -1 */
-    public int getSelectedIndex() {
+    int getSelectedIndex() {
         if (!multiSelect) {
             Integer val = selected.get(0);
             return val.intValue();
@@ -202,21 +195,21 @@
      * A getter method for XChoicePeer.
      * Returns vsbVisiblityChanged value and sets it to false.
      */
-    public boolean checkVsbVisibilityChangedAndReset(){
+    boolean checkVsbVisibilityChangedAndReset(){
         boolean returnVal = vsbVisibilityChanged;
         vsbVisibilityChanged = false;
         return returnVal;
     }
 
-    public boolean isEmpty() {
+    boolean isEmpty() {
         return items.isEmpty();
     }
 
-    public int getItemCount() {
+    int getItemCount() {
         return items.size();
     }
 
-    public String getItem(int index) {
+    String getItem(int index) {
         return items.get(index);
     }
 
@@ -224,15 +217,15 @@
     /* GUI-related methods                                                */
     /**********************************************************************/
 
-    public void setFocusedIndex(int index) {
+    void setFocusedIndex(int index) {
         focusedIndex = index;
     }
 
-    public boolean isFocusedIndex(int index) {
+    private boolean isFocusedIndex(int index) {
         return index == focusedIndex;
     }
 
-    public void setFont(Font newFont) {
+    void setFont(Font newFont) {
         if (newFont != font) {
             font = newFont;
             fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
@@ -243,7 +236,7 @@
     /*
      * Returns width of the text of the longest item
      */
-    public int getMaxItemWidth() {
+    int getMaxItemWidth() {
         int m = 0;
         int end = getItemCount();
         for(int i = 0 ; i < end ; i++) {
@@ -260,7 +253,7 @@
         return fm.getHeight() + (2*TEXT_SPACE);
     }
 
-    public int y2index(int y) {
+    int y2index(int y) {
         if (log.isLoggable(PlatformLogger.Level.FINE)) {
             log.fine("y=" + y +", firstIdx=" + firstDisplayedIndex() +", itemHeight=" + getItemHeight()
                      + ",item_margin=" + ITEM_MARGIN);
@@ -275,14 +268,14 @@
     public int numItemsDisplayed() {}
     */
 
-    public int firstDisplayedIndex() {
+    int firstDisplayedIndex() {
         if (vsbVis) {
             return vsb.getValue();
         }
         return 0;
     }
 
-    public int lastDisplayedIndex() {
+    int lastDisplayedIndex() {
         // FIXME: need to account for horiz scroll bar
         if (hsbVis) {
             assert false : "Implement for horiz scroll bar";
@@ -294,7 +287,7 @@
     /*
      * If the given index is not visible in the List, scroll so that it is.
      */
-    public void makeVisible(int index) {
+    private void makeVisible(int index) {
         if (vsbVis) {
             if (index < firstDisplayedIndex()) {
                 vsb.setValue(index);
@@ -306,7 +299,7 @@
     }
 
     // FIXME: multi-select needs separate focused index
-    public void up() {
+    void up() {
         int curIdx = getSelectedIndex();
         int numItems = getItemCount();
         int newIdx;
@@ -323,12 +316,12 @@
         select(newIdx);
     }
 
-    public void down() {
+    void down() {
         int newIdx = (getSelectedIndex() + 1) % getItemCount();
         select(newIdx);
     }
 
-    public void pageUp() {
+    void pageUp() {
         // FIXME: for multi-select, move the focused item, not the selected item
         if (vsbVis && firstDisplayedIndex() > 0) {
             if (multiSelect) {
@@ -343,7 +336,7 @@
             }
         }
     }
-    public void pageDown() {
+    void pageDown() {
         if (vsbVis && lastDisplayedIndex() < getItemCount() - 1) {
             if (multiSelect) {
                 assert false : "Implement pageDown() for multiSelect";
@@ -357,17 +350,17 @@
             }
         }
     }
-    public void home() {}
-    public void end() {}
+    void home() {}
+    void end() {}
 
 
-    public boolean isVSBVisible() { return vsbVis; }
-    public boolean isHSBVisible() { return hsbVis; }
+    boolean isVSBVisible() { return vsbVis; }
+    boolean isHSBVisible() { return hsbVis; }
 
-    public XVerticalScrollbar getVSB() { return vsb; }
-    public XHorizontalScrollbar getHSB() { return hsb; }
+    XVerticalScrollbar getVSB() { return vsb; }
+    XHorizontalScrollbar getHSB() { return hsb; }
 
-    public boolean isInVertSB(Rectangle bounds, int x, int y) {
+    boolean isInVertSB(Rectangle bounds, int x, int y) {
         if (vsbVis) {
             assert vsb != null : "Vert scrollbar is visible, yet is null?";
             int sbHeight = hsbVis ? bounds.height - SCROLLBAR_WIDTH : bounds.height;
@@ -379,7 +372,7 @@
         return false;
     }
 
-    public boolean isInHorizSB(Rectangle bounds, int x, int y) {
+    boolean isInHorizSB(Rectangle bounds, int x, int y) {
         if (hsbVis) {
             assert hsb != null : "Horiz scrollbar is visible, yet is null?";
 
@@ -392,7 +385,7 @@
         return false;
     }
 
-    public void handleVSBEvent(MouseEvent e, Rectangle bounds, int x, int y) {
+    void handleVSBEvent(MouseEvent e, Rectangle bounds, int x, int y) {
         int sbHeight = hsbVis ? bounds.height - SCROLLBAR_WIDTH : bounds.height;
 
         vsb.handleMouseEvent(e.getID(),
@@ -405,7 +398,7 @@
      * Called when items are added/removed.
      * Update whether the scrollbar is visible or not, scrollbar values
      */
-    void updateScrollbars() {
+    private void updateScrollbars() {
         boolean oldVsbVis = vsbVis;
         vsbVis = vsb != null && items.size() > maxVisItems;
         if (vsbVis) {
@@ -420,10 +413,11 @@
         // FIXME: check if added item makes a hsb necessary (if supported, that of course)
     }
 
-    public int getNumItemsDisplayed() {
+    private int getNumItemsDisplayed() {
         return items.size() > maxVisItems ? maxVisItems : items.size();
     }
 
+    @Override
     public void repaintScrollbarRequest(XScrollbar sb) {
         Graphics g = peer.getGraphics();
         Rectangle bounds = peer.getBounds();
@@ -436,6 +430,7 @@
         g.dispose();
     }
 
+    @Override
     public void notifyValue(XScrollbar obj, int type, int v, boolean isAdjusting) {
         if (obj == vsb) {
             int oldScrollValue = vsb.getValue();
@@ -467,7 +462,7 @@
         }
     }
 
-    public void updateColors(Color[] newColors) {
+    void updateColors(Color[] newColors) {
         colors = newColors;
     }
 
@@ -481,7 +476,7 @@
                            XVerticalScrollbar vsb,
                            XHorizontalScrollbar hsb) {
     */
-    public void paintItems(Graphics g,
+    void paintItems(Graphics g,
                            Color[] colors,
                            Rectangle bounds) {
         // paint border
@@ -490,17 +485,14 @@
         // paint focus?
 
     }
-    public void paintAllItems(Graphics g,
+    void paintAllItems(Graphics g,
                            Color[] colors,
                            Rectangle bounds) {
         paintItems(g, colors, bounds,
                    firstDisplayedIndex(), lastDisplayedIndex());
     }
-    public void paintItems(Graphics g,
-                           Color[] colors,
-                           Rectangle bounds,
-                           int first,
-                           int last) {
+    private void paintItems(Graphics g, Color[] colors, Rectangle bounds,
+                            int first, int last) {
         peer.flush();
         int x = BORDER_WIDTH + ITEM_MARGIN;
         int width = bounds.width - 2*ITEM_MARGIN - 2*BORDER_WIDTH - (vsbVis ? SCROLLBAR_WIDTH : 0);
@@ -529,12 +521,9 @@
     /*
      * comment about what is painted (i.e. the focus rect
      */
-    public void paintItem(Graphics g,
-                          Color[] colors,
-                          String string,
-                          int x, int y, int width, int height,
-                          boolean selected,
-                          boolean focused) {
+    private void paintItem(Graphics g, Color[] colors, String string, int x,
+                           int y, int width, int height, boolean selected,
+                           boolean focused) {
         //System.out.println("LP.pI(): x="+x+" y="+y+" w="+width+" h="+height);
         //g.setColor(colors[BACKGROUND_COLOR]);
 
@@ -575,7 +564,7 @@
         //g.clipRect(clip.x, clip.y, clip.width, clip.height);
     }
 
-    boolean isItemSelected(int index) {
+    private boolean isItemSelected(int index) {
         Iterator<Integer> itr = selected.iterator();
         while (itr.hasNext()) {
             Integer val = itr.next();
@@ -586,7 +575,7 @@
         return false;
     }
 
-    public void paintVSB(Graphics g, Color colors[], Rectangle bounds) {
+    private void paintVSB(Graphics g, Color colors[], Rectangle bounds) {
         int height = bounds.height - 2*BORDER_WIDTH - (hsbVis ? (SCROLLBAR_WIDTH-2) : 0);
         Graphics ng = g.create();
 
@@ -602,7 +591,7 @@
         }
     }
 
-    public void paintHSB(Graphics g, Color colors[], Rectangle bounds) {
+    private void paintHSB(Graphics g, Color colors[], Rectangle bounds) {
 
     }
 
--- a/jdk/src/solaris/classes/sun/awt/X11/XSelection.java	Sat Jul 26 03:18:05 2014 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XSelection.java	Sat Jul 26 04:02:56 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -43,7 +43,7 @@
 /**
  * A class which interfaces with the X11 selection service.
  */
-public final class XSelection {
+final class XSelection {
 
     /* Maps atoms to XSelection instances. */
     private static final Hashtable<XAtom, XSelection> table = new Hashtable<XAtom, XSelection>();
@@ -119,11 +119,10 @@
     /**
      * Creates a selection object.
      *
-     * @param atom   the selection atom.
-     * @param clpbrd the corresponding clipoboard
-     * @exception NullPointerException if atom is <code>null</code>.
+     * @param  atom the selection atom
+     * @throws NullPointerException if atom is {@code null}
      */
-    public XSelection(XAtom atom) {
+    XSelection(XAtom atom) {
         if (atom == null) {
             throw new NullPointerException("Null atom");
         }
@@ -135,10 +134,9 @@
         return selectionAtom;
     }
 
-    public synchronized boolean setOwner(Transferable contents,
-                                         Map<Long, DataFlavor> formatMap,
-                                         long[] formats, long time)
-    {
+    synchronized boolean setOwner(Transferable contents,
+                                  Map<Long, DataFlavor> formatMap,
+                                  long[] formats, long time) {
         long owner = XWindow.getXAWTRootWindow().getWindow();
         long selection = selectionAtom.getAtom();
 
@@ -435,7 +433,7 @@
         return data != null ? data : new byte[0];
     }
 
-    void validateDataGetter(WindowPropertyGetter propertyGetter)
+    private void validateDataGetter(WindowPropertyGetter propertyGetter)
             throws IOException
     {
         // The order of checks is important because a property getter
--- a/jdk/src/solaris/classes/sun/awt/X11FontManager.java	Sat Jul 26 03:18:05 2014 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11FontManager.java	Sat Jul 26 04:02:56 2014 +0400
@@ -1,3 +1,28 @@
+/*
+ * Copyright (c) 2009, 2014, 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
 package sun.awt;
 
 import java.awt.GraphicsEnvironment;
@@ -29,7 +54,7 @@
 /**
  * The X11 implementation of {@link FontManager}.
  */
-public class X11FontManager extends SunFontManager {
+public final class X11FontManager extends SunFontManager {
 
     // constants identifying XLFD and font ID fields
     private static final int FOUNDRY_FIELD = 1;
@@ -129,8 +154,6 @@
       */
      private static String[] fontdirs = null;
 
-    private static String[] defaultPlatformFont = null;
-
     private FontConfigManager fcManager = null;
 
     public static X11FontManager getInstance() {
@@ -768,11 +791,9 @@
         return getFontPathNative(noType1Fonts);
     }
 
-    public String[] getDefaultPlatformFont() {
-        if (defaultPlatformFont != null) {
-            return defaultPlatformFont;
-        }
-        String[] info = new String[2];
+    @Override
+    protected String[] getDefaultPlatformFont() {
+        final String[] info = new String[2];
         getFontConfigManager().initFontConfigFonts(false);
         FontConfigManager.FcCompFont[] fontConfigFonts =
             getFontConfigManager().getFontConfigFonts();
@@ -798,8 +819,7 @@
                 info[1] = "/dialog.ttf";
             }
         }
-        defaultPlatformFont = info;
-        return defaultPlatformFont;
+        return info;
     }
 
     public synchronized FontConfigManager getFontConfigManager() {
--- a/jdk/src/windows/classes/sun/awt/Win32FontManager.java	Sat Jul 26 03:18:05 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/Win32FontManager.java	Sat Jul 26 04:02:56 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, 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
@@ -37,7 +37,6 @@
 import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
 
-import sun.awt.Win32GraphicsEnvironment;
 import sun.awt.windows.WFontConfiguration;
 import sun.font.FontManager;
 import sun.font.SunFontManager;
@@ -46,9 +45,7 @@
 /**
  * The X11 implementation of {@link FontManager}.
  */
-public class Win32FontManager extends SunFontManager {
-
-    private static String[] defaultPlatformFont = null;
+public final class Win32FontManager extends SunFontManager {
 
     private static TrueTypeFont eudcFont;
 
@@ -213,12 +210,8 @@
 
     protected synchronized native String getFontPath(boolean noType1Fonts);
 
-    public String[] getDefaultPlatformFont() {
-
-        if (defaultPlatformFont != null) {
-            return defaultPlatformFont;
-        }
-
+    @Override
+    protected String[] getDefaultPlatformFont() {
         String[] info = new String[2];
         info[0] = "Arial";
         info[1] = "c:\\windows\\fonts";
@@ -245,8 +238,7 @@
             info[1] = dirs[0];
         }
         info[1] = info[1] + File.separator + "arial.ttf";
-        defaultPlatformFont = info;
-        return defaultPlatformFont;
+        return info;
     }
 
     /* register only TrueType/OpenType fonts