Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 89087 Details for
Bug 218104
Cleanup of DefaultGalleryItemRenderer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Gallery Renderer cleanup
GalleryRenderer.patch (text/plain), 14.33 KB, created by
Peter Centgraf
on 2008-02-06 18:22:06 EST
(
hide
)
Description:
Gallery Renderer cleanup
Filename:
MIME Type:
Creator:
Peter Centgraf
Created:
2008-02-06 18:22:06 EST
Size:
14.33 KB
patch
obsolete
>Index: src/org/eclipse/nebula/widgets/gallery/AbstractGalleryItemRenderer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/src/org/eclipse/nebula/widgets/gallery/AbstractGalleryItemRenderer.java,v >retrieving revision 1.5 >diff -u -r1.5 AbstractGalleryItemRenderer.java >--- src/org/eclipse/nebula/widgets/gallery/AbstractGalleryItemRenderer.java 29 Nov 2007 18:23:09 -0000 1.5 >+++ src/org/eclipse/nebula/widgets/gallery/AbstractGalleryItemRenderer.java 6 Feb 2008 23:13:41 -0000 >@@ -10,6 +10,9 @@ > *******************************************************************************/ > package org.eclipse.nebula.widgets.gallery; > >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; > import org.eclipse.swt.graphics.GC; > > /** >@@ -74,4 +77,68 @@ > this.gallery = gallery; > } > >+ /** >+ * Check the GalleryItem, Gallery, and Display in order for the active >+ * background color for the given GalleryItem. >+ * >+ * @param item >+ * @return the background Color to use for this item >+ */ >+ protected Color getBackground(GalleryItem item) { >+ Color backgroundColor = item.getBackground(); >+ if (backgroundColor == null) { >+ backgroundColor = item.getParent().getBackground(); >+ } >+ if (backgroundColor == null) { >+ backgroundColor = item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); >+ } >+ return backgroundColor; >+ } >+ >+ >+ /** >+ * Check the GalleryItem, Gallery, and Display in order for the active >+ * foreground color for the given GalleryItem. >+ * >+ * @param item >+ * @return the foreground Color to use for this item >+ */ >+ protected Color getForeground(GalleryItem item) { >+ Color foregroundColor = item.getForeground(); >+ if (foregroundColor == null) { >+ foregroundColor = item.getParent().getForeground(); >+ } >+ if (foregroundColor == null) { >+ foregroundColor = item.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); >+ } >+ return foregroundColor; >+ } >+ >+ /** >+ * Check the GalleryItem, Gallery, and Display in order for the active >+ * font color for the given GalleryItem. >+ * >+ * @param item >+ * @return the Font to use for this item >+ */ >+ protected Font getFont(GalleryItem item) { >+ Font font = item.getFont(); >+ if (font == null) { >+ font = item.getParent().getFont(); >+ } >+ if (font == null) { >+ font = item.getDisplay().getSystemFont(); >+ } >+ return font; >+ } >+ >+ /** >+ * Completely redraw the current Gallery, if one is set. >+ */ >+ protected void redrawGallery() { >+ if (gallery != null) { >+ gallery.redraw(); >+ } >+ } >+ > } >Index: src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java,v >retrieving revision 1.11 >diff -u -r1.11 DefaultGalleryItemRenderer.java >--- src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java 10 Jan 2008 09:46:37 -0000 1.11 >+++ src/org/eclipse/nebula/widgets/gallery/DefaultGalleryItemRenderer.java 6 Feb 2008 23:13:41 -0000 >@@ -45,57 +45,78 @@ > > int dropShadowsAlphaStep = 20; > >- Color selectionForegroundColor; >- >- Color selectionBackgroundColor; >- >- Color foregroundColor; >- >- Color backgroundColor; >+ Color selectionForegroundColor = null; >+ Color selectionBackgroundColor = null; > > boolean showLabels = true; > >- public boolean isShowLabels() { >- return showLabels; >- } >- >- public void setShowLabels(boolean showLabels) { >- this.showLabels = showLabels; >- } >- > public DefaultGalleryItemRenderer() { >- // Set defaults >- foregroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND); >- backgroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND); >- >- selectionForegroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); >- selectionBackgroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION); >- > // Create drop shadows > createColors(); > } > > public void draw(GC gc, GalleryItem item, int index, int x, int y, int width, int height) { >- Image itemImage = item.getImage(); >- Color itemBackgroundColor = item.getBackground(); >- Color itemForegroundColor = item.getForeground(); >+ // Find the colors, font, and image currently in effect for this item >+ Color backgroundColor = getBackground(item); >+ Color foregroundColor = getForeground(item); >+ Font font = getFont(item); >+ >+ // If no local override has been set, use the current system selection colors >+ Color selectionForegroundColor; >+ if (this.selectionForegroundColor != null) { >+ selectionForegroundColor = this.selectionForegroundColor; >+ } >+ else { >+ selectionForegroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); >+ } >+ >+ Color selectionBackgroundColor; >+ if (this.selectionBackgroundColor != null) { >+ selectionBackgroundColor = this.selectionBackgroundColor; >+ } >+ else { >+ selectionBackgroundColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION); >+ } >+ > // Set up the GC >- gc.setFont(getFont(item)); >+ if (selected) { >+ gc.setForeground(selectionForegroundColor); >+ gc.setBackground(selectionBackgroundColor); >+ } >+ else { >+ gc.setForeground(foregroundColor); >+ gc.setBackground(backgroundColor); >+ } >+ gc.setFont(font); > >+ // Compute the size of the image and background > int useableHeight = height; > int fontHeight = 0; > if (item.getText() != null && this.showLabels) { > fontHeight = gc.getFontMetrics().getHeight(); > useableHeight -= fontHeight + 2; > } >+ >+ // Redraw the background (rounded rectangles) if the item is selected >+ // or if a custom background color was set >+ if (selected || item.getBackground() != null) { >+ gc.fillRoundRectangle(x, y, width, useableHeight, 15, 15); >+ >+ // Also draw the background for the label, if there is one >+ if (item.getText() != null && showLabels) { >+ gc.fillRoundRectangle(x, y + height - fontHeight, width, fontHeight, 15, 15); >+ } >+ } > >- int imageWidth = 0; >- int imageHeight = 0; >- int xShift = 0; >- int yShift = 0; >- Point size = null; >- >+ // Draw the image and drop shadow, only if necessary >+ Image itemImage = item.getImage(); > if (itemImage != null) { >+ int imageWidth = 0; >+ int imageHeight = 0; >+ int xShift = 0; >+ int yShift = 0; >+ Point size = null; >+ > Rectangle itemImageBounds = itemImage.getBounds(); > imageWidth = itemImageBounds.width; > imageHeight = itemImageBounds.height; >@@ -104,83 +125,34 @@ > > xShift = (width - size.x) >> 1; > yShift = (useableHeight - size.y) >> 1; >+ >+ // Draw the image >+ if (size.x > 0 && size.y > 0) { >+ gc.drawImage(itemImage, 0, 0, imageWidth, imageHeight, x + xShift, y + yShift, size.x, size.y); >+ } > >+ // Draw the drop shadow around the image > if (dropShadows) { >- Color c = null; >+ // Save the old foreground color >+ Color oldForeground = gc.getForeground(); >+ >+ // Draw progressively lighter foreground lines > for (int i = this.dropShadowsSize - 1; i >= 0; i--) { >- c = (Color) dropShadowsColors.get(i); >+ Color c = (Color) dropShadowsColors.get(i); > gc.setForeground(c); > > gc.drawLine(x + width + i - xShift - 1, y + dropShadowsSize + yShift, x + width + i - xShift - 1, y + useableHeight + i - yShift); > gc.drawLine(x + xShift + dropShadowsSize, y + useableHeight + i - yShift - 1, x + width + i - xShift, y - 1 + useableHeight + i - yShift); > } >+ >+ // Restore the old foreground color >+ gc.setForeground(oldForeground); > } > } > >- // Set colors >- // if (selected) { >- // gc.setBackground(selectionBackgroundColor); >- // gc.setForeground(selectionBackgroundColor); >- // } else { >- // if (itemBackgroundColor != null) { >- // gc.setBackground(itemBackgroundColor); >- // } >- // if (itemForegroungColor != null) { >- // gc.setForeground(itemForegroungColor); >- // } >- // } >- >- // Draw background (rounded rectangles) >- if (selected || itemBackgroundColor != null) { >- >- // Set colors >- if (selected) { >- gc.setBackground(selectionBackgroundColor); >- gc.setForeground(selectionBackgroundColor); >- } else if (itemBackgroundColor != null) { >- gc.setBackground(itemBackgroundColor); >- } >- >- // Draw >- gc.fillRoundRectangle(x, y, width, useableHeight, 15, 15); >- if (item.getText() != null && showLabels) { >- gc.fillRoundRectangle(x, y + height - fontHeight, width, fontHeight, 15, 15); >- } >- } >- >- // Draw image >- if (itemImage != null) { >- if (size.x > 0 && size.y > 0) { >- gc.drawImage(itemImage, 0, 0, imageWidth, imageHeight, x + xShift, y + yShift, size.x, size.y); >- } >- } >- >- // Draw label >+ // Draw the text label > if (item.getText() != null && showLabels) { >- // Set colors >- if (selected) { >- // Selected : use selection colors. >- gc.setForeground(selectionForegroundColor); >- gc.setBackground(selectionBackgroundColor); >- } else { >- // Not selected, use item values or defaults. >- >- // Background >- if (itemBackgroundColor != null) { >- gc.setBackground(itemBackgroundColor); >- } else { >- gc.setBackground(backgroundColor); >- } >- >- // Foreground >- if (itemForegroundColor != null) { >- gc.setForeground(itemForegroundColor); >- } else { >- gc.setForeground(foregroundColor); >- } >- } >- >- // Create label >+ // Shorten the label with an ellipse if necessary > String text = RendererHelper.createLabel(item.getText(), gc, width - 10); > > // Center text >@@ -192,27 +164,13 @@ > } > } > >- /** >- * @param item >- * @return the Font to use for this item >- */ >- protected Font getFont(GalleryItem item) { >- // Item font >- Font itemFont = item.getFont(); >- >- // Parent item font >- if (itemFont == null) { >- if (item.getParentItem() != null) >- itemFont = item.getParentItem().getFont(); >- } >- >- // Gallery font >- if (itemFont == null) { >- if (item.getParentItem() != null) >- itemFont = item.getParent().getFont(); >- } >+ public boolean isDropShadows() { >+ return dropShadows; >+ } > >- return itemFont; >+ public void setDropShadows(boolean dropShadows) { >+ this.dropShadows = dropShadows; >+ redrawGallery(); > } > > public void setDropShadowsSize(int dropShadowsSize) { >@@ -221,72 +179,40 @@ > > freeDropShadowsColors(); > createColors(); >- // TODO: force redraw >+ >+ // force redraw >+ redrawGallery(); >+ } > >+ public int getDropShadowsSize() { >+ return dropShadowsSize; > } > >- private void createColors() { >- if (dropShadowsSize > 0) { >- int step = 125 / dropShadowsSize; >- // Create new colors >- for (int i = dropShadowsSize - 1; i >= 0; i--) { >- int value = 255 - i * step; >- Color c = new Color(Display.getDefault(), value, value, value); >- dropShadowsColors.add(c); >- } >- } >+ public boolean isShowLabels() { >+ return showLabels; > } > >- private void freeDropShadowsColors() { >- // Free colors : >- { >- Iterator i = this.dropShadowsColors.iterator(); >- while (i.hasNext()) { >- Color c = (Color) i.next(); >- if (c != null && !c.isDisposed()) >- c.dispose(); >- } >- } >+ public void setShowLabels(boolean showLabels) { >+ this.showLabels = showLabels; >+ redrawGallery(); > } > >- public boolean isDropShadows() { >- return dropShadows; >+ public Color getSelectionForegroundColor() { >+ return selectionForegroundColor; > } > >- public void setDropShadows(boolean dropShadows) { >- this.dropShadows = dropShadows; >+ public void setSelectionForegroundColor(Color selectionForegroundColor) { >+ this.selectionForegroundColor = selectionForegroundColor; >+ redrawGallery(); > } > >- public int getDropShadowsSize() { >- return dropShadowsSize; >+ public Color getSelectionBackgroundColor() { >+ return selectionBackgroundColor; > } > >- /** >- * Returns the font used for drawing item label or <tt>null</tt> if system >- * font is used. >- * >- * @return the font >- * @deprecated Use {@link Gallery#getFont()} >- */ >- public Font getFont() { >- if (gallery != null) { >- return gallery.getFont(); >- } >- return null; >- } >- >- /** >- * Set the font for drawing item label or <tt>null</tt> to use system >- * font. >- * >- * @param font >- * the font to set >- * @deprecated Use {@link Gallery#setFont(Font)} >- */ >- public void setFont(Font font) { >- if (gallery != null) { >- gallery.setFont(font); >- } >+ public void setSelectionBackgroundColor(Color selectionBackgroundColor) { >+ this.selectionBackgroundColor = selectionBackgroundColor; >+ redrawGallery(); > } > > public void dispose() { >@@ -305,35 +231,27 @@ > return new Point(newWidth, newHeight); > } > >- public Color getForegroundColor() { >- return foregroundColor; >- } >- >- public void setForegroundColor(Color foregroundColor) { >- this.foregroundColor = foregroundColor; >- } >- >- public Color getSelectionForegroundColor() { >- return selectionForegroundColor; >- } >- >- public void setSelectionForegroundColor(Color selectionForegroundColor) { >- this.selectionForegroundColor = selectionForegroundColor; >- } >- >- public Color getSelectionBackgroundColor() { >- return selectionBackgroundColor; >- } >- >- public void setSelectionBackgroundColor(Color selectionBackgroundColor) { >- this.selectionBackgroundColor = selectionBackgroundColor; >- } >- >- public Color getBackgroundColor() { >- return backgroundColor; >+ private void createColors() { >+ if (dropShadowsSize > 0) { >+ int step = 125 / dropShadowsSize; >+ // Create new colors >+ for (int i = dropShadowsSize - 1; i >= 0; i--) { >+ int value = 255 - i * step; >+ Color c = new Color(Display.getDefault(), value, value, value); >+ dropShadowsColors.add(c); >+ } >+ } > } > >- public void setBackgroundColor(Color backgroundColor) { >- this.backgroundColor = backgroundColor; >+ private void freeDropShadowsColors() { >+ // Free colors : >+ { >+ Iterator i = this.dropShadowsColors.iterator(); >+ while (i.hasNext()) { >+ Color c = (Color) i.next(); >+ if (c != null && !c.isDisposed()) >+ c.dispose(); >+ } >+ } > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 218104
: 89087 |
132117