View Javadoc

1   /*
2    * This file is part of NetPisteur.
3    * 
4    * Copyright 2001-2002 : Olivier CORNEC, David BOUANCHEAU, Loic LOPEZ,
5    *                       Gaetan BOUDARD, Mael LE LANNOU, Julien ROBINEAU
6    * 
7    * Copyright 2002-2003 : Olivier BRIENS, Simon DEZE, Florence FRIGOULT,
8    *                       Olivier JOURNEAULT, Francois MARTINIER, Damien RAUDE-MORVAN
9    * 
10   * Copyright 2004-2007 : Damien RAUDE-MORVAN
11   * 
12   * NetPisteur is free software; you can redistribute it and/or modify
13   * it under the terms of the GNU General Public License as published by
14   * the Free Software Foundation; either version 2 of the License, or
15   * (at your option) any later version.
16   *
17   * NetPisteur is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Public License for more details.
21   *
22   * You should have received a copy of the GNU General Public License
23   * along with NetPisteur; if not, write to the Free Software
24   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25   *
26   */
27  package com.drazzib.netpisteur.ui;
28  
29  import java.awt.BorderLayout;
30  import java.awt.event.ActionEvent;
31  import java.awt.event.ActionListener;
32  import java.awt.event.MouseAdapter;
33  import java.awt.event.MouseEvent;
34  import java.awt.event.WindowAdapter;
35  import java.awt.event.WindowEvent;
36  
37  import javax.swing.JFileChooser;
38  
39  import com.drazzib.netpisteur.util.HTMLFileFilter;
40  
41  /**
42   * Create an explorateur frame when the menu "Ouvrir..." is clicked
43   * 
44   * @author NetPisteur Team
45   */
46  public class ExplorerFrame extends javax.swing.JFrame {
47  
48  	/**
49  	 * 
50  	 */
51  	private static final long serialVersionUID = 6716999253322126130L;
52  
53  	JFileChooser fileChooser;
54  
55  	MainFrame win = null;
56  
57  	AdvancedOptionsFrame opt = null;
58  
59  	/** Creates new form */
60  	public ExplorerFrame(MainFrame env) {
61  		this.win = env;
62  		initComponents();
63  	}
64  
65  	/** Creates new form */
66  	public ExplorerFrame(AdvancedOptionsFrame env) {
67  		this.opt = env;
68  		initComponents();
69  	}
70  
71  	/**
72  	 * This method is called from within the constructor to initialize the form.
73  	 */
74  	private void initComponents() {
75  		this.fileChooser = new JFileChooser();
76  		this.fileChooser.setFileFilter(new HTMLFileFilter());
77  
78  		addWindowListener(new WindowAdapter() {
79  			public void windowClosing(WindowEvent evt) {
80  				exitForm(evt);
81  			}
82  		});
83  
84  		addMouseListener(new MouseAdapter() {
85  			public void mouseReleased(MouseEvent evt) {
86  				ExplorerFrame.this.fileChooser.approveSelection();
87  			}
88  		});
89  
90  		this.fileChooser.addActionListener(new ActionListener() {
91  
92  			public void actionPerformed(ActionEvent e) {
93  				String command = e.getActionCommand();
94  				if (command == null)
95  					return; // Can this happen? Probably not. Call me paranoid.
96  
97  				if (command.equals(JFileChooser.APPROVE_SELECTION)) {
98  					if (ExplorerFrame.this.win != null) {
99  						ExplorerFrame.this.win
100 								.loadPage(("file:" + ExplorerFrame.this.fileChooser
101 										.getSelectedFile()));
102 					} else {
103 						ExplorerFrame.this.opt
104 								.setAccueilPage(("file:" + ExplorerFrame.this.fileChooser
105 										.getSelectedFile()));
106 					}
107 					dispose();
108 				} else if (command.equals(JFileChooser.CANCEL_SELECTION))
109 					dispose();
110 			}
111 
112 		});
113 
114 		getContentPane().add(this.fileChooser, BorderLayout.NORTH);
115 
116 		pack();
117 	}
118 
119 	/** Exit the Application */
120 	void exitForm(WindowEvent evt) { // GEN-FIRST:event_exitForm
121 		dispose();
122 	}
123 
124 } // class explorateurFrame