Statistics
| Revision:

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

History | View | Annotate | Download (22 KB)

1
/* 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: PlacementProperties.java 14821 2007-10-22 12:15:26Z jmvivo $
45
* $Log$
46
* Revision 1.7  2007-04-19 14:22:29  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.6  2007/04/13 12:43:08  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.5  2007/04/13 12:10:56  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.4  2007/04/12 16:01:32  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.3  2007/03/28 15:38:56  jaume
59
* GUI for lines, points and polygons
60
*
61
* Revision 1.2  2007/03/09 11:25:00  jaume
62
* Advanced symbology (start committing)
63
*
64
* Revision 1.1.2.2  2007/02/09 11:00:03  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1.2.1  2007/02/01 12:12:41  jaume
68
* theme manager window and all its components are now dynamic
69
*
70
*
71
*/
72
package com.iver.cit.gvsig.project.documents.view.legend.gui;
73

    
74
import java.awt.BorderLayout;
75
import java.awt.Component;
76
import java.awt.Dimension;
77
import java.awt.FlowLayout;
78
import java.awt.GridLayout;
79
import java.awt.event.ActionEvent;
80
import java.awt.event.ActionListener;
81
import java.util.ArrayList;
82

    
83
import javax.swing.BorderFactory;
84
import javax.swing.BoxLayout;
85
import javax.swing.ButtonGroup;
86
import javax.swing.ImageIcon;
87
import javax.swing.JCheckBox;
88
import javax.swing.JComponent;
89
import javax.swing.JLabel;
90
import javax.swing.JPanel;
91
import javax.swing.JRadioButton;
92

    
93
import org.gvsig.gui.beans.AcceptCancelPanel;
94
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
95
import org.gvsig.gui.beans.swing.JBlank;
96
import org.gvsig.gui.beans.swing.JButton;
97

    
98
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
99
import com.iver.andami.PluginServices;
100
import com.iver.andami.ui.mdiManager.IWindow;
101
import com.iver.andami.ui.mdiManager.WindowInfo;
102
import com.iver.cit.gvsig.fmap.core.FShape;
103
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
104
import com.iver.cit.gvsig.fmap.core.styles.PointLabelPositioneer;
105
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
106
import com.iver.cit.gvsig.fmap.rendering.styling.IPlacementConstraints;
107
import com.iver.cit.gvsig.fmap.rendering.styling.LabelingFactory;
108
import com.iver.cit.gvsig.gui.styling.SelectorFilter;
109
import com.iver.cit.gvsig.gui.styling.StylePreviewer;
110
import com.iver.cit.gvsig.gui.styling.StyleSelector;
111
import com.iver.utiles.swing.JComboBox;
112
/**
113
 *
114
 * @author jaume dominguez faus - jaume.dominguez@iver.es
115
 *
116
 */
117
public class PlacementProperties extends JPanel implements IWindow, ActionListener {
118
        private PointLabelPositioneer pointStyle = new PointLabelPositioneer(
119
                        new byte[] { 2, 2, 1, 3, 2, 3, 3, 2        },
120
                        PluginServices.getText(this, "prefer_top_right_all_allowed")
121
                        );
122
        private int shapeType;
123
        private JPanel pnlContent = null;
124
        private JPanel pnlCenter = null;
125
        private GridBagLayoutPanel pnlSouth = null;
126
        private JRadioButton rdBtnRemoveDuplicates;
127
        private IPlacementConstraints constraints;
128
        private JRadioButton rdBtnOnePerFeature;
129
        private JRadioButton rdBtnOnePerFeaturePart;
130
        private GridBagLayoutPanel orientationPanel;
131
        private JRadioButton rdBtnHorizontal;
132
        private JRadioButton rdBtnParallel;
133
        private JRadioButton rdBtnFollowingLine;
134
        private JRadioButton rdBtnPerpendicular;
135
        private GridBagLayoutPanel positionPanel;
136
        private JLabel polygonIcon;
137
        private JLabel lineIcon;
138
        private ArrayList linePositionItem = new ArrayList();
139

    
140
        private ActionListener action = new ActionListener() {
141
                public void actionPerformed(ActionEvent e) {
142
                        if ("OK".equals(e.getActionCommand()))
143
                                applyConstraints();
144

    
145
                        if ("CANCEL".equals(e.getActionCommand()))
146
                                constraints = oldConstraints;
147
                        PluginServices.getMDIManager().closeWindow(PlacementProperties.this);
148
                }
149
        };
150
        private GridBagLayoutPanel polygonSettingsPanel;
151
        private JRadioButton rdBtnAlwaysHorizontal;
152
        private JRadioButton rdBtnAlwaysStraight;
153
        private GridBagLayoutPanel pointSettingsPanel;
154
        private JRadioButton rdBtnOffsetLabelHorizontally;
155
        private JRadioButton rdBtnOffsetLabelOnTopPoint;
156
        private StylePreviewer stylePreview;
157
        private JButton btnChangeLocation;
158
        private JPanel locationPanel;
159
        private JComboBox cmbLocationAlongLines;
160
        private JCheckBox chkBelow;
161
        private JCheckBox chkOnTheLine;
162
        private JCheckBox chkAbove;
163
        private JComboBox cmbOrientationSystem;
164
        private JLabel lblPointPosDesc = new JLabel(pointStyle.getDescription());
165
        private IPlacementConstraints oldConstraints;
166
        private JCheckBox chkFitInsidePolygon;
167

    
168
        public PlacementProperties(FLyrVect layer, IPlacementConstraints constraints) throws ReadDriverException {
169
                this.shapeType = layer.getShapeType();
170
                this.oldConstraints = constraints;
171
                this.constraints = constraints != null ?
172
                                LabelingFactory.createPlacementConstraints(constraints.getXMLEntity())        :
173
                                LabelingFactory.createPlacementConstraints(layer);
174
                initialize();
175
                refreshComponents();
176
        }
177

    
178
        private void refreshComponents() {
179
                getChkOnTheLine().setSelected(constraints.isOnTheLine());
180
                getChkAbove().setSelected(constraints.isAboveTheLine());
181
                getChkBelow().setSelected(constraints.isBellowTheLine());
182

    
183
                getRdBtnHorizontal().setSelected(constraints.isHorizontal());
184
                getRdBtnParallel().setSelected(constraints.isParallel());
185
                getRdBtnFollowingLine().setSelected(constraints.isFollowingLine());
186
                getRdBtnPerpendicular().setSelected(constraints.isPerpendicular());
187

    
188
                getCmbOrientationSystem().setSelectedIndex(constraints.isPageOriented() ? 1 : 0);
189

    
190
                // points mode
191
                if (constraints.isOnTopOfThePoint()) {
192
                        getRdOffsetLabelOnTopPoint().setSelected(true);
193
                } else if (constraints.isAroundThePoint()) {
194
                        getRdOffsetLabelHorizontally().setSelected(true);
195
                }
196

    
197
                // lines mode
198
                if (constraints.isAtTheBeginingOfLine()) {
199
                        getCmbLocationAlongLines().setSelectedIndex(1);
200
                } else if (constraints.isInTheMiddleOfLine()) {
201
                        getCmbLocationAlongLines().setSelectedIndex(0);
202
                } else if (constraints.isAtTheEndOfLine()) {
203
                        getCmbLocationAlongLines().setSelectedIndex(2);
204
                }
205

    
206
                // polygon mode
207
                getChkFitInsidePolygon().setSelected(constraints.isFitInsidePolygon());
208
                if (constraints.isHorizontal()) {
209
                        getRdBtnAlwaysHorizontal().setSelected(true);
210
                } else if (constraints.isParallel()) {
211
                        getRdBtnAlwaysStraight().setSelected(true);
212
                }
213

    
214
        }
215

    
216
        private void initialize() {
217
                linePositionItem.add(PluginServices.getText(this, "in_the_middle"));
218
                linePositionItem.add(PluginServices.getText(this, "at_begin"));
219
                linePositionItem.add(PluginServices.getText(this, "at_end"));
220
                linePositionItem.add(PluginServices.getText(this, "at_best"));
221

    
222
        this.setLayout(new BorderLayout());
223
        this.setSize(new Dimension(410,380));
224
        this.add(getPnlContent(), BorderLayout.CENTER);
225
        this.add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
226
        }
227

    
228
        public WindowInfo getWindowInfo() {
229
                WindowInfo viewInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
230
                viewInfo.setWidth(getWidth());
231
                viewInfo.setHeight(getHeight());
232
                viewInfo.setTitle(PluginServices.getText(this,"placement_properties"));
233
                return viewInfo;
234
        }
235

    
236
        private JPanel getPnlContent() {
237
                if (pnlContent == null) {
238
                        pnlContent = new JPanel();
239
                        pnlContent.setLayout(new BorderLayout());
240
                        pnlContent.add(getPnlCenter(), java.awt.BorderLayout.CENTER);
241
                        pnlContent.add(getPnlSouth(), java.awt.BorderLayout.SOUTH);
242
                }
243
                return pnlContent;
244
        }
245

    
246
        private JPanel getPnlCenter() {
247
                if (pnlCenter == null) {
248
                        pnlCenter = new JPanel();
249
                        switch (shapeType) {
250
                        case FShape.POINT:
251
                                pnlCenter.setBorder(BorderFactory.
252
                                                createTitledBorder(null,
253
                                                PluginServices.getText(this, "point_settings")));
254
                                pnlCenter.add(getPointSettingsPanel());
255
                                break;
256
                        case FShape.LINE:
257
                                pnlCenter.setLayout(new BorderLayout());
258
                                pnlCenter.setBorder(BorderFactory.
259
                                                createTitledBorder(null,
260
                                                PluginServices.getText(this, "line_settings")));
261
                                JPanel aux = new JPanel(
262
                                                new GridLayout(1, 2));
263
                                aux.add(getOrientationPanel());
264
                                aux.add(getPositionPanel());
265
                                pnlCenter.add(aux, BorderLayout.CENTER);
266
                                pnlCenter.add(getLocationPanel(), BorderLayout.SOUTH);
267

    
268
                                break;
269

    
270
                        case FShape.POLYGON:
271
                                pnlCenter.setBorder(BorderFactory.
272
                                                createTitledBorder(null,
273
                                                PluginServices.getText(this, "polygon_settings")));
274
                                pnlCenter.add(getPolygonSettingsPanel());
275
                                break;
276

    
277
                        default:
278
                                break;
279
                        }
280
                }
281
                return pnlCenter;
282
        }
283

    
284
        private JPanel getLocationPanel() {
285
                if (locationPanel == null) {
286
                        locationPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
287
                        locationPanel.setBorder(BorderFactory.
288
                                        createTitledBorder(null,
289
                                                        PluginServices.getText(this, "location")));
290
                        locationPanel.add(new JLabel(PluginServices.getText(this, "location_along_the_lines")+":"));
291
                        locationPanel.add(getCmbLocationAlongLines());
292
                }
293

    
294
                return locationPanel;
295
        }
296

    
297
        private JComboBox getCmbLocationAlongLines() {
298
                if (cmbLocationAlongLines == null) {
299
                        cmbLocationAlongLines = new JComboBox((String[]) linePositionItem.toArray(new String[linePositionItem.size()]));
300

    
301
                }
302

    
303
                return cmbLocationAlongLines;
304
        }
305

    
306
        private GridBagLayoutPanel getPointSettingsPanel() {
307
                if (pointSettingsPanel == null) {
308
                        pointSettingsPanel = new GridBagLayoutPanel();
309
                        pointSettingsPanel.addComponent(getRdOffsetLabelHorizontally());
310
                        JPanel aux = new JPanel();
311
                        aux.add(getStylePreviewer());
312

    
313
                        JPanel aux2 = new JPanel();
314
                        aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS));
315
                        aux2.add(lblPointPosDesc);
316
                        aux2.add(new JBlank(20, 20));
317
                        aux2.add(getBtnChangeLocation());
318

    
319
                        aux.add(aux2);
320
                        pointSettingsPanel.addComponent("", aux);
321
                        pointSettingsPanel.addComponent("",
322
                                        new JLabel(PluginServices.getText(this, "label-point-priority-help")));
323
                        pointSettingsPanel.addComponent(getRdOffsetLabelOnTopPoint());
324
                        ButtonGroup group = new ButtonGroup();
325
                        group.add(getRdOffsetLabelHorizontally());
326
                        group.add(getRdOffsetLabelOnTopPoint());
327
                }
328

    
329
                return pointSettingsPanel;
330
        }
331

    
332

    
333

    
334
        private JButton getBtnChangeLocation() {
335
                if (btnChangeLocation == null) {
336
                        btnChangeLocation = new JButton(PluginServices.getText(this, "change_location"));
337
                        btnChangeLocation.addActionListener(this);
338
                }
339

    
340
                return btnChangeLocation;
341
        }
342

    
343
        private StylePreviewer getStylePreviewer() {
344
                if (stylePreview == null) {
345
                        stylePreview = new StylePreviewer();
346
                        stylePreview.setStyle(pointStyle);
347
                        stylePreview.setPreferredSize(new Dimension(80, 80));
348
                }
349
                return stylePreview;
350
        }
351

    
352
        private JRadioButton getRdOffsetLabelOnTopPoint() {
353
                if (rdBtnOffsetLabelOnTopPoint == null) {
354
                        rdBtnOffsetLabelOnTopPoint = new JRadioButton(
355
                                        PluginServices.getText(this, "offset_labels_on_top_of_the_points"));
356

    
357
                }
358

    
359
                return rdBtnOffsetLabelOnTopPoint;
360
        }
361

    
362
        private JRadioButton getRdOffsetLabelHorizontally() {
363
                if (rdBtnOffsetLabelHorizontally == null) {
364
                        rdBtnOffsetLabelHorizontally = new JRadioButton(
365
                                        PluginServices.getText(this, "offset_labels_horizontally"));
366

    
367
                }
368

    
369
                return rdBtnOffsetLabelHorizontally;
370
        }
371

    
372
        private GridBagLayoutPanel getPolygonSettingsPanel() {
373
                if (polygonSettingsPanel == null) {
374
                        polygonSettingsPanel = new GridBagLayoutPanel();
375
                        JPanel aux = new JPanel();
376
                        aux.setLayout(new BoxLayout(aux, BoxLayout.Y_AXIS));
377
                        aux.add(new JBlank(10,10));
378
                        aux.add(getRdBtnAlwaysHorizontal());
379
                        aux.add(new JBlank(10,10));
380
                        aux.add(getRdBtnAlwaysStraight());
381
                        polygonSettingsPanel.addComponent(getPolygonIcon(), aux);
382
                        ButtonGroup group = new ButtonGroup();
383
                        group.add(getRdBtnAlwaysHorizontal());
384
                        group.add(getRdBtnAlwaysStraight());
385
                        polygonSettingsPanel.addComponent(new JBlank(20, 30));
386
                        polygonSettingsPanel.addComponent(getChkFitInsidePolygon());
387
                }
388

    
389
                return polygonSettingsPanel;
390
        }
391

    
392
        private JCheckBox getChkFitInsidePolygon() {
393
                if (chkFitInsidePolygon == null) {
394
                        chkFitInsidePolygon = new JCheckBox(PluginServices.getText(this, "fit_inside_polygon"));
395

    
396
                }
397

    
398
                return chkFitInsidePolygon;
399
        }
400

    
401
        private JRadioButton getRdBtnAlwaysStraight() {
402
                if (rdBtnAlwaysStraight == null) {
403
                        rdBtnAlwaysStraight = new JRadioButton(
404
                                        PluginServices.getText(this, "always_straight"));
405
                        rdBtnAlwaysStraight.addActionListener(this);
406
                }
407

    
408
                return rdBtnAlwaysStraight;
409
        }
410

    
411
        private JRadioButton getRdBtnAlwaysHorizontal() {
412
                if (rdBtnAlwaysHorizontal == null) {
413
                        rdBtnAlwaysHorizontal = new JRadioButton(
414
                                        PluginServices.getText(this, "always_horizontal"));
415
                        rdBtnAlwaysHorizontal.addActionListener(this);
416
                }
417

    
418
                return rdBtnAlwaysHorizontal;
419
        }
420

    
421
        private JLabel getPolygonIcon() {
422
                if (polygonIcon == null) {
423
                        polygonIcon = new JLabel(PluginServices.getIconTheme().get("polygon-al-h-label"));
424
                }
425
                return polygonIcon;
426
        }
