Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebLookAndFeel 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebLookAndFeel library.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.*;

public class Main {
    /**
     * Returns minimum insets combined from the specified ones.
     *
     * @param insets1 first insets
     * @param insets2 second insets
     * @return minimum insets
     */
    public static Insets min(final Insets insets1, final Insets insets2) {
        if (insets1 != null && insets2 != null) {
            return new Insets(Math.min(insets1.top, insets2.top), Math.min(insets1.left, insets2.left),
                    Math.min(insets1.bottom, insets2.bottom), Math.min(insets1.right, insets2.right));
        } else if (insets1 != null) {
            return insets1;
        } else if (insets2 != null) {
            return insets2;
        } else {
            return null;
        }
    }

    /**
     * Returns minimum dimension combined from specified components dimensions.
     *
     * @param component1 first component
     * @param component2 second component
     * @return minimum dimension
     */
    public static Dimension min(final Component component1, final Component component2) {
        return min(component1.getPreferredSize(), component2.getPreferredSize());
    }

    /**
     * Returns minimum dimension combined from specified ones.
     *
     * @param dimension1 first dimension
     * @param dimension2 second dimension
     * @return minimum dimension
     */
    public static Dimension min(final Dimension dimension1, final Dimension dimension2) {
        if (dimension1 == null || dimension2 == null) {
            return null;
        } else {
            return new Dimension(Math.min(dimension1.width, dimension2.width),
                    Math.min(dimension1.height, dimension2.height));
        }
    }
}