/** * Update the visibility of the buttons Only show them if the Viewport is too small for the * content. */ public void showOrHideButtons() { boolean needButtons = vp.getViewSize().height > vp.getViewRect().height || vp.getViewSize().width > vp.getViewRect().width; for (JButton b : buttons) { b.setVisible(needButtons); } }
/** Move a block it's prior location to the drop location */ @Override public boolean importData(TransferSupport supp) { if (canImport(supp)) { IconList list = (IconList) supp.getComponent().getParent().getParent().getParent(); JViewport panel = (JViewport) supp.getComponent().getParent(); try { Transferable t = supp.getTransferable(); int from = (int) t.getTransferData(DataFlavor.imageFlavor); list.move( from, (int) (Math.ceil( supp.getDropLocation().getDropPoint().getX() * list.length() / panel.getViewSize().getWidth() - 1)), false); } catch (Exception e) { e.printStackTrace(); return false; } return true; } return false; }
@Override public void layoutContainer(Container parent) { if (linkedViewPort == null) { super.layoutContainer(parent); } else { JViewport vp = (JViewport) parent; Component view = vp.getView(); if (view != null) { Point p = linkedViewPort.getViewPosition(); Dimension size = linkedViewPort.getViewSize(); if (horizontalLink) { p.y = 0; size.height = vp.getExtentSize().height; } else { p.x = 0; size.width = vp.getExtentSize().width; } vp.setViewPosition(p); vp.setViewSize(size); } } }
public void scrollToLine(FilePanel fp, int line) { JScrollPane scrollPane; FilePanel fp2; BufferDocumentIF bd; JTextComponent editor; JViewport viewport; Rectangle rect; int offset; Point p; Rectangle viewRect; Dimension viewSize; Dimension extentSize; int x; fp2 = fp == filePanelLeft ? filePanelRight : filePanelLeft; bd = fp.getBufferDocument(); if (bd == null) { return; } offset = bd.getOffsetForLine(line); if (offset < 0) { return; } viewport = fp.getScrollPane().getViewport(); editor = fp.getEditor(); try { rect = editor.modelToView(offset); if (rect == null) { return; } p = rect.getLocation(); p.y -= getHeightOffset(fp); p.y += getCorrectionOffset(fp2); // Do not allow scrolling before the begin. if (p.y < 0) { p.y = 0; } // Do not allow scrolling after the end. viewSize = viewport.getViewSize(); viewRect = viewport.getViewRect(); extentSize = viewport.getExtentSize(); if (p.y > viewSize.height - extentSize.height) { p.y = viewSize.height - extentSize.height; } p.x = viewRect.x; viewport.setViewPosition(p); } catch (Exception ex) { ex.printStackTrace(); } }
public void captureDecorated() { JViewport view = gui.graphComponent.getViewport(); Point currentPos = view.getViewPosition(); view.setViewPosition(new Point(0, 0)); // We have to do that otherwise, top left is not painted Dimension size = view.getViewSize(); BufferedImage image = (BufferedImage) view.createImage(size.width, size.height); Graphics2D captureG = image.createGraphics(); view.paintComponents(captureG); view.setViewPosition(currentPos); ImagePlus imp = new ImagePlus("TrackScheme capture", image); imp.show(); }
public void stateChanged(ChangeEvent e) { JViewport viewport = (JViewport) e.getSource(); int tabPlacement = tabPane.getTabPlacement(); int tabCount = tabPane.getTabCount(); Rectangle vpRect = viewport.getBounds(); Dimension viewSize = viewport.getViewSize(); Rectangle viewRect = viewport.getViewRect(); leadingTabIndex = getClosestTab(viewRect.x, viewRect.y); // If the tab isn't right aligned, adjust it. if (leadingTabIndex + 1 < tabCount) { if (rects[leadingTabIndex].x < viewRect.x) { leadingTabIndex++; } } Insets contentInsets = getContentBorderInsets(tabPlacement); tabPane.repaint(vpRect.x, vpRect.y + vpRect.height, vpRect.width, contentInsets.top); scrollBackwardButton.setEnabled(viewRect.x > 0); scrollForwardButton.setEnabled( leadingTabIndex < tabCount - 1 && viewSize.width - viewRect.x > viewRect.width); }
public Dimension getViewSize() { return vp.getViewSize(); }