package com.dbxml.db.admin.dialogs;
/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: FilesystemDialog.java,v 1.3 2006/02/02 18:53:46 bradford Exp $
*/
import java.awt.*;
import javax.swing.*;
import com.dbxml.db.admin.Admin;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import javax.swing.border.Border;
/**
* FilesystemDialog
*/
public final class FilesystemDialog extends JDialog {
ImageIcon imgFilesystem;
JLabel lblConnect = new JLabel();
Border brdSearch;
GridBagLayout thisLayout = new GridBagLayout();
JPanel pnlButtons = new JPanel();
JButton btnAttach = new JButton();
JButton btnCancel = new JButton();
JLabel lblDirectory = new JLabel();
JLabel lblLabel = new JLabel();
JTextField txtLabel = new JTextField();
BorderLayout pnlButtonsLayout = new BorderLayout();
JPanel pnlDialog = new JPanel();
JTextField txtDirectory = new JTextField();
JButton btnBrowse = new JButton();
public FilesystemDialog(Frame owner) {
super(owner, true);
testRequired();
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
pack();
// Center the Dialog
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}
catch ( Exception e ) {
Admin.getInstance().addMessage(e.toString());
}
}
private void jbInit() throws Exception {
imgFilesystem = new ImageIcon(FilesystemDialog.class.getResource("filesystem.gif"));
brdSearch = BorderFactory.createEmptyBorder(5, 5, 5, 5);
lblConnect.setIcon(imgFilesystem);
this.setModal(true);
this.setTitle("Attach Filesystem");
this.setResizable(false);
btnBrowse.setFont(new Font("Dialog", 0, 12));
btnBrowse.setActionCommand("browse");
btnBrowse.setText("browse");
btnBrowse.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnBrowse_actionPerformed(e);
}
});
this.getContentPane().add(pnlDialog);
pnlDialog.setLayout(thisLayout);
pnlButtons.setLayout(pnlButtonsLayout);
btnAttach.setFont(new Font("Dialog", 0, 12));
btnAttach.setActionCommand("connect");
btnAttach.setSelected(true);
btnAttach.setText("attach");
btnAttach.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnAttach_actionPerformed(e);
}
});
btnCancel.setFont(new Font("Dialog", 0, 12));
btnCancel.setActionCommand("cancel");
btnCancel.setText("cancel");
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnCancel_actionPerformed(e);
}
});
lblDirectory.setText("Directory");
lblLabel.setText("Label");
txtLabel.setText("");
txtLabel.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(KeyEvent e) {
txtLabel_keyReleased(e);
}
});
txtDirectory.setEditable(false);
pnlButtonsLayout.setHgap(5);
pnlDialog.add(pnlButtons, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 10, 10), 0, 0));
pnlButtons.add(btnAttach, BorderLayout.CENTER);
pnlButtons.add(btnCancel, BorderLayout.EAST);
pnlDialog.add(lblDirectory, new GridBagConstraints(1, 1, 1, 2, 0.0, 0.0
,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 10, 10, 0), 0, 0));
pnlDialog.add(lblLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 10, 10, 0), 0, 0));
pnlDialog.add(txtLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
pnlDialog.add(lblConnect, new GridBagConstraints(0, 0, 1, 4, 0.0, 0.0
,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
pnlDialog.add(btnBrowse, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 10, 10), 0, 0));
pnlDialog.add(txtDirectory, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if ( e.getID() == WindowEvent.WINDOW_CLOSING ) {
hide();
}
}
void btnBrowse_actionPerformed(ActionEvent e) {
Admin admin = Admin.getInstance();
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setMultiSelectionEnabled(false);
int result = fc.showDialog(admin, "Select");
if ( result == JFileChooser.APPROVE_OPTION ) {
txtDirectory.setText(fc.getSelectedFile().getPath());
if ( txtLabel.getText().trim().length() == 0 )
txtLabel.setText(fc.getSelectedFile().getName());
testRequired();
}
}
void btnAttach_actionPerformed(ActionEvent e) {
try {
Admin admin = Admin.getInstance();
String label = txtLabel.getText();
String path = txtDirectory.getText();
admin.browser.addFileSystem(path, label);
admin.addFileSystem(path, label);
hide();
}
catch ( Exception ex ) {
Admin.getInstance().addMessage(ex.getMessage());
}
}
void btnCancel_actionPerformed(ActionEvent e) {
hide();
}
void txtLabel_keyReleased(KeyEvent e) {
testRequired();
}
void testRequired() {
if ( txtLabel.getText().trim().length() == 0
|| txtDirectory.getText().trim().length() == 0 ) {
btnAttach.setEnabled(false);
return;
}
btnAttach.setEnabled(true);
}
}