Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » PShelf
PShelf [message #513516] Wed, 10 February 2010 13:06
Niels Lippke is currently offline Niels LippkeFriend
Messages: 71
Registered: December 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_000A_01CAAA5A.3B442260
Content-Type: text/plain;
format=flowed;
charset="iso-8859-1";
reply-type=original
Content-Transfer-Encoding: 7bit

Attached you'll find a RAP version for the pshelf. The API is unchanged. The
original implementation is changed in the way that it uses now the GCCanvas
instead of the (non-existing) internal GC.

The "animation" is missing, but I guess that's ok. I know that Tom did a
transcript as well, but was not allowed to release it. So feel free to use
this one.

Regards,
Niels

P.S.: You may use the snippet from the nebula project site as demo.

------=_NextPart_000_000A_01CAAA5A.3B442260
Content-Type: application/x-zip-compressed;
name="pshelf.zip"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="pshelf.zip"

PK=03=04=0A=
=00=00=00=00=00=A0nJ<=00=00=00=00=00=00=00=00=00=00=00=00"=00=00=00org.ec=
lipse.nebula.widgets.pshelf/PK=03=04=0A=
=00=00=00=00=00=15=00=00=00org.eclipse.=
nebula.widgets.pshelf/src/org/eclipse/nebula/widgets/pshelf/ AbstractRende=
rer.java/*************************************************** *************=
***************
* Copyright (c) 2006 IBM Corporation and others.
* 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:
* chris.gross@us.ibm.com - initial API and implementation
=
************************************************************ *************=
******/=20
package org.eclipse.nebula.widgets.pshelf;

import org.eclipse.rwt.widgets.GCCanvas; =20
//import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;

/**
* <p>
* NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT. THIS IS =
A PRE-RELEASE ALPHA=20
* VERSION. USERS SHOULD EXPECT API CHANGES IN FUTURE VERSIONS.
* </p>=20
* Renders a single visual unit.
* =20
* @author chris.gross@us.ibm.com
*/
public abstract class AbstractRenderer
{

/** Hover state. */
private boolean hover;

/** Renderer has focus. */
private boolean focus;

/** Mouse down on the renderer area. */
private boolean mouseDown;

/** Selection state. */
private boolean selected;

/** Expansion state. */
private boolean expanded;

/** The bounds the renderer paints on. */
private Rectangle bounds =3D new Rectangle(0, 0, 0, 0);

private boolean disposed =3D false;
=20
/**
* Returns the bounds.
*=20
* @return Rectangle describing the bounds.
*/
public Rectangle getBounds()
{
return bounds;
}

/**
* Sets the bounds of the drawing.
*=20
* @param x X coordinate.
* @param y Y coordinate.
* @param width Width.
* @param height Height.
*/
public void setBounds(int x, int y, int width, int height)
{
setBounds(new Rectangle(x, y, width, height));
}

/**
* Sets the bounds of the drawing.
*=20
* @param bounds Bounds.
*/
public void setBounds(Rectangle bounds)
{
this.bounds =3D bounds;
}

/**
* Returns the size.
*=20
* @return size of the renderer.
*/
public Point getSize()
{
return new Point(bounds.width, bounds.height);
}

/**
* Sets the location of the drawing.
*=20
* @param x X.
* @param y Y.
*/
public void setLocation(int x, int y)
{
setBounds(new Rectangle(x, y, bounds.width, bounds.height));
}

/**
* Sets the location of the drawing.
*=20
* @param location Location.
*/
public void setLocation(Point location)
{
setBounds(new Rectangle(location.x, location.y, bounds.width, =
bounds.height));
}

/**
* Sets the area of the drawing.
*=20
* @param width Width.
* @param height Height.
*/
public void setSize(int width, int height)
{
setBounds(new Rectangle(bounds.x, bounds.y, width, height));
}

/**
* Sets the area of the drawing.
*=20
* @param size Size.
*/
public void setSize(Point size)
{
setBounds(new Rectangle(bounds.x, bounds.y, size.x, size.y));
}

/**
* Returns a boolean value indicating if this renderer has focus.
*=20
* @return True/false if has focus.
*/
public boolean isFocus()
{
return focus;
}

/**
* Sets focus state.
*=20
* @param focus focus state.
*/
public void setFocus(boolean focus)
{
this.focus =3D focus;
}

/**
* Returns the hover state.
*=20
* @return Is the renderer in the hover state.
*/
public boolean isHover()
{
return hover;
}

/**
* Sets the hover state.
*=20
* @param hover Hover state.
*/
public void setHover(boolean hover)
{
this.hover =3D hover;
}

/**
* Returns the boolean value indicating if the renderer has the =
mouseDown
* state.
*=20
* @return mouse down state.
*/
public boolean isMouseDown()
{
return mouseDown;
}

/**
* Sets the mouse down state.
*=20
* @param mouseDown Mouse state.
*/
public void setMouseDown(boolean mouseDown)
{
this.mouseDown =3D mouseDown;
}

/**
* Returns the boolean state indicating if the selected state is =
set.
*=20
* @return selected state.
*/
public boolean isSelected()
{
return selected;
}

/**
* Sets the selected state.
*=20
* @param selected Selection state.
*/
public void setSelected(boolean selected)
{
this.selected =3D selected;
}

/**
* Returns the expansion state.
*=20
* @return Returns the expanded.
*/
public boolean isExpanded()
{
return expanded;
}

/**
* Sets the expansion state of this renderer.
*=20
* @param expanded The expanded to set.
*/
public void setExpanded(boolean expanded)
{
this.expanded =3D expanded;
}

/**
* Paints the visual representation of the given value on the given =
GC. The
* actual class of the value object is determined by the use of the
* implementing class.
* <p>
* Implementors need to respect the bounds values that may have been
* specified. The bounds values may affect the x and y values for =
all
* drawing operations as well as the width and heights. Implementors =
may use
* a <code>Transform</code> to translate the coordinates of all the
* drawing operations, otherwise they will need to offset each draw.
* </p>
*=20
* @param GCCanvas GCCanvas to paint with
* @param value the value being painted
*/
public abstract void paint(GCCanvas gc, Object value);

/**
* Returns the size of the given value's visual representation.
*=20
* @param GCCanvas convenience GCCanvas for string and text extents
* @param wHint given width (or SWT.DEFAULT)
* @param hHint given height (or SWT.DEFAULT)
* @param value value to be sized
* @return the size
*/
public abstract Point computeSize(GCCanvas gc, int wHint, int hHint, =
Object value);

/**
* Performs any initialization logic (such as creating new colors or =
fonts).
*=20
* @param parent control that is using the renderer
*/
public abstract void initialize(Control parent);
=20
/**
* Disposes of any resources managed by this renderer.
*/
public void dispose(){
setDisposed(true);
}

/**
* @return the disposed
*/
public boolean isDisposed()
{
return disposed;
}

/**
* @param disposed the disposed to set
*/
protected void setDisposed(boolean disposed)
{
this.disposed =3D disposed;
}
}
PK=03=04=0A=
=00=00=00=00=00=14.getHeight() + =
(2*(margin+textMargin)));
=09
//int h =3D =
Math.max(item.getImage().getBounds().height,gc.getFontMetric s().getFontDa=
ta().getHeight() + (2*textMargin)) + (2*margin);
int h =3D =
Math.max(item.getImage().getBounds().height,gc.getFont().get FontData()=
..getHeight() + (2*textMargin)) + (2*margin);
=09
if (h % 2 !=3D 0)
h ++;
=09
return new Point(wHint,h);
}
=09
=20
/**=20
* {@inheritDoc}
*/
public void paint(/*GC*/ GCCanvas gc, Object value)
{
PShelfItem item =3D (PShelfItem)value;
=20
//Color back =3D parent.getBackground();
Color fore =3D parent.getForeground();
=09
=
gc.fillRectangle(0,getBounds().y,getBounds().width-1,getBoun ds().height-1=
); =09
=20
gc.setForeground(shadeColor);

gc.fillGradientRectangle(0,getBounds().y,40,getBounds().heig ht-1,true =
/*false*/);
=09
=
gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLO R_WIDGET_HIGH=
LIGHT_SHADOW));
gc.drawLine(0,getBounds().y,0,getBounds().y +getBounds().height -1);
gc.drawLine(0,getBounds().y,getBounds().width -1,getBounds().y);
=09
=
gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLO R_WIDGET_NORM=
AL_SHADOW));
gc.drawLine(0,getBounds().y +getBounds().height =
-1,getBounds().width-1,getBounds().y +getBounds().height-1);
=
gc.drawLine(getBounds().width-1,getBounds().y,getBounds().wi dth-1,getBoun=
ds().y +getBounds().height-1);
=09
int x =3D 6;
if (item.getImage() !=3D null){
int y2 =3D (getBounds().height - =
item.getImage().getBounds().height)/2;
if ((getBounds().height - item.getImage().getBounds().height) % 2 =
!=3D 0)
y2 ++;
=09
gc.drawImage(item.getImage(),x,getBounds().y + y2);
=09
x +=3D item.getImage().getBounds().width + spacing;
}
gc.setForeground(fore);
=09
// int y2 =3D (getBounds().height - =
gc.getFontMetrics().getHeight())/2;
int y2 =3D (getBounds().height - =
gc.getFont().getFontData().getHeight())/2;
//if ((getBounds().height - gc.getFontMetrics().getHeight()) % 2 !=3D =
0)
if ((getBounds().height - gc.getFont().getFontData().getHeight()) % =
2 !=3D 0)
y2 ++;
=09
// if (center){
// x =3D (width - gc.stringExtent(item.getText()).x)/2;
// }
=20
// if (isHover() && !isSelected())
// =
gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_LIS T_SELECTION))=
;
=09
String text =3D getShortString(gc, item.getText(), =
getBounds().width - x - 4);
//gc.drawString(text,x,getBounds().y +y2,true);
gc.drawText(text,x,getBounds().y + y2 - 4);
=20
if (isFocus()){
//gc.drawFocus(1,1,getBounds().width-2,getBounds().height-1) ;
gc.drawRectangle(1,1,getBounds().width-2,getBounds().height- 1);
}
}
=09
public void initialize(Control control){
this.parent =3D (PShelf)control;
shadeColor =3D =
parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_S HADOW);
}

public Color getShadeColor() {
return shadeColor;
}

public void setShadeColor(Color shadeColor) {
this.shadeColor =3D shadeColor;
}

private static String getShortString(/*GC*/ GCCanvas gc, String t, =
int width)
{

if (t =3D=3D null)
{
return null;
}

if (t.equals(""))
{
return "";
}

//if (width >=3D gc.stringExtent(t).x)
if (width >=3D Graphics.stringExtent(gc.getFont(),t).x)
{
return t;
}

//int w =3D gc.stringExtent("...").x;
int w =3D Graphics.stringExtent(gc.getFont(),"...").x;
String text =3D t;
int l =3D text.length();
int pivot =3D l / 2;
int s =3D pivot;
int e =3D pivot + 1;
while (s >=3D 0 && e < l)
{
String s1 =3D text.substring(0, s);
String s2 =3D text.substring(e, l);
//int l1 =3D gc.stringExtent(s1).x;
int l1 =3D Graphics.stringExtent(gc.getFont(),s1).x;
//int l2 =3D gc.stringExtent(s2).x;
int l2 =3D Graphics.stringExtent(gc.getFont(),s1).x;
if (l1 + w + l2 < width)
{
text =3D s1 + "..." + s2;
break;
}
s--;
e++;
}

if (s =3D=3D 0 || e =3D=3D l)
{
text =3D text.substring(0, 1) + "..." + text.substring(l - =
1, l);
}

return text;
}
}
PK=03=04=0A=
=00=00=00=00=00=14 getItems()
{
checkWidget();
return (PShelfItem[])items.toArray(new =
PShelfItem);
}
=20
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's selection changes, by sending
* it one of the messages defined in the =
<code>SelectionListener</code>
* interface.
* <p>
* When <code>widgetSelected</code> is called, the item field of the =
event object is valid.
* <code>widgetDefaultSelected</code> is not called.
* </p>
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been =
disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the =
thread that created the receiver</li>
* </ul>
*
* @see SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
checkWidget ();
if (listener =3D=3D null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener =3D new TypedListener(listener);
addListener(SWT.Selection,typedListener);
addListener(SWT.DefaultSelection,typedListener);
}
=20
/**
* Removes the listener from the collection of listeners who will
* be notified when the receiver's selection changes.
*
* @param listener the listener which should no longer be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been =
disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the =
thread that created the receiver</li>
* </ul>
*
* @see SelectionListener
* @see #addSelectionListener
*/
public void removeSelectionListener (SelectionListener listener) {
checkWidget ();
if (listener =3D=3D null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener =3D new TypedListener(listener);
//removeListener(SWT.Selection, listener);
removeListener(SWT.Selection, typedListener);
//removeListener(SWT.DefaultSelection,listener);
removeListener(SWT.DefaultSelection,typedListener);
}

/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#redraw()
*/
public void redraw() {
super.redraw();
onPaint(gc); =09
}
=20
=20
}
PK=03=04=0A=
=00=00=00=00=00=14 initialColors; // to dispose created colors

private int textMargin =3D 2;
private int margin =3D 4;
private PShelf parent;
private int spacing =3D 8;

private Font initialFont;
private Font initialOpenFont;

private Color gradient1;
private Color gradient2;

private Font font;
private Font selectedFont;

private Color selectedGradient1;
private Color selectedGradient2;

private Color hoverGradient1;
private Color hoverGradient2;

private Color lineColor;

private Color selectedForeground;
private Color hoverForeground;
private Color foreground;

/**
* {@inheritDoc}
*/
public Point computeSize(/* GC */GCCanvas gc, int wHint, int hHint,
Object value) {
PShelfItem item =3D (PShelfItem) value;

int h =3D 0;

gc.setFont(font);

if (item.getImage() =3D=3D null) {
//h =3D gc.getFontMetrics().getHeight()+ (2 * (textMargin));
h =3D gc.getFont().getFontData().getHeight()+ (2 * (textMargin));
} else {
//h =3D Math.max(item.getImage().getBounds().height, =
gc.getFontMetrics().getHeight()+ (2 * textMargin));
h =3D Math.max(item.getImage().getBounds().height, =
gc.getFont().getFontData().getHeight()+ (2 * textMargin));
}

gc.setFont(selectedFont);

//h =3D Math.max(h, gc.getFontMetrics().getHeight() + (2 * =
textMargin));
h =3D Math.max(h, gc.getFont().getFontData().getHeight() + (2 * =
textMargin));

