home *** CD-ROM | disk | FTP | other *** search
Wrap
Java Source | 1997-02-04 | 10.2 KB | 329 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.*; import symantec.itools.awt.*; // Custom code: You must add this line below the line above. import java.io.*; 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 slideShowItinerary_SlideChanged(Event event) { //{{CONNECTION // Disable the Button on condition... Is at the last image? buttonNext.enable(! slideShowItinerary.isAtLastImage()); //}} //{{CONNECTION // Disable the Button on condition... Is at the first image? buttonPrevious.enable(! slideShowItinerary.isAtFirstImage()); //}} //{{CONNECTION // Set the text for WrappingLabel... Get current description { wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex())); } //}} } void buttonNext_Clicked(Event event) { //{{CONNECTION // Go to the SlideShow's next image slideShowItinerary.nextImage(); //}} //Custom code: Add the following four lines. //{{CONNECTION // Set the text for Label... labelDay.setText("Day " + (++dayCount)); //}} } void buttonPrevious_Clicked(Event event) { //{{CONNECTION // Go to the SlideShow's previous image slideShowItinerary.previousImage(); //}} //Custom code: Add the following four lines. //{{CONNECTION // Set the text for Label... labelDay.setText("Day " + (--dayCount)); //}} } void Open_Action(Event 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; slideShowItinerary = new symantec.itools.multimedia.SlideShow(); slideShowItinerary.reshape(insets().left + slideShowBounds.x,insets().top + slideShowBounds.y,slideShowBounds.width,slideShowBounds.height); add(slideShowItinerary); getEntries(openFileDialog1.getDirectory(), fileName); buttonNext.show(); buttonPrevious.show(); wrappingLabelTop.setText("Custom Itinerary for"); labelDay.setText("Day " + (dayCount)); wrappingLabelDesc.setText(slideShowItinerary.getDescription(slideShowItinerary.getCurrentImageIndex())); buttonPrevious.disable(); if(slideShowItinerary.isAtLastImage()) { buttonNext.disable(); } else { buttonNext.enable(); } // ...down to here. } void About_Action(Event event) { //{{CONNECTION // Action from About Create and show as modal (new AboutDialog(this, true)).show(); //}} } void Exit_Action(Event event) { //{{CONNECTION // Action from Exit Create and show as modal (new QuitDialog(this, true)).show(); //}} } public AmazingTour() { // Pre-load the classes so the current directory won't matter. // (The current directory could possibly change with the openFileDialog.) new AboutDialog(this, true); new QuitDialog(this, true); //{{INIT_CONTROLS setLayout(null); addNotify(); resize(insets().left + insets().right + 595,insets().top + insets().bottom + 550); setFont(new Font("Dialog", Font.BOLD, 12)); setForeground(new Color(0)); setBackground(new Color(16777215)); openFileDialog1 = new java.awt.FileDialog(this, "Open",FileDialog.LOAD); //$$ openFileDialog1.move(0,0); wrappingLabelStart = new symantec.itools.awt.WrappingLabel(); wrappingLabelStart.reshape(insets().left + 8,insets().top + 24,225,132); wrappingLabelStart.setFont(new Font("Dialog", Font.BOLD, 16)); add(wrappingLabelStart); wrappingLabelStart.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_LEFT); 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."); labelDay = new java.awt.Label("",Label.CENTER); labelDay.reshape(insets().left + 72,insets().top + 208,86,26); labelDay.setFont(new Font("Dialog", Font.ITALIC, 16)); add(labelDay); wrappingLabelPeople = new symantec.itools.awt.WrappingLabel(); wrappingLabelPeople.reshape(insets().left + 8,insets().top + 88,232,88); wrappingLabelPeople.setFont(new Font("Dialog", Font.BOLD, 24)); add(wrappingLabelPeople); wrappingLabelPeople.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED); wrappingLabelPeople.setText(""); slideShowItinerary = new symantec.itools.multimedia.SlideShow(); slideShowItinerary.reshape(insets().left + 251,insets().top + 219,340,235); add(slideShowItinerary); wrappingLabelDesc = new symantec.itools.awt.WrappingLabel(); wrappingLabelDesc.reshape(insets().left + 16,insets().top + 248,224,272); wrappingLabelDesc.setFont(new Font("Dialog", Font.PLAIN, 14)); add(wrappingLabelDesc); wrappingLabelDesc.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_LEFT); wrappingLabelDesc.setText(""); imageViewerLogo = new symantec.itools.multimedia.ImageViewer(); imageViewerLogo.reshape(insets().left + 256,insets().top + 16,320,217); add(imageViewerLogo); try { imageViewerLogo.setURL(symantec.itools.net.RelativeURL.getURL("Images/Logo.gif")); } catch (java.net.MalformedURLException error) { } buttonPrevious = new java.awt.Button("Previous"); buttonPrevious.hide(); buttonPrevious.reshape(insets().left + 336,insets().top + 496,82,25); add(buttonPrevious); buttonNext = new java.awt.Button("Next"); buttonNext.hide(); buttonNext.reshape(insets().left + 424,insets().top + 496,82,25); add(buttonNext); wrappingLabelTop = new symantec.itools.awt.WrappingLabel(); wrappingLabelTop.reshape(insets().left + 8,insets().top + 40,232,38); wrappingLabelTop.setFont(new Font("Dialog", Font.BOLD, 16)); add(wrappingLabelTop); wrappingLabelTop.setAlignStyle(symantec.itools.awt.WrappingLabel.ALIGN_CENTERED); wrappingLabelTop.setText(""); 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"); menu1.add("Open..."); menu1.addSeparator(); menu1.add("Exit"); mainMenuBar.add(menu1); menu3 = new java.awt.Menu("Help"); mainMenuBar.setHelpMenu(menu3); menu3.add("About"); mainMenuBar.add(menu3); setMenuBar(mainMenuBar); //$$ mainMenuBar.move(0,0); //}} } public AmazingTour(String title) { this(); setTitle(title); } public synchronized void show() { move(50, 50); super.show(); } public boolean handleEvent(Event event) { if (event.target == buttonPrevious && event.id == Event.ACTION_EVENT) { buttonPrevious_Clicked(event); } if (event.target == buttonNext && event.id == Event.ACTION_EVENT) { buttonNext_Clicked(event); } if (event.target == slideShowItinerary && event.id == Event.ACTION_EVENT) { slideShowItinerary_SlideChanged(event); } if (event.id == Event.WINDOW_DESTROY) { hide(); // hide the Frame dispose(); // free the system resources System.exit(0); // close the application return true; } return super.handleEvent(event); } public boolean action(Event event, Object arg) { if (event.target instanceof MenuItem) { String label = (String) arg; if (label.equalsIgnoreCase("Open...")) { Open_Action(event); return true; } else if (label.equalsIgnoreCase("About")) { About_Action(event); return true; } else if (label.equalsIgnoreCase("Exit")) { Exit_Action(event); return true; } } return super.action(event, arg); } static public void main(String args[]) { (new AmazingTour()).show(); } //{{DECLARE_CONTROLS java.awt.FileDialog openFileDialog1; symantec.itools.awt.WrappingLabel wrappingLabelStart; java.awt.Label labelDay; symantec.itools.awt.WrappingLabel wrappingLabelPeople; symantec.itools.multimedia.SlideShow slideShowItinerary; symantec.itools.awt.WrappingLabel wrappingLabelDesc; symantec.itools.multimedia.ImageViewer imageViewerLogo; java.awt.Button buttonPrevious; java.awt.Button buttonNext; symantec.itools.awt.WrappingLabel wrappingLabelTop; //}} //{{DECLARE_MENUS java.awt.MenuBar mainMenuBar; java.awt.Menu menu1; java.awt.Menu menu3; //}} // 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)); wrappingLabelPeople.setText(in.readLine()); 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. Notice the bracket at the end. }