1
6 import java.awt.geom.*;
7 import java.awt.*;
8 import java.awt.Graphics2D.*;
9 import java.awt.print.*;
10 import java.util.*;
11 import java.io.*;
12
13 public class Page extends Box {
14
15 private static final long serialVersionUID = Version.getSUID();
16
17 public static double PRINTWIDTH = 1;
18
19
20 public static int WIDTHMODE = 0;
21 public static int HEIGHTMODE = 1;
22 public static int PIXELMODE = 2;
23 public static int SCALEMODE = 3;
24
25
26
27
28
29 static Page defpage = null;
30
31 boolean printer;
32 boolean index;
33 boolean image;
34 double resolution;
35 double presolution;
36 double aspect = -1;
37 int ressetting;
38 int pressetting;
39 Unit printerunit;
40 Unit imageunit;
41 Unit mapunit;
42 File file;
43
44 Stacking stack = null;
45 boolean usestack = false;
46
47 public Comp comp = null;
48
49 public Page() {
50 super(new Point2D.Double(0,0),null,null);
51
52
53 printer = false;
54 index = false;
55 image = true;
56 resolution = 1.0;
57 presolution = 1.0;
58 ressetting = Page.SCALEMODE;
59 pressetting = Page.SCALEMODE;
60 file = new File("");
61 imageunit = Unit.inch;
62 printerunit = Unit.inch;
63 mapunit = Unit.foot;
64 }
65
66 public Page(Point2D where,View view,Object arg) {
67 super(where,view,null);
68
69
70
71 copy(defpage);
72 reshape();
73 comp = (Comp)arg;
74 }
75
76 public void copy(Page that) {
77 printerunit = that.printerunit;
78 imageunit = that.imageunit;
79 mapunit = that.mapunit;
80 printer = that.printer;
81 index=that.index;
82 image=that.image;
83 resolution = that.resolution;
84 presolution = that.presolution;
85 ressetting=that.ressetting;
86 pressetting=that.pressetting;
87 file=that.file;
88
89 super.copy(that);
90 }
91
92
101
102
120
121 public void print(View view,PageFormat format) {
122 view.trans.translate(format.getImageableX(),
123 -format.getImageableY());
124 view.trans.scale(format.getImageableWidth()/box.getWidth(),
125 format.getImageableWidth()/box.getWidth());
126 view.trans.translate(-box.getX(),box.getY());
127 System.out.println("printing "+this);
128 try {
129 view.trans.concatenate(anchorpoint.position.createInverse());
130 } catch (NoninvertibleTransformException e) {ErrorLog.exception(e);}
131
132
133 view.scale=format.getImageableWidth()/getPosScale(mapunit);
134 view.mapscale = new MapScale(view.scale,
135 Unit.pixel,
136 view.mapunit,
137 Print.imagescale);
138
139
140 view.angle = -anchorpoint.position.angle;
141 view.printing = !index;
142
143 if (comp.showall) view.visible = Layer.all;
144 else view.visible = comp.visible;
145
146 if (stack!=null && usestack)
147 view.stacking = stack;
148 else
149 view.stacking = comp.stack;
150
151
152 comp.paint(view);
153
154 comp.getSurvey().paint(view);
155 }
156
157 public void print(View view,PageFormat format,int lines) {
158 view.trans.translate(0,lines);
159 print(view,format);
160 }
161
162 public PageFormat getFormat(Unit globalmapunit) {
163 PageFormat form = new PageFormat();
164 Paper paper = new Paper();
165 Dimension size = getSize(globalmapunit);
166 paper.setSize(size.getWidth(),size.getHeight());
167 paper.setImageableArea(0,0,size.getWidth(),size.getHeight());
168 form.setPaper(paper);
169 return(form);
170 }
171
172
173
174
175
176
177 public Dimension getSize(Unit globalmapunit){
178
179 return(getSize(ressetting,
180 resolution,
181 globalmapunit,
182 Unit.pixel.toUnit(imageunit,Print.imagescale)));
183 }
184
185 public Dimension getPSSize(Unit globalmapunit){
186
187 return(getSize(ressetting,
188 resolution,
189 globalmapunit,
190 Unit.inch.toUnit(imageunit,Print.imagescale)));
191 }
192
193 public Dimension getPrintSize(Unit globalmapunit){
194 return(getSize(pressetting,presolution,globalmapunit,Unit.inch.toUnit(printerunit)));
195 }
196
197 public Dimension getSize(int set,double res,Unit globalmapunit,double unit) {
198 if (set==WIDTHMODE) return(new Dimension((int)(res*unit),(int)(res*unit*subaspect)));
199 if (set==HEIGHTMODE) return(new Dimension((int)(res*unit/subaspect),(int)(res*unit)));
200
201 double scale = 1;
202
203 if (set==PIXELMODE)
204 scale = getPosScale(globalmapunit)*res/unit;
205
206 if (set==SCALEMODE)
207 scale = getPosScale(globalmapunit)/res;
208
209
210
211 return(new Dimension((int)(scale*unit),(int)(scale*unit*subaspect)));
212 }
213
214 public double getPosScale(Unit globalmapunit) {
215 return(box.getWidth()*mapunit.toUnit(globalmapunit)*
216 Math.sqrt(anchorpoint.position.getScaleX()*anchorpoint.position.getScaleY() -
217 anchorpoint.position.getShearX()*anchorpoint.position.getShearY()));
218 }
219
220 public File getFile() {
221 File res = file;
222 if (res==null) res = PrefPage.pickFile();
223 if (res==null) res = new File("");
224 if (!res.getName().toLowerCase().endsWith(".png"))
225 res = new File(res.toString().concat(".png"));
226 return(res);
227 }
228
229 public void paint(View view) {
230 if (!view.visible.isMember(this)) return;
231 if (!view.printing) super.paint(view);
232 }
233
234 public int getLevel() {return(super.getLevel()+2);}
235
236 transient PrefPage prefs = null;
237 transient javax.swing.JCheckBox usestackbox = null;
238
239 public void getPropertyEdit(Object[] edits,int slot,Set sub, Symbol parent) {
240 prefs = new PrefPage(this);
241 edits[slot] = prefs.getPane(null);
242 ((Component)edits[slot]).setName("Page");
243
244 Container sbox = new javax.swing.Box(javax.swing.BoxLayout.Y_AXIS);
245
246 usestackbox = new javax.swing.JCheckBox("Overide default stacking",usestack);
247 sbox.add(usestackbox);
248
249 if (stack==null) stack = new Stacking();
250 Container res = stack.getPane(comp);
251 sbox.add(res);
252
253 edits[slot-1] = sbox;
254 sbox.setName("Stacking");
255
256 super.getPropertyEdit(edits,slot-2,sub,parent);
257 }
258
259 public void acceptPropertyEdit() {
260 super.acceptPropertyEdit();
261 prefs.save();
262
263 usestack = usestackbox.isSelected();
264 usestackbox = null;
265
266 stack.save();
267 stack.clear();
268
269 prefs = null;
270 }
271
272 public void abandonPropertyEdit() {
273 prefs = null;
274 usestackbox = null;
275
276 stack.clear();
277 super.abandonPropertyEdit();
278 }
279 }
280
281