h +=3D 2 * margin;

if (h % 2 !=3D 0)
h++;

return new Point(wHint, h);
}

/**
* {@inheritDoc}
*/
public void paint(/* GC */GCCanvas gc, Object value) {
PShelfItem item =3D (PShelfItem) value;

// Color back =3D parent.getBackground();
Color fore =3D parent.getForeground();

if (isSelected()) {
gc.setForeground(selectedGradient1);
gc.setBackground(selectedGradient2);
} else {
if (isHover()) {
gc.setForeground(hoverGradient1);
gc.setBackground(hoverGradient2);
} else {
gc.setForeground(gradient1);
gc.setBackground(gradient2);
}
}
gc.fillGradientRectangle(getBounds().x, getBounds().y,
getBounds().width + 10, getBounds().height, /* true */false);

if ((parent.getStyle() & SWT.SIMPLE) !=3D 0) {
if (!isSelected()) {
gc.setForeground(lineColor);
gc.drawLine(0, getBounds().y, getBounds().width - 1, getBounds().y);
}
} else {
if (parent.getItems() !=3D item) {
gc.setForeground(lineColor);
gc.drawLine(0, getBounds().y, getBounds().width - 1, getBounds().y);
}

if (isSelected()) {
gc.setForeground(lineColor);
gc.drawLine(0, getBounds().y + getBounds().height - 1, =
getBounds().width - 1, getBounds().y + getBounds().height - 1);
}
}

boolean imageLeft =3D true;

if ((parent.getStyle() & SWT.SIMPLE) !=3D 0) {
imageLeft =3D !isSelected();
}

int x =3D 6;
if (item.getImage() !=3D null && imageLeft) {
int y2 =3D (getBounds().height - item.getImage().getBounds().height) =
/ 2;
if ((getBounds().height - item.getImage().getBounds().height) % 2 =
!=3D 0)
y2++;

gc.drawImage(item.getImage(), x, getBounds().y + y2);

x +=3D item.getImage().getBounds().width + spacing;
}

if (isSelected()) {
gc.setFont(selectedFont);
gc.setForeground(selectedForeground !=3D null ? selectedForeground : =
fore);
} else if (isHover()) {
gc.setFont(font);
gc.setForeground(hoverForeground !=3D null ? hoverForeground : fore);
} else {
gc.setFont(font);
gc.setForeground(foreground !=3D null ? foreground : fore);
}

// int y2 =3D (getBounds().height - gc.getFontMetrics().getHeight()) / =
2;
int y2 =3D (getBounds().height - =
gc.getFont().getFontData().getHeight()) / 2;
// if ((getBounds().height - gc.getFontMetrics().getHeight()) % 2 !=3D =
0)
if ((getBounds().height - gc.getFont().getFontData().getHeight()) % =
2 !=3D 0)
y2++;

int textWidth =3D getBounds().width - 12;
if (item.getImage() !=3D null) {
textWidth -=3D item.getImage().getBounds().width;
textWidth -=3D 6;
}

// gc.drawString(getShortString(gc, item.getText(), textWidth), x,
// getBounds().y + y2, true);
gc.drawText(getShortString(gc, item.getText(), textWidth), x, =
getBounds().y + y2 - 4);

if (item.getImage() !=3D null && !imageLeft) {
int y3 =3D (getBounds().height - item.getImage().getBounds().height) =
/ 2;
if ((getBounds().height - item.getImage().getBounds().height) % 2 =
!=3D 0)
y3++;

gc.drawImage(item.getImage(), getBounds().width - 6 - =
item.getImage().getBounds().width, getBounds().y + y3);
}

if (isFocus()) {
// gc.drawFocus(1, 1, getBounds().width - 2, getBounds().height -
// 1);
gc.drawRectangle(1, 1, getBounds().width - 2, getBounds().height - =
1);
}
}

public void initialize(Control control) {
this.parent =3D (PShelf) control;

FontData fd =3D parent.getFont().getFontData();

initialFont =3D new Font(parent.getDisplay(), fd.getName(), fd
.getHeight(), SWT.BOLD);
// parent.setFont(initialFont);

Color baseColor =3D =
parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUN D_GRADIENT);
Color color1 =3D createNewBlendedColor(baseColor, =
parent.getDisplay().getSystemColor(SWT.COLOR_WHITE), 30);

baseColor =3D =
createNewBlendedColor(parent.getDisplay().getSystemColor(SWT .COLOR_TITLE_=
BACKGROUND_GRADIENT), parent.getDisplay()
.getSystemColor(SWT.COLOR_WHITE), 80);

Color color2 =3D createNewSaturatedColor(baseColor, .01f);

if ((parent.getStyle() & SWT.SIMPLE) !=3D 0) {
gradient1 =3D color1;
gradient2 =3D color2;
} else {
selectedGradient1 =3D color1;
selectedGradient2 =3D color2;
}

baseColor.dispose();

lineColor =3D =
createNewSaturatedColor(parent.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION), .02f);

baseColor =3D parent.getDisplay()
.getSystemColor(SWT.COLOR_LIST_SELECTION);

color1 =3D createNewBlendedColor(baseColor, parent.getDisplay()
.getSystemColor(SWT.COLOR_WHITE), 70);

baseColor =3D =
createNewBlendedColor(parent.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION), parent.getDisplay().getSystemColor(
SWT.COLOR_BLACK), 80);

color2 =3D createNewSaturatedColor(baseColor, .02f);

if ((parent.getStyle() & SWT.SIMPLE) !=3D 0) {
selectedGradient1 =3D color1;
selectedGradient2 =3D color2;
} else {
gradient1 =3D color1;
gradient2 =3D color2;
}

baseColor.dispose();

// initialOpenFont =3D =
FontUtils.createFont(parent.getFont(),4,SWT.BOLD);
if ((parent.getStyle() & SWT.SIMPLE) !=3D 0)
initialOpenFont =3D new Font(parent.getDisplay(), "Arial", 12,
SWT.BOLD);
else
initialOpenFont =3D new Font(parent.getDisplay(), initialFont
.getFontData());

font =3D initialFont;
selectedFont =3D initialOpenFont;

Color inverseColor =3D parent.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT);
if ((parent.getStyle() & SWT.SIMPLE) !=3D 0)
selectedForeground =3D inverseColor;
else
foreground =3D inverseColor;
// the other color left null, foreground color of the parent will be
// used for it

baseColor =3D =
createNewReverseColor(parent.getDisplay().getSystemColor(
SWT.COLOR_TITLE_BACKGROUND));

hoverGradient1 =3D createNewBlendedColor(baseColor, =
parent.getDisplay()
.getSystemColor(SWT.COLOR_WHITE), 30);

Color baseColor2 =3D createNewBlendedColor(baseColor, =
parent.getDisplay()
.getSystemColor(SWT.COLOR_WHITE), 99);

hoverGradient2 =3D createNewSaturatedColor(baseColor2, .00f);

baseColor2.dispose();
baseColor.dispose();

initialColors =3D new Color[] { gradient1, gradient2, =
selectedGradient1,
selectedGradient2, hoverGradient1, hoverGradient2, lineColor };
}

public void dispose() {
initialFont.dispose();
initialOpenFont.dispose();

for (int i =3D 0; i < initialColors.length; i++) {
initialColors.dispose();
}

super.dispose();
}

public Color getLineColor() {
return lineColor;
}

public void setLineColor(Color lineColor) {
this.lineColor =3D lineColor;
}

public Font getFont() {
return font;
}

public void setFont(Font font) {
this.font =3D font;
}

public Color getGradient1() {
return gradient1;
}

public void setGradient1(Color gradient1) {
this.gradient1 =3D gradient1;
}

public Color getGradient2() {
return gradient2;
}

public void setGradient2(Color gradient2) {
this.gradient2 =3D gradient2;
}

public Color getHoverGradient1() {
return hoverGradient1;
}

public void setHoverGradient1(Color hoverGradient1) {
this.hoverGradient1 =3D hoverGradient1;
}

public Color getHoverGradient2() {
return hoverGradient2;
}

public void setHoverGradient2(Color hoverGradient2) {
this.hoverGradient2 =3D hoverGradient2;
}

public Font getSelectedFont() {
return selectedFont;
}

public void setSelectedFont(Font selectedFont) {
this.selectedFont =3D selectedFont;
}

public Color getSelectedForeground() {
return selectedForeground;
}

/**
* Sets text color for the selected item.
*=20
* @param selectedForeground
* Can be <code>null</code>, foreground color of the parent =
is
* used in that case.
*/
public void setSelectedForeground(Color selectedForeground) {
this.selectedForeground =3D selectedForeground;
}

public Color getHoverForeground() {
return hoverForeground;
}

/**
* Sets text color for the hovered item.
*=20
* @param hoverForeground
* Can be <code>null</code>, foreground color of the parent =
is
* used in that case.
*/
public void setHoverForeground(Color hoverForeground) {
this.hoverForeground =3D hoverForeground;
}

public Color getForeground() {
return foreground;
}

/**
* Sets text color for non-selected items.
*=20
* @param foreground
* Can be <code>null</code>, foreground color of the parent =
is
* used in that case.
*/
public void setForeground(Color foreground) {
this.foreground =3D foreground;
}

public Color getSelectedGradient1() {
return selectedGradient1;
}

public void setSelectedGradient1(Color selectedGradient1) {
this.selectedGradient1 =3D selectedGradient1;
}

public Color getSelectedGradient2() {
return selectedGradient2;
}

public void setSelectedGradient2(Color selectedGradient2) {
this.selectedGradient2 =3D selectedGradient2;
}

private static String getShortString(/* GC */GCCanvas gc, String t, int =
width) {

if (t =3D=3D null) {
return null;
}

if (t.equals("")) {
return "";
}

// if (width >=3D gc.stringExtent(t).x) {
if (width >=3D Graphics.stringExtent(gc.getFont(), t).x) {
return t;
}

// int w =3D gc.stringExtent("...").x;
int w =3D Graphics.stringExtent(gc.getFont(), "...").x;
String text =3D t;
int l =3D text.length();
int pivot =3D l / 2;
int s =3D pivot;
int e =3D pivot + 1;
while (s >=3D 0 && e < l) {
String s1 =3D text.substring(0, s);
String s2 =3D text.substring(e, l);
// int l1 =3D gc.stringExtent(s1).x;
int l1 =3D Graphics.stringExtent(gc.getFont(), s1).x;
// int l2 =3D gc.stringExtent(s2).x;
int l2 =3D Graphics.stringExtent(gc.getFont(), s2).x;
if (l1 + w + l2 < width) {
text =3D s1 + "..." + s2;
break;
}
s--;
e++;
}

if (s =3D=3D 0 || e =3D=3D l) {
text =3D text.substring(0, 1) + "..." + text.substring(l - 1, l);
}

return text;
}

private static int blend(int v1, int v2, int ratio) {
return (ratio * v1 + (100 - ratio) * v2) / 100;
}

private static RGB blend(RGB c1, RGB c2, int ratio) {
int r =3D blend(c1.red, c2.red, ratio);
int g =3D blend(c1.green, c2.green, ratio);
int b =3D blend(c1.blue, c2.blue, ratio);
return new RGB(r, g, b);
}

private static Color createNewBlendedColor(Color c1, Color c2, int =
ratio) {
Color newColor =3D new Color(Display.getCurrent(), blend(c1.getRGB(), =
c2
.getRGB(), ratio));

return newColor;
}

private static Color createNewReverseColor(Color c) {
Color newColor =3D new Color(Display.getCurrent(), 255 - c.getRed(),
255 - c.getGreen(), 255 - c.getBlue());
return newColor;
}

private static RGB saturate(RGB rgb, float saturation) {
float[] hsb =3D rgb.getHSB();

hsb +=3D saturation;
if (hsb > 1.0f) {
hsb =3D 1.0f;
}
if (hsb < 0f) {
hsb =3D 0f;
}

// hue is 0.0..360.0, saturation and brightness 0.0..1.0
hsb +=3D 360.0 * saturation;
if (hsb > 360.0f) {
hsb =3D 360.0f;
}

if (hsb < 0f) {
hsb =3D 0f;
}

return new RGB(hsb, hsb, hsb);
}

private static Color createNewSaturatedColor(Color c, float saturation) =
{
RGB newRGB =3D saturate(c.getRGB(), saturation);
return new Color(Display.getCurrent(), newRGB);
}

}
PK=01=02=14=00=0A=
=00=00=00=00=00=A0nJ<=00=00=00=00=00=00=00=00=00=00=00=00"=00=00=00=00=00=
=00=00=00=00=10=00=00=00=00=00=00=00org.eclipse.nebula.widge ts.pshelf/PK=01=
=02=14=00=0A=
=00=00=00=00=00=15[J<=8A=AB=EA=A2v=01=00=00v=01=00=00,=00=00=00=00=00=00=00=
=00=00 =
=00=00=00@=00=00=00org.eclipse.nebula.widgets.pshelf/.classp athPK=01=02=14=
=00=0A=
=00=00=00=00=00=15[J<=94=F2=BA=BB=B6=02=00=00=B6=02=00=00*=00=00=00=00=00=
=00=00=00=00 =
=00=00=00=00=02=00=00org.eclipse.nebula.widgets.pshelf/.proj ectPK=01=02=14=
=00=0A=
=00=00=00=00=00=E6mJ<=00=00=00=00=00=00=00=00=00=00=00=00,=00=00=00=00=00=
=00=00=00=00=10=00=00=00=FE=04=00=00org.eclipse.nebula.widge ts.pshelf/.se=
ttings/PK=01=02=14=00=0A=
=00=00=00=00=00=14[J<s=81=8A=CCy=02=00=00y=02=00=00F=00=00=00=00=00=00=00=
=00=00 =
=00=00=00H=05=00=00org.eclipse.nebula.widgets.pshelf/.settin gs/org.eclips=
e.jdt.core.prefsPK=01=02=14=00=0A=
=00=00=00=00=00=15[J<U)D=EFS=01=00=00S=01=00=002=00=00=00=00=00=00=00=00=00=
=
=00=00=00%=08=00=00org.eclipse.nebula.widgets.pshelf/build.p ropertiesPK=01=
=02=14=00=0A=
=00=00=00=00=00=15[J<=E8=D6=12$B=1E=00=00B=1E=00=00+=00=00=00=00=00=00=00=
=00=00 =00=00=00=C8 =
=00=00org.eclipse.nebula.widgets.pshelf/build.xmlPK=01=02=14 =00=0A=
=00=00=00=00=00=E6mJ<=00=00=00=00=00=00=00=00=00=00=00=00+=00=00=00=00=00=
=00=00=00=00=10=00=00=00S(=00=00org.eclipse.nebula.widgets.p shelf/META-IN=
F/PK=01=02=14=00=0A=
=00=00=00=00=00=14[J<=181=D2{=DC=01=00=00=DC=01=00=006=00=00=00=00=00=00=00=
=00=00 =
=00=00=00=9C(=00=00org.eclipse.nebula.widgets.pshelf/META-IN F/MANIFEST.MF=
PK=01=02=14=00=0A=
=00=00=00=00=00=E6mJ<=00=00=00=00=00=00=00=00=00=00=00=00&=00=00=00=00=00=
=00=00=00=00=10=00=00=00=CC*=00=00org.eclipse.nebula.widgets .pshelf/src/P=
K=01=02=14=00=0A=
=00=00=00=00=00=E6mJ<=00=00=00=00=00=00=00=00=00=00=00=00*=00=00=00=00=00=
=00=00=00=00=10=00=00=00=10+=00=00org.eclipse.nebula.widgets .pshelf/src/o=
rg/PK=01=02=14=00=0A=
=00=00=00=00=00=E6mJ<=00=00=00=00=00=00=00=00=00=00=00=002=00=00=00=00=00=
=00=00=00=00=10=00=00=00X+=00=00org.eclipse.nebula.widgets.p shelf/src/org=
/eclipse/PK=01=02=14=00=0A=
=00=00=00=00=00=E6mJ<=00=00=00=00=00=00=00=00=00=00=00=009=00=00=00=00=00=
=00=00=00=00=10=00=00=00=A8+=00=00org.eclipse.nebula.widgets .pshelf/src/o=
rg/eclipse/nebula/PK=01=02=14=00=0A=
=00=00=00=00=00=97nJ<=00=00=00=00=00=00=00=00=00=00=00=00A=00=00=00=00=00=
=00=00=00=00=10=00=00=00=FF+=00=00org.eclipse.nebula.widgets .pshelf/src/o=
rg/eclipse/nebula/widgets/PK=01=02=14=00=0A=
=00=00=00=00=00=E6mJ<=00=00=00=00=00=00=00=00=00=00=00=00H=00=00=00=00=00=
=00=00=00=00=10=00=00=00^,=00=00org.eclipse.nebula.widgets.p shelf/src/org=
/eclipse/nebula/widgets/pshelf/PK=01=02=14=00=0A=
=00=00=00=00=00=14[J<=9Fo=FE=80Y=1C=00=00Y=1C=00=00]=00=00=00=00=00=00=00=
=00=00 =
=00=00=00=C4,=00=00org.eclipse.nebula.widgets.pshelf/src/org /eclipse/nebu=
la/widgets/pshelf/AbstractRenderer.javaPK=01=02=14=00=0A=
=00=00=00=00=00=14[J<m=9A=AB=F2j=17=00=00j=17=00=00a=00=00=00=00=00=00=00=
=00=00 =
=00=00=00=98I=00=00org.eclipse.nebula.widgets.pshelf/src/org /eclipse/nebu=
la/widgets/pshelf/PaletteShelfRenderer.javaPK=01=02=14=00=0A =
=00=00=00=00=00=14[J<=D77C=8B=E4[=00=00=E4[=00=00S=00=00=00=00=00=00=00=00=
=00 =
=00=00=00=81a=00=00org.eclipse.nebula.widgets.pshelf/src/org /eclipse/nebu=
la/widgets/pshelf/PShelf.javaPK=01=02=14=00=0A=
=00=00=00=00=00=14[J<=99=A8=B7=F6=CF=17=00=00=CF=17=00=00W=00=00=00=00=00=
=00=00=00=00 =
=00=00=00=D6=BD=00=00org.eclipse.nebula.widgets.pshelf/src/o rg/eclipse/ne=
bula/widgets/pshelf/PShelfItem.javaPK=01=02=14=00=0A=
=00=00=00=00=00=14[J<=C3@=F1=8A=117=00=00=117=00=00a=00=00=00=00=00=00=00=
=00=00 =
=00=00=00=1A=D6=00=00org.eclipse.nebula.widgets.pshelf/src/o rg/eclipse/ne=
bula/widgets/pshelf/RedmondShelfRenderer.javaPK=05=06=00=00= 00=00=14=00=14=
=00M=08=00=00=AA=0D=01=00=00=00
------=_NextPart_000_000A_01CAAA5A.3B442260--
Re: PShelf [message #513634 is a reply to message #513516] Wed, 10 February 2010 13:04 Go to previous message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Hi Nils,

cool thing. Thanks for sharing your work. If you would like to host and
maintain the PShelf in the RAP incubator at eclipse.org, please let us know.

Regards
Rüdiger
--
Rüdiger Herrmann
http://eclipsesource.com

On 10.02.2010 14:06, Niels Lippke wrote:
> Attached you'll find a RAP version for the pshelf. The API is unchanged.
> The original implementation is changed in the way that it uses now the
> GCCanvas instead of the (non-existing) internal GC.
>
> The "animation" is missing, but I guess that's ok. I know that Tom did a
> transcript as well, but was not allowed to release it. So feel free to
> use this one.
>
> Regards,
> Niels
>
> P.S.: You may use the snippet from the nebula project site as demo.
Previous Topic:any plans for Browser's AuthenticationListener?
Next Topic:Starting of a new session
Goto Forum:
  


Current Time: Fri Apr 26 21:19:09 GMT 2024

Powered by FUDForum. Page generated in 0.03120 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top