private void paintOnComponentUnderViewport(Component component, Graphics g) { JBViewport viewport = ObjectUtils.tryCast(myOwner, JBViewport.class); if (viewport == null || viewport.getView() != component || viewport.isPaintingNow()) return; // We're painting a component which has a viewport as it's ancestor. // As the viewport paints status text, we'll erase it, so we need to schedule a repaint for the viewport with status text's bounds. // But it causes flicker, so we paint status text over the component first and then schedule the viewport repaint. Rectangle textBoundsInViewport = getTextComponentBound(); int xInOwner = textBoundsInViewport.x - component.getX(); int yInOwner = textBoundsInViewport.y - component.getY(); Rectangle textBoundsInOwner = new Rectangle(xInOwner, yInOwner, textBoundsInViewport.width, textBoundsInViewport.height); doPaintStatusText(g, textBoundsInOwner); viewport.repaint(textBoundsInViewport); }
private MyListWrapper(final JList list) { super(UIUtil.isUnderAquaLookAndFeel() ? 0 : -1); JBViewport viewport = new JBViewport() { @Override protected LayoutManager createLayoutManager() { return new ViewportLayout() { @Override public Dimension preferredLayoutSize(Container parent) { int size = list.getModel().getSize(); if (size >= 0 && size <= 20) { return list.getPreferredSize(); } else { final Dimension sz = super.preferredLayoutSize(parent); final Point p = RelativePoint.getNorthWestOf(myList).getScreenPoint(); final Rectangle screen = ScreenUtil.getScreenRectangle(p); final int bordersEtc = 20; final int maxWidth = Math.abs(screen.x + screen.width - p.x) - 2 * bordersEtc; return new Dimension(Math.min(maxWidth, sz.width) + bordersEtc, sz.height + list.getCellBounds(0, 0).height / 2); } } }; } }; list.setVisibleRowCount(15); setViewport(viewport); setViewportView(list); if (myAutoselectOnMouseMove) { ListUtil.installAutoSelectOnMouseMove(list); } ScrollingUtil.installActions(list); setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); myList = list; }
private void repaintViewport() { if (!isDisplayable() || !isVisible()) return; Container p = getParent(); if (p instanceof JBViewport) { p.repaint(); } }
private MyListWrapper(final JList list) { super(UIUtil.isUnderAquaLookAndFeel() ? 0 : -1); JBViewport viewport = new JBViewport() { @Override protected LayoutManager createLayoutManager() { return new ViewportLayout() { @Override public Dimension preferredLayoutSize(Container parent) { int size = list.getModel().getSize(); if (size >= 0 && size <= 20) { return list.getPreferredSize(); } else { final Dimension sz = super.preferredLayoutSize(parent); final Point p = RelativePoint.getNorthWestOf(myList).getScreenPoint(); final Rectangle screen = ScreenUtil.getScreenRectangle(p); final int bordersEtc = 20; final int maxWidth = Math.abs(screen.x + screen.width - p.x) - 2 * bordersEtc; return new Dimension(Math.min(maxWidth, sz.width) + bordersEtc, sz.height + list.getCellBounds(0, 0).height / 2); } } }; } }; list.setVisibleRowCount(15); setViewport(viewport); setViewportView(list); if (myAutoselectOnMouseMove) { list.addMouseMotionListener(new MouseMotionAdapter() { boolean myIsEngaged = false; public void mouseMoved(MouseEvent e) { if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) { Point point = e.getPoint(); int index = list.locationToIndex(point); list.putClientProperty(SELECTED_BY_MOUSE_EVENT, Boolean.TRUE); list.setSelectedIndex(index); list.putClientProperty(SELECTED_BY_MOUSE_EVENT, Boolean.FALSE); } else { myIsEngaged = true; } } }); } ListScrollingUtil.installActions(list); setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); myList = list; }