classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Added Scrollable implementation methods to javax.swing


From: Roman Kennke
Subject: [cp-patches] FYI: Added Scrollable implementation methods to javax.swing.JTextArea
Date: Mon, 23 May 2005 16:10:01 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

I added two methods in order to improve Scrollable behaviour of JTextArea.

2005-05-23  Roman Kennke  <address@hidden>

       * javax/swing/JTextArea.java
       (getPreferredScrollableViewportSize): Added and implemented
       new method.
       (getScrollableUnitIncrement): Added and implemented new
       method.

/Roman

Index: javax/swing/JTextArea.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTextArea.java,v
retrieving revision 1.10
diff -u -r1.10 JTextArea.java
--- javax/swing/JTextArea.java  28 Apr 2005 05:46:01 -0000      1.10
+++ javax/swing/JTextArea.java  23 May 2005 14:06:38 -0000
@@ -38,7 +38,9 @@
 
 package javax.swing;
 
+import java.awt.Dimension;
 import java.awt.FontMetrics;
+import java.awt.Rectangle;
 
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
@@ -230,6 +232,55 @@
   }
 
   /**
+   * Returns the increment that is needed to expose exactly one new line
+   * of text. This is implemented here to return the values of
+   * address@hidden #getRowHeight} and address@hidden getColumnWidth}, 
depending on
+   * the value of the argument <code>direction</code>.
+   *
+   * @param visibleRect the view area that is visible in the viewport
+   * @param orientation either address@hidden SwingConstants.VERTICAL} or
+   *     address@hidden SwingConstants.HORIZONTAL}
+   * @param direction less than zero for up/left scrolling, greater
+   *     than zero for down/right scrolling
+   *
+   * @return the increment that is needed to expose exactly one new row
+   *     or column of text
+   *
+   * @throws IllegalArgumentException if <code>orientation</code> is invalid
+   */
+  public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
+                                        int direction)
+  {
+    if (orientation == SwingConstants.VERTICAL)
+      return getRowHeight();
+    else if (orientation == SwingConstants.HORIZONTAL)
+      return getColumnWidth();
+    else
+      throw new IllegalArgumentException("orientation must be either "
+                                     + "javax.swing.SwingConstants.VERTICAL "
+                                     + "or "
+                                     + "javax.swing.SwingConstants.HORIZONTAL"
+                                     );
+  }
+
+  /**
+   * Returns the preferred size of that text component in the case
+   * it is embedded within a JScrollPane. This uses the column and
+   * row settings if they are explicitly set, or fall back to
+   * the superclass's behaviour.
+   *
+   * @return the preferred size of that text component in the case
+   *     it is embedded within a JScrollPane
+   */
+  public Dimension getPreferredScrollableViewportSize()
+  {
+    if ((rows > 0) && (columns > 0))
+      return new Dimension(columns * getColumnWidth(), rows * getRowHeight());
+    else
+      return super.getPreferredScrollableViewportSize();
+  }
+
+  /**
    * Returns the UI class ID string.
    *
    * @return the string "TextAreaUI"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]