📄 paletteshelfstrategy.java
字号:
package com.swtplus.widgets.shelf;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import com.swtplus.widgets.PShelf;
import com.swtplus.widgets.PShelfItem;
public class PaletteShelfStrategy implements IShelfStrategy {
private int textMargin = 2;
private int margin = 2;
private PShelf parent;
private int spacing = 4;
private Color shadeColor;
public static final int CENTER = 1 << 1;
private boolean center = false;
public PaletteShelfStrategy(int style) {
if ((style & CENTER) == CENTER)
center = true;
}
/* (non-Javadoc)
* @see com.swtplus.widgets.shelf.IShelfStrategy#computeHeight(com.swtplus.widgets.shelf.ShelfItem, org.eclipse.swt.graphics.GC)
*/
public int computeHeight(PShelfItem item, GC gc){
if (item.getImage() == null)
return gc.getFontMetrics().getHeight() + (2*(margin+textMargin));
int h = Math.max(item.getImage().getBounds().height,gc.getFontMetrics().getHeight() + (2*textMargin)) + (2*margin);
if (h % 2 != 0)
h ++;
return h;
}
/* (non-Javadoc)
* @see com.swtplus.widgets.shelf.IShelfStrategy#paintItem(com.swtplus.widgets.shelf.ShelfItem, org.eclipse.swt.graphics.GC, int, int, int, boolean, boolean, boolean, boolean, boolean)
*/
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();
gc.fillRectangle(0,y,width-1,height-1);
gc.setForeground(shadeColor);
gc.fillGradientRectangle(0,y,40,height-1,false);
gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
gc.drawLine(0,y,0,y +height -1);
gc.drawLine(0,y,width -1,y);
gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
gc.drawLine(0,y +height -1,width-1,y +height-1);
gc.drawLine(width-1,y,width-1,y +height-1);
int x = 6;
if (item.getImage() != null){
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);
int y2 = (height - gc.getFontMetrics().getHeight())/2;
if ((height - gc.getFontMetrics().getHeight()) % 2 != 0)
y2 ++;
if (center){
x = (width - gc.stringExtent(item.getText()).x)/2;
}
gc.drawString(item.getText(),x,y +y2,true);
if (focus){
gc.drawFocus(1,1,width-2,height-1);
}
}
/* (non-Javadoc)
* @see com.swtplus.widgets.shelf.IShelfStrategy#initialize(com.swtplus.widgets.shelf.PShelf)
*/
public void initialize(PShelf parent){
this.parent = parent;
shadeColor = parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
}
public Color getShadeColor() {
return shadeColor;
}
public void setShadeColor(Color shadeColor) {
this.shadeColor = shadeColor;
}
public void dispose() {
}
public boolean isOpenOnTop() {
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -