Example #1
0
  /** Create the Swing window. */
  private void makeWindow(int columns, int rows) {
    Image icon = BlueJTheme.getIconImage();
    if (icon != null) {
      setIconImage(icon);
    }
    text = new TermTextArea(rows, columns, buffer, project, this, false);
    final InputMap origInputMap = text.getInputMap();
    text.setInputMap(
        JComponent.WHEN_FOCUSED,
        new InputMap() {
          {
            setParent(origInputMap);
          }

          @Override
          public Object get(KeyStroke keyStroke) {
            Object actionName = super.get(keyStroke);

            if (actionName == null) {
              return null;
            }

            char keyChar = keyStroke.getKeyChar();
            if (keyChar == KeyEvent.CHAR_UNDEFINED || keyChar < 32) {
              // We might want to filter the action
              if ("copy-to-clipboard".equals(actionName)) {
                return actionName;
              }
              if ("paste-from-clipboard".equals(actionName)) {
                // Handled via paste() in TermTextArea
                return actionName;
              }
              return PrefMgr.getFlag(PrefMgr.ACCESSIBILITY_SUPPORT) ? actionName : null;
            }

            return actionName;
          }
        });

    scrollPane = new JScrollPane(text);
    text.setFont(getTerminalFont());
    text.setEditable(false);
    text.setMargin(new Insets(6, 6, 6, 6));
    text.addKeyListener(this);

    getContentPane().add(scrollPane, BorderLayout.CENTER);

    setJMenuBar(makeMenuBar());

    // Close Action when close button is pressed
    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent event) {
            Window win = (Window) event.getSource();

            // don't allow them to close the window if the debug machine
            // is running.. tries to stop them from closing down the
            // input window before finishing off input in the terminal
            if (project != null) {
              if (project.getDebugger().getStatus() == Debugger.RUNNING) return;
            }
            DataCollector.showHideTerminal(project, false);
            win.setVisible(false);
          }
        });

    // save position when window is moved
    addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentMoved(ComponentEvent event) {
            Config.putLocation("bluej.terminal", getLocation());
          }
        });

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    setLocation(Config.getLocation("bluej.terminal"));

    pack();
  }