jdk/src/java.desktop/unix/classes/sun/awt/X11/ListHelper.java
changeset 26037 508779ce6619
parent 26007 dba8f49653ce
parent 25859 3317bb8137f4
child 28059 e576535359cc
child 28231 b608ffcaed74
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/ListHelper.java	Mon Aug 18 14:03:21 2014 +0100
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/ListHelper.java	Tue Aug 19 10:32:16 2014 -0700
@@ -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) {
 
     }