Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / view / legend / gui / PanelLegendAnnotation.java @ 28607

History | View | Annotate | Download (9.79 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 javax.swing.JCheckBox;
48

    
49
import com.iver.andami.PluginServices;
50
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
51
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
52
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
53
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
54
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.fmap.layers.LayerEvent;
57
import com.iver.cit.gvsig.fmap.layers.XMLException;
58
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend;
59
import com.iver.cit.gvsig.gui.JComboBoxUnits;
60
import com.iver.cit.gvsig.project.Project;
61

    
62
/**
63
 * Panel legend annotation properties.
64
 *
65
 * @author Vicente Caballero Navarro
66
 */
67
public class PanelLegendAnnotation extends AbstractThemeManagerPage {
68

    
69
        private Annotation_Legend m_Renderer;
70

    
71
        private Annotation_Layer m_lyr;
72

    
73
        private ITextSymbol symbol;
74

    
75
//        private javax.swing.JRadioButton jRadioButton = null;
76
//
77
//        private javax.swing.JRadioButton jRadioButton1 = null;
78

    
79
        private JCheckBox jCheckBoxTextOnly = null;
80

    
81
        private JCheckBox chkDelOverLapping = null;
82

    
83
        private JCheckBox chkAvoidOverLapping = null;
84

    
85
        private JComboBoxUnits cmbUnits;
86

    
87
        /**
88
         * This is the default constructor
89
         */
90
        public PanelLegendAnnotation() {
91
                super();
92
                initialize();
93
        }
94

    
95
        /**
96
         * This method initializes this
97
         *
98
         * @return void
99
         */
100
        private void initialize() {
101
                this.setLayout(null);
102
                this.setSize(454, 308);
103
                this.add(getJCheckBoxTextOnly(), null);
104
//                ButtonGroup jButtonGroup = new ButtonGroup();
105
//                jButtonGroup.add(getJRadioButton1());
106
//                jButtonGroup.add(getJRadioButton());
107

    
108
                this.add(getCmbUnits(),null);
109
//                this.add(getJRadioButton1(), null);
110
//                this.add(getJRadioButton(), null);
111
                this.add(getChkDelOverLapping(), null);
112
                this.add(getChkAvoidOverLapping(), null);
113
        }
114

    
115
//        public void setLayer(FLayer lyr, ILegend r) {
116
//                m_lyr = (Annotation_Layer) lyr;
117
//                m_Renderer = (Annotation_Legend) r;
118
//                getChkAvoidOverLapping().setSelected(((Annotation_Legend)r).isAvoidOverLapping());
119
//                getChkDelOverLapping().setSelected(((Annotation_Legend)r).isDelOverLapping());
120
//                if (r.getDefaultSymbol() instanceof FSymbol)
121
//                        setFSymbol((FSymbol) r.getDefaultSymbol());
122
//                m_lyr.addLayerListener(this);
123
//                if (m_lyr.isEditing()){
124
//                        chkAvoidOverLapping.setVisible(false);
125
//                        chkDelOverLapping.setVisible(false);
126
//                }else{
127
//                        chkAvoidOverLapping.setVisible(true);
128
//                        chkDelOverLapping.setVisible(true);
129
//                }
130
//        }
131

    
132
        public void setFSymbol(ISymbol sym) {
133
                if (sym == null) {
134
                        symbol = SymbologyFactory.createDefaultTextSymbol();
135
                } else
136
                        symbol = (ITextSymbol)sym;
137

    
138

    
139
        }
140
        public JComboBoxUnits getCmbUnits() {
141
                if (cmbUnits == null) {
142
                        cmbUnits = new JComboBoxUnits();
143
                        cmbUnits.setSelectedIndex(Project.getDefaultDistanceUnits());
144
                        cmbUnits.setName("CMBUNITS");
145
                        cmbUnits.setBounds(new java.awt.Rectangle(27,50,303,23));
146
                }
147

    
148
                return cmbUnits;
149
        }
150
        /**
151
         * This method initializes jRadioButton
152
         *
153
         * @return javax.swing.JRadioButton
154
         */
155
//        private javax.swing.JRadioButton getJRadioButton() {
156
//                if (jRadioButton == null) {
157
//                        jRadioButton = new javax.swing.JRadioButton();
158
//                        jRadioButton.setText(PluginServices.getText(this, "En_pixels"));
159
//                        jRadioButton.setBounds(new java.awt.Rectangle(27,50,303,23));
160
//                        jRadioButton.setSelected(true);
161
//                }
162
//                return jRadioButton;
163
//        }
164

    
165
        /**
166
         * This method initializes jRadioButton1
167
         *
168
         * @return javax.swing.JRadioButton
169
         */
170
//        private javax.swing.JRadioButton getJRadioButton1() {
171
//                if (jRadioButton1 == null) {
172
//                        jRadioButton1 = new javax.swing.JRadioButton();
173
//                        jRadioButton1.setText(PluginServices.getText(this, "En_metros"));
174
//                        jRadioButton1.setBounds(new java.awt.Rectangle(27,21,303,23));
175
//                }
176
//                return jRadioButton1;
177
//        }
178
//
179
//        public ILegend getLegend() {
180
//                return m_Renderer;
181
//        }
182

    
183
        /**
184
         * @param renderer
185
         *            The renderer to set.
186
         */
187
//        public void setRenderer(ILegend renderer) {
188
//                this.m_Renderer = (IVectorialLegend) renderer;
189
//                getChkDelOverLapping().setSelected(((Annotation_Legend)renderer).isDelOverLapping());
190
//                getChkAvoidOverLapping().setSelected(((Annotation_Legend)renderer).isAvoidOverLapping());
191
//                if (m_Renderer.getDefaultSymbol() instanceof FSymbol)
192
//                        setFSymbol((FSymbol) m_Renderer.getDefaultSymbol());
193
//        }
194

    
195
        /**
196
         * This method initializes jCheckBox1
197
         *
198
         * @return javax.swing.JCheckBox
199
         */
200
        private JCheckBox getJCheckBoxTextOnly() {
201
                if (jCheckBoxTextOnly == null) {
202
                        jCheckBoxTextOnly = new JCheckBox();
203
                        jCheckBoxTextOnly.setBounds(27, 88, 303, 23);
204
                        jCheckBoxTextOnly.setText(PluginServices.getText(this,
205
                                        "draw_text_only"));
206
                }
207
                return jCheckBoxTextOnly;
208
        }
209

    
210
//        public void updateValuesFromControls(IVectorialLegend l) {
211
//                m_FSymbol.setFontSizeInPixels(jRadioButton.isSelected());
212
//                m_FSymbol.setShapeVisible(!jCheckBoxTextOnly.isSelected());
213
//                ((Annotation_Legend)l).setAvoidOverLapping(chkAvoidOverLapping.isSelected());
214
//                ((Annotation_Legend)l).setDelOverLapping(chkDelOverLapping.isSelected());
215
//                l.setDefaultSymbol(m_FSymbol);
216
//        }
217

    
218
        public void repaint() {
219
                super.repaint();
220
        }
221

    
222
//        public void actualizar() {
223
//                getJRadioButton().setSelected(m_FSymbol.isFontSizeInPixels());
224
//                getJCheckBoxTextOnly().setSelected(!m_FSymbol.isShapeVisible());
225
//        }
226

    
227
        /**
228
         * This method initializes chkOverWrite
229
         *
230
         * @return javax.swing.JCheckBox
231
         */
232
        private JCheckBox getChkDelOverLapping() {
233
                if (chkDelOverLapping == null) {
234
                        chkDelOverLapping = new JCheckBox();
235
                        chkDelOverLapping.setBounds(new java.awt.Rectangle(27,147,303,23));
236
                        chkDelOverLapping.setText(PluginServices.getText(this,"remove_annotation_overlapping"));
237
                        chkDelOverLapping.setSelected(false);
238
                }
239
                return chkDelOverLapping;
240
        }
241

    
242
        /**
243
         * This method initializes chkTryNotOverWrite
244
         *
245
         * @return javax.swing.JCheckBox
246
         */
247
        private JCheckBox getChkAvoidOverLapping() {
248
                if (chkAvoidOverLapping == null) {
249
                        chkAvoidOverLapping = new JCheckBox();
250
                        chkAvoidOverLapping.setBounds(new java.awt.Rectangle(27,116,303,23));
251
                        chkAvoidOverLapping.setText(PluginServices.getText(this,"avoid_overlapping"));
252

    
253
                }
254
                return chkAvoidOverLapping;
255
        }
256

    
257
        public void visibilityChanged(LayerEvent e) {
258
                // TODO Auto-generated method stub
259

    
260
        }
261

    
262
        public void activationChanged(LayerEvent e) {
263
                // TODO Auto-generated method stub
264

    
265
        }
266

    
267
        public void nameChanged(LayerEvent e) {
268
                // TODO Auto-generated method stub
269

    
270
        }
271

    
272
        public void editionChanged(LayerEvent e) {
273
                if (m_lyr ==null)
274
                        return;
275
                if (m_lyr.isEditing()){
276
                        chkAvoidOverLapping.setVisible(false);
277
                        chkDelOverLapping.setVisible(false);
278
                }else{
279
                        chkAvoidOverLapping.setVisible(true);
280
                        chkDelOverLapping.setVisible(true);
281
                }
282

    
283
        }
284

    
285
        public String getName() {
286
                return PluginServices.getText(this,"annotation");
287
        }
288

    
289
        public void acceptAction() {
290
                // TODO Auto-generated method stub
291

    
292
        }
293

    
294
        public void cancelAction() {
295
                // TODO Auto-generated method stub
296

    
297
        }
298

    
299
        public void applyAction() {
300
//                AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
301
//            labeling.setUnit(getCmbUnits().getSelectedUnitIndex());
302
//            m_lyr.setLabelingStrategy(labeling);
303
//                m_Renderer.setFontInPixels(jRadioButton.isSelected());
304
                m_Renderer.setPointVisible(!jCheckBoxTextOnly.isSelected());
305
                m_Renderer.setAvoidOverLapping(chkAvoidOverLapping.isSelected());
306
                m_Renderer.setDelOverLapping(chkDelOverLapping.isSelected());
307
                m_Renderer.setDefaultSymbol(symbol);
308
                m_Renderer.setUnits(getCmbUnits().getSelectedUnitIndex());
309
                try {
310
                        m_lyr.setLegend(m_Renderer);
311
                } catch (LegendLayerException e) {
312
                        e.printStackTrace();
313
                }
314
        }
315

    
316
        public void setModel(FLayer layer) {
317
                m_lyr = (Annotation_Layer) layer;
318
                try {
319
                        m_Renderer = (Annotation_Legend) m_lyr.getLegend().cloneLegend();
320
                } catch (XMLException e) {
321
                        // TODO Auto-generated catch block
322
                        e.printStackTrace();
323
                }
324
                getChkAvoidOverLapping().setSelected(m_Renderer.isAvoidOverLapping());
325
                getChkDelOverLapping().setSelected(m_Renderer.isDelOverLapping());
326
                setFSymbol(m_Renderer.getDefaultSymbol());
327
                getJCheckBoxTextOnly().setSelected(!m_Renderer.isPointVisible());
328
                getCmbUnits().setSelectedUnitIndex(m_Renderer.getUnits());
329
//                if (m_lyr.getLabelingStrategy()!=null){
330
//                        getCmbUnits().setSelectedUnitIndex(((AttrInTableLabelingStrategy)m_lyr.getLabelingStrategy()).getUnit());
331
//                }else{
332
//                        getCmbUnits().setSelectedUnitIndex(-1);
333
//                }
334

    
335
//                getJRadioButton1().setSelected(!m_Renderer.isFontSizeInPixels());
336
//                m_lyr.addLayerListener(this);
337
                if (m_lyr.isEditing()){
338
                        chkAvoidOverLapping.setVisible(false);
339
                        chkDelOverLapping.setVisible(false);
340
                }else{
341
                        chkAvoidOverLapping.setVisible(true);
342
                        chkDelOverLapping.setVisible(true);
343
                }
344
        }
345
}