List of usage examples for org.eclipse.swt.widgets Display getSystemColor
@Override public Color getSystemColor(int id)
From source file:org.eclipse.swt.snippets.Snippet325.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 325"); shell.setLayout(new GridLayout()); shell.setText("StyledText: Variable tab stops"); Ruler ruler = new Ruler(shell, SWT.NONE); GridData data = new GridData(); data.heightHint = 10;/*w w w .ja va 2s .c om*/ data.horizontalAlignment = SWT.FILL; ruler.setLayoutData(data); ruler.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); StyledText styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); styledText.setText( "0\t1\t2\t3\t4\nDrag\tthe\ttab\tmarks\ton\ttop\tto\tchange\tthe\tposition\tof\tthe\ttab\tstops"); styledText.setTabStops(new int[] { 30, 70, 90, 140 }); styledText.setLayoutData(new GridData(GridData.FILL_BOTH)); ruler.setEditor(styledText); shell.setSize(800, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet328.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 328"); shell.setLayout(new GridLayout()); shell.setText("StyledText: Variable tab stops"); Ruler ruler = new Ruler(shell, SWT.NONE); GridData data = new GridData(); data.heightHint = 10;//from w w w .j a va 2s. c o m data.horizontalAlignment = SWT.FILL; ruler.setLayoutData(data); ruler.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); StyledText styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); styledText.setText( "0\t1\t2\t3\t4\nDrag\tthe\ttab\tmarks\ton\ttop\tto\tchange\tthe\tposition\tof\tthe\ttab\tstops"); styledText.setTabStops(new int[] { 30, 70, 90, 140 }); styledText.setLineTabStops(0, 1, new int[] { 10, 60, 80 }); styledText.setLineTabStops(1, 1, new int[] { 40, 70, 100, 150 }); styledText.setLayoutData(new GridData(GridData.FILL_BOTH)); ruler.setEditor(styledText); shell.setSize(800, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet163.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); StyledText text = new StyledText(shell, SWT.BORDER); text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); // make 0123456789 appear bold StyleRange style1 = new StyleRange(); style1.start = 0;/* w w w. ja v a 2s. co m*/ style1.length = 10; style1.fontStyle = SWT.BOLD; text.setStyleRange(style1); // make ABCDEFGHIJKLM have a red font StyleRange style2 = new StyleRange(); style2.start = 11; style2.length = 13; style2.foreground = display.getSystemColor(SWT.COLOR_RED); text.setStyleRange(style2); // make NOPQRSTUVWXYZ have a blue background StyleRange style3 = new StyleRange(); style3.start = 25; style3.length = 13; style3.background = display.getSystemColor(SWT.COLOR_BLUE); text.setStyleRange(style3); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet332.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 332"); GridLayout layout = new GridLayout(); layout.marginHeight = layout.marginWidth = 10; shell.setLayout(layout);/* ww w . jav a2 s .co m*/ StyledText text = new StyledText(shell, SWT.MULTI | SWT.BORDER); final String segment = "Eclipse"; String string = "Force RTL direction on this segment \"" + segment + "\"."; text.setText(string); int[] segments = { string.indexOf(segment), segment.length() }; StyleRange[] ranges = { new StyleRange(0, 0, display.getSystemColor(SWT.COLOR_RED), null) }; text.setStyleRanges(segments, ranges); Font font = new Font(display, "Tahoma", 16, 0); text.setFont(font); text.addBidiSegmentListener(event -> { String string1 = event.lineText; int start = string1.indexOf(segment); event.segments = new int[] { start, start + segment.length() }; event.segmentsChars = new char[] { '\u202e', '\u202C' }; }); Combo combo = new Combo(shell, SWT.SIMPLE); combo.setFont(font); combo.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); combo.setItems("Option 1...", "Option 2...", "Option 3...", "Option 4..."); combo.select(1); combo.addSegmentListener(event -> { event.segments = new int[] { 0, event.lineText.length() }; event.segmentsChars = new char[] { '\u202e', '\u202c' }; }); shell.setSize(500, 250); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } font.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet163.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 163"); shell.setLayout(new FillLayout()); StyledText text = new StyledText(shell, SWT.BORDER); text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); // make 0123456789 appear bold StyleRange style1 = new StyleRange(); style1.start = 0;// w w w . java2 s. co m style1.length = 10; style1.fontStyle = SWT.BOLD; text.setStyleRange(style1); // make ABCDEFGHIJKLM have a red font StyleRange style2 = new StyleRange(); style2.start = 11; style2.length = 13; style2.foreground = display.getSystemColor(SWT.COLOR_RED); text.setStyleRange(style2); // make NOPQRSTUVWXYZ have a blue background StyleRange style3 = new StyleRange(); style3.start = 25; style3.length = 13; style3.background = display.getSystemColor(SWT.COLOR_BLUE); text.setStyleRange(style3); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet236.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Table: Change style multiple times in cell"); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION); table.setLinesVisible(true);/* w ww .j ava 2 s .co m*/ for (int i = 0; i < 10; i++) { new TableItem(table, SWT.NONE); } final TextLayout textLayout = new TextLayout(display); textLayout.setText("SWT: Standard Widget Toolkit"); Font font1 = new Font(display, "Tahoma", 14, SWT.BOLD); Font font2 = new Font(display, "Tahoma", 10, SWT.NORMAL); Font font3 = new Font(display, "Tahoma", 14, SWT.ITALIC); TextStyle style1 = new TextStyle(font1, display.getSystemColor(SWT.COLOR_BLUE), null); TextStyle style2 = new TextStyle(font2, display.getSystemColor(SWT.COLOR_MAGENTA), null); TextStyle style3 = new TextStyle(font3, display.getSystemColor(SWT.COLOR_RED), null); textLayout.setStyle(style1, 0, 0); textLayout.setStyle(style1, 5, 12); textLayout.setStyle(style2, 1, 1); textLayout.setStyle(style2, 14, 19); textLayout.setStyle(style3, 2, 2); textLayout.setStyle(style3, 21, 27); /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be * as efficient as possible. */ table.addListener(SWT.PaintItem, event -> textLayout.draw(event.gc, event.x, event.y)); final Rectangle textLayoutBounds = textLayout.getBounds(); table.addListener(SWT.MeasureItem, e -> { e.width = textLayoutBounds.width + 2; e.height = textLayoutBounds.height + 2; }); shell.setSize(400, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } font1.dispose(); font2.dispose(); font3.dispose(); textLayout.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);//w ww. j av a2 s . 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:TableItemForegroundFont.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Table: Change style multiple times in cell"); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION); table.setLinesVisible(true);/*from ww w . jav a 2 s .co m*/ for (int i = 0; i < 10; i++) { new TableItem(table, SWT.NONE); } final TextLayout textLayout = new TextLayout(display); textLayout.setText("SWT: Standard Widget Toolkit"); Font font1 = new Font(display, "Tahoma", 14, SWT.BOLD); Font font2 = new Font(display, "Tahoma", 10, SWT.NORMAL); Font font3 = new Font(display, "Tahoma", 14, SWT.ITALIC); TextStyle style1 = new TextStyle(font1, display.getSystemColor(SWT.COLOR_BLUE), null); TextStyle style2 = new TextStyle(font2, display.getSystemColor(SWT.COLOR_MAGENTA), null); TextStyle style3 = new TextStyle(font3, display.getSystemColor(SWT.COLOR_RED), null); textLayout.setStyle(style1, 0, 0); textLayout.setStyle(style1, 5, 12); textLayout.setStyle(style2, 1, 1); textLayout.setStyle(style2, 14, 19); textLayout.setStyle(style3, 2, 2); textLayout.setStyle(style3, 21, 27); /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be as * efficient as possible. */ table.addListener(SWT.PaintItem, new Listener() { public void handleEvent(Event event) { textLayout.draw(event.gc, event.x, event.y); } }); final Rectangle textLayoutBounds = textLayout.getBounds(); table.addListener(SWT.MeasureItem, new Listener() { public void handleEvent(Event e) { e.width = textLayoutBounds.width + 2; e.height = textLayoutBounds.height + 2; } }); shell.setSize(400, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } font1.dispose(); font2.dispose(); font3.dispose(); textLayout.dispose(); display.dispose(); }
From source file:SyntaxColoring.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); final String PUNCTUATION = "(){}"; styledText.addExtendedModifyListener(new ExtendedModifyListener() { public void modifyText(ExtendedModifyEvent event) { int end = event.start + event.length - 1; if (event.start <= end) { String text = styledText.getText(event.start, end); java.util.List ranges = new java.util.ArrayList(); for (int i = 0, n = text.length(); i < n; i++) { if (PUNCTUATION.indexOf(text.charAt(i)) > -1) { ranges.add(new StyleRange(event.start + i, 1, display.getSystemColor(SWT.COLOR_BLUE), null, SWT.BOLD)); }/*w w w . java2 s. c o m*/ } if (!ranges.isEmpty()) { styledText.replaceStyleRanges(event.start, event.length, (StyleRange[]) ranges.toArray(new StyleRange[0])); } } } }); styledText.setBounds(10, 10, 500, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } 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 a v a2 s. c om*/ 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(); }