56
|
1 |
/*
|
87
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
56
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.microedition.m2g;
|
|
19 |
|
|
20 |
import org.w3c.dom.svg.*;
|
|
21 |
|
|
22 |
public class M2GSVGRGBColor implements SVGRGBColor
|
|
23 |
{
|
|
24 |
//--------------------------------------------------
|
|
25 |
// STATIC CONSTANTS
|
|
26 |
//--------------------------------------------------
|
|
27 |
private static final int R = 0;
|
|
28 |
private static final int G = 1;
|
|
29 |
private static final int B = 2;
|
|
30 |
// Exception text
|
|
31 |
private static final String OUT_OF_RANGE_ESTR =
|
|
32 |
"Color values out of range.";
|
|
33 |
|
|
34 |
//--------------------------------------------------
|
|
35 |
// VARIABLES
|
|
36 |
//--------------------------------------------------
|
|
37 |
private int[] iComponents;
|
|
38 |
|
|
39 |
//--------------------------------------------------
|
|
40 |
// METHODS
|
|
41 |
//--------------------------------------------------
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Constructor. Defualt color is black.
|
|
45 |
v */
|
|
46 |
public M2GSVGRGBColor()
|
|
47 |
{
|
|
48 |
iComponents = new int[3];
|
|
49 |
iComponents[R] = 0;
|
|
50 |
iComponents[G] = 0;
|
|
51 |
iComponents[B] = 0;
|
|
52 |
}
|
|
53 |
|
|
54 |
/**
|
|
55 |
* Constructor
|
|
56 |
* @param aR -
|
|
57 |
v * @param aG -
|
|
58 |
v * @param aB -
|
|
59 |
v */
|
|
60 |
public M2GSVGRGBColor(int aR, int aG, int aB) throws SVGException
|
|
61 |
{
|
|
62 |
checkValues(aR, aG, aB);
|
|
63 |
iComponents = new int[3];
|
|
64 |
iComponents[R] = aR;
|
|
65 |
iComponents[G] = aG;
|
|
66 |
iComponents[B] = aB;
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
|
70 |
* Checks value range
|
|
71 |
* @param aR
|
|
72 |
* @param aG
|
|
73 |
* @param aB
|
|
74 |
*/
|
|
75 |
protected void checkValues(int aR, int aG, int aB) throws SVGException
|
|
76 |
{
|
|
77 |
if (((aR > 255) || (aR < 0)) ||
|
|
78 |
((aG > 255) || (aG < 0)) ||
|
|
79 |
((aB > 255) || (aB < 0)))
|
|
80 |
{
|
|
81 |
throw new SVGException(
|
|
82 |
SVGException.SVG_INVALID_VALUE_ERR, OUT_OF_RANGE_ESTR);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Gets components
|
|
88 |
* @return components
|
|
89 |
*/
|
|
90 |
int[] getComponents()
|
|
91 |
{
|
|
92 |
return iComponents;
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* @see org.w3c.dom.svg.SVGRGBColor#getRed()
|
|
97 |
*/
|
|
98 |
public int getRed()
|
|
99 |
{
|
|
100 |
return iComponents[R];
|
|
101 |
}
|
|
102 |
|
|
103 |
/**
|
|
104 |
* @see org.w3c.dom.svg.SVGRGBColor#getGreen()
|
|
105 |
*/
|
|
106 |
public int getGreen()
|
|
107 |
{
|
|
108 |
return iComponents[G];
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* @see org.w3c.dom.svg.SVGRGBColor#getBlue()
|
|
113 |
*/
|
|
114 |
public int getBlue()
|
|
115 |
{
|
|
116 |
return iComponents[B];
|
|
117 |
}
|
|
118 |
|
|
119 |
public String toString()
|
|
120 |
{
|
|
121 |
return "SVGRGBColor( r = " + iComponents[R] + ", g = " +
|
|
122 |
iComponents[G] + ", b = " + iComponents[B] + " )";
|
|
123 |
}
|
|
124 |
}
|