001: /*
002: * Copyright (C) 2004 Nicky BRAMANTE
003: *
004: * This file is part of FreeQueryBuilder
005: *
006: * FreeQueryBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Send questions or suggestions to nickyb@interfree.it
021: */
022:
023: package it.frb.admin;
024:
025: import java.awt.GridLayout;
026: import java.awt.event.ActionEvent;
027:
028: import java.io.File;
029:
030: import java.util.StringTokenizer;
031:
032: import javax.swing.AbstractAction;
033: import javax.swing.Box;
034: import javax.swing.BoxLayout;
035: import javax.swing.DefaultListModel;
036: import javax.swing.JFileChooser;
037: import javax.swing.JList;
038: import javax.swing.JPanel;
039: import javax.swing.JScrollPane;
040: import javax.swing.JTabbedPane;
041: import javax.swing.filechooser.FileFilter;
042:
043: import it.frb.admin.*;
044:
045: public class InfoClasspathPane extends JTabbedPane {
046: private DialogAdministrator admin;
047:
048: private JList env;
049: private JList ext;
050: private JList cmd;
051: private JList run;
052:
053: public InfoClasspathPane(DialogAdministrator admin) {
054: this .admin = admin;
055:
056: env = new JList(new DefaultListModel());
057: ext = new JList(new DefaultListModel());
058: cmd = new JList(new DefaultListModel());
059: run = new JList(new DefaultListModel());
060:
061: JPanel pnlclasspath = new JPanel(new GridLayout(3, 1, 3, 3));
062: addTab("$CLASSPATH", pnlclasspath);
063:
064: pnlclasspath.add(new DefaultScrollPane("sun.boot.class.path",
065: env, false));
066: pnlclasspath.add(new DefaultScrollPane("java.class.path", cmd,
067: false));
068: pnlclasspath.add(new DefaultScrollPane("java.ext.dirs", ext,
069: false));
070:
071: String bootPath = System.getProperty("sun.boot.class.path");
072: String classPath = System.getProperty("java.class.path");
073: String extDir = System.getProperty("java.ext.dirs");
074:
075: File fileExtDir = new File(extDir);
076: String[] exts = fileExtDir.list();
077: for (int i = 0; i < exts.length; i++)
078: ((DefaultListModel) ext.getModel()).addElement(exts[i]);
079:
080: StringTokenizer tokenizer = new StringTokenizer(classPath, ";");
081: while (tokenizer.hasMoreElements())
082: ((DefaultListModel) cmd.getModel()).addElement(tokenizer
083: .nextElement());
084:
085: tokenizer = new StringTokenizer(bootPath, ";");
086: while (tokenizer.hasMoreElements())
087: ((DefaultListModel) env.getModel()).addElement(tokenizer
088: .nextElement());
089:
090: DefaultPanel pnlruntime = new DefaultPanel();
091: addTab("$RUNTIME", pnlruntime);
092: Box bar = new Box(BoxLayout.X_AXIS);
093: bar.add(UIUtilities.createCustomButton(new ActionArchiveAdd()));
094: bar.add(UIUtilities
095: .createCustomButton(new ActionArchiveRemove()));
096: bar.add(Box.createHorizontalGlue());
097:
098: pnlruntime.setCenterComponent(new JScrollPane(run));
099: pnlruntime.setSouthComponent(bar);
100: }
101:
102: void addArchive(String filename) {
103: ((DefaultListModel) this .run.getModel()).addElement(filename);
104: admin.dinfopane.addFile(filename);
105: }
106:
107: void removeArchive() {
108: int index = InfoClasspathPane.this .run.getSelectedIndex();
109: if (index != -1) {
110: String filename = InfoClasspathPane.this .run
111: .getSelectedValue().toString();
112:
113: ((DefaultListModel) InfoClasspathPane.this .run.getModel())
114: .removeElement(filename);
115: admin.dinfopane.removeFile(filename);
116: }
117: }
118:
119: private class ActionArchiveAdd extends AbstractAction {
120: ActionArchiveAdd() {
121: super ("add...");
122: }
123:
124: public void actionPerformed(ActionEvent ae) {
125: JFileChooser chooser = new JFileChooser();
126: chooser.setAcceptAllFileFilterUsed(false);
127: chooser.setFileFilter(new FileFilter() {
128: public boolean accept(File file) {
129: return file.isDirectory()
130: || file.getName().endsWith(".jar")
131: || file.getName().endsWith(".zip");
132: }
133:
134: public String getDescription() {
135: return "Archive files (*.jar, *.zip)";
136: }
137: });
138:
139: if (chooser.showOpenDialog(InfoClasspathPane.this ) == JFileChooser.APPROVE_OPTION) {
140: InfoClasspathPane.this .addArchive(chooser
141: .getSelectedFile().getAbsolutePath());
142: }
143: }
144: }
145:
146: private class ActionArchiveRemove extends AbstractAction {
147: ActionArchiveRemove() {
148: super ("remove");
149: }
150:
151: public void actionPerformed(ActionEvent ae) {
152: InfoClasspathPane.this.removeArchive();
153: }
154: }
155: }
|