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