Revision 7149

View differences:

org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
    <modelVersion>4.0.0</modelVersion>
6
    <artifactId>org.gvsig.legend.vectorfilterexpression.app.mainplugin</artifactId>
7
    <name>${project.artifactId}</name>
8
    <version>1.0.180</version>
9

  
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.desktop</artifactId>
13
        <version>2.0.374</version>
14
    </parent>
15

  
16
    <url>https://devel.gvsig.org/redmine/projects/gvsig-base-legends</url>
17

  
18
    <scm>
19
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180</connection>
20
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180</developerConnection>
21
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180</url>
22
    </scm>
23
    <repositories>
24
        <repository>
25
            <id>gvsig-public-http-repository</id>
26
            <name>gvSIG maven public HTTP repository</name>
27
            <url>http://devel.gvsig.org/m2repo/j2se</url>
28
            <releases>
29
                <enabled>true</enabled>
30
                <updatePolicy>daily</updatePolicy>
31
                <checksumPolicy>warn</checksumPolicy>
32
            </releases>
33
            <snapshots>
34
                <enabled>true</enabled>
35
                <updatePolicy>daily</updatePolicy>
36
                <checksumPolicy>warn</checksumPolicy>
37
            </snapshots>
38
        </repository>
39
    </repositories>
40

  
41
    <description>Vector legend: Filter by expression. For each feature, the symbol is only visible if the expression is evaluated to true.</description>
42
    <build>
43

  
44
        <plugins>
45

  
46
            <plugin>
47
                <artifactId>maven-release-plugin</artifactId>
48
                <configuration>
49
                    <tagBase>https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags</tagBase>
50
                </configuration>
51
            </plugin>
52

  
53
        </plugins>
54
    </build>
55
    <dependencies>
56
        <dependency>
57
            <groupId>org.gvsig</groupId>
58
            <artifactId>org.gvsig.app.mainplugin</artifactId>
59
        </dependency>
60
        <dependency>
61
            <groupId>org.gvsig</groupId>
62
            <artifactId>org.gvsig.andami</artifactId>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.symbology.lib.api</artifactId>
67
        </dependency>
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.symbology.lib.impl</artifactId>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.symbology.swing.api</artifactId>
75
        </dependency>
76
        <dependency>
77
            <groupId>org.gvsig</groupId>
78
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
79
        </dependency>
80
        <dependency>
81
            <groupId>org.gvsig</groupId>
82
            <artifactId>org.gvsig.utils</artifactId>
83
        </dependency>
84
        <dependency>
85
            <groupId>org.gvsig</groupId>
86
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
87
        </dependency>
88

  
89
        <dependency>
90
            <groupId>org.gvsig</groupId>
91
            <artifactId>org.gvsig.i18n</artifactId>
92
        </dependency>
93

  
94
        <dependency>
95
            <groupId>org.gvsig</groupId>
96
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
97
        </dependency>
98

  
99
        <dependency>
100
            <groupId>org.gvsig</groupId>
101
            <artifactId>org.gvsig.tools.lib</artifactId>
102
        </dependency>
103
        <dependency>
104
            <groupId>org.gvsig</groupId>
105
            <artifactId>org.gvsig.ui</artifactId>
106
        </dependency>
107
        <dependency>
108
            <groupId>org.gvsig</groupId>
109
            <artifactId>org.gvsig.projection.api</artifactId>
110
        </dependency>
111
        <dependency>
112
            <groupId>org.gvsig</groupId>
113
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
114
        </dependency>
115

  
116
        <dependency>
117
            <groupId>org.gvsig</groupId>
118
            <artifactId>org.gvsig.compat.api</artifactId>
119
        </dependency>
120

  
121
        <dependency>
122
            <groupId>org.gvsig</groupId>
123
            <artifactId>org.gvsig.tools.evaluator.sqljep</artifactId>
124
        </dependency>
125

  
126
        <dependency>
127
            <groupId>org.gvsig</groupId>
128
            <artifactId>org.gvsig.tools.lib</artifactId>
129
            <scope>compile</scope>
130
        </dependency>
131

  
132
        <dependency>
133
            <groupId>org.gvsig</groupId>
134
            <artifactId>org.gvsig.tools.swing.api</artifactId>
135
        </dependency>
136

  
137
        <!--
138
        <dependency>
139
                <groupId>bsf</groupId>
140
                <artifactId>bsf</artifactId>
141
    <scope>compile</scope>
142
        </dependency>
143
        -->
144

  
145
    </dependencies>
146

  
147
    <properties>
148
        <gvsig.package.info.name>Vector legend: Filter by expression</gvsig.package.info.name>
149
        <gvsig.package.info.categories>View,Vector,Symbology</gvsig.package.info.categories>
150
        <gvsig.package.info.official>true</gvsig.package.info.official>
151
        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.1.0-A</gvsig.package.info.dependencies>
152
        <gvsig.package.info.state>testing</gvsig.package.info.state>
153
        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-base-legends/pool</gvsig.package.info.poolURL>
154
    </properties>
155

  
156

  
157
</project>
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180/buildNumber.properties
1
#Mon May 09 01:09:37 CEST 2022
2
buildNumber=185
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180/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
<!-- No dependencies
51
  <dependencySets>
52
    <dependencySet>
53
      <useProjectArtifact>false</useProjectArtifact>
54
      <useTransitiveDependencies>false</useTransitiveDependencies>
55
      <outputDirectory>lib</outputDirectory>
56
      <includes>
57
		<include>...</include>
58
      </includes>
59
    </dependencySet>
60
  </dependencySets>
61
-->
62

  
63
</assembly>
64

  
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180/src/main/java/org/gvsig/symbology/gui/layerproperties/SymbolPickerController.java
1
package org.gvsig.symbology.gui.layerproperties;
2

  
3
import java.awt.Dimension;
4
import java.awt.Graphics2D;
5
import java.awt.Rectangle;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ComponentAdapter;
8
import java.awt.event.ComponentEvent;
9
import java.awt.event.ComponentListener;
10
import java.awt.geom.AffineTransform;
11
import java.awt.image.BufferedImage;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JTextField;
15
import javax.swing.text.JTextComponent;
16
import org.gvsig.andami.ui.mdiManager.MDIManager;
17
import org.gvsig.app.ApplicationLocator;
18
import org.gvsig.app.gui.styling.SymbolSelector;
19
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
20
import org.gvsig.fmap.mapcontext.MapContextLocator;
21
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
22
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
23
import org.gvsig.tools.swing.api.pickercontroller.AbstractPickerController;
24

  
25
/**
26
 *
27
 * @author gvSIG Team
28
 */
29
@SuppressWarnings("UseSpecificCatch")
30
public class SymbolPickerController extends AbstractPickerController<ISymbol> {
31

  
32
  private final JButton btnPreview;
33
  private final JTextComponent txtDescription;
34
  private Dimension previewSize;
35
  private int geomType;
36
  private ISymbol symbol;
37

  
38
  SymbolPickerController(JButton btnPreview, JTextComponent txtDescription, int geomType, ISymbol symbol) {
39
    this.btnPreview = btnPreview;
40
    if( txtDescription==null ) {
41
      this.txtDescription = new JTextField();
42
    } else {
43
      this.txtDescription = txtDescription;
44
    }
45

  
46
    if (symbol == null) {
47
      this.symbol = MapContextLocator.getSymbolManager().createSymbol(geomType);
48
    }
49
    this.previewSize = null;
50
    this.btnPreview.addActionListener((ActionEvent e) -> {
51
      doSelectSymbol();
52
    });
53
    this.btnPreview.addComponentListener(new ComponentAdapter() {
54
      @Override
55
      public void componentResized(ComponentEvent e) {
56
        updatePreview();
57
      }      
58
    });
59
    this.set(this.symbol);
60
  }
61

  
62
  private void updatePreview() {
63
    int width = btnPreview.getWidth();
64
    int height = btnPreview.getHeight();
65
    if( width<5 || height<5 ) {
66
      return;
67
    }
68
    previewSize = new Dimension(width - 4, height - 4);
69
    this.btnPreview.setIcon(
70
            new ImageIcon(this.createPreview(this.previewSize, this.symbol))
71
    );
72
  }
73
  
74
  private BufferedImage createPreview(Dimension size, ISymbol symbol) {
75
    BufferedImage previewImage = new BufferedImage(
76
            size.width,
77
            size.height, 
78
            BufferedImage.TYPE_INT_ARGB
79
    );
80

  
81
    Graphics2D g2 = (Graphics2D) previewImage.createGraphics();
82
    if (g2 != null) {
83
      Rectangle bounds = new Rectangle(size.width, size.height);
84
      ISymbol prevSymbol = symbol;
85
      try {
86
        prevSymbol.drawInsideRectangle(g2, new AffineTransform(), bounds, null);
87
      } catch (Exception e) {
88
          try {
89
            prevSymbol = MapContextLocator.getSymbolManager().getWarningSymbol(
90
                    SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
91
                    symbol.getDescription(),
92
                    SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS
93
            );
94
            prevSymbol.drawInsideRectangle(g2,g2.getTransform(),bounds,null);
95
          } catch (Exception e1) {
96
            LOG.debug("Can't create preview symbol",e1);
97
          }
98
      }
99
    }
100
    return previewImage;
101
  }
102

  
103
  private void doSelectSymbol() {
104
    MDIManager uiManager = ApplicationLocator.getManager().getUIManager();
105
    ISymbolSelector sSelect = SymbolSelector.createSymbolSelector(this.symbol, this.geomType);
106
    uiManager.addWindow(sSelect);
107
    if (sSelect.getSelectedObject() != null) {
108
      this.symbol = (ISymbol) sSelect.getSelectedObject();
109
      this.updatePreview();
110
    }
111
  }
112

  
113
  @Override
114
  public ISymbol get() {
115
    symbol.setDescription(this.txtDescription.getText());
116
    return symbol;
117
  }
118

  
119
  @Override
120
  public final void set(ISymbol symbol) {
121
      this.symbol = symbol;
122
      this.geomType = symbol.getSymbolType();
123
      this.txtDescription.setText(this.symbol.getDescription());
124
      this.updatePreview();
125
  }
126

  
127
  @Override
128
  public void coerceAndSet(Object o) {
129
    this.set((ISymbol) o);
130
  }
131

  
132
  @Override
133
  public void setEnabled(boolean enabled) {
134
    this.btnPreview.setEnabled(enabled);
135
    this.txtDescription.setEnabled(enabled);
136
  }
137

  
138
  @Override
139
  public boolean isEnabled() {
140
    return this.btnPreview.isEnabled();
141
  }
142

  
143
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 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.symbology.gui.layerproperties;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.io.File;
31
import java.io.IOException;
32
import java.util.ArrayList;
33
import java.util.List;
34

  
35
import javax.swing.BoxLayout;
36
import javax.swing.ImageIcon;
37
import javax.swing.JButton;
38
import javax.swing.JCheckBox;
39
import javax.swing.JOptionPane;
40
import javax.swing.JPanel;
41
import org.apache.commons.lang3.StringUtils;
42

  
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

  
46
import org.gvsig.andami.IconThemeHelper;
47
import org.gvsig.app.ApplicationLocator;
48
import org.gvsig.app.project.documents.view.legend.gui.Categories;
49
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
50
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton;
51
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable;
52
import org.gvsig.fmap.dal.exception.ReadException;
53
import org.gvsig.fmap.dal.feature.Feature;
54
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
55
import org.gvsig.fmap.dal.feature.FeatureStore;
56
import org.gvsig.fmap.dal.feature.FeatureType;
57
import org.gvsig.fmap.mapcontext.layers.FLayer;
58
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
59
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
60
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
61
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
62
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
63
import org.gvsig.gui.beans.swing.JBlank;
64
import org.gvsig.i18n.Messages;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
67
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend;
68
import org.gvsig.symbology.swing.SymbologySwingLocator;
69
import org.gvsig.tools.ToolsLocator;
70
import org.gvsig.tools.i18n.I18nManager;
71
import org.gvsig.tools.swing.api.ToolsSwingLocator;
72
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
73
import org.gvsig.tools.swing.api.windowmanager.Dialog;
74
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
75
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
76

  
77
/**
78
 * Implements the JPanel that shows the properties of a
79
 * VectorialFilterExpressionLegend
80
 * in order to allows the user to modify its characteristics
81
 *
82
 * @author gvSIG Team
83
 *
84
 */
85
public class VectorFilterExpressionPanel extends JPanel
86
implements ILegendPanel, ActionListener {
87

  
88
    private static final Logger logger = LoggerFactory.getLogger(
89
        VectorFilterExpressionPanel.class);
90

  
91
	private static final long serialVersionUID = -7187473609965942511L;
92
	private VectorFilterExpressionLegend theLegend;
93
	private VectorFilterExpressionLegend auxLegend;
94
	private ClassifiableVectorial layer;
95
	private PictureFillSymbol previewSymbol;
96
	private JPanel pnlCenter;
97
	private JPanel pnlMovBut;
98
	private SymbolTable symbolTable;
99
	private JButton btnAddExpression;
100
//	private JButton btnModExpression;
101
	private JButton btnRemoveExpression;
102
	private JButton moveUp;
103
	private JButton moveDown;
104
	private int shapeType;
105
	protected JCheckBox chkdefaultvalues = null;
106
	protected JSymbolPreviewButton defaultSymbolPrev;
107
	private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
108
	private UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator.getUsabilitySwingManager();
109

  
110
	/**
111
	 * This is the default constructor
112
	 */
113
	public VectorFilterExpressionPanel() {
114
		super();
115
		initialize();
116
	}
117

  
118

  
119
	/**
120
	 * This method initializes this
121
	 */
122
	private void initialize() {
123

  
124
		pnlCenter = new JPanel();
125
		pnlCenter.setLayout(new BorderLayout());
126

  
127
		JPanel pnlButtons = new JPanel();
128
		btnAddExpression = usabilitySwingManager.createJButton(
129
		    Messages.getText("Anadir"));
130
		btnAddExpression.setActionCommand("NEW_EXPRESSION");
131
		btnAddExpression.addActionListener(this);
132
		pnlButtons.add(btnAddExpression);
133

  
134
//		btnModExpression = usabilitySwingManager.createJButton(
135
//		    Messages.getText("modify_filter_expression"));
136
//		btnModExpression.setActionCommand("MODIFY_EXPRESSION");
137
//		btnModExpression.addActionListener(this);
138
//		pnlButtons.add(btnModExpression);
139

  
140
		btnRemoveExpression = usabilitySwingManager.createJButton(
141
		    Messages.getText("Quitar"));
142
		btnRemoveExpression.setActionCommand("REMOVE");
143
		btnRemoveExpression.addActionListener(this);
144
		pnlButtons.add(btnRemoveExpression);
145
		defaultSymbolPanel.add(getChkDefaultvalues());
146
		pnlCenter.add(defaultSymbolPanel,BorderLayout.NORTH);
147

  
148
		this.setLayout(new BorderLayout());
149
		this.add(pnlCenter, BorderLayout.CENTER);
150
		this.add(pnlButtons, BorderLayout.SOUTH);
151

  
152

  
153
	}
154
	public void getDefaultSymbolPrev(int shapeType) {
155
		if(defaultSymbolPrev == null){
156
			defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
157
			defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
158
			defaultSymbolPanel.add(defaultSymbolPrev,null);
159
		}
160
	}
161

  
162
	public String getDescription() {
163
		return Messages.getText(
164
		    "shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + ".";
165
	}
166

  
167
	public ISymbol getIconSymbol() {
168
		if (previewSymbol == null) {
169
			try {
170
				previewSymbol = new PictureFillSymbol();
171
				previewSymbol.setImage( new File(
172
						this.getClass().getClassLoader().
173
						getResource("images" + File.separator
174
						    + "legend" + File.separator
175
						    + "legend-overview-vectorial-unique-value.png").
176
						getFile()).toURI().toURL());
177
				previewSymbol.getMarkerFillProperties().
178
				setFillStyle(
179
						IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL);
180
			} catch (IOException e) {
181
				return null;
182
			}
183
		}
184
		return previewSymbol;
185
	}
186

  
187
	public ILegend getLegend() {
188
		auxLegend.clear();
189
		fillSymbolListFromTable();
190

  
191
		theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend();
192
		if(defaultSymbolPrev.getSymbol() != null)
193
			theLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol());
194

  
195
		theLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
196
		return theLegend;
197
	}
198
	/**
199
	 * Fills the list of symbols of the legend
200
	 *
201
	 */
202
	private void fillSymbolListFromTable() {
203
		Object clave;
204
		ISymbol theSymbol;
205

  
206
		FLyrVect m = (FLyrVect) layer;
207
		try {
208

  
209
			if(auxLegend.getClassifyingFieldNames() != null) {
210
				String[] fNames= auxLegend.getClassifyingFieldNames();
211
				int[] fieldTypes  = new int[auxLegend.getClassifyingFieldNames().length];
212

  
213
				FeatureStore fsto = (FeatureStore) m.getDataStore();
214
				FeatureType fty = fsto.getDefaultFeatureType();
215

  
216
				for (int i = 0; i < fNames.length; i++) {
217
					fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType();
218
				}
219

  
220
				auxLegend.setClassifyingFieldTypes(fieldTypes);
221
			}
222
		} catch (Exception e) {
223

  
224
		}
225

  
226
		auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
227

  
228
		for (int row = 0; row < symbolTable.getRowCount(); row++) {
229
			clave =  symbolTable.getFieldValue(row, 1);
230
			theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
231
			theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2));
232
			auxLegend.addSymbol(clave, theSymbol);
233
		}
234
		if(chkdefaultvalues.isSelected()){
235
			if(defaultSymbolPrev.getSymbol() != null){
236
				String description = VectorFilterExpressionLegend.I18N_DEFAULT;
237
				defaultSymbolPrev.getSymbol().setDescription(description);
238
				auxLegend.addSymbol(
239
				    description, defaultSymbolPrev.getSymbol());
240
			}
241
		}
242

  
243
	}
244

  
245
	public Class<VectorFilterExpressionLegend> getLegendClass() {
246
		return VectorFilterExpressionLegend.class;
247
	}
248

  
249
	public JPanel getPanel() {
250
		return this;
251
	}
252

  
253
	public Class<Categories> getParentClass() {
254
		return Categories.class;
255
	}
256

  
257
	public String getTitle() {
258
		return Messages.getText("expressions");
259
	}
260

  
261
	public boolean isSuitableFor(FLayer layer) {
262
		FLyrVect lVect = (FLyrVect) layer;
263
		try {
264
			return
265
			    VectorFilterExpressionLegend.isPoint(lVect.getShapeType())
266
			    ||
267
                VectorFilterExpressionLegend.isLinear(lVect.getShapeType())
268
                ||
269
                VectorFilterExpressionLegend.isPolygonal(lVect.getShapeType());
270
		} catch (Exception e) {
271
			return false;
272
		}
273

  
274
	}
275

  
276
	public void setData(FLayer lyr, ILegend legend) {
277
		this.layer = (ClassifiableVectorial) lyr;
278
		shapeType = 0;
279

  
280
		try {
281
			shapeType = this.layer.getGeometryType().getType();
282
		} catch (ReadException e) {
283
		    logger.info("Error while getting layer shp type", e);
284
		    ApplicationLocator.getManager().message(
285
		        Messages.getText("generating_intervals"),
286
		        JOptionPane.ERROR_MESSAGE);
287
		}
288

  
289
		if (symbolTable != null)
290
			pnlCenter.remove(symbolTable);
291
		if (pnlMovBut != null)
292
			pnlCenter.remove(pnlMovBut);
293

  
294
		getDefaultSymbolPrev(shapeType);
295

  
296
		symbolTable = new SymbolTable(this, "expressions", shapeType);
297
    try {
298
      ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor(
299
              ((FLyrVect)layer).getFeatureStore()
300
      );
301
      symbolTable.setCellEditor(cellEditor);
302
    } catch(Exception ex) {
303
      
304
    }
305
		pnlCenter.add(symbolTable, BorderLayout.CENTER);
306
		pnlCenter.add(getPnlMovBut(),BorderLayout.EAST);
307

  
308

  
309
		if (legend instanceof VectorFilterExpressionLegend) {
310

  
311
            auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend();
312
            if (auxLegend.isUseDefaultSymbol()) {
313
                // Default must not be in table
314
                fillTableSkipDefault(auxLegend);
315
            } else {
316
                symbolTable.fillTableFromSymbolList(
317
                    auxLegend.getSymbols(),
318
                    auxLegend.getValues(),
319
                    auxLegend.getDescriptions());
320
            }
321

  
322

  
323
		} else {
324
			auxLegend = new VectorFilterExpressionLegend();
325
			auxLegend.setShapeType(shapeType);
326
		}
327
		defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
328
		getChkDefaultvalues().setSelected(auxLegend.isUseDefaultSymbol());
329
	}
330

  
331
	private JPanel getPnlMovBut() {
332
		if(pnlMovBut == null){
333
			pnlMovBut = new JPanel();
334
			pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS));
335
			pnlMovBut.add(new JBlank(1, 70));
336
			ImageIcon ico = IconThemeHelper.getImageIcon(
337
			    "symbol-layer-move-up");
338
			moveUp = usabilitySwingManager.createJButton(ico);
339
			pnlMovBut.add(moveUp);
340
			moveUp.setSize(new Dimension(15,15));
341
			pnlMovBut.add(new JBlank(1,10));
342
			ico = IconThemeHelper.getImageIcon(
343
                "symbol-layer-move-down");
344
			moveDown = usabilitySwingManager.createJButton(ico);
345
			pnlMovBut.add(moveDown);
346
			pnlMovBut.add(new JBlank(1, 70));
347
			moveDown.setActionCommand("MOVE-DOWN");
348
			moveUp.setActionCommand("MOVE-UP");
349
			moveDown.addActionListener(this);
350
			moveUp.addActionListener(this);
351
		}
352
		return pnlMovBut;
353
	}
354

  
355
	public void actionPerformed(ActionEvent e) {
356

  
357
		int[] indices = null;
358
		Feature dummyFeat = null;
359

  
360
		if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
361
			indices = symbolTable.getSelectedRows();
362
		}
363

  
364
		if(e.getActionCommand() == "MOVE-UP"){
365
			if (indices.length>0) {
366
				int classIndex = indices[0];
367
				int targetPos = Math.max(0, classIndex-1);
368
				symbolTable.moveUpRows(classIndex, targetPos,indices.length);
369
			}
370
		}
371

  
372
		if(e.getActionCommand() == "MOVE-DOWN"){
373
			if (indices.length>0) {
374
				int classIndex = indices[indices.length-1];
375
				int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1);
376
				symbolTable.moveDownRows(classIndex, targetPos,indices.length);
377
			}
378
		}
379

  
380
		if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
381
			ArrayList<String> orders = new ArrayList<String>();
382

  
383
			for (int i = 0; i < symbolTable.getRowCount(); i++) {
384
				orders.add(symbolTable.getFieldValue(i,1).toString());
385
			}
386
      
387
		} if (e.getActionCommand() == "NEW_EXPRESSION") {
388

  
389
		    FLyrVect vect = (FLyrVect) layer;
390
		    final FeatureStore fsto = vect.getFeatureStore();
391
		    final FeatureType fty = fsto.getDefaultFeatureTypeQuietly();
392
		    final int shptype = fty.getDefaultGeometryAttribute().getGeomType().getType();
393
        final I18nManager i18n = ToolsLocator.getI18nManager();
394
        final ExpressionSymbolPanel esp = new ExpressionSymbolPanel(fsto, shptype, previewSymbol);
395
        final WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
396
        final Dialog dialog = windowManager.createDialog(
397
              esp,
398
              i18n.getTranslation("expression_creator"),
399
              "",
400
              WindowManager_v2.BUTTONS_OK_CANCEL
401
        );
402
        dialog.addActionListener((ActionEvent e1) -> {
403
          if( dialog.getAction()!=WindowManager_v2.BUTTON_OK ) {
404
            return;
405
          }
406
          String expr = esp.getExpression();
407
          if ( StringUtils.isBlank(expr) ) {
408
              ApplicationLocator.getManager().messageDialog(
409
                  Messages.getText("error_validating_filter_query"),
410
                  Messages.getText("error"),
411
                  JOptionPane.ERROR_MESSAGE);
412
              return;
413
          }
414
          ISymbol sym = esp.getSymbol();
415
          this.addClassFieldNames(fty);
416

  
417
          auxLegend.addSymbol(expr, sym);
418
          symbolTable.removeAllItems();
419
          fillTableSkipDefault(auxLegend);
420

  
421
          repaint();
422
        });
423
        dialog.show(WindowManager.MODE.DIALOG);
424
//
425
//    }
426
//		else if (e.getActionCommand() == "MODIFY_EXPRESSION") {
427
//
428
//			if(symbolTable.getSelectedRowElements() == null) {
429
//				JOptionPane.showMessageDialog(this,
430
//				    Messages.getText("select_one_row")+".\n");
431
//			} else {
432
//
433
//		         FLyrVect vect = (FLyrVect) layer;
434
//		         FeatureStore fsto = (FeatureStore) vect.getDataStore();
435
//		         FeatureType fty = null;
436
//		         int shptype = 0;
437
//		         try {
438
//		             fty = fsto.getDefaultFeatureType();
439
//		             shptype = vect.getGeometryType().getType();
440
//		             dummyFeat = fsto.createNewFeature(true);
441
//		         } catch (Exception exc) {
442
//		             logger.error(Messages.getText(
443
//		                 "error_trying_to_access_to_the_layer"), exc);
444
//		             return;
445
//		         }
446
//
447
//		        ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0];
448
//                String expression = (String) symbolTable.getSelectedRowElements()[1];
449
//
450
//                EvaluatorWithDescriptions evalu =
451
//                    EvaluatorCreator.getEvaluator(expression);
452
//
453
//                MDIManager mm = ApplicationLocator.getManager().getUIManager();
454
//                ExpressionSymbolPanel esp = new ExpressionSymbolPanel(
455
//                    dummyFeat, evalu, shptype, mySymbol);
456
//                mm.addCentredWindow(esp);
457
//	            /*
458
//	             * esp is modal
459
//	             */
460
//	            if (!esp.isOkPressed()) {
461
//	                return;
462
//	            }
463
//
464
//	            String expr = esp.getExpression();
465
//	            if (expr == null || expr.length() == 0) {
466
//	                ApplicationLocator.getManager().messageDialog(
467
//	                    Messages.getText("error_validating_filter_query"),
468
//	                    Messages.getText("error"),
469
//	                    JOptionPane.ERROR_MESSAGE);
470
//	                return;
471
//	            }
472
//
473
//	            ISymbol sym = esp.getSymbol();
474
////	            evalu = EvaluatorCreator.getEvaluator(expr);
475
//	            // Add all fields in the feature type
476
//	            this.addClassFieldNames(fty);
477
//
478
//	            // Remove old
479
//				auxLegend.delSymbol(expression);
480
//				auxLegend.addSymbol(expr, sym);
481
//				symbolTable.removeAllItems();
482
//				this.fillTableSkipDefault(auxLegend);
483
//
484
//				repaint();
485
//			}
486

  
487
    } else if (e.getActionCommand() == "REMOVE") {
488

  
489
			if(symbolTable.getSelectedRowElements() == null) {
490
				JOptionPane.showMessageDialog(this,
491
				    Messages.getText("select_one_row"));
492
			} else{
493
				String my_expr = (String) symbolTable.getSelectedRowElements()[1];
494
				auxLegend.delSymbol(my_expr);
495
				symbolTable.removeAllItems();
496
				fillTableSkipDefault(auxLegend);
497

  
498
				repaint();
499
			}
500
		}
501
	}
502

  
503

  
504
	private void addClassFieldNames(FeatureType ft) {
505

  
506
	    FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
507
	    String[] nn = new String[atts.length];
508
	    for (int i=0; i<atts.length; i++) {
509
	        nn[i] = atts[i].getName();
510
	    }
511
	    addClassFieldNames(nn);
512
	}
513
	/**
514
	 * Adds new classifying field names to the legend when a new expression is
515
	 * created or an existing one is modified
516
	 * @param fieldNamesExpression
517
	 */
518
	private void addClassFieldNames(String[] fieldNamesExpression) {
519
		boolean appears = false;
520
		ArrayList<String> myFieldNames = new ArrayList<String>();
521

  
522
		if (auxLegend.getClassifyingFieldNames() != null) {
523

  
524
			for (int i = 0; i < auxLegend.getClassifyingFieldNames().length; i++) {
525
				myFieldNames.add(auxLegend.getClassifyingFieldNames()[i]);
526
			}
527
			for (int i = 0; i < fieldNamesExpression.length; i++) {
528
				appears = false;
529
				for (int j = 0; j < auxLegend.getClassifyingFieldNames().length; j++) {
530
					if (auxLegend.getClassifyingFieldNames()[j].compareTo((String) fieldNamesExpression[i]) == 0)
531
						appears = true;
532
				}
533
				if(!appears) {
534
					myFieldNames.add((String) fieldNamesExpression[i]);
535
				}
536
			}
537

  
538
			auxLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new
539
					String[myFieldNames.size()]));
540
		}
541

  
542
		else {
543
			for (int i = 0; i < fieldNamesExpression.length; i++) {
544
				myFieldNames.add((String) fieldNamesExpression[i]);
545
			}
546
			auxLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new
547
					String[myFieldNames.size()]));
548
		}
549
	}
550

  
551

  
552
	public ImageIcon getIcon() {
553
	    ImageIcon ii = IconThemeHelper.getImageIcon(
554
	        "legend-overview-vector-filter-expression");
555
	    return ii;
556
	}
557

  
558
	/**
559
	 * This method initializes chkdefaultvalues
560
	 *
561
	 * @return javax.swing.JCheckBox
562
	 */
