File: PsPages.java

package info (click to toggle)
pstoedit 3.31-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,340 kB
  • ctags: 1,963
  • sloc: cpp: 20,167; perl: 3,182; sh: 2,466; java: 860; ansic: 540; makefile: 463
file content (163 lines) | stat: -rwxr-xr-x 5,514 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//
//   PsPages.java : This file is part of pstoedit.
//   Java classes needed to run the java code generated by pstoedit -f java
//   
//  
//   Copyright (C) 1998 - 1999 Wolfgang Glunz, wglunz@geocities.com
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//

import java.awt.*;
import java.util.*;

// the base class for the drawing objects
class PSDrawingObject {
        public PSDrawingObject(Color cp) { c = cp;}
        public void show(Graphics g ) { g.setColor(c);}
        Color c;
}

class FontDesc {
        FontDesc(String n, int s) { name = n; style = s;}
        public String name;
        public int    style;
};

class PSTextObject extends PSDrawingObject {
static FontDesc[] JavaFonts = {
        new FontDesc("Courier",Font.PLAIN),
        new FontDesc("Courier",Font.BOLD),
        new FontDesc("Courier",Font.ITALIC),
        new FontDesc("Courier",Font.BOLD + Font.ITALIC),
        new FontDesc("Helvetica",Font.PLAIN),
        new FontDesc("Helvetica",Font.BOLD),
        new FontDesc("Helvetica",Font.ITALIC),
        new FontDesc("Helvetica",Font.BOLD + Font.ITALIC),
        new FontDesc("TimesRoman",Font.PLAIN),
        new FontDesc("TimesRoman",Font.BOLD),
        new FontDesc("TimesRoman",Font.ITALIC),
        new FontDesc("TimesRoman",Font.BOLD + Font.ITALIC),
        new FontDesc("ZapfDingbats",Font.PLAIN),
        };

        PSTextObject(float r, float g, float b, 
                        String s, int x, int y, 
                        int fontNum, int fsize)
        {
                super(new Color(r,g,b));
                s_=s;
                x_=x;
                y_=y;
                f_=new Font(JavaFonts[fontNum].name, JavaFonts[fontNum].style, fsize);
        }
        PSTextObject(float r, float g, float b, 
                        String s, int x, int y, 
                        String fname, int fstyle, int fsize)
        {
                super(new Color(r,g,b));
                s_=s;
                x_=x;
                y_=y;
                f_=new Font(fname, fstyle, fsize);
        }
        public void show(Graphics g ) {
                super.show(g);
                g.setFont(f_);
                g.drawString(s_,x_,y_);
        }
        Font f_;
        int x_;
        int y_;
        String s_;
}

class PSLinesObject extends PSDrawingObject {
        PSLinesObject(float r, float g, float b) 
        {
                super(new Color(r,g,b));
                points = new Vector();
        }
        public void show(Graphics g ) {
                super.show(g);
                Point lastPoint = null;
                for (Enumeration e = points.elements() ; e.hasMoreElements() ;) {
                                Point currentPoint = (Point)(e.nextElement());
                                if (lastPoint != null) {
                                        g.drawLine( lastPoint.x,lastPoint.y, currentPoint.x,currentPoint.y);
                                }
                                lastPoint = currentPoint;
                } 
        }
        public void addPoint(int x, int y) {
                points.addElement(new Point(x,y));
        }
        Vector points;
}

class PSPolygonObject extends PSDrawingObject {
        public PSPolygonObject(float r, float g, float b) 
        {
                super(new Color(r,g,b));
                p = new Polygon();
        }
        public PSPolygonObject(int [] points,float r, float g, float b) 
        {
                super(new Color(r,g,b));
                p = new Polygon();
        }
        public void show(Graphics g ) {
                super.show(g);
                g.fillPolygon(p);
        }
        public void addPoint(int x, int y) {
                p.addPoint(x,y);
        }
        public Polygon p;
}

// describes a single page
class PageDescription 
{
        public PageDescription() {
                theObjects = new Vector();
        }
        public void showpage(Rectangle r, Graphics g )
        {
                for (Enumeration e = theObjects.elements() ; e.hasMoreElements() ;) {
                        PSDrawingObject current = (PSDrawingObject)(e.nextElement());
                        current.show(g);
                } 
        }
        public Vector theObjects;
}

// describes the set of all pages
public abstract class PsPages 
{

    public void showpage( Rectangle r, int pageNumber, Graphics g ) { 
        System.out.println("showing page #" + pageNumber);
        System.out.println(r);
        g.clearRect(r.x,r.y,r.width,r.height);
        pages[pageNumber-1].showpage(r,g);
    } 

    public abstract int numberOfPages();

    protected PageDescription [] pages;
}