001: package discRack.presentation.delements;
002:
003: import discRack.presentation.dpanels.*;
004:
005: import javax.swing.JPanel;
006: import javax.swing.JComponent;
007:
008: import java.io.*;
009: import java.util.*;
010:
011: /**
012: * Represents a simple element which have a panel for it's editing.
013: *
014: * @author Sasa Bojanic
015: * @version 1.0
016: */
017: public class DSimpleElement {
018:
019: protected String name;
020: protected Object value;
021:
022: protected boolean isRequired = false;
023: protected boolean isReadOnly = false;
024:
025: private boolean isDCheckPanel = false;
026: private boolean isPassword = false;
027:
028: public DSimpleElement(String name) {
029: this (name, false);
030: }
031:
032: public DSimpleElement(String name, boolean isDCheckPanel) {
033: this (name, isDCheckPanel, false);
034: }
035:
036: public DSimpleElement(String name, boolean isDCheckPanel,
037: boolean isPassword) {
038: this .name = name;
039: this .isDCheckPanel = isDCheckPanel;
040: this .isPassword = isPassword;
041: value = new String();
042: }
043:
044: public void setReadOnly(boolean ro) {
045: isReadOnly = ro;
046: }
047:
048: public boolean isReadOnly() {
049: return isReadOnly;
050: }
051:
052: public void setRequired(boolean r) {
053: isRequired = r;
054: }
055:
056: public boolean isRequired() {
057: return isRequired;
058: }
059:
060: public boolean isEmpty() {
061: return !(value != null && value.toString().trim().length() > 0);
062: }
063:
064: public boolean isValid() {
065: return true;
066: }
067:
068: public boolean setDODSElements(DPanel p) {
069: return true;
070: }
071:
072: public DPanel getPanel() {
073: if (!isDCheckPanel) {
074: return new DTextPanel(this , isPassword);
075: } else {
076: return new DCheckPanel(this );
077: }
078: }
079:
080: public void setValue(Object v) {
081: if (v != null) {
082: value = v;
083: } else {
084: value = "";
085: }
086: }
087:
088: public Object toValue() {
089: return value;
090: }
091:
092: public String toName() {
093: return name;
094: }
095:
096: public String toString() {
097: if (value != null) {
098: return value.toString().trim();
099: } else {
100: return name;
101: }
102: }
103:
104: }
|