01: package jtaDiscRack.presentation.dpanels;
02:
03: import jtaDiscRack.presentation.delements.*;
04:
05: import javax.swing.*;
06: import java.awt.*;
07:
08: /**
09: * Creates panel with JLabel and JTextField.
10: *
11: * @author Sasa Bojanic
12: * @version 1.0
13: */
14: public class DTextPanel extends DPanel {
15:
16: public DTextPanel(DSimpleElement myOwner, boolean isPasswordField) {
17:
18: super (myOwner, 3, "", false, false);
19:
20: JLabel jl = new JLabel(myOwner.toName() + ": ");
21: jl.setAlignmentX(Component.LEFT_ALIGNMENT);
22: jl.setAlignmentY(Component.TOP_ALIGNMENT);
23: jl.setHorizontalAlignment(SwingConstants.RIGHT);
24:
25: JTextField jtf;
26: if (isPasswordField) {
27: jtf = new JPasswordField();
28: } else {
29: jtf = new JTextField();
30: }
31: jtf.setText(myOwner.toValue().toString());
32: jtf.setAlignmentX(Component.LEFT_ALIGNMENT);
33: jtf.setAlignmentY(Component.TOP_ALIGNMENT);
34: jtf.setMinimumSize(new Dimension(textFieldDimension));
35: jtf.setMaximumSize(new Dimension(textFieldDimension));
36: jtf.setPreferredSize(new Dimension(textFieldDimension));
37:
38: jtf.setEnabled(!myOwner.isReadOnly());
39:
40: add(Box.createHorizontalGlue());
41: add(jl);
42: add(jtf);
43:
44: }
45:
46: public boolean checkRequired() {
47: if (isEmpty() && getOwner().isRequired()
48: && !getOwner().isReadOnly()) {
49: DPanel.defaultErrorMessage(this .getWindow(),
50: ((JLabel) getComponent(1)).getText());
51: ((JTextField) getComponent(2)).requestFocus();
52: return false;
53: }
54: return true;
55: }
56:
57: public boolean isEmpty() {
58: return getText().trim().equals("");
59: }
60:
61: public void setElements() {
62: getOwner().setValue(getText());
63: }
64:
65: public String getText() {
66: return ((JTextField) getComponent(2)).getText();
67: }
68:
69: }
|