Exemplo n.º 1
0
 private void updateScrolling() {
   if (myScrollingEnabled) {
     myBoundedRangeModel.setRangeProperties(
         0,
         myTermSize.height,
         -myTerminalTextBuffer.getHistoryBuffer().getLineCount(),
         myTermSize.height,
         false);
   } else {
     myBoundedRangeModel.setRangeProperties(0, myTermSize.height, 0, myTermSize.height, false);
   }
 }
  /**
   * This determines the amount of the progress bar that should be filled based on the percent done
   * gathered from the model. This is a common operation so it was abstracted out. It assumes that
   * your progress bar is linear. That is, if you are making a circular progress indicator, you will
   * want to override this method.
   */
  protected int getAmountFull(Insets b, int width, int height) {
    int amountFull = 0;
    BoundedRangeModel model = progressBar.getModel();

    if ((model.getMaximum() - model.getMinimum()) != 0) {
      if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        amountFull = (int) Math.round(width * progressBar.getPercentComplete());
      } else {
        amountFull = (int) Math.round(height * progressBar.getPercentComplete());
      }
    }
    return amountFull;
  }
 public synchronized void setPlayer(Player player) {
   if (this.player != null) {
     this.player.removeChangeListener(this);
     player.removePropertyChangeListener(this);
   }
   this.player = player;
   //        boundedRangeModel = player == null ? null : player.getBoundedRangeModel();
   boundedRangeModel = player == null ? null : player.getTimeModel();
   slider.setModel(boundedRangeModel);
   if (player != null) {
     if (player.getState() >= Player.REALIZED
         && boundedRangeModel != null
         && boundedRangeModel.getMaximum() == 0) {
       setPlayerControlsVisible(false);
     }
     slider.setProgressModel(player.getCachingModel());
     startButton.setSelected(player.isActive());
     player.addChangeListener(this);
     player.addPropertyChangeListener(this);
     audioButton.setVisible(player.isAudioAvailable());
     audioButton.setSelected(player.isAudioEnabled());
     colorCyclingButton.setVisible(
         (player instanceof ColorCyclePlayer)
             ? ((ColorCyclePlayer) player).isColorCyclingAvailable()
             : false);
     colorCyclingButton.setSelected(
         (player instanceof ColorCyclePlayer)
             ? ((ColorCyclePlayer) player).isColorCyclingStarted()
             : false);
     validate();
     repaint();
     BoundedRangeModel cachingControlModel = slider.getProgressModel();
   }
 }
    // ChangeListener
    public void stateChanged(ChangeEvent e) {
      BoundedRangeModel model = progressBar.getModel();
      int newRange = model.getMaximum() - model.getMinimum();
      int newPercent;
      int oldPercent = getCachedPercent();

      if (newRange > 0) {
        newPercent = (int) ((100 * (long) model.getValue()) / newRange);
      } else {
        newPercent = 0;
      }

      if (newPercent != oldPercent) {
        setCachedPercent(newPercent);
        progressBar.repaint();
      }
    }
  public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if (boundedRangeModel != null) {
      int value = boundedRangeModel.getValue();
      if (source == forwardButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMaximum() ? boundedRangeModel.getMinimum() : value + 1);
      } else if (source == rewindButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMinimum() ? boundedRangeModel.getMaximum() : value - 1);
      } else if (source == startButton) {
        if (startButton.isSelected() != player.isActive()) {
          if (startButton.isSelected()) {
            player.start();
          } else {
            player.stop();
          }
        }
      } else if (source == audioButton) {

        player.setAudioEnabled(audioButton.isSelected());
      } else if (source == colorCyclingButton) {
        if (player instanceof ColorCyclePlayer) {
          ((ColorCyclePlayer) player).setColorCyclingStarted(colorCyclingButton.isSelected());
        }
      }
    }
  }
Exemplo n.º 6
0
  private void clearBuffer() {
    if (!myTerminalTextBuffer.isUsingAlternateBuffer()) {
      myTerminalTextBuffer.clearHistory();

      if (myCoordsAccessor != null && myCoordsAccessor.getY() > 0) {
        TerminalLine line = myTerminalTextBuffer.getLine(myCoordsAccessor.getY() - 1);

        myTerminalTextBuffer.clearAll();

        myCoordsAccessor.setY(0);
        myCursor.setY(1);
        myTerminalTextBuffer.addLine(line);
      }

      updateScrolling();

      myClientScrollOrigin = myBoundedRangeModel.getValue();
    }
  }
Exemplo n.º 7
0
 private void moveScrollBar(int k) {
   myBoundedRangeModel.setValue(myBoundedRangeModel.getValue() + k);
 }
Exemplo n.º 8
0
 private void scrollToBottom() {
   myBoundedRangeModel.setValue(myTermSize.height);
 }
Exemplo n.º 9
0
  public void init() {
    initFont();

    setUpClipboard();

    setPreferredSize(new Dimension(getPixelWidth(), getPixelHeight()));

    setFocusable(true);
    enableInputMethods(true);
    setDoubleBuffered(true);

    setFocusTraversalKeysEnabled(false);

    addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseDragged(final MouseEvent e) {
            if (!isLocalMouseAction(e)) {
              return;
            }

            final Point charCoords = panelToCharCoords(e.getPoint());

            if (mySelection == null) {
              // prevent unlikely case where drag started outside terminal panel
              if (mySelectionStartPoint == null) {
                mySelectionStartPoint = charCoords;
              }
              mySelection = new TerminalSelection(new Point(mySelectionStartPoint));
            }
            repaint();
            mySelection.updateEnd(charCoords);
            if (mySettingsProvider.copyOnSelect()) {
              handleCopy(false);
            }

            if (e.getPoint().y < 0) {
              moveScrollBar((int) ((e.getPoint().y) * SCROLL_SPEED));
            }
            if (e.getPoint().y > getPixelHeight()) {
              moveScrollBar((int) ((e.getPoint().y - getPixelHeight()) * SCROLL_SPEED));
            }
          }
        });

    addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(MouseWheelEvent e) {
            if (isLocalMouseAction(e)) {
              int notches = e.getWheelRotation();
              moveScrollBar(notches);
            }
          }
        });

    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
              if (e.getClickCount() == 1) {
                mySelectionStartPoint = panelToCharCoords(e.getPoint());
                mySelection = null;
                repaint();
              }
            }
          }

          @Override
          public void mouseReleased(final MouseEvent e) {
            requestFocusInWindow();
            repaint();
          }

          @Override
          public void mouseClicked(final MouseEvent e) {
            requestFocusInWindow();
            if (e.getButton() == MouseEvent.BUTTON1 && isLocalMouseAction(e)) {
              int count = e.getClickCount();
              if (count == 1) {
                // do nothing
              } else if (count == 2) {
                // select word
                final Point charCoords = panelToCharCoords(e.getPoint());
                Point start = SelectionUtil.getPreviousSeparator(charCoords, myTerminalTextBuffer);
                Point stop = SelectionUtil.getNextSeparator(charCoords, myTerminalTextBuffer);
                mySelection = new TerminalSelection(start);
                mySelection.updateEnd(stop);

                if (mySettingsProvider.copyOnSelect()) {
                  handleCopy(false);
                }
              } else if (count == 3) {
                // select line
                final Point charCoords = panelToCharCoords(e.getPoint());
                int startLine = charCoords.y;
                while (startLine > -getScrollBuffer().getLineCount()
                    && myTerminalTextBuffer.getLine(startLine - 1).isWrapped()) {
                  startLine--;
                }
                int endLine = charCoords.y;
                while (endLine < myTerminalTextBuffer.getHeight()
                    && myTerminalTextBuffer.getLine(endLine).isWrapped()) {
                  endLine++;
                }
                mySelection = new TerminalSelection(new Point(0, startLine));
                mySelection.updateEnd(new Point(myTermSize.width, endLine));

                if (mySettingsProvider.copyOnSelect()) {
                  handleCopy(false);
                }
              }
            } else if (e.getButton() == MouseEvent.BUTTON2
                && mySettingsProvider.pasteOnMiddleMouseClick()
                && isLocalMouseAction(e)) {
              handlePaste();
            } else if (e.getButton() == MouseEvent.BUTTON3) {
              JPopupMenu popup = createPopupMenu();
              popup.show(e.getComponent(), e.getX(), e.getY());
            }
            repaint();
          }
        });

    addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(final ComponentEvent e) {
            sizeTerminalFromComponent();
          }
        });

    addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            myCursor.cursorChanged();
          }

          @Override
          public void focusLost(FocusEvent e) {
            myCursor.cursorChanged();
          }
        });

    myBoundedRangeModel.addChangeListener(
        new ChangeListener() {
          public void stateChanged(final ChangeEvent e) {
            myClientScrollOrigin = myBoundedRangeModel.getValue();
            repaint();
          }
        });

    createRepaintTimer();
  }