packagedev.equo;importorg.eclipse.swt.SWT;importorg.eclipse.swt.custom.StyleRange;importorg.eclipse.swt.custom.StyledText;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;/** * Demonstrates basic text styling with SWT StyledText widget. * This example shows how to apply different text styles to different portions of text: * - Bold formatting for the first 10 characters * - Red foreground color for the middle section * - Blue background color for the last section * Each style range is applied using StyleRange objects with specific start positions and lengths. */publicclassStyledTextSnippet1{publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("StyledText Snippet 1");shell.setLayout(newFillLayout());StyledTexttext=newStyledText(shell,SWT.BORDER);text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");StyleRangestyle1=newStyleRange();style1.start=0;style1.length=10;style1.fontStyle=SWT.BOLD;text.setStyleRange(style1);StyleRangestyle2=newStyleRange();style2.start=11;style2.length=13;style2.foreground=display.getSystemColor(SWT.COLOR_RED);text.setStyleRange(style2);StyleRangestyle3=newStyleRange();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();}}
packagedev.equo;importorg.eclipse.swt.SWT;importorg.eclipse.swt.custom.StyledText;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;/** * Demonstrates text paragraph formatting with SWT StyledText widget. * This example shows different paragraph-level formatting options: * - First paragraph: 50-pixel indentation from the left margin * - Second paragraph: Center alignment * - Third paragraph: Justified text alignment (text aligned to both margins) * The text content explains each formatting feature while demonstrating it visually. */publicclassStyledTextSnippet2{staticStringtext="The first paragraph has an indentation of fifty pixels. Indentation is the amount of white space in front of the first line of a paragraph.\n\n"+"The second paragraph is center aligned. Alignment, as with all other line attributes, can be set for the whole widget or just for a set of lines.\n\n"+"The third paragraph is justified, which means the text is aligned to both the left and right margins. This creates a uniform appearance by evenly distributing spaces between words.";publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("StyledText Snippet 2");shell.setLayout(newFillLayout());StyledTextstyledText=newStyledText(shell,SWT.WRAP|SWT.BORDER);styledText.setText(text);styledText.setLineIndent(0,1,50);styledText.setLineAlignment(2,1,SWT.CENTER);styledText.setLineJustify(4,1,true);shell.setSize(300,400);shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();}}
packagedev.equo;importorg.eclipse.swt.SWT;importorg.eclipse.swt.custom.StyleRange;importorg.eclipse.swt.custom.StyledText;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;/** * Combines character-level styling with paragraph-level formatting in SWT StyledText. * This example demonstrates both types of formatting applied together: * Character-level styling: * - First paragraph: Bold font style applied to specific text range * - Second paragraph: Red foreground color applied to specific text range * - Third paragraph: Blue background color applied to specific text range * Paragraph-level formatting: * - First paragraph: 50-pixel left indentation * - Second paragraph: Center alignment * - Third paragraph: Justified alignment */publicclassStyledTextSnippet3{staticStringtext="This paragraph has an indentation of fifty pixels and bold font style applied.\n\n"+"This paragraph is center aligned and has red foreground color.\n\n"+"This paragraph is justified and has blue background color.";publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("StyledText Snippet 3");shell.setLayout(newFillLayout());StyledTextstyledText=newStyledText(shell,SWT.WRAP|SWT.BORDER);styledText.setText(text);// Primer párrafo: negritaStyleRangestyle1=newStyleRange();style1.start=0;style1.length=78;style1.fontStyle=SWT.BOLD;styledText.setStyleRange(style1);// Segundo párrafo: color rojoStyleRangestyle2=newStyleRange();style2.start=80;style2.length=62;style2.foreground=display.getSystemColor(SWT.COLOR_RED);styledText.setStyleRange(style2);// Tercer párrafo: fondo azulStyleRangestyle3=newStyleRange();style3.start=144;style3.length=58;style3.background=display.getSystemColor(SWT.COLOR_BLUE);styledText.setStyleRange(style3);styledText.setLineIndent(0,1,50);styledText.setLineAlignment(2,1,SWT.CENTER);styledText.setLineJustify(4,1,true);shell.setSize(300,400);shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();}}
packagedev.equo;importorg.eclipse.swt.SWT;importorg.eclipse.swt.custom.StyleRange;importorg.eclipse.swt.custom.StyledText;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;/** * Demonstrates an editable StyledText widget with user interaction capabilities. * This example shows: * - A StyledText widget that allows user input and text editing * - Bold formatting applied to the entire initial text content * - Interactive text editing where users can click anywhere to position the caret * - Full editing capabilities including typing, deleting, and modifying text * The text content explains its own interactive features to guide user interaction. */publicclassStyledTextSnippet4{publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("StyledText Snippet 4");shell.setLayout(newFillLayout());StyledTexttext=newStyledText(shell,SWT.BORDER);text.setText("This text is editable. You may click at any part of it to change caret location and start modifying its content");StyleRangestyle1=newStyleRange();style1.start=0;style1.length=text.getCharCount();style1.fontStyle=SWT.BOLD;text.setStyleRange(style1);shell.setSize(500,80);shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();}}
packagedev.equo;importorg.eclipse.swt.SWT;importorg.eclipse.swt.custom.StyleRange;importorg.eclipse.swt.custom.StyledText;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;/** * Demonstrates a read-only StyledText widget that prevents user editing. * This example shows: * - A StyledText widget with editing disabled using setEditable(false) * - Bold formatting applied to the entire text content * - Text content that explains its read-only nature * - Users can still select text and navigate with the cursor, but cannot modify the content * Useful for displaying formatted text that should not be editable, like help text or status messages. */publicclassStyledTextSnippet5{publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("StyledText Snippet 5");shell.setLayout(newFillLayout());StyledTexttext=newStyledText(shell,SWT.BORDER);text.setText("This text is not editable, which means you can't modify its content");StyleRangestyle1=newStyleRange();style1.start=0;style1.length=text.getCharCount();style1.fontStyle=SWT.BOLD;text.setStyleRange(style1);text.setEditable(false);shell.pack();shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();}}