root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / Attributes.java @ 35778
History | View | Annotate | Download (45.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 25-jun-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.project.documents.layout; |
46 |
|
47 |
import java.awt.Rectangle; |
48 |
import java.awt.geom.Point2D; |
49 |
import java.awt.geom.Rectangle2D; |
50 |
import java.awt.print.PageFormat; |
51 |
import java.awt.print.Paper; |
52 |
import java.text.NumberFormat; |
53 |
import java.util.ArrayList; |
54 |
import java.util.HashMap; |
55 |
import java.util.Iterator; |
56 |
|
57 |
import javax.print.attribute.HashPrintRequestAttributeSet; |
58 |
import javax.print.attribute.PrintRequestAttributeSet; |
59 |
import javax.print.attribute.standard.Copies; |
60 |
import javax.print.attribute.standard.Fidelity; |
61 |
import javax.print.attribute.standard.Media; |
62 |
import javax.print.attribute.standard.MediaPrintableArea; |
63 |
import javax.print.attribute.standard.MediaSizeName; |
64 |
import javax.print.attribute.standard.OrientationRequested; |
65 |
import javax.print.attribute.standard.PrintQuality; |
66 |
import javax.print.attribute.standard.Sides; |
67 |
|
68 |
import org.apache.log4j.Logger; |
69 |
|
70 |
import com.iver.andami.PluginServices; |
71 |
import com.iver.cit.gvsig.fmap.MapContext; |
72 |
import com.iver.cit.gvsig.printutils.UserMediaSizeName; |
73 |
import com.iver.utiles.XMLEntity; |
74 |
|
75 |
|
76 |
/**
|
77 |
* Attributes of Layout.
|
78 |
*
|
79 |
* @author Vicente Caballero Navarro
|
80 |
*/
|
81 |
public class Attributes { |
82 |
|
83 |
private static Logger logger = Logger.getLogger(Attributes.class); |
84 |
/** Array of doubles containg the change factro from <b>CENTIMETERS</b> to KILOMETERS, METERS, CENTIMETERS, MILLIMETERS, MILES, YARDS, FEET, INCHES, DECIMAL DEGREES*/
|
85 |
/* Do not alter the order and the values of this array, if you need append values.*/
|
86 |
public static final double[] CHANGE = { |
87 |
100000, 100, 1, 0.1, 160934.4, 91.44, 30.48, 2.54, 8.983152841195214E-6 |
88 |
}; |
89 |
public static final String DEGREES="Grados"; |
90 |
/* Do not alter the order and the values of this array, if you need append values.*/
|
91 |
public static final double[] UNIT = { |
92 |
0.0000025, 0.0025, 0.25, 2.5, 0.0000025, 0.025, 0.025, 0.25, 8.8E-7 |
93 |
}; |
94 |
public static final int HIGH = 0; |
95 |
public static final int NORMAL = 1; |
96 |
public static final int DRAFT = 2; |
97 |
|
98 |
// Para impresi?n
|
99 |
public final static double PULGADA = 2.54; |
100 |
|
101 |
public final static Size NA_LETTER_PAPER_SIZE = new Size(PULGADA * 11.0, PULGADA * 8.5); |
102 |
public final static Size NA_LEGAL_PAPER_SIZE = new Size(PULGADA * 14.0, PULGADA * 8.5); |
103 |
public final static Size NA_TABLOID_PAPER_SIZE = new Size(PULGADA * 17.0, PULGADA * 11.0); |
104 |
// public final static Size FOLIO_PAPER_SIZE = new Size(PULGADA * 13.0, PULGADA * 8.5);
|
105 |
|
106 |
public final static Size METRIC_A0_PAPER_SIZE = new Size(118.9, 84.1); |
107 |
public final static Size METRIC_A1_PAPER_SIZE = new Size(84.1, 59.4); |
108 |
public final static Size METRIC_A2_PAPER_SIZE = new Size(59.4, 42.0); |
109 |
public final static Size METRIC_A3_PAPER_SIZE = new Size(42.0, 29.7); |
110 |
public final static Size METRIC_A4_PAPER_SIZE = new Size(29.7, 21.0); |
111 |
public final static Size METRIC_A5_PAPER_SIZE = new Size(21.0, 14.8); |
112 |
// public final static Size ANSI_ENG_A_PAPER_SIZE = new Size(11.0, 8.5);
|
113 |
// public final static Size ANSI_ENG_B_PAPER_SIZE = new Size(17.0, 11.0);
|
114 |
// public final static Size ANSI_ENG_C_PAPER_SIZE = new Size(22.0, 17.0);
|
115 |
// public final static Size ANSI_ENG_D_PAPER_SIZE = new Size(34.0, 22.0);
|
116 |
// public final static Size ANSI_ENG_E_PAPER_SIZE = new Size(44.0, 34.0);
|
117 |
// public final static Size ANSI_ARCH_A_PAPER_SIZE = new Size(12.0, 9.0);
|
118 |
// public final static Size ANSI_ARCH_B_PAPER_SIZE = new Size(18.0, 12.0);
|
119 |
// public final static Size ANSI_ARCH_C_PAPER_SIZE = new Size(24.0, 18.0);
|
120 |
// public final static Size ANSI_ARCH_D_PAPER_SIZE = new Size(36.0, 24.0);
|
121 |
// public final static Size ANSI_ARCH_E_PAPER_SIZE = new Size(42.0, 30.0);
|
122 |
|
123 |
public static Size CUSTOM_PAPER_SIZE = new Size(30.0, 20.0); |
124 |
|
125 |
// ===============================================
|
126 |
public final static int PREPARE_PAGE_ID_PRINT = 0; |
127 |
public final static int PREPARE_PAGE_ID_A4 = 1; |
128 |
public final static int PREPARE_PAGE_ID_A3 = 2; |
129 |
public final static int PREPARE_PAGE_ID_A2 = 3; |
130 |
public final static int PREPARE_PAGE_ID_A1 = 4; |
131 |
public final static int PREPARE_PAGE_ID_A0 = 5; |
132 |
|
133 |
// added gvSIG EIEL march 2011 - start
|
134 |
public final static int PREPARE_PAGE_ID_NA_LETTER = 6; |
135 |
public final static int PREPARE_PAGE_ID_NA_LEGAL = 7; |
136 |
public final static int PREPARE_PAGE_ID_EXEC_MONARCH = 8; |
137 |
public final static int PREPARE_PAGE_ID_B5_JIS = 9; |
138 |
public final static int PREPARE_PAGE_ID_TABLOID = 10; |
139 |
public final static int PREPARE_PAGE_ID_ENV_MONARCH = 11; |
140 |
public final static int PREPARE_PAGE_ID_ENV_N10 = 12; |
141 |
public final static int PREPARE_PAGE_ID_ENV_C5 = 13; |
142 |
public final static int PREPARE_PAGE_ID_ENV_DL = 14; |
143 |
public final static int PREPARE_PAGE_ID_ENV_B5 = 15; |
144 |
// ----------------------------------------------
|
145 |
public final static int PREPARE_PAGE_ID_CUSTOM = 16; |
146 |
// ======================================
|
147 |
// public final static Size US_LETTER_PAPER_SIZE = new Size(PULGADA * 8.5, PULGADA * 11);
|
148 |
// public final static Size NA_LEGAL_PAPER_SIZE = new Size(PULGADA * 8.5, PULGADA * 14);
|
149 |
public final static Size EXEC_MONARCH_PAPER_SIZE = new Size(PULGADA * 10.5, PULGADA * 7.25); |
150 |
public final static Size B5_JIS_PAPER_SIZE = new Size(25.7, 18.2); |
151 |
// public final static Size ENV_11X17_PAPER_SIZE = new Size(11, 17);
|
152 |
public final static Size ENV_MONARCH_PAPER_SIZE = new Size(PULGADA * 7.5, PULGADA * 3.875); |
153 |
public final static Size ENV_N10_PAPER_SIZE = new Size(PULGADA * 9.5, PULGADA * 4.125); |
154 |
public final static Size ENV_C5_PAPER_SIZE = new Size(22.9, 16.2); |
155 |
public final static Size ENV_DL_PAPER_SIZE = new Size(22,11); |
156 |
public final static Size ENV_B5_PAPER_SIZE = new Size(25,17.6); |
157 |
|
158 |
|
159 |
// ==========================================
|
160 |
// public static UserMediaSizeName USR_MEDIA_EXEC_MONARCH = new UserMediaSizeName("Executive");
|
161 |
// public static UserMediaSizeName USR_MEDIA_B5_JIS = new UserMediaSizeName("B5 (JIS)");
|
162 |
public static UserMediaSizeName USR_MEDIA_ENV_MONARCH = new UserMediaSizeName("Envelope_Monarch"); |
163 |
public static UserMediaSizeName USR_MEDIA_ENV_N10 = new UserMediaSizeName("Envelope_no10"); |
164 |
public static UserMediaSizeName USR_MEDIA_ENV_C5 = new UserMediaSizeName("Envelope_C5"); |
165 |
public static UserMediaSizeName USR_MEDIA_ENV_DL = new UserMediaSizeName("Envelope_DL"); |
166 |
public static UserMediaSizeName USR_MEDIA_ENV_B5 = new UserMediaSizeName("Envelope_B5"); |
167 |
// added gvSIG EIEL march 2011 - end
|
168 |
|
169 |
|
170 |
public static int DPI = 300; |
171 |
public static int DPISCREEN = 72; |
172 |
public static double STANDARD_SCREEN_DOTS_PER_CM = 72 / 2.54; |
173 |
|
174 |
public static Rectangle clipRect = new Rectangle(); |
175 |
private static Point2D defaultGridGap; |
176 |
|
177 |
// static {
|
178 |
// new Attributes();
|
179 |
// }
|
180 |
|
181 |
private PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); |
182 |
private MediaSizeName m_type = MediaSizeName.ISO_A4; |
183 |
private boolean m_isLandSel; |
184 |
private OrientationRequested m_Orientation; |
185 |
private double m_TypeUnit = CHANGE[2]; //CENTIMETROS; |
186 |
private String m_NameUnit; |
187 |
private Double m_numX=null; |
188 |
private Double m_numY=null; |
189 |
private double m_unitX = 0; |
190 |
private double m_unitY = 0; |
191 |
private boolean hasmargin; |
192 |
private int m_resolutionSel = NORMAL; |
193 |
private int m_typeSel = PREPARE_PAGE_ID_PRINT; |
194 |
private int m_selTypeUnit = 2; |
195 |
public Size m_sizePaper = new Size(METRIC_A4_PAPER_SIZE.getAlto(), |
196 |
METRIC_A4_PAPER_SIZE.getAncho()); |
197 |
public double[] m_area = { PULGADA, PULGADA, PULGADA, PULGADA }; |
198 |
private double anchoXalto = m_sizePaper.getAlto() / m_sizePaper.getAncho(); |
199 |
private Size m_sizeinUnits = m_sizePaper;
|
200 |
private PrintQuality m_resolution=PrintQuality.NORMAL; |
201 |
/**
|
202 |
* Create a new object of Attributes.
|
203 |
*
|
204 |
*/
|
205 |
public Attributes() { |
206 |
m_NameUnit = PluginServices.getText(this,"Centimetros"); |
207 |
m_type = MediaSizeName.ISO_A4;
|
208 |
m_isLandSel = true;
|
209 |
setSizeinUnits(m_isLandSel); |
210 |
|
211 |
hasmargin = false;
|
212 |
m_Orientation = OrientationRequested.LANDSCAPE;
|
213 |
attributes.add(new Copies(1)); |
214 |
attributes.add(MediaSizeName.ISO_A4);
|
215 |
attributes.add(Sides.ONE_SIDED);
|
216 |
attributes.add(Fidelity.FIDELITY_FALSE);
|
217 |
attributes.add(PrintQuality.NORMAL);
|
218 |
|
219 |
setType(m_typeSel); |
220 |
|
221 |
attributes.add(new MediaPrintableArea(0, 0, |
222 |
(float) ((m_sizePaper.getAlto() * DPISCREEN) / PULGADA),
|
223 |
(float) ((m_sizePaper.getAncho() * DPISCREEN) / PULGADA),
|
224 |
MediaPrintableArea.MM));
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* Inserts the Layout's properties to print.
|
229 |
*
|
230 |
* @param typeSel Type of sheet.
|
231 |
* @param units Units.
|
232 |
* @param isLand True if the sheet is horizontal.
|
233 |
* @param margin True if the sheet has margin.
|
234 |
* @param resolution Type of quality of resolution.
|
235 |
* @param area Printing area.
|
236 |
*/
|
237 |
public void setSelectedOptions(int typeSel, int units, boolean isLand, |
238 |
boolean margin, int resolution, double[] area) { |
239 |
setType(typeSel); |
240 |
setUnit(units); |
241 |
setIsLandScape(isLand); |
242 |
hasmargin = margin; |
243 |
setResolution(resolution); |
244 |
m_area = area; |
245 |
} |
246 |
|
247 |
/**
|
248 |
* Returns a PageFormat with the properties of printing.
|
249 |
*
|
250 |
* @return PageFormat
|
251 |
*/
|
252 |
public PageFormat getPageFormat() { |
253 |
PageFormat pf1 = new PageFormat(); |
254 |
Paper paper = pf1.getPaper();
|
255 |
|
256 |
if (isLandSpace()) {
|
257 |
pf1.setOrientation(0);
|
258 |
paper.setSize((m_sizePaper.getAncho() * DPISCREEN) / PULGADA, |
259 |
(m_sizePaper.getAlto() * DPISCREEN) / PULGADA); |
260 |
|
261 |
double aux = m_area[0]; |
262 |
m_area[0] = m_area[3]; |
263 |
m_area[3] = m_area[1]; |
264 |
m_area[1] = m_area[2]; |
265 |
m_area[2] = aux;
|
266 |
paper.setImageableArea(getInPixels(m_area[2]),
|
267 |
getInPixels(m_area[0]),
|
268 |
getInPixels(m_sizeinUnits.getAncho() - m_area[2] - m_area[3]), |
269 |
getInPixels(m_sizeinUnits.getAlto() - m_area[0] - m_area[1])); |
270 |
} else {
|
271 |
pf1.setOrientation(1);
|
272 |
paper.setSize((m_sizePaper.getAlto() * DPISCREEN) / PULGADA, |
273 |
(m_sizePaper.getAncho() * DPISCREEN) / PULGADA); |
274 |
paper.setImageableArea(getInPixels(m_area[2]),
|
275 |
getInPixels(m_area[0]),
|
276 |
getInPixels(m_sizeinUnits.getAlto() - m_area[2] - m_area[3]), |
277 |
getInPixels(m_sizeinUnits.getAncho() - m_area[0] - m_area[1])); |
278 |
} |
279 |
|
280 |
pf1.setPaper(paper); |
281 |
|
282 |
return pf1;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* Changes centimeters to pixels.
|
287 |
*
|
288 |
* @param d Centimeters.
|
289 |
*
|
290 |
* @return Pixels.
|
291 |
*/
|
292 |
private double getInPixels(double d) { |
293 |
return d * (DPISCREEN / PULGADA);
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* Changes pixels to centimeters.
|
298 |
*
|
299 |
* @param d Pixel.
|
300 |
*
|
301 |
* @return Centimeters.
|
302 |
*/
|
303 |
private double getInCM(double d) { |
304 |
return d / (DPISCREEN / PULGADA);
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Returns the printing area.
|
309 |
*
|
310 |
* @return Rectangle Area.
|
311 |
*/
|
312 |
public Rectangle2D getArea() { |
313 |
Rectangle2D.Double rect = new Rectangle2D.Double(); |
314 |
rect.setRect(m_area[0], m_area[1], |
315 |
m_sizePaper.getAncho() - m_area[0] - m_area[2], |
316 |
m_sizePaper.getAlto() - m_area[1] - m_area[3]); |
317 |
|
318 |
return rect;
|
319 |
} |
320 |
|
321 |
/**
|
322 |
* Get current 4 margin values as an array[0..3] [top, bottom, left, right]
|
323 |
* @return 4 margin values as an array[0..3] [top, bottom, left, right]
|
324 |
*/
|
325 |
public double[] getMargins() { |
326 |
return m_area;
|
327 |
} |
328 |
|
329 |
/**
|
330 |
* Inserts the attributes with a PageFormat.
|
331 |
*
|
332 |
* @param pf PageFormat.
|
333 |
*/
|
334 |
public void setPageFormat(PageFormat pf) { |
335 |
Size size = null;
|
336 |
|
337 |
if (pf.getOrientation() == 0) { |
338 |
setIsLandScape(true);
|
339 |
m_Orientation = OrientationRequested.LANDSCAPE;
|
340 |
size = new Size(pf.getHeight(), pf.getWidth());
|
341 |
} else {
|
342 |
setIsLandScape(false);
|
343 |
m_Orientation = OrientationRequested.PORTRAIT;
|
344 |
size = new Size(pf.getHeight(), pf.getWidth());
|
345 |
} |
346 |
|
347 |
attributes.add(m_Orientation); |
348 |
|
349 |
//area
|
350 |
m_area[0] = getInCM(pf.getImageableY());
|
351 |
m_area[2] = getInCM(pf.getImageableX());
|
352 |
m_area[1] = m_sizePaper.getAlto() - getInCM(pf.getImageableHeight()) -
|
353 |
m_area[0];
|
354 |
m_area[3] = m_sizePaper.getAncho() - getInCM(pf.getImageableWidth()) -
|
355 |
m_area[2];
|
356 |
|
357 |
// tipo formato
|
358 |
if (isLandSpace()) {
|
359 |
//double aux = m_area[0];
|
360 |
//m_area[0] = m_area[3];
|
361 |
//m_area[3] = m_area[1];
|
362 |
//m_area[1] = m_area[2];
|
363 |
//m_area[2] = aux;
|
364 |
attributes.add(new MediaPrintableArea((float) (m_area[2] * 10), |
365 |
(float) (m_area[0] * 10), |
366 |
(float) (m_sizeinUnits.getAlto() - m_area[0] - m_area[1]) * 10, |
367 |
(float) (m_sizeinUnits.getAncho() - m_area[2] - m_area[3]) * 10, |
368 |
MediaPrintableArea.MM));
|
369 |
} else {
|
370 |
attributes.add(new MediaPrintableArea((float) (m_area[0] * 10), |
371 |
(float) (m_area[1] * 10), |
372 |
(float) (getInCM(pf.getImageableWidth()) * 10), |
373 |
(float) (getInCM(pf.getImageableHeight()) * 10), |
374 |
MediaPrintableArea.MM));
|
375 |
} |
376 |
|
377 |
setType(getTypePaper(size)); |
378 |
} |
379 |
|
380 |
/**
|
381 |
* Returns a PrintRequestAttributeSet with all properties to the PrintDialog.
|
382 |
*
|
383 |
* @return PrintRequestAttributesSet.
|
384 |
*/
|
385 |
public PrintRequestAttributeSet toPrintAttributes() { |
386 |
HashPrintRequestAttributeSet resul = new HashPrintRequestAttributeSet(); |
387 |
|
388 |
setType(m_typeSel); |
389 |
|
390 |
resul.add(m_type); |
391 |
|
392 |
//units, no hace falta a?adirlo a attributes
|
393 |
resul.add(m_Orientation); |
394 |
setArea(m_area); |
395 |
resul.add(new MediaPrintableArea(0, 0, |
396 |
(float) ((m_sizePaper.getAlto() * DPISCREEN) / PULGADA),
|
397 |
(float) ((m_sizePaper.getAncho() * DPISCREEN) / PULGADA),
|
398 |
MediaPrintableArea.MM));
|
399 |
|
400 |
resul.add(m_resolution); |
401 |
//resul.add(new PrinterResolution(DPI,DPI,PrinterResolution.DPI));
|
402 |
return resul;
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* Inserts printing area.
|
407 |
*
|
408 |
* @param area Printing area.
|
409 |
*/
|
410 |
public void setArea(double[] area) { |
411 |
if (!isLandSpace()) {
|
412 |
attributes.add(new MediaPrintableArea((float) (area[2] * 10), |
413 |
(float) (area[0] * 10), |
414 |
(float) ((m_sizePaper.getAncho() - area[2] - area[3]) * 10), |
415 |
(float) ((m_sizePaper.getAlto() - area[0] - area[1]) * 10), |
416 |
MediaPrintableArea.MM));
|
417 |
|
418 |
clipRect.setRect((area[2] / PULGADA * DPI),
|
419 |
area[0] / PULGADA * DPI,
|
420 |
(m_sizePaper.getAncho() - area[2] - area[3]) / PULGADA * DPI, |
421 |
(m_sizePaper.getAlto() - area[0] - area[1]) / PULGADA * DPI); |
422 |
} else {
|
423 |
attributes.add(new MediaPrintableArea((float) (area[0] * 10), |
424 |
(float) (area[3] * 10), |
425 |
(float) ((m_sizePaper.getAlto() - area[0] - area[1]) * 10), |
426 |
(float) ((m_sizePaper.getAncho() - area[3] - area[2]) * 10), |
427 |
MediaPrintableArea.MM));
|
428 |
|
429 |
clipRect.setRect((area[1] / PULGADA * DPI),
|
430 |
area[2] / PULGADA * DPI,
|
431 |
(m_sizePaper.getAncho() - area[1] - area[0]) / PULGADA * DPI, |
432 |
(m_sizePaper.getAlto() - area[2] - area[3]) / PULGADA * DPI); |
433 |
} |
434 |
} |
435 |
|
436 |
/**
|
437 |
* Returns true if the margin should be used.
|
438 |
*
|
439 |
* @return True if margin should be used.
|
440 |
*/
|
441 |
public boolean isMargin() { |
442 |
return hasmargin;
|
443 |
} |
444 |
|
445 |
/**
|
446 |
* Returns the resolution of properties to print.
|
447 |
*
|
448 |
* @return Resolution.
|
449 |
*/
|
450 |
public int getResolution() { |
451 |
return m_resolutionSel;
|
452 |
} |
453 |
|
454 |
/**
|
455 |
* Inserts the resolution to apply at printing.
|
456 |
*
|
457 |
* @param i Type of resolution.
|
458 |
*
|
459 |
* The type of resolution can be:
|
460 |
*
|
461 |
* DRAFT: 27 dpi.
|
462 |
* NORMAL: 300 dpi.
|
463 |
* HIGH: 600 dpi.
|
464 |
*/
|
465 |
public void setResolution(int i) { |
466 |
m_resolutionSel = i; |
467 |
|
468 |
switch (i) {
|
469 |
case (HIGH):
|
470 |
|
471 |
m_resolution=PrintQuality.HIGH;
|
472 |
DPI = 600;
|
473 |
|
474 |
break;
|
475 |
|
476 |
case (NORMAL):
|
477 |
|
478 |
m_resolution=PrintQuality.NORMAL;
|
479 |
DPI = 300;
|
480 |
|
481 |
break;
|
482 |
|
483 |
case (DRAFT):
|
484 |
|
485 |
m_resolution=PrintQuality.DRAFT;
|
486 |
DPI = 72;
|
487 |
|
488 |
break;
|
489 |
} |
490 |
attributes.add(m_resolution); |
491 |
} |
492 |
|
493 |
/**
|
494 |
* Returns attributes of PrintDialog.
|
495 |
*
|
496 |
* @return Attributes of printing.
|
497 |
*/
|
498 |
public PrintRequestAttributeSet getAttributes() { |
499 |
return attributes;
|
500 |
} |
501 |
|
502 |
/**
|
503 |
* Returns True if the position of sheet is horizontal or vertical.
|
504 |
*
|
505 |
* @return True if position is horizontal.
|
506 |
*/
|
507 |
public boolean isLandSpace() { |
508 |
return m_isLandSel;
|
509 |
} |
510 |
|
511 |
/**
|
512 |
* Returns the format of sheet.
|
513 |
*
|
514 |
* @return Format of sheet.
|
515 |
*/
|
516 |
public int getType() { |
517 |
return m_typeSel;
|
518 |
} |
519 |
|
520 |
/**
|
521 |
* Inserts the number of units to define the coords X grid.
|
522 |
*
|
523 |
* @param d number of units to define the grid.
|
524 |
*/
|
525 |
public void setNumUnitsX(double d) { |
526 |
m_numX = new Double(d); |
527 |
} |
528 |
|
529 |
/**
|
530 |
* Returns the number of pixels that represents a unit of coords X.
|
531 |
*
|
532 |
* @return Number of pixels coords X.
|
533 |
*/
|
534 |
|
535 |
public double getNumUnitsX() { |
536 |
if (m_numX == null) |
537 |
m_numX = new Double(getDefaultGridGap().getX()); |
538 |
return m_numX.doubleValue();
|
539 |
} |
540 |
|
541 |
/**
|
542 |
* Returns the number of pixels that represents a unit of coords Y.
|
543 |
*
|
544 |
* @return Number of pixels coords Y.
|
545 |
*/
|
546 |
|
547 |
public double getNumUnitsY() { |
548 |
if (m_numY == null) |
549 |
m_numY = new Double(getDefaultGridGap().getY()); |
550 |
return m_numY.doubleValue();
|
551 |
} |
552 |
|
553 |
/**
|
554 |
* Inserts the number of units to define the coords X grid.
|
555 |
*
|
556 |
* @param d number of units to define the grid.
|
557 |
*/
|
558 |
public void setNumUnitsY(double d) { |
559 |
m_numY = new Double(d); |
560 |
} |
561 |
|
562 |
/**
|
563 |
* Inserts true if the sheet is horizontal or false if is vertical.
|
564 |
*
|
565 |
* @param b True if sheet is horizontal.
|
566 |
*/
|
567 |
public void setIsLandScape(boolean b) { |
568 |
m_isLandSel = b; |
569 |
setType(m_typeSel); |
570 |
|
571 |
if (m_isLandSel) {
|
572 |
m_Orientation = OrientationRequested.LANDSCAPE;
|
573 |
} else {
|
574 |
m_Orientation = OrientationRequested.PORTRAIT;
|
575 |
} |
576 |
} |
577 |
|
578 |
/**
|
579 |
* Inserts the type of sheet to show.
|
580 |
*
|
581 |
* @param t Type of sheet.
|
582 |
*/
|
583 |
public void setType(int t) { |
584 |
m_typeSel = t; |
585 |
|
586 |
//m_sizePaper=getSizePaper(t);
|
587 |
switch (t) {
|
588 |
case (PREPARE_PAGE_ID_PRINT):
|
589 |
m_type = ((MediaSizeName) attributes.get(Media.class)); |
590 |
|
591 |
if (isLandSpace()) {
|
592 |
m_sizePaper = new Size(METRIC_A4_PAPER_SIZE.getAncho(),
|
593 |
METRIC_A4_PAPER_SIZE.getAlto()); |
594 |
} else {
|
595 |
m_sizePaper = METRIC_A4_PAPER_SIZE; |
596 |
} |
597 |
|
598 |
break;
|
599 |
|
600 |
case (PREPARE_PAGE_ID_A4):
|
601 |
m_type = MediaSizeName.ISO_A4;
|
602 |
|
603 |
if (isLandSpace()) {
|
604 |
m_sizePaper = new Size(METRIC_A4_PAPER_SIZE.getAncho(),
|
605 |
METRIC_A4_PAPER_SIZE.getAlto()); |
606 |
} else {
|
607 |
m_sizePaper = METRIC_A4_PAPER_SIZE; |
608 |
} |
609 |
|
610 |
break;
|
611 |
|
612 |
case (PREPARE_PAGE_ID_A3):
|
613 |
m_type = MediaSizeName.ISO_A3;
|
614 |
|
615 |
if (isLandSpace()) {
|
616 |
m_sizePaper = new Size(METRIC_A3_PAPER_SIZE.getAncho(),
|
617 |
METRIC_A3_PAPER_SIZE.getAlto()); |
618 |
} else {
|
619 |
m_sizePaper = METRIC_A3_PAPER_SIZE; |
620 |
} |
621 |
|
622 |
break;
|
623 |
|
624 |
case (PREPARE_PAGE_ID_A2):
|
625 |
m_type = MediaSizeName.ISO_A2;
|
626 |
|
627 |
if (isLandSpace()) {
|
628 |
m_sizePaper = new Size(METRIC_A2_PAPER_SIZE.getAncho(),
|
629 |
METRIC_A2_PAPER_SIZE.getAlto()); |
630 |
} else {
|
631 |
m_sizePaper = METRIC_A2_PAPER_SIZE; |
632 |
} |
633 |
|
634 |
break;
|
635 |
|
636 |
case (PREPARE_PAGE_ID_A1):
|
637 |
m_type = MediaSizeName.ISO_A1;
|
638 |
|
639 |
if (isLandSpace()) {
|
640 |
m_sizePaper = new Size(METRIC_A1_PAPER_SIZE.getAncho(),
|
641 |
METRIC_A1_PAPER_SIZE.getAlto()); |
642 |
} else {
|
643 |
m_sizePaper = METRIC_A1_PAPER_SIZE; |
644 |
} |
645 |
|
646 |
break;
|
647 |
|
648 |
case (PREPARE_PAGE_ID_A0):
|
649 |
m_type = MediaSizeName.ISO_A0;
|
650 |
|
651 |
if (isLandSpace()) {
|
652 |
m_sizePaper = new Size(METRIC_A0_PAPER_SIZE.getAncho(),
|
653 |
METRIC_A0_PAPER_SIZE.getAlto()); |
654 |
} else {
|
655 |
m_sizePaper = METRIC_A0_PAPER_SIZE; |
656 |
} |
657 |
|
658 |
break;
|
659 |
|
660 |
case (PREPARE_PAGE_ID_CUSTOM):
|
661 |
m_type = MediaSizeName.PERSONAL_ENVELOPE;
|
662 |
// if (isLandSpace()) {
|
663 |
// m_sizePaper = new Size(CUSTOM_PAPER_SIZE.getAncho()*m_TypeUnit,
|
664 |
// CUSTOM_PAPER_SIZE.getAlto()*m_TypeUnit);
|
665 |
// } else {
|
666 |
// m_sizePaper = new Size(CUSTOM_PAPER_SIZE.getAlto()*m_TypeUnit,
|
667 |
// CUSTOM_PAPER_SIZE.getAncho()*m_TypeUnit);
|
668 |
// }
|
669 |
break;
|
670 |
|
671 |
|
672 |
|
673 |
// public final static int PREPARE_PAGE_ID_US_LETTER = 7;
|
674 |
case (PREPARE_PAGE_ID_NA_LETTER):
|
675 |
m_type = MediaSizeName.NA_LETTER;
|
676 |
if (isLandSpace()) {
|
677 |
m_sizePaper = new Size(
|
678 |
NA_LETTER_PAPER_SIZE.getAncho(), |
679 |
NA_LETTER_PAPER_SIZE.getAlto()); |
680 |
} else {
|
681 |
m_sizePaper = NA_LETTER_PAPER_SIZE; |
682 |
} |
683 |
break;
|
684 |
// public final static int PREPARE_PAGE_ID_US_LEGAL = 8;
|
685 |
case (PREPARE_PAGE_ID_NA_LEGAL):
|
686 |
m_type = MediaSizeName.NA_LEGAL;
|
687 |
if (isLandSpace()) {
|
688 |
m_sizePaper = new Size(
|
689 |
NA_LEGAL_PAPER_SIZE.getAncho(), |
690 |
NA_LEGAL_PAPER_SIZE.getAlto()); |
691 |
} else {
|
692 |
m_sizePaper = NA_LEGAL_PAPER_SIZE; |
693 |
} |
694 |
break;
|
695 |
// public final static int PREPARE_PAGE_ID_EXEC_MONARCH = 9;
|
696 |
case (PREPARE_PAGE_ID_EXEC_MONARCH):
|
697 |
m_type = MediaSizeName.EXECUTIVE;
|
698 |
if (isLandSpace()) {
|
699 |
m_sizePaper = new Size(
|
700 |
EXEC_MONARCH_PAPER_SIZE.getAncho(), |
701 |
EXEC_MONARCH_PAPER_SIZE.getAlto()); |
702 |
} else {
|
703 |
m_sizePaper = EXEC_MONARCH_PAPER_SIZE; |
704 |
} |
705 |
break;
|
706 |
// public final static int PREPARE_PAGE_ID_B5_JIS = 10;
|
707 |
case (PREPARE_PAGE_ID_B5_JIS):
|
708 |
m_type = MediaSizeName.JIS_B5;
|
709 |
if (isLandSpace()) {
|
710 |
m_sizePaper = new Size(
|
711 |
B5_JIS_PAPER_SIZE.getAncho(), |
712 |
B5_JIS_PAPER_SIZE.getAlto()); |
713 |
} else {
|
714 |
m_sizePaper = B5_JIS_PAPER_SIZE; |
715 |
} |
716 |
break;
|
717 |
// public final static int PREPARE_PAGE_ID_ENV_11X17 = 11;
|
718 |
case (PREPARE_PAGE_ID_TABLOID):
|
719 |
m_type = MediaSizeName.TABLOID;
|
720 |
if (isLandSpace()) {
|
721 |
m_sizePaper = new Size(
|
722 |
NA_TABLOID_PAPER_SIZE.getAncho(), |
723 |
NA_TABLOID_PAPER_SIZE.getAlto()); |
724 |
} else {
|
725 |
m_sizePaper = NA_TABLOID_PAPER_SIZE; |
726 |
} |
727 |
break;
|
728 |
// public final static int PREPARE_PAGE_ID_ENV_MONARCH = 12;
|
729 |
case (PREPARE_PAGE_ID_ENV_MONARCH):
|
730 |
m_type = MediaSizeName.MONARCH_ENVELOPE;
|
731 |
if (isLandSpace()) {
|
732 |
m_sizePaper = new Size(
|
733 |
ENV_MONARCH_PAPER_SIZE.getAncho(), |
734 |
ENV_MONARCH_PAPER_SIZE.getAlto()); |
735 |
} else {
|
736 |
m_sizePaper = ENV_MONARCH_PAPER_SIZE; |
737 |
} |
738 |
break;
|
739 |
// public final static int PREPARE_PAGE_ID_ENV_N10 = 13;
|
740 |
case (PREPARE_PAGE_ID_ENV_N10):
|
741 |
m_type = MediaSizeName.NA_NUMBER_10_ENVELOPE;
|
742 |
if (isLandSpace()) {
|
743 |
m_sizePaper = new Size(
|
744 |
ENV_N10_PAPER_SIZE.getAncho(), |
745 |
ENV_N10_PAPER_SIZE.getAlto()); |
746 |
} else {
|
747 |
m_sizePaper = ENV_N10_PAPER_SIZE; |
748 |
} |
749 |
break;
|
750 |
// public final static int PREPARE_PAGE_ID_ENV_C5 = 14;
|
751 |
case (PREPARE_PAGE_ID_ENV_C5):
|
752 |
m_type = USR_MEDIA_ENV_C5; |
753 |
if (isLandSpace()) {
|
754 |
m_sizePaper = new Size(
|
755 |
ENV_C5_PAPER_SIZE.getAncho(), |
756 |
ENV_C5_PAPER_SIZE.getAlto()); |
757 |
} else {
|
758 |
m_sizePaper = ENV_C5_PAPER_SIZE; |
759 |
} |
760 |
break;
|
761 |
// public final static int PREPARE_PAGE_ID_ENV_DL = 15;
|
762 |
case (PREPARE_PAGE_ID_ENV_DL):
|
763 |
m_type = USR_MEDIA_ENV_DL; |
764 |
// MediaSizeName.NA_LETTER.
|
765 |
|
766 |
if (isLandSpace()) {
|
767 |
m_sizePaper = new Size(
|
768 |
ENV_DL_PAPER_SIZE.getAncho(), |
769 |
ENV_DL_PAPER_SIZE.getAlto()); |
770 |
} else {
|
771 |
m_sizePaper = ENV_DL_PAPER_SIZE; |
772 |
} |
773 |
break;
|
774 |
// public final static int PREPARE_PAGE_ID_ENV_B5 = 16;
|
775 |
case (PREPARE_PAGE_ID_ENV_B5):
|
776 |
m_type = USR_MEDIA_ENV_B5; |
777 |
if (isLandSpace()) {
|
778 |
m_sizePaper = new Size(
|
779 |
ENV_B5_PAPER_SIZE.getAncho(), |
780 |
ENV_B5_PAPER_SIZE.getAlto()); |
781 |
} else {
|
782 |
m_sizePaper = ENV_B5_PAPER_SIZE; |
783 |
} |
784 |
break;
|
785 |
|
786 |
} |
787 |
attributes.add(m_type); |
788 |
setSizeinUnits(isLandSpace()); |
789 |
m_sizeinUnits = getSizeInUnits(); |
790 |
} |
791 |
|
792 |
/**
|
793 |
* Returns the size of sheet.
|
794 |
*
|
795 |
* @param isLand True if is horizontal and false if is vertical.
|
796 |
* @param type Type of sheet.
|
797 |
*
|
798 |
* @return Size of sheet with these properties.
|
799 |
*/
|
800 |
public Size getSizeinUnits(boolean isLand, int type) { |
801 |
Size size = null;
|
802 |
|
803 |
switch (type) {
|
804 |
case (PREPARE_PAGE_ID_PRINT):
|
805 |
|
806 |
if (isLand) {
|
807 |
size = new Size(METRIC_A4_PAPER_SIZE.getAncho(),
|
808 |
METRIC_A4_PAPER_SIZE.getAlto()); |
809 |
} else {
|
810 |
size = METRIC_A4_PAPER_SIZE; |
811 |
} |
812 |
|
813 |
break;
|
814 |
|
815 |
case (PREPARE_PAGE_ID_A4):
|
816 |
|
817 |
if (isLand) {
|
818 |
size = new Size(METRIC_A4_PAPER_SIZE.getAncho(),
|
819 |
METRIC_A4_PAPER_SIZE.getAlto()); |
820 |
} else {
|
821 |
size = METRIC_A4_PAPER_SIZE; |
822 |
} |
823 |
|
824 |
break;
|
825 |
|
826 |
case (PREPARE_PAGE_ID_A3):
|
827 |
|
828 |
if (isLand) {
|
829 |
size = new Size(METRIC_A3_PAPER_SIZE.getAncho(),
|
830 |
METRIC_A3_PAPER_SIZE.getAlto()); |
831 |
} else {
|
832 |
size = METRIC_A3_PAPER_SIZE; |
833 |
} |
834 |
|
835 |
break;
|
836 |
|
837 |
case (PREPARE_PAGE_ID_A2):
|
838 |
|
839 |
if (isLand) {
|
840 |
size = new Size(METRIC_A2_PAPER_SIZE.getAncho(),
|
841 |
METRIC_A2_PAPER_SIZE.getAlto()); |
842 |
} else {
|
843 |
size = METRIC_A2_PAPER_SIZE; |
844 |
} |
845 |
|
846 |
break;
|
847 |
|
848 |
case (PREPARE_PAGE_ID_A1):
|
849 |
|
850 |
if (isLand) {
|
851 |
size = new Size(METRIC_A1_PAPER_SIZE.getAncho(),
|
852 |
METRIC_A1_PAPER_SIZE.getAlto()); |
853 |
} else {
|
854 |
size = METRIC_A1_PAPER_SIZE; |
855 |
} |
856 |
|
857 |
break;
|
858 |
|
859 |
case (PREPARE_PAGE_ID_A0):
|
860 |
|
861 |
if (isLand) {
|
862 |
size = new Size(METRIC_A0_PAPER_SIZE.getAncho(),
|
863 |
METRIC_A0_PAPER_SIZE.getAlto()); |
864 |
} else {
|
865 |
size = METRIC_A0_PAPER_SIZE; |
866 |
} |
867 |
|
868 |
break;
|
869 |
|
870 |
case (PREPARE_PAGE_ID_CUSTOM):
|
871 |
|
872 |
size = new Size(CUSTOM_PAPER_SIZE.getAncho(),
|
873 |
CUSTOM_PAPER_SIZE.getAlto()); |
874 |
break;
|
875 |
|
876 |
// =============================
|
877 |
// =============================
|
878 |
|
879 |
case (PREPARE_PAGE_ID_NA_LETTER):
|
880 |
if (isLand) {
|
881 |
size = new Size(
|
882 |
NA_LETTER_PAPER_SIZE.getAncho(), |
883 |
NA_LETTER_PAPER_SIZE.getAlto()); |
884 |
} else {
|
885 |
size = NA_LETTER_PAPER_SIZE; |
886 |
} |
887 |
break;
|
888 |
// public final static int PREPARE_PAGE_ID_US_LEGAL = 8;
|
889 |
case (PREPARE_PAGE_ID_NA_LEGAL):
|
890 |
if (isLand) {
|
891 |
size = new Size(
|
892 |
NA_LEGAL_PAPER_SIZE.getAncho(), |
893 |
NA_LEGAL_PAPER_SIZE.getAlto()); |
894 |
} else {
|
895 |
size = NA_LEGAL_PAPER_SIZE; |
896 |
} |
897 |
break;
|
898 |
// public final static int PREPARE_PAGE_ID_EXEC_MONARCH = 9;
|
899 |
case (PREPARE_PAGE_ID_EXEC_MONARCH):
|
900 |
if (isLand) {
|
901 |
size = new Size(
|
902 |
EXEC_MONARCH_PAPER_SIZE.getAncho(), |
903 |
EXEC_MONARCH_PAPER_SIZE.getAlto()); |
904 |
} else {
|
905 |
size = EXEC_MONARCH_PAPER_SIZE; |
906 |
} |
907 |
break;
|
908 |
// public final static int PREPARE_PAGE_ID_B5_JIS = 10;
|
909 |
case (PREPARE_PAGE_ID_B5_JIS):
|
910 |
if (isLand) {
|
911 |
size = new Size(
|
912 |
B5_JIS_PAPER_SIZE.getAncho(), |
913 |
B5_JIS_PAPER_SIZE.getAlto()); |
914 |
} else {
|
915 |
size = B5_JIS_PAPER_SIZE; |
916 |
} |
917 |
break;
|
918 |
// public final static int PREPARE_PAGE_ID_ENV_11X17 = 11;
|
919 |
case (PREPARE_PAGE_ID_TABLOID):
|
920 |
if (isLand) {
|
921 |
size = new Size(
|
922 |
NA_TABLOID_PAPER_SIZE.getAncho(), |
923 |
NA_TABLOID_PAPER_SIZE.getAlto()); |
924 |
} else {
|
925 |
size = NA_TABLOID_PAPER_SIZE; |
926 |
} |
927 |
break;
|
928 |
// public final static int PREPARE_PAGE_ID_ENV_MONARCH = 12;
|
929 |
case (PREPARE_PAGE_ID_ENV_MONARCH):
|
930 |
if (isLand) {
|
931 |
size = new Size(
|
932 |
ENV_MONARCH_PAPER_SIZE.getAncho(), |
933 |
ENV_MONARCH_PAPER_SIZE.getAlto()); |
934 |
} else {
|
935 |
size = ENV_MONARCH_PAPER_SIZE; |
936 |
} |
937 |
break;
|
938 |
// public final static int PREPARE_PAGE_ID_ENV_N10 = 13;
|
939 |
case (PREPARE_PAGE_ID_ENV_N10):
|
940 |
if (isLand) {
|
941 |
size = new Size(
|
942 |
ENV_N10_PAPER_SIZE.getAncho(), |
943 |
ENV_N10_PAPER_SIZE.getAlto()); |
944 |
} else {
|
945 |
size = ENV_N10_PAPER_SIZE; |
946 |
} |
947 |
break;
|
948 |
// public final static int PREPARE_PAGE_ID_ENV_C5 = 14;
|
949 |
case (PREPARE_PAGE_ID_ENV_C5):
|
950 |
if (isLand) {
|
951 |
size = new Size(
|
952 |
ENV_C5_PAPER_SIZE.getAncho(), |
953 |
ENV_C5_PAPER_SIZE.getAlto()); |
954 |
} else {
|
955 |
size = ENV_C5_PAPER_SIZE; |
956 |
} |
957 |
break;
|
958 |
// public final static int PREPARE_PAGE_ID_ENV_DL = 15;
|
959 |
case (PREPARE_PAGE_ID_ENV_DL):
|
960 |
if (isLand) {
|
961 |
size = new Size(
|
962 |
ENV_DL_PAPER_SIZE.getAncho(), |
963 |
ENV_DL_PAPER_SIZE.getAlto()); |
964 |
} else {
|
965 |
size = ENV_DL_PAPER_SIZE; |
966 |
} |
967 |
break;
|
968 |
// public final static int PREPARE_PAGE_ID_ENV_B5 = 16;
|
969 |
case (PREPARE_PAGE_ID_ENV_B5):
|
970 |
if (isLand) {
|
971 |
size = new Size(
|
972 |
ENV_B5_PAPER_SIZE.getAncho(), |
973 |
ENV_B5_PAPER_SIZE.getAlto()); |
974 |
} else {
|
975 |
size = ENV_B5_PAPER_SIZE; |
976 |
} |
977 |
break;
|
978 |
|
979 |
} |
980 |
|
981 |
m_sizeinUnits = new Size(size.getAlto() / m_TypeUnit,
|
982 |
size.getAncho() / m_TypeUnit); |
983 |
|
984 |
return m_sizeinUnits;
|
985 |
} |
986 |
|
987 |
/**
|
988 |
* Retunrs the type of units is in use.
|
989 |
*
|
990 |
* @return Type of units.
|
991 |
*/
|
992 |
public int getSelTypeUnit() { |
993 |
return m_selTypeUnit;
|
994 |
} |
995 |
|
996 |
/**
|
997 |
* Returns the name of units.
|
998 |
*
|
999 |
* @return String Name of units.
|
1000 |
*/
|
1001 |
public String getNameUnit() { |
1002 |
return m_NameUnit;
|
1003 |
} |
1004 |
|
1005 |
/**
|
1006 |
* Selecting the type of unit that is utilized in the Layout, by default is in centimetres.
|
1007 |
*
|
1008 |
* @param sel Type of unit.
|
1009 |
*/
|
1010 |
public void setUnit(int sel) { |
1011 |
m_selTypeUnit = sel; |
1012 |
m_TypeUnit = CHANGE[sel]; |
1013 |
m_NameUnit = PluginServices.getText(this,MapContext.getDistanceNames()[sel]);
|
1014 |
m_numX = m_numY = new Double(UNIT[sel]); |
1015 |
} |
1016 |
|
1017 |
/**
|
1018 |
* Actualize to date m_sizeinUnits with the height and width of the sheet
|
1019 |
* in the units of mediated selected.
|
1020 |
*
|
1021 |
* @param b True if is horizontal.
|
1022 |
*/
|
1023 |
public void setSizeinUnits(boolean b) { |
1024 |
if (b) {
|
1025 |
m_sizeinUnits = new Size(m_sizePaper.getAlto() / m_TypeUnit,
|
1026 |
m_sizePaper.getAncho() / m_TypeUnit); |
1027 |
} else {
|
1028 |
m_sizeinUnits = new Size(m_sizePaper.getAncho() / m_TypeUnit,
|
1029 |
m_sizePaper.getAlto() / m_TypeUnit); |
1030 |
} |
1031 |
} |
1032 |
|
1033 |
/**
|
1034 |
* Returns a double in the unit of measure selected from the double in centimeters.
|
1035 |
*
|
1036 |
* @param d Distance in centimeters.
|
1037 |
*
|
1038 |
* @return Distance in the unit measure selected.
|
1039 |
*/
|
1040 |
public double toUnits(double d) { |
1041 |
NumberFormat nf = NumberFormat.getInstance(); |
1042 |
nf.setMaximumFractionDigits(2);
|
1043 |
|
1044 |
String s = String.valueOf(nf.format(d)); |
1045 |
s = s.replace(',', '.'); |
1046 |
|
1047 |
return (Double.valueOf(s).doubleValue() / m_TypeUnit); |
1048 |
} |
1049 |
|
1050 |
/**
|
1051 |
* Returns a double in centimeters from the the unit of measure selected.
|
1052 |
*
|
1053 |
* @param d Distance in the unit measure selected.
|
1054 |
*
|
1055 |
* @return Distance in centimeters.
|
1056 |
*/
|
1057 |
public double fromUnits(double d) { |
1058 |
return (d * m_TypeUnit);
|
1059 |
} |
1060 |
|
1061 |
/**
|
1062 |
* Returns one centimeter in pixels on screen in this moment.
|
1063 |
*
|
1064 |
* @param rect Rectangle of sheet.
|
1065 |
*
|
1066 |
* @return Pixels from centimeter.
|
1067 |
*/
|
1068 |
public double getPixXCm(Rectangle2D rect) { |
1069 |
double value = m_sizePaper.getAncho();
|
1070 |
double cm = CHANGE[2]; |
1071 |
double unidades = 0; |
1072 |
unidades = ((rect.getMaxX() - rect.getMinX()) /((value / cm))); |
1073 |
return unidades;
|
1074 |
} |
1075 |
|
1076 |
/**
|
1077 |
* Inserts the number of pixels of one centimeter of X.
|
1078 |
*
|
1079 |
* @param rect Rectangle of sheet.
|
1080 |
*/
|
1081 |
public void setDistanceUnitX(Rectangle2D rect) { |
1082 |
double value = m_sizePaper.getAncho();
|
1083 |
double unidades = ((rect.getMaxX() - rect.getMinX()) / ((value / m_TypeUnit) / getNumUnitsX()));
|
1084 |
m_unitX = unidades; |
1085 |
} |
1086 |
|
1087 |
/**
|
1088 |
* Inserts the number of pixels of one centimeter of Y.
|
1089 |
*
|
1090 |
* @param rect Rectangle of sheet.
|
1091 |
*/
|
1092 |
public void setDistanceUnitY(Rectangle2D rect) { |
1093 |
double value = m_sizePaper.getAncho();
|
1094 |
double unidades = ((rect.getMaxX() - rect.getMinX()) / ((value / m_TypeUnit) / getNumUnitsY()));
|
1095 |
m_unitY = unidades; |
1096 |
} |
1097 |
|
1098 |
/**
|
1099 |
* Obtains the rectangle that represents the sheet with the characteristics
|
1100 |
* that contains attributes
|
1101 |
*
|
1102 |
* @param rect rectangle.
|
1103 |
*
|
1104 |
*/
|
1105 |
public void obtainRect(boolean isPrint, Rectangle2D rect, int w, int h) { |
1106 |
double value1 = 0; |
1107 |
double value2 = 0; |
1108 |
|
1109 |
if (!isPrint) {
|
1110 |
if (isLandSpace()) {
|
1111 |
anchoXalto = m_sizePaper.getAncho() / m_sizePaper.getAlto(); |
1112 |
rect = getRectangleLandscape(rect, w, h); |
1113 |
} else {
|
1114 |
anchoXalto = m_sizePaper.getAlto() / m_sizePaper.getAncho(); |
1115 |
rect = getRectanglePortrait(rect, w, h); |
1116 |
} |
1117 |
} else {
|
1118 |
value1 = m_sizePaper.getAncho(); |
1119 |
value2 = m_sizePaper.getAlto(); |
1120 |
rect.setRect(0, 0, ((value1 / PULGADA) * DPI), |
1121 |
((value2 / PULGADA) * DPI)); |
1122 |
} |
1123 |
|
1124 |
setDistanceUnitX(rect); |
1125 |
setDistanceUnitY(rect); |
1126 |
} |
1127 |
|
1128 |
/**
|
1129 |
* It obtains the rect that is adjusted to the size of the window,
|
1130 |
* to see the full extent of horizontal layout.
|
1131 |
*
|
1132 |
* @param rect Rectangle sheet.
|
1133 |
* @param w Width of Layout.
|
1134 |
* @param h Height of Layout.
|
1135 |
*
|
1136 |
* @return Rectangle modified.
|
1137 |
*/
|
1138 |
public Rectangle2D.Double getRectangleLandscape(Rectangle2D rect, |
1139 |
int w, int h) { |
1140 |
Rectangle2D.Double rectaux = new Rectangle2D.Double(); |
1141 |
int x0 = (int) rect.getMinX(); |
1142 |
int y0 = (int) rect.getMinY(); |
1143 |
int y1;
|
1144 |
int x1;
|
1145 |
y1 = (h - (2 * y0));
|
1146 |
x1 = (int) (y1 * anchoXalto);
|
1147 |
|
1148 |
if (((int) (((h) - (2 * y0)) * anchoXalto)) > ((w) - (2 * x0))) { |
1149 |
x1 = ((w) - (2 * x0));
|
1150 |
y1 = (int) (x1 / anchoXalto);
|
1151 |
} |
1152 |
|
1153 |
rectaux.setRect(x0, y0, x1, y1); |
1154 |
|
1155 |
return rectaux;
|
1156 |
} |
1157 |
|
1158 |
/**
|
1159 |
* Returns the size of sheet in the units of measure selected.
|
1160 |
*
|
1161 |
* @return Size of sheet.
|
1162 |
*/
|
1163 |
public Size getSizeInUnits() {
|
1164 |
return m_sizeinUnits;
|
1165 |
} |
1166 |
|
1167 |
/**
|
1168 |
* It obtains the rect that is adjusted to the size of the window,
|
1169 |
* to see the full extent of vertical layout.
|
1170 |
*
|
1171 |
* @param rect Rectangle sheet.
|
1172 |
* @param w Width of Layout.
|
1173 |
* @param h Height of Layout.
|
1174 |
*
|
1175 |
* @return Rectangle modified.
|
1176 |
*/
|
1177 |
public Rectangle2D.Double getRectanglePortrait(Rectangle2D rect, |
1178 |
int w, int h) { |
1179 |
Rectangle2D.Double rectaux = new Rectangle2D.Double(); |
1180 |
int x0 = (int) rect.getMinX(); |
1181 |
int y0 = (int) rect.getMinY(); |
1182 |
int y1;
|
1183 |
int x1;
|
1184 |
x1 = (w - (2 * x0));
|
1185 |
y1 = (int) (x1 * anchoXalto);
|
1186 |
|
1187 |
if (((int) (((w) - (2 * x0)) * anchoXalto)) > ((h) - (2 * y0))) { |
1188 |
y1 = (h - (2 * y0));
|
1189 |
x1 = (int) (y1 / anchoXalto);
|
1190 |
} |
1191 |
|
1192 |
rectaux.setRect(x0, y0, x1, y1); |
1193 |
|
1194 |
return rectaux;
|
1195 |
} |
1196 |
|
1197 |
/**
|
1198 |
* It obtains the type of format from the size.
|
1199 |
*
|
1200 |
* @param size Size of sheet.
|
1201 |
*
|
1202 |
* @return Type of sheet.
|
1203 |
*/
|
1204 |
private int getTypePaper(Size size) { |
1205 |
|
1206 |
float tol = 0.1f; // 1mm |
1207 |
Size auxSize = null;
|
1208 |
|
1209 |
if (isLandSpace()) {
|
1210 |
auxSize = new Size(size.getAncho() - tol, size.getAlto() - tol);
|
1211 |
} else {
|
1212 |
auxSize = new Size(size.getAlto() - tol, size.getAncho() - tol);
|
1213 |
} |
1214 |
|
1215 |
Size small = getSmallestFor(auxSize.getAncho(), auxSize.getAlto()); |
1216 |
if (small == null) { |
1217 |
return PREPARE_PAGE_ID_A4;
|
1218 |
} else {
|
1219 |
Integer resp = idForSize(small);
|
1220 |
if (resp == null) { |
1221 |
return PREPARE_PAGE_ID_A4;
|
1222 |
} else {
|
1223 |
return resp.intValue();
|
1224 |
} |
1225 |
} |
1226 |
|
1227 |
|
1228 |
// if ((((auxSize.getAncho() * PULGADA) / DPISCREEN) < (tol +
|
1229 |
// METRIC_A4_PAPER_SIZE.getAncho())) &&
|
1230 |
// (((auxSize.getAlto() * PULGADA) / DPISCREEN) < (tol +
|
1231 |
// METRIC_A4_PAPER_SIZE.getAlto()))) {
|
1232 |
// return PREPARE_PAGE_ID_A4;
|
1233 |
// } else if ((((auxSize.getAncho() * PULGADA) / DPISCREEN) < (tol +
|
1234 |
// METRIC_A3_PAPER_SIZE.getAncho())) &&
|
1235 |
// (((auxSize.getAlto() * PULGADA) / DPISCREEN) < (tol +
|
1236 |
// METRIC_A3_PAPER_SIZE.getAlto()))) {
|
1237 |
// return PREPARE_PAGE_ID_A3;
|
1238 |
// } else if ((((auxSize.getAncho() * PULGADA) / DPISCREEN) < (tol +
|
1239 |
// METRIC_A2_PAPER_SIZE.getAncho())) &&
|
1240 |
// (((auxSize.getAlto() * PULGADA) / DPISCREEN) < (tol +
|
1241 |
// METRIC_A2_PAPER_SIZE.getAlto()))) {
|
1242 |
// return PREPARE_PAGE_ID_A2;
|
1243 |
// } else if ((((auxSize.getAncho() * PULGADA) / DPISCREEN) < (tol +
|
1244 |
// METRIC_A1_PAPER_SIZE.getAncho())) &&
|
1245 |
// (((auxSize.getAlto() * PULGADA) / DPISCREEN) < (tol +
|
1246 |
// METRIC_A1_PAPER_SIZE.getAlto()))) {
|
1247 |
// return PREPARE_PAGE_ID_A1;
|
1248 |
// } else if ((((auxSize.getAncho() * PULGADA) / DPISCREEN) < (tol +
|
1249 |
// METRIC_A0_PAPER_SIZE.getAncho())) &&
|
1250 |
// (((auxSize.getAlto() * PULGADA) / DPISCREEN) < (tol +
|
1251 |
// METRIC_A0_PAPER_SIZE.getAlto()))) {
|
1252 |
// return PREPARE_PAGE_ID_A0;
|
1253 |
// }
|
1254 |
|
1255 |
|
1256 |
} |
1257 |
|
1258 |
/**
|
1259 |
* It returns an Object XMLEntity with the information the necessary attributes
|
1260 |
* to be able later to create again the original object.
|
1261 |
*
|
1262 |
* @return XMLEntity.
|
1263 |
*
|
1264 |
*/
|
1265 |
public XMLEntity getXMLEntity() {
|
1266 |
XMLEntity xml = new XMLEntity();
|
1267 |
xml.putProperty("className",this.getClass().getName()); |
1268 |
xml.putProperty("DPI", DPI);
|
1269 |
xml.putProperty("DPISCREEN", DPISCREEN);
|
1270 |
xml.putProperty("m_TypeUnit", m_TypeUnit);
|
1271 |
xml.putProperty("m_numX", m_numX);
|
1272 |
xml.putProperty("m_numY", m_numY);
|
1273 |
xml.putProperty("m_unitX", m_unitX);
|
1274 |
xml.putProperty("m_unitY", m_unitY);
|
1275 |
xml.putProperty("hasmargin", hasmargin);
|
1276 |
xml.putProperty("m_resolutionSel", m_resolutionSel);
|
1277 |
xml.putProperty("m_typeSel", m_typeSel);
|
1278 |
xml.putProperty("m_selTypeUnit", m_selTypeUnit);
|
1279 |
xml.addChild(m_sizePaper.getXMLEntity()); |
1280 |
xml.putProperty("m_area", m_area);
|
1281 |
xml.putProperty("anchoXalto", anchoXalto);
|
1282 |
xml.addChild(m_sizeinUnits.getXMLEntity()); |
1283 |
|
1284 |
// Landscape
|
1285 |
xml.putProperty("m_isLandSel", m_isLandSel);
|
1286 |
|
1287 |
return xml;
|
1288 |
} |
1289 |
|
1290 |
/**
|
1291 |
* It returns an Object of this class from a XMLEntity.
|
1292 |
*
|
1293 |
*
|
1294 |
* @param xml XMLEntity
|
1295 |
*
|
1296 |
* @return Object of Attributes.
|
1297 |
*/
|
1298 |
public static Attributes createAtributes(XMLEntity xml) { |
1299 |
Attributes atri = new Attributes(); |
1300 |
DPI = xml.getIntProperty("DPI");
|
1301 |
if (DPI==300){ |
1302 |
atri.m_resolution=PrintQuality.NORMAL;
|
1303 |
}else if (DPI==600){ |
1304 |
atri.m_resolution=PrintQuality.HIGH;
|
1305 |
}else if (DPI==72){ |
1306 |
atri.m_resolution=PrintQuality.DRAFT;
|
1307 |
} |
1308 |
DPISCREEN = xml.getIntProperty("DPISCREEN");
|
1309 |
atri.m_TypeUnit = xml.getDoubleProperty("m_TypeUnit");
|
1310 |
atri.setNumUnitsX(xml.getDoubleProperty("m_numX"));
|
1311 |
atri.setNumUnitsY(xml.getDoubleProperty("m_numY"));
|
1312 |
atri.m_unitX = xml.getDoubleProperty("m_unitX");
|
1313 |
atri.m_unitY = xml.getDoubleProperty("m_unitY");
|
1314 |
atri.hasmargin = xml.getBooleanProperty("hasmargin");
|
1315 |
atri.m_resolutionSel = xml.getIntProperty("m_resolutionSel");
|
1316 |
atri.m_typeSel = xml.getIntProperty("m_typeSel");
|
1317 |
atri.m_selTypeUnit = xml.getIntProperty("m_selTypeUnit");
|
1318 |
atri.m_sizePaper = Size.createSize(xml.getChild(0));
|
1319 |
|
1320 |
if (atri.hasmargin) {
|
1321 |
atri.m_area = xml.getDoubleArrayProperty("m_area");
|
1322 |
} |
1323 |
|
1324 |
atri.anchoXalto = xml.getDoubleProperty("anchoXalto");
|
1325 |
atri.m_sizeinUnits = Size.createSize(xml.getChild(1));
|
1326 |
atri.m_isLandSel = xml.getBooleanProperty("m_isLandSel");
|
1327 |
atri.setIsLandScape(atri.m_isLandSel); |
1328 |
return atri;
|
1329 |
} |
1330 |
|
1331 |
/**
|
1332 |
* It returns an Object of this class from a XMLEntity.
|
1333 |
*
|
1334 |
*
|
1335 |
* @param xml XMLEntity
|
1336 |
*
|
1337 |
* @return Object of Attributes.
|
1338 |
*/
|
1339 |
public static Attributes createAtributes03(XMLEntity xml) { |
1340 |
Attributes atri = new Attributes(); |
1341 |
DPI = xml.getIntProperty("DPI");
|
1342 |
if (DPI==300){ |
1343 |
atri.m_resolution=PrintQuality.NORMAL;
|
1344 |
}else if (DPI==600){ |
1345 |
atri.m_resolution=PrintQuality.HIGH;
|
1346 |
}else if (DPI==72){ |
1347 |
atri.m_resolution=PrintQuality.DRAFT;
|
1348 |
} |
1349 |
DPISCREEN = xml.getIntProperty("DPISCREEN");
|
1350 |
atri.m_TypeUnit = xml.getDoubleProperty("m_TypeUnit");
|
1351 |
atri.setNumUnitsX(xml.getDoubleProperty("m_numX"));
|
1352 |
atri.setNumUnitsY(xml.getDoubleProperty("m_numY"));
|
1353 |
atri.m_unitX = xml.getDoubleProperty("m_unitX");
|
1354 |
atri.m_unitY = xml.getDoubleProperty("m_unitY");
|
1355 |
atri.hasmargin = xml.getBooleanProperty("hasmargin");
|
1356 |
atri.m_resolutionSel = xml.getIntProperty("m_resolutionSel");
|
1357 |
atri.m_typeSel = xml.getIntProperty("m_typeSel");
|
1358 |
atri.m_selTypeUnit = xml.getIntProperty("m_selTypeUnit");
|
1359 |
atri.m_sizePaper = Size.createSize(xml.getChild(0));
|
1360 |
|
1361 |
if (atri.hasmargin) {
|
1362 |
atri.m_area = xml.getDoubleArrayProperty("m_area");
|
1363 |
} |
1364 |
|
1365 |
atri.anchoXalto = xml.getDoubleProperty("anchoXalto");
|
1366 |
atri.m_sizeinUnits = Size.createSize(xml.getChild(1));
|
1367 |
atri.m_isLandSel = xml.getBooleanProperty("m_isLandSel");
|
1368 |
atri.setIsLandScape(atri.m_isLandSel); |
1369 |
return atri;
|
1370 |
} |
1371 |
/**
|
1372 |
* Inserts the default number of pixels that represents a unit of grid.
|
1373 |
*
|
1374 |
* @param hGap Horizontal distance.
|
1375 |
* @param vGap Vertical distance.
|
1376 |
*/
|
1377 |
public static void setDefaultGridGap(double hGap, double vGap) { |
1378 |
defaultGridGap = new Point2D.Double(hGap, vGap); |
1379 |
} |
1380 |
/**
|
1381 |
* Returns the default number of pixels that represents a unit of grid.
|
1382 |
*
|
1383 |
* @return Number of pixels of grid.
|
1384 |
*/
|
1385 |
public static Point2D getDefaultGridGap() { |
1386 |
if (defaultGridGap == null){ |
1387 |
XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
1388 |
double hGap = xml.contains("DefaultLayoutGridHorizontalGapX") ? xml.getDoubleProperty("DefaultLayoutGridHorizontalGapX"): 0.25; |
1389 |
double vGap = xml.contains("DefaultLayoutGridHorizontalGapY") ? xml.getDoubleProperty("DefaultLayoutGridHorizontalGapY"): 0.25; |
1390 |
defaultGridGap = new Point2D.Double(hGap, vGap); |
1391 |
} |
1392 |
return defaultGridGap;
|
1393 |
} |
1394 |
|
1395 |
/**
|
1396 |
* Devuelve el n?mero de pixels de longitud en el eje Y que representa a la unidad del mapa que est?
|
1397 |
* seleccionada, suelen ser cent?metros.
|
1398 |
*
|
1399 |
* @return n?mero de pixels que representa la unidad seleccionada.
|
1400 |
*/
|
1401 |
public double getUnitInPixelsY() { |
1402 |
return m_unitY;
|
1403 |
} |
1404 |
|
1405 |
/**
|
1406 |
* Devuelve el n?mero de pixels de longitud en el eje X que representa a la unidad del mapa que est?
|
1407 |
* seleccionada, suelen ser cent?metros.
|
1408 |
*
|
1409 |
* @return n?mero de pixels que representa la unidad seleccionada.
|
1410 |
*/
|
1411 |
public double getUnitInPixelsX() { |
1412 |
return m_unitX;
|
1413 |
} |
1414 |
|
1415 |
|
1416 |
public static Size getSmallestFor(double ancho, double alto) { |
1417 |
|
1418 |
ArrayList cand = new ArrayList(); |
1419 |
Iterator kiter = PAPER_SIZES_LIST.keySet().iterator();
|
1420 |
Size aux = null;
|
1421 |
Integer kitem = null; |
1422 |
while (kiter.hasNext()) {
|
1423 |
kitem = (Integer) kiter.next();
|
1424 |
aux = (Size) PAPER_SIZES_LIST.get(kitem); |
1425 |
if (fitsIn(ancho, alto, aux) && isRealFormat(kitem)) {
|
1426 |
cand.add(aux); |
1427 |
} |
1428 |
} |
1429 |
return smallest(cand);
|
1430 |
} |
1431 |
|
1432 |
private static boolean isRealFormat(Integer k) { |
1433 |
return
|
1434 |
(k.intValue() != PREPARE_PAGE_ID_CUSTOM) |
1435 |
&& (k.intValue() != PREPARE_PAGE_ID_PRINT); |
1436 |
} |
1437 |
|
1438 |
public static HashMap PAPER_SIZES_LIST = new HashMap(); |
1439 |
static {
|
1440 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_CUSTOM), CUSTOM_PAPER_SIZE); |
1441 |
// as printer
|
1442 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_PRINT), CUSTOM_PAPER_SIZE); |
1443 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_A0), METRIC_A0_PAPER_SIZE); |
1444 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_A1), METRIC_A1_PAPER_SIZE); |
1445 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_A2), METRIC_A2_PAPER_SIZE); |
1446 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_A3), METRIC_A3_PAPER_SIZE); |
1447 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_A4), METRIC_A4_PAPER_SIZE); |
1448 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_NA_LETTER), NA_LETTER_PAPER_SIZE); |
1449 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_NA_LEGAL), NA_LEGAL_PAPER_SIZE); |
1450 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_TABLOID), NA_TABLOID_PAPER_SIZE); |
1451 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_EXEC_MONARCH), EXEC_MONARCH_PAPER_SIZE); |
1452 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_B5_JIS), B5_JIS_PAPER_SIZE); |
1453 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_MONARCH), ENV_MONARCH_PAPER_SIZE); |
1454 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_N10), ENV_N10_PAPER_SIZE); |
1455 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_C5), ENV_C5_PAPER_SIZE); |
1456 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_DL), ENV_DL_PAPER_SIZE); |
1457 |
PAPER_SIZES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_B5), ENV_B5_PAPER_SIZE); |
1458 |
} |
1459 |
|
1460 |
public static HashMap PAPER_NAMES_LIST = new HashMap(); |
1461 |
static {
|
1462 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_CUSTOM), new UserMediaSizeName( |
1463 |
"Personalizado"));
|
1464 |
// as printer
|
1465 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_PRINT), new UserMediaSizeName( |
1466 |
"Igual_que_la_impresora"));
|
1467 |
|
1468 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_A0), MediaSizeName.ISO_A0); |
1469 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_A1), MediaSizeName.ISO_A1); |
1470 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_A2), MediaSizeName.ISO_A2); |
1471 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_A3), MediaSizeName.ISO_A3); |
1472 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_A4), MediaSizeName.ISO_A4); |
1473 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_NA_LETTER), MediaSizeName.NA_LETTER); |
1474 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_NA_LEGAL), MediaSizeName.NA_LEGAL); |
1475 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_TABLOID), MediaSizeName.TABLOID); |
1476 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_EXEC_MONARCH), MediaSizeName.EXECUTIVE); |
1477 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_B5_JIS), MediaSizeName.JIS_B5); |
1478 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_MONARCH), USR_MEDIA_ENV_MONARCH); |
1479 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_N10), USR_MEDIA_ENV_N10); |
1480 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_C5), USR_MEDIA_ENV_C5); |
1481 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_DL), USR_MEDIA_ENV_DL); |
1482 |
PAPER_NAMES_LIST.put(new Integer(PREPARE_PAGE_ID_ENV_B5), USR_MEDIA_ENV_B5); |
1483 |
} |
1484 |
|
1485 |
|
1486 |
public static Integer idForSize(Size sz) { |
1487 |
|
1488 |
Iterator kiter = PAPER_SIZES_LIST.keySet().iterator();
|
1489 |
Size aux = null;
|
1490 |
Integer kitem = null; |
1491 |
while (kiter.hasNext()) {
|
1492 |
kitem = (Integer) kiter.next();
|
1493 |
aux = (Size) PAPER_SIZES_LIST.get(kitem); |
1494 |
if (aux == sz) {
|
1495 |
return kitem;
|
1496 |
} |
1497 |
} |
1498 |
logger.error("Did not find paper size [h,w] : [" + sz.getAlto() + " , " + sz.getAncho() + "] (returned id a4)"); |
1499 |
return PREPARE_PAGE_ID_A4;
|
1500 |
} |
1501 |
|
1502 |
public static Size sizeForId(int id) { |
1503 |
|
1504 |
Iterator kiter = PAPER_SIZES_LIST.keySet().iterator();
|
1505 |
Integer kitem = null; |
1506 |
while (kiter.hasNext()) {
|
1507 |
kitem = (Integer) kiter.next();
|
1508 |
if (kitem.intValue() == id) {
|
1509 |
return (Size) PAPER_SIZES_LIST.get(kitem);
|
1510 |
} |
1511 |
} |
1512 |
|
1513 |
logger.error("Did not find paper type id: " + id + " (returned a4)"); |
1514 |
return METRIC_A4_PAPER_SIZE;
|
1515 |
} |
1516 |
|
1517 |
|
1518 |
public static Size smallest(ArrayList sszs) { |
1519 |
|
1520 |
int len = sszs.size();
|
1521 |
|
1522 |
if (len == 0) { |
1523 |
return null; |
1524 |
} |
1525 |
|
1526 |
if (len == 1) { |
1527 |
return (Size) sszs.get(0); |
1528 |
} |
1529 |
|
1530 |
int resp = 0; |
1531 |
Size aux = (Size) sszs.get(0);
|
1532 |
double min = aux.getAlto() * aux.getAncho();
|
1533 |
double auxmin = 0; |
1534 |
for (int i=1; i<len; i++) { |
1535 |
aux = (Size) sszs.get(i); |
1536 |
auxmin = aux.getAlto() * aux.getAncho(); |
1537 |
if (auxmin < min) {
|
1538 |
min = auxmin; |
1539 |
resp = i; |
1540 |
} |
1541 |
} |
1542 |
return (Size) sszs.get(resp);
|
1543 |
} |
1544 |
|
1545 |
public static boolean fitsIn(double anchoin, double altoin, Size outer) { |
1546 |
return (anchoin <= outer.getAncho()) && (altoin <= outer.getAlto());
|
1547 |
} |
1548 |
|
1549 |
public static MediaSizeName getMediaSizeNameForId(int type) { |
1550 |
|
1551 |
Iterator iter = PAPER_NAMES_LIST.keySet().iterator();
|
1552 |
Integer kitem = null; |
1553 |
while (iter.hasNext()) {
|
1554 |
|
1555 |
kitem = (Integer) iter.next();
|
1556 |
if (kitem.intValue() == type) {
|
1557 |
return (MediaSizeName) PAPER_NAMES_LIST.get(kitem); |
1558 |
} |
1559 |
} |
1560 |
logger.error("Did not find paper type id: " + type + " (returned a4)"); |
1561 |
return MediaSizeName.ISO_A4; |
1562 |
} |
1563 |
|
1564 |
public static int getIdForMediaSizeName(MediaSizeName msn) { |
1565 |
|
1566 |
Iterator iter = PAPER_NAMES_LIST.keySet().iterator();
|
1567 |
Integer kitem = null; |
1568 |
MediaSizeName item_msn = null; |
1569 |
while (iter.hasNext()) {
|
1570 |
kitem = (Integer) iter.next();
|
1571 |
item_msn = (MediaSizeName) PAPER_NAMES_LIST.get(kitem);
|
1572 |
if (item_msn == msn) {
|
1573 |
return kitem.intValue();
|
1574 |
} |
1575 |
} |
1576 |
logger.error("Did not find msn: " + msn.toString() + " (returned id for a4)"); |
1577 |
return PREPARE_PAGE_ID_A4;
|
1578 |
} |
1579 |
|
1580 |
public Size getPaperSize() {
|
1581 |
return m_sizePaper;
|
1582 |
} |
1583 |
|
1584 |
} |
1585 |
|
1586 |
// [eiel-add-print-formats]
|