Revision 785

View differences:

tags/org.gvsig.app.document.layout2.app-2.0.123/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.123</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.225</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.123</connection>
21
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-app-document-layout/tags/org.gvsig.app.document.layout2.app-2.0.123</developerConnection>
22
        <url>https://devel.gvsig.org/redmine/projects/gvsig-app-document-layout/repository/show/tags/org.gvsig.app.document.layout2.app-2.0.123</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.123</version>
63
            </dependency>
64

  
65
        </dependencies>
66
    </dependencyManagement>
67

  
68
	<modules>
69
		<module>org.gvsig.app.document.layout2.app.mainplugin</module>
70
	</modules>
71

  
72
</project>
tags/org.gvsig.app.document.layout2.app-2.0.123/org.gvsig.app.document.layout2.app.mainplugin/buildNumber.properties
1
#Mon Jul 09 23:30:32 CEST 2018
2
buildNumber=142
0 3

  
tags/org.gvsig.app.document.layout2.app-2.0.123/org.gvsig.app.document.layout2.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/org.gvsig.app.document.layout2.app-2.0.123/org.gvsig.app.document.layout2.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.
0 9

  
tags/org.gvsig.app.document.layout2.app-2.0.123/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.123/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.123/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.123/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
}
tags/org.gvsig.app.document.layout2.app-2.0.123/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
}
0 141

  
tags/org.gvsig.app.document.layout2.app-2.0.123/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutZooms.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;
23

  
24
import java.awt.Dimension;
25
import java.awt.Point;
26
import java.awt.Toolkit;
27
import java.awt.geom.AffineTransform;
28
import java.awt.geom.Point2D;
29
import java.awt.geom.Rectangle2D;
30
import java.util.prefs.Preferences;
31

  
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
35
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
36
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
37
import org.gvsig.compat.CompatLocator;
38
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
42
import org.gvsig.fmap.mapcontext.MapContext;
43
import org.gvsig.tools.observer.Observable;
44
import org.gvsig.tools.observer.ObservableHelper;
45
import org.gvsig.tools.observer.Observer;
46

  
47
/**
48
 * Clase encargada de realizar los zooms al Layout.
49
 * 
50
 * @author Vicente Caballero Navarro
51
 */
52
public class FLayoutZooms implements Observable{
53

  
54
    private static final GeometryManager geomManager = GeometryLocator
55
        .getGeometryManager();
56
    private static final Logger logger = LoggerFactory
57
        .getLogger(FLayoutZooms.class);
58
    private LayoutPanel layout = null;
59
    private ObservableHelper observers;
60
    
61
    public FLayoutZooms(LayoutPanel layoutPanel) {
62
        layout = layoutPanel;
63
        observers = new ObservableHelper();
64
        observers.addObserver(layoutPanel.getLayoutControl());
65
    }
66

  
67
    /**
68
     * Realiza un zoom por rect?ngulo o por punto con un escalado por defecto
69
     * sobre el Layout que se le pasa como par?metro.
70
     * 
71
     * @param p1
72
     *            punto de inicio del rect?ngulo.
73
     * @param p2
74
     *            punto final del rec?ngulo.
75
     */
76
    public void setZoomIn(Point p1, Point p2) {
77
        if (java.lang.Math.abs(layout.getLayoutControl().getFirstPoint().x
78
            - p2.x) < 4) {
79
            double difw = 2;
80
            setZoom(difw, p2);
81
        } else {
82
            if (p1.getX() > p2.getX()) {
83
                int aux = p2.x;
84
                p2.x = p1.x;
85
                p1.x = aux;
86
            }
87

  
88
            if (p1.getY() > p2.getY()) {
89
                int aux = p2.y;
90
                p2.y = p1.y;
91
                p1.y = aux;
92
            }
93

  
94
            Point2D.Double pSheet1 =
95
                FLayoutUtilities.toSheetPoint(
96
                    new Point2D.Double(p1.getX(), p1.getY()), layout
97
                        .getLayoutControl().getAT());
98
            Point2D.Double pSheet2 =
99
                FLayoutUtilities.toSheetPoint(
100
                    new Point2D.Double(p2.getX(), p2.getY()), layout
101
                        .getLayoutControl().getAT());
102

  
103
            double xmin;
104
            double xmax;
105
            double ymin;
106
            double ymax = 0;
107

  
108
            if (pSheet1.x > pSheet2.x) {
109
                xmin = pSheet2.x;
110
                xmax = pSheet1.x;
111
            } else {
112
                xmin = pSheet1.x;
113
                xmax = pSheet2.x;
114
            }
115

  
116
            if (pSheet1.y > pSheet2.y) {
117
                ymin = pSheet2.y;
118
                ymax = pSheet1.y;
119
            } else {
120
                ymin = pSheet1.y;
121
                ymax = pSheet2.y;
122
            }
123

  
124
            Rectangle2D.Double rScreen = new Rectangle2D.Double();
125
            Rectangle2D.Double rSheet = new Rectangle2D.Double();
126
            double x =
127
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
128
                    .getRect().getX(), layout.getLayoutControl().getAT());
129
            double y =
130
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
131
                    .getRect().getY(), layout.getLayoutControl().getAT());
132
            double w =
133
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
134
                    .getRect().getWidth(), layout.getLayoutControl().getAT());
