| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 25 |
|
| 26 |
public class JBInsets extends Insets { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 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 |
|
| 76 |
|
| 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 |
|
| 87 |
|
| 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 |
|
| 98 |
|
| 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 |
|
| 111 |
|
| 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 |
} |