PageRenderTime 103ms CodeModel.GetById 61ms app.highlight 11ms RepoModel.GetById 29ms app.codeStats 0ms

/src/mpv5/ui/beans/LabeledTextChooser.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 185 lines | 106 code | 22 blank | 57 comment | 14 complexity | 25741ebfe6d22dc0f20ccf2bf7858a34 MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6/*
  7 * LabeledTextField.java
  8 *
  9 * Created on 20.11.2008, 19:26:39
 10 */
 11package mpv5.ui.beans;
 12
 13import java.awt.Font;
 14import java.io.File;
 15import javax.swing.JComponent;
 16import javax.swing.filechooser.FileFilter;
 17import mpv5.globals.Messages;
 18import mpv5.ui.dialogs.DialogForFile;
 19import mpv5.ui.dialogs.Popup;
 20import mpv5.ui.dialogs.subcomponents.wizard_XMLImport_1;
 21
 22/**
 23 *
 24 *  
 25 */
 26public class LabeledTextChooser extends javax.swing.JPanel {
 27
 28    private static final long serialVersionUID = 1L;
 29    private String _text;
 30    private String _label;
 31    private int _mode = DialogForFile.FILES_AND_DIRECTORIES;
 32    private FileFilter filter;
 33    private JComponent mparent;
 34
 35    /** Creates new form LabeledTextField */
 36    public LabeledTextChooser() {
 37        initComponents();
 38    }
 39
 40    /**
 41     * Determines if the field has some text
 42     * @return
 43     */
 44    public boolean hasText() {
 45        if (jTextField1.getText() != null && jTextField1.getText().length() > 0) {
 46            return true;
 47        } else {
 48            return false;
 49        }
 50    }
 51
 52    /**
 53     * Sets a File filter for this text field
 54     * @param f
 55     */
 56    public void setFilter(FileFilter f) {
 57        filter = f;
 58    }
 59
 60    /** This method is called from within the constructor to
 61     * initialize the form.
 62     * WARNING: Do NOT modify this code. The content of this method is
 63     * always regenerated by the Form Editor.
 64     */
 65    @SuppressWarnings("unchecked")
 66    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 67    private void initComponents() {
 68
 69        jTextField1 = new mpv5.ui.beans.LabeledTextField();
 70        jButton1 = new javax.swing.JButton();
 71
 72        setOpaque(false);
 73        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));
 74        add(jTextField1);
 75
 76        jButton1.setText("...");
 77        jButton1.setToolTipText("Choose");
 78        jButton1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
 79        jButton1.setMaximumSize(new java.awt.Dimension(50, 100));
 80        jButton1.addActionListener(new java.awt.event.ActionListener() {
 81            public void actionPerformed(java.awt.event.ActionEvent evt) {
 82                jButton1ActionPerformed(evt);
 83            }
 84        });
 85        add(jButton1);
 86    }// </editor-fold>//GEN-END:initComponents
 87
 88    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
 89        DialogForFile dialog = new DialogForFile(getMode());
 90        dialog.setModalityParent(mparent);
 91        if (filter != null) {
 92            dialog.setFileFilter(filter);
 93        }
 94        if (dialog.chooseFile()) {
 95            jTextField1.setText(dialog.getFile().getPath());
 96        }
 97    }//GEN-LAST:event_jButton1ActionPerformed
 98    // Variables declaration - do not modify//GEN-BEGIN:variables
 99    private javax.swing.JButton jButton1;
100    private mpv5.ui.beans.LabeledTextField jTextField1;
101    // End of variables declaration//GEN-END:variables
102
103    /**
104     * @param check if the file exists (pops up a warning if not)
105     * @return the _text
106     */
107    public String get_Text(boolean check) {
108        if (new File(jTextField1.getText()).exists()) {
109            return jTextField1.getText();
110        } else {
111            if (check) {
112                Popup.notice(Messages.FILE_OPEN_FAILED + jTextField1.getText());
113            }
114        }
115        return jTextField1.getText();
116    }
117
118    /**
119     * @param text the _text to set
120     */
121    public void set_Text(String text) {
122        if (text == null) {
123            text = "";
124        }
125        this._text = text;
126        jTextField1.setText(text);
127    }
128
129    /**
130     * @param text the text to set
131     */
132    public void setText(String text) {
133        if (text == null) {
134            text = "";
135        }
136        this._text = text;
137        jTextField1.setText(text);
138    }
139
140    /**
141     * @return the _label
142     */
143    public String get_Label() {
144        return jTextField1.get_Label();
145    }
146
147    /**
148     * @param label the _label to set
149     */
150    public void set_Label(String label) {
151        this._label = label;
152        jTextField1.set_Label(label);
153    }
154
155    @Override
156    public void setEnabled(boolean enabled) {
157        jTextField1.setEnabled(enabled);
158    }
159
160    public void set_LabelFont(Font ignore) {
161    }
162
163    /**
164     * @return the selection mode
165     */
166    public int getMode() {
167        return _mode;
168    }
169
170    /**
171     * Default: javax.?swing.?JFileChooser.FILES_AND_DIRECTORIES
172     * @param mode the selection mode to set
173     */
174    public void setMode(int mode) {
175        this._mode = mode;
176    }
177
178    /**
179     * Sets the modality parent for the popup dialogs
180     * @param parent
181     */
182    public void setModalityParent(JComponent parent) {
183        this.mparent=parent;
184    }
185}