001: /**
002: * $RCSfile: XuiDirectoryPanel.java,v $
003: * @creation 01/02/00
004: * @modification $Date: 2005/03/16 19:56:06 $
005: */package com.memoire.vainstall.xui;
006:
007: import java.io.*;
008: import java.awt.*;
009: import java.awt.event.*;
010: import javax.swing.*;
011: import javax.swing.border.*;
012: import com.memoire.vainstall.VADirectoryStep;
013: import com.memoire.vainstall.VAGlobals;
014:
015: /**
016: * @version $Id: XuiDirectoryPanel.java,v 1.7 2005/03/16 19:56:06 deniger Exp $
017: * @author Guillaume Desnoix
018: */
019:
020: public class XuiDirectoryPanel extends XuiAbstractPanel implements
021: VADirectoryStep {
022: JTextField tfDir_;
023: JButton btBrowse_;
024:
025: public XuiDirectoryPanel() {
026: super ();
027:
028: setLayout(new BorderLayout());
029:
030: JPanel pnMain = new XuiPanel();
031: pnMain.setLayout(new BorderLayout());
032: pnMain.setBorder(new EmptyBorder(5, 5, 5, 5));
033: pnMain.setForeground(new Color(128, 255, 255));
034:
035: JPanel pnMainInt = new XuiPanel();
036: pnMainInt.setLayout(new BorderLayout(0, 0));
037: pnMainInt.setBorder(new CompoundBorder(new LineBorder(
038: Color.black, 2), new CompoundBorder(new EmptyBorder(5,
039: 5, 5, 5), new LineBorder(Color.black, 2))));
040:
041: JLabel lb1 = new XuiLabel(VAGlobals.i18n("UI_Directory"));
042: lb1.setBackground(new Color(160, 224, 224));
043: lb1.setBorder(new EmptyBorder(0, 5, 0, 5));
044: lb1.setOpaque(true);
045: pnMainInt.add(lb1, BorderLayout.CENTER);
046:
047: tfDir_ = new JTextField();
048: tfDir_.setText(VAGlobals.DEST_PATH);
049: tfDir_.setBorder(new EmptyBorder(0, 5, 0, 5));
050: tfDir_.setFont(new Font("Monospaced", Font.PLAIN, 14));
051: pnMainInt.add(tfDir_, BorderLayout.SOUTH);
052:
053: JPanel p = new JPanel();
054: p.setBorder(new EmptyBorder(2, 4, 2, 4));
055: p.setLayout(new BorderLayout());
056: p.setBackground(new Color(160, 224, 224));
057: // p.setForeground(new Color(160,224,224));
058: p.setOpaque(true);
059: btBrowse_ = new XuiButton(VAGlobals.i18n("UI_Browse"));
060: btBrowse_.setForeground(Color.black);
061: btBrowse_.addActionListener(new ActionListener() {
062: public void actionPerformed(ActionEvent e) {
063: XuiDirectoryPanel.this .browse();
064: }
065: });
066: p.add(btBrowse_, BorderLayout.EAST);
067: pnMainInt.add(p, BorderLayout.EAST);
068:
069: XuiTitle lbTitle = new XuiTitle(VAGlobals.i18n("UI_Directory"),
070: XuiTitle.LEFT);
071: lbTitle.setFont(new Font("SansSerif", Font.PLAIN, 16));
072:
073: JPanel q = new JPanel();
074: q.setOpaque(false);
075: q.setBorder(null);
076: q.setLayout(new BorderLayout());
077: q.add(lbTitle, BorderLayout.NORTH);
078: q.add(pnMainInt, BorderLayout.CENTER);
079:
080: pnMain.add(q, BorderLayout.NORTH);
081:
082: JPanel pnImage = XuiImagePanel.IMAGE_PANEL;
083: add(pnImage, BorderLayout.WEST);
084: add(pnMain, BorderLayout.CENTER);
085: }
086:
087: public void setDirectory(File f) {
088: if (f != null)
089: tfDir_.setText(f.getAbsolutePath());
090: }
091:
092: public File getDirectory() {
093: String dirstr = tfDir_.getText();
094: File dir = new File(dirstr);
095: File parent = dir.getParentFile();
096: if ((dir.exists() && !dir.canWrite()) || (parent != null)
097: && ((!parent.exists()) || (!parent.canWrite()))) {
098: XuiOptionPane.showErrorDialog(
099: (Dialog) getTopLevelAncestor(), parent
100: + VAGlobals.i18n("UI_NoDirectoryAccess"),
101: VAGlobals.i18n("UI_Error"));
102: dir = null;
103: }
104: return dir;
105: }
106:
107: public void roDirectory(File d) {
108: XuiOptionPane
109: .showErrorDialog(
110: (Dialog) getTopLevelAncestor(),
111: VAGlobals.i18n("Setup_NoWritableDirectory")
112: + d.getAbsolutePath()
113: + "\n"
114: + VAGlobals
115: .i18n("Setup_NoWritableDirectoryInfos"),
116: VAGlobals.i18n("UI_Error"));
117: }
118:
119: public void rejectDirectory() {
120: XuiOptionPane.showErrorDialog((Dialog) getTopLevelAncestor(),
121: VAGlobals.i18n("UI_NotChooseDirectory"), VAGlobals
122: .i18n("UI_Error"));
123: }
124:
125: public boolean acceptDirectory() {
126: int res = XuiOptionPane.showConfirmDialog(
127: (Dialog) getTopLevelAncestor(), VAGlobals
128: .i18n("UI_InstallationDirectory")
129: + "\n"
130: + getDirectory()
131: + "\n"
132: + VAGlobals.i18n("UI_IsThatRight"), VAGlobals
133: .i18n("UI_Confirm"));
134: return (res == XuiOptionPane.YES);
135: }
136:
137: private void browse() {
138: JFileChooser fc = new JFileChooser();
139: fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
140: int res = fc.showDialog(this , VAGlobals.i18n("UI_Select"));
141:
142: File dir = null;
143: if (res == JFileChooser.APPROVE_OPTION) {
144: dir = fc.getSelectedFile();
145: if (dir != null) {
146: if ((dir.exists()) && (dir.isDirectory())
147: && (dir.canWrite())) {
148: tfDir_.setText(dir.getAbsolutePath());
149: } else {
150: XuiOptionPane
151: .showErrorDialog(
152: (Dialog) getTopLevelAncestor(),
153: dir.getName()
154: + VAGlobals
155: .i18n("UI_NotValidDirectory"),
156: VAGlobals.i18n("UI_Error"));
157: }
158: }
159: }
160: }
161: }
|