View Javadoc

1   /***********************************************************************************************************************
2   Copyright (c) 2003, International Barcode Consortium
3   All rights reserved.
4   
5   Redistribution and use in source and binary forms, with or without modification,
6   are permitted provided that the following conditions are met:
7   
8       * Redistributions of source code must retain the above copyright notice, this list of
9         conditions and the following disclaimer.
10      * Redistributions in binary form must reproduce the above copyright notice, this list of
11        conditions and the following disclaimer in the documentation and/or other materials
12        provided with the distribution.
13      * Neither the name of the International Barcode Consortium nor the names of any contributors may be used to endorse
14        or promote products derived from this software without specific prior written permission.
15  
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
17  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  POSSIBILITY OF SUCH DAMAGE.
25  ***********************************************************************************************************************/
26  
27  package net.sourceforge.barbecue.output;
28  
29  import java.awt.*;
30  
31  /**
32   * Abstract class of which concrete implementations provide means for outputting
33   * barcodes to different output formats.
34   *
35   * @author <a href="mailto:opensource@ianbourke.com">Ian Bourke</a>
36   */
37  public abstract class AbstractOutput implements Output {
38  
39  	/** Flag indicating whether the barcode will actually be outputted, or is just being sized. */
40  	protected final boolean painting;
41  	/** The scaling factor to correctly size the barcode in the output units. */
42  	protected final double scalar;
43  	/** The font to draw any text labels with. */
44  	protected final Font font;
45  	/** The background colour for drawing */
46  	protected Color backgroundColour;
47  	/** The foreground colour for drawing */
48  	protected Color foregroundColour;
49  
50  	/**
51  	 * Populates this abstract outputter with common values.
52  	 * @param font The font to draw text labels with
53  	 * @param painting Flag indicating whether painting will actually occur
54  	 * @param scalar The scaling factor to size the barcode into the correct units
55  	 * @param foregroundColour The colour to paint in
56  	 * @param backgroundColour The background colour
57  	 */
58  	protected AbstractOutput(Font font, boolean painting,
59  							 double scalar, Color foregroundColour, Color backgroundColour) {
60  		this.painting = painting;
61  		this.scalar = scalar;
62  		this.font = font;
63  		this.foregroundColour = foregroundColour;
64  		this.backgroundColour = backgroundColour;
65  	}
66  
67  	/**
68  	 * Disables any drawing to the Output. Useful for sizing calculations.
69  	 */
70  	public void toggleDrawingColor() {
71  		Color temp = foregroundColour;
72  		foregroundColour = backgroundColour;
73  		backgroundColour = temp;
74  	}
75  }