001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t;
032:
033: import java.awt.*;
034: import java.awt.image.*;
035: import java.io.*;
036: import java.nio.*;
037: import java.nio.channels.*;
038: import java.nio.charset.*;
039: import java.util.*;
040:
041: import javax.imageio.*;
042: import javax.servlet.*;
043: import javax.swing.*;
044:
045: import bsh.*;
046:
047: import com.thoughtworks.xstream.*;
048:
049: import de.ug2t.channel.ho.client.swing.*;
050: import de.ug2t.channel.ho.server.generic.*;
051: import de.ug2t.channel.ho.session.*;
052: import de.ug2t.channel.markup.generic.*;
053: import de.ug2t.channel.markup.html.*;
054: import de.ug2t.channel.markup.service.*;
055: import de.ug2t.connector.*;
056: import de.ug2t.kernel.*;
057: import de.ug2t.model.*;
058: import de.ug2t.model.persistence.*;
059: import de.ug2t.model.values.*;
060: import de.ug2t.process.*;
061: import de.ug2t.unifiedGui.*;
062: import de.ug2t.unifiedGui.interfaces.*;
063: import de.ug2t.xmlScript.*;
064:
065: class BoxBorder {
066: public int pem_width = 1;
067: public int pem_style = IUnComponent.LINE_BORDER;
068: public String pem_color = "black";
069:
070: public BoxBorder(String xColor, int xWidth, int xStyle) {
071: this .pem_width = xWidth;
072: this .pem_style = xStyle;
073: this .pem_color = xColor;
074: }
075: }
076:
077: class SwingBox extends JPanel {
078: class BoxGridBag extends GridBagLayout {
079: public BoxGridBag() {
080: super ();
081: }
082:
083: public void layoutContainer(Container parent) {
084: if (parent.getComponentCount() == 0)
085: return;
086:
087: this .removeLayoutComponent(parent.getComponent(0));
088: GridBagConstraints l_constr = new GridBagConstraints();
089: l_constr.anchor = GridBagConstraints.SOUTHEAST;
090: l_constr.weightx = 1;
091: l_constr.weighty = 1;
092: this .addLayoutComponent(parent.getComponent(0), l_constr);
093: super .layoutContainer(parent);
094:
095: }
096: }
097:
098: private int pem_alignment = 0;
099:
100: private UnBoxBorder pem_bLeft = null;
101: private UnBoxBorder pem_bRight = null;
102: private UnBoxBorder pem_bTop = null;
103: private UnBoxBorder pem_bBottom = null;
104:
105: private int pem_marginLeft = 0;
106: private int pem_marginTop = 0;
107: private int pem_marginRight = 0;
108: private int pem_marginBottom = 0;
109:
110: private int pem_paddingLeft = 0;
111: private int pem_paddingTop = 0;
112: private int pem_paddingRight = 0;
113: private int pem_paddingBottom = 0;
114:
115: private JPanel pem_content = new JPanel();
116:
117: private ImageIcon pem_bg = null;
118:
119: public SwingBox() {
120: super ();
121: this .setLayout(new BoxGridBag());
122: }
123:
124: public Insets getInsets() {
125: int l_lo = this .pem_marginLeft
126: + this .pem_paddingLeft
127: + (this .pem_bLeft != null ? this .pem_bLeft.pcm_width
128: : 0);
129: int l_ro = this .pem_marginRight
130: + this .pem_paddingRight
131: + (this .pem_bRight != null ? this .pem_bRight.pcm_width
132: : 0);
133: int l_bo = this .pem_marginBottom
134: + this .pem_paddingBottom
135: + (this .pem_bBottom != null ? this .pem_bBottom.pcm_width
136: : 0);
137: int l_to = this .pem_marginTop + this .pem_paddingTop
138: + (this .pem_bTop != null ? this .pem_bTop.pcm_width : 0);
139:
140: if (l_lo == 0 && l_ro == 0 && l_bo == 0 && l_to == 0)
141: return (super .getInsets());
142: else
143: return new Insets(l_to, l_lo, l_bo, l_ro);
144: }
145:
146: public void pcmf_setBorder(int xDir, String xCol, int xWidth,
147: int xStyle) {
148: switch (xDir) {
149: case IUnBox.LEFT:
150: this .pem_bLeft = new UnBoxBorder(xCol, xWidth, xStyle);
151: break;
152: case IUnBox.RIGHT:
153: this .pem_bRight = new UnBoxBorder(xCol, xWidth, xStyle);
154: break;
155: case IUnBox.TOP:
156: this .pem_bTop = new UnBoxBorder(xCol, xWidth, xStyle);
157: break;
158: case IUnBox.BOTTOM:
159: this .pem_bBottom = new UnBoxBorder(xCol, xWidth, xStyle);
160: break;
161: }
162: }
163:
164: public void pcmf_setPadding(int xDir, int xWidth) {
165: switch (xDir) {
166: case IUnBox.LEFT:
167: this .pem_paddingLeft = xWidth;
168: break;
169: case IUnBox.RIGHT:
170: this .pem_paddingRight = xWidth;
171: break;
172: case IUnBox.TOP:
173: this .pem_paddingTop = xWidth;
174: break;
175: case IUnBox.BOTTOM:
176: this .pem_paddingBottom = xWidth;
177: break;
178: }
179: }
180:
181: public void pcmf_setMargin(int xDir, int xWidth) {
182: switch (xDir) {
183: case IUnBox.LEFT:
184: this .pem_marginLeft = xWidth;
185: break;
186: case IUnBox.RIGHT:
187: this .pem_marginRight = xWidth;
188: break;
189: case IUnBox.TOP:
190: this .pem_marginTop = xWidth;
191: break;
192: case IUnBox.BOTTOM:
193: this .pem_marginBottom = xWidth;
194: break;
195: }
196: }
197:
198: public void pcmf_setBgImage(IUnImage xImg) {
199: this .pem_bg = (ImageIcon) ((HoSwingImage) xImg).pcmf_getIcon();
200: }
201:
202: protected void paintComponent(Graphics g) {
203: if (this .pem_bg != null) {
204: int hi = (int) this .getHeight();
205: int wi = (int) this .getWidth();
206: if (hi != 0 && wi != 0) {
207: Image l_img = this .pem_bg.getImage().getScaledInstance(
208: wi, hi, Image.SCALE_DEFAULT);
209: new ImageIcon(l_img).paintIcon(this , g, 0, 0);
210: }
211: } else
212: super .paintComponent(g);
213: }
214:
215: public void paint(Graphics g) {
216: super .paintBorder(g);
217: super .paintComponent(g);
218:
219: Graphics l_og = g;
220: g = g.create(this .pem_marginLeft, this .pem_marginTop, this
221: .getWidth()
222: - this .pem_marginRight - this .pem_marginLeft, this
223: .getHeight()
224: - this .pem_marginTop - pem_marginBottom);
225:
226: int l_x = this .getWidth() - this .pem_marginRight
227: - this .pem_marginLeft - 1;
228: int l_y = this .getHeight() - this .pem_marginBottom
229: - this .pem_marginTop - 1;
230:
231: if (this .pem_bBottom != null) {
232: int l_red1 = 0;
233: int l_red2 = 0;
234: g.setColor(HoSwingComponent
235: .pcmf_createColor(this .pem_bBottom.pcm_color));
236: for (int i = 0; i < this .pem_bBottom.pcm_width; i++) {
237: if (this .pem_bBottom.pcm_style == IUnBox.BORDER_DOUBLE) {
238: int l_th = this .pem_bBottom.pcm_width / 3;
239: if (i >= l_th && i < l_th * 2)
240: g.setColor(this .getBackground());
241: }
242:
243: g.drawLine(this .pem_bLeft != null ? l_red1++ : 0, l_y
244: - i, this .pem_bRight != null ? l_x - l_red2++
245: : l_x, l_y - i);
246: g.setColor(HoSwingComponent
247: .pcmf_createColor(this .pem_bBottom.pcm_color));
248: }
249: switch (this .pem_bBottom.pcm_style) {
250: case IUnBox.BORDER_DOTTED:
251: g.setColor(this .getBackground());
252: for (int dot = l_red1 << 1; dot < l_x - (l_red2 << 1); dot += this .pem_bBottom.pcm_width * 2)
253: g.fillRect(dot, l_y - pem_bBottom.pcm_width,
254: this .pem_bBottom.pcm_width,
255: this .pem_bBottom.pcm_width);
256: break;
257: case IUnBox.BORDER_DASHED:
258: g.setColor(this .getBackground());
259: for (int dot = l_red1 << 1; dot < l_x - (l_red2 << 1); dot += this .pem_bBottom.pcm_width * 3)
260: g.fillRect(dot, l_y - pem_bBottom.pcm_width,
261: this .pem_bBottom.pcm_width,
262: this .pem_bBottom.pcm_width);
263: }
264: }
265: if (this .pem_bTop != null) {
266: int l_red1 = 0;
267: int l_red2 = 0;
268: g.setColor(HoSwingComponent
269: .pcmf_createColor(this .pem_bTop.pcm_color));
270: for (int i = 0; i < this .pem_bTop.pcm_width; i++) {
271: if (this .pem_bTop.pcm_style == IUnBox.BORDER_DOUBLE) {
272: int l_th = this .pem_bBottom.pcm_width / 3;
273: if (i >= l_th && i < l_th * 2)
274: g.setColor(this .getBackground());
275: }
276: g.drawLine(this .pem_bLeft != null ? l_red1++ : 0, i,
277: this .pem_bRight != null ? l_x - l_red2++ : l_x,
278: i);
279: g.setColor(HoSwingComponent
280: .pcmf_createColor(this .pem_bTop.pcm_color));
281: }
282: switch (this .pem_bTop.pcm_style) {
283: case IUnBox.BORDER_DOTTED:
284: g.setColor(this .getBackground());
285: for (int dot = l_red1 << 1; dot < l_x - (l_red2 << 1); dot += this .pem_bTop.pcm_width * 2)
286: g.fillRect(dot, 0, this .pem_bTop.pcm_width,
287: this .pem_bTop.pcm_width);
288: break;
289: case IUnBox.BORDER_DASHED:
290: g.setColor(this .getBackground());
291: for (int dot = l_red1 << 1; dot < l_x - (l_red2 << 1); dot += this .pem_bTop.pcm_width * 3)
292: g.fillRect(dot, 0, this .pem_bTop.pcm_width,
293: this .pem_bTop.pcm_width);
294: }
295: }
296: if (this .pem_bLeft != null) {
297: g.setColor(HoSwingComponent
298: .pcmf_createColor(this .pem_bLeft.pcm_color));
299: int l_red1 = 0;
300: int l_red2 = 0;
301: for (int i = 0; i < this .pem_bLeft.pcm_width; i++) {
302: if (this .pem_bLeft.pcm_style == IUnBox.BORDER_DOUBLE) {
303: int l_th = this .pem_bLeft.pcm_width / 3;
304: if (i >= l_th && i < l_th * 2)
305: g.setColor(this .getBackground());
306: }
307: g
308: .drawLine(i, this .pem_bTop != null ? l_red1++
309: : 0, i, this .pem_bBottom != null ? l_y
310: - l_red2++ : l_y);
311: g.setColor(HoSwingComponent
312: .pcmf_createColor(this .pem_bLeft.pcm_color));
313: }
314: switch (this .pem_bLeft.pcm_style) {
315: case IUnBox.BORDER_DOTTED:
316: g.setColor(this .getBackground());
317: for (int dot = l_red1 << 1; dot < l_y - (l_red2 << 1); dot += this .pem_bLeft.pcm_width * 2)
318: g.fillRect(0, dot, this .pem_bLeft.pcm_width,
319: this .pem_bLeft.pcm_width);
320: break;
321: case IUnBox.BORDER_DASHED:
322: g.setColor(this .getBackground());
323: for (int dot = l_red1 << 1; dot < l_y - (l_red2 << 1); dot += this .pem_bLeft.pcm_width * 3)
324: g.fillRect(0, dot, this .pem_bLeft.pcm_width,
325: this .pem_bLeft.pcm_width);
326: }
327: }
328: if (this .pem_bRight != null) {
329: int l_red1 = 0;
330: int l_red2 = 0;
331: g.setColor(HoSwingComponent
332: .pcmf_createColor(this .pem_bRight.pcm_color));
333: for (int i = 0; i < this .pem_bRight.pcm_width; i++) {
334: if (this .pem_bRight.pcm_style == IUnBox.BORDER_DOUBLE) {
335: int l_th = this .pem_bRight.pcm_width / 3;
336: if (i >= l_th && i < l_th * 2)
337: g.setColor(this .getBackground());
338: }
339: g.drawLine(l_x - i, this .pem_bTop != null ? l_red1++
340: : 0, l_x - i, this .pem_bBottom != null ? l_y
341: - l_red2++ : l_y);
342: g.setColor(HoSwingComponent
343: .pcmf_createColor(this .pem_bRight.pcm_color));
344: }
345: switch (this .pem_bRight.pcm_style) {
346: case IUnBox.BORDER_DOTTED:
347: g.setColor(this .getBackground());
348: for (int dot = l_red1 << 1; dot < l_y - (l_red2 << 1); dot += this .pem_bRight.pcm_width * 2)
349: g.fillRect(l_x - l_red2 + 1, dot,
350: this .pem_bRight.pcm_width,
351: this .pem_bRight.pcm_width);
352: break;
353: case IUnBox.BORDER_DASHED:
354: g.setColor(this .getBackground());
355: for (int dot = l_red1 << 1; dot < l_y - (l_red2 << 1); dot += this .pem_bRight.pcm_width * 3)
356: g.fillRect(l_x - l_red2 + 1, dot,
357: this .pem_bRight.pcm_width,
358: this .pem_bRight.pcm_width);
359: }
360: }
361:
362: super .paintChildren(l_og);
363: }
364: }
365:
366: public class Testdriver extends KeRegisteredObject {
367: // @@
368: }
|