001: package org.pentaho.designstudio.widgets.flowtable;
002:
003: import org.eclipse.swt.SWT;
004: import org.eclipse.swt.graphics.Color;
005: import org.eclipse.swt.graphics.GC;
006: import org.eclipse.swt.graphics.Point;
007: import org.eclipse.swt.graphics.RGB;
008: import org.eclipse.swt.graphics.Rectangle;
009: import org.eclipse.swt.widgets.Display;
010: import org.pentaho.actionsequence.dom.ActionIfStatement;
011: import org.pentaho.actionsequence.dom.ActionLoop;
012: import org.pentaho.actionsequence.dom.ActionOutput;
013: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
014: import org.pentaho.actionsequence.dom.ActionSequenceInput;
015: import org.pentaho.actionsequence.dom.ActionSequenceOutput;
016: import org.pentaho.actionsequence.dom.ActionSequenceResource;
017: import org.pentaho.actionsequence.dom.actions.ActionDefinition;
018: import org.pentaho.designstudio.editors.actionsequence.pages.ActionSequenceLabelProvider;
019:
020: import de.kupzog.ktable.KTableModel;
021: import de.kupzog.ktable.renderers.DefaultCellRenderer;
022:
023: public class ActionsFlowCellRenderer extends DefaultCellRenderer {
024:
025: public static final int SHADOW_WIDTH = 2;
026:
027: public static final int ARROW_LINE_WIDTH = 3;
028: public static final int ARROW_HEIGHT = 7;
029: public static final int ARROW_WIDTH = 4;
030: static final Color ARROW_COLOR = Display.getDefault()
031: .getSystemColor(SWT.COLOR_BLACK);
032:
033: static final Color BORDER_COLOR = Display.getDefault()
034: .getSystemColor(SWT.COLOR_DARK_GRAY);
035: static final Color SHADOW_COLOR = Display.getDefault()
036: .getSystemColor(SWT.COLOR_DARK_GRAY);
037: public static final RGB BOX_COLOR_RGB = new RGB(245, 245, 255);
038: static final Color BOX_FILL_COLOR = new Color(Display.getDefault(),
039: BOX_COLOR_RGB);
040: static final Color SELECTED_COLOR = Display.getDefault()
041: .getSystemColor(SWT.COLOR_GRAY);
042:
043: ActionSequenceDocument actionSequence;
044:
045: public ActionsFlowCellRenderer() {
046: super (INDICATION_FOCUS);
047: }
048:
049: public void setActionSequenceDocument(
050: ActionSequenceDocument actionSequence) {
051: this .actionSequence = actionSequence;
052: }
053:
054: public int getOptimalWidth(GC gc, int col, int row, Object content,
055: boolean fixed, KTableModel model) {
056: return ActionsFlowModel.DEFAULT_COLUMN_WIDTH;
057: }
058:
059: private void drawActionConnector(GC gc, Rectangle rect) {
060: gc.setLineWidth(ARROW_LINE_WIDTH);
061:
062: int arrowStartX = rect.x + rect.width / 2;
063: int arrowStartY = rect.y;
064: int arrowEndY = rect.y + rect.height;
065:
066: gc.setForeground(ARROW_COLOR);
067: gc.setBackground(ARROW_COLOR);
068:
069: gc.drawLine(arrowStartX, arrowStartY, arrowStartX, arrowEndY
070: - ARROW_HEIGHT);
071: gc
072: .fillPolygon(new int[] { arrowStartX - ARROW_WIDTH,
073: arrowEndY - ARROW_HEIGHT, arrowStartX,
074: arrowEndY, arrowStartX + ARROW_WIDTH + 1,
075: arrowEndY - ARROW_HEIGHT });
076: }
077:
078: private void drawLoopbackConnector(GC gc, Rectangle rect, int col,
079: int row, KTableModel model) {
080: gc.setLineWidth(ARROW_LINE_WIDTH);
081: gc.setBackground(getBackground());
082:
083: gc.setForeground(ARROW_COLOR);
084: gc.setBackground(ARROW_COLOR);
085:
086: Object adjacentData = model.getContentAt(col + 1, row);
087: if (adjacentData instanceof ActionIfStatement) {
088: Point startPoint = new Point(rect.x + rect.width / 2 - 1,
089: rect.y + rect.height / 2);
090: Point endPoint = new Point(rect.x + rect.width,
091: startPoint.y);
092: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
093: endPoint.y);
094:
095: startPoint = new Point(rect.x + rect.width / 2, rect.y
096: + rect.height / 2);
097: endPoint = new Point(startPoint.x, rect.y + rect.height + 1);
098: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
099: endPoint.y);
100: } else if (adjacentData == ActionsFlowModel.LOOP_END_PLACEHOLDER) {
101: Point startPoint = new Point(rect.x + rect.width / 2 - 1,
102: rect.y + rect.height / 2);
103: Point endPoint = new Point(rect.x + rect.width,
104: startPoint.y);
105: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
106: endPoint.y);
107:
108: startPoint = new Point(rect.x + rect.width / 2, rect.y
109: + rect.height / 2);
110: endPoint = new Point(startPoint.x, rect.y);
111: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
112: endPoint.y);
113: } else if (adjacentData instanceof ActionLoop) {
114: Point startPoint = new Point(rect.x + rect.width / 2,
115: rect.y + rect.height / 2);
116: Point endPoint = new Point(rect.x + rect.width
117: - ARROW_HEIGHT, startPoint.y);
118: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
119: endPoint.y);
120:
121: startPoint.x = rect.x + rect.width / 2;
122: startPoint.y = rect.y + rect.height / 2 - 1;
123: endPoint.x = startPoint.x;
124: endPoint.y = rect.y + rect.height + 1;
125: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
126: endPoint.y);
127:
128: Point point1 = new Point(rect.x + rect.width, rect.y
129: + rect.height / 2);
130: Point point2 = new Point(point1.x - ARROW_HEIGHT, point1.y
131: - ARROW_WIDTH);
132: Point point3 = new Point(point2.x, point1.y + ARROW_WIDTH);
133: gc.fillPolygon(new int[] { point1.x, point1.y, point2.x,
134: point2.y, point3.x, point3.y });
135: } else if (adjacentData == ActionsFlowModel.IF_END_PLACEHOLDER) {
136: Point startPoint = new Point(rect.x + rect.width / 2,
137: rect.y + rect.height / 2);
138: Point endPoint = new Point(rect.x + rect.width
139: - ARROW_HEIGHT, startPoint.y);
140: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
141: endPoint.y);
142:
143: startPoint.x = rect.x + rect.width / 2;
144: startPoint.y = rect.y + rect.height / 2 + 1;
145: endPoint.x = startPoint.x;
146: endPoint.y = rect.y;
147: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
148: endPoint.y);
149:
150: Point point1 = new Point(rect.x + rect.width, rect.y
151: + rect.height / 2);
152: Point point2 = new Point(point1.x - ARROW_HEIGHT, point1.y
153: - ARROW_WIDTH);
154: Point point3 = new Point(point2.x, point1.y + ARROW_WIDTH);
155: gc.fillPolygon(new int[] { point1.x, point1.y, point2.x,
156: point2.y, point3.x, point3.y });
157: } else {
158: Point startPoint = new Point(rect.x + rect.width / 2,
159: rect.y);
160: Point endPoint = new Point(startPoint.x, rect.y
161: + rect.height + 1);
162: gc.drawLine(startPoint.x, startPoint.y, endPoint.x,
163: endPoint.y);
164: }
165: }
166:
167: private void drawTop(GC gc, Rectangle rect, String text,
168: int indent, boolean focus) {
169: int origLineWidth = gc.getLineWidth();
170: Color origForeground = gc.getForeground();
171: Color origBackground = gc.getBackground();
172: gc.setForeground(BORDER_COLOR);
173: gc.setBackground(BORDER_COLOR);
174: gc.setLineWidth(1);
175:
176: //Top Line
177: gc.drawLine(rect.x, rect.y, rect.x + rect.width - SHADOW_WIDTH,
178: rect.y);
179:
180: //Left Line
181: gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
182:
183: //Right Line
184: gc.drawLine(rect.x + rect.width - SHADOW_WIDTH + 1, rect.y,
185: rect.x + rect.width - SHADOW_WIDTH + 1, rect.y
186: + rect.height);
187:
188: //Right Shadow
189: gc.fillRectangle(rect.x + rect.width - SHADOW_WIDTH + 1, rect.y
190: + SHADOW_WIDTH, SHADOW_WIDTH, rect.height
191: - SHADOW_WIDTH + 1);
192:
193: if (focus && (m_Style & INDICATION_FOCUS) != 0) {
194: gc.setForeground(BOX_FILL_COLOR);
195: gc.setBackground(SELECTED_COLOR);
196: gc.fillGradientRectangle(rect.x + 1, rect.y + 1, rect.width
197: - SHADOW_WIDTH, rect.height, false);
198:
199: } else {
200: gc.setBackground(BOX_FILL_COLOR);
201: gc.fillRectangle(rect.x + 1, rect.y + 1, rect.width
202: - SHADOW_WIDTH, rect.height);
203: }
204:
205: gc.setForeground(origForeground);
206: gc.setBackground(origBackground);
207: gc.setLineWidth(origLineWidth);
208:
209: gc.setClipping(rect.x, rect.y, rect.width - 2, rect.height);
210: gc.drawText(text, rect.x + indent, rect.y + 2, true);
211: }
212:
213: private void drawMiddle(GC gc, Rectangle rect, String text,
214: int indent, boolean focus) {
215: int origLineWidth = gc.getLineWidth();
216: Color origForeground = gc.getForeground();
217: Color origBackground = gc.getBackground();
218: gc.setForeground(BORDER_COLOR);
219: gc.setBackground(BORDER_COLOR);
220: gc.setLineWidth(1);
221:
222: //Left Line
223: gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
224:
225: //Right Shadow
226: gc.fillRectangle(rect.x + rect.width - SHADOW_WIDTH + 1,
227: rect.y, SHADOW_WIDTH, rect.height + 1);
228:
229: if (focus && (m_Style & INDICATION_FOCUS) != 0) {
230: gc.setForeground(BOX_FILL_COLOR);
231: gc.setBackground(SELECTED_COLOR);
232: gc.fillGradientRectangle(rect.x + 1, rect.y, rect.width
233: - SHADOW_WIDTH, rect.height + 1, false);
234:
235: } else {
236: gc.setBackground(BOX_FILL_COLOR);
237: gc.fillRectangle(rect.x + 1, rect.y, rect.width
238: - SHADOW_WIDTH, rect.height + 1);
239: }
240:
241: gc.setForeground(origForeground);
242: gc.setBackground(origBackground);
243: gc.setLineWidth(origLineWidth);
244:
245: gc.setClipping(rect.x, rect.y, rect.width - 2, rect.height);
246: gc.drawText(text, rect.x + indent, rect.y + 2, true);
247: }
248:
249: private void drawBottom(GC gc, Rectangle rect, String text,
250: int indent, boolean focus) {
251: int origLineWidth = gc.getLineWidth();
252: Color origForeground = gc.getForeground();
253: Color origBackground = gc.getBackground();
254: gc.setForeground(BORDER_COLOR);
255: gc.setBackground(BORDER_COLOR);
256: gc.setLineWidth(1);
257:
258: //Left Line
259: gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height
260: - SHADOW_WIDTH + 1);
261:
262: //Bottom Line
263: gc.drawLine(rect.x, rect.y + rect.height - SHADOW_WIDTH + 1,
264: rect.x + rect.width - SHADOW_WIDTH, rect.y
265: + rect.height - SHADOW_WIDTH + 1);
266:
267: //Bottom Shadow
268: gc.fillRectangle(rect.x + SHADOW_WIDTH, rect.y + rect.height
269: - SHADOW_WIDTH + 1, rect.width + 1 - SHADOW_WIDTH,
270: SHADOW_WIDTH);
271:
272: //Right Shadow
273: gc.fillRectangle(rect.x + rect.width - SHADOW_WIDTH + 1,
274: rect.y, SHADOW_WIDTH, rect.height + 1);
275:
276: if (focus && (m_Style & INDICATION_FOCUS) != 0) {
277: gc.setForeground(BOX_FILL_COLOR);
278: gc.setBackground(SELECTED_COLOR);
279: gc.fillGradientRectangle(rect.x + 1, rect.y, rect.width
280: - SHADOW_WIDTH, rect.height - SHADOW_WIDTH + 1,
281: false);
282:
283: } else {
284: gc.setBackground(BOX_FILL_COLOR);
285: gc.fillRectangle(rect.x + 1, rect.y, rect.width
286: - SHADOW_WIDTH, rect.height - SHADOW_WIDTH + 1);
287: }
288:
289: gc.setForeground(origForeground);
290: gc.setBackground(origBackground);
291: gc.setLineWidth(origLineWidth);
292:
293: gc.setClipping(rect.x, rect.y, rect.width - 2, rect.height);
294: gc.drawText(text, rect.x + indent, rect.y + 2, true);
295: }
296:
297: private void drawRect(GC gc, Rectangle rect, String text,
298: int indent, boolean focus) {
299: int origLineWidth = gc.getLineWidth();
300: Color origForeground = gc.getForeground();
301: Color origBackground = gc.getBackground();
302: gc.setForeground(BORDER_COLOR);
303: gc.setBackground(BORDER_COLOR);
304: gc.setLineWidth(1);
305:
306: //Top Line
307: gc.drawLine(rect.x, rect.y, rect.x + rect.width - SHADOW_WIDTH,
308: rect.y);
309:
310: //Left Line
311: gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height
312: - SHADOW_WIDTH + 1);
313:
314: //Bottom Line
315: gc.drawLine(rect.x, rect.y + rect.height - SHADOW_WIDTH + 1,
316: rect.x + rect.width - SHADOW_WIDTH, rect.y
317: + rect.height - SHADOW_WIDTH + 1);
318:
319: //Bottom Shadow
320: gc.fillRectangle(rect.x + SHADOW_WIDTH, rect.y + rect.height
321: - SHADOW_WIDTH + 1, rect.width + 1 - SHADOW_WIDTH,
322: SHADOW_WIDTH);
323:
324: //Right Line
325: gc.drawLine(rect.x + rect.width - SHADOW_WIDTH + 1, rect.y,
326: rect.x + rect.width - SHADOW_WIDTH + 1, rect.y
327: + rect.height);
328:
329: //Right Shadow
330: gc.fillRectangle(rect.x + rect.width - SHADOW_WIDTH + 1, rect.y
331: + SHADOW_WIDTH, SHADOW_WIDTH, rect.height
332: - SHADOW_WIDTH + 1);
333:
334: if (focus && (m_Style & INDICATION_FOCUS) != 0) {
335: gc.setForeground(BOX_FILL_COLOR);
336: gc.setBackground(SELECTED_COLOR);
337: gc.fillGradientRectangle(rect.x + 1, rect.y + 1, rect.width
338: - SHADOW_WIDTH, rect.height - SHADOW_WIDTH, false);
339:
340: } else {
341: gc.setBackground(BOX_FILL_COLOR);
342: gc.fillRectangle(rect.x + 1, rect.y + 1, rect.width
343: - SHADOW_WIDTH, rect.height - SHADOW_WIDTH);
344: }
345:
346: gc.setForeground(origForeground);
347: gc.setBackground(origBackground);
348: gc.setLineWidth(origLineWidth);
349:
350: gc.setClipping(rect.x, rect.y, rect.width - 2, rect.height);
351: gc.drawText(text, rect.x + indent, rect.y + 2, true);
352: }
353:
354: private void drawLoopBlock(String text, GC gc, Rectangle rect,
355: Color borderColor, Color fillColor1, Color fillColor2) {
356: Color origBackground = gc.getBackground();
357: Color origForeground = gc.getForeground();
358:
359: gc.setLineWidth(1);
360: if ((fillColor1 != null) && (fillColor2 != null)) {
361: gc.setBackground(fillColor1);
362: gc.fillRoundRectangle(rect.x, rect.y, rect.width,
363: rect.height, 20, 20);
364:
365: gc.setBackground(fillColor2);
366: gc.fillRoundRectangle(rect.x + 20, rect.y, rect.width - 20,
367: rect.height, 20, 20);
368:
369: gc.setForeground(fillColor1);
370: gc.setBackground(fillColor2);
371: gc.fillGradientRectangle(rect.x + 20, rect.y,
372: rect.width - 40, rect.height, false);
373: } else {
374: gc.setBackground(fillColor1);
375: gc.fillRoundRectangle(rect.x, rect.y, rect.width,
376: rect.height + 1, 20, 20);
377: }
378:
379: gc.setForeground(borderColor);
380:
381: gc.drawRoundRectangle(rect.x, rect.y, rect.width, rect.height,
382: 20, 20);
383:
384: Rectangle textBox = new Rectangle(rect.x + rect.height / 2,
385: rect.y + 2, rect.width - 20, rect.height - 2);
386:
387: Rectangle oldClip = gc.getClipping();
388: gc.setForeground(getForeground());
389: gc.setClipping(textBox);
390: gc.drawText(text, textBox.x, textBox.y, true);
391: gc.setClipping(oldClip);
392: gc.setBackground(origBackground);
393: gc.setForeground(origForeground);
394: }
395:
396: public void drawCell(GC gc, Rectangle rect, int col, int row,
397: Object content, boolean focus, boolean header,
398: boolean clicked, KTableModel model) {
399:
400: Color origBackground = gc.getBackground();
401: Color origForeground = gc.getForeground();
402:
403: applyFont(gc);
404: int indent = 3;
405: gc.setForeground(getBackground());
406: gc.drawRectangle(rect);
407: gc.fillRectangle(rect);
408: gc.setForeground(origForeground);
409:
410: if (content == ActionsFlowModel.ACTION_CONNECTOR) {
411: drawActionConnector(gc, rect);
412: } else if (content == ActionsFlowModel.LOOPBACK_CONNECTOR) {
413: drawLoopbackConnector(gc, rect, col, row, model);
414: } else if (content instanceof ActionDefinition) {
415: ActionDefinition actionDefinition = (ActionDefinition) content;
416: if (actionDefinition.getAllOutputParams().length == 0) {
417: drawRect(gc, rect, ActionSequenceLabelProvider
418: .getText((ActionDefinition) content), indent,
419: focus);
420: } else {
421: drawTop(gc, rect, ActionSequenceLabelProvider
422: .getText((ActionDefinition) content), indent,
423: focus);
424: }
425: } else if (content instanceof ActionSequenceInput) {
426: ActionSequenceInput actionSequenceInput = (ActionSequenceInput) content;
427: ActionSequenceInput[] actionSequenceInputs = actionSequenceInput
428: .getDocument().getInputs();
429: if (actionSequenceInputs[actionSequenceInputs.length - 1]
430: .equals(actionSequenceInput)) {
431: drawBottom(gc, rect, ActionSequenceLabelProvider
432: .getText((ActionSequenceInput) content),
433: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
434: } else {
435: drawMiddle(gc, rect, ActionSequenceLabelProvider
436: .getText((ActionSequenceInput) content),
437: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
438: }
439: } else if (content instanceof ActionOutput) {
440: ActionOutput actionOutput = (ActionOutput) content;
441: ActionOutput[] actionOutputs = actionOutput
442: .getActionDefinition().getAllOutputParams();
443: if (actionOutputs[actionOutputs.length - 1]
444: .equals(actionOutput)) {
445: drawBottom(gc, rect, ActionSequenceLabelProvider
446: .getText((ActionOutput) content),
447: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
448: } else {
449: drawMiddle(gc, rect, ActionSequenceLabelProvider
450: .getText((ActionOutput) content),
451: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
452: }
453: } else if (content instanceof ActionSequenceOutput) {
454: ActionSequenceOutput actionSequenceOutput = (ActionSequenceOutput) content;
455: ActionSequenceOutput[] actionSequenceOutputs = actionSequenceOutput
456: .getDocument().getOutputs();
457: if (actionSequenceOutputs[actionSequenceOutputs.length - 1]
458: .equals(actionSequenceOutput)) {
459: drawBottom(gc, rect, ActionSequenceLabelProvider
460: .getText((ActionSequenceOutput) content),
461: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
462: } else {
463: drawMiddle(gc, rect, ActionSequenceLabelProvider
464: .getText((ActionSequenceOutput) content),
465: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
466: }
467: } else if (content instanceof ActionLoop) {
468: drawLoop(ActionSequenceLabelProvider
469: .getText((ActionLoop) content), gc, rect, focus);
470: } else if (content instanceof ActionIfStatement) {
471: drawIf(ActionSequenceLabelProvider
472: .getText((ActionIfStatement) content), gc, rect,
473: focus);
474: } else if (content instanceof ActionSequenceResource) {
475: ActionSequenceResource actionSequenceResource = (ActionSequenceResource) content;
476: ActionSequenceResource[] actionSequenceResources = actionSequenceResource
477: .getDocument().getResources();
478: if (actionSequenceResources[actionSequenceResources.length - 1]
479: .equals(actionSequenceResource)) {
480: drawBottom(gc, rect, ActionSequenceLabelProvider
481: .getText((ActionSequenceResource) content),
482: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
483: } else {
484: drawMiddle(gc, rect, ActionSequenceLabelProvider
485: .getText((ActionSequenceResource) content),
486: ActionsFlowModel.DEFAULT_COLUMN_WIDTH, focus);
487: }
488: } else if (content == ActionsFlowModel.ACTION_SEQUENCE_INPUTS_HEADER) {
489: if (actionSequence.getInputs().length == 0) {
490: drawRect(gc, rect, content.toString(), indent, focus);
491: } else {
492: drawTop(gc, rect, content.toString(), indent, focus);
493: }
494: } else if (content == ActionsFlowModel.ACTION_SEQUENCE_OUTPUTS_HEADER) {
495: if (actionSequence.getOutputs().length == 0) {
496: drawRect(gc, rect, content.toString(), indent, focus);
497: } else {
498: drawTop(gc, rect, content.toString(), indent, focus);
499: }
500: } else if (content == ActionsFlowModel.ACTION_SEQUENCE_RESOURCES_HEADER) {
501: if (actionSequence.getResources().length == 0) {
502: drawRect(gc, rect, content.toString(), indent, focus);
503: } else {
504: drawTop(gc, rect, content.toString(), indent, focus);
505: }
506: } else if (content == ActionsFlowModel.LOOP_END_PLACEHOLDER) {
507: drawLoop(content.toString(), gc, rect, focus);
508: } else if (content == ActionsFlowModel.IF_END_PLACEHOLDER) {
509: drawIf(content.toString(), gc, rect, focus);
510: }
511:
512: gc.setBackground(origBackground);
513: gc.setForeground(origForeground);
514:
515: resetFont(gc);
516: }
517:
518: private void drawIfBlock(String text, GC gc, Rectangle rect,
519: Color borderColor, Color fillColor1, Color fillColor2) {
520: Color origBackground = gc.getBackground();
521: Color origForeground = gc.getForeground();
522: int offset = 3;
523:
524: gc.setLineWidth(1);
525: if ((fillColor1 != null) && (fillColor2 != null)) {
526: gc.setBackground(fillColor1);
527: gc.fillPolygon(new int[] { rect.x,
528: rect.y + rect.height / 2,
529: rect.x + rect.height / 2 - offset + 1, rect.y,
530: rect.x + rect.height / 2 - offset + 1,
531: rect.y + rect.height });
532:
533: gc.setBackground(fillColor2);
534: gc.fillPolygon(new int[] {
535: rect.x + rect.width - rect.height / 2 + offset - 1,
536: rect.y, rect.x + rect.width,
537: rect.y + rect.height / 2,
538: rect.x + rect.width - rect.height / 2 + offset - 1,
539: rect.y + rect.height });
540:
541: gc.setForeground(fillColor1);
542: gc.setBackground(fillColor2);
543: gc.fillGradientRectangle(rect.x + rect.height / 2 - offset
544: + 1, rect.y, rect.width - rect.height + offset + 2,
545: rect.height, false);
546: gc.setForeground(getForeground());
547: gc.setBackground(getBackground());
548: } else {
549: gc.setBackground(fillColor1);
550: gc.fillPolygon(new int[] { rect.x,
551: rect.y + rect.height / 2,
552: rect.x + rect.height / 2 - offset, rect.y,
553: rect.x + rect.width - rect.height / 2 + offset,
554: rect.y, rect.x + rect.width,
555: rect.y + rect.height / 2,
556: rect.x + rect.width - rect.height / 2 + offset,
557: rect.y + rect.height,
558: rect.x + rect.height / 2 - offset,
559: rect.y + rect.height });
560: gc.setBackground(getBackground());
561: }
562:
563: gc.setForeground(borderColor);
564:
565: gc
566: .drawPolygon(new int[] { rect.x,
567: rect.y + rect.height / 2,
568: rect.x + rect.height / 2 - offset, rect.y,
569: rect.x + rect.width - rect.height / 2 + offset,
570: rect.y, rect.x + rect.width,
571: rect.y + rect.height / 2,
572: rect.x + rect.width - rect.height / 2 + offset,
573: rect.y + rect.height,
574: rect.x + rect.height / 2 - offset,
575: rect.y + rect.height });
576:
577: Rectangle textBox = new Rectangle(rect.x + rect.height / 2,
578: rect.y + 2, rect.width - rect.height, rect.height - 2);
579:
580: Rectangle oldClip = gc.getClipping();
581: gc.setForeground(getForeground());
582: gc.setClipping(textBox);
583: gc.drawText(text, textBox.x, textBox.y, true);
584: gc.setClipping(oldClip);
585: gc.setBackground(origBackground);
586: gc.setForeground(origForeground);
587: }
588:
589: private void drawLoop(String text, GC gc, Rectangle rect,
590: boolean focus) {
591: Rectangle tempRect = new Rectangle(rect.x + SHADOW_WIDTH,
592: rect.y + SHADOW_WIDTH, rect.width - SHADOW_WIDTH,
593: rect.height - SHADOW_WIDTH);
594: drawLoopBlock(
595: "", gc, tempRect, BORDER_COLOR, SHADOW_COLOR, null); //$NON-NLS-1$
596: tempRect = new Rectangle(rect.x, rect.y, rect.width
597: - SHADOW_WIDTH + 1, rect.height - SHADOW_WIDTH + 1);
598: if (focus) {
599: drawLoopBlock(text, gc, tempRect, BORDER_COLOR,
600: BOX_FILL_COLOR, SELECTED_COLOR);
601: } else {
602: drawLoopBlock(text, gc, tempRect, BORDER_COLOR,
603: BOX_FILL_COLOR, null);
604: }
605: }
606:
607: private void drawIf(String text, GC gc, Rectangle rect,
608: boolean focus) {
609: Rectangle tempRect = new Rectangle(rect.x + SHADOW_WIDTH,
610: rect.y + SHADOW_WIDTH, rect.width - SHADOW_WIDTH,
611: rect.height - SHADOW_WIDTH);
612: drawIfBlock("", gc, tempRect, BORDER_COLOR, SHADOW_COLOR, null); //$NON-NLS-1$
613: tempRect = new Rectangle(rect.x, rect.y, rect.width
614: - SHADOW_WIDTH + 1, rect.height - SHADOW_WIDTH + 1);
615: if (focus) {
616: drawIfBlock(text, gc, tempRect, BORDER_COLOR,
617: BOX_FILL_COLOR, SELECTED_COLOR);
618: } else {
619: drawIfBlock(text, gc, tempRect, BORDER_COLOR,
620: BOX_FILL_COLOR, null);
621: }
622: }
623: }
|