rectangleinsets.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 542 行 · 第 1/2 页
JAVA
542 行
/* ======================================================================== * JCommon : a free general purpose class library for the Java(tm) platform * ======================================================================== * * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jcommon/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * -------------------- * RectangleInsets.java * -------------------- * (C) Copyright 2004, 2005, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * $Id: RectangleInsets.java,v 1.10 2005/06/01 14:12:29 taqua Exp $ * * Changes: * -------- * 11-Feb-2004 : Version 1 (DG); * 14-Jun-2004 : Implemented Serializable (DG); * 02-Feb-2005 : Added new methods and renamed some existing methods (DG); * 22-Feb-2005 : Added a new constructor for convenience (DG); * 19-Apr-2005 : Changed order of parameters in constructors to match * java.awt.Insets (DG); * */package org.jfree.ui;import java.awt.geom.Rectangle2D;import java.io.Serializable;import org.jfree.util.UnitType;/** * Represents the insets for a rectangle, specified in absolute or relative * terms. This class is immutable. * * @author David Gilbert */public class RectangleInsets implements Serializable { /** For serialization. */ private static final long serialVersionUID = 1902273207559319996L; /** * A useful constant representing zero insets. */ public static final RectangleInsets ZERO_INSETS = new RectangleInsets( UnitType.ABSOLUTE, 0.0, 0.0, 0.0, 0.0 ); /** Absolute or relative units. */ private UnitType unitType; /** The top insets. */ private double top; /** The left insets. */ private double left; /** The bottom insets. */ private double bottom; /** The right insets. */ private double right; /** * Creates a new instance with the specified insets (as 'absolute' units). * * @param top the top insets. * @param left the left insets. * @param bottom the bottom insets. * @param right the right insets. */ public RectangleInsets(final double top, final double left, final double bottom, final double right) { this(UnitType.ABSOLUTE, top, left, bottom, right); } /** * Creates a new instance. * * @param unitType absolute or relative units (<code>null</code> not * permitted). * @param top the top insets. * @param left the left insets. * @param bottom the bottom insets. * @param right the right insets. */ public RectangleInsets(final UnitType unitType, final double top, final double left, final double bottom, final double right) { if (unitType == null) { throw new IllegalArgumentException("Null 'unitType' argument."); } this.unitType = unitType; this.top = top; this.bottom = bottom; this.left = left; this.right = right; } /** * Returns the unit type (absolute or relative). This specifies whether * the insets are measured as Java2D units or percentages. * * @return The unit type (never <code>null</code>). */ public UnitType getUnitType() { return this.unitType; } /** * Returns the top insets. * * @return The top insets. */ public double getTop() { return this.top; } /** * Returns the bottom insets. * * @return The bottom insets. */ public double getBottom() { return this.bottom; } /** * Returns the left insets. * * @return The left insets. */ public double getLeft() { return this.left; } /** * Returns the right insets. * * @return The right insets. */ public double getRight() { return this.right; } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof RectangleInsets)) { return false; } final RectangleInsets that = (RectangleInsets) obj; if (that.unitType != this.unitType) { return false; } if (this.left != that.left) { return false; } if (this.right != that.right) { return false; } if (this.top != that.top) { return false; } if (this.bottom != that.bottom) { return false; } return true; } /** * Returns a hash code for the object. * * @return A hash code. */ public int hashCode() { int result; long temp; result = (this.unitType != null ? this.unitType.hashCode() : 0); temp = this.top != +0.0d ? Double.doubleToLongBits(this.top) : 0l; result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = this.bottom != +0.0d ? Double.doubleToLongBits(this.bottom) : 0l; result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = this.left != +0.0d ? Double.doubleToLongBits(this.left) : 0l; result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = this.right != +0.0d ? Double.doubleToLongBits(this.right) : 0l; result = 29 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Creates an adjusted rectangle using the supplied rectangle, the insets * specified by this instance, and the horizontal and vertical * adjustment types. * * @param base the base rectangle (<code>null</code> not permitted). * @param horizontal the horizontal adjustment type (<code>null</code> not * permitted). * @param vertical the vertical adjustment type (<code>null</code> not * permitted). * * @return The inset rectangle. */ public Rectangle2D createAdjustedRectangle(final Rectangle2D base, final LengthAdjustmentType horizontal, final LengthAdjustmentType vertical) { if (base == null) { throw new IllegalArgumentException("Null 'base' argument."); } double x = base.getX(); double y = base.getY(); double w = base.getWidth(); double h = base.getHeight(); if (horizontal == LengthAdjustmentType.EXPAND) { final double leftOutset = calculateLeftOutset(w); x = x - leftOutset; w = w + leftOutset + calculateRightOutset(w); } else if (horizontal == LengthAdjustmentType.CONTRACT) { final double leftMargin = calculateLeftInset(w); x = x + leftMargin; w = w - leftMargin - calculateRightInset(w); } if (vertical == LengthAdjustmentType.EXPAND) { final double topMargin = calculateTopOutset(h); y = y - topMargin; h = h + topMargin + calculateBottomOutset(h); } else if (vertical == LengthAdjustmentType.CONTRACT) { final double topMargin = calculateTopInset(h); y = y + topMargin; h = h - topMargin - calculateBottomInset(h); } return new Rectangle2D.Double(x, y, w, h); } /** * Creates an 'inset' rectangle. * * @param base the base rectangle (<code>null</code> not permitted).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?