Revision 37472

View differences:

tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.app.document.layout.app</artifactId>
7
	<packaging>pom</packaging>
8
	<version>2.0.0-SNAPSHOT</version>
9
    <name>Layout document plugins</name>
10
    <description>Layout document plugins</description>
11
	<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.app.document.layout.app/${project.version}/org.gvsig.app.document.layout.app</url>
12
	<parent>
13
		<groupId>org.gvsig</groupId>
14
		<artifactId>org.gvsig.maven.base.extension.pom</artifactId>
15
		<version>1.0.8-SNAPSHOT</version>
16
	</parent>
17

  
18
    <scm>
19
        <connection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-desktop/branches/extensions/org.gvsig.app.document.layout.app</connection>
20
        <developerConnection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-desktop/branches/extensions/org.gvsig.app.document.layout.app</developerConnection>
21
        <url>https://forge.osor.eu/plugins/scmsvn/viewcvs.php/branches/extensions/org.gvsig.app.document.layout.app?root=gvsig-desktop</url>
22
    </scm>
23

  
24
	<developers>
25
		<developer>
26
			<id>jjdelcerro</id>
27
			<name>Joaqu?n Jos? del Cerro</name>
28
			<email>jjdelcerro@gvsig.org</email>
29
			<roles>
30
				<role>Architect</role>
31
				<role>Developer</role>
32
			</roles>
33
		</developer>
34
		<developer>
35
			<id>cordinyana</id>
36
			<name>C?sar Ordi?ana</name>
37
			<email>cordinyana@gvsig.com</email>
38
			<roles>
39
				<role>Architect</role>
40
				<role>Developer</role>
41
			</roles>
42
		</developer>
43
	</developers>
44

  
45
	<distributionManagement>
46
		<site>
47
			<id>gvsig-repository</id>
48
			<url>scp://shell.forge.osor.eu/home/groups/gvsig-desktop/www/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.app.document.layout.app/${project.version}/basic/org.gvsig.app.document.layout.app</url>
49
		</site>
50
	</distributionManagement>
51
	<repositories>
52
		<repository>
53
			<id>gvsig-public-http-repository</id>
54
			<name>gvSIG maven public HTTP repository</name>
55
			<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository</url>
56
			<releases>
57
				<enabled>true</enabled>
58
				<updatePolicy>daily</updatePolicy>
59
				<checksumPolicy>warn</checksumPolicy>
60
			</releases>
61
			<snapshots>
62
				<enabled>true</enabled>
63
				<updatePolicy>daily</updatePolicy>
64
				<checksumPolicy>warn</checksumPolicy>
65
			</snapshots>
66
		</repository>
67
	</repositories>
68
	<build>
69
		<plugins>
70
			<plugin>
71
				<groupId>org.apache.maven.plugins</groupId>
72
				<artifactId>maven-release-plugin</artifactId>
73
				<configuration>
74
					<tagBase>https://svn.forge.osor.eu/svn/gvsig-desktop/tags</tagBase>
75
				</configuration>
76
			</plugin>
77
		</plugins>
78
	</build>
79
	<dependencyManagement>
80
		<dependencies>
81
			<dependency>
82
				<groupId>org.gvsig</groupId>
83
				<artifactId>org.gvsig.core.maven.dependencies</artifactId>
84
				<version>2.0.1-SNAPSHOT</version>
85
				<type>pom</type>
86
				<scope>import</scope>
87
			</dependency>
88
			<dependency>
89
				<groupId>org.gvsig</groupId>
90
				<artifactId>org.gvsig.andami</artifactId>
91
				<version>2.0-SNAPSHOT</version>
92
				<scope>compile</scope>
93
			</dependency>
94
			<dependency>
95
				<groupId>org.gvsig</groupId>
96
				<artifactId>org.gvsig.app</artifactId>
97
				<version>2.0-SNAPSHOT</version>
98
				<scope>compile</scope>
99
			</dependency>
100
		</dependencies>
101
	</dependencyManagement>
102
	<modules>
103
		<module>org.gvsig.app.document.layout.app.mainplugin</module>
104
	</modules>
105
	<properties>
106
		<package.info.state>alpha2</package.info.state>
107
	</properties>
