Clover icon

Magnolia Imaging Module 3.4.2-SUPPORT-10161

  1. Project Clover database Tue Jul 16 2019 23:33:19 EEST
  2. Package info.magnolia.imaging.operations.load

File Blank.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
16
5
1
137
69
7
0.44
3.2
5
1.4
39% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
Blank 53 16 39% 7 2
0.9292%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.imaging.operations.load;
35   
36    import info.magnolia.imaging.ImagingException;
37    import info.magnolia.imaging.ParameterProvider;
38    import info.magnolia.imaging.operations.ImageOperation;
39   
40    import java.awt.Color;
41    import java.awt.Graphics2D;
42    import java.awt.Rectangle;
43    import java.awt.image.BufferedImage;
44   
45    /**
46    * Just generates an empty BufferedImage canvas, fills it with the specified color if any.
47    * Use this if you don't use an image background.
48    *
49    * TODO -- maybe merge this into ImageGenerator. At least provide a simpler way for non-transparent images...
50    *
51    * @param <P> type of the ParameterProvider
52    */
 
53    public class Blank<P extends ParameterProvider<?>> implements ImageOperation<P> {
54    private static final int DEFAULT_TYPE = BufferedImage.TYPE_INT_ARGB_PRE;
55    private static final int DEFAULT_SIZE = 200;
56    private int type;
57    private Color backgroundColor;
58    private int width;
59    private int height;
60   
 
61  1 toggle public Blank() {
62  1 this(DEFAULT_SIZE, DEFAULT_SIZE);
63    }
64   
 
65  3 toggle public Blank(int width, int height) {
66  3 this(null, width, height);
67    }
68   
 
69  4 toggle public Blank(Color backgroundColor, int width, int height) {
70  4 this(DEFAULT_TYPE, backgroundColor, width, height);
71    }
72   
 
73  4 toggle public Blank(int type, Color backgroundColor, int width, int height) {
74  4 this.type = type;
75  4 this.backgroundColor = backgroundColor;
76  4 this.width = width;
77  4 this.height = height;
78    }
79   
 
80  4 toggle @Override
81    public BufferedImage apply(BufferedImage source, P params) throws ImagingException {
82  4 if (source != null) {
83  0 throw new ImagingException("This operation currently does not support overlaying images");
84    }
85   
86  4 final BufferedImage img = new BufferedImage(width, height, type);
87   
88  4 if (backgroundColor != null) {
89  2 final Graphics2D g = img.createGraphics();
90  2 g.setColor(backgroundColor);
91  2 g.fill(new Rectangle(0, 0, width, height));
92  2 g.dispose();
93    }
94   
95  4 return img;
96    }
97   
 
98    toggle public int getType() {
99    return type;
100    }
101   
102    /**
103    * One of BufferedImage.TYPE_*; defaults to TYPE_INT_ARGB_PRE.
104    *
105    * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
106    */
 
107    toggle public void setType(int type) {
108    this.type = type;
109    }
110   
 
111    toggle public Color getBackgroundColor() {
112    return backgroundColor;
113    }
114   
115    /**
116    * Background color for the new canvas. Default to white.
117    */
 
118    toggle public void setBackgroundColor(Color backgroundColor) {
119    this.backgroundColor = backgroundColor;
120    }
121   
 
122    toggle public int getWidth() {
123    return width;
124    }
125   
 
126    toggle public void setWidth(int width) {
127    this.width = width;
128    }
129   
 
130    toggle public int getHeight() {
131    return height;
132    }
133   
 
134    toggle public void setHeight(int height) {
135    this.height = height;
136    }
137    }