1
package latexDraw.ui.dialog;
4
import java.awt.event.ItemEvent;
7
import javax.swing.border.CompoundBorder;
8
import javax.swing.border.EmptyBorder;
9
import javax.swing.border.TitledBorder;
10
import javax.swing.event.ChangeEvent;
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;
25
* This class defines the frame which allows to change the parameters of dots.<br>
27
* This file is part of LaTeXDraw<br>
28
* Copyright (c) 2005-2008 Arnaud BLOUIN<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>
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>
40
* @author Arnaud BLOUIN<br>
43
public class ParametersDotFrame extends AbstractParametersFrame
45
private static final long serialVersionUID = 1L;
47
/** Allows to change the x-coordinates of the centre of the figure */
48
protected JSpinner centerXField;
50
/** Allows to change the y-coordinates of the centre of the figure */
51
protected JSpinner centerYField;
53
/** Allows to change the y-coordinates of the width of the figure */
54
protected JSpinner widthField;
56
/** The list of the styles of dots */
57
protected LaTeXDrawComboBox dotChoice;
62
* The constructor by default
64
public ParametersDotFrame(Frame parent, DrawPanel p, boolean attachToMainFrame)
66
super(parent, p, attachToMainFrame);
69
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
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());
76
GridBagConstraints constraint = new GridBagConstraints();
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);
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);
95
constraint.gridx = 0; constraint.gridy = 1;
96
constraint.gridwidth = 1;
97
pParams.add(new JLabel(LABEL_CENTER_Y), constraint);
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);
107
constraint.gridx = 0; constraint.gridy++;
108
constraint.gridwidth = 1;
109
pParams.add(new JLabel(LABEL_WIDTH), constraint);
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);
119
constraint.gridx = 0; constraint.gridy++;
120
constraint.gridwidth = 1;
121
pParams.add(new JLabel(LABEL_ROTATION), constraint);
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);
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);
138
constraint.gridx = 1; constraint.gridwidth = 1;
139
pParams.add(new JLabel(LaTeXDrawLang.getDialogFrameString("ParametersDotFrame.0")), constraint); //$NON-NLS-1$
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);
148
pParams.setBorder(new CompoundBorder(new TitledBorder(null, TITLE_GENERAL,
149
TitledBorder.LEFT, TitledBorder.TOP), new EmptyBorder(0,0,0,0)));
151
pGeneral.add(pParams);
152
pGeneral.add(createFillPanel());
153
hatchChoice.setVisible(false);
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);
162
setLocation(dim.width/2-getWidth()/2, dim.height/2-getHeight()/2);
167
ExceptionFrameDialog.showExceptionDialog(e);
175
public void saveParameters()
177
super.saveParameters();
181
float x = Float.valueOf(centerXField.getValue().toString()).floatValue();
182
float y = Float.valueOf(centerYField.getValue().toString()).floatValue();
184
JLabel label = (JLabel) dotChoice.getSelectedItem();
185
d.setCurrentStyle(label.getText());
186
d.setWidth(Float.valueOf(widthField.getValue().toString()).floatValue());
192
drawPanel.getDraw().updateBorders();
193
drawPanel.updateDraw(true);
200
public void setFigureFrameField()
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());
211
interiorButton.setColor(d.getInteriorColor());
217
public void setDefaultsValues()
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);
230
ExceptionFrameDialog.showExceptionDialog(e);
237
public void setVisible(boolean visible, Figure selected, boolean deleteOnCancel, boolean isFramedBox)
241
if(!(selected instanceof Dot))
242
throw new ClassCastException();
244
super.setVisible(visible, selected, deleteOnCancel, isFramedBox);
247
ex.printStackTrace();
248
ExceptionFrameDialog.showExceptionDialog(ex);
256
public void stateChanged(ChangeEvent e)
260
Object o = e.getSource();
262
Dot f = (Dot) glimpsePanel.getGlimpseFigure();
264
if(o instanceof JSpinner)
266
String name = ((JSpinner)o).getName();
268
if(name.equals(LABEL_CENTER_X))
271
f.getCenter().x = Float.valueOf(centerXField.getValue().toString()).floatValue();
272
glimpsePanel.repaint();
276
if(name.equals(LABEL_CENTER_Y))
279
f.getCenter().y = Float.valueOf(centerYField.getValue().toString()).floatValue();
280
glimpsePanel.repaint();
284
if(name.equals(LABEL_WIDTH))
287
f.setWidth(Float.valueOf(widthField.getValue().toString()).floatValue());
288
glimpsePanel.repaint();
294
ex.printStackTrace();
295
ExceptionFrameDialog.showExceptionDialog(ex);
298
super.stateChanged(e);
305
public void itemStateChanged(ItemEvent e)
309
Dot f = (Dot) glimpsePanel.getGlimpseFigure();
310
Object o = e.getSource();
312
if(o instanceof LaTeXDrawComboBox)
314
if(((LaTeXDrawComboBox)o).getName().equals(LaTeXDrawResources.CHOICE_DOT_NAME))
316
JLabel l = (JLabel) ((LaTeXDrawComboBox)o).getSelectedItem();
317
f.setCurrentStyle(l.getText());
318
interiorButton.setEnabled(f.canBeFilled());
322
interiorButton.setColor(f.getInteriorColor());
323
interiorButton.repaint();
327
glimpsePanel.repaint();
334
ex.printStackTrace();
335
ExceptionFrameDialog.showExceptionDialog(ex);
337
super.itemStateChanged(e);