tkormann 01/10/04 07:39:26
Modified: resources/org/apache/batik/apps/svgbrowser/resources
FindDialog.properties
sources/org/apache/batik/apps/svgbrowser FindDialog.java
sources/org/apache/batik/gvt/text ConcreteTextSelector.java
sources/org/apache/batik/swing/gvt TextSelectionManager.java
Log:
bug fix with text search (multiple occurences of the same substring in the
same TextNode).
Revision Changes Path
1.4 +2 -2
xml-batik/resources/org/apache/batik/apps/svgbrowser/resources/FindDialog.properties
Index: FindDialog.properties
===================================================================
RCS file:
/home/cvs/xml-batik/resources/org/apache/batik/apps/svgbrowser/resources/FindDialog.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FindDialog.properties 2001/10/03 16:08:19 1.3
+++ FindDialog.properties 2001/10/04 14:39:26 1.4
@@ -9,7 +9,7 @@
# FindDialog properties file
#
# Author: [EMAIL PROTECTED]
-# $Id: FindDialog.properties,v 1.3 2001/10/03 16:08:19 tkormann Exp $
+# $Id: FindDialog.properties,v 1.4 2001/10/04 14:39:26 tkormann Exp $
#
Dialog.title = Batik: Find
@@ -31,7 +31,7 @@
ClearButton.mnemonic = C
ClearButton.action = ClearButtonAction
-CloseButton.text = Closec
+CloseButton.text = Close
CloseButton.mnemonic = X
CloseButton.action = CloseButtonAction
1.5 +39 -35
xml-batik/sources/org/apache/batik/apps/svgbrowser/FindDialog.java
Index: FindDialog.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/FindDialog.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FindDialog.java 2001/10/03 16:08:19 1.4
+++ FindDialog.java 2001/10/04 14:39:26 1.5
@@ -16,6 +16,8 @@
import java.awt.Insets;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Dimension2D;
+import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.text.AttributedCharacterIterator;
@@ -64,7 +66,7 @@
* an SVG document.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: FindDialog.java,v 1.4 2001/10/03 16:08:19 tkormann Exp $
+ * @version $Id: FindDialog.java,v 1.5 2001/10/04 14:39:26 tkormann Exp $
*/
public class FindDialog extends JDialog implements ActionMap {
@@ -103,6 +105,11 @@
/** The GVTTreeWalker used to scan the GVT Tree. */
protected GVTTreeWalker walker;
+ /**
+ * The current index in the TextNode's string.
+ */
+ protected int currentIndex;
+
/** The TextField that owns the text to search. */
protected JTextField search;
@@ -224,27 +231,18 @@
if (walker == null && gvtRoot != null) {
walker = new GVTTreeWalker(gvtRoot);
}
- GraphicsNode gn = walker.nextGraphicsNode();
- while (gn != null && !match(gn, text)) {
- gn = walker.nextGraphicsNode();
- }
- return gn;
- }
-
- /**
- * Returns the previous GraphicsNode that matches the specified string or
- * null if any.
- *
- * @param text the text to match
- */
- protected GraphicsNode getPrevious(String text) {
- if (walker == null && gvtRoot != null) {
- walker = new GVTTreeWalker(gvtRoot);
+ GraphicsNode gn = walker.getCurrentGraphicsNode();
+ int index = match(gn, text, currentIndex+text.length());
+ if (index >= 0) {
+ currentIndex = index;
+ } else {
+ currentIndex = 0;
+ gn = walker.nextGraphicsNode();
+ while (gn != null &&
+ ((currentIndex = match(gn, text, currentIndex)) < 0)) {
+ gn = walker.nextGraphicsNode();
+ }
}
- GraphicsNode gn = walker.previousGraphicsNode();
- while (gn != null && !match(gn, text)) {
- gn = walker.previousGraphicsNode();
- }
return gn;
}
@@ -254,19 +252,20 @@
*
* @param node the graphics node to check
* @param text the text use to match
+ * @param index the index from which to start
*/
- protected boolean match(GraphicsNode node, String text) {
+ protected int match(GraphicsNode node, String text, int index) {
if (!(node instanceof TextNode)
|| !node.isVisible()
|| text == null || text.length() == 0) {
- return false;
+ return -1;
}
String s = ((TextNode)node).getText();
if (!caseSensitive.isSelected()) {
s = s.toLowerCase();
text = text.toLowerCase();
}
- return (s.indexOf(text) >= 0);
+ return s.indexOf(text, index);
}
/**
@@ -284,7 +283,7 @@
AttributedCharacterIterator aci =
textNode.getAttributedCharacterIterator();
aci.first();
- for (int i=0; i < text.indexOf(pattern); ++i) {
+ for (int i=0; i < text.indexOf(pattern, currentIndex); ++i) {
aci.next();
}
Mark startMark = textNode.getMarkerForChar(aci.getIndex(), true);
@@ -296,16 +295,21 @@
// zoom on the TextNode if needed
if (enableZoom.isSelected()) {
- Rectangle2D bounds = gn.getBounds();
- bounds = gn.getGlobalTransform().createTransformedShape
- (bounds).getBounds();
- Dimension dim = svgCanvas.getSize();
- AffineTransform Tx = new AffineTransform();
- double s = Math.min(dim.width/bounds.getWidth(),
- dim.height/bounds.getHeight());
- Tx.scale(s*.8, s*.8);
- Tx.translate(-bounds.getX(), -bounds.getY());
- svgCanvas.setRenderingTransform(Tx);
+ Dimension2D docSize = svgCanvas.getSVGDocumentSize();
+ Rectangle2D nb = textNode.getBounds();
+ AffineTransform at = gn.getGlobalTransform();
+
+ Rectangle2D gnb = at.createTransformedShape(nb).getBounds();
+ Dimension canvasSize = svgCanvas.getSize();
+
+ Point2D p = at.deltaTransform
+ (new Point2D.Float(canvasSize.width, canvasSize.height), null);
+
+ AffineTransform Tx = AffineTransform.getTranslateInstance
+ (-gnb.getX() - gnb.getWidth() / 2 + p.getX() / 2,
+ -gnb.getY() - gnb.getHeight() / 2 + p.getY() / 2);
+
+ svgCanvas.setRenderingTransform(Tx);
}
}
1.8 +3 -3
xml-batik/sources/org/apache/batik/gvt/text/ConcreteTextSelector.java
Index: ConcreteTextSelector.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/gvt/text/ConcreteTextSelector.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ConcreteTextSelector.java 2001/09/27 21:19:44 1.7
+++ ConcreteTextSelector.java 2001/10/04 14:39:26 1.8
@@ -39,7 +39,7 @@
* A simple implementation of GraphicsNodeMouseListener for text selection.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Bill Haneman</a>
- * @version $Id: ConcreteTextSelector.java,v 1.7 2001/09/27 21:19:44 deweese Exp $
+ * @version $Id: ConcreteTextSelector.java,v 1.8 2001/10/04 14:39:26 tkormann Exp $
*/
public class ConcreteTextSelector implements Selector {
@@ -312,7 +312,7 @@
}
private void copyToClipboard(Object o) {
-
+/*
// first see if we can access the clipboard
SecurityManager securityManager = System.getSecurityManager();
boolean canAccessClipboard = true;
@@ -339,7 +339,7 @@
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection selection = new StringSelection(label);
clipboard.setContents(selection, selection);
- }
+ }*/
}
private void report(GraphicsNodeEvent evt, String message) {
1.12 +2 -2
xml-batik/sources/org/apache/batik/swing/gvt/TextSelectionManager.java
Index: TextSelectionManager.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/swing/gvt/TextSelectionManager.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TextSelectionManager.java 2001/10/04 08:25:47 1.11
+++ TextSelectionManager.java 2001/10/04 14:39:26 1.12
@@ -36,7 +36,7 @@
* This class represents an object which manage GVT text nodes selection.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: TextSelectionManager.java,v 1.11 2001/10/04 08:25:47 tkormann Exp $
+ * @version $Id: TextSelectionManager.java,v 1.12 2001/10/04 14:39:26 tkormann Exp $
*/
public class TextSelectionManager {
@@ -99,7 +99,7 @@
* A flag bit that indicates whether or not the selection overlay is painted
* in XOR mode.
*/
- protected boolean xorMode = true;
+ protected boolean xorMode = false;
/**
* Creates a new TextSelectionManager.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]