Revision 10028

View differences:

branches/simbologia/applications/appgvSIG/config/text.properties
775 775
size=Tama?o
776 776
angle=?ngulo
777 777
width=Ancho
778
save_error=Error guardando
778
save_error=Error guardando
779
marker_fill=Relleno de marcadores
780
simple_line=L?nea simple
781
simple_marker=Marcador simple
782
x_offset=Desplazamiento en X
783
y_offset=Desplazamiento en Y
784
simple_marker_symbol=S?mbolo de marcador simple
785
enter_description=Introduzca una descripci?n
786
syntax_error=Error de sintaxis
787
error=Error
788
label_expression_help=
789
expression=Expresi?n
790
label_expression_editor=Editor de expresiones de etiqueta
791
method=M?todo
792
class=Clase
793
classes=Clases
794
text_string=Texto
795
text_symbol=S?mbolo de texto
796
font_color=Color de fuente
797
enable_labelling=Habilitar etiquetado
798
visualization=Visualizaci?n
799
label_styles=Estilos de etiqueta
800
placement=Colocaci?n
801
edit_expression=Editar expresi?n
802
SQL_query=Sentencia SQL
803
remane_class=Renombrar clase
804
delete_class=Eliminar clase
805
add_class=A?adir clase
806
label_features_in_this_class=Etiquetar entidades dentro de esta clase
807
labeling=Etiquetado
808
shape_type_error=Tipo de shape err?neo.
809
enter_new_name=Introduzca el nuevo nombre
810
placement_properties=Propiedades de colocaci?n
811
point_settings=Configuraci?n de punto
812
line_settings=Configuraci?n de l?nea
813
polygon_settings=Configuraci?n de pol?gono
814
position=Posici?n
815
orientation=Orientaci?n
816
parallel=Paralela
817
following_line=Siguiendo la l?nea
818
perpedicular=Perpendicular
819
duplicate_labels=Etiquetas repetidas
820
place_one_label_per_feature_part=Situar una etiqueta por cada parte de la entidad
821
place_one_label_per_feature=Situar ?nicamente una etiqueta por entidad
822
remove_duplicate_labels=Eliminar etiquetas repetidas
823
label_features_in_the_same_way=Etiquetar todas las entidades de la misma manera
824
define_classes_of_features_and_label_each_differently=Definir diferentes clases de entidades y etiquetarlas de manera diferente
825
label_only_when_selected=Etiquetar solamente cuando sus entidades est?n seleccionadas
826
could_not_apply_legend=No se pudo aplicar la leyenda
branches/simbologia/applications/appgvSIG/config/config.xml
93 93
				<action-tool icon="images/addlayer.png" tooltip="Anadir_Capa" position="1"/>
94 94
			</tool-bar>
95 95
		</extension>
96
		<extension class-name="com.iver.cit.gvsig.AdvancedSymbologyExtension"
97
			description="Enables the advanced symbology (available since v1.1)."
98
			active="true"
99
			priority="20">
100
		</extension>
96 101

  
97 102
		<extension class-name="com.iver.cit.gvsig.CopyPasteExtension"
98 103
			description="Extensi?n que habilita el copiado y pegado de capas y documentos."
branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/AdvancedSymbologyExtension.java
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$
45
* $Log$
46
* Revision 1.1.2.1  2007-02-01 12:12:41  jaume
47
* theme manager window and all its components are now dynamic
48
*
49
*
50
*/
51
package com.iver.cit.gvsig;
52

  
53
import com.iver.andami.PluginServices;
54
import com.iver.andami.plugins.Extension;
55
import com.iver.cit.gvsig.fmap.rendering.styling.EquallyLabeled;
56
import com.iver.cit.gvsig.fmap.rendering.styling.FeatureDependentLabeled;
57
import com.iver.cit.gvsig.fmap.rendering.styling.OnSelectionLabeled;
58
import com.iver.cit.gvsig.project.documents.view.legend.gui.Categories;
59
import com.iver.cit.gvsig.project.documents.view.legend.gui.DotDensity;
60
import com.iver.cit.gvsig.project.documents.view.legend.gui.Features;
61
import com.iver.cit.gvsig.project.documents.view.legend.gui.FilePage;
62
import com.iver.cit.gvsig.project.documents.view.legend.gui.LabelingManager;
63
import com.iver.cit.gvsig.project.documents.view.legend.gui.LegendManager;
64
import com.iver.cit.gvsig.project.documents.view.legend.gui.General;
65
import com.iver.cit.gvsig.project.documents.view.legend.gui.Quantities;
66
import com.iver.cit.gvsig.project.documents.view.legend.gui.SingleSymbol;
67
import com.iver.cit.gvsig.project.documents.view.legend.gui.ThemeManagerWindow;
68
import com.iver.cit.gvsig.project.documents.view.legend.gui.VectorialInterval;
69
import com.iver.cit.gvsig.project.documents.view.legend.gui.VectorialUniqueValue;
70

  
71
public class AdvancedSymbologyExtension extends Extension {
72

  
73
	public void initialize() {
74
		// Install required features
75

  
76
		// labeling methods
77
		LabelingManager.addLabelingMethod(
78
				PluginServices.getText(this, "label_features_in_the_same_way")+".",
79
				new EquallyLabeled());
80
		LabelingManager.addLabelingMethod(
81
				PluginServices.getText(this, "define_classes_of_features_and_label_each_differently")+".",
82
				new FeatureDependentLabeled());
83
		LabelingManager.addLabelingMethod(
84
				PluginServices.getText(this, "label_only_when_selected")+".",
85
				new OnSelectionLabeled());
86

  
87
		// legends
88
		LegendManager.addLegendPage(Quantities.class);
89
		LegendManager.addLegendPage(Features.class);
90
		LegendManager.addLegendPage(Categories.class);
91

  
92
		LegendManager.addLegendPage(SingleSymbol.class);
93
		LegendManager.addLegendPage(DotDensity.class);
94

  
95
		LegendManager.addLegendPage(VectorialInterval.class);
96
		LegendManager.addLegendPage(VectorialUniqueValue.class);
97

  
98

  
99
		// pages
100
		ThemeManagerWindow.addPage(General.class);
101
		ThemeManagerWindow.addPage(LegendManager.class);
102
		ThemeManagerWindow.addPage(LabelingManager.class);
103
		ThemeManagerWindow.addPage(FilePage.class);
104
	}
105

  
106
	public void execute(String actionCommand) {
107

  
108
	}
109

  
110
	public boolean isEnabled() {
111
		return true;
112
	}
113

  
114
	public boolean isVisible() {
115
		return false; // or whatever
116
	}
117

  
118
}
0 119

  
branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/gui/FPanelLocConfig.java
375 375
				FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
376 376
				if (lyr instanceof Classifiable)
377 377
				{
378
					ThemeManagerWindow m_LegendEditor = new ThemeManagerWindow();
379
					try {
380
						theLayers.setActive(false);
381
						lyr.setActive(true);
382
						m_LegendEditor.setMapContext(mapCtrl.getMapContext());
383
					} catch (DriverException e1) {
384
						// TODO Auto-generated catch block
385
						e1.printStackTrace();
386
					}
378
					ThemeManagerWindow m_LegendEditor = new ThemeManagerWindow(lyr/*, mapCtrl.getMapContext()*/);
379
					theLayers.setActive(false);
380
					lyr.setActive(true);
387 381
					if (PluginServices.getMainFrame() == null) {
388 382
						JDialog dlg = new JDialog();
389 383

  
branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/FLyrVectEditPropertiesTocMenuEntry.java
56 56
 *
57 57
 * $Id$
58 58
 * $Log$
59
 * Revision 1.4.2.2  2007-01-30 18:10:10  jaume
59
 * Revision 1.4.2.3  2007-02-01 12:12:41  jaume
60
 * theme manager window and all its components are now dynamic
61
 *
62
 * Revision 1.4.2.2  2007/01/30 18:10:10  jaume
60 63
 * start commiting labeling stuff
61 64
 *
62 65
 * Revision 1.4.2.1  2007/01/26 13:49:03  jaume
......
127 130
	public void execute(ITocItem item, FLayer[] selectedItems) {
128 131
		FLayer[] actives = selectedItems;
129 132
		ThemeManagerWindow fThemeManagerWindow;
130
    	if (actives.length==1) {
131
    		if (!actives[0].isAvailable()) return;
132
    		fThemeManagerWindow = new ThemeManagerWindow();
133
    		try {
134
    			fThemeManagerWindow.setMapContext(getMapContext());
135
    		} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
136
    			e1.printStackTrace();
137
    		}
138
            //PluginServices.getMDIManager().addView(fThemeManagerWindow);
139
    		if (PluginServices.getMainFrame() == null) {
140
    			JDialog dlg = new JDialog();
141
    			fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
142
    			dlg.getContentPane().add(fThemeManagerWindow);
143
    			dlg.setModal(false);
144
    			dlg.pack();
145
    			dlg.show();
146
    		} else {
147
    			PluginServices.getMDIManager().addWindow(fThemeManagerWindow);
148
    		}
149
    	} else {
133
//    	if (actives.length==1) {
134
//    		if (!actives[0].isAvailable()) return;
135
//    		fThemeManagerWindow = new ThemeManagerWindow();
136
//    		try {
137
//    			fThemeManagerWindow.setMapContext(getMapContext());
138
//    		} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
139
//    			e1.printStackTrace();
140
//    		}
141
//            //PluginServices.getMDIManager().addView(fThemeManagerWindow);
142
//    		if (PluginServices.getMainFrame() == null) {
143
//    			JDialog dlg = new JDialog();
144
//    			fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
145
//    			dlg.getContentPane().add(fThemeManagerWindow);
146
//    			dlg.setModal(false);
147
//    			dlg.pack();
148
//    			dlg.show();
149
//    		} else {
150
//    			PluginServices.getMDIManager().addWindow(fThemeManagerWindow);
151
//    		}
152
//    	} else {
150 153
        	for (int i = 0; i < actives.length; i++){
151 154
        		if (actives[0].isAvailable()) {
152 155
        			System.out.println("openPliegoThemeProperties(): Muchas capas. Abrimos el panel para la capa " + actives[i]);
153
        			fThemeManagerWindow = new ThemeManagerWindow(actives[i], getMapContext());
156
        			fThemeManagerWindow = new ThemeManagerWindow(actives[i]/*, getMapContext()*/);
154 157
        			//PluginServices.getMDIManager().addView(fThemeManagerWindow);
155 158
        			if (PluginServices.getMainFrame() == null) {
156 159
        				JDialog dlg = new JDialog();
......
164 167
        			}
165 168
        		}
166 169
        	}
167
    	}
170
//    	}
168 171
    	Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
169 172
		project.setModified(true);
170 173
	}
branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/Labeling.java
1
/*
2
 * Created on 01-jun-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.project.documents.view.legend.gui;
46

  
47
import java.awt.Component;
48
import java.awt.Dimension;
49
import java.awt.FlowLayout;
50
import java.awt.Font;
51
import java.awt.GridLayout;
52
import java.awt.event.ActionEvent;
53
import java.awt.event.ActionListener;
54
import java.util.ArrayList;
55

  
56
import javax.swing.BorderFactory;
57
import javax.swing.JCheckBox;
58
import javax.swing.JComponent;
59
import javax.swing.JLabel;
60
import javax.swing.JPanel;
61

  
62
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
63
import org.gvsig.gui.beans.swing.JButton;
64

  
65
import com.iver.andami.PluginServices;
66
import com.iver.cit.gvsig.fmap.core.ILabelable;
67
import com.iver.cit.gvsig.fmap.layers.FLayer;
68
import com.iver.cit.gvsig.fmap.rendering.Legend;
69
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingMethod;
70
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
71
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer;
72
import com.iver.cit.gvsig.gui.utils.FontChooser;
73
import com.iver.utiles.swing.JComboBox;
74

  
75
public class Labeling extends GridBagLayoutPanel implements ActionListener {
76

  
77
	private static final Font DEFAULT_FONT =
78
		  new Font("SansSerif", Font.PLAIN, 9);
79
	private JCheckBox chkApplyLabels;
80
	private JComboBox cmbMethod;
81
	private GridBagLayoutPanel classesPanel;
82
	private JComboBox cmbClasses;
83
	private JCheckBox chkLabel;
84
	private JButton btnRenameClass;
85
	private JButton btnSQLQuery;
86
	private JButton btnDelClass;
87
	private JButton btnAddClass;
88
	private JComboBox cmbExpressions;
89
	private JButton btnEditExpression;
90
	private SymbolPreviewer previewer;
91
	private JButton btnFont;
92
	protected Font labelFont;
93
	private ColorChooserPanel colorChooser;
94
	private JButton btnPlacement;
95
	private JButton btnLabelStyles;
96
	private JCheckBox chkTextOnly;
97
	private ILabelable layer;
98
	private Legend renderer;
99
	private JButton btnVisualization;
100
	private ILabelingMethod method;
101

  
102
	private class MethodItem {
103
		private String name;
104
		private ILabelingMethod method;
105

  
106
		private MethodItem(String name, ILabelingMethod method) {
107
			this.name = name;
108
			this.method = method;
109
		}
110

  
111
		public String toString() {
112
			return name;
113
		}
114

  
115
	}
116

  
117
	public Labeling() {
118
		super();
119
		initialize();
120
	}
121

  
122
	private void initialize() {
123
		addComponent(chkApplyLabels = new JCheckBox(PluginServices.getText(this, "enable_labelling")));
124
		chkApplyLabels.addActionListener(this);
125
		JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
126
		aux.add(new JLabel(PluginServices.getText(this, "method")+":"));
127
		aux.add(getCmbMethod());
128
		aux.setPreferredSize(new Dimension(550, 40));
129
		addComponent(aux);
130

  
131

  
132
		classesPanel = new GridBagLayoutPanel();
133
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
134
		aux.add(new JLabel(PluginServices.getText(this, "class")+":"));
135
		aux.add(getCmbClasses());
136
		aux.add(getChkLabelFeatures());
137
		aux.setPreferredSize(new Dimension(530, 40));
138
		classesPanel.addComponent(aux);
139

  
140
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
141
		aux.add(getBtnAddClass());
142
		aux.add(getBtnDelClass());
143
		aux.add(getBtnRenameClass());
144
		aux.add(getBtnSQLQuery());
145
		aux.setPreferredSize(new Dimension(530, 30));
146
		classesPanel.addComponent(aux);
147
		classesPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "classes")));
148
		addComponent(classesPanel);
149

  
150

  
151
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
152
		aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "text_string")));
153
		aux.add(new JLabel(PluginServices.getText(this, "expression")+":"));
154
		aux.add(getCmbExpressions());
155
		aux.add(getBtnEditExpression());
156
		aux.setPreferredSize(new Dimension(540, 60));
157
		addComponent(aux);
158

  
159

  
160
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
161
		aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "text_symbol")));
162
		aux.add(getSymbolPreviewer());
163
		JPanel aux2 = new JPanel();
164
		aux2.add(getBtnFont());
165
		aux2.add(new JLabel(PluginServices.getText(this, "font_color")));
166
		colorChooser = new ColorChooserPanel();
167
		colorChooser.setAlpha(255);
168
		aux2.add(colorChooser);
169
		aux2.setLayout(new GridLayout(aux2.getComponentCount(), 1));
170
		aux.add(aux2);
171
		addComponent(aux);
172

  
173

  
174
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
175
		aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options")));
176
		aux.add(getChkTextOnly());
177
		aux.add(getBtnVisualization());
178
		aux.add(getBtnPlacement());
179
		aux.add(getBtnLabelStyles());
180
		aux.setPreferredSize(new Dimension(540, 60));
181
		addComponent(aux);
182
	}
183

  
184
	public void addLabelingMethod(String name, ILabelingMethod method) {
185
		getCmbMethod().addItem(new MethodItem(name, method));
186
	}
187

  
188
	private JButton getBtnVisualization() {
189
		if (btnVisualization == null) {
190
			btnVisualization = new JButton(PluginServices.getText(this, "visualization")+"...");
191
			btnVisualization.addActionListener(this);
192
		}
193
		return btnVisualization;
194
	}
195

  
196
	private JCheckBox getChkTextOnly() {
197
    	if (chkTextOnly == null) {
198
    		chkTextOnly = new JCheckBox();
199
    		chkTextOnly.setText(PluginServices.getText(this, "draw_text_only"));
200
    		chkTextOnly.addActionListener(this);
201
    	}
202
    	return chkTextOnly;
203
    }
204

  
205
	private JButton getBtnLabelStyles() {
206
		if (btnLabelStyles == null) {
207
			btnLabelStyles = new JButton(PluginServices.getText(this, "label_styles")+"...");
208
			btnLabelStyles.addActionListener(this);
209
		}
210
		return btnLabelStyles;
211
	}
212

  
213
	private JButton getBtnPlacement() {
214
		if (btnPlacement == null) {
215
			btnPlacement = new JButton(PluginServices.getText(this, "placement")+"...");
216
			btnPlacement.addActionListener(this);
217
		}
218
		return btnPlacement;
219
	}
220

  
221
	private JButton getBtnFont() {
222
		if (btnFont == null) {
223
			btnFont = new JButton();
224
			btnFont.setText(PluginServices.getText(this,"fuente")+"...");
225
			btnFont.addActionListener(this);
226
		}
227
		return btnFont;
228
	}
229

  
230
	private SymbolPreviewer getSymbolPreviewer() {
231
		if (previewer == null) {
232
			previewer = new SymbolPreviewer();
233
			previewer.setPreferredSize(new Dimension(420, 65));
234
		}
235
		return previewer;
236
	}
237

  
238
	private JComboBox getCmbMethod() {
239
		if (cmbMethod == null) {
240
			cmbMethod = new JComboBox();
241
			cmbMethod.setSize(new Dimension(300, 22));
242
			cmbMethod.addActionListener(this);
243
		}
244
		return cmbMethod;
245
	}
246

  
247
	private JButton getBtnEditExpression() {
248
		if (btnEditExpression == null) {
249
			btnEditExpression = new JButton(
250
					PluginServices.getText(this, "edit_expression")+"...");
251
			btnEditExpression.addActionListener(this);
252
		}
253
		return btnEditExpression;
254
	}
255

  
256
	private JComboBox getCmbExpressions() {
257
		if (cmbExpressions == null) {
258
			cmbExpressions = new JComboBox();
259
			cmbExpressions.addActionListener(this);
260
		}
261
		return cmbExpressions;
262

  
263
	}
264

  
265
	private JButton getBtnSQLQuery() {
266
		if (btnSQLQuery == null) {
267
			btnSQLQuery = new JButton(PluginServices.getText(this, "SQL_query"));
268
			btnSQLQuery.addActionListener(this);
269
		}
270
		return btnSQLQuery;
271
	}
272

  
273
	private JButton getBtnRenameClass() {
274
		if (btnRenameClass == null) {
275
			btnRenameClass = new JButton(PluginServices.getText(this, "remane_class"));
276
			btnRenameClass.addActionListener(this);
277
		}
278
		return btnRenameClass;
279
	}
280

  
281
	private JButton getBtnDelClass() {
282
		if (btnDelClass == null) {
283
			btnDelClass = new JButton(PluginServices.getText(this, "delete_class"));
284
			btnDelClass.addActionListener(this);
285
		}
286
		return btnDelClass;
287
	}
288

  
289
	private JButton getBtnAddClass() {
290
		if (btnAddClass == null) {
291
			btnAddClass = new JButton(PluginServices.getText(this, "add_class"));
292
			btnAddClass.addActionListener(this);
293
		}
294
		return btnAddClass;
295
	}
296

  
297
	private JCheckBox getChkLabelFeatures() {
298
		if (chkLabel == null) {
299
			chkLabel = new JCheckBox();
300
			chkLabel.setText(PluginServices.getText(this, "label_features_in_this_class"));
301
			chkLabel.addActionListener(this);
302
		}
303
		return chkLabel;
304
	}
305

  
306
	private JComboBox getCmbClasses() {
307
		if (cmbClasses == null) {
308
			cmbClasses = new JComboBox();
309
			cmbClasses.addActionListener(this);
310
		}
311
		return cmbClasses;
312
	}
313

  
314
	private void setComponentEnabled(Component c, boolean b) {
315
		if (c instanceof JComponent) {
316
			JComponent c1 = (JComponent) c;
317
			for (int i = 0; i < c1.getComponentCount(); i++) {
318
				setComponentEnabled(c1.getComponent(i), b);
319
			}
320
		}
321
		c.setEnabled(b);
322
	}
323

  
324
	public void actionPerformed(ActionEvent e) {
325
		JComponent c = (JComponent)e.getSource();
326
		if (c.equals(chkApplyLabels)) {
327
			boolean b = chkApplyLabels.isSelected();
328
			// enables/disables all components
329
			for (int i = 0; i < getComponentCount(); i++) {
330
				Component c1 = getComponent(i);
331
				if (!c1.equals(c))
332
					setComponentEnabled(c1, b);
333
			}
334
		} else if (c.equals(btnAddClass)) {
335
		} else if (c.equals(btnDelClass)) {
336
		} else if (c.equals(btnEditExpression)) {
337
		} else if (c.equals(btnFont)) {
338
			Font newFont = FontChooser.showDialog("Choose Font", labelFont);
339
	        if (newFont != null) {
340
	            labelFont = newFont;
341
	        }
342
		} else if (c.equals(btnLabelStyles)) {
343
		} else if (c.equals(btnPlacement)) {
344
		} else if (c.equals(btnRenameClass)) {
345
		} else if (c.equals(btnSQLQuery)) {
346
		} else if (c.equals(btnVisualization)) {
347
		} else if (c.equals(chkLabel)) {
348
		} else if (c.equals(chkTextOnly)) {
349
		} else if (c.equals(cmbClasses)) {
350
		} else if (c.equals(cmbExpressions)) {
351
		} else if (c.equals(cmbMethod)) {
352
			int selection = cmbMethod.getSelectedIndex();
353
			// disable components in class panel
354
			setComponentEnabled(classesPanel, selection == 1 && chkApplyLabels.isSelected());
355
		} else if (c.equals(colorChooser)) {
356

  
357
		}
358
	}
359

  
360
	public void setModel(FLayer layer, Legend renderer) throws IllegalArgumentException {
361
		if (layer instanceof ILabelable) {
362
			this.layer = (ILabelable) layer;
363
			this.renderer = renderer;
364
			setMethod(this.layer.getLabelingMethod());
365
			setComponentEnabled(this, true);
366
			refreshControls();
367
			actionPerformed(new ActionEvent(chkApplyLabels, 0, null));
368
		} else {
369
			setComponentEnabled(this, false);
370
		}
371
	}
372

  
373
	private void setMethod(ILabelingMethod labelingMethod) {
374
		ArrayList aux = new ArrayList();
375
		for (int i = 0; i < getCmbMethod().getItemCount(); i++) {
376
			aux.add(((MethodItem) getCmbMethod().getItemAt(i)).method);
377
		}
378
		int i = aux.indexOf(labelingMethod);
379
		if (i == -1)
380
			i = 0; // index of the simplest method: EquallyLabeled (must be installed)
381
		getCmbMethod().setSelectedIndex(i);
382
	}
383

  
384
	private ILabelingMethod getMethod() {
385
		return ((MethodItem) getCmbMethod().getSelectedItem()).method;
386
	}
387

  
388
	private void refreshControls() {
389
		// enables labeling
390
		chkApplyLabels.setSelected(layer.isLabeled());
391

  
392
		// multiple class or not enables or disables the class panel
393
		setComponentEnabled(classesPanel, getMethod().allowsMultipleClass());
394
	}
395
}
branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/LabelingManager.java
1
/*
2
 * Created on 01-jun-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.project.documents.view.legend.gui;
46

  
47
import java.awt.BorderLayout;
48
import java.awt.Component;
49
import java.awt.Dimension;
50
import java.awt.FlowLayout;
51
import java.awt.Font;
52
import java.awt.GridLayout;
53
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionListener;
55
import java.util.ArrayList;
56
import java.util.Hashtable;
57
import java.util.Iterator;
58

  
59
import javax.swing.BorderFactory;
60
import javax.swing.JCheckBox;
61
import javax.swing.JComponent;
62
import javax.swing.JLabel;
63
import javax.swing.JOptionPane;
64
import javax.swing.JPanel;
65
import javax.swing.JTextField;
66

  
67
import org.gvsig.gui.beans.AcceptCancelPanel;
68
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
69
import org.gvsig.gui.beans.swing.JButton;
70

  
71
import com.iver.andami.PluginServices;
72
import com.iver.andami.messages.NotificationManager;
73
import com.iver.andami.ui.mdiManager.IWindow;
74
import com.iver.andami.ui.mdiManager.WindowInfo;
75
import com.iver.cit.gvsig.fmap.DriverException;
76
import com.iver.cit.gvsig.fmap.core.FShape;
77
import com.iver.cit.gvsig.fmap.core.ILabelable;
78
import com.iver.cit.gvsig.fmap.layers.FLayer;
79
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
80
import com.iver.cit.gvsig.fmap.rendering.Legend;
81
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingMethod;
82
import com.iver.cit.gvsig.fmap.rendering.styling.LabelClass;
83
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
84
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer;
85
import com.iver.cit.gvsig.gui.utils.FontChooser;
86
import com.iver.utiles.swing.JComboBox;
87

  
88
public class LabelingManager extends AbstractThemeManagerPage implements ActionListener {
89
	private static int newClassSuffix = 0;
90
	private static Hashtable methods = new Hashtable();
91
	private static final Font DEFAULT_FONT =
92
		  new Font("SansSerif", Font.PLAIN, 9);
93
	private JCheckBox chkApplyLabels;
94
	private JComboBox cmbMethod;
95
	private GridBagLayoutPanel classesPanel;
96
	private JComboBox cmbClasses;
97
	private JCheckBox chkLabel;
98
	private JButton btnRenameClass;
99
	private JButton btnSQLQuery;
100
	private JButton btnDelClass;
101
	private JButton btnAddClass;
102
	private JComboBox cmbExpressions;
103
	private JButton btnEditExpression;
104
	private SymbolPreviewer previewer;
105
	private JButton btnFont;
106
	protected Font labelFont;
107
	private ColorChooserPanel colorChooser;
108
	private JButton btnPlacement;
109
	private JButton btnLabelStyles;
110
	private JCheckBox chkTextOnly;
111
	private ILabelable layer;
112
	private Legend renderer;
113
	private JButton btnVisualization;
114
	private ILabelingMethod method;
115
	private ArrayList expressions;
116
	private GridBagLayoutPanel content;
117

  
118
	private class MethodItem {
119
		private String name;
120
		private ILabelingMethod method;
121

  
122
		private MethodItem(String name, ILabelingMethod method) {
123
			this.name = name;
124
			this.method = method;
125
		}
126

  
127
		public String toString() {
128
			return name;
129
		}
130
	}
131

  
132
	private class ExprEditorPanel extends JPanel implements IWindow {
133
		private ActionListener action = new ActionListener() {
134
			public void actionPerformed(ActionEvent e) {
135
				if ("OK".equals(e.getActionCommand())) {
136
					if (validateExpr())
137
						PluginServices.getMDIManager().closeWindow(
138
								ExprEditorPanel.this);
139
					else
140
						JOptionPane.showMessageDialog(ExprEditorPanel.this,
141
								PluginServices.getText(this, "syntax_error"),
142
								PluginServices.getText(this, "error"),
143
								JOptionPane.ERROR_MESSAGE);
144
				} else {
145
					getTxtExpression().setText(lastExtression);
146
					PluginServices.getMDIManager().closeWindow(
147
							ExprEditorPanel.this);
148
				}
149
			}
150

  
151

  
152
		};
153
		private JTextField txtExpression;
154
		private String lastExtression;
155

  
156
		public ExprEditorPanel(String currentExpression) {
157
			super();
158
			initialize();
159
			lastExtression = currentExpression;
160
			getTxtExpression().setText(currentExpression);
161

  
162
		}
163

  
164
		private void initialize() {
165
			GridBagLayoutPanel content = new GridBagLayoutPanel();
166
			content.addComponent(new JLabel(" "+PluginServices.getText(this, "label_expression_help")));
167
			content.addComponent(
168
					" "+PluginServices.getText(this, "expression")+":",
169
					getTxtExpression());
170
			setLayout(new BorderLayout(5, 5));
171
			add(content, BorderLayout.CENTER);
172
			add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
173
			setSize(new Dimension(300, 80));
174
		}
175

  
176
		private JTextField getTxtExpression() {
177
			if (txtExpression == null) {
178
				txtExpression = new JTextField(25);
179
			}
180
			return txtExpression;
181
		}
182

  
183
		public String getExpression() {
184
			return getTxtExpression().getText();
185
		}
186

  
187
		public WindowInfo getWindowInfo() {
188
			WindowInfo viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
189
			viewInfo.setWidth(getWidth());
190
			viewInfo.setHeight(getHeight());
191
			viewInfo.setTitle(PluginServices.getText(this,"label_expression_editor"));
192
			return viewInfo;
193
		}
194

  
195
		private boolean validateExpr() {
196
			// TODO Implement it
197
			throw new Error("Not yet implemented!");
198

  
199
		}
200
	}
201

  
202
	public LabelingManager() {
203
		super();
204
		initialize();
205
	}
206

  
207
	private void initialize() {
208
		content = new GridBagLayoutPanel();
209
		content.addComponent(getChkApplyLabels());
210
		JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
211
		aux.add(new JLabel(PluginServices.getText(this, "method")+":"));
212
		aux.add(getCmbMethod());
213
		aux.setPreferredSize(new Dimension(550, 40));
214
		content.addComponent(aux);
215

  
216

  
217
		classesPanel = new GridBagLayoutPanel();
218
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
219
		aux.add(new JLabel(PluginServices.getText(this, "class")+":"));
220
		aux.add(getCmbClasses());
221
		aux.add(getChkLabelFeatures());
222
		aux.setPreferredSize(new Dimension(530, 40));
223
		classesPanel.addComponent(aux);
224

  
225
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
226
		aux.add(getBtnAddClass());
227
		aux.add(getBtnDelClass());
228
		aux.add(getBtnRenameClass());
229
		aux.add(getBtnSQLQuery());
230
		aux.setPreferredSize(new Dimension(530, 30));
231
		classesPanel.addComponent(aux);
232
		classesPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "classes")));
233
		content.addComponent(classesPanel);
234

  
235

  
236
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
237
		aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "text_string")));
238
		aux.add(new JLabel(PluginServices.getText(this, "expression")+":"));
239
		aux.add(getCmbExpressions());
240
		aux.add(getBtnEditExpression());
241
		aux.setPreferredSize(new Dimension(540, 60));
242
		content.addComponent(aux);
243

  
244

  
245
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
246
		aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "text_symbol")));
247
		aux.add(getSymbolPreviewer());
248
		JPanel aux2 = new JPanel();
249
		aux2.add(getBtnFont());
250
		aux2.add(new JLabel(PluginServices.getText(this, "font_color")));
251
		colorChooser = new ColorChooserPanel();
252
		colorChooser.setAlpha(255);
253
		aux2.add(colorChooser);
254
		aux2.setLayout(new GridLayout(aux2.getComponentCount(), 1));
255
		aux.add(aux2);
256
		content.addComponent(aux);
257

  
258

  
259
		aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
260
		aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options")));
261
		aux.add(getBtnVisualization());
262
		aux.add(getBtnPlacement());
263
		aux.add(getBtnLabelStyles());
264
		aux.setPreferredSize(new Dimension(540, 60));
265
		content.addComponent(aux);
266
		add(content);
267
	}
268

  
269
	private JCheckBox getChkApplyLabels() {
270
		if (chkApplyLabels == null) {
271
			chkApplyLabels = new JCheckBox(PluginServices.getText(this, "enable_labelling"));
272
			chkApplyLabels.addActionListener(this);
273
		}
274
		return chkApplyLabels;
275
	}
276

  
277
	public static void addLabelingMethod(String name, ILabelingMethod method) {
278
		methods.put(name, method);
279
	}
280

  
281
	private JButton getBtnVisualization() {
282
		if (btnVisualization == null) {
283
			btnVisualization = new JButton(PluginServices.getText(this, "visualization")+"...");
284
			btnVisualization.addActionListener(this);
285
		}
286
		return btnVisualization;
287
	}
288

  
289
	private JButton getBtnLabelStyles() {
290
		if (btnLabelStyles == null) {
291
			btnLabelStyles = new JButton(PluginServices.getText(this, "label_styles")+"...");
292
			btnLabelStyles.addActionListener(this);
293
		}
294
		return btnLabelStyles;
295
	}
296

  
297
	private JButton getBtnPlacement() {
298
		if (btnPlacement == null) {
299
			btnPlacement = new JButton(PluginServices.getText(this, "placement")+"...");
300
			btnPlacement.addActionListener(this);
301
		}
302
		return btnPlacement;
303
	}
304

  
305
	private JButton getBtnFont() {
306
		if (btnFont == null) {
307
			btnFont = new JButton();
308
			btnFont.setText(PluginServices.getText(this,"fuente")+"...");
309
			btnFont.addActionListener(this);
310
		}
311
		return btnFont;
312
	}
313

  
314
	private SymbolPreviewer getSymbolPreviewer() {
315
		if (previewer == null) {
316
			previewer = new SymbolPreviewer();
317
			previewer.setPreferredSize(new Dimension(420, 65));
318
		}
319
		return previewer;
320
	}
321

  
322
	private JComboBox getCmbMethod() {
323
		if (cmbMethod == null) {
324
			Iterator it = methods.keySet().iterator();
325
			ArrayList aux = new ArrayList();
326
			while (it.hasNext()) {
327
				String name = (String) it.next();
328
				MethodItem newItem = new MethodItem(name, (ILabelingMethod) methods.get(name));
329
				aux.add(newItem);
330
			}
331
			cmbMethod = new JComboBox(aux.toArray());
332
			cmbMethod.setSize(new Dimension(300, 22));
333
			cmbMethod.addActionListener(this);
334
		}
335
		return cmbMethod;
336
	}
337

  
338
	private JButton getBtnEditExpression() {
339
		if (btnEditExpression == null) {
340
			btnEditExpression = new JButton(
341
					PluginServices.getText(this, "edit_expression")+"...");
342
			btnEditExpression.addActionListener(this);
343
		}
344
		return btnEditExpression;
345
	}
346

  
347
	private JComboBox getCmbExpressions() {
348
		if (cmbExpressions == null) {
349
			cmbExpressions = new JComboBox();
350
			cmbExpressions.setPreferredSize(new Dimension(150, 20));
351
			cmbExpressions.addActionListener(this);
352
		}
353
		return cmbExpressions;
354

  
355
	}
356

  
357
	private JButton getBtnSQLQuery() {
358
		if (btnSQLQuery == null) {
359
			btnSQLQuery = new JButton(PluginServices.getText(this, "SQL_query"));
360
			btnSQLQuery.addActionListener(this);
361
		}
362
		return btnSQLQuery;
363
	}
364

  
365
	private JButton getBtnRenameClass() {
366
		if (btnRenameClass == null) {
367
			btnRenameClass = new JButton(PluginServices.getText(this, "remane_class"));
368
			btnRenameClass.addActionListener(this);
369
		}
370
		return btnRenameClass;
371
	}
372

  
373
	private JButton getBtnDelClass() {
374
		if (btnDelClass == null) {
375
			btnDelClass = new JButton(PluginServices.getText(this, "delete_class"));
376
			btnDelClass.addActionListener(this);
377
		}
378
		return btnDelClass;
379
	}
380

  
381
	private JButton getBtnAddClass() {
382
		if (btnAddClass == null) {
383
			btnAddClass = new JButton(PluginServices.getText(this, "add_class"));
384
			btnAddClass.addActionListener(this);
385
		}
386
		return btnAddClass;
387
	}
388

  
389
	private JCheckBox getChkLabelFeatures() {
390
		if (chkLabel == null) {
391
			chkLabel = new JCheckBox();
392
			chkLabel.setText(PluginServices.getText(this, "label_features_in_this_class"));
393
			chkLabel.addActionListener(this);
394
		}
395
		return chkLabel;
396
	}
397

  
398
	private JComboBox getCmbClasses() {
399
		if (cmbClasses == null) {
400
			cmbClasses = new JComboBox();
401
			cmbClasses.setPreferredSize(new Dimension(150, 20));
402
			cmbClasses.addActionListener(this);
403
		}
404
		return cmbClasses;
405
	}
406

  
407
	private void setComponentEnabled(Component c, boolean b) {
408
		if (c instanceof JComponent) {
409
			JComponent c1 = (JComponent) c;
410
			for (int i = 0; i < c1.getComponentCount(); i++) {
411
				setComponentEnabled(c1.getComponent(i), b);
412
			}
413
		}
414
		c.setEnabled(b);
415
	}
416

  
417

  
418
	public void setModel(FLayer layer, Legend renderer) throws IllegalArgumentException {
419
		if (layer instanceof ILabelable) {
420
			this.layer = (ILabelable) layer;
421
			this.renderer = renderer;
422
			setMethod(this.layer.getLabelingMethod());
423
			setComponentEnabled(this, true);
424
			refreshControls();
425
			actionPerformed(new ActionEvent(chkApplyLabels, 0, null));
426
		} else {
427
			setComponentEnabled(this, false);
428
		}
429
	}
430

  
431
	private void setMethod(ILabelingMethod labelingMethod) {
432
		ArrayList aux = new ArrayList();
433
		for (int i = 0; i < getCmbMethod().getItemCount(); i++) {
434
			aux.add(((MethodItem) getCmbMethod().getItemAt(i)).method);
435
		}
436
		int i = aux.indexOf(labelingMethod);
437
		if (i == -1)
438
			i = 0; // index of the simplest method: EquallyLabeled (must be installed)
439
		getCmbMethod().setSelectedIndex(i);
440
	}
441

  
442
	private ILabelingMethod getMethod() {
443
		return ((MethodItem) getCmbMethod().getSelectedItem()).method;
444
	}
445

  
446
	private void refreshControls() {
447
		if (layer == null) return;
448

  
449
		// enables labeling
450
		getChkApplyLabels().setSelected(layer.isLabeled());
451

  
452
		// fires an event from the method's combobox
453
		actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
454

  
455
		// expressions combobox
456
		ArrayList exp = getExpressions();
457
		getCmbExpressions().removeAllItems();
458
		for (int i = 0; i < exp.size(); i++)
459
			getCmbExpressions().addItem(exp.get(i));
460

  
461

  
462
	}
463

  
464
	private ArrayList getExpressions() {
465
		if (expressions == null) {
466
			expressions = new ArrayList();
467
			try {
468
				String[] n =  ((FLyrVect) layer).getRecordset().getFieldNames();
469
				for (int i = 0; i < n.length; i++) {
470
					expressions.add("[ "+n[i]+" ]");
471
				}
472
			} catch (Exception e) {
473
				NotificationManager.addError(
474
						PluginServices.getText(
475
								this, "could_not_retreive_layer_names"), e);
476
			}
477
		}
478
		return expressions;
479
	}
480

  
481
	public void actionPerformed(ActionEvent e) {
482
		JComponent c = (JComponent)e.getSource();
483
		if (c.equals(chkApplyLabels)) {
484
			boolean b = chkApplyLabels.isSelected();
485
			// enables/disables all components
486
			for (int i = 0; i < content.getComponentCount(); i++) {
487
				Component c1 = content.getComponent(i);
488
				if (!c1.equals(c))
489
					setComponentEnabled(c1, b);
490
			}
491
			if (b) actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
492

  
493
		} else if (c.equals(btnAddClass)) {
494
			LabelClass newClass = new LabelClass();
495
			newClass.setName(PluginServices.getText(this, "labeling")+String.valueOf(++newClassSuffix));
496
			getMethod().addLabelClass(newClass);
497

  
498
		} else if (c.equals(btnDelClass)) {
499
			LabelClass clazz = getActiveClass();
500
			getMethod().deleteLabelClass(clazz);
501

  
502
		} else if (c.equals(btnEditExpression)) {
503
			ExprEditorPanel ep = new ExprEditorPanel((String) getCmbExpressions().
504
					getSelectedItem());
505
			PluginServices.getMDIManager().addWindow( ep );
506
			getCmbExpressions().addItem(ep.getExpression());
507
			getCmbExpressions().setSelectedItem(ep.getExpression());
508
		} else if (c.equals(btnFont)) {
509
			Font newFont = FontChooser.showDialog("Choose Font", labelFont);
510
	        if (newFont != null) {
511
	            labelFont = newFont;
512
	        }
513

  
514
		} else if (c.equals(btnLabelStyles)) {
515

  
516
		} else if (c.equals(btnPlacement)) {
517
			int shapeType = FShape.POINT;
518
			// TODO for now, all layers in this point are FLyrVect but likely
519
			// they can be any. For those, the shape type is FShape.POINT.
520
			// TODO : missing an abstraction of this in each layer type
521
			if (layer instanceof FLyrVect) {
522
				FLyrVect l = (FLyrVect) layer;
523
				try {
524
					shapeType = l.getShapeType();
525
				} catch (DriverException ex) {
526
					NotificationManager.addError(
527
							PluginServices.getText(this, "shape_type_error"), ex);
528
				}
529
			}
530
			PlacementProperties pp = new PlacementProperties(
531
					shapeType, getActiveClass().getPlacementConstraints());
532
			PluginServices.getMDIManager().addWindow(pp);
533

  
534
			getActiveClass().setPlacementConstraints(
535
					pp.getPlacementConstraints());
536

  
537
		} else if (c.equals(btnRenameClass)) {
538
			LabelClass clazz = getActiveClass();
539
			String newName = JOptionPane.showInputDialog(
540
					PluginServices.getText(this, "enter_new_name"));
541
			if (newName != null)
542
				getMethod().renameLabelClass(clazz, newName);
543

  
544
		} else if (c.equals(btnSQLQuery)) {
545

  
546
		} else if (c.equals(btnVisualization)) {
547

  
548
		} else if (c.equals(chkLabel)) {
549

  
550
		} else if (c.equals(chkTextOnly)) {
551

  
552
		} else if (c.equals(cmbClasses)) {
553

  
554
		} else if (c.equals(cmbExpressions)) {
555

  
556
		} else if (c.equals(cmbMethod)) {
557
			// disable components in class panel
558
			// multiple class or not enables or disables the class panel
559
			setComponentEnabled(classesPanel, getMethod().allowsMultipleClass());
560
			// label classes
561
			getCmbClasses().removeAllItems();
562
			LabelClass[] lClasses = getMethod().getLabelClasses();
563
			for (int i = 0; i < lClasses.length; i++) {
564
				getCmbClasses().addItem(lClasses[i]);
565
			}
566
		} else if (c.equals(colorChooser)) {
567
		}
568
	}
569

  
570
	private LabelClass getActiveClass() {
571
		return (LabelClass) getCmbClasses().getSelectedItem();
572
	}
573

  
574
	public void acceptAction() {
575
		// TODO Implement it
576
		throw new Error("Not yet implemented!");
577

  
578
	}
579

  
580
	public void cancelAction() {
581

  
582
	}
583

  
584
	public void applyAction() {
585
		// TODO Implement it
586
		throw new Error("Not yet implemented!");
587

  
588
	}
589

  
590
	public String getName() {
591
		return PluginServices.getText(this,"Etiquetados");
592
	}
593
}
594

  
0 595

  
branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/FilePage.java
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$
45
* $Log$
46
* Revision 1.1.2.1  2007-02-01 12:12:41  jaume
47
* theme manager window and all its components are now dynamic
48
*
49
*
50
*/
51
package com.iver.cit.gvsig.project.documents.view.legend.gui;
52

  
53
import java.awt.Component;
54
import java.awt.event.ActionListener;
55
import java.io.File;
56
import java.io.FileNotFoundException;
57
import java.io.FileReader;
58
import java.io.FileWriter;
59

  
60
import javax.swing.JComponent;
61
import javax.swing.JFileChooser;
62

  
63
import org.exolab.castor.xml.MarshalException;
64
import org.exolab.castor.xml.Marshaller;
65
import org.exolab.castor.xml.ValidationException;
66
import org.gvsig.gui.beans.swing.JButton;
67

  
68
import com.iver.andami.PluginServices;
69
import com.iver.andami.messages.NotificationManager;
70
import com.iver.cit.gvsig.fmap.layers.FLayer;
71
import com.iver.cit.gvsig.fmap.layers.XMLException;
72
import com.iver.cit.gvsig.fmap.rendering.Legend;
73
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
74
import com.iver.utiles.GenericFileFilter;
75
import com.iver.utiles.XMLEntity;
76
import com.iver.utiles.xmlEntity.generate.XmlTag;
77

  
78
public class FilePage extends AbstractThemeManagerPage {
79

  
80
	private Legend legend;
81
	private FLayer layer;
82
	private JButton btnSaveLegend;
83
	private JButton btnLoadLegend;
84
	private ActionListener actionListener = new ActionListener() {
85
		public void actionPerformed(java.awt.event.ActionEvent e) {
86
			JComponent c = (JComponent) e.getSource();
87
			if (c.equals(getBtnSaveLegend())) {
88
				JFileChooser jfc = new JFileChooser();
89
				jfc.addChoosableFileFilter(new GenericFileFilter("sld","*.sld"));
90
				jfc.addChoosableFileFilter(new GenericFileFilter("gvl",
91
						PluginServices.getText(this, "tipo_de_leyenda")));
92

  
93

  
94
				if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
95
					File file=jfc.getSelectedFile();
96
					if (jfc.getFileFilter().accept(new File("dummy.sld"))) {
97
						if (!(file.getPath().toLowerCase().endsWith(".sld"))){
98
							file=new File(file.getPath()+".sld");
99
						}
100
						export2SLD(file);
101
					}
102
					else{
103
						if (!(file.getPath().toLowerCase().endsWith(".gvl"))){
104
							file=new File(file.getPath()+".gvl");
105
						}
106
						writeLegend(file);
107
					}
108
				}
109
			} else if (c.equals(getBtnLoadLegend())) {
110
				JFileChooser jfc = new JFileChooser();
111
	    		jfc.addChoosableFileFilter(new GenericFileFilter("gvl",
112
	    				PluginServices.getText(this, "tipo_de_leyenda")));
113
	    		//jfc.addChoosableFileFilter(new GenericFileFilter("sld","sld"));
114

  
115
	    		if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
116
	    			File file=jfc.getSelectedFile();
117
	    			if (!(file.getPath().endsWith(".gvl") || file.getPath().endsWith(".GVL")))	{
118
	    				file=new File(file.getPath()+".gvl");
119
	    			}
120
	    			loadLegend(file);
121
	    		}
122
			}
123
		};
124
	};
125
	public FilePage() {
126
		super();
127
		initialize();
128
	}
129

  
130
	private void initialize() {
131

  
132
	}
133

  
134
	private JButton getBtnSaveLegend() {
135
		if (btnSaveLegend == null) {
136
			btnSaveLegend = new JButton(PluginServices.getText(this,"Guardar_leyenda")+"...");
137
			btnSaveLegend.setActionCommand("SAVE_LEGEND");
138
			btnSaveLegend.addActionListener(actionListener);
139
		}
140
		return btnSaveLegend;
141
	}
142

  
143
	private JButton getBtnLoadLegend() {
144
		if (btnLoadLegend == null) {
145
			btnLoadLegend = new JButton(PluginServices.getText(this,"Recuperar_leyenda")+"...");
146
			btnLoadLegend.setActionCommand("LOAD_LEGEND");
147
			btnLoadLegend.addActionListener(actionListener);
148
		}
149
		return btnLoadLegend;
150
	}
151

  
152
	public String getName() {
153
		return PluginServices.getText(this, "file");
154
	}
155

  
156
	public void acceptAction() {
157
	}
158

  
159
	public void cancelAction() {
160
	}
161

  
162
	public void applyAction() {
163
	}
164

  
165
	 /**
166
     * Reads a legend file and loads into the this LegendManager
167
     * @param file
168
     */
169
    private void loadLegend(File file) {
170
    	File xmlFile = new File(file.getAbsolutePath());
171
    	FileReader reader;
172
    	try {
173
    		reader = new FileReader(xmlFile);
174

  
175
    		XmlTag tag = (XmlTag) XmlTag.unmarshal(reader);
176

  
177
    		setModel(layer, LegendFactory.createFromXML(new XMLEntity(tag)));
178
    	} catch (FileNotFoundException e) {
179
    		// should be unreachable code
180
    		NotificationManager.addError(PluginServices.getText(this, "file_not_found"), e);
181
    	} catch (MarshalException e) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff