Revision 1395
tags/org.gvsig.app.document.layout2.app-2.0.242/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.242</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.378</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.242</connection> |
|
21 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-app-document-layout/tags/org.gvsig.app.document.layout2.app-2.0.242</developerConnection> |
|
22 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-app-document-layout/repository/show/tags/org.gvsig.app.document.layout2.app-2.0.242</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.242</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> |
|
0 | 73 |
tags/org.gvsig.app.document.layout2.app-2.0.242/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. |
tags/org.gvsig.app.document.layout2.app-2.0.242/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> |
|
0 | 38 |
tags/org.gvsig.app.document.layout2.app-2.0.242/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.242/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/DefaultLayoutManager.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.geom.AffineTransform; |
|
25 |
import java.lang.reflect.Array; |
|
26 |
import java.text.NumberFormat; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Arrays; |
|
29 |
import java.util.Comparator; |
|
30 |
import java.util.Iterator; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import javax.swing.ImageIcon; |
|
34 |
|
|
35 |
import org.gvsig.andami.PluginServices; |
|
36 |
import org.gvsig.andami.PluginsLocator; |
|
37 |
import org.gvsig.andami.messages.NotificationManager; |
|
38 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
39 |
import org.gvsig.app.ApplicationLocator; |
|
40 |
import org.gvsig.app.gui.preferencespage.PreferenceKeys; |
|
41 |
import org.gvsig.app.project.ProjectManager; |
|
42 |
import org.gvsig.app.project.documents.AbstractDocument; |
|
43 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
|
44 |
import org.gvsig.app.project.documents.Document; |
|
45 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
|
46 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
|
47 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
|
48 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
|
49 |
import org.gvsig.app.project.documents.layout.contextmenu.gui.AbstractLayoutContextMenuAction; |
|
50 |
import org.gvsig.app.project.documents.layout.fframes.FrameFactory; |
|
51 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
|
52 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
|
53 |
import org.gvsig.app.project.documents.layout.gui.DefaultLayoutPanel; |
|
54 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
55 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanelImpl; |
|
56 |
import org.gvsig.app.project.documents.layout.gui.MapProperties; |
|
57 |
import org.gvsig.app.project.documents.layout.gui.dialogs.FConfigLayoutDialog; |
|
58 |
import org.gvsig.app.project.documents.view.IContextMenuAction; |
|
59 |
import org.gvsig.tools.ToolsLocator; |
|
60 |
import org.gvsig.tools.dynobject.DynStruct; |
|
61 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
62 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
|
63 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
64 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
65 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
66 |
import org.gvsig.utils.XMLEntity; |
|
67 |
import org.slf4j.Logger; |
|
68 |
import org.slf4j.LoggerFactory; |
|
69 |
|
|
70 |
/** |
|
71 |
* Factory of maps. |
|
72 |
* |
|
73 |
* @author Vicente Caballero Navarro |
|
74 |
*/ |
|
75 |
public class DefaultLayoutManager extends AbstractDocumentManager implements |
|
76 |
LayoutManager { |
|
77 |
static final Logger LOG = LoggerFactory |
|
78 |
.getLogger(DefaultLayoutManager.class); |
|
79 |
|
|
80 |
static final String KEY_LAYOUT_FFRAMEDIALOG = |
|
81 |
"app.project.documents.layout.fframes.gui"; |
|
82 |
static final String KEY_LAYOUT_FFRAME = |
|
83 |
"app.project.documents.layout.fframes"; |
|
84 |
|
|
85 |
public static final String PERSISTENCE_LAYOUT_DOCUMENT_DEFINITION_NAME = |
|
86 |
"LayoutDocument"; |
|
87 |
|
|
88 |
private static final String LAYOUT_CONTEXT_MENUS = "Layout_ContextMenus"; |
|
89 |
|
|
90 |
ExtensionPointManager extensionPoints = ToolsLocator |
|
91 |
.getExtensionPointManager(); |
|
92 |
|
|
93 |
private Boolean defaultShowGrid = null; |
|
94 |
private Boolean defaultAdjustToGrid = null; |
|
95 |
private Boolean defaultShowRulers = null; |
|
96 |
|
|
97 |
private DynStruct persistenceDefinition; |
|
98 |
|
|
99 |
/** |
|
100 |
* Returns image of button. |
|
101 |
* |
|
102 |
* @return Image button. |
|
103 |
*/ |
|
104 |
public ImageIcon getIcon() { |
|
105 |
return ToolsSwingLocator.getIconThemeManager().getCurrent().get("document-map-icon"); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Returns image of selected button. |
|
110 |
* |
|
111 |
* @return Image button. |
|
112 |
*/ |
|
113 |
public ImageIcon getIconSelected() { |
|
114 |
return ToolsSwingLocator.getIconThemeManager().getCurrent().get("document-map-icon-sel"); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Returns the name of registration in the point of extension. |
|
119 |
* |
|
120 |
* @return Name of registration |
|
121 |
*/ |
|
122 |
public String getTypeName() { |
|
123 |
return TYPENAME; |
|
124 |
} |
|
125 |
|
|
126 |
/** |
|
127 |
* Returns the name of ProjectDocument. |
|
128 |
* |
|
129 |
* @return Name of ProjectDocument. |
|
130 |
*/ |
|
131 |
public String getTitle() { |
|
132 |
return PluginServices.getText(this, "Mapa"); |
|
133 |
} |
|
134 |
|
|
135 |
public AbstractDocument createDocument() { |
|
136 |
return new DefaultLayoutDocument(this); |
|
137 |
} |
|
138 |
|
|
139 |
public Class getMainWindowClass() { |
|
140 |
return LayoutPanelImpl.class; |
|
141 |
} |
|
142 |
|
|
143 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
|
144 |
LayoutPanel layoutPanel = (LayoutPanel) super.getMainWindow(doc, layout); |
|
145 |
if (layoutPanel == null) { |
|
146 |
layoutPanel = (LayoutPanel) this.createDocumentWindow(doc); |
|
147 |
if (layout != null) { |
|
148 |
layoutPanel.setWindowLayout(layout); |
|
149 |
layoutPanel.setLayoutManager(this); |
|
150 |
layoutPanel.getLayoutControl().fullRect(); |
|
151 |
layoutPanel.getWindowInfo().setTitle( |
|
152 |
PluginServices.getText(this, "Mapa") + " : " |
|
153 |
+ layoutPanel.getName()); |
|
154 |
} |
|
155 |
} |
|
156 |
((AbstractDocument) doc).raiseEventCreateWindow(layoutPanel); |
|
157 |
return layoutPanel; |
|
158 |
} |
|
159 |
|
|
160 |
public IFFrameDialog createFFrameDialog(IFFrame fframe, |
|
161 |
LayoutPanel layoutPanel, AffineTransform affineTransform) { |
|
162 |
ExtensionPoint ep = extensionPoints.add(KEY_LAYOUT_FFRAMEDIALOG); |
|
163 |
|
|
164 |
try { |
|
165 |
Object[] args = new Object[2]; |
|
166 |
args[0] = layoutPanel; |
|
167 |
args[1] = fframe; |
|
168 |
Object obj = ep.create(fframe.getName(), args); |
|
169 |
if (obj != null) { |
|
170 |
IFFrameDialog fframedialog = (IFFrameDialog) obj; |
|
171 |
fframedialog.setRectangle(fframe |
|
172 |
.getBoundingBox(affineTransform)); |
|
173 |
return fframedialog; |
|
174 |
} |
|
175 |
} catch (Exception e) { |
|
176 |
LOG.error("Error creating a FFrameDialog", e); |
|
177 |
} |
|
178 |
return null; |
|
179 |
} |
|
180 |
|
|
181 |
public IFFrameDialog createFFrameDialog(IFFrame fframe, |
|
182 |
LayoutPanel layoutPanel) { |
|
183 |
return createFFrameDialog(fframe, layoutPanel, layoutPanel |
|
184 |
.getLayoutControl().getAT()); |
|
185 |
} |
|
186 |
|
|
187 |
public void registerFrameFactory(FrameFactory frameFactory, String alias) { |
|
188 |
ExtensionPoint ep = |
|
189 |
ToolsLocator.getExtensionPointManager().add(KEY_LAYOUT_FFRAME); |
|
190 |
ep.append(frameFactory.getRegisterName(), "", frameFactory); |
|
191 |
if (alias != null) { |
|
192 |
ep.addAlias(frameFactory.getRegisterName(), alias); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
public void registerFrameFactory(FrameFactory frameFactory) { |
|
197 |
registerFrameFactory(frameFactory, null); |
|
198 |
} |
|
199 |
|
|
200 |
@SuppressWarnings("unchecked") |
|
201 |
public IFFrame createFrame(String frameName) { |
|
202 |
|
|
203 |
Iterator<Extension> iterator = |
|
204 |
ToolsLocator.getExtensionPointManager().get(KEY_LAYOUT_FFRAME) |
|
205 |
.iterator(); |
|
206 |
while (iterator.hasNext()) { |
|
207 |
try { |
|
208 |
FrameFactory frameFactory = |
|
209 |
(FrameFactory) iterator.next().create(); |
|
210 |
if (frameFactory.getRegisterName().equals(frameName)) { |
|
211 |
IFFrame frame = frameFactory.createFrame(); |
|
212 |
if (frame == null) { |
|
213 |
return null; |
|
214 |
} |
|
215 |
frame.setFrameFactory(frameFactory); |
|
216 |
return frame; |
|
217 |
} |
|
218 |
} catch (Exception e) { |
|
219 |
NotificationManager.addError(e); |
|
220 |
} |
|
221 |
} |
|
222 |
return null; |
|
223 |
} |
|
224 |
|
|
225 |
@SuppressWarnings("unchecked") |
|
226 |
public void registerFFrameDialog(String name, Class clazz) { |
|
227 |
if (!IFFrameDialog.class.isAssignableFrom(clazz)) { |
|
228 |
throw new IllegalArgumentException(clazz.getName() |
|
229 |
+ " must implement the IFFrameDialog interface"); |
|
230 |
} |
|
231 |
ExtensionPoint extensionPoint = |
|
232 |
extensionPoints.add(KEY_LAYOUT_FFRAMEDIALOG, ""); |
|
233 |
extensionPoint.append(name, name, clazz); |
|
234 |
} |
|
235 |
|
|
236 |
@Override |
|
237 |
public IWindow getPropertiesWindow(Document doc) { |
|
238 |
IWindow win = super.getPropertiesWindow(doc); |
|
239 |
if( win == null ) { |
|
240 |
win = new MapProperties((LayoutDocument) doc); |
|
241 |
} |
|
242 |
return win; |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* Registers in the points of extension the Factory with alias. |
|
247 |
* |
|
248 |
*/ |
|
249 |
public static void register() { |
|
250 |
DefaultLayoutManager factory = new DefaultLayoutManager(); |
|
251 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
252 |
manager.registerFactory(factory); |
|
253 |
|
|
254 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
|
255 |
|
|
256 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction()); |
|
257 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction()); |
|
258 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction()); |
|
259 |
|
|
260 |
|
|
261 |
if (factory.persistenceDefinition == null) { |
|
262 |
factory.persistenceDefinition = |
|
263 |
manager.addDefinition(LayoutDocument.class, |
|
264 |
PERSISTENCE_LAYOUT_DOCUMENT_DEFINITION_NAME, |
|
265 |
"Layout document Persistence definition", null, null); |
|
266 |
factory.persistenceDefinition.extend(manager |
|
267 |
.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME)); |
|
268 |
|
|
269 |
factory.persistenceDefinition |
|
270 |
.addDynFieldObject(DefaultLayoutDocument.LAYOUT_CONTEXT_OBJECT) |
|
271 |
.setClassOfValue(LayoutContext.class).setMandatory(false); |
|
272 |
|
|
273 |
DefaultLayoutPanel.registerPersistent(); |
|
274 |
DefaultLayoutContext.registerPersistent(); |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
public int getPriority() { |
|
279 |
return 2; |
|
280 |
} |
|
281 |
|
|
282 |
/** |
|
283 |
* Sets whether the grid should be shown. |
|
284 |
* |
|
285 |
* @param showGrid |
|
286 |
*/ |
|
287 |
public void setDefaultShowGrid(boolean showGrid) { |
|
288 |
defaultShowGrid = new Boolean(showGrid); |
|
289 |
} |
|
290 |
|
|
291 |
/** |
|
292 |
* Sets whether the snapping to grid should be enabled or not |
|
293 |
* |
|
294 |
* @param gridEnable |
|
295 |
*/ |
|
296 |
public void setDefaultAdjustToGrid(boolean gridEnabled) { |
|
297 |
defaultAdjustToGrid = new Boolean(gridEnabled); |
|
298 |
} |
|
299 |
|
|
300 |
/** |
|
301 |
* Sets whether the ruler should be shown or not |
|
302 |
* |
|
303 |
* @param showRuler |
|
304 |
*/ |
|
305 |
public void setDefaultShowRulers(boolean showRules) { |
|
306 |
defaultShowRulers = new Boolean(showRules); |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 |
* Returns if the grid should be shown. |
|
311 |
* |
|
312 |
* @return True if the grid should be shown. |
|
313 |
*/ |
|
314 |
public boolean getDefaultShowGrid() { |
|
315 |
if (defaultShowGrid == null) { |
|
316 |
XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML(); |
|
317 |
if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) { |
|
318 |
defaultShowGrid = |
|
319 |
new Boolean(xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)); |
|
320 |
} else { |
|
321 |
defaultShowGrid = new Boolean(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_SHOW); |
|
322 |
} |
|
323 |
} |
|
324 |
return defaultShowGrid.booleanValue(); |
|
325 |
} |
|
326 |
|
|
327 |
/** |
|
328 |
* Returns if the adjust to grid should be active. |
|
329 |
* |
|
330 |
* @return True if the adjust to grid should be active. |
|
331 |
*/ |
|
332 |
public boolean getDefaultAdjustToGrid() { |
|
333 |
if (defaultAdjustToGrid == null) { |
|
334 |
XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML(); |
|
335 |
if (xml.contains(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) { |
|
336 |
defaultAdjustToGrid = |
|
337 |
new Boolean( |
|
338 |
xml.getBooleanProperty(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)); |
|
339 |
} else { |
|
340 |
defaultAdjustToGrid = new Boolean(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_ENABLE); |
|
341 |
} |
|
342 |
} |
|
343 |
return defaultAdjustToGrid.booleanValue(); |
|
344 |
} |
|
345 |
|
|
346 |
/** |
|
347 |
* Returns if the ruler should be shown. |
|
348 |
* |
|
349 |
* @return True if the ruler should be shown. |
|
350 |
*/ |
|
351 |
public boolean getDefaultShowRulers() { |
|
352 |
if (defaultShowRulers == null) { |
|
353 |
XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML(); |
|
354 |
if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME)) { |
|
355 |
defaultShowRulers = |
|
356 |
new Boolean( |
|
357 |
xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME)); |
|
358 |
} else { |
|
359 |
defaultShowRulers = new Boolean(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS); |
|
360 |
} |
|
361 |
} |
|
362 |
return defaultShowRulers.booleanValue(); |
|
363 |
} |
|
364 |
|
|
365 |
public boolean getDefaultShowInitialPageConfigDialog() { |
|
366 |
XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML(); |
|
367 |
boolean value; |
|
368 |
if (xml.contains(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME)) { |
|
369 |
value = xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME); |
|
370 |
} else { |
|
371 |
value = PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT; |
|
372 |
} |
|
373 |
return value; |
|
374 |
} |
|
375 |
|
|
376 |
public DynStruct getDefinition(String className) { |
|
377 |
|
|
378 |
if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
|
379 |
return this.persistenceDefinition; |
|
380 |
} |
|
381 |
if (this.persistenceDefinition.getFullName() |
|
382 |
.equalsIgnoreCase(className)) { |
|
383 |
return this.persistenceDefinition; |
|
384 |
} |
|
385 |
if (this.getDocumentClass().getName().equals(className)) { |
|
386 |
return this.persistenceDefinition; |
|
387 |
} |
|
388 |
return null; |
|
389 |
} |
|
390 |
|
|
391 |
@SuppressWarnings("unchecked") |
|
392 |
protected Class getDocumentClass() { |
|
393 |
return DefaultLayoutDocument.class; |
|
394 |
} |
|
395 |
|
|
396 |
public boolean manages(Object object) { |
|
397 |
return object instanceof LayoutDocument; |
|
398 |
} |
|
399 |
|
|
400 |
public void registerLayoutMenuAction(String name, |
|
401 |
Class<? extends IContextMenuAction> clazz) { |
|
402 |
ExtensionPoint extensionPoint = |
|
403 |
ToolsLocator.getExtensionPointManager().add(LAYOUT_CONTEXT_MENUS); |
|
404 |
extensionPoint.append(name, "", clazz); |
|
405 |
} |
|
406 |
|
|
407 |
public IContextMenuAction[] createLayoutMenuActions(LayoutPanel layoutPanel) { |
|
408 |
List<IContextMenuAction> actionArrayList = |
|
409 |
new ArrayList<IContextMenuAction>(); |
|
410 |
@SuppressWarnings("unchecked") |
|
411 |
Iterator<ExtensionPoint.Extension> iter = |
|
412 |
ToolsLocator.getExtensionPointManager().get(LAYOUT_CONTEXT_MENUS).iterator(); |
|
413 |
AbstractLayoutContextMenuAction action; |
|
414 |
while (iter.hasNext()) { |
|
415 |
action = null; |
|
416 |
try { |
|
417 |
action = (AbstractLayoutContextMenuAction) iter.next().create(); |
|
418 |
} catch (InstantiationException e) { |
|
419 |
LOG.error("Error creating the context menu", e); |
|
420 |
} catch (IllegalAccessException e) { |
|
421 |
LOG.error("Error creating the context menu", e); |
|
422 |
} |
|
423 |
if (action != null) { |
|
424 |
action.setLayout(layoutPanel); |
|
425 |
if (action.isVisible(null, layoutPanel.getLayoutContext().getSelectedFFrames())) { |
|
426 |
actionArrayList.add(action); |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
IContextMenuAction[] result = |
|
431 |
(IContextMenuAction[]) Array.newInstance(IContextMenuAction.class, |
|
432 |
actionArrayList.size()); |
|
433 |
System.arraycopy(actionArrayList.toArray(), 0, result, 0, |
|
434 |
actionArrayList.size()); |
|
435 |
Arrays.sort(result, new CompareAction()); |
|
436 |
return result; |
|
437 |
} |
|
438 |
|
|
439 |
private class CompareAction implements Comparator<IContextMenuAction> { |
|
440 |
|
|
441 |
public int compare(IContextMenuAction o1, IContextMenuAction o2) { |
|
442 |
NumberFormat formater = NumberFormat.getInstance(); |
|
443 |
formater.setMinimumIntegerDigits(3); |
|
444 |
String key1 = |
|
445 |
"" + formater.format(o1.getGroupOrder()) + o1.getGroup() |
|
446 |
+ formater.format(o1.getOrder()); |
|
447 |
String key2 = |
|
448 |
"" + formater.format(o2.getGroupOrder()) + o2.getGroup() |
|
449 |
+ formater.format(o2.getOrder()); |
|
450 |
return key1.compareTo(key2); |
|
451 |
} |
|
452 |
} |
|
453 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.242/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutControl.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.Image; |
|
25 |
import java.awt.Point; |
|
26 |
import java.awt.Rectangle; |
|
27 |
import java.awt.geom.AffineTransform; |
|
28 |
import java.awt.geom.Rectangle2D; |
|
29 |
import java.awt.image.BufferedImage; |
|
30 |
|
|
31 |
import javax.swing.JComponent; |
|
32 |
|
|
33 |
import org.gvsig.app.project.documents.layout.geometryadapters.GeometryAdapter; |
|
34 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
35 |
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutBehavior; |
|
36 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
37 |
import org.gvsig.tools.observer.Observer; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
|
41 |
*/ |
|
42 |
public interface LayoutControl extends Observer { |
|
43 |
|
|
44 |
/** |
|
45 |
* <p>Returns a copy of the rectangle that represents the size |
|
46 |
* and position of the layout sheet (in pixels), relative to |
|
47 |
* the containing LayoutControl.</p> |
|
48 |
* |
|
49 |
* <p>Note: you must use {@link #setRect(Rectangle2D)} to update |
|
50 |
* the rectangle, as this method only returns a copy of it.</p> |
|
51 |
* @return Rectangle2D.Double Rectangle that represents the sheet. |
|
52 |
* @see LayoutControl#setRect(Rectangle2D) |
|
53 |
*/ |
|
54 |
public Rectangle2D.Double getRect(); |
|
55 |
|
|
56 |
/** |
|
57 |
* <p>Sets the size and position of the layout sheet in screen coordinates |
|
58 |
* (pixels), relative to the LayoutControl.</p> |
|
59 |
* |
|
60 |
* <p>The size of the sheet is usually different from the |
|
61 |
* bounds of the underlying UI control, for instance if we have zoomed in |
|
62 |
* an area of the sheet then the paper size in pixels will be bigger than |
|
63 |
* the actual control size.</p> |
|
64 |
* |
|
65 |
*/ |
|
66 |
public void setRect(Rectangle2D r); |
|
67 |
|
|
68 |
/** |
|
69 |
* Returns the name of the current selected tool on this Layout |
|
70 |
* |
|
71 |
* @return A tool name. |
|
72 |
*/ |
|
73 |
public String getCurrentTool(); |
|
74 |
|
|
75 |
/** |
|
76 |
* Add a new Layout tool. |
|
77 |
* |
|
78 |
* @param name |
|
79 |
* Name of tool. |
|
80 |
* @param tool |
|
81 |
* LayoutBehavior |
|
82 |
*/ |
|
83 |
public void addLayoutTool(String name, LayoutBehavior tool); |
|
84 |
|
|
85 |
/** |
|
86 |
* Inserts the LayoutContext. |
|
87 |
* |
|
88 |
* @param lc |
|
89 |
* LayoutContext. |
|
90 |
*/ |
|
91 |
public void setLayoutContext(LayoutContext lc); |
|
92 |
|
|
93 |
/** |
|
94 |
* Returns the image with the ruler. |
|
95 |
* |
|
96 |
* @return Ruler image. |
|
97 |
*/ |
|
98 |
public BufferedImage getImgRuler(); |
|
99 |
|
|
100 |
/** |
|
101 |
* It obtains the rect that is adjusted to the size of the window, |
|
102 |
* to see the full extent of layout. |
|
103 |
*/ |
|
104 |
public void fullRect(); |
|
105 |
|
|
106 |
/** |
|
107 |
* Returns the current image of Layout. |
|
108 |
* |
|
109 |
* @return Current image of Layout. |
|
110 |
*/ |
|
111 |
public BufferedImage getImage(); |
|
112 |
|
|
113 |
/** |
|
114 |
* Changes the pointer of the mouse by the image of parameter. |
|
115 |
* |
|
116 |
* @param image |
|
117 |
* Image |
|
118 |
*/ |
|
119 |
public void setMapCursor(Image image); |
|
120 |
|
|
121 |
/** |
|
122 |
* It establishes as selected to the tool from its name of identification. |
|
123 |
* |
|
124 |
* @param toolName |
|
125 |
* Name of identification tool. |
|
126 |
*/ |
|
127 |
public void setTool(String toolName); |
|
128 |
|
|
129 |
/** |
|
130 |
* Changes the currently selected tool to the default tool |
|
131 |
*/ |
|
132 |
public void setDefaultTool(); |
|
133 |
|
|
134 |
/** |
|
135 |
* Start the vertex edition of graphics. |
|
136 |
* |
|
137 |
*/ |
|
138 |
public void startEdit(); |
|
139 |
|
|
140 |
/** |
|
141 |
* Stop the vertex edition of graphics. |
|
142 |
* |
|
143 |
*/ |
|
144 |
public void stopEdit(); |
|
145 |
|
|
146 |
/** |
|
147 |
* It returns the point that represents the northwest corner of the Layout. |
|
148 |
* |
|
149 |
* @return Point. |
|
150 |
*/ |
|
151 |
public Point getRectOrigin(); |
|
152 |
|
|
153 |
/** |
|
154 |
* Returns the object to draw the Layout. |
|
155 |
* |
|
156 |
* @return FLayoutDraw. |
|
157 |
*/ |
|
158 |
public FLayoutDraw getLayoutDraw(); |
|
159 |
|
|
160 |
/** |
|
161 |
* Returns the current Layout tool. |
|
162 |
* |
|
163 |
* @return LayoutBehavior Current Layout Tool. |
|
164 |
*/ |
|
165 |
public LayoutBehavior getCurrentLayoutTool(); |
|
166 |
|
|
167 |
/** |
|
168 |
* It returns the first click point of mouse. |
|
169 |
* |
|
170 |
* @return Point. |
|
171 |
*/ |
|
172 |
public Point getFirstPoint(); |
|
173 |
|
|
174 |
/** |
|
175 |
* Returns the previous click of mouse. |
|
176 |
* |
|
177 |
* @return Point. |
|
178 |
*/ |
|
179 |
public Point getPointAnt(); |
|
180 |
|
|
181 |
/** |
|
182 |
* Returns the last click point of mouse. |
|
183 |
* |
|
184 |
* @return Point. |
|
185 |
*/ |
|
186 |
public Point getLastPoint(); |
|
187 |
|
|
188 |
/** |
|
189 |
* Inserts the first click point of mouse. |
|
190 |
* |
|
191 |
* @param p |
|
192 |
* Point. |
|
193 |
*/ |
|
194 |
public void setFirstPoint(); |
|
195 |
|
|
196 |
/** |
|
197 |
* Inserts the previous click point of mouse. |
|
198 |
* |
|
199 |
* @param p |
|
200 |
* Point. |
|
201 |
*/ |
|
202 |
public void setPointAnt(); |
|
203 |
|
|
204 |
/** |
|
205 |
* Inserts the last click point of mouse. |
|
206 |
* |
|
207 |
* @param p |
|
208 |
* Point. |
|
209 |
*/ |
|
210 |
public void setLastPoint(); |
|
211 |
|
|
212 |
/** |
|
213 |
* Insert the position point and calculate the new position if the grid is |
|
214 |
* actived. |
|
215 |
* |
|
216 |
* @param point2 |
|
217 |
* Position. |
|
218 |
*/ |
|
219 |
public void setPosition(Point point2); |
|
220 |
|
|
221 |
/** |
|
222 |
* Returns the position adjusted point. |
|
223 |
* |
|
224 |
* @return |
|
225 |
*/ |
|
226 |
public Point getPosition(); |
|
227 |
|
|
228 |
/** |
|
229 |
* Returns the AffineTransform that is applying in the Layout. |
|
230 |
* |
|
231 |
* @return AffineTransform |
|
232 |
*/ |
|
233 |
public AffineTransform getAT(); |
|
234 |
|
|
235 |
/** |
|
236 |
* It returns the current GeometryAdapter. |
|
237 |
* |
|
238 |
* @return Current GeometryAdapter. |
|
239 |
*/ |
|
240 |
public GeometryAdapter getGeometryAdapter(); |
|
241 |
|
|
242 |
/** |
|
243 |
* Remove last point of geometryAdapter. |
|
244 |
* |
|
245 |
*/ |
|
246 |
public void delLastPoint(); |
|
247 |
|
|
248 |
/** |
|
249 |
* Add a new point to geometryAdapter. |
|
250 |
* |
|
251 |
* @return Number of points in the geometryAdapter. |
|
252 |
*/ |
|
253 |
public int addGeometryAdapterPoint(); |
|
254 |
|
|
255 |
/** |
|
256 |
* Change the position of mousemoved point of geometryAdapter. |
|
257 |
*/ |
|
258 |
public void setGeometryAdapterPoinPosition(); |
|
259 |
|
|
260 |
/** |
|
261 |
* Clear the image of pointer of mouse. |
|
262 |
*/ |
|
263 |
public void clearMouseImage(); |
|
264 |
|
|
265 |
/** |
|
266 |
* Refres the Layout. |
|
267 |
*/ |
|
268 |
public void refresh(); |
|
269 |
|
|
270 |
/** |
|
271 |
* It returns true if the drawing has been canceled. |
|
272 |
* |
|
273 |
* @return true if the drawn has been canceled. |
|
274 |
*/ |
|
275 |
public boolean isDrawingCancelled(); |
|
276 |
|
|
277 |
/** |
|
278 |
* It cancels the drawing if the parameter is true. |
|
279 |
* |
|
280 |
* @param b |
|
281 |
* true if the drawing wants to be canceled |
|
282 |
*/ |
|
283 |
public void setCancelDrawing(boolean b); |
|
284 |
|
|
285 |
/** |
|
286 |
* Returns the rectangle of selection. |
|
287 |
* |
|
288 |
* @return Rectangle of selection. |
|
289 |
*/ |
|
290 |
public Rectangle getReSel(); |
|
291 |
|
|
292 |
/** |
|
293 |
* It returns true if should draw the rectangle of selection and does the |
|
294 |
* selection. |
|
295 |
* |
|
296 |
* @return true if should draw the rectangle of selection. |
|
297 |
*/ |
|
298 |
public boolean isReSel(); |
|
299 |
|
|
300 |
/** |
|
301 |
* Insert true if should draw the rectangle of selection and does the |
|
302 |
* selection. |
|
303 |
* |
|
304 |
* @param b |
|
305 |
* boolean. |
|
306 |
*/ |
|
307 |
public void setIsReSel(boolean b); |
|
308 |
|
|
309 |
/** |
|
310 |
* It does a full extent of the layers that contains the view of the |
|
311 |
* FFrameView selected. |
|
312 |
* |
|
313 |
* @throws ReadDriverException |
|
314 |
*/ |
|
315 |
public void viewFull() throws ReadException; |
|
316 |
|
|
317 |
/** |
|
318 |
* Returns the object to make zooms. |
|
319 |
* |
|
320 |
* @return FLayoutZooms. |
|
321 |
*/ |
|
322 |
public FLayoutZooms getLayoutZooms(); |
|
323 |
|
|
324 |
/** |
|
325 |
* Returns the object of FLayoutFunctions. |
|
326 |
* |
|
327 |
* @return FLayoutFunctions |
|
328 |
*/ |
|
329 |
public FLayoutFunctions getLayoutFunctions(); |
|
330 |
|
|
331 |
/** |
|
332 |
* Returns the LayoutContext. |
|
333 |
* |
|
334 |
* @return LayoutContext. |
|
335 |
*/ |
|
336 |
public LayoutContext getLayoutContext(); |
|
337 |
|
|
338 |
/** |
|
339 |
* Inserts the geometryAdapter. |
|
340 |
* |
|
341 |
* @param adapter |
|
342 |
* GeometryAdapter. |
|
343 |
*/ |
|
344 |
public void setGeometryAdapter(GeometryAdapter adapter); |
|
345 |
|
|
346 |
public JComponent getComponent(); |
|
347 |
|
|
348 |
public int getWidth(); |
|
349 |
|
|
350 |
public int getHeight(); |
|
351 |
|
|
352 |
public void repaint(); |
|
353 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.242/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutUtilities.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.geom.AffineTransform; |
|
27 |
import java.awt.geom.NoninvertibleTransformException; |
|
28 |
import java.awt.geom.Point2D; |
|
29 |
import java.awt.geom.Rectangle2D; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import org.cresques.cts.IProjection; |
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
37 |
import org.gvsig.app.project.documents.Document; |
|
38 |
import org.gvsig.app.project.documents.layout.fframes.FFrameView; |
|
39 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
|
40 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
|
41 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
42 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
43 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
46 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
47 |
|
|
48 |
/** |
|
49 |
* Clase que recoge m?todos est?ticos sobre el Layout. |
|
50 |
* |
|
51 |
* @author Vicente Caballero Navarro |
|
52 |
*/ |
|
53 |
public class FLayoutUtilities { |
|
54 |
|
|
55 |
private static Logger logger = LoggerFactory.getLogger( |
|
56 |
FLayoutUtilities.class); |
|
57 |
|
|
58 |
/** |
|
59 |
* Devuelve true si las dos ArrayList que se le pasan como parametro son |
|
60 |
* iguales. |
|
61 |
* |
|
62 |
* @param n |
|
63 |
* lista anterior |
|
64 |
* @param l |
|
65 |
* lista actual |
|
66 |
* |
|
67 |
* @return true si los ArrayList son iguales. |
|
68 |
*/ |
|
69 |
public static boolean isEqualList(ArrayList n, ArrayList l) { |
|
70 |
if (n.size() != l.size()) { |
|
71 |
return false; |
|
72 |
} |
|
73 |
|
|
74 |
for (int i = 0; i < n.size(); i++) { |
|
75 |
if (l.get(i) != n.get(i)) { |
|
76 |
return false; |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
return true; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Pasa una distancia en pixels a unidades del folio. |
|
85 |
* |
|
86 |
* @param d |
|
87 |
* distancia en pixels. |
|
88 |
* @param at |
|
89 |
* Matriz de transformaci?n. |
|
90 |
* |
|
91 |
* @return distancia en unidades de folio. |
|
92 |
*/ |
|
93 |
public static double toSheetDistance(double d, AffineTransform at) { |
|
94 |
double dist = d / at.getScaleX(); // pProv.x; |
|
95 |
|
|
96 |
return dist; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Pasa una distancia de coordenadas del folio a pixels. |
|
101 |
* |
|
102 |
* @param d |
|
103 |
* distancia en coordenadas de folio. |
|
104 |
* @param at |
|
105 |
* Matriz de transformaci?n. |
|
106 |
* |
|
107 |
* @return double en pixels. |
|
108 |
*/ |
|
109 |
public static double fromSheetDistance(double d, AffineTransform at) { |
|
110 |
Point2D.Double pSheet1 = new Point2D.Double(0, 0); |
|
111 |
Point2D.Double pSheet2 = new Point2D.Double(1, 0); |
|
112 |
Point2D.Double pScreen1 = new Point2D.Double(); |
|
113 |
Point2D.Double pScreen2 = new Point2D.Double(); |
|
114 |
|
|
115 |
try { |
|
116 |
at.transform(pSheet1, pScreen1); |
|
117 |
at.transform(pSheet2, pScreen2); |
|
118 |
} catch (Exception e) { |
|
119 |
System.err.print(e.getMessage()); |
|
120 |
} |
|
121 |
|
|
122 |
return pScreen1.distance(pScreen2) * d; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Pasa un punto en pixels a coordenadas del folio. |
|
127 |
* |
|
128 |
* @param pScreen |
|
129 |
* pixels. |
|
130 |
* @param at |
|
131 |
* Matriz de transformaci?n. |
|
132 |
* |
|
133 |
* @return Point2D en coordenadas de folio. |
|
134 |
*/ |
|
135 |
public static Point2D.Double toSheetPoint(Point2D pScreen, |
|
136 |
AffineTransform at) { |
|
137 |
Point2D.Double pWorld = new Point2D.Double(); |
|
138 |
AffineTransform at1; |
|
139 |
|
|
140 |
try { |
|
141 |
at1 = at.createInverse(); |
|
142 |
at1.transform(pScreen, pWorld); |
|
143 |
} catch (NoninvertibleTransformException e) { |
|
144 |
} |
|
145 |
|
|
146 |
return pWorld; |
|
147 |
} |
|
148 |
|
|
149 |
/** |
|
150 |
* Pasa un ret?ngulo de pixels a coordenadas del folio. |
|
151 |
* |
|
152 |
* @param r |
|
153 |
* rect?ngulo en coordenadas de pixels a coordenadas de folio. |
|
154 |
* @param at |
|
155 |
* Matriz de transformaci?n. |
|
156 |
* |
|
157 |
* @return Rectangle2D en coordenadas de folio. |
|
158 |
*/ |
|
159 |
public static Rectangle2D.Double toSheetRect(Rectangle2D r, |
|
160 |
AffineTransform at) { |
|
161 |
Point2D.Double pSheet = |
|
162 |
toSheetPoint(new Point2D.Double(r.getX(), r.getY()), at); |
|
163 |
Point2D.Double pSheetX = |
|
164 |
toSheetPoint(new Point2D.Double(r.getMaxX(), r.getMinY()), at); |
|
165 |
Point2D.Double pSheetY = |
|
166 |
toSheetPoint(new Point2D.Double(r.getMinX(), r.getMaxY()), at); |
|
167 |
Rectangle2D.Double res = new Rectangle2D.Double(); |
|
168 |
res.setRect(pSheet.getX(), pSheet.getY(), pSheet.distance(pSheetX), |
|
169 |
pSheet.distance(pSheetY)); |
|
170 |
|
|
171 |
return res; |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* Pasa de un punto en coordenadas del folio a pixels. |
|
176 |
* |
|
177 |
* @param pSheet |
|
178 |
* punto en coordenadas de folio. |
|
179 |
* @param at |
|
180 |
* Matriz de transformaci?n. |
|
181 |
* |
|
182 |
* @return Point2D en pixels. |
|
183 |
*/ |
|
184 |
public static Point2D.Double fromSheetPoint(Point2D pSheet, |
|
185 |
AffineTransform at) { |
|
186 |
Point2D.Double pScreen = new Point2D.Double(); |
|
187 |
|
|
188 |
try { |
|
189 |
at.transform(pSheet, pScreen); |
|
190 |
} catch (Exception e) { |
|
191 |
System.err.print(e.getMessage()); |
|
192 |
} |
|
193 |
|
|
194 |
return pScreen; |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Pasa un rect?ngulo en coordenadas del folio a pixels. |
|
199 |
* |
|
200 |
* @param r |
|
201 |
* rect?ngulo en coordenadas de folio. |
|
202 |
* @param at |
|
203 |
* Matriz de transformaci?n. |
|
204 |
* |
|
205 |
* @return Rectangle2D en pixels. |
|
206 |
*/ |
|
207 |
public static Rectangle2D.Double fromSheetRect(Rectangle2D r, |
|
208 |
AffineTransform at) { |
|
209 |
Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY()); |
|
210 |
Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY()); |
|
211 |
Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY()); |
|
212 |
Point2D.Double pScreen = new Point2D.Double(); |
|
213 |
Point2D.Double pScreenX = new Point2D.Double(); |
|
214 |
Point2D.Double pScreenY = new Point2D.Double(); |
|
215 |
|
|
216 |
try { |
|
217 |
at.transform(pSheet, pScreen); |
|
218 |
at.transform(pSX, pScreenX); |
|
219 |
at.transform(pSY, pScreenY); |
|
220 |
} catch (Exception e) { |
|
221 |
System.err.print(e.getMessage()); |
|
222 |
} |
|
223 |
|
|
224 |
Rectangle2D.Double res = new Rectangle2D.Double(); |
|
225 |
res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), |
|
226 |
pScreen.distance(pScreenY)); |
|
227 |
|
|
228 |
return res; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Obtiene el punto ajustado al grid del layout. |
|
233 |
* |
|
234 |
* @param p |
|
235 |
* Punto a ajustar. |
|
236 |
* @param distX |
|
237 |
* Distancia m?nima en cm de X. |
|
238 |
* @param distY |
|
239 |
* Distancia m?nima en cm de Y. |
|
240 |
* @param at |
|
241 |
* Matriz de transformaci?n. |
|
242 |
*/ |
|
243 |
public static Point getPointGrid(Point p, double distX, double distY, |
|
244 |
AffineTransform at) { |
|
245 |
|
|
246 |
if (distX * at.getScaleX() < 2 && distY * at.getScaleY() < 2) { |
|
247 |
/* |
|
248 |
* In this case, it makes no sense to care about snapping |
|
249 |
* because snapping would mean to move the position by one pixel |
|
250 |
*/ |
|
251 |
return p; |
|
252 |
} |
|
253 |
|
|
254 |
Point2D.Double auxp = |
|
255 |
FLayoutUtilities.fromSheetPoint(new Point2D.Double(0, 0), at); |
|
256 |
|
|
257 |
double gridintx = distX * at.getScaleX(); |
|
258 |
double gridinty = distY * at.getScaleY(); |
|
259 |
|
|
260 |
double seppx = p.x - Math.round(auxp.x); |
|
261 |
double seppy = p.y - Math.round(auxp.y); |
|
262 |
|
|
263 |
long round_int_p_x = Math.round(seppx / gridintx); |
|
264 |
long round_int_p_y = Math.round(seppy / gridinty); |
|
265 |
|
|
266 |
// Rounded |
|
267 |
seppx = round_int_p_x * gridintx; |
|
268 |
seppy = round_int_p_y * gridinty; |
|
269 |
|
|
270 |
return new Point( |
|
271 |
(int) (auxp.x + seppx), |
|
272 |
(int) (auxp.y + seppy)); |
|
273 |
} |
|
274 |
|
|
275 |
/** |
|
276 |
* Cuando se dibuja sobre el graphics todo se tiene que situar en enteros y |
|
277 |
* aqu? lo que se comprueba es que si los valores que contiene el |
|
278 |
* Rectangle2D, que toma como par?metro, supera los valores soportados por |
|
279 |
* un entero. |
|
280 |
* |
|
281 |
* @param r |
|
282 |
* Rectangle2D a comprobar si los valores que contiene no superan |
|
283 |
* a los que puede tener un entero. |
|
284 |
* |
|
285 |
* @return true si no se han superado los l?mites. |
|
286 |
*/ |
|
287 |
public static boolean isPosible(Rectangle2D.Double r) { |
|
288 |
if ((r.getMaxX() > Integer.MAX_VALUE) |
|
289 |
|| (r.getMaxY() > Integer.MAX_VALUE) |
|
290 |
|| (r.getMinX() < Integer.MIN_VALUE) |
|
291 |
|| (r.getMinY() < Integer.MIN_VALUE) |
|
292 |
|| (r.getWidth() > Integer.MAX_VALUE) |
|
293 |
|| (r.getHeight() > Integer.MAX_VALUE)) { |
|
294 |
return false; |
|
295 |
} |
|
296 |
|
|
297 |
return true; |
|
298 |
} |
|
299 |
|
|
300 |
public static List<Document> removeEditing(List<Document> list) { |
|
301 |
|
|
302 |
List<Document> resp = new ArrayList<Document>(); |
|
303 |
|
|
304 |
Document item = null; |
|
305 |
ViewDocument viewdoc = null; |
|
306 |
for (int i=0; i<list.size(); i++) { |
|
307 |
item = list.get(i); |
|
308 |
if (item instanceof ViewDocument) { |
|
309 |
viewdoc = (ViewDocument) item; |
|
310 |
if (!hasEditingLayers(viewdoc)) { |
|
311 |
resp.add(item); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
return resp; |
|
316 |
} |
|
317 |
|
|
318 |
|
|
319 |
public static boolean hasEditingLayers(ViewDocument viewdoc) { |
|
320 |
return hasEditingLayers(viewdoc.getMapContext().getLayers()); |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* Recursively find out if any layer is in editing mode |
|
325 |
* |
|
326 |
* @param lyrs |
|
327 |
* @return |
|
328 |
*/ |
|
329 |
public static boolean hasEditingLayers(FLayers lyrs) { |
|
330 |
|
|
331 |
int len = lyrs.getLayersCount(); |
|
332 |
FLayer lyr = null; |
|
333 |
FLyrVect vlyr = null; |
|
334 |
for (int i=0; i<len; i++) { |
|
335 |
lyr = lyrs.getLayer(i); |
|
336 |
if (lyr instanceof FLyrVect) { |
|
337 |
vlyr = (FLyrVect) lyr; |
|
338 |
if (vlyr.isEditing()) { |
|
339 |
return true; |
|
340 |
} |
|
341 |
} else { |
|
342 |
if (lyr instanceof FLayers) { |
|
343 |
if (hasEditingLayers((FLayers) lyr)) { |
|
344 |
return true; |
|
345 |
} |
|
346 |
} |
|
347 |
} |
Also available in: Unified diff