Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / MarkerFillProperties.java @ 34294

History | View | Annotate | Download (6.75 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
package org.gvsig.app.gui.styling;
42

    
43
import java.awt.FlowLayout;
44
import java.awt.GridLayout;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47
import java.util.ArrayList;
48

    
49
import javax.swing.BorderFactory;
50
import javax.swing.JLabel;
51
import javax.swing.JPanel;
52

    
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
55
import org.gvsig.i18n.Messages;
56
import org.gvsig.symbology.SymbologyLocator;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
58

    
59
/**
60
 * Implements a tab to modify attributes to fill the padding of a polygon
61
 * such offset and separation (between pictures or markers).<p>
62
 * <p>
63
 * This tab is used several times in different places in our applicattion becuase the
64
 * behaviour is the same if the user is filling the padding of a polygon using pictures
65
 * or makers .For this reason, in order to avoid the repetition of code, this class has been
66
 * created (instead of treat it like a simple tab). With this solution, the user
67
 * only has to refer it to use it (and do not need to create a tab and fill it again
68
 * and so on).
69
 *
70
 * @author jaume dominguez faus - jaume.dominguez@iver.es
71
 */
72
public class MarkerFillProperties extends JPanel {
73
        private static final long serialVersionUID = 2873569057822494979L;
74
        private static final double DEFAULT_SEPARATION = 20;
75
        private static final double DEFAULT_OFFSET = 10;
76
        private JIncrementalNumberField txtOffsetX;
77
        private JIncrementalNumberField txtOffsetY;
78
        private JIncrementalNumberField txtSeparationX;
79
        private JIncrementalNumberField txtSeparationY;
80
        private ArrayList<ActionListener> listeners = new ArrayList<ActionListener>();
81
        private ActionListener action = new ActionListener() {
82
                public void actionPerformed(ActionEvent e) {
83
                        for (int i = 0; i < listeners.size(); i++) {
84
                                ((ActionListener) listeners.get(i)).actionPerformed(e);
85
                        }
86
                }
87
        };
88
        /**
89
         * Constructor method
90
         *
91
         */
92
        public MarkerFillProperties() {
93
                super();
94
                initialize();
95
        }
96

    
97
        /**
98
         * Initializes the parameters to create a tab to modify attributes to fill the
99
         * padding of a polygon such offset and separation (between pictures or markers)
100
         *
101
         */
102
        private void initialize() {
103
                GridLayout layout = new GridLayout();
104
                layout.setColumns(1);
105
                layout.setVgap(5);
106
                setName(Messages.getText("fill_properties"));
107
                JPanel offsetPnl = new JPanel();
108
                offsetPnl.setBorder(BorderFactory.
109
                                createTitledBorder(null,
110
                                                Messages.getText("offset")));
111

    
112
                // add components to the offset panel here
113
                {
114
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
115
                        aux.add(new JLabel("X:"));
116
                        aux.add(txtOffsetX = new JIncrementalNumberField("0", 10, 0, 150,1));
117
                        offsetPnl.add(aux);
118

    
119
                        aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
120
                        aux.add(new JLabel("Y:"));
121
                        aux.add(txtOffsetY = new JIncrementalNumberField("0", 10, 0, 150,1));
122
                        offsetPnl.add(aux);
123

    
124

    
125

    
126
                }
127
                layout.setRows(offsetPnl.getComponentCount());
128
                offsetPnl.setLayout(layout);
129

    
130
                add(offsetPnl);
131

    
132
                JPanel separationPnl = new JPanel();
133
                layout = new GridLayout();
134
                layout.setColumns(1);
135
                layout.setVgap(5);
136
                separationPnl.setBorder(BorderFactory.
137
                                createTitledBorder(null,
138
                                                Messages.getText("separation")));
139

    
140
                // add components to the separation panel here
141
                {
142
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
143
                        aux.add(new JLabel("X:"));
144
                        aux.add(txtSeparationX = new JIncrementalNumberField("0", 10,0, 150,1));
145
                        separationPnl.add(aux);
146

    
147
                        aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
148
                        aux.add(new JLabel("Y:"));
149
                        aux.add(txtSeparationY = new JIncrementalNumberField("0", 10, 0, 150,1));
150
                        separationPnl.add(aux);
151
                }
152
                layout.setRows(separationPnl.getComponentCount());
153
                separationPnl.setLayout(layout);
154
                add(separationPnl);
155
                layout = new GridLayout();
156
                layout.setColumns(1);
157
                layout.setVgap(5);
158
                layout.setRows(getComponentCount());
159
                txtOffsetX.setDouble(DEFAULT_OFFSET);
160
                txtOffsetY.setDouble(DEFAULT_OFFSET);
161
                txtSeparationX.setDouble(DEFAULT_SEPARATION);
162
                txtSeparationY.setDouble(DEFAULT_SEPARATION);
163

    
164
                txtOffsetX.addActionListener(action);
165
                txtOffsetY.addActionListener(action);
166
                txtSeparationX.addActionListener(action);
167
                txtSeparationY.addActionListener(action);
168

    
169
                setLayout(layout);
170
        }
171
        /**
172
         * Sets the graphical component that shows the properties of the model.
173
         * @param fillProps,IMarkerFillPropertiesStyle
174
         */
175
        public void setModel(IMarkerFillPropertiesStyle fillProps) {
176
                if (fillProps != null) {
177
                        txtOffsetX.setDouble(fillProps.getXOffset());
178
                        txtOffsetY.setDouble(fillProps.getYOffset());
179
                        txtSeparationX.setDouble(fillProps.getXSeparation());
180
                        txtSeparationY.setDouble(fillProps.getYSeparation());
181
                }
182
        }
183

    
184
        /**
185
         * Obtains the MarkerFillProperties
186
         *
187
         * @return mfProps,IMarkerFillPropertiesStyle
188
         */
189
        public IMarkerFillPropertiesStyle getMarkerFillProperties() {
190
                IMarkerFillPropertiesStyle mfProps = SymbologyLocator.getSymbologyManager().createSimpleMarkerFillPropertiesStyle();
191
                mfProps.setXOffset(txtOffsetX.getDouble());
192
                mfProps.setYOffset(txtOffsetY.getDouble());
193
                mfProps.setXSeparation(txtSeparationX.getDouble());
194
                mfProps.setYSeparation(txtSeparationY.getDouble());
195
                return mfProps;
196
        }
197
        /**
198
         * Permits the good operation of the JIncrementalNumberFields that are included
199
         * in the panel
200
         * @param l,ActionListener
201
         */
202

    
203
        public void addActionListener(ActionListener l) {
204
                listeners.add(l);
205
        }
206

    
207
        public void setEnabled(boolean enabled){
208
                super.setEnabled(enabled);
209
                txtOffsetX.setEnabled(enabled);
210
                txtOffsetY.setEnabled(enabled);
211
                txtSeparationX.setEnabled(enabled);
212
                txtSeparationY.setEnabled(enabled);
213
        }
214
}