List of usage examples for org.eclipse.swt.graphics FontData FontData
public FontData(String name, int height, int style)
From source file:FontRegistry.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(); shell.setLayout(new GridLayout(1, false)); FontRegistry fontRegistry = new FontRegistry(display); fontRegistry.put("button-text", new FontData[] { new FontData("Arial", 9, SWT.BOLD) }); fontRegistry.put("code", new FontData[] { new FontData("Courier New", 10, SWT.NORMAL) }); Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP); text.setFont(fontRegistry.get("code")); text.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); text.setText(""); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2;//from w w w.j a v a 2s .c o m text.setLayoutData(gd); Button executeButton = new Button(shell, SWT.PUSH); executeButton.setText("Execute"); executeButton.setFont(fontRegistry.get("button-text")); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FontDataConstruct.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Canvas Example"); shell.setLayout(new FillLayout()); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Font font = new Font(shell.getDisplay(), new FontData("Helvetica", 18, SWT.NORMAL)); e.gc.setFont(font);//from ww w. j a va 2 s. co m e.gc.drawText("My Text", 0, 0); font.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FontMetricsPaintSWT.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Canvas Example"); shell.setLayout(new FillLayout()); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Font font = new Font(shell.getDisplay(), new FontData("Helvetica", 18, SWT.NORMAL)); e.gc.setFont(font);/* w w w. ja v a 2 s . c om*/ e.gc.drawText("My Text", 0, 0); FontMetrics fm = e.gc.getFontMetrics(); int bHeight = fm.getLeading() + fm.getAscent(); int oHeight = fm.getAscent(); int yHeight = fm.getAscent() + fm.getDescent(); int totalHeight = fm.getHeight(); // Equals fm.getLeading() + fm.getAscent() // + fm.getDescent(); e.gc.drawLine(10, bHeight, 100, bHeight); e.gc.drawLine(10, oHeight, 100, oHeight); e.gc.drawLine(10, yHeight, 100, yHeight); e.gc.drawLine(10, totalHeight, 100, totalHeight); font.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell s = new Shell(d); s.setSize(300, 300);// w ww.j av a 2 s .co m s.setText("A FontDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Font"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell s = new Shell(d); s.setSize(300, 300);/*from ww w .j ava 2 s .c o m*/ s.setText("A ColorDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Color"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:FontDialogExample.java
FontDialogExample() { d = new Display(); s = new Shell(d); s.setSize(400, 400);//from w ww . ja v a 2 s . co m s.setText("A FontDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Font"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:FontRegistryExample.java
private void init() { shell.setLayout(new GridLayout(2, false)); fontRegistry = new FontRegistry(display); fontRegistry.put("button-text", new FontData[] { new FontData("Arial", 9, SWT.BOLD) }); fontRegistry.put("code", new FontData[] { new FontData("Courier New", 10, SWT.NORMAL) }); Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP); text.setFont(fontRegistry.get("code")); text.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); text.setText("public static void main() {\n\tSystem.out.println(\"Hello\"); \n}"); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2;/*from ww w.j a v a2s .c om*/ text.setLayoutData(gd); Button executeButton = new Button(shell, SWT.PUSH); executeButton.setText("Execute"); executeButton.setFont(fontRegistry.get("button-text")); Button cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.setFont(fontRegistry.get("button-text")); }
From source file:RegistryTest.java
/** * Creates the window's contents/*from www .j av a2 s . c o m*/ * * @param parent the parent composite * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new FillLayout(SWT.VERTICAL)); // Set up the registries CR = new ColorRegistry(); CR.addListener(this); FR = new FontRegistry(); FR.addListener(this); // Create the label label = new Label(composite, SWT.CENTER); label.setText("Hello from JFace"); // Create the randomize button Button button = new Button(composite, SWT.PUSH); button.setText("Randomize"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { CR.put(FOREGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); CR.put(BACKGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); FontData fontData = new FontData("Times New Roman", (int) (Math.random() * 72), SWT.BOLD); FR.put(FONT, new FontData[] { fontData }); } }); return composite; }