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.java < prev    next >
Encoding:
Java Source  |  1998-03-19  |  12.4 KB  |  413 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. // Custom code: You must add this line below the line above.
  9. import java.io.*;
  10.  
  11. import symantec.itools.multimedia.ImageViewer;
  12. import symantec.itools.awt.*;
  13. import symantec.itools.awt.WrappingLabel;
  14. import symantec.itools.awt.LabelButton;
  15. import symantec.itools.multimedia.SlideShow;
  16. public class AmazingTour extends Frame
  17. {
  18.     // Custom code: You must add the following three lines after the line above.
  19.     int dayCount = 1;
  20.     String fileName;
  21.     Rectangle slideShowBounds;
  22.  
  23.     void miAbout_Action(java.awt.event.ActionEvent event)
  24.     {
  25.         //{{CONNECTION
  26.         // Action from About Create and show as modal
  27.         (new AboutDialog(this, true)).show();
  28.         //}}
  29.     }
  30.  
  31.     void miExit_Action(java.awt.event.ActionEvent event)
  32.     {
  33.         //{{CONNECTION
  34.         // Action from Exit Create and show as modal
  35.         (new QuitDialog(this, true)).show();
  36.         //}}
  37.     }
  38.  
  39.     void miOpen_Action(java.awt.event.ActionEvent event)
  40.     {
  41.         // Custom code: You must add this line after the line above.
  42.         String tempFileName;
  43.  
  44.         //{{CONNECTION
  45.         // Action from Open... Show the OpenFileDialog
  46.         openFileDialog1.show();
  47.         //}}
  48.  
  49.         // Custom code: You must add this block of code to support the openFileDialog.
  50.         // From here...
  51.         tempFileName = openFileDialog1.getDirectory() + openFileDialog1.getFile();
  52.  
  53.         if((fileName == null && !tempFileName.endsWith(".dat")) ||
  54.             !tempFileName.endsWith(".dat"))
  55.         {
  56.             return;
  57.         }
  58.         if(fileName == null)
  59.         {
  60.             wrappingLabelStart.hide();
  61.         }
  62.  
  63.         fileName = tempFileName;
  64.  
  65.         if(slideShowItinerary != null)
  66.         {
  67.             remove(slideShowItinerary);
  68.         }
  69.  
  70.         dayCount = 1;
  71.         
  72.         if (slideShowItinerary != null)
  73.            slideShowItinerary.removeActionListener(glAction);           
  74.         slideShowItinerary = new symantec.itools.multimedia.SlideShow();
  75.         slideShowItinerary.addActionListener(glAction);
  76.         slideShowItinerary.reshape(insets().left + slideShowBounds.x,insets().top + slideShowBounds.y,slideShowBounds.width,slideShowBounds.height);
  77.         add(slideShowItinerary);
  78.         
  79.         getEntries(openFileDialog1.getDirectory(), fileName);
  80.         buttonNext.show();
  81.         buttonPrevious.show();
  82.         try {
  83.            wrappingLabelTop.setText("Custom Itinerary for");
  84.         }catch (java.beans.PropertyVetoException pve) {}
  85.         labelDay.setText("Day " + (dayCount));
  86.         try {
  87.             wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex()));
  88.         }catch (java.beans.PropertyVetoException pve) {}
  89.         buttonPrevious.disable();
  90.  
  91.         if(slideShowItinerary.isAtLastImage())
  92.         {
  93.             buttonNext.disable();
  94.         }
  95.         else
  96.         {
  97.             buttonNext.enable();
  98.         }
  99.         // ...down to here.
  100.     }
  101.  
  102.     void Frame1_WindowClosing(java.awt.event.WindowEvent event)
  103.     {
  104.         hide();         // hide the Frame
  105.         dispose();      // free the system resources
  106.         System.exit(0); // close the application
  107.     }
  108.  
  109.     public AmazingTour()
  110.     {
  111.         // This code is automatically generated by Visual Cafe when you add
  112.         // components to the visual environment. It instantiates and initializes
  113.         // the components. To modify the code, only use code syntax that matches
  114.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  115.         // parse your Java file into its visual environment.
  116.  
  117.         //{{INIT_CONTROLS
  118.         setLayout(null);
  119.         setVisible(false);
  120.         setSize(600,530);
  121.         setFont(new Font("Dialog", Font.PLAIN, 12));
  122.         setForeground(new Color(0));
  123.         setBackground(new Color(16777215));
  124.         openFileDialog1 = new java.awt.FileDialog(this);
  125.         openFileDialog1.setMode(FileDialog.LOAD);
  126.         openFileDialog1.setTitle("Open");
  127.         //$$ openFileDialog1.move(573,504);
  128.         wrappingLabelStart = new symantec.itools.awt.WrappingLabel();
  129.         try {
  130.             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.");
  131.         }
  132.         catch(java.beans.PropertyVetoException e) { }
  133.         wrappingLabelStart.setBounds(5,16,247,179);
  134.         wrappingLabelStart.setFont(new Font("Dialog", Font.BOLD, 16));
  135.         add(wrappingLabelStart);
  136.         wrappingLabelTop = new symantec.itools.awt.WrappingLabel();
  137.         try {
  138.             wrappingLabelTop.setText("Custom itinerary for");
  139.         }
  140.         catch(java.beans.PropertyVetoException e) { }
  141.         try {
  142.             wrappingLabelTop.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED);
  143.         }
  144.         catch(java.beans.PropertyVetoException e) { }
  145.         wrappingLabelTop.setBounds(7,18,244,52);
  146.         wrappingLabelTop.setFont(new Font("Dialog", Font.BOLD, 16));
  147.         add(wrappingLabelTop);
  148.         wrappingLabelPeople = new symantec.itools.awt.WrappingLabel();
  149.         try {
  150.             wrappingLabelPeople.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED);
  151.         }
  152.         catch(java.beans.PropertyVetoException e) { }
  153.         wrappingLabelPeople.setBounds(7,75,244,109);
  154.         wrappingLabelPeople.setFont(new Font("Dialog", Font.BOLD, 24));
  155.         add(wrappingLabelPeople);
  156.         imageViewerLogo = new symantec.itools.multimedia.ImageViewer();
  157.         try {
  158.             imageViewerLogo.setImageURL(symantec.itools.net.RelativeURL.getURL("Images/Logo.gif"));
  159.         }
  160.         catch (java.net.MalformedURLException error) { }
  161.         catch(java.beans.PropertyVetoException e) { }
  162.         imageViewerLogo.setBounds(268,2,311,203);
  163.         add(imageViewerLogo);
  164.         slideShowItinerary = new symantec.itools.multimedia.SlideShow();
  165.         slideShowItinerary.setBounds(254,232,340,235);
  166.         add(slideShowItinerary);
  167.         labelDay = new java.awt.Label("",Label.CENTER);
  168.         labelDay.setBounds(65,199,108,32);
  169.         labelDay.setFont(new Font("Dialog", Font.ITALIC, 16));
  170.         add(labelDay);
  171.         buttonNext = new java.awt.Button();
  172.         buttonNext.setActionCommand("button");
  173.         buttonNext.setLabel("Next");
  174.         buttonNext.setVisible(false);
  175.         buttonNext.setBounds(431,470,80,31);
  176.         add(buttonNext);
  177.         buttonPrevious = new java.awt.Button();
  178.         buttonPrevious.setActionCommand("button");
  179.         buttonPrevious.setLabel("Previous");
  180.         buttonPrevious.setVisible(false);
  181.         buttonPrevious.setBounds(341,470,80,31);
  182.         add(buttonPrevious);
  183.         wrappingLabelDesc = new symantec.itools.awt.WrappingLabel();
  184.         wrappingLabelDesc.setBounds(8,236,240,265);
  185.         wrappingLabelDesc.setFont(new Font("Dialog", Font.PLAIN, 14));
  186.         add(wrappingLabelDesc);
  187.         setTitle("Amazing Adventures Travel - Custom Itinerary Application");
  188.         //}}
  189.  
  190.         // Custom code: Add the following line to save the bounds of the SlideShow component.
  191.         slideShowBounds = slideShowItinerary.bounds();
  192.  
  193.         //{{INIT_MENUS
  194.         mainMenuBar = new java.awt.MenuBar();
  195.         menu1 = new java.awt.Menu("File");
  196.         miOpen = new java.awt.MenuItem("Open...");
  197.         menu1.add(miOpen);
  198.         menu1.addSeparator();
  199.         miExit = new java.awt.MenuItem("Exit");
  200.         menu1.add(miExit);
  201.         mainMenuBar.add(menu1);
  202.         menu3 = new java.awt.Menu("Help");
  203.         mainMenuBar.setHelpMenu(menu3);
  204.         miAbout = new java.awt.MenuItem("About..");
  205.         menu3.add(miAbout);
  206.         mainMenuBar.add(menu3);
  207.         setMenuBar(mainMenuBar);
  208.         //$$ mainMenuBar.move(548,504);
  209.         //}}
  210.  
  211.         //{{REGISTER_LISTENERS
  212.         SymWindow aSymWindow = new SymWindow();
  213.         addWindowListener(aSymWindow);
  214.         SymAction lSymAction = new SymAction();
  215.         miOpen.addActionListener(lSymAction);
  216.         miAbout.addActionListener(lSymAction);
  217.         miExit.addActionListener(lSymAction);
  218.         buttonPrevious.addActionListener(lSymAction);
  219.         buttonNext.addActionListener(lSymAction);
  220.         slideShowItinerary.addActionListener(lSymAction);
  221.         //}}
  222.         // Custom code: Copy the following line to set the parent's Action object to this instance.
  223.         glAction = lSymAction;
  224.     }
  225.  
  226.     public AmazingTour(String title)
  227.     {
  228.         this();
  229.         setTitle(title);
  230.     }
  231.  
  232.     public synchronized void show()
  233.     {
  234.         move(50, 50);
  235.         super.show();
  236.     }
  237.  
  238.     static public void main(String args[])
  239.     {
  240.         (new AmazingTour()).show();
  241.     }
  242.  
  243.     public void addNotify()
  244.     {
  245.         super.addNotify();
  246.  
  247.         if (fComponentsAdjusted)
  248.             return;
  249.  
  250.         // Adjust components according to the insets
  251.         setSize(insets().left + insets().right + getSize().width, insets().top + insets().bottom + getSize().height);
  252.         Component components[] = getComponents();
  253.         for (int i = 0; i < components.length; i++)
  254.         {
  255.             Point p = components[i].getLocation();
  256.             p.translate(insets().left, insets().top);
  257.             components[i].setLocation(p);
  258.         }
  259.         fComponentsAdjusted = true;
  260.     }
  261.  
  262.     boolean fComponentsAdjusted = false;
  263.  
  264.     //{{DECLARE_CONTROLS
  265.     java.awt.FileDialog openFileDialog1;
  266.     symantec.itools.awt.WrappingLabel wrappingLabelStart;
  267.     symantec.itools.awt.WrappingLabel wrappingLabelTop;
  268.     symantec.itools.awt.WrappingLabel wrappingLabelPeople;
  269.     symantec.itools.multimedia.ImageViewer imageViewerLogo;
  270.     symantec.itools.multimedia.SlideShow slideShowItinerary;
  271.     java.awt.Label labelDay;
  272.     java.awt.Button buttonNext;
  273.     java.awt.Button buttonPrevious;
  274.     symantec.itools.awt.WrappingLabel wrappingLabelDesc;
  275.     //}}
  276.     
  277.     // Custom code: Add the following line to keep a copy of lAction to reattach to new instances of SlideShow.
  278.     SymAction glAction;
  279.  
  280.     //{{DECLARE_MENUS
  281.     java.awt.MenuBar mainMenuBar;
  282.     java.awt.Menu menu1;
  283.     java.awt.MenuItem miOpen;
  284.     java.awt.MenuItem miExit;
  285.     java.awt.Menu menu3;
  286.     java.awt.MenuItem miAbout;
  287.     //}}
  288.  
  289.     // Custom code: You must add this block of code to support external data files.
  290.     // From here...
  291.     private void getEntries(String dir, String filename)
  292.     {
  293.         try
  294.         {
  295.              DataInputStream in;
  296.               int numEntries;
  297.  
  298.                in = new DataInputStream(new FileInputStream(filename));
  299.                try {
  300.                  wrappingLabelPeople.setText(in.readLine());
  301.             }catch (java.beans.PropertyVetoException pve) {}
  302.             numEntries = Integer.parseInt(in.readLine());
  303.             dir = "file:/" + dir.substring(0, dir.lastIndexOf('\\'));
  304.  
  305.              for(int i = 0; i < numEntries; i++)
  306.              {
  307.                  String s1 = dir + "/" + in.readLine();
  308.                  String s2 = in.readLine();
  309.                  slideShowItinerary.addImageAndDescription(new java.net.URL(s1), s2);
  310.              }
  311.  
  312.              in.close();
  313.             invalidate();
  314.             validate();
  315.         }
  316.         catch(FileNotFoundException e)
  317.         {
  318.             System.err.println("Can't open " + filename);
  319.         }
  320.         catch(IOException e)
  321.         {
  322.             System.err.println("Error reading " + filename);
  323.         }
  324.     }
  325.     // ...up to here.
  326.  
  327.     class SymWindow extends java.awt.event.WindowAdapter
  328.     {
  329.         public void windowClosing(java.awt.event.WindowEvent event)
  330.         {
  331.             Object object = event.getSource();
  332.             if (object == AmazingTour.this)
  333.                 Frame1_WindowClosing(event);
  334.         }
  335.     }
  336.  
  337.     class SymAction implements java.awt.event.ActionListener
  338.     {
  339.         public void actionPerformed(java.awt.event.ActionEvent event)
  340.         {
  341.             Object object = event.getSource();
  342.             if (object == miOpen)
  343.                 miOpen_Action(event);
  344.             else if (object == miAbout)
  345.                 miAbout_Action(event);
  346.             else if (object == miExit)
  347.                 miExit_Action(event);
  348.             else if (object == buttonPrevious)
  349.                 buttonPrevious_Action(event);
  350.             else if (object == buttonNext)
  351.                 buttonNext_Action(event);
  352.             else if (object == slideShowItinerary)
  353.                 slideShowItinerary_SlideChanged(event);
  354.         }
  355.     }
  356.  
  357.     void buttonPrevious_Action(java.awt.event.ActionEvent event)
  358.     {
  359.         // to do: code goes here.
  360.              
  361.         //{{CONNECTION
  362.         // Go to the SlideShow's previous image
  363.         slideShowItinerary.previousImage();
  364.         //}}
  365.              
  366.         //{{CONNECTION
  367.         // Set the text for Label...
  368.         labelDay.setText("Day " + (--dayCount));
  369.         //}}
  370.     }
  371.  
  372.     void buttonNext_Action(java.awt.event.ActionEvent event)
  373.     {
  374.         // to do: code goes here.
  375.              
  376.         //{{CONNECTION
  377.         // Go to the SlideShow's next image
  378.         slideShowItinerary.nextImage();
  379.         //}}
  380.              
  381.         //{{CONNECTION
  382.         // Set the text for Label...
  383.         labelDay.setText("Day " + (++dayCount));
  384.         //}}
  385.     }
  386.  
  387.     void slideShowItinerary_SlideChanged(java.awt.event.ActionEvent event)
  388.     {
  389.         // to do: code goes here.
  390.              
  391.         //{{CONNECTION
  392.         // Disable the Button on condition... Is at the last image?
  393.         buttonNext.setEnabled(! slideShowItinerary.isAtLastImage());
  394.         //}}
  395.              
  396.         //{{CONNECTION
  397.         // Disable the Button on condition... Is at the first image?
  398.         buttonPrevious.setEnabled(! slideShowItinerary.isAtFirstImage());
  399.         //}}
  400.              
  401.         //{{CONNECTION
  402.         // Set the text for WrappingLabel... Get current description
  403.         {
  404.             try {
  405.                 wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex()));
  406.             }
  407.             catch(java.beans.PropertyVetoException e) { }
  408.         }
  409.         //}}
  410.     }
  411. }
  412.  
  413.