home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / ddetour.bin / AmazingTour.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-19  |  9.6 KB  |  304 lines

  1. import java.awt.Button;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.FileDialog;
  6. import java.awt.Font;
  7. import java.awt.Frame;
  8. import java.awt.Label;
  9. import java.awt.LayoutManager;
  10. import java.awt.Menu;
  11. import java.awt.MenuBar;
  12. import java.awt.MenuItem;
  13. import java.awt.Point;
  14. import java.awt.Rectangle;
  15. import java.awt.Window;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.WindowEvent;
  18. import java.beans.PropertyVetoException;
  19. import java.io.DataInputStream;
  20. import java.io.FileInputStream;
  21. import java.io.FileNotFoundException;
  22. import java.io.FilterInputStream;
  23. import java.io.IOException;
  24. import java.net.MalformedURLException;
  25. import java.net.URL;
  26. import symantec.itools.awt.WrappingLabel;
  27. import symantec.itools.multimedia.ImageViewer;
  28. import symantec.itools.multimedia.SlideShow;
  29. import symantec.itools.net.RelativeURL;
  30.  
  31. public class AmazingTour extends Frame {
  32.    int dayCount;
  33.    String fileName;
  34.    Rectangle slideShowBounds;
  35.    boolean fComponentsAdjusted;
  36.    FileDialog openFileDialog1;
  37.    WrappingLabel wrappingLabelStart;
  38.    WrappingLabel wrappingLabelTop;
  39.    WrappingLabel wrappingLabelPeople;
  40.    ImageViewer imageViewerLogo;
  41.    SlideShow slideShowItinerary;
  42.    Label labelDay;
  43.    Button buttonNext;
  44.    Button buttonPrevious;
  45.    WrappingLabel wrappingLabelDesc;
  46.    AmazingTour$SymAction glAction;
  47.    MenuBar mainMenuBar;
  48.    Menu menu1;
  49.    MenuItem miOpen;
  50.    MenuItem miExit;
  51.    Menu menu3;
  52.    MenuItem miAbout;
  53.  
  54.    void miAbout_Action(ActionEvent event) {
  55.       (new AboutDialog(this, true)).show();
  56.    }
  57.  
  58.    void miExit_Action(ActionEvent event) {
  59.       (new QuitDialog(this, true)).show();
  60.    }
  61.  
  62.    void miOpen_Action(ActionEvent event) {
  63.       this.openFileDialog1.show();
  64.       String tempFileName = this.openFileDialog1.getDirectory() + this.openFileDialog1.getFile();
  65.       if ((this.fileName != null || tempFileName.endsWith(".dat")) && tempFileName.endsWith(".dat")) {
  66.          if (this.fileName == null) {
  67.             this.wrappingLabelStart.hide();
  68.          }
  69.  
  70.          this.fileName = tempFileName;
  71.          if (this.slideShowItinerary != null) {
  72.             ((Container)this).remove(this.slideShowItinerary);
  73.          }
  74.  
  75.          this.dayCount = 1;
  76.          if (this.slideShowItinerary != null) {
  77.             this.slideShowItinerary.removeActionListener(this.glAction);
  78.          }
  79.  
  80.          this.slideShowItinerary = new SlideShow();
  81.          this.slideShowItinerary.addActionListener(this.glAction);
  82.          this.slideShowItinerary.reshape(((Container)this).insets().left + this.slideShowBounds.x, ((Container)this).insets().top + this.slideShowBounds.y, this.slideShowBounds.width, this.slideShowBounds.height);
  83.          ((Container)this).add(this.slideShowItinerary);
  84.          this.getEntries(this.openFileDialog1.getDirectory(), this.fileName);
  85.          this.buttonNext.show();
  86.          this.buttonPrevious.show();
  87.  
  88.          try {
  89.             this.wrappingLabelTop.setText("Custom Itinerary for");
  90.          } catch (PropertyVetoException var4) {
  91.          }
  92.  
  93.          this.labelDay.setText("Day " + this.dayCount);
  94.  
  95.          try {
  96.             this.wrappingLabelDesc.setText(this.slideShowItinerary.getDescription(this.slideShowItinerary.getCurrentImageIndex()));
  97.          } catch (PropertyVetoException var3) {
  98.          }
  99.  
  100.          this.buttonPrevious.disable();
  101.          if (this.slideShowItinerary.isAtLastImage()) {
  102.             this.buttonNext.disable();
  103.          } else {
  104.             this.buttonNext.enable();
  105.          }
  106.  
  107.       }
  108.    }
  109.  
  110.    void Frame1_WindowClosing(WindowEvent event) {
  111.       ((Component)this).hide();
  112.       ((Frame)this).dispose();
  113.       System.exit(0);
  114.    }
  115.  
  116.    public AmazingTour() {
  117.       this.dayCount = 1;
  118.       this.fComponentsAdjusted = false;
  119.       ((Container)this).setLayout((LayoutManager)null);
  120.       ((Component)this).setVisible(false);
  121.       ((Component)this).setSize(600, 530);
  122.       ((Component)this).setFont(new Font("Dialog", 0, 12));
  123.       ((Component)this).setForeground(new Color(0));
  124.       ((Component)this).setBackground(new Color(16777215));
  125.       this.openFileDialog1 = new FileDialog(this);
  126.       this.openFileDialog1.setMode(0);
  127.       this.openFileDialog1.setTitle("Open");
  128.       this.wrappingLabelStart = new WrappingLabel();
  129.  
  130.       try {
  131.          this.wrappingLabelStart.setText("To start, choose Open from the File menu and open your data file. Your .dat file and the graphics files must be in the same directory.");
  132.       } catch (PropertyVetoException var8) {
  133.       }
  134.  
  135.       this.wrappingLabelStart.setBounds(5, 16, 247, 179);
  136.       this.wrappingLabelStart.setFont(new Font("Dialog", 1, 16));
  137.       ((Container)this).add(this.wrappingLabelStart);
  138.       this.wrappingLabelTop = new WrappingLabel();
  139.  
  140.       try {
  141.          this.wrappingLabelTop.setText("Custom itinerary for");
  142.       } catch (PropertyVetoException var7) {
  143.       }
  144.  
  145.       try {
  146.          this.wrappingLabelTop.setAlignStyle(1);
  147.       } catch (PropertyVetoException var6) {
  148.       }
  149.  
  150.       this.wrappingLabelTop.setBounds(7, 18, 244, 52);
  151.       this.wrappingLabelTop.setFont(new Font("Dialog", 1, 16));
  152.       ((Container)this).add(this.wrappingLabelTop);
  153.       this.wrappingLabelPeople = new WrappingLabel();
  154.  
  155.       try {
  156.          this.wrappingLabelPeople.setAlignStyle(1);
  157.       } catch (PropertyVetoException var5) {
  158.       }
  159.  
  160.       this.wrappingLabelPeople.setBounds(7, 75, 244, 109);
  161.       this.wrappingLabelPeople.setFont(new Font("Dialog", 1, 24));
  162.       ((Container)this).add(this.wrappingLabelPeople);
  163.       this.imageViewerLogo = new ImageViewer();
  164.  
  165.       try {
  166.          this.imageViewerLogo.setImageURL(RelativeURL.getURL("Images/Logo.gif"));
  167.       } catch (MalformedURLException var3) {
  168.       } catch (PropertyVetoException var4) {
  169.       }
  170.  
  171.       this.imageViewerLogo.setBounds(268, 2, 311, 203);
  172.       ((Container)this).add(this.imageViewerLogo);
  173.       this.slideShowItinerary = new SlideShow();
  174.       this.slideShowItinerary.setBounds(254, 232, 340, 235);
  175.       ((Container)this).add(this.slideShowItinerary);
  176.       this.labelDay = new Label("", 1);
  177.       this.labelDay.setBounds(65, 199, 108, 32);
  178.       this.labelDay.setFont(new Font("Dialog", 2, 16));
  179.       ((Container)this).add(this.labelDay);
  180.       this.buttonNext = new Button();
  181.       this.buttonNext.setActionCommand("button");
  182.       this.buttonNext.setLabel("Next");
  183.       this.buttonNext.setVisible(false);
  184.       this.buttonNext.setBounds(431, 470, 80, 31);
  185.       ((Container)this).add(this.buttonNext);
  186.       this.buttonPrevious = new Button();
  187.       this.buttonPrevious.setActionCommand("button");
  188.       this.buttonPrevious.setLabel("Previous");
  189.       this.buttonPrevious.setVisible(false);
  190.       this.buttonPrevious.setBounds(341, 470, 80, 31);
  191.       ((Container)this).add(this.buttonPrevious);
  192.       this.wrappingLabelDesc = new WrappingLabel();
  193.       this.wrappingLabelDesc.setBounds(8, 236, 240, 265);
  194.       this.wrappingLabelDesc.setFont(new Font("Dialog", 0, 14));
  195.       ((Container)this).add(this.wrappingLabelDesc);
  196.       ((Frame)this).setTitle("Amazing Adventures Travel - Custom Itinerary Application");
  197.       this.slideShowBounds = this.slideShowItinerary.bounds();
  198.       this.mainMenuBar = new MenuBar();
  199.       this.menu1 = new Menu("File");
  200.       this.miOpen = new MenuItem("Open...");
  201.       this.menu1.add(this.miOpen);
  202.       this.menu1.addSeparator();
  203.       this.miExit = new MenuItem("Exit");
  204.       this.menu1.add(this.miExit);
  205.       this.mainMenuBar.add(this.menu1);
  206.       this.menu3 = new Menu("Help");
  207.       this.mainMenuBar.setHelpMenu(this.menu3);
  208.       this.miAbout = new MenuItem("About..");
  209.       this.menu3.add(this.miAbout);
  210.       this.mainMenuBar.add(this.menu3);
  211.       ((Frame)this).setMenuBar(this.mainMenuBar);
  212.       AmazingTour$SymWindow aSymWindow = new AmazingTour$SymWindow(this);
  213.       ((Window)this).addWindowListener(aSymWindow);
  214.       AmazingTour$SymAction lSymAction = new AmazingTour$SymAction(this);
  215.       this.miOpen.addActionListener(lSymAction);
  216.       this.miAbout.addActionListener(lSymAction);
  217.       this.miExit.addActionListener(lSymAction);
  218.       this.buttonPrevious.addActionListener(lSymAction);
  219.       this.buttonNext.addActionListener(lSymAction);
  220.       this.slideShowItinerary.addActionListener(lSymAction);
  221.       this.glAction = lSymAction;
  222.    }
  223.  
  224.    public AmazingTour(String title) {
  225.       this();
  226.       ((Frame)this).setTitle(title);
  227.    }
  228.  
  229.    public synchronized void show() {
  230.       ((Component)this).move(50, 50);
  231.       super.show();
  232.    }
  233.  
  234.    public static void main(String[] args) {
  235.       (new AmazingTour()).show();
  236.    }
  237.  
  238.    public void addNotify() {
  239.       super.addNotify();
  240.       if (!this.fComponentsAdjusted) {
  241.          ((Component)this).setSize(((Container)this).insets().left + ((Container)this).insets().right + ((Component)this).getSize().width, ((Container)this).insets().top + ((Container)this).insets().bottom + ((Component)this).getSize().height);
  242.          Component[] components = ((Container)this).getComponents();
  243.  
  244.          for(int i = 0; i < components.length; ++i) {
  245.             Point p = components[i].getLocation();
  246.             p.translate(((Container)this).insets().left, ((Container)this).insets().top);
  247.             components[i].setLocation(p);
  248.          }
  249.  
  250.          this.fComponentsAdjusted = true;
  251.       }
  252.    }
  253.  
  254.    private void getEntries(String dir, String filename) {
  255.       try {
  256.          DataInputStream in = new DataInputStream(new FileInputStream(filename));
  257.  
  258.          try {
  259.             this.wrappingLabelPeople.setText(in.readLine());
  260.          } catch (PropertyVetoException var8) {
  261.          }
  262.  
  263.          int numEntries = Integer.parseInt(in.readLine());
  264.          dir = "file:/" + dir.substring(0, dir.lastIndexOf(92));
  265.  
  266.          for(int i = 0; i < numEntries; ++i) {
  267.             String s1 = dir + "/" + in.readLine();
  268.             String s2 = in.readLine();
  269.             this.slideShowItinerary.addImageAndDescription(new URL(s1), s2);
  270.          }
  271.  
  272.          ((FilterInputStream)in).close();
  273.          ((Container)this).invalidate();
  274.          ((Container)this).validate();
  275.       } catch (FileNotFoundException var9) {
  276.          System.err.println("Can't open " + filename);
  277.       } catch (IOException var10) {
  278.          System.err.println("Error reading " + filename);
  279.       }
  280.  
  281.    }
  282.  
  283.    void buttonPrevious_Action(ActionEvent event) {
  284.       this.slideShowItinerary.previousImage();
  285.       this.labelDay.setText("Day " + --this.dayCount);
  286.    }
  287.  
  288.    void buttonNext_Action(ActionEvent event) {
  289.       this.slideShowItinerary.nextImage();
  290.       this.labelDay.setText("Day " + ++this.dayCount);
  291.    }
  292.  
  293.    void slideShowItinerary_SlideChanged(ActionEvent event) {
  294.       this.buttonNext.setEnabled(!this.slideShowItinerary.isAtLastImage());
  295.       this.buttonPrevious.setEnabled(!this.slideShowItinerary.isAtFirstImage());
  296.  
  297.       try {
  298.          this.wrappingLabelDesc.setText(this.slideShowItinerary.getDescription(this.slideShowItinerary.getCurrentImageIndex()));
  299.       } catch (PropertyVetoException var2) {
  300.       }
  301.  
  302.    }
  303. }
  304.