1 package jp.sourceforge.stigmata.ui.swing;
7 import java.awt.BorderLayout;
8 import java.awt.GridLayout;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
12 import java.io.IOException;
13 import java.net.MalformedURLException;
16 import javax.swing.Box;
17 import javax.swing.JButton;
18 import javax.swing.JComponent;
19 import javax.swing.JLabel;
20 import javax.swing.JOptionPane;
21 import javax.swing.JPanel;
22 import javax.swing.JTextField;
23 import javax.swing.border.TitledBorder;
24 import javax.swing.event.DocumentEvent;
25 import javax.swing.event.DocumentListener;
27 import jp.sourceforge.stigmata.Stigmata;
28 import jp.sourceforge.stigmata.digger.ClasspathContext;
29 import jp.sourceforge.talisman.i18n.Messages;
35 * @author Haruaki TAMADA
37 public class ClasspathSettingsPane extends JPanel{
38 private static final long serialVersionUID = 320973463423634L;
40 private StigmataFrame stigmata;
41 private TargetSelectionPane classpath;
42 private TargetSelectionPane bootClasspath;
44 public ClasspathSettingsPane(StigmataFrame frame){
45 this.stigmata = frame;
50 public void updateClasspathContext(ClasspathContext context){
51 String[] cplist = classpath.getValues();
52 if(cplist != null && cplist.length >= 0){
53 for(int i = 0; i < cplist.length; i++){
57 url = new URL(cplist[i]);
58 } catch(MalformedURLException e){
59 url = new File(cplist[i]).toURI().toURL();
61 context.addClasspath(url);
62 }catch(IOException ee){
69 classpath.removeAllElements();
70 bootClasspath.removeAllElements();
72 ClasspathContext context = stigmata.getEnvironment().getClasspathContext();
73 for(URL url: context){
74 classpath.addValue(url.toString());
77 addClasspath(bootClasspath, System.getProperty("java.class.path"));
78 addClasspath(bootClasspath, System.getProperty("sun.boot.class.path"));
79 } catch(SecurityException e){
84 private void addClasspath(TargetSelectionPane target, String classpath){
85 if(classpath != null){
86 target.addValues(classpath.split(System.getProperty("path.separator")));
87 stigmata.setNeedToSaveSettings(true);
91 private boolean findClass(String className){
93 ClasspathContext b = Stigmata.getInstance().createEnvironment().getClasspathContext();
94 ClasspathContext bytecode = new ClasspathContext(b);
95 String[] path = classpath.getValues();
97 bytecode.addClasspath(new File(cp).toURI().toURL());
99 return bytecode.findClass(className) != null;
100 }catch(ClassNotFoundException e){
101 }catch(MalformedURLException e){
106 private void initLayouts(){
107 final Messages messages = stigmata.getMessages();
108 JComponent panel = new JPanel(new GridLayout(1, 2));
109 classpath = new TargetSelectionPane(stigmata);
110 bootClasspath = new TargetSelectionPane(stigmata);
111 JComponent south = Box.createHorizontalBox();
112 final JButton findButton = GUIUtility.createButton(messages, "findclass");
113 final JTextField text = new JTextField();
114 final JLabel label = new JLabel();
116 classpath.setBorder(new TitledBorder(stigmata.getMessages().get("userclasspath.border")));
117 classpath.addTargetExtensions(stigmata.getMessages().getArray("userclasspath.extensions"));
118 classpath.setDescription(stigmata.getMessages().get("userclasspath.description"));
119 classpath.setDirectorySelectable(true);
121 bootClasspath.setBorder(new TitledBorder(stigmata.getMessages().get("bootclasspath.border")));
122 bootClasspath.setEnabled(false);
124 findButton.setEnabled(false);
126 south.setBorder(new TitledBorder(stigmata.getMessages().get("classpathchecker.border")));
128 label.setIcon(GUIUtility.getIcon(messages, "classpathchecker.default.icon"));
129 label.setToolTipText(stigmata.getMessages().get("classpathchecker.default.tooltip"));
131 setLayout(new BorderLayout());
132 add(panel, BorderLayout.CENTER);
133 add(south, BorderLayout.SOUTH);
135 panel.add(classpath);
136 panel.add(bootClasspath);
138 south.add(Box.createHorizontalGlue());
140 south.add(Box.createHorizontalGlue());
141 south.add(findButton);
142 south.add(Box.createHorizontalGlue());
144 south.add(Box.createHorizontalGlue());
146 text.getDocument().addDocumentListener(new DocumentListener(){
148 public void changedUpdate(DocumentEvent arg0){
149 String t = text.getText();
150 findButton.setEnabled(t.trim().length() > 0);
154 public void insertUpdate(DocumentEvent arg0){
155 String t = text.getText();
156 findButton.setEnabled(t.trim().length() > 0);
160 public void removeUpdate(DocumentEvent arg0){
161 String t = text.getText();
162 findButton.setEnabled(t.trim().length() > 0);
165 ActionListener action = new ActionListener(){
167 public void actionPerformed(ActionEvent e){
168 String t = text.getText().trim();
169 boolean flag = findClass(t);
170 String message = stigmata.getMessages().get("classpathchecker.found.tooltip");
172 label.setIcon(GUIUtility.getIcon(messages, "classpathchecker.found.icon"));
175 label.setIcon(GUIUtility.getIcon(messages, "classpathchecker.notfound.icon"));
176 message = stigmata.getMessages().get("classpathchecker.notfound.tooltip");
178 label.setToolTipText(message);
179 String dm = String.format(
180 "<html><body><dl><dt>%s</dt><dd>%s</dd></body></html>", t, message
182 JOptionPane.showMessageDialog(
183 stigmata, dm, stigmata.getMessages().get("classpathchecker.dialog.title"),
184 JOptionPane.INFORMATION_MESSAGE
189 classpath.addDataChangeListener(new DataChangeListener(){
191 public void valueChanged(Object source){
192 stigmata.setNeedToSaveSettings(true);
196 findButton.addActionListener(action);
197 text.addActionListener(action);