You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Thomas E Deweese <th...@kodak.com> on 2001/04/10 21:18:44 UTC

Text Selection Hack


Hi All,

   I put this hack togeather on the plane (I had mentioned an earier
version of this to Vincent at ApacheCON).  I'm not commiting it since
this sort of thing tends to be very personal, but for those that
want to try it out I've attached it as a unified context diff.

   It basically replaces the really ugly (but almost always visible)
XOR with a nice semi-transparent off-white rectangle with a white
border.  This almost always gives a nice results when selecting,
although in some cases it isn't as visible as one might want.

   Much of the diff is to 'fix' the TextSelectionManager so it pays
attention to it's own highlight bounds.
          

--- sources/org/apache/batik/swing/gvt/TextSelectionManager.java.orig   Tue Apr 10 12:49:34 2001
+++ sources/org/apache/batik/swing/gvt/TextSelectionManager.java        Tue Apr 10 13:44:05 2001
@@ -14,6 +14,8 @@
 import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.BasicStroke;
 
 import java.awt.geom.AffineTransform;
 
@@ -191,18 +193,15 @@
             Rectangle r = null;
             AffineTransform at = component.getRenderingTransform();
             if (selectionHighlight != null) {
-                r = at.createTransformedShape(selectionHighlight).getBounds();
+                r = getHighlightBounds();
             }
 
             selectionHighlight = e.getHighlightShape();
             if (selectionHighlight != null) {
-                if (r != null) {
-                    Rectangle r2;
-                    r2 = at.createTransformedShape(selectionHighlight).getBounds();
-                    component.paintImmediately(r.union(r2));
-                } else {
-                    component.paintImmediately(getHighlightBounds());
-                }
+                Rectangle r2 = getHighlightBounds();
+                if (r != null) 
+                    r2 = r.union(r2);
+                component.paintImmediately(r2);
             } else if (r != null) {
                 component.paintImmediately(r);
             }
@@ -216,7 +215,10 @@
     protected Rectangle getHighlightBounds() {
         AffineTransform at = component.getRenderingTransform();
         Shape s = at.createTransformedShape(selectionHighlight);
-        return s.getBounds();
+        Stroke stroke = new BasicStroke(2);
+        s = stroke.createStrokedShape(s);
+        Rectangle r = s.getBounds();
+        return r;
     }
 
     /**
@@ -233,11 +235,16 @@
                 Shape s = at.createTransformedShape(selectionHighlight);
                 
                 Graphics2D g2d = (Graphics2D)g;
-                
-                g2d.setXORMode(Color.white);
-                g2d.setColor(Color.black);
 
+                Stroke stroke = g2d.getStroke();
+                g2d.setColor(new Color(180,180,180,80));
                 g2d.fill(s);
+
+                g2d.setColor(new Color(255,255,255));
+                g2d.setStroke(new BasicStroke(2));
+                g2d.draw(s);
+
+                g2d.setStroke(stroke);
             }
         }
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org