| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.bulenkov.iconloader.util; |
| 18 |
|
| 19 |
import javax.swing.plaf.UIResource; |
| 20 |
import java.awt.*; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class JBDimension extends Dimension { |
| 26 |
public final float originalScale = JBUI.scale(1f); |
| 27 |
|
| 28 |
public JBDimension(int width, int height) { |
| 29 |
super(scale(width), scale(height)); |
| 30 |
} |
| 31 |
|
| 32 |
private static int scale(int size) { |
| 33 |
return size == -1 ? -1 : JBUI.scale(size); |
| 34 |
} |
| 35 |
|
| 36 |
public static JBDimension create(Dimension from) { |
| 37 |
if (from instanceof JBDimension) { |
| 38 |
return ((JBDimension)from); |
| 39 |
} |
| 40 |
return new JBDimension(from.width, from.height); |
| 41 |
} |
| 42 |
|
| 43 |
public JBDimensionUIResource asUIResource() { |
| 44 |
return new JBDimensionUIResource(this); |
| 45 |
} |
| 46 |
|
| 47 |
public static class JBDimensionUIResource extends JBDimension implements UIResource { |
| 48 |
public JBDimensionUIResource(JBDimension size) { |
| 49 |
super(0, 0); |
| 50 |
width = size.width; |
| 51 |
height = size.height; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public JBDimension withWidth(int width) { |
| 56 |
JBDimension size = new JBDimension(0, 0); |
| 57 |
size.width = scale(width); |
| 58 |
size.height = height; |
| 59 |
return size; |
| 60 |
} |
| 61 |
|
| 62 |
public JBDimension withHeight(int height) { |
| 63 |
JBDimension size = new JBDimension(0, 0); |
| 64 |
size.width = width; |
| 65 |
size.height = scale(height); |
| 66 |
return size; |
| 67 |
} |
| 68 |
} |