public void setZoom(float zoom) {
   if (!SwingUtilities.isEventDispatchThread()) {
     throw new IllegalStateException("Must be on EDT");
   }
   if (zoom == zoom && zoom > 0.01 && Math.abs(zoom - this.zoom) > 0.01) {
     JScrollBar hsb = scrollPane.getHorizontalScrollBar();
     JScrollBar vsb = scrollPane.getVerticalScrollBar();
     float hv = (float) hsb.getValue();
     float vv = (float) vsb.getValue();
     float hm = (float) hsb.getMaximum();
     float vm = (float) vsb.getMaximum();
     this.zoom = zoom;
     view.setSize(view.getPreferredSize());
     listener.setEnabled(false); // don't send adjustment events
     Dimension viewsize = view.getSize();
     hv *= ((float) viewsize.width) / hm;
     vv *= ((float) viewsize.height) / vm;
     hsb.setMaximum(viewsize.width);
     vsb.setMaximum(viewsize.height);
     hsb.setValue(Math.round(hv));
     vsb.setValue(Math.round(vv));
     listener.setEnabled(true);
     view.revalidate();
     view.repaint();
   }
 }
Esempio n. 2
0
    public void mouseWheelMoved(MouseWheelEvent e) {

      int notches = e.getWheelRotation();
      int sign = 1;
      if (notches > 0) {
        sign = -1;
      }
      if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        int numClicks = e.getScrollAmount();
        scale = scale + (numClicks * 0.1f) * sign;
        if (scale <= 0) scale = 0.1f;
      }

      TheDisplayPanel.initDisplay();
      TheDisplayPanel.repaint();

      JScrollBar verticalScrollBar = TheScrollPane.getVerticalScrollBar();
      JScrollBar horizScrollBar = TheScrollPane.getHorizontalScrollBar();

      // Point pInImage = new
      // Point((int)(mouseMovePoint.x+lastScrollValueX),
      // (int)(mouseMovePoint.y+lastScrollValueY));

      verticalScrollBar.setValue((int) (lastScrollValueY + mouseMovePoint.y));
      horizScrollBar.setValue((int) (lastScrollValueX + mouseMovePoint.x));

      lastScrollValueX = horizScrollBar.getValue();
      lastScrollValueY = verticalScrollBar.getValue();

      TheFrame.validate();
      TheFrame.repaint();
    }
  private void refreshInfo() {
    int channelsCount = mModel.getChannelCount();
    mChannelLabel.setVisible(channelsCount > 1);
    mChannelScrollBar.setVisible(channelsCount > 1);

    mChannelLabel.setText(
        String.format("Channel: %s / %s", mModel.getCurrentChannel() + 1, channelsCount));
    mChannelScrollBar.setValue(mModel.getCurrentChannel());
    mChannelScrollBar.setMaximum(channelsCount);

    int zPlanesCount = mModel.getZPlanesCount();
    mZPlaneLabel.setVisible(zPlanesCount > 1);
    mZPlaneScrollBar.setVisible(zPlanesCount > 1);

    mZPlaneLabel.setText(
        String.format("Z plane: %s / %s", mModel.getCurrentZPlane() + 1, zPlanesCount));
    mZPlaneScrollBar.setValue(mModel.getCurrentZPlane());
    mZPlaneScrollBar.setMaximum(zPlanesCount);

    int timePointsCount = mModel.getTimePointCount();
    mTimePointScrollBar.setVisible(timePointsCount > 1);
    mTimePointLabel.setVisible(timePointsCount > 1);

    mTimePointLabel.setText(
        String.format("Time point: %s / %s", mModel.getCurrentTimePoint() + 1, timePointsCount));
    mTimePointScrollBar.setValue(mModel.getCurrentTimePoint());
    mTimePointScrollBar.setMaximum(timePointsCount);
  }
Esempio n. 4
0
    public void mouseDragged(MouseEvent e) {

      JScrollBar verticalScrollBar = TheScrollPane.getVerticalScrollBar();
      JScrollBar horizScrollBar = TheScrollPane.getHorizontalScrollBar();

      verticalScrollBar.setValue((int) (lastScrollValueY + startPoint.y - e.getPoint().y));
      horizScrollBar.setValue((int) (lastScrollValueX + startPoint.x - e.getPoint().x));

      lastScrollValueX = horizScrollBar.getValue();
      lastScrollValueY = verticalScrollBar.getValue();
    }
Esempio n. 5
0
 /** Centers the graph in the display. */
 public void center() {
   // toggle the scrollbars back and forth to center the image
   JScrollBar sb = scrollPane.getHorizontalScrollBar();
   sb.setValue(sb.getMaximum());
   sb.setValue(sb.getMinimum());
   sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2);
   sb = scrollPane.getVerticalScrollBar();
   sb.setValue(sb.getMaximum());
   sb.setValue(sb.getMinimum());
   sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2);
 }
  /**
   * @param x x coordinate in PDF units
   * @param y y coordinate in PDF units
   * @param centre if true, centre this location in the viewport, otherwise cause it to be displayed
   *     at the top left of the viewport.
   */
  private void ensureVisible(PDFPage page, double x, double y, boolean centre) {
    PDFPage oldPage = view.getPage();
    Collection<PagePanel> oldPagePanels = view.getPagePanels();
    view.setPage(page, false);
    Rectangle pageRect = view.getPageRectangle(page);

    if (pageRect != null) {
      Rectangle2D crop = PagePanel.getFullPageView(page);
      int xoffset = pageRect.x, yoffset = pageRect.y;
      if (x > crop.getMinX()) { // Also confirms !NaN
        xoffset += pointsToPixels((float) (Math.min(crop.getMaxX(), x) - crop.getMinX()));
      }
      if (y < crop.getMaxY()) { // Also confirms !NaN
        yoffset += pointsToPixels((float) (crop.getHeight() - Math.max(0, y - crop.getMinY())));
      }

      JScrollBar hsb = scrollPane.getHorizontalScrollBar();
      JScrollBar vsb = scrollPane.getVerticalScrollBar();
      if (centre) {
        xoffset -= hsb.getVisibleAmount() / 2;
        yoffset -= vsb.getVisibleAmount() / 2;
      }
      if (getPagePanel() != null && getPagePanel().getClip() != null) {
        hsb.setValue(xoffset); // Don't want to smooth scroll if we're clipping
        vsb.setValue(yoffset); // the page rectangles.
      } else {
        smoothScroll(xoffset, yoffset, hsb, vsb);
      }
    }
    if (page != oldPage) {
      DocumentPanel docpanel = getDocumentPanel();
      if (docpanel != null) {
        DocumentPanelEvent dpe = DocumentPanelEvent.createPageChanged(docpanel);
        dpe.setPreviousPage(oldPage);
        docpanel.raiseDocumentPanelEvent(dpe);
      }
      Collection<PagePanel> newPagePanels = view.getPagePanels();
      for (Iterator<PagePanel> i = oldPagePanels.iterator(); i.hasNext(); ) {
        PagePanel oldPagePanel = i.next();
        if (!newPagePanels.contains(oldPagePanel)) {
          oldPagePanel.raisePagePanelEvent(PagePanelEvent.createPageHidden(oldPagePanel, oldPage));
        }
      }
      for (Iterator<PagePanel> i = newPagePanels.iterator(); i.hasNext(); ) {
        PagePanel newPagePanel = i.next();
        if (!oldPagePanels.contains(newPagePanel)) {
          newPagePanel.raisePagePanelEvent(PagePanelEvent.createPageVisible(newPagePanel, page));
        }
      }
    }
  }
 private void sendMessage(String message) {
   try {
     updateBtnSelection();
     showUserMessage(userName + ": ", message);
     message = encrypting(message);
     // System.out.println(message);
     outputStrm.writeObject(userName + ": " + message);
     outputStrm.flush();
     cipherTextArea.append(" " + userName + ": " + message + "\n");
     sb.setValue(sb.getMaximum());
     sb2.setValue(sb2.getMaximum() + 50);
   } catch (IOException e) {
     chatTextWindow.append(" Something messed up!\n");
   }
 }
Esempio n. 8
0
 private void formComponentResized(
     java.awt.event.ComponentEvent evt) { // GEN-FIRST:event_formComponentResized
   if (enBas) {
     JScrollBar scroll = jScrollPane1.getVerticalScrollBar();
     scroll.setValue(scroll.getMaximum() - scroll.getVisibleAmount());
   }
 } // GEN-LAST:event_formComponentResized
Esempio n. 9
0
      public void mouseWheelMoved(MouseWheelEvent e) {
        String st[] = {"PER UNITA'", "PER BLOCCO"};

        int unit = e.getUnitsToScroll();

        // calcolo per la scrollbar verticale l'attuale posizione
        // e l'unità di incremento per scroll
        JScrollBar sb = sp.getVerticalScrollBar();
        int y = sb.getValue();
        int y1 =
            e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL
                ? sb.getUnitIncrement(1)
                : sb.getBlockIncrement(1);

        sb.setValue(y + y1 * unit); // aggiorna la view della textarea

        int a = e.getScrollAmount();
        int b = e.getScrollType();
        int c = e.getUnitsToScroll();
        int d = e.getWheelRotation();
        double f = e.getPreciseWheelRotation();
        String g =
            "Unità da scorrere per giro di tacca: "
                + a
                + "\nTipo di scroll: "
                + st[e.getScrollType()]
                + "\nUnità che scorreranno verso l'alto: "
                + c
                + "\nNumero di tacche ruotate: "
                + d
                + "\nNumero di tacche precisamente ruotate: "
                + f;

        wheel_area.setText(g);
      }
Esempio n. 10
0
  public void print(final String line) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              ConsoleTab.this.print(line);
            }
          });
      return;
    }

    Document document = this.console.getDocument();
    JScrollBar scrollBar = getVerticalScrollBar();
    boolean shouldScroll = false;

    if (getViewport().getView() == this.console) {
      shouldScroll =
          scrollBar.getValue() + scrollBar.getSize().getHeight() + MONOSPACED.getSize() * 4
              > scrollBar.getMaximum();
    }
    try {
      document.insertString(document.getLength(), line, null);
    } catch (BadLocationException localBadLocationException) {
    }
    if (shouldScroll) scrollBar.setValue(2147483647);
  }
Esempio n. 11
0
 void finishConversion(File outFile, Date start) {
   isBusy = false;
   progressBar.setIndeterminate(false);
   Date end = new Date();
   textArea.append(
       format("Created %s in %s ms.%n", outFile.getPath(), end.getTime() - start.getTime()));
   JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
   scrollBar.setValue(scrollBar.getMaximum());
 }
Esempio n. 12
0
 @Override
 public void focusGained(FocusEvent fe) {
   if (-1 == table.getSelectedRow() && table.getRowCount() > 0) {
     table.setRowSelectionInterval(0, 0);
     JScrollBar scrollbar = scrollpane.getVerticalScrollBar();
     scrollbar.setValue(scrollbar.getMinimum());
   }
   if (-1 == table.getSelectedColumn()) {
     table.setColumnSelectionInterval(0, 0);
   }
 }
 protected void scrollToCorrectLocation() {
   JScrollBar verticalScrollBarForScrollPane = _scrollPaneAroundWidgetBox.getVerticalScrollBar();
   if ((_selection != null) && (_selection.getParent() != null)) {
     _selectionRectangle = _selection.getBounds();
     _selectionRectangle.y += (_selection.getParent()).getY();
     _viewport.scrollRectToVisible(_selectionRectangle);
     _viewport.repaint();
   } else {
     verticalScrollBarForScrollPane.setValue(0);
   }
   return;
 }
 public void showMessage(String message) {
   int x = frame.getX() + (frame.getWidth() - WIDTH) / 2,
       y = frame.getY() + (frame.getHeight() - HEIGHT) / 2;
   setLocation(x, y);
   textArea.append(message + "\n");
   int value = jsbar.getMaximum() - jsbar.getVisibleAmount();
   jsbar.setValue(value);
   repaint();
   if (!isVisible()) {
     setVisible(true);
   }
 }
Esempio n. 15
0
  public void scrollToBottom() {
    if (mousePressed) return;

    int lengthOfChat = transcriptWindow.getDocument().getLength();
    transcriptWindow.setCaretPosition(lengthOfChat);

    try {
      JScrollBar scrollBar = textScroller.getVerticalScrollBar();
      scrollBar.setValue(scrollBar.getMaximum());
    } catch (Exception e) {
    }
  }
 private boolean doHorizontalScrolling(Component c, MouseWheelEvent me) {
   final JScrollBar scrollBar = findHorizontalScrollBar(c);
   if (scrollBar != null) {
     if (scrollBar.hashCode() != myLastHorScrolledComponentHash) {
       FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.horizontal.scrolling");
       myLastHorScrolledComponentHash = scrollBar.hashCode();
     }
     scrollBar.setValue(scrollBar.getValue() + getScrollAmount(c, me, scrollBar));
     return true;
   }
   return false;
 }
Esempio n. 17
0
  public void setResultSet(DiskResultSet rset) throws Exception {
    set = rset;

    max = rset.getRowCount();

    table.setModel(model);
    table.setModel(this);

    offset = 0;
    scrollBar.setValue(0);
    scrollBar.setMaximum((max < window ? 0 : max - window));
  }
Esempio n. 18
0
 public void keyPressed(KeyEvent ke) {
   switch (ke.getKeyCode()) {
     case KeyEvent.VK_UP:
       JScrollBar scrollBar = viewerScrollPane.getVerticalScrollBar();
       scrollBar.setValue(scrollBar.getValue() - scrollBar.getUnitIncrement(-1));
       ke.consume();
       break;
     case KeyEvent.VK_DOWN:
       scrollBar = viewerScrollPane.getVerticalScrollBar();
       scrollBar.setValue(scrollBar.getValue() + scrollBar.getUnitIncrement(1));
       ke.consume();
       break;
     case KeyEvent.VK_LEFT:
       scrollBar = viewerScrollPane.getHorizontalScrollBar();
       scrollBar.setValue(scrollBar.getValue() - scrollBar.getUnitIncrement(-1));
       ke.consume();
       break;
     case KeyEvent.VK_RIGHT:
       scrollBar = viewerScrollPane.getHorizontalScrollBar();
       scrollBar.setValue(scrollBar.getValue() + scrollBar.getUnitIncrement(1));
       ke.consume();
       break;
   }
 }
Esempio n. 19
0
  private void addjButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addjButtonActionPerformed
    int fil, i, j;
    int temp = 0;
    Object nuevo[][];
    boolean flagEnd = false;

    fil = this.jTable1.getSelectedRow();
    if (fil == -1) {
      flagEnd = true;
      fil = this.tablaDataset.getData().length;
    } else {
      this.jTable1.removeRowSelectionInterval(fil, fil);
    }
    nuevo =
        new Object[this.tablaDataset.getData().length + 1][this.tablaDataset.getData()[0].length];
    for (i = 0; i < nuevo.length; i++) {
      for (j = 0; j < nuevo[i].length; j++) {
        if (i == fil && temp == 0) {
          temp++;
        }
        if (i == fil) {
          if (this.data.getAttributeTypeIndex(j).equalsIgnoreCase("nominal")) {
            nuevo[i][j] = new String("<null>");
          } else {
            nuevo[i][j] = null;
          }
        } else {
          nuevo[i][j] = this.tablaDataset.getData()[i - temp][j];
        }
      }
    }
    // Refresh
    this.tablaDataset.setData(nuevo);

    this.jTable1.setModel(this.tablaDataset);
    datajScrollPane.getViewport().remove(jTable1);
    datajScrollPane.getViewport().add(jTable1);

    if (flagEnd == true) {
      JScrollBar scroll = this.datajScrollPane.getVerticalScrollBar();
      scroll.setValue(scroll.getMaximum());
    }

    // Posible change in Table
    this.editVariablePanel.refreshVariablePanel(this.data);
  } // GEN-LAST:event_addjButtonActionPerformed
Esempio n. 20
0
 @Override
 public void insert(final String text, final int pos) {
   final ScrollableJTextArea pane = getDelegate();
   synchronized (getDelegateLock()) {
     final JTextArea area = pane.getView();
     final boolean doScroll =
         pos >= area.getDocument().getLength() && area.getDocument().getLength() != 0;
     area.insert(text, pos);
     revalidate();
     if (doScroll) {
       final JScrollBar vbar = pane.getVerticalScrollBar();
       if (vbar != null) {
         vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
       }
     }
   }
   repaintPeer();
 }
Esempio n. 21
0
  public void func_164247_a(
      final JTextArea p_164247_1_, final JScrollPane p_164247_2_, final String p_164247_3_) {
    try {
      latch.await();
    } catch (InterruptedException e) {
    } // Prevent logging until after constructor has ended.
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              MinecraftServerGui.this.func_164247_a(p_164247_1_, p_164247_2_, p_164247_3_);
            }
          });
    } else {
      Document document = p_164247_1_.getDocument();
      JScrollBar jscrollbar = p_164247_2_.getVerticalScrollBar();
      boolean flag = false;

      if (p_164247_2_.getViewport().getView() == p_164247_1_) {
        flag =
            (double) jscrollbar.getValue()
                    + jscrollbar.getSize().getHeight()
                    + (double) (serverGuiFont.getSize() * 4)
                > (double) jscrollbar.getMaximum();
      }

      try {
        document.insertString(document.getLength(), p_164247_3_, (AttributeSet) null);
      } catch (BadLocationException var8) {;
      }

      if (flag) {
        jscrollbar.setValue(Integer.MAX_VALUE);
      }
    }
  }
Esempio n. 22
0
    // {{{ restoreSelection() method
    public void restoreSelection(Set<String> savedChecked, Set<String> savedSelection) {
      for (int i = 0, c = getRowCount(); i < c; i++) {
        Object obj = filteredEntries.get(i);
        String name = obj.toString();
        if (obj instanceof Entry) {
          name = ((Entry) obj).plugin.jar;
        }
        if (pluginSet.contains(name)) setValueAt(true, i, 0);
        else setValueAt(savedChecked.contains(name), i, 0);
      }
      if (table == null) return;

      table.setColumnSelectionInterval(0, 0);
      if (!savedSelection.isEmpty()) {
        int i = 0;
        int rowCount = getRowCount();
        for (; i < rowCount; i++) {
          String name = filteredEntries.get(i).toString();
          if (savedSelection.contains(name)) {
            table.setRowSelectionInterval(i, i);
            break;
          }
        }
        ListSelectionModel lsm = table.getSelectionModel();
        for (; i < rowCount; i++) {
          String name = filteredEntries.get(i).toString();
          if (savedSelection.contains(name)) {
            lsm.addSelectionInterval(i, i);
          }
        }
      } else {
        if (table.getRowCount() != 0) table.setRowSelectionInterval(0, 0);
        JScrollBar scrollbar = scrollpane.getVerticalScrollBar();
        scrollbar.setValue(scrollbar.getMinimum());
      }
    } // }}}
 private void scrollDown() {
   final JScrollBar v = sp.getVerticalScrollBar();
   v.setValue(v.getMaximum() - v.getVisibleAmount());
 }
 @Override
 public void updateUIFromModel(Class<?> modelFieldClass, Object modelValue) {
   scrollBar.setValue(((Number) modelValue).intValue());
 }
Esempio n. 25
0
 public void clear() {
   table.setModel(model);
   offset = 0;
   scrollBar.setValue(0);
   scrollBar.setMaximum(0);
 }
Esempio n. 26
0
  /**
   * Scroll the vertical or horizontal scroll bar, if possible, using the given increment.
   *
   * @param increment The increment to apply on the vertical scroll bar.
   * @param vertical True: the vertical scroll bar is
   * @since 0.1
   */
  protected void scroll(final int increment, final boolean vertical) {
    final JScrollBar scrollbar = getScrollbar(vertical);

    if (scrollbar != null && scrollbar.isVisible())
      scrollbar.setValue(scrollbar.getValue() - increment);
  }
 private void scrollToTheLastList(JScrollPane scroll, ScrollTo to) {
   JScrollBar bar = scroll.getHorizontalScrollBar();
   bar.setValue(to.equals(ScrollTo.last) ? bar.getMaximum() : bar.getMinimum());
 }
Esempio n. 28
0
  private void initialize() {
    this.setSize(733, 515);
    this.setLayout(new BorderLayout());
    if (getContent() != null) {
      content = getContent();
      getJTextPane().setText(new String(content));
    }
    settings = PropertiesUtils.deserializeProperties(getSettings());
    applySettings();
    JScrollBar sb = getJScrollPane().getVerticalScrollBar();
    if (sb != null) {
      String val = settings.getProperty(PROPERTY_SCROLLBAR_VERT);
      if (val != null) {
        sb.setVisibleAmount(0);
        sb.setValue(sb.getMaximum());
        sb.setValue(Integer.valueOf(val));
      }
    }
    sb = getJScrollPane().getHorizontalScrollBar();
    if (sb != null) {
      String val = settings.getProperty(PROPERTY_SCROLLBAR_HORIZ);
      if (val != null) {
        sb.setVisibleAmount(0);
        sb.setValue(sb.getMaximum());
        sb.setValue(Integer.valueOf(val));
      }
    }
    String caretPos = settings.getProperty(PROPERTY_CARET_POSITION);
    if (!Validator.isNullOrBlank(caretPos)) {
      try {
        getJTextPane().setCaretPosition(Integer.valueOf(caretPos));
      } catch (IllegalArgumentException iae) {
        // ignore incorrect caret positioning
      }
    }
    getJTextPane().getDocument().addUndoableEditListener(new UndoRedoManager(jTextPane));
    getJTextPane()
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void changedUpdate(DocumentEvent e) {
                dataChanged();
              }

              public void insertUpdate(DocumentEvent e) {
                dataChanged();
              }

              public void removeUpdate(DocumentEvent e) {
                dataChanged();
              }

              private void dataChanged() {
                if (getJTextPane().isEditable()) {
                  contentChanged = true;
                }
              }
            });
    this.add(getJScrollPane(), BorderLayout.CENTER);
    this.add(getJToolBar(), BorderLayout.SOUTH);
  }