Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / MarkerFill.java @ 10626

History | View | Annotate | Download (10.4 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 10626 2007-03-06 16:55:54Z caballero $
45
* $Log$
46
* Revision 1.2  2007-03-06 16:35:02  caballero
47
* Exceptions
48
*
49
* Revision 1.1  2007/01/16 11:52:11  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.8  2007/01/10 17:05:05  jaume
53
* moved to FMap and gvSIG
54
*
55
* Revision 1.7  2006/11/13 09:15:23  jaume
56
* javadoc and some clean-up
57
*
58
* Revision 1.6  2006/11/06 16:06:52  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.5  2006/11/02 17:19:28  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.4  2006/10/31 16:16:34  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.3  2006/10/30 19:30:35  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.2  2006/10/29 23:53:49  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.1  2006/10/27 12:41:09  jaume
74
* GUI
75
*
76
*
77
*/
78
package com.iver.cit.gvsig.gui.styling;
79

    
80
import java.awt.Color;
81
import java.awt.FlowLayout;
82
import java.awt.GridLayout;
83
import java.awt.event.ActionEvent;
84
import java.awt.event.ActionListener;
85
import java.util.ArrayList;
86

    
87
import javax.swing.BorderFactory;
88
import javax.swing.ButtonGroup;
89
import javax.swing.JComponent;
90
import javax.swing.JLabel;
91
import javax.swing.JPanel;
92
import javax.swing.JRadioButton;
93

    
94
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
95
import org.gvsig.gui.beans.swing.JButton;
96

    
97
import com.iver.andami.PluginServices;
98
import com.iver.cit.gvsig.fmap.core.FShape;
99
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol;
100
import com.iver.cit.gvsig.fmap.core.symbols.MarkerFillSymbol;
101
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerSymbol;
102
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
103
import com.iver.utiles.XMLEntity;
104

    
105
import de.ios.framework.swing.JDecimalField;
106

    
107
public class MarkerFill extends AbstractTypeSymbolEditorPanel implements ActionListener {
108
    private static final String NAME = PluginServices.
109
    getText(MarkerFill.class, "marker_fill");
110
    private static final double DEFAULT_SEPARATION = 20;
111
    private static final double DEFAULT_OFFSET = 10;
112
    private ArrayList tabs = new ArrayList();
113
    private JDecimalField txtOffsetX;
114
    private JDecimalField txtOffsetY;
115
    private JDecimalField txtSeparationX;
116
    private JDecimalField txtSeparationY;
117
    private ColorChooserPanel markerCC;
118
    private JButton btnChooseMarker;
119
    private JButton btnOutline;
120
    private JRadioButton rdGrid;
121
    private JRadioButton rdRandom;
122
    private MarkerFillSymbol mfs = new MarkerFillSymbol();
123
    public MarkerFill(SymbolEditor owner) {
124
        super(owner);
125
        initialize();
126
    }
127

    
128
    private void initialize() {
129
        GridLayout layout;
130
        JPanel myTab;
131
        // Marker fill tab
132

    
133
        {
134
                myTab = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
135
                myTab.setName(PluginServices.getText(this, "marker_fill"));
136

    
137
                GridBagLayoutPanel p = new GridBagLayoutPanel();
138
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
139
            markerCC = new ColorChooserPanel();
140
            markerCC.setAlpha(255);
141
            markerCC.addActionListener(this);
142
            aux.add(markerCC);
143

    
144
            p.addComponent(PluginServices.getText(this, "color"), aux);
145
            btnChooseMarker = new JButton(PluginServices.getText(this, "choose_marker"));
146
            btnChooseMarker.addActionListener(this);
147
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
148
            aux.add(btnChooseMarker);
149
            p.addComponent("", aux);
150

    
151
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
152
            btnOutline = new JButton(PluginServices.getText(this, "outline"));
153
            aux.add(btnOutline);
154
            btnOutline.setEnabled(false);
155
            p.addComponent("", aux);
156

    
157
            ButtonGroup group = new ButtonGroup();
158
            rdGrid = new JRadioButton(PluginServices.getText(this, "grid"));
159
            rdGrid.addActionListener(this);
160
            rdRandom = new JRadioButton(PluginServices.getText(this, "random"));
161
            rdRandom.addActionListener(this);
162
            group.add(rdGrid);
163
            group.add(rdRandom);
164

    
165

    
166

    
167
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
168
            aux.add(rdGrid);
169
            aux.add(rdRandom);
170

    
171
            p.addComponent("", aux);
172

    
173
            myTab.add(p);
174

    
175
        }
176
        tabs.add(myTab);
177

    
178
        // Fill properties tab
179
        {
180
            layout = new GridLayout();
181
            layout.setColumns(1);
182
            layout.setVgap(5);
183
            myTab = new JPanel();
184
            myTab.setName(PluginServices.getText(this, "fill_properties"));
185
            JPanel offsetPnl = new JPanel();
186
            offsetPnl.setBorder(BorderFactory.
187
                        createTitledBorder(null,
188
                                PluginServices.getText(this, "offset")));
189

    
190
            // add components to the offset panel here
191
            {
192
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
193
                aux.add(new JLabel("X:"));
194
                aux.add(txtOffsetX = new JDecimalField(10));
195
                offsetPnl.add(aux);
196

    
197
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
198
                aux.add(new JLabel("Y:"));
199
                aux.add(txtOffsetY = new JDecimalField(10));
200
                offsetPnl.add(aux);
201

    
202

    
203

    
204
            }
205
            layout.setRows(offsetPnl.getComponentCount());
206
            offsetPnl.setLayout(layout);
207

    
208
            myTab.add(offsetPnl);
209

    
210
            JPanel separationPnl = new JPanel();
211
            layout = new GridLayout();
212
            layout.setColumns(1);
213
            layout.setVgap(5);
214
            separationPnl.setBorder(BorderFactory.
215
                        createTitledBorder(null,
216
                                PluginServices.getText(this, "separation")));
217

    
218
            // add components to the separation panel here
219
            {
220
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
221
                aux.add(new JLabel("X:"));
222
                aux.add(txtSeparationX = new JDecimalField(10));
223
                separationPnl.add(aux);
224

    
225
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
226
                aux.add(new JLabel("Y:"));
227
                aux.add(txtSeparationY = new JDecimalField(10));
228
                separationPnl.add(aux);
229
            }
230
            layout.setRows(separationPnl.getComponentCount());
231
            separationPnl.setLayout(layout);
232
            myTab.add(separationPnl);
233
            layout = new GridLayout();
234
            layout.setColumns(1);
235
            layout.setVgap(5);
236
            layout.setRows(myTab.getComponentCount());
237
            myTab.setLayout(layout);
238
        }
239
       tabs.add(myTab);
240
    }
241

    
242
    public void refreshControls(int layerIndex) {
243
            MultiLayerSymbol sym = owner.getSymbol();
244
        if (sym.getLayer(layerIndex) == null) {
245
                // set defaults
246
                   markerCC.setColor(Color.BLACK);
247
                   rdGrid.setSelected(true);
248
                    rdRandom.setSelected(false);
249
                    txtOffsetX.setText(String.valueOf(DEFAULT_OFFSET));
250
                    txtOffsetY.setText(String.valueOf(DEFAULT_OFFSET));
251
                    txtSeparationX.setText(String.valueOf(DEFAULT_SEPARATION));
252
                    txtSeparationY.setText(String.valueOf(DEFAULT_SEPARATION));
253
        } else {
254
                XMLEntity xml = sym.getLayer(layerIndex).getXMLEntity();
255

    
256
                // TODO este marker color es del MarkerSymbol,
257
                // no del MarkerFill (l'has de buscar dins del fill d'este xmlEntity)
258
//                markerCC.setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
259
                boolean b = xml.getBooleanProperty("grid");
260
                rdGrid.setSelected(b);
261
                rdRandom.setSelected(!b);
262

    
263
                txtOffsetX.setText(String.valueOf(xml.getDoubleProperty("xOffset")));
264
                txtOffsetY.setText(String.valueOf(xml.getDoubleProperty("yOffset")));
265

    
266
                txtSeparationX.setText(String.valueOf(xml.getDoubleProperty("xSeparation")));
267
                txtSeparationY.setText(String.valueOf(xml.getDoubleProperty("ySeparation")));
268
        }
269
    }
270

    
271
    public XMLEntity getXMLEntity() {
272
        return mfs.getXMLEntity();
273
    }
274

    
275
    public String getName() {
276
        return NAME;
277
    }
278

    
279
    public JPanel[] getTabs() {
280
        return (JPanel[]) tabs.toArray(new JPanel[0]);
281
    }
282

    
283
    public void actionPerformed(ActionEvent e) {
284
        JComponent comp = (JComponent) e.getSource();
285
        if (comp.equals(btnChooseMarker)) {
286
            MultiLayerSymbol ownersSymbol =  owner.getSymbol();
287
            SymbolSelector symSelect = new SymbolSelector( ownersSymbol.getLayer(layerIndex), FShape.POINT);
288
            PluginServices.getMDIManager().addWindow(symSelect);
289
            AbstractMarkerSymbol marker = (AbstractMarkerSymbol) symSelect.getSymbol();
290
            mfs.setMarker(marker);
291
        }
292
        try {
293
            mfs.setXOffset(Double.parseDouble(txtOffsetX.getText()));
294
        } catch (Exception ex) {}
295
        try {
296
            mfs.setYOffset(Double.parseDouble(txtOffsetY.getText()));
297
        } catch (Exception ex) {}
298
        try {
299
            mfs.setXSeparation(Double.parseDouble(txtSeparationX.getText()));
300
        } catch (Exception ex) {}
301
        try {
302
            mfs.setYSeparation(Double.parseDouble(txtSeparationY.getText()));
303
        } catch (Exception ex) {}
304
        try {
305
            mfs.setGrid(rdGrid.isSelected());
306
        } catch (Exception ex) {}
307

    
308
        fireSymbolChangedEvent();
309
    }
310

    
311
        public Class getSymbolClass() {
312
                return MarkerFillSymbol.class;
313
        }
314

    
315
}