Revision 316
tags/org.gvsig.app.document.layout2.app-2.0.41/org.gvsig.app.document.layout2.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Wed Oct 29 10:56:12 EDT 2014 |
|
2 |
buildNumber=60 |
|
0 | 3 |
tags/org.gvsig.app.document.layout2.app-2.0.41/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.41/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.41/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.41/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.41/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/PrintPropertiesPage.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.gui.preferencespage; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.awt.GridLayout; |
|
26 |
|
|
27 |
import javax.swing.ButtonGroup; |
|
28 |
import javax.swing.ImageIcon; |
|
29 |
import javax.swing.JCheckBox; |
|
30 |
import javax.swing.JLabel; |
|
31 |
import javax.swing.JPanel; |
|
32 |
import javax.swing.JRadioButton; |
|
33 |
import javax.swing.JTextField; |
|
34 |
|
|
35 |
import org.gvsig.andami.PluginServices; |
|
36 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
|
37 |
import org.gvsig.andami.preferences.StoreException; |
|
38 |
|
|
39 |
public class PrintPropertiesPage extends AbstractPreferencePage { |
|
40 |
|
|
41 |
private static final long serialVersionUID = 5806304468312341691L; |
|
42 |
private static final boolean FACTORY_DEFAULT_LANDSCAPED_PAGE = true; |
|
43 |
protected static String id = PrintPropertiesPage.class.getName(); |
|
44 |
private ImageIcon icon; |
|
45 |
private JRadioButton rdBtnPortraitPage; |
|
46 |
private JRadioButton rdBtnLandscapePage; |
|
47 |
private JCheckBox chkCustomMargins; |
|
48 |
private JTextField txtTopMargin; |
|
49 |
private JTextField txtLeftMargin; |
|
50 |
private JTextField txtBottomMargin; |
|
51 |
private JTextField txtRightMargin; |
|
52 |
|
|
53 |
public PrintPropertiesPage() { |
|
54 |
super(); |
|
55 |
setParentID(LayoutPage.class.getName()); |
|
56 |
icon = PluginServices.getIconTheme().get("prepare-page-icon"); |
|
57 |
rdBtnPortraitPage = |
|
58 |
new JRadioButton(PluginServices.getText(this, |
|
59 |
"options.layout.paper_properties.portrait")); |
|
60 |
ImageIcon portrait = |
|
61 |
PluginServices.getIconTheme().get("portrait-page-setup"); |
|
62 |
rdBtnLandscapePage = |
|
63 |
new JRadioButton(PluginServices.getText(this, |
|
64 |
"options.layout.paper_properties.landscaped")); |
|
65 |
ImageIcon landscape = |
|
66 |
PluginServices.getIconTheme().get("landscape-page-setup"); |
|
67 |
|
|
68 |
ButtonGroup group = new ButtonGroup(); |
|
69 |
group.add(rdBtnLandscapePage); |
|
70 |
group.add(rdBtnPortraitPage); |
|
71 |
|
|
72 |
JPanel aux = new JPanel(new GridLayout(2, 2, 10, 0)); |
|
73 |
aux.setPreferredSize(new Dimension(200, 150)); |
|
74 |
aux.setSize(200, 150); |
|
75 |
aux.add(new JLabel(landscape)); |
|
76 |
aux.add(new JLabel(portrait)); |
|
77 |
aux.add(rdBtnLandscapePage); |
|
78 |
aux.add(rdBtnPortraitPage); |
|
79 |
|
|
80 |
addComponent(new JLabel(PluginServices.getText(this, |
|
81 |
"options.layout.paper_properties.paper_direction"))); |
|
82 |
addComponent("", aux); |
|
83 |
addComponent(chkCustomMargins = |
|
84 |
new JCheckBox(PluginServices.getText(this, "personalizar_margenes"))); |
|
85 |
|
|
86 |
JPanel aux2 = new JPanel(new GridLayout(2, 4, 10, 3)); |
|
87 |
aux2.add(new JLabel(PluginServices.getText(this, "Superior"))); |
|
88 |
aux2.add(txtTopMargin = new JTextField(10)); |
|
89 |
aux2.add(new JLabel(PluginServices.getText(this, "Izquierdo"))); |
|
90 |
aux2.add(txtLeftMargin = new JTextField(10)); |
|
91 |
aux2.add(new JLabel(PluginServices.getText(this, "Inferior"))); |
|
92 |
aux2.add(txtBottomMargin = new JTextField(10)); |
|
93 |
aux2.add(new JLabel(PluginServices.getText(this, "Derecho"))); |
|
94 |
aux2.add(txtRightMargin = new JTextField(10)); |
|
95 |
addComponent("", aux2); |
|
96 |
} |
|
97 |
|
|
98 |
public void storeValues() throws StoreException { |
|
99 |
// TODO Auto-generated method stub |
|
100 |
|
|
101 |
} |
|
102 |
|
|
103 |
public void setChangesApplied() { |
|
104 |
// TODO Auto-generated method stub |
|
105 |
|
|
106 |
} |
|
107 |
|
|
108 |
public String getID() { |
|
109 |
return id; |
|
110 |
} |
|
111 |
|
|
112 |
public String getTitle() { |
|
113 |
return PluginServices.getText(this, |
|
114 |
"options.layout.paper_properties.title"); |
|
115 |
} |
|
116 |
|
|
117 |
public JPanel getPanel() { |
|
118 |
return this; |
|
119 |
} |
|
120 |
|
|
121 |
public void initializeValues() { |
|
122 |
// TODO Auto-generated method stub |
|
123 |
|
|
124 |
} |
|
125 |
|
|
126 |
public void initializeDefaults() { |
|
127 |
rdBtnLandscapePage.setSelected(FACTORY_DEFAULT_LANDSCAPED_PAGE); |
|
128 |
rdBtnPortraitPage.setSelected(!FACTORY_DEFAULT_LANDSCAPED_PAGE); |
|
129 |
} |
|
130 |
|
|
131 |
public ImageIcon getIcon() { |
|
132 |
return icon; |
|
133 |
} |
|
134 |
|
|
135 |
public boolean isValueChanged() { |
|
136 |
// TODO Auto-generated method stub |
|
137 |
return false; |
|
138 |
} |
|
139 |
|
|
140 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.41/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.41/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/PreferenceKeys.java | ||
---|---|---|
1 |
package org.gvsig.app.gui.preferencespage; |
|
2 |
|
|
3 |
/** |
|
4 |
* The purpose of this interface is to define the keys used for the |
|
5 |
* persistence of this plugin in order to make these keys available |
|
6 |
* on library level, instead of defining them within the |
|
7 |
* preference page (which has UI dependences). |
|
8 |
* |
|
9 |
* @author Cesar Martinez Izquierdo <cesar.izq@gmail.com> |
|
10 |
* |
|
11 |
*/ |
|
12 |
public interface PreferenceKeys { |
|
13 |
String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME = "DefaultShowLayoutGrid"; |
|
14 |
String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME = "DefaultEnableLayoutGrid"; |
|
15 |
String DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME = "DefaultShowLayoutRules"; |
|
16 |
String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME = "DefaultGridVerticalGap"; |
|
17 |
String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME = "DefaultGridHorizontalGap"; |
|
18 |
String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME = "DefaultGridVerticalGapUnits"; |
|
19 |
String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME = "DefaultGridHorizontalGapUnits"; |
|
20 |
String DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME = "DefaulShowInitialPageConfigLayout"; |
|
21 |
String DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME = "DefaultShowLayoutToc"; |
|
22 |
boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS = true; |
|
23 |
boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true; |
|
24 |
double FACTORY_DEFAULT_VERTICAL_GAP = 1.0d; |
|
25 |
double FACTORY_DEFAULT_HORIZONTAL_GAP = 1.0d; |
|
26 |
String FACTORY_DEFAULT_VERTICAL_GAP_UNIT = "cm"; |
|
27 |
String FACTORY_DEFAULT_HORIZONTAL_GAP_UNIT = "cm"; |
|
28 |
boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false; |
|
29 |
boolean FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT = true; |
|
30 |
boolean FACTORY_DEFAULT_SHOW_LAYOUT_TOC = true; |
|
31 |
|
|
32 |
} |
|
0 | 33 |
tags/org.gvsig.app.document.layout2.app-2.0.41/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutDraw.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
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.Color; |
|
25 |
import java.awt.Component; |
|
26 |
import java.awt.Cursor; |
|
27 |
import java.awt.Graphics; |
|
28 |
import java.awt.Graphics2D; |
|
29 |
import java.awt.geom.AffineTransform; |
|
30 |
import java.awt.geom.Point2D; |
|
31 |
import java.awt.geom.Rectangle2D; |
|
32 |
import java.awt.image.BufferedImage; |
|
33 |
import java.awt.print.PageFormat; |
|
34 |
import java.awt.print.Printable; |
|
35 |
import java.awt.print.PrinterException; |
|
36 |
import java.io.BufferedOutputStream; |
|
37 |
import java.io.File; |
|
38 |
import java.io.FileOutputStream; |
|
39 |
import java.io.IOException; |
|
40 |
import java.io.OutputStream; |
|
41 |
|
|
42 |
import javax.print.Doc; |
|
43 |
import javax.print.DocFlavor; |
|
44 |
import javax.print.DocPrintJob; |
|
45 |
import javax.print.PrintException; |
|
46 |
import javax.print.SimpleDoc; |
|
47 |
import javax.print.StreamPrintService; |
|
48 |
import javax.print.StreamPrintServiceFactory; |
|
49 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
50 |
import javax.swing.JOptionPane; |
|
51 |
|
|
52 |
import com.lowagie.text.Document; |
|
53 |
import com.lowagie.text.DocumentException; |
|
54 |
import com.lowagie.text.PageSize; |
|
55 |
import com.lowagie.text.Rectangle; |
|
56 |
import com.lowagie.text.pdf.PdfContentByte; |
|
57 |
import com.lowagie.text.pdf.PdfWriter; |
|
58 |
|
|
59 |
import org.slf4j.Logger; |
|
60 |
import org.slf4j.LoggerFactory; |
|
61 |
import org.gvsig.andami.PluginServices; |
|
62 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
|
63 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
64 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
65 |
import org.gvsig.tools.observer.Observable; |
|
66 |
import org.gvsig.tools.observer.ObservableHelper; |
|
67 |
import org.gvsig.tools.observer.Observer; |
|
68 |
|
|
69 |
/** |
|
70 |
* Clase que implementa los m?todos del Layout que dibujan sobre el Graphics. |
|
71 |
* |
|
72 |
* @author Vicente Caballero Navarro |
|
73 |
*/ |
|
74 |
public class FLayoutDraw implements Observable, Printable{ |
|
75 |
private static final Logger LOG = |
|
76 |
LoggerFactory.getLogger(FLayoutDraw.class); |
|
77 |
|
|
78 |
private LayoutPanel layoutPanel; |
|
79 |
private LayoutControl layoutControl; |
|
80 |
private LayoutContext layoutContext; |
|
81 |
private ObservableHelper observers; |
|
82 |
|
|
83 |
/** |
|
84 |
* Crea un nuevo FLayoutDraw. |
|
85 |
* |
|
86 |
* @param l |
|
87 |
* Referencia al Layout. |
|
88 |
*/ |
|
89 |
public FLayoutDraw(LayoutPanel layoutPanel) { |
|
90 |
this.layoutPanel = layoutPanel; |
|
91 |
observers = new ObservableHelper(); |
|
92 |
observers.addObserver(layoutPanel.getLayoutControl()); |
|
93 |
} |
|
94 |
|
|
95 |
public void initialize(){ |
|
96 |
if ((layoutContext == null) || (layoutControl == null)){ |
|
97 |
this.layoutControl = layoutPanel.getLayoutControl(); |
|
98 |
this.layoutContext = layoutPanel.getLayoutContext(); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* M?todo para dibujar el Layout y modificar la matriz de transformaci?n a |
|
104 |
* partir del tama?o en pixels que tenga rect y el formato de papel |
|
105 |
* seleccionado. |
|
106 |
* |
|
107 |
* @param g2 |
|
108 |
* @param imgBase |
|
109 |
* Si es null, est?s imprimiendo. Si no, la usas para el |
|
110 |
* c?digo de optimizaci?n. |
|
111 |
* |
|
112 |
* @throws ReadDriverException |
|
113 |
*/ |
|
114 |
public void drawLayout(Graphics2D g2, BufferedImage imgBase) |
|
115 |
throws ReadException { |
|
116 |
if (!initializeAffineTransform()) { |
|
117 |
return; |
|
118 |
} |
|
119 |
|
|
120 |
IFFrame[] fframes = layoutContext.getFFrames(); |
|
121 |
for (int i = 0; i < fframes.length; i++) { |
|
122 |
IFFrame f = fframes[i]; |
|
123 |
f.draw(g2, layoutContext.getAT(), layoutControl.getComponent().getVisibleRect(), |
|
124 |
imgBase); |
|
125 |
|
|
126 |
// Dibuja el s?mbolo de que contiene un tag. |
|
127 |
if ((f.getTag() != null) && (layoutPanel.isShowIconTag())) { |
|
128 |
f.drawSymbolTag(g2); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
if (!(fframes.length == 0)) { |
|
133 |
observers.notifyObservers(this, |
|
134 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_VALIDATED)); |
|
135 |
} else { |
|
136 |
observers.notifyObservers(this, |
|
137 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
private boolean initializeAffineTransform(){ |
|
142 |
initialize(); |
|
143 |
AffineTransform at = layoutContext.getAT(); |
|
144 |
Rectangle2D rLayout = layoutControl.getRect(); |
|
145 |
if (rLayout.getHeight()<0) { |
|
146 |
// still not ready to be painted |
|
147 |
return false; |
|
148 |
} |
|
149 |
Attributes attributes = layoutContext.getAttributes(); |
|
150 |
|
|
151 |
layoutControl.setCancelDrawing(false); |
|
152 |
|
|
153 |
double scale = 0; |
|
154 |
scale = rLayout.getHeight() / attributes.m_sizePaper.getHeight() * 1; // paper (paper units) to screen (pixels) scale |
|
155 |
AffineTransform escalado = new AffineTransform(); |
|
156 |
AffineTransform translacion = new AffineTransform(); |
|
157 |
translacion.setToTranslation(rLayout.getMinX(), rLayout.getMinY()); |
|
158 |
escalado.setToScale(scale, scale); |
|
159 |
at.setToIdentity(); |
|
160 |
at.concatenate(translacion); |
|
161 |
at.concatenate(escalado); |
|
162 |
attributes.calculateGridGapX(rLayout); |
|
163 |
attributes.calculateGridGapY(rLayout); |
|
164 |
return true; |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* Dibuja sobre un Graphics2D el rect?ngulo que representa al folio. |
|
169 |
* |
|
170 |
* @param g |
|
171 |
* Graphics2D |
|
172 |
*/ |
|
173 |
public void drawRectangle(Graphics2D g) { |
|
174 |
initialize(); |
|
175 |
Attributes attributes = layoutContext.getAttributes(); |
|
176 |
Rectangle2D rLayout = layoutControl.getRect(); |
|
177 |
AffineTransform at = layoutContext.getAT(); |
|
178 |
|
|
179 |
double unidadesX = attributes.getHGridGapCm(); |
|
180 |
double unidadesY = attributes.getVGridGapCm(); |
|
181 |
|
|
182 |
if ((unidadesX == 0) && (unidadesY == 0)) { |
|
183 |
return; |
|
184 |
} |
|
185 |
|
|
186 |
g.setColor(Color.darkGray); |
|
187 |
|
|
188 |
Rectangle2D.Double rectBig = |
|
189 |
new Rectangle2D.Double(rLayout.getX(), rLayout.getY(), |
|
190 |
rLayout.getWidth(), rLayout.getHeight()); |
|
191 |
|
|
192 |
g.fillRect((int) rectBig.x + 7, (int) rectBig.y + 7, |
|
193 |
(int) rectBig.width, (int) rectBig.height); |
|
194 |
|
|
195 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
196 |
|
|
197 |
if (attributes.isMargin()) { |
|
198 |
|
|
199 |
r = |
|
200 |
new Rectangle2D.Double( |
|
201 |
(rLayout.getX() + FLayoutUtilities.fromSheetDistance( |
|
202 |
attributes.getAreaInsets()[2], at)), |
|
203 |
(rLayout.getY() + FLayoutUtilities.fromSheetDistance( |
|
204 |
attributes.getAreaInsets()[0], at)), |
|
205 |
(rLayout.getWidth() - FLayoutUtilities.fromSheetDistance( |
|
206 |
attributes.getAreaInsets()[2] + attributes.getAreaInsets()[3], at)), |
|
207 |
(rLayout.getHeight() - FLayoutUtilities.fromSheetDistance( |
|
208 |
attributes.getAreaInsets()[0] + attributes.getAreaInsets()[1], at))); |
|
209 |
} else { |
|
210 |
r.setRect(rLayout); |
|
211 |
} |
|
212 |
|
|
213 |
g.setColor(Color.white); |
|
214 |
g.fill(rLayout); |
|
215 |
|
|
216 |
g.setColor(Color.darkGray); |
|
217 |
g.drawRect((int) rLayout.getMinX(), (int) rLayout.getMinY(), |
|
218 |
(int) rLayout.getWidth(), (int) rLayout.getHeight()); |
|
219 |
|
|
220 |
if (attributes.isMargin()) { |
|
221 |
g.setColor(Color.black); |
|
222 |
|
|
223 |
g.drawRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* DOCUMENT ME! |
|
229 |
* |
|
230 |
* @param g |
|
231 |
* DOCUMENT ME! |
|
232 |
*/ |
|
233 |
public void drawGrid(Graphics2D g) { |
|
234 |
int unidadesMin = 6; |
|
235 |
Attributes attributes = layoutContext.getAttributes(); |
|
236 |
Rectangle2D rLayout = layoutControl.getRect(); |
|
237 |
AffineTransform at = layoutContext.getAT(); |
|
238 |
|
|
239 |
double unidadesX = attributes.getHGridGapPx(); |
|
240 |
double unidadesY = attributes.getVGridGapPx(); |
|
241 |
|
|
242 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
243 |
|
|
244 |
if (attributes.isMargin()) { |
|
245 |
r = |
|
246 |
new Rectangle2D.Double( |
|
247 |
(rLayout.getX() + FLayoutUtilities.fromSheetDistance( |
|
248 |
attributes.getAreaInsets()[2], at)), |
|
249 |
(rLayout.getY() + FLayoutUtilities.fromSheetDistance( |
|
250 |
attributes.getAreaInsets()[0], at)), |
|
251 |
(rLayout.getWidth() - FLayoutUtilities.fromSheetDistance( |
|
252 |
attributes.getAreaInsets()[2] + attributes.getAreaInsets()[3], at)), |
|
253 |
(rLayout.getHeight() - FLayoutUtilities.fromSheetDistance( |
|
254 |
attributes.getAreaInsets()[0] + attributes.getAreaInsets()[1], at))); |
|
255 |
} else { |
|
256 |
r.setRect(rLayout); |
|
257 |
} |
|
258 |
if ((unidadesX == 0) && (unidadesY == 0)) { |
|
259 |
return; |
|
260 |
} |
|
261 |
g.setColor(Color.darkGray); |
|
262 |
|
|
263 |
if (((unidadesX > unidadesMin) || (unidadesY > unidadesMin)) |
|
264 |
&& layoutContext.isGridVisible()) { |
|
265 |
double ax = r.getMinX(); |
|
266 |
double ay; |
|
267 |
|
|
268 |
while (ax < (r.getMaxX())) { |
|
269 |
ay = (r.getMinY()); |
|
270 |
|
|
271 |
while (ay < (r.getMaxY())) { |
|
272 |
g.drawLine((int) ax, (int) ay, (int) ax, (int) ay); |
|
273 |
ay = ay + unidadesY; |
|
274 |
} |
|
275 |
|
|
276 |
ax = ax + unidadesX; |
|
277 |
} |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Dibuja sobre el graphics2d las reglas. |
|
283 |
* |
|
284 |
* @param g |
|
285 |
* graphics2d sobre el que se dibuja. |
|
286 |
* @param color |
|
287 |
* Color de la regla. |
|
288 |
*/ |
|
289 |
public void drawRuler(Graphics2D g, Color color) { |
|
290 |
Attributes attributes = layoutContext.getAttributes(); |
|
291 |
Rectangle2D rLayout = layoutControl.getRect(); |
|
292 |
AffineTransform at = layoutContext.getAT(); |
|
293 |
|
|
294 |
if (layoutContext.getRuler()) { |
|
295 |
int ini = 10; |
|
296 |
int w = 30; |
|
297 |
int wi = 16; |
|
298 |
|
|
299 |
g.setColor(new Color(250, 255, 250, 180)); |
|
300 |
g.fillRect(ini, w, wi, layoutControl.getComponent().getHeight() - w); |
|
301 |
g.fillRect(w, ini, layoutControl.getWidth() - w, wi); |
|
302 |
|
|
303 |
g.setColor(new Color(100, 155, 150, 180)); |
|
304 |
g.fillRect(w, ini, (int) rLayout.getX() - w, wi); |
|
305 |
g.fillRect((int) rLayout.getMaxX(), ini, layoutControl.getWidth() |
|
306 |
- (int) rLayout.getMaxX(), wi); |
|
307 |
|
|
308 |
g.fillRect(ini, w, wi, (int) rLayout.getY() - w); |
|
309 |
g.fillRect(ini, (int) rLayout.getMaxY(), wi, |
|
310 |
layoutControl.getHeight() - (int) rLayout.getMaxY()); |
|
311 |
|
|
312 |
if (attributes.isMargin()) { |
|
313 |
g.setColor(new Color(50, 55, 50, 180)); |
|
314 |
g.fillRect((int) rLayout.getX(), ini, (int) FLayoutUtilities |
|
315 |
.fromSheetDistance(attributes.getAreaInsets()[2], at), wi); |
|
316 |
g.fillRect( |
|
317 |
(int) rLayout.getMaxX() |
|
318 |
- (int) FLayoutUtilities.fromSheetDistance( |
|
319 |
attributes.getAreaInsets()[3], at), ini, |
|
320 |
(int) FLayoutUtilities.fromSheetDistance( |
|
321 |
attributes.getAreaInsets()[3], at), wi); |
|
322 |
|
|
323 |
g.fillRect(ini, (int) rLayout.getY(), wi, |
|
324 |
(int) FLayoutUtilities.fromSheetDistance( |
|
325 |
attributes.getAreaInsets()[0], at)); |
|
326 |
g.fillRect( |
|
327 |
ini, |
|
328 |
(int) rLayout.getMaxY() |
|
329 |
- (int) FLayoutUtilities.fromSheetDistance( |
|
330 |
attributes.getAreaInsets()[1], at), wi, |
|
331 |
(int) FLayoutUtilities.fromSheetDistance( |
|
332 |
attributes.getAreaInsets()[1], at)); |
|
333 |
} |
|
334 |
|
|
335 |
g.setColor(color); |
|
336 |
g.drawLine(w, wi + ini, layoutControl.getWidth(), wi + ini); |
|
337 |
g.drawLine(w, ini, layoutControl.getWidth(), ini); |
|
338 |
g.drawLine(ini, w, ini, layoutControl.getHeight()); |
|
339 |
g.drawLine(wi + ini, w, wi + ini, layoutControl.getHeight()); |
|
340 |
|
|
341 |
drawLineY(g, 5, 12, 22, rLayout.getY(), 0); |
|
342 |
drawLineX(g, 5, 12, 22, rLayout.getX(), 0); |
|
343 |
|
|
344 |
if (FLayoutUtilities.fromSheetDistance(1, at) > 15) { |
|
345 |
drawLineY(g, 1, 12, 22, rLayout.getY(), 0); |
|
346 |
drawLineX(g, 1, 12, 22, rLayout.getX(), 0); |
|
347 |
|
|
348 |
if (FLayoutUtilities.fromSheetDistance(1, at) > 25) { |
|
349 |
drawLineY(g, 1, 18, 22, rLayout.getY(), 0.5); |
|
350 |
drawLineY(g, 0.1, 21, 22, rLayout.getY(), 0); |
|
351 |
drawLineX(g, 1, 18, 22, rLayout.getX(), 0.5); |
|
352 |
drawLineX(g, 0.1, 21, 22, rLayout.getX(), 0); |
|
353 |
} |
|
354 |
} |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* Dibuja sobre el graphics2d las l?neas verticales que representan a las |
|
360 |
* unidades de medida. |
|
361 |
* |
|
362 |
* @param g |
|
363 |
* Graphics2d sobre el que se dibuja. |
|
364 |
* @param dist |
|
365 |
* distancia en cent?metros de una l?nea a otra. |
|
366 |
* @param init |
|
367 |
* inicio de la l?nea. |
|
368 |
* @param end |
|
369 |
* fin de la l?nea. |
|
370 |
* @param y |
|
371 |
* rect?ngulo, dentro del cual se dibujan las l?neas. |
|
372 |
* @param desp |
|
373 |
* Desplazamiento. |
|
374 |
*/ |
|
375 |
private void drawLineY(Graphics2D g, double dist, int init, int end, |
|
376 |
double y, double desp) { |
|
377 |
initialize(); |
|
378 |
AffineTransform at = layoutContext.getAT(); |
|
379 |
|
|
380 |
double distY = FLayoutUtilities.fromSheetDistance(dist, at); |
|
381 |
double rota = Math.toRadians(90); |
|
382 |
|
|
383 |
if (distY > 4) { |
|
384 |
double despY = FLayoutUtilities.fromSheetDistance(desp, at); |
|
385 |
|
|
386 |
double posUnitY = y + despY; |
|
387 |
double posUnitYNeg = posUnitY; |
|
388 |
int num = 0; |
|
389 |
double iniY = 40; |
|
390 |
Point2D.Double pfin = |
|
391 |
FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
|
392 |
layoutControl.getWidth(), layoutControl.getHeight()), at); |
|
393 |
|
|
394 |
while (posUnitY < (pfin.y - 5)) { |
|
395 |
posUnitYNeg -= distY; |
|
396 |
|
|
397 |
if (distY > 16) { |
|
398 |
if (init == 12) { |
|
399 |
if (posUnitY > iniY) { |
|
400 |
g.rotate(-rota, 20, posUnitY - 12); |
|
401 |
g.drawString(String.valueOf(num), 10, |
|
402 |
(int) posUnitY - 12); |
|
403 |
g.rotate(rota, 20, posUnitY - 12); |
|
404 |
} |
|
405 |
|
|
406 |
if (dist == 5) { |
|
407 |
num = num + 5; |
|
408 |
} else { |
|
409 |
num++; |
|
410 |
} |
|
411 |
|
|
412 |
if (posUnitYNeg > iniY) { |
|
413 |
g.rotate(-rota, 20, posUnitYNeg - 12); |
|
414 |
g.drawString(String.valueOf(-num), 10, |
|
415 |
(int) posUnitYNeg - 12); |
|
416 |
g.rotate(rota, 20, posUnitYNeg - 12); |
|
417 |
} |
|
418 |
} |
|
419 |
} |
|
420 |
|
|
421 |
if (posUnitY > iniY) { |
|
422 |
g.drawLine(2 + init, (int) posUnitY, 2 + end, |
|
423 |
(int) posUnitY); |
|
424 |
} |
|
425 |
|
|
426 |
if (posUnitYNeg > iniY) { |
|
427 |
g.drawLine(2 + init, (int) posUnitYNeg, 2 + end, |
|
428 |
(int) posUnitYNeg); |
|
429 |
} |
|
430 |
|
|
431 |
posUnitY += distY; |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
435 |
|
|
436 |
/** |
|
437 |
* Dibuja sobre el graphics2d las l?neas horizontales que representan a las |
|
438 |
* unidades de medida. |
|
439 |
* |
|
440 |
* @param g |
|
441 |
* Graphics2d sobre el que se dibuja. |
|
442 |
* @param dist |
|
443 |
* distancia en cent?metros de una l?nea a otra. |
|
444 |
* @param init |
|
445 |
* inicio de la l?nea. |
|
446 |
* @param end |
|
447 |
* fin de la l?nea. |
|
448 |
* @param x |
|
449 |
* rect?ngulo, dentro del cual se dibujan las l?neas. |
|
450 |
* @param desp |
|
451 |
* Desplazamiento. |
|
452 |
*/ |
|
453 |
private void drawLineX(Graphics2D g, double dist, int init, int end, |
|
454 |
double x, double desp) { |
|
455 |
initialize(); |
|
456 |
AffineTransform at = layoutContext.getAT(); |
|
457 |
|
|
458 |
double distX = FLayoutUtilities.fromSheetDistance(dist, at); |
|
459 |
|
|
460 |
if (distX > 4) { |
|
461 |
double despX = FLayoutUtilities.fromSheetDistance(desp, at); |
|
462 |
double posUnitX = x + despX; |
|
463 |
double posUnitXNeg = posUnitX; |
|
464 |
int num = 0; |
|
465 |
double iniX = 40; |
|
466 |
Point2D.Double pfin = |
|
467 |
FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
|
468 |
layoutControl.getWidth(), layoutControl.getHeight()), at); |
|
469 |
|
|
470 |
while (posUnitX < (pfin.x - 5)) { |
|
471 |
posUnitXNeg -= distX; |
|
472 |
|
|
473 |
if (init == 12) { |
|
474 |
if (distX > 16) { |
|
475 |
if (posUnitX > iniX) { |
|
476 |
g.drawString(String.valueOf(num), |
|
477 |
(int) posUnitX + 3, 20); |
|
478 |
} |
|
479 |
|
|
480 |
if (dist == 5) { |
|
481 |
num = num + 5; |
|
482 |
} else { |
|
483 |
num++; |
|
484 |
} |
|
485 |
|
|
486 |
if (posUnitXNeg > iniX) { |
|
487 |
g.drawString(String.valueOf(-num), |
|
488 |
(int) posUnitXNeg + 3, 20); |
|
489 |
} |
|
490 |
} |
|
491 |
} |
|
492 |
|
|
493 |
if (posUnitX > iniX) { |
|
494 |
g.drawLine((int) posUnitX, 2 + init, (int) posUnitX, |
|
495 |
2 + end); |
|
496 |
} |
|
497 |
|
|
498 |
if (posUnitXNeg > iniX) { |
|
499 |
g.drawLine((int) posUnitXNeg, 2 + init, (int) posUnitXNeg, |
|
500 |
2 + end); |
|
501 |
} |
|
502 |
|
|
503 |
posUnitX += distX; |
|
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
|
|
508 |
/** |
|
509 |
* Dibuja los handlers sobre los fframes que esten seleccionados. |
|
510 |
* |
|
511 |
* @param g |
|
512 |
* Graphics sobre el que se dibuja. |
|
513 |
* @param color |
|
514 |
* Color de los Handlers. |
|
515 |
*/ |
|
516 |
public void drawHandlers(Graphics2D g, Color color) { |
|
517 |
initialize(); |
|
518 |
|
|
519 |
g.setColor(color); |
|
520 |
IFFrame[] fframes = layoutContext.getFFrames(); |
|
521 |
for (int i = 0; i < fframes.length; i++) { |
|
522 |
IFFrame fframe = fframes[i]; |
|
523 |
|
|
524 |
if (fframe.getSelected() != IFFrame.NOSELECT) { |
|
525 |
fframe.drawHandlers(g); |
|
526 |
} |
|
527 |
} |
|
528 |
} |
|
529 |
|
|
530 |
/** |
|
531 |
* A partir de un fichero que se pasa como par?metro se crea un ps con el |
|
532 |
* contenido del Layout. |
|
533 |
* |
|
534 |
* @param ps |
|
535 |
*/ |
|
536 |
public void toPS(File ps) { |
|
537 |
initialize(); |
|
538 |
Attributes attributes = layoutContext.getAttributes(); |
|
539 |
|
|
540 |
try { |
|
541 |
// Prepare the output file to receive the postscript |
|
542 |
OutputStream fos = |
|
543 |
new BufferedOutputStream(new FileOutputStream(ps)); |
|
544 |
|
|
545 |
// Find a factory that can do the conversion |
|
546 |
// DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; |
|
547 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
|
548 |
StreamPrintServiceFactory[] factories = |
|
549 |
StreamPrintServiceFactory.lookupStreamPrintServiceFactories( |
|
550 |
flavor, "application/postscript"); |
|
551 |
|
|
552 |
if (factories.length > 0) { |
|
553 |
StreamPrintService service = factories[0].getPrintService(fos); |
|
554 |
|
|
555 |
// Create the print job |
|
556 |
DocPrintJob job = service.createPrintJob(); |
|
557 |
|
|
558 |
Doc doc = new SimpleDoc(this, flavor, null); |
|
559 |
// Doc doc = new SimpleDoc(is, flavor, null); |
|
560 |
// Monitor print job events; for the implementation of |
|
561 |
// PrintJobWatcher, |
|
562 |
// see e702 Determining When a Print Job Has Finished |
|
563 |
// PrintJobWatcher pjDone = new PrintJobWatcher(job); |
|
564 |
// Actualizar attributes |
|
565 |
PrintRequestAttributeSet att = |
|
566 |
attributes.toPrintRequestAttributeSet(); |
|
567 |
// Print it |
|
568 |
job.print(doc, att); |
|
569 |
|
|
570 |
// Wait for the print job to be done |
|
571 |
// pjDone.waitForDone(); |
|
572 |
// It is now safe to close the streams |
|
573 |
} |
|
574 |
|
|
575 |
// is.close(); |
|
576 |
fos.close(); |
|
577 |
} catch (PrintException e) { |
|
578 |
LOG.error("Error printing the map", e); |
|
579 |
} catch (IOException e) { |
|
580 |
LOG.error("Error printing the map", e); |
|
581 |
} |
|
582 |
/* |
|
583 |
* PrintService defaultPrintService = |
|
584 |
* PrintServiceLookup.lookupDefaultPrintService(); |
|
585 |
* DocPrintJob printerJob = defaultPrintService.createPrintJob(); |
|
586 |
* |
|
587 |
* try { |
|
588 |
* DocFlavor flavor=DocFlavor.URL.POSTSCRIPT; |
|
589 |
* if (!defaultPrintService.isDocFlavorSupported(flavor)) { |
|
590 |
* System.err.println( |
|
591 |
* "The printer does not support the appropriate DocFlavor"); |
|
592 |
* }else { |
|
593 |
* |
|
594 |
* SimpleDoc simpleDoc; |
|
595 |
* simpleDoc = new SimpleDoc(ps.toURL(),flavor, null); |
|
596 |
* printerJob.print(simpleDoc, null); |
|
597 |
* } |
|
598 |
* } catch (MalformedURLException e) { |
|
599 |
* // TODO Auto-generated catch block |
|
600 |
* e.printStackTrace(); |
|
601 |
* } catch (PrintException e) { |
|
602 |
* // TODO Auto-generated catch block |
|
603 |
* e.printStackTrace(); |
|
604 |
* } |
|
605 |
*/ |
|
606 |
layoutControl.fullRect(); |
|
607 |
} |
|
608 |
|
|
609 |
/** |
|
610 |
* A partir de un fichero que se pasa como par?metro se crea un pdf con el |
|
611 |
* contenido del Layout. |
|
612 |
* |
|
613 |
* @param pdf |
|
614 |
*/ |
|
615 |
public void toPDF(File pdf) { |
|
616 |
Attributes attributes = layoutContext.getAttributes(); |
|
617 |
|
|
618 |
double w = ((attributes.m_sizePaper.getWidth() * Attributes.DPISCREEN) / Attributes.PULGADA); |
|
619 |
double h = ((attributes.m_sizePaper.getHeight() * Attributes.DPISCREEN) / Attributes.PULGADA); |
|
620 |
Rectangle pageSize = new com.lowagie.text.Rectangle((float) w, (float) h); |
|
621 |
Document document = new Document(pageSize); |
|
622 |
|
|
623 |
try { |
|
624 |
FileOutputStream fos = new FileOutputStream(pdf); |
|
625 |
PdfWriter writer = PdfWriter.getInstance(document, fos); |
|
626 |
document.open(); |
|
627 |
|
|
628 |
PdfContentByte cb = writer.getDirectContent(); |
|
629 |
Graphics2D g2 = cb.createGraphicsShapes((float) w, (float) h); |
|
630 |
|
|
631 |
try { |
|
632 |
print(g2, new PageFormat(), 0); |
|
633 |
} catch (PrinterException e) { |
|
634 |
LOG.error("Error printing the map", e); |
|
635 |
} |
|
636 |
g2.dispose(); |
|
637 |
|
|
638 |
} catch (DocumentException de) { |
|
639 |
LOG.error("Error printing the map", de); |
|
640 |
} catch (IOException ioe) { |
|
641 |
JOptionPane.showMessageDialog( |
|
642 |
(Component) PluginServices.getMainFrame(), ioe.getMessage()); |
|
643 |
} |
|
644 |
|
|
645 |
document.close(); |
|
646 |
|
|
647 |
layoutControl.fullRect(); |
|
648 |
} |
|
649 |
|
|
650 |
public int print(Graphics g, PageFormat format, int pi) |
|
651 |
throws PrinterException { |
|
652 |
initialize(); |
|
653 |
if (pi >= 1) { |
|
654 |
return Printable.NO_SUCH_PAGE; |
|
655 |
} |
|
656 |
|
|
657 |
Graphics2D g2d = (Graphics2D) g; |
|
658 |
|
|
659 |
AffineTransform at = g2d.getTransform(); |
|
660 |
g2d.translate(0, 0); |
|
661 |
layoutPanel.obtainRect(true); |
|
662 |
|
|
663 |
g2d.scale((double) 72 / (double) (Attributes.DPI), (double) 72 |
|
664 |
/ (double) (Attributes.DPI)); |
|
665 |
|
|
666 |
if (layoutContext.getAttributes().isMargin()) { |
|
667 |
g2d.setClip( |
|
668 |
(int) (layoutControl.getRect().getMinX() + FLayoutUtilities.fromSheetDistance( |
|
669 |
layoutContext.getAttributes().getAreaInsets()[2], layoutControl.getAT())), |
|
670 |
(int) (layoutPanel.getLayoutControl().getRect().getMinY() + FLayoutUtilities.fromSheetDistance( |
|
671 |
layoutContext.getAttributes().getAreaInsets()[0], layoutControl.getAT())), |
|
672 |
(int) (layoutControl.getRect().getWidth() - FLayoutUtilities.fromSheetDistance( |
|
673 |
layoutContext.getAttributes().getAreaInsets()[2] + layoutContext.getAttributes().getAreaInsets()[3], layoutControl.getAT())), |
|
674 |
(int) (layoutPanel.getLayoutControl().getRect().getHeight() - FLayoutUtilities.fromSheetDistance( |
|
675 |
layoutContext.getAttributes().getAreaInsets()[0] + layoutContext.getAttributes().getAreaInsets()[1], layoutControl.getAT()))); |
|
676 |
} |
|
677 |
drawShapes(g2d); |
|
678 |
g2d.setTransform(at); |
|
679 |
return Printable.PAGE_EXISTS; |
|
680 |
} |
|
681 |
|
|
682 |
/** |
|
683 |
* Se dibuja sobre el graphics el Layout. |
|
684 |
* |
|
685 |
* @param g2 |
|
686 |
* graphics sobre el que se dibuja. |
|
687 |
*/ |
|
688 |
public void drawShapes(Graphics2D g2) { |
|
689 |
initialize(); |
|
690 |
layoutPanel.setCursor(Cursor.getDefaultCursor()); |
|
691 |
if (!initializeAffineTransform()) { |
|
692 |
return; |
|
693 |
} |
|
694 |
|
|
695 |
IFFrame[] fframes = layoutContext.getFFrames(); |
|
696 |
for (int i = 0; i < fframes.length; i++) { |
|
697 |
fframes[i].print(g2, layoutControl.getAT(), null, layoutContext |
|
698 |
.getAttributes().toPrintAttributes()); |
|
699 |
} |
|
700 |
} |
|
701 |
|
|
702 |
public void addObserver(Observer o) { |
|
703 |
observers.addObserver(o); |
|
704 |
} |
|
705 |
|
|
706 |
public void deleteObserver(Observer o) { |
|
707 |
observers.deleteObserver(o); |
|
708 |
} |
|
709 |
|
|
710 |
public void deleteObservers() { |
|
711 |
observers.deleteObservers(); |
|
712 |
} |
|
713 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.41/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutEvents.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. |
Also available in: Unified diff