Java Examples for javax.swing.JViewport

The following java examples will help you to understand the usage of javax.swing.JViewport. These source code samples are taken from different open source projects.

Example 1
Project: jeboorker-master  File: HeaderlessColumnResizer.java View source code
public void mouseDragged(MouseEvent e) {
    int mouseX = e.getX();
    TableColumn resizingColumn = table.getTableHeader().getResizingColumn();
    boolean headerLeftToRight = table.getTableHeader().getComponentOrientation().isLeftToRight();
    if (resizingColumn != null) {
        int oldWidth = resizingColumn.getWidth();
        int newWidth;
        if (headerLeftToRight) {
            newWidth = mouseX - mouseXOffset;
        } else {
            newWidth = mouseXOffset - mouseX;
        }
        resizingColumn.setWidth(newWidth);
        Container container;
        if ((table.getTableHeader().getParent() == null) || ((container = table.getTableHeader().getParent().getParent()) == null) || !(container instanceof JScrollPane)) {
            return;
        }
        if (!container.getComponentOrientation().isLeftToRight() && !headerLeftToRight) {
            if (table != null) {
                JViewport viewport = ((JScrollPane) container).getViewport();
                int viewportWidth = viewport.getWidth();
                int diff = newWidth - oldWidth;
                int newHeaderWidth = table.getWidth() + diff;
                /* Resize a table */
                Dimension tableSize = table.getSize();
                tableSize.width += diff;
                table.setSize(tableSize);
                /*
           * If this table is in AUTO_RESIZE_OFF mode and has a horizontal
           * scrollbar, we need to update a view's position.
           */
                if ((newHeaderWidth >= viewportWidth) && (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                    Point p = viewport.getViewPosition();
                    p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                    viewport.setViewPosition(p);
                    /* Update the original X offset value. */
                    mouseXOffset += diff;
                }
            }
        }
    }
}
Example 2
Project: lar_361-master  File: PosTable.java View source code
public void growScrollbars() {
    // fatter scroll bars
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(30, 0));
            scrollPane.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 30));
        }
    }
}
Example 3
Project: glug-master  File: TimelineViewportTest.java View source code
@Test
public void shouldMoveViewSoThatInstantIsAtRequiredLocationInViewport() {
    UITimeScale uiTimeScale = new UITimeScale();
    uiTimeScale.setFullInterval(new Interval(4000, 7000));
    uiTimeScale.setMillisecondsPerPixel(100);
    JViewport viewport = new JViewport();
    viewport.setView(viewOfSize(new Dimension(10000, 100)));
    viewport.setExtentSize(new Dimension(1000, 100));
    viewport.setViewPosition(new Point(3000, 0));
    TimelineViewport timelineViewport = new TimelineViewport(uiTimeScale, viewport);
    Instant instant = new Instant(5000);
    timelineViewport.setViewPosition(instant, 200);
    assertThat(timelineViewport.getViewportCoordinateFor(instant), equalTo(200));
}
Example 4
Project: ismp_manager-master  File: TableUtil.java View source code
public static final JComponent addTable(JComponent component, TableModel model) {
    JScrollPane pane = new JScrollPane();
    component.setLayout(new BorderLayout());
    JTable t = getTable();
    t.setModel(model);
    JViewport viewport = pane.getViewport();
    viewport.add(t.getTableHeader(), BorderLayout.PAGE_START);
    viewport.add(t, BorderLayout.CENTER);
    component.add(pane);
    return component;
}
Example 5
Project: josm-master  File: ImageMarker.java View source code
@Override
public void actionPerformed(ActionEvent ev) {
    final JPanel p = new JPanel(new BorderLayout());
    final JScrollPane scroll = new JScrollPane(new JLabel(loadScaledImage(imageUrl, 580)));
    final JViewport vp = scroll.getViewport();
    p.add(scroll, BorderLayout.CENTER);
    final JToggleButton scale = new JToggleButton(ImageProvider.get("misc", "rectangle"));
    JPanel p2 = new JPanel();
    p2.add(scale);
    p.add(p2, BorderLayout.SOUTH);
    scale.addActionListener( ev1 -> {
        p.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        if (scale.getModel().isSelected()) {
            ((JLabel) vp.getView()).setIcon(loadScaledImage(imageUrl, Math.max(vp.getWidth(), vp.getHeight())));
        } else {
            ((JLabel) vp.getView()).setIcon(new ImageIcon(imageUrl));
        }
        p.setCursor(Cursor.getDefaultCursor());
    });
    scale.setSelected(true);
    JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE);
    if (!GraphicsEnvironment.isHeadless()) {
        JDialog dlg = pane.createDialog(Main.parent, imageUrl.toString());
        dlg.setModal(false);
        dlg.toFront();
        dlg.setVisible(true);
    }
}
Example 6
Project: platypus-master  File: ScalableComboPopup.java View source code
public void onInstall() {
    JViewport viewport = scroller.getViewport();
    if (viewport != null) {
        Component lview = viewport.getView();
        if (lview != null && lview instanceof JComponent) {
            JComponent ljcview = (JComponent) lview;
            oldOpaque = ljcview.isOpaque();
            ljcview.setOpaque(false);
        }
    }
}
Example 7
Project: servoy-client-master  File: RuntimePortal.java View source code
public void setScroll(int x, int y) {
    if (jComponent != null) {
        Rectangle rect = new Rectangle(x, y, getComponent().getSize().width, getComponent().getSize().height);
        if (jComponent.getParent() instanceof JViewport) {
            // you cannot ask for a region bigger then the actual view extent size to be visible - that would have no effect in some cases;
            // but if you want x and y to be the coordinates where the visible area starts (if that is possible) then a rectangle the same size as the visible area must be used
            Dimension s = ((JViewport) jComponent.getParent()).getExtentSize();
            rect.width = s.width;
            rect.height = s.height;
        }
        jComponent.scrollRectToVisible(rect);
    }
}
Example 8
Project: colossus-titan-master  File: KDialog.java View source code
/**
     * Place dialog relative to parentFrame's origin, offset by
     * point, and fully on-screen.
     */
public void placeRelative(JFrame parentFrame, Point point, JScrollPane pane) {
    JViewport viewPort = pane.getViewport();
    // Absolute coordinate in the screen since the window is toplevel
    Point parentOrigin = parentFrame.getLocation();
    // Relative coordinate of the view, change when scrolling
    Point viewOrigin = viewPort.getViewPosition();
    Point origin = new Point(point.x + parentOrigin.x - viewOrigin.x, point.y + parentOrigin.y - viewOrigin.y);
    setLocation(origin);
}
Example 9
Project: SubTools-master  File: ZebraJTable.java View source code
/** Force the table to fill the viewport's height. */
public boolean getScrollableTracksViewportHeight() {
    final java.awt.Component p = getParent();
    /**
     * if ( !(p instanceof javax.swing.JViewport) ) return false; return
     * ((javax.swing.JViewport)p).getHeight() > getPreferredSize().height;
     **/
    Dimension preferredSize = getPreferredSize();
    if (preferredSize == null)
        return false;
    return p instanceof javax.swing.JViewport && p.getHeight() > preferredSize.height;
}
Example 10
Project: importlist-master  File: JCustomScrollPaneTest.java View source code
@Test
public void testAddNotify() {
    this.customScrollPane.setColumnHeader(null);
    this.customScrollPane.setViewport(null);
    this.customScrollPane.addNotify();
    this.customScrollPane.setColumnHeader(new JViewport());
    this.customScrollPane.setViewport(null);
    this.customScrollPane.addNotify();
    Assert.assertSame("background color must match", this.customScrollPane.getBackground(), this.customScrollPane.getColumnHeader().getBackground());
    this.customScrollPane.setColumnHeader(null);
    this.customScrollPane.setViewport(new JViewport());
    this.customScrollPane.addNotify();
    this.customScrollPane.setColumnHeader(new JViewport());
    this.customScrollPane.setViewport(new JViewport());
    this.customScrollPane.addNotify();
    Assert.assertSame("background color must match", this.customScrollPane.getBackground(), this.customScrollPane.getColumnHeader().getBackground());
}
Example 11
Project: jabref-2.9.2-master  File: MyEditorKit.java View source code
public void actionPerformed(ActionEvent e) {
    JTextComponent c = getTextComponent(e);
    if (c.getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) c.getParent();
        Point p = viewport.getViewPosition();
        if (this.direction == SwingConstants.NORTH) {
            c.setCaretPosition(c.viewToModel(p));
        } else {
            p.y += viewport.getExtentSize().height;
            c.setCaretPosition(c.viewToModel(p));
        }
    }
    textActn.actionPerformed(e);
}
Example 12
Project: monsiaj-master  File: Fixed.java View source code
public void focusGained(FocusEvent e) {
    final int FOCUS_MARGIN = 10;
    Component parent;
    parent = this.getParent();
    if (parent != null && parent instanceof JViewport) {
        Rectangle childRect = e.getComponent().getBounds();
        Rectangle viewRect = ((JViewport) parent).getViewRect();
        Point p = ((JViewport) parent).getViewPosition();
        int childTop = (int) childRect.getY();
        int childBottom = (int) (childRect.getY() + childRect.getHeight());
        int childLeft = (int) childRect.getX();
        int childRight = (int) (childRect.getX() + childRect.getWidth());
        int viewTop = (int) viewRect.getY();
        int viewBottom = (int) (viewRect.getY() + viewRect.getHeight());
        int viewLeft = (int) viewRect.getX();
        int viewRight = (int) (viewRect.getX() + viewRect.getWidth());
        int viewHeight = (int) viewRect.getHeight();
        int viewWidth = (int) viewRect.getWidth();
        int thisBottom = (int) this.getHeight();
        int thisRight = (int) this.getWidth();
        if (childTop < viewTop) {
            if (childTop - FOCUS_MARGIN < 0) {
                p.move((int) p.getX(), 0);
            } else {
                p.move((int) p.getX(), childTop - FOCUS_MARGIN);
            }
            ((JViewport) parent).setViewPosition(p);
        }
        if (childBottom > viewBottom) {
            if (childBottom + FOCUS_MARGIN > thisBottom) {
                p.move((int) p.getX(), childBottom - viewHeight);
            } else {
                p.move((int) p.getX(), childBottom + FOCUS_MARGIN - viewHeight);
            }
            ((JViewport) parent).setViewPosition(p);
        }
        if (childLeft < viewLeft) {
            if (childLeft - FOCUS_MARGIN < 0) {
                p.move(0, (int) p.getY());
            } else {
                p.move(childLeft - FOCUS_MARGIN, (int) p.getY());
            }
            ((JViewport) parent).setViewPosition(p);
        }
        if (childRight > viewRight) {
            if (childRight + FOCUS_MARGIN > thisRight) {
                p.move(childRight - viewWidth, (int) p.getY());
            } else {
                p.move(childRight + FOCUS_MARGIN - viewWidth, (int) p.getY());
            }
            ((JViewport) parent).setViewPosition(p);
        }
    }
}
Example 13
Project: svarog-master  File: NewArtifactExclusionTable.java View source code
@Override
protected void configureEnclosingScrollPane() {
    super.configureEnclosingScrollPane();
    TableModel model = getModel();
    if (!(model instanceof NewArtifactExclusionTableModel)) {
        return;
    }
    NewArtifactExclusionTableModel artifactExclusionTableModel = (NewArtifactExclusionTableModel) model;
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.setColumnHeaderView(new ColumnHeaderTable(artifactExclusionTableModel.getColumnTableModel()));
            scrollPane.setRowHeaderView(new RowHeaderTable(artifactExclusionTableModel.getRowTableModel()));
            scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, new CornerPanel());
        }
    }
}
Example 14
Project: windowtester-master  File: JTreeTest.java View source code
/*	public void testTreeSelections() throws WidgetSearchException {
		
		IWidgetLocator locator;
		
		locator = ui.click(new JTreeItemLocator("Root/Parent1/Child10/grandChild102",
					new WidgetLocator(JViewport.class,new WidgetLocator(JScrollPane.class,"scrollPane1"))));
	
		tree = (JTree)((IWidgetReference)locator).getWidget();
		TreePath path = tree.getSelectionPath();
		int[] items = tree.getSelectionRows();
		assertEquals(1, items.length);
		assertEquals("grandChild102", path.getLastPathComponent().toString());
		
		ui.click(new JTreeItemLocator("Root/Parent3/Child30",
				new WidgetLocator(JViewport.class,new WidgetLocator(JScrollPane.class,"scrollPane1"))));
		path = tree.getSelectionPath();
		items = tree.getSelectionRows();
		assertEquals(1, items.length);
		assertEquals("Child30", path.getLastPathComponent().toString());

	}	
	
*/
public void testTreeShiftSelections() throws WidgetSearchException {
    ui.wait(new WindowShowingCondition("Swing Tree Example"));
    // tree selections
    tree = doTreeClick(1, "Root/Parent1/Child10/grandChild102", "scrollPane1", InputEvent.BUTTON1_MASK);
    TreePath path = tree.getSelectionPath();
    int[] items = tree.getSelectionRows();
    assertEquals(1, items.length);
    assertEquals("grandChild102", path.getLastPathComponent().toString());
    doTreeClick(1, "Root/Parent3/Child30", "scrollPane1", InputEvent.BUTTON1_MASK);
    path = tree.getSelectionPath();
    items = tree.getSelectionRows();
    assertEquals(1, items.length);
    assertEquals("Child30", path.getLastPathComponent().toString());
    // test shift clicks
    tree = doTreeClick(1, "Root/Item 0/Node 01", "scrollPane2", InputEvent.BUTTON1_MASK);
    doTreeClick(1, "Root/Item 1/Node 10", "scrollPane2", InputEvent.BUTTON1_MASK | InputEvent.SHIFT_MASK);
    TreePath[] paths = tree.getSelectionPaths();
    assertEquals(3, paths.length);
/*		IWidgetLocator locator;
		locator = ui.click(new JTreeItemLocator("Root/Item 0/Node 01",
				new WidgetLocator(JViewport.class,new WidgetLocator(JScrollPane.class,"scrollPane2"))));
		ui.click(1,new JTreeItemLocator("Root/Item 1/Node 10",
				new WidgetLocator(JViewport.class,new WidgetLocator(JScrollPane.class,"scrollPane2"))),
				InputEvent.BUTTON1_MASK | InputEvent.SHIFT_MASK);
		
		tree = (JTree)((IWidgetReference)locator).getWidget();
		TreePath[] paths = tree.getSelectionPaths();
		assertEquals(3, paths.length);
*/
//fail("need to confirm items match too");
//	}
//	public void testTreeCtrlSelections() throws WidgetSearchException {
// test cntrl clicks
//		IWidgetLocator locator;
/*		locator = ui.click(new JTreeItemLocator("Root/Parent1/Child10/grandChild100",
				new WidgetLocator(JViewport.class,new WidgetLocator(JScrollPane.class,"scrollPane1"))));
		ui.click(1,new JTreeItemLocator("Root/Parent1/Child10/grandChild102",
				new WidgetLocator(JViewport.class,new WidgetLocator(JScrollPane.class,"scrollPane1"))),
				InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK);

		tree = (JTree)((IWidgetReference)locator).getWidget();
//		TreePath[] paths = tree.getSelectionPaths();
		paths = tree.getSelectionPaths();
		assertEquals(2, paths.length);		
*/
//fail("need to confirm items match too");
}
Example 15
Project: SwingBox-master  File: ViewportView.java View source code
private void hook() {
    Container container = getContainer();
    Container parentContainer;
    if (container != null && (container instanceof javax.swing.JEditorPane) && (parentContainer = container.getParent()) != null && (parentContainer instanceof javax.swing.JViewport)) {
        editor = (JEditorPane) container;
        // our parent is a JScrollPane (JViewPort)
        JViewport viewPort = (JViewport) parentContainer;
        Object cachedObject;
        if (cachedViewPort != null) {
            if ((cachedObject = cachedViewPort.get()) != null) {
                if (cachedObject != viewPort) {
                    // parent is different from previous, remove listener
                    ((JComponent) cachedObject).removeComponentListener(this);
                }
            } else {
                // parent has been garbage-collected
                cachedViewPort = null;
            }
        }
        if (cachedViewPort == null) {
            // hook it
            viewPort.addComponentListener(this);
            cachedViewPort = new WeakReference<JViewport>(viewPort);
        }
    // System.err.println("Hooked at : " + viewPort.getExtentSize());
    // checkSize(viewPort.getExtentSize());
    } else {
        unhook();
    }
}
Example 16
Project: assertj-swing-master  File: Scrolling.java View source code
/**
   * Returns a {@code JComponent}'s closest validating root ancestor in the AWT containment hierarchy.
   * 
   * @param c the given {@code JComponent}.
   * @return the found ancestor or {@code null} if there isn't one.
   */
@Nullable
private static JComponent findClosestValidatingRootAncestor(@Nonnull JComponent c) {
    // the candidate validating root at every iteration (candidate = not necessarily a root)
    Container root = c;
    // we go up to the top of the hierarchy
    while (root != null) {
        Container parent = root.getParent();
        // the new candidate root becomes the parent of the previous one
        root = parent;
        // if the candidate isn't a JComponent, we're not interested in it (we need JComponent#scrollRectToVisible)
        if (!(root instanceof JComponent)) {
            continue;
        }
        // we don't have to take JFrame into account, it's not a JComponent (ant it's a top-level container anyway)
        if (root instanceof JViewport || root instanceof JInternalFrame) {
            return (JComponent) root;
        }
    }
    return null;
}
Example 17
Project: BioPano-master  File: SchemaGraphComponent.java View source code
/**
	 * 
	 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
    Component[] c = components.get(terminal.getCell());
    int y = 0;
    if (c != null) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof JTableRenderer) {
                JTableRenderer vertex = (JTableRenderer) c[i];
                JTable table = vertex.table;
                JViewport viewport = (JViewport) table.getParent();
                double dy = -viewport.getViewPosition().getY();
                y = (int) Math.max(terminal.getY() + 22, terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
            }
        }
    }
    return y;
}
Example 18
Project: Desktop-master  File: FitToPage.java View source code
private void zoom() {
    final Rectangle rect = view.getInnerBounds();
    final double oldZoom = view.getZoom();
    final JViewport viewPort = (JViewport) view.getParent();
    final Dimension viewer = viewPort.getExtentSize();
    double newZoom = viewer.width * oldZoom / (rect.width + 0.0);
    final double heightZoom = viewer.height * oldZoom / (rect.height + 0.0);
    if (heightZoom < newZoom) {
        newZoom = heightZoom;
    }
    Controller.getCurrentController().getMapViewManager().setZoom((float) (newZoom));
}
Example 19
Project: Docear-master  File: FitToPage.java View source code
private void zoom() {
    final Rectangle rect = view.getInnerBounds();
    final double oldZoom = view.getZoom();
    final JViewport viewPort = (JViewport) view.getParent();
    final Dimension viewer = viewPort.getExtentSize();
    double newZoom = viewer.width * oldZoom / (rect.width + 0.0);
    final double heightZoom = viewer.height * oldZoom / (rect.height + 0.0);
    if (heightZoom < newZoom) {
        newZoom = heightZoom;
    }
    Controller.getCurrentController().getViewController().setZoom((float) (newZoom));
}
Example 20
Project: energyefficientfattree-master  File: SchemaGraphComponent.java View source code
/**
	 * 
	 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
    Component[] c = components.get(terminal.getCell());
    int y = 0;
    if (c != null) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof JTableRenderer) {
                JTableRenderer vertex = (JTableRenderer) c[i];
                JTable table = vertex.table;
                JViewport viewport = (JViewport) table.getParent();
                double dy = -viewport.getViewPosition().getY();
                y = (int) Math.max(terminal.getY() + 22, terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
            }
        }
    }
    return y;
}
Example 21
Project: eXist-1.4.x-master  File: AutoScroller.java View source code
public void actionPerformed(ActionEvent event) {
    Container parent = comp.getParent();
    if (!(parent instanceof JViewport))
        return;
    JViewport view = (JViewport) parent;
    Rectangle rect = view.getViewRect();
    int horizontal = 0;
    int vertical = 0;
    int verticalDiffTop = cursorLocation.y - rect.y;
    int verticalDiffBottom = rect.height - verticalDiffTop;
    int horizontalDiffLeft = cursorLocation.x - rect.x;
    int horizontalDiffRight = rect.width - horizontalDiffLeft;
    if (verticalDiffTop < DELTA)
        vertical = -1;
    else if (verticalDiffBottom < DELTA)
        vertical = 1;
    if (horizontalDiffLeft < DELTA)
        horizontal = -1;
    else if (horizontalDiffRight < DELTA)
        horizontal = 1;
    if (comp instanceof Scrollable) {
        Scrollable scrollable = (Scrollable) comp;
        vertical *= scrollable.getScrollableUnitIncrement(rect, SwingConstants.VERTICAL, vertical);
        horizontal *= scrollable.getScrollableUnitIncrement(rect, SwingConstants.HORIZONTAL, horizontal);
    } else {
        vertical *= DEFAULT_INCREMENT;
        horizontal *= DEFAULT_INCREMENT;
    }
    Dimension viewSize = view.getViewSize();
    Point newPosition = new Point(rect.x + horizontal, rect.y + vertical);
    if (newPosition.x < 0)
        newPosition.x = 0;
    else if (newPosition.x > viewSize.width - rect.width)
        newPosition.x = viewSize.width - rect.width;
    if (newPosition.y < 0)
        newPosition.y = 0;
    else if (newPosition.y > viewSize.height - rect.height)
        newPosition.y = viewSize.height - rect.height;
    if (newPosition.x != rect.x || newPosition.y != rect.y) {
        cursorLocation.x += (newPosition.x - rect.x);
        cursorLocation.y += (newPosition.y - rect.y);
        view.setViewPosition(newPosition);
    }
}
Example 22
Project: freemind-mmx-master  File: FitToPage.java View source code
private void zoom() {
    Rectangle rect = view.getInnerBounds();
    // calculate the zoom:
    double oldZoom = getController().getView().getZoom();
    JViewport viewPort = (JViewport) view.getParent();
    JScrollPane pane = (JScrollPane) viewPort.getParent();
    Dimension viewer = viewPort.getExtentSize();
    logger.info("Found viewer rect=" + viewer.height + "/" + rect.height + ", " + viewer.width + "/" + rect.width);
    double newZoom = viewer.width * oldZoom / (rect.width + 0.0);
    double heightZoom = viewer.height * oldZoom / (rect.height + 0.0);
    if (heightZoom < newZoom) {
        newZoom = heightZoom;
    }
    logger.info("Calculated new zoom " + (newZoom));
    getController().getController().setZoom((float) (newZoom));
}
Example 23
Project: GKA1-master  File: SchemaGraphComponent.java View source code
/**
	 * 
	 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
    Component[] c = components.get(terminal.getCell());
    int y = 0;
    if (c != null) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof JTableRenderer) {
                JTableRenderer vertex = (JTableRenderer) c[i];
                JTable table = vertex.table;
                JViewport viewport = (JViewport) table.getParent();
                double dy = -viewport.getViewPosition().getY();
                y = (int) Math.max(terminal.getY() + 22, terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
            }
        }
    }
    return y;
}
Example 24
Project: JGeagle-master  File: ImageViewerPanel.java View source code
/**
     *
     * @param options
     * @param diffImageFile
     * @param eagleFile
     * @param sheet
     * @throws IOException
     */
public static void showImageViewer(Options options, Path diffImageFile, EagleFile eagleFile, String sheet) throws IOException {
    JFrame jFrame = new JFrame();
    jFrame.setTitle("JGeagle - " + eagleFile.getRepoFile() + sheet);
    jFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("de/andreasgiemza/jgeagle/gui/icons/jgeagle.png")));
    Color background;
    if (eagleFile.getFileExtension().equals(EagleFile.SCH)) {
        background = Color.decode(options.getPropSchematicBackground());
    } else {
        background = Color.decode(options.getPropBoardBackground());
    }
    ImageViewerPanel ivp = new ImageViewerPanel(background, diffImageFile);
    JScrollPane scroll = new JScrollPane(ivp);
    jFrame.getContentPane().add(scroll);
    scroll.removeMouseWheelListener(scroll.getMouseWheelListeners()[0]);
    JViewport vport = scroll.getViewport();
    MouseAdapter ma = new HandScrollListener();
    MouseZoomListener mzl = new MouseZoomListener(ivp);
    vport.addMouseMotionListener(ma);
    vport.addMouseWheelListener(mzl);
    vport.addMouseListener(ma);
    Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    jFrame.setSize(new Double(size.getWidth() * 0.8).intValue(), new Double(size.getHeight() * 0.8).intValue());
    jFrame.setLocation(new Double((size.getWidth() / 2) - (jFrame.getWidth() / 2)).intValue(), new Double((size.getHeight() / 2) - (jFrame.getHeight() / 2)).intValue());
    jFrame.setVisible(true);
    ivp.setFirstSize(vport.getSize());
}
Example 25
Project: jgraphx-master  File: SchemaGraphComponent.java View source code
/**
	 * 
	 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
    Component[] c = components.get(terminal.getCell());
    int y = 0;
    if (c != null) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof JTableRenderer) {
                JTableRenderer vertex = (JTableRenderer) c[i];
                JTable table = vertex.table;
                JViewport viewport = (JViewport) table.getParent();
                double dy = -viewport.getViewPosition().getY();
                y = (int) Math.max(terminal.getY() + 22, terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
            }
        }
    }
    return y;
}
Example 26
Project: mage-master  File: UI.java View source code
public static void setVerticalScrollingView(JScrollPane scrollPane, final Component view) {
    final JViewport viewport = new JViewport();
    viewport.setLayout(new ViewportLayout() {

        private static final long serialVersionUID = 7701568740313788935L;

        @Override
        public void layoutContainer(Container parent) {
            viewport.setViewPosition(new Point(0, 0));
            Dimension viewportSize = viewport.getSize();
            int width = viewportSize.width;
            int height = Math.max(view.getPreferredSize().height, viewportSize.height);
            viewport.setViewSize(new Dimension(width, height));
        }
    });
    viewport.setView(view);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setViewport(viewport);
}
Example 27
Project: nenya-master  File: SafeScrollPane.java View source code
@Override
protected JViewport createViewport() {
    JViewport vp = new JViewport() {

        @Override
        public void setViewPosition(Point p) {
            super.setViewPosition(p);
            // simple scroll mode results in setViewPosition causing
            // our view to become invalid, but nothing ever happens to
            // queue up a revalidate for said view, so we have to do
            // it here
            Component c = getView();
            if (c instanceof JComponent) {
                ((JComponent) c).revalidate();
            }
        }
    };
    vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
    return vp;
}
Example 28
Project: OsmUi-master  File: SchemaGraphComponent.java View source code
/**
	 * 
	 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
    Component[] c = components.get(terminal.getCell());
    int y = 0;
    if (c != null) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof JTableRenderer) {
                JTableRenderer vertex = (JTableRenderer) c[i];
                JTable table = vertex.table;
                JViewport viewport = (JViewport) table.getParent();
                double dy = -viewport.getViewPosition().getY();
                y = (int) Math.max(terminal.getY() + 22, terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
            }
        }
    }
    return y;
}
Example 29
Project: Puzzledice-master  File: SchemaGraphComponent.java View source code
/**
	 * 
	 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
    Component[] c = components.get(terminal.getCell());
    int y = 0;
    if (c != null) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof JTableRenderer) {
                JTableRenderer vertex = (JTableRenderer) c[i];
                JTable table = vertex.table;
                JViewport viewport = (JViewport) table.getParent();
                double dy = -viewport.getViewPosition().getY();
                y = (int) Math.max(terminal.getY() + 22, terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
            }
        }
    }
    return y;
}
Example 30
Project: VUE-master  File: ContentPanel.java View source code
protected void addBrowser(String title, JPanel browser) {
    JScrollPane scrollPane = new JScrollPane(null, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    JViewport viewport = scrollPane.getViewport();
    viewport.setOpaque(false);
    scrollPane.setOpaque(false);
    scrollPane.setBorder(null);
    scrollPane.setName(title + ".dockScroll");
    scrollPane.setWheelScrollingEnabled(true);
    scrollPane.setViewportView(browser);
    browser.putClientProperty("VUE.sizeTrack", viewport);
    tabbedPane.addTab(title, scrollPane);
    if (DEBUG.BOXES)
        scrollPane.setBorder(new LineBorder(Color.green, 4));
}
Example 31
Project: jide-oss-master  File: JideScrollPane.java View source code
@Override
public void setViewport(JViewport viewport) {
    JViewport old = getViewport();
    super.setViewport(viewport);
    if (old != null) {
        if (rowHeader != null) {
            JideSwingUtilities.unsynchronizeView(rowHeader, old);
        }
        if (_rowFooter != null) {
            JideSwingUtilities.unsynchronizeView(_rowFooter, old);
            JideSwingUtilities.unsynchronizeView(old, _rowFooter);
        }
        if (_columnFooter != null) {
            JideSwingUtilities.unsynchronizeView(_columnFooter, old);
            JideSwingUtilities.unsynchronizeView(old, _columnFooter);
        }
        if (columnHeader != null) {
            JideSwingUtilities.unsynchronizeView(columnHeader, old);
        }
        if (_subColumnHeader != null) {
            JideSwingUtilities.unsynchronizeView(_subColumnHeader, old);
            JideSwingUtilities.unsynchronizeView(old, _subColumnHeader);
        }
    }
    if (viewport != null) {
        if (rowHeader != null) {
            JideSwingUtilities.synchronizeView(rowHeader, getViewport(), SwingConstants.VERTICAL);
        }
        if (_rowFooter != null) {
            JideSwingUtilities.synchronizeView(_rowFooter, getViewport(), SwingConstants.VERTICAL);
            JideSwingUtilities.synchronizeView(getViewport(), _rowFooter, SwingConstants.VERTICAL);
        }
        if (_columnFooter != null) {
            JideSwingUtilities.synchronizeView(_columnFooter, getViewport(), SwingConstants.HORIZONTAL);
            JideSwingUtilities.synchronizeView(getViewport(), _columnFooter, SwingConstants.HORIZONTAL);
        }
        if (columnHeader != null) {
            JideSwingUtilities.synchronizeView(columnHeader, getViewport(), SwingConstants.HORIZONTAL);
        }
        if (_subColumnHeader != null) {
            JideSwingUtilities.synchronizeView(_subColumnHeader, getViewport(), SwingConstants.HORIZONTAL);
            JideSwingUtilities.synchronizeView(getViewport(), _subColumnHeader, SwingConstants.HORIZONTAL);
        }
    }
}
Example 32
Project: ApkAnalyser-master  File: Util.java View source code
public static void printInjectionInfoInTextBuilder(String text1, String text2, DalvikInjectionMethod injection) {
    if (!(Selection.getSelectedView() instanceof TextBuilder)) {
        return;
    }
    TextBuilder text = (TextBuilder) Selection.getSelectedView();
    if (text == null) {
        return;
    }
    int pos = text.getCaretPosition();
    JViewport view = text.getScrollPane().getViewport();
    text.getLineBuilder().insertLineBefore(text.getCurrentLine());
    text.getLineBuilder().append("        >>>    ", 0xbb0000);
    text.getLineBuilder().append("PRINT(", 0x000000);
    text.getLineBuilder().append("\"" + text1 + "\"", 0x0000bb);
    if (text2 != null) {
        text.getLineBuilder().append("+" + text2, 0x000000);
    }
    text.getLineBuilder().append(")", 0x000000);
    text.getLineBuilder().setReferenceToCurrent(injection);
    text.updateDocument();
    text.setCaretPosition(pos);
    text.getScrollPane().setViewport(view);
}
Example 33
Project: ComplexRapidMiner-master  File: ExtendedFixedColumnJTable.java View source code
public static ExtendedFixedColumnJTable createFixedColumnTable(TableModel model) {
    // determine and set preferred size from data, use maximum size anyway
    int max = 0;
    for (int r = 0; r < model.getRowCount(); r++) {
        String valueString = model.getValueAt(r, 0).toString();
        max = Math.max(valueString.length() * 8, max);
    }
    final int preferredWidth = Math.min(max, 250);
    // create a column model for the main table. This model ignores the first column added
    TableColumnModel cm = new DefaultTableColumnModel() {

        private static final long serialVersionUID = -4882307040329823339L;

        private boolean first = true;

        public void addColumn(TableColumn tc) {
            if (first) {
                first = false;
                return;
            }
            super.addColumn(tc);
        }
    };
    // create a column model that will serve as our row header table. This model only stores the first column.
    TableColumnModel rowHeaderModel = new DefaultTableColumnModel() {

        private static final long serialVersionUID = -4852540063984136543L;

        private boolean first = true;

        public void addColumn(TableColumn tc) {
            if (first) {
                super.addColumn(tc);
                tc.setPreferredWidth(preferredWidth);
                first = false;
            }
        }
    };
    // shut off autoResizeMode, our tables won't scroll correctly (horizontally, anyway)!
    ExtendedJTable mainDataTable = new ExtendedJTable(model, false, true, false, true);
    mainDataTable.setColumnModel(cm);
    // header column
    ExtendedJTable headerColumn = new ExtendedJTable(model, false, true, false, true);
    headerColumn.setCellColorProvider(new CellColorProviderYellow());
    headerColumn.setColumnModel(rowHeaderModel);
    mainDataTable.createDefaultColumnsFromModel();
    headerColumn.createDefaultColumnsFromModel();
    headerColumn.getTableHeader().setReorderingAllowed(false);
    headerColumn.getTableHeader().setResizingAllowed(false);
    // make sure that selections between the main table and the header stay in sync (by sharing the same model)
    mainDataTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    mainDataTable.setSelectionModel(headerColumn.getSelectionModel());
    // adjust preferred size
    headerColumn.setPreferredScrollableViewportSize(headerColumn.getPreferredSize());
    // put it in a viewport that we can control a bit
    JViewport viewport = new JViewport();
    viewport.setView(headerColumn);
    viewport.setPreferredSize(headerColumn.getPreferredSize());
    return new ExtendedFixedColumnJTable(mainDataTable, viewport, headerColumn.getTableHeader());
}
Example 34
Project: DDS-Utils-master  File: ScrollCanvasListener.java View source code
/**
	 * 
	 */
private void drag(MouseEvent event) {
    JViewport viewport = scrollViewPane.getViewport();
    Point position = viewport.getViewPosition();
    Rectangle rectViewport = viewport.getViewRect();
    // get new click coordinates
    int xNew = event.getX();
    int yNew = event.getY();
    // translation aka difference
    int deltaX = xOld - xNew;
    int deltaY = yOld - yNew;
    int x = position.x + deltaX;
    int y = position.y + deltaY;
    // boundaries
    int canvasWidth = (int) viewport.getViewSize().getWidth();
    int canvasHeight = (int) viewport.getViewSize().getHeight();
    if (rectViewport.width < canvasWidth) {
        // left and top edge
        if (x <= 0)
            x = 0;
        // right edge
        int maxX = canvasWidth - rectViewport.width;
        if (x > maxX)
            x = maxX;
        position.x = x;
    }
    if (rectViewport.height < canvasHeight) {
        if (y <= 0)
            y = 0;
        int maxY = canvasHeight - rectViewport.height;
        // bottom edge
        if (y > maxY)
            y = maxY;
        position.y = y;
    }
    viewport.setViewPosition(position);
}
Example 35
Project: EclipseColorer-master  File: ColorerDemo.java View source code
public static final void main(String[] args) {
    JColoredTextArea text = new JColoredTextArea();
    text.setText("test");
    JFrame frame = new JFrame();
    frame.setTitle("Colorer Demo");
    frame.getContentPane().setLayout(new BorderLayout());
    JScrollPane scroller = new JScrollPane();
    JViewport port = scroller.getViewport();
    port.add(text);
    frame.getContentPane().add("Center", scroller);
    frame.pack();
    frame.setSize(300, 200);
    frame.setVisible(true);
    frame.addWindowListener(new AppCloser());
}
Example 36
Project: fest-swing-1.x-master  File: Scrolling.java View source code
/**
   * Returns a {@code JComponent}'s closest validating root ancestor in the AWT containment hierarchy.
   *
   * @param c the given {@code JComponent}.
   * @return the found ancestor or {@code null} if there isn't one.
   */
@Nullable
private static JComponent findClosestValidatingRootAncestor(@Nonnull JComponent c) {
    // the candidate validating root at every iteration (candidate = not necessarily a root)
    Container root = c;
    // we go up to the top of the hierarchy
    while (root != null) {
        Container parent = root.getParent();
        // the new candidate root becomes the parent of the previous one
        root = parent;
        // if the candidate isn't a JComponent, we're not interested in it (we need JComponent#scrollRectToVisible)
        if (!(root instanceof JComponent)) {
            continue;
        }
        // we don't have to take JFrame into account, it's not a JComponent (ant it's a top-level container anyway)
        if (root instanceof JViewport || root instanceof JInternalFrame) {
            return (JComponent) root;
        }
    }
    return null;
}
Example 37
Project: jdk7u-jdk-master  File: Test6660049.java View source code
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Test6660049(javax.swing.JButton.class, javax.swing.JCheckBox.class, javax.swing.JCheckBoxMenuItem.class, javax.swing.JColorChooser.class, javax.swing.JComboBox.class, javax.swing.JDesktopPane.class, javax.swing.JEditorPane.class, javax.swing.JFileChooser.class, javax.swing.JFormattedTextField.class, javax.swing.JInternalFrame.class, javax.swing.JLabel.class, javax.swing.JList.class, javax.swing.JMenu.class, javax.swing.JMenuBar.class, javax.swing.JMenuItem.class, javax.swing.JOptionPane.class, javax.swing.JPanel.class, javax.swing.JPasswordField.class, javax.swing.JPopupMenu.class, javax.swing.JProgressBar.class, javax.swing.JRadioButton.class, javax.swing.JRadioButtonMenuItem.class, javax.swing.JRootPane.class, javax.swing.JScrollBar.class, javax.swing.JScrollPane.class, javax.swing.JSeparator.class, javax.swing.JSlider.class, javax.swing.JSpinner.class, javax.swing.JSplitPane.class, javax.swing.JTabbedPane.class, javax.swing.JTable.class, javax.swing.JTextArea.class, javax.swing.JTextField.class, javax.swing.JTextPane.class, javax.swing.JToggleButton.class, javax.swing.JToolBar.class, javax.swing.JToolTip.class, javax.swing.JTree.class, javax.swing.JViewport.class, javax.swing.table.JTableHeader.class));
}
Example 38
Project: josm-older-master  File: ImageMarker.java View source code
@Override
public void actionPerformed(ActionEvent ev) {
    final JPanel p = new JPanel(new BorderLayout());
    final JScrollPane scroll = new JScrollPane(new JLabel(loadScaledImage(imageUrl, 580)));
    final JViewport vp = scroll.getViewport();
    p.add(scroll, BorderLayout.CENTER);
    final JToggleButton scale = new JToggleButton(ImageProvider.get("misc", "rectangle"));
    JPanel p2 = new JPanel();
    p2.add(scale);
    p.add(p2, BorderLayout.SOUTH);
    scale.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ev) {
            p.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            if (scale.getModel().isSelected()) {
                ((JLabel) vp.getView()).setIcon(loadScaledImage(imageUrl, Math.max(vp.getWidth(), vp.getHeight())));
            } else {
                ((JLabel) vp.getView()).setIcon(new ImageIcon(imageUrl));
            }
            p.setCursor(Cursor.getDefaultCursor());
        }
    });
    scale.setSelected(true);
    JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE);
    JDialog dlg = pane.createDialog(Main.parent, imageUrl.toString());
    dlg.setModal(false);
    dlg.toFront();
    dlg.setVisible(true);
}
Example 39
Project: LateralGM-master  File: EditorScrollPane.java View source code
public void createTransparencyViewport(Component view) {
    JViewport viewport = new JViewport() {

        /**
		 * NOTE: Default UID generated, change if necessary.
		 */
        private static final long serialVersionUID = -488286791453210520L;

        private BufferedImage componentBackground = null;

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            int width = (int) Math.ceil(this.getWidth() / 16f);
            int height = (int) Math.ceil(this.getHeight() / 16f);
            width = width < 1 ? 1 : width;
            height = height < 1 ? 1 : height;
            if (componentBackground == null || componentBackground.getWidth() != width | componentBackground.getHeight() != height) {
                componentBackground = Util.paintBackground(width, height);
            }
            g.drawImage(componentBackground, 0, 0, componentBackground.getWidth() * 16, componentBackground.getHeight() * 16, null);
        }
    };
    viewport.setView(view);
    this.setViewport(viewport);
}
Example 40
Project: magarena-master  File: DeckViewTablePanel.java View source code
private void scrollRowToViewportCenter(int row) {
    JViewport viewport = (JViewport) table.getParent();
    Rectangle viewRect = viewport.getViewRect();
    Rectangle rect = table.getCellRect(row, 0, true);
    int y = rect.y < viewRect.y || rect.y > (viewRect.y + viewRect.height) ? rect.y - (viewRect.height / 2) + rect.height : viewRect.y;
    viewport.setViewPosition(new Point(viewRect.x, y));
}
Example 41
Project: Mandtool-master  File: BufferedFrame.java View source code
@Override
public void componentResized(ComponentEvent e) {
    //System.out.println("RS: "+e);
    JViewport vp = scrollpane.getViewport();
    if (vp != null) {
        if (debug)
            System.out.println("PREF:" + buffer.getPreferredSize());
        if (debug)
            System.out.println("VP: " + vp.getViewPosition());
        if (debug)
            System.out.println("VP: " + vp.getExtentSize());
        partial = !buffer.getPreferredSize().equals(vp.getExtentSize());
    } else
        partial = false;
}
Example 42
Project: openjdk-master  File: Test6660049.java View source code
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Test6660049(javax.swing.JButton.class, javax.swing.JCheckBox.class, javax.swing.JCheckBoxMenuItem.class, javax.swing.JColorChooser.class, javax.swing.JComboBox.class, javax.swing.JDesktopPane.class, javax.swing.JEditorPane.class, javax.swing.JFileChooser.class, javax.swing.JFormattedTextField.class, javax.swing.JInternalFrame.class, javax.swing.JLabel.class, javax.swing.JList.class, javax.swing.JMenu.class, javax.swing.JMenuBar.class, javax.swing.JMenuItem.class, javax.swing.JOptionPane.class, javax.swing.JPanel.class, javax.swing.JPasswordField.class, javax.swing.JPopupMenu.class, javax.swing.JProgressBar.class, javax.swing.JRadioButton.class, javax.swing.JRadioButtonMenuItem.class, javax.swing.JRootPane.class, javax.swing.JScrollBar.class, javax.swing.JScrollPane.class, javax.swing.JSeparator.class, javax.swing.JSlider.class, javax.swing.JSpinner.class, javax.swing.JSplitPane.class, javax.swing.JTabbedPane.class, javax.swing.JTable.class, javax.swing.JTextArea.class, javax.swing.JTextField.class, javax.swing.JTextPane.class, javax.swing.JToggleButton.class, javax.swing.JToolBar.class, javax.swing.JToolTip.class, javax.swing.JTree.class, javax.swing.JViewport.class, javax.swing.table.JTableHeader.class));
}
Example 43
Project: openjdk8-jdk-master  File: Test6660049.java View source code
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Test6660049(javax.swing.JButton.class, javax.swing.JCheckBox.class, javax.swing.JCheckBoxMenuItem.class, javax.swing.JColorChooser.class, javax.swing.JComboBox.class, javax.swing.JDesktopPane.class, javax.swing.JEditorPane.class, javax.swing.JFileChooser.class, javax.swing.JFormattedTextField.class, javax.swing.JInternalFrame.class, javax.swing.JLabel.class, javax.swing.JList.class, javax.swing.JMenu.class, javax.swing.JMenuBar.class, javax.swing.JMenuItem.class, javax.swing.JOptionPane.class, javax.swing.JPanel.class, javax.swing.JPasswordField.class, javax.swing.JPopupMenu.class, javax.swing.JProgressBar.class, javax.swing.JRadioButton.class, javax.swing.JRadioButtonMenuItem.class, javax.swing.JRootPane.class, javax.swing.JScrollBar.class, javax.swing.JScrollPane.class, javax.swing.JSeparator.class, javax.swing.JSlider.class, javax.swing.JSpinner.class, javax.swing.JSplitPane.class, javax.swing.JTabbedPane.class, javax.swing.JTable.class, javax.swing.JTextArea.class, javax.swing.JTextField.class, javax.swing.JTextPane.class, javax.swing.JToggleButton.class, javax.swing.JToolBar.class, javax.swing.JToolTip.class, javax.swing.JTree.class, javax.swing.JViewport.class, javax.swing.table.JTableHeader.class));
}
Example 44
Project: pcgen-deprecated-master  File: JDynamicTable.java View source code
@Override
protected void configureEnclosingScrollPane() {
    super.configureEnclosingScrollPane();
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, cornerButton);
        }
    }
}
Example 45
Project: rapidminer-5-master  File: ExtendedJTableColumnFitMouseListener.java View source code
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
        JTableHeader header = (JTableHeader) e.getSource();
        TableColumn tableColumn = getResizingColumn(header, e.getPoint());
        if (tableColumn == null)
            return;
        JTable table = header.getTable();
        if ((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
            if (table instanceof ExtendedJTable) {
                ((ExtendedJTable) table).pack();
                e.consume();
            }
        } else {
            int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
            int width = (int) header.getDefaultRenderer().getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col).getPreferredSize().getWidth();
            int firstRow = 0;
            int lastRow = table.getRowCount();
            if (table instanceof ExtendedJTable) {
                ExtendedJScrollPane scrollPane = ((ExtendedJTable) table).getExtendedScrollPane();
                if (scrollPane != null) {
                    JViewport viewport = scrollPane.getViewport();
                    Rectangle viewRect = viewport.getViewRect();
                    if (viewport.getHeight() < table.getHeight()) {
                        firstRow = table.rowAtPoint(new Point(0, viewRect.y));
                        firstRow = Math.max(0, firstRow);
                        lastRow = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1));
                        lastRow = Math.min(lastRow, table.getRowCount());
                    }
                }
            }
            for (int row = firstRow; row < lastRow; row++) {
                int preferedWidth = (int) table.getCellRenderer(row, col).getTableCellRendererComponent(table, table.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
                width = Math.max(width, preferedWidth);
            }
            // this line is very important 
            header.setResizingColumn(tableColumn);
            tableColumn.setWidth(width + table.getIntercellSpacing().width);
            e.consume();
        }
    }
}
Example 46
Project: rapidminer-studio-master  File: RowNumberTable.java View source code
@Override
public void addNotify() {
    super.addNotify();
    Component c = getParent();
    // Keep scrolling of the row table in sync with the main table.
    if (c instanceof JViewport) {
        JViewport viewport = (JViewport) c;
        viewport.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                // Keep the scrolling of the row table in sync with main table
                JViewport viewport = (JViewport) e.getSource();
                JScrollPane scrollPane = (JScrollPane) viewport.getParent();
                scrollPane.getVerticalScrollBar().setValue(viewport.getViewPosition().y);
            }
        });
    }
}
Example 47
Project: rapidminer-vega-master  File: ExtendedJTableColumnFitMouseListener.java View source code
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
        JTableHeader header = (JTableHeader) e.getSource();
        TableColumn tableColumn = getResizingColumn(header, e.getPoint());
        if (tableColumn == null)
            return;
        JTable table = header.getTable();
        if ((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
            if (table instanceof ExtendedJTable) {
                ((ExtendedJTable) table).pack();
                e.consume();
            }
        } else {
            int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
            int width = (int) header.getDefaultRenderer().getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col).getPreferredSize().getWidth();
            int firstRow = 0;
            int lastRow = table.getRowCount();
            if (table instanceof ExtendedJTable) {
                ExtendedJScrollPane scrollPane = ((ExtendedJTable) table).getExtendedScrollPane();
                if (scrollPane != null) {
                    JViewport viewport = scrollPane.getViewport();
                    Rectangle viewRect = viewport.getViewRect();
                    if (viewport.getHeight() < table.getHeight()) {
                        firstRow = table.rowAtPoint(new Point(0, viewRect.y));
                        firstRow = Math.max(0, firstRow);
                        lastRow = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1));
                        lastRow = Math.min(lastRow, table.getRowCount());
                    }
                }
            }
            for (int row = firstRow; row < lastRow; row++) {
                int preferedWidth = (int) table.getCellRenderer(row, col).getTableCellRendererComponent(table, table.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
                width = Math.max(width, preferedWidth);
            }
            // this line is very important 
            header.setResizingColumn(tableColumn);
            tableColumn.setWidth(width + table.getIntercellSpacing().width);
            e.consume();
        }
    }
}
Example 48
Project: SmallMind-master  File: ComponentPanel.java View source code
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
    Rectangle viewRectangle;
    int index;
    int jiggleJump = 0;
    viewRectangle = ((JViewport) getParent()).getViewRect();
    if (direction < 0) {
        if (viewRectangle.getY() > 0) {
            index = getIndexAtPoint(new Point(0, (int) viewRectangle.getY()));
            jiggleJump = (int) (viewRectangle.getY() - getSquashedRectangleAtIndex(index).getY());
            if (jiggleJump == 0) {
                jiggleJump += getSquashedRectangleAtIndex(index - 1).getHeight();
            }
        }
    } else if (direction > 0) {
        if ((viewRectangle.getY() + viewRectangle.getHeight()) < getPreferredSize().getHeight()) {
            index = getIndexAtPoint(new Point(0, (int) (viewRectangle.getY() + viewRectangle.getHeight())));
            jiggleJump = (int) ((getSquashedRectangleAtIndex(index).getY() + getSquashedRectangleAtIndex(index).getHeight()) - (viewRectangle.getY() + viewRectangle.getHeight()));
            if (jiggleJump == 0) {
                if (index >= (getComponentCount() - 1)) {
                    jiggleJump = 0;
                } else {
                    jiggleJump += getSquashedRectangleAtIndex(index + 1).getHeight();
                }
            }
        }
    }
    return jiggleJump;
}
Example 49
Project: SOAP-master  File: AutoscrollSupport.java View source code
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();
    if (viewport == null) {
        return;
    }
    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;
    int viewWidth = viewport.getExtentSize().width;
    // resolve scrolling
    if ((cursorLoc.y - viewPos.y) < insets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
    } else if ((viewPos.y + viewHeight - cursorLoc.y) < insets.bottom) {
        // scroll down
        viewport.setViewPosition(new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight() - viewHeight)));
    } else if ((cursorLoc.x - viewPos.x) < insets.left) {
        // scroll left
        viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
    } else if ((viewPos.x + viewWidth - cursorLoc.x) < insets.right) {
        // scroll right
        viewport.setViewPosition(new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth), viewPos.y));
    }
}
Example 50
Project: soapui-master  File: AutoscrollSupport.java View source code
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();
    if (viewport == null) {
        return;
    }
    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;
    int viewWidth = viewport.getExtentSize().width;
    // resolve scrolling
    if ((cursorLoc.y - viewPos.y) < insets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
    } else if ((viewPos.y + viewHeight - cursorLoc.y) < insets.bottom) {
        // scroll down
        viewport.setViewPosition(new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight() - viewHeight)));
    } else if ((cursorLoc.x - viewPos.x) < insets.left) {
        // scroll left
        viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
    } else if ((viewPos.x + viewWidth - cursorLoc.x) < insets.right) {
        // scroll right
        viewport.setViewPosition(new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth), viewPos.y));
    }
}
Example 51
Project: studio-master  File: SheetButton.java View source code
/** Implements <code>FocusListener</code> interface method. */
public void focusGained(FocusEvent fe) {
    notifySheetButtonListenersAboutEntered(new ActionEvent(SheetButton.this, ActionEvent.ACTION_FIRST + 1, actionCommand));
    Component c = SheetButton.this;
    Rectangle r = SheetButton.this.getBounds();
    while ((c != null) && (!(c instanceof javax.swing.JViewport))) {
        c = c.getParent();
        if (c != null) {
            r.x += c.getX();
            r.y += c.getY();
        }
    }
    if (c != null) {
        javax.swing.JViewport jvp = (javax.swing.JViewport) c;
        jvp.scrollRectToVisible(r);
    }
    repaint();
}
Example 52
Project: Towel-master  File: GuiUtils.java View source code
private static void setViewPortPosition(JViewport viewport, Rectangle position) {
    // The location of the viewport relative to the object
    Point pt = viewport.getViewPosition();
    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    position.setLocation(position.x - pt.x, position.y - pt.y);
    // Scroll the area into view
    viewport.scrollRectToVisible(position);
}
Example 53
Project: tpml-master  File: SmallStepView.java View source code
protected void nodeAdded(AbstractNode node) {
    if (getParent() instanceof JViewport) {
        JViewport vp = (JViewport) getParent();
        // the viewport scroll to the rightmost position of
        // the bounds rectangle. 
        // Use a hardcoded width of 10 pixels to prevent the
        // viewport from scrolling to the right.
        // 
        // look like the visible rect is relative to the
        // current visible rect
        Rectangle bounds = node.getBounds();
        bounds.x = 0;
        bounds.width = 10;
        vp.scrollRectToVisible(bounds);
    }
}
Example 54
Project: yoursway-ide-master  File: ColorerDemo.java View source code
public static final void main(String[] args) {
    JColoredTextArea text = new JColoredTextArea();
    text.setText("test");
    JFrame frame = new JFrame();
    frame.setTitle("Colorer Demo");
    frame.getContentPane().setLayout(new BorderLayout());
    JScrollPane scroller = new JScrollPane();
    JViewport port = scroller.getViewport();
    port.add(text);
    frame.getContentPane().add("Center", scroller);
    frame.pack();
    frame.setSize(300, 200);
    frame.setVisible(true);
    frame.addWindowListener(new AppCloser());
}
Example 55
Project: kevoree-master  File: TableUtils.java View source code
private static void parentDidChange(JTable table, Color stipeColor) {
    // a JScrollpane, then install the custom BugFixedViewportLayout.
    if (table.getParent() instanceof JViewport && table.getParent().getParent() instanceof JScrollPane) {
        JScrollPane scrollPane = (JScrollPane) table.getParent().getParent();
        scrollPane.setViewportBorder(new StripedViewportBorder(scrollPane.getViewport(), table, stipeColor));
        scrollPane.getViewport().setOpaque(false);
        scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, TableHeaderUtils.createCornerComponent(table));
        scrollPane.setBorder(BorderFactory.createEmptyBorder());
    }
}
Example 56
Project: ASH-Viewer-master  File: JFrameLauncher.java View source code
public void initialise(String arguments[]) {
    JPanel main = new JPanel();
    main.setLayout(new GridLayout(1, 1, 3, 3));
    JSplitPane splitPane = new JSplitPane();
    splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setDividerLocation(600);
    main.add(splitPane);
    getContentPane().add(main);
/*
		  String[][] columnNames = {
	        		{"First Name", "Last Name", "# of Years"}};

	        final GanttEntryHelper helper = new GanttEntryHelper();
	        final GanttDrawingPartHelper partHelper = new GanttDrawingPartHelper();
	        // Data works the same with E-Gantt but in this example we are going
	        // to specify a graphics object for rendering
	        Object[][] data = {
	            {"Mary", "Campione", createDrawingState(partHelper,0, 100, 3)},
	            {"Alison", "Huml",createDrawingState(partHelper, 0, 50, 4)},
	            {"Kathy", "Walrath", createDrawingState(partHelper, 0, 100, 10)},
	            {"Sharon", "Zakhour", createDrawingState(partHelper,10, 90, 6)},
	            {"Philip", "Milne",helper.createActivityEntry(new Date(0), new Date(100))}
	        };

	        
	        final GanttTable table = new GanttTable(data, columnNames);
	        final GanttTable table1 = new GanttTable(data, columnNames);
		
	        JScrollPane leftPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
					JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
			leftPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
			
			JScrollPane rihtPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
					JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
			rihtPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
	        
			splitPane.setLeftComponent(leftPane);
			splitPane.setRightComponent(rihtPane);
			
			leftPane.setVerticalScrollBar(leftPane.getVerticalScrollBar());
			rihtPane.setVerticalScrollBar(rihtPane.getVerticalScrollBar());			
			
			leftPane.setViewportView(table.getJTable());
			rihtPane.setViewportView(table1.getJTable());
			
			splitPane.setOneTouchExpandable(true);
			splitPane.setDividerLocation(this.getWidth()/2);
			splitPane.setDoubleBuffered(false);*/
}
Example 57
Project: bobbin-master  File: SearchDialog.java View source code
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if (SEARCH.equals(cmd)) {
        if (searchComp instanceof JTree) {
            //FIXME : search in monitors didn't work
            TreePath searchPath = ((JTree) searchComp).getNextMatch(searchField.getText(), 0, Position.Bias.Forward);
            if (searchPath != null) {
                ((JTree) searchComp).setSelectionPath(searchPath);
                Rectangle view = ((JTree) searchComp).getPathBounds(searchPath);
                ((JViewport) searchComp.getParent()).scrollRectToVisible(view);
                dispose();
                searchComp.requestFocusInWindow();
            } else {
                JOptionPane.showMessageDialog(getOwner(), searchField.getText() + " not found!", "Search Error", JOptionPane.ERROR_MESSAGE);
                resetFocus();
            }
        } else if (searchComp instanceof ColoredTable) {
            ColoredTable theTable = (ColoredTable) searchComp;
            int row = -1;
            TableModel tableModel = ((TableSorter) theTable.getModel()).getTableModel();
            if (tableModel instanceof ThreadsTableModel) {
                ThreadsTableModel ttm = (ThreadsTableModel) tableModel;
                row = ttm.searchRowWithName(theTable.getSelectedRow(), searchField.getText());
            } else {
                LinesTableModel ltm = (LinesTableModel) tableModel;
                row = ltm.searchRowWithName(theTable.getSelectedRow(), searchField.getText());
            }
            theTable.getSelectionModel().setSelectionInterval(row, row);
            theTable.scrollRectToVisible(theTable.getCellRect(row, 0, true));
        }
    }
}
Example 58
Project: cats-master  File: CommonTestUtils.java View source code
public static JPanel getConfigPanelFromTabbedPane(JTabbedPane mainTabbedPane) {
    JPanel configPanel = null;
    Component[] mainComponents = mainTabbedPane.getComponents();
    for (Component component : mainComponents) {
        if (component instanceof JScrollPane) {
            if ((component.getName() != null) && (component.getName().equals("mySettopsPane"))) {
                JScrollPane mySettopsPane = (JScrollPane) component;
                Component viewPortComponent = mySettopsPane.getComponent(0);
                JViewport viewPort = (JViewport) viewPortComponent;
                Component configPanelComponent = viewPort.getComponent(0);
                configPanel = (JPanel) configPanelComponent;
                break;
            }
        }
    }
    return configPanel;
}
Example 59
Project: ChromisPOS-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 60
Project: CodenameOne-master  File: HeaderlessColumnResizer.java View source code
public void mouseDragged(MouseEvent e) {
    int mouseX = e.getX();
    TableColumn resizingColumn = table.getTableHeader().getResizingColumn();
    boolean headerLeftToRight = table.getTableHeader().getComponentOrientation().isLeftToRight();
    if (resizingColumn != null) {
        int oldWidth = resizingColumn.getWidth();
        int newWidth;
        if (headerLeftToRight) {
            newWidth = mouseX - mouseXOffset;
        } else {
            newWidth = mouseXOffset - mouseX;
        }
        resizingColumn.setWidth(newWidth);
        Container container;
        if ((table.getTableHeader().getParent() == null) || ((container = table.getTableHeader().getParent().getParent()) == null) || !(container instanceof JScrollPane)) {
            return;
        }
        if (!container.getComponentOrientation().isLeftToRight() && !headerLeftToRight) {
            if (table != null) {
                JViewport viewport = ((JScrollPane) container).getViewport();
                int viewportWidth = viewport.getWidth();
                int diff = newWidth - oldWidth;
                int newHeaderWidth = table.getWidth() + diff;
                /* Resize a table */
                Dimension tableSize = table.getSize();
                tableSize.width += diff;
                table.setSize(tableSize);
                /*
           * If this table is in AUTO_RESIZE_OFF mode and has a horizontal
           * scrollbar, we need to update a view's position.
           */
                if ((newHeaderWidth >= viewportWidth) && (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                    Point p = viewport.getViewPosition();
                    p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                    viewport.setViewPosition(p);
                    /* Update the original X offset value. */
                    mouseXOffset += diff;
                }
            }
        }
    }
}
Example 61
Project: damp.ekeko.snippets-master  File: ScrollPalette.java View source code
/**
     * If the viewports view is a Scrollable then ask the view to compute
     * the unit increment.  Otherwise return super.getUnitIncrement().
     *
     * @see Scrollable#getScrollableUnitIncrement
     */
public int getUnitIncrement(int direction) {
    JViewport vp = getViewport();
    if ((vp != null) && (vp.getView() instanceof Scrollable)) {
        Scrollable view = (Scrollable) (vp.getView());
        Rectangle vr = vp.getViewRect();
        return view.getScrollableUnitIncrement(vr, getOrientation(), direction);
    } else {
        return super.getUnitIncrement(direction);
    }
}
Example 62
Project: DLect-master  File: AnimatedHideLayoutManager.java View source code
private Component traverseTree(Component current) throws IllegalStateException {
    if (current instanceof JViewport || current instanceof Window || current instanceof Dialog) {
        return current;
    }
    if (current.getParent() == null) {
        throw new IllegalStateException("Can't animate a panel without it having a parent");
    }
    return traverseTree(current.getParent());
}
Example 63
Project: eadventure-master  File: ZoomablePanelHolder.java View source code
@Override
public JViewport createViewport() {
    return new JViewport() {

        @Override
        public void doLayout() {
            Dimension c = new Dimension(getComponent(0).getPreferredSize());
            logger.debug("GrowableViewport resizing to {}x{}", new Object[] { c.width, c.height });
            setPreferredSize(c);
            getParent().doLayout();
            super.doLayout();
        }
    };
}
Example 64
Project: ISODonosti-master  File: kisama.java View source code
public void actionPerformed(java.awt.event.ActionEvent e) {
    int select = ((JTable) ((JViewport) scroll.getComponent(0)).getComponent(0)).getSelectedRow();
    try {
        Oferta oferSel = (Oferta) ofertas.elementAt(select);
        ReservarCasa reser = new ReservarCasa(oferSel.getNumCasa(), oferSel.getDiaIni(), oferSel.getDiaFin());
        reser.setVisible(true);
    } catch (Exception ex) {
        JFrame alerta = new JFrame();
        try {
            JOptionPane.showMessageDialog(alerta, "No se ha seleccionado ninguna oferta!", "Alerta", JOptionPane.WARNING_MESSAGE);
        } catch (Exception a) {
            System.out.println("error mostrando dialogo");
            a.printStackTrace();
        }
    }
}
Example 65
Project: JDK-master  File: SynthViewportUI.java View source code
private void updateStyle(JComponent c) {
    SynthContext context = getContext(c, ENABLED);
    // Note: JViewport is special cased as it does not allow for
    // a border to be set. JViewport.setBorder is overriden to throw
    // an IllegalArgumentException. Refer to SynthScrollPaneUI for
    // details of this.
    SynthStyle newStyle = SynthLookAndFeel.getStyle(context.getComponent(), context.getRegion());
    SynthStyle oldStyle = context.getStyle();
    if (newStyle != oldStyle) {
        if (oldStyle != null) {
            oldStyle.uninstallDefaults(context);
        }
        context.setStyle(newStyle);
        newStyle.installDefaults(context);
    }
    this.style = newStyle;
    context.dispose();
}
Example 66
Project: l2fprod-common-master  File: HeaderlessColumnResizer.java View source code
public void mouseDragged(MouseEvent e) {
    int mouseX = e.getX();
    TableColumn resizingColumn = table.getTableHeader().getResizingColumn();
    boolean headerLeftToRight = table.getTableHeader().getComponentOrientation().isLeftToRight();
    if (resizingColumn != null) {
        int oldWidth = resizingColumn.getWidth();
        int newWidth;
        if (headerLeftToRight) {
            newWidth = mouseX - mouseXOffset;
        } else {
            newWidth = mouseXOffset - mouseX;
        }
        resizingColumn.setWidth(newWidth);
        Container container;
        if ((table.getTableHeader().getParent() == null) || ((container = table.getTableHeader().getParent().getParent()) == null) || !(container instanceof JScrollPane)) {
            return;
        }
        if (!container.getComponentOrientation().isLeftToRight() && !headerLeftToRight) {
            if (table != null) {
                JViewport viewport = ((JScrollPane) container).getViewport();
                int viewportWidth = viewport.getWidth();
                int diff = newWidth - oldWidth;
                int newHeaderWidth = table.getWidth() + diff;
                /* Resize a table */
                Dimension tableSize = table.getSize();
                tableSize.width += diff;
                table.setSize(tableSize);
                /*
           * If this table is in AUTO_RESIZE_OFF mode and has a horizontal
           * scrollbar, we need to update a view's position.
           */
                if ((newHeaderWidth >= viewportWidth) && (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                    Point p = viewport.getViewPosition();
                    p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                    viewport.setViewPosition(p);
                    /* Update the original X offset value. */
                    mouseXOffset += diff;
                }
            }
        }
    }
}
Example 67
Project: laf-widget-master  File: LockBorder.java View source code
/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.border.Border#paintBorder(java.awt.Component,
	 * java.awt.Graphics, int, int, int, int)
	 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    this.originalBorder.paintBorder(c, g, x, y, width, height);
    LafWidgetSupport lafSupport = LafWidgetRepository.getRepository().getLafSupport();
    Icon lockIcon = lafSupport.getLockIcon(c);
    if (lockIcon == null)
        lockIcon = LafWidgetUtilities.getSmallLockIcon();
    int offsetY = 0;
    if (c.getParent() instanceof JViewport) {
        // enhancement 9 - show the lock icon of components
        // in JScrollPane so that it is visible in the bottom
        // corner of the scroll pane
        JViewport viewport = (JViewport) c.getParent();
        // painting.
        if (viewport.getScrollMode() != JViewport.SIMPLE_SCROLL_MODE) {
            viewport.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
        }
        Rectangle viewRect = viewport.getViewRect();
        offsetY = c.getHeight() - viewRect.y - viewRect.height;
    }
    int iconY = y + height - lockIcon.getIconHeight() - offsetY;
    if (c.getComponentOrientation().isLeftToRight()) {
        lockIcon.paintIcon(c, g, x + width - lockIcon.getIconWidth(), iconY);
    } else {
        // support for RTL
        lockIcon.paintIcon(c, g, x, iconY);
    }
}
Example 68
Project: libbio-formats-java-master  File: TemplateTools.java View source code
/** Get the value from the given component. */
public static Object getComponentValue(JComponent c) {
    Object value = null;
    if (c instanceof JCheckBox) {
        value = new Boolean(((JCheckBox) c).isSelected());
    } else if (c instanceof JComboBox) {
        value = ((JComboBox) c).getSelectedItem();
    } else if (c instanceof JScrollPane) {
        JScrollPane scroll = (JScrollPane) c;
        JViewport view = scroll.getViewport();
        value = ((JTextArea) view.getView()).getText();
    } else if (c instanceof JSpinner) {
        value = ((JSpinner) c).getValue();
    }
    return value;
}
Example 69
Project: micro-Blagajna-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 70
Project: micro-Blagajna-v1.x-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 71
Project: minuteProject-master  File: UIUtils.java View source code
public static void updateTextAreaScroll(JScrollPane pane, String text) {
    JViewport jview = (JViewport) pane.getComponent(0);
    Component comp = jview.getView();
    JTextArea jTextArea = null;
    if (comp instanceof JTextArea) {
        jTextArea = (JTextArea) comp;
    } else {
        System.out.println("comp = " + comp);
    }
    if (jTextArea != null)
        jTextArea.setText(text);
}
Example 72
Project: Nor-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 73
Project: nordpos-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 74
Project: Openbravo-2B-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 75
Project: Openbravo-POS-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds)
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 76
Project: openmicroscopy-master  File: ImageCanvas.java View source code
/** 
	 * Paints the scale bar on the specified graphics context.
	 * 
	 * @param g2D 		The graphics context.
	 * @param width 	The image's width.
	 * @param height 	The image's height.
	 * @param viewPort 	The viewport hosting the canvas.
	 */
void paintScaleBar(Graphics2D g2D, int width, int height, JViewport viewPort) {
    if (!model.isUnitBar())
        return;
    String value = model.getUnitBarValue();
    if (value == null)
        return;
    value += " " + model.getUnitBarUnit();
    int size = (int) (model.getUnitBarSize());
    // Position scalebar in the bottom left of the viewport or
    // the image which ever is viewable. 
    Rectangle imgRect = new Rectangle(0, 0, width, height);
    Rectangle viewRect = viewPort.getBounds();
    Point p = viewPort.getViewPosition();
    int x = (int) p.getX();
    int y = (int) p.getY();
    int w = Math.min(x + viewRect.width, width);
    int h = Math.min(y + viewRect.height, height);
    if (imgRect.contains(viewRect)) {
        w = x + viewRect.width;
        h = y + viewRect.height;
    }
    if (imgRect.getWidth() < size)
        size = 1;
    if (viewRect.width >= size && size > 1) {
        switch(view.getBirdEyeViewLocationIndex()) {
            case ImageCanvas.BOTTOM_RIGHT:
                ImagePaintingFactory.paintScaleBar(g2D, x + 10, h - 10, size, value, model.getUnitBarColor());
                break;
            case ImageCanvas.TOP_LEFT:
            default:
                ImagePaintingFactory.paintScaleBar(g2D, w - size - 10, h - 10, size, value, model.getUnitBarColor());
        }
    }
}
Example 77
Project: opennars-master  File: HeaderlessColumnResizer.java View source code
public void mouseDragged(MouseEvent e) {
    int mouseX = e.getX();
    TableColumn resizingColumn = table.getTableHeader().getResizingColumn();
    boolean headerLeftToRight = table.getTableHeader().getComponentOrientation().isLeftToRight();
    if (resizingColumn != null) {
        int oldWidth = resizingColumn.getWidth();
        int newWidth;
        if (headerLeftToRight) {
            newWidth = mouseX - mouseXOffset;
        } else {
            newWidth = mouseXOffset - mouseX;
        }
        resizingColumn.setWidth(newWidth);
        Container container;
        if ((table.getTableHeader().getParent() == null) || ((container = table.getTableHeader().getParent().getParent()) == null) || !(container instanceof JScrollPane)) {
            return;
        }
        if (!container.getComponentOrientation().isLeftToRight() && !headerLeftToRight) {
            if (table != null) {
                JViewport viewport = ((JScrollPane) container).getViewport();
                int viewportWidth = viewport.getWidth();
                int diff = newWidth - oldWidth;
                int newHeaderWidth = table.getWidth() + diff;
                /* Resize a table */
                Dimension tableSize = table.getSize();
                tableSize.width += diff;
                table.setSize(tableSize);
                /*
           * If this table is in AUTO_RESIZE_OFF mode and has a horizontal
           * scrollbar, we need to update a view's position.
           */
                if ((newHeaderWidth >= viewportWidth) && (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                    Point p = viewport.getViewPosition();
                    p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                    viewport.setViewPosition(p);
                    /* Update the original X offset value. */
                    mouseXOffset += diff;
                }
            }
        }
    }
}
Example 78
Project: pcgen-master  File: JDynamicTable.java View source code
@Override
protected void configureEnclosingScrollPane() {
    super.configureEnclosingScrollPane();
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, cornerButton);
        }
    }
}
Example 79
Project: pentaho-reporting-master  File: TextAreaParameterComponentTest.java View source code
private JTextArea findTextArea(TextAreaParameterComponent comp) {
    JTextArea result = null;
    if (comp.getComponentCount() > 0) {
        for (int i = 0; i < comp.getComponentCount(); i++) {
            if (comp.getComponent(i) instanceof JViewport) {
                JViewport viewport = (JViewport) comp.getComponent(i);
                result = (JTextArea) viewport.getView();
            }
        }
    }
    return result;
}
Example 80
Project: project-x-cvs-master  File: AboutBox.java View source code
/* (non-Javadoc)
		 * @see java.lang.Runnable#run()
		 */
public void run() {
    while (!stopIt) {
        try {
            sleep(100);
        } catch (InterruptedException e) {
        }
        JViewport viewport = scroll.getViewport();
        int height = viewport.getViewSize().height - viewport.getViewRect().height;
        int viewHeight = (int) viewport.getViewPosition().getY();
        if (up) {
            if (viewHeight < height) {
                viewHeight++;
            } else {
                viewHeight--;
                up = false;
            }
        } else {
            if (viewHeight > 0) {
                viewHeight--;
            } else {
                viewHeight++;
                up = true;
            }
        }
        viewport.setViewPosition(new Point(0, viewHeight));
    }
}
Example 81
Project: Scarlet-Nebula-master  File: ServerList.java View source code
@Override
public void componentResized(final ComponentEvent e) {
    final JList list = (JList) e.getSource();
    final JViewport viewport = (JViewport) list.getParent();
    final Dimension newSize = viewport.getExtentSize();
    final int totalWidth = newSize.width - list.getInsets().left - list.getInsets().right - 1;
    final int serverCount = totalWidth / 200;
    if (serverCount == 0) {
        return;
    }
    final int serverWidth = totalWidth / serverCount;
    list.setFixedCellHeight(100);
    list.setFixedCellWidth(serverWidth);
    list.revalidate();
    list.repaint();
}
Example 82
Project: seaglass-master  File: SeaGlassViewportUI.java View source code
private void updateStyle(JComponent c) {
    SeaGlassContext context = getContext(c, ENABLED);
    // Note: JViewport is special cased as it does not allow for
    // a border to be set. JViewport.setBorder is overriden to throw
    // an IllegalArgumentException. Refer to SynthScrollPaneUI for
    // details of this.
    SynthStyle newStyle = SynthLookAndFeel.getStyle(context.getComponent(), context.getRegion());
    SynthStyle oldStyle = context.getStyle();
    if (newStyle != oldStyle) {
        if (oldStyle != null) {
            oldStyle.uninstallDefaults(context);
        }
        context.setStyle(newStyle);
        newStyle.installDefaults(context);
    }
    this.style = newStyle;
    context.dispose();
}
Example 83
Project: SikuliX-2014-master  File: ScrollableSizeHint.java View source code
@Override
boolean getTracksParentSizeImpl(JComponent component, int orientation) {
    switch(orientation) {
        case SwingConstants.HORIZONTAL:
            return component.getParent() instanceof JViewport && component.getParent().getWidth() > component.getMinimumSize().width && component.getParent().getWidth() < component.getMaximumSize().width;
        case SwingConstants.VERTICAL:
            return component.getParent() instanceof JViewport && component.getParent().getHeight() > component.getMinimumSize().height && component.getParent().getHeight() < component.getMaximumSize().height;
        default:
            throw new IllegalArgumentException("invalid orientation");
    }
}
Example 84
Project: swingx-master  File: ScrollableSizeHint.java View source code
@Override
boolean getTracksParentSizeImpl(JComponent component, int orientation) {
    switch(orientation) {
        case SwingConstants.HORIZONTAL:
            return component.getParent() instanceof JViewport && component.getParent().getWidth() > component.getMinimumSize().width && component.getParent().getWidth() < component.getMaximumSize().width;
        case SwingConstants.VERTICAL:
            return component.getParent() instanceof JViewport && component.getParent().getHeight() > component.getMinimumSize().height && component.getParent().getHeight() < component.getMaximumSize().height;
        default:
            throw new IllegalArgumentException("invalid orientation");
    }
}
Example 85
Project: UniCenta-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 86
Project: unicentaopos381-johnl-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 87
Project: UnicentaPOS_AD-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 88
Project: WANDA-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 89
Project: WandaPOS-master  File: JFlowPanel.java View source code
private Dimension calculateFlowLayout(boolean bDoChilds) {
    Dimension dim = new Dimension(0, hgap);
    int maxWidth;
    if (getParent() != null && getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) getParent();
        maxWidth = viewport.getExtentSize().width;
    } else if (getParent() != null) {
        maxWidth = getParent().getWidth();
    } else {
        maxWidth = getWidth();
    }
    synchronized (getTreeLock()) {
        int compCount = getComponentCount();
        int maxRowWidth = 0;
        int maxRowHeight = 0;
        int x = 0;
        for (int i = 0; i < compCount; i++) {
            Component m = getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                if (x == 0 || (x + hgap + d.width + hgap) <= maxWidth) {
                    // continuamos con esta linea
                    x += hgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(x, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    x += d.width;
                    if (d.height > maxRowHeight) {
                        maxRowHeight = d.height;
                    }
                } else {
                    // nueva linea
                    dim.height += maxRowHeight + vgap;
                    if (bDoChilds) {
                        m.setBounds(getPosition(hgap, maxWidth - d.width), dim.height, d.width, d.height);
                    }
                    if (x > maxRowWidth) {
                        maxRowWidth = x;
                    }
                    x = hgap + d.width;
                    maxRowHeight = d.height;
                }
            }
        }
        // calculamos la ultima linea.
        dim.height += maxRowHeight + vgap;
        if (x > maxRowWidth) {
            maxRowWidth = x;
        }
        dim.width = maxRowWidth;
    }
    return dim;
}
Example 90
Project: abstools-master  File: AdvancedHelpPanel.java View source code
@SuppressWarnings("serial")
private void init() {
    setLayout(new BorderLayout());
    navigatorScrollPane = new JScrollPane();
    contentScrollPane = new JScrollPane();
    editorPane = new JEditorPane() {

        protected void paintComponent(Graphics g) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            super.paintComponent(g);
        }
    };
    editorPane.setContentType("text/html; charset=ISO-8859-1");
    editorPane.setEditable(false);
    JViewport viewPort = new GrabbableViewport();
    viewPort.setView(editorPane);
    contentScrollPane.setViewport(viewPort);
    Border emptyBorder1 = BorderFactory.createEmptyBorder(5, 5, 0, 10);
    add(navigatorScrollPane, BorderLayout.WEST);
    Border border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
    navigatorScrollPane.setBorder(border);
    add(contentScrollPane, BorderLayout.CENTER);
    navigatorRoot = new DefaultMutableTreeNode();
    navigatorModel = new DefaultTreeModel(navigatorRoot);
    navigator = new JTree() {

        protected void paintComponent(Graphics g) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            super.paintComponent(g);
        }
    };
    navigator.setBorder(emptyBorder1);
    navigator.setCellRenderer(this);
    navigator.setModel(navigatorModel);
    navigator.setRootVisible(false);
    navigatorScrollPane.setViewportView(navigator);
}
Example 91
Project: acs-master  File: SmartTextPane.java View source code
/**
	 * Comment
	 */
private synchronized void showPopup(java.awt.event.MouseEvent mouseEvent) {
    if (mouseEvent.getModifiers() == java.awt.event.MouseEvent.META_MASK) {
        if (getPopup().getComponents().length < 2) {
            java.awt.Component p = getParent();
            if (p instanceof JViewport)
                p = p.getParent().getParent();
            if (p instanceof SmartPanel) {
                javax.swing.JMenuItem[] array = ((SmartPanel) p).getNewMenuItems();
                for (int i = 0; i < array.length; i++) {
                    getPopup().add(array[i]);
                }
            }
        //popupInitialized = true;
        }
        getPopup().show(this, mouseEvent.getX(), mouseEvent.getY());
    }
}
Example 92
Project: AIWekaProject-master  File: JTableHelper.java View source code
/** 
   * Assumes table is contained in a JScrollPane.
   * Scrolls the cell (rowIndex, vColIndex) so that it is visible
   * within the viewport.
   */
public static void scrollToVisible(JTable table, int row, int col) {
    if (!(table.getParent() instanceof JViewport))
        return;
    JViewport viewport = (JViewport) table.getParent();
    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(row, col, true);
    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();
    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);
    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
}
Example 93
Project: carrie-in-java-master  File: JExerciseTable.java View source code
private void showMessageErrorIfNecessary() {
    if (correction.thereIsMessage()) {
        JTextPane paneMsg = new JTextPane();
        paneMsg.setContentType("text/html");
        paneMsg.setBackground(Color.RED);
        paneMsg.setText(correction.getErrorMessage());
        paneMsg.setEditable(false);
        balloonMessage = new TablecellBalloonTip(this, paneMsg, getSelectedRow(), getSelectedColumn() - 1, new EdgedBalloonStyle(Color.RED, Color.WHITE), BalloonTip.Orientation.RIGHT_ABOVE, BalloonTip.AttachLocation.NORTHEAST, 60, 20, true);
        balloonMessage.setViewport((JViewport) this.getParent());
    }
}
Example 94
Project: ceres-master  File: TreeCellExtender.java View source code
private void showOrHideCellExtender(Point point) {
    final int oldRow = row;
    row = tree.getRowForLocation(point.x, point.y);
    if (row == oldRow) {
        return;
    }
    hideCellExtender();
    if (row < 0) {
        return;
    }
    TreePath path = tree.getPathForRow(row);
    if (path == null) {
        return;
    }
    Rectangle rowRect = tree.getPathBounds(path);
    if (rowRect == null) {
        return;
    }
    Rectangle viewRect;
    if (tree.getParent() instanceof JViewport) {
        viewRect = ((JViewport) tree.getParent()).getViewRect();
    } else {
        viewRect = tree.getBounds();
    }
    int rx1 = rowRect.x;
    int ry1 = rowRect.y;
    int rx2 = rowRect.x + rowRect.width - 1;
    int ry2 = rowRect.y + rowRect.height - 1;
    // int vx1 = viewRect.x;
    int vy1 = viewRect.y;
    int vx2 = viewRect.x + viewRect.width - 1;
    int vy2 = viewRect.y + viewRect.height - 1;
    boolean cellExtenderVisible = rx2 > vx2 && ry1 >= vy1 && ry2 <= vy2;
    if (!cellExtenderVisible) {
        return;
    }
    offset = vx2 - rx1;
    int wx = rx1 < vx2 ? vx2 : rx1;
    int wy = rowRect.y - 1;
    int ww = rx2 - wx + 2;
    int wh = rowRect.height + 2;
    Rectangle windowRect = new Rectangle(wx, wy, ww, wh);
    if (windowRect.isEmpty()) {
        return;
    }
    showCellExtender(windowRect);
}
Example 95
Project: domainmath-ide-master  File: FastListUI.java View source code
/**
	 * Recalculates the cell width and height of each cell in the list.  This
	 * method is overridden to do a fast estimation if the completion list is
	 * too long, to improve performance for lists with huge amounts of
	 * completions.
	 */
@Override
protected void updateLayoutState() {
    ListModel model = list.getModel();
    int itemCount = model.getSize();
    // the optimal cell sizes.
    if (itemCount < ESTIMATION_THRESHOLD) {
        super.updateLayoutState();
        return;
    }
    // Otherwise, assume all cells are the same height as the first cell,
    // and estimate the necessary width.
    ListCellRenderer renderer = list.getCellRenderer();
    cellWidth = list.getWidth();
    if (// Always true for us
    list.getParent() instanceof JViewport) {
        cellWidth = list.getParent().getWidth();
    }
    //System.out.println(cellWidth);
    // We're getting a fixed cell height for all cells
    cellHeights = null;
    if (renderer != null && itemCount > 0) {
        Object value = model.getElementAt(0);
        java.awt.Component c = renderer.getListCellRendererComponent(list, value, 0, false, false);
        rendererPane.add(c);
        Dimension cellSize = c.getPreferredSize();
        cellHeight = cellSize.height;
        cellWidth = Math.max(cellWidth, cellSize.width);
    } else {
        cellHeight = 20;
    }
}
Example 96
Project: encog-java-workbench-master  File: DirChooser.java View source code
/**
     * Select directory.
     */
public void selectDirectory(File dir) {
    // error check
    if (dir == null) {
        return;
    }
    if (!dir.exists()) {
        return;
    }
    // resolve the path name
    try {
        dir = dir.getCanonicalFile();
    } catch (Exception ex) {
        return;
    }
    if (!dir.isDirectory()) {
        dir = dir.getParentFile();
        if (dir == null) {
            return;
        }
    }
    List<File> dirs = new ArrayList<File>();
    while (true) {
        dirs.add(dir);
        if (FILE_VIEW.isRoot(dir)) {
            break;
        }
        File parent = dir.getParentFile();
        if (parent == null) {
            break;
        }
        if (!parent.exists()) {
            return;
        }
        dir = parent;
    }
    JViewport viewPort = scrollPane.getViewport();
    TreeModel model = tree.getModel();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) model.getRoot();
    for (int i = dirs.size(); --i >= 0; ) {
        File currDir = (File) dirs.get(i);
        tree.expandPath(new TreePath(node.getPath()));
        int count = node.getChildCount();
        int j;
        for (j = 0; j < count; ++j) {
            DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) node.getChildAt(j);
            if (currNode.getUserObject().equals(currDir)) {
                node = currNode;
                TreePath currPath = new TreePath(currNode.getPath());
                tree.setSelectionPath(currPath);
                Rectangle rect = tree.getPathBounds(currPath);
                if (rect != null) {
                    viewPort.setViewPosition(rect.getLocation());
                }
                break;
            }
        }
        if (j == count) {
            break;
        }
    }
}
Example 97
Project: eniac-master  File: OVPanel.java View source code
// centers the configuration panel
private void centerConfigurationPanel(int x, int y) {
    ConfigPanel configPanel = EFrame.getInstance().getConfigPanel();
    float dx = (float) configPanel.getWidth() / (float) getWidth();
    float dy = (float) configPanel.getHeight() / (float) getHeight();
    // determine viewport, init helpers
    JViewport viewPort = ((JViewport) configPanel.getParent());
    Point p = viewPort.getViewPosition();
    // compute x-coordinate
    if (viewPort.getWidth() <= configPanel.getWidth()) {
        p.x = ((int) (x * dx)) - viewPort.getWidth() / 2;
        if (p.x < 0) {
            p.x = 0;
        } else if (p.x > configPanel.getWidth() - viewPort.getWidth()) {
            p.x = configPanel.getWidth() - viewPort.getWidth();
        }
    }
    // compute y-coordinate
    if (viewPort.getHeight() <= configPanel.getHeight()) {
        p.y = ((int) (y * dy)) - viewPort.getHeight() / 2;
        if (p.y < 0) {
            p.y = 0;
        } else if (p.y > configPanel.getHeight() - viewPort.getHeight()) {
            p.y = configPanel.getHeight() - viewPort.getHeight();
        }
    }
    // set view position
    viewPort.setViewPosition(p);
}
Example 98
Project: ESPlorer-master  File: FastListUI.java View source code
/**
	 * Recalculates the cell width and height of each cell in the list.  This
	 * method is overridden to do a fast estimation if the completion list is
	 * too long, to improve performance for lists with huge amounts of
	 * completions.
	 */
@Override
protected void updateLayoutState() {
    ListModel model = list.getModel();
    int itemCount = model.getSize();
    // the optimal cell sizes.
    if (itemCount < ESTIMATION_THRESHOLD) {
        super.updateLayoutState();
        return;
    }
    // Otherwise, assume all cells are the same height as the first cell,
    // and estimate the necessary width.
    ListCellRenderer renderer = list.getCellRenderer();
    cellWidth = list.getWidth();
    if (// Always true for us
    list.getParent() instanceof JViewport) {
        cellWidth = list.getParent().getWidth();
    }
    //System.out.println(cellWidth);
    // We're getting a fixed cell height for all cells
    cellHeights = null;
    if (renderer != null && itemCount > 0) {
        Object value = model.getElementAt(0);
        java.awt.Component c = renderer.getListCellRendererComponent(list, value, 0, false, false);
        rendererPane.add(c);
        Dimension cellSize = c.getPreferredSize();
        cellHeight = cellSize.height;
        cellWidth = Math.max(cellWidth, cellSize.width);
    } else {
        cellHeight = 20;
    }
}
Example 99
Project: extweka-master  File: JTableHelper.java View source code
/** 
   * Assumes table is contained in a JScrollPane.
   * Scrolls the cell (rowIndex, vColIndex) so that it is visible
   * within the viewport.
   */
public static void scrollToVisible(JTable table, int row, int col) {
    if (!(table.getParent() instanceof JViewport))
        return;
    JViewport viewport = (JViewport) table.getParent();
    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(row, col, true);
    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();
    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);
    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
}
Example 100
Project: get-organized-master  File: DragDrop.java View source code
@Override
public void drop(DropTargetDropEvent ev) {
    ev.acceptDrop(ev.getDropAction());
    try {
        if (response1 == -1 && response2 == -1) {
            if (!repeat) {
                JPanel panel = (JPanel) ((DropTarget) ev.getSource()).getComponent();
                JPanel targetPanel = (JPanel) ((JViewport) ((JScrollPane) panel.getComponent(1)).getComponent(0)).getComponent(0);
                Object source = ev.getTransferable().getTransferData(supportedFlavors[0]);
                ListItem item = (ListItem) ((DragSourceContext) source).getComponent().getParent();
                Calendar shownCal = viewPanel.miniCalendar.getCalendar();
                int shownMonth = shownCal.get(Calendar.MONTH);
                int dayIndex = viewPanel.getIndexFromDaysArray((JPanel) ((JScrollPane) ((JViewport) targetPanel.getParent()).getParent()).getParent());
                viewPanel.assignmentsTable.setSelectedRowFromVectorIndex(viewPanel.domain.utility.getAssignmentOrEventIndexByID(item.getUniqueID()));
                if (item instanceof Event) {
                    Calendar cal = viewPanel.eventDateChooser.getCalendar();
                    int dueMonth = Integer.parseInt(item.getDueDate().split("/")[0]);
                    if ((dueMonth == shownMonth - 1 && dueMonth - 1 != shownMonth) || (dueMonth == shownMonth + 11 && dueMonth - 1 != shownMonth)) {
                        String day = ((JLabel) panel.getComponent(0)).getText();
                        int dayNum = Integer.parseInt(day);
                        cal.set(Calendar.DAY_OF_MONTH, dayNum);
                        viewPanel.eventDateChooser.setDate(cal.getTime());
                    } else if ((dueMonth == shownMonth + 1 && dueMonth - 1 != shownMonth) || (dueMonth == shownMonth - 11 && dueMonth - 1 != shownMonth)) {
                        String day = ((JLabel) panel.getComponent(0)).getText();
                        int dayNum = Integer.parseInt(day);
                        cal.set(Calendar.DAY_OF_MONTH, dayNum);
                        viewPanel.eventDateChooser.setDate(cal.getTime());
                    } else {
                        if (cal.get(Calendar.MONTH) == shownMonth - 1 || cal.get(Calendar.MONTH) == shownMonth + 11) {
                            cal.add(Calendar.MONTH, 1);
                        } else if (cal.get(Calendar.MONTH) == shownMonth + 1 || cal.get(Calendar.MONTH) == shownMonth - 11) {
                            cal.add(Calendar.MONTH, -1);
                        }
                        if (dayIndex != -1) {
                            cal.set(Calendar.DAY_OF_MONTH, dayIndex + 1);
                            viewPanel.eventDateChooser.setDate(cal.getTime());
                        } else {
                            String day = ((JLabel) panel.getComponent(0)).getText();
                            int dayNum = Integer.parseInt(day);
                            if (dayNum > 7) {
                                cal.add(Calendar.MONTH, -1);
                            } else {
                                cal.add(Calendar.MONTH, 1);
                            }
                            cal.set(Calendar.DAY_OF_MONTH, dayNum);
                            viewPanel.eventDateChooser.setDate(cal.getTime());
                        }
                    }
                } else {
                    Calendar cal = viewPanel.dueDateChooser.getCalendar();
                    int dueMonth = Integer.parseInt(item.getDueDate().split("/")[0]);
                    if ((dueMonth == shownMonth - 1 && dueMonth - 1 != shownMonth) || (dueMonth == shownMonth + 11 && dueMonth - 1 != shownMonth)) {
                        String day = ((JLabel) panel.getComponent(0)).getText();
                        int dayNum = Integer.parseInt(day);
                        cal.set(Calendar.DAY_OF_MONTH, dayNum);
                        viewPanel.eventDateChooser.setDate(cal.getTime());
                    } else if ((dueMonth == shownMonth + 1 && dueMonth - 1 != shownMonth) || (dueMonth == shownMonth - 11 && dueMonth - 1 != shownMonth)) {
                        String day = ((JLabel) panel.getComponent(0)).getText();
                        int dayNum = Integer.parseInt(day);
                        cal.set(Calendar.DAY_OF_MONTH, dayNum);
                        viewPanel.eventDateChooser.setDate(cal.getTime());
                    } else {
                        if (cal.get(Calendar.MONTH) == shownMonth - 1 || cal.get(Calendar.MONTH) == shownMonth + 11) {
                            cal.add(Calendar.MONTH, 1);
                        } else if (cal.get(Calendar.MONTH) == shownMonth + 1 || cal.get(Calendar.MONTH) == shownMonth - 11) {
                            cal.add(Calendar.MONTH, -1);
                        }
                        if (dayIndex != -1) {
                            cal.set(Calendar.DAY_OF_MONTH, dayIndex + 1);
                            viewPanel.dueDateChooser.setDate(cal.getTime());
                        } else {
                            String day = ((JLabel) panel.getComponent(0)).getText();
                            int dayNum = Integer.parseInt(day);
                            if (dayNum > 7) {
                                cal.add(Calendar.MONTH, -1);
                            } else {
                                cal.add(Calendar.MONTH, 1);
                            }
                            cal.set(Calendar.DAY_OF_MONTH, dayNum);
                            viewPanel.dueDateChooser.setDate(cal.getTime());
                        }
                    }
                }
                viewPanel.scrollToItemOrToday(item);
            }
            repeat = false;
        }
    } catch (UnsupportedFlavorException ex) {
    } catch (IOException ex) {
    }
    ev.dropComplete(true);
}
Example 101
Project: haskell-java-parser-master  File: BasicViewportUI.java View source code
public void paint(Graphics g, JComponent c) {
    JViewport port = (JViewport) c;
    Component view = port.getView();
    if (view == null)
        return;
    Point pos = port.getViewPosition();
    Rectangle viewBounds = view.getBounds();
    Rectangle portBounds = port.getBounds();
    if (viewBounds.width == 0 || viewBounds.height == 0 || portBounds.width == 0 || portBounds.height == 0)
        return;
    switch(port.getScrollMode()) {
        case JViewport.BACKINGSTORE_SCROLL_MODE:
            paintBackingStore(g, port, view, pos, viewBounds, portBounds);
            break;
        case JViewport.BLIT_SCROLL_MODE:
        case JViewport.SIMPLE_SCROLL_MODE:
        default:
            paintSimple(g, port, view, pos, viewBounds, portBounds);
            break;
    }
}