108
</project>
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed Nov 23 09:47:49 CET 2011
3
buildNumber=8
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.app.document.layout">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/PrintPropertiesPage.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.gui.preferencespage;
23

  
24
import java.awt.Dimension;
25
import java.awt.GridLayout;
26

  
27
import javax.swing.ButtonGroup;
28
import javax.swing.ImageIcon;
29
import javax.swing.JCheckBox;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JRadioButton;
33
import javax.swing.JTextField;
34

  
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.andami.preferences.AbstractPreferencePage;
37
import org.gvsig.andami.preferences.StoreException;
38

  
39
public class PrintPropertiesPage extends AbstractPreferencePage {
40

  
41
    private static final long serialVersionUID = 5806304468312341691L;
42
    private static final boolean FACTORY_DEFAULT_LANDSCAPED_PAGE = true;
43
    protected static String id = PrintPropertiesPage.class.getName();
44
    private ImageIcon icon;
45
    private JRadioButton rdBtnPortraitPage;
46
    private JRadioButton rdBtnLandscapePage;
47
    private JCheckBox chkCustomMargins;
48
    private JTextField txtTopMargin;
49
    private JTextField txtLeftMargin;
50
    private JTextField txtBottomMargin;
51
    private JTextField txtRightMargin;
52

  
53
    public PrintPropertiesPage() {
54
        super();
55
        setParentID(LayoutPage.class.getName());
56
        icon = PluginServices.getIconTheme().get("prepare-page-icon");
57
        rdBtnPortraitPage =
58
            new JRadioButton(PluginServices.getText(this,
59
                "options.layout.paper_properties.portrait"));
60
        ImageIcon portrait =
61
            PluginServices.getIconTheme().get("portrait-page-setup");
62
        rdBtnLandscapePage =
63
            new JRadioButton(PluginServices.getText(this,
64
                "options.layout.paper_properties.landscaped"));
65
        ImageIcon landscape =
66
            PluginServices.getIconTheme().get("landscape-page-setup");
67

  
68
        ButtonGroup group = new ButtonGroup();
69
        group.add(rdBtnLandscapePage);
70
        group.add(rdBtnPortraitPage);
71

  
72
        JPanel aux = new JPanel(new GridLayout(2, 2, 10, 0));
73
        aux.setPreferredSize(new Dimension(200, 150));
74
        aux.setSize(200, 150);
75
        aux.add(new JLabel(landscape));
76
        aux.add(new JLabel(portrait));
77
        aux.add(rdBtnLandscapePage);
78
        aux.add(rdBtnPortraitPage);
79

  
80
        addComponent(new JLabel(PluginServices.getText(this,
81
            "options.layout.paper_properties.paper_direction")));
82
        addComponent("", aux);
83
        addComponent(chkCustomMargins =
84
            new JCheckBox(PluginServices.getText(this, "personalizar_margenes")));
85

  
86
        JPanel aux2 = new JPanel(new GridLayout(2, 4, 10, 3));
87
        aux2.add(new JLabel(PluginServices.getText(this, "Superior")));
88
        aux2.add(txtTopMargin = new JTextField(10));
89
        aux2.add(new JLabel(PluginServices.getText(this, "Izquierdo")));
90
        aux2.add(txtLeftMargin = new JTextField(10));
91
        aux2.add(new JLabel(PluginServices.getText(this, "Inferior")));
92
        aux2.add(txtBottomMargin = new JTextField(10));
93
        aux2.add(new JLabel(PluginServices.getText(this, "Derecho")));
94
        aux2.add(txtRightMargin = new JTextField(10));
95
        addComponent("", aux2);
96
    }
97

  
98
    public void storeValues() throws StoreException {
99
        // TODO Auto-generated method stub
100

  
101
    }
102

  
103
    public void setChangesApplied() {
104
        // TODO Auto-generated method stub
105

  
106
    }
107

  
108
    public String getID() {
109
        return id;
110
    }
111

  
112
    public String getTitle() {
113
        return PluginServices.getText(this,
114
            "options.layout.paper_properties.title");
115
    }
116

  
117
    public JPanel getPanel() {
118
        return this;
119
    }
120

  
121
    public void initializeValues() {
122
        // TODO Auto-generated method stub
123

  
124
    }
125

  
126
    public void initializeDefaults() {
127
        rdBtnLandscapePage.setSelected(FACTORY_DEFAULT_LANDSCAPED_PAGE);
128
        rdBtnPortraitPage.setSelected(!FACTORY_DEFAULT_LANDSCAPED_PAGE);
129
    }
130

  
131
    public ImageIcon getIcon() {
132
        return icon;
133
    }
134

  
135
    public boolean isValueChanged() {
136
        // TODO Auto-generated method stub
137
        return false;
138
    }
139

  
140
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/LayoutPage.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.gui.preferencespage;
23

  
24
import javax.swing.ImageIcon;
25
import javax.swing.JCheckBox;
26
import javax.swing.JPanel;
27
import javax.swing.JTextField;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.preferences.AbstractPreferencePage;
31
import org.gvsig.andami.preferences.StoreException;
32
import org.gvsig.app.project.ProjectManager;
33
import org.gvsig.app.project.documents.layout.Attributes;
34
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
35
import org.gvsig.utils.XMLEntity;
36

  
37
/**
38
 * Layout preference page where the user can establish default values for
39
 * <ol>
40
 * <li><b>grid horizontal gap</b></li>
41
 * <li><b>grid vertical gap</b></li>
42
 * <li><b>show or hide grid</b></li>
43
 * <li><b>adjust elements to grid</b></li>
44
 * <li><b>show or hide rules</b></li>
45
 * </ol>
46
 * 
47
 * @author jaume dominguez faus - jaume.dominguez@iver.es
48
 * 
49
 */
50
public class LayoutPage extends AbstractPreferencePage {
51

  
52
    private static final long serialVersionUID = -8225970409668105935L;
53
    private static final boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULES = true;
54
    private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true;
55
    private static final double FACTORY_DEFAULT_VERTICAL_GAP = 1;
56
    private static final double FACTORY_DEFAULT_HORIZONTAL_GAP = 1;
57
    private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false;
58
    private static final String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME =
59
        "DefaultShowLayoutGrid";
60
    private static final String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME =
61
        "DefaultEnableLayoutGrid";
62
    private static final String DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME =
63
        "DefaultShowLayoutRules";
64
    private static final String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME =
65
        "DefaultGridVerticalGap";
66
    private static final String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME =
67
        "DefaultGridHorizontalGap";
68
    static String id = LayoutPage.class.getName();;
69
    private ImageIcon icon;
70
    private JCheckBox chkGridEnabled;
71
    private JCheckBox chkShowRules;
72
    private JCheckBox chkShowGrid;
73
    private JTextField txtVGap;
74
    private JTextField txtHGap;
75

  
76
    private static DefaultLayoutManager layoutManager = null;
77

  
78
    /**
79
     * Builds preference page where the user can establish default values for
80
     * <ol>
81
     * <li><b>grid horizontal gap</b></li>
82
     * <li><b>grid vertical gap</b></li>
83
     * <li><b>show or hide grid</b></li>
84
     * <li><b>adjust elements to grid</b></li>
85
     * <li><b>show or hide rules</b></li>
86
     * </ol>
87
     */
88
    public LayoutPage() {
89
        super();
90
        layoutManager =
91
            (DefaultLayoutManager) ProjectManager.getInstance()
92
                .getDocumentManager(DefaultLayoutManager.TYPENAME);
93

  
94
        icon = PluginServices.getIconTheme().get("mapa-icono");
95

  
96
        // horizontal gap text field
97
        addComponent(PluginServices.getText(this, "espaciado_horizontal"),
98
            txtHGap = new JTextField(5));
99

  
100
        // vertical gap text field
101
        addComponent(PluginServices.getText(this, "espaciado_vertical"),
102
            txtVGap = new JTextField(5));
103

  
104
        // show/hide show check
105
        addComponent(chkShowGrid =
106
            new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula")));
107

  
108
        // enable/disable grid
109
        addComponent(chkGridEnabled =
110
            new JCheckBox(PluginServices.getText(this, "malla_activada")));
111

  
112
        // show/hide rules
113
        addComponent(chkShowRules =
114
            new JCheckBox(PluginServices.getText(this, "activar_regla")));
115

  
116
    }
117

  
118
    public void storeValues() throws StoreException {
119
        double hGap, vGap;
120
        boolean gridEnabled, showRules, showGrid;
121
        try {
122
            hGap = Double.parseDouble(txtHGap.getText());
123
            vGap = Double.parseDouble(txtVGap.getText());
124
            gridEnabled = chkGridEnabled.isSelected();
125
            showGrid = chkShowGrid.isSelected();
126
            showRules = chkShowRules.isSelected();
127
        } catch (Exception e) {
128
            throw new StoreException(PluginServices.getText(this,
129
                "invalid_value_for_gap"));
130
        }
131
        layoutManager.setDefaultShowGrid(showGrid);
132
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
133
        layoutManager.setDefaultShowRulers(showRules);
134
        Attributes.setDefaultGridGap(hGap, vGap);
135
        PluginServices ps = PluginServices.getPluginServices(this);
136
        XMLEntity xml = ps.getPersistentXML();
137
        xml.putProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME, hGap);
138
        xml.putProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME, vGap);
139
        xml.putProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME, showGrid);
140
        xml.putProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME, gridEnabled);
141
        xml.putProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME, showRules);
142
    }
143

  
144
    public String getID() {
145
        return id;
146
    }
147

  
148
    public String getTitle() {
149
        return PluginServices.getText(this, "Mapa");
150
    }
151

  
152
    public JPanel getPanel() {
153
        return this;
154
    }
155

  
156
    public void initializeValues() {
157
        PluginServices ps = PluginServices.getPluginServices(this);
158
        XMLEntity xml = ps.getPersistentXML();
159
        double hGap = FACTORY_DEFAULT_HORIZONTAL_GAP;
160
        double vGap = FACTORY_DEFAULT_VERTICAL_GAP;
161
        boolean showGrid = FACTORY_DEFAULT_LAYOUT_GRID_SHOW;
162
        boolean gridEnabled = FACTORY_DEFAULT_LAYOUT_GRID_ENABLE;
163
        boolean showRules = FACTORY_DEFAULT_LAYOUT_ENABLE_RULES;
164
        // horizontal gap
165
        if (xml.contains(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
166
            hGap =
167
                xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME);
168
        }
169
        txtHGap.setText(String.valueOf(hGap));
170

  
171
        // vertical gap
172
        if (xml.contains(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
173
            vGap =
174
                xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME);
175
        }
176
        txtVGap.setText(String.valueOf(vGap));
177

  
178
        // show/hide grid check
179
        if (xml.contains(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
180
            showGrid =
181
                xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME);
182
        }
183
        chkShowGrid.setSelected(showGrid);
184

  
185
        // enable/disable grid check
186
        if (xml.contains(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
187
            gridEnabled =
188
                xml.getBooleanProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME);
189
        }
190
        chkGridEnabled.setSelected(gridEnabled);
191

  
192
        // enable/disable rules
193
        if (xml.contains(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)) {
194
            showRules =
195
                xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME);
196
        }
197
        chkShowRules.setSelected(showRules);
198

  
199
        layoutManager.setDefaultShowGrid(showGrid);
200
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
201
        layoutManager.setDefaultShowRulers(showRules);
202
        Attributes.setDefaultGridGap(hGap, vGap);
203
    }
204

  
205
    public void initializeDefaults() {
206
        txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
207
        txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
208
        chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW);
209
        chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE);
210
        chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES);
211
    }
212

  
213
    public ImageIcon getIcon() {
214
        return icon;
215
    }
216

  
217
    public boolean isValueChanged() {
218
        return super.hasChanged();
219
    }
220

  
221
    public void setChangesApplied() {
222
        setChanged(false);
223
    }
224
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/RectangleAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

  
24
import java.awt.geom.Point2D;
25

  
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

  
29
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
30
import org.gvsig.fmap.geom.Geometry.TYPES;
31
import org.gvsig.fmap.geom.exception.CreateGeometryException;
32
import org.gvsig.fmap.geom.primitive.Surface;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynStruct;
35
import org.gvsig.tools.persistence.PersistenceManager;
36

  
37
/**
38
 * DOCUMENT ME!
39
 * 
40
 * @author Vicente Caballero Navarro
41
 */
42
public class RectangleAdapter extends PolygonAdapter {
43

  
44
    public static final String PERSISTENCE_DEFINITION_NAME = "RectangleAdapter";
45
    private static final Logger logger = LoggerFactory.getLogger(RectangleAdapter.class);
46
    
47
    public RectangleAdapter() {
48
        super();
49
    }
50

  
51
    /**
52
     * DOCUMENT ME!
53
     * 
54
     * @param p
55
     *            DOCUMENT ME!
56
     */
57
    public void obtainShape(Point2D p) {
58
        Point2D[] points = getPoints();
59
        
60
        try {
61
            Surface surface = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
62
            if (points.length > 0) {
63
                surface.addMoveToVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D));
64
            }
65
            if (points.length > 0) {
66
                surface.addVertex(geomManager.createPoint(p.getX(), points[0].getY(), SUBTYPES.GEOM2D));
67
                surface.addVertex(geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D));
68
                surface.addVertex(geomManager.createPoint(points[0].getX(), p.getY(), SUBTYPES.GEOM2D));
69
                surface.addVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D));
70
            }
71
            
72
            setGeometry(surface);
73
        } catch (CreateGeometryException e) {
74
            logger.error("Error creating the circle", e);
75
        }    
76
    }
77

  
78
    public static void registerPersistent() {
79
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
80
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
81
            DynStruct definition =
82
                manager.addDefinition(RectangleAdapter.class,
83
                    PERSISTENCE_DEFINITION_NAME,
84
                    "Recangle Adapter persistence definition", null, null);
85

  
86
            definition.extend(manager
87
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
88
        }
89
    }
90
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/PolygonAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

  
24
import java.awt.geom.Point2D;
25

  
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

  
29
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
30
import org.gvsig.fmap.geom.Geometry.TYPES;
31
import org.gvsig.fmap.geom.exception.CreateGeometryException;
32
import org.gvsig.fmap.geom.primitive.Surface;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynStruct;
35
import org.gvsig.tools.persistence.PersistenceManager;
36

  
37
/**
38
 * DOCUMENT ME!
39
 * 
40
 * @author Vicente Caballero Navarro
41
 */
42
public class PolygonAdapter extends PolyLineAdapter {
43

  
44
    public static final String PERSISTENCE_DEFINITION_NAME = "PolygonAdapter";
45
    private static final Logger logger = LoggerFactory
46
        .getLogger(PolygonAdapter.class);
47

  
48
    public PolygonAdapter() {
49
        super();
50
    }
51

  
52
    /**
53
     * DOCUMENT ME!
54
     * 
55
     * @param p
56
     *            DOCUMENT ME!
57
     */
58
    public void obtainShape(Point2D p) {
59
        Point2D[] points = getPoints();
60
        
61
        try {
62
            Surface surface = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
63
            if (points.length > 0) {
64
                surface.addMoveToVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D));
65
            }
66
            for (int i = 1; i < points.length; i++) {
67
                surface.addVertex(geomManager.createPoint(points[i].getX(), points[i].getY(), SUBTYPES.GEOM2D));
68
            }
69
            if (points.length > 0) {
70
                surface.addVertex(geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D));
71
                surface.addVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D));
72
            }
73

  
74
            setGeometry(surface);
75
        } catch (CreateGeometryException e) {
76
            logger.error("Error creating the circle", e);
77
        }    
78
    }
79
   
80
    public static void registerPersistent() {
81
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
82
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
83
            DynStruct definition =
84
                manager.addDefinition(PolygonAdapter.class,
85
                    PERSISTENCE_DEFINITION_NAME,
86
                    "Polygon Adapter persistence definition", null, null);
87

  
88
            definition.extend(manager
89
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
90
        }
91
    }
92
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/PointAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

  
24
import java.awt.Graphics2D;
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28

  
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

  
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.exception.CreateGeometryException;
34
import org.gvsig.fmap.geom.primitive.Point;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.persistence.PersistenceManager;
38

  
39
/**
40
 * DOCUMENT ME!
41
 * 
42
 * @author Vicente Caballero Navarro
43
 */
44
public class PointAdapter extends PolyLineAdapter {
45

  
46
    public static final String PERSISTENCE_DEFINITION_NAME = "PointAdapter";
47
    private static final Logger logger = LoggerFactory
48
        .getLogger(PointAdapter.class);
49

  
50
    public PointAdapter() {
51
        super();
52
    }
53

  
54
    public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
55

  
56
    }
57

  
58
    public void obtainShape(Point2D p) {
59
        try {
60
            Point point = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);   
61
            setGeometry(point);
62
        } catch (CreateGeometryException e) {
63
            logger.error("Error creating a point", e);
64
        }       
65
    }
66

  
67
    public Rectangle2D getBounds2D() {
68
        Rectangle2D r = getGeometry(new AffineTransform()).getBounds2D();
69
        double w = r.getWidth();
70
        double h = r.getHeight();
71
        double x = r.getX();
72
        double y = r.getY();
73
        boolean modified = false;
74
        if (r.getWidth() < 0.5) {
75
            modified = true;
76
            w = 1;
77
            x = x - 0.25;
78
        }
79
        if (r.getHeight() < 0.5) {
80
            modified = true;
81
            h = 1;
82
            // y=y-0.5;
83
        }
84
        if (modified) {
85
            return new Rectangle2D.Double(x, y, w, h);
86
        }
87
        return r;
88
    }
89

  
90
    public static void registerPersistent() {
91
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
92
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
93
            DynStruct definition =
94
                manager.addDefinition(PointAdapter.class,
95
                    PERSISTENCE_DEFINITION_NAME,
96
                    "Point Adapter persistence definition", null, null);
97

  
98
            definition.extend(manager
99
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
100
        }
101
    }
102
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/GeometryAdapter.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 program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.app.project.documents.layout.geometryadapters;
42

  
43
import java.awt.Graphics2D;
44
import java.awt.geom.AffineTransform;
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47
import java.util.ArrayList;
48
import java.util.Collections;
49
import java.util.List;
50

  
51
import org.gvsig.compat.print.PrintAttributes;
52
import org.gvsig.fmap.geom.Geometry;
53
import org.gvsig.fmap.geom.GeometryLocator;
54
import org.gvsig.fmap.geom.GeometryManager;
55
import org.gvsig.fmap.geom.exception.CreateGeometryException;
56
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
57
import org.gvsig.tools.ToolsLocator;
58
import org.gvsig.tools.dynobject.DynStruct;
59
import org.gvsig.tools.lang.Cloneable;
60
import org.gvsig.tools.persistence.PersistenceManager;
61
import org.gvsig.tools.persistence.Persistent;
62
import org.gvsig.tools.persistence.PersistentState;
63
import org.gvsig.tools.persistence.exception.PersistenceException;
64

  
65
/**
66
 * Abstract adaptor to relate the geometries with the fframes and to be able to
67
 * integrate them in the Layout.
68
 * 
69
 * @author Vicente Caballero Navarro
70
 */
71
public abstract class GeometryAdapter implements Persistent, Cloneable {
72

  
73
    public static final String PERSISTENCE_DEFINITION_NAME = "GeometryAdapter";
74

  
75
    private static final String POINTS_FIELD = "points";
76
    
77
    protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
78

  
79
    private List<Point2D> points = new ArrayList<Point2D>();
80
    private Geometry geometry;
81

  
82
    public GeometryAdapter() {
83
        super();
84
    }
85

  
86
    /**
87
     * Add a point to de geometry.
88
     * 
89
     * @param point
90
     *            Point that is added.
91
     * 
92
     * @return Number of points that contains the geometry.
93
     */
94
    public int addPoint(Point2D point) {
95
        points.add(point);
96

  
97
        return points.size();
98
    }
99

  
100
    /**
101
     * End the creation of the geometry with the last point added.
102
     */
103
    public void end() {
104
        obtainShape((Point2D) points.get(points.size() - 1));
105
    }
106

  
107
    /**
108
     * Adds the GeneralPathX with all the points of the geometry.
109
     * 
110
     * @param gpx
111
     *            GeneralPathX
112
     */
113
    protected void setGeometry(Geometry geometry) {
114
        this.geometry = geometry;
115
    }
116

  
117
    /**
118
     * Obtains the geometry passing him as parameter the last point.
119
     * 
120
     * @param p
121
     *            Last Point.
122
     * @throws CreateGeometryException 
123
     */
124
    public abstract void obtainShape(Point2D p);
125

  
126
    /**
127
     * Applies the transformation to all the points of the geometry.
128
     * 
129
     * @param at
130
     *            AffineTransform
131
     */
132
    public void applyTransform(AffineTransform at) {
133
        for (int i = 0; i < points.size(); i++) {
134
            at.transform((Point2D) points.get(i), (Point2D) points.get(i));
135
        }
136

  
137
        geometry.transform(at);
138
    }
139

  
140
    /**
141
     * It draws the geometry on the Graphics that is passed like parameter.
142
     * 
143
     * @param g
144
     *            Graphics
145
     * @param at
146
     *            AffineTransform
147
     * @param symbol
148
     *            FSymbol
149
     */
150
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol){
151
        symbol.draw(g, at, geometry, null, null);
152
    }
153

  
154
    /**
155
     * It print the geometry on the Graphics that is passed like parameter.
156
     * 
157
     * @param g
158
     *            Graphics
159
     * @param at
160
     *            AffineTransform
161
     * @param symbol
162
     *            ISymbol
163
     * @param properties
164
     */
165
    public void print(Graphics2D g, AffineTransform at,
166
        ISymbol symbol, PrintAttributes properties){
167
        symbol.print(g, at, getGeometry(), properties);
168
    }
169

  
170
    /**
171
     * Paints the geometry on the Graphics adding him the last point if the
172
     * parameter andLastPoint is true.
173
     * 
174
     * @param g
175
     *            Graphics
176
     * @param at
177
     *            AffineTransform
178
     * @param andLastPoint
179
     *            If true add last point.
180
     */
181
    public abstract void paint(Graphics2D g, AffineTransform at,
182
        boolean andLastPoint);
183

  
184
    /**
185
     * Set the point of cursor.
186
     * 
187
     * @param p
188
     *            Point of cursor.
189
     */
190
    public abstract void pointPosition(Point2D p);
191

  
192
    /**
193
     * Obtains the shape of the Geometry.
194
     * 
195
     * @return Geometry.
196
     * @deprecated
197
     */
198
    public Geometry getGeometry(AffineTransform at){
199
        Geometry clonedGeom = geometry.cloneGeometry();
200
        clonedGeom.transform(at);
201
        return clonedGeom;
202
    }
203
    
204
    /**
205
     * Returns the geometry to draw
206
     * @return
207
     *      the geometry
208
     */
209
    public Geometry getGeometry(){
210
        return geometry;
211
    }
212

  
213
    /**
214
     * Returns all the points of Geometry.
215
     * 
216
     * @return Array of points.
217
     */
218
    public Point2D[] getPoints() {
219
        return (Point2D[]) points.toArray(new Point2D[0]);
220
    }
221

  
222
    /**
223
     * Draws a handler in each vertex of the Geometry.
224
     * 
225
     * @param g
226
     *            Graphics
227
     * @param at
228
     *            AffineTransform.
229
     */
230
    public void drawVertex(Graphics2D g, AffineTransform at) {
231
        Point2D[] ps = getPoints();
232
        Point2D[] pointRes = new Point2D[ps.length];
233
        at.transform(ps, 0, pointRes, 0, ps.length);
234

  
235
        int d = 3;
236

  
237
        for (int i = 0; i < pointRes.length; i++) {
238
            g.fillRect((int) pointRes[i].getX() - d, (int) pointRes[i].getY()
239
                - d, d * 2, d * 2);
240
        }
241
    }
242

  
243
    /**
244
     * Modifies a point of the Geometry from an index by the one that is passed
245
     * like parameter.
246
     * 
247
     * @param pos
248
     *            Index
249
     * @param point
250
     *            Point
251
     */
252
    public void changePoint(int pos, Point2D point) {
253
        this.points.set(pos, point);
254
    }
255

  
256
    /**
257
     * Add all the points of Geometry.
258
     * 
259
     * @param points
260
     *            All points.
261
     */
262
    public void setPoints(Point2D[] points) {
263
        this.points.clear();
264

  
265
        for (int i = 0; i < points.length; i++) {
266
            this.points.add(points[i]);
267
        }
268
    }
269

  
270
    /**
271
     * Remove last point of Geometry.
272
     */
273
    public void delLastPoint() {
274
        if (points.size() > 0) {
275
            points.remove(points.size() - 1);
276
        }
277
    }
278

  
279
    public Object clone() throws CloneNotSupportedException {
280
        GeometryAdapter cloneAdapter = (GeometryAdapter) super.clone();
281
        Collections.copy(cloneAdapter.points, this.points);
282
        cloneAdapter.geometry = (Geometry) this.geometry.cloneGeometry();
283
        return cloneAdapter;
284
    }
285

  
286
    public Rectangle2D getBounds2D() {
287
        Rectangle2D r = geometry.getBounds2D();
288
        double w = r.getWidth();
289
        double h = r.getHeight();
290
        double x = r.getX();
291
        double y = r.getY();
292
        boolean modified = false;
293
        if (r.getWidth() < 0.5) {
294
            modified = true;
295
            w = 0.5;
296
            x = x - 0.25;
297
        }
298
        if (r.getHeight() < 0.5) {
299
            modified = true;
300
            h = 0.5;
301
            y = y - 0.25;
302
        }
303
        if (modified) {
304
            return new Rectangle2D.Double(x, y, w, h);
305
        }
306
        return r;
307
    }
308

  
309
    public static void registerPersistent() {
310
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
311
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
312
            DynStruct definition =
313
                manager.addDefinition(GeometryAdapter.class,
314
                    PERSISTENCE_DEFINITION_NAME,
315
                    "GeometryAdapter persistence definition", null, null);
316

  
317
            definition.addDynFieldList(POINTS_FIELD)
318
                .setClassOfItems(Point2D.class).setMandatory(true);
319
        }
320

  
321
        CircleAdapter.registerPersistent();
322
        PointAdapter.registerPersistent();
323
        PolygonAdapter.registerPersistent();
324
        PolyLineAdapter.registerPersistent();
325
        RectangleAdapter.registerPersistent();
326
    }
327

  
328
    public void loadFromState(PersistentState state)
329
        throws PersistenceException {
330
        points = state.getList(POINTS_FIELD);
331
        obtainShape((Point2D) points.get(points.size() - 1));
332
    }
333

  
334
    public void saveToState(PersistentState state) throws PersistenceException {
335
        state.set(POINTS_FIELD, points);
336
    }
337
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/PolyLineAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

  
24
import java.awt.Color;
25
import java.awt.Graphics2D;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.Point2D;
28

  
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

  
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
34
import org.gvsig.fmap.geom.Geometry.TYPES;
35
import org.gvsig.fmap.geom.exception.CreateGeometryException;
36
import org.gvsig.fmap.geom.primitive.Curve;
37
import org.gvsig.fmap.mapcontext.MapContextLocator;
38
import org.gvsig.fmap.mapcontext.MapContextManager;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43

  
44
/**
45
 * DOCUMENT ME!
46
 * 
47
 * @author Vicente Caballero Navarro
48
 */
49
public class PolyLineAdapter extends GeometryAdapter {
50

  
51
    public static final String PERSISTENCE_DEFINITION_NAME = "PolyLineAdapter";
52
    private static final Logger logger = LoggerFactory
53
        .getLogger(PolyLineAdapter.class);
54
    protected Point2D pointPosition = new Point2D.Double();
55
    private AffineTransform identity = new AffineTransform();
56

  
57
    private MapContextManager mapContextManager = MapContextLocator
58
        .getMapContextManager();
59

  
60
    public PolyLineAdapter() {
61
        super();
62
    }
63

  
64
    /**
65
     * DOCUMENT ME!
66
     * 
67
     * @param p
68
     *            DOCUMENT ME!
69
     */
70
    public void obtainShape(Point2D p) {
71
        Point2D[] points = getPoints();
72
        
73
        try {
74
            Curve curve = (Curve)geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
75
            if (points.length > 0) {
76
                curve.addMoveToVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D));
77
            }
78
            for (int i = 1; i < points.length; i++) {
79
                curve.addVertex(geomManager.createPoint(points[i].getX(), points[i].getY(), SUBTYPES.GEOM2D));
80
            }
81
            if (points.length > 0) {
82
                curve.addVertex(geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D));
83
            }
84

  
85
            setGeometry(curve);
86
        } catch (CreateGeometryException e) {
87
            logger.error("Error creating the circle", e);
88
        }      
89
    }
90

  
91
    /**
92
     * DOCUMENT ME!
93
     * 
94
     * @param g
95
     *            DOCUMENT ME!
96
     * @param at
97
     *            DOCUMENT ME!
98
     * @param andLastPoint
99
     *            DOCUMENT ME!
100
     */
101
    public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
102
        if (andLastPoint) {
103
            obtainShape(pointPosition);
104
        }
105

  
106
        Geometry shapeAux = getGeometry(at);
107
        // ISymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
108
        ILineSymbol symbol =
109
            (ILineSymbol) mapContextManager.getSymbolManager().createSymbol(
110
                ILineSymbol.SYMBOL_NAME);
111
        symbol.setLineColor(Color.RED);
112
        symbol.draw(g, identity, shapeAux, null, null);
113
        // FGraphicUtilities.DrawShape(g, identity, shapeAux,
114
        // new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red));
115
    }
116

  
117
    /**
118
     * DOCUMENT ME!
119
     * 
120
     * @param p
121
     *            DOCUMENT ME!
122
     */
123
    public void pointPosition(Point2D p) {
124
        pointPosition = p;
125
    }
126

  
127
    public static void registerPersistent() {
128
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
129
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
130
            DynStruct definition =
131
                manager.addDefinition(PolyLineAdapter.class,
132
                    PERSISTENCE_DEFINITION_NAME,
133
                    "PolyLine Adapter persistence definition", null, null);
134

  
135
            definition.extend(manager
136
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
137
        }
138
    }
139
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/CircleAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

  
24
import java.awt.Color;
25
import java.awt.Graphics2D;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.Point2D;
28

  
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

  
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
34
import org.gvsig.fmap.geom.Geometry.TYPES;
35
import org.gvsig.fmap.geom.exception.CreateGeometryException;
36
import org.gvsig.fmap.geom.primitive.Circle;
37
import org.gvsig.fmap.mapcontext.MapContextLocator;
38
import org.gvsig.fmap.mapcontext.MapContextManager;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43

  
44
/**
45
 * DOCUMENT ME!
46
 * 
47
 * @author Vicente Caballero Navarro
48
 */
49
public class CircleAdapter extends GeometryAdapter {
50
    public static final String PERSISTENCE_DEFINITION_NAME = "CircleAdapter";
51
    private static final Logger logger = LoggerFactory
52
        .getLogger(CircleAdapter.class);
53
    private Point2D pointPosition = new Point2D.Double();
54
    private AffineTransform identity = new AffineTransform();
55

  
56
    private MapContextManager mapContextManager = MapContextLocator
57
        .getMapContextManager();
58

  
59
    public CircleAdapter() {
60
        super();
61
    }
62

  
63
    /**
64
     * DOCUMENT ME!
65
     * 
66
     * @param g
67
     *            DOCUMENT ME!
68
     * @param at
69
     *            DOCUMENT ME!
70
     * @param andLastPoint
71
     *            DOCUMENT ME!
72
     */
73
    public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) {
74
        if (getPoints().length > 0) {
75
            if (andLastPoint) {
76
                obtainShape(pointPosition);
77
            }
78

  
79
            Geometry shapeAux = getGeometry(at);
80

  
81
            ILineSymbol symbol =
82
                (ILineSymbol) mapContextManager.getSymbolManager()
83
                    .createSymbol(ILineSymbol.SYMBOL_NAME);
84
            ILineSymbol redOutline =
85
                (ILineSymbol) MapContextLocator.getSymbolManager()
86
                    .createSymbol(ILineSymbol.SYMBOL_NAME);
87
            redOutline.setLineColor(Color.red);
88
            symbol.draw(g, identity, shapeAux, null, null);
89
        }
90
    }
91

  
92
    /**
93
     * DOCUMENT ME!
94
     * 
95
     * @param p
96
     *            DOCUMENT ME!
97
     */
98
    public void pointPosition(Point2D p) {
99
        pointPosition = p;
100
    }
101

  
102
    /**
103
     * DOCUMENT ME!
104
     * 
105
     * @param p
106
     *            DOCUMENT ME!
107
     * @throws CreateGeometryException 
108
     */
109
    public void obtainShape(Point2D p) {
110
        Point2D[] points = getPoints();
111

  
112
        double x = (points[0]).getX(); 
113
        double y = (points[0]).getY();
114
        double r = p.distance(points[0]);
115
              
116
        try {
117
            Circle circle = (Circle)geomManager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
118
            circle.setPoints(geomManager.createPoint(x, y, SUBTYPES.GEOM2D), r) ;
119
            setGeometry(circle);
120
        } catch (CreateGeometryException e) {
121
            logger.error("Error creating the circle", e);
122
        }            
123
    }
124

  
125
    public static void registerPersistent() {
126
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
127
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
128
            DynStruct definition =
129
                manager.addDefinition(CircleAdapter.class,
130
                    PERSISTENCE_DEFINITION_NAME,
131
                    "Circle Adapter persistence definition", null, null);
132

  
133
            definition.extend(manager
134
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
135
        }
136
    }
137
}
tags/v2_0_0_Build_2042/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutDraw.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff