1    /*
2    Copyright 2000 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    import java.awt.geom.*;
7    import java.awt.*;
8    import java.io.*;
9    import java.util.*;
10   import javax.swing.*;
11   
12   public class View implements Serializable,Cloneable{
13   
14     private static final long serialVersionUID = Version.getSUID();
15   
16     public transient Graphics2D draw;
17   
18     public transient java.awt.image.ImageObserver observer;
19   
20     public AffineTransform trans = new AffineTransform(1,0,0,-1,0,0);
21     public double scale=1.0;
22     public double angle=0.0;
23   
24     public Unit mapunit = Carto.defmapunit;
25     public MapScale mapscale = new MapScale(1,Unit.pixel,Unit.pixel,-1);
26   
27     public boolean showalign = false;
28   
29   //  public boolean showstations = true;
30   //  public boolean showlabels = true;
31   //  public boolean showshots = true;
32   //  public boolean showsegs = true;
33   
34   //  public boolean showselection = true;
35   
36     public boolean printing = false;
37   
38     public Stacking stacking = null;
39   
40     public JComponent parent = null;
41     public Comp composite = null;
42   
43     public HashSet offsets = new HashSet();
44   
45     int mod = 0;
46   
47     public Stack stack = new Stack();
48     private int last = 0;
49   
50     public Layer visible = Layer.all;
51     public boolean showall = false;
52   
53     public static boolean waitdefault = false;
54     public boolean wait = waitdefault;
55   
56   //  public Map passpriority = null;
57   //  public Set dontShowIn = null;
58   //  public Set dontShowOut = null;
59   
60   //  public double calib = 1;
61     Rectangle getClipBounds() {
62       try {return(draw.getClipBounds());}
63       catch (RuntimeException ex) {
64         if (clip ==null) return(null);
65         else return((Rectangle)clip.getBounds2D());
66       }
67     }
68   
69     Shape clip = null;
70   //  Rectangle2D cliprect = null;
71   
72     Shape getClip() {
73       try {return(draw.getClip());}
74       catch (RuntimeException ex) {return(clip);}
75     }
76   
77   /*  Shape setClip(Shape newclip) {
78       Shape old = getClip();
79       if (old!=null)
80         clip = old.getBounds().
81       clip = newclip;
82       draw.setClip(newclip);
83     }
84   */
85     void clip(Shape newclip) {
86       clip = newclip;
87       draw.clip(newclip);
88     }
89   
90     void setClip(Shape newclip) {
91       clip = newclip;
92       draw.setClip(newclip);
93     }
94   
95     public View() {
96     }
97   
98     public View(JComponent parent) {
99       this.parent = parent;
100    }
101  
102    public Object clone() {
103      View res = new View();
104      res.draw = (Graphics2D)draw.create();
105      res.observer = observer;
106      res.trans = trans;
107      res.scale = scale;
108      res.angle = angle;
109      res.mapunit = mapunit;
110      res.showalign = showalign;
111      res.printing = printing;
112      res.stacking = stacking;
113      res.parent = parent;
114      res.composite = composite;
115      res.offsets = offsets;
116      res.mod = mod;
117      res.stack = stack;
118      res.last = last;
119      res.visible = visible;
120      res.showall = showall;
121      res.wait = wait;
122      if (clip!=null) res.clip = new Area(clip);
123      else res.clip = null;
124  
125      return(res);
126    }
127  
128    public void intersectClip(Area inarea) {
129      clip(inarea);
130    }
131  
132    public void subtractClip(Area outarea) {
133      Area a = new Area(getClip());
134      a.subtract(outarea);
135      clip(a);
136    }
137  
138    public int push() {
139      stack.push(new Integer(last));
140      last = stack.size();
141      return(last);
142    }
143  
144    public int push(ViewOperator op) {
145      stack.push(new Integer(last));
146      last = stack.size();
147      if (op!=null) op.apply(this);
148      return(last);
149    }
150  
151    public int pop() {
152      return(pop(last));
153    }
154  
155    public int pop(int lev) {
156      while (stack.size()>lev) {
157        Object op = stack.pop();
158        if (op instanceof ViewOperator)
159          ((ViewOperator)op).strip(this);
160      }
161      last = ((Integer)stack.pop()).intValue();
162      return(last);
163    }
164  
165    public void setScale(double scale,double x,double y) {
166      trans.translate((1.0-scale/this.scale)*x,(1.0-scale/this.scale)*y);
167      trans.scale(scale/this.scale,scale/this.scale);
168      this.scale = scale;
169    }
170  
171    public void setRotation(double angle,double x, double y) {
172  //    if (mode==ABSOLUTE) trans.rotate(-angle+this.angle,x,y);
173  //    else 
174      trans.rotate(angle-this.angle,x,y);
175      this.angle = angle;
176    }
177  
178  }
179