427

    
428
        private JLabel getLineIcon() {
429
                if (lineIcon == null) {
430
                        lineIcon = new JLabel(PluginServices.getIconTheme().get("line-label"));
431
                }
432
                return lineIcon;
433
        }
434

    
435
        private GridBagLayoutPanel getPositionPanel() {
436
                if (positionPanel == null) {
437
                        positionPanel = new GridBagLayoutPanel();
438
                        positionPanel.setBorder(BorderFactory.
439
                                        createTitledBorder(null,
440
                                                        PluginServices.getText(this, "position")));
441
                        JPanel aux = new JPanel(new GridLayout(3, 1));
442
                        aux.add(getChkAbove());
443
                        aux.add(getChkOnTheLine());
444
                        aux.add(getChkBelow());
445
                        positionPanel.addComponent(aux, getLineIcon());
446
                        positionPanel.addComponent(
447
                                        PluginServices.getText(this, "orientation_system"), getCmbOrientationSystem());
448

    
449
                }
450
                return positionPanel;
451
        }
452

    
453
        private JComboBox getCmbOrientationSystem() {
454
                if (cmbOrientationSystem == null) {
455
                        cmbOrientationSystem = new JComboBox(new String[] {
456
                                PluginServices.getText(this, "line"),
457
                                PluginServices.getText(this, "page")
458
                        });
459
                        cmbOrientationSystem.setSelectedIndex(0);
460
                }
461

    
462
                return cmbOrientationSystem;
463
        }
464

    
465
        private JCheckBox getChkBelow() {
466
                if (chkBelow == null) {
467
                        chkBelow = new JCheckBox(PluginServices.getText(this, "below"));
468
                }
469
                return chkBelow;
470
        }
471

    
472
        private JCheckBox getChkOnTheLine() {
473
                if (chkOnTheLine == null) {
474
                        chkOnTheLine = new JCheckBox(PluginServices.getText(this, "on_the_line"));
475
                }
476
                return chkOnTheLine;
477
        }
478

    
479
        private JCheckBox getChkAbove() {
480
                if (chkAbove == null) {
481
                        chkAbove = new JCheckBox(PluginServices.getText(this, "above"));
482
                }
483
                return chkAbove;
484
        }
485

    
486
        private GridBagLayoutPanel getOrientationPanel() {
487
                if (orientationPanel == null) {
488
                        orientationPanel = new GridBagLayoutPanel();
489
                        orientationPanel.setBorder(BorderFactory.
490
                                        createTitledBorder(null,
491
                                                        PluginServices.getText(this, "orientation")));
492
                        orientationPanel.addComponent(getRdBtnHorizontal());
493
                        orientationPanel.addComponent(getRdBtnParallel());
494
                        orientationPanel.addComponent(getRdBtnFollowingLine());
495
                        orientationPanel.addComponent(getRdBtnPerpendicular());
496
                        ButtonGroup group = new ButtonGroup();
497
                        group.add(getRdBtnHorizontal());
498
                        group.add(getRdBtnParallel());
499
                        group.add(getRdBtnFollowingLine());
500
                        group.add(getRdBtnPerpendicular());
501

    
502

    
503

    
504
                }
505
                return orientationPanel;
506
        }
507

    
508
        private JRadioButton getRdBtnParallel() {
509
                if (rdBtnParallel == null) {
510
                        rdBtnParallel = new JRadioButton(
511
                                PluginServices.getText(this, "parallel"));
512

    
513
                        rdBtnParallel.addActionListener(this);
514
                }
515
                return rdBtnParallel;
516
        }
517

    
518
        private JRadioButton getRdBtnFollowingLine() {
519
                if (rdBtnFollowingLine == null) {
520
                        rdBtnFollowingLine = new JRadioButton(
521
                                PluginServices.getText(this, "following_line"));
522
                        rdBtnFollowingLine.addActionListener(this);
523
                }
524
                return rdBtnFollowingLine;
525
        }
526

    
527
        private JRadioButton getRdBtnPerpendicular() {
528
                if (rdBtnPerpendicular == null) {
529
                        rdBtnPerpendicular = new JRadioButton(
530
                                PluginServices.getText(this, "perpedicular"));
531
                        rdBtnPerpendicular.addActionListener(this);
532
                }
533
                return rdBtnPerpendicular;
534
        }
535

    
536
        private JRadioButton getRdBtnHorizontal() {
537
                if (rdBtnHorizontal == null) {
538
                        rdBtnHorizontal = new JRadioButton(
539
                                PluginServices.getText(this, "horizontal"));
540
                        rdBtnHorizontal.addActionListener(this);
541
                }
542
                return rdBtnHorizontal;
543
        }
544

    
545
        private JPanel getPnlSouth() {
546
                if (pnlSouth == null) {
547
                        pnlSouth = new GridBagLayoutPanel();
548
                        pnlSouth.setBorder(BorderFactory.
549
                                        createTitledBorder(null,
550
                                        PluginServices.getText(this, "duplicate_labels")));
551
                        pnlSouth.addComponent(getRdBtnRemoveDuplicates());
552
                        pnlSouth.addComponent(getRdBtnOnePerFeature());
553
                        pnlSouth.addComponent(getRdBtnOnePerFeaturePart());
554

    
555
                        ButtonGroup group = new ButtonGroup();
556
                        group.add(getRdBtnOnePerFeature());
557
                        group.add(getRdBtnOnePerFeaturePart());
558
                        group.add(getRdBtnRemoveDuplicates());
559
                }
560
                return pnlSouth;
561
        }
562

    
563
        private JRadioButton getRdBtnOnePerFeaturePart() {
564
                if (rdBtnOnePerFeaturePart == null) {
565
                        rdBtnOnePerFeaturePart = new JRadioButton(
566
                                PluginServices.getText(this, "place_one_label_per_feature_part"),
567
                                constraints.getDuplicateLabelsMode() == IPlacementConstraints.ONE_LABEL_PER_FEATURE_PART);
568
                }
569
                return rdBtnOnePerFeaturePart;
570
        }
571

    
572
        private JRadioButton getRdBtnOnePerFeature() {
573
                if (rdBtnOnePerFeature == null) {
574
                        rdBtnOnePerFeature = new JRadioButton(
575
                                PluginServices.getText(this, "place_one_label_per_feature"),
576
                                constraints.getDuplicateLabelsMode() == IPlacementConstraints.ONE_LABEL_PER_FEATURE);
577
                }
578
                return rdBtnOnePerFeature;
579
        }
580

    
581
        private JRadioButton getRdBtnRemoveDuplicates() {
582
                if (rdBtnRemoveDuplicates == null) {
583
                        rdBtnRemoveDuplicates = new JRadioButton(
584
                                PluginServices.getText(this, "remove_duplicate_labels"),
585
                                constraints.getDuplicateLabelsMode() == IPlacementConstraints.REMOVE_DUPLICATE_LABELS);
586

    
587
                }
588
                return rdBtnRemoveDuplicates;
589
        }
590

    
591
        private void applyConstraints() {
592
                int mode=0;
593

    
594
                switch (shapeType) {
595
                case FShape.POINT:
596
                        if (getRdOffsetLabelOnTopPoint().isSelected()) {
597
                                mode = IPlacementConstraints.ON_TOP_OF_THE_POINT;
598
                        } else if (getRdOffsetLabelHorizontally().isSelected()) {
599
                                mode = IPlacementConstraints.OFFSET_HORIZONTALY_AROUND_THE_POINT;
600
                        }
601
                        break;
602
                case FShape.LINE:
603
                        if (getRdBtnFollowingLine().isSelected()) {
604
                                mode = IPlacementConstraints.FOLLOWING_LINE;
605
                        } else if (getRdBtnParallel().isSelected()) {
606
                                mode = IPlacementConstraints.PARALLEL;
607
                        } else if (getRdBtnPerpendicular().isSelected()) {
608
                                mode = IPlacementConstraints.PERPENDICULAR;
609
                        } else {
610
                                mode = IPlacementConstraints.HORIZONTAL;
611
                        }
612

    
613
                        constraints.setAboveTheLine(getChkAbove().isSelected());
614
                        constraints.setBellowTheLine(getChkBelow().isSelected());
615
                        constraints.setOnTheLine(getChkOnTheLine().isSelected());
616

    
617
                        constraints.setPageOriented(
618
                                        getCmbOrientationSystem().getSelectedIndex() == 1);
619
                        int i = getCmbLocationAlongLines().getSelectedIndex();
620
                        if (i == 0) {
621
                                i = IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE;
622
                        } else if (i == 1) {
623
                                i = IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE;
624
                        } else if (i == 2){
625
                                i = IPlacementConstraints.AT_THE_END_OF_THE_LINE;
626
                        }
627
                        constraints.setLocationAlongTheLine(i);
628
                        break;
629
                case FShape.POLYGON:
630
                        if (getRdBtnAlwaysHorizontal().isSelected()) {
631
                                mode = IPlacementConstraints.HORIZONTAL;
632
                        } else if (getRdBtnAlwaysStraight().isSelected()) {
633
                                mode = IPlacementConstraints.PARALLEL;
634
                        }
635

    
636
                        constraints.setFitInsidePolygon(getChkFitInsidePolygon().isSelected());
637
                        break;
638
                }
639
                constraints.setPlacementMode(mode);
640
        }
641

    
642
        private void setComponentEnabled(Component c, boolean b) {
643
                if (c instanceof JComponent) {
644
                        JComponent c1 = (JComponent) c;
645
                        for (int i = 0; i < c1.getComponentCount(); i++) {
646
                                setComponentEnabled(c1.getComponent(i), b);
647
                        }
648
                }
649
                c.setEnabled(b);
650
        }
651

    
652

    
653
        public IPlacementConstraints getPlacementConstraints() {
654
                return constraints;
655
        }
656

    
657
        public void actionPerformed(ActionEvent e) {
658
                JComponent c = (JComponent) e.getSource();
659
                if (c.equals(rdBtnAlwaysHorizontal) || c.equals(rdBtnAlwaysStraight) ) {
660
                        boolean horizontal = rdBtnAlwaysHorizontal.isSelected();
661
                        if (horizontal) {
662
                                getPolygonIcon().setIcon(PluginServices.getIconTheme()
663
                                                .get("polygon-al-h-label"));
664
                        } else {
665
                                getPolygonIcon().setIcon(PluginServices.getIconTheme()        
666
                                                .get("polygon-al-s-label"));
667
                        }
668
                } else if (c.equals(rdBtnHorizontal)) {
669
                        // lock position panel and location panel
670
                        setComponentEnabled(getPositionPanel(), false);
671
                        setComponentEnabled(getLocationPanel(), false);
672
                } else if (c.equals(rdBtnParallel) || c.equals(rdBtnPerpendicular)) {
673
                        // unlock position panel and location panel but keep orientation system locked
674
                        setComponentEnabled(getLocationPanel(), true);
675
                        setComponentEnabled(getPositionPanel(), true);
676
                        getCmbOrientationSystem().setEnabled(true);
677
                } else if (c.equals(rdBtnFollowingLine)) {
678
                        // lock location panel, unlock position panel, but keep orientation system locked
679
                        setComponentEnabled(getLocationPanel(), false);
680
                        setComponentEnabled(getPositionPanel(), true);
681
                        getCmbOrientationSystem().setEnabled(true);
682
//                } else if (c.equals(rdBtnPerpendicular)) {
683
//                        // unlock location panel and position panel but keep orientation system locked
684
//                        setComponentEnabled(getLocationPanel(), true);
685
//                        setComponentEnabled(getPositionPanel(), true);
686
//                        getCmbOrientationSystem().setEnabled(true);
687
                } else if (c.equals(btnChangeLocation)) {
688
                        StyleSelector stySel = new StyleSelector(
689
                                pointStyle,
690
                                FShape.POINT,  new SelectorFilter() {
691
                                        public boolean accepts(Object obj) {
692
                                                return obj instanceof PointLabelPositioneer;
693
                                        }
694
                                });
695
                        PluginServices.getMDIManager().addWindow(stySel);
696
                        IStyle sty = (IStyle) stySel.getSelectedObject();
697
                        if (sty != null) {
698
                                stylePreview.setStyle(sty);
699
                                lblPointPosDesc.setText(sty.getDescription());
700
                        }
701
                }
702
        }
703

    
704
}  //  @jve:decl-index=0:visual-constraint="10,10"