563
	protected JCheckBox getChkDefaultvalues() {
564
		if (chkdefaultvalues == null) {
565
			chkdefaultvalues = new JCheckBox();
566
			chkdefaultvalues.setText(Messages.getText("resto_valores")+": ");
567
			chkdefaultvalues.setBounds(new java.awt.Rectangle(342, 26, 141, 20));
568
			chkdefaultvalues.setSelected(false);
569
			chkdefaultvalues.addActionListener(new java.awt.event.ActionListener() {
570
				public void actionPerformed(java.awt.event.ActionEvent e) {
571
					if (chkdefaultvalues.isSelected()) {
572
						auxLegend.useDefaultSymbol(true);
573
					} else {
574
						auxLegend.useDefaultSymbol(false);
575
					}
576
				}
577
			});
578
		}
579

  
580
		return chkdefaultvalues;
581
	}
582

  
583
	private void fillTableSkipDefault(VectorFilterExpressionLegend leg) {
584

  
585
	    Object[] src_expr = leg.getValues();
586
	    List<Integer> rem_ind = new ArrayList<Integer>();
587
	    for (int i=0; i<src_expr.length; i++) {
588
	        if (VectorFilterExpressionLegend.I18N_DEFAULT.
589
	            compareToIgnoreCase((String) src_expr[i]) == 0) {
590
	            rem_ind.add(new Integer(i));
591
	        }
592
	    }
593
        ISymbol[] src_syms = leg.getSymbols();
594
        String[] src_descs = leg.getDescriptions();
595
        // Object[] src_expr
596

  
597
        List<ISymbol> syms = new ArrayList<ISymbol>();
598
        List<Object> vals = new ArrayList<Object>();
599
        List<String> descs = new ArrayList<String>();
600
        for (int i=0; i<src_expr.length; i++) {
601
            if (!isIn(i, rem_ind)) {
602
                syms.add(src_syms[i]);
603
                vals.add(src_expr[i]);
604
                descs.add(src_descs[i]);
605
            }
606
        }
607
	    symbolTable.fillTableFromSymbolList(
608
	        (ISymbol[]) syms.toArray(new ISymbol[0]),
609
            (Object[]) vals.toArray(new Object[0]),
610
            (String[]) descs.toArray(new String[0]));
611
      doUpdateCellEditor();
612
	}
613

  
614
  private void doUpdateCellEditor() {
615
      try {
616
        ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor(
617
                ((FLyrVect)layer).getFeatureStore()
618
        );
619
        symbolTable.setCellEditor(cellEditor);
620
      } catch(Exception ex) {
621
        logger.debug("Can't update cell editors",ex);
622
      }    
623
  }
624

  
625
    /**
626
     * @param i
627
     * @param rem_ind
628
     * @return
629
     */
630
    private boolean isIn(int n, List<Integer> int_list) {
631

  
632
        if (int_list == null || int_list.size() == 0) {
633
            return false;
634
        }
635

  
636
        for (int i=0; i<int_list.size(); i++) {
637
            if (int_list.get(i) instanceof Integer) {
638
                Integer item = (Integer) int_list.get(i);
639
                if (item.intValue() == n) {
640
                    return true;
641
                }
642
            }
643
        }
644
        return false;
645
    }
646

  
647
    public static void selfRegister() {
648
        IconThemeHelper.registerIcon("legend","legend-overview-vector-filter-expression", VectorFilterExpressionPanel.class);
649
        IconThemeHelper.registerIcon("legend","legend-overview-vectorial-unique-value", VectorFilterExpressionPanel.class);
650
        IconThemeHelper.registerIcon("symbol","symbol-layer-move-down", VectorFilterExpressionPanel.class);
651
        IconThemeHelper.registerIcon("symbol","symbol-layer-move-up", VectorFilterExpressionPanel.class);
652
        
653
        
654
        SymbologySwingLocator.getSwingManager().registerLegendEditor(VectorFilterExpressionPanel.class);
655

  
656
//        SymbologySwingLocator.getSwingManager().registerLegendEditor(VectorFilterExpressionPanel2.class);
657

  
658
        
659
        
660
        SymbolTable.addNewCellEditor("expressions",
661
            new ExpressionFieldCellEditor(null));
662
      
663
    }
664
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180/src/main/java/org/gvsig/symbology/gui/layerproperties/ExpressionFieldCellEditor.java
1
/* gvSIG. Sistema de Informaci๏ฟฝn Geogr๏ฟฝfica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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 progra/**
11
 * gvSIG. Desktop Geographic Information System.
12
 *
13
 * Copyright (C) 2007-2020 gvSIG Association.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 3
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28
 * MA  02110-1301, USA.
29
 *
30
 * For any additional information, do not hesitate to contact us
31
 * at info AT gvsig.com, or visit our website www.gvsig.com.
32
 */
33
package org.gvsig.symbology.gui.layerproperties;
34

  
35
import java.awt.Component;
36
import javax.swing.AbstractCellEditor;
37

  
38
import javax.swing.JTable;
39
import javax.swing.table.TableCellEditor;
40
import org.gvsig.expressionevaluator.Expression;
41
import org.gvsig.expressionevaluator.ExpressionUtils;
42
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
43
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
44
import org.gvsig.expressionevaluator.swing.JExpressionPicker;
45
import org.gvsig.fmap.dal.feature.FeatureStore;
46
import org.gvsig.fmap.dal.swing.DALSwingLocator;
47
import org.gvsig.fmap.dal.swing.DataSwingManager;
48

  
49
/**
50
 * Cell Editor for expressions. It controls the edition events in an expression
51
 * column of the table
52
 *
53
 * @author gvSIG Team
54
 */
55
public class ExpressionFieldCellEditor 
56
        extends AbstractCellEditor
57
        implements TableCellEditor 
58
  {
59

  
60
  private final JExpressionPicker picker;
61

  
62
	public ExpressionFieldCellEditor(FeatureStore store) {
63
    ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager();
64
    this.picker = manager.createJExpressionPicker();
65
    if( store != null ) {
66
      DataSwingManager dataSwingManager = DALSwingLocator.getManager();    
67
      dataSwingManager.configureExpressionBuilder(picker, store);  
68
    }
69
	}
70

  
71
  @Override
72
  public Object getCellEditorValue() {
73
    Expression value = this.picker.getExpression();
74
    if( value == null ) {
75
      return null;
76
    }
77
    return value.getPhrase();
78
  }
79

  
80
  @Override
81
  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
82
    if( value instanceof String ) {
83
      this.picker.setExpression(ExpressionUtils.createExpression((String) value));
84
    } else {
85
      this.picker.setExpression(null);
86
    }
87
    return this.picker.asJComponent();
88
  }
89

  
90

  
91
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.180/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel2.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 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.symbology.gui.layerproperties;
25

  
26
import java.awt.event.ActionEvent;
27
import java.io.File;
28
import java.io.IOException;
29
import java.net.URL;
30
import java.util.ArrayList;
31
import java.util.Arrays;
32
import java.util.List;
33

  
34
import javax.swing.ImageIcon;
35
import javax.swing.JOptionPane;
36
import javax.swing.JPanel;
37
import org.apache.commons.lang3.StringUtils;
38

  
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

  
42
import org.gvsig.andami.IconThemeHelper;
43
import org.gvsig.app.ApplicationLocator;
44
import org.gvsig.app.project.documents.view.legend.gui.Categories;
45
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
46
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable;
47
import org.gvsig.fmap.dal.exception.ReadException;
48
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
49
import org.gvsig.fmap.dal.feature.FeatureStore;
50
import org.gvsig.fmap.dal.feature.FeatureType;
51
import org.gvsig.fmap.mapcontext.layers.FLayer;
52
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
53
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
54
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
55
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
56
import org.gvsig.i18n.Messages;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
59
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend;
60
import org.gvsig.tools.ToolsLocator;
61
import org.gvsig.tools.i18n.I18nManager;
62
import org.gvsig.tools.swing.api.ToolsSwingLocator;
63
import org.gvsig.tools.swing.api.ToolsSwingManager;
64
import org.gvsig.tools.swing.api.windowmanager.Dialog;
65
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
66
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
67

  
68
/**
69
 * Implements the JPanel that shows the properties of a
70
 * VectorialFilterExpressionLegend in order to allows the user to modify its
71
 * characteristics
72
 *
73
 * @author gvSIG Team
74
 *
75
 */
76
@SuppressWarnings("UseSpecificCatch")
77
public class VectorFilterExpressionPanel2
78
        extends VectorFilterExpressionPanelView
79
        implements ILegendPanel {
80

  
81
  private static final Logger LOGGER = LoggerFactory.getLogger(VectorFilterExpressionPanel2.class);
82

  
83
  private VectorFilterExpressionLegend theLegend;
84
  private VectorFilterExpressionLegend auxLegend;
85
  private ClassifiableVectorial layer;
86
  private PictureFillSymbol previewSymbol;
87
  private SymbolTable symbolTable;
88
  private int shapeType;
89
  private SymbolPickerController defaultSymbolPrev;
90

  
91
  /**
92
   * This is the default constructor
93
   */
94
  public VectorFilterExpressionPanel2() {
95
    super();
96
    initComponents();
97
  }
98

  
99
  /**
100
   * This method initializes this
101
   */
102
  private void initComponents() {
103
    ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
104
    
105
    toolsSwingManager.translate(this.btnAdd);
106
    toolsSwingManager.translate(this.btnRemove);
107
    toolsSwingManager.translate(this.btnRemoveAll);
108
    toolsSwingManager.translate(this.btnDown);
109
    toolsSwingManager.translate(this.btnUp);
110
    toolsSwingManager.translate(this.chkDefaultValues);
111
    
112
    this.defaultSymbolPrev = new SymbolPickerController(
113
            this.btnDefaultValuesPreview, 
114
            null, 
115
            shapeType, 
116
            null
117
    );
118

  
119
    this.btnUp.setIcon(IconThemeHelper.getImageIcon("symbol-layer-move-up"));
120
    this.btnDown.setIcon(IconThemeHelper.getImageIcon("symbol-layer-move-down"));
121

  
122
    this.btnUp.setText("");
123
    this.btnDown.setText("");
124
    
125
    this.btnUp.addActionListener((ActionEvent e) -> {
126
      doUp();
127
    });
128
    this.btnDown.addActionListener((ActionEvent e) -> {
129
      doDown();
130
    });
131
    this.btnAdd.addActionListener((ActionEvent e) -> {
132
      doAdd();
133
    });
134
    this.btnRemove.addActionListener((ActionEvent e) -> {
135
      doRemove();
136
    });
137
    this.btnRemoveAll.addActionListener((ActionEvent e) -> {
138
      doRemoveAll();
139
    });
140
  }
141

  
142
  @Override
143
  public String getDescription() {
144
    return Messages.getText(
145
            "shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + ".";
146
  }
147

  
148
  public ISymbol getIconSymbol() {
149
    if (previewSymbol == null) {
150
      try {
151
        previewSymbol = new PictureFillSymbol();
152
        URL resource = this.getClass().getClassLoader().getResource("images/legend/legend-overview-vectorial-unique-value.png");
153
        if( resource == null ) {
154
          return null;
155
        }
156
        previewSymbol.setImage(resource);
157
        previewSymbol.getMarkerFillProperties().setFillStyle(
158
                IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL
159
        );
160
      } catch (IOException e) {
161
        return null;
162
      }
163
    }
164
    return previewSymbol;
165
  }
166

  
167
  @Override
168
  public ILegend getLegend() {
169
    auxLegend.clear();
170
    fillSymbolListFromTable();
171

  
172
    theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend();
173
    if (defaultSymbolPrev.get() != null) {
174
      theLegend.setDefaultSymbol(defaultSymbolPrev.get());
175
    }
176
    theLegend.useDefaultSymbol(chkDefaultValues.isSelected());
177
    return theLegend;
178
  }
179

  
180
  /**
181
   * Fills the list of symbols of the legend
182
   */
183
  private void fillSymbolListFromTable() {
184
    Object clave;
185
    ISymbol theSymbol;
186

  
187
    FLyrVect m = (FLyrVect) layer;
188
    try {
189

  
190
      if (auxLegend.getClassifyingFieldNames() != null) {
191
        String[] fNames = auxLegend.getClassifyingFieldNames();
192
        int[] fieldTypes = new int[auxLegend.getClassifyingFieldNames().length];
193

  
194
        FeatureStore fsto = (FeatureStore) m.getDataStore();
195
        FeatureType fty = fsto.getDefaultFeatureType();
196

  
197
        for (int i = 0; i < fNames.length; i++) {
198
          fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType();
199
        }
200

  
201
        auxLegend.setClassifyingFieldTypes(fieldTypes);
202
      }
203
    } catch (Exception e) {
204

  
205
    }
206

  
207
    auxLegend.useDefaultSymbol(chkDefaultValues.isSelected());
208

  
209
    for (int row = 0; row < symbolTable.getRowCount(); row++) {
210
      clave = symbolTable.getFieldValue(row, 1);
211
      theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
212
      theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2));
213
      auxLegend.addSymbol(clave, theSymbol);
214
    }
215
    if (chkDefaultValues.isSelected()) {
216
      if (defaultSymbolPrev.get() != null) {
217
        String description = VectorFilterExpressionLegend.I18N_DEFAULT;
218
        defaultSymbolPrev.get().setDescription(description);
219
        auxLegend.addSymbol(
220
                description, defaultSymbolPrev.get());
221
      }
222
    }
223

  
224
  }
225

  
226
  @Override
227
  public Class<VectorFilterExpressionLegend> getLegendClass() {
228
    return VectorFilterExpressionLegend.class;
229
  }
230

  
231
  @Override
232
  public JPanel getPanel() {
233
    return this;
234
  }
235

  
236
  @Override
237
  public Class<Categories> getParentClass() {
238
    return Categories.class;
239
  }
240

  
241
  @Override
242
  public String getTitle() {
243
    return Messages.getText("expressions");
244
  }
245

  
246
  @Override
247
  public boolean isSuitableFor(FLayer layer) {
248
    FLyrVect lVect = (FLyrVect) layer;
249
    try {
250
      return VectorFilterExpressionLegend.isPoint(lVect.getShapeType())
251
              || VectorFilterExpressionLegend.isLinear(lVect.getShapeType())
252
              || VectorFilterExpressionLegend.isPolygonal(lVect.getShapeType());
253
    } catch (Exception e) {
254
      return false;
255
    }
256

  
257
  }
258

  
259
  @Override
260
  public void setData(FLayer lyr, ILegend legend) {
261
    this.layer = (ClassifiableVectorial) lyr;
262
    shapeType = 0;
263

  
264
    try {
265
      shapeType = this.layer.getGeometryType().getType();
266
    } catch (ReadException e) {
267
      LOGGER.warn("Error while getting layer shp type", e);
268
      ApplicationLocator.getManager().message(
269
              Messages.getText("generating_intervals"),
270
              JOptionPane.ERROR_MESSAGE);
271
    }
272

  
273
    this.defaultSymbolPrev = new SymbolPickerController(this.btnDefaultValuesPreview, null, shapeType, null);
274

  
275
    symbolTable = new SymbolTable(this.tblSymbols, this, "expressions", shapeType);
276
    doUpdateCellEditor();
277
    if (legend instanceof VectorFilterExpressionLegend) {
278

  
279
      auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend();
280
      if (auxLegend.isUseDefaultSymbol()) {
281
        // Default must not be in table
282
        fillTableSkipDefault(auxLegend);
283
      } else {
284
        symbolTable.fillTableFromSymbolList(
285
                auxLegend.getSymbols(),
286
                auxLegend.getValues(),
287
                auxLegend.getDescriptions());
288
      }
289

  
290
    } else {
291
      auxLegend = new VectorFilterExpressionLegend();
292
      auxLegend.setShapeType(shapeType);
293
    }
294
    defaultSymbolPrev.set(auxLegend.getDefaultSymbol());
295
    this.chkDefaultValues.setSelected(auxLegend.isUseDefaultSymbol());
296
  }
297
  
298
  private void doUpdateCellEditor() {
299
      try {
300
        ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor(
301
                ((FLyrVect)layer).getFeatureStore()
302
        );
303
        symbolTable.setCellEditor(cellEditor);
304
      } catch(Exception ex) {
305
        LOGGER.debug("Can't update cell editors",ex);
306
      }    
307
  }
308

  
309

  
310
  private void doUp() {
311
    int[] indices = symbolTable.getSelectedRows();
312
    if (indices.length > 0) {
313
      int classIndex = indices[0];
314
      int targetPos = Math.max(0, classIndex - 1);
315
      symbolTable.moveUpRows(classIndex, targetPos, indices.length);
316
    }
317
  }
318

  
319
  private void doDown() {
320
    int[] indices = symbolTable.getSelectedRows();
321
    if (indices.length > 0) {
322
      int classIndex = indices[indices.length - 1];
323
      int targetPos = Math.min(symbolTable.getRowCount() - 1, classIndex + 1);
324
      symbolTable.moveDownRows(classIndex, targetPos, indices.length);
325
    }
326

  
327
  }
328

  
329
  private void doAdd() {
330
    FLyrVect vect = (FLyrVect) layer;
331
    final FeatureStore fsto = vect.getFeatureStore();
332
    final FeatureType fty = fsto.getDefaultFeatureTypeQuietly();
333
    final int shptype = fty.getDefaultGeometryAttribute().getGeomType().getType();
334
    final I18nManager i18n = ToolsLocator.getI18nManager();
335
    final ExpressionSymbolPanel esp = new ExpressionSymbolPanel(fsto, shptype, previewSymbol);
336
    final WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
337
    final Dialog dialog = windowManager.createDialog(
338
            esp,
339
            i18n.getTranslation("expression_creator"),
340
            "",
341
            WindowManager_v2.BUTTONS_OK_CANCEL
342
    );
343
    dialog.addActionListener((ActionEvent e1) -> {
344
      if (dialog.getAction() != WindowManager_v2.BUTTON_OK) {
345
        return;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff