001: package org.enhydra.jawe.base.panel.panels;
002:
003: import java.awt.Color;
004: import java.awt.Component;
005: import java.awt.Dimension;
006: import java.awt.event.KeyAdapter;
007: import java.awt.event.KeyEvent;
008:
009: import javax.swing.Box;
010: import javax.swing.JLabel;
011: import javax.swing.JPasswordField;
012: import javax.swing.JTextField;
013: import javax.swing.SwingConstants;
014:
015: import org.enhydra.jawe.ResourceManager;
016: import org.enhydra.jawe.Settings;
017: import org.enhydra.jawe.base.panel.PanelContainer;
018: import org.enhydra.jawe.base.panel.PanelSettings;
019: import org.enhydra.shark.xpdl.XMLElement;
020:
021: /**
022: * Creates panel with JLabel and JTextField.
023: * @author Sasa Bojanic
024: */
025: public class XMLTextPanel extends XMLBasicPanel {
026:
027: protected JLabel jl;
028: protected JTextField jtf;
029:
030: public XMLTextPanel(PanelContainer pc, XMLElement myOwnerL,
031: boolean isVertical, boolean isPasswordField,
032: boolean isEnabled) {
033:
034: this (pc, myOwnerL, null, isVertical, isPasswordField, isEnabled);
035: }
036:
037: public XMLTextPanel(PanelContainer pc, XMLElement myOwnerL,
038: String label, boolean isVertical, boolean isPasswordField,
039: boolean isEnabled) {
040:
041: super (pc, myOwnerL, "", isVertical, false, true);
042:
043: boolean rightAllignment = false;
044: Dimension textDim = new Dimension(250, 20);
045:
046: Color bkgCol = new Color(245, 245, 245);
047:
048: if (pc != null) {
049: Settings settings = pc.getSettings();
050:
051: rightAllignment = settings
052: .getSettingBoolean("XMLBasicPanel.RightAllignment");
053:
054: textDim = new Dimension(settings
055: .getSettingInt("SimplePanelTextWidth"), settings
056: .getSettingInt("SimplePanelTextHeight"));
057:
058: if (settings instanceof PanelSettings) {
059: bkgCol = ((PanelSettings) settings)
060: .getBackgroundColor();
061: }
062:
063: }
064: if (label == null) {
065: if (pc != null) {
066: label = pc.getLabelGenerator().getLabel(myOwner);
067: } else {
068: label = ResourceManager
069: .getLanguageDependentString(myOwner.toName()
070: + "Key");
071: }
072: }
073: jl = new JLabel(label + ": ");
074: jl.setAlignmentX(Component.LEFT_ALIGNMENT);
075: jl.setAlignmentY(Component.BOTTOM_ALIGNMENT);
076: if (rightAllignment) {
077: jl.setHorizontalAlignment(SwingConstants.RIGHT);
078: } else {
079: jl.setHorizontalAlignment(SwingConstants.LEFT);
080: }
081:
082: if (!isPasswordField) {
083: jtf = new JTextField();
084: } else {
085: jtf = new JPasswordField();
086: }
087: jtf.setText(myOwner.toValue());
088: jtf.setAlignmentX(Component.LEFT_ALIGNMENT);
089: jtf.setAlignmentY(Component.BOTTOM_ALIGNMENT);
090: jtf.setMinimumSize(new Dimension(textDim));
091: jtf.setMaximumSize(new Dimension(textDim));
092: jtf.setPreferredSize(new Dimension(textDim));
093:
094: jtf.setEnabled(isEnabled);
095:
096: jtf.setBackground(bkgCol);
097:
098: if (rightAllignment && !isVertical) {
099: add(Box.createHorizontalGlue());
100: }
101: add(jl);
102: if (!rightAllignment && !isVertical) {
103: //add(Box.createRigidArea(new Dimension(200-jl.getPreferredSize().width,1)));
104: add(Box.createHorizontalGlue());
105: }
106: add(jtf);
107:
108: final XMLPanel p = this ;
109: //add key listener
110: jtf.addKeyListener(new KeyAdapter() {
111: public void keyPressed(KeyEvent e) {
112: if (getPanelContainer() == null)
113: return;
114: if (PanelUtilities.isModifyingEvent(e)) {
115: getPanelContainer().panelChanged(p, e);
116: }
117: }
118: });
119: }
120:
121: public boolean validateEntry() {
122: if (isEmpty() && getOwner().isRequired()
123: && !getOwner().isReadOnly()) {
124:
125: XMLBasicPanel.defaultErrorMessage(this .getWindow(), jl
126: .getText());
127: jtf.requestFocus();
128: return false;
129: }
130: return true;
131: }
132:
133: public boolean isEmpty() {
134: return getText().trim().equals("");
135: }
136:
137: public void setElements() {
138: if (!getOwner().isReadOnly()) {
139: getOwner().setValue(getText().trim());
140: }
141: }
142:
143: public String getText() {
144: return jtf.getText();
145: }
146:
147: public Object getValue() {
148: return getText();
149: }
150:
151: public void requestFocus() {
152: jtf.requestFocus();
153: }
154:
155: }
|