KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > gui > VADirectoryPanel


1 /**
2  * $RCSfile: VADirectoryPanel.java,v $
3  * @creation 01/02/00
4  * @modification $Date: 2005/03/16 19:56:18 $
5  */

6
7 package com.memoire.vainstall.gui;
8
9 import java.io.*;
10 import java.awt.*;
11 import java.awt.event.*;
12 import javax.swing.*;
13 import javax.swing.border.*;
14 import com.memoire.vainstall.VADirectoryStep;
15 import com.memoire.vainstall.VAGlobals;
16
17 /**
18  * @version $Id: VADirectoryPanel.java,v 1.5 2005/03/16 19:56:18 deniger Exp $
19  * @author Axel von Arnim
20  */

21
22 public class VADirectoryPanel
23        extends VAPanel
24        implements VADirectoryStep
25 {
26   JTextField tfDir_;
27   JButton btBrowse_;
28
29   public VADirectoryPanel()
30   {
31     super();
32
33     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
34
35     JPanel pnMain=new JPanel();
36     pnMain.setBorder(new CompoundBorder(new EtchedBorder(),
37                                         new EmptyBorder(new Insets(5, 5, 5, 5))));
38     pnMain.setLayout(new BoxLayout(pnMain, BoxLayout.Y_AXIS));
39
40     JPanel pnHaut=new JPanel();
41     pnHaut.setLayout(new BorderLayout());
42
43     JLabel lbTitle=new JLabel(VAGlobals.i18n("UI_Directory"));
44     lbTitle.setFont(lbTitle.getFont().deriveFont(Font.BOLD, 20));
45     lbTitle.setOpaque(true);
46     lbTitle.setBorder(new EmptyBorder(new Insets(5, 0, 5, 0)));
47     lbTitle.setBackground(pnMain.getBackground().darker());
48     lbTitle.setForeground(Color.white);
49     pnHaut.add(BorderLayout.NORTH, lbTitle);
50
51     tfDir_=new JTextField();
52     pnHaut.add(BorderLayout.SOUTH, tfDir_);
53
54     JPanel pnBas=new JPanel();
55     pnBas.setLayout(new BorderLayout());
56
57     btBrowse_=new JButton(VAGlobals.i18n("UI_Browse"));
58     btBrowse_.addActionListener(new ActionListener() {
59       public void actionPerformed(ActionEvent e)
60       { VADirectoryPanel.this.browse(); } });
61     pnBas.add(BorderLayout.NORTH, btBrowse_);
62
63     pnMain.add(pnHaut);
64     pnMain.add(pnBas);
65
66     JComponent pnImage=VAImagePanel.IMAGE_PANEL;
67     add(pnImage);
68     add(pnMain);
69   }
70
71   public void setDirectory(File f)
72   {
73     if( f!=null )
74       tfDir_.setText(f.getAbsolutePath());
75   }
76
77   public File getDirectory()
78   {
79     String JavaDoc dirstr=tfDir_.getText().trim();
80     if( (dirstr==null)||("".equals(dirstr)) ) {
81       JOptionPane.showMessageDialog(
82         this,
83         VAGlobals.i18n("UI_MustChoose"),
84         VAGlobals.i18n("UI_Error"),
85         JOptionPane.ERROR_MESSAGE);
86       return null;
87     }
88     File dir=new File(dirstr);
89     return dir;
90   }
91
92   public void roDirectory(File d)
93   {
94     JOptionPane.showMessageDialog(this,
95       VAGlobals.i18n("Setup_NoWritableDirectory")+d.getAbsolutePath()
96           +"\n"+VAGlobals.i18n("Setup_NoWritableDirectoryInfos"),
97       VAGlobals.i18n("UI_Error"),
98       JOptionPane.ERROR_MESSAGE);
99   }
100
101   public void rejectDirectory()
102   {
103     JOptionPane.showMessageDialog(this,
104       VAGlobals.i18n("UI_NotChooseDirectory"),
105       VAGlobals.i18n("UI_Error"),
106       JOptionPane.ERROR_MESSAGE);
107   }
108
109   public boolean acceptDirectory()
110   {
111     int res=JOptionPane.showConfirmDialog(this,
112       VAGlobals.i18n("UI_InstallationDirectory")+"\n"+getDirectory()+"\n"+
113       VAGlobals.i18n("UI_IsThatRight"),
114       VAGlobals.i18n("UI_Confirm"),
115       JOptionPane.YES_NO_OPTION,
116       JOptionPane.QUESTION_MESSAGE);
117     return (res==JOptionPane.YES_OPTION);
118   }
119
120   private void browse()
121   {
122     JFileChooser fc=new JFileChooser();
123     fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
124     int res=fc.showSaveDialog(this);
125     File dir=null;
126     if( res==JFileChooser.APPROVE_OPTION ) {
127       dir=fc.getSelectedFile();
128       if( dir!=null ) {
129         if( ((dir.exists())&&(dir.isDirectory())&&(dir.canWrite())) || (!dir.exists()) ) {
130           tfDir_.setText(dir.getAbsolutePath());
131         } else {
132           JOptionPane.showMessageDialog(this,
133             dir.getName()+VAGlobals.i18n("UI_NotValidDirectory"),
134             VAGlobals.i18n("UI_Error"),
135             JOptionPane.ERROR_MESSAGE);
136         }
137       }
138     }
139   }
140 }
141
Popular Tags