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 vh...@apache.org on 2001/05/03 20:10:47 UTC

cvs commit: xml-batik/sources/org/apache/batik/i18n LocalizableSupport.java

vhardy      01/05/03 11:10:47

  Modified:    sources/org/apache/batik/apps/svgbrowser
                        JSVGViewerFrame.java
               sources/org/apache/batik/i18n LocalizableSupport.java
  Added:       sources/org/apache/batik/ext/swing JGridBagPanel.java
                        JAffineTransformChooser.java Messages.java
                        Resources.java DoubleDocument.java
  Log:
  Added a "Set Transform" dialog box in viewer to let the user control
  the rendering transform precisely. This can be used, for example, to
  set a precise rotation angle.
  
  Revision  Changes    Path
  1.1                  xml-batik/sources/org/apache/batik/ext/swing/JGridBagPanel.java
  
  Index: JGridBagPanel.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.batik.ext.swing;
  
  import javax.swing.JPanel;
  import java.awt.LayoutManager;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.AWTError;
  import java.awt.Component;
  import java.awt.Container;
  import java.awt.Insets;
  
  /**
   * An implementation of JPanel that uses the GridBagLayout.
   * 
   * @author  <a href="mailto:vincent.hardy@eng.sun.com>Vincent Hardy</a>
   * @version $Id: JGridBagPanel.java,v 1.1 2001/05/03 18:10:30 vhardy Exp $
   */
  
  public class JGridBagPanel extends JPanel {
      /**
       * Provides insets desired for a given grid cell
       */
      public static interface InsetsManager{
          /**
           * Returns the insets for cell (gridx, gridy);
           */
          public Insets getInsets(int gridx, int gridy);
      }
  
      /**
       * Always use 0 insets
       */
      private static class ZeroInsetsManager implements InsetsManager{
          private Insets insets = new Insets(0, 0, 0, 0);
  
          public Insets getInsets(int gridx, int gridy){
              return insets;
          }
      }
  
      /**
       * Default implemenation
       */
      private static class DefaultInsetsManager implements InsetsManager{
          /**
           * leftInset is the space used by default as a padding to the 
           * left of each grid cell.
           */
          int leftInset=5;
          
          /**
           * topInset is the space used by default as a padding to the 
           * top of each grid cell.
           */
          int topInset=5;
          
          public Insets positiveInsets = new Insets(topInset, leftInset, 0, 0);
          public Insets leftInsets = new Insets(topInset, 0, 0, 0);
          public Insets topInsets = new Insets(0, leftInset, 0, 0);
          public Insets topLeftInsets = new Insets(0, 0, 0, 0);
  
          public Insets getInsets(int gridx, int gridy){
              if(gridx > 0){
                  if(gridy > 0)
                      return positiveInsets;
                  else
                      return topInsets;
              }
              else{
                  if(gridy > 0)
                      return leftInsets;
                  else
                      return topLeftInsets;
              }
          }
      }
  
      /**
       * An InsetsManager that uses zero insets
       */
      public static final InsetsManager ZERO_INSETS = new ZeroInsetsManager();
  
      /**
       * An InsetsManager that uses padding for inside cells
       */
      public static final InsetsManager DEFAULT_INSETS = new DefaultInsetsManager();
  
      /**
       * Specify that this component is the 
       * last component in its column or row. 
       * @since   JDK1.0
       */
      public static final int REMAINDER = GridBagConstraints.REMAINDER;
  
      /**
       * Do not resize the component. 
       * @since   JDK1.0
       */
      public static final int NONE = GridBagConstraints.NONE;
  
      /**
       * Resize the component both horizontally and vertically. 
       * @since   JDK1.0
       */
      public static final int BOTH = GridBagConstraints.BOTH;
  
      /**
       * Resize the component horizontally but not vertically. 
       * @since   JDK1.0
       */
      public static final int HORIZONTAL = GridBagConstraints.HORIZONTAL;
  
      /**
       * Resize the component vertically but not horizontally. 
       * @since   JDK1.0
       */
      public static final int VERTICAL = GridBagConstraints.VERTICAL;
  
      /**
       * Put the component in the center of its display area.
       * @since    JDK1.0
       */
      public static final int CENTER = GridBagConstraints.CENTER;
  
      /**
       * Put the component at the top of its display area,
       * centered horizontally. 
       * @since   JDK1.0
       */
      public static final int NORTH = GridBagConstraints.NORTH;
  
      /**
       * Put the component at the top-right corner of its display area. 
       * @since   JDK1.0
       */
      public static final int NORTHEAST = GridBagConstraints.NORTHEAST;
  
      /**
       * Put the component on the left side of its display area, 
       * centered vertically.
       * @since    JDK1.0
       */
      public static final int EAST = GridBagConstraints.EAST;
  
      /**
       * Put the component at the bottom-right corner of its display area. 
       * @since   JDK1.0
       */
      public static final int SOUTHEAST = GridBagConstraints.SOUTHEAST;
  
      /**
       * Put the component at the bottom of its display area, centered 
       * horizontally. 
       * @since   JDK1.0
       */
      public static final int SOUTH = GridBagConstraints.SOUTH;
  
      /**
       * Put the component at the bottom-left corner of its display area. 
       * @since   JDK1.0
       */
      public static final int SOUTHWEST = GridBagConstraints.SOUTHWEST;
  
      /**
       * Put the component on the left side of its display area, 
       * centered vertically.
       * @since    JDK1.0
       */
      public static final int WEST = GridBagConstraints.WEST;
  
      /**
       * Put the component at the top-left corner of its display area. 
       * @since   JDK1.0
       */
      public static final int NORTHWEST = GridBagConstraints.NORTHWEST;
  
      /**
       * Used to get insets at any given cell location
       */
      public InsetsManager insetsManager;
  
      /**
       * Sets the layout manager to GridBagLayout
       */
      public JGridBagPanel(){
          this(new DefaultInsetsManager());
      }
  
      /**
       * Initializes panel with a given insets manager
       */
      public JGridBagPanel(InsetsManager insetsManager){
          super(new GridBagLayout());
  
          if(insetsManager != null)
              this.insetsManager = insetsManager;
          else
              this.insetsManager = new DefaultInsetsManager();
      }
  
      /**
       * This method only takes effect if the LayoutManager is a GridBagLayout
       */
      public void setLayout(LayoutManager layout){
          if(layout instanceof GridBagLayout)
              super.setLayout(layout);
      }
  
      /**
       * This version uses default insets and assumes that components are added in
       * positive cell coordinates. Top inset for components added to the top
       * is 0. Left inset for components added to the left is 0. For compoents at
       * index gridx more than zero and index gridy more than zero, the insets 
       * are set to a default value.
       *
       * @param cmp Component to add to the panel
       * @param gridx x position of the cell into which component should be added
       * @param gridy y position of the cell into which component should be added
       * @param gridwidth width, in cells, of the space occupied by the component in the grid
       * @param gridheight height, in cells, of the space occupied by the component in the grid
       * @param anchor placement of the component in its allocated space: WEST, NORTH, SOUTH, NORTHWEST, ...
       * @param fill out should the component be resized within its space? NONE, BOTH, HORIZONTAL, VERTICAL.
       * @param weightx what amount of extra horizontal space, if any, should be given to this component?
       * @param weighty what amount of extra vertical space, if any, should be given to this component?
       */
      public void add(Component cmp, int gridx, int gridy,
                      int gridwidth, int gridheight, int anchor, int fill, 
                      double weightx, double weighty){
          Insets insets = insetsManager.getInsets(gridx, gridy);
          GridBagConstraints constraints = new GridBagConstraints();
          constraints.gridx = gridx;
          constraints.gridy = gridy;
          constraints.gridwidth = gridwidth;
          constraints.gridheight = gridheight;
          constraints.anchor = anchor;
          constraints.fill = fill;
          constraints.weightx = weightx;
          constraints.weighty = weighty;
          constraints.insets = insets;
          add(cmp, constraints);
      }
  
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/ext/swing/JAffineTransformChooser.java
  
  Index: JAffineTransformChooser.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.batik.ext.swing;
  
  import java.awt.BorderLayout;
  import java.awt.Component;
  import java.awt.Container;
  import java.awt.FlowLayout;
  import java.awt.Window;
  import java.awt.geom.AffineTransform;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.ComponentAdapter;
  import java.awt.event.ComponentEvent;
  import java.awt.event.KeyEvent;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  
  import java.io.Serializable;
  
  import javax.swing.AbstractAction;
  import javax.swing.AbstractButton;
  import javax.swing.Action;
  import javax.swing.ActionMap;
  import javax.swing.BorderFactory;
  import javax.swing.InputMap;
  import javax.swing.JButton;
  import javax.swing.JComponent;
  import javax.swing.JDialog;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JTextField;
  import javax.swing.KeyStroke;
  import javax.swing.border.Border;
  
  import javax.swing.text.Document;
  
  /**
   * The <tt>JAffineTransformChooser</tt> is a pane that contains
   * controls to let a user select the various components that 
   * make up an <tt>AffineTransform</tt>
   *
   * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
   * @version $Id: JAffineTransformChooser.java,v 1.1 2001/05/03 18:10:32 vhardy Exp $
   */
  public class JAffineTransformChooser extends JGridBagPanel{
      public static final String LABEL_ANGLE
          = "JAffineTransformChooser.label.angle";
  
      public static final String LABEL_DEGREE
          = "JAffineTransformChooser.label.degree";
  
      public static final String LABEL_PERCENT
          = "JAffineTransformChooser.label.percent";
  
      public static final String LABEL_ROTATE
          = "JAffineTransformChooser.label.rotate";
  
      public static final String LABEL_SCALE
          = "JAffineTransformChooser.label.scale";
  
      public static final String LABEL_RX
          = "JAffineTransformChooser.label.rx";
  
      public static final String LABEL_RY
          = "JAffineTransformChooser.label.ry";
  
      public static final String LABEL_SX
          = "JAffineTransformChooser.label.sx";
  
      public static final String LABEL_SY
          = "JAffineTransformChooser.label.sy";
  
      public static final String LABEL_TRANSLATE
          = "JAffineTransformChooser.label.translate";
  
      public static final String LABEL_TX 
          = "JAffineTransformChooser.label.tx";
  
      public static final String LABEL_TY
          = "JAffineTransformChooser.label.ty";
      
      public static final String CONFIG_TEXT_FIELD_WIDTH 
          = "JAffineTransformChooser.config.text.field.width";
  
      public static final String CONFIG_TOP_PAD
          = "JAffineTransformChooser.config.top.pad";
  
      public static final String CONFIG_LEFT_PAD
          = "JAffineTransformChooser.config.left.pad";
  
      public static final String CONFIG_BOTTOM_PAD
          = "JAffineTransformChooser.config.bottom.pad";
  
      public static final String CONFIG_RIGHT_PAD
          = "JAffineTransformChooser.config.right.pad";
  
      /**
       * The <tt>AffineTransform</tt> value represented by the 
       * chooser
       */
      protected AffineTransform txf;
  
      /**
       * The Model for the x-axis translate component
       */
      protected DoubleDocument txModel = new DoubleDocument();
  
      /**
       * The Model for the y-axis translate component
       */
      protected DoubleDocument tyModel = new DoubleDocument();
      
      /**
       * The Model for the x-axis scale component
       */
      protected DoubleDocument sxModel = new DoubleDocument();
  
      /**
       * The Model for the y-axis scale component
       */
      protected DoubleDocument syModel = new DoubleDocument();
  
      /**
       * The Model for the x-axis rotation center
       */
      protected DoubleDocument rxModel = new DoubleDocument();
  
      /**
       * The Model for the y-axis rotation center
       */
      protected DoubleDocument ryModel = new DoubleDocument();
  
      /**
       * The Model for the rotation
       */
      protected DoubleDocument rotateModel = new DoubleDocument();
  
      protected static final double RAD_TO_DEG = 180./Math.PI;
      protected static final double DEG_TO_RAD = Math.PI/180.;
  
      /**
       * Default constructor
       */
      public JAffineTransformChooser(){
          this(null);
      }
        
      /**
       * @param txf initial value for the <tt>AffineTransform</tt>
       */
      public JAffineTransformChooser(AffineTransform txf){
          setAffineTransform(txf);
          build();
      }
  
      /**
       * Adds the control components into this panel.
       */
      protected void build(){
          Component txyCmp = buildPanel(Resources.getString(LABEL_TRANSLATE),
                                        Resources.getString(LABEL_TX),
                                        txModel,
                                        Resources.getString(LABEL_TY),
                                        tyModel,
                                        "",
                                        "",
                                        true);
          
          Component sxyCmp = buildPanel(Resources.getString(LABEL_SCALE),
                                        Resources.getString(LABEL_SX),
                                        sxModel,
                                        Resources.getString(LABEL_SY),
                                        syModel,
                                        Resources.getString(LABEL_PERCENT),
                                        Resources.getString(LABEL_PERCENT),
                                        true);
  
          Component rCmp = buildRotatePanel();
                                   
          add(txyCmp,  0, 0, 1, 1, CENTER, BOTH, 1, 1);
          add(sxyCmp,  1, 0, 1, 1, CENTER, BOTH, 1, 1);
          add(rCmp,    0, 1, 2, 1, CENTER, BOTH, 1, 1);
      }
  
      protected Component buildRotatePanel(){
          JGridBagPanel panel = new JGridBagPanel();
  
          Component anglePanel = buildPanel(Resources.getString(LABEL_ROTATE),
                                            Resources.getString(LABEL_ANGLE),
                                            rotateModel,
                                            null,
                                            null,
                                            Resources.getString(LABEL_DEGREE),
                                            null,
                                            false);
  
          Component centerPanel = buildPanel("",
                                             Resources.getString(LABEL_RX),
                                             rxModel,
                                             Resources.getString(LABEL_RY),
                                             ryModel,
                                             null,
                                             null,
                                             false);
  
          panel.add(anglePanel,   0, 0, 1, 1, CENTER, BOTH, 1, 1);
          panel.add(centerPanel,  1, 0, 1, 1, CENTER, BOTH, 1, 1);
  
          setPanelBorder(panel, Resources.getString(LABEL_ROTATE));
  
          return panel;
      }
  
      protected Component buildPanel(String panelName,
                                     String tfALabel,
                                     Document tfAModel,
                                     String tfBLabel,
                                     Document tfBModel,
                                     String tfASuffix,
                                     String tfBSuffix,
                                     boolean setBorder){
          JGridBagPanel panel = new JGridBagPanel();
          
          addToPanelAtRow(tfALabel, tfAModel, tfASuffix, panel, 0);
          if(tfBLabel != null){
              addToPanelAtRow(tfBLabel, tfBModel, tfBSuffix, panel, 1);
          }
  
          // Create a border
          if(setBorder){
              setPanelBorder(panel, panelName);
          }
  
          return panel;
  
      }
  
      public void setPanelBorder(JComponent panel, String panelName){
          Border border 
              = BorderFactory.createTitledBorder
              (BorderFactory.createEtchedBorder(), panelName);
  
          int topPad = Resources.getInteger(CONFIG_TOP_PAD);
          int leftPad = Resources.getInteger(CONFIG_LEFT_PAD);
          int bottomPad = Resources.getInteger(CONFIG_BOTTOM_PAD);
          int rightPad = Resources.getInteger(CONFIG_RIGHT_PAD);
  
          border 
              = BorderFactory.createCompoundBorder
              (border,
               BorderFactory.createEmptyBorder(topPad, leftPad, 
                                               bottomPad, rightPad));
  
          panel.setBorder(border);
      }
  
      protected void addToPanelAtRow(String label,
                                     Document model,
                                     String suffix,
                                     JGridBagPanel p,
                                     int row){
          JTextField tf = new JTextField(Resources.getInteger(CONFIG_TEXT_FIELD_WIDTH));
          tf.setDocument(model);
          p.add(new JLabel(label),    0, row, 1, 1, WEST, HORIZONTAL, 0, 0);
          p.add(tf,                   1, row, 1, 1, CENTER, HORIZONTAL, 1, 0);
          p.add(new JLabel(suffix),   2, row, 1, 1, WEST, HORIZONTAL, 0, 0);
      }
  
      public AffineTransform getAffineTransform(){
          double sx = sxModel.getValue()/100.;
          double sy = syModel.getValue()/100.;
          double theta = rotateModel.getValue()*DEG_TO_RAD;
          double rx = rxModel.getValue();
          double ry = ryModel.getValue();
          double tx = txModel.getValue();
          double ty = tyModel.getValue();
  
          double[] m = new double[6];
  
          m[0] = sx*Math.cos(theta);
          m[1] = sx*Math.sin(theta);
          m[2] = -sy*Math.sin(theta);
          m[3] = sy*Math.cos(theta);
          m[4] = tx + rx - rx*Math.cos(theta) + ry*Math.sin(theta);
          m[5] = ty + ry - rx*Math.sin(theta) - ry*Math.cos(theta);
  
          txf = new AffineTransform(m);
  
          return txf;
      }
  
      public void setAffineTransform(AffineTransform txf){
          if(txf == null){
              txf = new AffineTransform();
          }
  
          if(!txf.equals(this.txf)){
              this.txf = txf;
              
              /**
               * Now, update model
               */
              double[] m = new double[6];
              txf.getMatrix(m);
  
              for(int i=0; i<m.length; i++){
                  System.out.println("m[" + i + "] = " + m[i]);
              }
  
              // Translation
              txModel.setValue(m[4]);
              tyModel.setValue(m[5]);
              
              // Scale, in percentages
              double sx = Math.sqrt(m[0]*m[0] + m[1]*m[1]);
              double sy = Math.sqrt(m[2]*m[2] + m[3]*m[3]);
              sxModel.setValue(100*sx);
              syModel.setValue(100*sy);
              
              // Rotation
              double theta = 0;
              if(m[0] > 0){
                  theta = Math.atan2(m[1], m[0]);
              }
  
              // Rotate
              rotateModel.setValue(RAD_TO_DEG*theta);
              rxModel.setValue(0);
              ryModel.setValue(0);
          }
          
      }        
  
      /**
       * Displays the panel in a modal dialog box.
       * @param cmp the dialog's parent component
       * @param title the dialog's title
       * @param txf transform
       *
       * @return null if the dialog was cancelled. Otherwise, the value entered
       *         by the user.
       */
      public static AffineTransform showDialog(Component cmp,
                                               String title,
                                               AffineTransform txf){
          final JAffineTransformChooser pane 
              = new JAffineTransformChooser(txf);
  
          AffineTransformTracker tracker = new AffineTransformTracker(pane);
          JDialog dialog = new Dialog(cmp, title, true, pane, tracker, null);
          dialog.addWindowListener(new Closer());
          dialog.addComponentListener(new DisposeOnClose());
  
          dialog.show(); // blocks until user brings dialog down...
  
          return tracker.getAffineTransform();
      }
      
      /**
       * Creates a new modal dialog box that can be used to 
       * configure an <tt>AffineTransform</tt>
       *
       * @param cmp the dialog's parent component
       * @param title the dialog's title
       * @param txf transform
       *
       */
      public static Dialog createDialog(Component cmp,
                                        String title,
                                        AffineTransform txf){
          final JAffineTransformChooser pane 
              = new JAffineTransformChooser(txf);
          
          AffineTransformTracker tracker = new AffineTransformTracker(pane);
          Dialog dialog = new Dialog(cmp, title, true, pane, tracker, null);
          dialog.addWindowListener(new Closer());
          dialog.addComponentListener(new DisposeOnClose());
  
          return dialog;
      }
      
  
      public static void main(String args[]){
          AffineTransform t = showDialog(null, "Hello", AffineTransform.getRotateInstance(DEG_TO_RAD*45, 100, 200));
          // AffineTransform.getScaleInstance(.25, .25));
          // new AffineTransform()); 
          // AffineTransform.getShearInstance(1, 1));
          if(t == null){
              System.out.println("Cancelled");
          }
          else{
              System.out.println("t = " + t);
          }
      }
  
      /*
       * Class which builds a AffineTransform chooser dialog consisting of
       * a JAffineTransformChooser with "Ok", "Cancel", and "Reset" buttons.
       *
       * Note: This needs to be fixed to deal with localization!
       */
      public static class Dialog extends JDialog {
          private AffineTransform initialAffineTransform;
          private JAffineTransformChooser chooserPane;
          private AffineTransformTracker tracker;
  
          public static final String LABEL_OK 
              = "JAffineTransformChooser.label.ok";
  
          public static final String LABEL_CANCEL 
              = "JAffineTransformChooser.label.cancel";
  
          public static final String LABEL_RESET
              = "JAffineTransformChooser.label.reset";
  
          public static final String ACTION_COMMAND_OK
              = "OK";
  
          public static final String ACTION_COMMAND_CANCEL 
              = "cancel";
  
  
          public Dialog(Component c, String title, boolean modal,
                        JAffineTransformChooser chooserPane,
                        AffineTransformTracker okListener, ActionListener cancelListener) {
              super(JOptionPane.getFrameForComponent(c), title, modal);
          
              this.chooserPane = chooserPane;
              this.tracker = okListener;
  
              String okString = Resources.getString(LABEL_OK);
              String cancelString = Resources.getString(LABEL_CANCEL);
              String resetString = Resources.getString(LABEL_RESET);
  
              Container contentPane = getContentPane();
              contentPane.setLayout(new BorderLayout());
              contentPane.add(chooserPane, BorderLayout.CENTER);
  
              /*
               * Create Lower button panel
               */
              JPanel buttonPane = new JPanel();
              buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
              JButton okButton = new JButton(okString);
              getRootPane().setDefaultButton(okButton);
              okButton.setActionCommand(ACTION_COMMAND_OK);
              if (okListener != null) {
                  okButton.addActionListener(okListener);
              }
              okButton.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          hide();
                      }
                  });
              buttonPane.add(okButton);
  
              JButton cancelButton = new JButton(cancelString);
  
              // The following few lines are used to register esc to close the dialog
              Action cancelKeyAction = new AbstractAction() {
                      public void actionPerformed(ActionEvent e) {
                          hide();
                      }
                  }; 
              KeyStroke cancelKeyStroke = KeyStroke.getKeyStroke((char)KeyEvent.VK_ESCAPE);
              InputMap inputMap = cancelButton.getInputMap(JComponent.
                                                           WHEN_IN_FOCUSED_WINDOW);
              ActionMap actionMap = cancelButton.getActionMap();
              if (inputMap != null && actionMap != null) {
                  inputMap.put(cancelKeyStroke, ACTION_COMMAND_CANCEL);
                  actionMap.put(ACTION_COMMAND_CANCEL, cancelKeyAction);
              }
              // end esc handling
  
              cancelButton.setActionCommand(ACTION_COMMAND_CANCEL);
              if (cancelListener != null) {
                  cancelButton.addActionListener(cancelListener);
              }
              cancelButton.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          hide();
                      }
                  });
              buttonPane.add(cancelButton);
  
              JButton resetButton = new JButton(resetString);
              resetButton.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          reset();
                      }
                  });
              buttonPane.add(resetButton);
              contentPane.add(buttonPane, BorderLayout.SOUTH);
  
              pack();
              setLocationRelativeTo(c);
          }
  
          public void show() {
              initialAffineTransform = chooserPane.getAffineTransform();
              super.show();
          }
  
          public AffineTransform showDialog(){
              this.show();
              return tracker.getAffineTransform();
          }
  
          public void reset() {
              chooserPane.setAffineTransform(initialAffineTransform);
          }
  
          public void setTransform(AffineTransform at){
              if(at == null){
                  at = new AffineTransform();
              }
  
              initialAffineTransform = at;
              chooserPane.setAffineTransform(at);
          }
  
  
  
      }
  
      static class Closer extends WindowAdapter implements Serializable{
          public void windowClosing(WindowEvent e) {
              Window w = e.getWindow();
              w.hide();
          }
      }
      
      static class DisposeOnClose extends ComponentAdapter implements Serializable{
          public void componentHidden(ComponentEvent e) {
              Window w = (Window)e.getComponent();
              w.dispose();
          }
      }
      
  }
  
  
  class AffineTransformTracker implements ActionListener, Serializable {
      JAffineTransformChooser chooser;
      AffineTransform txf;
  
      public AffineTransformTracker(JAffineTransformChooser c) {
          chooser = c;
      }
  
      public void actionPerformed(ActionEvent e) {
          txf = chooser.getAffineTransform();
      }
  
      public AffineTransform getAffineTransform() {
          return txf;
      }
  }
  
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/ext/swing/Messages.java
  
  Index: Messages.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.ext.swing;
  
  import java.util.Locale;
  import java.util.MissingResourceException;
  import org.apache.batik.i18n.Localizable;
  import org.apache.batik.i18n.LocalizableSupport;
  
  /**
   * This class manages the message for the Swing extensions.
   *
   * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
   * @version $Id: Messages.java,v 1.1 2001/05/03 18:10:33 vhardy Exp $
   */
  public class Messages {
  
      /**
       * This class does not need to be instantiated.
       */
      protected Messages() { }
  
      /**
       * The error messages bundle class name.
       */
      protected final static String RESOURCES =
          "org.apache.batik.ext.swing.resources.Messages";
  
      /**
       * The localizable support for the error messages.
       */
      protected static LocalizableSupport localizableSupport =
          new LocalizableSupport(RESOURCES);
  
      /**
       * Implements {@link org.apache.batik.i18n.Localizable#setLocale(Locale)}.
       */
      public static void setLocale(Locale l) {
          localizableSupport.setLocale(l);
      }
  
      /**
       * Implements {@link org.apache.batik.i18n.Localizable#getLocale()}.
       */
      public static Locale getLocale() {
          return localizableSupport.getLocale();
      }
  
      /**
       * Implements {@link
       * org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}.
       */
      public static String formatMessage(String key, Object[] args)
          throws MissingResourceException {
          return localizableSupport.formatMessage(key, args);
      }
  
      public static String getString(String key)
          throws MissingResourceException {
          return formatMessage(key, null);
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/ext/swing/Resources.java
  
  Index: Resources.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.ext.swing;
  
  import java.util.Locale;
  import java.util.MissingResourceException;
  import org.apache.batik.i18n.Localizable;
  import org.apache.batik.i18n.LocalizableSupport;
  
  /**
   * This class manages the message for the Swing extensions.
   *
   * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
   * @version $Id: Resources.java,v 1.1 2001/05/03 18:10:34 vhardy Exp $
   */
  public class Resources {
  
      /**
       * This class does not need to be instantiated.
       */
      protected Resources() { }
  
      /**
       * The error messages bundle class name.
       */
      protected final static String RESOURCES =
          "org.apache.batik.ext.swing.resources.Messages";
  
      /**
       * The localizable support for the error messages.
       */
      protected static LocalizableSupport localizableSupport =
          new LocalizableSupport(RESOURCES);
  
      /**
       * Implements {@link org.apache.batik.i18n.Localizable#setLocale(Locale)}.
       */
      public static void setLocale(Locale l) {
          localizableSupport.setLocale(l);
      }
  
      /**
       * Implements {@link org.apache.batik.i18n.Localizable#getLocale()}.
       */
      public static Locale getLocale() {
          return localizableSupport.getLocale();
      }
  
      /**
       * Implements {@link
       * org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}.
       */
      public static String formatMessage(String key, Object[] args)
          throws MissingResourceException {
          return localizableSupport.formatMessage(key, args);
      }
  
      public static String getString(String key)
          throws MissingResourceException {
          return formatMessage(key, null);
      }
  
      public static int getInteger(String key) 
          throws MissingResourceException {
          return localizableSupport.getResourceManager().getInteger(key);
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/ext/swing/DoubleDocument.java
  
  Index: DoubleDocument.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.batik.ext.swing;
  
  import javax.swing.text.AttributeSet;
  import javax.swing.text.BadLocationException;
  import javax.swing.text.PlainDocument;
  
  /**
   * Helper class. Only allows an Double value in the document.
   * 
   * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
   * @version $Id: DoubleDocument.java,v 1.1 2001/05/03 18:10:34 vhardy Exp $
   */
  public class DoubleDocument extends PlainDocument {
      /** 
       * Strip all non digit characters. '-' and '+' are only allowed as the
       * first character. Only one '.' is allowed.
       **/
      public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { 
          if (str == null) {
              return;
          }
  
          // Get current value
          String curVal = getText(0, getLength());
          boolean hasDot = curVal.indexOf(".")!=-1;
  
          // Strip non digit characters
          char[] buffer = str.toCharArray();
          char[] digit = new char[buffer.length];
          int j = 0;
  
          if(offs==0 && buffer!=null && buffer.length>0 && buffer[0]=='-')
              digit[j++] = buffer[0];
  
          for (int i = 0; i < buffer.length; i++) {
              if(Character.isDigit(buffer[i]))
                  digit[j++] = buffer[i];
              if(!hasDot && buffer[i]=='.'){
                  digit[j++] = '.';
                  hasDot = true;
              }
          }
  
          // Now, test that new value is within range.
          String added = new String(digit, 0, j);
          try{
              StringBuffer val = new StringBuffer(curVal);
              val.insert(offs, added);
              if(val.toString().equals(".") || val.toString().equals("-") || val.toString().equals("-."))
                  super.insertString(offs, added, a);
              else{
                  Double.valueOf(val.toString());
                  super.insertString(offs, added, a);
              }
          }catch(NumberFormatException e){
              // Ignore insertion, as it results in an out of range value
          }
      }
  
      public void setValue(double d){
          try{
              remove(0, getLength());
              insertString(0, (new Double(d)).toString(), null);
          }catch(BadLocationException e){
              // Will not happen because we are sure
              // we use the proper range
          }
      }
  
      public double getValue(){
          try{
              String t = getText(0, getLength());
              if(t != null && t.length() > 0){
                  return Double.parseDouble(t);
              }
              else{
                  return 0;
              }
          }catch(BadLocationException e){
              // Will not happen because we are sure
              // we use the proper range
              throw new Error();
          }
      }
  }
  
  
  
  
  
  1.30      +36 -1     xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java
  
  Index: JSVGViewerFrame.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- JSVGViewerFrame.java	2001/05/02 15:31:29	1.29
  +++ JSVGViewerFrame.java	2001/05/03 18:10:38	1.30
  @@ -119,6 +119,8 @@
   import org.apache.batik.util.gui.resource.ResourceManager;
   import org.apache.batik.util.gui.resource.ToolBarFactory;
   
  +import org.apache.batik.ext.swing.JAffineTransformChooser;
  +
   import org.apache.batik.xml.XMLUtilities;
   
   import org.w3c.dom.css.ViewCSS;
  @@ -129,7 +131,7 @@
    * This class represents a SVG viewer swing frame.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: JSVGViewerFrame.java,v 1.29 2001/05/02 15:31:29 hillion Exp $
  + * @version $Id: JSVGViewerFrame.java,v 1.30 2001/05/03 18:10:38 vhardy Exp $
    */
   public class JSVGViewerFrame
       extends    JFrame
  @@ -171,6 +173,7 @@
       public final static String STYLE_SHEET_ACTION = "StyleSheetAction";
       public final static String MONITOR_ACTION = "MonitorAction";
       public final static String DOM_VIEWER_ACTION = "DOMViewerAction";
  +    public final static String SET_TRANSFORM_ACTION = "SetTransformAction";
   
       /**
        * The cursor indicating that an operation is pending.
  @@ -286,6 +289,11 @@
       protected LanguageDialog languageDialog;
   
       /**
  +     * The transform dialog
  +     */
  +    protected JAffineTransformChooser.Dialog transformDialog;
  +
  +    /**
        * The user style dialog.
        */
       protected UserStyleDialog styleSheetDialog;
  @@ -373,6 +381,7 @@
           listeners.put(STYLE_SHEET_ACTION, new StyleSheetAction());
           listeners.put(MONITOR_ACTION, new MonitorAction());
           listeners.put(DOM_VIEWER_ACTION, new DOMViewerAction());
  +        listeners.put(SET_TRANSFORM_ACTION, new SetTransformAction());
   
           svgCanvas = new JSVGCanvas(userAgent, true, true);
   
  @@ -1191,6 +1200,32 @@
   
           public void update(boolean enabled) {
               menuItem.setEnabled(enabled);
  +        }
  +    }
  +
  +    /**
  +     * To show the set transform dialog
  +     */
  +    public class SetTransformAction extends AbstractAction {
  +        public SetTransformAction(){}
  +        public void actionPerformed(ActionEvent e){
  +            if (transformDialog == null){
  +                transformDialog 
  +                    = JAffineTransformChooser.createDialog
  +                    (JSVGViewerFrame.this,
  +                     resources.getString("SetTransform.title"),
  +                     null);
  +            }
  +
  +            AffineTransform at = svgCanvas.getRenderingTransform();
  +            transformDialog.setTransform(at);
  +
  +            System.out.println("AT : " + at);
  +            AffineTransform txf = transformDialog.showDialog();
  +            System.out.println("TXF : " + txf);
  +            if(txf != null){
  +                svgCanvas.setRenderingTransform(txf);
  +            }
           }
       }
   
  
  
  
  1.4       +20 -1     xml-batik/sources/org/apache/batik/i18n/LocalizableSupport.java
  
  Index: LocalizableSupport.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/i18n/LocalizableSupport.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalizableSupport.java	2000/11/21 12:03:16	1.3
  +++ LocalizableSupport.java	2001/05/03 18:10:44	1.4
  @@ -12,6 +12,8 @@
   import java.util.Locale;
   import java.util.ResourceBundle;
   
  +import org.apache.batik.util.gui.resource.ResourceManager;
  +
   /**
    * This class provides a default implementation of the Localizable interface.
    * You can use it as a base class or as a member field and delegates various
  @@ -63,7 +65,7 @@
    * default group common to each instance of LocalizableSupport.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: LocalizableSupport.java,v 1.3 2000/11/21 12:03:16 tkormann Exp $
  + * @version $Id: LocalizableSupport.java,v 1.4 2001/05/03 18:10:44 vhardy Exp $
    */
   public class LocalizableSupport implements Localizable {
       /**
  @@ -97,6 +99,11 @@
       protected ResourceBundle resourceBundle;
   
       /**
  +     * The resource manager
  +     */
  +    protected ResourceManager resourceManager;
  +
  +    /**
        * Same as LocalizableSupport(s, null).
        */
       public LocalizableSupport(String s) {
  @@ -125,6 +132,7 @@
           if (locale != l) {
               locale = l;
               resourceBundle = null;
  +            resourceManager = null;
           }
       }
   
  @@ -184,6 +192,8 @@
        */
       public ResourceBundle getResourceBundle() {
           Locale l;
  +        ResourceBundle oldBundle = resourceBundle;
  +
           if (resourceBundle == null) {
               if (locale == null) {
                   if ((l = localeGroup.getLocale()) == null) {
  @@ -228,6 +238,15 @@
                   }
               }
           }
  +
  +        if(oldBundle != resourceBundle){
  +            resourceManager = new ResourceManager(resourceBundle);
  +        }
  +
           return resourceBundle;
  +    }
  +
  +    public ResourceManager getResourceManager(){
  +        return resourceManager;
       }
   }
  
  
  

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