001: /**
002: * $RCSfile: VADirectoryPanel.java,v $
003: * @creation 01/02/00
004: * @modification $Date: 2005/03/16 19:56:18 $
005: */package com.memoire.vainstall.gui;
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: VADirectoryPanel.java,v 1.5 2005/03/16 19:56:18 deniger Exp $
017: * @author Axel von Arnim
018: */
019:
020: public class VADirectoryPanel extends VAPanel implements
021: VADirectoryStep {
022: JTextField tfDir_;
023: JButton btBrowse_;
024:
025: public VADirectoryPanel() {
026: super ();
027:
028: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
029:
030: JPanel pnMain = new JPanel();
031: pnMain.setBorder(new CompoundBorder(new EtchedBorder(),
032: new EmptyBorder(new Insets(5, 5, 5, 5))));
033: pnMain.setLayout(new BoxLayout(pnMain, BoxLayout.Y_AXIS));
034:
035: JPanel pnHaut = new JPanel();
036: pnHaut.setLayout(new BorderLayout());
037:
038: JLabel lbTitle = new JLabel(VAGlobals.i18n("UI_Directory"));
039: lbTitle.setFont(lbTitle.getFont().deriveFont(Font.BOLD, 20));
040: lbTitle.setOpaque(true);
041: lbTitle.setBorder(new EmptyBorder(new Insets(5, 0, 5, 0)));
042: lbTitle.setBackground(pnMain.getBackground().darker());
043: lbTitle.setForeground(Color.white);
044: pnHaut.add(BorderLayout.NORTH, lbTitle);
045:
046: tfDir_ = new JTextField();
047: pnHaut.add(BorderLayout.SOUTH, tfDir_);
048:
049: JPanel pnBas = new JPanel();
050: pnBas.setLayout(new BorderLayout());
051:
052: btBrowse_ = new JButton(VAGlobals.i18n("UI_Browse"));
053: btBrowse_.addActionListener(new ActionListener() {
054: public void actionPerformed(ActionEvent e) {
055: VADirectoryPanel.this .browse();
056: }
057: });
058: pnBas.add(BorderLayout.NORTH, btBrowse_);
059:
060: pnMain.add(pnHaut);
061: pnMain.add(pnBas);
062:
063: JComponent pnImage = VAImagePanel.IMAGE_PANEL;
064: add(pnImage);
065: add(pnMain);
066: }
067:
068: public void setDirectory(File f) {
069: if (f != null)
070: tfDir_.setText(f.getAbsolutePath());
071: }
072:
073: public File getDirectory() {
074: String dirstr = tfDir_.getText().trim();
075: if ((dirstr == null) || ("".equals(dirstr))) {
076: JOptionPane.showMessageDialog(this , VAGlobals
077: .i18n("UI_MustChoose"), VAGlobals.i18n("UI_Error"),
078: JOptionPane.ERROR_MESSAGE);
079: return null;
080: }
081: File dir = new File(dirstr);
082: return dir;
083: }
084:
085: public void roDirectory(File d) {
086: JOptionPane.showMessageDialog(this , VAGlobals
087: .i18n("Setup_NoWritableDirectory")
088: + d.getAbsolutePath()
089: + "\n"
090: + VAGlobals.i18n("Setup_NoWritableDirectoryInfos"),
091: VAGlobals.i18n("UI_Error"), JOptionPane.ERROR_MESSAGE);
092: }
093:
094: public void rejectDirectory() {
095: JOptionPane.showMessageDialog(this , VAGlobals
096: .i18n("UI_NotChooseDirectory"), VAGlobals
097: .i18n("UI_Error"), JOptionPane.ERROR_MESSAGE);
098: }
099:
100: public boolean acceptDirectory() {
101: int res = JOptionPane.showConfirmDialog(this , VAGlobals
102: .i18n("UI_InstallationDirectory")
103: + "\n"
104: + getDirectory()
105: + "\n"
106: + VAGlobals.i18n("UI_IsThatRight"), VAGlobals
107: .i18n("UI_Confirm"), JOptionPane.YES_NO_OPTION,
108: JOptionPane.QUESTION_MESSAGE);
109: return (res == JOptionPane.YES_OPTION);
110: }
111:
112: private void browse() {
113: JFileChooser fc = new JFileChooser();
114: fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
115: int res = fc.showSaveDialog(this );
116: File dir = null;
117: if (res == JFileChooser.APPROVE_OPTION) {
118: dir = fc.getSelectedFile();
119: if (dir != null) {
120: if (((dir.exists()) && (dir.isDirectory()) && (dir
121: .canWrite()))
122: || (!dir.exists())) {
123: tfDir_.setText(dir.getAbsolutePath());
124: } else {
125: JOptionPane.showMessageDialog(this , dir.getName()
126: + VAGlobals.i18n("UI_NotValidDirectory"),
127: VAGlobals.i18n("UI_Error"),
128: JOptionPane.ERROR_MESSAGE);
129: }
130: }
131: }
132: }
133: }
|