Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jpicedt/graphic/model/PicPut.java


1   /*  jPicEdt version 1.3.2, a picture editor for LaTeX.
2       Copyright (C) 1999-2002  Sylvain Reynal
3   
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8   
9       This program is distributed in the hope that it will be useful,
10      but WITHOUT ANY WARRANTY; without even the implied warranty of
11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12      GNU General Public License for more details.
13  
14      You should have received a copy of the GNU General Public License
15      along with this program; if not, write to the Free Software
16      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  
18      Sylvain Reynal
19      Département de Physique
20      Ecole Nationale Supérieure de l'Electronique et de ses Applications (ENSEA)
21      6, avenue du Ponceau
22      95014 CERGY CEDEX
23      FRANCE
24  
25      Tel : 00 +33 130 736 245
26      Fax : 00 +33 130 736 667
27      e-mail : reynal@ensea.fr
28      jPicEdt web page : http://www.jpicedt.org
29  */
30  
31  package jpicedt.graphic.model;
32  
33  import jpicedt.graphic.toolkit.*;
34  import jpicedt.graphic.*;
35  import jpicedt.widgets.*;
36  
37  import java.awt.*;
38  import java.awt.event.*;
39  import java.awt.geom.*;
40  import javax.swing.*;
41  
42  /**
43   * This object allow the user to insert any \\put(x,y){...} command anywhere in the drawing
44   * This is especially useful for people willing to use their own macro or packages.
45   *
46   * A PicPut object is made of an anchor point an a command string.
47   *
48   * @author Sylvain Reynal
49   * @since PicEdt 1.2.a
50   */
51  
52  public class PicPut extends TextEditable implements CustomizerFactory {  // exemple : \\put(15,20){\\frame{GNU}}
53  
54  
55    //////////////////////////////
56    /// CONSTRUCTORS
57    //////////////////////////////
58  
59    /**
60     * Constructor with the whole set of parameters as arguments
61     *
62     * @param ptA Anchor point
63     * @param command The command string (argument of the put command)
64     * @since PicEdt 1.2.a
65     */
66    public PicPut(PicPoint ptA, String command, PicAttributeSet set) {
67      super(command, ptA, set);
68    }
69  
70    /**
71     * Constructor filling the parameters with their default value : empty command string,
72     * @param ptA Anchor point
73     * @since PicEdt 1.2.a
74     */
75    public PicPut(PicPoint ptA, PicAttributeSet set) {
76      this(ptA, "", set);
77    }
78  
79    /**
80     * "cloning" constructor (to be used by clone())
81     * @param The PicPut object to clone
82     * @since PicEdt 1.2.a
83     */
84    public PicPut(PicPut putObj){
85      super(putObj);
86    }
87  
88    /**
89     * Overload Object.clone() method
90     *
91     * @since PicEdt 1.2.a
92     */
93    public Object clone(){
94      return new PicPut(this);
95    }
96  
97    /**
98     * @return a localised string that represents this object's name
99     */
100   public String getName(){
101     return "\\put{...}";
102   }
103 
104   //////////////////////////////////
105   /// OPERATIONS ON CONTROL POINTS
106   //////////////////////////////////
107 
108   // inherited
109 
110   ///////////////////////
111   /// BOUNDING BOX
112   ///////////////////////
113 
114 
115   ///////////////////////////////
116   //// STRING FORMATING
117   ///////////////////////////////
118 
119   /**
120    * @return a formater for the given object
121    * @param parent a formater that helps this Element determines the type of Formater it's to return
122    */
123   //   public Formater createFormater(Formater parent){
124   //     return new PicPutFormater(this,parent);
125   //   }
126 
127 
128   /**
129    * @return a string representation of this object for debugging purpose only
130    */
131   public String toString(){
132 
133     return "[PicPut@" + Integer.toHexString(hashCode()) + " : "
134            + getText() + "\""
135            + super.toString();
136   }
137 
138 
139   ////////////////////////////////
140   //// GUI
141   ////////////////////////////////
142 
143   /**
144    * @return a Customizer for geometry editing
145    */
146   public AbstractCustomizer createCustomizer(){
147     return new Customizer();
148   }
149   
150   /**
151    * geometry customizer
152    */
153   class Customizer extends AbstractCustomizer implements ActionListener {
154 
155     private JTextField putCommandTF;
156     private DecimalNumberField putAnchorXTF,putAnchorYTF;
157     private boolean isListenersAdded = false; // flag
158 
159     public Customizer(){
160 
161       super();
162       JPanel p = new JPanel(new GridLayout(2,1,5,5));
163 
164       // line 1: put command string
165       p.add(putCommandTF = new JTextField(25));
166       putCommandTF.setText(getText());
167 
168       // line 2: anchor point label
169       Box box;
170       box = new Box(BoxLayout.X_AXIS);
171       box.add(PEToolKit.createJLabel("PutAnchorPoint"));
172       box.add(Box.createHorizontalStrut(10));
173       // x-coordinate of anchor point
174       box.add(putAnchorXTF = new DecimalNumberField(4));
175       // y-coordinate of anchor point
176       box.add(putAnchorYTF = new DecimalNumberField(4));
177       p.add(box);
178 
179       // cyclic focus TAB
180       putAnchorYTF.setNextFocusableComponent(putCommandTF);
181       add(p, BorderLayout.NORTH);
182     }
183     
184     /** add action listeners to widgets to reflect changes immediately */ 
185     private void addActionListeners(){
186       if (isListenersAdded) return; // already done
187       putCommandTF.addActionListener(this);
188       putAnchorXTF.addActionListener(this);
189       putAnchorYTF.addActionListener(this);
190       isListenersAdded = true;
191     }
192 
193     /**
194      * (re)init widgets with Element's properties
195      */
196     public void load(){
197       putAnchorXTF.setValue(getPointX(P_ANCHOR));
198       putAnchorYTF.setValue(getPointY(P_ANCHOR));
199       // add listeners AFTERWARDS ! otherwise loading widgets initial value has a painful side-effet...
200       // since it call "store" before everything has been loaded 
201       addActionListeners(); // done the first time load is called
202     }
203 
204     /**
205      * update Element's properties
206      */
207     public void store(){
208       setText(putCommandTF.getText());
209       PicPoint point1Frame = new PicPoint(putAnchorXTF.getValue(), putAnchorYTF.getValue());
210       setPoint(P_ANCHOR,point1Frame);
211     }
212 
213     public void actionPerformed(ActionEvent e){
214       store();
215     }
216     
217     /**
218      * @return the panel title, used e.g. for Border or Tabpane title. 
219      * @since jPicEdt 1.3.2
220      * @author Sylvain Reynal
221      */
222     public String getTitle(){ 
223       return jpicedt.Localizer.currentLocalizer().get(PicPut.this.getName());
224     }
225     
226   }
227 } // PicPut