Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / MarkerFillProperties.java @ 40560

History | View | Annotate | Download (6.5 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.gui.styling;
25

    
26
import java.awt.FlowLayout;
27
import java.awt.GridLayout;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.util.ArrayList;
31

    
32
import javax.swing.BorderFactory;
33
import javax.swing.JLabel;
34
import javax.swing.JPanel;
35

    
36
import org.gvsig.andami.PluginServices;
37
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
38
import org.gvsig.i18n.Messages;
39
import org.gvsig.symbology.SymbologyLocator;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
41

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

    
80
        /**
81
         * Initializes the parameters to create a tab to modify attributes to fill the
82
         * padding of a polygon such offset and separation (between pictures or markers)
83
         *
84
         */
85
        private void initialize() {
86
                GridLayout layout = new GridLayout();
87
                layout.setColumns(1);
88
                layout.setVgap(5);
89
                setName(Messages.getText("fill_properties"));
90
                JPanel offsetPnl = new JPanel();
91
                offsetPnl.setBorder(BorderFactory.
92
                                createTitledBorder(null,
93
                                                Messages.getText("offset")));
94

    
95
                // add components to the offset panel here
96
                {
97
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
98
                        aux.add(new JLabel("X:"));
99
                        aux.add(txtOffsetX = new JIncrementalNumberField("0", 10, 0, 150,1));
100
                        offsetPnl.add(aux);
101

    
102
                        aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
103
                        aux.add(new JLabel("Y:"));
104
                        aux.add(txtOffsetY = new JIncrementalNumberField("0", 10, 0, 150,1));
105
                        offsetPnl.add(aux);
106

    
107

    
108

    
109
                }
110
                layout.setRows(offsetPnl.getComponentCount());
111
                offsetPnl.setLayout(layout);
112

    
113
                add(offsetPnl);
114

    
115
                JPanel separationPnl = new JPanel();
116
                layout = new GridLayout();
117
                layout.setColumns(1);
118
                layout.setVgap(5);
119
                separationPnl.setBorder(BorderFactory.
120
                                createTitledBorder(null,
121
                                                Messages.getText("separation")));
122

    
123
                // add components to the separation panel here
124
                {
125
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
126
                        aux.add(new JLabel("X:"));
127
                        aux.add(txtSeparationX = new JIncrementalNumberField("0", 10,0, 150,1));
128
                        separationPnl.add(aux);
129

    
130
                        aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
131
                        aux.add(new JLabel("Y:"));
132
                        aux.add(txtSeparationY = new JIncrementalNumberField("0", 10, 0, 150,1));
133
                        separationPnl.add(aux);
134
                }
135
                layout.setRows(separationPnl.getComponentCount());
136
                separationPnl.setLayout(layout);
137
                add(separationPnl);
138
                layout = new GridLayout();
139
                layout.setColumns(1);
140
                layout.setVgap(5);
141
                layout.setRows(getComponentCount());
142
                txtOffsetX.setDouble(DEFAULT_OFFSET);
143
                txtOffsetY.setDouble(DEFAULT_OFFSET);
144
                txtSeparationX.setDouble(DEFAULT_SEPARATION);
145
                txtSeparationY.setDouble(DEFAULT_SEPARATION);
146

    
147
                txtOffsetX.addActionListener(action);
148
                txtOffsetY.addActionListener(action);
149
                txtSeparationX.addActionListener(action);
150
                txtSeparationY.addActionListener(action);
151

    
152
                setLayout(layout);
153
        }
154
        /**
155
         * Sets the graphical component that shows the properties of the model.
156
         * @param fillProps,IMarkerFillPropertiesStyle
157
         */
158
        public void setModel(IMarkerFillPropertiesStyle fillProps) {
159
                if (fillProps != null) {
160
                        txtOffsetX.setDouble(fillProps.getXOffset());
161
                        txtOffsetY.setDouble(fillProps.getYOffset());
162
                        txtSeparationX.setDouble(fillProps.getXSeparation());
163
                        txtSeparationY.setDouble(fillProps.getYSeparation());
164
                }
165
        }
166

    
167
        /**
168
         * Obtains the MarkerFillProperties
169
         *
170
         * @return mfProps,IMarkerFillPropertiesStyle
171
         */
172
        public IMarkerFillPropertiesStyle getMarkerFillProperties() {
173
                IMarkerFillPropertiesStyle mfProps = SymbologyLocator.getSymbologyManager().createSimpleMarkerFillPropertiesStyle();
174
                mfProps.setXOffset(txtOffsetX.getDouble());
175
                mfProps.setYOffset(txtOffsetY.getDouble());
176
                mfProps.setXSeparation(txtSeparationX.getDouble());
177
                mfProps.setYSeparation(txtSeparationY.getDouble());
178
                return mfProps;
179
        }
180
        /**
181
         * Permits the good operation of the JIncrementalNumberFields that are included
182
         * in the panel
183
         * @param l,ActionListener
184
         */
185

    
186
        public void addActionListener(ActionListener l) {
187
                listeners.add(l);
188
        }
189

    
190
        public void setEnabled(boolean enabled){
191
                super.setEnabled(enabled);
192
                txtOffsetX.setEnabled(enabled);
193
                txtOffsetY.setEnabled(enabled);
194
                txtSeparationX.setEnabled(enabled);
195
                txtSeparationY.setEnabled(enabled);
196
        }
197
}