01: package discRack.presentation.dpanels;
02:
03: import discRack.presentation.delements.*;
04:
05: import java.util.*;
06: import javax.swing.*;
07: import java.awt.*;
08: import java.awt.event.*;
09:
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()
54: && !getOwner().isReadOnly()) {
55: DPanel.defaultErrorMessage(this .getWindow(),
56: ((JLabel) getComponent(1)).getText());
57: ((JTextField) getComponent(2)).requestFocus();
58: return false;
59: }
60: return true;
61: }
62:
63: public boolean isEmpty() {
64: return getText().trim().equals("");
65: }
66:
67: public void setElements() {
68: getOwner().setValue(getText());
69: }
70:
71: public String getText() {
72: return ((JTextField) getComponent(2)).getText();
73: }
74:
75: }
|