tkormann 01/10/05 08:34:26 Modified: resources/org/apache/batik/apps/svgbrowser/resources FindDialog.properties sources/org/apache/batik/apps/svgbrowser FindDialog.java sources/org/apache/batik/swing/gvt JGVTComponent.java Log: Add some cool zoom options for the find dialog. 1. You are now able to zoom and pan on the result. 2. You can also fix a zoom factor by hand in the browser and just pan on the result. 3. The last option is just to highlight the result (no pan, no zoom) really cool when displaying maps :) Revision Changes Path 1.5 +12 -5 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- FindDialog.properties 2001/10/04 14:39:26 1.4 +++ FindDialog.properties 2001/10/05 15:34:26 1.5 @@ -9,20 +9,18 @@ # FindDialog properties file # # Author: [EMAIL PROTECTED] -# $Id: FindDialog.properties,v 1.4 2001/10/04 14:39:26 tkormann Exp $ +# $Id: FindDialog.properties,v 1.5 2001/10/05 15:34:26 tkormann Exp $ # Dialog.title = Batik: Find Panel.title = Search for text +ShowResultPanel.title = Display FindLabel.text = Find : CaseSensitiveCheckBox.text = Case sensitive CaseSensitiveCheckBox.mnemonic = S -EnableZoomCheckBox.text = Enable zoom -EnableZoomCheckBox.mnemonic = A - FindButton.text = Find FindButton.mnemonic = F FindButton.action = FindButtonAction @@ -32,8 +30,17 @@ ClearButton.action = ClearButtonAction CloseButton.text = Close -CloseButton.mnemonic = X +CloseButton.mnemonic = O CloseButton.action = CloseButtonAction + +Highlight.text = Highlight result +Highlight.mnemonic = H + +HighlightAndCenter.text = Highlight and center result +HighlightButtonAction.mnemonic = A + +HighlightCenterAndZoom.text = Highlight, center and zoom on result +HighlightCenterAndZoom.mnemonic = Z End.text = End of document reached; continue from beginning. End.title = Batik: Find wrap 1.6 +102 -31 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FindDialog.java 2001/10/04 14:39:26 1.5 +++ FindDialog.java 2001/10/05 15:34:26 1.6 @@ -14,6 +14,7 @@ import java.awt.Frame; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; @@ -34,12 +35,14 @@ import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.event.DocumentListener; @@ -66,7 +69,7 @@ * an SVG document. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: FindDialog.java,v 1.5 2001/10/04 14:39:26 tkormann Exp $ + * @version $Id: FindDialog.java,v 1.6 2001/10/05 15:34:26 tkormann Exp $ */ public class FindDialog extends JDialog implements ActionMap { @@ -78,7 +81,9 @@ // action names public final static String FIND_ACTION = "FindButtonAction"; + public final static String CLEAR_ACTION = "ClearButtonAction"; + public final static String CLOSE_ACTION = "CloseButtonAction"; /** @@ -105,9 +110,7 @@ /** The GVTTreeWalker used to scan the GVT Tree. */ protected GVTTreeWalker walker; - /** - * The current index in the TextNode's string. - */ + /** The current index in the TextNode's string. */ protected int currentIndex; /** The TextField that owns the text to search. */ @@ -125,12 +128,17 @@ /** The case sensitive button. */ protected JCheckBox caseSensitive; - /** The zoom button. */ - protected JCheckBox enableZoom; - /** The canvas. */ protected JSVGCanvas svgCanvas; + /** The highlight button. */ + protected JRadioButton highlightButton; + + /** The highlight and center button. */ + protected JRadioButton highlightCenterButton; + + /** The highlight center and zoom button. */ + protected JRadioButton highlightCenterZoomButton; /** * Constructs a new <tt>FindDialog</tt>. */ @@ -146,12 +154,22 @@ this.svgCanvas = svgCanvas; buttonFactory = new ButtonFactory(bundle, this); + + listeners.put(FIND_ACTION, + new FindButtonAction()); + + listeners.put(CLEAR_ACTION, + new ClearButtonAction()); - listeners.put(FIND_ACTION, new FindButtonAction()); - listeners.put(CLEAR_ACTION, new ClearButtonAction()); - listeners.put(CLOSE_ACTION, new CloseButtonAction()); + listeners.put(CLOSE_ACTION, + new CloseButtonAction()); - getContentPane().add(createFindPanel(), BorderLayout.CENTER); + JPanel p = new JPanel(new BorderLayout()); + p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + p.add(createFindPanel(), BorderLayout.CENTER); + p.add(createShowResultPanel(), BorderLayout.SOUTH); + + getContentPane().add(p, BorderLayout.CENTER); getContentPane().add(createButtonsPanel(), BorderLayout.SOUTH); } @@ -186,14 +204,44 @@ caseSensitive = buttonFactory.createJCheckBox("CaseSensitiveCheckBox"); panel.add(caseSensitive, gbc); - gbc.fill = ExtendedGridBagConstraints.NONE; + return panel; + } + + protected JPanel createShowResultPanel() { + JPanel panel = new JPanel(new GridBagLayout()); + + panel.setBorder(BorderFactory.createTitledBorder + (BorderFactory.createEtchedBorder(), + resources.getString("ShowResultPanel.title"))); + + ExtendedGridBagConstraints gbc = new ExtendedGridBagConstraints(); + gbc.insets = new Insets(2, 2, 2, 2); + gbc.anchor = ExtendedGridBagConstraints.WEST; + gbc.fill = ExtendedGridBagConstraints.NONE; gbc.setWeight(0, 0); - gbc.setGridBounds(2, 1, 1, 1); - enableZoom = buttonFactory.createJCheckBox("EnableZoomCheckBox"); - //panel.add(enableZoom, gbc); - return panel; + ButtonGroup grp = new ButtonGroup(); + + highlightButton = buttonFactory.createJRadioButton("Highlight"); + highlightButton.setSelected(true); + grp.add(highlightButton); + gbc.setGridBounds(0, 0, 1, 1); + panel.add(highlightButton, gbc); + + highlightCenterButton = + buttonFactory.createJRadioButton("HighlightAndCenter"); + grp.add(highlightCenterButton); + gbc.setGridBounds(0, 1, 1, 1); + panel.add(highlightCenterButton, gbc); + + highlightCenterZoomButton = + buttonFactory.createJRadioButton("HighlightCenterAndZoom"); + grp.add(highlightCenterZoomButton); + gbc.setGridBounds(0, 2, 1, 1); + panel.add(highlightCenterZoomButton, gbc); + + return panel; } /** @@ -294,23 +342,46 @@ svgCanvas.select(startMark, endMark); // zoom on the TextNode if needed - if (enableZoom.isSelected()) { - Dimension2D docSize = svgCanvas.getSVGDocumentSize(); - Rectangle2D nb = textNode.getBounds(); - AffineTransform at = gn.getGlobalTransform(); - - Rectangle2D gnb = at.createTransformedShape(nb).getBounds(); - Dimension canvasSize = svgCanvas.getSize(); + if (highlightButton.isSelected()) { + return; + } - Point2D p = at.deltaTransform - (new Point2D.Float(canvasSize.width, canvasSize.height), null); + // get the highlight shape in GVT root (global) coordinate sytem + Shape s = textNode.getHighlightShape(); + AffineTransform at; + if (highlightCenterZoomButton.isSelected()) { + at = svgCanvas.getInitialTransform(); + } else { + at = svgCanvas.getRenderingTransform(); + } + // get the bounds of the highlight shape in the canvas coordinate system + Rectangle2D gnb = at.createTransformedShape(s).getBounds(); - AffineTransform Tx = AffineTransform.getTranslateInstance - (-gnb.getX() - gnb.getWidth() / 2 + p.getX() / 2, - -gnb.getY() - gnb.getHeight() / 2 + p.getY() / 2); - - svgCanvas.setRenderingTransform(Tx); - } + Dimension canvasSize = svgCanvas.getSize(); + // translate the highlight region to (0, 0) in the canvas coordinate + // system + AffineTransform Tx = AffineTransform.getTranslateInstance + (-gnb.getX()-gnb.getWidth()/2, + -gnb.getY()-gnb.getHeight()/2); + + if (highlightCenterZoomButton.isSelected()) { + // zoom on the highlight shape such as the shape takes x% of the + // canvas size + double sx = canvasSize.width/gnb.getWidth(); + double sy = canvasSize.height/gnb.getHeight(); + double scale = Math.min(sx, sy) / 8; + if (scale > 1) { + Tx.preConcatenate + (AffineTransform.getScaleInstance(scale, scale)); + } + } + Tx.preConcatenate(AffineTransform.getTranslateInstance + (canvasSize.width/2, canvasSize.height/2)); + // take into account the initial transform + AffineTransform newRT = new AffineTransform(at); + newRT.preConcatenate(Tx); + // change the rendering transform + svgCanvas.setRenderingTransform(newRT); } // ActionMap implementation 1.20 +8 -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.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- JGVTComponent.java 2001/10/04 08:25:47 1.19 +++ JGVTComponent.java 2001/10/05 15:34:26 1.20 @@ -53,7 +53,7 @@ * 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.19 2001/10/04 08:25:47 tkormann Exp $ + * @version $Id: JGVTComponent.java,v 1.20 2001/10/05 15:34:26 tkormann Exp $ */ public class JGVTComponent extends JComponent { @@ -467,6 +467,13 @@ } } scheduleGVTRendering(); + } + + /** + * Returns the initial transform. + */ + public AffineTransform getInitialTransform() { + return initialTransform; } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]