Exemple #1
0
 /**
  * Initializes the JTextPane and JScrollPane in the GUI. This is where document text is entered.
  */
 private void initPane() {
   textPane = new JTextPane();
   textPane.setEditable(false);
   currentDoc = textPane.getStyledDocument();
   TextPaneListener tpLis = new TextPaneListener();
   textPane.addKeyListener(tpLis);
   scrollPane = new JScrollPane(textPane);
 }
  private void _setUpEvents() {
    mHeadingComboBox.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent itemEvent) {
            if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
              String key = itemEvent.getItem().toString();
              Integer fontSize = HEADING_LIST.get(key);

              Font cFont = mTextEditor.getFont();
              Font font = new Font(cFont.getFamily(), cFont.getStyle(), fontSize);
              _applyFontStyleForSelection(font);
            }
          }
        });
    mTextEditor.addKeyListener(
        new KeyListener() {
          public void keyTyped(KeyEvent keyEvent) {}

          public void keyPressed(KeyEvent keyEvent) {}

          public void keyReleased(KeyEvent keyEvent) {
            if (keyEvent.isControlDown() && keyEvent.getKeyCode() == KeyEvent.VK_B) {
              Font font = new Font(mTextEditor.getFont().getFamily(), Font.BOLD, 12);
              _applyFontStyleForSelection(font);
              CharArrayWriter caw = new CharArrayWriter();
              try {
                mTextEditor.write(caw);
                MutableAttributeSet set = mTextEditor.getInputAttributes();
                Enumeration e = set.getAttributeNames();
                while (e.hasMoreElements()) {
                  try {
                    StyleConstants.FontConstants at =
                        (StyleConstants.FontConstants) e.nextElement();

                  } catch (Exception ex) {
                    ex.printStackTrace();
                  }
                }
                System.out.println(caw.toString());
              } catch (IOException e) {
                e.printStackTrace(); // To change body of catch statement use File | Settings |
                // File Templates.
              }
            }
          }
        });
  }
Exemple #3
0
  public EditorWindow(RedJClass jClass, RedJProject project) {
    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosed(WindowEvent e) {
            RedJ.openedWindows.remove(jClass.getName());
            RedJ.openedClasses.remove(jClass.getName());
          }
        });

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 899, 522);
    setTitle(jClass.getName() + " - " + project.getName());
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    this.jClass = jClass;
    this.project = project;

    // mnClass.add(mntmClose);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JTextPane editorPane = new JTextPane(/*SyntaxColor.getDoc()*/ );
    editorPane.setFont(new Font("Swis721 BT", Font.PLAIN, 14));
    contentPane.add(editorPane, BorderLayout.CENTER);
    editPane = editorPane;

    JScrollPane scrollPane = new JScrollPane(editPane);
    getContentPane().add(scrollPane);
    scrollPane.setBackground(new Color(45, 50, 59));

    JPanel panel = new JPanel();
    panel.setBackground(new Color(211, 211, 211));
    contentPane.add(panel, BorderLayout.NORTH);

    JPanel panel2 = new JPanel();
    panel2.setBackground(new Color(211, 211, 211));
    contentPane.add(panel2, BorderLayout.SOUTH);

    JTextPane textPane = new JTextPane();
    textPane.setEditable(false);
    textPane.setSize(new Dimension(100, 1000));
    textPane.setVisible(false);

    panel2.add(textPane);

    errorPane = textPane;

    JButton btnNewButton = new JButton("Compile");
    btnNewButton.setToolTipText("(F11)");
    btnNewButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            CompilerJob job = new CompilerJob(jClass, project);
            job.doJob();
          }
        });

    JButton btnSave = new JButton("Save");
    btnSave.setToolTipText("(CTRL + S)");
    btnSave.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // The name of the file to open.
            String fileName = project.getPath() + File.separator + jClass.fileName;

            try {
              // Assume default encoding.
              FileWriter fileWriter = new FileWriter(fileName);

              // Always wrap FileWriter in BufferedWriter.
              BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

              // Note that write() does not automatically
              // append a newline character.
              bufferedWriter.write(editPane.getText());

              // Always close files.
              bufferedWriter.close();
            } catch (IOException ex) {
              System.out.println("Error writing to file '" + fileName + "'");
              // Or we could just do this:
              // ex.printStackTrace();
            }
          }
        });
    panel.add(btnSave);
    panel.add(btnNewButton);

    JButton btnNewButton_1 = new JButton("Cut");
    btnNewButton_1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            StringSelection selection = new StringSelection(editPane.getSelectedText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(selection, selection);
          }
        });
    btnNewButton_1.setToolTipText("CTRL + X");
    panel.add(btnNewButton_1);

    JButton btnNewButton_2 = new JButton("Copy");
    btnNewButton_2.setToolTipText("(CTRL + C)");
    btnNewButton_2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            StringSelection selection = new StringSelection(editPane.getSelectedText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(selection, selection);
          }
        });
    panel.add(btnNewButton_2);

    JButton btnPaste = new JButton("Paste");
    btnPaste.setToolTipText("(CTRL + V)");
    btnPaste.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String data = "";
            try {
              data =
                  (String)
                      Toolkit.getDefaultToolkit()
                          .getSystemClipboard()
                          .getData(DataFlavor.stringFlavor);
            } catch (HeadlessException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            } catch (UnsupportedFlavorException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            }

            try {
              editPane.getDocument().insertString(editPane.getCaretPosition(), data, null);
            } catch (BadLocationException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            }
          }
        });
    panel.add(btnPaste);

    JButton btnClose = new JButton("Close");
    btnClose.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setVisible(false);
          }
        });
    panel.add(btnClose);

    completeManager = new CompleteManager(editPane);
    completeManager.addAction("{", "{}");
    completeManager.addAction("(", "()");
    completeManager.addAction("[", "[]");
    completeManager.addAction("<", "<>");
    completeManager.addAction("\"", "\"\"");
    completeManager.addAction("'", "''");

    editPane.addKeyListener(this);
  }
  private void jbInit() throws Exception {

    saveButton.setText("Save");
    saveButton.addActionListener(new PrintfTemplateEditor_saveButton_actionAdapter(this));
    cancelButton.setText("Cancel");
    cancelButton.addActionListener(new PrintfTemplateEditor_cancelButton_actionAdapter(this));
    this.setTitle(this.getTitle() + " Template Editor");
    printfPanel.setLayout(gridBagLayout1);
    formatLabel.setFont(new java.awt.Font("DialogInput", 0, 12));
    formatLabel.setText("Format String:");
    buttonPanel.setLayout(flowLayout1);
    printfPanel.setBorder(BorderFactory.createEtchedBorder());
    printfPanel.setMinimumSize(new Dimension(100, 160));
    printfPanel.setPreferredSize(new Dimension(380, 160));
    parameterPanel.setLayout(gridBagLayout2);
    parameterLabel.setText("Parameters:");
    parameterLabel.setFont(new java.awt.Font("DialogInput", 0, 12));
    parameterTextArea.setMinimumSize(new Dimension(100, 25));
    parameterTextArea.setPreferredSize(new Dimension(200, 25));
    parameterTextArea.setEditable(true);
    parameterTextArea.setText("");
    insertButton.setMaximumSize(new Dimension(136, 20));
    insertButton.setMinimumSize(new Dimension(136, 20));
    insertButton.setPreferredSize(new Dimension(136, 20));
    insertButton.setToolTipText(
        "insert the format in the format string and add parameter to list.");
    insertButton.setText("Insert Parameter");
    insertButton.addActionListener(new PrintfTemplateEditor_insertButton_actionAdapter(this));
    formatTextArea.setMinimumSize(new Dimension(100, 25));
    formatTextArea.setPreferredSize(new Dimension(200, 15));
    formatTextArea.setText("");
    parameterPanel.setBorder(null);
    parameterPanel.setMinimumSize(new Dimension(60, 40));
    parameterPanel.setPreferredSize(new Dimension(300, 40));
    insertMatchButton.addActionListener(
        new PrintfTemplateEditor_insertMatchButton_actionAdapter(this));
    insertMatchButton.setText("Insert Match");
    insertMatchButton.setToolTipText(
        "insert the match in the format string and add parameter to list.");
    insertMatchButton.setPreferredSize(new Dimension(136, 20));
    insertMatchButton.setMinimumSize(new Dimension(136, 20));
    insertMatchButton.setMaximumSize(new Dimension(136, 20));
    matchPanel.setPreferredSize(new Dimension(300, 40));
    matchPanel.setBorder(null);
    matchPanel.setMinimumSize(new Dimension(60, 60));
    matchPanel.setLayout(gridBagLayout3);
    InsertPanel.setLayout(gridLayout1);
    gridLayout1.setColumns(1);
    gridLayout1.setRows(2);
    gridLayout1.setVgap(0);
    InsertPanel.setBorder(BorderFactory.createEtchedBorder());
    InsertPanel.setMinimumSize(new Dimension(100, 100));
    InsertPanel.setPreferredSize(new Dimension(380, 120));
    editorPane.setText("");
    editorPane.addKeyListener(new PrintfEditor_editorPane_keyAdapter(this));
    printfTabPane.addChangeListener(new PrintfEditor_printfTabPane_changeAdapter(this));
    parameterPanel.add(
        insertButton,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(8, 6, 13, 8),
            0,
            10));
    parameterPanel.add(
        paramComboBox,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(8, 8, 13, 0),
            258,
            11));
    paramComboBox.setRenderer(new MyCellRenderer());
    InsertPanel.add(matchPanel, null);
    InsertPanel.add(parameterPanel, null);
    buttonPanel.add(cancelButton, null);
    buttonPanel.add(saveButton, null);
    this.getContentPane().add(printfTabPane, BorderLayout.NORTH);
    this.getContentPane().add(InsertPanel, BorderLayout.CENTER);
    matchPanel.add(
        insertMatchButton,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(8, 6, 13, 8),
            0,
            10));
    matchPanel.add(
        matchComboBox,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(8, 8, 13, 0),
            258,
            11));
    printfPanel.add(
        parameterLabel,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(7, 5, 0, 5),
            309,
            0));
    printfPanel.add(
        formatLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(4, 5, 0, 5),
            288,
            0));
    printfPanel.add(
        formatTextArea,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(6, 5, 0, 5),
            300,
            34));
    printfPanel.add(
        parameterTextArea,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(6, 5, 6, 5),
            300,
            34));
    printfTabPane.addTab("Editor View", null, editorPanel, "View in Editor");
    printfTabPane.addTab("Printf View", null, printfPanel, "Vies as Printf");
    editorPane.setCharacterAttributes(PLAIN_ATTR, true);
    editorPane.addStyle("PLAIN", editorPane.getLogicalStyle());
    editorPanel.getViewport().add(editorPane, null);
    this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    buttonGroup.add(cancelButton);
  }