Statistics
| Revision:

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

History | View | Annotate | Download (21.2 KB)

1
/*
2
 * Created on 01-jun-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.project.documents.view.legend.gui;
46

    
47
import java.awt.BorderLayout;
48
import java.awt.Component;
49
import java.awt.Dimension;
50
import java.awt.FlowLayout;
51
import java.awt.Font;
52
import java.awt.GridLayout;
53
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionListener;
55
import java.util.ArrayList;
56
import java.util.Hashtable;
57
import java.util.Iterator;
58

    
59
import javax.swing.BorderFactory;
60
import javax.swing.JCheckBox;
61
import javax.swing.JComponent;
62
import javax.swing.JLabel;
63
import javax.swing.JOptionPane;
64
import javax.swing.JPanel;
65
import javax.swing.JTextField;
66

    
67
import org.gvsig.gui.beans.AcceptCancelPanel;
68
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
69
import org.gvsig.gui.beans.swing.JButton;
70

    
71
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
72
import com.hardcode.gdbms.engine.data.driver.DriverException;
73
import com.iver.andami.PluginServices;
74
import com.iver.andami.messages.NotificationManager;
75
import com.iver.andami.ui.mdiManager.IWindow;
76
import com.iver.andami.ui.mdiManager.WindowInfo;
77
import com.iver.cit.gvsig.fmap.core.FShape;
78
import com.iver.cit.gvsig.fmap.core.ILabelable;
79
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
80
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
81
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
82
import com.iver.cit.gvsig.fmap.layers.FLayer;
83
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
84
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingMethod;
85
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingStrategy;
86
import com.iver.cit.gvsig.fmap.rendering.styling.IPlacementConstraints;
87
import com.iver.cit.gvsig.fmap.rendering.styling.IZoomConstraints;
88
import com.iver.cit.gvsig.fmap.rendering.styling.LabelClass;
89
import com.iver.cit.gvsig.fmap.rendering.styling.LabelingFactory;
90
import com.iver.cit.gvsig.gui.styling.LabelStyleSelector;
91
import com.iver.cit.gvsig.gui.styling.SelectorFilter;
92
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer;
93
import com.iver.cit.gvsig.gui.styling.SymbolSelector;
94
import com.iver.cit.gvsig.gui.utils.FontChooser;
95
import com.iver.utiles.swing.JComboBox;
96

    
97
public class LabelingManager extends AbstractThemeManagerPage implements ActionListener {
98
        private static int newClassSuffix = 0;
99
        private static Hashtable methods = new Hashtable();
100
        private static final Font DEFAULT_FONT =
101
                  new Font("SansSerif", Font.PLAIN, 9);
102
        private JCheckBox chkApplyLabels;
103
        private JComboBox cmbMethod;
104
        private GridBagLayoutPanel classesPanel;
105
        private JComboBox cmbClasses;
106
        private JCheckBox chkLabel;
107
        private JButton btnRenameClass;
108
        private JButton btnSQLQuery;
109
        private JButton btnDelClass;
110
        private JButton btnAddClass;
111
        private JComboBox cmbExpressions;
112
        private JButton btnEditExpression;
113
        private SymbolPreviewer previewer;
114
        private JButton btnFont;
115
        protected Font labelFont;
116
        private JButton btnPlacement;
117
        private JButton btnLabelStyles;
118
        private JCheckBox chkTextOnly;
119
        private ILabelable layer;
120
        private JButton btnVisualization;
121
        private ArrayList expressions;
122
        private GridBagLayoutPanel content;
123
        private IPlacementConstraints placementConstraints;
124
        private IZoomConstraints zoomConstraints;
125
        private JButton btnSymbol;
126

    
127
        private class MethodItem {
128
                private String name;
129
                private ILabelingMethod method;
130

    
131
                private MethodItem(String name, ILabelingMethod method) {
132
                        this.name = name;
133
                        this.method = method;
134
                }
135

    
136
                public String toString() {
137
                        return name;
138
                }
139
        }
140

    
141
        private class ExprEditorPanel extends JPanel implements IWindow {
142
                private ActionListener action = new ActionListener() {
143
                        public void actionPerformed(ActionEvent e) {
144
                                if ("OK".equals(e.getActionCommand())) {
145
                                        if (validateExpr())
146
                                                PluginServices.getMDIManager().closeWindow(
147
                                                                ExprEditorPanel.this);
148
                                        else
149
                                                JOptionPane.showMessageDialog(ExprEditorPanel.this,
150
                                                                PluginServices.getText(this, "syntax_error"),
151
                                                                PluginServices.getText(this, "error"),
152
                                                                JOptionPane.ERROR_MESSAGE);
153
                                } else {
154
                                        getTxtExpression().setText(lastExtression);
155
                                        PluginServices.getMDIManager().closeWindow(
156
                                                        ExprEditorPanel.this);
157
                                }
158
                        }
159

    
160

    
161
                };
162
                private JTextField txtExpression;
163
                private String lastExtression;
164

    
165
                public ExprEditorPanel(String currentExpression) {
166
                        super();
167
                        initialize();
168
                        lastExtression = currentExpression;
169
                        getTxtExpression().setText(currentExpression);
170

    
171
                }
172

    
173
                private void initialize() {
174
                        GridBagLayoutPanel content = new GridBagLayoutPanel();
175
                        content.addComponent(new JLabel(" "+PluginServices.getText(this, "label_expression_help")));
176
                        content.addComponent(
177
                                        " "+PluginServices.getText(this, "expression")+":",
178
                                        getTxtExpression());
179
                        setLayout(new BorderLayout(5, 5));
180
                        add(content, BorderLayout.CENTER);
181
                        add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
182
                        setSize(new Dimension(300, 80));
183
                }
184

    
185
                private JTextField getTxtExpression() {
186
                        if (txtExpression == null) {
187
                                txtExpression = new JTextField(25);
188
                        }
189
                        return txtExpression;
190
                }
191

    
192
                public String getExpression() {
193
                        return getTxtExpression().getText();
194
                }
195

    
196
                public WindowInfo getWindowInfo() {
197
                        WindowInfo viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
198
                        viewInfo.setWidth(getWidth());
199
                        viewInfo.setHeight(getHeight());
200
                        viewInfo.setTitle(PluginServices.getText(this,"label_expression_editor"));
201
                        return viewInfo;
202
                }
203

    
204
                private boolean validateExpr() {
205
                        // TODO : implement it
206
                        return true;
207
                }
208
        }
209

    
210
        public LabelingManager() {
211
                super();
212
                initialize();
213
        }
214

    
215
        private void initialize() {
216
                content = new GridBagLayoutPanel();
217
                content.addComponent(getChkApplyLabels());
218
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
219
                aux.add(new JLabel(PluginServices.getText(this, "method")+":"));
220
                aux.add(getCmbMethod());
221
                aux.setPreferredSize(new Dimension(550, 40));
222
                content.addComponent(aux);
223

    
224

    
225
                classesPanel = new GridBagLayoutPanel();
226
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
227
                aux.add(new JLabel(PluginServices.getText(this, "class")+":"));
228
                aux.add(getCmbClasses());
229
                aux.add(getChkLabelFeatures());
230
                aux.setPreferredSize(new Dimension(530, 40));
231
                classesPanel.addComponent(aux);
232

    
233
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
234
                aux.add(getBtnAddClass());
235
                aux.add(getBtnDelClass());
236
                aux.add(getBtnRenameClass());
237
                aux.add(getBtnSQLQuery());
238
                aux.setPreferredSize(new Dimension(530, 30));
239
                classesPanel.addComponent(aux);
240
                classesPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "classes")));
241
                content.addComponent(classesPanel);
242

    
243

    
244
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
245
                aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "text_string")));
246
                aux.add(new JLabel(PluginServices.getText(this, "expression")+":"));
247
                aux.add(getCmbExpressions());
248
                aux.add(getBtnEditExpression());
249
                aux.setPreferredSize(new Dimension(540, 60));
250
                content.addComponent(aux);
251

    
252

    
253
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
254
                aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "text_symbol")));
255
                aux.add(getSymbolPreviewer());
256
                JPanel aux2 = new JPanel();
257
                aux2.add(getBtnFont());
258
                aux2.add(getBtnSymbol());
259

    
260
                aux2.setLayout(new GridLayout(aux2.getComponentCount(), 1));
261
                aux.add(aux2);
262
                content.addComponent(aux);
263

    
264

    
265
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
266
                aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options")));
267
                aux.add(getBtnVisualization());
268
                aux.add(getBtnPlacement());
269
                aux.add(getBtnLabelStyles());
270
                aux.setPreferredSize(new Dimension(540, 60));
271
                content.addComponent(aux);
272
                add(content);
273
        }
274

    
275
        private Component getBtnSymbol() {
276
                if (btnSymbol == null) {
277
                        btnSymbol = new JButton(PluginServices.getText(this, "symbol"));
278
                        btnSymbol.addActionListener(this);
279
                }
280

    
281
                return btnSymbol;
282
        }
283

    
284
        private JCheckBox getChkApplyLabels() {
285
                if (chkApplyLabels == null) {
286
                        chkApplyLabels = new JCheckBox(PluginServices.getText(this, "enable_labelling"));
287
                        chkApplyLabels.addActionListener(this);
288
                }
289
                return chkApplyLabels;
290
        }
291

    
292
        public static void addLabelingMethod(String name, Class iLabelingMethodClass) {
293
                methods.put(name, iLabelingMethodClass);
294
        }
295

    
296
        private JButton getBtnVisualization() {
297
                if (btnVisualization == null) {
298
                        btnVisualization = new JButton(PluginServices.getText(this, "visualization")+"...");
299
                        btnVisualization.addActionListener(this);
300
                }
301
                return btnVisualization;
302
        }
303

    
304
        private JButton getBtnLabelStyles() {
305
                if (btnLabelStyles == null) {
306
                        btnLabelStyles = new JButton(PluginServices.getText(this, "label_styles")+"...");
307
                        btnLabelStyles.addActionListener(this);
308
                }
309
                return btnLabelStyles;
310
        }
311

    
312
        private JButton getBtnPlacement() {
313
                if (btnPlacement == null) {
314
                        btnPlacement = new JButton(PluginServices.getText(this, "placement")+"...");
315
                        btnPlacement.addActionListener(this);
316
                }
317
                return btnPlacement;
318
        }
319

    
320
        private JButton getBtnFont() {
321
                if (btnFont == null) {
322
                        btnFont = new JButton();
323
                        btnFont.setText(PluginServices.getText(this,"fuente")+"...");
324
                        btnFont.addActionListener(this);
325
                }
326
                return btnFont;
327
        }
328

    
329
        private SymbolPreviewer getSymbolPreviewer() {
330
                if (previewer == null) {
331
                        previewer = new SymbolPreviewer();
332
                        previewer.setPreferredSize(new Dimension(420, 65));
333
                }
334
                return previewer;
335
        }
336

    
337
        private JComboBox getCmbMethod() {
338
                if (cmbMethod == null) {
339
                        Iterator it = methods.keySet().iterator();
340
                        ArrayList aux = new ArrayList();
341
                        while (it.hasNext()) {
342
                                String name = (String) it.next();
343

    
344
                                Class methodClass = (Class) methods.get(name);
345
                            ILabelingMethod method;
346
                                try {
347
                                        method = (ILabelingMethod) methodClass.newInstance();
348
                                        MethodItem newItem = new MethodItem(name, method);
349
                                        aux.add(newItem);
350

    
351
                                } catch (InstantiationException e) {
352
                                        NotificationManager.addError("Trying to instantiate an interface" +
353
                                                        " or abstract class + "+methodClass.getName(), e);
354
                                } catch (IllegalAccessException e) {
355
                                        NotificationManager.addError("IllegalAccessException: does " +
356
                                                        methodClass.getName()        + " class have an anonymous" +
357
                                                                        " constructor?", e);
358
                                }
359

    
360
                        }
361
                        cmbMethod = new JComboBox(aux.toArray());
362
                        cmbMethod.setSize(new Dimension(300, 22));
363
                        cmbMethod.addActionListener(this);
364
                }
365
                return cmbMethod;
366
        }
367

    
368
        private JButton getBtnEditExpression() {
369
                if (btnEditExpression == null) {
370
                        btnEditExpression = new JButton(
371
                                        PluginServices.getText(this, "edit_expression")+"...");
372
                        btnEditExpression.addActionListener(this);
373
                }
374
                return btnEditExpression;
375
        }
376

    
377
        private JComboBox getCmbExpressions() {
378
                if (cmbExpressions == null) {
379
                        cmbExpressions = new JComboBox();
380
                        cmbExpressions.setPreferredSize(new Dimension(150, 20));
381
                        cmbExpressions.addActionListener(this);
382
                }
383
                return cmbExpressions;
384

    
385
        }
386

    
387
        private JButton getBtnSQLQuery() {
388
                if (btnSQLQuery == null) {
389
                        btnSQLQuery = new JButton(PluginServices.getText(this, "SQL_query"));
390
                        btnSQLQuery.addActionListener(this);
391
                }
392
                return btnSQLQuery;
393
        }
394

    
395
        private JButton getBtnRenameClass() {
396
                if (btnRenameClass == null) {
397
                        btnRenameClass = new JButton(PluginServices.getText(this, "remane_class"));
398
                        btnRenameClass.addActionListener(this);
399
                }
400
                return btnRenameClass;
401
        }
402

    
403
        private JButton getBtnDelClass() {
404
                if (btnDelClass == null) {
405
                        btnDelClass = new JButton(PluginServices.getText(this, "delete_class"));
406
                        btnDelClass.addActionListener(this);
407
                }
408
                return btnDelClass;
409
        }
410

    
411
        private JButton getBtnAddClass() {
412
                if (btnAddClass == null) {
413
                        btnAddClass = new JButton(PluginServices.getText(this, "add_class"));
414
                        btnAddClass.addActionListener(this);
415
                }
416
                return btnAddClass;
417
        }
418

    
419
        private JCheckBox getChkLabelFeatures() {
420
                if (chkLabel == null) {
421
                        chkLabel = new JCheckBox();
422
                        chkLabel.setText(PluginServices.getText(this, "label_features_in_this_class"));
423
                        chkLabel.addActionListener(this);
424
                }
425
                return chkLabel;
426
        }
427

    
428
        private JComboBox getCmbClasses() {
429
                if (cmbClasses == null) {
430
                        cmbClasses = new JComboBox();
431
                        cmbClasses.setPreferredSize(new Dimension(150, 20));
432
                        cmbClasses.addActionListener(this);
433
                }
434
                return cmbClasses;
435
        }
436

    
437
        private void setComponentEnabled(Component c, boolean b) {
438
                if (c instanceof JComponent) {
439
                        JComponent c1 = (JComponent) c;
440
                        for (int i = 0; i < c1.getComponentCount(); i++) {
441
                                setComponentEnabled(c1.getComponent(i), b);
442
                        }
443
                }
444
                c.setEnabled(b);
445
        }
446

    
447

    
448
        public void setModel(FLayer layer) throws IllegalArgumentException {
449
                if (layer instanceof ILabelable) {
450
                        this.layer = (ILabelable) layer;
451

    
452
                        // get the labeling strategy
453
                        ILabelingStrategy strategy = this.layer.getLabelingStrategy();
454
                        if (strategy == null) {
455
                                // set a new (simplest) one
456
                                try {
457
                                        strategy = LabelingFactory.createDefaultStrategy(layer);
458
                                } catch (ReadDriverException e) {
459
                                        strategy = null;
460
                                }
461
                        }
462
                        if (strategy != null)
463
                                setMethod(strategy.getLabelingMethod());
464
                        setComponentEnabled(this, true);
465
                        refreshControls();
466
                        actionPerformed(new ActionEvent(chkApplyLabels, 0, null));
467
                } else {
468
                        setComponentEnabled(this, false);
469
                }
470
        }
471

    
472
        private void setMethod(ILabelingMethod labelingMethod) {
473
                ArrayList aux = new ArrayList();
474
                for (int i = 0; i < getCmbMethod().getItemCount(); i++) {
475
                        aux.add(((MethodItem) getCmbMethod().getItemAt(i)).method);
476
                }
477
                int i = aux.indexOf(labelingMethod);
478
                if (i == -1)
479
                        i = 0; // index of the simplest method: EquallyLabeled (must be installed)
480
                getCmbMethod().setSelectedIndex(i);
481

    
482

    
483
        }
484

    
485
        private ILabelingMethod getMethod() {
486
                return ((MethodItem) getCmbMethod().getSelectedItem()).method;
487
        }
488

    
489
        private void refreshControls() {
490
                if (layer == null) return;
491

    
492
                // enables labeling
493
                getChkApplyLabels().setSelected(layer.isLabeled());
494

    
495
                // fires an event from the method's combobox
496
                actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
497

    
498
                // expressions combobox
499
                refreshCmbExpressions();
500
        }
501

    
502
        private void refreshCmbExpressions() {
503
                ArrayList exp = getExpressions();
504
                getCmbExpressions().removeAllItems();
505
                for (int i = 0; i < exp.size(); i++)
506
                        getCmbExpressions().addItem(exp.get(i));
507
                LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem();
508
                if (lc != null)
509
                        getCmbExpressions().setSelectedItem(lc.getLabelExpression());
510
        }
511

    
512
        private ArrayList getExpressions() {
513
                if (expressions == null) {
514
                        expressions = new ArrayList();
515
                        try {
516
                                String[] n =  ((FLyrVect) layer).getRecordset().getFieldNames();
517
                                for (int i = 0; i < n.length; i++) {
518
                                        expressions.add("[ "+n[i]+" ]");
519
                                }
520
                        } catch (Exception e) {
521
                                NotificationManager.addError(
522
                                                PluginServices.getText(
523
                                                                this, "could_not_retreive_layer_names"), e);
524
                        }
525
                }
526
                return expressions;
527
        }
528

    
529
        public void actionPerformed(ActionEvent e) {
530
                JComponent c = (JComponent)e.getSource();
531
                if (c.equals(chkApplyLabels)) {
532
                        boolean b = chkApplyLabels.isSelected();
533
                        // enables/disables all components
534
                        for (int i = 0; i < content.getComponentCount(); i++) {
535
                                Component c1 = content.getComponent(i);
536
                                if (!c1.equals(c))
537
                                        setComponentEnabled(c1, b);
538
                        }
539
                        if (b) actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
540

    
541
                } else if (c.equals(btnAddClass)) {
542
                        LabelClass newClass = new LabelClass();
543
                        newClass.setName(PluginServices.getText(this, "labeling")+String.valueOf(++newClassSuffix));
544
                        getMethod().addLabelClass(newClass);
545
                        refreshCmbClasses();
546
                        getCmbClasses().setSelectedItem(newClass);
547
                } else if (c.equals(btnDelClass)) {
548
                        LabelClass clazz = getActiveClass();
549
                        getMethod().deleteLabelClass(clazz);
550
                        refreshCmbClasses();
551
                } else if (c.equals(btnEditExpression)) {
552
                        ExprEditorPanel ep = new ExprEditorPanel((String) getCmbExpressions().
553
                                        getSelectedItem());
554
                        PluginServices.getMDIManager().addWindow( ep );
555
                        getCmbExpressions().addItem(ep.getExpression());
556
                        getCmbExpressions().setSelectedItem(ep.getExpression());
557
                } else if (c.equals(btnFont)) {
558
                        Font newFont = FontChooser.showDialog(PluginServices.getText(this, "font"), labelFont);
559
                if (newFont != null) {
560
                    labelFont = newFont;
561
                }
562

    
563
                } else if (c.equals(btnLabelStyles)) {
564
                        LabelClass clazz = getActiveClass();
565
                        // here open symbol selector
566

    
567
                        LabelStyleSelector stySel = new LabelStyleSelector(
568
                                        clazz.getLabelSymbol(),
569
                                        FShape.TEXT );
570
                        PluginServices.getMDIManager().addWindow(stySel);
571
                        IStyle sty = (IStyle) stySel.getSelectedObject();
572
//                        if (sty != null)
573
//                                // gather the symbol and apply to the class
574
//                                clazz.setSymbol(sty);
575
                } else if (c.equals(btnPlacement)) {
576

    
577
                        try {
578
                                PlacementProperties pp = new PlacementProperties(
579
                                                (FLyrVect) layer,
580
                                                getPlacementConstraints());
581
                                PluginServices.getMDIManager().addWindow(pp);
582
                                placementConstraints = pp.getPlacementConstraints();
583
                        } catch (ClassCastException ccEx) {
584
                                NotificationManager.addError("Placement constraints not prepared for:"
585
                                                +layer.getClass().getName(),
586
                                                ccEx);
587
                        } catch (ReadDriverException dEx) {
588
                                NotificationManager.addWarning("Should be unreachable code", dEx);
589
                                NotificationManager.addError(PluginServices.getText(this, "usupported_layer_type"), dEx);
590
                        }
591

    
592
                } else if (c.equals(btnRenameClass)) {
593
                        LabelClass clazz = getActiveClass();
594
                        String newName = JOptionPane.showInputDialog(
595
                                        PluginServices.getText(this, "enter_new_name"));
596
                        if (newName != null)
597
                                getMethod().renameLabelClass(clazz, newName);
598
                        refreshCmbClasses();
599
                } else if (c.equals(btnSQLQuery)) {
600

    
601
                } else if (c.equals(btnVisualization)) {
602

    
603
                } else if (c.equals(chkLabel)) {
604
                        LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem();
605
                        if (lc == null)
606
                                lc = getMethod().getDefaultLabelClass();
607
                        lc.setVisible(chkLabel.isSelected());
608
                } else if (c.equals(chkTextOnly)) {
609

    
610
                } else if (c.equals(cmbClasses)) {
611
                        // refresh expressions
612
                        LabelClass lc = (LabelClass) cmbClasses.getSelectedItem();
613
                        if (lc != null && !getExpressions().contains(lc.getLabelExpression())) {
614
                                getExpressions().add(0, lc.getLabelExpression());
615
                        }
616
                        refreshCmbExpressions();
617
                } else if (c.equals(cmbExpressions)) {
618
                        LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem();
619
                        if (lc == null)
620
                                lc = getMethod().getDefaultLabelClass();
621
                        lc.setLabelExpression((String) cmbExpressions.getSelectedItem());
622
                } else if (c.equals(cmbMethod)) {
623
                        // disable components in class panel
624
                        // multiple class or not enables or disables the class panel
625
                        setComponentEnabled(classesPanel, getMethod().allowsMultipleClass());
626
                        refreshCmbClasses();
627
                } else if (c.equals(btnSymbol)) {
628
                        LabelClass clazz = getActiveClass();
629
                        // here open symbol selector
630

    
631
                        SymbolSelector symSel = new SymbolSelector(
632
                                        clazz.getLabelSymbol(),
633
                                        FShape.TEXT,
634
                                        new SelectorFilter() {
635
                                                public boolean accepts(Object obj) {
636
                                                        if (obj instanceof ISymbol) {
637
                                                                ISymbol sym = (ISymbol) obj;
638
                                                                return sym.getSymbolType() == FShape.TEXT;
639
                                                        }
640
                                                        return false;
641
                                                }
642
                                        });
643
                        PluginServices.getMDIManager().addWindow(symSel);
644
                        ISymbol sym = (ISymbol) symSel.getSelectedObject();
645
                        if (sym != null)
646
                                // gather the symbol and apply to the class
647
                                clazz.setSymbol((ITextSymbol) symSel.getSelectedObject());
648
                }
649
        }
650

    
651
        private void refreshCmbClasses() {
652
                // label classes
653
                getCmbClasses().removeAllItems();
654
                LabelClass[] lClasses = getMethod().getLabelClasses();
655
                for (int i = 0; i < lClasses.length; i++) {
656
                        getCmbClasses().addItem(lClasses[i]);
657
                }
658

    
659
                refreshCmbExpressions();
660
        }
661

    
662
        private LabelClass getActiveClass() {
663
                return (LabelClass) getCmbClasses().getSelectedItem();
664
        }
665

    
666
        public void acceptAction() {
667

    
668
        }
669

    
670
        public void cancelAction() {
671

    
672
        }
673

    
674
        public void applyAction() {
675
                if (layer != null) { // in other case the layer is not labelable
676
                        layer.setIsLabeled(getChkApplyLabels().isSelected());
677
                        try {
678
                                layer.setLabelingStrategy(
679
                                                LabelingFactory.
680
                                                createStrategy((FLayer) layer,
681
                                                                getMethod(),
682
                                                                getPlacementConstraints(),
683
                                                                getZoomConstraints()));
684
                        } catch (ReadDriverException e) {
685
                                // TODO Auto-generated catch block
686
                                NotificationManager.addError(PluginServices.getText(this, "XXXX"), e);
687
                        }
688
                }
689
        }
690

    
691
        private IZoomConstraints getZoomConstraints() {
692
                return zoomConstraints;
693
        }
694

    
695
        private IPlacementConstraints getPlacementConstraints() {
696
                return placementConstraints;
697
        }
698

    
699
        public String getName() {
700
                return PluginServices.getText(this,"Etiquetados");
701
        }
702
}
703