mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 12:00:17 +02:00
better implementation for ZLColor class
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@153 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
882289c560
commit
62dba68578
2 changed files with 60 additions and 130 deletions
|
@ -11,7 +11,6 @@ import org.zlibrary.options.util.*;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class ZLColorOption extends ZLOption {
|
public final class ZLColorOption extends ZLOption {
|
||||||
|
|
||||||
private long myIntValue;
|
private long myIntValue;
|
||||||
private long myDefaultValue;
|
private long myDefaultValue;
|
||||||
|
|
||||||
|
@ -24,8 +23,7 @@ public final class ZLColorOption extends ZLOption {
|
||||||
public long getValue(){
|
public long getValue(){
|
||||||
if (!myIsSynchronized){
|
if (!myIsSynchronized){
|
||||||
String strDefaultValue = ZLToStringConverter.convert(myDefaultValue);
|
String strDefaultValue = ZLToStringConverter.convert(myDefaultValue);
|
||||||
String value = myConfig.getValue(myCategory, myGroup,
|
String value = myConfig.getValue(myCategory, myGroup, myOptionName, strDefaultValue);
|
||||||
myOptionName, strDefaultValue);
|
|
||||||
myIntValue = ZLFromStringConverter.getIntegerValue(value);
|
myIntValue = ZLFromStringConverter.getIntegerValue(value);
|
||||||
myIsSynchronized = true;
|
myIsSynchronized = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,114 +1,46 @@
|
||||||
package org.zlibrary.options.util;
|
package org.zlibrary.options.util;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ñóùíîñòü "öâåò". ïðåäñòàâëåíèå çäåñü - ñòàíäàðòíûå RGB êîìïîíåíòû
|
* class Color. Color is presented as the triple of short's (Red, Green, Blue components)
|
||||||
* @author Àäìèíèñòðàòîð
|
* Each component should be in the range 0..255
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ZLColor {
|
public class ZLColor {
|
||||||
|
public final short Red;
|
||||||
|
public final short Green;
|
||||||
|
public final short Blue;
|
||||||
|
|
||||||
private int myRed = 0;
|
public ZLColor() {
|
||||||
private int myGreen = 0;
|
Red = 0;
|
||||||
private int myBlue = 0;
|
Green = 0;
|
||||||
|
Blue = 0;
|
||||||
/**
|
|
||||||
* è êîíñòðóêòîð ñîîòâåòñòâåííî äëÿ óäîáñòâà
|
|
||||||
* @param color
|
|
||||||
*/
|
|
||||||
public ZLColor(Color color){
|
|
||||||
setColor((int)color.getRed(), (int)color.getGreen(), (int)color.getBlue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ZLColor(short r, short g, short b) {
|
||||||
* êîíñòðóêòîð ïî óìîë÷àíèþ äåëàåò öâåò ÷åðíûì
|
Red = (short)(r & 0xFF);
|
||||||
*/
|
Green = (short)(g & 0xFF);
|
||||||
public ZLColor(){
|
Blue = (short)(b & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ZLColor(int intValue) {
|
||||||
* êîíñòðóêòîð ñ ïàðàìåòðàìè
|
Red = (short)((intValue >> 16) & 0xFF);
|
||||||
*/
|
Green = (short)((intValue >> 8) & 0xFF);
|
||||||
public ZLColor(int red, int green, int blue){
|
Blue = (short)(intValue & 0xFF);
|
||||||
setColor(red, green, blue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLColor(String color){
|
public int getIntValue() {
|
||||||
String[] components = color.split(",");
|
return (Red << 16) + (Green << 8) + Blue;
|
||||||
setColor(Integer.parseInt(components[0]), Integer.parseInt(components[1]),
|
|
||||||
Integer.parseInt(components[2]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean equals(Object o) {
|
||||||
* ïåðåêðûâàåì ìåòîä toString,
|
if (o == this) {
|
||||||
* ïî ñóòè - êîäèðîâêà â äåñÿòè÷íóþ çàïèñü
|
|
||||||
* ðåçóëüòàò äîëæåí íàãëÿäíî ñîâïàäàòü ñ ðåçóëüòàòîì getIntValue
|
|
||||||
*/
|
|
||||||
public String toString(){
|
|
||||||
return "" + myRed + "," + myGreen + "," + myBlue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ÿâëÿåòñÿ ëè ÷èñëî êîððåêòíûì çíà÷åíèåì êîìïîíåíòû ðãá öâåòà.
|
|
||||||
*/
|
|
||||||
private boolean isCorrectComponent(int value){
|
|
||||||
return (value >=0 && value <= 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* óñòàíàâëèâàåì òîëüêî òå êîìïîíåíòû, êîòîðûå çàäàíû êîððåêòíî,
|
|
||||||
* òî åñòü ÿâëÿþòñÿ íåîòðèöàòåëüíûì ÷èñëîì < 256
|
|
||||||
*/
|
|
||||||
public void setColor (int red, int green, int blue){
|
|
||||||
if (isCorrectComponent(red)) {
|
|
||||||
myRed = red;
|
|
||||||
}
|
|
||||||
if (isCorrectComponent(green)) {
|
|
||||||
myGreen = green;
|
|
||||||
}
|
|
||||||
if (isCorrectComponent(blue)) {
|
|
||||||
myBlue = blue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* êîíâåðòèðîâàíèå â ÀÂÒøíûé öâåò.
|
|
||||||
* @param color
|
|
||||||
*/
|
|
||||||
//TODO ðåøèòü íóæíî ëè ýòî âîîáùå
|
|
||||||
public void convertFromColor(Color color){
|
|
||||||
myRed = (int)color.getRed();
|
|
||||||
myGreen = (int)color.getGreen();
|
|
||||||
myBlue = (int)color.getBlue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color convertToColor(){
|
|
||||||
return new Color(myRed, myGreen, myBlue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return öâåò îäíèì ÷èñëîì, ÷òîáû õðàíèòü â ïàìÿòè ìåíüøå =)
|
|
||||||
*/
|
|
||||||
public long getIntValue(){
|
|
||||||
return myRed*1000000 + myGreen*1000 + myBlue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ïåðåêðûâàåì ìåòîä equals. öâåòà ñ÷èòàåì ðàâíûìè ïðè ðàâåíñòâå âñåõ êîìïîíåíò
|
|
||||||
*/
|
|
||||||
public boolean equals (Object o){
|
|
||||||
if (o == this)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (! (o.getClass() == this.getClass()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ZLColor zlc = (ZLColor) o;
|
|
||||||
|
|
||||||
return ((zlc.myRed == this.myRed) &&
|
|
||||||
(zlc.myGreen == this.myGreen) &&
|
|
||||||
(zlc.myBlue == this.myBlue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(o instanceof ZLColor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLColor color = (ZLColor)o;
|
||||||
|
return (color.Red == Red) && (color.Green == Green) && (color.Blue == Blue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue