?? redmondshelfstrategy.java
字號(hào):
package com.swtplus.widgets.shelf;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import com.swtplus.internal.FontUtils;
import com.swtplus.internal.GraphicUtils;
import com.swtplus.internal.PGC;
import com.swtplus.widgets.PShelf;
import com.swtplus.widgets.PShelfItem;
public class RedmondShelfStrategy implements IShelfStrategy {
private int textMargin = 2;
private int margin = 4;
private PShelf parent;
private int spacing = 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;
public RedmondShelfStrategy(int style) {
}
public int computeHeight(PShelfItem item, GC gc) {
int h = 0;
gc.setFont(font);
if (item.getImage() == null){
h = gc.getFontMetrics().getHeight() + (2*(textMargin));
} else {
h = Math.max(item.getImage().getBounds().height,gc.getFontMetrics().getHeight() + (2*textMargin));
}
gc.setFont(selectedFont);
h = Math.max(h,gc.getFontMetrics().getHeight() + (2*textMargin));
h += 2*margin;
if (h % 2 != 0)
h ++;
return h;
}
public void paintItem(PShelfItem item, GC gc, int y, int height, int width,
boolean open, boolean focus, boolean hover, boolean showPin,
boolean pinned) {
//Color back = parent.getBackground();
Color fore = parent.getForeground();
if (open){
gc.setForeground(selectedGradient1);
} else {
if (hover){
gc.setForeground(hoverGradient1);
} else {
gc.setForeground(gradient1);
}
}
if (open){
gc.setBackground(selectedGradient2);
} else {
if (hover){
gc.setBackground(hoverGradient2);
} else {
gc.setBackground(gradient2);
}
}
gc.fillGradientRectangle(0,y,width,height,true);
if (!open){
gc.setForeground(lineColor);
gc.drawLine(0,y,width -1,y);
}
int x = 6;
if (item.getImage() != null && !open){
int y2 = (height - item.getImage().getBounds().height)/2;
if ((height - item.getImage().getBounds().height) % 2 != 0)
y2 ++;
gc.drawImage(item.getImage(),x,y + y2);
x += item.getImage().getBounds().width + spacing;
}
gc.setForeground(fore);
if (open){
gc.setFont(selectedFont);
gc.setForeground(selectedForeground);
} else {
gc.setFont(font);
}
int y2 = (height - gc.getFontMetrics().getHeight())/2;
if ((height - gc.getFontMetrics().getHeight()) % 2 != 0)
y2 ++;
int textWidth = width - 12;
if (item.getImage() != null){
textWidth -= item.getImage().getBounds().width;
textWidth -= 6;
}
PGC pgc = new PGC(gc);
gc.drawString(pgc.getShortString(item.getText(),textWidth),x,y +y2,true);
if (item.getImage() != null && open){
int y3 = (height - item.getImage().getBounds().height)/2;
if ((height - item.getImage().getBounds().height) % 2 != 0)
y3 ++;
gc.drawImage(item.getImage(),width - 6 - item.getImage().getBounds().width,y + y3);
}
if (focus){
gc.drawFocus(1,1,width-2,height-1);
}
}
public void initialize(PShelf parent) {
this.parent = parent;
initialFont = FontUtils.createBoldFont(parent.getFont());
//parent.setFont(initialFont);
Color baseColor = parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
gradient1 = GraphicUtils.createNewBlendedColor(baseColor,parent.getDisplay().getSystemColor(SWT.COLOR_WHITE),30);
baseColor = GraphicUtils.createNewBlendedColor(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT),parent.getDisplay().getSystemColor(SWT.COLOR_WHITE),80);
gradient2 = GraphicUtils.createNewSaturatedColor(baseColor,.01f);
baseColor.dispose();
lineColor = GraphicUtils.createNewSaturatedColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION),.02f);
baseColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
selectedGradient1 = GraphicUtils.createNewBlendedColor(baseColor,parent.getDisplay().getSystemColor(SWT.COLOR_WHITE),70);
baseColor = GraphicUtils.createNewBlendedColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION),parent.getDisplay().getSystemColor(SWT.COLOR_BLACK),80);
selectedGradient2 = GraphicUtils.createNewSaturatedColor(baseColor,.02f);
baseColor.dispose();
//initialOpenFont = FontUtils.createFont(parent.getFont(),4,SWT.BOLD);
initialOpenFont = new Font(parent.getDisplay(),"Arial",12,SWT.BOLD);
font = initialFont;
selectedFont = initialOpenFont;
selectedForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
baseColor = GraphicUtils.createNewReverseColor(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
hoverGradient1 = GraphicUtils.createNewBlendedColor(baseColor,parent.getDisplay().getSystemColor(SWT.COLOR_WHITE),30);
Color baseColor2 = GraphicUtils.createNewBlendedColor(baseColor,parent.getDisplay().getSystemColor(SWT.COLOR_WHITE),99);
hoverGradient2 = GraphicUtils.createNewSaturatedColor(baseColor2,.00f);
baseColor2.dispose();
baseColor.dispose();
}
public void dispose() {
initialFont.dispose();
gradient1.dispose();
gradient2.dispose();
lineColor.dispose();
selectedGradient1.dispose();
selectedGradient2.dispose();
initialFont.dispose();
initialOpenFont.dispose();
hoverGradient1.dispose();
hoverGradient2.dispose();
}
public boolean isOpenOnTop() {
return true;
}
public Color getLineColor() {
return lineColor;
}
public void setLineColor(Color lineColor) {
this.lineColor = lineColor;
}
public Font getFont() {
return font;
}
public void setFont(Font font) {
this.font = font;
}
public Color getGradient1() {
return gradient1;
}
public void setGradient1(Color gradient1) {
this.gradient1 = gradient1;
}
public Color getGradient2() {
return gradient2;
}
public void setGradient2(Color gradient2) {
this.gradient2 = gradient2;
}
public Color getHoverGradient1() {
return hoverGradient1;
}
public void setHoverGradient1(Color hoverGradient1) {
this.hoverGradient1 = hoverGradient1;
}
public Color getHoverGradient2() {
return hoverGradient2;
}
public void setHoverGradient2(Color hoverGradient2) {
this.hoverGradient2 = hoverGradient2;
}
public Font getSelectedFont() {
return selectedFont;
}
public void setSelectedFont(Font selectedFont) {
this.selectedFont = selectedFont;
}
public Color getSelectedForeground() {
return selectedForeground;
}
public void setSelectedForeground(Color selectedForeground) {
this.selectedForeground = selectedForeground;
}
public Color getSelectedGradient1() {
return selectedGradient1;
}
public void setSelectedGradient1(Color selectedGradient1) {
this.selectedGradient1 = selectedGradient1;
}
public Color getSelectedGradient2() {
return selectedGradient2;
}
public void setSelectedGradient2(Color selectedGradient2) {
this.selectedGradient2 = selectedGradient2;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -