KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > dpanels > DTextPanel


1 package discRack.presentation.dpanels;
2
3 import discRack.presentation.delements.*;
4
5 import java.util.*;
6 import javax.swing.*;
7 import java.awt.*;
8 import java.awt.event.*;
9
10 /**
11  * Creates panel with JLabel and JTextField.
12  *
13  * @author Sasa Bojanic
14  * @version 1.0
15  */

16 public class DTextPanel extends DPanel {
17
18    public DTextPanel (DSimpleElement myOwner,boolean isPasswordField) {
19
20       super(myOwner,3,"",false,false);
21
22       JLabel jl=new JLabel(myOwner.toName()+": ");
23       jl.setAlignmentX(Component.LEFT_ALIGNMENT);
24       jl.setAlignmentY(Component.TOP_ALIGNMENT);
25       jl.setHorizontalAlignment(SwingConstants.RIGHT);
26
27       JTextField jtf;
28       if (isPasswordField) {
29          jtf=new JPasswordField();
30       } else {
31          jtf=new JTextField();
32       }
33       jtf.setText(myOwner.toValue().toString());
34       jtf.setAlignmentX(Component.LEFT_ALIGNMENT);
35       jtf.setAlignmentY(Component.TOP_ALIGNMENT);
36       jtf.setMinimumSize(new Dimension(textFieldDimension));
37       jtf.setMaximumSize(new Dimension(textFieldDimension));
38       jtf.setPreferredSize(new Dimension(textFieldDimension));
39
40       jtf.setEnabled(!myOwner.isReadOnly());
41
42       Dimension minSize = new Dimension(5, 10);
43       Dimension prefSize = new Dimension(100, 10);
44       Dimension maxSize = new Dimension(Short.MAX_VALUE,10);
45
46       add(Box.createHorizontalGlue());
47       add(jl);
48       add(jtf);
49
50    }
51
52    public boolean checkRequired () {
53       if (isEmpty() && getOwner().isRequired() && !getOwner().isReadOnly()) {
54          DPanel.defaultErrorMessage(this.getWindow(),((JLabel)getComponent(1)).getText());
55          ((JTextField)getComponent(2)).requestFocus();
56          return false;
57       }
58       return true;
59    }
60
61    public boolean isEmpty () {
62       return getText().trim().equals("");
63    }
64
65    public void setElements () {
66       getOwner().setValue(getText());
67    }
68
69    public String JavaDoc getText () {
70       return ((JTextField)getComponent(2)).getText();
71    }
72
73 }
74
Popular Tags