alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.editor.view.spi;

import java.io.Serializable;

/**
 * Immutable analogy of the {@link java.awt.Insets} based
 * on floats.
 * 
* Any view implementation may benefit from presence * of this class. * *

* As the views of a same type should possibly use the same * insets there is a potential for sharing * of ViewInsets instances. * * @author Miloslav Metelka * @version 1.00 */ public final class ViewInsets implements Serializable { public static final ViewInsets ZERO_INSETS = new ViewInsets(0, 0, 0, 0); private float top; private float left; private float bottom; private float right; /** * Creates and initializes a new ViewInsets object with the * specified top, left, bottom, and right insets. * @param top the inset from the top. * @param left the inset from the left. * @param bottom the inset from the bottom. * @param right the inset from the right. */ public ViewInsets(float top, float left, float bottom, float right) { this.top = top; this.left = left; this.bottom = bottom; this.right = right; } public float getTop() { return top; } public float getLeft() { return left; } public float getBottom() { return bottom; } public float getRight() { return right; } public float getLeftRight() { return left + right; } public float getTopBottom() { return top + bottom; } /** * Checks whether two float insets objects are equal. Two instances * of ViewInsets are equal if the four float values * of the fields top, left, * bottom, and right are all equal. * @return true if the two float insets are equal; * otherwise false. */ public boolean equals(Object obj) { if (obj instanceof ViewInsets) { ViewInsets insets = (ViewInsets)obj; return ((top == insets.top) && (left == insets.left) && (bottom == insets.bottom) && (right == insets.right)); } return false; } /** * Returns the hash code for this Insets. * * @return a hash code for this Insets. */ public int hashCode() { float sum1 = left + bottom; float sum2 = right + top; float val1 = sum1 * (sum1 + 1)/2 + left; float val2 = sum2 * (sum2 + 1)/2 + top; int sum3 = (int)(val1 + val2); return sum3 * (sum3 + 1)/2 + (int)val2; } /** * Returns a string representation of this Insets object. * This method is intended to be used only for debugging purposes, and * the content and format of the returned string may vary between * implementations. The returned string may be empty but may not be * null. * * @return a string representation of this Insets object. */ public String toString() { return getClass().getName() + "[top=" + top + ",left=" + left // NOI18N + ",bottom=" + bottom + ",right=" + right + "]"; // NOI18N } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.