📄 defaultcellrenderer.java
字号:
rect.height-6, rect.width-6);
gcImg.dispose();
Image mirrorImg = mirrorImage(vImg);
gc.drawImage(mirrorImg, rect.x, rect.y);
vImg.dispose();
mirrorImg.dispose();
}
private int mirrorAlignment() {
int align = getAlignment();
int result=0;
if ((align & SWTX.ALIGN_HORIZONTAL_MASK)==SWTX.ALIGN_HORIZONTAL_CENTER)
result = SWTX.ALIGN_VERTICAL_CENTER;
else if ((align & SWTX.ALIGN_HORIZONTAL_MASK)==SWTX.ALIGN_HORIZONTAL_RIGHT)
result = SWTX.ALIGN_VERTICAL_TOP;
else
result = SWTX.ALIGN_VERTICAL_BOTTOM;
if ((align & SWTX.ALIGN_VERTICAL_MASK)==SWTX.ALIGN_VERTICAL_CENTER)
result |= SWTX.ALIGN_HORIZONTAL_CENTER;
else if ((align & SWTX.ALIGN_VERTICAL_MASK )== SWTX.ALIGN_VERTICAL_TOP)
result |= SWTX.ALIGN_HORIZONTAL_RIGHT;
else
result |= SWTX.ALIGN_HORIZONTAL_LEFT;
result |= (SWTX.WRAP_MASK & align);
return result;
}
/**
* Mirrors the given image. Note that the returned image must be disposed after rendering!
* @param source The source image. Gets disposed in this method.
* @return Returns a new image with mirrored content. The caller is responsible for disposing this image!
*/
private Image mirrorImage(Image source) {
Rectangle bounds = source.getBounds();
ImageData sourceData = source.getImageData();
ImageData resultData = new ImageData(
sourceData.height, sourceData.width,
sourceData.depth, sourceData.palette);
for (int x = 0; x<bounds.width; x++)
for (int y=0; y<bounds.height; y++)
resultData.setPixel(y, resultData.height-x-1, sourceData.getPixel(x, y));
source.dispose();
return new Image(Display.getCurrent(), resultData);
}
/**
* Draws the default border by invoking the relevant method in BorderPainter.
* <p>
* Overwrite this method if you desire another border style.
* @param gc The GC to use.
* @param rect The cell bounds. Note that this method returns the new cell bounds
* that exlude the border area.
* @param vBorderColor The vertical border color.
* @param hBorderColor The horizontal border color.
* @return Returns the new bounds of the cell that should be filled with content.
*/
protected Rectangle drawDefaultSolidCellLine(GC gc, Rectangle rect, Color vBorderColor, Color hBorderColor) {
return BorderPainter.drawDefaultSolidCellLine(gc, rect, vBorderColor, hBorderColor);
}
/**
* Paints a sign that a comment is present in the right upper corner!
* @param gc The GC to use when painting.
* @param rect The cell area where content should be added.
*/
protected final void drawCommentSign(GC gc, Rectangle rect) {
gc.setBackground(COLOR_COMMENTSIGN);
gc.fillPolygon(new int[] {rect.x+rect.width-4, rect.y+1,
rect.x+rect.width-1, rect.y+1,
rect.x+rect.width-1, rect.y+4});
}
/**
* Sets the alignment of the cell content.
* @param style The OR-ed alignment constants for
* vertical and horizontal alignment as defined in
* SWTX.
* @see SWTX#ALIGN_HORIZONTAL_CENTER
* @see SWTX#ALIGN_HORIZONTAL_LEFT
* @see SWTX#ALIGN_HORIZONTAL_RIGHT
* @see SWTX#ALIGN_VERTICAL_CENTER
* @see SWTX#ALIGN_VERTICAL_TOP
* @see SWTX#ALIGN_VERTICAL_BOTTOM
*/
public void setAlignment(int style) {
m_alignment = style;
}
/**
* @return Returns the alignment for the cell content. 2 or-ed
* constants, one for horizontal, one for vertical alignment.
* @see SWTX#ALIGN_HORIZONTAL_CENTER
* @see SWTX#ALIGN_HORIZONTAL_LEFT
* @see SWTX#ALIGN_HORIZONTAL_RIGHT
* @see SWTX#ALIGN_VERTICAL_CENTER
* @see SWTX#ALIGN_VERTICAL_TOP
* @see SWTX#ALIGN_VERTICAL_BOTTOM
*/
public int getAlignment() {
return m_alignment;
}
/**
* Set the foreground color used to paint text et al.
* @param fgcolor The color or <code>null</code> to
* reset to default (black). Note that also the default color can be set using <code>setDefaultForeground(Color)</code>
* @see #setDefaultForeground(Color)
*/
public void setForeground(Color fgcolor) {
m_fgColor=fgcolor;
}
/**
* Changes the default foreground color that will be used
* when no other foreground color is set.
* (for example when <code>setForeground(null)</code> is called)
* @param fgcolor The foreground color to use.
* @see #setForeground(Color)
*/
public void setDefaultForeground(Color fgcolor) {
COLOR_TEXT = fgcolor;
}
/**
* Set the background color that should be used when
* painting the cell background.<p>
* If the <code>null</code> value is given, the default
* color will be used. The default color is settable using
* <code>setDefaultBacktround(Color)</code>
* @param bgcolor The color or <code>null</code> to
* reset to default.
* @see #setDefaultBackground(Color)
*/
public void setBackground(Color bgcolor) {
m_bgColor=bgcolor;
}
/**
* Changes the default background color that will be used when
* no background color is set via setBackground().
* @param bgcolor The color for the background.
* @see #setBackground(Color)
*/
public void setDefaultBackground(Color bgcolor) {
COLOR_BACKGROUND = bgcolor;
}
/**
* @return returns the currently set foreground color.
* If none was set, the default value is returned.
*/
public Color getForeground() {
if (m_fgColor!=null)
return m_fgColor;
return COLOR_TEXT;
}
/**
* @return returns the currently set background color.
* If none was set, the default value is returned.
*/
public Color getBackground() {
if (m_bgColor!=null)
return m_bgColor;
return COLOR_BACKGROUND;
}
/**
* Sets the font the renderer will use for drawing
* its content.
* @param font The font to use. Be aware that
* you must dispose fonts you have created.
*/
public void setFont(Font font) {
m_font = font;
}
/**
* @return Returns the font the renderer will
* use to draw the content.
*/
public Font getFont() {
return m_font;
}
/**
* Applies the font style of the renderer to the
* gc that will draw the content.<p>
* <b>To be called by implementors</b>
* @param gc The gc that will draw the
* renderers content.
*/
protected void applyFont(GC gc) {
m_GCfont = gc.getFont();
if (m_font == null)
m_font = Display.getCurrent().getSystemFont();
if ((m_Style & SWT.BOLD) != 0 || (m_Style & SWT.ITALIC)!=0) {
FontData[] fd = m_font.getFontData();
int style = SWT.NONE;
if ((m_Style & SWT.BOLD)!=0)
style |= SWT.BOLD;
if ((m_Style & SWT.ITALIC)!=0)
style |= SWT.ITALIC;
for (int i=0; i<fd.length; i++)
fd[i].setStyle(style);
m_TMPfont = new Font(Display.getCurrent(), fd);
gc.setFont(m_TMPfont);
} else
gc.setFont(m_font);
}
/**
* Resets the given GC's font parameters to the
* original state.
* @param gc The gc to draw with.
*/
protected void resetFont(GC gc) {
if (m_TMPfont!=null) {
m_TMPfont.dispose();
m_TMPfont = null;
}
gc.setFont(m_GCfont);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -