001: package org.swingml.model;
002:
003: import javax.swing.*;
004: import javax.swing.text.*;
005:
006: import org.swingml.*;
007: import org.swingml.system.*;
008:
009: /**
010: * @author NumberSix
011: */
012: public class JFormattedTextFieldModel extends SwingMLModel {
013:
014: private boolean autoSelect = true;
015: private String button; // Name of the button that should be clicked on a return (enter) key press.
016: private String cols = null;
017: private boolean editable = true;
018: private boolean enabled = true;
019: private JFormattedTextField.AbstractFormatter formatter = null;
020: private boolean overwrite = false;
021: private String pattern = null;
022: private char placeholdChar = ' ';
023: private String placeholder = null;
024:
025: public JFormattedTextFieldModel() {
026: super ();
027: }
028:
029: public String getCols() {
030: return this .cols;
031: }
032:
033: public JFormattedTextField.AbstractFormatter getFormatter() {
034: return this .formatter;
035: }
036:
037: public String getPattern() {
038: return pattern;
039: }
040:
041: public char getPlaceholdChar() {
042: return placeholdChar;
043: }
044:
045: public String getPlaceholder() {
046: return placeholder;
047: }
048:
049: public String getReturnButton() {
050: return button;
051: }
052:
053: public boolean isEditable() {
054: return this .editable;
055: }
056:
057: public boolean isEnabled() {
058: return this .enabled;
059: }
060:
061: public boolean isOverwrite() {
062: return overwrite;
063: }
064:
065: public void setAutoSelect(boolean shouldAutoSelect) {
066: this .autoSelect = shouldAutoSelect;
067: }
068:
069: public void setCols(String columns) {
070: this .cols = columns;
071: }
072:
073: public void setEditable(boolean isEditable) {
074: this .editable = isEditable;
075: }
076:
077: public void setEnabled(boolean isEnabled) {
078: this .enabled = isEnabled;
079: }
080:
081: public void setFormatter(
082: JFormattedTextField.AbstractFormatter aFormatter) {
083: this .formatter = aFormatter;
084: }
085:
086: public void setOverwrite(boolean shouldOverwrite) {
087: overwrite = shouldOverwrite;
088: }
089:
090: public void setPattern(String aPattern) {
091: pattern = aPattern;
092: }
093:
094: public void setPlaceholdChar(char aChar) {
095: placeholdChar = aChar;
096: }
097:
098: public void setPlaceholder(String aPlaceholder) {
099: placeholder = aPlaceholder;
100: }
101:
102: public void setReturnButton(final String aButtonName) {
103: button = aButtonName;
104: }
105:
106: public boolean shouldAutoSelectOnFocus() {
107: return autoSelect;
108: }
109:
110: public void validate() {
111: if (super .getParent().getLayout() != null
112: && super .getParent().getLayout().equalsIgnoreCase(
113: Constants.BORDERLAYOUT)) {
114: if (super .getOrientation() == null) {
115: SwingMLLogger
116: .getInstance()
117: .log(
118: "Syntax error: The parameter ORIENTATION in the element "
119: + super .getName()
120: + " is required since its parent's LAYOUT is BorderLayout. Add the parameter ORIENTATION to the element "
121: + super .getName()
122: + " or change its parent's LAYOUT to other than BorderLayout.");
123: }
124: }
125: if (super .getParent().getLayout() != null
126: && !super .getParent().getLayout().equalsIgnoreCase(
127: Constants.BORDERLAYOUT)) {
128: if (super .getOrientation() != null) {
129: SwingMLLogger
130: .getInstance()
131: .log(
132: "Syntax error: The parameter ORIENTATION in the element "
133: + super .getName()
134: + " should be used only when its parent's LAYOUT is BorderLayout. Change its parent's LAYOUT to BorderLayout or delete the parameter ORIENTATION from the element "
135: + super .getName() + ".");
136: }
137: }
138: try {
139: Integer.parseInt(this .cols);
140: } catch (NumberFormatException e) {
141: this .cols = "0";
142: SwingMLLogger.getInstance().log(
143: "Syntax error: The parameter COLS in the element "
144: + super .getName()
145: + " should be a numeric value.");
146: }
147: JFormattedTextField.AbstractFormatter aFormatter = this
148: .getFormatter();
149: if (aFormatter == null) {
150: SwingMLLogger.getInstance().log(
151: "Syntax error: The parameter FORMATTER in the element "
152: + super .getName() + " is required.");
153: }
154: if (aFormatter != null && aFormatter instanceof MaskFormatter) {
155: if (this .pattern == null) {
156: SwingMLLogger
157: .getInstance()
158: .log(
159: "Syntax error: The parameter PATTERN in the element "
160: + super .getName()
161: + " is required for FORMATTER MaskFormatter.");
162: }
163: }
164: }
165: }
|