Statistics
| Revision:

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

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

    
101
import java.awt.Color;
102
import java.awt.FlowLayout;
103
import java.awt.GridLayout;
104
import java.awt.event.ActionEvent;
105
import java.awt.event.ActionListener;
106
import java.util.ArrayList;
107

    
108
import javax.swing.BorderFactory;
109
import javax.swing.ButtonGroup;
110
import javax.swing.JComponent;
111
import javax.swing.JLabel;
112
import javax.swing.JPanel;
113
import javax.swing.JRadioButton;
114

    
115
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
116
import org.gvsig.gui.beans.swing.JButton;
117

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

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

    
152
    private void initialize() {
153
        GridLayout layout;
154
        JPanel myTab;
155
        // Marker fill tab
156

    
157
        {
158
                myTab = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
159
                myTab.setName(PluginServices.getText(this, "marker_fill"));
160

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

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

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

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

    
189

    
190

    
191
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
192
            aux.add(rdGrid);
193
            aux.add(rdRandom);
194
            rdGrid.setSelected(true);
195
            p.addComponent("", aux);
196

    
197
            myTab.add(p);
198

    
199
        }
200
        tabs.add(myTab);
201

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

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

    
221
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
222
                aux.add(new JLabel("Y:"));
223
                aux.add(txtOffsetY = new JDecimalField(10));
224
                offsetPnl.add(aux);
225

    
226

    
227

    
228
            }
229
            layout.setRows(offsetPnl.getComponentCount());
230
            offsetPnl.setLayout(layout);
231

    
232
            myTab.add(offsetPnl);
233

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

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

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

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

    
278
                MarkerFillSymbol mfs = (MarkerFillSymbol) layer;
279
                int fillStyle = mfs.getFillStyle();
280
                rdGrid.setSelected(fillStyle == MarkerFillStyle.GRID_FILL);
281
                rdRandom.setSelected(fillStyle == MarkerFillStyle.RANDOM_FILL);
282

    
283
                txtOffsetX.setText(String.valueOf(mfs.getXOffset()));
284
                txtOffsetY.setText(String.valueOf(mfs.getYOffset()));
285

    
286
                txtSeparationX.setText(String.valueOf(mfs.getXSeparation()));
287
                txtSeparationY.setText(String.valueOf(mfs.getYSeparation()));
288
        }
289
    }
290

    
291
    public String getName() {
292
        return PluginServices.getText(this, "marker_fill");
293
    }
294

    
295
    public JPanel[] getTabs() {
296
        return (JPanel[]) tabs.toArray(new JPanel[0]);
297
    }
298

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

    
306
            if (marker == null) return;
307

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

    
330
        fireSymbolChangedEvent();
331
    }
332

    
333
        public Class getSymbolClass() {
334
                return MarkerFillSymbol.class;
335
        }
336

    
337
        public ISymbol getLayer() {
338
                return mfs;
339
        }
340

    
341
        public EditorTool getEditorTool() {
342
                return null;
343
        }
344
}