/*
* Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
* subject to license terms.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the Lesser 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.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import javax.swing.table.TableColumn;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.io.IOException;
import java.io.File;
import org.jdesktop.jdic.desktop.*;
/**
* JDIC API demo main class.
* <p>
* The main class for the demo. Class <code>FileExplorer</code> creates a UI
* interface demonstrating the usage of the public API of <code>org.jdesktop.jdic.desktop.*
* </code> classes.
*/
public class FileExplorer extends JPanel {
public static ImageIcon computerIcon;
public static ImageIcon driverIcon;
public static ImageIcon folderIcon;
public static ImageIcon fileIcon;
public static ImageIcon browseIcon;
public static String MY_COMPUTER_FOLDER_PATH = System.getProperty("java.io.tmpdir")
+ File.separator + "My Computer";
// Currently selected tree node in the left disk tree.
public static MyTreeNode selectedTreeNode = null;
// Currently selected file in the right table.
File selectedFile = null;
BorderLayout borderLayout1 = new BorderLayout();
JPopupMenu jDesktopPopupMenu = new JPopupMenu();
JMenuItem jMenuItemOpen = new JMenuItem();
JMenuItem jMenuItemEdit = new JMenuItem();
JMenuItem jMenuItemPrint = new JMenuItem();
JMenuItem jMenuItemBrowse = new JMenuItem();
JMenuItem jMenuItemMail = new JMenuItem();
JSplitPane jSplitPane = new JSplitPane();
JTree jTreeDisk = new JTree(createTreeModel());
JScrollPane tableScrollPane = new JScrollPane();
MyTableModel tableModel = new MyTableModel();
MyTable jTable = new MyTable();
JPanel jAddressPanel = new JPanel();
JLabel jAddressLabel = new JLabel();
JTextField jAddressTextField = new JTextField();
JButton jBrowseButton = new JButton();
MyStatusBar statusBar = new MyStatusBar();
public FileExplorer() {
try {
System.setSecurityManager(null);
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
JFrame frame = new JFrame("JDIC API Demo - FileExplorer");
Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(1, 1));
contentPane.add(new FileExplorer());
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
private void jbInit() throws Exception {
try {
computerIcon = new ImageIcon(FileExplorer.class.getResource("images/Computer.gif"));
driverIcon = new ImageIcon(FileExplorer.class.getResource("images/Driver.gif"));
folderIcon = new ImageIcon(FileExplorer.class.getResource("images/Folder.gif"));
fileIcon = new ImageIcon(FileExplorer.class.getResource("images/File.gif"));
browseIcon = new ImageIcon(FileExplorer.class.getResource("images/Right.gif"));
} catch (Exception e) {
System.out.println("ERROR loading image files !");
}
this.setLayout(borderLayout1);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setPreferredSize(new Dimension(screenSize.width * 4 / 5,
screenSize.height * 7 / 10));
jMenuItemOpen.setText("Open");
jMenuItemOpen.addActionListener(new
FileExplorer_jMenuItemOpen_actionAdapter(this));
jMenuItemEdit.setText("Edit");
jMenuItemEdit.addActionListener(new
FileExplorer_jMenuItemEdit_actionAdapter(this));
jMenuItemPrint.setText("Print");
jMenuItemPrint.addActionListener(new
FileExplorer_jMenuItemPrint_actionAdapter(this));
jMenuItemBrowse.setText("Browse");
jMenuItemBrowse.addActionListener(new
FileExplorer_jMenuItemBrowse_actionAdapter(this));
jMenuItemMail.setText("Mail to ...");
jMenuItemMail.addActionListener(new
FileExplorer_jMenuItemMail_actionAdapter(this));
jTreeDisk.addTreeExpansionListener(new
FileExplorer_jTreeDisk_treeExpansionAdapter(this));
jAddressLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
jAddressLabel.setToolTipText("");
jAddressLabel.setText("Address");
jBrowseButton.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(0,
2, 0, 2),
new EtchedBorder()));
jBrowseButton.setToolTipText("Browse the given URL with system default browser");
jBrowseButton.setIcon(browseIcon);
jBrowseButton.setText("Browse ");
jBrowseButton.addActionListener(new
FileExplorer_jBrowseButton_actionAdapter(this));
jAddressPanel.setLayout(new BorderLayout());
jAddressTextField.addActionListener(new
FileExplorer_jAddressTextField_actionAdapter(this));
jAddressPanel.add(jAddressLabel, BorderLayout.WEST);
jAddressPanel.add(jAddressTextField, BorderLayout.CENTER);
jAddressPanel.add(jBrowseButton, BorderLayout.EAST);
jAddressPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
jTreeDisk.addMouseListener(new FileExplorer_jTreeDisk_mouseAdapter(this));
jTreeDisk.addTreeWillExpandListener(new
FileExplorer_jTreeDisk_treeWillExpandAdapter(this));
jTreeDisk.setCellRenderer(new MyTreeRenderer());
jTreeDisk.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
jTreeDisk.setSelectionRow(0);
jTreeDisk.setBackground(Color.white);
jTreeDisk.setAlignmentX((float) 0.5);
jTreeDisk.setShowsRootHandles(false);
jTreeDisk.addTreeSelectionListener(new
FileExplorer_jTreeDisk_treeSelectionAdapter(this));
jTable.setBorder(null);
jTable.setModel(tableModel);
TableColumn column = jTable.getColumnModel().getColumn(0);
column.setCellRenderer(new MyTableRenderer());
column = jTable.getColumnModel().getColumn(1);
column.setCellRenderer(new MyTableRenderer());
jTable.setShowHorizontalLines(false);
jTable.setShowVerticalLines(false);
jTable.addMouseListener(new FileExplorer_jTable_mouseAdapter(this));
tableScrollPane.setViewportView(jTable);
jSplitPane.setBorder(null);
jSplitPane.add(new JScrollPane(jTreeDisk), JSplitPane.LEFT);
jSplitPane.add(tableScrollPane, JSplit