e170f0eb8e4066fac53185e08baa3f5df724431b
[jalview.git] / src / jalview / util / imagemaker / BitmapImageSizing.java
1 package jalview.util.imagemaker;
2
3 import jalview.bin.Cache;
4
5 public class BitmapImageSizing
6 {
7   private final float scale;
8
9   private final int width;
10
11   private final int height;
12
13   private boolean isDefault = false;
14
15   public BitmapImageSizing(float scale, int width, int height,
16           boolean isDefault)
17   {
18     this.scale = scale;
19     this.width = width;
20     this.height = height;
21     this.isDefault = isDefault;
22   }
23
24   public boolean isNull()
25   {
26     return scale == 0.0f && width == 0 && height == 0;
27   }
28
29   public static BitmapImageSizing nullBitmapImageSizing()
30   {
31     return new BitmapImageSizing(0.0f, 0, 0, false);
32   }
33
34   public static final String BITMAP_SCALE = "BITMAP_SCALE";
35
36   public static final String BITMAP_HEIGHT = "BITMAP_HEIGHT";
37
38   public static final String BITMAP_WIDTH = "BITMAP_WIDTH";
39
40   /**
41    * 
42    * @return bean configured from Cache keys
43    */
44   public static BitmapImageSizing defaultBitmapImageSizing()
45   {
46     return new BitmapImageSizing(0f, 0, 0, true);
47   }
48
49   private float defaultScale()
50   {
51     return Cache.getDefault(BITMAP_SCALE, 0f);
52   }
53
54   private int defaultWidth()
55   {
56     return Cache.getDefault(BITMAP_WIDTH, 0);
57   }
58
59   private int defaultHeight()
60   {
61     return Cache.getDefault(BITMAP_HEIGHT, 0);
62   }
63
64   public float scale()
65   {
66     return isDefault() ? defaultScale() : scale;
67   }
68
69   public int width()
70   {
71     return isDefault() ? defaultWidth() : width;
72   }
73
74   public int height()
75   {
76     return isDefault() ? defaultHeight() : height;
77   }
78
79   public boolean isDefault()
80   {
81     return isDefault;
82   }
83 }