Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / MarkerFill.java @ 11055

History | View | Annotate | Download (10.9 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: MarkerFill.java 11055 2007-04-04 16:01:14Z jaume $
45
* $Log$
46
* Revision 1.6  2007-04-04 16:01:14  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.5  2007/03/28 16:44:08  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.4  2007/03/13 16:57:35  jaume
53
* Added MultiVariable legend
54
*
55
* Revision 1.3  2007/03/09 11:25:00  jaume
56
* Advanced symbology (start committing)
57
*
58
* Revision 1.1.2.3  2007/02/21 07:35:14  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.1.2.2  2007/02/08 15:43:05  jaume
62
* some bug fixes in the editor and removed unnecessary imports
63
*
64
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1  2007/01/16 11:52:11  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.8  2007/01/10 17:05:05  jaume
71
* moved to FMap and gvSIG
72
*
73
* Revision 1.7  2006/11/13 09:15:23  jaume
74
* javadoc and some clean-up
75
*
76
* Revision 1.6  2006/11/06 16:06:52  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.5  2006/11/02 17:19:28  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.4  2006/10/31 16:16:34  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.3  2006/10/30 19:30:35  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.2  2006/10/29 23:53:49  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.1  2006/10/27 12:41:09  jaume
92
* GUI
93
*
94
*
95
*/
96
package com.iver.cit.gvsig.gui.styling;
97

    
98
import java.awt.Color;
99
import java.awt.FlowLayout;
100
import java.awt.GridLayout;
101
import java.awt.event.ActionEvent;
102
import java.awt.event.ActionListener;
103
import java.util.ArrayList;
104

    
105
import javax.swing.BorderFactory;
106
import javax.swing.ButtonGroup;
107
import javax.swing.JComponent;
108
import javax.swing.JLabel;
109
import javax.swing.JPanel;
110
import javax.swing.JRadioButton;
111

    
112
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
113
import org.gvsig.gui.beans.swing.JButton;
114

    
115
import com.iver.andami.PluginServices;
116
import com.iver.cit.gvsig.fmap.core.FShape;
117
import com.iver.cit.gvsig.fmap.core.styles.MarkerFillStyle;
118
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol;
119
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
120
import com.iver.cit.gvsig.fmap.core.symbols.MarkerFillSymbol;
121
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
122
import com.iver.utiles.XMLEntity;
123

    
124
import de.ios.framework.swing.JDecimalField;
125
/**
126
*
127
* @author jaume dominguez faus - jaume.dominguez@iver.es
128
*
129
*/
130
public class MarkerFill extends AbstractTypeSymbolEditorPanel implements ActionListener {
131
    private static final double DEFAULT_SEPARATION = 20;
132
    private static final double DEFAULT_OFFSET = 10;
133
    private ArrayList tabs = new ArrayList();
134
    private JDecimalField txtOffsetX;
135
    private JDecimalField txtOffsetY;
136
    private JDecimalField txtSeparationX;
137
    private JDecimalField txtSeparationY;
138
    private ColorChooserPanel markerCC;
139
    private JButton btnChooseMarker;
140
    private JButton btnOutline;
141
    private JRadioButton rdGrid;
142
    private JRadioButton rdRandom;
143
    private MarkerFillSymbol mfs = new MarkerFillSymbol();
144
    public MarkerFill(SymbolEditor owner) {
145
        super(owner);
146
        initialize();
147
    }
148

    
149
    private void initialize() {
150
        GridLayout layout;
151
        JPanel myTab;
152
        // Marker fill tab
153

    
154
        {
155
                myTab = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
156
                myTab.setName(PluginServices.getText(this, "marker_fill"));
157

    
158
                GridBagLayoutPanel p = new GridBagLayoutPanel();
159
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
160
            markerCC = new ColorChooserPanel();
161
            markerCC.setAlpha(255);
162
            markerCC.addActionListener(this);
163
            aux.add(markerCC);
164

    
165
            p.addComponent(PluginServices.getText(this, "color"), aux);
166
            btnChooseMarker = new JButton(PluginServices.getText(this, "choose_marker"));
167
            btnChooseMarker.addActionListener(this);
168
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
169
            aux.add(btnChooseMarker);
170
            p.addComponent("", aux);
171

    
172
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
173
            btnOutline = new JButton(PluginServices.getText(this, "outline"));
174
            aux.add(btnOutline);
175
            btnOutline.setEnabled(false);
176
            p.addComponent("", aux);
177

    
178
            ButtonGroup group = new ButtonGroup();
179
            rdGrid = new JRadioButton(PluginServices.getText(this, "grid"));
180
            rdGrid.addActionListener(this);
181
            rdRandom = new JRadioButton(PluginServices.getText(this, "random"));
182
            rdRandom.addActionListener(this);
183
            group.add(rdGrid);
184
            group.add(rdRandom);
185

    
186

    
187

    
188
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
189
            aux.add(rdGrid);
190
            aux.add(rdRandom);
191
            rdGrid.setSelected(true);
192
            p.addComponent("", aux);
193

    
194
            myTab.add(p);
195

    
196
        }
197
        tabs.add(myTab);
198

    
199
        // Fill properties tab
200
        {
201
            layout = new GridLayout();
202
            layout.setColumns(1);
203
            layout.setVgap(5);
204
            myTab = new JPanel();
205
            myTab.setName(PluginServices.getText(this, "fill_properties"));
206
            JPanel offsetPnl = new JPanel();
207
            offsetPnl.setBorder(BorderFactory.
208
                        createTitledBorder(null,
209
                                PluginServices.getText(this, "offset")));
210

    
211
            // add components to the offset panel here
212
            {
213
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
214
                aux.add(new JLabel("X:"));
215
                aux.add(txtOffsetX = new JDecimalField(10));
216
                offsetPnl.add(aux);
217

    
218
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
219
                aux.add(new JLabel("Y:"));
220
                aux.add(txtOffsetY = new JDecimalField(10));
221
                offsetPnl.add(aux);
222

    
223

    
224

    
225
            }
226
            layout.setRows(offsetPnl.getComponentCount());
227
            offsetPnl.setLayout(layout);
228

    
229
            myTab.add(offsetPnl);
230

    
231
            JPanel separationPnl = new JPanel();
232
            layout = new GridLayout();
233
            layout.setColumns(1);
234
            layout.setVgap(5);
235
            separationPnl.setBorder(BorderFactory.
236
                        createTitledBorder(null,
237
                                PluginServices.getText(this, "separation")));
238

    
239
            // add components to the separation panel here
240
            {
241
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
242
                aux.add(new JLabel("X:"));
243
                aux.add(txtSeparationX = new JDecimalField(10));
244
                separationPnl.add(aux);
245

    
246
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
247
                aux.add(new JLabel("Y:"));
248
                aux.add(txtSeparationY = new JDecimalField(10));
249
                separationPnl.add(aux);
250
            }
251
            layout.setRows(separationPnl.getComponentCount());
252
            separationPnl.setLayout(layout);
253
            myTab.add(separationPnl);
254
            layout = new GridLayout();
255
            layout.setColumns(1);
256
            layout.setVgap(5);
257
            layout.setRows(myTab.getComponentCount());
258
            myTab.setLayout(layout);
259
        }
260
       tabs.add(myTab);
261
    }
262

    
263
    public void refreshControls(ISymbol layer) {
264
            if (layer == null) {
265
                // set defaults
266
                   markerCC.setColor(Color.BLACK);
267
                   rdGrid.setSelected(true);
268
                    rdRandom.setSelected(false);
269
                    txtOffsetX.setText(String.valueOf(DEFAULT_OFFSET));
270
                    txtOffsetY.setText(String.valueOf(DEFAULT_OFFSET));
271
                    txtSeparationX.setText(String.valueOf(DEFAULT_SEPARATION));
272
                    txtSeparationY.setText(String.valueOf(DEFAULT_SEPARATION));
273
        } else {
274

    
275
                MarkerFillSymbol mfs = (MarkerFillSymbol) layer;
276
                int fillStyle = mfs.getFillStyle();
277
                rdGrid.setSelected(fillStyle == MarkerFillStyle.GRID_FILL);
278
                rdRandom.setSelected(fillStyle == MarkerFillStyle.RANDOM_FILL);
279

    
280
                txtOffsetX.setText(String.valueOf(mfs.getXOffset()));
281
                txtOffsetY.setText(String.valueOf(mfs.getYOffset()));
282

    
283
                txtSeparationX.setText(String.valueOf(mfs.getXSeparation()));
284
                txtSeparationY.setText(String.valueOf(mfs.getYSeparation()));
285
        }
286
    }
287

    
288
    public String getName() {
289
        return PluginServices.getText(this, "marker_fill");
290
    }
291

    
292
    public JPanel[] getTabs() {
293
        return (JPanel[]) tabs.toArray(new JPanel[0]);
294
    }
295

    
296
    public void actionPerformed(ActionEvent e) {
297
        JComponent comp = (JComponent) e.getSource();
298
        if (comp.equals(btnChooseMarker)) {
299
            SymbolSelector symSelect = new SymbolSelector( getLayer(), FShape.POINT);
300
            PluginServices.getMDIManager().addWindow(symSelect);
301
            AbstractMarkerSymbol marker = (AbstractMarkerSymbol) symSelect.getSelectedObject();
302

    
303
            if (marker == null) return;
304

    
305
            mfs.setMarker(marker);
306
        }
307
        try {
308
            mfs.setXOffset(Double.parseDouble(txtOffsetX.getText()));
309
        } catch (Exception ex) { /* zero will be used */ }
310
        try {
311
            mfs.setYOffset(Double.parseDouble(txtOffsetY.getText()));
312
        } catch (Exception ex) { /* zero will be used */ }
313
        try {
314
            mfs.setXSeparation(Double.parseDouble(txtSeparationX.getText()));
315
        } catch (Exception ex) { /* zero will be used */ }
316
        try {
317
            mfs.setYSeparation(Double.parseDouble(txtSeparationY.getText()));
318
        } catch (Exception ex) { /* zero will be used */ }
319
        int markerFillStyle;
320
        if (rdGrid.isSelected()) {
321
                markerFillStyle = MarkerFillStyle.GRID_FILL;
322
        } else /*if (rdRandom.isSelected() )*/ {
323
                markerFillStyle = MarkerFillStyle.RANDOM_FILL;
324
        }
325
        mfs.setFillStyle(markerFillStyle);
326

    
327
        fireSymbolChangedEvent();
328
    }
329

    
330
        public Class getSymbolClass() {
331
                return MarkerFillSymbol.class;
332
        }
333

    
334
        public ISymbol getLayer() {
335
                return mfs;
336
        }
337

    
338
}