135
            double h =
136
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
137
                    .getRect().getHeight(), layout.getLayoutControl().getAT());
138

  
139
            double wv =
140
                FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
141
                    .getWidth(), layout.getLayoutControl().getAT());
142
            double hv =
143
                FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
144
                    .getHeight(), layout.getLayoutControl().getAT());
145
            double mw = xmax - xmin;
146
            double mh = ymax - ymin;
147
            double difw = wv / mw;
148
            double difh = hv / mh;
149

  
150
            if (difw < difh) {
151
                rSheet.x =
152
                    (-xmin * difw)
153
                        - x
154
                        + ((wv - ((pSheet2.getX() - pSheet1.getX()) * difw)) / 2);
155
                rSheet.y =
156
                    (-ymin * difw)
157
                        - y
158
                        + ((hv - ((pSheet2.getY() - pSheet1.getY()) * difw)) / 2);
159

  
160
                rSheet.width = w * difw;
161
                rSheet.height = h * difw;
162
            } else {
163
                rSheet.x =
164
                    (-xmin * difh)
165
                        - x
166
                        + ((wv - ((pSheet2.getX() - pSheet1.getX()) * difh)) / 2);
167
                rSheet.y =
168
                    (-ymin * difh)
169
                        - y
170
                        + ((hv - ((pSheet2.getY() - pSheet1.getY()) * difh)) / 2);
171

  
172
                rSheet.width = w * difh;
173
                rSheet.height = h * difh;
174
            }
175
            setPointsToZoom(p1, p2);
176
            rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout
177
                .getLayoutControl().getAT()));
178
            if (FLayoutUtilities.isPosible(rScreen)) {
179
                layout.getLayoutControl().setRect(rScreen);
180
            }
181
        }
182
    }
183

  
184
    /**
185
     * Realiza un zoom out sobre el Layout que se le pasa como par?metro.
186
     * 
187
     * @param p2
188
     *            punto central del rect?ngulo.
189
     */
190
    public void setZoomOut(Point p2) {
191
        double difw = 0.5;
192
        setZoom(difw, p2);
193
    }
194

  
195
    /**
196
     * Realiza un zoom out sobre el Layout que se le pasa como par?metro.
197
     * 
198
     * @param dif
199
     *            factor.
200
     * @param p2
201
     *            punto final del rec?ngulo.
202
     */
203
    public void setZoom(double dif, Point p2) {
204
        Point2D.Double pSheet2 =
205
            FLayoutUtilities.toSheetPoint(
206
                new Point2D.Double(p2.getX(), p2.getY()), layout
207
                    .getLayoutControl().getAT());
208
        Rectangle2D.Double rScreen = new Rectangle2D.Double();
209
        Rectangle2D.Double rSheet = new Rectangle2D.Double();
210

  
211
        double difw = dif;
212

  
213
        rSheet.x =
214
            (-pSheet2.getX() * difw)
215
                - FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
216
                    .getRect().getX(), layout.getLayoutControl().getAT())
217
                + FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
218
                    layout.getLayoutControl().getAT());
219
        rSheet.y =
220
            (-pSheet2.getY() * difw)
221
                - FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
222
                    .getRect().getY(), layout.getLayoutControl().getAT())
223
                + FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
224
                    layout.getLayoutControl().getAT());
225

  
226
        rSheet.width =
227
            FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
228
                .getRect().getWidth(), layout.getLayoutControl().getAT())
229
                * difw;
230
        rSheet.height =
231
            FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
232
                .getRect().getHeight(), layout.getLayoutControl().getAT())
233
                * difw;
234

  
235
        rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout
236
            .getLayoutControl().getAT()));
237

  
238
        if (FLayoutUtilities.isPosible(rScreen)) {
239
            layout.getLayoutControl().setRect(rScreen);
240
        }
241

  
242
        // Para realizar el zoom a partir de un punto.
243
        Point p1 =
244
            new Point((int) (p2.getX() - (layout.getWidth() / (difw * 2))),
245
                (int) (p2.getY() - (layout.getHeight() / (difw * 2))));
246
        p2 =
247
            new Point((int) (p2.getX() + (layout.getWidth() / (difw * 2))),
248
                (int) (p2.getY() + (layout.getHeight() / (difw * 2))));
249
        setPointsToZoom(p1, p2);
250
    }
251

  
252
    /**
253
     * Introduce los puntos de control para controlar el zoom del Layout.
254
     */
255
    private void setPointsToZoom(Point p1, Point p2) {
256
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
257

  
258
        for (int i = 0; i < fframes.length; i++) {
259
            if (fframes[i] instanceof IFFrameUseFMap) {
260
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
261
                if (fframe.getATMap() != null) {
262
                    
263
                    Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates(
264
                        p1, fframes[i]);
265
                    Point2D vppo2 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates(
266
                        p2, fframes[i]);
267
                    
268
                    Point2D px1 =
269
                        FLayoutFunctions.toMapPoint(vppo1, fframe.getATMap());
270
                    Point2D px2 =
271
                        FLayoutFunctions.toMapPoint(vppo2, fframe.getATMap());
272
                    fframe.setPointsToZoom(px1, px2);
273
                }
274
            }
275
        }
276
    }
277

  
278
    /**
279
     * Aplica el zoom real teniendo en cuenta la resoluci?n de pantalla.
280
     */
281
    public void realZoom() {
282
        double cm =
283
            layout.getLayoutContext().getAttributes()
284
                .getPixXCm(layout.getLayoutControl().getRect());
285
        double dpi = CompatLocator.getGraphicsUtils().getScreenDPI();
286
        double dif = (cm * Attributes.PULGADA) / dpi;
287
        setZoom(1 / dif, new Point(layout.getWidth() / 2,
288
            layout.getHeight() / 2));
289
        layout.getLayoutControl().refresh();
290
    }
291

  
292
    /**
293
     * Realiza un zoom in a partir del zoom actual de la vista.
294
     */
295
    public void zoomIn() {
296
        setZoom(2, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
297
        layout.getLayoutControl().refresh();
298
    }
299

  
300
    /**
301
     * Realiza un zoom out a partir del zoom actual de la vista.
302
     */
303
    public void zoomOut() {
304
        setZoom(0.5, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
305
        layout.getLayoutControl().refresh();
306
    }
307

  
308
    /**
309
     * Realiza un zoom a los elementos que esten seleccionados, si no hay
310
     * ning?n elemento seleccionado no realiza ning?n zoom
311
     */
312
    public void zoomSelect() {
313
        Rectangle2D.Double recaux = null;
314
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
315
        for (int i = 0; i < fframes.length; i++) {
316
            if (fframes[i].getSelected() != IFFrame.NOSELECT) {
317
                if (recaux == null) {
318
                    recaux =
319
                        fframes[i].getBoundingBox(layout.getLayoutControl()
320
                            .getAT());
321
                } else {
322
                    recaux.add(fframes[i].getBoundingBox(layout
323
                        .getLayoutControl().getAT()));
324
                }
325
            }
326
        }
327

  
328
        if (recaux != null) {
329
            Point p1 = new Point((int) recaux.x, (int) recaux.y);
330
            Point p2 =
331
                new Point((int) recaux.getMaxX(), (int) recaux.getMaxY());
332
            setZoomIn(p1, p2);
333
            layout.getLayoutControl().refresh();
334
        }
335
    }
336

  
337
    /**
338
     * Realiza un zoom a todos los elementos del layout.
339
     */
340
    public void zoomAllFrames() {
341
        Rectangle2D.Double recaux = null;
342
        IFFrame[] fframes =
343
            layout.getLayoutControl().getLayoutContext().getFFrames();
344
        for (int i = 0; i < fframes.length; i++) {
345
            if (recaux == null) {
346
                recaux =
347
                    fframes[i]
348
                        .getBoundingBox(layout.getLayoutControl().getAT());
349
            } else {
350
                recaux.add(fframes[i].getBoundingBox(layout.getLayoutControl()
351
                    .getAT()));
352
            }
353
        }
354

  
355
        if (recaux != null) {
356
            Point p1 = new Point((int) recaux.x, (int) recaux.y);
357
            Point p2 =
358
                new Point((int) recaux.getMaxX(), (int) recaux.getMaxY());
359
            setZoomIn(p1, p2);
360
            layout.getLayoutControl().refresh();
361
        }
362
    }
363

  
364
    /**
365
     * Realiza un zoom in a las vista a?adidas al Layout que esten seleccionadas
366
     * 
367
     * @param p1
368
     *            Punto inicial del rect?ngulo
369
     * @param p2
370
     *            Punto final del rect?ngulo
371
     */
372
    public void setViewZoomIn(Point2D poi1, Point2D poi2) {
373
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
374
        for (int i = 0; i < fframes.length; i++) {
375
            if (fframes[i] instanceof IFFrameUseFMap) {
376
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
377

  
378
                if (fframe.isSelected() && fframe.getMapContext()!=null) {
379
                    
380
                    Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates(
381
                        poi1, fframes[i]);
382
                    Point2D vppo2 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates(
383
                        poi2, fframes[i]);
384
                    
385
                    Point2D.Double mapp1 = FLayoutFunctions.toMapPoint(vppo1, fframe.getATMap());
386
                    Point2D.Double mapp2 = FLayoutFunctions.toMapPoint(vppo2, fframe.getATMap());
387

  
388
                    Rectangle2D.Double r = new Rectangle2D.Double();
389

  
390
                    if (java.lang.Math.abs(poi1.getX() - poi2.getX()) <= 3) {
391
                        double nuevoX;
392
                        double nuevoY;
393
                        double cX;
394
                        double cY;
395

  
396
                        cX = mapp2.getX();
397
                        cY = mapp2.getY();
398

  
399
                        double factor = 1 / MapContext.ZOOMINFACTOR;
400

  
401
                        Rectangle2D extent =
402
                            fframe.getMapContext().getViewPort().getExtent();
403
                        if (extent != null) {
404
                            nuevoX = cX - ((extent.getWidth() * factor) / 2.0);
405
                            nuevoY = cY - ((extent.getHeight() * factor) / 2.0);
406
                            r.x = nuevoX;
407
                            r.y = nuevoY;
408
                            r.width = extent.getWidth() * factor;
409
                            r.height = extent.getHeight() * factor;
410
                        }
411
                    } else {
412
                        // Fijamos el nuevo extent
413
                        r.setFrameFromDiagonal(mapp1, mapp2);
414
                    }
415
                    try {
416
                        fframe.setNewEnvelope(geomManager.createEnvelope(
417
                            r.getX(), r.getY(), r.getMaxX(), r.getMaxY(),
418
                            SUBTYPES.GEOM2D));
419
                    } catch (CreateEnvelopeException e) {
420
                        logger.error("Error creating the envelope", e);
421
                    }
422
                }
423
            }
424
        }
425
    }
426

  
427
    /**
428
     * Realiza un zoom out a las vistas a?adidas al Layout y que est?n
429
     * seleccionadas
430
     * 
431
     * @param p2
432
     *            Punto central
433
     */
434
    public void setViewZoomOut(Point p2) {
435
        Point2D.Double pWorld;
436
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
437
        for (int i = 0; i < fframes.length; i++) {
438
            if (fframes[i] instanceof IFFrameUseFMap) {
439
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
440

  
441
                if (fframe.isSelected() && fframe.getMapContext()!=null) {
442

  
443
                    double nuevoX;
444
                    double nuevoY;
445
                    double cX;
446
                    double cY;
447
                    Point pScreen = new Point((int) p2.getX(), (int) p2.getY());
448
                    
449
                    Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates(
450
                        pScreen, fframes[i]);
451
                    
452
                    pWorld = FLayoutFunctions.toMapPoint(vppo1, fframe.getATMap());
453

  
454
                    cX = pWorld.getX();
455
                    cY = pWorld.getY();
456

  
457
                    double factor = 1 / MapContext.ZOOMOUTFACTOR;
458
                    Rectangle2D extent =
459
                        fframe.getMapContext().getViewPort().getExtent();
460
                    if (extent != null) {
461
                        nuevoX = cX - ((extent.getWidth() * factor) / 2.0);
462
                        nuevoY = cY - ((extent.getHeight() * factor) / 2.0);
463
                        double x = nuevoX;
464
                        double y = nuevoY;
465
                        double width = extent.getWidth() * factor;
466
                        double height = extent.getHeight() * factor;
467
                        try {
468
                            fframe.setNewEnvelope(geomManager.createEnvelope(x,
469
                                y, x + width, y + height, SUBTYPES.GEOM2D));
470
                        } catch (CreateEnvelopeException e) {
471
                            logger.error("Error creating the envelope", e);
472
                        }
473
                    }
474
                }
475
            }
476
        }
477
    }
478

  
479
    /**
480
     * Modifica los puntos de control para generar el zoom del Layout
481
     * 
482
     * @param p1
483
     *            Punto inicial
484
     * @param p2
485
     *            Punto final
486
     */
487
    public void setPan(Point p1, Point p2) {
488
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
489

  
490
        for (int i = 0; i < fframes.length; i++) {
491
            if (fframes[i] instanceof IFFrameUseFMap) {
492
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
493
                if (fframe.getMapContext()!=null) {
494
                	AffineTransform at = fframe.getATMap();
495
                	if (at != null) {
496

  
497
                		Point2D vppo1 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates(
498
                				p1, fframes[i]);
499
                		Point2D vppo2 = FLayoutUtilities.screenCoordinatesToViewportImageCoordinates(
500
                				p2, fframes[i]);
501

  
502
                		Point2D px1 = FLayoutFunctions.toMapPoint(vppo1, at);
503
                		Point2D px2 = FLayoutFunctions.toMapPoint(vppo2, at);
504
                		fframe.movePoints(px1, px2);
505
                	}
506
                }
507
            }
508
        }
509
    }
510

  
511
    public void addObserver(Observer o) {
512
        observers.addObserver(o);        
513
    }
514

  
515
    public void deleteObserver(Observer o) {
516
      observers.deleteObserver(o);        
517
    }
518

  
519
    public void deleteObservers() {
520
       observers.deleteObservers();        
521
    }
522
}
tags/org.gvsig.app.document.layout2.app-2.0.123/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutDocument.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;
23

  
24
import java.util.Iterator;
25
import org.gvsig.app.project.documents.Document;
26

  
27
/**
28
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
29
 */
30
public interface LayoutDocument extends Document {
31

  
32
    public LayoutContext getLayoutContext();
33
   
34
    /**
35
     * Get an Iterator over al elements in the layout.
36
     * 
37
     * @return 
38
     */
39
    public Iterator deepiterator();
40

  
41
    public Iterator iterator();
42
    
43
}
tags/org.gvsig.app.document.layout2.app-2.0.123/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutFunctions.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;
23

  
24
import java.awt.Point;
25
import java.awt.Rectangle;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.NoninvertibleTransformException;
28
import java.awt.geom.Point2D;
29
import java.awt.geom.Rectangle2D;
30
import java.awt.print.PageFormat;
31

  
32
import org.gvsig.app.project.documents.layout.commands.FrameCommandsRecord;
33
import org.gvsig.app.project.documents.layout.fframes.FFrameGroup;
34
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
35
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
36
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
37
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
38
import org.gvsig.fmap.geom.GeometryLocator;
39
import org.gvsig.fmap.geom.GeometryManager;
40
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff