1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  CPViz Constraint Visualization System
15// The Initial Developer of the Original Code is  Helmut Simonis
16// Portions created by the Initial Developer are
17// Copyright (C) 2009-2010 Helmut Simonis
18//
19// Contributor(s): 	Helmut Simonis, 4C, Univerity College Cork, Cork
20//			Paul Davern, 4C, Univerity College Cork, Cork
21//
22// END LICENSE BLOCK
23// ----------------------------------------------------------------------
24package components;
25
26
27import javax.help.HelpBroker;
28import javax.help.HelpSet;
29import javax.help.SwingHelpUtilities;
30import javax.swing.AbstractAction;
31import javax.swing.Action;
32import javax.swing.JButton;
33import javax.swing.JComponent;
34import javax.swing.JFileChooser;
35import javax.swing.JInternalFrame;
36import javax.swing.JDesktopPane;
37import javax.swing.JMenu;
38import javax.swing.JMenuItem;
39import javax.swing.JMenuBar;
40import javax.swing.JFrame;
41import javax.swing.JOptionPane;
42import javax.swing.JPanel;
43import javax.swing.JSlider;
44import javax.swing.JToolBar;
45import javax.swing.KeyStroke;
46import javax.swing.Timer;
47import javax.swing.UIManager;
48import javax.swing.event.ChangeEvent;
49
50
51import org.apache.batik.util.Service;
52//import org.apache.batik.util.gui.resource.ActionMap;
53//import org.apache.batik.util.gui.resource.JComponentModifier;
54//import org.apache.batik.util.gui.resource.JToolbarButton;
55//import org.apache.batik.util.gui.resource.MissingListenerException;
56//import org.apache.batik.util.gui.resource.ToolBarFactory;
57import org.apache.batik.util.resources.ResourceManager;
58
59import java.awt.event.*;
60import java.awt.geom.AffineTransform;
61import java.awt.*;
62import java.io.BufferedReader;
63import java.io.BufferedWriter;
64import java.io.File;
65import java.io.FileNotFoundException;
66import java.io.FileReader;
67import java.io.FileWriter;
68import java.io.IOException;
69import java.net.URL;
70import java.util.Collection;
71import java.util.HashMap;
72import java.util.Iterator;
73import java.util.LinkedList;
74import java.util.List;
75import java.util.Locale;
76import java.util.Map;
77import java.util.ResourceBundle;
78import java.util.Vector;
79
80/*
81 * InternalFrameDemo.java requires:
82 *   MyInternalFrame.java
83 */
84public class InternalFrame extends JFrame
85                               implements ActionListener,
86                                ActionMap{
87	 public static final int FILESSTARTPOS = 2;
88	 public static final int NOFILEITEMS = 4;
89	 public static final String ABOUT_ACTION = "AboutAction";
90	    public static final String OPEN_ACTION = "OpenAction";
91	    public static final String OPEN_LOCATION_ACTION = "OpenLocationAction";
92	    public static final String NEW_WINDOW_ACTION = "NewWindowAction";
93	    public static final String RELOAD_ACTION = "ReloadAction";
94	    public static final String SAVE_AS_ACTION = "SaveAsAction";
95	    public static final String BACK_ACTION = "BackAction";
96	    public static final String FORWARD_ACTION = "ForwardAction";
97	    public static final String MOVIE_SETUP_ACTION = "MovieSetupAction";
98	    public static final String END_BACK_ACTION = "EndBackAction";
99	    public static final String END_FORWARD_ACTION = "EndForwardAction";
100	    public static final String FAST_FORWARD_ACTION = "FastForwardAction";
101	    public static final String REWIND_ACTION = "RewindAction";
102	    public static final String FULL_SCREEN_ACTION = "FullScreenAction";
103	    public static final String PRINT_ACTION = "PrintAction";
104	    public static final String EXPORT_AS_JPG_ACTION = "ExportAsJPGAction";
105	    public static final String EXPORT_AS_PNG_ACTION = "ExportAsPNGAction";
106	    public static final String EXPORT_AS_TIFF_ACTION = "ExportAsTIFFAction";
107	    public static final String PREFERENCES_ACTION = "PreferencesAction";
108	    public static final String CLOSE_ACTION = "CloseAction";
109	    public static final String VIEW_SOURCE_ACTION = "ViewSourceAction";
110	    public static final String EXIT_ACTION = "ExitAction";
111	    public static final String RESET_TRANSFORM_ACTION = "ResetTransformAction";
112	    public static final String ZOOM_IN_ACTION = "ZoomInAction";
113	    public static final String ZOOM_OUT_ACTION = "ZoomOutAction";
114	    public static final String PREVIOUS_TRANSFORM_ACTION = "PreviousTransformAction";
115	    public static final String NEXT_TRANSFORM_ACTION = "NextTransformAction";
116	    public static final String USE_STYLESHEET_ACTION = "UseStylesheetAction";
117	    public static final String PLAY_ACTION = "PlayAction";
118	    public static final String PAUSE_ACTION = "PauseAction";
119	    public static final String STOP_ACTION = "StopAction";
120	    public static final String MONITOR_ACTION = "MonitorAction";
121	    public static final String DOM_VIEWER_ACTION = "DOMViewerAction";
122	    public static final String SET_TRANSFORM_ACTION = "SetTransformAction";
123	    public static final String FIND_DIALOG_ACTION = "FindDialogAction";
124	    public static final String THUMBNAIL_DIALOG_ACTION = "ThumbnailDialogAction";
125	    public static final String FLUSH_ACTION = "FlushAction";
126	    public static final String TOGGLE_DEBUGGER_ACTION = "ToggleDebuggerAction";
127public static	String initfilename;
128private HelpSet hs;
129private HelpBroker hb;
130private URL hsURL;
131    JDesktopPane desktop;
132    JSlider slide_images = new JSlider();
133    int WhichIndex = 0;
134    String LeftFileName;
135    String ThePath;
136    Dimension OldSize=null;
137    MyInternalFrame left;
138    MyInternalFrame right;
139    JMenuBar TheMenuBar=null;
140    boolean doSlideradjust = true;
141    protected BackAction backAction = new BackAction();
142    protected EndBackAction endbackAction = new EndBackAction();
143
144    /**
145     * The forward action
146     */
147    protected ForwardAction forwardAction = new ForwardAction();
148    protected EndForwardAction endforwardAction = new EndForwardAction();
149    protected FastForwardAction fastforwardAction = new FastForwardAction();
150    protected RewindAction rewindAction = new RewindAction();
151    protected StopAction stopAction = new StopAction();
152    protected MovieSetupAction moviesetupAction = new MovieSetupAction();
153
154    public static final String RESOURCES =
155        "components.resources.GUI";
156protected static ResourceBundle bundle;
157
158/**
159 * The resource manager
160 */
161protected static ResourceManager resources;
162static {
163    bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault());
164    resources = new ResourceManager(bundle);
165}
166
167
168protected Map listeners = new HashMap();
169
170/**
171 * Returns the action associated with the given string
172 * or null on error
173 * @param key the key mapped with the action to get
174 * @throws MissingListenerException if the action is not found
175 */
176public Action getAction(String key) throws MissingListenerException {
177    Action result = (Action)listeners.get(key);
178   // System.out.println("The Action"+result);
179    //if (result == null) {
180    //result = canvas.getAction(key);
181    //}
182    if (result == null) {
183        throw new MissingListenerException("Can't find action.", RESOURCES, key);
184    }
185    return result;
186}
187    public InternalFrame() {
188        super("ECLiPSe Visualizer");
189        try {
190      	  UIManager.setLookAndFeel(
191      	    UIManager.getSystemLookAndFeelClassName());
192      	} catch (Exception e) {
193      	}
194        ThePath = System.getProperty("user.dir");
195        //Make the big window be indented 50 pixels from each edge
196        //of the screen.
197        int inset = 50;
198        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
199        setBounds(inset, inset,
200                  screenSize.width  - inset*2,
201                  screenSize.height - inset*2);
202        listeners.put(OPEN_ACTION, new OpenAction());
203       // listeners.put(OPEN_LOCATION_ACTION, new OpenLocationAction());
204       listeners.put(BACK_ACTION, backAction);
205       listeners.put(END_BACK_ACTION, endbackAction);
206        listeners.put(FORWARD_ACTION, forwardAction);
207        listeners.put(END_FORWARD_ACTION, endforwardAction);
208        listeners.put(MOVIE_SETUP_ACTION, moviesetupAction);
209        listeners.put(REWIND_ACTION, rewindAction);
210        listeners.put(FAST_FORWARD_ACTION, fastforwardAction);
211        listeners.put(STOP_ACTION, stopAction);
212       // listeners.put(EXIT_ACTION, application.createExitAction(this));
213        listeners.put(THUMBNAIL_DIALOG_ACTION, new ThumbnailDialogAction());
214
215        //Set up the GUI.
216        desktop = new JDesktopPane(); //a specialized layered pane
217        left = createFrame(); //create first "window"
218        right = createFrame();
219        left.setSize((screenSize.width  - inset*3)/2,screenSize.height - inset*4);
220        //Set the window's location.
221        left.setLocation(0, 0);
222        right.setSize((screenSize.width  - inset*3)/2,screenSize.height - inset*4);
223        JPanel p = new JPanel(new BorderLayout());
224        //Set the window's location.
225        right.setLocation((screenSize.width  - inset*3)/2, 30);
226        ToolBarFactory tbf = new ToolBarFactory(bundle, this);
227        JToolBar tb = tbf.createJToolBar("ToolBar");
228        tb.setFloatable(false);
229        p.add(tb, BorderLayout.NORTH);
230        for (int iu=0;iu<10;iu++){
231        	Component c = tb.getComponentAtIndex(iu);
232        	//System.out.println("Compoent "+iu+" "+c);
233        	if (c!=null){
234        		try{
235        		JToolbarButton b = (JToolbarButton)c;
236        		//System.out.println("icon "+b.getIcon());
237        		}catch (Exception ee){
238        		//	System.out.println("exp");
239        		}
240        	}
241        }
242        p.add(slide_images,BorderLayout.SOUTH);
243        getContentPane().add(p, BorderLayout.NORTH);
244        getContentPane().add(desktop, BorderLayout.CENTER);
245       // setContentPane(desktop);
246        TheMenuBar = createMenuBar();
247        setJMenuBar(TheMenuBar);
248
249        //Make dragging a little faster but perhaps uglier.
250        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
251        addComponentListener(new ComponentAdapter() {
252            public void componentResized(ComponentEvent e) {
253         	 Dimension d = desktop.getSize();
254         	 if (OldSize != null){
255         		 Dimension l = left.getSize();
256         		 Dimension r = right.getSize();
257         		 int x = (int)(d.getWidth()* l.getWidth()/OldSize.getWidth());
258         		 int y = (int)(d.getHeight()* l.getHeight()/OldSize.getHeight());
259         		 left.setSize(x,y);
260         		 int rx = (int)(d.getWidth()* r.getWidth()/OldSize.getWidth());
261         		 int ry = (int)(d.getHeight()* r.getHeight()/OldSize.getHeight());
262         		 right.setSize(rx,ry);
263         		 left.setLocation(0,0);
264         		 right.setLocation(x,0);
265         	 }
266         	 else{
267         	  	left.setSize((int)(d.getWidth()/2),(int)(d.getHeight()));
268         	    right.setSize((int)(d.getWidth()/2),(int)(d.getHeight()));
269         	    right.setLocation((int)(d.getWidth()/2),0);
270         	 }
271         	OldSize = d;
272            	//System.out.println("JSVG canvas component resize listener");
273
274      	   }
275
276
277
278        });
279        slide_images.setValue(1);
280        slide_images.setMaximum(100);
281        slide_images.addChangeListener(new javax.swing.event.ChangeListener() {
282            public void stateChanged(ChangeEvent e) {
283            	JSlider source = (JSlider)e.getSource();
284                //if (!source.getValueIsAdjusting())
285                {
286                if (doSlideradjust){
287                	float fps = source.getValue();
288                	float pos;
289                	pos = fps/100;
290                	Iterator ii = FileNames.iterator();
291                	int size = FileNames.size();
292                	if (size == 0) return;
293                	int num = (int)(size * pos);
294                	if (fps>0.0)
295                	num = (int)fps-1;
296                	else
297                		num=0;
298                	//if ( num %2 == 1) num--;
299                //	System.out.println("num is"+num+"fps"+fps+" size "+size);
300                	int i=0;
301                	boolean didit=false;
302                	if (source.getValueIsAdjusting()){//&&firstAdjust){
303                		//AffineTransform at = activePane.svgCanvas.getRenderingTransform();
304                		//if (activePane == leftpane)
305                		   // leftoldTransform = leftpane.svgCanvas.getRenderingTransform();;
306                		//else
307                			//rightoldTransform = rightpane.svgCanvas.getRenderingTransform();;
308                		//firstAdjust = false;
309                	}
310                	if (!source.getValueIsAdjusting()){
311                		//firstAdjust = true;
312                	}
313
314                	boolean found;
315                	ii = FileNames.iterator();
316             //   	while (ii.hasNext ()) {
317                		String filenames[] = (String[])(FileNamesarr[num]);//(ii.next());
318                	//	if (i==num ){//&& !filenames[0].equals(LeftFileName)){
319                			WhichIndex = num;
320                			/*if (!LeftFileName.equals("")){
321                				didit = true;
322                        		System.out.println("done transform possibly");
323                        		Iterator iii = activePane.svgCanvas.getInteractors().iterator();
324                        		while (iii.hasNext()){
325                        			Object o = iii.next();
326                        			if (o.getClass().getName().equals("org.apache.batik.swing.gvt.AbstractZoomInteractor")){
327                        				AbstractZoomInteractor azi = (AbstractZoomInteractor)o;
328                        				//azi.
329                        				found = true;
330                        			}
331                        			System.out.println("Interactor "+o);
332                        	//	listInteractors.add(o);
333                        		}
334                        	}*/
335
336                			//System.out.println("got the num");
337                			LeftFileName = filenames[0];
338                			String ss= "file:///"+ThePath+filenames[0];
339                			String ss1 = "file:///"+ThePath+filenames[1];
340                			//System.out.println("uri="+ss);
341                			//leftpane.svgCanvas.setURI("file:///"+ThePath+filenames[0]);
342                			//rightpane.svgCanvas.setURI("file:///"+ThePath+filenames[1]);
343                			left.setURI(ss);
344                			right.setURI(ss1);
345                			//drawSVG(ss,ss1);
346                		//	break;
347                	//	}
348                		i++;
349                	//}
350                }
351               else
352              	doSlideradjust=true;
353
354                }
355            }
356            });
357        if (initfilename!=null){
358        	fileopen(initfilename,true);
359        }
360    }
361
362    protected JMenuBar createMenuBar() {
363        JMenuBar menuBar = new JMenuBar();
364
365        //Set up the lone menu.
366        JMenu menu = new JMenu("File");
367        menu.setMnemonic(KeyEvent.VK_D);
368        menuBar.add(menu);
369
370        //Set up the first menu item.
371        JMenuItem menuItem = new JMenuItem("Open");
372        menuItem.setMnemonic(KeyEvent.VK_O);
373        menuItem.setAccelerator(KeyStroke.getKeyStroke(
374                KeyEvent.VK_O, ActionEvent.ALT_MASK));
375        menuItem.setActionCommand("open");
376        menuItem.addActionListener(this);
377        menu.add(menuItem);
378        menu.addSeparator();
379
380
381        //Set up the second menu item.
382        try {
383			FileReader fr = new FileReader("history.hist");
384			BufferedReader br = new BufferedReader(fr);
385			String s;
386			try {
387				int i=0;
388				while((s = br.readLine()) != null && i<4) {
389					if (s.length()<2)
390						break;
391					int pos = s.lastIndexOf("/");
392		    		if (pos==-1)
393		    			pos = s.lastIndexOf("\\");
394					menuItem = new JMenuItem(s.substring(pos+1));
395				    menuItem.setActionCommand("visited");
396				    menuItem.setToolTipText(s);
397				    menuItem.addActionListener(this);
398				    menu.add(menuItem);
399				    i++;
400				}
401				fr.close();
402			} catch (IOException e) {
403				// TODO Auto-generated catch block
404				e.printStackTrace();
405			}
406			menu.addSeparator();
407			 //Set up the last menu item.
408	        menuItem = new JMenuItem("Quit");
409	        menuItem.setMnemonic(KeyEvent.VK_Q);
410	        menuItem.setAccelerator(KeyStroke.getKeyStroke(
411	                KeyEvent.VK_Q, ActionEvent.ALT_MASK));
412	        menuItem.setActionCommand("quit");
413	        menuItem.addActionListener(this);
414	        menu.add(menuItem);
415	        menu = new JMenu("Help");
416	        menu.setMnemonic(KeyEvent.VK_D);
417	        menuBar.add(menu);
418	        menuItem = new JMenuItem("Contents");
419	        menuItem.setMnemonic(KeyEvent.VK_H);
420	        menuItem.setAccelerator(KeyStroke.getKeyStroke(
421	                KeyEvent.VK_H, ActionEvent.ALT_MASK));
422	        menuItem.setActionCommand("help");
423	        menuItem.addActionListener(this);
424	        menu.add(menuItem);
425		} catch (FileNotFoundException e) {
426			// TODO Auto-generated catch block
427			e.printStackTrace();
428		}
429
430
431        return menuBar;
432    }
433    protected static Vector handlers;
434    /**
435     * Registers an input file handler by adding it to the handlers map.
436     * @param handler the new input handler to register.
437     */
438    public static synchronized
439        void registerHandler(SquiggleInputHandler handler) {
440        Vector handlers = getHandlers();
441        handlers.addElement(handler);
442    }
443    public class OpenAction extends AbstractAction {
444
445        public OpenAction() {
446        }
447        public void actionPerformed(ActionEvent e) {
448        	fileopen(null,true);
449        }
450    }
451    Collection FileNames = new LinkedList();
452    Object[] FileNamesarr = null;
453    protected static Vector getHandlers() {
454        if (handlers != null) {
455            return handlers;
456        }
457
458        handlers = new Vector();
459        registerHandler(new SVGInputHandler());
460
461        Iterator iter = Service.providers(SquiggleInputHandler.class);
462        while (iter.hasNext()) {
463            SquiggleInputHandler handler
464                = (SquiggleInputHandler)iter.next();
465
466            registerHandler(handler);
467        }
468
469        return handlers;
470    }
471
472    public void fileopen(String fname, boolean addHistory){
473    	JFileChooser fileChooser = null;
474   	 File f =null;
475    	if (fname == null){
476    	 fileChooser = new JFileChooser(ThePath);
477        fileChooser.setFileHidingEnabled(false);
478        fileChooser.setFileSelectionMode
479            (JFileChooser.FILES_ONLY);
480
481        //
482        // Add file filters from the handlers map
483        //get rid of zip file expandsion
484        // regsvr32 /u %windir%\system32\zipfldr.dll
485        // regsvr32 %windir%\system32\zipfldr.dll
486
487
488
489        Iterator iter = getHandlers().iterator();
490        while (iter.hasNext()) {
491            SquiggleInputHandler handler
492                = (SquiggleInputHandler)iter.next();
493            fileChooser.addChoosableFileFilter
494                (new SquiggleInputHandlerFilter(handler));
495        }
496//System.out.println("do filechooser");
497        int choice = fileChooser.showOpenDialog(this);
498
499        if (choice == JFileChooser.APPROVE_OPTION) {
500            f = fileChooser.getSelectedFile();
501            //activePane.currentPath = f;
502        }
503    	}
504    	else
505    		f = new File(fname);
506    if (f != null){
507    	try {
508    		//System.out.println("file name:"+f.getPath());
509    		FileReader fr = new FileReader(f);
510    		FileNames.clear();
511    		BufferedReader br = new BufferedReader(fr);
512    		String s;
513    		try {
514				while((s = br.readLine()) != null) {
515					int x = s.indexOf(' ');
516					String left = s.substring(0, x);
517					String right = s.substring(x+1,s.length());
518					String p = f.getAbsolutePath();
519					x = p.lastIndexOf('\\');
520					if ( x == -1){
521						x = p.lastIndexOf('/');
522					}
523					p = p.substring(0,x+1);
524					ThePath = p;
525					FileNames.add(new String[]{left,right});
526				//System.out.println("x "+x+" left "+left+" right "+right+" path "+p + "oldpath= "+f.getAbsolutePath());
527				}
528			fr.close();
529			FileNamesarr = FileNames.toArray();
530			slide_images.setValue(1);
531            slide_images.setMaximum(FileNames.size());
532            left.SetVeryFirst(true);
533            right.SetVeryFirst(true);
534            if (addHistory){
535            	JMenu jm = TheMenuBar.getMenu(0);
536            	int max = jm.getItemCount();
537            	int i=2;
538            	int x=0;
539            	if (max-NOFILEITEMS >=4){
540            		x=1;
541            		jm.remove(jm.getItem(FILESSTARTPOS+3));
542            	}
543            	s = f.getName();
544            	int pos = s.lastIndexOf("/");
545	    		if (pos==-1)
546	    			pos = s.lastIndexOf("\\");
547            	JMenuItem menuItem = new JMenuItem(f.getName());//(s.substring(pos+1));
548			    menuItem.setActionCommand("visited");
549			    menuItem.setToolTipText(f.getAbsolutePath());
550			    menuItem.addActionListener(this);
551			    jm.add(menuItem,FILESSTARTPOS);//-x+(max-NOFILEITEMS));
552			    FileWriter fw = new FileWriter("history.hist");
553				BufferedWriter bw = new BufferedWriter(fw);
554				max = jm.getItemCount();
555				for (i=FILESSTARTPOS;i<max-(NOFILEITEMS-FILESSTARTPOS);i++){
556					menuItem = jm.getItem(i);
557					bw.write(menuItem.getToolTipText());
558					bw.newLine();
559				}
560				bw.close();
561
562            }
563			} catch (IOException e1) {
564				// TODO Auto-generated catch block
565				e1.printStackTrace();
566			}
567    		try {
568				fr.close();
569			} catch (IOException e1) {
570				// TODO Auto-generated catch block
571				e1.printStackTrace();
572			}
573
574
575
576		} catch (FileNotFoundException e1) {
577			// TODO Auto-generated catch block
578			e1.printStackTrace();
579		}
580    }
581    }
582    //React to menu selections.
583    public void actionPerformed(ActionEvent e) {
584        if ("open".equals(e.getActionCommand())) { //new
585            fileopen(null,true);
586        }
587        if ("visited".equals(e.getActionCommand())) { //new
588        	JMenuItem ji = (JMenuItem)e.getSource();
589        	String fname = ji.getToolTipText();
590        	fileopen(fname,false);
591        }
592        if ("help".equals(e.getActionCommand())) { //new
593        	openHelp();
594        }
595       // else { //quit
596         //   quit();
597        //}
598    }
599    /**
600     * To go forward to the next document
601     */
602    public class ForwardAction extends    AbstractAction
603                               implements JComponentModifier {
604       List components = new LinkedList();
605        public ForwardAction() {}
606
607        /*public void actionPerformed(ActionEvent e) {
608         //   if (localHistory.canGoForward()) {
609                localHistory.forward();
610            }
611        }*/
612        public void actionPerformed(ActionEvent arg0) {
613	//		System.out.println("Right");
614			if (FileNames.size()>0 && WhichIndex != FileNames.size()-1){
615				//System.out.println("Right after if");
616				WhichIndex++;
617				float fps = slide_images.getValue();
618            	float pos;
619            	pos = fps/100;
620            	int size = FileNames.size();
621            	int num = (int)(size * pos);
622            	doSlideradjust=false;
623            	slide_images.setValue(WhichIndex);
624				String filenames[] = (String[])((LinkedList)FileNames).get(WhichIndex);
625				String ss= "file:///"+ThePath+filenames[0];
626    			String ss1 = "file:///"+ThePath+filenames[1];
627    		//	System.out.println("uri="+ss);
628      			left.setURI(ss);
629    			right.setURI(ss1);
630			}
631
632		}
633
634        public void addJComponent(JComponent c) {
635//            components.add(c);
636//            c.setEnabled(false);
637        }
638
639        protected void update() {
640
641        }
642    }
643    class MyActionListener implements ActionListener{
644
645			public void actionPerformed(ActionEvent arg0) {
646			// TODO Auto-generated method stub
647			if ( GoBack )
648				if ( WhichIndex == 0){
649					timeractive=false;
650					TheTimer.stop();
651				}
652				else
653					backAction.actionPerformed(null);
654			else{
655				if ( WhichIndex == FileNames.size()-1){
656					timeractive=false;
657					TheTimer.stop();
658				}
659				else
660				   forwardAction.actionPerformed(null);
661			}
662			}
663
664    }
665    MyActionListener timeraction = new MyActionListener();
666    boolean timeractive = false;
667    int TheTimerDelay = 400;
668    Timer TheTimer = new Timer(TheTimerDelay, timeraction);
669    boolean GoBack = false;
670    /**
671     * To go forward to the next document
672     */
673    public class RewindAction extends    AbstractAction
674                               implements JComponentModifier {
675       List components = new LinkedList();
676        public RewindAction() {}
677
678        /*public void actionPerformed(ActionEvent e) {
679         //   if (localHistory.canGoForward()) {
680                localHistory.forward();
681            }
682        }*/
683        public void actionPerformed(ActionEvent arg0) {
684        	if(FileNames.size()==0 ) return;
685			//System.out.println("Left");
686			if (!timeractive){
687				TheTimer.start();
688				timeractive = true;
689			}
690				GoBack = true;
691
692			}
693
694        public void addJComponent(JComponent c) {
695//            components.add(c);
696//            c.setEnabled(false);
697        }
698
699        protected void update() {
700
701        }
702    }
703    /**
704     * To go forward to the next document
705     */
706    public class FastForwardAction extends    AbstractAction
707                               implements JComponentModifier {
708       List components = new LinkedList();
709        public FastForwardAction() {}
710
711        /*public void actionPerformed(ActionEvent e) {
712         //   if (localHistory.canGoForward()) {
713                localHistory.forward();
714            }
715        }*/
716        public void actionPerformed(ActionEvent arg0) {
717		//	System.out.println("FAst Forward");
718		//	System.out.println("Left");
719			if(FileNames.size()==0 ) return;
720			if (!timeractive){
721				TheTimer.start();
722				timeractive = true;
723			}
724				GoBack = false;
725
726		}
727
728        public void addJComponent(JComponent c) {
729//            components.add(c);
730//            c.setEnabled(false);
731        }
732
733        protected void update() {
734
735        }
736    }
737
738    public class StopAction extends    AbstractAction{
739
740		@Override
741		public void actionPerformed(ActionEvent arg0) {
742			// TODO Auto-generated method stub
743			TheTimer.stop();
744			timeractive = false;
745		}
746
747    }
748    public class EndBackAction extends    AbstractAction{
749
750		@Override
751		public void actionPerformed(ActionEvent arg0) {
752			// TODO Auto-generated method stub
753			if (timeractive){
754			TheTimer.stop();
755			timeractive = false;
756			}
757			if (FileNames.size()>0 ){
758				//System.out.println("Right after if");
759				WhichIndex = 0;
760				doSlideradjust=false;
761            	slide_images.setValue(WhichIndex);
762				String filenames[] = (String[])((LinkedList)FileNames).get(WhichIndex);
763				String ss= "file:///"+ThePath+filenames[0];
764    			String ss1 = "file:///"+ThePath+filenames[1];
765    		//	System.out.println("uri="+ss);
766      			left.setURI(ss);
767    			right.setURI(ss1);
768			}
769		}
770
771    }
772    public class EndForwardAction extends    AbstractAction{
773
774		@Override
775		public void actionPerformed(ActionEvent arg0) {
776			// TODO Auto-generated method stub
777			if (timeractive){
778			TheTimer.stop();
779			timeractive = false;
780			}
781			if (FileNames.size()>0 ){
782				//System.out.println("Right after if");
783				WhichIndex = FileNames.size()-1;
784				doSlideradjust=false;
785            	slide_images.setValue(WhichIndex);
786				String filenames[] = (String[])((LinkedList)FileNames).get(WhichIndex);
787				String ss= "file:///"+ThePath+filenames[0];
788    			String ss1 = "file:///"+ThePath+filenames[1];
789    		//	System.out.println("uri="+ss);
790      			left.setURI(ss);
791    			right.setURI(ss1);
792			}
793		}
794
795    }
796    public class MovieSetupAction extends    AbstractAction{
797
798		@Override
799		public void actionPerformed(ActionEvent arg0) {
800			// TODO Auto-generated method stub
801			Object[] possibilities = {"500", "1000","1500","2000","2500"};
802			String s = (String)JOptionPane.showInputDialog(
803			                    desktop,
804			                    "Select the delay between documents in milliseconds\n",
805			                    "Customized Dialog",
806			                    JOptionPane.PLAIN_MESSAGE,
807			                    null,
808			                    possibilities,
809			                    ""+TheTimerDelay );
810//System.out.println("return from dialog "+s);
811			//If a string was returned, say so.
812			if ((s != null) && (s.length() > 2)) {
813			    //setLabel("Green eggs and... " + s + "!");
814				TheTimerDelay = Integer.valueOf(s).intValue();
815			//	System.out.println("timer delay "+TheTimerDelay);
816				TheTimer.setDelay(TheTimerDelay);
817			    return;
818			}
819
820			//If you're here, the return value was null/empty.
821			//setLabel("Come on, finish the sentence!");
822
823
824		}
825
826    }
827
828    public void openHelp() {
829        // Identify the location of the .hs file
830        String pathToHS = "/javahelp/docs/helpset.hs";
831        //Create a URL for the location of the help set
832        try {
833        	SwingHelpUtilities.setContentViewerUI("components.ExternalLinkContentViewerUI");
834
835          URL hsURL = getClass().getResource(pathToHS);
836            hs = new HelpSet(null, hsURL);
837         // hs = new HelpSet(null,
838        	//	  new URL("file:///c:/documents and settings/pdavern/my documents/firsthelp/helpset.hs"));
839        } catch (Exception ee) {
840            // Print info to the console if there is an exception
841        //    System.out.println( "HelpSet " + ee.getMessage());
842        //    System.out.println("Help Set "+ pathToHS +" not found");
843            return;
844        }
845
846        // Create a HelpBroker object for manipulating the help set
847        hb = hs.createHelpBroker();
848        //Display help set
849        hb.setDisplayed(true);
850    }
851
852    public class ExitAction extends    AbstractAction{
853
854		@Override
855		public void actionPerformed(ActionEvent arg0) {
856			// TODO Auto-generated method stub
857
858		}
859
860    }
861    public class BackAction extends    AbstractAction
862    implements JComponentModifier {
863    		List components = new LinkedList();
864    			public BackAction() {//System.out.println("left");
865
866    			}
867
868    			public void actionPerformed(ActionEvent arg0) {
869    			//	System.out.println("Left");
870    				if (FileNames.size() >0 && WhichIndex != 0){
871    					WhichIndex--;
872    					float fps = slide_images.getValue();
873    	            	float pos;
874    	            	pos = fps/100;
875    	            	int size = FileNames.size();
876    	            	int num = (int)(size * pos);
877    	            	doSlideradjust=false;
878    	            	slide_images.setValue(WhichIndex);
879    					String filenames[] = (String[])((LinkedList)FileNames).get(WhichIndex);
880    					String ss= "file:///"+ThePath+filenames[0];
881    	    			String ss1 = "file:///"+ThePath+filenames[1];
882    	    		//	System.out.println("uri="+ss);
883    	    			left.setURI(ss);
884    	    			right.setURI(ss1);
885    				}
886    			}
887
888
889    			public void addJComponent(JComponent c) {
890//          components.add(c);
891//c.setEnabled(false);
892    			}
893
894    			protected void update() {
895/*boolean b = localHistory.canGoBack();
896Iterator it = components.iterator();
897while (it.hasNext()) {
898((JComponent)it.next()).setEnabled(b);
899}*/
900    			}
901}
902
903    /**
904     * To display the Thumbnail dialog
905     */
906    public class ThumbnailDialogAction extends AbstractAction {
907        public ThumbnailDialogAction() {}
908        public void actionPerformed(ActionEvent e) {
909
910        }
911    }
912
913    //Create a new internal frame.
914    protected  MyInternalFrame createFrame() {
915        MyInternalFrame frame = new MyInternalFrame();
916        frame.setVisible(true); //necessary as of 1.3
917        desktop.add(frame);
918        try {
919            frame.setSelected(true);
920        } catch (java.beans.PropertyVetoException e) {}
921        return frame;
922    }
923
924    //Quit the application.
925    protected void quit() {
926        System.exit(0);
927    }
928
929    /**
930     * Create the GUI and show it.  For thread safety,
931     * this method should be invoked from the
932     * event-dispatching thread.
933     */
934    private static void createAndShowGUI() {
935        //Make sure we have nice window decorations.
936        JFrame.setDefaultLookAndFeelDecorated(false);
937
938        //Create and set up the window.
939        InternalFrame frame = new InternalFrame();
940        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
941
942        //Display the window.
943        frame.setVisible(true);
944    }
945
946    public static void main(String[] args) {
947        //Schedule a job for the event-dispatching thread:
948        //creating and showing this application's GUI.
949    	if (args.length !=0){
950    		initfilename = args[0];
951    	}
952        javax.swing.SwingUtilities.invokeLater(new Runnable() {
953            public void run() {
954                createAndShowGUI();
955            }
956        });
957    }
958}
959
960