本文整理汇总了Java中org.eclipse.draw2d.Graphics.setFont方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.setFont方法的具体用法?Java Graphics.setFont怎么用?Java Graphics.setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.draw2d.Graphics
的用法示例。
在下文中一共展示了Graphics.setFont方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawHorizontalTitleBar
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* rect는 타이틀 바를 그릴 사각형이다. 여기서는 이 사각형에 타이틀 바를 그린다.
* 타이틀 바를 가로로 생성한 파티션의 왼쪽에 세로로 그린다.
*
* @param figure
* @param g
* @param rect
* void
*/
private void drawHorizontalTitleBar(IFigure figure, Graphics g, Rectangle rect) {
g.setBackgroundColor(getBackgroundColor());
g.fillRectangle(rect);
Insets padding = getPadding();
int x = rect.x + padding.left;
int y = rect.y + padding.top + (rect.height - getTextExtents(figure).height) / 2;
int textWidth = getTextExtents(figure).width;
int freeSpace = rect.width - padding.getWidth() - textWidth;
if (getTextAlignment() == PositionConstants.CENTER)
freeSpace /= 2;
if (getTextAlignment() != PositionConstants.LEFT)
x += freeSpace;
Font f = getFont(figure);
FontData fData = f.getFontData()[0];
fData.setName(this.getFontName());
fData.setStyle(this.getTextStyle());
fData.setHeight(this.getFontSize());
g.setFont(f);
g.setForegroundColor(this.getTextColor());
g.drawString(getLabel(), x, y);
}
示例2: drawTitleBar
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* rect는 타이틀 바를 그릴 사각형이다. 여기서는 이 사각형에 타이틀 바를 그린다.
*
* @param figure
* @param g
* @param rect
* void
*/
private void drawTitleBar(IFigure figure, Graphics g, Rectangle rect) {
g.setBackgroundColor(getBackgroundColor());
g.fillRectangle(rect);
Insets padding = getPadding();
int x = rect.x + padding.left;
int y = rect.y + padding.top + (rect.height - getTextExtents(figure).height) / 2;
int textWidth = getTextExtents(figure).width;
int freeSpace = rect.width - padding.getWidth() - textWidth;
if (getTextAlignment() == PositionConstants.CENTER)
freeSpace /= 2;
if (getTextAlignment() != PositionConstants.LEFT)
x += freeSpace;
Font f = getFont(figure);
FontData fData = f.getFontData()[0];
fData.setName(this.getFontName());
fData.setStyle(this.getTextStyle());
fData.setHeight(this.getFontSize());
g.setFont(f);
g.setForegroundColor(this.getTextColor());
g.drawString(getLabel(), x, y);
}
示例3: draw
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
@Override
public void draw(TextAttribute textAttr, Graphics graphics, ResourceManager resourceManager) {
Color fgColor = graphics.getForegroundColor();
java.awt.Color color = textAttr.textColor.asColor();
if (color != null) {
Color rgb = resourceManager.createColor(new RGB(color.getRed(), color.getGreen(), color.getBlue()));
graphics.setForegroundColor(rgb);
}
try {
String text = textAttr.text.getExpression();
int fontSize = ((IntToken) textAttr.textSize.getToken()).intValue();
String fontFamily = textAttr.fontFamily.stringValue();
boolean italic = ((BooleanToken) textAttr.italic.getToken()).booleanValue();
boolean bold = ((BooleanToken) textAttr.bold.getToken()).booleanValue();
int style = SWT.NORMAL | (italic ? SWT.ITALIC : SWT.NORMAL) | (bold ? SWT.BOLD : SWT.NORMAL);
Font f = resourceManager.createFont(FontDescriptor.createFrom(fontFamily, fontSize, style));
graphics.setFont(f);
Point tlp = getTopLeftLocation(textAttr);
graphics.drawText(text, tlp);
} catch (IllegalActionException e) {
LOGGER.error("Error reading properties for " + textAttr.getFullName(), e);
}
graphics.setForegroundColor(fgColor);
}
示例4: drawYTick
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* Draw the Y tick.
*
* @param grahpics
* the graphics context
*/
private void drawYTick(Graphics grahpics) {
// draw tick labels
grahpics.setFont(scale.getFont());
int fontHeight = tickLabelMaxHeight;
for (int i = 0; i < tickLabelPositions.size(); i++) {
if (tickVisibilities.size() == 0 || tickLabels.size() == 0) {
break;
}
if (tickVisibilities.get(i) == true) {
String text = tickLabels.get(i);
int x = 0;
if (tickLabels.get(0).startsWith("-") && !text.startsWith("-")) {
x += FigureUtilities.getTextExtents("-", getFont()).width;
}
int y = (int) Math.ceil(scale.getLength() - tickLabelPositions.get(i)
- fontHeight / 2.0);
grahpics.drawText(text, x, y);
}
}
}
示例5: setupPrinterGraphicsFor
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void setupPrinterGraphicsFor(final Graphics graphics, final IFigure figure) {
final ERDiagram diagram = getDiagram();
final PageSetting pageSetting = diagram.getPageSetting();
final double dpiScale = (double) getPrinter().getDPI().x / Display.getCurrent().getDPI().x * pageSetting.getScale() / 100;
final Rectangle printRegion = getPrintRegion();
// put the print region in display coordinates
printRegion.width /= dpiScale;
printRegion.height /= dpiScale;
final Rectangle bounds = figure.getBounds();
final double xScale = (double) printRegion.width / bounds.width;
final double yScale = (double) printRegion.height / bounds.height;
switch (getPrintMode()) {
case FIT_PAGE:
graphics.scale(Math.min(xScale, yScale) * dpiScale);
break;
case FIT_WIDTH:
graphics.scale(xScale * dpiScale);
break;
case FIT_HEIGHT:
graphics.scale(yScale * dpiScale);
break;
default:
graphics.scale(dpiScale);
}
graphics.setForegroundColor(figure.getForegroundColor());
graphics.setBackgroundColor(figure.getBackgroundColor());
graphics.setFont(figure.getFont());
}
示例6: setupPrinterGraphicsFor
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void setupPrinterGraphicsFor(Graphics graphics, IFigure figure) {
ERDiagram diagram = this.getDiagram();
PageSetting pageSetting = diagram.getPageSetting();
double dpiScale = (double) getPrinter().getDPI().x
/ Display.getCurrent().getDPI().x * pageSetting.getScale()
/ 100;
Rectangle printRegion = getPrintRegion();
// put the print region in display coordinates
printRegion.width /= dpiScale;
printRegion.height /= dpiScale;
Rectangle bounds = figure.getBounds();
double xScale = (double) printRegion.width / bounds.width;
double yScale = (double) printRegion.height / bounds.height;
switch (getPrintMode()) {
case FIT_PAGE:
graphics.scale(Math.min(xScale, yScale) * dpiScale);
break;
case FIT_WIDTH:
graphics.scale(xScale * dpiScale);
break;
case FIT_HEIGHT:
graphics.scale(yScale * dpiScale);
break;
default:
graphics.scale(dpiScale);
}
graphics.setForegroundColor(figure.getForegroundColor());
graphics.setBackgroundColor(figure.getBackgroundColor());
graphics.setFont(figure.getFont());
}
示例7: paintTitaniumFigure
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
@Override
protected void paintTitaniumFigure(Graphics graphics) {
titleFont = createTitleFont();
graphics.pushState();
graphics.setFont(titleFont);
paintTitle(graphics);
graphics.popState();
paintLines(graphics, getLines(), getLinesHolderRectangle());
Rectangle expRect = getTextHolderRectangle();
if (explanation != null && explanation.length() > 0){
int titleHeight = getMargin()*2;
if (getText() != null && getText().length() > 0){
titleHeight += FigureUtilities.getStringExtents(getText(), titleFont).height;
}
expRect.height -= titleHeight;
expRect.y += titleHeight;
paintString(graphics, explanation, expRect);
}
if (okButton.getText() != null){
graphics.setFont(okButton.getFont_());
Dimension p = FigureUtilities.getStringExtents(okButton.getText(), okButton.getFont_());
p.expand(20, 4);
p.width = Math.min(p.width, expRect.width);
p.height = 40;
okButton.setBounds(new Rectangle(expRect.getBottomLeft().getTranslated(
(expRect.width - p.width) / 2, -2 - p.height), p));
okButton.paint(graphics);
}
titleFont.dispose();
}
示例8: setupPrinterGraphicsFor
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* @see org.eclipse.draw2d.PrintFigureOperation#setupPrinterGraphicsFor(org.eclipse.draw2d.Graphics, org.eclipse.draw2d.IFigure)
*/
protected void setupPrinterGraphicsFor(Graphics graphics, IFigure figure) {
double dpiScale = (double)getPrinter().getDPI().x / Display.getCurrent().getDPI().x;
Rectangle printRegion = getPrintRegion();
// put the print region in display coordinates
printRegion.width /= dpiScale;
printRegion.height /= dpiScale;
// Rectangle bounds = figure.getBounds();
double xScale = (double)printRegion.width / previewBounds.width;
double yScale = (double)printRegion.height / previewBounds.height;
switch (getPrintMode()) {
case FIT_PAGE:
graphics.scale(Math.min(xScale, yScale) * dpiScale);
break;
case FIT_WIDTH:
graphics.scale(xScale * dpiScale);
break;
case FIT_HEIGHT:
graphics.scale(yScale * dpiScale);
break;
default:
graphics.scale(dpiScale);
}
graphics.setForegroundColor(figure.getForegroundColor());
graphics.setBackgroundColor(figure.getBackgroundColor());
graphics.setFont(figure.getFont());
}
示例9: paint
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* Paints this figure, including its border and children. Border is painted
* first.
*/
public void paint(Graphics graphics) {
paintBorder(graphics);
if (getBackgroundColor() != null)
graphics.setBackgroundColor(getBackgroundColor());
if (getForegroundColor() != null)
graphics.setForegroundColor(getForegroundColor());
if (getFont() != null)
graphics.setFont(getFont());
paintFigure(graphics);
paintClientArea(graphics);
}
示例10: paintText
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
@Override
protected void paintText(Graphics g, String draw, int x, int y, int bidiLevel) {
if (ranges.length == 0) {
draw = replaceTabs(draw);
super.paintText(g, draw, x, y, bidiLevel);
return;
}
if (bidiLevel == -1) {
String originalDraw = draw;
int paintOffset = 0;
int lineOffset = getText().indexOf(originalDraw);
try {
g.pushState();
g.setFont(getFont());
for (StyleRange range : ranges) {
int beginIndex = range.start - lineOffset;
if (beginIndex > draw.length()) {
break;
}
Font font = SWT.BOLD == (range.fontStyle & SWT.BOLD) ? boldFont : getFont();
if (font != g.getFont()) {
g.setFont(font);
}
g.setForegroundColor(range.foreground != null ? range.foreground : getForegroundColor());
g.setBackgroundColor(range.background != null ? range.background : getBackgroundColor());
int endIndex = beginIndex + range.length;
String substring = draw.substring(beginIndex > 0 ? beginIndex : 0,
Math.min(endIndex > 0 ? endIndex : 0, draw.length()));
substring = replaceTabs(substring);
g.drawText(substring, x + paintOffset, y);
int offset = getTextExtend(g.getFont(), substring);
paintOffset += offset;
}
} finally {
g.popState();
}
} else {
super.paintText(g, draw, x, y, bidiLevel);
}
}
示例11: drawXTick
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
/**
* Draw the X tick.
*
* @param grahics
* the graphics context
*/
private void drawXTick(Graphics grahics) {
// draw tick labels
grahics.setFont(scale.getFont());
for (int i = 0; i < tickLabelPositions.size(); i++) {
if (tickVisibilities.get(i) == true) {
String text = tickLabels.get(i);
int fontWidth = FigureUtilities.getTextExtents(text, getFont()).width;
int x = (int) Math.ceil(tickLabelPositions.get(i) - fontWidth / 2.0);// + offset);
grahics.drawText(text, x, 0);
}
}
}
示例12: setupPrinterGraphicsFor
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
@Override
protected void setupPrinterGraphicsFor(Graphics graphics, IFigure figure) {
final ERDiagram diagram = getDiagram();
final PageSettings pageSetting = diagram.getPageSetting();
final double dpiScale = (double) getPrinter().getDPI().x / Display.getCurrent().getDPI().x * pageSetting.getScale() / 100;
final Rectangle printRegion = getPrintRegion();
// put the print region in display coordinates
printRegion.width /= dpiScale;
printRegion.height /= dpiScale;
final Rectangle bounds = figure.getBounds();
final double xScale = (double) printRegion.width / bounds.width;
final double yScale = (double) printRegion.height / bounds.height;
switch (getPrintMode()) {
case FIT_PAGE:
graphics.scale(Math.min(xScale, yScale) * dpiScale);
break;
case FIT_WIDTH:
graphics.scale(xScale * dpiScale);
break;
case FIT_HEIGHT:
graphics.scale(yScale * dpiScale);
break;
default:
graphics.scale(dpiScale);
}
graphics.setForegroundColor(figure.getForegroundColor());
graphics.setBackgroundColor(figure.getBackgroundColor());
graphics.setFont(figure.getFont());
}
示例13: paintClientArea
import org.eclipse.draw2d.Graphics; //导入方法依赖的package包/类
@Override
protected void paintClientArea(final Graphics graphics) {
// Don't do anything when hidden
if (!isVisible())
return;
super.paintClientArea(graphics);
// graphics.pushState();
graphics.setFont(titleFont);
final Dimension titleSize = FigureUtilities.getTextExtents(title, titleFont);
if(isHorizontal()){
if(getTickLablesSide() == LabelSide.Primary)
graphics.drawText(title,
bounds.x + bounds.width/2 - titleSize.width/2,
bounds.y + bounds.height - titleSize.height);
else
graphics.drawText(title,
bounds.x + bounds.width/2 - titleSize.width/2,
bounds.y);
}else{
final int w = titleSize.height;
final int h = titleSize.width +1;
if(getTickLablesSide() == LabelSide.Primary){
GraphicsUtil.drawVerticalText(graphics, title,
bounds.x, bounds.y + bounds.height/2 - h/2, false);
}else {
GraphicsUtil.drawVerticalText(graphics, title,
bounds.x + bounds.width - w, bounds.y + bounds.height/2 - h/2, true);
}
}
// graphics.popState();
// Show the start/end cursor or the 'rubberband' of a zoom operation?
if(armed && end != null && start != null){
switch (zoomType) {
case RUBBERBAND_ZOOM:
case HORIZONTAL_ZOOM:
case VERTICAL_ZOOM:
graphics.setLineStyle(SWTConstants.LINE_DOT);
graphics.setLineWidth(1);
graphics.setForegroundColor(revertBackColor);
graphics.drawRectangle(start.x, start.y, end.x - start.x-1, end.y - start.y-1);
break;
default:
break;
}
}
}