示例#1
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == input) {
      String s = input.getText() + "\n";
      Utils.debugMsg(s);
      model.sendToBiocham(s); // .getBiochamInput().println(s);
      /*if (historyVector.size() > 31){
         historyVector.removeElementAt(0);
      }*/
      // historyVector.add(s);
      output.append(s);
      //  System.out.println("doc length= "+output.getDocument().getLength());
      //  output.setCaretPosition(output.getDocument().getLength());
      // scrollPane.setPreferredSize(new Dimension(200,200));
      input.setText(null);
      // historyIndex = -1;
    }

    output.setCaretPosition(output.getDocument().getLength());
  }
示例#2
0
  /**
   * It constructs the commandline panel with its 3 text areas.
   *
   * @param p
   * @param m
   */
  private void buildPanel(DefaultMutableTreeNode p, BiochamModel m) { // Create the console Panel
    historyVector = new Vector<String>();
    historyIndex = -1;
    model = m;
    model.setHistoryIndex(historyIndex);
    model.setHistoryVector(historyVector);

    setLayout(new GridBagLayout());
    // setBackground(Utils.backgroundColor);
    GridBagConstraints c = new GridBagConstraints();
    setOpaque(true);

    c.gridx = 0;
    c.gridy = 0;
    JLabel l = new JLabel("Command: ");
    l.setBackground(Color.blue);
    add(l, c);

    input = new JTextField(80);

    input.addActionListener(this);
    // avoid TAB events consumption by FocusTraversal
    // keep them for command completion
    input.setFocusTraversalKeysEnabled(false);
    input.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            // History
            if (e.getKeyCode() == KeyEvent.VK_UP && !historyVector.isEmpty()) {
              if (historyIndex < 0) historyIndex = historyVector.size() - 1;
              else if (historyIndex > 0) historyIndex--;
              input.setText(historyVector.elementAt(historyIndex));
            }
            if (e.getKeyCode() == KeyEvent.VK_DOWN && historyIndex >= 0) {
              if (historyIndex < historyVector.size() - 1) {
                historyIndex++;
                input.setText(historyVector.elementAt(historyIndex));
              } else {
                historyIndex = -1;
                input.setText(null);
              }
            }
            // Command completion
            if (e.getKeyCode() == KeyEvent.VK_TAB) {
              input.setText(BiochamCommands.getContinuation(input.getText()));
            }
          }
        });

    c.gridx = 1;
    c.gridy = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    add(input, c);

    // Create a scrolled text area.
    output = new JTextArea(5, 30);
    /* output.setBackground(Color.black);
    output.setForeground(Color.white);*/
    output.setEditable(false);
    output.setFont(new Font("Monospaced", Font.PLAIN, 12));
    output.setWrapStyleWord(true);
    output.setLineWrap(true);
    output.setCaretPosition(output.getDocument().getLength());
    scrollPane = new JScrollPane(output);
    scrollPane.setAutoscrolls(true);
    // Add the text area to the panel.
    c.gridx = 0;
    c.gridy = 1;
    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.weighty = 1.0;
    add(scrollPane, c);
    Utils.debugMsg(
        "******************************************doc length= "
            + output.getDocument().getLength());
  }