001 package jmaster.jumploader.model.api.config;
002
003 import java.util.MissingResourceException;
004
005 import jmaster.jumploader.model.api.IModel;
006 import jmaster.jumploader.model.api.config.ImageConfig;
007 import jmaster.util.property.Property;
008 import jmaster.util.property.PropertyFactory;
009 import jmaster.util.property.PropertyHelper;
010
011
012 /**
013 * ImageConfig
014 *
015 * @author timur
016 */
017
018 public class ImageConfig {
019 //---------------------------------------------------------------
020 // constants
021 //---------------------------------------------------------------
022 /**
023 * property file
024 */
025 private static final String PROPERTY = "ImageConfig.properties";
026 /**
027 * jpeg default quality
028 */
029 public static final int JPEG_QUALITY_DEFAULT = 800;
030 //---------------------------------------------------------------
031 // common properties
032 //---------------------------------------------------------------
033 /**
034 * jpeg compression default quality, 0..1000
035 */
036 private int jpegQuality = JPEG_QUALITY_DEFAULT;
037 /**
038 * minimum perimeter size for crop (pixels)
039 */
040 private String cropPerimeterMin = null;
041 /**
042 * crop ratio constraint (width/height), e.g. "1.44"
043 */
044 private String cropRatio = null;
045 /**
046 * crop ratio options (semicolon separated key=value pairs)
047 * to display as dropdown in an image editor,
048 * for example: "Standard=1.3333;Wide=1.7778"
049 */
050 private String cropRatioOptions = null;
051 /**
052 * shows whether image should be auto rotated using exif orientation flag
053 */
054 private boolean respectExifOrientation = true;
055 /**
056 * image editor resize options, must be text formatted as follows:
057 * ${title1};${width1};${height1};...${titleN};${widthN};${heightN};
058 * where title is a text to display, width and height - image target bounding box.
059 * Example: Small (200x100);200;100;Medium (500x300);500;300;Large (800x600);800;600
060 * this will result with 3 options.
061 */
062 private String resizeOptions = "400x300;400;300;640x480;640;480;800x600;800;600;1024x768;1024;768;1200x800;1200;800";
063 /**
064 * shows whether arbitrary resize enabled (false by default)
065 */
066 private boolean arbitraryResizeEnabled = false;
067 /**
068 * shows whether selection info should be shown on the image editor toolbar (false by default)
069 */
070 private boolean showSelectionInfo = false;
071
072 /**
073 * shows whether color picker should be shown on the image editor toolbar (false by default)
074 */
075 private boolean showColorPicker = false;
076
077 /**
078 * shows whether new image editor (with draw features) should be used (false by default)
079 */
080 private boolean useDrawEditor = false;
081
082 /**
083 * crop area dimension (pixels, {width}x{height}) to display on a draw editor.
084 * if specified and drawing does not fit in the box, then drawing margins
085 * that doesnt fit will be shahed with red.
086 */
087 private String drawEditorCropBox = null;
088
089 /**
090 * crop area target size(pixels, {width}x{height}) to resize crop result to.
091 * i.e. user crop selection aspect ratio will be constrained to w/h,
092 * crop result will be resized to w x h.
093 * If this property specified, another crop tool button will be placed on a toolbar.
094 * Original crop tool will be left intact.
095 */
096 private String drawEditorCropSize = null;
097 //---------------------------------------------------------------
098 // constructors
099 //---------------------------------------------------------------
100 /**
101 * with model
102 */
103 public ImageConfig( IModel model ) {
104 super();
105 //
106 // inject properties, if present
107 try {
108 PropertyFactory pf = PropertyFactory.getInstance();
109 Property pr = pf.getProperty( PROPERTY );
110 PropertyHelper ph = PropertyHelper.getInstance();
111 ph.injectProperties( this, pr, null );
112 } catch( MissingResourceException ignore ) {
113 }
114 }
115 //---------------------------------------------------------------
116 // property accessors
117 //---------------------------------------------------------------
118 /* (non-Javadoc)
119 * @see jmaster.jumploader.model.impl.config.xx#toString()
120 */
121 public String toString() {
122 return "" +
123 "jpegQuality=" + jpegQuality + "\r\n" +
124 "cropPerimeterMin=" + cropPerimeterMin + "\r\n" +
125 "cropRatio=" + cropRatio + "\r\n" +
126 "cropRatioOptions=" + cropRatioOptions + "\r\n" +
127 "respectExifOrientation=" + respectExifOrientation + "\r\n" +
128 "resizeOptions=" + resizeOptions + "\r\n" +
129 "arbitraryResizeEnabled=" + arbitraryResizeEnabled + "\r\n" +
130 "showSelectionInfo=" + showSelectionInfo + "\r\n" +
131 "showColorPicker=" + showColorPicker + "\r\n" +
132 "useDrawEditor=" + useDrawEditor + "\r\n" +
133 "drawEditorCropBox=" + drawEditorCropBox + "\r\n" +
134 "drawEditorCropSize=" + drawEditorCropSize + "\r\n" +
135 "";
136 }
137 public int getJpegQuality() {
138 return jpegQuality;
139 }
140 public void setJpegQuality(int jpegQuality) {
141 this.jpegQuality = jpegQuality;
142 }
143 public String getCropPerimeterMin() {
144 return cropPerimeterMin;
145 }
146 public void setCropPerimeterMin(String cropPerimeterMin) {
147 this.cropPerimeterMin = cropPerimeterMin;
148 }
149 public String getCropRatio() {
150 return cropRatio;
151 }
152 public void setCropRatio(String cropRatio) {
153 this.cropRatio = cropRatio;
154 }
155 public boolean isRespectExifOrientation() {
156 return respectExifOrientation;
157 }
158 public void setRespectExifOrientation(boolean respectExifOrientation) {
159 this.respectExifOrientation = respectExifOrientation;
160 }
161 public String getResizeOptions() {
162 return resizeOptions;
163 }
164 public void setResizeOptions(String resizeOptions) {
165 this.resizeOptions = resizeOptions;
166 }
167 public String getCropRatioOptions() {
168 return cropRatioOptions;
169 }
170 public void setCropRatioOptions(String cropRatioOptions) {
171 this.cropRatioOptions = cropRatioOptions;
172 }
173 public boolean isShowSelectionInfo() {
174 return showSelectionInfo;
175 }
176 public void setShowSelectionInfo(boolean showSelectionInfo) {
177 this.showSelectionInfo = showSelectionInfo;
178 }
179 public boolean isShowColorPicker() {
180 return showColorPicker;
181 }
182 public void setShowColorPicker(boolean showColorPicker) {
183 this.showColorPicker = showColorPicker;
184 }
185 public boolean isUseDrawEditor() {
186 return useDrawEditor;
187 }
188 public void setUseDrawEditor(boolean useDrawEditor) {
189 this.useDrawEditor = useDrawEditor;
190 }
191 public boolean isArbitraryResizeEnabled() {
192 return arbitraryResizeEnabled;
193 }
194 public void setArbitraryResizeEnabled(boolean arbitraryResizeEnabled) {
195 this.arbitraryResizeEnabled = arbitraryResizeEnabled;
196 }
197 public String getDrawEditorCropBox() {
198 return drawEditorCropBox;
199 }
200 public void setDrawEditorCropBox(String drawEditorCropBox) {
201 this.drawEditorCropBox = drawEditorCropBox;
202 }
203 public String getDrawEditorCropSize() {
204 return drawEditorCropSize;
205 }
206 public void setDrawEditorCropSize(String drawEditorCropSize) {
207 this.drawEditorCropSize = drawEditorCropSize;
208 }
209 }
210