01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: DimensionUtil.java,v 1.11 2005/12/04 13:46:04 jesper Exp $
23: package net.infonode.gui;
24:
25: import net.infonode.util.Direction;
26:
27: import java.awt.*;
28:
29: /**
30: * @author $Author: jesper $
31: * @version $Revision: 1.11 $
32: */
33: public class DimensionUtil {
34: public static final Dimension ZERO = new Dimension(0, 0);
35:
36: public static Dimension min(Dimension d1, Dimension d2) {
37: return new Dimension(Math.min((int) d1.getWidth(), (int) d2
38: .getWidth()), Math.min((int) d1.getHeight(), (int) d2
39: .getHeight()));
40: }
41:
42: public static Dimension max(Dimension d1, Dimension d2) {
43: return new Dimension(Math.max((int) d1.getWidth(), (int) d2
44: .getWidth()), Math.max((int) d1.getHeight(), (int) d2
45: .getHeight()));
46: }
47:
48: public static Dimension getInnerDimension(Dimension d, Insets i) {
49: return new Dimension((int) (d.getWidth() - i.left - i.right),
50: (int) (d.getHeight() - i.top - i.bottom));
51: }
52:
53: public static Dimension add(Dimension dim, Insets insets) {
54: return new Dimension(dim.width + insets.left + insets.right,
55: dim.height + insets.top + insets.bottom);
56: }
57:
58: public static Dimension add(Dimension d1, Dimension d2,
59: boolean isHorizontalAdd) {
60: return new Dimension(isHorizontalAdd ? (d1.width + d2.width)
61: : Math.max(d1.width, d2.width), isHorizontalAdd ? Math
62: .max(d1.height, d2.height) : d1.height + d2.height);
63: }
64:
65: public static Dimension rotate(Direction source, Dimension d,
66: Direction destination) {
67: if (source.isHorizontal() && destination.isHorizontal())
68: return d;
69:
70: return new Dimension(d.height, d.width);
71: }
72: }
|