home *** CD-ROM | disk | FTP | other *** search
Wrap
Java Source | 1997-09-05 | 12.7 KB | 414 lines
/* This simple extension of the java.awt.Frame class contains all the elements necessary to act as the main window of an application. */ import java.awt.*; // Custom code: You must add this line below the line above. import java.io.*; import symantec.itools.multimedia.ImageViewer; import symantec.itools.awt.*; import symantec.itools.awt.WrappingLabel; import symantec.itools.awt.LabelButton; public class AmazingTour extends Frame { // Custom code: You must add the following three lines after the line above. int dayCount = 1; String fileName; Rectangle slideShowBounds; void miAbout_Action(java.awt.event.ActionEvent event) { //{{CONNECTION // Action from About Create and show as modal (new AboutDialog(this, true)).show(); //}} } void miExit_Action(java.awt.event.ActionEvent event) { //{{CONNECTION // Action from Exit Create and show as modal (new QuitDialog(this, true)).show(); //}} } void miOpen_Action(java.awt.event.ActionEvent event) { // Custom code: You must add this line after the line above. String tempFileName; //{{CONNECTION // Action from Open... Show the OpenFileDialog openFileDialog1.show(); //}} // Custom code: You must add this block of code to support the openFileDialog. // From here... tempFileName = openFileDialog1.getDirectory() + openFileDialog1.getFile(); if((fileName == null && !tempFileName.endsWith(".dat")) || !tempFileName.endsWith(".dat")) { return; } if(fileName == null) { wrappingLabelStart.hide(); } fileName = tempFileName; if(slideShowItinerary != null) { remove(slideShowItinerary); } dayCount = 1; if (slideShowItinerary != null) slideShowItinerary.removeActionListener(glAction); slideShowItinerary = new symantec.itools.multimedia.SlideShow(); slideShowItinerary.addActionListener(glAction); slideShowItinerary.reshape(insets().left + slideShowBounds.x,insets().top + slideShowBounds.y,slideShowBounds.width,slideShowBounds.height); add(slideShowItinerary); getEntries(openFileDialog1.getDirectory(), fileName); buttonNext.show(); buttonPrevious.show(); try { wrappingLabelTop.setText("Custom Itinerary for"); }catch (java.beans.PropertyVetoException pve) {} labelDay.setText("Day " + (dayCount)); try { wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex())); }catch (java.beans.PropertyVetoException pve) {} buttonPrevious.disable(); if(slideShowItinerary.isAtLastImage()) { buttonNext.disable(); } else { buttonNext.enable(); } // ...down to here. } void Frame1_WindowClosing(java.awt.event.WindowEvent event) { hide(); // hide the Frame dispose(); // free the system resources System.exit(0); // close the application } public AmazingTour() { // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setVisible(false); setSize(insets().left + insets().right + 600,insets().top + insets().bottom + 530); setFont(new Font("Dialog", Font.PLAIN, 12)); setForeground(new Color(0)); setBackground(new Color(16777215)); openFileDialog1 = new java.awt.FileDialog(this); openFileDialog1.setMode(FileDialog.LOAD); openFileDialog1.setTitle("Open"); //$$ openFileDialog1.move(573,504); wrappingLabelStart = new symantec.itools.awt.WrappingLabel(); try { 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."); } catch(java.beans.PropertyVetoException e) { } wrappingLabelStart.setBounds(insets().left + 5,insets().top + 16,247,179); wrappingLabelStart.setFont(new Font("Dialog", Font.BOLD, 16)); add(wrappingLabelStart); wrappingLabelTop = new symantec.itools.awt.WrappingLabel(); try { wrappingLabelTop.setText("Custom itinerary for"); } catch(java.beans.PropertyVetoException e) { } try { wrappingLabelTop.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED); } catch(java.beans.PropertyVetoException e) { } wrappingLabelTop.setBounds(insets().left + 7,insets().top + 18,244,52); wrappingLabelTop.setFont(new Font("Dialog", Font.BOLD, 16)); add(wrappingLabelTop); wrappingLabelPeople = new symantec.itools.awt.WrappingLabel(); try { wrappingLabelPeople.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED); } catch(java.beans.PropertyVetoException e) { } wrappingLabelPeople.setBounds(insets().left + 7,insets().top + 75,244,109); wrappingLabelPeople.setFont(new Font("Dialog", Font.BOLD, 24)); add(wrappingLabelPeople); imageViewerLogo = new symantec.itools.multimedia.ImageViewer(); try { imageViewerLogo.setURL(symantec.itools.net.RelativeURL.getURL("Images/Logo.gif")); } catch (java.net.MalformedURLException error) { } catch(java.beans.PropertyVetoException e) { } imageViewerLogo.setBounds(insets().left + 268,insets().top + 2,311,203); add(imageViewerLogo); slideShowItinerary = new symantec.itools.multimedia.SlideShow(); slideShowItinerary.setBounds(insets().left + 254,insets().top + 232,340,235); add(slideShowItinerary); labelDay = new java.awt.Label("",Label.CENTER); labelDay.setBounds(insets().left + 65,insets().top + 199,108,32); labelDay.setFont(new Font("Dialog", Font.ITALIC, 16)); add(labelDay); buttonNext = new java.awt.Button(); buttonNext.setActionCommand("button"); buttonNext.setLabel("Next"); buttonNext.setVisible(false); buttonNext.setBounds(insets().left + 431,insets().top + 470,80,31); add(buttonNext); buttonPrevious = new java.awt.Button(); buttonPrevious.setActionCommand("button"); buttonPrevious.setLabel("Previous"); buttonPrevious.setVisible(false); buttonPrevious.setBounds(insets().left + 341,insets().top + 470,80,31); add(buttonPrevious); wrappingLabelDesc = new symantec.itools.awt.WrappingLabel(); wrappingLabelDesc.setBounds(insets().left + 8,insets().top + 236,240,265); wrappingLabelDesc.setFont(new Font("Dialog", Font.PLAIN, 14)); add(wrappingLabelDesc); setTitle("Amazing Adventures Travel - Custom Itinerary Application"); //}} // Custom code: Add the following line to save the bounds of the SlideShow component. slideShowBounds = slideShowItinerary.bounds(); //{{INIT_MENUS mainMenuBar = new java.awt.MenuBar(); menu1 = new java.awt.Menu("File"); miOpen = new java.awt.MenuItem("Open..."); menu1.add(miOpen); menu1.addSeparator(); miExit = new java.awt.MenuItem("Exit"); menu1.add(miExit); mainMenuBar.add(menu1); menu3 = new java.awt.Menu("Help"); mainMenuBar.setHelpMenu(menu3); miAbout = new java.awt.MenuItem("About.."); menu3.add(miAbout); mainMenuBar.add(menu3); setMenuBar(mainMenuBar); //$$ mainMenuBar.move(548,504); //}} //{{REGISTER_LISTENERS SymWindow aSymWindow = new SymWindow(); addWindowListener(aSymWindow); SymAction lSymAction = new SymAction(); miOpen.addActionListener(lSymAction); miAbout.addActionListener(lSymAction); miExit.addActionListener(lSymAction); buttonPrevious.addActionListener(lSymAction); buttonNext.addActionListener(lSymAction); slideShowItinerary.addActionListener(lSymAction); //}} // Custom code: Copy the following line to set the parent's Action object to this instance. glAction = lSymAction; } public AmazingTour(String title) { this(); setTitle(title); } public synchronized void show() { move(50, 50); super.show(); } static public void main(String args[]) { (new AmazingTour()).show(); } public void addNotify() { super.addNotify(); if (fComponentsAdjusted) return; // Adjust components according to the insets setSize(insets().left + insets().right + getSize().width, insets().top + insets().bottom + getSize().height); Component components[] = getComponents(); for (int i = 0; i < components.length; i++) { Point p = components[i].getLocation(); p.translate(insets().left, insets().top); components[i].setLocation(p); } fComponentsAdjusted = true; } boolean fComponentsAdjusted = false; //{{DECLARE_CONTROLS java.awt.FileDialog openFileDialog1; symantec.itools.awt.WrappingLabel wrappingLabelStart; symantec.itools.awt.WrappingLabel wrappingLabelTop; symantec.itools.awt.WrappingLabel wrappingLabelPeople; symantec.itools.multimedia.ImageViewer imageViewerLogo; symantec.itools.multimedia.SlideShow slideShowItinerary; java.awt.Label labelDay; java.awt.Button buttonNext; java.awt.Button buttonPrevious; symantec.itools.awt.WrappingLabel wrappingLabelDesc; //}} // Custom code: Add the following line to keep a copy of lAction to reattach to new instances of SlideShow. SymAction glAction; //{{DECLARE_MENUS java.awt.MenuBar mainMenuBar; java.awt.Menu menu1; java.awt.MenuItem miOpen; java.awt.MenuItem miExit; java.awt.Menu menu3; java.awt.MenuItem miAbout; //}} // Custom code: You must add this block of code to support external data files. // From here... private void getEntries(String dir, String filename) { try { DataInputStream in; int numEntries; in = new DataInputStream(new FileInputStream(filename)); try { wrappingLabelPeople.setText(in.readLine()); }catch (java.beans.PropertyVetoException pve) {} numEntries = Integer.parseInt(in.readLine()); dir = "file:/" + dir.substring(0, dir.lastIndexOf('\\')); for(int i = 0; i < numEntries; i++) { String s1 = dir + "/" + in.readLine(); String s2 = in.readLine(); slideShowItinerary.addImageAndDescription(new java.net.URL(s1), s2); } in.close(); invalidate(); validate(); } catch(FileNotFoundException e) { System.err.println("Can't open " + filename); } catch(IOException e) { System.err.println("Error reading " + filename); } } // ...up to here. class SymWindow extends java.awt.event.WindowAdapter { public void windowClosing(java.awt.event.WindowEvent event) { Object object = event.getSource(); if (object == AmazingTour.this) Frame1_WindowClosing(event); } } class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == miOpen) miOpen_Action(event); else if (object == miAbout) miAbout_Action(event); else if (object == miExit) miExit_Action(event); else if (object == buttonPrevious) buttonPrevious_Action(event); else if (object == buttonNext) buttonNext_Action(event); else if (object == slideShowItinerary) slideShowItinerary_SlideChanged(event); } } void buttonPrevious_Action(java.awt.event.ActionEvent event) { // to do: code goes here. //{{CONNECTION // Go to the SlideShow's previous image slideShowItinerary.previousImage(); //}} //{{CONNECTION // Set the text for Label... labelDay.setText("Day " + (--dayCount)); //}} } void buttonNext_Action(java.awt.event.ActionEvent event) { // to do: code goes here. //{{CONNECTION // Go to the SlideShow's next image slideShowItinerary.nextImage(); //}} //{{CONNECTION // Set the text for Label... labelDay.setText("Day " + (++dayCount)); //}} } void slideShowItinerary_SlideChanged(java.awt.event.ActionEvent event) { // to do: code goes here. //{{CONNECTION // Disable the Button on condition... Is at the last image? buttonNext.setEnabled(! slideShowItinerary.isAtLastImage()); //}} //{{CONNECTION // Disable the Button on condition... Is at the first image? buttonPrevious.setEnabled(! slideShowItinerary.isAtFirstImage()); //}} //{{CONNECTION // Set the text for WrappingLabel... Get current description { try { wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex())); } catch(java.beans.PropertyVetoException e) { } } //}} } }