Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / PlacementProperties.java @ 11199

History | View | Annotate | Download (20.2 KB)

1 10679 jaume
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46 11199 jaume
* Revision 1.6  2007-04-13 12:43:08  jaume
47 11170 jaume
* *** empty log message ***
48
*
49 11199 jaume
* Revision 1.5  2007/04/13 12:10:56  jaume
50
* *** empty log message ***
51
*
52 11195 jaume
* Revision 1.4  2007/04/12 16:01:32  jaume
53
* *** empty log message ***
54
*
55 11170 jaume
* Revision 1.3  2007/03/28 15:38:56  jaume
56 10955 jaume
* GUI for lines, points and polygons
57
*
58
* Revision 1.2  2007/03/09 11:25:00  jaume
59 10679 jaume
* Advanced symbology (start committing)
60
*
61
* Revision 1.1.2.2  2007/02/09 11:00:03  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.1.2.1  2007/02/01 12:12:41  jaume
65
* theme manager window and all its components are now dynamic
66
*
67
*
68
*/
69
package com.iver.cit.gvsig.project.documents.view.legend.gui;
70
71
import java.awt.BorderLayout;
72 10955 jaume
import java.awt.Component;
73 10679 jaume
import java.awt.Dimension;
74 10955 jaume
import java.awt.FlowLayout;
75 10679 jaume
import java.awt.GridLayout;
76
import java.awt.event.ActionEvent;
77
import java.awt.event.ActionListener;
78
79
import javax.swing.BorderFactory;
80 10955 jaume
import javax.swing.BoxLayout;
81 10679 jaume
import javax.swing.ButtonGroup;
82 10955 jaume
import javax.swing.ImageIcon;
83
import javax.swing.JCheckBox;
84
import javax.swing.JComponent;
85
import javax.swing.JLabel;
86 10679 jaume
import javax.swing.JPanel;
87
import javax.swing.JRadioButton;
88
89
import org.gvsig.gui.beans.AcceptCancelPanel;
90
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
91 10955 jaume
import org.gvsig.gui.beans.swing.JBlank;
92
import org.gvsig.gui.beans.swing.JButton;
93 10679 jaume
94
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
95
import com.iver.andami.PluginServices;
96
import com.iver.andami.ui.mdiManager.IWindow;
97
import com.iver.andami.ui.mdiManager.WindowInfo;
98
import com.iver.cit.gvsig.fmap.core.FShape;
99 10955 jaume
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
100
import com.iver.cit.gvsig.fmap.core.styles.PointLabelPositioneer;
101 10679 jaume
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
102
import com.iver.cit.gvsig.fmap.rendering.styling.IPlacementConstraints;
103
import com.iver.cit.gvsig.fmap.rendering.styling.LabelingFactory;
104 10955 jaume
import com.iver.cit.gvsig.gui.styling.StyleSelector;
105
import com.iver.cit.gvsig.gui.styling.SelectorFilter;
106
import com.iver.cit.gvsig.gui.styling.StylePreviewer;
107
import com.iver.utiles.swing.JComboBox;
108
import com.vividsolutions.jts.geom.Point;
109
/**
110
 *
111
 * @author jaume dominguez faus - jaume.dominguez@iver.es
112
 *
113
 */
114
public class PlacementProperties extends JPanel implements IWindow, ActionListener {
115
        private PointLabelPositioneer pointStyle = new PointLabelPositioneer(
116
                        new byte[] { 2, 2, 1, 3, 2, 3, 3, 2        },
117
                        PluginServices.getText(this, "prefer_top_right_all_allowed")
118
                        );
119 10679 jaume
        private int shapeType;
120
        private JPanel pnlContent = null;
121
        private JPanel pnlCenter = null;
122
        private GridBagLayoutPanel pnlSouth = null;
123
        private JRadioButton rdBtnRemoveDuplicates;
124
        private IPlacementConstraints constraints;
125
        private JRadioButton rdBtnOnePerFeature;
126
        private JRadioButton rdBtnOnePerFeaturePart;
127
        private GridBagLayoutPanel orientationPanel;
128
        private JRadioButton rdBtnHorizontal;
129 10955 jaume
        private JRadioButton rdBtnParallel;
130 10679 jaume
        private JRadioButton rdBtnFollowingLine;
131
        private JRadioButton rdBtnPerpendicular;
132
        private GridBagLayoutPanel positionPanel;
133 10955 jaume
        private JLabel polygonIcon;
134
        private JLabel lineIcon;
135 10679 jaume
        private ActionListener action = new ActionListener() {
136
                public void actionPerformed(ActionEvent e) {
137
                        if ("OK".equals(e.getActionCommand()))
138
                                applyConstraints();
139 11195 jaume
140
                        if ("CANCEL".equals(e.getActionCommand()))
141
                                constraints = oldConstraints;
142 10679 jaume
                        PluginServices.getMDIManager().closeWindow(PlacementProperties.this);
143
                }
144
        };
145 10955 jaume
        private GridBagLayoutPanel polygonSettingsPanel;
146
        private JRadioButton rdBtnAlwaysHorizontal;
147
        private JRadioButton rdBtnAlwaysStraight;
148
        private GridBagLayoutPanel pointSettingsPanel;
149
        private JRadioButton rdBtnOffsetLabelHorizontally;
150
        private JRadioButton rdBtnOffsetLabelOnTopPoint;
151
        private StylePreviewer stylePreview;
152
        private JButton btnChangeLocation;
153
        private JPanel locationPanel;
154
        private JComboBox cmbLocationAlongLines;
155
        private JCheckBox chkBelow;
156
        private JCheckBox chkOnTheLine;
157
        private JCheckBox chkAbove;
158
        private JComboBox cmbOrientationSystem;
159
        private JLabel lblPointPosDesc = new JLabel(pointStyle.getDescription());
160 11195 jaume
        private IPlacementConstraints oldConstraints;
161
162 10679 jaume
        public PlacementProperties(FLyrVect layer, IPlacementConstraints constraints) throws ReadDriverException {
163
                this.shapeType = layer.getShapeType();
164 11195 jaume
                this.oldConstraints = constraints;
165 10679 jaume
                this.constraints = constraints != null ?
166 11195 jaume
                                LabelingFactory.createPlacementConstraints(constraints.getXMLEntity())        :
167 10679 jaume
                                LabelingFactory.createPlacementConstraints(layer);
168
                initialize();
169 11199 jaume
                refreshComponents();
170 10679 jaume
        }
171
172 11199 jaume
        private void refreshComponents() {
173
                getChkOnTheLine().setSelected(constraints.isOnTheLine());
174
                getChkAbove().setSelected(constraints.isAboveTheLine());
175
176
177
        }
178
179 10679 jaume
        private void initialize() {
180
        this.setLayout(new BorderLayout());
181 10955 jaume
        this.setSize(new Dimension(410,380));
182 10679 jaume
        this.add(getPnlContent(), BorderLayout.CENTER);
183
        this.add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
184
        }
185
186
        public WindowInfo getWindowInfo() {
187
                WindowInfo viewInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
188
                viewInfo.setWidth(getWidth());
189
                viewInfo.setHeight(getHeight());
190
                viewInfo.setTitle(PluginServices.getText(this,"placement_properties"));
191
                return viewInfo;
192
        }
193
194
        private JPanel getPnlContent() {
195
                if (pnlContent == null) {
196
                        pnlContent = new JPanel();
197
                        pnlContent.setLayout(new BorderLayout());
198
                        pnlContent.add(getPnlCenter(), java.awt.BorderLayout.CENTER);
199
                        pnlContent.add(getPnlSouth(), java.awt.BorderLayout.SOUTH);
200
                }
201
                return pnlContent;
202
        }
203
204
        private JPanel getPnlCenter() {
205
                if (pnlCenter == null) {
206
                        pnlCenter = new JPanel();
207
                        switch (shapeType) {
208
                        case FShape.POINT:
209
                                pnlCenter.setBorder(BorderFactory.
210
                                                createTitledBorder(null,
211
                                                PluginServices.getText(this, "point_settings")));
212 10955 jaume
                                pnlCenter.add(getPointSettingsPanel());
213
                                break;
214 10679 jaume
                        case FShape.LINE:
215 10955 jaume
                                pnlCenter.setLayout(new BorderLayout());
216 10679 jaume
                                pnlCenter.setBorder(BorderFactory.
217
                                                createTitledBorder(null,
218
                                                PluginServices.getText(this, "line_settings")));
219 10955 jaume
                                JPanel aux = new JPanel(
220
                                                new GridLayout(1, 2));
221
                                aux.add(getOrientationPanel());
222
                                aux.add(getPositionPanel());
223
                                pnlCenter.add(aux, BorderLayout.CENTER);
224
                                pnlCenter.add(getLocationPanel(), BorderLayout.SOUTH);
225
226 10679 jaume
                                break;
227
228
                        case FShape.POLYGON:
229
                                pnlCenter.setBorder(BorderFactory.
230
                                                createTitledBorder(null,
231
                                                PluginServices.getText(this, "polygon_settings")));
232 10955 jaume
                                pnlCenter.add(getPolygonSettingsPanel());
233
                                break;
234 10679 jaume
235
                        default:
236
                                break;
237
                        }
238
                }
239
                return pnlCenter;
240
        }
241
242 10955 jaume
        private JPanel getLocationPanel() {
243
                if (locationPanel == null) {
244
                        locationPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
245
                        locationPanel.setBorder(BorderFactory.
246
                                        createTitledBorder(null,
247
                                                        PluginServices.getText(this, "location")));
248
                        locationPanel.add(new JLabel(PluginServices.getText(this, "location_along_the_lines")+":"));
249
                        locationPanel.add(getCmbLocationAlongLines());
250
                }
251
252
                return locationPanel;
253
        }
254
255
        private JComboBox getCmbLocationAlongLines() {
256
                if (cmbLocationAlongLines == null) {
257
                        cmbLocationAlongLines = new JComboBox(new String[] {
258 11195 jaume
                                        PluginServices.getText(this, "in_the_middle"),
259 10955 jaume
                                        PluginServices.getText(this, "at_begin"),
260
                                        PluginServices.getText(this, "at_end"),
261 11195 jaume
                                        PluginServices.getText(this, "at_best"),
262 10955 jaume
                        });
263 11195 jaume
                        cmbLocationAlongLines.setSelectedIndex(0);
264 10955 jaume
                }
265
266
                return cmbLocationAlongLines;
267
        }
268
269
        private GridBagLayoutPanel getPointSettingsPanel() {
270
                if (pointSettingsPanel == null) {
271
                        pointSettingsPanel = new GridBagLayoutPanel();
272
                        pointSettingsPanel.addComponent(getRdOffsetLabelHorizontally());
273
                        JPanel aux = new JPanel();
274
                        aux.add(getStylePreviewer());
275
276
                        JPanel aux2 = new JPanel();
277
                        aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS));
278
                        aux2.add(lblPointPosDesc);
279
                        aux2.add(new JBlank(20, 20));
280
                        aux2.add(getBtnChangeLocation());
281
282
                        aux.add(aux2);
283
                        pointSettingsPanel.addComponent("", aux);
284
                        pointSettingsPanel.addComponent("",
285
                                        new JLabel(PluginServices.getText(this, "label-point-priority-help")));
286
                        pointSettingsPanel.addComponent(getRdOffsetLabelOnTopPoint());
287
                        ButtonGroup group = new ButtonGroup();
288
                        group.add(getRdOffsetLabelHorizontally());
289
                        group.add(getRdOffsetLabelOnTopPoint());
290
                }
291
292
                return pointSettingsPanel;
293
        }
294
295
296
297
        private JButton getBtnChangeLocation() {
298
                if (btnChangeLocation == null) {
299
                        btnChangeLocation = new JButton(PluginServices.getText(this, "change_location"));
300
                        btnChangeLocation.addActionListener(this);
301
                }
302
303
                return btnChangeLocation;
304
        }
305
306
        private StylePreviewer getStylePreviewer() {
307
                if (stylePreview == null) {
308
                        stylePreview = new StylePreviewer();
309
                        stylePreview.setStyle(pointStyle);
310
                        stylePreview.setPreferredSize(new Dimension(80, 80));
311
                }
312
                return stylePreview;
313
        }
314
315
        private JRadioButton getRdOffsetLabelOnTopPoint() {
316
                if (rdBtnOffsetLabelOnTopPoint == null) {
317
                        rdBtnOffsetLabelOnTopPoint = new JRadioButton(
318
                                        PluginServices.getText(this, "offset_labels_on_top_of_the_points"));
319
320
                }
321
322
                return rdBtnOffsetLabelOnTopPoint;
323
        }
324
325
        private JRadioButton getRdOffsetLabelHorizontally() {
326
                if (rdBtnOffsetLabelHorizontally == null) {
327
                        rdBtnOffsetLabelHorizontally = new JRadioButton(
328
                                        PluginServices.getText(this, "offset_labels_horizontally"));
329
330
                }
331
332
                return rdBtnOffsetLabelHorizontally;
333
        }
334
335
        private GridBagLayoutPanel getPolygonSettingsPanel() {
336
                if (polygonSettingsPanel == null) {
337
                        polygonSettingsPanel = new GridBagLayoutPanel();
338
                        JPanel aux = new JPanel();
339
                        aux.setLayout(new BoxLayout(aux, BoxLayout.Y_AXIS));
340
                        aux.add(new JBlank(10,10));
341
                        aux.add(getRdBtnAlwaysHorizontal());
342
                        aux.add(new JBlank(10,10));
343
                        aux.add(getRdBtnAlwaysStraight());
344
                        polygonSettingsPanel.addComponent(getPolygonIcon(), aux);
345
                        ButtonGroup group = new ButtonGroup();
346
                        group.add(getRdBtnAlwaysHorizontal());
347
                        group.add(getRdBtnAlwaysStraight());
348
                        getRdBtnAlwaysHorizontal().setSelected(true);
349
                }
350
351
                return polygonSettingsPanel;
352
        }
353
354
        private JRadioButton getRdBtnAlwaysStraight() {
355
                if (rdBtnAlwaysStraight == null) {
356
                        rdBtnAlwaysStraight = new JRadioButton(
357
                                        PluginServices.getText(this, "always_straight"));
358
                        rdBtnAlwaysStraight.addActionListener(this);
359
                }
360
361
                return rdBtnAlwaysStraight;
362
        }
363
364
        private JRadioButton getRdBtnAlwaysHorizontal() {
365
                if (rdBtnAlwaysHorizontal == null) {
366
                        rdBtnAlwaysHorizontal = new JRadioButton(
367
                                        PluginServices.getText(this, "always_horizontal"));
368
                        rdBtnAlwaysHorizontal.addActionListener(this);
369
                }
370
371
                return rdBtnAlwaysHorizontal;
372
        }
373
374
        private JLabel getPolygonIcon() {
375
                if (polygonIcon == null) {
376
                        polygonIcon = new JLabel(new ImageIcon(
377
                                        getClass().getClassLoader().
378
                                        getResource("images/label-polygon-always-horizontal.png")));
379
                }
380
                return polygonIcon;
381
        }
382
383
        private JLabel getLineIcon() {
384
                if (lineIcon == null) {
385
                        lineIcon = new JLabel(new ImageIcon(
386
                                        getClass().getClassLoader().
387
                                        getResource("images/label-line.png")));
388
                }
389
                return lineIcon;
390
        }
391
392 10679 jaume
        private GridBagLayoutPanel getPositionPanel() {
393
                if (positionPanel == null) {
394
                        positionPanel = new GridBagLayoutPanel();
395
                        positionPanel.setBorder(BorderFactory.
396
                                        createTitledBorder(null,
397
                                                        PluginServices.getText(this, "position")));
398 10955 jaume
                        JPanel aux = new JPanel(new GridLayout(3, 1));
399
                        aux.add(getChkAbove());
400
                        aux.add(getChkOnTheLine());
401
                        aux.add(getChkBelow());
402
                        positionPanel.addComponent(aux, getLineIcon());
403
                        positionPanel.addComponent(
404
                                        PluginServices.getText(this, "orientation_system"), getCmbOrientationSystem());
405 10679 jaume
406
                }
407
                return positionPanel;
408
        }
409
410 10955 jaume
        private JComboBox getCmbOrientationSystem() {
411
                if (cmbOrientationSystem == null) {
412
                        cmbOrientationSystem = new JComboBox(new String[] {
413
                                PluginServices.getText(this, "line"),
414
                                PluginServices.getText(this, "page")
415
                        });
416 11170 jaume
                        cmbOrientationSystem.setSelectedIndex(0);
417 10955 jaume
                }
418
419
                return cmbOrientationSystem;
420
        }
421
422
        private JCheckBox getChkBelow() {
423
                if (chkBelow == null) {
424
                        chkBelow = new JCheckBox(PluginServices.getText(this, "below"));
425
                }
426
                return chkBelow;
427
        }
428
429
        private JCheckBox getChkOnTheLine() {
430
                if (chkOnTheLine == null) {
431
                        chkOnTheLine = new JCheckBox(PluginServices.getText(this, "on_the_line"));
432
                }
433
                return chkOnTheLine;
434
        }
435
436
        private JCheckBox getChkAbove() {
437
                if (chkAbove == null) {
438
                        chkAbove = new JCheckBox(PluginServices.getText(this, "above"));
439
                        chkAbove.setSelected(true);
440
                }
441
                return chkAbove;
442
        }
443
444 10679 jaume
        private GridBagLayoutPanel getOrientationPanel() {
445
                if (orientationPanel == null) {
446
                        orientationPanel = new GridBagLayoutPanel();
447
                        orientationPanel.setBorder(BorderFactory.
448
                                        createTitledBorder(null,
449
                                                        PluginServices.getText(this, "orientation")));
450
                        orientationPanel.addComponent(getRdBtnHorizontal());
451 10955 jaume
                        orientationPanel.addComponent(getRdBtnParallel());
452 10679 jaume
                        orientationPanel.addComponent(getRdBtnFollowingLine());
453
                        orientationPanel.addComponent(getRdBtnPerpendicular());
454
                        ButtonGroup group = new ButtonGroup();
455
                        group.add(getRdBtnHorizontal());
456 10955 jaume
                        group.add(getRdBtnParallel());
457 10679 jaume
                        group.add(getRdBtnFollowingLine());
458
                        group.add(getRdBtnPerpendicular());
459 10955 jaume
                        getRdBtnParallel().setSelected(true);
460
461 10679 jaume
                }
462
                return orientationPanel;
463
        }
464
465 10955 jaume
        private JRadioButton getRdBtnParallel() {
466
                if (rdBtnParallel == null) {
467
                        rdBtnParallel = new JRadioButton(
468 10679 jaume
                                PluginServices.getText(this, "parallel"),
469
                                constraints.isParallel());
470 10955 jaume
471
                        rdBtnParallel.addActionListener(this);
472 10679 jaume
                }
473 10955 jaume
                return rdBtnParallel;
474 10679 jaume
        }
475
476
        private JRadioButton getRdBtnFollowingLine() {
477
                if (rdBtnFollowingLine == null) {
478
                        rdBtnFollowingLine = new JRadioButton(
479
                                PluginServices.getText(this, "following_line"),
480
                                constraints.isFollowingLine());
481 10955 jaume
                        rdBtnFollowingLine.addActionListener(this);
482 10679 jaume
                }
483
                return rdBtnFollowingLine;
484
        }
485
486
        private JRadioButton getRdBtnPerpendicular() {
487
                if (rdBtnPerpendicular == null) {
488
                        rdBtnPerpendicular = new JRadioButton(
489
                                PluginServices.getText(this, "perpedicular"),
490
                                constraints.isPerpendicular());
491 10955 jaume
                        rdBtnPerpendicular.addActionListener(this);
492 10679 jaume
                }
493
                return rdBtnPerpendicular;
494
        }
495
496
        private JRadioButton getRdBtnHorizontal() {
497
                if (rdBtnHorizontal == null) {
498
                        rdBtnHorizontal = new JRadioButton(
499
                                PluginServices.getText(this, "horizontal"),
500
                                constraints.isHorizontal());
501 10955 jaume
                        rdBtnHorizontal.addActionListener(this);
502 10679 jaume
                }
503
                return rdBtnHorizontal;
504
        }
505
506
        private JPanel getPnlSouth() {
507
                if (pnlSouth == null) {
508
                        pnlSouth = new GridBagLayoutPanel();
509
                        pnlSouth.setBorder(BorderFactory.
510
                                        createTitledBorder(null,
511
                                        PluginServices.getText(this, "duplicate_labels")));
512
                        pnlSouth.addComponent(getRdBtnRemoveDuplicates());
513
                        pnlSouth.addComponent(getRdBtnOnePerFeature());
514
                        pnlSouth.addComponent(getRdBtnOnePerFeaturePart());
515
516
                        ButtonGroup group = new ButtonGroup();
517
                        group.add(getRdBtnOnePerFeature());
518
                        group.add(getRdBtnOnePerFeaturePart());
519
                        group.add(getRdBtnRemoveDuplicates());
520
                }
521
                return pnlSouth;
522
        }
523
524
        private JRadioButton getRdBtnOnePerFeaturePart() {
525
                if (rdBtnOnePerFeaturePart == null) {
526
                        rdBtnOnePerFeaturePart = new JRadioButton(
527
                                PluginServices.getText(this, "place_one_label_per_feature_part"),
528
                                constraints.getDuplicateLabelsMode() == IPlacementConstraints.ONE_LABEL_PER_FEATURE_PART);
529
                }
530
                return rdBtnOnePerFeaturePart;
531
        }
532
533
        private JRadioButton getRdBtnOnePerFeature() {
534
                if (rdBtnOnePerFeature == null) {
535
                        rdBtnOnePerFeature = new JRadioButton(
536
                                PluginServices.getText(this, "place_one_label_per_feature"),
537
                                constraints.getDuplicateLabelsMode() == IPlacementConstraints.ONE_LABEL_PER_FEATURE);
538
                }
539
                return rdBtnOnePerFeature;
540
        }
541
542
        private JRadioButton getRdBtnRemoveDuplicates() {
543
                if (rdBtnRemoveDuplicates == null) {
544
                        rdBtnRemoveDuplicates = new JRadioButton(
545
                                PluginServices.getText(this, "remove_duplicate_labels"),
546
                                constraints.getDuplicateLabelsMode() == IPlacementConstraints.REMOVE_DUPLICATE_LABELS);
547 10955 jaume
548 10679 jaume
                }
549
                return rdBtnRemoveDuplicates;
550
        }
551
552
        private void applyConstraints() {
553
                switch (shapeType) {
554
                case FShape.POINT:
555
                        break;
556
                case FShape.LINE:
557
                        int mode;
558
                        if (getRdBtnFollowingLine().isSelected()) {
559
                                mode = IPlacementConstraints.FOLLOWING_LINE;
560 10955 jaume
                        } else if (getRdBtnParallel().isSelected()) {
561 10679 jaume
                                mode = IPlacementConstraints.PARALLEL;
562
                        } else if (getRdBtnPerpendicular().isSelected()) {
563
                                mode = IPlacementConstraints.PERPENDICULAR;
564
                        } else {
565
                                mode = IPlacementConstraints.HORIZONTAL;
566
                        }
567
568
                        constraints.setPlacementMode(mode);
569 11170 jaume
                        constraints.setAboveTheLine(getChkAbove().isSelected());
570
                        constraints.setBellowTheLine(getChkBelow().isSelected());
571 11199 jaume
                        constraints.setOnTheLine(getChkOnTheLine().isSelected());
572 11170 jaume
573 11195 jaume
                        constraints.setPageOriented(
574
                                        getCmbOrientationSystem().getSelectedIndex() == 1);
575
                        int i = getCmbLocationAlongLines().getSelectedIndex();
576
                        if (i == 0) {
577
                                i = IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE;
578
                        } else if (i == 1) {
579
                                i = IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE;
580
                        } else {
581
                                i = IPlacementConstraints.AT_THE_END_OF_THE_LINE;
582
                        }
583
                        constraints.setLocationAlongTheLine(i);
584 10679 jaume
                        break;
585
                case FShape.POLYGON:
586
                        break;
587
                }
588 10955 jaume
        }
589 10679 jaume
590 10955 jaume
        private void setComponentEnabled(Component c, boolean b) {
591
                if (c instanceof JComponent) {
592
                        JComponent c1 = (JComponent) c;
593
                        for (int i = 0; i < c1.getComponentCount(); i++) {
594
                                setComponentEnabled(c1.getComponent(i), b);
595
                        }
596
                }
597
                c.setEnabled(b);
598
        }
599 10679 jaume
600
601
        public IPlacementConstraints getPlacementConstraints() {
602
                return constraints;
603
        }
604
605 10955 jaume
        public void actionPerformed(ActionEvent e) {
606
                JComponent c = (JComponent) e.getSource();
607
                if (c.equals(rdBtnAlwaysHorizontal) || c.equals(rdBtnAlwaysStraight) ) {
608
                        boolean horizontal = rdBtnAlwaysHorizontal.isSelected();
609
                        if (horizontal) {
610
                                getPolygonIcon().setIcon(new ImageIcon(
611
                                                getClass().getClassLoader().
612
                                                getResource("images/label-polygon-always-horizontal.png")));
613
                        } else {
614
                                getPolygonIcon().setIcon(new ImageIcon(
615
                                                getClass().getClassLoader().
616
                                                getResource("images/label-polygon-always-straight.png")));
617
                        }
618
                } else if (c.equals(rdBtnHorizontal)) {
619
                        // lock position panel and location panel
620
                        setComponentEnabled(getPositionPanel(), false);
621
                        setComponentEnabled(getLocationPanel(), false);
622
                } else if (c.equals(rdBtnParallel) || c.equals(rdBtnPerpendicular)) {
623
                        // unlock position panel and location panel but keep orientation system locked
624
                        setComponentEnabled(getLocationPanel(), true);
625
                        setComponentEnabled(getPositionPanel(), true);
626
                        getCmbOrientationSystem().setEnabled(true);
627
                } else if (c.equals(rdBtnFollowingLine)) {
628
                        // lock location panel, unlock position panel, but keep orientation system locked
629
                        setComponentEnabled(getLocationPanel(), false);
630
                        setComponentEnabled(getPositionPanel(), true);
631
                        getCmbOrientationSystem().setEnabled(true);
632
//                } else if (c.equals(rdBtnPerpendicular)) {
633
//                        // unlock location panel and position panel but keep orientation system locked
634
//                        setComponentEnabled(getLocationPanel(), true);
635
//                        setComponentEnabled(getPositionPanel(), true);
636
//                        getCmbOrientationSystem().setEnabled(true);
637
                } else if (c.equals(btnChangeLocation)) {
638
                        StyleSelector stySel = new StyleSelector(
639
                                pointStyle,
640
                                FShape.POINT,  new SelectorFilter() {
641
                                        public boolean accepts(Object obj) {
642
                                                return obj instanceof PointLabelPositioneer;
643
                                        }
644
                                });
645
                        PluginServices.getMDIManager().addWindow(stySel);
646
                        IStyle sty = (IStyle) stySel.getSelectedObject();
647
                        if (sty != null) {
648
                                stylePreview.setStyle(sty);
649
                                lblPointPosDesc.setText(sty.getDescription());
650
                        }
651
                }
652
        }
653
654 10679 jaume
}  //  @jve:decl-index=0:visual-constraint="10,10"