private void _applyFontStyleForSelection(Font font) {
    StyledDocument doc = mTextEditor.getStyledDocument();
    MutableAttributeSet attrs = mTextEditor.getInputAttributes();
    StyleConstants.setFontFamily(attrs, font.getFamily());
    StyleConstants.setFontSize(attrs, font.getSize());
    StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0));
    StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0));
    StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0));

    int start = mTextEditor.getSelectionStart();
    int end = mTextEditor.getSelectionEnd();
    doc.setCharacterAttributes(start, (end - start), attrs, false);
  }
示例#2
0
  public JConsole() {
    super();

    setBackground(new Color(70, 70, 70));
    setForeground(Color.WHITE);
    text = new MyJTextPane();

    text.setAutoscrolls(true);
    final Font lFont = new Font("Monospaced", Font.PLAIN, 15);
    text.setText("");
    text.setFont(lFont);
    text.setMargin(new Insets(5, 3, 5, 3));
    text.addKeyListener(new MyKeyListener());
    setViewportView(text);

    contextMenu = new JPopupMenu();
    final ActionListener lActionListener = new MyActionListener();
    contextMenu.add(new JMenuItem(CMD_CUT)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_COPY)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_PASTE)).addActionListener(lActionListener);
    text.addMouseListener(new MyMouseListener());

    MutableAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.BLACK);

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.WHITE);
    attrOut = attr;

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.RED);
    StyleConstants.setItalic(attr, true);
    StyleConstants.setBold(attr, true);
    attrError = attr;

    try {
      fromConsoleStream = new PipedOutputStream();
      in = new PipedInputStream((PipedOutputStream) fromConsoleStream);

      final PipedOutputStream lOutPipe = new PipedOutputStream();
      out = new PrintStream(lOutPipe);

      final PipedOutputStream lErrPipe = new PipedOutputStream();
      err = new PrintStream(lErrPipe);

    } catch (IOException e) {
      e.printStackTrace();
    }
    requestFocus();
  }
示例#3
0
 static {
   StyleConstants.setForeground(PLAIN_ATTR, Color.black);
   StyleConstants.setBold(PLAIN_ATTR, false);
   StyleConstants.setFontFamily(PLAIN_ATTR, "Helvetica");
   StyleConstants.setFontSize(PLAIN_ATTR, 14);
 }