Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / util / imagemaker / BitmapImageSizing.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.util.imagemaker;
22
23 import jalview.bin.Cache;
24
25 public class BitmapImageSizing
26 {
27   private final float scale;
28
29   private final int width;
30
31   private final int height;
32
33   private boolean isDefault = false;
34
35   public BitmapImageSizing(float scale, int width, int height,
36           boolean isDefault)
37   {
38     this.scale = scale;
39     this.width = width;
40     this.height = height;
41     this.isDefault = isDefault;
42   }
43
44   public boolean isNull()
45   {
46     return scale == 0.0f && width == 0 && height == 0;
47   }
48
49   public static BitmapImageSizing nullBitmapImageSizing()
50   {
51     return new BitmapImageSizing(0.0f, 0, 0, false);
52   }
53
54   public static final String BITMAP_SCALE = "BITMAP_SCALE";
55
56   public static final String BITMAP_HEIGHT = "BITMAP_HEIGHT";
57
58   public static final String BITMAP_WIDTH = "BITMAP_WIDTH";
59
60   /**
61    * 
62    * @return bean configured from Cache keys
63    */
64   public static BitmapImageSizing defaultBitmapImageSizing()
65   {
66     return new BitmapImageSizing(0f, 0, 0, true);
67   }
68
69   private float defaultScale()
70   {
71     return Cache.getDefault(BITMAP_SCALE, 0f);
72   }
73
74   private int defaultWidth()
75   {
76     return Cache.getDefault(BITMAP_WIDTH, 0);
77   }
78
79   private int defaultHeight()
80   {
81     return Cache.getDefault(BITMAP_HEIGHT, 0);
82   }
83
84   public float scale()
85   {
86     return isDefault() ? defaultScale() : scale;
87   }
88
89   public int width()
90   {
91     return isDefault() ? defaultWidth() : width;
92   }
93
94   public int height()
95   {
96     return isDefault() ? defaultHeight() : height;
97   }
98
99   public boolean isDefault()
100   {
101     return isDefault;
102   }
103 }