| 1 |
// Copyright 2007 FreeHEP |
| 2 |
package org.freehep.graphicsio.emf.gdi; |
| 3 |
|
| 4 |
import java.awt.Color; |
| 5 |
import java.awt.Font; |
| 6 |
|
| 7 |
import org.freehep.graphicsio.emf.EMFConstants; |
| 8 |
|
| 9 |
/** |
| 10 |
* StockObjects.java |
| 11 |
* |
| 12 |
* Created: Wed Dec 20 14:20:00 2006 |
| 13 |
* |
| 14 |
* Copyright: |
| 15 |
* Company: |
| 16 |
* |
| 17 |
* @author Daniel Noll [email protected] |
| 18 |
* @version $Id: freehep-graphicsio-emf/src/main/java/org/freehep/graphicsio/emf/gdi/StockObjects.java c0f15e7696d3 2007/01/22 19:26:48 duns $ |
| 19 |
*/ |
| 20 |
|
| 21 |
public class StockObjects { |
| 22 |
// Supported by all versions of Win32... |
| 23 |
private static final int WHITE_BRUSH = 0; |
| 24 |
private static final int LTGRAY_BRUSH = 1; |
| 25 |
private static final int GRAY_BRUSH = 2; |
| 26 |
private static final int DKGRAY_BRUSH = 3; |
| 27 |
private static final int BLACK_BRUSH = 4; |
| 28 |
private static final int NULL_BRUSH = 5; |
| 29 |
private static final int WHITE_PEN = 6; |
| 30 |
private static final int BLACK_PEN = 7; |
| 31 |
private static final int NULL_PEN = 8; |
| 32 |
private static final int OEM_FIXED_FONT = 10; |
| 33 |
private static final int ANSI_FIXED_FONT = 11; |
| 34 |
private static final int ANSI_VAR_FONT = 12; |
| 35 |
private static final int SYSTEM_FONT = 13; |
| 36 |
private static final int DEVICE_DEFAULT_FONT = 14; |
| 37 |
private static final int DEFAULT_PALETTE = 15; |
| 38 |
private static final int SYSTEM_FIXED_FONT = 16; |
| 39 |
|
| 40 |
// Windows 2000 or later... |
| 41 |
private static final int DEFAULT_GUI_FONT = 17; |
| 42 |
|
| 43 |
// Windows XP or later... |
| 44 |
// These ones are magic. They take the colour of the current device context |
| 45 |
// as set by SetDCBrushColor and SetDCPenColor |
| 46 |
private static final int DC_BRUSH = 18; |
| 47 |
private static final int DC_PEN = 19; |
| 48 |
|
| 49 |
private static final GDIObject[] objects = new GDIObject[20]; |
| 50 |
static { |
| 51 |
Color nullColor = new Color(0, 0, 0, 0); |
| 52 |
|
| 53 |
objects[WHITE_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.WHITE, 0); |
| 54 |
objects[LTGRAY_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.LIGHT_GRAY, 0); |
| 55 |
objects[GRAY_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.GRAY, 0); |
| 56 |
objects[DKGRAY_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.DARK_GRAY, 0); |
| 57 |
objects[BLACK_BRUSH] = new LogBrush32(EMFConstants.BS_SOLID, Color.BLACK, 0); |
| 58 |
objects[NULL_BRUSH] = new LogBrush32(EMFConstants.BS_NULL, nullColor, 0); |
| 59 |
|
| 60 |
objects[WHITE_PEN] = new LogPen(EMFConstants.PS_SOLID, 1, Color.WHITE); |
| 61 |
objects[BLACK_PEN] = new LogPen(EMFConstants.PS_SOLID, 1, Color.BLACK); |
| 62 |
objects[NULL_PEN] = new LogPen(EMFConstants.PS_NULL, 1, nullColor); |
| 63 |
|
| 64 |
// XXX: Should these depend on the look and feel? |
| 65 |
objects[OEM_FIXED_FONT] = new LogFontW(new Font("Monospaced", Font.PLAIN, 12)); |
| 66 |
objects[ANSI_FIXED_FONT] = objects[OEM_FIXED_FONT]; |
| 67 |
objects[ANSI_VAR_FONT] = new LogFontW(new Font("SansSerif", Font.PLAIN, 12)); |
| 68 |
objects[SYSTEM_FONT] = new LogFontW(new Font("Dialog", Font.PLAIN, 12)); |
| 69 |
objects[DEVICE_DEFAULT_FONT] = objects[ANSI_VAR_FONT]; |
| 70 |
objects[SYSTEM_FIXED_FONT] = objects[OEM_FIXED_FONT]; |
| 71 |
objects[DEFAULT_GUI_FONT] = objects[SYSTEM_FONT]; |
| 72 |
|
| 73 |
// TODO: DEFAULT_PALETTE, DC_BRUSH and DC_PEN |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Gets a stock object by value. |
| 78 |
* |
| 79 |
* @param value the value. |
| 80 |
* @return the stock object. |
| 81 |
*/ |
| 82 |
public static GDIObject getStockObject(int value) { |
| 83 |
if (value >= 0) { |
| 84 |
throw new IllegalArgumentException("Value does not represent a stock object: " + value); |
| 85 |
} |
| 86 |
|
| 87 |
value ^= 0x80000000; |
| 88 |
|
| 89 |
if (value >= objects.length) { |
| 90 |
throw new IllegalArgumentException("Stock object is out of bounds: " + value); |
| 91 |
} |
| 92 |
|
| 93 |
GDIObject object = objects[value]; |
| 94 |
if (object == null) { |
| 95 |
throw new UnsupportedOperationException("Stock object not yet supported: " + value); |
| 96 |
} |
| 97 |
|
| 98 |
return object; |
| 99 |
} |
| 100 |
} |