Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. package shared;
  2.  
  3. import java.awt.BorderLayout;
  4.  
  5. public class test {
  6.  
  7.     protected Shell shell;
  8.  
  9.     /**
  10.      * Launch the application.
  11.      * @param args
  12.      */
  13.     public static void main(String[] args) {
  14.         try {
  15.             test window = new test();
  16.             window.open();
  17.         } catch (Exception e) {
  18.             e.printStackTrace();
  19.         }
  20.     }
  21.  
  22.     /**
  23.      * Open the window.
  24.      */
  25.     public void open() {
  26.         Display display = Display.getDefault();
  27.         createContents();
  28.         shell.open();
  29.         shell.layout();
  30.         while (!shell.isDisposed()) {
  31.             if (!display.readAndDispatch()) {
  32.                 display.sleep();
  33.             }
  34.         }
  35.     }
  36.  
  37.     /**
  38.      * Create contents of the window.
  39.      */
  40.     protected void createContents() {
  41.         shell = new Shell();
  42.         shell.setSize(450, 300);
  43.         shell.setText("SWT Application");
  44.        
  45.         Composite composite = new Composite(shell, SWT.EMBEDDED | SWT.NO_BACKGROUND);
  46.         composite.setBounds(0, 0, 434, 262);
  47.         new ScriptEditor(composite, new File("aliases.js").toString());
  48.     }
  49.  
  50.     class ScriptEditor extends JPanel {
  51.  
  52.         private static final long serialVersionUID = 1L;
  53.  
  54.         RSyntaxTextArea textArea;
  55.  
  56.         public ScriptEditor(Composite parent, String s) {
  57.  
  58.             Frame frame = SWT_AWT.new_Frame(parent);
  59.  
  60.             SwingUtilities.invokeLater(new Runnable() {
  61.                 public void run() {
  62.                     try {
  63.                         String laf = UIManager.getSystemLookAndFeelClassName();
  64.                         UIManager.setLookAndFeel(laf);
  65.                     } catch (Exception e) {
  66.                     }
  67.                 }
  68.             });
  69.  
  70.             this.setLayout(new BorderLayout());
  71.             textArea = new RSyntaxTextArea();
  72.             textArea.setText(s);
  73.             // textArea.setLineWrap(true);
  74.             // textArea.setWrapStyleWord(true);
  75.             RTextScrollPane pane = new RTextScrollPane(textArea);
  76.             this.add(pane);
  77.  
  78.             textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
  79.  
  80.             JScrollPane scroll = new JScrollPane(this);
  81.             frame.add(scroll, BorderLayout.CENTER);
  82.         }
  83.  
  84.         public void changeSyntaxStyle(String s) {
  85.             // textArea.setSyntaxEditingStyle(determineScriptType(s));
  86.             CompletionProvider provider = createCompletionProvider();
  87.  
  88.             AutoCompletion ac = new AutoCompletion(provider);
  89.             ac.install(textArea);
  90.  
  91.         }
  92.  
  93.         private CompletionProvider createCompletionProvider() {
  94.             DefaultCompletionProvider provider = new DefaultCompletionProvider();
  95.             String[] keywords = { "cake" };
  96.             for (String keyword : keywords) {
  97.                 provider.addCompletion(new BasicCompletion(provider, keyword));
  98.             }
  99.             return provider;
  100.         }
  101.  
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement