~ubuntu-branches/debian/squeeze/latexdraw/squeeze

« back to all changes in this revision

Viewing changes to latexDraw/ui/dialog/ParametersDotFrame.java

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2009-05-03 23:49:35 UTC
  • Revision ID: james.westby@ubuntu.com-20090503234935-cls7n48x018g0vk2
Tags: upstream-2.0.2+1
ImportĀ upstreamĀ versionĀ 2.0.2+1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package latexDraw.ui.dialog;
 
2
 
 
3
import java.awt.*;
 
4
import java.awt.event.ItemEvent;
 
5
 
 
6
import javax.swing.*;
 
7
import javax.swing.border.CompoundBorder;
 
8
import javax.swing.border.EmptyBorder;
 
9
import javax.swing.border.TitledBorder;
 
10
import javax.swing.event.ChangeEvent;
 
11
 
 
12
import latexDraw.figures.Dot;
 
13
import latexDraw.figures.Figure;
 
14
import latexDraw.lang.LaTeXDrawLang;
 
15
import latexDraw.psTricks.PSTricksConstants;
 
16
import latexDraw.ui.DrawPanel;
 
17
import latexDraw.ui.components.ButtonIcon;
 
18
import latexDraw.ui.components.ColorButton;
 
19
import latexDraw.ui.components.LaTeXDrawComboBox;
 
20
import latexDraw.util.LaTeXDrawPoint2D;
 
21
import latexDraw.util.LaTeXDrawResources;
 
22
 
 
23
 
 
24
/** 
 
25
 * This class defines the frame which allows to change the parameters of dots.<br>
 
26
 *<br>
 
27
 * This file is part of LaTeXDraw<br>
 
28
 * Copyright (c) 2005-2008 Arnaud BLOUIN<br>
 
29
 *<br>
 
30
 *  LaTeXDraw is free software; you can redistribute it and/or modify
 
31
 *  it under the terms of the GNU General Public License as published by
 
32
 *  the Free Software Foundation; either version 2 of the License, or
 
33
 *  (at your option) any later version.<br>
 
34
 *<br>
 
35
 *  LaTeXDraw is distributed without any warranty; without even the 
 
36
 *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 
37
 *  PURPOSE. See the GNU General Public License for more details.<br>
 
38
 *<br>
 
39
 * 01/20/06<br>
 
40
 * @author Arnaud BLOUIN<br>
 
41
 * @version 2.0.0<br>
 
42
 */
 
43
public class ParametersDotFrame extends AbstractParametersFrame
 
