Revision 1567

View differences:

tags/org.gvsig.app.document.layout2.app-2.0.274/pom.xml
1
<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/maven-v4_0_0.xsd">
2

  
3
    <modelVersion>4.0.0</modelVersion>
4
    <artifactId>org.gvsig.app.document.layout2.app</artifactId>
5
    <packaging>pom</packaging>
6
    <version>2.0.274</version>
7

  
8
    <name>${project.artifactId}</name>
9
    <description>This plugin adds creation/management of layout (map) documents.</description>
10

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

  
17
	<url>https://devel.gvsig.org/redmine/projects/gvsig-app-document-layout</url>
18

  
19
    <scm>
20
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-app-document-layout/tags/org.gvsig.app.document.layout2.app-2.0.274</connection>
21
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-app-document-layout/tags/org.gvsig.app.document.layout2.app-2.0.274</developerConnection>
22
        <url>https://devel.gvsig.org/redmine/projects/gvsig-app-document-layout/repository/show/tags/org.gvsig.app.document.layout2.app-2.0.274</url>
23
    </scm>
24
    <repositories>
25
      <repository>
26
        <id>gvsig-public-http-repository</id>
27
        <name>gvSIG maven public HTTP repository</name>
28
        <url>http://devel.gvsig.org/m2repo/j2se</url>
29
        <releases>
30
          <enabled>true</enabled>
31
          <updatePolicy>daily</updatePolicy>
32
          <checksumPolicy>warn</checksumPolicy>
33
        </releases>
34
        <snapshots>
35
          <enabled>true</enabled>
36
          <updatePolicy>daily</updatePolicy>
37
          <checksumPolicy>warn</checksumPolicy>
38
        </snapshots>
39
      </repository>
40
    </repositories>
41

  
42
	<build>
43
		<plugins>
44
			<plugin>
45
				<groupId>org.apache.maven.plugins</groupId>
46
				<artifactId>maven-release-plugin</artifactId>
47
				<configuration>
48
					<tagBase>https://devel.gvsig.org/svn/gvsig-app-document-layout/tags</tagBase>
49
				</configuration>
50
			</plugin>
51
		</plugins>
52
	</build>
53

  
54
    <dependencyManagement>
55
         <dependencies>
56
            <!--
57
            Versions of child projects
58
            -->
59
            <dependency>
60
                <groupId>org.gvsig</groupId>
61
                <artifactId>org.gvsig.app.document.layout2.app.mainplugin</artifactId>
62
                <version>2.0.274</version>
63
            </dependency>
64
            <dependency>
65
                <groupId>org.gvsig</groupId>
66
                <artifactId>org.gvsig.pdf.swing.api</artifactId>
67
                <version>${org.gvsig.pdf.version}</version>
68
            </dependency>
69

  
70
        </dependencies>
71
    </dependencyManagement>
72
    <properties>
73
        <org.gvsig.pdf.version>1.0.125</org.gvsig.pdf.version>
74
    </properties>
75
	<modules>
76
		<module>org.gvsig.app.document.layout2.app.mainplugin</module>
77
	</modules>
78

  
79
</project>
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.app.mainplugin/buildNumber.properties
1
#Thu May 18 00:03:16 CEST 2023
2
buildNumber=296
0 3

  
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25
  <dependencySets>
26
  
27
  <!--
28
    <dependencySet>
29
      <useProjectArtifact>false</useProjectArtifact>
30
      <useTransitiveDependencies>false</useTransitiveDependencies>
31
      <outputDirectory>lib</outputDirectory>
32
      <includes>
33
      </includes>
34
    </dependencySet>
35
    
36
    -->
37
    
38
  </dependencySets>
39

  
40
</assembly>
0 41

  
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/math/intervals/IntervalUtils.java
1
package org.gvsig.math.intervals;
2

  
3
public class IntervalUtils {
4

  
5
	/**
6
	 * Calculates an nice round interval division. For instance, for
7
	 * intervalLenght = 1100000 and numberOfDivisions=5,
8
	 * the result would be 250000.
9
	 * 
10
	 * @param intervalLength The full interval to be divided
11
	 * @param numberOfDivisions The exact number of divisions to perform
12
	 * @return A nice round interval division. The calculated result
13
	 * ensures that the whole interval length is covered by the proposed
14
	 * division, so it always fulfills the following formula:
15
	 *  <code>result*numberOfDivisions>=intervalLength</code>
16
	 */
17
	public static double roundIntervalDivision(double intervalLength, int numberOfDivisions) {
18
		if (intervalLength<=0.0d || numberOfDivisions<=0) {
19
			return 0.0d;
20
		}
21

  
22
		double division = intervalLength/numberOfDivisions;
23
		if (division==0.0d) {
24
			return 0.0d;
25
		}
26
		double digitShift = Math.floor((Math.log10(division)));
27
		double scale = Math.pow(10, -digitShift);
28
		double firstSignificatDigit = Math.floor(scale*division);
29
		double result = firstSignificatDigit*Math.pow(10, digitShift);
30
		if (result*numberOfDivisions>=intervalLength) {
31
			return result;
32
		}
33
		else {
34
			result = (0.5+firstSignificatDigit)*Math.pow(10, digitShift);
35
			if (result*numberOfDivisions>=intervalLength) {
36
				return result;
37
			}
38
		}
39
		result = (1+firstSignificatDigit)*Math.pow(10, digitShift);
40
		return result;
41
	}
42
}
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.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/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.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 java.awt.GridBagConstraints;
25
import java.awt.Insets;
26

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

  
35
import org.gvsig.andami.IconThemeHelper;
36
import org.gvsig.andami.PluginServices;
37
import org.gvsig.andami.PluginsLocator;
38
import org.gvsig.andami.preferences.AbstractPreferencePage;
39
import org.gvsig.andami.preferences.StoreException;
40
import org.gvsig.app.project.ProjectManager;
41
import org.gvsig.app.project.documents.layout.Attributes;
42
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
43
import org.gvsig.fmap.mapcontext.MapContext;
44
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
45
import org.gvsig.i18n.Messages;
46
import org.gvsig.utils.XMLEntity;
47

  
48
/**
49
 * Layout preference page where the user can establish default values for
50
 * <ol>
51
 * <li><b>grid horizontal gap</b></li>
52
 * <li><b>grid vertical gap</b></li>
53
 * <li><b>show or hide grid</b></li>
54
 * <li><b>adjust elements to grid</b></li>
55
 * <li><b>show or hide rules</b></li>
56
 * </ol>
57
 * 
58
 * @author jaume dominguez faus - jaume.dominguez@iver.es
59
 * 
60
 */
61
public class LayoutPage extends AbstractPreferencePage {
62

  
63
    private static final long serialVersionUID = -8225970409668105935L;
64
    static String id = LayoutPage.class.getName();;
65
    private ImageIcon icon;
66
    private JCheckBox chkGridEnabled;
67
    private JCheckBox chkShowRules;
68
    private JCheckBox chkShowGrid;
69
    private JTextField txtVGap;
70
    private JTextField txtHGap;
71
    private JCheckBox chkShowInitialPageConfig;
72
	private JCheckBox chkShowLayoutTOC;
73
	private JComboBox cbHGapUnit;
74
	private JComboBox cbVGapUnit;
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 = IconThemeHelper.getImageIcon("document-map-icon");
95

  
96
        GridBagLayoutPanel gridRulerPanel = new GridBagLayoutPanel();
97
        Insets topInsets = new Insets(10, 10, 0, 10);
98
        Insets insets = new Insets(8, 10, 0, 10);
99
        Insets lastInsets = new Insets(8, 10, 12, 10);
100
        gridRulerPanel.setBorder(BorderFactory.createTitledBorder(Messages.getText("Grid_and_ruler")));
101
        
102
        // horizontal gap text field and units combo
103
        cbHGapUnit = new JComboBox();
104
        String[] names = MapContext.getDistanceNames();
105
        for (int i = 0; i < names.length; i++) {
106
        	cbHGapUnit.addItem(PluginServices.getText(this, names[i]));
107
        }
108
        gridRulerPanel.addComponent(new JLabel(PluginServices.getText(this, "espaciado_horizontal")),
109
            txtHGap = new JTextField(5), cbHGapUnit, GridBagConstraints.NONE, insets);
110
        
111
        // vertical gap text field and units combo
112
        cbVGapUnit = new JComboBox();
113
        for (int i = 0; i < names.length; i++) {
114
        	cbVGapUnit.addItem(PluginServices.getText(this, names[i]));
115
        }
116
        gridRulerPanel.addComponent(new JLabel(PluginServices.getText(this, "espaciado_vertical")),
117
        		txtVGap = new JTextField(5), cbVGapUnit, GridBagConstraints.NONE, insets);
118

  
119
        // show/hide show check
120
        gridRulerPanel.addComponent(chkShowGrid =
121
            new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula")), insets);
122

  
123
        // enable/disable grid
124
        gridRulerPanel.addComponent(chkGridEnabled =
125
            new JCheckBox(PluginServices.getText(this, "malla_activada")), insets);
126

  
127
        // show/hide rules
128
        gridRulerPanel.addComponent(chkShowRules =
129
            new JCheckBox(PluginServices.getText(this, "activar_regla")), lastInsets);
130
        
131
        addComponent(gridRulerPanel, topInsets);
132
        
133
        GridBagLayoutPanel behaviourPanel = new GridBagLayoutPanel();
134
        behaviourPanel.setBorder(BorderFactory.createTitledBorder(Messages.getText("User_interface")));
135
        
136
        behaviourPanel.addComponent(
137
        		chkShowInitialPageConfig = new JCheckBox(Messages.getText("Show_page_config_dialog_when_layout_document_is_created")),
138
        		insets);
139
        
140
        behaviourPanel.addComponent(
141
        		chkShowLayoutTOC = new JCheckBox(Messages.getText("Show_table_of_contents_TOC_for_Layout_views")),
142
        		insets);
143
        
144
        addComponent(behaviourPanel, lastInsets);
145

  
146
    }
147

  
148
    public void storeValues() throws StoreException {
149
        double hGap, vGap;
150
        boolean gridEnabled, showRules, showGrid, showInitPageConfig,
151
        	showLayoutToc;
152
        String hGapUnits, vGapUnits;
153
        try {
154
            hGap = Double.parseDouble(txtHGap.getText());
155
            hGapUnits = MapContext.getDistanceAbbr()[cbHGapUnit.getSelectedIndex()];
156
            vGap = Double.parseDouble(txtVGap.getText());
157
            vGapUnits = MapContext.getDistanceAbbr()[cbVGapUnit.getSelectedIndex()];
158
            gridEnabled = chkGridEnabled.isSelected();
159
            showGrid = chkShowGrid.isSelected();
160
            showRules = chkShowRules.isSelected();
161
            showInitPageConfig = chkShowInitialPageConfig.isSelected();
162
            showLayoutToc = chkShowLayoutTOC.isSelected();
163
        } catch (Exception e) {
164
            throw new StoreException(PluginServices.getText(this,
165
                "invalid_value_for_gap"));
166
        }
167
        layoutManager.setDefaultShowGrid(showGrid);
168
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
169
        layoutManager.setDefaultShowRulers(showRules);
170
        Attributes.setDefaultGridGap(hGap, vGap, hGapUnits, vGapUnits);
171
        PluginServices ps = PluginsLocator.getManager().getPlugin(this);
172
		XMLEntity xml = ps.getPersistentXML();
173
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME, hGap);
174
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME, vGap);
175
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME, hGapUnits);
176
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME, vGapUnits);
177
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME, showGrid);
178
        xml.putProperty(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME, gridEnabled);
179
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME, showRules);
180
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME, showInitPageConfig);
181
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME, showLayoutToc);
182
    }
183

  
184
    public String getID() {
185
        return id;
186
    }
187

  
188
    public String getTitle() {
189
        return PluginServices.getText(this, "Mapa");
190
    }
191

  
192
    public JPanel getPanel() {
193
        return this;
194
    }
195

  
196
    public void initializeValues() {
197
    	PluginServices ps = PluginsLocator.getManager().getPlugin(this);
198
		XMLEntity xml = ps.getPersistentXML();
199
        double hGap = PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP;
200
        double vGap = PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP;
201
        boolean showGrid = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_SHOW;
202
        boolean gridEnabled = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_ENABLE;
203
        boolean showRules = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS;
204
        boolean showInitPageConfig = PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT;
205
        boolean showLayoutToc = PreferenceKeys.FACTORY_DEFAULT_SHOW_LAYOUT_TOC;
206
        // horizontal gap
207
        if (xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
208
            hGap =
209
                xml.getDoubleProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME);
210
        }
211
        txtHGap.setText(String.valueOf(hGap));
212

  
213
        // vertical gap
214
        if (xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
215
            vGap =
216
                xml.getDoubleProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME);
217
        }
218
        txtVGap.setText(String.valueOf(vGap));
219
        
220
        String hGapUnit = xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME)?
221
        		xml.getStringProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME):
222
        			PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP_UNIT;
223
        cbHGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(hGapUnit));
224
        
225
        String vGapUnit = xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME)?
226
                		xml.getStringProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME):
227
                			PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP_UNIT;
228
        cbVGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(vGapUnit));
229

  
230
        // show/hide grid check
231
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
232
            showGrid =
233
                xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME);
234
        }
235
        chkShowGrid.setSelected(showGrid);
236

  
237
        // enable/disable grid check
238
        if (xml.contains(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
239
            gridEnabled =
240
                xml.getBooleanProperty(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME);
241
        }
242
        chkGridEnabled.setSelected(gridEnabled);
243

  
244
        // enable/disable rules
245
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME)) {
246
            showRules =
247
                xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME);
248
        }
249
        chkShowRules.setSelected(showRules);
250
        
251
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME)) {
252
        	showInitPageConfig = xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME);
253
        }
254
        chkShowInitialPageConfig.setSelected(showInitPageConfig);
255
        
256
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME)) {
257
        	showLayoutToc = xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME);
258
        }
259
        chkShowLayoutTOC.setSelected(showLayoutToc);
260

  
261
        layoutManager.setDefaultShowGrid(showGrid);
262
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
263
        layoutManager.setDefaultShowRulers(showRules);
264
        Attributes.setDefaultGridGap(hGap, vGap, hGapUnit, vGapUnit);
265
    }
266

  
267
    public void initializeDefaults() {
268
        txtHGap.setText(String.valueOf(PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP));
269
        txtVGap.setText(String.valueOf(PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP));
270
        cbHGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP_UNIT));
271
        cbVGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP_UNIT));
272
        chkShowGrid.setSelected(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_SHOW);
273
        chkGridEnabled.setSelected(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_ENABLE);
274
        chkShowRules.setSelected(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS);
275
        chkShowInitialPageConfig.setSelected(PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT);
276
    }
277

  
278
    public ImageIcon getIcon() {
279
        return icon;
280
    }
281

  
282
    public boolean isValueChanged() {
283
        return super.hasChanged();
284
    }
285

  
286
    public void setChangesApplied() {
287
        setChanged(false);
288
    }
289
}
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/PreferenceKeys.java
1
package org.gvsig.app.gui.preferencespage;
2

  
3
/**
4
 * The purpose of this interface is to define the keys used for the
5
 * persistence of this plugin in order to make these keys available
6
 * on library level, instead of defining them within the
7
 * preference page (which has UI dependences).
8
 * 
9
 * @author Cesar Martinez Izquierdo <cesar.izq@gmail.com>
10
 *
11
 */
12
public interface PreferenceKeys {
13
    String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME = "DefaultShowLayoutGrid";
14
    String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME = "DefaultEnableLayoutGrid";
15
    String DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME = "DefaultShowLayoutRules";
16
    String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME = "DefaultGridVerticalGap";
17
    String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME = "DefaultGridHorizontalGap";
18
    String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME = "DefaultGridVerticalGapUnits";
19
    String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME = "DefaultGridHorizontalGapUnits";
20
    String DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME = "DefaulShowInitialPageConfigLayout";
21
    String DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME = "DefaultShowLayoutToc";
22
    boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS = true;
23
    boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true;
24
    double FACTORY_DEFAULT_VERTICAL_GAP = 1.0d;
25
    double FACTORY_DEFAULT_HORIZONTAL_GAP = 1.0d;
26
    String FACTORY_DEFAULT_VERTICAL_GAP_UNIT = "cm";
27
    String FACTORY_DEFAULT_HORIZONTAL_GAP_UNIT = "cm";
28
    boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false;
29
    boolean FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT = true;
30
    boolean FACTORY_DEFAULT_SHOW_LAYOUT_TOC = true;
31

  
32
}
0 33

  
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/report/LayoutReportActionFactory.java
1
package org.gvsig.app.project.documents.layout.report;
2

  
3
import javax.json.JsonObject;
4
import org.apache.commons.lang3.StringUtils;
5
import org.gvsig.fmap.dal.feature.FeatureQuery;
6
import org.gvsig.fmap.dal.feature.FeatureSelection;
7
import org.gvsig.fmap.dal.feature.FeatureStore;
8
import org.gvsig.fmap.dal.swing.DALSwingLocator;
9
import org.gvsig.fmap.dal.swing.DataSwingManager;
10
import org.gvsig.fmap.dal.swing.report.AbstractReportActionFactory;
11
import org.gvsig.fmap.dal.swing.report.ReportAction;
12
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
13

  
14
/**
15
 *
16
 * @author jjdelcerro
17
 */
18
public class LayoutReportActionFactory extends AbstractReportActionFactory implements ReportActionFactory {
19

  
20
    public static final String LAYOUT_REPORT_ACTION_NAME = "Layout";
21
    
22
    public LayoutReportActionFactory() {
23
        super(LAYOUT_REPORT_ACTION_NAME);
24
    }
25

  
26
    @Override
27
    public ReportAction createReportAction(FeatureStore store, FeatureQuery query, FeatureSelection selecteds, JsonObject json) {
28
        String type = json.getString("type", "jasper").trim();
29
        if( !StringUtils.equalsIgnoreCase(type, LAYOUT_REPORT_ACTION_NAME) ) {
30
            return null;
31
        }
32
        ReportAction reportAction = new LayoutReportAction(this, store, query, selecteds, json);
33
        return reportAction;
34
    }
35
    
36
    public static void selfRegister() {
37
        DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
38
        dalSwingManager.registerReportAction(new LayoutReportActionFactory());
39
    }
40

  
41
    @Override
42
    public boolean isApplicable(Object... args) {
43
        JsonObject json = (JsonObject) args[0];
44
        String type = json.getString("type", "jasper").trim();
45
        return StringUtils.equalsIgnoreCase(type, LAYOUT_REPORT_ACTION_NAME);
46
    }
47
    
48
}
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/report/LayoutReportAction.java
1
package org.gvsig.app.project.documents.layout.report;
2

  
3
import java.awt.Dimension;
4
import java.awt.event.ActionEvent;
5
import java.io.File;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import javax.json.Json;
9
import javax.json.JsonObject;
10
import javax.swing.JComponent;
11
import org.apache.commons.io.IOUtils;
12
import org.gvsig.andami.ui.mdiManager.IWindow;
13
import org.gvsig.app.ApplicationLocator;
14
import org.gvsig.app.ApplicationManager;
15
import org.gvsig.app.project.documents.Document;
16
import org.gvsig.app.project.documents.layout.LayoutContext;
17
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
18
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
19
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
20
import static org.gvsig.app.project.documents.layout.report.LayoutReportActionFactory.LAYOUT_REPORT_ACTION_NAME;
21
import org.gvsig.app.project.documents.view.ViewDocument;
22
import org.gvsig.app.project.documents.view.gui.IView;
23
import org.gvsig.desktopopen.DesktopOpen;
24
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
25
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
26
import org.gvsig.expressionevaluator.ExpressionUtils;
27
import org.gvsig.expressionevaluator.MutableSymbolTable;
28
import org.gvsig.fmap.dal.feature.Feature;
29
import org.gvsig.fmap.dal.feature.FeatureQuery;
30
import org.gvsig.fmap.dal.feature.FeatureSelection;
31
import org.gvsig.fmap.dal.feature.FeatureSet;
32
import org.gvsig.fmap.dal.feature.FeatureStore;
33
import org.gvsig.fmap.dal.swing.DALSwingLocator;
34
import org.gvsig.fmap.dal.swing.DataSwingManager;
35
import org.gvsig.fmap.dal.swing.report.AbstractReportAction;
36
import org.gvsig.fmap.dal.swing.report.ReportAction;
37
import org.gvsig.fmap.dal.swing.report.ReportActionFactory;
38
import org.gvsig.fmap.geom.primitive.Envelope;
39
import org.gvsig.fmap.mapcontext.MapContext;
40
import org.gvsig.fmap.mapcontext.layers.FLayer;
41
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
42
import org.gvsig.pdf.lib.api.PDFDocument;
43
import org.gvsig.pdf.lib.api.PDFLocator;
44
import org.gvsig.pdf.lib.api.PDFManager;
45
import org.gvsig.pdf.swing.api.PDFSwingLocator;
46
import org.gvsig.pdf.swing.api.PDFSwingManager;
47
import org.gvsig.pdf.swing.api.PDFViewer;
48
import org.gvsig.tools.ToolsLocator;
49
import org.gvsig.tools.persistence.PersistenceManager;
50
import org.gvsig.tools.persistence.PersistentState;
51
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
52
import org.gvsig.tools.swing.api.ToolsSwingLocator;
53
import org.gvsig.tools.swing.api.ToolsSwingUtils;
54
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
55
import org.gvsig.tools.util.ToolsUtilLocator;
56

  
57
/**
58
 *
59
 * @author jjdelcerro
60
 */
61
@SuppressWarnings("UseSpecificCatch")
62
public class LayoutReportAction extends AbstractReportAction implements ReportAction {
63

  
64
    public static LayoutReportAction createFakeLayoutReportAction(Document doc) {
65
        ApplicationManager application = ApplicationLocator.getApplicationManager();
66
        DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
67
        Feature f = null;
68
        FeatureStore theStore = null;
69
        ReportActionFactory theFactory = dataSwingManager.getReportActionFactory(LAYOUT_REPORT_ACTION_NAME);
70
        try {
71
            IWindow activeView = application.getActiveWindow(ViewDocument.class);
72
            ViewDocument viewdoc = (ViewDocument) ((IView)activeView).getDocument();
73
            FLyrVect layer = viewdoc.getMapContext().getLayers().getFirstActiveVectorLayer();
74
            theStore = layer.getFeatureStore();
75
            if( theStore.isFeatureSelectionEmpty() ) {
76
                f = theStore.first();
77
            } else {
78
                f = theStore.getFeatureSelection().first();
79
            }
80
        } catch(Throwable t) {
81
            LOGGER.debug("Can't retrieve test feature",t);
82
        }
83
        LayoutReportAction report = new LayoutReportAction(theFactory, theStore, f);
84
        report.getSymbolTable().setVar("$LAYOUT", doc);
85
        return report;        
86
    }
87
    
88
    
89
    private final JsonObject json;
90
    private final FeatureStore store;
91
    private final FeatureQuery query;
92
    private FeatureSet selection;
93
    private Feature current_row;
94
    private MutableSymbolTable symbolTable;
95
    
96
    @SuppressWarnings("OverridableMethodCallInConstructor")
97
    private LayoutReportAction(ReportActionFactory factory, FeatureStore store, Feature feature) {
98
        // Fake layoutReportAction constructor
99
        super(factory, null);
100
        try {
101
            this.selection = store.createFeatureSelection();
102
            ((FeatureSelection)this.selection).select(feature);
103
        } catch(Throwable t) {
104
            LOGGER.debug("Can't initialize selection",t);
105
        }
106
        this.store = store;
107
        this.query = store.createFeatureQuery(feature.createFilter());
108
        this.current_row = feature;
109
        this.json = Json.createObjectBuilder()
110
                .add("name", store.getName())
111
                .add("type", LAYOUT_REPORT_ACTION_NAME)
112
                .build();
113

  
114
        this.setLabel(this.json.getString("name", store.getName()));
115
    }
116
    
117
    @SuppressWarnings("OverridableMethodCallInConstructor")
118
    public LayoutReportAction(ReportActionFactory factory, FeatureStore store, FeatureQuery query, FeatureSet selection, final JsonObject json) {
119
        super(factory, null);
120
        this.json = json;
121
        this.setLabel(this.json.getString("name", store.getName()));
122
        this.selection = selection;
123
        this.store = store;
124
        this.query = query;
125
        this.current_row = null;
126
    }
127

  
128
    public Feature row() {
129
        return this.current_row;
130
    }
131
    
132
    @Override
133
    public void actionPerformed(ActionEvent e) {
134
        try {
135
            if( selection == null ) {
136
                this.current_row = this.store.findFirst(this.query);
137
            } else {
138
                this.current_row = this.selection.first();
139
            }
140
            final LayoutPanel layout = this.loadTemplate();
141
            final LayoutContext context = layout.getLayoutContext();
142
            final Document document = layout.getDocument();
143

  
144
            this.getSymbolTable();
145
            this.symbolTable.setVar("$LAYOUT", document);
146
                    
147
            File pdfFile = null;
148
            Object previous_report = document.getProperty("$REPORT");
149
            try {
150
                document.setProperty("$REPORT", this);
151
                /*
152
                TODO: Aqui podriamos consultar en el json para ver si hacemos zoom al
153
                envelope de la geometria de current_row, si le aplicamos un buffer 
154
                antes a ese envelop, si la seleccionamos... asi como con que vista
155
                tenemos que hacerlo.
156
                */
157
                MapContext mapContext = null;
158
                for (IFFrame frame : context.getAllFFrames()) {
159
                    if( frame instanceof FFrameView ) {
160
                        mapContext = ((FFrameView)frame).getMapContext();
161
                    }
162
                }
163
                FeatureStore storeInLayout = this.store;
164
                if( mapContext != null ) {
165
                    Envelope envelope = this.current_row.getDefaultGeometry()
166
                            .getEnvelope().getGeometry().buffer(2).getEnvelope();
167
                    mapContext.getViewPort().setEnvelope(envelope);
168
                    /*
169
                    FIXME: Habria que localizar el store en la vista y buscar ahi
170
                    la current_row para seleccionarla. Seleccionando directamente
171
                    la del store puede no funcionar por no ser el mismo store.
172
                     */
173
                    for (FLayer layer : mapContext.getLayers().getLayers(null)) {
174
                        if( layer instanceof FLyrVect ) {
175
                            FeatureStore layerStore = ((FLyrVect) layer).getFeatureStore();
176
                            if( layerStore != null ) {
177
                                if( layerStore.getParameters().isTheSameStore(this.store.getParameters())) {
178
                                    storeInLayout = layerStore;
179
                                }
180
                            }
181
                        }
182
                    }
183
                }
184
                storeInLayout.getFeatureSelection().deselectAll();
185
                storeInLayout.getFeatureSelection().select(current_row.getReference());
186

  
187
                context.fullRefresh();
188
                layout.getLayoutControl().getLayoutDraw().initialize();
189

  
190
                pdfFile = ToolsLocator.getFoldersManager().getUniqueTemporaryFile("report.pdf");
191
                layout.layoutToPDF(pdfFile);    
192
            } finally {
193
                document.setProperty("$REPORT", previous_report);
194
            }
195
            /*
196
            TODO: Aqui vendria bien consultar en el json si usar en visor interno de
197
            PDF o el del sistema.
198
            */
199
            this.showEmbedded(pdfFile);
200
//            this.showExternal(tmpFile);
201
            
202
            this.getStatus().terminate();
203

  
204
        } catch(Throwable t) {
205
            LOGGER.warn("Can't create layout report.",t);
206
            this.getStatus().abort();
207
        }
208
    }
209

  
210
    private void showEmbedded(File pdfFile) throws IOException {
211
        final WindowManager windowManager = ToolsSwingLocator.getWindowManager();
212
        final PDFSwingManager pdfSwingManager = PDFSwingLocator.getPDFSwingManager();
213
        final PDFManager pdfManager = PDFLocator.getPDFManager();
214

  
215
        final PDFDocument pdfdoc = pdfManager.createPDFDocument(pdfFile);            
216
        PDFViewer viewer = pdfSwingManager.createPDFViewer();
217
        viewer.put(pdfdoc);
218
        viewer.setMode(PDFViewer.MODE_LIGHT);
219

  
220
        JComponent comp = viewer.asJComponent();
221
        Dimension size = ToolsSwingUtils.ensureRowsCols(comp.getPreferredSize(), 20, 100, 40, 150);
222
        comp.setSize(size);
223

  
224
        String title = "Report: " + this.getLabel();
225
        windowManager.showWindow(
226
                comp,
227
                title,
228
                WindowManager.MODE.WINDOW
229
        );
230
    }
231

  
232
    private void showExternal(File pdfFile) {
233
        DesktopOpen desktop = ToolsUtilLocator.getToolsUtilManager().createDesktopOpen();
234
        desktop.open(pdfFile);
235
    }
236
    
237
    private LayoutPanel loadTemplate() throws Exception {
238
        ResourcesStorage resources = store.getResourcesStorage();
239
        if (resources == null) {
240
            return null;
241
        }
242
        String templateName = this.json.getString("templateName", "layout"); // "1.layout"...
243
        ResourcesStorage.Resource resource = resources.getResource(templateName);
244
        InputStream is = null;
245
        try {
246
            is = resource.asInputStream();
247
            PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
248
            PersistentState persistentState = persistenceManager.loadState(is);
249

  
250
            // TODO: ? Lo que recuperamos de aqui es de tipo LayoutPanel ?
251
            LayoutPanel layout = (LayoutPanel) persistenceManager.create(persistentState);
252
            return layout;
253
        } finally {
254
            IOUtils.closeQuietly(is);
255
        }
256
    }
257
    
258
    public MutableSymbolTable getSymbolTable() {
259
        if( this.symbolTable == null ) {
260
            this.symbolTable = ExpressionUtils.createSymbolTable();
261
            this.symbolTable.setVar("$REPORT", this);
262
        }
263
        return this.symbolTable;
264
    }
265

  
266
    public String evaluateDynamicText(String s) {
267
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager();
268
        if( !manager.isDynamicText(s) ) {
269
            return s;
270
        }
271
        String x = manager.evaluateDynamicText(
272
                this.getSymbolTable(), 
273
                s, 
274
                null, 
275
                this.store.getResourcesStorage()
276
        );
277
        return x;
278
    }
279
   
280
}
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.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.addVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D));
64
                surface.addVertex(geomManager.createPoint(p.getX(), points[0].getY(), SUBTYPES.GEOM2D));
65
                surface.addVertex(geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D));
66
                surface.addVertex(geomManager.createPoint(points[0].getX(), p.getY(), SUBTYPES.GEOM2D));
67
                surface.addVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D));
68
            }
69

  
70
            setGeometry(surface);
71
        } catch (CreateGeometryException e) {
72
            logger.error("Error creating the circle", e);
73
        }
74
    }
75

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

  
84
            definition.extend(manager
85
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
86
        }
87
    }
88
}
tags/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.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.addVertex(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/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.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/org.gvsig.app.document.layout2.app-2.0.274/org.gvsig.app.document.layout2.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
 */
20
package org.gvsig.app.project.documents.layout.geometryadapters;
21

  
22
import java.awt.Graphics2D;
23
import java.awt.geom.AffineTransform;
24
import java.awt.geom.Point2D;
25
import java.awt.geom.Rectangle2D;
26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.List;
29

  
30
import org.gvsig.compat.print.PrintAttributes;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.exception.CreateGeometryException;
35
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.dynobject.DynStruct;
38
import org.gvsig.tools.lang.Cloneable;
39
import org.gvsig.tools.persistence.PersistenceManager;
40
import org.gvsig.tools.persistence.Persistent;
41
import org.gvsig.tools.persistence.PersistentState;
42
import org.gvsig.tools.persistence.exception.PersistenceException;
43

  
44
/**
45
 * Abstract adaptor to relate the geometries with the fframes and to be able to
46
 * integrate them in the Layout.
47
 *
48
 * @author Vicente Caballero Navarro
49
 */
50
public abstract class GeometryAdapter implements Persistent, Cloneable {
51

  
52
    public static final String PERSISTENCE_DEFINITION_NAME = "GeometryAdapter";
53

  
54
    private static final String POINTS_FIELD = "points";
55

  
56
    protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
57

  
58
    private List<Point2D> points = new ArrayList<Point2D>();
59
    private Geometry geometry;
60

  
61
    public GeometryAdapter() {
62
        super();
63
    }
64

  
65
    /**
66
     * Add a point to de geometry.
67
     *
68
     * @param point Point that is added.
69
     *
70
     * @return Number of points that contains the geometry.
71
     */
72
    public int addPoint(Point2D point) {
73
        points.add(point);
74

  
75
        return points.size();
76
    }
77

  
78
    /**
79
     * End the creation of the geometry with the last point added.
80
     */
81
    public void end() {
82
        obtainShape((Point2D) points.get(points.size() - 1));
83
    }
84

  
85
    /**
86
     * Adds the GeneralPathX with all the points of the geometry.
87
     *
88
     * @param gpx GeneralPathX
89
     */
90
    protected void setGeometry(Geometry geometry) {
91
        this.geometry = geometry;
92
    }
93

  
94
    /**
95
     * Obtains the geometry passing him as parameter the last point.
96
     *
97
     * @param p Last Point.
98
     * @throws CreateGeometryException
99
     */
100
    public abstract void obtainShape(Point2D p);
101

  
102
    /**
103
     * Applies the transformation to all the points of the geometry.
104
     *
105
     * @param at AffineTransform
106
     */
107
    public void applyTransform(AffineTransform at) {
108
        for (int i = 0; i < points.size(); i++) {
109
            at.transform((Point2D) points.get(i), (Point2D) points.get(i));
110
        }
111

  
112
        geometry.transform(at);
113
    }
114

  
115
    /**
116
     * It draws the geometry on the Graphics that is passed like parameter.
117
     *
118
     * @param g Graphics
119
     * @param at AffineTransform
120
     * @param symbol FSymbol
121
     */
122
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
123
        symbol.draw(g, at, geometry, null, null);
124
    }
125

  
126
    /**
127
     * It print the geometry on the Graphics that is passed like parameter.
128
     *
129
     * @param g Graphics
130
     * @param at AffineTransform
131
     * @param symbol ISymbol
132
     * @param properties
133
     */
134
    public void print(Graphics2D g, AffineTransform at,
135
            ISymbol symbol, PrintAttributes properties) {
136
        Geometry geom = getGeometry();
137
        symbol.print(g, at, geom, properties);
138
    }
139

  
140
    /**
141
     * Paints the geometry on the Graphics adding him the last point if the
142
     * parameter andLastPoint is true.
143
     *
144
     * @param g Graphics
145
     * @param at AffineTransform
146
     * @param andLastPoint If true add last point.
147
     */
148
    public abstract void paint(Graphics2D g, AffineTransform at,
149
            boolean andLastPoint);
150

  
151
    /**
152
     * Set the point of cursor.
153
     *
154
     * @param p Point of cursor.
155
     */
156
    public abstract void pointPosition(Point2D p);
157

  
158
    /**
159
     * Obtains the shape of the Geometry.
160
     *
161
     * @return Geometry.
162
     * @deprecated
163
     */
164
    public Geometry getGeometry(AffineTransform at) {
165
        Geometry clonedGeom = geometry.cloneGeometry();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff