home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.5 KB | 96 lines |
- // DrawingComponent.java
- // An AWT component for viewing a structured drawing, loaded via JFS
- import java.awt.*;
- import java.io.*;
- import JFScomponent;
- import JFSclient;
- import FileReq;
- import DrawingPanel;
- import Drawing;
-
- public class DrawingComponent extends JFScomponent
- {
- DrawingCanvas canv;
- Drawing dr;
- Button loadb;
- Checkbox zoom1, zoom2, zoom3, zoom4;
- BorderPanel bot;
- FileReq loadreq;
-
- DrawingComponent()
- {
- // create user interface
- setLayout(new BorderLayout());
- Panel top = new Panel();
- top.setLayout(new BorderLayout());
- Panel left = new Panel();
- left.setLayout(new FlowLayout());
- left.add(loadb = new Button("Load"));
- top.add("West",left);
-
- Panel right = new Panel();
- right.setLayout(new FlowLayout(FlowLayout.LEFT));
- right.add(new Label("Zoom"));
- CheckboxGroup zoomg = new CheckboxGroup();
- right.add(zoom1 = new Checkbox("x 1/2", zoomg, false));
- right.add(zoom2 = new Checkbox("x 1", zoomg, true));
- right.add(zoom3 = new Checkbox("x 2", zoomg, false));
- right.add(zoom4 = new Checkbox("x 4", zoomg, false));
- top.add("East",right);
- add("North",top);
-
- // create space for the drawing
- bot = new BorderPanel(new Color(50,50,50),
- new Color(220,220,220));
- bot.setLayout(new BorderLayout());
- bot.add("Center", canv = new DrawingCanvas(true));
- add("Center",bot);
- }
-
- public boolean action(Event evt, Object obj)
- {
- if (evt.target == zoom1) canv.setZoom(0.5);
- else if (evt.target == zoom2) canv.setZoom(1.0);
- else if (evt.target == zoom3) canv.setZoom(2.0);
- else if (evt.target == zoom4) canv.setZoom(4.0);
- else if (evt.target == loadb && loadreq == null) {
- // Open load requestor
- loadreq = new FileReq(client, this, "Load", "image/x-drawing",
- false, null);
- }
- else if (evt.target == loadreq) {
- // load requestor submitted / closed
- if (((String)evt.arg).equals("Load")) {
- try load(loadreq.getfile(), loadreq.getversion());
- catch(RequestException e)
- new ErrorWindow("Could not open "+
- loadreq.getfile()+" : "+
- e.getMessage());
- }
- loadreq = null;
- }
- return true;
- }
-
- // load
- // Load the named file and version. Create a new DrawingPanel to
- // display the drawing in.
- void load(String file, int ver) throws RequestException
- {
- byte fd[] = client.get(file, ver);
- ByteArrayInputStream buf = new ByteArrayInputStream(fd);
- try dr = new Drawing(buf);
- catch(IOException e)
- throw new RequestException("Drawing format error : "+
- e.getMessage());
- canv.setdrawing(dr);
- client.setcurrent(file, client.statfile(file).type);
- }
-
- Dimension wantedsize()
- {
- return new Dimension(400,400);
- }
- }
-
-