KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > delements > DSimpleElement


1 package discRack.presentation.delements;
2
3 import discRack.presentation.dpanels.*;
4
5 import javax.swing.JPanel JavaDoc;
6 import javax.swing.JComponent JavaDoc;
7
8 import java.io.*;
9 import java.util.*;
10
11 /**
12  * Represents a simple element which have a panel for it's editing.
13  *
14  * @author Sasa Bojanic
15  * @version 1.0
16  */

17 public class DSimpleElement {
18
19    protected String JavaDoc name;
20    protected Object JavaDoc value;
21
22    protected boolean isRequired=false;
23    protected boolean isReadOnly=false;
24
25    private boolean isDCheckPanel=false;
26    private boolean isPassword=false;
27
28    public DSimpleElement (String JavaDoc name) {
29       this (name,false);
30    }
31
32    public DSimpleElement (String JavaDoc name,boolean isDCheckPanel) {
33       this(name,isDCheckPanel,false);
34    }
35
36    public DSimpleElement (String JavaDoc name,boolean isDCheckPanel,boolean isPassword) {
37       this.name=name;
38       this.isDCheckPanel=isDCheckPanel;
39       this.isPassword=isPassword;
40       value=new String JavaDoc();
41    }
42
43    public void setReadOnly (boolean ro) {
44       isReadOnly=ro;
45    }
46
47    public boolean isReadOnly () {
48       return isReadOnly;
49    }
50
51    public void setRequired (boolean r) {
52       isRequired=r;
53    }
54
55    public boolean isRequired () {
56       return isRequired;
57    }
58
59    public boolean isEmpty () {
60       return !(value!=null && value.toString().trim().length()>0);
61    }
62
63    public boolean isValid () {
64       return true;
65    }
66
67    public boolean setDODSElements (DPanel p) {
68       return true;
69    }
70
71    public DPanel getPanel () {
72       if (!isDCheckPanel) {
73          return new DTextPanel(this,isPassword);
74       } else {
75          return new DCheckPanel(this);
76       }
77    }
78
79    public void setValue(Object JavaDoc v) {
80       if (v!=null) {
81          value=v;
82       } else {
83          value="";
84       }
85    }
86
87    public Object JavaDoc toValue() {
88       return value;
89    }
90
91    public String JavaDoc toName () {
92       return name;
93    }
94
95    public String JavaDoc toString () {
96       if (value!=null) {
97          return value.toString().trim();
98       }
99       else {
100          return name;
101       }
102    }
103
104 }
105
Popular Tags