コード例 #1
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
  // Show the command from the command history, pointed to by the index.
  // Note that the index runs in reverse.
  private void showHistory() {
    String lShowLine;
    if (commandHistoryIndex == 0) lShowLine = currentCommand;
    else lShowLine = commandHistory.get(commandHistory.size() - commandHistoryIndex);

    replaceConsoleText(lShowLine, commandPos, textLength());
    text.setCaretPosition(textLength());
    text.repaint();
  }
コード例 #2
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 private String getCmd() {
   try {
     return text.getText(commandPos, textLength() - commandPos);
   } catch (BadLocationException e) {
     return "";
   }
 }
コード例 #3
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
  private void processCommand() {
    String lCommandRepr = getCmd();
    if (lCommandRepr.length() != 0) commandHistory.add(lCommandRepr);
    lCommandRepr = lCommandRepr + "\n";

    appendConsoleText("\n");
    commandHistoryIndex = 0;
    acceptLine(lCommandRepr);
    text.repaint();
  }
コード例 #4
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
  /**
   * The user of the component can write a command in the console as if the user typed the command
   * himself. The application using the console can simnulate user actions in this way.
   *
   * @param aCommand
   */
  public void setCommand(String aCommand) {
    String lCommandRepr = aCommand;

    if (lCommandRepr.length() != 0) commandHistory.add(lCommandRepr);
    lCommandRepr = lCommandRepr + "\n";

    appendConsoleText(lCommandRepr);
    commandHistoryIndex = 0;
    acceptLine(lCommandRepr);
    text.repaint();
  }
コード例 #5
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
  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();
  }
コード例 #6
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 private int textLength() {
   return text.getDocument().getLength();
 }
コード例 #7
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 public void setFont(Font aFont) {
   super.setFont(aFont);
   if (text != null) text.setFont(aFont);
 }
コード例 #8
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 /** Clear the console. */
 public void clear() {
   text.setText("");
   text.repaint();
 }
コード例 #9
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 private void moveCaret() {
   if (text.getCaretPosition() < commandPos) {
     text.setCaretPosition(textLength());
   }
   text.repaint();
 }
コード例 #10
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 // Replace part of the text in the text component.
 private String replaceConsoleText(Object aContent, int aFrom, int aTo) {
   final String aContentRepr = aContent.toString();
   text.select(aFrom, aTo);
   text.replaceSelection(aContentRepr);
   return aContentRepr;
 }
コード例 #11
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 // Append text to the end of the text already present in the
 // text component.
 private void appendConsoleText(String aContent) {
   final int lTxtLen = textLength();
   text.select(lTxtLen, lTxtLen);
   text.replaceSelection(aContent);
 }
コード例 #12
0
ファイル: JConsole.java プロジェクト: nybbs2003/RipplePower
 // Focus handling.
 public void requestFocus() {
   super.requestFocus();
   text.requestFocus();
 }