KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > xui > XuiDirectoryPanel


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

6
7 package com.memoire.vainstall.xui;
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: XuiDirectoryPanel.java,v 1.7 2005/03/16 19:56:06 deniger Exp $
19  * @author Guillaume Desnoix
20  */

21
22 public class XuiDirectoryPanel
23        extends XuiAbstractPanel
24        implements VADirectoryStep
25 {
26   JTextField tfDir_;
27   JButton btBrowse_;
28
29   public XuiDirectoryPanel()
30   {
31     super();
32
33     setLayout(new BorderLayout());
34
35     JPanel pnMain=new XuiPanel();
36     pnMain.setLayout(new BorderLayout());
37     pnMain.setBorder(new EmptyBorder(5,5,5,5));
38     pnMain.setForeground(new Color(128,255,255));
39
40     JPanel pnMainInt=new XuiPanel();
41     pnMainInt.setLayout(new BorderLayout(0,0));
42     pnMainInt.setBorder(new CompoundBorder
43       (new LineBorder(Color.black,2),
44        new CompoundBorder(new EmptyBorder(5,5,5,5),
45               new LineBorder(Color.black,2))));
46
47     JLabel lb1 = new XuiLabel(VAGlobals.i18n("UI_Directory"));
48     lb1.setBackground(new Color(160,224,224));
49     lb1.setBorder(new EmptyBorder(0,5,0,5));
50     lb1.setOpaque(true);
51     pnMainInt.add(lb1,BorderLayout.CENTER);
52
53     tfDir_=new JTextField();
54     tfDir_.setText(VAGlobals.DEST_PATH);
55     tfDir_.setBorder(new EmptyBorder(0,5,0,5));
56     tfDir_.setFont(new Font("Monospaced",Font.PLAIN,14));
57     pnMainInt.add(tfDir_,BorderLayout.SOUTH);
58
59     JPanel p=new JPanel();
60     p.setBorder(new EmptyBorder(2,4,2,4));
61     p.setLayout(new BorderLayout());
62     p.setBackground(new Color(160,224,224));
63     // p.setForeground(new Color(160,224,224));
64
p.setOpaque(true);
65     btBrowse_=new XuiButton(VAGlobals.i18n("UI_Browse"));
66     btBrowse_.setForeground(Color.black);
67     btBrowse_.addActionListener(new ActionListener() {
68       public void actionPerformed(ActionEvent e)
69       { XuiDirectoryPanel.this.browse(); } });
70     p.add(btBrowse_,BorderLayout.EAST);
71     pnMainInt.add(p,BorderLayout.EAST);
72
73     XuiTitle lbTitle=new XuiTitle(VAGlobals.i18n("UI_Directory"),XuiTitle.LEFT);
74     lbTitle.setFont(new Font("SansSerif",Font.PLAIN,16));
75
76     JPanel q=new JPanel();
77     q.setOpaque(false);
78     q.setBorder(null);
79     q.setLayout(new BorderLayout());
80     q.add(lbTitle ,BorderLayout.NORTH);
81     q.add(pnMainInt,BorderLayout.CENTER);
82
83     pnMain.add(q,BorderLayout.NORTH);
84
85     JPanel pnImage=XuiImagePanel.IMAGE_PANEL;
86     add(pnImage,BorderLayout.WEST);
87     add(pnMain,BorderLayout.CENTER);
88   }
89
90   public void setDirectory(File f)
91   {
92     if( f!=null )
93       tfDir_.setText(f.getAbsolutePath());
94   }
95
96   public File getDirectory()
97   {
98     String JavaDoc dirstr=tfDir_.getText();
99     File dir=new File(dirstr);
100     File parent=dir.getParentFile();
101     if( (dir.exists() && !dir.canWrite()) || (parent!=null)&&((!parent.exists())||(!parent.canWrite())) ) {
102       XuiOptionPane.showErrorDialog
103   ((Dialog)getTopLevelAncestor(),
104    parent+VAGlobals.i18n("UI_NoDirectoryAccess"),
105    VAGlobals.i18n("UI_Error"));
106       dir=null;
107     }
108     return dir;
109   }
110
111   public void roDirectory(File d)
112   {
113     XuiOptionPane.showErrorDialog(
114       (Dialog)getTopLevelAncestor(),
115       VAGlobals.i18n("Setup_NoWritableDirectory")+d.getAbsolutePath()
116           +"\n"+VAGlobals.i18n("Setup_NoWritableDirectoryInfos"),
117       VAGlobals.i18n("UI_Error"));
118   }
119
120   public void rejectDirectory()
121   {
122     XuiOptionPane.showErrorDialog(
123        (Dialog)getTopLevelAncestor(),
124        VAGlobals.i18n("UI_NotChooseDirectory"),
125        VAGlobals.i18n("UI_Error"));
126   }
127
128   public boolean acceptDirectory()
129   {
130     int res=XuiOptionPane.showConfirmDialog(
131       (Dialog)getTopLevelAncestor(),
132       VAGlobals.i18n("UI_InstallationDirectory")+"\n"+getDirectory()+"\n"+
133       VAGlobals.i18n("UI_IsThatRight"),
134       VAGlobals.i18n("UI_Confirm"));
135     return (res==XuiOptionPane.YES);
136   }
137
138   private void browse()
139   {
140     JFileChooser fc=new JFileChooser();
141     fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
142     int res=fc.showDialog(this,VAGlobals.i18n("UI_Select"));
143
144     File dir=null;
145     if( res==JFileChooser.APPROVE_OPTION ) {
146       dir=fc.getSelectedFile();
147       if(dir!=null)
148       {
149         if( (dir.exists())&&(dir.isDirectory())&&(dir.canWrite()) ) {
150           tfDir_.setText(dir.getAbsolutePath());
151   }
152   else
153   {
154     XuiOptionPane.showErrorDialog
155       ((Dialog)getTopLevelAncestor(),
156        dir.getName()+
157        VAGlobals.i18n("UI_NotValidDirectory"),
158        VAGlobals.i18n("UI_Error"));
159         }
160       }
161     }
162   }
163 }
164
Popular Tags