List of usage examples for org.eclipse.swt.graphics FontData getName
public String getName()
From source file:PathTextFrom.java
public static void main(String[] args) { Display display = new Display(); FontData data = display.getSystemFont().getFontData()[0]; Font font = new Font(display, data.getName(), 96, SWT.BOLD | SWT.ITALIC); final Color green = display.getSystemColor(SWT.COLOR_GREEN); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); final Path path = new Path(display); path.addString("SWT", 0, 0, font); Shell shell = new Shell(display); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { GC gc = e.gc;//from w w w . j a v a 2 s . co m gc.setBackground(green); gc.setForeground(blue); gc.fillPath(path); gc.drawPath(path); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } path.dispose(); font.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet198.java
public static void main(String[] args) { Display display = new Display(); FontData data = display.getSystemFont().getFontData()[0]; Font font = new Font(display, data.getName(), 96, SWT.BOLD | SWT.ITALIC); final Color green = display.getSystemColor(SWT.COLOR_GREEN); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); final Path path; try {/*from w w w. jav a2s . c o m*/ path = new Path(display); path.addString("SWT", 0, 0, font); } catch (SWTException e) { //Advanced Graphics not supported. //This new API requires the Cairo Vector engine on GTK and GDI+ on Windows. System.out.println(e.getMessage()); display.dispose(); return; } Shell shell = new Shell(display); shell.setText("Snippet 198"); shell.addListener(SWT.Paint, e -> { GC gc = e.gc; gc.setBackground(green); gc.setForeground(blue); gc.fillPath(path); gc.drawPath(path); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } path.dispose(); font.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet10.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Advanced Graphics"); FontData fd = shell.getFont().getFontData()[0]; final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC); final Image image = new Image(display, 640, 480); final Rectangle rect = image.getBounds(); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillOval(rect.x, rect.y, rect.width, rect.height); gc.dispose();// w w w. ja v a 2 s . c o m shell.addListener(SWT.Paint, event -> { GC gc1 = event.gc; Transform tr = new Transform(display); tr.translate(50, 120); tr.rotate(-30); gc1.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2); gc1.setAlpha(100); gc1.setTransform(tr); Path path = new Path(display); path.addString("SWT", 0, 0, font); gc1.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); gc1.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc1.fillPath(path); gc1.drawPath(path); tr.dispose(); path.dispose(); }); shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); font.dispose(); display.dispose(); }
From source file:AlphaBlending.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); FontData fd = shell.getFont().getFontData()[0]; final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC); final Image image = new Image(display, 640, 480); final Rectangle rect = image.getBounds(); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillOval(rect.x, rect.y, rect.width, rect.height); gc.dispose();/*from ww w . j a v a2s . co m*/ shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { GC gc = event.gc; gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2); gc.setAlpha(100); Path path = new Path(display); path.addString("SWT", 0, 0, font); gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.fillPath(path); gc.drawPath(path); path.dispose(); } }); shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); font.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet218.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 218"); shell.setLayout(new FillLayout()); final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); styledText.setText(text);/*from w ww .j a v a2s . com*/ FontData data = display.getSystemFont().getFontData()[0]; Font font = new Font(display, data.getName(), 16, SWT.BOLD); styledText.setFont(font); styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); styledText.addListener(SWT.Resize, event -> { Rectangle rect = styledText.getClientArea(); Image newImage = new Image(display, 1, Math.max(1, rect.height)); GC gc = new GC(newImage); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true); gc.dispose(); styledText.setBackgroundImage(newImage); if (oldImage != null) oldImage.dispose(); oldImage = newImage; }); shell.setSize(700, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (oldImage != null) oldImage.dispose(); font.dispose(); display.dispose(); }
From source file:TransformationDrawing.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); FontData fd = shell.getFont().getFontData()[0]; final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC); final Image image = new Image(display, 640, 480); final Rectangle rect = image.getBounds(); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillOval(rect.x, rect.y, rect.width, rect.height); gc.dispose();//from w ww . j av a 2s. c o m shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { GC gc = event.gc; Transform tr = new Transform(display); tr.translate(50, 120); tr.rotate(-30); gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2); gc.setAlpha(100); gc.setTransform(tr); Path path = new Path(display); path.addString("SWT", 0, 0, font); gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.fillPath(path); gc.drawPath(path); tr.dispose(); path.dispose(); } }); shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); font.dispose(); display.dispose(); }
From source file:StyledTextGradientBackground.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); styledText.setText(text);//from ww w . j a v a2s. co m FontData data = display.getSystemFont().getFontData()[0]; Font font = new Font(display, data.getName(), 16, SWT.BOLD); styledText.setFont(font); styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); styledText.addListener(SWT.Resize, new Listener() { public void handleEvent(Event event) { Rectangle rect = styledText.getClientArea(); Image newImage = new Image(display, 1, Math.max(1, rect.height)); GC gc = new GC(newImage); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true); gc.dispose(); styledText.setBackgroundImage(newImage); if (oldImage != null) oldImage.dispose(); oldImage = newImage; } }); shell.setSize(700, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (oldImage != null) oldImage.dispose(); font.dispose(); display.dispose(); }
From source file:StyledTextStyleRangeFont.java
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);// ww w . j a v a2 s . co m 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(); }
From source file:org.eclipse.swt.snippets.Snippet211.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 211"); shell.setLayout(new FillLayout()); StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); styledText.setText(text);//from w w w .j av a2s. c o m 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(); }
From source file:org.eclipse.swt.snippets.Snippet204.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); shell.setText("Modify Rise"); FontData data = display.getSystemFont().getFontData()[0]; Font font = new Font(display, data.getName(), 24, SWT.NORMAL); Font smallFont = new Font(display, data.getName(), 8, SWT.NORMAL); GC gc = new GC(shell); gc.setFont(smallFont);//from w w w . ja va 2 s. c om FontMetrics smallMetrics = gc.getFontMetrics(); final int smallBaseline = smallMetrics.getAscent() + smallMetrics.getLeading(); gc.setFont(font); FontMetrics metrics = gc.getFontMetrics(); final int baseline = metrics.getAscent() + metrics.getLeading(); gc.dispose(); final TextLayout layout0 = new TextLayout(display); layout0.setText("SubscriptScriptSuperscript"); layout0.setFont(font); TextStyle subscript0 = new TextStyle(smallFont, null, null); TextStyle superscript0 = new TextStyle(smallFont, null, null); superscript0.rise = baseline - smallBaseline; layout0.setStyle(subscript0, 0, 8); layout0.setStyle(superscript0, 15, 25); final TextLayout layout1 = new TextLayout(display); layout1.setText("SubscriptScriptSuperscript"); layout1.setFont(font); TextStyle subscript1 = new TextStyle(smallFont, null, null); subscript1.rise = -smallBaseline; TextStyle superscript1 = new TextStyle(smallFont, null, null); superscript1.rise = baseline; layout1.setStyle(subscript1, 0, 8); layout1.setStyle(superscript1, 15, 25); shell.addListener(SWT.Paint, event -> { Display display1 = event.display; GC gc1 = event.gc; Rectangle rect0 = layout0.getBounds(); rect0.x += 10; rect0.y += 10; gc1.setBackground(display1.getSystemColor(SWT.COLOR_WHITE)); gc1.setForeground(display1.getSystemColor(SWT.COLOR_BLACK)); gc1.fillRectangle(rect0); layout0.draw(gc1, rect0.x, rect0.y); gc1.setForeground(display1.getSystemColor(SWT.COLOR_MAGENTA)); gc1.drawLine(rect0.x, rect0.y, rect0.x + rect0.width, rect0.y); gc1.drawLine(rect0.x, rect0.y + baseline, rect0.x + rect0.width, rect0.y + baseline); gc1.drawLine(rect0.x + rect0.width / 2, rect0.y, rect0.x + rect0.width / 2, rect0.y + rect0.height); Rectangle rect1 = layout1.getBounds(); rect1.x += 10; rect1.y += 20 + rect0.height; gc1.setBackground(display1.getSystemColor(SWT.COLOR_WHITE)); gc1.setForeground(display1.getSystemColor(SWT.COLOR_BLACK)); gc1.fillRectangle(rect1); layout1.draw(gc1, rect1.x, rect1.y); gc1.setForeground(display1.getSystemColor(SWT.COLOR_MAGENTA)); gc1.drawLine(rect1.x, rect1.y + smallBaseline, rect1.x + rect1.width, rect1.y + smallBaseline); gc1.drawLine(rect1.x, rect1.y + baseline + smallBaseline, rect1.x + rect1.width, rect1.y + baseline + smallBaseline); gc1.drawLine(rect1.x + rect1.width / 2, rect1.y, rect1.x + rect1.width / 2, rect1.y + rect1.height); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } layout0.dispose(); layout1.dispose(); smallFont.dispose(); font.dispose(); display.dispose(); }