www.pudn.com > DomView.zip > OpenFileDialog.java
/********************************************************************
Domview 1.0 displays contents of an XML DOM object
Copyright (C) 1999 The Bean Factory, LLC.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Author: Sun Koh, The Bean Factory, LLC.
*******************************************************************/
import java.awt.*; //AWT classes
import java.awt.event.*; //AWT event classes
import java.util.*; //Vectors, etc
import java.io.*; //Serializable, etc
import java.net.*; //Network classes
import javax.swing.*; //Swing classes
import javax.swing.event.*; //Swing events
import javax.swing.table.*; //JTable models
import javax.swing.tree.*; //JTree models
import javax.swing.border.*; //JComponent Borders
/********************************************************************
OpenFileDialog gets an XML file location
@version : 1.0
@author : Sun Koh
********************************************************************/
public class OpenFileDialog
extends JDialog
implements java.io.Serializable {
//
// Data Members
//
protected DomView mainFrame;
protected JLabel lFile;
protected JTextField tfFile;
protected JButton btnOpen;
protected JButton btnCancel;
//
// Methods
//
/**
Default Constructor
@param d DomView frame
*/
public OpenFileDialog(DomView d){
mainFrame = d;
this.setTitle("File Open");
this.setModal(true);
Container c = this.getContentPane();
lFile = new JLabel("XML file location: ");
tfFile = new JTextField();
tfFile.setColumns(10);
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS ));
p1.add(lFile);
p1.add(tfFile);
btnOpen = new JButton("Open");
btnCancel = new JButton("Cancel");
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
p2.add(btnOpen);
p2.add(btnCancel);
//register listener
btnOpen.addActionListener(new OpenAction(this));
btnCancel.addActionListener(new CancelAction(this));
c.setLayout(new GridLayout(2, 1));
c.add(p1 );
c.add(p2 );
pack();
setLocationRelativeTo(mainFrame);
show();
} //end method
/**
Return preferrred size of this panel
@return a dimension of the panel
*/
public Dimension getPreferredSize(){
return new Dimension(500, 100);
}
/**
Return minimun size of this panel
@return a dimension of the panel
*/
public Dimension getMinimunSize(){
return getPreferredSize();
}
/**
Open Action inner class
*/
protected class OpenAction implements ActionListener {
OpenFileDialog dialog;
/**
Constructor
*/
public OpenAction(OpenFileDialog f){
dialog = f;
}
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e) {
dialog.dispose();
mainFrame.panel.openFile(tfFile.getText());
}
}
/**
Cancel Action inner class
*/
protected class CancelAction implements ActionListener {
OpenFileDialog dialog;
/**
Constructor
*/
public CancelAction(OpenFileDialog f){
dialog = f;
}
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
}
}//end of OpenFileDialog class