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.ActionEvent;
007: import java.awt.event.ActionListener;
008: import java.awt.event.KeyAdapter;
009: import java.awt.event.KeyEvent;
010:
011: import javax.swing.Box;
012: import javax.swing.JButton;
013: import javax.swing.JLabel;
014: import javax.swing.JTextField;
015: import javax.swing.SwingConstants;
016:
017: import org.enhydra.jawe.JaWEXMLUtil;
018: import org.enhydra.jawe.ResourceManager;
019: import org.enhydra.jawe.Settings;
020: import org.enhydra.jawe.base.panel.PanelContainer;
021: import org.enhydra.jawe.base.panel.PanelSettings;
022: import org.enhydra.shark.xpdl.XMLElement;
023:
024: /**
025: * Creates panel with JLabel, JTextField and JButton, this panel is
026: * used to set the file name from some choosed location.
027: * @author Sasa Bojanic
028: */
029: public class XMLLocationPanel extends XMLBasicPanel {
030:
031: private static Dimension fileButtonDimension = new Dimension(25, 20);
032:
033: protected JTextField jtf;
034: protected JLabel jl;
035:
036: public XMLLocationPanel(PanelContainer pc, XMLElement myOwnerL,
037: boolean isEnabled) {
038: this (pc, myOwnerL, isEnabled, -1);
039: }
040:
041: public XMLLocationPanel(PanelContainer pc, XMLElement myOwner,
042: boolean isEnabled, final int filteringMode) {
043:
044: super (pc, myOwner, "", false, false, true);
045:
046: boolean rightAllignment = false;
047: Dimension textDim = new Dimension(250, 20);
048:
049: Color bkgCol = new Color(245, 245, 245);
050: if (pc != null) {
051: Settings settings = pc.getSettings();
052:
053: rightAllignment = settings
054: .getSettingBoolean("XMLBasicPanel.RightAllignment");
055:
056: textDim = new Dimension(settings
057: .getSettingInt("SimplePanelTextWidth"), settings
058: .getSettingInt("SimplePanelTextHeight"));
059: fileButtonDimension = new Dimension(
060: fileButtonDimension.width, textDim.height);
061: textDim.width = textDim.width - fileButtonDimension.width;
062:
063: if (settings instanceof PanelSettings) {
064: bkgCol = ((PanelSettings) settings)
065: .getBackgroundColor();
066: }
067:
068: jl = new JLabel(pc.getLabelGenerator().getLabel(myOwner)
069: + ": ");
070: } else {
071: jl = new JLabel(ResourceManager
072: .getLanguageDependentString(myOwner.toName()
073: + "Key")
074: + ": ");
075: }
076:
077: jl.setAlignmentX(Component.LEFT_ALIGNMENT);
078: jl.setAlignmentY(Component.BOTTOM_ALIGNMENT);
079: jl.setHorizontalAlignment(SwingConstants.RIGHT);
080: //jl.setMaximumSize(new Dimension(Short.MAX_VALUE,10));
081:
082: jtf = new JTextField();
083: jtf.setText(myOwner.toValue());
084: jtf.setAlignmentX(Component.LEFT_ALIGNMENT);
085: jtf.setAlignmentY(Component.BOTTOM_ALIGNMENT);
086: jtf.setMinimumSize(new Dimension(textDim));
087: jtf.setMaximumSize(new Dimension(textDim));
088: jtf.setPreferredSize(new Dimension(textDim));
089: jtf.setEnabled(isEnabled);
090: jtf.setBackground(bkgCol);
091:
092: //add key listener
093: final XMLPanel p = this ;
094: jtf.addKeyListener(new KeyAdapter() {
095: public void keyPressed(KeyEvent e) {
096: if (getPanelContainer() == null)
097: return;
098: if (PanelUtilities.isModifyingEvent(e)) {
099: getPanelContainer().panelChanged(p, e);
100: }
101: }
102: });
103:
104: JButton jb = new JButton("...");
105: jb.setAlignmentX(Component.LEFT_ALIGNMENT);
106: jb.setAlignmentY(Component.BOTTOM_ALIGNMENT);
107: jb.setMinimumSize(new Dimension(fileButtonDimension));
108: jb.setMaximumSize(new Dimension(fileButtonDimension));
109: jb.setPreferredSize(new Dimension(fileButtonDimension));
110: jb.setEnabled(isEnabled);
111:
112: if (rightAllignment) {
113: add(Box.createHorizontalGlue());
114: }
115: add(jl);
116: if (!rightAllignment) {
117: // add(Box.createRigidArea(new Dimension(200-jl.getPreferredSize().width,1)));
118: add(Box.createHorizontalGlue());
119:
120: }
121: add(jtf);
122: add(jb);
123:
124: jb.addActionListener(new ActionListener() {
125: public void actionPerformed(ActionEvent ae) {
126: String fileName = "";
127: String message = ResourceManager
128: .getLanguageDependentString("DialogChooseFile");
129: fileName = JaWEXMLUtil.dialog(getWindow(), message, 0,
130: filteringMode, null);
131: if (fileName != null && fileName.length() > 0) {
132: jtf.setText(fileName);
133: if (getPanelContainer() == null)
134: return;
135: getPanelContainer().panelChanged(p, ae);
136: }
137: }
138: });
139: }
140:
141: public boolean validateEntry() {
142: if (isEmpty() && getOwner().isRequired()
143: && !getOwner().isReadOnly()) {
144:
145: //TODO CHECK THIS
146: XMLBasicPanel.defaultErrorMessage(this .getWindow(), jl
147: .getText());
148: jtf.requestFocus();
149: return false;
150: }
151: return true;
152: }
153:
154: public boolean isEmpty() {
155: return getText().trim().equals("");
156: }
157:
158: public void setElements() {
159: if (!getOwner().isReadOnly()) {
160: myOwner.setValue(getText().trim());
161: }
162: }
163:
164: public String getText() {
165: return jtf.getText();
166: }
167:
168: public Object getValue() {
169: return getText();
170: }
171:
172: public void requestFocus() {
173: jtf.requestFocus();
174: }
175:
176: }
|