home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 2.9 KB | 101 lines |
- import dnx.lr.*;
- import dnx.lr.app.*;
- import java.awt.*;
- import java.io.IOException;
- import java.net.URL;
-
-
- public class VRMLBrowser extends Frame {
-
- protected ApplicationDocument document;
- protected View3D view;
-
-
- public VRMLBrowser(String title) {
- super(title);
- setLayout(new BorderLayout(5, 5));
- Panel p = new Panel();
- p.setLayout(new BorderLayout());
- p.add("West", new Label("Location: ", Label.LEFT));
- p.add("Center", new TextField());
- add("North", p);
- }
-
- public boolean action(Event event, Object arg) {
- if (event.target instanceof TextField) {
- System.err.println("Loading new URL: " + arg);
- try {
- readScene((String) arg);
- }
- catch (VRMLSyntaxException e) {
- System.out.println ("Invalid VRML Syntax in file: " + arg);
- return false;
- }
- catch (IOException e) {
- System.out.println ("Unable to load: " + e);
- return false;
- }
- return true;
- }
- return false;
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == Event.WINDOW_DESTROY) {
- System.exit(0);
- }
- return super.handleEvent(event);
- }
-
- public Insets insets() {
- return new Insets(super.insets().top +5, super.insets().left +5,
- super.insets().bottom+5, super.insets().right+5);
- }
-
- public void readScene(String arg) throws VRMLSyntaxException,
- IOException {
- URL url = new URL(ApplicationDocument.getCurrentDirectory(), arg);
- Scene scene = new Scene(new ReadAction(url));
- ApplicationDocument doc = new ApplicationDocument(scene);
- if (view == null) {
- document = doc;
- view = new BrowserView3D(document);
- }
- else {
- document.stop();
- document = doc;
- view = new BrowserView3D(document);
- add("Center", view.getComponent());
- validate();
- document.start();
- }
- }
-
- public static void main(String[] args) {
- VRMLBrowser frame = new VRMLBrowser("Minimal VRML Browser");
-
- if (args.length != 1) {
- System.err.println("Usage: java VRMLBrowser <url>");
- System.exit(0);
- }
-
- try {
- frame.readScene(args[0]);
- }
- catch (VRMLSyntaxException e) {
- System.out.println ("Invalid VRML Syntax in file: " + args[0]);
- return;
- }
- catch (IOException e) {
- System.out.println ("Unable to load: " + e);
- return;
- }
-
- frame.add("Center", frame.view.getComponent());
- frame.resize(440, 340);
- frame.show();
-
- frame.document.start();
- }
- }
-