private void recalculateMaxValues() { myIdxLeft = widestEditor(myLeftEditors); final Editor leftEditor = myLeftEditors.get(myIdxLeft); final int wholeWidth = leftEditor.getContentComponent().getWidth(); final Rectangle va = leftEditor.getScrollingModel().getVisibleArea(); final int visibleLeft = leftEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsLeft = (int) (visibleLeft * ((double) wholeWidth / va.getWidth())); myIdxRight = widestEditor(myRightEditors); final Editor rightEditor = myRightEditors.get(myIdxRight); final int wholeWidthRight = rightEditor.getContentComponent().getWidth(); final Rectangle vaRight = rightEditor.getScrollingModel().getVisibleArea(); final int visibleRight = rightEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsRight = (int) (visibleRight * ((double) wholeWidthRight / vaRight.getWidth())); myByLeft = !(myMaxColumnsLeft <= visibleLeft); if (!myByLeft) { // check right editor if (myLeftScroll.getVisibleAmount() != visibleRight) { myLeftScroll.setVisibleAmount(visibleRight); } myLeftScroll.setMaximum(myMaxColumnsRight); } else { if (myLeftScroll.getVisibleAmount() != visibleLeft) { myLeftScroll.setVisibleAmount(visibleLeft); } myLeftScroll.setMaximum(myMaxColumnsLeft); } }
/** * @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 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
public void toChatScreen(String toScreen, boolean selfSeen) throws IOException, BadLocationException { // Timestamp ts = new Timestamp(); String toScreenFinal = ""; Date now = Calendar.getInstance().getTime(); SimpleDateFormat format = new SimpleDateFormat("hh:mm"); String ts = format.format(now); // chatScreen.append(ts + " " + toScreen + "\n"); toScreenFinal = "<font color=gray>" + ts + "</font> "; if (selfSeen) toScreenFinal = toScreenFinal + "<font color=red>" + toScreen + "</font>"; else toScreenFinal = toScreenFinal + toScreen; // chatter.addTo(toScreen); // if(standardWindow) { // chatScreen.setCaretPosition(chatScreen.getDocument().getLength()); // } // else { JScrollBar vBar = scrollChat.getVerticalScrollBar(); int vSize = vBar.getVisibleAmount(); int maxVBar = vBar.getMaximum(); int currVBar = vBar.getValue() + vSize; kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null); if (maxVBar == currVBar) { chatScreen.setCaretPosition(chatScreen.getDocument().getLength()); } // } // kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null); }
/** * This method is used to append a line of text to be displayed. * * @param text Is the text to be apppended */ private void append(final String text) { this.textArea.append(text); JScrollBar vertBar = this.scrollPane.getVerticalScrollBar(); if (vertBar.getValue() == vertBar.getMaximum() - vertBar.getVisibleAmount()) { this.autoscroll = true; } }
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); } }
public void ecrire(String s) { JScrollBar scroll = jScrollPane1.getVerticalScrollBar(); scrollMax = scroll.getMaximum(); scrollVisible = scroll.isShowing(); if (scroll.getValue() + scroll.getVisibleAmount() == scrollMax) { // enBas = false; scrollAuto = true; // scrollMax = scroll.getMaximum(); } else { enBas = false; scrollAuto = false; } HTMLDocument d = (HTMLDocument) afficheurHTML.getStyledDocument(); Element a = d.getParagraphElement(1); // Element a=d.getElement("conversation"); try { if (!vide) { d.insertBeforeEnd(a, "<br />" + s); } else { d.insertBeforeEnd(a, s); vide = false; } } catch (BadLocationException | IOException ex) { Logger.getLogger(FenetreJeu.class.getName()).log(Level.SEVERE, null, ex); } /* * if (enBas) { while (scroll.getMaximum() == scrollMax) { try { * Thread.sleep(5); * * * } catch (InterruptedException ex) { * Logger.getLogger(FenetreJeu.class.getName()).log(Level.SEVERE, null, * ex); } } scroll.setValue(scroll.getMaximum() - * scroll.getVisibleAmount()); } */ /* * if (jScrollPane1.getVerticalScrollBar().getValue() == * jScrollPane1.getVerticalScrollBar().getMaximum()) { * afficheurHTML.setCaretPosition(afficheurHTML.getDocument().getLength()); * } */ // System.out.println(afficheurHTML.getText()); // System.out.println(jScrollPane1.getVerticalScrollBar().getMaximum()); }
@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(); }
private void displayMessages(boolean friendSignedOff) { String chatDoc = ChatDocumentBuilder.buildChatText( messages, currentChatState, conversationName, friendSignedOff); LOG.debugf("Chat doc: {0}", chatDoc); final JScrollBar verticalScrollBar = conversationScroll.getVerticalScrollBar(); final int scrollValue = verticalScrollBar.getValue(); editor.setText(chatDoc); // LWC-2262: If the scroll bar was moved above the bottom of the scrollpane, reset the value of // the bar to where it was before the text was updated. This needs to be issued to the end of // the // queue because the actual repainting/resizing of the scrollbar happens later in a // task added to the EDT by the plaf listener of the editor's document. // A better fix for this behavior may be possible if (verticalScrollBar.getMaximum() > (scrollValue + verticalScrollBar.getVisibleAmount() + PADDING)) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { verticalScrollBar.setValue(scrollValue); } }); } else { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { verticalScrollBar.setValue(verticalScrollBar.getMaximum()); } }); } decorateFileOfferButtons(); chatWrapper.repaint(); }
protected void layoutHScrollbar(JScrollBar sb) { if (AbstractLookAndFeel.getTheme().isLinuxStyleScrollBarOn()) { Dimension sbSize = sb.getSize(); Insets sbInsets = sb.getInsets(); int sizeW = sbSize.width - sbInsets.left - sbInsets.right; /* * Height and top edge of the buttons and thumb. */ int itemY = sbInsets.top; int itemH = sbSize.height - (sbInsets.top + sbInsets.bottom); // Math.min(itemW, sizeH / 2); int itemW = Math.min(itemH, sizeW / 2); // sbSize.width - (sbInsets.left + sbInsets.right); /* Nominal locations of the buttons, assuming their preferred * size will fit. */ int decrButtonX = sbSize.width - sbInsets.right - itemW - itemW + 1; int incrButtonX = sbSize.width - sbInsets.right - itemW; /* Compute the width and origin of the thumb. The case * where the thumb is at the right edge is handled specially * to avoid numerical problems in computing thumbX. Enforce * the thumbs min/max dimensions. If the thumb doesn't * fit in the track (trackW) we'll hide it later. */ float trackW = sbSize.width - sbInsets.left - sbInsets.right - itemH - itemH + 1; float min = sb.getMinimum(); float max = sb.getMaximum(); float extent = sb.getVisibleAmount(); float range = max - min; float value = sb.getValue(); int maxThumbW = getMaximumThumbSize().width; int minThumbW = getMinimumThumbSize().width; int thumbW = (range <= 0) ? maxThumbW : (int) (trackW * (extent / range)); thumbW = Math.max(thumbW, minThumbW); thumbW = Math.min(thumbW, maxThumbW); int thumbX = decrButtonX - thumbW; if (value < (max - extent)) { float thumbRange = trackW - thumbW; thumbX = (int) (0.5f + (thumbRange * ((value - min) / (range - extent)))); } /* If the thumb isn't going to fit, zero it's bounds. Otherwise * make sure it fits between the buttons. Note that setting the * thumbs bounds will cause a repaint. */ if (thumbW > trackW) { setThumbBounds(0, 0, 0, 0); } else { setThumbBounds(thumbX, itemY, thumbW, itemH); } decrButton.setBounds(decrButtonX, itemY, itemW, itemH); incrButton.setBounds(incrButtonX, itemY, itemW, itemH); /* Update the trackRect field. */ trackRect.setBounds(0, itemY, (int) trackW, itemH); } else { super.layoutHScrollbar(sb); } }
protected void alternateLayoutVScrollbar(JScrollBar sb) { Dimension sbSize = sb.getSize(); Insets sbInsets = sb.getInsets(); /* * Width and left edge of the buttons and thumb. */ int itemW = sbSize.width - (sbInsets.left + sbInsets.right); int itemX = sbInsets.left; /* Nominal locations of the buttons, assuming their preferred * size will fit. */ int incrButtonH = incrButton.getPreferredSize().height; int incrButtonY = sbSize.height - (sbInsets.bottom + incrButtonH); int decrButtonH = decrButton.getPreferredSize().height; int decrButtonY = incrButtonY - decrButtonH; /* The thumb must fit within the height left over after we * subtract the preferredSize of the buttons and the insets. */ int sbInsetsH = sbInsets.top + sbInsets.bottom; int sbButtonsH = decrButtonH + incrButtonH; float trackH = sbSize.height - (sbInsetsH + sbButtonsH); /* Compute the height and origin of the thumb. The case * where the thumb is at the bottom edge is handled specially * to avoid numerical problems in computing thumbY. Enforce * the thumbs min/max dimensions. If the thumb doesn't * fit in the track (trackH) we'll hide it later. */ float min = sb.getMinimum(); float extent = sb.getVisibleAmount(); float range = sb.getMaximum() - min; float value = sb.getValue(); int thumbH = (range <= 0) ? getMaximumThumbSize().height : (int) (trackH * (extent / range)); thumbH = Math.max(thumbH, getMinimumThumbSize().height); thumbH = Math.min(thumbH, getMaximumThumbSize().height); int thumbY = decrButtonY - thumbH; // incrButtonY - thumbH; if (sb.getValue() < (sb.getMaximum() - sb.getVisibleAmount())) { float thumbRange = trackH - thumbH; thumbY = (int) (0.5f + (thumbRange * ((value - min) / (range - extent)))); // thumbY += decrButtonY + decrButtonH; } /* If the buttons don't fit, allocate half of the available * space to each and move the lower one (incrButton) down. */ int sbAvailButtonH = (sbSize.height - sbInsetsH); if (sbAvailButtonH < sbButtonsH) { incrButtonH = decrButtonH = sbAvailButtonH / 2; incrButtonY = sbSize.height - (sbInsets.bottom + incrButtonH); } decrButton.setBounds(itemX, decrButtonY, itemW, decrButtonH); incrButton.setBounds(itemX, incrButtonY, itemW, incrButtonH); /* Update the trackRect field. */ int itrackY = sbInsets.top; int itrackH = decrButtonY - itrackY; trackRect.setBounds(itemX, itrackY, itemW, itrackH); /* If the thumb isn't going to fit, zero it's bounds. Otherwise * make sure it fits between the buttons. Note that setting the * thumbs bounds will cause a repaint. */ if (thumbH >= (int) trackH) { setThumbBounds(0, 0, 0, 0); } else { if ((thumbY + thumbH) > decrButtonY) { thumbY = decrButtonY - thumbH; } /* if (thumbY < (decrButtonY + decrButtonH)) { thumbY = decrButtonY + decrButtonH + 1; }*/ setThumbBounds(itemX, thumbY, itemW, thumbH); } }
protected void alternateLayoutHScrollbar(JScrollBar sb) { Dimension sbSize = sb.getSize(); Insets sbInsets = sb.getInsets(); /* Height and top edge of the buttons and thumb. */ int itemH = sbSize.height - (sbInsets.top + sbInsets.bottom); int itemY = sbInsets.top; /* Nominal locations of the buttons, assuming their preferred * size will fit. */ int incrButtonW = incrButton.getPreferredSize().width; int incrButtonX = sbSize.width - (sbInsets.right + incrButtonW); int decrButtonW = decrButton.getPreferredSize().width; int decrButtonX = incrButtonX - decrButtonW; /* The thumb must fit within the width left over after we * subtract the preferredSize of the buttons and the insets. */ int sbInsetsW = sbInsets.left + sbInsets.right; int sbButtonsW = decrButtonW + incrButtonW; float trackW = sbSize.width - (sbInsetsW + sbButtonsW); /* Compute the width and origin of the thumb. Enforce * the thumbs min/max dimensions. The case where the thumb * is at the right edge is handled specially to avoid numerical * problems in computing thumbX. If the thumb doesn't * fit in the track (trackH) we'll hide it later. */ float min = sb.getMinimum(); float extent = sb.getVisibleAmount(); float range = sb.getMaximum() - min; float value = sb.getValue(); int thumbW = (range <= 0) ? getMaximumThumbSize().width : (int) (trackW * (extent / range)); thumbW = Math.max(thumbW, getMinimumThumbSize().width); thumbW = Math.min(thumbW, getMaximumThumbSize().width); int thumbX = decrButtonX - thumbW; if (sb.getValue() < (sb.getMaximum() - sb.getVisibleAmount())) { float thumbRange = trackW - thumbW; thumbX = (int) (0.5f + (thumbRange * ((value - min) / (range - extent)))); // thumbX += decrButtonX + decrButtonW; } /* If the buttons don't fit, allocate half of the available * space to each and move the right one (incrButton) over. */ int sbAvailButtonW = (sbSize.width - sbInsetsW); if (sbAvailButtonW < sbButtonsW) { incrButtonW = decrButtonW = sbAvailButtonW / 2; incrButtonX = sbSize.width - (sbInsets.right + incrButtonW); } decrButton.setBounds(decrButtonX, itemY, decrButtonW, itemH); incrButton.setBounds(incrButtonX, itemY, incrButtonW, itemH); /* Update the trackRect field. */ int itrackX = sbInsets.left; // decrButtonX + decrButtonW; int itrackW = decrButtonX - itrackX; trackRect.setBounds(itrackX, itemY, itrackW, itemH); /* Make sure the thumb fits between the buttons. Note * that setting the thumbs bounds causes a repaint. */ if (thumbW >= (int) trackW) { setThumbBounds(0, 0, 0, 0); } else { if (thumbX + thumbW > incrButtonX) { thumbX = incrButtonX - thumbW; } /*if (thumbX < decrButtonX + decrButtonW) { thumbX = decrButtonX + decrButtonW + 1; }*/ setThumbBounds(thumbX, itemY, thumbW, itemH); } }
private Rectangle getClip() { JScrollBar hsb = scrollPane.getHorizontalScrollBar(); JScrollBar vsb = scrollPane.getVerticalScrollBar(); return new Rectangle( hsb.getValue(), vsb.getValue(), hsb.getVisibleAmount(), vsb.getVisibleAmount()); }
private void scrollDown() { final JScrollBar v = sp.getVerticalScrollBar(); v.setValue(v.getMaximum() - v.getVisibleAmount()); }