⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tonicscrollpanelayout.java

📁 用于java swing的皮肤软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	  * @see JScrollPane#getHorizontalScrollBar
	  */
	 public JScrollBar getHorizontalScrollBar() {
	return hsb;
	 }

	 /**
	  * Returns the <code>JScrollBar</code> object that handles vertical scrolling.
	  * @return the <code>JScrollBar</code> object that handles vertical scrolling
	  * @see JScrollPane#getVerticalScrollBar
	  */
	 public JScrollBar getVerticalScrollBar() {
	return vsb;
	 }


	 /**
	  * Returns the <code>JViewport</code> object that is the row header.
	  * @return the <code>JViewport</code> object that is the row header
	  * @see JScrollPane#getRowHeader
	  */
	 public JViewport getRowHeader() {
	return rowHead;
	 }


	 /**
	  * Returns the <code>JViewport</code> object that is the column header.
	  * @return the <code>JViewport</code> object that is the column header
	  * @see JScrollPane#getColumnHeader
	  */
	 public JViewport getColumnHeader() {
	return colHead;
	 }


	 /**
	  * Returns the <code>Component</code> at the specified corner.
	  * @param key the <code>String</code> specifying the corner
	  * @return the <code>Component</code> at the specified corner, as defined in
	  *         {@link ScrollPaneConstants}; if <code>key</code> is not one of the
	  *		four corners, <code>null</code> is returned
	  * @see JScrollPane#getCorner
	  */
	 public Component getCorner(String key) {
	if (key.equals(LOWER_LEFT_CORNER)) {
		 return lowerLeft;
	}
	else if (key.equals(LOWER_RIGHT_CORNER)) {
		 return lowerRight;
	}
	else if (key.equals(UPPER_LEFT_CORNER)) {
		 return upperLeft;
	}
	else if (key.equals(UPPER_RIGHT_CORNER)) {
		 return upperRight;
	}
	else {
		 return null;
	}
	 }


	 /** 
	  * The preferred size of a <code>ScrollPane</code> is the size of the insets,
	  * plus the preferred size of the viewport, plus the preferred size of 
	  * the visible headers, plus the preferred size of the scrollbars
	  * that will appear given the current view and the current
	  * scrollbar displayPolicies.  
	  * <p>Note that the rowHeader is calculated as part of the preferred width
	  * and the colHeader is calculated as part of the preferred size.
	  * 
	  * @param parent the <code>Container</code> that will be laid out
	  * @return a <code>Dimension</code> object specifying the preferred size of the 
	  *         viewport and any scrollbars
	  * @see ViewportLayout
	  * @see LayoutManager
	  */
	 public Dimension preferredLayoutSize(Container parent) 
	 {
	/* Sync the (now obsolete) policy fields with the
	 * JScrollPane.
	 */
	JScrollPane scrollPane = (JScrollPane)parent;
	vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
	hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();

	Insets insets = parent.getInsets();
	int prefWidth = insets.left + insets.right;
	int prefHeight = insets.top + insets.bottom;

	/* Note that viewport.getViewSize() is equivalent to 
	 * viewport.getView().getPreferredSize() modulo a null
	 * view or a view whose size was explicitly set.
	 */

	Dimension extentSize = null;
	Dimension viewSize = null;
	Component view = null;

	if (viewport !=  null) {
		 extentSize = viewport.getPreferredSize();
		 viewSize = viewport.getViewSize();
		 view = viewport.getView();
	}

	/* If there's a viewport add its preferredSize.
	 */

	if (extentSize != null) {
		 prefWidth += extentSize.width;
		 prefHeight += extentSize.height;
	}

	/* If there's a JScrollPane.viewportBorder, add its insets.
	 */

	Border viewportBorder = scrollPane.getViewportBorder();
	if (viewportBorder != null) {
		 Insets vpbInsets = viewportBorder.getBorderInsets(parent);
		 prefWidth += vpbInsets.left + vpbInsets.right;
		 prefHeight += vpbInsets.top + vpbInsets.bottom;
	}

	/* If a header exists and it's visible, factor its
	 * preferred size in.
	 */

	if ((rowHead != null) && rowHead.isVisible()) {
		 prefWidth += rowHead.getPreferredSize().width;
	}

	if ((colHead != null) && colHead.isVisible()) {
		 prefHeight += colHead.getPreferredSize().height;
	}

	/* If a scrollbar is going to appear, factor its preferred size in.
	 * If the scrollbars policy is AS_NEEDED, this can be a little
	 * tricky:
	 * 
	 * - If the view is a Scrollable then scrollableTracksViewportWidth
	 * and scrollableTracksViewportHeight can be used to effectively 
	 * disable scrolling (if they're true) in their respective dimensions.
	 * 
	 * - Assuming that a scrollbar hasn't been disabled by the 
	 * previous constraint, we need to decide if the scrollbar is going 
	 * to appear to correctly compute the JScrollPanes preferred size.
	 * To do this we compare the preferredSize of the viewport (the 
	 * extentSize) to the preferredSize of the view.  Although we're
	 * not responsible for laying out the view we'll assume that the 
	 * JViewport will always give it its preferredSize.
	 */

	if ((vsb != null) && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
		 if (vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
		prefWidth += vsb.getPreferredSize().width;
		 }
		 else if ((viewSize != null) && (extentSize != null)) {
		boolean canScroll = true;
		if (view instanceof Scrollable) {
			 canScroll = !((Scrollable)view).getScrollableTracksViewportHeight();
		}
		if (canScroll && (viewSize.height > extentSize.height)) {
			 prefWidth += vsb.getPreferredSize().width;
		}
		 }
	}

	if ((hsb != null) && (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)) {
		 if (hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
		prefHeight += hsb.getPreferredSize().height;
		 }
		 else if ((viewSize != null) && (extentSize != null)) {
		boolean canScroll = true;
		if (view instanceof Scrollable) {
			 canScroll = !((Scrollable)view).getScrollableTracksViewportWidth();
		}
		if (canScroll && (viewSize.width > extentSize.width)) {
			 prefHeight += hsb.getPreferredSize().height;
		}
		 }
	}

	return new Dimension(prefWidth, prefHeight);
	 }


	 /** 
	  * The minimum size of a <code>ScrollPane</code> is the size of the insets 
	  * plus minimum size of the viewport, plus the scrollpane's
	  * viewportBorder insets, plus the minimum size 
	  * of the visible headers, plus the minimum size of the 
	  * scrollbars whose displayPolicy isn't NEVER.
	  * 
	  * @param parent the <code>Container</code> that will be laid out
	  * @return a <code>Dimension</code> object specifying the minimum size
	  */
	 public Dimension minimumLayoutSize(Container parent) 
	 {
	/* Sync the (now obsolete) policy fields with the
	 * JScrollPane.
	 */
	JScrollPane scrollPane = (JScrollPane)parent;
	vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
	hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();

	Insets insets = parent.getInsets();
	int minWidth = insets.left + insets.right;
	int minHeight = insets.top + insets.bottom;
	
	/* If there's a viewport add its minimumSize.
	 */
	
	if (viewport != null) {
		 Dimension size = viewport.getMinimumSize();
		 minWidth += size.width;
		 minHeight += size.height;
	}

	/* If there's a JScrollPane.viewportBorder, add its insets.
	 */

	Border viewportBorder = scrollPane.getViewportBorder();
	if (viewportBorder != null) {
		 Insets vpbInsets = viewportBorder.getBorderInsets(parent);
		 minWidth += vpbInsets.left + vpbInsets.right;
		 minHeight += vpbInsets.top + vpbInsets.bottom;
	}

	/* If a header exists and it's visible, factor its
	 * minimum size in.
	 */

	if ((rowHead != null) && rowHead.isVisible()) {
		 Dimension size = rowHead.getMinimumSize();
		 minWidth += size.width;
		 minHeight = Math.max(minHeight, size.height);
	}

	if ((colHead != null) && colHead.isVisible()) {
		 Dimension size = colHead.getMinimumSize();
		 minWidth = Math.max(minWidth, size.width);
		 minHeight += size.height;
	}

	/* If a scrollbar might appear, factor its minimum
	 * size in.
	 */

	if ((vsb != null) && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
		 Dimension size = vsb.getMinimumSize();
		 minWidth += size.width;
		 minHeight = Math.max(minHeight, size.height);
	}

	if ((hsb != null) && (hsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
		 Dimension size = hsb.getMinimumSize();
		 minWidth = Math.max(minWidth, size.width);
		 minHeight += size.height;
	}

	return new Dimension(minWidth, minHeight);
	 }


	 /** 
	  * Lays out the scrollpane. The positioning of components depends on
	  * the following constraints:
	  * <ul>
	  * <li> The row header, if present and visible, gets its preferred
	  * width and the viewport's height.
	  * 
	  * <li> The column header, if present and visible, gets its preferred
	  * height and the viewport's width.
	  * 
	  * <li> If a vertical scrollbar is needed, i.e. if the viewport's extent
	  * height is smaller than its view height or if the <code>displayPolicy</code>
	  * is ALWAYS, it's treated like the row header with respect to its
	  * dimensions and is made visible.
	  * 
	  * <li> If a horizontal scrollbar is needed, it is treated like the
	  * column header (see the paragraph above regarding the vertical scrollbar).
	  * 
	  * <li> If the scrollpane has a non-<code>null</code>
	  * <code>viewportBorder</code>, then space is allocated for that.
	  * 
	  * <li> The viewport gets the space available after accounting for
	  * the previous constraints.
	  * 
	  * <li> The corner components, if provided, are aligned with the 
	  * ends of the scrollbars and headers. If there is a vertical
	  * scrollbar, the right corners appear; if there is a horizontal
	  * scrollbar, the lower corners appear; a row header gets left
	  * corners, and a column header gets upper corners.
	  * </ul>
	  *
	  * @param parent the <code>Container</code> to lay out
	  */
	 public void layoutContainer(Container parent) 
	 {
	/* Sync the (now obsolete) policy fields with the
	 * JScrollPane.
	 */
	JScrollPane scrollPane = (JScrollPane)parent;
	vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
	hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();

	Rectangle availR = scrollPane.getBounds();
	availR.x = availR.y = 0;

	Insets insets = parent.getInsets();
	availR.x = insets.left;
	availR.y = insets.top;
	availR.width -= insets.left + insets.right;
	availR.height -= insets.top + insets.bottom;

		  /* Get the scrollPane's orientation.
			*/
		  boolean leftToRight = TonicUtils.isLeftToRight(scrollPane);

	/* If there's a visible column header remove the space it 
	 * needs from the top of availR.  The column header is treated 
	 * as if it were fixed height, arbitrary width.
	 */

	Rectangle colHeadR = new Rectangle(0, availR.y, 0, 0);

	if ((colHead != null) && (colHead.isVisible())) {
		 int colHeadHeight = Math.min(availR.height,
													  colHead.getPreferredSize().height);
		 colHeadR.height = colHeadHeight; 
		 availR.y += colHeadHeight;
		 availR.height -= colHeadHeight;
	}

	/* If there's a visible row header remove the space it needs
	 * from the left or right of availR.  The row header is treated 
	 * as if it were fixed width, arbitrary height.
	 */

	Rectangle rowHeadR = new Rectangle(0, 0, 0, 0);
	
	if ((rowHead != null) && (rowHead.isVisible())) {
		 int rowHeadWidth = Math.min(availR.width,
													 rowHead.getPreferredSize().width);
		 rowHeadR.width = rowHeadWidth;
		 availR.width -= rowHeadWidth;
				if ( leftToRight ) {
					 rowHeadR.x = availR.x;
					 availR.x += rowHeadWidth;
				} else {
					 rowHeadR.x = availR.x + availR.width;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -