示例#1
0
  public MessageInputPanel() {
    messagePanel = new MessagePanel();
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;

    add(messagePanel, gbc);

    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.anchor = GridBagConstraints.LINE_END;

    charLabel = new JLabel("0");
    charLabel.setOpaque(true);
    add(charLabel, gbc);
    setBackground(Color.LIGHT_GRAY);
    JTextPane tp = messagePanel.getTextPane();
    StyledDocument doc = tp.getStyledDocument();
    doc.addDocumentListener(new TheDocumentListener());
    if (logger.isDebugEnabled()) logger.debug("Attached DocumentListener to {}.", doc);
    tp.addCaretListener(new TheCaretListener());
    KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    KeyStroke shiftEnterStroke =
        KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK);
    KeyStroke ctrlSpaceStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.CTRL_DOWN_MASK);
    Object enterActionKey = tp.getInputMap().get(enterStroke);
    Action enterAction = tp.getActionMap().get(enterActionKey);
    tp.getInputMap().put(shiftEnterStroke, enterActionKey);
    tp.getInputMap().put(enterStroke, new EnterAction());
    tp.getInputMap().put(ctrlSpaceStroke, new CompleteAction());
  }
示例#2
0
  public InterpreterFrame() {
    super("Simple Lisp Interpreter");

    // Create the menu
    menubar = buildMenuBar();
    setJMenuBar(menubar);
    // Create the toolbar
    toolbar = buildToolBar();
    // disable cut and copy actions
    cutAction.setEnabled(false);
    copyAction.setEnabled(false);
    // Setup text area for editing source code
    // and setup document listener so interpreter
    // is notified when current file modified and
    // when the cursor is moved.
    textView = buildEditor();
    textView.getDocument().addDocumentListener(this);
    textView.addCaretListener(this);

    // set default key bindings
    bindKeyToCommand("ctrl C", "(buffer-copy)");
    bindKeyToCommand("ctrl X", "(buffer-cut)");
    bindKeyToCommand("ctrl V", "(buffer-paste)");
    bindKeyToCommand("ctrl E", "(buffer-eval)");
    bindKeyToCommand("ctrl O", "(file-open)");
    bindKeyToCommand("ctrl S", "(file-save)");
    bindKeyToCommand("ctrl Q", "(exit)");

    // Give text view scrolling capability
    Border border =
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(3, 3, 3, 3),
            BorderFactory.createLineBorder(Color.gray));
    JScrollPane topSplit = addScrollers(textView);
    topSplit.setBorder(border);

    // Create tabbed pane for console/problems
    consoleView = makeConsoleArea(10, 50, true);
    problemsView = makeConsoleArea(10, 50, false);
    tabbedPane = buildProblemsConsole();

    // Plug the editor and problems/console together
    // using a split pane. This allows one to change
    // their relative size using the split-bar in
    // between them.
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, tabbedPane);

    // Create status bar
    statusView = new JLabel(" Status");
    lineNumberView = new JLabel("0:0");
    statusbar = buildStatusBar();

    // Now, create the outer panel which holds
    // everything together
    outerpanel = new JPanel();
    outerpanel.setLayout(new BorderLayout());
    outerpanel.add(toolbar, BorderLayout.PAGE_START);
    outerpanel.add(splitPane, BorderLayout.CENTER);
    outerpanel.add(statusbar, BorderLayout.SOUTH);
    getContentPane().add(outerpanel);

    // tell frame to fire a WindowsListener event
    // but not to close when "x" button clicked.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(this);
    // set minimised icon to use
    setIconImage(makeImageIcon("spi.png").getImage());

    // setup additional internal functions
    InternalFunctions.setup_internals(interpreter, this);

    // set default window size
    Component top = splitPane.getTopComponent();
    Component bottom = splitPane.getBottomComponent();
    top.setPreferredSize(new Dimension(100, 400));
    bottom.setPreferredSize(new Dimension(100, 200));
    pack();

    // load + run user configuration file (if there is one)
    String homedir = System.getProperty("user.home");
    try {
      interpreter.load(homedir + "/.simplelisp");
    } catch (FileNotFoundException e) {
      // do nothing if file does not exist!
      System.out.println("Didn't find \"" + homedir + "/.simplelisp\"");
    }

    textView.grabFocus();
    setVisible(true);

    // redirect all I/O to problems/console
    redirectIO();

    // start highlighter thread
    highlighter = new DisplayThread(250);
    highlighter.setDaemon(true);
    highlighter.start();
  }
示例#3
0
    public DocumentPanel() {
      super(new BorderLayout());

      JLabel lblDocument = new JLabel("Document: " + document.getTitle());
      lblDocument.setBorder(new EtchedBorder());

      textPane = new JTextPane(document);
      textPane.setEditable(false);
      textPane.setMargin(new Insets(5, 20, 5, 5));
      textPane.setMaximumSize(new Dimension(364, 1000000000));
      textPane.setPreferredSize(new Dimension(364, 400));
      textPane.setMinimumSize(new Dimension(364, 10));
      textPane.addCaretListener(
          new CaretListener() {
            public void caretUpdate(CaretEvent e) {
              int length = document.getLength();
              int offset = e.getDot();

              if (e.getDot() == e.getMark()) textPane.getCaret().moveDot(offset + 1);

              Paragraph p = lockManager.getParFromOffset(offset);
              int pOffset = p.getOffset();

              lblCursor.setText(
                  "Document Length="
                      + String.valueOf(length)
                      + ", CaretOffset="
                      + String.valueOf(offset)
                      + ", Paragraph="
                      + p.toString()
                      + ", Offset in Paragraph="
                      + String.valueOf(offset - p.getOffset()));
            }
          });
      Box box = new Box(BoxLayout.X_AXIS);
      box.add(textPane);
      box.add(Box.createGlue());
      box.setBackground(Color.WHITE);
      box.setOpaque(true);
      box.setPreferredSize(new Dimension(600, 10000));

      lblCursor = new JLabel("Cursor");
      lblCursor.setBorder(new EtchedBorder());

      JPanel boxText = new JPanel(new BorderLayout());
      boxText.setBorder(new EmptyBorder(5, 5, 5, 5));
      boxText.add(lblDocument, BorderLayout.NORTH);
      boxText.add(new JScrollPane(box), BorderLayout.CENTER);
      boxText.add(lblCursor, BorderLayout.SOUTH);

      JLabel lblPars = new JLabel("Paragraphs: ");
      lblPars.setBorder(new EtchedBorder());

      parList = new JList();
      parList.setPreferredSize(new Dimension(100, 300));
      parList.setEnabled(false);

      JPanel boxPars = new JPanel(new BorderLayout());
      boxPars.setBorder(new EmptyBorder(5, 5, 5, 5));
      boxPars.add(lblPars, BorderLayout.NORTH);
      boxPars.add(new JScrollPane(parList), BorderLayout.CENTER);

      add(boxText, BorderLayout.CENTER);
      add(boxPars, BorderLayout.EAST);
    }
示例#4
0
  /** Prepares a new <code>TerminalPanel</code> object. */
  public TerminalPanel(final Host host) {
    super();
    this.host = host;
    host.setTerminalPanel(this);
    /* Sets terminal some of the output colors. This is in no way complete
     * or correct and probably doesn't have to be. */
    terminalColor.put("0", Tools.getDefaultColor("TerminalPanel.TerminalWhite"));
    terminalColor.put("30", Tools.getDefaultColor("TerminalPanel.TerminalBlack"));
    terminalColor.put("31", Tools.getDefaultColor("TerminalPanel.TerminalRed"));
    terminalColor.put("32", Tools.getDefaultColor("TerminalPanel.TerminalGreen"));
    terminalColor.put("33", Tools.getDefaultColor("TerminalPanel.TerminalYellow"));
    terminalColor.put("34", Tools.getDefaultColor("TerminalPanel.TerminalBlue"));
    terminalColor.put("35", Tools.getDefaultColor("TerminalPanel.TerminalPurple"));
    terminalColor.put("36", Tools.getDefaultColor("TerminalPanel.TerminalCyan"));
    final Font f = new Font("Monospaced", Font.PLAIN, Tools.getConfigData().scaled(14));
    terminalArea = new JTextPane();
    terminalArea.setStyledDocument(new MyDocument());
    final DefaultCaret caret =
        new DefaultCaret() {
          private static final long serialVersionUID = 1L;

          @Override
          protected synchronized void damage(final Rectangle r) {
            if (r != null) {
              x = r.x;
              y = r.y;
              width = 8;
              height = r.height;
              repaint();
            }
          }

          @Override
          public void paint(final Graphics g) {
            /* painting cursor. If it is not visible it is out of focus, we
             * make it barely visible. */
            try {
              TextUI mapper = getComponent().getUI();
              Rectangle r = mapper.modelToView(getComponent(), getDot(), getDotBias());
              if (r == null) {
                return;
              }
              g.setColor(getComponent().getCaretColor());
              if (isVisible() && editEnabled) {
                g.fillRect(r.x, r.y, 8, r.height);
              } else {
                g.drawRect(r.x, r.y, 8, r.height);
              }
            } catch (BadLocationException e) {
              Tools.appError("Drawing of cursor failed", e);
            }
          }
        };
    terminalArea.setCaret(caret);
    terminalArea.addCaretListener(
        new CaretListener() {
          @Override
          public void caretUpdate(final CaretEvent e) {
            /* don't do this if caret moved because of selection */
            mPosLock.lock();
            try {
              if (e != null && e.getDot() < commandOffset && e.getDot() == e.getMark()) {
                terminalArea.setCaretPosition(commandOffset);
              }
            } finally {
              mPosLock.unlock();
            }
          }
        });

    /* set font and colors */
    terminalArea.setFont(f);
    terminalArea.setBackground(Tools.getDefaultColor("TerminalPanel.Background"));

    commandColor = new SimpleAttributeSet();
    StyleConstants.setForeground(commandColor, Tools.getDefaultColor("TerminalPanel.Command"));

    errorColor = new SimpleAttributeSet();
    StyleConstants.setForeground(errorColor, Tools.getDefaultColor("TerminalPanel.Error"));

    outputColor = new SimpleAttributeSet();
    defaultOutputColor = Tools.getDefaultColor("TerminalPanel.Output");
    StyleConstants.setForeground(outputColor, defaultOutputColor);

    promptColor = new SimpleAttributeSet();
    StyleConstants.setForeground(promptColor, host.getPmColors()[0]);

    append(prompt(), promptColor);
    terminalArea.setEditable(true);
    getViewport().add(terminalArea, BorderLayout.PAGE_END);
    setPreferredSize(
        new Dimension(Short.MAX_VALUE, Tools.getDefaultInt("MainPanel.TerminalPanelHeight")));
    setMinimumSize(getPreferredSize());
    setMaximumSize(getPreferredSize());
  }