home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / AmazingTour.java < prev    next >
Encoding:
Java Source  |  1997-02-04  |  10.2 KB  |  329 lines

  1. /*
  2.     This simple extension of the java.awt.Frame class
  3.     contains all the elements necessary to act as the
  4.     main window of an application.
  5.  */
  6.  
  7. import java.awt.*;
  8. import symantec.itools.awt.*;
  9. // Custom code: You must add this line below the line above.
  10. import java.io.*;
  11.  
  12. public class AmazingTour extends Frame {
  13.  
  14.     // Custom code: You must add the following three lines after the line above.
  15.     int dayCount = 1;
  16.     String fileName;
  17.     Rectangle slideShowBounds;
  18.  
  19.     void slideShowItinerary_SlideChanged(Event event) {
  20.  
  21.  
  22.         //{{CONNECTION
  23.         // Disable the Button on condition... Is at the last image?
  24.         buttonNext.enable(! slideShowItinerary.isAtLastImage());
  25.         //}}
  26.  
  27.         //{{CONNECTION
  28.         // Disable the Button on condition... Is at the first image?
  29.         buttonPrevious.enable(! slideShowItinerary.isAtFirstImage());
  30.         //}}
  31.  
  32.         //{{CONNECTION
  33.         // Set the text for WrappingLabel... Get current description
  34.         {
  35.             wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex()));
  36.         }
  37.         //}}
  38.     }
  39.  
  40.     void buttonNext_Clicked(Event event) {
  41.  
  42.  
  43.         //{{CONNECTION
  44.         // Go to the SlideShow's next image
  45.         slideShowItinerary.nextImage();
  46.         //}}
  47.  
  48.         //Custom code: Add the following four lines.
  49.         //{{CONNECTION
  50.         // Set the text for Label...
  51.         labelDay.setText("Day " + (++dayCount));
  52.         //}}
  53.     }
  54.  
  55.     void buttonPrevious_Clicked(Event event) {
  56.  
  57.  
  58.         //{{CONNECTION
  59.         // Go to the SlideShow's previous image
  60.         slideShowItinerary.previousImage();
  61.         //}}
  62.  
  63.         //Custom code: Add the following four lines.
  64.         //{{CONNECTION
  65.         // Set the text for Label...
  66.         labelDay.setText("Day " + (--dayCount));
  67.         //}}
  68.     }
  69.  
  70.     void Open_Action(Event event) {
  71.  
  72.         // Custom code: You must add this line after the line above.
  73.         String tempFileName;
  74.  
  75.         //{{CONNECTION
  76.         // Action from Open... Show the OpenFileDialog
  77.         openFileDialog1.show();
  78.         //}}
  79.  
  80.         // Custom code: You must add this block of code to support the openFileDialog.
  81.         // From here...
  82.         tempFileName = openFileDialog1.getDirectory() + openFileDialog1.getFile();
  83.  
  84.         if((fileName == null && !tempFileName.endsWith(".dat")) ||
  85.             !tempFileName.endsWith(".dat"))
  86.         {
  87.             return;
  88.         }
  89.         if(fileName == null)
  90.         {
  91.             wrappingLabelStart.hide();
  92.         }
  93.  
  94.         fileName = tempFileName;
  95.  
  96.         if(slideShowItinerary != null)
  97.         {
  98.             remove(slideShowItinerary);
  99.         }
  100.  
  101.         dayCount = 1;
  102.         slideShowItinerary = new symantec.itools.multimedia.SlideShow();
  103.         slideShowItinerary.reshape(insets().left + slideShowBounds.x,insets().top + slideShowBounds.y,slideShowBounds.width,slideShowBounds.height);
  104.         add(slideShowItinerary);
  105.         getEntries(openFileDialog1.getDirectory(), fileName);
  106.         buttonNext.show();
  107.         buttonPrevious.show();
  108.         wrappingLabelTop.setText("Custom Itinerary for");
  109.         labelDay.setText("Day " + (dayCount));
  110.         wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex()));
  111.         buttonPrevious.disable();
  112.  
  113.         if(slideShowItinerary.isAtLastImage())
  114.         {
  115.             buttonNext.disable();
  116.         }
  117.         else
  118.         {
  119.             buttonNext.enable();
  120.         }
  121.         // ...down to here.
  122.     }
  123.  
  124.     void About_Action(Event event) {
  125.         //{{CONNECTION
  126.         // Action from About Create and show as modal
  127.         (new AboutDialog(this, true)).show();
  128.         //}}
  129.     }
  130.  
  131.     void Exit_Action(Event event) {
  132.         //{{CONNECTION
  133.         // Action from Exit Create and show as modal
  134.         (new QuitDialog(this, true)).show();
  135.         //}}
  136.     }
  137.  
  138.     public AmazingTour() {
  139.         // Pre-load the classes so the current directory won't matter.
  140.         // (The current directory could possibly change with the openFileDialog.)
  141.         new AboutDialog(this, true);
  142.         new QuitDialog(this, true);
  143.         //{{INIT_CONTROLS
  144.         setLayout(null);
  145.         addNotify();
  146.         resize(insets().left + insets().right + 595,insets().top + insets().bottom + 550);
  147.         setFont(new Font("Dialog", Font.BOLD, 12));
  148.         setForeground(new Color(0));
  149.         setBackground(new Color(16777215));
  150.         openFileDialog1 = new java.awt.FileDialog(this, "Open",FileDialog.LOAD);
  151.         //$$ openFileDialog1.move(0,0);
  152.         wrappingLabelStart = new symantec.itools.awt.WrappingLabel();
  153.         wrappingLabelStart.reshape(insets().left + 8,insets().top + 24,225,132);
  154.         wrappingLabelStart.setFont(new Font("Dialog", Font.BOLD, 16));
  155.         add(wrappingLabelStart);
  156.         wrappingLabelStart.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_LEFT);
  157.         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.");
  158.         labelDay = new java.awt.Label("",Label.CENTER);
  159.         labelDay.reshape(insets().left + 72,insets().top + 208,86,26);
  160.         labelDay.setFont(new Font("Dialog", Font.ITALIC, 16));
  161.         add(labelDay);
  162.         wrappingLabelPeople = new symantec.itools.awt.WrappingLabel();
  163.         wrappingLabelPeople.reshape(insets().left + 8,insets().top + 88,232,88);
  164.         wrappingLabelPeople.setFont(new Font("Dialog", Font.BOLD, 24));
  165.         add(wrappingLabelPeople);
  166.         wrappingLabelPeople.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED);
  167.         wrappingLabelPeople.setText("");
  168.         slideShowItinerary = new symantec.itools.multimedia.SlideShow();
  169.         slideShowItinerary.reshape(insets().left + 251,insets().top + 219,340,235);
  170.         add(slideShowItinerary);
  171.         wrappingLabelDesc = new symantec.itools.awt.WrappingLabel();
  172.         wrappingLabelDesc.reshape(insets().left + 16,insets().top + 248,224,272);
  173.         wrappingLabelDesc.setFont(new Font("Dialog", Font.PLAIN, 14));
  174.         add(wrappingLabelDesc);
  175.         wrappingLabelDesc.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_LEFT);
  176.         wrappingLabelDesc.setText("");
  177.         imageViewerLogo = new symantec.itools.multimedia.ImageViewer();
  178.         imageViewerLogo.reshape(insets().left + 256,insets().top + 16,320,217);
  179.         add(imageViewerLogo);
  180.         try {
  181.             imageViewerLogo.setURL(symantec.itools.net.RelativeURL.getURL("Images/Logo.gif"));
  182.         } catch (java.net.MalformedURLException error) {
  183.         }
  184.         buttonPrevious = new java.awt.Button("Previous");
  185.         buttonPrevious.hide();
  186.         buttonPrevious.reshape(insets().left + 336,insets().top + 496,82,25);
  187.         add(buttonPrevious);
  188.         buttonNext = new java.awt.Button("Next");
  189.         buttonNext.hide();
  190.         buttonNext.reshape(insets().left + 424,insets().top + 496,82,25);
  191.         add(buttonNext);
  192.         wrappingLabelTop = new symantec.itools.awt.WrappingLabel();
  193.         wrappingLabelTop.reshape(insets().left + 8,insets().top + 40,232,38);
  194.         wrappingLabelTop.setFont(new Font("Dialog", Font.BOLD, 16));
  195.         add(wrappingLabelTop);
  196.         wrappingLabelTop.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED);
  197.         wrappingLabelTop.setText("");
  198.         setTitle("Amazing Adventures Travel - Custom Itinerary Application");
  199.         //}}
  200.  
  201.         // Custom code: Add the following line to save the bounds of the SlideShow component.
  202.         slideShowBounds = slideShowItinerary.bounds();
  203.  
  204.         //{{INIT_MENUS
  205.         mainMenuBar = new java.awt.MenuBar();
  206.  
  207.         menu1 = new java.awt.Menu("File");
  208.         menu1.add("Open...");
  209.         menu1.addSeparator();
  210.         menu1.add("Exit");
  211.         mainMenuBar.add(menu1);
  212.  
  213.         menu3 = new java.awt.Menu("Help");
  214.         mainMenuBar.setHelpMenu(menu3);
  215.         menu3.add("About");
  216.         mainMenuBar.add(menu3);
  217.         setMenuBar(mainMenuBar);
  218.         //$$ mainMenuBar.move(0,0);
  219.         //}}
  220.     }
  221.  
  222.     public AmazingTour(String title) {
  223.         this();
  224.         setTitle(title);
  225.     }
  226.  
  227.     public synchronized void show() {
  228.         move(50, 50);
  229.         super.show();
  230.     }
  231.  
  232.     public boolean handleEvent(Event event) {
  233.         if (event.target == buttonPrevious && event.id == Event.ACTION_EVENT) {
  234.             buttonPrevious_Clicked(event);
  235.         }
  236.         if (event.target == buttonNext && event.id == Event.ACTION_EVENT) {
  237.             buttonNext_Clicked(event);
  238.         }
  239.         if (event.target == slideShowItinerary && event.id == Event.ACTION_EVENT) {
  240.             slideShowItinerary_SlideChanged(event);
  241.         }
  242.         if (event.id == Event.WINDOW_DESTROY) {
  243.             hide();         // hide the Frame
  244.             dispose();      // free the system resources
  245.             System.exit(0); // close the application
  246.             return true;
  247.         }
  248.         return super.handleEvent(event);
  249.     }
  250.  
  251.     public boolean action(Event event, Object arg) {
  252.         if (event.target instanceof MenuItem) {
  253.             String label = (String) arg;
  254.             if (label.equalsIgnoreCase("Open...")) {
  255.                 Open_Action(event);
  256.                 return true;
  257.             } else
  258.             if (label.equalsIgnoreCase("About")) {
  259.                 About_Action(event);
  260.                 return true;
  261.             } else
  262.                 if (label.equalsIgnoreCase("Exit")) {
  263.                     Exit_Action(event);
  264.                     return true;
  265.             }
  266.         }
  267.         return super.action(event, arg);
  268.     }
  269.  
  270.     static public void main(String args[]) {
  271.         (new AmazingTour()).show();
  272.     }
  273.  
  274.     //{{DECLARE_CONTROLS
  275.     java.awt.FileDialog openFileDialog1;
  276.     symantec.itools.awt.WrappingLabel wrappingLabelStart;
  277.     java.awt.Label labelDay;
  278.     symantec.itools.awt.WrappingLabel wrappingLabelPeople;
  279.     symantec.itools.multimedia.SlideShow slideShowItinerary;
  280.     symantec.itools.awt.WrappingLabel wrappingLabelDesc;
  281.     symantec.itools.multimedia.ImageViewer imageViewerLogo;
  282.     java.awt.Button buttonPrevious;
  283.     java.awt.Button buttonNext;
  284.     symantec.itools.awt.WrappingLabel wrappingLabelTop;
  285.     //}}
  286.  
  287.     //{{DECLARE_MENUS
  288.     java.awt.MenuBar mainMenuBar;
  289.     java.awt.Menu menu1;
  290.     java.awt.Menu menu3;
  291.     //}}
  292.  
  293.     // Custom code: You must add this block of code to support external data files.
  294.     // From here...
  295.     private void getEntries(String dir, String filename)
  296.     {
  297.         try
  298.         {
  299.              DataInputStream in;
  300.               int numEntries;
  301.  
  302.                in = new DataInputStream(new FileInputStream(filename));
  303.             wrappingLabelPeople.setText(in.readLine());
  304.             numEntries = Integer.parseInt(in.readLine());
  305.             dir = "file:/" + dir.substring(0, dir.lastIndexOf('\\'));
  306.  
  307.              for(int i = 0; i < numEntries; i++)
  308.              {
  309.                  String s1 = dir + "/" + in.readLine();
  310.                  String s2 = in.readLine();
  311.                  slideShowItinerary.addImageAndDescription(new java.net.URL(s1), s2);
  312.              }
  313.  
  314.              in.close();
  315.             invalidate();
  316.             validate();
  317.         }
  318.         catch(FileNotFoundException e)
  319.         {
  320.             System.err.println("Can't open " + filename);
  321.         }
  322.         catch(IOException e)
  323.         {
  324.             System.err.println("Error reading " + filename);
  325.         }
  326.     }
  327.     // ...up to here. Notice the bracket at the end.
  328. }
  329.