On Wed, 2005-10-19 at 14:58 +0000, Roman Kennke wrote:
> Some cleanup for javax.swing.text.
> 
> 2005-10-19  Roman Kennke  <[EMAIL PROTECTED]>
> 
>         * javax/swing/text/AbstractDocument.java
>         * javax/swing/text/AttributeSet.java
>         * javax/swing/text/ComponentView.java
>         * javax/swing/text/DefaultCaret.java
>         * javax/swing/text/DefaultEditorKit.java
>         * javax/swing/text/DefaultHighlighter.java
>         * javax/swing/text/EditorKit.java
>         * javax/swing/text/FieldView.java
>         * javax/swing/text/FlowView.java
>         * javax/swing/text/GlyphView.java
>         * javax/swing/text/JTextComponent.java
>         * javax/swing/text/LayoutQueue.java
>         * javax/swing/text/PlainView.java
>         * javax/swing/text/Segment.java
>         * javax/swing/text/StyledDocument.java
>         * javax/swing/text/html/HTMLEditorKit.java
>         * javax/swing/text/html/HTMLFrameHyperlinkEvent.java
>         * javax/swing/text/html/parser/DocumentParser.java
>         Reformatted slightly. Filled emtpy blocks with comments. Fixed
> some
>         slight API doc errors. Removed some unneeded imports.
> 
> /Roman

The changes to PlainView were more than just reformatting and docs, and
were regressions that were then fixed on November 24 (message
attached).  

Please keep the functional changes separate from reformatting patches.

--Tony
--- Begin Message ---
This patch fixes the PasswordView, so that the caret gets positioned
correctly. The model->view mapping was previously done by the
superclass, which provides a mapping based on the real content. However,
the PasswordView needs to base this mapping on the echo character.

Also I did some small cleanups in PlainView.

2005-11-24  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/PasswordView.java
        (modelToView): Overridden to correctly map between model and view
        respecting the echo character.
        (viewToModel): Added FIXME to show that this method also needs
        to be adjusted like the above method.
        * javax/swing/text/PlainView.java
        (paint): Don't set the font here. This is already done in the
        text component's JComponent.getComponentGraphics() method.
        (damageLineRange): Only repaint the damaged rectangle.

/Roman
Index: javax/swing/text/PasswordView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PasswordView.java,v
retrieving revision 1.7
diff -u -r1.7 PasswordView.java
--- javax/swing/text/PasswordView.java	17 Aug 2005 19:59:35 -0000	1.7
+++ javax/swing/text/PasswordView.java	24 Nov 2005 20:36:15 -0000
@@ -41,6 +41,7 @@
 import java.awt.Color;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
+import java.awt.Rectangle;
 import java.awt.Shape;
 
 import javax.swing.JPasswordField;
@@ -211,7 +212,10 @@
   /**
    * Provides a mapping from the document model coordinate space to the
    * coordinate space of the view mapped to it.
-   * 
+   *
+   * This method is overridden to provide a correct mapping with respect to the
+   * echo char and not to the real content.
+   *
    * @param pos - the position to convert >= 0
    * @param a - the allocated region to render into
    * @param b - typesafe enumeration to indicate bias to a position in the model.
@@ -222,7 +226,35 @@
   public Shape modelToView(int pos, Shape a, Position.Bias b)
     throws BadLocationException
   {
-    return super.modelToView(pos, a, b);
+    Shape newAlloc = adjustAllocation(a);
+
+    // Ensure metrics are up-to-date.
+    updateMetrics();
+    
+    // Get rectangle of the line containing position.
+    int lineIndex = getElement().getElementIndex(pos);
+    Rectangle rect = lineToRect(newAlloc, lineIndex);
+
+    // Get the rectangle for position.
+    Element line = getElement().getElement(lineIndex);
+    int lineStart = line.getStartOffset();
+    Segment segment = getLineBuffer();
+    segment.array = new char[pos - lineStart];
+    char echoChar = getEchoChar();
+    for (int i = 0; i < segment.array.length; ++i)
+      segment.array[i] = echoChar;
+    segment.offset = 0;
+    segment.count = segment.array.length;
+
+    int xoffset = Utilities.getTabbedTextWidth(segment, metrics, rect.x,
+                           this, lineStart);
+
+    // Calc the real rectangle.
+    rect.x += xoffset;
+    rect.width = 1;
+    rect.height = metrics.getHeight();
+
+    return rect;
   }
 
   /**
@@ -239,6 +271,8 @@
    */
   public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias)
   {
+    // FIXME: This only provides a view->model mapping for the real text
+    // content and does not respect the echo char.
     return super.viewToModel(fx, fy, a, bias);
   }
 }
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.33
diff -u -r1.33 PlainView.java
--- javax/swing/text/PlainView.java	23 Nov 2005 11:59:30 -0000	1.33
+++ javax/swing/text/PlainView.java	24 Nov 2005 20:36:15 -0000
@@ -185,7 +185,6 @@
     
     JTextComponent textComponent = (JTextComponent) getContainer();
 
-    g.setFont(textComponent.getFont());
     selectedColor = textComponent.getSelectedTextColor();
     unselectedColor = textComponent.getForeground();
     disabledColor = textComponent.getDisabledTextColor();
@@ -513,7 +512,8 @@
     else
       {
         Rectangle repaintRec = rec0.union(rec1);
-        host.repaint();
+        host.repaint(repaintRec.x, repaintRec.y, repaintRec.width,
+                     repaintRec.height);
       }    
   }
 
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

--- End Message ---
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to