Revision 40911
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Tue Aug 13 14:00:42 CEST 2013 |
|
2 |
buildNumber=1 |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<!-- |
|
2 |
|
|
3 |
gvSIG. Desktop Geographic Information System. |
|
4 |
|
|
5 |
Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
|
8 |
modify it under the terms of the GNU General Public License |
|
9 |
as published by the Free Software Foundation; either version 3 |
|
10 |
of the License, or (at your option) any later version. |
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
GNU General Public License for more details. |
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
|
18 |
along with this program; if not, write to the Free Software |
|
19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
MA 02110-1301, USA. |
|
21 |
|
|
22 |
For any additional information, do not hesitate to contact us |
|
23 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
|
|
25 |
--> |
|
26 |
<assembly> |
|
27 |
<id>gvsig-plugin-package</id> |
|
28 |
<formats> |
|
29 |
<format>zip</format> |
|
30 |
</formats> |
|
31 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
32 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
33 |
<files> |
|
34 |
<file> |
|
35 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
36 |
<outputDirectory>lib</outputDirectory> |
|
37 |
</file> |
|
38 |
<file> |
|
39 |
<source>target/package.info</source> |
|
40 |
</file> |
|
41 |
</files> |
|
42 |
|
|
43 |
<fileSets> |
|
44 |
<fileSet> |
|
45 |
<directory>src/main/resources-plugin</directory> |
|
46 |
<outputDirectory>.</outputDirectory> |
|
47 |
</fileSet> |
|
48 |
</fileSets> |
|
49 |
|
|
50 |
<!-- |
|
51 |
<dependencySets> |
|
52 |
<dependencySet> |
|
53 |
<useProjectArtifact>false</useProjectArtifact> |
|
54 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
55 |
<outputDirectory>lib</outputDirectory> |
|
56 |
<includes> |
|
57 |
</includes> |
|
58 |
</dependencySet> |
|
59 |
</dependencySets> |
|
60 |
|
|
61 |
--> |
|
62 |
|
|
63 |
</assembly> |
|
64 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/lang/LabelClassUtils.java | ||
---|---|---|
1 |
package org.gvsig.labeling.lang; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.exception.DataException; |
|
4 |
import org.gvsig.fmap.dal.feature.Feature; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
6 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
|
7 |
import org.gvsig.tools.ToolsLocator; |
|
8 |
import org.gvsig.tools.evaluator.Evaluator; |
|
9 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
10 |
import org.gvsig.tools.evaluator.EvaluatorException; |
|
11 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
|
12 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
13 |
import org.gvsig.tools.persistence.Persistent; |
|
14 |
import org.gvsig.tools.persistence.PersistentContext; |
|
15 |
import org.gvsig.tools.persistence.PersistentState; |
|
16 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
17 |
import org.gvsig.tools.persistence.spi.PersistentContextServices; |
|
18 |
import org.slf4j.Logger; |
|
19 |
import org.slf4j.LoggerFactory; |
|
20 |
|
|
21 |
public class LabelClassUtils { |
|
22 |
|
|
23 |
private static Logger logger = |
|
24 |
LoggerFactory.getLogger(LabelClassUtils.class); |
|
25 |
|
|
26 |
private static PersistenceManager persman = |
|
27 |
ToolsLocator.getPersistenceManager(); |
|
28 |
|
|
29 |
public static boolean isUseSqlQuery(ILabelClass lbl) { |
|
30 |
String str = lbl.getSQLQuery(); |
|
31 |
return str != null && str.trim().length() > 0; |
|
32 |
} |
|
33 |
|
|
34 |
|
|
35 |
public static Object clone(Persistent persi) { |
|
36 |
|
|
37 |
PersistentContext context = null; |
|
38 |
Object resp = null; |
|
39 |
PersistentState state = null; |
|
40 |
try { |
|
41 |
state = persman.getState(persi, true); |
|
42 |
} catch (PersistenceException e) { |
|
43 |
logger.error("While cloning ILabelClass", e); |
|
44 |
return persi; |
|
45 |
} |
|
46 |
context = state.getContext(); |
|
47 |
if (context instanceof PersistentContextServices) { |
|
48 |
/* |
|
49 |
* Ensure that previous instances are not used, |
|
50 |
* so objects are recreated |
|
51 |
*/ |
|
52 |
((PersistentContextServices) context).clear(); |
|
53 |
} |
|
54 |
try { |
|
55 |
resp = persman.create(state); |
|
56 |
} catch (Exception e) { |
|
57 |
logger.error("While cloning ILabelClass", e); |
|
58 |
return persi; |
|
59 |
} |
|
60 |
return resp; |
|
61 |
} |
|
62 |
|
|
63 |
public static Object evaluate(String expr, EvaluatorData data) { |
|
64 |
|
|
65 |
Evaluator ev = EvaluatorCreator.getEvaluator(expr); |
|
66 |
Object resp_obj = null; |
|
67 |
try { |
|
68 |
resp_obj = ev.evaluate(data); |
|
69 |
} catch (EvaluatorException e) { |
|
70 |
/* |
|
71 |
* Parse exception or field not found or |
|
72 |
* divison by zero, etc. Malformed expression, not valid |
|
73 |
*/ |
|
74 |
return null; |
|
75 |
} catch (Exception e) { |
|
76 |
/* |
|
77 |
* All other exceptions. Should not happen often. |
|
78 |
* We assume a strange exception (NPE, etc) and decide it's not a valid expression |
|
79 |
*/ |
|
80 |
return null; |
|
81 |
} |
|
82 |
return resp_obj; |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
public static boolean validExpression( |
|
87 |
String str, FeatureStore sto, boolean must_be_boolean) { |
|
88 |
|
|
89 |
Feature dummyfeat = null;; |
|
90 |
try { |
|
91 |
dummyfeat = sto.createNewFeature(true); |
|
92 |
} catch (DataException e1) { |
|
93 |
logger.error("While getting dummy feature in labeling expression.", e1); |
|
94 |
return false; |
|
95 |
} |
|
96 |
|
|
97 |
|
|
98 |
EvaluatorWithDescriptions evde = EvaluatorCreator.getEvaluator(str); |
|
99 |
Object resp_obj = null; |
|
100 |
try { |
|
101 |
/* |
|
102 |
* Try evaluate feature with default values |
|
103 |
*/ |
|
104 |
resp_obj = evde.evaluate(dummyfeat.getEvaluatorData()); |
|
105 |
} catch (EvaluatorException e) { |
|
106 |
/* |
|
107 |
* Parse exception or field not found or |
|
108 |
* divison by zero, etc. |
|
109 |
* Malformed expression, not valid |
|
110 |
*/ |
|
111 |
return false; |
|
112 |
} catch (Exception e) { |
|
113 |
/* |
|
114 |
* All other exceptions. |
|
115 |
* Should not happen often. |
|
116 |
* We assume a strange |
|
117 |
* exception (NPE, etc) and decide it's not a valid |
|
118 |
* expression |
|
119 |
* |
|
120 |
*/ |
|
121 |
return false; |
|
122 |
} |
|
123 |
|
|
124 |
if (must_be_boolean) { |
|
125 |
return resp_obj.getClass() == Boolean.class; |
|
126 |
} else { |
|
127 |
return true; |
|
128 |
} |
|
129 |
|
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/lang/LabelFieldComparator.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 |
package org.gvsig.labeling.lang; |
|
42 |
|
|
43 |
import java.util.Comparator; |
|
44 |
|
|
45 |
public class LabelFieldComparator implements Comparator<LabelField> { |
|
46 |
|
|
47 |
public int compare(LabelField o1, LabelField o2) |
|
48 |
{ |
|
49 |
if ( o1 != null && o2 == null ) |
|
50 |
return -1; |
|
51 |
if ( o1 == null && o2 != null ) |
|
52 |
return 1; |
|
53 |
if ( o1 == null && o2 == null ) |
|
54 |
return 0; |
|
55 |
if ( o1.pos <= o2.pos ) |
|
56 |
return -1; |
|
57 |
else |
|
58 |
return 1; |
|
59 |
} |
|
60 |
|
|
61 |
} |
|
62 |
class LabelField |
|
63 |
{ |
|
64 |
String text; |
|
65 |
int pos; |
|
66 |
public LabelField(String text,int pos) |
|
67 |
{ |
|
68 |
this.text = text; |
|
69 |
this.pos = pos; |
|
70 |
} |
|
71 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/lang/EvaluatorCreator.java | ||
---|---|---|
1 |
package org.gvsig.labeling.lang; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
|
8 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* Utility class to centralize the creation of an |
|
14 |
* @link {@link EvaluatorWithDescriptions} |
|
15 |
* |
|
16 |
* TODO Perhaps create a manager in Tools to perform this operation |
|
17 |
* |
|
18 |
* @author jldominguez |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class EvaluatorCreator { |
|
22 |
|
|
23 |
private static Map<String, EvaluatorWithDescriptions> evCache = |
|
24 |
new HashMap<String, EvaluatorWithDescriptions>(); |
|
25 |
|
|
26 |
static { |
|
27 |
for (int i=0; i<200; i++) { |
|
28 |
String e = "XXX" + i; |
|
29 |
SQLJEPEvaluator p = new SQLJEPEvaluator(e); |
|
30 |
evCache.put(e, p); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
|
|
35 |
/** |
|
36 |
* Create an {@link EvaluatorWithDescriptions} that uses |
|
37 |
* the string expression provided |
|
38 |
* |
|
39 |
* @param expr |
|
40 |
* @return |
|
41 |
*/ |
|
42 |
public static EvaluatorWithDescriptions getEvaluator(String expr) { |
|
43 |
|
|
44 |
EvaluatorWithDescriptions resp = evCache.get(expr); |
|
45 |
if (resp == null) { |
|
46 |
resp = new SQLJEPEvaluator(expr); |
|
47 |
if (evCache.size() > 100) { |
|
48 |
removeOne(evCache); |
|
49 |
} |
|
50 |
evCache.put(expr, resp); |
|
51 |
} |
|
52 |
return resp; |
|
53 |
} |
|
54 |
|
|
55 |
private static void removeOne( |
|
56 |
Map<String, EvaluatorWithDescriptions> themap) { |
|
57 |
|
|
58 |
Iterator<String> iter = themap.keySet().iterator(); |
|
59 |
int count = 50; |
|
60 |
String k = null; |
|
61 |
while (iter.hasNext() && count > 0) { |
|
62 |
k = iter.next(); |
|
63 |
count--; |
|
64 |
} |
|
65 |
themap.remove(k); |
|
66 |
} |
|
67 |
|
|
68 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/gui/layerproperties/IPlacementProperties.java | ||
---|---|---|
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.labeling.gui.layerproperties; |
|
25 |
|
|
26 |
import java.awt.event.ActionListener; |
|
27 |
|
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
29 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
|
30 |
|
|
31 |
public interface IPlacementProperties extends IWindow, ActionListener { |
|
32 |
public IPlacementConstraints getPlacementConstraints(); |
|
33 |
|
|
34 |
|
|
35 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/gui/layerproperties/DuplicateLayersMode.java | ||
---|---|---|
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.labeling.gui.layerproperties; |
|
25 |
|
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
28 |
|
|
29 |
import javax.swing.BorderFactory; |
|
30 |
import javax.swing.ButtonGroup; |
|
31 |
import javax.swing.JRadioButton; |
|
32 |
|
|
33 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
|
34 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
35 |
import org.gvsig.i18n.Messages; |
|
36 |
|
|
37 |
public class DuplicateLayersMode extends GridBagLayoutPanel |
|
38 |
implements ActionListener { |
|
39 |
|
|
40 |
private static final long serialVersionUID = 1091963463412809652L; |
|
41 |
private JRadioButton rdBtnRemoveDuplicates; |
|
42 |
private JRadioButton rdBtnOnePerFeature; |
|
43 |
private JRadioButton rdBtnOnePerFeaturePart; |
|
44 |
|
|
45 |
private ActionListener actListeneter = null; |
|
46 |
|
|
47 |
public DuplicateLayersMode(ActionListener act_lis) { |
|
48 |
super(); |
|
49 |
actListeneter = act_lis; |
|
50 |
initialize(); |
|
51 |
} |
|
52 |
private void initialize() { |
|
53 |
setBorder(BorderFactory. |
|
54 |
createTitledBorder(null, |
|
55 |
Messages.getText("duplicate_labels"))); |
|
56 |
addComponent(getRdBtnRemoveDuplicates()); |
|
57 |
addComponent(getRdBtnOnePerFeature()); |
|
58 |
addComponent(getRdBtnOnePerFeaturePart()); |
|
59 |
|
|
60 |
ButtonGroup group = new ButtonGroup(); |
|
61 |
group.add(getRdBtnOnePerFeature()); |
|
62 |
group.add(getRdBtnOnePerFeaturePart()); |
|
63 |
group.add(getRdBtnRemoveDuplicates()); |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
private JRadioButton getRdBtnOnePerFeaturePart() { |
|
68 |
if (rdBtnOnePerFeaturePart == null) { |
|
69 |
rdBtnOnePerFeaturePart = new JRadioButton( |
|
70 |
Messages.getText("place_one_label_per_feature_part")); |
|
71 |
rdBtnOnePerFeaturePart.addActionListener(this); |
|
72 |
|
|
73 |
} |
|
74 |
return rdBtnOnePerFeaturePart; |
|
75 |
} |
|
76 |
|
|
77 |
private JRadioButton getRdBtnOnePerFeature() { |
|
78 |
if (rdBtnOnePerFeature == null) { |
|
79 |
rdBtnOnePerFeature = new JRadioButton( |
|
80 |
Messages.getText("place_one_label_per_feature")); |
|
81 |
rdBtnOnePerFeature.setSelected(true); |
|
82 |
rdBtnOnePerFeature.addActionListener(this); |
|
83 |
} |
|
84 |
return rdBtnOnePerFeature; |
|
85 |
} |
|
86 |
|
|
87 |
private JRadioButton getRdBtnRemoveDuplicates() { |
|
88 |
if (rdBtnRemoveDuplicates == null) { |
|
89 |
rdBtnRemoveDuplicates = new JRadioButton( |
|
90 |
Messages.getText("remove_duplicate_labels")); |
|
91 |
rdBtnRemoveDuplicates.addActionListener(this); |
|
92 |
|
|
93 |
} |
|
94 |
return rdBtnRemoveDuplicates; |
|
95 |
} |
|
96 |
|
|
97 |
public void setMode(int dupMode) { |
|
98 |
|
|
99 |
rdBtnRemoveDuplicates.setSelected(dupMode == IPlacementConstraints.REMOVE_DUPLICATE_LABELS); |
|
100 |
rdBtnOnePerFeature.setSelected(dupMode == IPlacementConstraints.ONE_LABEL_PER_FEATURE); |
|
101 |
rdBtnOnePerFeaturePart.setSelected(dupMode == IPlacementConstraints.ONE_LABEL_PER_FEATURE_PART); |
|
102 |
} |
|
103 |
|
|
104 |
public int getMode() { |
|
105 |
if (rdBtnRemoveDuplicates.isSelected()) { |
|
106 |
return IPlacementConstraints.REMOVE_DUPLICATE_LABELS; |
|
107 |
} |
|
108 |
if (rdBtnOnePerFeature.isSelected()) { |
|
109 |
return IPlacementConstraints.ONE_LABEL_PER_FEATURE; |
|
110 |
} |
|
111 |
if (rdBtnOnePerFeaturePart.isSelected()) { |
|
112 |
return IPlacementConstraints.ONE_LABEL_PER_FEATURE_PART; |
|
113 |
} |
|
114 |
|
|
115 |
throw new Error("Unsupported layer duplicates mode"); |
|
116 |
} |
|
117 |
public void actionPerformed(ActionEvent e) { |
|
118 |
|
|
119 |
if (actListeneter != null) { |
|
120 |
ActionEvent aev = new ActionEvent(this, 0, ""); |
|
121 |
actListeneter.actionPerformed(aev); |
|
122 |
} |
|
123 |
|
|
124 |
} |
|
125 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/gui/layerproperties/MultiShapePlacementProperties.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 |
package org.gvsig.labeling.gui.layerproperties; |
|
42 |
|
|
43 |
import java.awt.BorderLayout; |
|
44 |
import java.awt.event.ActionEvent; |
|
45 |
|
|
46 |
import javax.swing.JPanel; |
|
47 |
import javax.swing.JTabbedPane; |
|
48 |
|
|
49 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
50 |
import org.gvsig.app.ApplicationLocator; |
|
51 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
52 |
import org.gvsig.fmap.geom.GeometryException; |
|
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
|
54 |
import org.gvsig.i18n.Messages; |
|
55 |
import org.gvsig.labeling.placements.AbstractPlacementConstraints; |
|
56 |
import org.gvsig.labeling.placements.LinePlacementConstraints; |
|
57 |
import org.gvsig.labeling.placements.MultiShapePlacementConstraints; |
|
58 |
import org.gvsig.labeling.placements.PlacementManager; |
|
59 |
import org.gvsig.labeling.placements.PointPlacementConstraints; |
|
60 |
import org.gvsig.labeling.placements.PolygonPlacementConstraints; |
|
61 |
import org.slf4j.Logger; |
|
62 |
import org.slf4j.LoggerFactory; |
|
63 |
|
|
64 |
|
|
65 |
public class MultiShapePlacementProperties extends JPanel |
|
66 |
implements IPlacementProperties { |
|
67 |
|
|
68 |
private static Logger logger = LoggerFactory.getLogger( |
|
69 |
MultiShapePlacementProperties.class); |
|
70 |
private static final long serialVersionUID = 2935114466845029008L; |
|
71 |
private PlacementProperties pointProperties; |
|
72 |
private PlacementProperties lineProperties; |
|
73 |
private PlacementProperties polygonProperties; |
|
74 |
private DuplicateLayersMode dupMode; |
|
75 |
|
|
76 |
|
|
77 |
public MultiShapePlacementProperties( |
|
78 |
MultiShapePlacementConstraints constraints) throws Exception { |
|
79 |
|
|
80 |
MultiShapePlacementConstraints c = null; |
|
81 |
if (constraints != null) { |
|
82 |
c = (MultiShapePlacementConstraints) constraints.clone(); |
|
83 |
} else { |
|
84 |
c = (MultiShapePlacementConstraints) |
|
85 |
PlacementManager.createPlacementConstraints(TYPES.GEOMETRY); |
|
86 |
} |
|
87 |
|
|
88 |
this.pointProperties = new PlacementProperties( |
|
89 |
c.getPointConstraints(), TYPES.POINT, getDuplicatesMode()); |
|
90 |
this.lineProperties = new PlacementProperties( |
|
91 |
c.getLineConstraints(), TYPES.CURVE, getDuplicatesMode()); |
|
92 |
this.polygonProperties = new PlacementProperties( |
|
93 |
c.getPolygonConstraints(), TYPES.SURFACE, getDuplicatesMode()); |
|
94 |
initialize(); |
|
95 |
} |
|
96 |
|
|
97 |
private DuplicateLayersMode getDuplicatesMode() { |
|
98 |
if (dupMode == null) { |
|
99 |
dupMode = new DuplicateLayersMode(null); |
|
100 |
} |
|
101 |
return dupMode; |
|
102 |
} |
|
103 |
|
|
104 |
private void initialize() { |
|
105 |
setLayout(new BorderLayout()); |
|
106 |
JPanel aux = new JPanel(new BorderLayout()); |
|
107 |
JTabbedPane p = new JTabbedPane(); |
|
108 |
|
|
109 |
p.addTab(Messages.getText("points"), pointProperties); |
|
110 |
p.addTab(Messages.getText("lines"), lineProperties); |
|
111 |
p.addTab(Messages.getText("polygon"), polygonProperties); |
|
112 |
setLayout(new BorderLayout()); |
|
113 |
aux.add(p, BorderLayout.CENTER); |
|
114 |
aux.add(getDuplicatesMode(), BorderLayout.SOUTH); |
|
115 |
add(aux, BorderLayout.CENTER); |
|
116 |
} |
|
117 |
|
|
118 |
public IPlacementConstraints getPlacementConstraints() { |
|
119 |
return new MultiShapePlacementConstraints( |
|
120 |
(PointPlacementConstraints) pointProperties.getPlacementConstraints(), |
|
121 |
(LinePlacementConstraints) lineProperties.getPlacementConstraints(), |
|
122 |
(PolygonPlacementConstraints) polygonProperties.getPlacementConstraints()); |
|
123 |
|
|
124 |
} |
|
125 |
|
|
126 |
public WindowInfo getWindowInfo() { |
|
127 |
return pointProperties.getWindowInfo(); |
|
128 |
} |
|
129 |
|
|
130 |
public Object getWindowProfile() { |
|
131 |
return pointProperties.getWindowProfile(); |
|
132 |
} |
|
133 |
|
|
134 |
|
|
135 |
public void actionPerformed(ActionEvent e) { |
|
136 |
boolean okPressed = "OK".equals(e.getActionCommand()); |
|
137 |
boolean cancelPressed = "CANCEL".equals(e.getActionCommand()); |
|
138 |
if (okPressed || cancelPressed) { |
|
139 |
if (okPressed) { |
|
140 |
try { |
|
141 |
pointProperties.applyConstraints(); |
|
142 |
lineProperties.applyConstraints(); |
|
143 |
polygonProperties.applyConstraints(); |
|
144 |
} catch (GeometryException e1) { |
|
145 |
logger.error("While applying constraints.", e1); |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
if ("CANCEL".equals(e.getActionCommand())) { |
|
150 |
pointProperties.constraints = pointProperties.oldConstraints; |
|
151 |
lineProperties.constraints = lineProperties.oldConstraints; |
|
152 |
polygonProperties.constraints = polygonProperties.oldConstraints; |
|
153 |
} |
|
154 |
|
|
155 |
ApplicationLocator.getManager().getUIManager().closeWindow(this); |
|
156 |
|
|
157 |
return; |
|
158 |
} |
|
159 |
} |
|
160 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/gui/layerproperties/AbstractLabelingMethodPanel.java | ||
---|---|---|
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.labeling.gui.layerproperties; |
|
25 |
|
|
26 |
import java.beans.PropertyChangeListener; |
|
27 |
|
|
28 |
import javax.swing.JPanel; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
33 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
34 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
|
35 |
|
|
36 |
|
|
37 |
public abstract class AbstractLabelingMethodPanel extends JPanel implements PropertyChangeListener { |
|
38 |
|
|
39 |
public static final String PLACEMENT_CONSTRAINTS = "PLACEMENT_CONSTRAINTS"; |
|
40 |
public static final String ALLOW_OVERLAP = "ALLOW_OVERLAP"; |
|
41 |
public static final String ZOOM_CONSTRAINTS= "ZOOM_CONSTRAINTS"; |
|
42 |
|
|
43 |
protected FLyrVect layer; |
|
44 |
protected ILabelingMethod method; |
|
45 |
|
|
46 |
public abstract String getName(); |
|
47 |
public abstract Class<? extends ILabelingMethod> getLabelingMethodClass(); |
|
48 |
public void setModel(ILabelingMethod method, FLyrVect srcLayer) |
|
49 |
throws ReadException { |
|
50 |
|
|
51 |
if (srcLayer == null) { |
|
52 |
throw new ReadException("FLyrVect is null", |
|
53 |
new Exception("FLyrVect is null")); |
|
54 |
} |
|
55 |
this.layer = srcLayer; |
|
56 |
|
|
57 |
try { |
|
58 |
if (method!= null && method.getClass().equals(getLabelingMethodClass())) { |
|
59 |
this.method = method; |
|
60 |
} else { |
|
61 |
this.method = getLabelingMethodClass().newInstance(); |
|
62 |
} |
|
63 |
initializePanel(); |
|
64 |
|
|
65 |
} catch (Exception e) { |
|
66 |
|
|
67 |
throw new ReadException( |
|
68 |
srcLayer.getFeatureStore().getName(), |
|
69 |
new Exception("Unable to load labeling method. Is it in your classpath?", e)); |
|
70 |
} |
|
71 |
|
|
72 |
try { |
|
73 |
fillPanel(this.method, srcLayer.getFeatureStore().getDefaultFeatureType()); |
|
74 |
} catch (DataException de) { |
|
75 |
throw new ReadException(srcLayer.getFeatureStore().getName(), de); |
|
76 |
} |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
protected abstract void initializePanel() ; |
|
81 |
public abstract void fillPanel( |
|
82 |
ILabelingMethod method, |
|
83 |
FeatureType ftype) throws ReadException; |
|
84 |
|
|
85 |
public String toString() { |
|
86 |
return getName(); |
|
87 |
} |
|
88 |
|
|
89 |
public ILabelingMethod getMethod() { |
|
90 |
return method; |
|
91 |
} |
|
92 |
|
|
93 |
public boolean equals(Object obj) { |
|
94 |
if (obj == null) return false; |
|
95 |
return getClass().equals(obj.getClass()); |
|
96 |
} |
|
97 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/gui/layerproperties/DefaultLabeling.java | ||
---|---|---|
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.labeling.gui.layerproperties; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.FlowLayout; |
|
28 |
import java.awt.IllegalComponentStateException; |
|
29 |
import java.awt.Rectangle; |
|
30 |
import java.awt.event.ActionEvent; |
|
31 |
import java.awt.event.ActionListener; |
|
32 |
import java.awt.event.ItemEvent; |
|
33 |
import java.awt.event.ItemListener; |
|
34 |
import java.beans.PropertyChangeEvent; |
|
35 |
|
|
36 |
import javax.swing.JButton; |
|
37 |
import javax.swing.JCheckBox; |
|
38 |
import javax.swing.JPanel; |
|
39 |
import javax.swing.JSplitPane; |
|
40 |
|
|
41 |
import org.gvsig.andami.messages.NotificationManager; |
|
42 |
import org.gvsig.app.ApplicationLocator; |
|
43 |
import org.gvsig.fmap.dal.exception.DataException; |
|
44 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
45 |
import org.gvsig.fmap.dal.feature.Feature; |
|
46 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
48 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
49 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
|
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
|
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
|
52 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
|
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints; |
|
54 |
import org.gvsig.gui.beans.swing.JBlank; |
|
55 |
import org.gvsig.i18n.Messages; |
|
56 |
import org.gvsig.labeling.gui.styling.LayerPreview; |
|
57 |
import org.gvsig.labeling.label.GeneralLabelingStrategy; |
|
58 |
import org.gvsig.labeling.lang.LabelClassUtils; |
|
59 |
import org.gvsig.symbology.SymbologyLocator; |
|
60 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.DefaultLabelingMethod; |
|
61 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
62 |
import org.slf4j.Logger; |
|
63 |
import org.slf4j.LoggerFactory; |
|
64 |
|
|
65 |
|
|
66 |
public class DefaultLabeling extends AbstractLabelingMethodPanel implements ActionListener { |
|
67 |
|
|
68 |
private static final Logger logger = |
|
69 |
LoggerFactory.getLogger(DefaultLabeling.class); |
|
70 |
|
|
71 |
private static final long serialVersionUID = 7100208944546698724L; |
|
72 |
private ILabelClass defaultLabel; |
|
73 |
private IPlacementConstraints placementConstraints; |
|
74 |
private LayerPreview layerPrev; |
|
75 |
private JCheckBox enableLayerPrev; |
|
76 |
private LabelClassPreview labelPrev; |
|
77 |
private JButton btnProperties; |
|
78 |
|
|
79 |
private FeatureAttributeDescriptor[] fieldDescs; |
|
80 |
|
|
81 |
private boolean allowOverlap; |
|
82 |
private IZoomConstraints zoomConstraints; |
|
83 |
private LabelClassProperties lcProp; |
|
84 |
|
|
85 |
public Class<? extends ILabelingMethod> getLabelingMethodClass() { |
|
86 |
return DefaultLabelingMethod.class; |
|
87 |
} |
|
88 |
|
|
89 |
|
|
90 |
public String getName() { |
|
91 |
return Messages.getText("label_features_in_the_same_way") + "."; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public void fillPanel(ILabelingMethod method, FeatureType fty) { |
|
96 |
try { |
|
97 |
if (enableLayerPrev.isSelected()) { |
|
98 |
layerPrev.setLayer(layer); |
|
99 |
} else { |
|
100 |
layerPrev.setLayer(null); |
|
101 |
} |
|
102 |
|
|
103 |
fieldDescs = fty.getAttributeDescriptors(); |
|
104 |
|
|
105 |
ILabelingStrategy labeling = layer.getLabelingStrategy(); |
|
106 |
if (!(labeling instanceof GeneralLabelingStrategy)) { |
|
107 |
labeling = new GeneralLabelingStrategy(); |
|
108 |
labeling.setLayer(layer); |
|
109 |
layer.setLabelingStrategy(labeling); |
|
110 |
} |
|
111 |
|
|
112 |
} catch (Exception e) { |
|
113 |
NotificationManager.addWarning(e.getMessage(), e); |
|
114 |
} |
|
115 |
|
|
116 |
ILabelClass lc = null; |
|
117 |
if (method.getLabelClasses() != null && method.getLabelClasses().length > 0) { |
|
118 |
lc = method.getLabelClasses()[0]; |
|
119 |
} else { |
|
120 |
lc = SymbologyLocator.getSymbologyManager().createDefaultLabel(); |
|
121 |
} |
|
122 |
setLabel(lc); |
|
123 |
getLcProp(); |
|
124 |
} |
|
125 |
|
|
126 |
private JButton getBtnProperties(){ |
|
127 |
if (btnProperties == null){ |
|
128 |
btnProperties = new JButton(Messages.getText("properties")); |
|
129 |
btnProperties.addActionListener(this); |
|
130 |
} |
|
131 |
return btnProperties; |
|
132 |
} |
|
133 |
|
|
134 |
private LabelClassPreview getLabelPrev(){ |
|
135 |
if (labelPrev == null){ |
|
136 |
labelPrev = new LabelClassPreview(); |
|
137 |
} |
|
138 |
return labelPrev; |
|
139 |
} |
|
140 |
|
|
141 |
private JCheckBox getEnableLayerPreview(){ |
|
142 |
if(enableLayerPrev == null){ |
|
143 |
enableLayerPrev = new JCheckBox( |
|
144 |
Messages.getText("Enable_layer_preview")); |
|
145 |
enableLayerPrev.addItemListener(new ItemListener() { |
|
146 |
|
|
147 |
public void itemStateChanged(ItemEvent e) { |
|
148 |
try { |
|
149 |
if (e.getStateChange()==ItemEvent.SELECTED) { |
|
150 |
layerPrev.setLayer(layer); |
|
151 |
} |
|
152 |
else if (e.getStateChange()==ItemEvent.DESELECTED) { |
|
153 |
layerPrev.setLayer(null); |
|
154 |
} |
|
155 |
} catch (ReadException e1) { |
|
156 |
logger.error("While setting changing layer in preview", e1); |
|
157 |
} |
|
158 |
} |
|
159 |
}); |
|
160 |
} |
|
161 |
return enableLayerPrev; |
|
162 |
} |
|
163 |
|
|
164 |
private LayerPreview getLayerPreview(){ |
|
165 |
if (layerPrev == null){ |
|
166 |
layerPrev = new LayerPreview(); |
|
167 |
} |
|
168 |
return layerPrev; |
|
169 |
} |
|
170 |
@Override |
|
171 |
protected void initializePanel() { |
|
172 |
setLayout(new BorderLayout()); |
|
173 |
JSplitPane scrl = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
|
174 |
scrl.add(getLayerPreview(), JSplitPane.LEFT); |
|
175 |
|
|
176 |
labelPrev = getLabelPrev(); //new LabelClassPreview(); |
|
177 |
JPanel aux = new JPanel(new BorderLayout()); |
|
178 |
aux.add(new JBlank(10, 10), BorderLayout.NORTH ); |
|
179 |
aux.add(new JBlank(10, 10), BorderLayout.WEST ); |
|
180 |
aux.add(labelPrev, BorderLayout.CENTER); |
|
181 |
aux.add(new JBlank(10, 10), BorderLayout.EAST ); |
|
182 |
JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); |
|
183 |
btnProperties = getBtnProperties(); |
|
184 |
aux2.add(btnProperties); |
|
185 |
// btnProperties.addActionListener(this); |
|
186 |
aux.add(aux2, BorderLayout.SOUTH); |
|
187 |
scrl.add(aux, JSplitPane.RIGHT); |
|
188 |
add(scrl, BorderLayout.CENTER); |
|
189 |
scrl.setDividerLocation(500); |
|
190 |
|
|
191 |
getEnableLayerPreview().setSelected(false); |
|
192 |
add(enableLayerPrev, BorderLayout.SOUTH); |
|
193 |
} |
|
194 |
|
|
195 |
private LabelClassProperties getLcProp(){ |
|
196 |
if(lcProp == null) { |
|
197 |
|
|
198 |
int n = this.fieldDescs.length; |
|
199 |
String[] fnames = new String[n]; |
|
200 |
int[] ftypes = new int[n]; |
|
201 |
for (int i=0; i<n; i++) { |
|
202 |
fnames[i] = fieldDescs[i].getName(); |
|
203 |
ftypes[i] = fieldDescs[i].getType(); |
|
204 |
} |
|
205 |
lcProp = new LabelClassProperties(this.layer.getFeatureStore()); |
|
206 |
lcProp.setLabelClass(method.getLabelClasses()[0]); |
|
207 |
} |
|
208 |
return lcProp; |
|
209 |
|
|
210 |
} |
|
211 |
|
|
212 |
public void actionPerformed(ActionEvent e) { |
|
213 |
if (e.getSource().equals(getBtnProperties())) { |
|
214 |
// LabelClassProperties lcProp = new LabelClassProperties(fieldNames, fieldTypes); |
|
215 |
// lcProp.setLabelClass(method.getLabelClasses()[0]); |
|
216 |
// PluginServices.getMDIManager().addWindow(lcProp); |
|
217 |
// setLabel(lcProp.getLabelClass()); |
|
218 |
LabelClassProperties lcProp = getLcProp(); |
|
219 |
ILabelClass lc = defaultLabel; |
|
220 |
lcProp.setLabelClass(lc); |
|
221 |
boolean eval = false; |
|
222 |
while (!eval){ |
|
223 |
|
|
224 |
ApplicationLocator.getManager().getUIManager().addWindow(lcProp); |
|
225 |
if(!lcProp.isAccepted()){ break; }; |
|
226 |
lc = lcProp.getLabelClass(); |
|
227 |
eval = checkValidSQL(lc); |
|
228 |
} |
|
229 |
setLabel(lc); |
|
230 |
} |
|
231 |
} |
|
232 |
|
|
233 |
private boolean checkValidSQL(ILabelClass lc){ |
|
234 |
|
|
235 |
String sqlQuery = lc.getSQLQuery(); |
|
236 |
if (sqlQuery != null && sqlQuery.trim().length() > 0) { |
|
237 |
return LabelClassUtils.validExpression( |
|
238 |
sqlQuery, layer.getFeatureStore(), true); |
|
239 |
} else { |
|
240 |
return true; |
|
241 |
} |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
private void setLabel(ILabelClass labelClass) { |
|
246 |
|
|
247 |
defaultLabel = labelClass; |
|
248 |
// defaultLabel = LabelingFactory.createLabelClassFromXML(labelClass.getXMLEntity()); |
|
249 |
labelPrev.setLabelClass(defaultLabel); |
|
250 |
method = newMethodForThePreview(defaultLabel); |
|
251 |
|
|
252 |
updatePreview(); |
|
253 |
|
|
254 |
} |
|
255 |
|
|
256 |
protected ILabelingMethod newMethodForThePreview(ILabelClass defaultLabel) { |
|
257 |
|
|
258 |
ILabelingMethod resp = |
|
259 |
SymbologyLocator.getSymbologyManager().createDefaultLabelingMethod(); |
|
260 |
resp.addLabelClass(defaultLabel); |
|
261 |
return resp; |
|
262 |
} |
|
263 |
|
|
264 |
private void updatePreview() { |
|
265 |
|
|
266 |
ILabelingStrategy stra = layer.getLabelingStrategy(); |
|
267 |
if (method == null){ |
|
268 |
stra.setLabelingMethod(newMethodForThePreview(defaultLabel)); |
|
269 |
} else { |
|
270 |
stra.setLabelingMethod(method); |
|
271 |
} |
|
272 |
// s.setPlacementConstraints(placementConstraints); |
|
273 |
// s.setAllowOverlapping(allowOverlap); |
|
274 |
// s.setZoomConstraints(zoomConstraints); |
|
275 |
|
|
276 |
layer.setIsLabeled(true); |
|
277 |
|
|
278 |
DisposableIterator diter = null; |
|
279 |
FeatureSelection fsel = null; |
|
280 |
|
|
281 |
try { |
|
282 |
diter = layer.getFeatureStore().getFeatureSet().fastIterator(); |
|
283 |
fsel = layer.getFeatureStore().getFeatureSelection(); |
|
284 |
fsel.deselectAll(); |
|
285 |
} catch (DataException de) { |
|
286 |
logger.error("While getting store selection", de); |
|
287 |
return; |
|
288 |
} |
|
289 |
|
|
290 |
long count = 0; |
|
291 |
Feature feat = null; |
|
292 |
while (diter.hasNext() && count < 200) { |
|
293 |
feat = (Feature) diter.next(); |
|
294 |
if (count % 4 == 0) { |
|
295 |
fsel.select(feat); |
|
296 |
} |
|
297 |
count++; |
|
298 |
} |
|
299 |
diter.dispose(); |
|
300 |
|
|
301 |
try { |
|
302 |
Rectangle r = layerPrev.getBounds(); |
|
303 |
r.setLocation(layerPrev.getLocationOnScreen()); |
|
304 |
layerPrev.paintImmediately(r); |
|
305 |
layerPrev.doLayout(); |
|
306 |
} catch (IllegalComponentStateException ex) { |
|
307 |
// this happens when the component is not showing in the |
|
308 |
// screen. If that is the case, then we don't need to do |
|
309 |
// anything. |
|
310 |
} |
|
311 |
|
|
312 |
} |
|
313 |
|
|
314 |
public void propertyChange(PropertyChangeEvent evt) { |
|
315 |
|
|
316 |
String prop = evt.getPropertyName(); |
|
317 |
ILabelingStrategy strat = layer.getLabelingStrategy(); |
|
318 |
|
|
319 |
if (AbstractLabelingMethodPanel.PLACEMENT_CONSTRAINTS.equals(prop)) { |
|
320 |
placementConstraints = (IPlacementConstraints) evt.getNewValue(); |
|
321 |
strat.setPlacementConstraints(placementConstraints); |
|
322 |
} else if ((strat instanceof GeneralLabelingStrategy) && |
|
323 |
AbstractLabelingMethodPanel.ALLOW_OVERLAP.equals(prop)) { |
|
324 |
allowOverlap = (Boolean) evt.getNewValue(); |
|
325 |
((GeneralLabelingStrategy) strat).setAllowOverlapping(allowOverlap); |
|
326 |
} else if (AbstractLabelingMethodPanel.ZOOM_CONSTRAINTS.equals(prop)) { |
|
327 |
zoomConstraints = (IZoomConstraints) evt.getNewValue(); |
|
328 |
strat.setZoomConstraints(zoomConstraints); |
|
329 |
} |
|
330 |
|
|
331 |
updatePreview(); |
|
332 |
} |
|
333 |
|
|
334 |
public void setEnabled(boolean enabled) { |
|
335 |
super.setEnabled(enabled); |
|
336 |
if (layerPrev!=null) { |
|
337 |
layerPrev.setEnabled(enabled); |
|
338 |
}; |
|
339 |
if (labelPrev!=null) { |
|
340 |
labelPrev.setEnabled(enabled); |
|
341 |
}; |
|
342 |
if (btnProperties!=null) { |
|
343 |
btnProperties.setEnabled(enabled); |
|
344 |
}; |
|
345 |
} |
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/gui/layerproperties/FeatureDependent.java | ||
---|---|---|
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.labeling.gui.layerproperties; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.Component; |
|
28 |
import java.awt.Dimension; |
|
29 |
import java.awt.GridLayout; |
|
30 |
import java.awt.event.ActionEvent; |
|
31 |
import java.awt.event.ActionListener; |
|
32 |
import java.awt.event.MouseAdapter; |
|
33 |
import java.awt.event.MouseEvent; |
|
34 |
import java.beans.PropertyChangeEvent; |
|
35 |
|
|
36 |
import javax.swing.AbstractCellEditor; |
|
37 |
import javax.swing.JButton; |
|
38 |
import javax.swing.JCheckBox; |
|
39 |
import javax.swing.JComponent; |
|
40 |
import javax.swing.JLabel; |
|
41 |
import javax.swing.JOptionPane; |
|
42 |
import javax.swing.JPanel; |
|
43 |
import javax.swing.JScrollPane; |
|
44 |
import javax.swing.JTable; |
|
45 |
import javax.swing.ListSelectionModel; |
|
46 |
import javax.swing.event.TableModelEvent; |
|
47 |
import javax.swing.event.TableModelListener; |
|
48 |
import javax.swing.table.DefaultTableModel; |
|
49 |
import javax.swing.table.TableCellEditor; |
|
50 |
import javax.swing.table.TableCellRenderer; |
|
51 |
import javax.swing.table.TableColumnModel; |
|
52 |
|
|
53 |
import org.gvsig.app.ApplicationLocator; |
|
54 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
56 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
57 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
|
58 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
|
59 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
60 |
import org.gvsig.gui.beans.swing.JBlank; |
|
61 |
import org.gvsig.gui.beans.swing.celleditors.BooleanTableCellEditor; |
|
62 |
import org.gvsig.gui.beans.swing.cellrenderers.BooleanTableCellRenderer; |
|
63 |
import org.gvsig.i18n.Messages; |
|
64 |
import org.gvsig.labeling.label.FeatureDependentLabeled; |
|
65 |
import org.gvsig.symbology.SymbologyLocator; |
|
66 |
|
|
67 |
public class FeatureDependent extends AbstractLabelingMethodPanel implements ActionListener{ |
|
68 |
private static final long serialVersionUID = 5493451803343695650L; |
|
69 |
private static int NAME_FIELD_INDEX = 0; |
|
70 |
private static int PREVIEW_FIELD_INDEX = 1; |
|
71 |
private static int FILTER_FIELD_INDEX = 2; |
|
72 |
private static int LABEL_EXPRESSION_FIELD_INDEX = 3; |
|
73 |
private static int VISIBLE_FIELD_INDEX = 4; |
|
74 |
JTable tblClasses = null; |
|
75 |
private JButton btnMoveUpClass; |
|
76 |
private JButton btnAddClass; |
|
77 |
private JCheckBox chkLabel; |
|
78 |
private JCheckBox chkDefinePriorities; |
|
79 |
private JScrollPane scrlPan; |
|
80 |
private boolean openEditor = false; |
|
81 |
private JButton btnMoveDownClass; |
|
82 |
private JButton btnDelClass; |
|
83 |
|
|
84 |
/* |
|
85 |
private String[] fieldNames; |
|
86 |
private int[] fieldTypes; |
|
87 |
*/ |
|
88 |
private JPanel buttonPanel; |
|
89 |
|
|
90 |
@Override |
|
91 |
public String getName() { |
|
92 |
|
|
93 |
return Messages.getText( |
|
94 |
"define_classes_of_features_and_label_each_differently")+"."; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public Class<? extends ILabelingMethod> getLabelingMethodClass() { |
|
99 |
return FeatureDependentLabeled.class; |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
private JCheckBox getChkDefinePriorities() { |
|
104 |
if (chkDefinePriorities == null) { |
|
105 |
chkDefinePriorities = new JCheckBox(Messages.getText("label_priority")); |
|
106 |
chkDefinePriorities.addActionListener(this); |
|
107 |
chkDefinePriorities.setName("CHK_DEFINE_PRIORITIES"); |
|
108 |
} |
|
109 |
return chkDefinePriorities; |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
private JButton getBtnDelClass() { |
|
114 |
if (btnDelClass == null) { |
|
115 |
btnDelClass = new JButton(Messages.getText("delete")); |
|
116 |
btnDelClass.setName("BTNDELCLASS"); |
|
117 |
btnDelClass.addActionListener(this); |
|
118 |
} |
|
119 |
return btnDelClass; |
|
120 |
} |
|
121 |
|
|
122 |
private JButton getBtnAddClass() { |
|
123 |
if (btnAddClass == null) { |
|
124 |
btnAddClass = new JButton(Messages.getText("add")); |
|
125 |
btnAddClass.setName("BTNADDCLASS"); |
|
126 |
btnAddClass.addActionListener(this); |
|
127 |
} |
|
128 |
return btnAddClass; |
|
129 |
} |
|
130 |
|
|
131 |
private JButton getBtnMoveUpClass() { |
|
132 |
if (btnMoveUpClass == null) { |
|
133 |
btnMoveUpClass = new JButton(Messages.getText("move_up")); |
|
134 |
btnMoveUpClass.setName("BTNMOVEUPCLASS"); |
|
135 |
btnMoveUpClass.addActionListener(this); |
|
136 |
} |
|
137 |
return btnMoveUpClass; |
|
138 |
} |
|
139 |
|
|
140 |
private JButton getBtnMoveDownClass() { |
|
141 |
if (btnMoveDownClass == null) { |
|
142 |
btnMoveDownClass = new JButton(Messages.getText("move_down")); |
|
143 |
btnMoveDownClass.setName("BTNMOVEDOWNCLASS"); |
|
144 |
btnMoveDownClass.addActionListener(this); |
|
145 |
} |
|
146 |
return btnMoveDownClass; |
|
147 |
} |
|
148 |
|
|
149 |
private JScrollPane getCenterScrl() { |
|
150 |
|
|
151 |
scrlPan = new JScrollPane(getTblClasses()); |
|
152 |
scrlPan.setPreferredSize(new Dimension(180, 300)); |
|
153 |
|
|
154 |
return scrlPan; |
|
155 |
} |
|
156 |
|
|
157 |
|
|
158 |
private JTable getTblClasses() { |
|
159 |
|
|
160 |
tblClasses = new JTable(new LabelClassTableModel()); |
|
161 |
tblClasses.setRowHeight(50); |
|
162 |
tblClasses.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
163 |
tblClasses.addMouseListener(new MouseAdapter() { |
|
164 |
int prevRow =-1; |
|
165 |
@Override |
|
166 |
public void mouseClicked(MouseEvent e) { |
|
167 |
if (!tblClasses.isEnabled()){ |
|
168 |
return; |
|
169 |
} |
|
170 |
int col = tblClasses.getColumnModel().getColumnIndexAtX(e.getX()); |
|
171 |
int row = (int) ((e.getY()-tblClasses.getLocation().getY()) / tblClasses.getRowHeight()); |
|
172 |
if(!(row > tblClasses.getRowCount()-1 || col > tblClasses.getColumnCount()-1)) |
|
173 |
{ |
|
174 |
openEditor = (row == prevRow && e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2 |
|
175 |
) ; |
|
176 |
prevRow = row; |
|
177 |
if (openEditor) |
|
178 |
tblClasses.editCellAt(row, col); |
|
179 |
} |
|
180 |
} |
|
181 |
}); |
|
182 |
|
|
183 |
tblClasses.getModel().addTableModelListener(new TableModelListener() { |
|
184 |
|
|
185 |
public void tableChanged(TableModelEvent e) { |
|
186 |
if (!tblClasses.isEnabled()){ |
|
187 |
return; |
|
188 |
} |
|
189 |
|
|
190 |
if(e.getColumn() == VISIBLE_FIELD_INDEX){ |
|
191 |
ILabelClass oldLc = (ILabelClass) tblClasses.getValueAt(e.getFirstRow(), PREVIEW_FIELD_INDEX); |
|
192 |
oldLc.setVisible(Boolean.valueOf(tblClasses.getValueAt(e.getFirstRow(), VISIBLE_FIELD_INDEX).toString())); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
}); |
|
197 |
|
|
198 |
TableColumnModel cm = tblClasses.getColumnModel(); |
|
199 |
|
|
200 |
tblClasses.getColumnModel().getColumn(PREVIEW_FIELD_INDEX).setCellRenderer(new TableCellRenderer() { |
|
201 |
|
|
202 |
public Component getTableCellRendererComponent(JTable table, |
|
203 |
Object value, boolean isSelected, boolean hasFocus, |
|
204 |
int row, int column) { |
|
205 |
LabelClassPreview lcPr = new LabelClassPreview(); |
|
206 |
lcPr.setLabelClass((ILabelClass) value); |
|
207 |
return lcPr; |
|
208 |
} |
|
209 |
|
|
210 |
}); |
|
211 |
tblClasses.getColumnModel().getColumn(VISIBLE_FIELD_INDEX).setCellRenderer(new BooleanTableCellRenderer(false)); |
|
212 |
tblClasses.getColumnModel().getColumn(LABEL_EXPRESSION_FIELD_INDEX).setCellRenderer(new TableCellRenderer() { |
|
213 |
public Component getTableCellRendererComponent(JTable table, |
|
214 |
Object value, boolean isSelected, boolean hasFocus, |
|
215 |
int row, int column) { |
|
216 |
String expr = null; |
|
217 |
if (value != null) |
|
218 |
expr = (String) value; |
|
219 |
if (expr == null) |
|
220 |
expr = ""; |
|
221 |
// LabelExpressionParser.tokenFor(LabelExpressionParser.EOEXPR); |
|
222 |
|
|
223 |
// expr = expr.replaceAll(LabelExpressionParser.tokenFor(LabelExpressionParser.EOFIELD), " | "); |
|
224 |
// expr = expr.substring(0, expr.length()-1); |
|
225 |
return new JLabel("<html><p>"+expr+"</p></html>", JLabel.CENTER); |
|
226 |
} |
|
227 |
}); |
|
228 |
|
|
229 |
// the editors |
|
230 |
|
|
231 |
for (int i = 0; i < tblClasses.getColumnModel().getColumnCount(); i++) { |
|
232 |
if (i!= VISIBLE_FIELD_INDEX) { |
|
233 |
tblClasses.getColumnModel().getColumn(i).setCellEditor( |
|
234 |
new LabelClassCellEditor(this.layer.getFeatureStore())); |
|
235 |
} else { |
|
236 |
tblClasses.getColumnModel().getColumn(VISIBLE_FIELD_INDEX). |
|
237 |
setCellEditor(new BooleanTableCellEditor(tblClasses)); |
|
238 |
} |
|
239 |
} |
|
240 |
((DefaultTableModel)tblClasses.getModel()).fireTableDataChanged(); |
|
241 |
repaint(); |
|
242 |
|
|
243 |
return tblClasses; |
|
244 |
} |
|
245 |
|
|
246 |
|
|
247 |
private class LabelClassCellEditor extends AbstractCellEditor implements TableCellEditor { |
|
248 |
|
|
249 |
private static final long serialVersionUID = 6399823783851437400L; |
|
250 |
private FeatureStore fsto = null; |
|
251 |
|
|
252 |
public LabelClassCellEditor(FeatureStore store) { |
|
253 |
fsto = store; |
|
254 |
} |
|
255 |
|
|
256 |
public Component getTableCellEditorComponent( |
|
257 |
JTable table, Object value, boolean isSelected, int row, int column) { |
|
258 |
|
|
259 |
if (openEditor) { |
|
260 |
ILabelClass oldLc = (ILabelClass) tblClasses.getValueAt(row, PREVIEW_FIELD_INDEX); |
|
261 |
oldLc.setVisible(Boolean.valueOf(tblClasses.getValueAt(row, VISIBLE_FIELD_INDEX).toString())); |
|
262 |
LabelClassProperties lcProp = new LabelClassProperties(fsto); |
|
263 |
oldLc.setTexts(new String[] {oldLc.getName()}); |
|
264 |
lcProp.setLabelClass(oldLc); |
|
265 |
|
|
266 |
ApplicationLocator.getManager().getUIManager().addWindow(lcProp); |
|
267 |
ILabelClass newLc = lcProp.getLabelClass(); |
|
268 |
|
|
269 |
LabelClassTableModel m = (LabelClassTableModel) tblClasses.getModel(); |
|
270 |
Boolean changeDone = false; |
|
271 |
|
|
272 |
if (!(oldLc.getName().equals(newLc.getName()))) |
|
273 |
if(!checSameLablClassName(m,newLc.getName())){ |
|
274 |
|
|
275 |
m.setValueAt(newLc.getStringLabelExpression(), row, LABEL_EXPRESSION_FIELD_INDEX); |
|
276 |
m.setValueAt(newLc.getName(), row, NAME_FIELD_INDEX); |
|
277 |
m.setValueAt(newLc, row, PREVIEW_FIELD_INDEX); |
|
278 |
m.setValueAt(newLc.getSQLQuery(), row, FILTER_FIELD_INDEX); |
|
279 |
m.setValueAt(newLc.isVisible(), row, VISIBLE_FIELD_INDEX); |
|
280 |
fireEditingStopped(); //Make the renderer reappear. |
|
281 |
changeDone = true; |
|
282 |
} else { |
|
283 |
JOptionPane.showMessageDialog(tblClasses, |
|
284 |
Messages.getText( |
|
285 |
"cannot_exist_two_label_classes_with_the_same_name") |
|
286 |
+"\n", |
|
287 |
Messages.getText("error"), |
|
288 |
JOptionPane.ERROR_MESSAGE); |
|
289 |
changeDone = true; |
|
290 |
} |
|
291 |
if (!changeDone){ |
|
292 |
m.setValueAt(newLc.getStringLabelExpression(), row, LABEL_EXPRESSION_FIELD_INDEX); |
|
293 |
m.setValueAt(newLc.getName(), row, NAME_FIELD_INDEX); |
|
294 |
m.setValueAt(newLc, row, PREVIEW_FIELD_INDEX); |
|
295 |
m.setValueAt(newLc.getSQLQuery(), row, FILTER_FIELD_INDEX); |
|
296 |
m.setValueAt(newLc.isVisible(), row, VISIBLE_FIELD_INDEX); |
|
297 |
fireEditingStopped(); //Make the renderer reappear. |
|
298 |
changeDone = true; |
|
299 |
} |
|
300 |
} |
|
301 |
|
|
302 |
method.clearAllClasses(); |
|
303 |
ILabelClass[] classes = ((LabelClassTableModel)tblClasses.getModel()).toLabelClassArray(); |
|
304 |
for (int i = 0; i < classes.length; i++) { |
|
305 |
method.addLabelClass(classes[i]); |
|
306 |
} |
|
307 |
|
|
308 |
openEditor = false; |
|
309 |
return null; |
|
310 |
} |
|
311 |
|
|
312 |
public Object getCellEditorValue() { |
|
313 |
return null; |
|
314 |
} |
|
315 |
|
|
316 |
} |
|
317 |
|
|
318 |
|
|
319 |
private boolean checSameLablClassName(LabelClassTableModel mod, String name) { |
|
320 |
for (int i = 0; i < mod.getRowCount(); i++) { |
|
321 |
if(name.equals(mod.getLabelAtRow(i).getName())) |
|
322 |
return true; |
|
323 |
} |
|
324 |
return false; |
|
325 |
} |
|
326 |
|
|
327 |
|
|
328 |
private class LabelClassTableModel extends DefaultTableModel { |
|
329 |
|
|
330 |
private static final long serialVersionUID = -9152998982339430209L; |
|
331 |
Object[][] values; |
|
332 |
|
|
333 |
private String[] classesTableFieldNames = new String[] { |
|
334 |
Messages.getText("name"), |
|
335 |
Messages.getText("preview"), |
|
336 |
Messages.getText("filter"), |
|
337 |
Messages.getText("label_expression"), |
|
338 |
Messages.getText("visible"), |
|
339 |
}; |
|
340 |
|
Also available in: Unified diff