Debian Codegraph @

src/com/bulenkov/iconloader/util/JBInsets.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2016 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.bulenkov.iconloader.util;
17
18 import javax.swing.plaf.UIResource;
19 import java.awt.*;
20
21 import static com.bulenkov.iconloader.util.JBUI.scale;
22
23 /**
24 * @author Konstantin Bulenkov
25 */
26 public class JBInsets extends Insets {
27 /**
28 * Creates and initializes a new <code>Insets</code> object with the
29 * specified top, left, bottom, and right insets.
30 *
31 * @param top the inset from the top.
32 * @param left the inset from the left.
33 * @param bottom the inset from the bottom.
34 * @param right the inset from the right.
35 */
36 public JBInsets(int top, int left, int bottom, int right) {
37 super(scale(top), scale(left), scale(bottom), scale(right));
38 }
39
40 public int width() {
41 return left + right;
42 }
43
44 public int height() {
45 return top + bottom;
46 }
47
48 public static JBInsets create(Insets insets) {
49 if (insets instanceof JBInsets) {
50 JBInsets copy = new JBInsets(0, 0, 0, 0);
51 copy.top = insets.top;
52 copy.left = insets.left;
53 copy.bottom = insets.bottom;
54 copy.right = insets.right;
55 return copy;
56 }
57 return new JBInsets(insets.top, insets.left, insets.bottom, insets.right);
58 }
59
60 public JBInsetsUIResource asUIResource() {
61 return new JBInsetsUIResource(this);
62 }
63
64 public static class JBInsetsUIResource extends JBInsets implements UIResource {
65 public JBInsetsUIResource(JBInsets insets) {
66 super(0, 0, 0, 0);
67 top = insets.top;
68 left = insets.left;
69 bottom = insets.bottom;
70 right = insets.right;
71 }
72 }
73
74 /**
75 * @param dimension the size to increase
76 * @param insets the insets to add
77 */
78 public static void addTo(Dimension dimension, Insets insets) {
79 if (insets != null) {
80 dimension.width += insets.left + insets.right;
81 dimension.height += insets.top + insets.bottom;
82 }
83 }
84
85 /**
86 * @param dimension the size to decrease
87 * @param insets the insets to remove
88 */
89 public static void removeFrom(Dimension dimension, Insets insets) {
90 if (insets != null) {
91 dimension.width -= insets.left + insets.right;
92 dimension.height -= insets.top + insets.bottom;
93 }
94 }
95
96 /**
97 * @param rectangle the size to increase and the location to move
98 * @param insets the insets to add
99 */
100 public static void addTo(Rectangle rectangle, Insets insets) {
101 if (insets != null) {
102 rectangle.x -= insets.left;
103 rectangle.y -= insets.top;
104 rectangle.width += insets.left + insets.right;
105 rectangle.height += insets.top + insets.bottom;
106 }
107 }
108
109 /**
110 * @param rectangle the size to decrease and the location to move
111 * @param insets the insets to remove
112 */
113 public static void removeFrom(Rectangle rectangle, Insets insets) {
114 if (insets != null) {
115 rectangle.x += insets.left;
116 rectangle.y += insets.top;
117 rectangle.width -= insets.left + insets.right;
118 rectangle.height -= insets.top + insets.bottom;
119 }
120 }
121 }