本文整理汇总了Java中org.eclipse.swt.graphics.FontData.getStyle方法的典型用法代码示例。如果您正苦于以下问题:Java FontData.getStyle方法的具体用法?Java FontData.getStyle怎么用?Java FontData.getStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.FontData
的用法示例。
在下文中一共展示了FontData.getStyle方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFontChooser
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
private FontData getFontChooser(final Composite parent,String title,FontData fontData){
final FontData selection = new FontData(fontData.getName(),fontData.getHeight(),fontData.getStyle());
Label label = new Label(parent, SWT.NULL);
label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, true));
label.setText(title);
Button button = new Button(parent, SWT.PUSH);
button.setLayoutData(getAlignmentData(MINIMUM_CONTROL_WIDTH,SWT.FILL));
button.setText(TuxGuitar.getProperty("choose"));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
Font font = new Font(parent.getDisplay(),selection);
FontDialog fontDialog = new FontDialog(parent.getShell());
fontDialog.setFontList(font.getFontData());
FontData fd = fontDialog.open();
if(fd != null){
selection.setName( fd.getName() );
selection.setHeight( fd.getHeight() );
selection.setStyle( fd.getStyle() );
}
font.dispose();
}
});
return selection;
}
示例2: toAwtFont
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
/**
* Create an awt font by converting as much information
* as possible from the provided swt <code>FontData</code>.
* <p>Generally speaking, given a font size, an swt font will
* display differently on the screen than the corresponding awt
* one. Because the SWT toolkit use native graphical ressources whenever
* it is possible, this fact is platform dependent. To address
* this issue, it is possible to enforce the method to return
* an awt font with the same height as the swt one.
*
* @param device The swt device being drawn on (display or gc device).
* @param fontData The swt font to convert.
* @param ensureSameSize A boolean used to enforce the same size
* (in pixels) between the swt font and the newly created awt font.
* @return An awt font converted from the provided swt font.
*/
public static java.awt.Font toAwtFont(Device device, FontData fontData,
boolean ensureSameSize) {
int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
/ 72.0);
// hack to ensure the newly created awt fonts will be rendered with the
// same height as the swt one
if (ensureSameSize) {
GC tmpGC = new GC(device);
Font tmpFont = new Font(device, fontData);
tmpGC.setFont(tmpFont);
JPanel DUMMY_PANEL = new JPanel();
java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
fontData.getStyle(), height);
if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
> tmpGC.textExtent(Az).x) {
while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
> tmpGC.textExtent(Az).x) {
height--;
tmpAwtFont = new java.awt.Font(fontData.getName(),
fontData.getStyle(), height);
}
}
else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
< tmpGC.textExtent(Az).x) {
while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
< tmpGC.textExtent(Az).x) {
height++;
tmpAwtFont = new java.awt.Font(fontData.getName(),
fontData.getStyle(), height);
}
}
tmpFont.dispose();
tmpGC.dispose();
}
return new java.awt.Font(fontData.getName(), fontData.getStyle(),
height);
}
示例3: convertTopLevelFont
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
public static String convertTopLevelFont(String styles, FontData fontData) {
boolean bold = (fontData.getStyle() & SWT.BOLD) != 0;
boolean italic = (fontData.getStyle() & SWT.ITALIC) != 0;
String size = Integer.toString(fontData.getHeight()) + UNIT;
String family = "'" + fontData.getName() + "',sans-serif";
styles = styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-size:\\s*)\\d+pt(\\;?.*\\})", "$1" + size + "$2");
styles = styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-weight:\\s*)\\w+(\\;?.*\\})", "$1" + (bold ? "bold" : "normal") + "$2");
styles = styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-style:\\s*)\\w+(\\;?.*\\})", "$1" + (italic ? "italic" : "normal") + "$2");
styles = styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-family:\\s*).+?(;.*\\})", "$1" + family + "$2");
return styles;
}
示例4: getModifiedFontData
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
private static FontData[] getModifiedFontData(int style) {
FontData[] styleData = new FontData[ArchitecturalLabelDecoratorBase.baseData.length];
for (int i = 0; i < styleData.length; i++) {
FontData base = ArchitecturalLabelDecoratorBase.baseData[i];
styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | style);
}
return styleData;
}
示例5: getTransformedFont
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
/**
* Deprecated since SWT now handles this.
*
* @deprecated
* @return font that's been transformed by the current transform
*/
protected org.eclipse.swt.graphics.Font getTransformedFont() {
if (curFont != null) {
final FontData fontData = curFont.getFontData()[0];
int height = fontData.getHeight();
TEMP_RECT.setRect(0, 0, height, height);
SWTShapeManager.transform(TEMP_RECT, transform);
height = (int) (TEMP_RECT.getHeight() + 0.5);
final String fontString = "name=" + fontData.getName() + ";bold=" + ((fontData.getStyle() & SWT.BOLD) != 0)
+ ";italic=" + ((fontData.getStyle() & SWT.ITALIC) != 0) + ";size=" + height;
return getFont(fontString);
}
return null;
}
示例6: toAwtFont
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
/**
* Create an awt font by converting as much information
* as possible from the provided swt <code>FontData</code>.
* <p>Generally speaking, given a font size, an swt font will
* display differently on the screen than the corresponding awt
* one. Because the SWT toolkit use native graphical ressources whenever
* it is possible, this fact is plateform dependent. To address
* this issue, it is possible to enforce the method to return
* an awt font with the same height as the swt one.
*
* @param device The swt device being drawn on (display or gc device).
* @param fontData The swt font to convert.
* @param ensureSameSize A boolean used to enforce the same size
* (in pixels) between the swt font and the newly created awt font.
* @return An awt font converted from the provided swt font.
*/
public static java.awt.Font toAwtFont(Device device, FontData fontData,
boolean ensureSameSize) {
int style;
switch (fontData.getStyle()) {
case SWT.NORMAL:
style = java.awt.Font.PLAIN;
break;
case SWT.ITALIC:
style = java.awt.Font.ITALIC;
break;
case SWT.BOLD:
style = java.awt.Font.BOLD;
break;
default:
style = java.awt.Font.PLAIN;
break;
}
int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
/ 72.0);
// hack to ensure the newly created awt fonts will be rendered with the
// same height as the swt one
if (ensureSameSize) {
GC tmpGC = new GC(device);
Font tmpFont = new Font(device, fontData);
tmpGC.setFont(tmpFont);
JPanel DUMMY_PANEL = new JPanel();
java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
style, height);
if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
> tmpGC.textExtent(Az).x) {
while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
> tmpGC.textExtent(Az).x) {
height--;
tmpAwtFont = new java.awt.Font(fontData.getName(), style,
height);
}
}
else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
< tmpGC.textExtent(Az).x) {
while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
< tmpGC.textExtent(Az).x) {
height++;
tmpAwtFont = new java.awt.Font(fontData.getName(), style,
height);
}
}
tmpFont.dispose();
tmpGC.dispose();
}
return new java.awt.Font(fontData.getName(), style, height);
}
示例7: hasStyle
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
private static boolean hasStyle(FontData fontData, int style) {
return (fontData.getStyle() & style) == style;
}
示例8: Styles
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
private Styles(Shell shell) {
Font font = shell.getDisplay().getSystemFont();
FontData fd = font.getFontData()[0];
fontStyle = new FontStyle(fd.getName(), fd.getHeight(), fd.getStyle());
}
示例9: print
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
public void print(){
if (printer.startJob("Text")) { // the string is the job name - shows up
try {// in the printer's job list
Rectangle clientArea = printer.getClientArea();
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
Point dpi = printer.getDPI();
leftMargin = dpi.x + trim.x; // one inch from left side of paper
rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one
// inch
// from
// right
// side
// of
// paper
topMargin = dpi.y + trim.y; // one inch from top edge of paper
bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one
// inch
// from
// bottom
// edge
// of
// paper
/* Create a buffer for computing tab width. */
int tabSize = 4; // is tab width a user setting in your UI?
StringBuilder tabBuffer = new StringBuilder(tabSize);
for (int i = 0; i < tabSize; i++)
tabBuffer.append(' ');
tabs = tabBuffer.toString();
/*
* Create printer GC, and create and set the printer font &
* foreground color.
*/
gc = new GC(printer);
font = printer.getSystemFont(); // ResourceUtils.getFont(Styles.getInstance().FONT_COURIER);
// foregroundColor = ResourceUtils.getColor(Styles.DARK_RGB_TEXT);
// backgroundColor =
// ResourceUtils.getColor(Styles.BACKGROUND_ENABLED);
FontData fontData = font.getFontData()[0];
printerFont = new Font(printer, fontData.getName(), fontData.getHeight(), fontData.getStyle());
gc.setFont(printerFont);
tabWidth = gc.stringExtent(tabs).x;
lineHeight = gc.getFontMetrics().getHeight();
// RGB rgb = foregroundColor.getRGB();
// printerForegroundColor = new Color(printer, rgb);
// gc.setForeground(printerForegroundColor);
// rgb = backgroundColor.getRGB();
// printerBackgroundColor = new Color(printer, rgb);
// gc.setBackground(printerBackgroundColor);
/* Print text to current gc using word wrap */
printText(printer);
printer.endJob();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
/* Cleanup graphics resources used in printing */
if (printerFont != null)
printerFont.dispose();
// if(printerForegroundColor != null)
// printerForegroundColor.dispose();
// if(printerBackgroundColor != null)
// printerBackgroundColor.dispose();
if (gc != null)
gc.dispose();
}
}
}
示例10: main
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
public static void main(String [] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
styledText.setText(text);
FontData data = styledText.getFont().getFontData()[0];
Font font1 = new Font(display, data.getName(), data.getHeight() * 2, data.getStyle());
Font font2 = new Font(display, data.getName(), data.getHeight() * 4 / 5, data.getStyle());
StyleRange[] styles = new StyleRange[8];
styles[0] = new StyleRange();
styles[0].font = font1;
styles[1] = new StyleRange();
styles[1].rise = data.getHeight() / 3;
styles[2] = new StyleRange();
styles[2].background = display.getSystemColor(SWT.COLOR_GREEN);
styles[3] = new StyleRange();
styles[3].foreground = display.getSystemColor(SWT.COLOR_MAGENTA);
styles[4] = new StyleRange();
styles[4].font = font2;
styles[4].foreground = display.getSystemColor(SWT.COLOR_BLUE);;
styles[4].underline = true;
styles[5] = new StyleRange();
styles[5].rise = -data.getHeight() / 3;
styles[5].strikeout = true;
styles[5].underline = true;
styles[6] = new StyleRange();
styles[6].font = font1;
styles[6].foreground = display.getSystemColor(SWT.COLOR_YELLOW);
styles[6].background = display.getSystemColor(SWT.COLOR_BLUE);
styles[7] = new StyleRange();
styles[7].rise = data.getHeight() / 3;
styles[7].underline = true;
styles[7].fontStyle = SWT.BOLD;
styles[7].foreground = display.getSystemColor(SWT.COLOR_RED);
styles[7].background = display.getSystemColor(SWT.COLOR_BLACK);
int[] ranges = new int[] {16, 4, 61, 13, 107, 10, 122, 10, 134, 3, 143, 6, 160, 7, 168, 7};
styledText.setStyleRanges(ranges, styles);
shell.setSize(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
font1.dispose();
font2.dispose();
display.dispose();
}
示例11: getSWTTextStyle
import org.eclipse.swt.graphics.FontData; //导入方法依赖的package包/类
/** Converts a TRP {@link TextStyleType} to an SWT {@link TextStyle} object
* @param tst The TextStyleType object to convert to an SWT TextStyle object. If null, a default TextStyle is created
* @param fd Font data currently set in the widget. If null, a default font is created.
* @param settings The trp settings from the main widget
*/
public static TextStyle getSWTTextStyle(TextStyleType tst, FontData fd, TrpSettings settings) {
TextStyle swtTs = new TextStyle();
if (tst == null) {
tst = new TextStyleType(); // if no TextStyleType given, create default
}
if (fd == null) fd = Display.getDefault().getSystemFont().getFontData()[0]; // if no font-data given, get default
// return default font if no TextStyleType given:
// if (tst == null) {
// FontData fdDefault = fd==null ? Display.getDefault().getSystemFont().getFontData()[0] : fd;
// swtTs.font = Fonts.createFont(fdDefault.getName(), fdDefault.getHeight(), fdDefault.getStyle());
// return swtTs;
// }
int height = fd==null ? DEFAULT_TEXT_HEIGHT : fd.getHeight();
if (tst.getFontSize()!=null && fd==null) {
height = tst.getFontSize().intValue();
}
String fontName="";
if (settings.isRenderFontStyles()) {
fontName = Fonts.getSystemFontName(Utils.val(tst.isSerif()), Utils.val(tst.isMonospace()), Utils.val(tst.isLetterSpaced()));
}
else {
fontName = fd.getName();
}
logger.trace("fontName = "+fontName);
int style = settings.isRenderTextStyles() ? Fonts.createStyle(Utils.val(tst.isBold()), Utils.val(tst.isItalic())) : fd.getStyle();
if (settings.isRenderOtherStyles()) {
swtTs.rise = Fonts.createRise(Utils.val(tst.isSubscript()), Utils.val(tst.isSuperscript()), height);
swtTs.underline = Utils.val(tst.isUnderlined());
swtTs.strikeout = Utils.val(tst.isStrikethrough());
}
swtTs.font = Fonts.createFont(fontName, height, style);
return swtTs;
}