001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.application.gui.editors;
022:
023: import net.charabia.jsmoothgen.skeleton.*;
024: import net.charabia.jsmoothgen.application.*;
025: import net.charabia.jsmoothgen.application.gui.*;
026: import net.charabia.jsmoothgen.application.gui.util.*;
027: import javax.swing.*;
028: import java.awt.*;
029: import java.util.*;
030: import java.io.File;
031: import java.util.jar.*;
032:
033: import com.l2fprod.common.swing.*;
034: import com.l2fprod.common.propertysheet.*;
035:
036: public class MainClass extends Editor {
037: private JTextField m_classname = new JTextField();
038: private JButton m_chooserButton = new JButton("...");
039:
040: public MainClass() {
041: setLayout(new BorderLayout());
042: add(BorderLayout.CENTER, m_classname);
043: add(BorderLayout.EAST, m_chooserButton);
044:
045: m_chooserButton
046: .addActionListener(new java.awt.event.ActionListener() {
047: public void actionPerformed(
048: java.awt.event.ActionEvent evt) {
049: displayChooser();
050: }
051: });
052:
053: }
054:
055: public void dataChanged() {
056: m_classname.setText(m_model.getMainClassName());
057: }
058:
059: public void updateModel() {
060: m_model.setMainClassName(m_classname.getText());
061: }
062:
063: public String getLabel() {
064: return "MAINCLASS_LABEL";
065: }
066:
067: public String getDescription() {
068: return "MAINCLASS_HELP";
069: }
070:
071: protected void displayChooser() {
072: ClassChooserDialog chooser = new ClassChooserDialog(Main.MAIN,
073: true);
074:
075: Vector jars = new Vector();
076: if (m_model.getEmbeddedJar() == true) {
077: String ejar = m_model.getJarLocation();
078: if (ejar != null) {
079: File f = getAbsolutePath(new File(ejar));
080: jars.add(f);
081: }
082: }
083:
084: String[] cp = m_model.getClassPath();
085: if (cp != null) {
086: for (int i = 0; i < cp.length; i++) {
087: jars.add(getAbsolutePath(new File(cp[i])));
088: }
089: }
090:
091: chooser.clear();
092: for (Iterator i = jars.iterator(); i.hasNext();) {
093: File f = (File) i.next();
094: // System.out.println("Adding jar <" + f + ">");
095: try {
096: chooser.addJar(new JarFile(f));
097: } catch (Exception ex) {
098: ex.printStackTrace();
099: }
100: }
101:
102: chooser.setClassName(m_classname.getText());
103: chooser.setVisible(true);
104: if (chooser.validated()) {
105: String classname = chooser.getClassName();
106: m_classname.setText(classname);
107: }
108: }
109:
110: }
|