Statistics
| Revision:

svn-gvsig-desktop / 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 / SimpleText.java @ 34291

History | View | Annotate | Download (7.04 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.util.ArrayList;
46

    
47
import javax.swing.JLabel;
48
import javax.swing.JPanel;
49
import javax.swing.JToggleButton;
50

    
51
import org.gvsig.andami.PluginServices;
52
import org.gvsig.app.gui.panels.ColorChooserPanel;
53
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
54
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
55
import org.gvsig.gui.beans.swing.JComboBoxFontSizes;
56
import org.gvsig.gui.beans.swing.JComboBoxFonts;
57
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
58
import org.gvsig.i18n.Messages;
59
import org.gvsig.symbology.SymbologyLocator;
60
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol;
61

    
62

    
63
/**
64
 * SimpleText allows the user to store and modify the main properties that define a <b>simple text</b>.<p>
65
 * <p>
66
 * This functionality is carried out thanks to three tabs (text, formatted, advanced)
67
 * and a Mask which are included in the panel to edit the properities of a symbol
68
 * (SymbolEditor)how is explained in AbstractTypeSymbolEditor.<p>
69
 * <p>
70
 * The first tab (text)allows the user to change the font (<b>cmbFonts</b>),
71
 * the size(<b>cmbFontSize</b>), the style (which can be underlined
72
 * -<b>btnUnderlined</b>-, italic -<b>btnItalic</b>- or bold -<b>btnBold</b>-),the
73
 * color (<b>jcc</b>)and the offset of the the text(<b>txtXOffset</b> and <b>txtYOffset</b>).<p>
74
 * <p>
75
 * The rest of tabs that are not mask are not yet implemented.
76
 *
77
 *
78
 *@see Mask
79
 *@see AbstractTypeSymbolEditor
80
 *@author jaume dominguez faus - jaume.dominguez@iver.es
81
 */
82
public class SimpleText extends AbstractTypeSymbolEditor {
83

    
84
        private ArrayList tabs = new ArrayList();
85
        //TODO: Comentarizado hasta que mask est? acabado
86
//        private Mask mask;
87
        private JComboBoxFonts cmbFonts;
88
        private JToggleButton btnUnderlined;
89
        private JToggleButton btnItalic;
90
        private JToggleButton btnBold;
91
        private JComboBoxFontSizes cmbFontSize;
92
        private ColorChooserPanel jcc;
93
        private JIncrementalNumberField txtXOffset;
94
        private JIncrementalNumberField txtYOffset;
95

    
96
        public SimpleText(SymbolEditor owner) {
97
                super(owner);
98
                initialize();
99
        }
100

    
101

    
102
        /**
103
         * Initializes the parameters that define a simpletext.To do it, four tabs
104
         * are created (one of them is a mask)inside the SymbolEditor panel with
105
         * default values for the different attributes of the simple text.For the
106
         * moment only the text tab has been created and it allows the user to modify
107
         * the font,color, offset and style of the text.
108
         *
109
         */
110

    
111
        private void initialize() {
112
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
113
                JPanel aux = new JPanel(new GridLayout(1,2,15,0));
114
                myTab.setName(Messages.getText("text"));
115

    
116
                ////------------ Tab Text
117
                GridBagLayoutPanel leftColumn = new GridBagLayoutPanel();
118
                leftColumn.addComponent(Messages.getText("font")+": ", cmbFonts = new JComboBoxFonts());
119

    
120
                JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.LEADING,0,1));
121
                aux2.add(getBtnBold());
122
                aux2.add(getBtnItalic());
123
                aux2.add(getBtnUnderlined());
124
                leftColumn.addComponent(
125
                                Messages.getText("style")+":", aux2);
126

    
127
                jcc = new ColorChooserPanel();
128
                jcc.setAlpha(255);
129
                leftColumn.addComponent(Messages.getText("color")+":", jcc);
130
                // vertical alignment stuff
131
                leftColumn.addComponent(new JLabel(" "));
132
                // \vertical alignment stuff
133
                leftColumn.addComponent(Messages.getText("x_offset")+":",
134
                                txtXOffset = new JIncrementalNumberField("0", 3));
135
                leftColumn.addComponent(Messages.getText("x_offset")+":",
136
                                txtYOffset = new JIncrementalNumberField("0", 3));
137

    
138

    
139
                GridBagLayoutPanel rightColumn = new GridBagLayoutPanel();
140
                aux2 = new JPanel(new FlowLayout(0, 0, FlowLayout.LEFT));
141
                cmbFontSize = new JComboBoxFontSizes();
142
                aux2.add(cmbFontSize);
143
                rightColumn.addComponent(Messages.getText("size")+":", aux2);
144
                // vertical alignment stuff
145
                rightColumn.addComponent(new JLabel(" "));
146
                rightColumn.addComponent(new JLabel(" "));
147
                rightColumn.addComponent(new JLabel(" "));
148
                rightColumn.addComponent(new JLabel(" "));
149
                rightColumn.addComponent(new JLabel(" "));
150
                rightColumn.addComponent(new JLabel(" "));
151
                rightColumn.addComponent(new JLabel(" "));
152
                // \vertical alignment stuff
153

    
154

    
155
                aux.add(leftColumn);
156
                aux.add(rightColumn);
157

    
158

    
159
                myTab.add(aux);
160
                tabs.add(myTab);
161

    
162
                ////------------ Tab FORMATTED
163
                myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
164
                myTab.setName(Messages.getText("formatted"));
165

    
166
                leftColumn = new GridBagLayoutPanel();
167

    
168
                myTab.add(leftColumn);
169
                tabs.add(myTab);
170

    
171
                ////------------ Tab ADVANCED
172
                myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
173
                myTab.setName(Messages.getText("advanced"));
174
                leftColumn = new GridBagLayoutPanel();
175

    
176
                myTab.add(leftColumn);
177
                tabs.add(myTab);
178

    
179
                ////------------ Tab MASK
180
//                mask = new Mask(this);
181
//                tabs.add(mask);
182
        }
183

    
184
        public ISymbol getLayer() {
185
                ISimpleTextSymbol sts = SymbologyLocator.getSymbologyManager().createSimpleTextSymbol();
186
                return sts;
187
        }
188

    
189
        public String getName() {
190
                return Messages.getText("simple_text_symbol");
191
        }
192

    
193
        public JPanel[] getTabs() {
194
                return (JPanel[]) tabs.toArray(new JPanel[tabs.size()]);
195
        }
196

    
197
        public void refreshControls(ISymbol layer) {
198
                // TODO Implement it
199
//                throw new Error("Not yet implemented!");
200

    
201
        }
202

    
203
        public EditorTool[] getEditorTools() {
204
                return null;
205
        }
206

    
207
        private JToggleButton getBtnUnderlined() {
208
                if (btnUnderlined == null) {
209
                        btnUnderlined = new JToggleButton(PluginServices.getIconTheme().get("underline-icon"));
210
                }
211
                return btnUnderlined;
212
        }
213

    
214
        private JToggleButton getBtnItalic() {
215
                if (btnItalic == null) {
216
                        btnItalic = new JToggleButton(PluginServices.getIconTheme().get("italic-icon"));
217
                }
218
                return btnItalic;
219
        }
220

    
221
        private JToggleButton getBtnBold() {
222
                if (btnBold == null) {
223
                        btnBold = new JToggleButton(PluginServices.getIconTheme().get("bold-icon"));
224
                }
225
                return btnBold;
226
        }
227

    
228

    
229
        @Override
230
        public boolean canManageSymbol(ISymbol symbol) {
231
                return symbol instanceof ISimpleTextSymbol;
232
        }
233
}