001: package org.enhydra.jawe.base.panel.panels;
002:
003: import java.awt.Component;
004: import java.awt.Container;
005: import java.awt.Window;
006:
007: import javax.swing.BorderFactory;
008: import javax.swing.BoxLayout;
009: import javax.swing.JOptionPane;
010: import javax.swing.border.Border;
011: import javax.swing.border.EtchedBorder;
012:
013: import org.enhydra.jawe.JaWEManager;
014: import org.enhydra.jawe.ResourceManager;
015: import org.enhydra.jawe.base.editor.XPDLElementEditor;
016: import org.enhydra.jawe.base.panel.PanelContainer;
017: import org.enhydra.shark.xpdl.XMLElement;
018:
019: /**
020: * Basic implementation of XMLPanel interface.
021: *
022: * @author Sasa Bojanic
023: */
024: public class XMLBasicPanel extends XMLPanel {
025:
026: protected XMLElement myOwner;
027: // protected XMLElement myOwnerOrginal;
028: protected String title;
029:
030: protected XPDLElementEditor editor;
031: protected PanelContainer pc;
032:
033: public XMLBasicPanel() {
034: super ();
035: }
036:
037: public XPDLElementEditor getEditor() {
038: return editor;
039: }
040:
041: public XMLBasicPanel(PanelContainer pc, XMLElement myOwnerL,
042: String title, boolean isVertical, boolean hasBorder,
043: boolean hasEmptyBorder) {
044:
045: super ();
046: this .pc = pc;
047: this .myOwner = myOwnerL;
048:
049: setBorder(title, hasBorder, hasEmptyBorder);
050:
051: setLayout(new BoxLayout(this , ((isVertical) ? BoxLayout.Y_AXIS
052: : BoxLayout.X_AXIS)));
053: setAlignmentX(Component.LEFT_ALIGNMENT);
054: setAlignmentY(Component.TOP_ALIGNMENT);
055:
056: if (myOwner != null) {
057: setEnabled(JaWEManager.getInstance().getJaWEController()
058: .canModifyElement(myOwner));
059: }
060:
061: }
062:
063: public void setBorder(String title, boolean hasBorder,
064: boolean hasEmptyBorder) {
065: this .title = title;
066:
067: // int emptyBorderHSize=4;
068: // int emptyBorderVSize=4;
069: //
070: // Border emptyb=BorderFactory.createEmptyBorder(emptyBorderVSize,emptyBorderHSize,
071: // emptyBorderVSize,emptyBorderHSize);
072: // Border inb=BorderFactory.createEmptyBorder(0,0,0,0);
073: // if (hasBorder) {
074: // inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
075: // inb=BorderFactory.createTitledBorder(inb,title);
076: // }
077: // else {
078: // emptyb=BorderFactory.createTitledBorder(emptyb,title);
079: // }
080: // setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
081:
082: int emptyBT = 0;
083: int emptyBL = 3;
084: int emptyBB = 4;
085: int emptyBR = 3;
086: try {
087: emptyBT = pc.getSettings().getSettingInt("EmptyBorder.TOP");
088: emptyBL = pc.getSettings()
089: .getSettingInt("EmptyBorder.LEFT");
090: emptyBB = pc.getSettings().getSettingInt(
091: "EmptyBorder.BOTTOM");
092: emptyBR = pc.getSettings().getSettingInt(
093: "EmptyBorder.RIGHT");
094: } catch (Exception e) {
095: }
096:
097: Border border = null;
098: if (hasBorder) {
099: //BorderFactory.cre
100: border = BorderFactory
101: .createEtchedBorder(EtchedBorder.LOWERED);
102: //border=BorderFactory.createMatteBorder(1,0,0,0);
103: border = BorderFactory.createTitledBorder(border, title);
104: //border=BorderFactory.createCompoundBorder(etched,border);
105: } else {
106: if (hasEmptyBorder) {
107: border = BorderFactory.createEmptyBorder(emptyBT,
108: emptyBL, emptyBB, emptyBR);
109: }
110: }
111: if (border != null) {
112: setBorder(border);
113: }
114:
115: }
116:
117: public static void defaultErrorMessage(Window w, String elementTitle) {
118: String message = ResourceManager
119: .getLanguageDependentString("ErrorValueMustBeDefined");
120: String dialogTitle = ResourceManager
121: .getLanguageDependentString("DialogValueIsNotDefined");
122: XMLBasicPanel.errorMessage(w, dialogTitle, elementTitle,
123: message);
124: }
125:
126: public static void errorMessage(Window w, String dialogTitle,
127: String elementTitle, String message) {
128: JOptionPane.showMessageDialog(w, elementTitle + message,
129: dialogTitle, JOptionPane.ERROR_MESSAGE);
130: }
131:
132: public void setOwner(XMLElement owner) {
133: this .myOwner = owner;
134: }
135:
136: public XMLElement getOwner() {
137: return myOwner;
138: }
139:
140: // public XMLElement getOrginalOwner () {
141: // return myOwnerOrginal;
142: // }
143:
144: public String getTitle() {
145: return title;
146: }
147:
148: /**
149: * Checks if the element that owns panel
150: */
151: public boolean validateEntry() {
152: return true;
153: }
154:
155: // Always returns true, this is set because of panels that are never empty
156: // but this method is used when checking emptiness of group panel,
157: // and panels that do not override this method should not be ever considered
158: public boolean isEmpty() {
159: return true;
160: }
161:
162: public void setElements() {
163: return;
164: }
165:
166: public Object getValue() {
167: return null;
168: }
169:
170: public void updateView() {
171:
172: }
173:
174: //public JComponent getMainComponent () {
175: // return this;
176: //}
177: /**
178: * Find the hosting window.
179: */
180: public Window getWindow() {
181: for (Container p = getParent(); p != null; p = p.getParent()) {
182: if (p instanceof Window) {
183: return (Window) p;
184: }
185: }
186: return null;
187: }
188:
189: public void cleanup() {
190: }
191:
192: public PanelContainer getPanelContainer() {
193: return this .pc;
194: }
195:
196: public void canceled() {
197: }
198:
199: }
|