Beispiel #1
0
  public Main() {

    JPanel contentPane = new JPanel(new BorderLayout());
    RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
    textArea.setCodeFoldingEnabled(true);
    textArea.setAntiAliasingEnabled(true);
    contentPane.add(new RTextScrollPane(textArea));

    // A CompletionProvider is what knows of all possible completions, and
    // analyzes the contents of the text area at the caret position to
    // determine what completion choices should be presented. Most
    // instances of CompletionProvider (such as DefaultCompletionProvider)
    // are designed so that they can be shared among multiple text
    // components.
    CompletionProvider provider = createCompletionProvider();

    // An AutoCompletion acts as a "middle-man" between a text component
    // and a CompletionProvider. It manages any options associated with
    // the auto-completion (the popup trigger key, whether to display a
    // documentation window along with completion choices, etc.). Unlike
    // CompletionProviders, instances of AutoCompletion cannot be shared
    // among multiple text components.
    AutoCompletion ac = new AutoCompletion(provider);
    ac.install(textArea);

    setContentPane(contentPane);
    setTitle("AutoComplete Demo");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
  }
Beispiel #2
0
 /** Construit un panneau d'édition. */
 public TextEditor() {
   setLayout(new BorderLayout());
   // Creation de la barre de commande
   {
     toolBar = new ToolBar();
     add(toolBar, BorderLayout.NORTH);
   }
   // Creation de la zone d'édition
   {
     textArea = new RSyntaxTextArea(25, 70);
     textArea.setCaretPosition(0);
     textArea.requestFocusInWindow();
     textArea.setMarkOccurrences(true);
     textArea.setText("");
     scrollPane = new RTextScrollPane(textArea, true);
     Gutter gutter = scrollPane.getGutter();
     gutter.setBorderColor(Color.BLUE);
     add(scrollPane, BorderLayout.CENTER);
   }
   // Définition du mécanisme de complétion
   {
     completionsProvider = new DefaultCompletionProvider();
     LanguageAwareCompletionProvider lacp =
         new LanguageAwareCompletionProvider(completionsProvider);
     AutoCompletion ac =
         new AutoCompletion(lacp) {
           @Override
           public void doCompletion() {
             if (isAutoCompleteEnabled()) {
               super.doCompletion();
             }
           }
         };
     ac.install(textArea);
     ac.setAutoCompleteSingleChoices(false);
     ac.setAutoActivationEnabled(true);
     ac.setAutoActivationDelay(1500);
     ac.setShowDescWindow(true);
   }
   // Ajout de l'aide à l'édition
   {
     JPopupMenu j = toolBar.addRightTool("Aide");
     j.add(new JLabel("<html>\n<b>Commandes d'édition</b><br><table>\n" + helpText + "</table>"));
   }
 }