private void jCmbLangsItemStateChanged(java.awt.event.ItemEvent evt) {
    if (evt.getStateChange() == ItemEvent.SELECTED) {
      String lang = jCmbLangs.getSelectedItem().toString();

      // save the state of the current JEditorPane, as it's Document is about
      // to be replaced.
      String oldText = jEditor.getText();

      // install a new DefaultSyntaxKit on the JEditorPane for the requested language.
      jEditor.setContentType(lang);
      // Recreate the Toolbar
      jToolBar1.removeAll();
      EditorKit kit = jEditor.getEditorKit();
      if (kit instanceof DefaultSyntaxKit) {
        DefaultSyntaxKit defaultSyntaxKit = (DefaultSyntaxKit) kit;
        defaultSyntaxKit.addToolBarActions(jEditor, jToolBar1);
      }
      jToolBar1.validate();
      try {
        // setText should not be called (read the JavaDocs).  Better use the read
        // method and create a new document.
        jEditor.read(new StringReader(oldText), lang);
      } catch (IOException ex) {
        Logger.getLogger(SyntaxTester.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    jEditor.requestFocusInWindow();
  }
示例#2
0
 // public ProtocolEditor() {
 public ProtocolEditor(String protocolClass) { // by urueda
   this.protocolClass = protocolClass;
   DefaultSyntaxKit.initKit();
   initComponents();
   codeEditor.setContentType("text/java");
   // codeEditor.setText(Util.readFile(new File("./CustomProtocol.java")));
   codeEditor.setText(Util.readFile(new File("./" + protocolClass + ".java"))); // by urueda
 }
  /** Creates new form Tester */
  public SyntaxPanel() {
    initComponents();
    jCmbLangs.setModel(new DefaultComboBoxModel(DefaultSyntaxKit.getContentTypes()));
    // jEditor.setContentType(jCmbLangs.getItemAt(0).toString());
    jCmbLangs.setSelectedItem("text/xml");
    // new CaretMonitor(jEditor, lblCaretPos);

  }
示例#4
0
  public void initJSyntaxPane() {
    DefaultSyntaxKit.initKit();
    Configuration conf = DefaultSyntaxKit.getConfig(DefaultSyntaxKit.class);

    // remove built-in undo/redo
    conf.remove("Action.undo");
    conf.remove("Action.redo");

    if (Program.PROGRAM_NAME == ProgramName.PLOTLET) {
      log.info("Register PlotletSyntaxKit");

      try {
        // IMPORTANT: The config-key "Action.combo-completion.Items" only accepts a
        // semikolon-separated string because we have changed the method:
        //            jsyntaxpane/actions/ComboCompletionAction.java#setItems(). Otherwise it would
        // only accept a real list
        String autocompletionList = PlotletSyntaxKit.createAutocompletionList(";");
        DefaultSyntaxKit.getConfig(PlotletSyntaxKit.class)
            .put("Action.combo-completion.Items", autocompletionList);
      } catch (Exception e) {
        log.error("Error at creating the autocompletion");
      }
      DefaultSyntaxKit.registerContentType(
          "text/propertypanel", PlotletSyntaxKit.class.getCanonicalName());
    } else {
      log.info("Register UmletSyntaxKit");

      // removes the line numbering
      conf.remove("Components");

      DefaultSyntaxKit.registerContentType(
          "text/propertypanel", UmletSyntaxKit.class.getCanonicalName());
    }

    this.setContentType("text/propertypanel");
    this.setFont(Constants.PANEL_FONT); // Set font to make sure UTF-8 characters work
    this.validate();
  }
  public CKSyntaxPaneTest() {
    JFrame f = new JFrame("Party"); // CKSytaxPaneTest.class.getName());
    final Container c = f.getContentPane();
    c.setLayout(new BorderLayout());

    // DefaultSyntaxKit.initKit();

    final JEditorPane codeEditor = new JEditorPane();
    JScrollPane scrPane = new JScrollPane(codeEditor);
    // codeEditor.setContentType("text/python");
    codeEditor.setEditorKit(new PythonSyntaxKit());
    // codeEditor.setText("public static void main(String[] args) {\n}");

    // toolbar is part of the editor kit--ausome!
    JToolBar jToolBar1 = new javax.swing.JToolBar();
    jToolBar1.setRollover(true);
    jToolBar1.setFocusable(false);

    EditorKit kit = codeEditor.getEditorKit();
    if (kit instanceof DefaultSyntaxKit) {
      DefaultSyntaxKit defaultSyntaxKit = (DefaultSyntaxKit) kit;
      defaultSyntaxKit.addToolBarActions(codeEditor, jToolBar1);
    }
    jToolBar1.validate();
    c.add(jToolBar1, BorderLayout.PAGE_START);

    c.add(scrPane, BorderLayout.CENTER);
    // c.add(codeEditor, BorderLayout.CENTER);

    // create console for output?
    JTextPane tpane = new JTextPane();
    c.add(tpane, BorderLayout.LINE_START);
    c.doLayout();

    f.setSize(800, 600);
    f.setVisible(true);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  }
示例#6
0
文件: Tao.java 项目: pranava/Tao_Java
  public static void main(String[] args) {
    if (isOSX()) {
      System.setProperty("apple.laf.useScreenMenuBar", "true");
      System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Tao");
    }

    DefaultSyntaxKit.initKit();
    EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            try {
              ModelEditor editor = new ModelEditor();
              editor.getFrame().setVisible(true);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
  }