Revision 138

View differences:

tags/org.gvsig.app.document.layout.app-2.0.22/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
    <modelVersion>4.0.0</modelVersion>
3
    <artifactId>org.gvsig.app.document.layout.app</artifactId>
4
    <packaging>pom</packaging>
5
    <version>2.0.22</version>
6
    <name>Document: Layout document support</name>
7
    <description>This plugin adds creation/management of layout (map) documents.</description>
8
    <parent>
9
        <groupId>org.gvsig</groupId>
10
        <artifactId>org.gvsig.desktop</artifactId>
11
        <version>2.0.40</version>
12
    </parent>
13
    <url>https://devel.gvsig.org/redmine/projects/gvsig-app-document-layout</url>
14
    <scm>
15
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-app-document-layout/tags/org.gvsig.app.document.layout.app-2.0.22</connection>
16
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-app-document-layout/tags/org.gvsig.app.document.layout.app-2.0.22</developerConnection>
17
        <url>https://devel.gvsig.org/redmine/projects/gvsig-app-document-layout/repository/show/tags/org.gvsig.app.document.layout.app-2.0.22</url>
18
    </scm>
19
    <repositories>
20
      <repository>
21
        <id>gvsig-public-http-repository</id>
22
        <name>gvSIG maven public HTTP repository</name>
23
        <url>http://devel.gvsig.org/m2repo/j2se</url>
24
        <releases>
25
          <enabled>true</enabled>
26
          <updatePolicy>daily</updatePolicy>
27
          <checksumPolicy>warn</checksumPolicy>
28
        </releases>
29
        <snapshots>
30
          <enabled>true</enabled>
31
          <updatePolicy>daily</updatePolicy>
32
          <checksumPolicy>warn</checksumPolicy>
33
        </snapshots>
34
      </repository>
35
    </repositories>
36
        
37
	<build>
38
		<plugins>
39
			<plugin>
40
				<groupId>org.apache.maven.plugins</groupId>
41
				<artifactId>maven-release-plugin</artifactId>
42
				<configuration>
43
					<tagBase>https://devel.gvsig.org/svn/gvsig-app-document-layout/tags</tagBase>
44
				</configuration>
45
			</plugin>
46
		</plugins>
47
	</build>
48

  
49
	<modules>
50
		<module>org.gvsig.app.document.layout.app.mainplugin</module>
51
	</modules>
52

  
53
</project>
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/buildNumber.properties
1
#Tue Jun 17 11:57:46 CEST 2014
2
buildNumber=36
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.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.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/PointAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

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

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

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

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

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

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

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

  
56
    }
57

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

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

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

  
98
            definition.extend(manager
99
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
100
        }
101
    }
102
}
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/GeometryAdapter.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.app.project.documents.layout.geometryadapters;
42

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

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

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

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

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

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

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

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

  
97
        return points.size();
98
    }
99

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

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

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

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

  
137
        geometry.transform(at);
138
    }
139

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

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

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

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

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

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

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

  
235
        int d = 3;
236

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

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

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

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

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

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

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

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

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

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

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

  
334
    public void saveToState(PersistentState state) throws PersistenceException {
335
        state.set(POINTS_FIELD, points);
336
    }
337
}
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/PolyLineAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

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

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

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

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

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

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

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

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

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

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

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

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

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

  
135
            definition.extend(manager
136
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
137
        }
138
    }
139
}
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/CircleAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

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

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

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

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

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

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

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

  
79
            Geometry shapeAux = getGeometry(at);
80

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

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

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

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

  
131
    public static void registerPersistent() {
132
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
133
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
134
            DynStruct definition =
135
                manager.addDefinition(CircleAdapter.class,
136
                    PERSISTENCE_DEFINITION_NAME,
137
                    "Circle Adapter persistence definition", null, null);
138

  
139
            definition.extend(manager
140
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
141
        }
142
    }
143
}
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/RectangleAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

  
24
import java.awt.geom.Point2D;
25

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

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

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

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

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

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

  
86
            definition.extend(manager
87
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
88
        }
89
    }
90
}
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/PolygonAdapter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.geometryadapters;
23

  
24
import java.awt.geom.Point2D;
25

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

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

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

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

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

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

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

  
88
            definition.extend(manager
89
                .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME));
90
        }
91
    }
92
}
0 93

  
tags/org.gvsig.app.document.layout.app-2.0.22/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutDraw.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
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.pdf.PdfContentByte;
55
import com.lowagie.text.pdf.PdfWriter;
56

  
57
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
59

  
60
import org.gvsig.andami.PluginServices;
61
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
62
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
63
import org.gvsig.fmap.dal.exception.ReadException;
64
import org.gvsig.tools.observer.Observable;
65
import org.gvsig.tools.observer.ObservableHelper;
66
import org.gvsig.tools.observer.Observer;
67

  
68
/**
69
 * Clase que implementa los m?todos del Layout que dibujan sobre el Graphics.
70
 * 
71
 * @author Vicente Caballero Navarro
72
 */
73
public class FLayoutDraw implements Observable, Printable{
74
    private static final Logger LOG = 
75
        LoggerFactory.getLogger(FLayoutDraw.class);
76
    
77
    private LayoutPanel layoutPanel;
78
    private LayoutControl layoutControl;
79
    private LayoutContext layoutContext;
80
    private ObservableHelper observers;
81

  
82
    /**
83
     * Crea un nuevo FLayoutDraw.
84
     * 
85
     * @param l
86
     *            Referencia al Layout.
87
     */
88
    public FLayoutDraw(LayoutPanel layoutPanel) {
89
        this.layoutPanel = layoutPanel;
90
        observers = new ObservableHelper();
91
        observers.addObserver(layoutPanel.getLayoutControl());
92
    }
93

  
94
    public void initialize(){
95
        if ((layoutContext == null) || (layoutControl == null)){
96
            this.layoutControl = layoutPanel.getLayoutControl();
97
            this.layoutContext = layoutPanel.getLayoutContext();
98
        }
99
    }
100

  
101
    /**
102
     * M?todo para dibujar el Layout y modificar la matriz de transformaci?n a
103
     * partir del tama?o en pixels que tenga rect y el formato de papel
104
     * seleccionado.
105
     * 
106
     * @param g2
107
     * @param imgBase
108
     *            Si es null, est?s imprimiendo. Si no, la usas para el
109
     *            c?digo de optimizaci?n.
110
     * 
111
     * @throws ReadDriverException
112
     */
113
    public void drawLayout(Graphics2D g2, BufferedImage imgBase)
114
    throws ReadException {     
115
        initializeAffineTransform();
116

  
117
        IFFrame[] fframes = layoutContext.getFFrames();
118
        for (int i = 0; i < fframes.length; i++) {
119
            IFFrame f = fframes[i];
120
            f.draw(g2, layoutContext.getAT(), layoutControl.getComponent().getVisibleRect(),
121
                imgBase);          
122

  
123
            // Dibuja el s?mbolo de que contiene un tag.
124
            if ((f.getTag() != null) && (layoutPanel.isShowIconTag())) {
125
                f.drawSymbolTag(g2);
126
            }
127
        }
128

  
129
        if (!(fframes.length == 0)) {
130
            observers.notifyObservers(this, 
131
                new DefaultLayoutNotification(LayoutNotification.LAYOUT_VALIDATED));           
132
        } else {
133
            observers.notifyObservers(this, 
134
                new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));           
135
        }  
136
    }
137

  
138
    private void initializeAffineTransform(){
139
        initialize();
140
        AffineTransform at = layoutContext.getAT();
141
        Rectangle2D rLayout = layoutControl.getRect();
142
        Attributes attributes = layoutContext.getAttributes();
143

  
144
        layoutControl.setCancelDrawing(false);
145

  
146
        double scale = 0;
147
        scale = rLayout.getHeight() / attributes.m_sizePaper.getAlto() * 1;
148
        AffineTransform escalado = new AffineTransform();
149
        AffineTransform translacion = new AffineTransform();
150
        translacion.setToTranslation(rLayout.getMinX(), rLayout.getMinY());
151
        escalado.setToScale(scale, scale);
152
        at.setToIdentity();
153
        at.concatenate(translacion);
154
        at.concatenate(escalado);
155
        attributes.setDistanceUnitX(rLayout);
156
        attributes.setDistanceUnitY(rLayout);
157
    }
158

  
159
    /**
160
     * Dibuja sobre un Graphics2D el rect?ngulo que representa al folio.
161
     * 
162
     * @param g
163
     *            Graphics2D
164
     */
165
    public void drawRectangle(Graphics2D g) {
166
        initialize();
167
        Attributes attributes = layoutContext.getAttributes();
168
        Rectangle2D rLayout = layoutControl.getRect();
169
        AffineTransform at = layoutContext.getAT();
170

  
171
        double unidadesX = attributes.getNumUnitsX();
172
        double unidadesY = attributes.getNumUnitsY();
173

  
174
        if ((unidadesX == 0) && (unidadesY == 0)) {
175
            return;
176
        }
177

  
178
        g.setColor(Color.darkGray);
179

  
180
        Rectangle2D.Double rectBig =
181
            new Rectangle2D.Double(rLayout.getX(), rLayout.getY(),
182
                rLayout.getWidth(), rLayout.getHeight());
183

  
184
        g.fillRect((int) rectBig.x + 7, (int) rectBig.y + 7,
185
            (int) rectBig.width, (int) rectBig.height);
186

  
187
        Rectangle2D.Double r = new Rectangle2D.Double();
188

  
189
        if (attributes.isMargin()) {
190

  
191
            r =
192
                new Rectangle2D.Double(
193
                    (rLayout.getX() + FLayoutUtilities.fromSheetDistance(
194
                        attributes.getAreaInsets()[2], at)),
195
                        (rLayout.getY() + FLayoutUtilities.fromSheetDistance(
196
                            attributes.getAreaInsets()[0], at)),
197
                            (rLayout.getWidth() - FLayoutUtilities.fromSheetDistance(
198
                                attributes.getAreaInsets()[2] + attributes.getAreaInsets()[3], at)),
199
                                (rLayout.getHeight() - FLayoutUtilities.fromSheetDistance(
200
                                    attributes.getAreaInsets()[0] + attributes.getAreaInsets()[1], at)));
201
        } else {
202
            r.setRect(rLayout);
203
        }
204

  
205
        g.setColor(Color.white);
206
        g.fill(rLayout);
207

  
208
        g.setColor(Color.darkGray);
209
        g.drawRect((int) rLayout.getMinX(), (int) rLayout.getMinY(),
210
            (int) rLayout.getWidth(), (int) rLayout.getHeight());
211

  
212
        if (attributes.isMargin()) {
213
            g.setColor(Color.black);
214

  
215
            g.drawRect((int) r.x, (int) r.y, (int) r.width, (int) r.height);
216
        }
217
    }
218

  
219
    /**
220
     * DOCUMENT ME!
221
     * 
222
     * @param g
223
     *            DOCUMENT ME!
224
     */
225
    public void drawGrid(Graphics2D g) {
226
        int unidadesMin = 6;       
227
        Attributes attributes = layoutContext.getAttributes();
228
        Rectangle2D rLayout = layoutControl.getRect();
229
        AffineTransform at = layoutContext.getAT();
230

  
231
        double unidadesX = attributes.getUnitInPixelsX();
232
        double unidadesY = attributes.getUnitInPixelsY();
233

  
234
        Rectangle2D.Double r = new Rectangle2D.Double();
235

  
236
        if (attributes.isMargin()) {
237
            r =
238
                new Rectangle2D.Double(
239
                    (rLayout.getX() + FLayoutUtilities.fromSheetDistance(
240
                        attributes.getAreaInsets()[2], at)),
241
                        (rLayout.getY() + FLayoutUtilities.fromSheetDistance(
242
                            attributes.getAreaInsets()[0], at)),
243
                            (rLayout.getWidth() - FLayoutUtilities.fromSheetDistance(
244
                                attributes.getAreaInsets()[2] + attributes.getAreaInsets()[3], at)),
245
                                (rLayout.getHeight() - FLayoutUtilities.fromSheetDistance(
246
                                    attributes.getAreaInsets()[0] + attributes.getAreaInsets()[1], at)));
247
        } else {
248
            r.setRect(rLayout);
249
        }
250
        if ((unidadesX == 0) && (unidadesY == 0)) {
251
            return;
252
        }
253
        g.setColor(Color.darkGray);
254

  
255
        if (((unidadesX > unidadesMin) || (unidadesY > unidadesMin))
256
            && layoutContext.isGridVisible()) {
257
            double ax = r.getMinX();
258
            double ay;
259

  
260
            while (ax < (r.getMaxX())) {
261
                ay = (r.getMinY());
262

  
263
                while (ay < (r.getMaxY())) {
264
                    g.drawLine((int) ax, (int) ay, (int) ax, (int) ay);
265
                    ay = ay + unidadesY;
266
                }
267

  
268
                ax = ax + unidadesX;
269
            }
270
        }
271
    }
272

  
273
    /**
274
     * Dibuja sobre el graphics2d las reglas.
275
     * 
276
     * @param g
277
     *            graphics2d sobre el que se dibuja.
278
     * @param color
279
     *            Color de la regla.
280
     */
281
    public void drawRuler(Graphics2D g, Color color) {     
282
        Attributes attributes = layoutContext.getAttributes();
283
        Rectangle2D rLayout = layoutControl.getRect();
284
        AffineTransform at = layoutContext.getAT();
285

  
286
        if (layoutContext.getRuler()) {
287
            int ini = 10;
288
            int w = 30;
289
            int wi = 16;
290

  
291
            g.setColor(new Color(250, 255, 250, 180));
292
            g.fillRect(ini, w, wi, layoutControl.getComponent().getHeight() - w);
293
            g.fillRect(w, ini, layoutControl.getWidth() - w, wi);
294

  
295
            g.setColor(new Color(100, 155, 150, 180));
296
            g.fillRect(w, ini, (int) rLayout.getX() - w, wi);
297
            g.fillRect((int) rLayout.getMaxX(), ini, layoutControl.getWidth()
298
                - (int) rLayout.getMaxX(), wi);
299

  
300
            g.fillRect(ini, w, wi, (int) rLayout.getY() - w);
301
            g.fillRect(ini, (int) rLayout.getMaxY(), wi,
302
                layoutControl.getHeight() - (int) rLayout.getMaxY());
303

  
304
            if (attributes.isMargin()) {
305
                g.setColor(new Color(50, 55, 50, 180));
306
                g.fillRect((int) rLayout.getX(), ini, (int) FLayoutUtilities
307
                    .fromSheetDistance(attributes.getAreaInsets()[2], at), wi);
308
                g.fillRect(
309
                    (int) rLayout.getMaxX()
310
                    - (int) FLayoutUtilities.fromSheetDistance(
311
                        attributes.getAreaInsets()[3], at), ini,
312
                        (int) FLayoutUtilities.fromSheetDistance(
313
                            attributes.getAreaInsets()[3], at), wi);
314

  
315
                g.fillRect(ini, (int) rLayout.getY(), wi,
316
                    (int) FLayoutUtilities.fromSheetDistance(
317
                        attributes.getAreaInsets()[0], at));
318
                g.fillRect(
319
                    ini,
320
                    (int) rLayout.getMaxY()
321
                    - (int) FLayoutUtilities.fromSheetDistance(
322
                        attributes.getAreaInsets()[1], at), wi,
323
                        (int) FLayoutUtilities.fromSheetDistance(
324
                            attributes.getAreaInsets()[1], at));
325
            }
326

  
327
            g.setColor(color);
328
            g.drawLine(w, wi + ini, layoutControl.getWidth(), wi + ini);
329
            g.drawLine(w, ini, layoutControl.getWidth(), ini);
330
            g.drawLine(ini, w, ini, layoutControl.getHeight());
331
            g.drawLine(wi + ini, w, wi + ini, layoutControl.getHeight());
332

  
333
            drawLineY(g, 5, 12, 22, rLayout.getY(), 0);
334
            drawLineX(g, 5, 12, 22, rLayout.getX(), 0);
335

  
336
            if (FLayoutUtilities.fromSheetDistance(1, at) > 15) {
337
                drawLineY(g, 1, 12, 22, rLayout.getY(), 0);
338
                drawLineX(g, 1, 12, 22, rLayout.getX(), 0);
339

  
340
                if (FLayoutUtilities.fromSheetDistance(1, at) > 25) {
341
                    drawLineY(g, 1, 18, 22, rLayout.getY(), 0.5);
342
                    drawLineY(g, 0.1, 21, 22, rLayout.getY(), 0);
343
                    drawLineX(g, 1, 18, 22, rLayout.getX(), 0.5);
344
                    drawLineX(g, 0.1, 21, 22, rLayout.getX(), 0);
345
                }
346
            }
347
        }
348
    }
349

  
350
    /**
351
     * Dibuja sobre el graphics2d las l?neas verticales que representan a las
352
     * unidades de medida.
353
     * 
354
     * @param g
355
     *            Graphics2d sobre el que se dibuja.
356
     * @param dist
357
     *            distancia en cent?metros de una l?nea a otra.
358
     * @param init
359
     *            inicio de la l?nea.
360
     * @param end
361
     *            fin de la l?nea.
362
     * @param y
363
     *            rect?ngulo, dentro del cual se dibujan las l?neas.
364
     * @param desp
365
     *            Desplazamiento.
366
     */
367
    private void drawLineY(Graphics2D g, double dist, int init, int end,
368
        double y, double desp) {
369
        initialize();
370
        AffineTransform at = layoutContext.getAT();
371

  
372
        double distY = FLayoutUtilities.fromSheetDistance(dist, at);
373
        double rota = Math.toRadians(90);
374

  
375
        if (distY > 4) {
376
            double despY = FLayoutUtilities.fromSheetDistance(desp, at);
377

  
378
            double posUnitY = y + despY;
379
            double posUnitYNeg = posUnitY;
380
            int num = 0;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff