KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > wminstaller > screens > ScreenDirChooser


1 package de.webman.wminstaller.screens;
2
3 import de.webman.wminstaller.app.*;
4 import de.webman.wminstaller.tools.*;
5 import javax.swing.*;
6 import javax.swing.tree.*;
7 import javax.swing.event.*;
8 import java.awt.*;
9 import java.awt.event.*;
10 import java.io.*;
11
12 /**
13  * Implementierung des Zielverzeichnis-Setup screens
14  *
15  * @author <a HREF="mailto:ulf@webman.de">Ulf Goldammer</a>
16  * @version $Revision: 1.2 $
17  **/

18 public class ScreenDirChooser extends InstallerScreen implements TreeSelectionListener
19 {
20     /* $Id: ScreenDirChooser.java,v 1.2 2002/02/11 18:19:05 gregor Exp $ */
21
22     JPanel main;
23     final FileTree chooser;
24     String JavaDoc selectedPath;
25     TreePath selectedTreePath;
26     JTextField pathInfo = new JTextField("Kein Verzeichnis ausgewählt.");
27     JButton mkSubDir = new JButton("Unterverzeichnis einrichten ...");
28     
29     public ScreenDirChooser( Installer wmi, int bt) {
30         
31         super( wmi, bt);
32         
33         main = new JPanel( new BorderLayout( 0, 12));
34         // p.setBackground( Color.red );
35

36         chooser = new FileTree( this);
37         JScrollPane sp = new JScrollPane( chooser);
38         sp.setPreferredSize( new Dimension( 250, 200));
39         main.add( sp, BorderLayout.CENTER);
40         
41         JPanel p1 = new JPanel( new BorderLayout( 0, 16));
42         p1.add( pathInfo, BorderLayout.NORTH);
43         mkSubDir.setEnabled( false);
44         mkSubDir.setActionCommand("subdir");
45         mkSubDir.addActionListener( new DirMaker());
46         pathInfo.setEditable( false);
47         pathInfo.setBorder( BorderFactory.createLoweredBevelBorder());
48         // pathInfo.setBackground( p.getBackground());
49
p1.add( mkSubDir, BorderLayout.EAST);
50         main.add( p1, BorderLayout.SOUTH);
51
52         addScreen( "Auswahl/Erzeugung des Installationsverzeichnisses.", main);
53     }
54
55     public void valueChanged( TreeSelectionEvent evt) {
56         TreePath path = evt.getPath();
57         String JavaDoc name = chooser.getPathName( path);
58         if ( ( evt.isAddedPath()) && ( name.length() > 0)) {
59             selectedPath = name;
60             selectedTreePath = path;
61             pathInfo.setText(selectedPath);
62             mkSubDir.setEnabled(true);
63         }
64         else {
65             selectedPath = null;
66             selectedTreePath = null;
67             pathInfo.setText("Kein Verzeichnis ausgewählt.");
68             mkSubDir.setEnabled(false);
69         }
70         // System.out.println("selectedPath >> '" + (selectedPath == null ? "" : selectedPath) +"'");
71
}
72     
73     public boolean storeValues() {
74         /* TODO */
75         if (selectedPath != null) {
76             wmi.getDictionary().put(DictConstants.SELECTED_PATH, selectedPath);
77             return true;
78         }
79         else {
80             Object JavaDoc[] options = {"Korregieren", "Abbrechen"};
81             int n = JOptionPane.showOptionDialog(main,
82                                                  "Sie haben kein Verzeichnis ausgewählt!\n",
83                                                  "Fehlerhafte Eingabe",
84                                                  JOptionPane.YES_NO_OPTION,
85                                                  JOptionPane.QUESTION_MESSAGE,
86                                                  null, //don't use a custom Icon
87
options, //the titles of buttons
88
options[0]); //default button title
89
switch (n) {
90             case JOptionPane.YES_OPTION:
91                 return false;
92             case JOptionPane.NO_OPTION:
93                     wmi.leave(-1);
94                     break;
95             }
96             return false;
97         }
98     }
99     
100     
101     protected class DirMaker implements ActionListener
102     {
103         public void actionPerformed( ActionEvent evt) {
104             String JavaDoc cmd = evt.getActionCommand();
105             if (( cmd.equals("subdir")) && ( selectedTreePath != null) ) {
106                 String JavaDoc newDir = JOptionPane.showInputDialog( "Name des neuen Unterverzeichnisses:");
107                 if ( ( newDir == null) || ( newDir.length() < 1)) return;
108                 File f = new File( selectedPath, newDir);
109                 boolean madeDir = false;
110                 try{ madeDir = f.mkdir(); }
111                 catch( SecurityException JavaDoc e) {}
112                 if ( madeDir) {
113                     chooser.redisplayChildren( selectedTreePath, newDir);
114                 }
115                 else {
116                     JOptionPane.showMessageDialog(main,
117                                                   "Das Unterverzeichnis konnte nicht eingerichtet werden.\n",
118                                                   "Fehler",
119                                                   JOptionPane.ERROR_MESSAGE
120                                                   );
121                 }
122             }
123         }
124     }
125
126     public void onEnter() {
127     }
128 }
129
Popular Tags