44
{
 
45
        private static final long serialVersionUID = 1L;
 
46
 
 
47
        /** Allows to change the x-coordinates of the centre of the figure */
 
48
        protected JSpinner centerXField;
 
49
        
 
50
        /** Allows to change the y-coordinates of the centre of the figure */
 
51
        protected JSpinner centerYField;
 
52
        
 
53
        /** Allows to change the y-coordinates of the width of the figure */
 
54
        protected JSpinner widthField;
 
55
        
 
56
        /** The list of the styles of dots */
 
57
        protected LaTeXDrawComboBox dotChoice;
 
58
        
 
59
        
 
60
        
 
61
        /**
 
62
         * The constructor by default
 
63
         */
 
64
        public ParametersDotFrame(Frame parent, DrawPanel p, boolean attachToMainFrame)
 
65
        {
 
66
                super(parent, p, attachToMainFrame);
 
67
                try
 
68
                {
 
69
                        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
 
70
                                                
 
71
                        JPanel pButton  = createButtonsPanel(this);
 
72
                        JPanel pGeneral = new JPanel();
 
73
                        pGeneral.setLayout(new BoxLayout(pGeneral, BoxLayout.Y_AXIS));
 
74
                        JPanel pParams = new JPanel(new GridBagLayout());
 
75
                        
 
76
                        GridBagConstraints constraint = new GridBagConstraints();
 
77
                constraint.gridx = 0;
 
78
                constraint.gridy = 0;
 
79
                constraint.gridwidth = 1;
 
80
                constraint.gridheight = 1;
 
81
                constraint.weightx = 0.1;
 
82
                constraint.weighty = 0.1;
 
83
                constraint.fill = GridBagConstraints.NONE;
 
84
                constraint.anchor = GridBagConstraints.CENTER;
 
85
                pParams.add(new JLabel(LABEL_CENTER_X), constraint);
 
86
                        
 
87
                SpinnerModel model = new SpinnerNumberModel(0,0,10000,0.1);
 
88
                centerXField = new JSpinner(model);
 
89
                        centerXField.setEditor(new JSpinner.NumberEditor(centerXField, "0.0"));//$NON-NLS-1$
 
90
                        centerXField.addChangeListener(this);
 
91
                centerXField.setName(LABEL_CENTER_X);
 
92
                constraint.gridx = 1;   constraint.gridwidth = 1;
 
93
                pParams.add(centerXField, constraint);
 
94
 
 
95
                constraint.gridx = 0;   constraint.gridy = 1;
 
96
                constraint.gridwidth = 1;
 
97
                pParams.add(new JLabel(LABEL_CENTER_Y), constraint);
 
98
                        
 
99
                model = new SpinnerNumberModel(0,0,10000,0.1);
 
100
                centerYField = new JSpinner(model);
 
101
                centerYField.setEditor(new JSpinner.NumberEditor(centerYField, "0.0"));//$NON-NLS-1$
 
102
                        centerYField.addChangeListener(this);
 
103
                centerYField.setName(LABEL_CENTER_Y);
 
104
                constraint.gridx = 1;   constraint.gridwidth = 1;
 
105
                pParams.add(centerYField, constraint);
 
106
                
 
107
                constraint.gridx = 0;   constraint.gridy++;
 
108
                constraint.gridwidth = 1;
 
109
                pParams.add(new JLabel(LABEL_WIDTH), constraint);
 
110
 
 
111
                model = new SpinnerNumberModel(0.1,0.1,10000,0.1);
 
112
                widthField = new JSpinner(model);
 
113
                widthField.setEditor(new JSpinner.NumberEditor(widthField, "0.0"));//$NON-NLS-1$
 
114
                widthField.addChangeListener(this);
 
115
                widthField.setName(LABEL_WIDTH);
 
116
                constraint.gridx = 1;   constraint.gridwidth = 1;
 
117
                pParams.add(widthField, constraint);
 
118
                
 
119
                constraint.gridx = 0;   constraint.gridy++;
 
120
                constraint.gridwidth = 1;
 
121
                pParams.add(new JLabel(LABEL_ROTATION), constraint);
 
122
                
 
123
                model = new SpinnerNumberModel(Figure.DEFAULT_ROTATION_ANGLE, -360, 360,0.1);
 
124
                rotationField = new JSpinner(model);
 
125
                rotationField.setEditor(new JSpinner.NumberEditor(rotationField, "0.0"));//$NON-NLS-1$
 
126
                rotationField.addChangeListener(this);
 
127
                rotationField.setName(LaTeXDrawResources.LABEL_ROTATE);
 
128
                constraint.gridx = 1;   constraint.gridwidth = 1;
 
129
                pParams.add(rotationField, constraint);
 
130
                
 
131
                bordersButton = new ColorButton(LaTeXDrawResources.LABEL_COLOR_BUTTON, new ButtonIcon(Color.BLACK));
 
132
                bordersButton.setText(LaTeXDrawResources.LABEL_COLOR_BUTTON);
 
133
                bordersButton.setActionCommand(LaTeXDrawResources.LABEL_COLOR_BUTTON);
 
134
                bordersButton.addActionListener(this);
 
135
                constraint.gridx = 0;   constraint.gridy++;
 
136
                pParams.add(bordersButton, constraint);
 
137
                                
 
138
                constraint.gridx = 1;   constraint.gridwidth = 1;
 
139
                pParams.add(new JLabel(LaTeXDrawLang.getDialogFrameString("ParametersDotFrame.0")), constraint); //$NON-NLS-1$
 
140
                
 
141
                dotChoice = Dot.createDotStyleChoice();
 
142
                dotChoice.setName(LaTeXDrawResources.CHOICE_DOT_NAME);
 
143
                dotChoice.setSelectedItem(PSTricksConstants.LINE_NONE_STYLE);
 
144
                dotChoice.addItemListener(this);
 
145
                constraint.gridx = 2;   constraint.gridwidth = 1;
 
146
                pParams.add(dotChoice, constraint);
 
147
                
 
148
                pParams.setBorder(new CompoundBorder(new TitledBorder(null, TITLE_GENERAL, 
 
149
                                                                TitledBorder.LEFT, TitledBorder.TOP), new EmptyBorder(0,0,0,0)));
 
150
                
 
151
                pGeneral.add(pParams);
 
152
                pGeneral.add(createFillPanel());
 
153
                        hatchChoice.setVisible(false);
 
154
                        
 
155
                BoxLayout bl = new BoxLayout(getContentPane(), BoxLayout.Y_AXIS);
 
156
                getContentPane().setLayout(bl);
 
157
                getContentPane().add(glimpsePanelZoom);
 
158
                getContentPane().add(pGeneral);
 
159
                        getContentPane().add(pButton);
 
160
                        filledCheckBox.setVisible(false);
 
161
                        pack();
 
162
                        setLocation(dim.width/2-getWidth()/2, dim.height/2-getHeight()/2);
 
163
                        setVisible(false);
 
164
                }catch(Exception e)
 
165
                {
 
166
                        e.printStackTrace(); 
 
167
                        ExceptionFrameDialog.showExceptionDialog(e);
 
168
                }
 
169
        }
 
170
        
 
171
        
 
172
        
 
173
        
 
174
        @Override
 
175
        public void saveParameters()
 
176
        {
 
177
                super.saveParameters();
 
178
                
 
179
                Dot d = (Dot)figure;
 
180
                
 
181
                float x = Float.valueOf(centerXField.getValue().toString()).floatValue();
 
182
                float y = Float.valueOf(centerYField.getValue().toString()).floatValue();
 
183
 
 
184
                JLabel label = (JLabel) dotChoice.getSelectedItem();
 
185
                d.setCurrentStyle(label.getText());
 
186
                d.setWidth(Float.valueOf(widthField.getValue().toString()).floatValue());
 
187
                d.getCenter().x = x;
 
188
                d.getCenter().y = y;
 
189
                d.updateDelimitor();
 
190
                d.updateShape();
 
191
                
 
192
                drawPanel.getDraw().updateBorders();
 
193
                drawPanel.updateDraw(true);
 
194
        }
 
195
        
 
196
        
 
197
        
 
198
        
 
199
        @Override
 
200
        public void setFigureFrameField()
 
201
        {
 
202
                Dot d = (Dot)figure;
 
203
                LaTeXDrawPoint2D center = d.getCenter();
 
204
                dotChoice.setSelectedItem(d.getCurrentStyle());
 
205
                centerXField.setValue(center.x);
 
206
                centerYField.setValue(center.y);
 
207
                widthField.setValue((double)d.getWidth());
 
208
                interiorButton.setEnabled(d.canBeFilled());
 
209
                
 
210
                if(d.canBeFilled())
 
211
                        interiorButton.setColor(d.getInteriorColor());
 
212
        }
 
213
 
 
214
        
 
215
        
 
216
        @Override
 
217
        public void setDefaultsValues()
 
218
        {
 
219
                try
 
220
                {
 
221
                        super.setDefaultsValues();
 
222
                        dotChoice.setSelectedItem(Dot.DEFAULT_DOT_STYLE);
 
223
                        widthField.setValue(Dot.DEFAULT_WIDTH);
 
224
                        interiorButton.setEnabled(glimpsePanel.glimpseFigure.canBeFilled());
 
225
                        interiorButton.setColor(Figure.DEFAULT_INTERIOR_COL);
 
226
                        
 
227
                }catch(Exception e)
 
228
                {
 
229
                        e.printStackTrace();
 
230
                        ExceptionFrameDialog.showExceptionDialog(e);
 
231
                }
 
232
        }
 
233
 
 
234
        
 
235
        
 
236
        @Override
 
237
        public void setVisible(boolean visible, Figure selected, boolean deleteOnCancel, boolean isFramedBox) 
 
238
        {
 
239
                try
 
240
                {
 
241
                        if(!(selected instanceof Dot))
 
242
                                throw new ClassCastException();
 
243
 
 
244
                        super.setVisible(visible, selected, deleteOnCancel, isFramedBox);
 
245
                }catch(Exception ex)
 
246
                {
 
247
                        ex.printStackTrace(); 
 
248
                        ExceptionFrameDialog.showExceptionDialog(ex);
 
249
                }       
 
250
        }
 
251
        
 
252
        
 
253
        
 
254
        
 
255
        @Override
 
256
        public void stateChanged(ChangeEvent e) 
 
257
        {
 
258
                try
 
259
                {
 
260
                        Object o = e.getSource();
 
261
                        
 
262
                        Dot f = (Dot) glimpsePanel.getGlimpseFigure();
 
263
                        
 
264
                        if(o instanceof JSpinner)
 
265
                        {
 
266
                                String name = ((JSpinner)o).getName();
 
267
                                
 
268
                                if(name.equals(LABEL_CENTER_X))
 
269
                                {
 
270
                                        setModified(true);
 
271
                                        f.getCenter().x = Float.valueOf(centerXField.getValue().toString()).floatValue();
 
272
                                        glimpsePanel.repaint();
 
273
                                        return ;
 
274
                                }
 
275
                                
 
276
                                if(name.equals(LABEL_CENTER_Y))
 
277
                                {
 
278
                                        setModified(true);
 
279
                                        f.getCenter().y = Float.valueOf(centerYField.getValue().toString()).floatValue();
 
280
                                        glimpsePanel.repaint();
 
281
                                        return ;
 
282
                                }
 
283
                                
 
284
                                if(name.equals(LABEL_WIDTH))
 
285
                                {
 
286
                                        setModified(true);
 
287
                                        f.setWidth(Float.valueOf(widthField.getValue().toString()).floatValue());
 
288
                                        glimpsePanel.repaint();
 
289
                                        return ;
 
290
                                }
 
291
                        }
 
292
                }catch(Exception ex)
 
293
                {
 
294
                        ex.printStackTrace(); 
 
295
                        ExceptionFrameDialog.showExceptionDialog(ex);
 
296
                }
 
297
                
 
298
                super.stateChanged(e);
 
299
        }
 
300
        
 
301
        
 
302
        
 
303
        
 
304
        @Override
 
305
        public void itemStateChanged(ItemEvent e) 
 
306
        {       
 
307
                try
 
308
                {
 
309
                        Dot f = (Dot) glimpsePanel.getGlimpseFigure();
 
310
                        Object o = e.getSource();
 
311
                        
 
312
                        if(o instanceof LaTeXDrawComboBox)
 
313
                        {
 
314
                                if(((LaTeXDrawComboBox)o).getName().equals(LaTeXDrawResources.CHOICE_DOT_NAME))
 
315
                                {
 
316
                                        JLabel l = (JLabel) ((LaTeXDrawComboBox)o).getSelectedItem();
 
317
                                        f.setCurrentStyle(l.getText());
 
318
                                        interiorButton.setEnabled(f.canBeFilled());
 
319
                                        
 
320
                                        if(f.canBeFilled())
 
321
                                        {
 
322
                                                interiorButton.setColor(f.getInteriorColor());
 
323
                                                interiorButton.repaint();
 
324
                                        }
 
325
                                        
 
326
                                        setModified(true);
 
327
                                        glimpsePanel.repaint();
 
328
                                        return ;
 
329
                                }
 
330
                        }
 
331
                }
 
332
                catch(Exception ex)
 
333
                {
 
334
                        ex.printStackTrace(); 
 
335
                        ExceptionFrameDialog.showExceptionDialog(ex);
 
336
                }
 
337
                super.itemStateChanged(e);
 
338
        }
 
339
}