Home » Eclipse Projects » Remote Application Platform (RAP) » Form & Section Title Backgrounds
Form & Section Title Backgrounds [message #114839] |
Mon, 08 December 2008 21:56  |
Eclipse User |
|
|
|
Originally posted by: paul.kendall.orionhealth.com
--nextPart1494406.mUpDUsVv1N
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7Bit
I have been working on support for getting the form and section title
backgrounds working. I have used AWT classes to generate the image
for the background and set it in the container. It all works quite well for
me. I am attaching the patch if others would like to try it.
Perhaps it could make it into some release of RAP?
Cheers,
Paul Kendall
--nextPart1494406.mUpDUsVv1N
Content-Type: text/plain; name="forms-gradient-patch.txt"
Content-Transfer-Encoding: 8Bit
Content-Disposition: attachment; filename="forms-gradient-patch.txt"
### Eclipse Workspace Patch 1.0
#P org.eclipse.rap.ui.forms
Index: src/org/eclipse/ui/internal/forms/widgets/FormHeading.java
============================================================ =======
RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.ui.fo rms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.ja va,v
retrieving revision 1.2
diff -u -r1.2 FormHeading.java
--- src/org/eclipse/ui/internal/forms/widgets/FormHeading.java 16 Sep 2008 16:26:21 -0000 1.2
+++ src/org/eclipse/ui/internal/forms/widgets/FormHeading.java 9 Dec 2008 00:17:55 -0000
@@ -10,47 +10,28 @@
************************************************************ *******************/
package org.eclipse.ui.internal.forms.widgets;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
import java.util.Hashtable;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.rwt.graphics.Graphics;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
-//import org.eclipse.swt.dnd.DragSourceListener;
-//import org.eclipse.swt.dnd.DropTargetListener;
-//import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
-//import org.eclipse.swt.events.MouseEvent;
-//import org.eclipse.swt.events.MouseMoveListener;
-//import org.eclipse.swt.events.MouseTrackListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-//import org.eclipse.swt.graphics.FontMetrics;
-//import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Layout;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.ToolBar;
-//import org.eclipse.ui.forms.IFormColors;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.graphics.ResourceFactory;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.IMessage;
import org.eclipse.ui.forms.events.IHyperlinkListener;
-import org.eclipse.ui.forms.widgets.Hyperlink;
-import org.eclipse.ui.forms.widgets.ILayoutExtension;
-import org.eclipse.ui.forms.widgets.SizeCache;
+import org.eclipse.ui.forms.widgets.*;
import org.eclipse.ui.internal.forms.IMessageToolTipManager;
import org.eclipse.ui.internal.forms.MessageManager;
@@ -864,25 +845,48 @@
// titleRegion.setHoverState(TitleRegion.STATE_NORMAL);
// }
-// RAP [rh] updateGradientImage: empty implementation
private void updateGradientImage() {
-// Rectangle rect = getBounds();
-// if (gradientImage != null) {
-// FormImages.getInstance().markFinished(gradientImage);
-// gradientImage = null;
-// }
-// if (gradientInfo != null) {
-// gradientImage = FormImages.getInstance().getGradient(getDisplay(), gradientInfo.gradientColors, gradientInfo.percents,
-// gradientInfo.vertical ? rect.height : rect.width, gradientInfo.vertical, getColor(COLOR_BASE_BG));
-// } else if (backgroundImage != null && !isBackgroundImageTiled()) {
-// gradientImage = new Image(getDisplay(), Math.max(rect.width, 1),
-// Math.max(rect.height, 1));
-// gradientImage.setBackground(getBackground());
-// GC gc = new GC(gradientImage);
-// gc.drawImage(backgroundImage, 0, 0);
-// gc.dispose();
-// }
-// setBackgroundImage(gradientImage);
+ Rectangle rect = getBounds();
+ if (gradientImage != null) {
+ FormImages.getInstance().markFinished(gradientImage);
+ gradientImage = null;
+ }
+ if (gradientInfo != null) {
+ gradientImage = FormImages.getInstance().getGradient(getDisplay(), gradientInfo.gradientColors, gradientInfo.percents,
+ gradientInfo.vertical ? rect.height : rect.width, gradientInfo.vertical, getColor(COLOR_BASE_BG));
+ } else if (backgroundImage != null && !isBackgroundImageTiled()) {
+ gradientImage = FormImages.getInstance().getBackgroundImage(rect, getBackground(), backgroundImage);
+ }
+
+ if (isSeparatorVisible()) {
+ Rectangle carea = getClientArea();
+ int width = gradientImage.getBounds().width;
+ int height = carea.height;
+ BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2 = bufferedImage.createGraphics();
+ g2.clearRect(0, 0, width, height);
+ g2.drawImage(AWTHelper.convertToAWT(ResourceFactory.getImage Data(gradientImage)), 0,
+ 0, gradientImage.getBounds().width, gradientImage.getBounds().height,
+ AWTHelper.toAWTColor(getBackground()), null);
+
+ // bg separator
+ if (hasColor(IFormColors.H_BOTTOM_KEYLINE1))
+ g2.setColor(AWTHelper.toAWTColor(getColor(IFormColors.H_BOTT OM_KEYLINE1)));
+ else
+ g2.setColor(AWTHelper.toAWTColor(getBackground()));
+ g2.drawLine(carea.x, carea.height - 2, carea.x + carea.width - 1,
+ carea.height - 2);
+ if (hasColor(IFormColors.H_BOTTOM_KEYLINE2))
+ g2.setColor(AWTHelper.toAWTColor(getColor(IFormColors.H_BOTT OM_KEYLINE2)));
+ else
+ g2.setColor(AWTHelper.toAWTColor(getForeground()));
+ g2.drawLine(carea.x, carea.height - 1, carea.x + carea.width - 1,
+ carea.height - 1);
+
+ gradientImage = ResourceFactory.findImage(AWTHelper.convertToSWT(bufferedIma ge));
+ }
+
+ setBackgroundImage(gradientImage);
}
public boolean isSeparatorVisible() {
Index: src/org/eclipse/ui/internal/forms/widgets/FormImages.java
============================================================ =======
RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.ui.fo rms/src/org/eclipse/ui/internal/forms/widgets/FormImages.jav a,v
retrieving revision 1.1
diff -u -r1.1 FormImages.java
--- src/org/eclipse/ui/internal/forms/widgets/FormImages.java 16 Apr 2008 09:44:27 -0000 1.1
+++ src/org/eclipse/ui/internal/forms/widgets/FormImages.java 9 Dec 2008 00:17:55 -0000
@@ -10,12 +10,10 @@
************************************************************ *******************/
package org.eclipse.ui.internal.forms.widgets;
-//import java.util.Arrays;
+import java.util.Arrays;
import java.util.HashMap;
-import org.eclipse.swt.graphics.Color;
-//import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Display;
public class FormImages {
@@ -29,26 +27,27 @@
private HashMap images;
private HashMap ids;
-
+
private FormImages() {
}
-
+
private abstract class ImageIdentifier {
Display fDisplay;
Color[] fColors;
int fLength;
-
+
ImageIdentifier(Display display, Color[] colors, int length) {
fDisplay = display;
fColors = colors;
fLength = length;
}
-
+
public boolean equals(Object obj) {
if (obj instanceof ImageIdentifier) {
- ImageIdentifier id = (ImageIdentifier)obj;
+ ImageIdentifier id = (ImageIdentifier) obj;
if (id.fColors.length == fColors.length) {
- boolean result = id.fDisplay.equals(fDisplay) && id.fLength == fLength;
+ boolean result = id.fDisplay.equals(fDisplay)
+ && id.fLength == fLength;
for (int i = 0; i < fColors.length && result; i++) {
result = result && id.fColors[i].equals(fColors[i]);
}
@@ -57,7 +56,7 @@
}
return false;
}
-
+
public int hashCode() {
int hash = fDisplay.hashCode();
for (int i = 0; i < fColors.length; i++)
@@ -66,83 +65,84 @@
return hash;
}
}
-
-// RAP [rh] Unused code: was used by getGradient
-// private class SimpleImageIdentifier extends ImageIdentifier{
-// private int fTheight;
-// private int fMarginHeight;
-//
-// SimpleImageIdentifier (Display display, Color color1, Color color2,
-// int realtheight, int theight, int marginHeight) {
-// super(display, new Color[] {color1, color2}, realtheight);
-// fTheight = theight;
-// fMarginHeight = marginHeight;
-// }
-//
-// public boolean equals(Object obj) {
-// if (obj instanceof SimpleImageIdentifier) {
-// SimpleImageIdentifier id = (SimpleImageIdentifier) obj;
-// if (super.equals(obj) &&
-// id.fTheight == fTheight && id.fMarginHeight == fMarginHeight)
-// return true;
-// }
-// return false;
-// }
-//
-// public int hashCode() {
-// int hash = super.hashCode();
-// hash = hash * 7 + new Integer(fTheight).hashCode();
-// hash = hash * 7 + new Integer(fMarginHeight).hashCode();
-// return hash;
-// }
-// }
-//
-// private class ComplexImageIdentifier extends ImageIdentifier {
-// Color fBg;
-// boolean fVertical;
-// int[] fPercents;
-//
-// public ComplexImageIdentifier(Display display, Color[] colors, int length,
-// int[] percents, boolean vertical, Color bg) {
-// super(display, colors, length);
-// fBg = bg;
-// fVertical = vertical;
-// fPercents = percents;
-// }
-//
-// public boolean equals(Object obj) {
-// if (obj instanceof ComplexImageIdentifier) {
-// ComplexImageIdentifier id = (ComplexImageIdentifier) obj;
-// if (super.equals(obj) &&
-// id.fVertical == fVertical && Arrays.equals(id.fPercents, fPercents)) {
-// if ((id.fBg == null && fBg == null) ||
-// (id.fBg != null && id.fBg.equals(fBg)))
-// return true;
-// // if the only thing that isn't the same is the background color
-// // still return true if it does not matter (percents add up to 100)
-// int sum = 0;
-// for (int i = 0; i < fPercents.length; i++)
-// sum += fPercents[i];
-// if (sum >= 100)
-// return true;
-// }
-// }
-// return false;
-// }
-//
-// public int hashCode() {
-// int hash = super.hashCode();
-// hash = hash * 7 + new Boolean(fVertical).hashCode();
-// for (int i = 0; i < fPercents.length; i++)
-// hash = hash * 7 + new Integer(fPercents[i]).hashCode();
-// return hash;
-// }
-// }
-
+
+ private class SimpleImageIdentifier extends ImageIdentifier {
+ private int fTheight;
+ private int fMarginHeight;
+
+ SimpleImageIdentifier(Display display, Color color1, Color color2,
+ int realtheight, int theight, int marginHeight) {
+ super(display, new Color[] { color1, color2 }, realtheight);
+ fTheight = theight;
+ fMarginHeight = marginHeight;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof SimpleImageIdentifier) {
+ SimpleImageIdentifier id = (SimpleImageIdentifier) obj;
+ if (super.equals(obj) && id.fTheight == fTheight
+ && id.fMarginHeight == fMarginHeight)
+ return true;
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ int hash = super.hashCode();
+ hash = hash * 7 + new Integer(fTheight).hashCode();
+ hash = hash * 7 + new Integer(fMarginHeight).hashCode();
+ return hash;
+ }
+ }
+
+ private class ComplexImageIdentifier extends ImageIdentifier {
+ Color fBg;
+ boolean fVertical;
+ int[] fPercents;
+
+ public ComplexImageIdentifier(Display display, Color[] colors,
+ int length, int[] percents, boolean vertical, Color bg) {
+ super(display, colors, length);
+ fBg = bg;
+ fVertical = vertical;
+ fPercents = percents;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof ComplexImageIdentifier) {
+ ComplexImageIdentifier id = (ComplexImageIdentifier) obj;
+ if (super.equals(obj) && id.fVertical == fVertical
+ && Arrays.equals(id.fPercents, fPercents)) {
+ if ((id.fBg == null && fBg == null)
+ || (id.fBg != null && id.fBg.equals(fBg)))
+ return true;
+ // if the only thing that isn't the same is the background
+ // color
+ // still return true if it does not matter (percents add up
+ // to 100)
+ int sum = 0;
+ for (int i = 0; i < fPercents.length; i++)
+ sum += fPercents[i];
+ if (sum >= 100)
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ int hash = super.hashCode();
+ hash = hash * 7 + new Boolean(fVertical).hashCode();
+ for (int i = 0; i < fPercents.length; i++)
+ hash = hash * 7 + new Integer(fPercents[i]).hashCode();
+ return hash;
+ }
+ }
+
private class ImageReference {
private Image fImage;
private int fCount;
-
+
public ImageReference(Image image) {
fImage = image;
fCount = 1;
@@ -151,66 +151,76 @@
public Image getImage() {
return fImage;
}
- // returns a boolean indicating if all clients of this image are finished
+
+ // returns a boolean indicating if all clients of this image are
+ // finished
// a true result indicates the underlying image should be disposed
public boolean decCount() {
return --fCount == 0;
}
+
public void incCount() {
fCount++;
}
}
-
-// RAP [rh] missing Image-GC
-// public Image getGradient(Display display, Color color1, Color color2,
-// int realtheight, int theight, int marginHeight) {
-// checkHashMaps();
-// ImageIdentifier id = new SimpleImageIdentifier(display, color1, color2, realtheight, theight, marginHeight);
-// ImageReference result = (ImageReference) images.get(id);
-// if (result != null && !result.getImage().isDisposed()) {
-// result.incCount();
-// return result.getImage();
-// }
-// Image image = createGradient(display, color1, color2, realtheight, theight, marginHeight);
-// images.put(id, new ImageReference(image));
-// ids.put(image, id);
-// return image;
-// }
-//
-// public Image getGradient(Display display, Color[] colors, int[] percents,
-// int length, boolean vertical, Color bg) {
-// checkHashMaps();
-// ImageIdentifier id = new ComplexImageIdentifier(display, colors, length, percents, vertical, bg);
-// ImageReference result = (ImageReference) images.get(id);
-// if (result != null && !result.getImage().isDisposed()) {
-// result.incCount();
-// return result.getImage();
-// }
-// Image image = createGradient(display, colors, percents, length, vertical, bg);
-// images.put(id, new ImageReference(image));
-// ids.put(image, id);
-// return image;
-// }
-
+
+ public Image getGradient(Display display, Color color1, Color color2,
+ int realtheight, int theight, int marginHeight) {
+ checkHashMaps();
+ ImageIdentifier id = new SimpleImageIdentifier(display, color1, color2,
+ realtheight, theight, marginHeight);
+ ImageReference result = (ImageReference) images.get(id);
+ if (result != null) {
+ return result.getImage();
+ }
+ Image image = AWTHelper.createGradient(color1, color2, realtheight,
+ theight, marginHeight);
+ images.put(id, new ImageReference(image));
+ ids.put(image, id);
+ return image;
+ }
+
+ public Image getGradient(Display display, Color[] colors, int[] percents,
+ int length, boolean vertical, Color bg) {
+ checkHashMaps();
+ ImageIdentifier id = new ComplexImageIdentifier(display, colors,
+ length, percents, vertical, bg);
+ ImageReference result = (ImageReference) images.get(id);
+ if (result != null) {
+ result.incCount();
+ return result.getImage();
+ }
+ Image image = AWTHelper.createGradient(colors, percents, length,
+ vertical, bg);
+ images.put(id, new ImageReference(image));
+ ids.put(image, id);
+ return image;
+ }
+
+ public Image getBackgroundImage(Rectangle rect, Color background, Image backgroundImage) {
+ Image image = AWTHelper.createBackgroundImage(rect.width, rect.height, background, backgroundImage);
+ return image;
+ }
+
public boolean markFinished(Image image) {
checkHashMaps();
- ImageIdentifier id = (ImageIdentifier)ids.get(image);
+ ImageIdentifier id = (ImageIdentifier) ids.get(image);
if (id != null) {
ImageReference ref = (ImageReference) images.get(id);
if (ref != null) {
if (ref.decCount()) {
images.remove(id);
ids.remove(ref.getImage());
-// RAP [rh] no Image#dispose() API
-// ref.getImage().dispose();
+ // RAP [rh] no Image#dispose() API
+ // ref.getImage().dispose();
validateHashMaps();
}
return true;
}
}
// if the image was not found, dispose of it for the caller
-// RAP [rh] no Image#dispose() API
-// image.dispose();
+ // RAP [rh] no Image#dispose() API
+ // image.dispose();
return false;
}
@@ -220,85 +230,11 @@
if (ids == null)
ids = new HashMap();
}
-
+
private void validateHashMaps() {
if (images.size() == 0)
images = null;
if (ids.size() == 0)
ids = null;
}
-
-// RAP [rh] Disabled unused code, called by getGradient
-// private Image createGradient(Display display, Color color1, Color color2,
-// int realtheight, int theight, int marginHeight) {
-// Image image = new Image(display, 1, realtheight);
-// image.setBackground(color1);
-// GC gc = new GC(image);
-// gc.setBackground(color1);
-// gc.fillRectangle(0, 0, 1, realtheight);
-// gc.setForeground(color2);
-// gc.setBackground(color1);
-// gc.fillGradientRectangle(0, marginHeight + 2, 1, theight - 2, true);
-// gc.dispose();
-// return image;
-// }
-//
-// private Image createGradient(Display display, Color[] colors, int[] percents,
-// int length, boolean vertical, Color bg) {
-// int width = vertical ? 1 : length;
-// int height = vertical ? length : 1;
-// Image gradient = new Image(display, Math.max(width, 1), Math
-// .max(height, 1));
-// GC gc = new GC(gradient);
-// drawTextGradient(gc, width, height, colors, percents, vertical, bg);
-// gc.dispose();
-// return gradient;
-// }
-//
-// private void drawTextGradient(GC gc, int width, int height, Color[] colors,
-// int[] percents, boolean vertical, Color bg) {
-// final Color oldBackground = gc.getBackground();
-// if (colors.length == 1) {
-// if (colors[0] != null)
-// gc.setBackground(colors[0]);
-// gc.fillRectangle(0, 0, width, height);
-// } else {
-// final Color oldForeground = gc.getForeground();
-// Color lastColor = colors[0];
-// if (lastColor == null)
-// lastColor = oldBackground;
-// int pos = 0;
-// for (int i = 0; i < percents.length; ++i) {
-// gc.setForeground(lastColor);
-// lastColor = colors[i + 1];
-// if (lastColor == null)
-// lastColor = oldBackground;
-// gc.setBackground(lastColor);
-// if (vertical) {
-// int gradientHeight = percents[i] * height / 100;
-//
-// gc.fillGradientRectangle(0, pos, width, gradientHeight,
-// true);
-// pos += gradientHeight;
-// } else {
-// int gradientWidth = percents[i] * height / 100;
-//
-// gc.fillGradientRectangle(pos, 0, gradientWidth, height,
-// false);
-// pos += gradientWidth;
-// }
-// }
-// if (vertical && pos < height) {
-// if (bg != null)
-// gc.setBackground(bg);
-// gc.fillRectangle(0, pos, width, height - pos);
-// }
-// if (!vertical && pos < width) {
-// if (bg != null)
-// gc.setBackground(bg);
-// gc.fillRectangle(pos, 0, width - pos, height);
-// }
-// gc.setForeground(oldForeground);
-// }
-// }
}
Index: src/org/eclipse/ui/forms/widgets/Section.java
============================================================ =======
RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.ui.fo rms/src/org/eclipse/ui/forms/widgets/Section.java,v
retrieving revision 1.1
diff -u -r1.1 Section.java
--- src/org/eclipse/ui/forms/widgets/Section.java 16 Apr 2008 09:44:33 -0000 1.1
+++ src/org/eclipse/ui/forms/widgets/Section.java 9 Dec 2008 00:17:55 -0000
@@ -12,23 +12,24 @@
************************************************************ *******************/
package org.eclipse.ui.forms.widgets;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
import java.util.Hashtable;
import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.SWT;
-//import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
-//import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
-//import org.eclipse.swt.graphics.Point;
-//import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.internal.graphics.ResourceFactory;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.internal.forms.widgets.AWTHelper;
import org.eclipse.ui.internal.forms.widgets.FormImages;
-//import org.eclipse.ui.internal.forms.widgets.FormUtil;
/**
* A variation of the expandable composite that adds optional description below
@@ -98,7 +99,11 @@
}
};
addListener(SWT.Dispose, listener);
- addListener(SWT.Resize, listener);
+ addListener(SWT.Resize, new Listener() {
+ public void handleEvent(Event event) {
+ updateTitleBackground();
+ }
+ });
}
}
@@ -110,10 +115,11 @@
protected void internalSetExpanded(boolean expanded) {
super.internalSetExpanded(expanded);
- if ((getExpansionStyle() & TITLE_BAR) != 0) {
- if (!expanded)
- super.setBackgroundImage(null);
- }
+// PAK resetting to null is not a good thing!
+// if ((getExpansionStyle() & TITLE_BAR) != 0) {
+// if (!expanded)
+// super.setBackgroundImage(null);
+// }
reflow();
}
@@ -332,139 +338,116 @@
titleColors.put(key, color);
}
-// RAP [rh] missing Paint events
-// protected void onPaint(PaintEvent e) {
-// Color bg = null;
-// Color fg = null;
-// Color border = null;
-//
-// GC gc = e.gc;
-// Image buffer = null;
-// Rectangle bounds = getClientArea();
-//
-// if ((getExpansionStyle() & TITLE_BAR) != 0) {
-// buffer = new Image(getDisplay(), bounds.width, bounds.height);
-// buffer.setBackground(getBackground());
-// gc = new GC(buffer);
-// }
-// if (titleColors != null) {
-// bg = (Color) titleColors.get(COLOR_BG);
-// fg = getTitleBarForeground();
-// border = (Color) titleColors.get(COLOR_BORDER);
-// }
-// if (bg == null)
-// bg = getBackground();
-// if (fg == null)
-// fg = getForeground();
-// if (border == null)
-// border = fg;
-// int theight = 0;
-// int gradientheight = 0;
-// int tvmargin = IGAP;
-// if ((getExpansionStyle() & TITLE_BAR) != 0) {
-// Point tsize = null;
-// Point tcsize = null;
-// if (toggle != null)
-// tsize = toggle.getSize();
-// int twidth = bounds.width - marginWidth - marginWidth;
-// if (tsize != null)
-// twidth -= tsize.x + IGAP;
-// if (getTextClient() != null)
-// tcsize = getTextClient().getSize();
-// if (tcsize != null)
-// twidth -= tcsize.x + IGAP;
-// Point size = textLabel.getSize();
-// if (tsize != null)
-// theight += Math.max(theight, tsize.y);
-// gradientheight = theight;
-// if (tcsize != null) {
-// theight = Math.max(theight, tcsize.y);
-// }
-// theight = Math.max(theight, size.y);
-// gradientheight = Math.max(gradientheight, size.y);
-// theight += tvmargin + tvmargin;
-// gradientheight += tvmargin + tvmargin;
-// } else {
-// theight = 5;
-// }
-// if ((getExpansionStyle() & TITLE_BAR) != 0) {
-// if (getBackgroundImage() == null)
-// updateHeaderImage(bg, bounds, gradientheight, theight);
-// gc.setBackground(getBackground());
-// gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
-// drawBackground(gc, bounds.x, bounds.y, bounds.width, theight);
-// if (marginWidth > 0) {
-// // fix up margins
-// gc.setBackground(getBackground());
-// gc.fillRectangle(0, 0, marginWidth, theight);
-// gc.fillRectangle(bounds.x + bounds.width - marginWidth, 0,
-// marginWidth, theight);
-// }
-// } else if (isExpanded()) {
-// gc.setForeground(bg);
-// gc.setBackground(getBackground());
-// gc.fillGradientRectangle(marginWidth, marginHeight, bounds.width
-// - marginWidth - marginWidth, theight, true);
-// }
-// gc.setBackground(getBackground());
+ protected void updateTitleBackground() {
+ Color bg = null;
+ Color fg = null;
+ Color border = null;
+
+ Rectangle bounds = getClientArea();
+ BufferedImage bufferedImage = new BufferedImage(bounds.width, bounds.height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2 = bufferedImage.createGraphics();
+ g2.setBackground(AWTHelper.toAWTColor(getBackground()));
+ g2.clearRect(0, 0, bounds.width, bounds.height);
+
+ if (titleColors != null) {
+ bg = (Color) titleColors.get(COLOR_BG);
+ fg = getTitleBarForeground();
+ border = (Color) titleColors.get(COLOR_BORDER);
+ }
+ if (bg == null)
+ bg = getBackground();
+ if (fg == null)
+ fg = getForeground();
+ if (border == null)
+ border = fg;
+ int theight = 0;
+ int gradientheight = 0;
+ int tvmargin = IGAP;
+ if ((getExpansionStyle() & TITLE_BAR) != 0) {
+ Point tsize = null;
+ Point tcsize = null;
+ if (toggle != null)
+ tsize = toggle.getSize();
+ int twidth = bounds.width - marginWidth - marginWidth;
+ if (tsize != null)
+ twidth -= tsize.x + IGAP;
+ if (getTextClient() != null)
+ tcsize = getTextClient().getSize();
+ if (tcsize != null)
+ twidth -= tcsize.x + IGAP;
+ Point size = textLabel.getSize();
+ if (tsize != null)
+ theight += Math.max(theight, tsize.y);
+ gradientheight = theight;
+ if (tcsize != null) {
+ theight = Math.max(theight, tcsize.y);
+ }
+ theight = Math.max(theight, size.y);
+ gradientheight = Math.max(gradientheight, size.y);
+ theight += tvmargin + tvmargin;
+ gradientheight += tvmargin + tvmargin;
+ } else {
+ theight = 5;
+ }
+ if ((getExpansionStyle() & TITLE_BAR) != 0) {
+ g2.setColor(AWTHelper.toAWTColor(getBackground()));
+ g2.fillRect(0, 0, bounds.width, bounds.height);
+ AWTHelper.fillGradientRectangle(g2, bg, getBackground(), 0, marginHeight + 2, bounds.width, theight - marginHeight - 4);
+ if (marginWidth > 0) {
+ // fix up margins
+ g2.setColor(AWTHelper.toAWTColor(getBackground()));
+ g2.fillRect(0, 0, marginWidth, theight);
+ g2.fillRect(bounds.width - marginWidth, 0,
+ marginWidth, theight);
+ }
+ } else if (isExpanded()) {
+ AWTHelper.fillGradientRectangle(g2, bg, getBackground(), marginWidth, marginHeight, bounds.width
+ - marginWidth - marginWidth, theight);
+ }
+ g2.setColor(AWTHelper.toAWTColor(getBackground()));
// FormUtil.setAntialias(gc, SWT.ON);
-// // repair the upper left corner
-// gc.fillPolygon(new int[] { marginWidth, marginHeight, marginWidth,
-// marginHeight + 2, marginWidth + 2, marginHeight });
-// // repair the upper right corner
-// gc.fillPolygon(new int[] { bounds.width - marginWidth - 3,
-// marginHeight, bounds.width - marginWidth, marginHeight,
-// bounds.width - marginWidth, marginHeight + 3 });
-// gc.setForeground(border);
-// if (isExpanded() || (getExpansionStyle() & TITLE_BAR) != 0) {
-// // top left curve
-// gc.drawLine(marginWidth, marginHeight + 2, marginWidth + 2,
-// marginHeight);
-// // top edge
-// gc.drawLine(marginWidth + 2, marginHeight, bounds.width
-// - marginWidth - 3, marginHeight);
-// // top right curve
-// gc.drawLine(bounds.width - marginWidth - 3, marginHeight,
-// bounds.width - marginWidth - 1, marginHeight + 2);
-// } else {
-// // collapsed short title bar
-// // top edge
-// gc.drawLine(marginWidth, marginHeight, bounds.width - 1,
-// marginHeight);
-// }
-// if ((getExpansionStyle() & TITLE_BAR) != 0 || isExpanded()) {
-// // left vertical edge gradient
-// gc.fillGradientRectangle(marginWidth, marginHeight + 2, 1,
-// gradientheight - 2, true);
-// // right vertical edge gradient
-// gc.fillGradientRectangle(bounds.width - marginWidth - 1,
-// marginHeight + 2, 1, gradientheight - 2, true);
-// }
-// if ((getExpansionStyle() & TITLE_BAR) != 0) {
-// // New in 3.3 - edge treatmant
-// gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE ));
-// gc.drawPolyline(new int[] { marginWidth + 1,
-// marginHeight + gradientheight - 1, marginWidth + 1,
-// marginHeight + 2, marginWidth + 2, marginHeight + 2,
-// marginWidth + 2, marginHeight + 1,
-// bounds.width - marginWidth - 3, marginHeight + 1,
-// bounds.width - marginWidth - 3, marginHeight + 2,
-// bounds.width - marginWidth - 2, marginHeight + 2,
-// bounds.width - marginWidth - 2,
-// marginHeight + gradientheight - 1 });
-// }
-// if (buffer != null) {
-// gc.dispose();
-// e.gc.drawImage(buffer, 0, 0);
-// buffer.dispose();
-// }
-// }
-//
-// private void updateHeaderImage(Color bg, Rectangle bounds, int theight,
-// int realtheight) {
-// Image image = FormImages.getInstance().getGradient(getDisplay(), getBackground(), bg, realtheight, theight, marginHeight);
-// super.setBackgroundImage(image);
-// }
+ // repair the upper left corner
+ g2.fillPolygon(new int[] { marginWidth, marginWidth, marginWidth + 2}, new int[] { marginHeight, marginHeight + 2, marginHeight }, 3);
+ // repair the upper right corner
+ g2.fillPolygon(new int[] { bounds.width - marginWidth - 3, bounds.width - marginWidth, bounds.width - marginWidth}, new int[] {marginHeight, marginHeight, marginHeight + 3}, 3);
+ g2.setColor(AWTHelper.toAWTColor(border));
+ if (isExpanded() || (getExpansionStyle() & TITLE_BAR) != 0) {
+ // top left curve
+ g2.drawLine(marginWidth, marginHeight + 2, marginWidth + 2,
+ marginHeight);
+ // top edge
+ g2.drawLine(marginWidth + 2, marginHeight, bounds.width
+ - marginWidth - 3, marginHeight);
+ // top right curve
+ g2.drawLine(bounds.width - marginWidth - 3, marginHeight,
+ bounds.width - marginWidth - 1, marginHeight + 2);
+ } else {
+ // collapsed short title bar
+ // top edge
+ g2.drawLine(marginWidth, marginHeight, bounds.width - 1,
+ marginHeight);
+ }
+ if ((getExpansionStyle() & TITLE_BAR) != 0 || isExpanded()) {
+ // left vertical edge gradient
+ AWTHelper.fillGradientRectangle(g2, border, getBackground(), marginWidth, marginHeight + 2, 1, gradientheight - 2);
+ // right vertical edge gradient
+ AWTHelper.fillGradientRectangle(g2, border, getBackground(), bounds.width - marginWidth - 1, marginHeight + 2, 1, gradientheight - 2);
+ }
+ if ((getExpansionStyle() & TITLE_BAR) != 0) {
+ // New in 3.3 - edge treatmant
+ g2.setColor(AWTHelper.toAWTColor(getDisplay().getSystemColor (SWT.COLOR_WHITE)));
+ g2.drawPolygon(new int[] { marginWidth + 1, marginWidth + 1,marginWidth + 2,
+ marginWidth + 2, bounds.width - marginWidth - 3, bounds.width - marginWidth - 3,
+ bounds.width - marginWidth - 2, bounds.width - marginWidth - 2},
+ new int[] {marginHeight + gradientheight - 1, marginHeight + 2, marginHeight + 2, marginHeight + 1, marginHeight + 1,
+ marginHeight + 2, marginHeight + 2, marginHeight + gradientheight - 1 }, 8
+ );
+ }
+
+ g2.dispose();
+ super.setBackgroundImage(ResourceFactory.findImage(AWTHelper .convertToSWT(bufferedImage)));
+ }
/**
* Background image is used for the title gradient - does nothing.
Index: src/org/eclipse/ui/internal/forms/widgets/AWTHelper.java
============================================================ =======
RCS file: src/org/eclipse/ui/internal/forms/widgets/AWTHelper.java
diff -N src/org/eclipse/ui/internal/forms/widgets/AWTHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/internal/forms/widgets/AWTHelper.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,243 @@
+/********************************************************** *********************
+ * Copyright (c) 2008 Innoopract Informationssysteme GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Innoopract Informationssysteme GmbH - initial API and implementation
+ ************************************************************ ******************/
+
+package org.eclipse.ui.internal.forms.widgets;
+
+import java.awt.*;
+import java.awt.Rectangle;
+import java.awt.image.*;
+
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.internal.graphics.*;
+
+public class AWTHelper {
+
+ private AWTHelper() {
+ ;
+ }
+
+ public static void fillGradientRectangle(Graphics2D g2, Color color1, Color color2, int x, int y, int width, int height) {
+ java.awt.Color awtColor1 = toAWTColor(color1);
+ java.awt.Color awtColor2 = toAWTColor(color2);
+ GradientPaint paint = new GradientPaint(0, y, awtColor1, 0, height+y, awtColor2);
+ g2.setPaint(paint);
+ g2.fill(new Rectangle(x, y, width, height));
+ }
+
+ static Image createGradient(Color color1, Color color2,
+ int realtheight, int theight, int marginHeight) {
+ BufferedImage bufferedImage = new BufferedImage(1, realtheight,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2 = bufferedImage.createGraphics();
+ java.awt.Color awtColor1 = new java.awt.Color(color1.getRed(), color1
+ .getGreen(), color1.getBlue());
+ java.awt.Color awtColor2 = new java.awt.Color(color2.getRed(), color2
+ .getGreen(), color2.getBlue());
+ g2.setBackground(awtColor1);
+ g2.clearRect(0, 0, 1, realtheight);
+ GradientPaint paint = new GradientPaint(0, marginHeight + 2, awtColor1,
+ 0, theight - 2, awtColor2);
+ g2.setPaint(paint);
+ g2.fill(new Rectangle(0, marginHeight + 2, 1, theight - marginHeight
+ - 4));
+ g2.dispose();
+ return ResourceFactory.findImage(convertToSWT(bufferedImage));
+ }
+
+ static Image createGradient(Color[] colors, int[] percents,
+ int length, boolean vertical, Color bg) {
+ int width = vertical ? 1 : length;
+ int height = vertical ? length : 1;
+ BufferedImage bufferedImage = new BufferedImage(Math.max(width, 1),
+ Math.max(height, 1), BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2 = bufferedImage.createGraphics();
+ drawTextGradient(g2, width, height, colors, percents, vertical, bg);
+ g2.dispose();
+ return ResourceFactory.findImage(convertToSWT(bufferedImage));
+ }
+
+ static Image createBackgroundImage(int width, int height,
+ Color background, Image backgroundImage) {
+ BufferedImage bufferedImage = new BufferedImage(Math.max(width, 1),
+ Math.max(height, 1), BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2 = bufferedImage.createGraphics();
+ g2.setBackground(toAWTColor(background));
+ g2.clearRect(0, 0, width, height);
+ g2.drawImage(convertToAWT(ResourceFactory.getImageData(backg roundImage)), 0,
+ 0, backgroundImage.getBounds().width, backgroundImage.getBounds().height,
+ toAWTColor(background), null);
+ return ResourceFactory.findImage(convertToSWT(bufferedImage));
+ }
+
+ private static void drawTextGradient(Graphics2D gc, int width, int height,
+ Color[] colors, int[] percents, boolean vertical, Color bg) {
+ final Color oldBackground = bg;
+ if (colors.length == 1) {
+ if (colors[0] != null)
+ gc.setColor(toAWTColor(colors[0]));
+ gc.fillRect(0, 0, width, height);
+ } else {
+ Color lastColor = colors[0];
+ if (lastColor == null)
+ lastColor = oldBackground;
+ int pos = 0;
+ for (int i = 0; i < percents.length; ++i) {
+ java.awt.Color awtColor1 = toAWTColor(lastColor);
+ lastColor = colors[i + 1];
+ if (lastColor == null)
+ lastColor = oldBackground;
+ java.awt.Color awtColor2 = toAWTColor(lastColor);
+ if (vertical) {
+ int gradientHeight = percents[i] * height / 100;
+ GradientPaint paint = new GradientPaint(0, 0, awtColor1, 1,
+ gradientHeight - pos, awtColor2);
+ gc.setPaint(paint);
+ gc.fill(new Rectangle(0, pos, 1, gradientHeight));
+ pos += gradientHeight;
+ } else {
+ int gradientWidth = percents[i] * width / 100;
+ GradientPaint paint = new GradientPaint(0, 0, awtColor1,
+ gradientWidth - pos, 1, awtColor2);
+ gc.setPaint(paint);
+ gc.fill(new Rectangle(pos, 0, gradientWidth, 1));
+ pos += gradientWidth;
+ }
+ }
+ if (vertical && pos < height) {
+ if (bg != null)
+ gc.setColor(toAWTColor(bg));
+ gc.fillRect(0, pos, width, height - pos);
+ }
+ if (!vertical && pos < width) {
+ if (bg != null)
+ gc.setColor(toAWTColor(bg));
+ gc.fillRect(pos, 0, width - pos, height);
+ }
+ }
+ }
+
+ public static java.awt.Color toAWTColor(Color color) {
+ return new java.awt.Color(color.getRed(), color.getGreen(), color
+ .getBlue());
+ }
+
+ public static ImageData convertToSWT(BufferedImage bufferedImage) {
+ if (bufferedImage.getColorModel() instanceof DirectColorModel) {
+ DirectColorModel colorModel = (DirectColorModel) bufferedImage
+ .getColorModel();
+ PaletteData palette = new PaletteData(colorModel.getRedMask(),
+ colorModel.getGreenMask(), colorModel.getBlueMask());
+ ImageData data = new ImageData(bufferedImage.getWidth(),
+ bufferedImage.getHeight(), colorModel.getPixelSize(),
+ palette);
+ WritableRaster raster = bufferedImage.getRaster();
+ int[] pixelArray = new int[3];
+ for (int y = 0; y < data.height; y++) {
+ for (int x = 0; x < data.width; x++) {
+ raster.getPixel(x, y, pixelArray);
+ int pixel = palette.getPixel(new RGB(pixelArray[0],
+ pixelArray[1], pixelArray[2]));
+ data.setPixel(x, y, pixel);
+ }
+ }
+ return data;
+ } else if (bufferedImage.getColorModel() instanceof IndexColorModel) {
+ IndexColorModel colorModel = (IndexColorModel) bufferedImage
+ .getColorModel();
+ int size = colorModel.getMapSize();
+ byte[] reds = new byte[size];
+ byte[] greens = new byte[size];
+ byte[] blues = new byte[size];
+ colorModel.getReds(reds);
+ colorModel.getGreens(greens);
+ colorModel.getBlues(blues);
+ RGB[] rgbs = new RGB[size];
+ for (int i = 0; i < rgbs.length; i++) {
+ rgbs[i] = new RGB(reds[i] & 0xFF, greens[i] & 0xFF,
+ blues[i] & 0xFF);
+ }
+ PaletteData palette = new PaletteData(rgbs);
+ ImageData data = new ImageData(bufferedImage.getWidth(),
+ bufferedImage.getHeight(), colorModel.getPixelSize(),
+ palette);
+ data.transparentPixel = colorModel.getTransparentPixel();
+ WritableRaster raster = bufferedImage.getRaster();
+ int[] pixelArray = new int[1];
+ for (int y = 0; y < data.height; y++) {
+ for (int x = 0; x < data.width; x++) {
+ raster.getPixel(x, y, pixelArray);
+ data.setPixel(x, y, pixelArray[0]);
+ }
+ }
+ return data;
+ }
+ return null;
+ }
+
+ static BufferedImage convertToAWT(ImageData data) {
+ ColorModel colorModel = null;
+ PaletteData palette = data.palette;
+ if (palette.isDirect) {
+ colorModel = new DirectColorModel(data.depth, palette.redMask,
+ palette.greenMask, palette.blueMask);
+ BufferedImage bufferedImage = new BufferedImage(colorModel,
+ colorModel.createCompatibleWritableRaster(data.width,
+ data.height), false, null);
+ WritableRaster raster = bufferedImage.getRaster();
+ int[] pixelArray = new int[3];
+ for (int y = 0; y < data.height; y++) {
+ for (int x = 0; x < data.width; x++) {
+ int pixel = data.getPixel(x, y);
+ RGB rgb = palette.getRGB(pixel);
+ pixelArray[0] = rgb.red;
+ pixelArray[1] = rgb.green;
+ pixelArray[2] = rgb.blue;
+ raster.setPixels(x, y, 1, 1, pixelArray);
+ }
+ }
+ return bufferedImage;
+ } else {
+ RGB[] rgbs = palette.getRGBs();
+ byte[] red = new byte[rgbs.length];
+ byte[] green = new byte[rgbs.length];
+ byte[] blue = new byte[rgbs.length];
+ for (int i = 0; i < rgbs.length; i++) {
+ RGB rgb = rgbs[i];
+ red[i] = (byte) rgb.red;
+ green[i] = (byte) rgb.green;
+ blue[i] = (byte) rgb.blue;
+ }
+ if (data.transparentPixel != -1) {
+ colorModel = new IndexColorModel(data.depth, rgbs.length, red,
+ green, blue, data.transparentPixel);
+ } else {
+ colorModel = new IndexColorModel(data.depth, rgbs.length, red,
+ green, blue);
+ }
+ BufferedImage bufferedImage = new BufferedImage(colorModel,
+ colorModel.createCompatibleWritableRaster(data.width,
+ data.height), false, null);
+ WritableRaster raster = bufferedImage.getRaster();
+ int[] pixelArray = new int[1];
+ for (int y = 0; y < data.height; y++) {
+ for (int x = 0; x < data.width; x++) {
+ int pixel = data.getPixel(x, y);
+ pixelArray[0] = pixel;
+ raster.setPixel(x, y, pixelArray);
+ }
+ }
+ return bufferedImage;
+ }
+ }
+
+}
--nextPart1494406.mUpDUsVv1N--
|
|
| | | | |
Re: Form & Section Title Backgrounds [message #115126 is a reply to message #115089] |
Tue, 09 December 2008 13:08  |
Eclipse User |
|
|
|
Originally posted by: paul.kendall.orionhealth.com
Setya wrote:
>> this bug seems to be about the same thing:
>> 213193: [Forms] Section setTitleBarBackground
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=213193
>
> Maybe also Bug#234087.
>
>
> Setya
I have attached the patch to 213193 as thats where I put my previous patch.
This one implements both the form header and the section header.
I see in the bug that the RAP team is not wanting to have the AWT code
because it will require an X server installed, which is fair enough. I have
attached the patch to the ticket in case it is useful for others.
Cheers,
Paul
|
|
|
Goto Forum:
Current Time: Mon Apr 28 02:53:08 EDT 2025
Powered by FUDForum. Page generated in 0.02399 seconds
|