001: package com.salmonllc.html;
002:
003: /////////////////////////
004: //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlPasswordEdit.java $
005: //$Author: Dan $
006: //$Revision: 22 $
007: //$Modtime: 10/28/03 1:22p $
008: /////////////////////////
009:
010: import java.util.Hashtable;
011:
012: import com.salmonllc.html.events.ValueChangedEvent;
013: import com.salmonllc.properties.Props;
014:
015: /**
016: * This class is used for password style text input in a page.
017: */
018: public class HtmlPasswordEdit extends HtmlFormComponent {
019: private String _fontTagStart;
020: private String _fontTagEnd;
021: private int _maxLength = 20;
022: private int _size = 10;
023: private Boolean _readOnly;
024: private Integer _tabIndex;
025: private String _accessKey;
026:
027: /**
028: * Constructs a new HTMLPasswordEdit component.
029: * @param name The name of the component
030: * @param p The page the component will be placed in.
031: */
032: public HtmlPasswordEdit(String name, com.salmonllc.html.HtmlPage p) {
033: this (name, null, p);
034: }
035:
036: /**
037: * Constructs a new HTMLPasswordEdit component.
038: * @param name The name of the component
039: * @param theme The theme to use for loading properties.
040: * @param p The page the component will be placed in.
041: */
042: public HtmlPasswordEdit(String name, String theme,
043: com.salmonllc.html.HtmlPage p) {
044: super (name, theme, p);
045: }
046:
047: public void generateHTML(java.io.PrintWriter p, int rowNo)
048: throws Exception {
049: if (!_visible)
050: return;
051:
052: String name = getFullName();
053: if (rowNo > -1)
054: name += "_" + rowNo;
055:
056: String tag = "<INPUT TYPE=\"PASSWORD\" NAME=\"" + name + "\"";
057:
058: if (!getEnabled()) {
059: if (useDisabledAttribute())
060: tag += " DISABLED=\"true\"";
061: else {
062: String value = getValue(rowNo, true);
063: String out = "";
064: if (value == null)
065: value = "";
066: int n = value.length();
067: while (n-- > 0)
068: out += "*";
069: n = _size - value.length();
070: while (n-- > 0)
071: out += " ";
072: if ((value.length() == 0) && (_size <= 0))
073: out = " ";
074: if (_disabledFontStartTag != null)
075: p.print(_disabledFontStartTag + out
076: + _disabledFontEndTag);
077: else
078: p.print(out);
079: return;
080: }
081: }
082:
083: if (_maxLength > -1)
084: tag += " MAXLENGTH=\"" + _maxLength + "\"";
085:
086: if (_size > -1) {
087: int size = _size;
088: if (getPage().getBrowserType() == HtmlPage.BROWSER_NETSCAPE
089: && getPage().getBrowserVersion() == 4)
090: size = (int) (size * .60);
091: tag += " SIZE=\"" + size + "\"";
092: }
093:
094: String value = getValue(rowNo, true);
095:
096: if (value != null)
097: tag += " VALUE=\"" + value + "\"";
098:
099: if (_class != null)
100: tag += " class=\"" + _class + "\"";
101:
102: if (_tabIndex != null)
103: tag += " tabindex=\"" + _tabIndex + "\"";
104:
105: if (_accessKey != null)
106: tag += " accesskey=\"" + _accessKey + "\"";
107:
108: if (_readOnly != null)
109: tag += " readonly=\"" + _readOnly + "\"";
110:
111: tag += ">";
112:
113: if (_fontTagStart != null)
114: tag = _fontTagStart + tag + _fontTagEnd;
115:
116: p.println(tag);
117: writeFocusScript(p, rowNo);
118: }
119:
120: /**
121: * This method gets the end font tag for the component.
122: */
123: public String getFontEndTag() {
124: return _fontTagEnd;
125: }
126:
127: /**
128: * This method gets the start font tag for the component.
129: */
130: public String getFontStartTag() {
131: return _fontTagStart;
132: }
133:
134: /**
135: * This method gets the maximum length for the text in the component.
136: */
137: public int getMaxLength() {
138: return _maxLength;
139: }
140:
141: /**
142: * This method gets the display size for the component in characters.
143: */
144: public int getSize() {
145: return _size;
146: }
147:
148: public boolean processParms(Hashtable parms, int rowNo)
149: throws Exception {
150: if (!getEnabled())
151: return false;
152: Object oldValue = _value;
153:
154: String name = getFullName();
155: if (rowNo > -1) {
156: name += "_" + rowNo;
157: if (_dsBuff != null)
158: oldValue = _dsBuff.getAny(rowNo, _dsColNo);
159: } else {
160: if (_dsBuff != null)
161: oldValue = _dsBuff.getAny(_dsColNo);
162: }
163:
164: String val[] = (String[]) parms.get(name);
165:
166: if (val != null) {
167: _value = val[0].trim();
168: if (_value.equals(""))
169: _value = null;
170: } else
171: _value = null;
172:
173: if (!valuesEqual(oldValue, _value)) {
174: String s = null;
175: if (oldValue != null)
176: s = oldValue.toString();
177: ValueChangedEvent e = new ValueChangedEvent(getPage(),
178: this , getName(), getFullName(), s, _value, rowNo,
179: _dsColNo, _dsBuff);
180: addEvent(e);
181: }
182:
183: return false;
184:
185: }
186:
187: /**
188: * This method sets the end font tag for the component.
189: */
190: public void setFontEndTag(String value) {
191: _fontTagEnd = value;
192: }
193:
194: /**
195: * This method sets the start font tag for the component.
196: */
197: public void setFontStartTag(String value) {
198: _fontTagStart = value;
199: }
200:
201: /**
202: * This method sets the maximum length for the text in the component.
203: */
204: public void setMaxLength(int maxLength) {
205: _maxLength = maxLength;
206: }
207:
208: /**
209: * This method sets the display size for the component in characters.
210: */
211: public void setSize(int size) {
212: _size = size;
213: }
214:
215: /**
216: * This method sets the property theme for the component.
217: * @param theme The theme to use.
218: */
219: public void setTheme(String theme) {
220:
221: super .setTheme(theme);
222: Props props = getPage().getPageProperties();
223: _fontTagStart = props.getThemeProperty(theme,
224: Props.FONT_TEXT_EDIT + Props.TAG_START);
225: _fontTagEnd = props.getThemeProperty(theme,
226: Props.FONT_TEXT_EDIT + Props.TAG_END);
227:
228: }
229:
230: /**
231: * @returns the access key html attribute
232: */
233: public String getAccessKey() {
234: return _accessKey;
235: }
236:
237: /**
238: * @returns the read only html attribute
239: */
240: public boolean getReadOnly() {
241: if (_readOnly == null)
242: return false;
243: return _readOnly.booleanValue();
244: }
245:
246: /**
247: * @returns the tab index html attribute
248: */
249: public int getTabIndex() {
250: if (_tabIndex == null)
251: return -1;
252: return _tabIndex.intValue();
253: }
254:
255: /**
256: * @param sets the access key html attribute
257: */
258: public void setAccessKey(String string) {
259: _accessKey = string;
260: }
261:
262: /**
263: * @param sets the read only html attribute
264: */
265: public void setReadOnly(boolean val) {
266: if (val == false)
267: _readOnly = null;
268: else
269: _readOnly = Boolean.TRUE;
270: }
271:
272: /**
273: * @param sets the tab index html attribute. You can also pass TAB_INDEX_DEFAULT to use the default tab index for the component or TAB_INDEX_NONE to keep this component from being tabbed to
274: */
275: public void setTabIndex(int val) {
276: if (val == -1)
277: _tabIndex = null;
278: else
279: _tabIndex = new Integer(val);
280: }
281:
282: }
|