tkormann    01/10/03 09:08:20

  Modified:    resources/org/apache/batik/apps/svgbrowser/resources
                        FindDialog.properties GUI.properties
               sources/org/apache/batik/apps/svgbrowser FindDialog.java
               sources/org/apache/batik/gvt TextPainter.java
               sources/org/apache/batik/swing/gvt JGVTComponent.java
                        TextSelectionManager.java
  Log:
  commit the text search. Selection is now working. Zoom is disable at this time.
  
  Revision  Changes    Path
  1.3       +14 -11    
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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FindDialog.properties     2001/05/07 23:49:51     1.2
  +++ FindDialog.properties     2001/10/03 16:08:19     1.3
  @@ -9,10 +9,10 @@
   # FindDialog properties file
   #
   # Author: [EMAIL PROTECTED]
  -# $Id: FindDialog.properties,v 1.2 2001/05/07 23:49:51 tkormann Exp $
  +# $Id: FindDialog.properties,v 1.3 2001/10/03 16:08:19 tkormann Exp $
   #
   
  -Dialog.title = Find...
  +Dialog.title = Batik: Find
   Panel.title = Search for text
   
   FindLabel.text = Find :
  @@ -23,19 +23,22 @@
   EnableZoomCheckBox.text = Enable zoom
   EnableZoomCheckBox.mnemonic = A
   
  -NextButton.text = Next
  -NextButton.mnemonic = N
  -NextButton.action   = NextButtonAction
  -
  -PreviousButton.text = Previous
  -PreviousButton.mnemonic = P
  -PreviousButton.action   = PreviousButtonAction
  +FindButton.text = Find
  +FindButton.mnemonic = F
  +FindButton.action   = FindButtonAction
  +
  +ClearButton.text = Clear
  +ClearButton.mnemonic = C
  +ClearButton.action   = ClearButtonAction
   
  -CloseButton.text = Close
  -CloseButton.mnemonic = C
  +CloseButton.text = Closec
  +CloseButton.mnemonic = X
   CloseButton.action   = CloseButtonAction
   
  +End.text = End of document reached; continue from beginning.
  +End.title = Batik: Find wrap
   
  + 
   
   
   
  
  
  
  1.32      +3 -3      
xml-batik/resources/org/apache/batik/apps/svgbrowser/resources/GUI.properties
  
  Index: GUI.properties
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/resources/org/apache/batik/apps/svgbrowser/resources/GUI.properties,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- GUI.properties    2001/09/28 15:40:08     1.31
  +++ GUI.properties    2001/10/03 16:08:19     1.32
  @@ -9,7 +9,7 @@
   # The viewer's GUI resources.
   #
   # Author: [EMAIL PROTECTED]
  -# $Id: GUI.properties,v 1.31 2001/09/28 15:40:08 hillion Exp $
  +# $Id: GUI.properties,v 1.32 2001/10/03 16:08:19 tkormann Exp $
   #
   
   ViewSource.width = 750
  @@ -129,9 +129,9 @@
   
   
   # Edit menu ################
  -#Edit = FindDialog - Preferences
  +Edit = FindDialog - Preferences
   #Edit = Preferences Flush
  -Edit = Preferences
  +#Edit = Preferences
   
   Edit.type = MENU
   Edit.text = Edit
  
  
  
  1.4       +68 -91    
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FindDialog.java   2001/09/17 13:37:30     1.3
  +++ FindDialog.java   2001/10/03 16:08:19     1.4
  @@ -18,6 +18,8 @@
   import java.awt.geom.AffineTransform;
   import java.awt.geom.Rectangle2D;
   
  +import java.text.AttributedCharacterIterator;
  +
   import java.util.HashMap;
   import java.util.List;
   import java.util.Locale;
  @@ -34,6 +36,7 @@
   import javax.swing.JCheckBox;
   import javax.swing.JDialog;
   import javax.swing.JLabel;
  +import javax.swing.JOptionPane;
   import javax.swing.JPanel;
   import javax.swing.JTextField;
   
  @@ -45,7 +48,10 @@
   import org.apache.batik.gvt.GraphicsNode;
   import org.apache.batik.gvt.TextNode;
   
  +import org.apache.batik.gvt.text.Mark;
  +
   import org.apache.batik.swing.JSVGCanvas;
  +import org.apache.batik.swing.gvt.TextSelectionManager;
   
   import org.apache.batik.util.gui.ExtendedGridBagConstraints;
   import org.apache.batik.util.gui.resource.ActionMap;
  @@ -58,7 +64,7 @@
    * an SVG document.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thierry Kormann</a>
  - * @version $Id: FindDialog.java,v 1.3 2001/09/17 13:37:30 tkormann Exp $
  + * @version $Id: FindDialog.java,v 1.4 2001/10/03 16:08:19 tkormann Exp $
    */
   public class FindDialog extends JDialog implements ActionMap {
   
  @@ -69,8 +75,8 @@
           "org.apache.batik.apps.svgbrowser.resources.FindDialog";
   
       // action names
  -    public final static String NEXT_ACTION = "NextButtonAction";
  -    public final static String PREVIOUS_ACTION = "PreviousButtonAction";
  +    public final static String FIND_ACTION = "FindButtonAction";
  +    public final static String CLEAR_ACTION = "ClearButtonAction";
       public final static String CLOSE_ACTION = "CloseButtonAction";
   
       /**
  @@ -101,13 +107,13 @@
       protected JTextField search;
   
       /** The next button. */
  -    protected JButton next;
  +    protected JButton findButton;
   
       /** The next button. */
  -    protected JButton previous;
  +    protected JButton clearButton;
   
       /** The cancel button. */
  -    protected JButton close;
  +    protected JButton closeButton;
   
       /** The case sensitive button. */
       protected JCheckBox caseSensitive;
  @@ -134,8 +140,8 @@
   
           buttonFactory = new ButtonFactory(bundle, this);
   
  -        listeners.put(NEXT_ACTION, new NextButtonAction());
  -        listeners.put(PREVIOUS_ACTION, new PreviousButtonAction());
  +        listeners.put(FIND_ACTION, new FindButtonAction());
  +        listeners.put(CLEAR_ACTION, new ClearButtonAction());
           listeners.put(CLOSE_ACTION, new CloseButtonAction());
   
           getContentPane().add(createFindPanel(), BorderLayout.CENTER);
  @@ -165,7 +171,6 @@
           gbc.setWeight(1.0, 0);
           gbc.setGridBounds(1, 0, 2, 1);
           panel.add(search = new JTextField(20), gbc);
  -        search.getDocument().addDocumentListener(new TextTracker());
   
           gbc.fill = ExtendedGridBagConstraints.NONE;
           gbc.anchor = ExtendedGridBagConstraints.WEST;
  @@ -179,7 +184,7 @@
           gbc.setWeight(0, 0);
           gbc.setGridBounds(2, 1, 1, 1);
           enableZoom = buttonFactory.createJCheckBox("EnableZoomCheckBox");
  -        panel.add(enableZoom, gbc);
  +        //panel.add(enableZoom, gbc);
   
           return panel;
       }
  @@ -189,12 +194,9 @@
        */
       protected JPanel createButtonsPanel() {
           JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  -        panel.add(next = buttonFactory.createJButton("NextButton"));
  -        panel.add(previous = buttonFactory.createJButton("PreviousButton"));
  -        panel.add(close = buttonFactory.createJButton("CloseButton"));
  -
  -        updateButtonState();
  -
  +        panel.add(findButton = buttonFactory.createJButton("FindButton"));
  +        panel.add(clearButton = buttonFactory.createJButton("ClearButton"));
  +        panel.add(closeButton = buttonFactory.createJButton("CloseButton"));
           return panel;
       }
   
  @@ -210,7 +212,6 @@
           } else {
               this.walker = null;
           }
  -        updateButtonState();
       }
   
       /**
  @@ -220,6 +221,9 @@
        * @param text the text to match
        */
       protected GraphicsNode getNext(String text) {
  +     if (walker == null && gvtRoot != null) {
  +         walker = new GVTTreeWalker(gvtRoot);
  +     }
           GraphicsNode gn = walker.nextGraphicsNode();
           while (gn != null && !match(gn, text)) {
               gn = walker.nextGraphicsNode();
  @@ -234,6 +238,9 @@
        * @param text the text to match
        */
       protected GraphicsNode getPrevious(String text) {
  +     if (walker == null && gvtRoot != null) {
  +         walker = new GVTTreeWalker(gvtRoot);
  +     }
           GraphicsNode gn = walker.previousGraphicsNode();
           while (gn != null && !match(gn, text)) {
               gn = walker.previousGraphicsNode();
  @@ -242,11 +249,11 @@
       }
   
       /**
  -     * Returns true if the specified node matches the following text, false
  -     * otherwise.
  +     * Returns the index inside the specified TextNode of the specified text, or
  +     * -1 if not found.
        *
        * @param node the graphics node to check
  -     * @param text the text use to match
  +     * @param text the text use to match 
        */
       protected boolean match(GraphicsNode node, String text) {
           if (!(node instanceof TextNode)
  @@ -254,29 +261,14 @@
               || text == null || text.length() == 0) {
               return false;
           }
  -
           String s = ((TextNode)node).getText();
           if (!caseSensitive.isSelected()) {
               s = s.toLowerCase();
               text = text.toLowerCase();
           }
  -        return s.startsWith(text);
  -    }
  -
  -    /**
  -     * Updates the state of the 'next', 'previous' buttons and 'search' text
  -     * field.
  -     */
  -    private void updateButtonState() {
  -        boolean b1 = (gvtRoot != null);
  -        String text = search.getText();
  -        boolean b2 = (text != null && text.length() > 0);
  -        next.setEnabled(b1 && b2);
  -        previous.setEnabled(b1 && b2);
  -        search.setEnabled(b1);
  +        return (s.indexOf(text) >= 0);
       }
   
  -
       /**
        * Shows the current selected <tt>TextNode</tt>.
        */
  @@ -285,7 +277,24 @@
           if (!(gn instanceof TextNode)) {
               return;
           }
  -        System.out.println(((TextNode)gn).getText());
  +     TextNode textNode = (TextNode)gn;
  +     // mark the selection of the substring found
  +     String text = textNode.getText();
  +     String pattern = search.getText();
  +     AttributedCharacterIterator aci = 
  +         textNode.getAttributedCharacterIterator();
  +     aci.first();
  +     for (int i=0; i < text.indexOf(pattern); ++i) {
  +         aci.next();
  +     }
  +     Mark startMark = textNode.getMarkerForChar(aci.getIndex(), true);
  +     for (int i = 0; i < pattern.length()-1; ++i) {
  +         aci.next();
  +     }
  +     Mark endMark = textNode.getMarkerForChar(aci.getIndex(), false);
  +     svgCanvas.select(startMark, endMark);
  +
  +     // zoom on the TextNode if needed
           if (enableZoom.isSelected()) {
               Rectangle2D bounds = gn.getBounds();
               bounds = gn.getGlobalTransform().createTransformedShape
  @@ -300,7 +309,6 @@
           }
       }
   
  -
       // ActionMap implementation
   
       /**
  @@ -323,32 +331,35 @@
       //////////////////////////////////////////////////////////////////////////
   
       /**
  -     * The action associated to the 'next' button.
  +     * The action associated to the 'find' button.
        */
  -    protected class NextButtonAction extends AbstractAction {
  +    protected class FindButtonAction extends AbstractAction {
           public void actionPerformed(ActionEvent e) {
  -            GraphicsNode gn = getNext(search.getText());
  -            if (gn != null) {
  -                previous.setEnabled(true);
  -                showSelectedGraphicsNode();
  -            } else {
  -                next.setEnabled(false);
  -            }
  -        }
  +            String text = search.getText();
  +         if (text == null || text.length() == 0) {
  +             return;
  +         }
  +         GraphicsNode gn = getNext(text);
  +         if (gn != null) {
  +             showSelectedGraphicsNode();
  +         } else {
  +             // end of document reached
  +             walker = null;
  +             JOptionPane.showMessageDialog(FindDialog.this, 
  +                                           resources.getString("End.text"), 
  +                                           resources.getString("End.title"),
  +                                           JOptionPane.INFORMATION_MESSAGE);
  +         }
  +     }
       }
   
       /**
  -     * The action associated to the 'previous' button.
  +     * The action associated to the 'clear' button.
        */
  -    protected class PreviousButtonAction extends AbstractAction {
  +    protected class ClearButtonAction extends AbstractAction {
           public void actionPerformed(ActionEvent e) {
  -            GraphicsNode gn = getPrevious(search.getText());
  -            if (gn != null) {
  -                next.setEnabled(true);
  -                showSelectedGraphicsNode();
  -            } else {
  -                previous.setEnabled(false);
  -            }
  +         search.setText(null);
  +         walker = null;
           }
       }
   
  @@ -358,40 +369,6 @@
       protected class CloseButtonAction extends AbstractAction {
           public void actionPerformed(ActionEvent e) {
               dispose();
  -        }
  -    }
  -
  -    /**
  -     * This class is used to track all modifications of the search TextField.
  -     */
  -    protected class TextTracker implements DocumentListener {
  -
  -        public void changedUpdate(DocumentEvent e) { }
  -
  -        public void insertUpdate(DocumentEvent e) {
  -            updateButtonState();
  -            String text = search.getText();
  -            // go to next only if the current node does not match the text
  -            if (!match(walker.getCurrentGraphicsNode(), text)) {
  -                GraphicsNode gn = getNext(text);
  -                if (gn != null) {
  -                    previous.setEnabled(true);
  -                    showSelectedGraphicsNode();
  -                } else {
  -                    next.setEnabled(false);
  -                }
  -            }
  -        }
  -
  -        public void removeUpdate(DocumentEvent e) {
  -            updateButtonState();
  -            GraphicsNode gn = getPrevious(search.getText());
  -            if (gn != null) {
  -                next.setEnabled(true);
  -                showSelectedGraphicsNode();
  -            } else {
  -                previous.setEnabled(false);
  -            }
           }
       }
   }
  
  
  
  1.15      +2 -3      xml-batik/sources/org/apache/batik/gvt/TextPainter.java
  
  Index: TextPainter.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/TextPainter.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TextPainter.java  2001/09/27 20:09:10     1.14
  +++ TextPainter.java  2001/10/03 16:08:19     1.15
  @@ -21,7 +21,7 @@
    * Renders the attributed character iterator of a <tt>TextNode</tt>.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thierry Kormann</a>
  - * @version $Id: TextPainter.java,v 1.14 2001/09/27 20:09:10 deweese Exp $
  + * @version $Id: TextPainter.java,v 1.15 2001/10/03 16:08:19 tkormann Exp $
    */
   public interface TextPainter {
   
  @@ -33,8 +33,7 @@
        * @param g2d the Graphics2D to use
        * @param context the rendering context.
        */
  -    void paint(TextNode node, 
  -               Graphics2D g2d);
  +    void paint(TextNode node, Graphics2D g2d);
   
       /**
        * Initiates a text selection on a particular AttributedCharacterIterator,
  
  
  
  1.18      +32 -1     xml-batik/sources/org/apache/batik/swing/gvt/JGVTComponent.java
  
  Index: JGVTComponent.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/gvt/JGVTComponent.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- JGVTComponent.java        2001/09/18 21:19:01     1.17
  +++ JGVTComponent.java        2001/10/03 16:08:19     1.18
  @@ -47,11 +47,13 @@
   import org.apache.batik.gvt.renderer.ImageRenderer;
   import org.apache.batik.gvt.renderer.ImageRendererFactory;
   
  +import org.apache.batik.gvt.text.Mark;
  +
   /**
    * This class represents a component which can display a GVT tree.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: JGVTComponent.java,v 1.17 2001/09/18 21:19:01 deweese Exp $
  + * @version $Id: JGVTComponent.java,v 1.18 2001/10/03 16:08:19 tkormann Exp $
    */
   public class JGVTComponent extends JComponent {
   
  @@ -288,6 +290,35 @@
               }
           }
       }
  +
  +    ////////////////////////////////////////////////////////////////////////
  +    // Selection methods
  +    ////////////////////////////////////////////////////////////////////////
  +
  +    /**
  +     * Sets the selection to the specified start and end mark.
  +     *
  +     * @param start the mark used to define where the selection starts
  +     * @param end the mark used to define where the selection ends
  +     */
  +    public void select(Mark start, Mark end) {
  +     if (textSelectionManager != null) {
  +         textSelectionManager.setSelection(start, end);
  +     }
  +    }
  +
  +    /**
  +     * Deselects all.
  +     */
  +    public void deselectAll() {
  +     if (textSelectionManager != null) {
  +         textSelectionManager.clearSelection();
  +     }
  +    }
  +
  +    ////////////////////////////////////////////////////////////////////////
  +    // Painting methods
  +    ////////////////////////////////////////////////////////////////////////
   
       /**
        * Whether to enable the progressive paint.
  
  
  
  1.10      +8 -1      
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TextSelectionManager.java 2001/09/27 21:19:44     1.9
  +++ TextSelectionManager.java 2001/10/03 16:08:19     1.10
  @@ -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.9 2001/09/27 21:19:44 deweese Exp $
  + * @version $Id: TextSelectionManager.java,v 1.10 2001/10/03 16:08:19 tkormann Exp $
    */
   public class TextSelectionManager {
   
  @@ -113,6 +113,13 @@
        */
       public void setSelection(Mark start, Mark end) {
           textSelector.setSelection(start, end);
  +    }
  +
  +    /**
  +     * Clears the selection.
  +     */
  +    public void clearSelection() {
  +     textSelector.clearSelection();
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to