mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Source: Restore broken commit
This commit is contained in:
46
150_gfui/src/gplx/gfui/draws/ColorAdp.java
Normal file
46
150_gfui/src/gplx/gfui/draws/ColorAdp.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
import gplx.core.strings.*; import gplx.core.encoders.*;
|
||||
public class ColorAdp {
|
||||
public int Value() {return val;} int val;
|
||||
public int Alpha() {return (255 & val >> 24);}
|
||||
public int Red () {return (255 & val >> 16);}
|
||||
public int Green() {return (255 & val >> 8);}
|
||||
public int Blue() {return (255 & val);}
|
||||
public String XtoHexStr() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
sb.Add("#");
|
||||
sb.Add(Hex_utl_.To_str(Alpha(), 2));
|
||||
sb.Add(Hex_utl_.To_str(Red(), 2));
|
||||
sb.Add(Hex_utl_.To_str(Green(), 2));
|
||||
sb.Add(Hex_utl_.To_str(Blue(), 2));
|
||||
return sb.To_str();
|
||||
}
|
||||
public boolean Eq(Object obj) {
|
||||
ColorAdp comp = ColorAdp_.as_(obj); if (comp == null) return false;
|
||||
return Object_.Eq(val, comp.val);
|
||||
}
|
||||
@Override public String toString() {return XtoHexStr();}
|
||||
public Object CloneNew() {return this;} // NOTE: 'return this' works b/c ColorAdp is read-only class; needed for comparisons; ex: ColorAdp_.Null == ColorAdp_.Null.CloneNew(); alternative would fail: return ColorAdp.new_(this.Alpha(), this.Red(), this.Green(), this.Blue());}
|
||||
public static ColorAdp new_(int alpha, int red, int green, int blue) {
|
||||
ColorAdp rv = new ColorAdp();
|
||||
rv.val = (int)((alpha << 24) | (red << 16) | (green << 8) | (blue));
|
||||
return rv;
|
||||
} ColorAdp() {}
|
||||
}
|
||||
28
150_gfui/src/gplx/gfui/draws/ColorAdpCache.java
Normal file
28
150_gfui/src/gplx/gfui/draws/ColorAdpCache.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
public class ColorAdpCache {
|
||||
public java.awt.Color GetNativeColor(ColorAdp color) {
|
||||
Object rv = hash.Get_by(color.Value()); if (rv != null) return (java.awt.Color)rv;
|
||||
rv = new java.awt.Color(color.Red(), color.Green(), color.Blue(), color.Alpha());
|
||||
hash.Add(color.Value(), rv);
|
||||
return (java.awt.Color)rv;
|
||||
}
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
public static final ColorAdpCache Instance = new ColorAdpCache(); ColorAdpCache() {}
|
||||
}
|
||||
118
150_gfui/src/gplx/gfui/draws/ColorAdp_.java
Normal file
118
150_gfui/src/gplx/gfui/draws/ColorAdp_.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
import gplx.core.encoders.*; import gplx.core.interfaces.*;
|
||||
public class ColorAdp_ implements ParseAble {
|
||||
public static ColorAdp as_(Object obj) {return obj instanceof ColorAdp ? (ColorAdp)obj : null;}
|
||||
public static ColorAdp cast(Object obj) {try {return (ColorAdp)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, ColorAdp.class, obj);}}
|
||||
public static ColorAdp new_(int a, int r, int g, int b) {return ColorAdp.new_((int)a, (int)r, (int)g, (int)b);}
|
||||
public static final ColorAdp_ Parser = new ColorAdp_();
|
||||
public Object ParseAsObj(String raw) {return ColorAdp_.parse(raw);}
|
||||
public static ColorAdp parseOr_(String raw, ColorAdp or) {
|
||||
ColorAdp rv = parse_internal_(raw); if (rv == null) return or;
|
||||
return rv;
|
||||
}
|
||||
public static ColorAdp parse(String raw) {
|
||||
ColorAdp rv = parse_internal_(raw); if (rv == null) throw Err_.new_parse_type(ColorAdp.class, raw);
|
||||
return rv;
|
||||
}
|
||||
static ColorAdp parse_internal_(String raw) {
|
||||
if (raw == null) return null;
|
||||
char firstChar = String_.CharAt(raw, 0);
|
||||
if (firstChar == '#') return parse_hex_(raw);
|
||||
else if (Char_.IsNumber(firstChar)) return parse_int_(raw);
|
||||
String rawLower = String_.Lower(raw);
|
||||
if (String_.Eq(rawLower, "black")) return Black;
|
||||
else if (String_.Eq(rawLower, "white")) return White;
|
||||
else if (String_.Eq(rawLower, "gray")) return Gray;
|
||||
else if (String_.Eq(rawLower, "red")) return Red;
|
||||
else if (String_.Eq(rawLower, "lime")) return Lime;
|
||||
else if (String_.Eq(rawLower, "blue")) return Blue;
|
||||
else if (String_.Eq(rawLower, "yellow")) return Yellow;
|
||||
else if (String_.Eq(rawLower, "fuchsia")) return Fuchsia;
|
||||
else if (String_.Eq(rawLower, "maroon")) return Maroon;
|
||||
else if (String_.Eq(rawLower, "green")) return Green;
|
||||
else if (String_.Eq(rawLower, "navy")) return Navy;
|
||||
else if (String_.Eq(rawLower, "olive")) return Olive;
|
||||
else if (String_.Eq(rawLower, "purple")) return Purple;
|
||||
else if (String_.Eq(rawLower, "teal")) return Teal;
|
||||
else if (String_.Eq(rawLower, "brown")) return Brown;
|
||||
else if (String_.Eq(rawLower, "lightgray")) return LightGray;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
@gplx.Internal protected static ColorAdp parse_hex_(String raw) {
|
||||
try {
|
||||
int[] ary = new int[4]; // make ARGB ary
|
||||
int idx = 0;
|
||||
int rawLen = String_.Len(raw);
|
||||
for (int i = 1; i < rawLen; i += 2) { // fill ARGB ary by parsing raw 2 at a time; EX: #FFFFFFFF -> 255,255,255,255; NOTE: start at 1 to ignore leading #
|
||||
String hexStr = String_.MidByLen(raw, i, 2);
|
||||
ary[idx++] = Hex_utl_.Parse(hexStr);
|
||||
}
|
||||
return ColorAdp.new_(ary[0], ary[1], ary[2], ary[3]);
|
||||
} catch (Exception exc) {throw Err_.new_parse_exc(exc, ColorAdp.class, raw);}
|
||||
}
|
||||
@gplx.Internal protected static ColorAdp parse_int_(String v) {
|
||||
String[] ary = String_.Split(v, ",");
|
||||
switch (ary.length) {
|
||||
case 1: return new_int_(Int_.parse(ary[0]));
|
||||
case 3:
|
||||
case 4: return parse_int_ary_(ary);
|
||||
default: throw Err_.new_wo_type("invalid array", "len", ary.length);
|
||||
}
|
||||
}
|
||||
static ColorAdp parse_int_ary_(String[] ary) {
|
||||
int a;
|
||||
int idx = 0;
|
||||
if (ary.length == 3) {idx = 0; a = 255;}
|
||||
else {idx = 1; a = Int_.parse(ary[0]);}
|
||||
int r = Int_.parse(ary[idx++]);
|
||||
int g = Int_.parse(ary[idx++]);
|
||||
int b = Int_.parse(ary[idx++]);
|
||||
return ColorAdp_.new_(a, r, g, b);
|
||||
}
|
||||
public static ColorAdp new_int_(int val) {
|
||||
int a = ((val >> 24) & 255);
|
||||
int r = ((val >> 16) & 255);
|
||||
int g = ((val >> 8) & 255);
|
||||
int b = ((val) & 255);
|
||||
return ColorAdp.new_(a, r, g, b);
|
||||
}
|
||||
public static ColorAdp read_(Object o) {String s = String_.as_(o); return s != null ? ColorAdp_.parse(s) : ColorAdp_.cast(o);}
|
||||
public static final ColorAdp
|
||||
Null = new_( 0, 0, 0, 0)
|
||||
, Black = new_(255, 0, 0, 0)
|
||||
, White = new_(255, 255, 255, 255)
|
||||
, Gray = new_(255, 128, 128, 128)
|
||||
, Red = new_(255, 255, 0, 0)
|
||||
, Lime = new_(255, 0, 255, 0)
|
||||
, Blue = new_(255, 0, 0, 255)
|
||||
, Yellow = new_(255, 255, 255, 0)
|
||||
, Fuchsia = new_(255, 255, 0, 255)
|
||||
, Aqua = new_(255, 0, 255, 255)
|
||||
, Maroon = new_(255, 128, 0, 0)
|
||||
, Green = new_(255, 0, 128, 0)
|
||||
, Navy = new_(255, 0, 0, 128)
|
||||
, Olive = new_(255, 128, 128, 0)
|
||||
, Purple = new_(255, 128, 0, 128)
|
||||
, Teal = new_(255, 0, 128, 128)
|
||||
, Brown = new_(255, 165, 42, 42)
|
||||
, LightGray = new_(255, 211, 211, 211)
|
||||
;
|
||||
}
|
||||
58
150_gfui/src/gplx/gfui/draws/ColorAdp__tst.java
Normal file
58
150_gfui/src/gplx/gfui/draws/ColorAdp__tst.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
import org.junit.*;
|
||||
public class ColorAdp__tst {
|
||||
@Test public void parse_hex_() {
|
||||
tst_parse_hex_("#00000000", 0, 0, 0, 0);
|
||||
tst_parse_hex_("#000102FF", 0, 1, 2, 255);
|
||||
tst_parse_hex_("#FF000102", 255, 0, 1, 2);
|
||||
}
|
||||
@Test public void parse_int_() {
|
||||
tst_parse_int_(0, 0, 0, 0, 0);
|
||||
tst_parse_int_(255, 0, 0, 0, 255);
|
||||
tst_parse_int_(65535, 0, 0, 255, 255);
|
||||
tst_parse_int_(16777215, 0, 255, 255, 255);
|
||||
tst_parse_int_(Int_.Max_value, 127, 255, 255, 255);
|
||||
tst_parse_int_(-1, 255, 255, 255, 255);
|
||||
}
|
||||
@Test public void parse() {
|
||||
tst_parse_("0,0,0,0", 0, 0, 0, 0); // parse all ints
|
||||
tst_parse_("0,0,0", 255, 0, 0, 0); // a=255, parse rest
|
||||
tst_parse_("255", 0, 0, 0, 255); // parse as single int
|
||||
}
|
||||
void tst_parse_hex_(String raw, int a, int r, int g, int b) {
|
||||
ColorAdp color = ColorAdp_.parse_hex_(raw);
|
||||
tst_ColorAdp(color, a, r, g, b);
|
||||
Tfds.Eq(color.XtoHexStr(), raw);
|
||||
}
|
||||
void tst_parse_int_(int val, int a, int r, int g, int b) {
|
||||
ColorAdp color = ColorAdp_.new_int_(val);
|
||||
tst_ColorAdp(color, a, r, g, b);
|
||||
Tfds.Eq(color.Value(), val);
|
||||
}
|
||||
void tst_parse_(String s, int alpha, int red, int green, int blue) {tst_ColorAdp(ColorAdp_.parse(s), alpha, red, green, blue);}
|
||||
void tst_ColorAdp(ColorAdp color, int alpha, int red, int green, int blue) {
|
||||
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
|
||||
tstr.Eq_str(color.Alpha(), alpha, "alpha");
|
||||
tstr.Eq_str(color.Red(), red, "red");
|
||||
tstr.Eq_str(color.Green(), green, "green");
|
||||
tstr.Eq_str(color.Blue(), blue, "blue");
|
||||
tstr.tst_Equal("color");
|
||||
}
|
||||
}
|
||||
65
150_gfui/src/gplx/gfui/draws/FontAdp.java
Normal file
65
150_gfui/src/gplx/gfui/draws/FontAdp.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
import gplx.core.strings.*; import gplx.core.envs.*; import gplx.gfui.controls.gxws.*;
|
||||
public class FontAdp implements Gfo_invk {
|
||||
public String Name() {return name;} public FontAdp Name_(String val) {name = val; InitUnder(); return this;} private String name;
|
||||
public float Size() {return size;} public FontAdp Size_(float val) {size = val; InitUnder(); return this;} float size;
|
||||
public FontStyleAdp Style() {return style;} public FontAdp Style_(FontStyleAdp val) {style = val; InitUnder(); return this;} FontStyleAdp style;
|
||||
public Font UnderFont() {if (font == null) InitUnder(); return font;} Font font = null;
|
||||
void InitUnder() {
|
||||
if (Env_.Mode_testing()) return; // WORKAROUND/.NET: NUnit will randomlyly throw exceptions
|
||||
font = FontAdpCache.Instance.GetNativeFont(this);
|
||||
if (ownerGxwCore != null) ownerGxwCore.TextFont_set(this);
|
||||
}
|
||||
public FontAdp OwnerGxwCore_(GxwCore_base v) {ownerGxwCore = v; return this;} GxwCore_base ownerGxwCore;
|
||||
public boolean Eq(Object obj) {
|
||||
FontAdp comp = FontAdp.as_(obj); if (comp == null) return false;
|
||||
return name == comp.name && size == comp.size && style == comp.style;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, "Name")) {return ctx.Deny() ? (Object)this : Name();}
|
||||
else if (ctx.Match(k, "Size")) {return ctx.Deny() ? (Object)this : Size();}
|
||||
else if (ctx.Match(k, "Style")) {return ctx.Deny() ? (Object)this : Style();}
|
||||
else if (ctx.Match(k, Invk_name_)) {
|
||||
String v = m.ReadStr("v");
|
||||
return ctx.Deny() ? (Object)this : Name_(v);
|
||||
}
|
||||
else if (ctx.Match(k, Invk_size_)) {
|
||||
float v = m.ReadFloat("v");
|
||||
return ctx.Deny() ? (Object)this : Size_(v);
|
||||
}
|
||||
else if (ctx.Match(k, Invk_style_)) {
|
||||
Object v = m.CastObj("v");
|
||||
return ctx.Deny() ? (Object)this : Style_(FontStyleAdp_.read_(v));
|
||||
}
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} static final String Invk_name_ = "name_", Invk_size_ = "size_", Invk_style_ = "style_";
|
||||
@Override public String toString() {return String_bldr_.new_().Add_kv("name", name).Add_kv_obj("size", size).Add_kv_obj("style", style).To_str();}
|
||||
|
||||
public static final FontAdp NullPtr = null;
|
||||
public static FontAdp as_(Object obj) {return obj instanceof FontAdp ? (FontAdp)obj : null;}
|
||||
public static FontAdp cast(Object obj) {try {return (FontAdp)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, FontAdp.class, obj);}}
|
||||
public static FontAdp new_(String name, float size, FontStyleAdp style) {
|
||||
FontAdp rv = new FontAdp();
|
||||
rv.name = name; rv.size = size; rv.style = style;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
36
150_gfui/src/gplx/gfui/draws/FontAdpCache.java
Normal file
36
150_gfui/src/gplx/gfui/draws/FontAdpCache.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
public class FontAdpCache {
|
||||
public Font GetNativeFont(FontAdp fontAdp) {
|
||||
String key = fontAdp.toString();
|
||||
Font rv = (Font)hash.Get_by(key); if (rv != null) return rv;
|
||||
if (screenResolutionInDpi == -1) ScreenResolution_set();
|
||||
int fontSize = XtoJavaDpi(fontAdp.Size());
|
||||
rv = new Font(fontAdp.Name(), fontAdp.Style().Val(), fontSize);
|
||||
hash.Add(key, rv);
|
||||
return rv;
|
||||
} Hash_adp hash = Hash_adp_.New();
|
||||
public static void ScreenResolution_set() {screenResolutionInDpi = Toolkit.getDefaultToolkit().getScreenResolution();} // usually either 96 or 120
|
||||
public static int XtoOsDpi(float v) {return Math.round((v * 72) / screenResolutionInDpi);} // WORKAROUND/JAVA: Java needs 72 dpi screen resolution; wnt uses 96 or 120 dpi
|
||||
public static int XtoJavaDpi(float v) {return Math.round((v * screenResolutionInDpi) / 72);}
|
||||
static int screenResolutionInDpi = -1;
|
||||
public static final FontAdpCache Instance = new FontAdpCache(); FontAdpCache() {}
|
||||
}
|
||||
23
150_gfui/src/gplx/gfui/draws/FontStyleAdp.java
Normal file
23
150_gfui/src/gplx/gfui/draws/FontStyleAdp.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
public class FontStyleAdp {
|
||||
public int Val() {return val;} int val;
|
||||
@Override public String toString() {return FontStyleAdp_.XtoStr_(this);}
|
||||
public FontStyleAdp(int v) {val = v;}
|
||||
}
|
||||
68
150_gfui/src/gplx/gfui/draws/FontStyleAdp_.java
Normal file
68
150_gfui/src/gplx/gfui/draws/FontStyleAdp_.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
import gplx.core.primitives.*; import gplx.core.interfaces.*;
|
||||
public class FontStyleAdp_ implements ParseAble {
|
||||
public static final FontStyleAdp
|
||||
Plain = new FontStyleAdp(0)
|
||||
, Bold = new FontStyleAdp(1)
|
||||
, Italic = new FontStyleAdp(2)
|
||||
, BoldItalic = new FontStyleAdp(3)
|
||||
;
|
||||
public static final FontStyleAdp_ Parser = new FontStyleAdp_();
|
||||
public Object ParseAsObj(String raw) {return FontStyleAdp_.parse(raw);}
|
||||
|
||||
public static FontStyleAdp cast(Object obj) {try {return (FontStyleAdp)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, FontStyleAdp.class, obj);}}
|
||||
public static FontStyleAdp parseOr_(String raw, FontStyleAdp or) {
|
||||
FontStyleAdp rv = parse_internal_(raw); if (rv == null) return or;
|
||||
return rv;
|
||||
}
|
||||
public static FontStyleAdp parts_(Bool_obj_val bold, Bool_obj_val italic) {
|
||||
int v = bold == Bool_obj_val.True ? 1 : 0;
|
||||
v += italic == Bool_obj_val.True ? 2 : 0;
|
||||
return lang_(v);
|
||||
}
|
||||
public static FontStyleAdp parse(String raw) {
|
||||
FontStyleAdp rv = parse_internal_(raw); if (rv == null) throw Err_.new_unhandled(raw);
|
||||
return rv;
|
||||
}
|
||||
public static FontStyleAdp read_(Object o) {String s = String_.as_(o); return s != null ? FontStyleAdp_.parse(s) : FontStyleAdp_.cast(o);}
|
||||
static FontStyleAdp parse_internal_(String raw) {
|
||||
if (String_.Eq(raw, "plain")) return FontStyleAdp_.Plain;
|
||||
else if (String_.Eq(raw, "bold")) return FontStyleAdp_.Bold;
|
||||
else if (String_.Eq(raw, "italic")) return FontStyleAdp_.Italic;
|
||||
else if (String_.Eq(raw, "bold+italic"))return FontStyleAdp_.BoldItalic;
|
||||
else if (String_.Eq(raw, "italic+bold"))return FontStyleAdp_.BoldItalic;
|
||||
else return null;
|
||||
}
|
||||
public static FontStyleAdp lang_(int v) {
|
||||
if (v == Plain.Val()) return Plain;
|
||||
else if (v == Bold.Val()) return Bold;
|
||||
else if (v == Italic.Val()) return Italic;
|
||||
else if (v == BoldItalic.Val()) return BoldItalic;
|
||||
else throw Err_.new_unhandled(v);
|
||||
}
|
||||
public static String XtoStr_(FontStyleAdp fontStyle) {
|
||||
int val = fontStyle.Val();
|
||||
if (val == FontStyleAdp_.Plain.Val()) return "plain";
|
||||
else if (val == FontStyleAdp_.Bold.Val()) return "bold";
|
||||
else if (val == FontStyleAdp_.Italic.Val()) return "italic";
|
||||
else if (val == FontStyleAdp_.BoldItalic.Val()) return "bold+italic";
|
||||
else throw Err_.new_unhandled(val);
|
||||
}
|
||||
}
|
||||
53
150_gfui/src/gplx/gfui/draws/PenAdp.java
Normal file
53
150_gfui/src/gplx/gfui/draws/PenAdp.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Stroke;
|
||||
import gplx.core.strings.*;
|
||||
public class PenAdp implements Gfo_invk {
|
||||
public float Width() {return width;} public void Width_set(float v) {width = v; InitUnder();} float width;
|
||||
public ColorAdp Color() {return color;} public void Color_set(ColorAdp v) {color = v; InitUnder();} ColorAdp color;
|
||||
public BasicStroke UnderStroke() {if (underStroke == null) InitUnder(); return underStroke;} BasicStroke underStroke;
|
||||
void InitUnder() {underStroke = PenAdpCache.Instance.Fetch(width);}
|
||||
public PenAdp Clone() {return PenAdp_.new_(color, width);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_Width_)) Width_set(m.ReadFloat(Invk_Width_));
|
||||
else if (ctx.Match(k, Invk_Color_)) Color_set((ColorAdp)m.ReadObj(Invk_Color_, ColorAdp_.Parser));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} static final String Invk_Width_ = "Width_", Invk_Color_ = "Color_";
|
||||
@Override public String toString() {return String_bldr_.new_().Add_kv_obj("width", width).Add_kv("color", color.XtoHexStr()).To_str();}
|
||||
@Override public int hashCode() {return color.Value() ^ (int)width;}
|
||||
@Override public boolean equals(Object obj) { // cannot use Eq b/c of difficulty in comparing null instances
|
||||
PenAdp comp = PenAdp_.as_(obj); if (comp == null) return false;
|
||||
return color.Eq(comp.color) && width == comp.width;
|
||||
}
|
||||
@gplx.Internal protected PenAdp(ColorAdp color, float width) {this.color = color; this.width = width;}
|
||||
}
|
||||
class PenAdpCache {
|
||||
public BasicStroke Fetch(float width) {
|
||||
Object rv = hash.Get_by(width);
|
||||
if (rv == null) {
|
||||
rv = new BasicStroke(width);
|
||||
hash.Add(width, rv);
|
||||
}
|
||||
return (BasicStroke)rv;
|
||||
}
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
public static final PenAdpCache Instance = new PenAdpCache(); PenAdpCache() {}
|
||||
}
|
||||
25
150_gfui/src/gplx/gfui/draws/PenAdp_.java
Normal file
25
150_gfui/src/gplx/gfui/draws/PenAdp_.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
public class PenAdp_ {
|
||||
public static PenAdp as_(Object obj) {return obj instanceof PenAdp ? (PenAdp)obj : null;}
|
||||
public static PenAdp cast(Object obj) {try {return (PenAdp)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, PenAdp.class, obj);}}
|
||||
public static PenAdp black_() {return new_(ColorAdp_.Black, 1);}
|
||||
public static PenAdp new_(ColorAdp color) {return new_(color, 1);}
|
||||
public static PenAdp new_(ColorAdp color, float width) {return new PenAdp(color, width);}
|
||||
}
|
||||
31
150_gfui/src/gplx/gfui/draws/SolidBrushAdp.java
Normal file
31
150_gfui/src/gplx/gfui/draws/SolidBrushAdp.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
public class SolidBrushAdp {
|
||||
public ColorAdp Color() {return color;} ColorAdp color;
|
||||
@Override public String toString() {return color.XtoHexStr();}
|
||||
public boolean Eq(Object obj) {
|
||||
SolidBrushAdp comp = SolidBrushAdp_.as_(obj); if (comp == null) return false;
|
||||
return color.Eq(comp.color);
|
||||
}
|
||||
@gplx.Internal protected static SolidBrushAdp new_(ColorAdp color) {
|
||||
SolidBrushAdp rv = new SolidBrushAdp();
|
||||
rv.color = color;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
38
150_gfui/src/gplx/gfui/draws/SolidBrushAdp_.java
Normal file
38
150_gfui/src/gplx/gfui/draws/SolidBrushAdp_.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
|
||||
public class SolidBrushAdp_ {
|
||||
public static SolidBrushAdp as_(Object obj) {return obj instanceof SolidBrushAdp ? (SolidBrushAdp)obj : null;}
|
||||
public static SolidBrushAdp cast(Object obj) {try {return (SolidBrushAdp)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, SolidBrushAdp.class, obj);}}
|
||||
public static final SolidBrushAdp Black = new_(ColorAdp_.Black);
|
||||
public static final SolidBrushAdp White = new_(ColorAdp_.White);
|
||||
public static final SolidBrushAdp Null = new_(ColorAdp_.Null);
|
||||
public static SolidBrushAdp new_(ColorAdp color) {return SolidBrushAdpCache.Instance.Get_by(color);}
|
||||
}
|
||||
class SolidBrushAdpCache {
|
||||
public SolidBrushAdp Get_by(ColorAdp color) {
|
||||
SolidBrushAdp rv = (SolidBrushAdp)hash.Get_by(color.Value());
|
||||
if (rv == null) {
|
||||
rv = SolidBrushAdp.new_(color);
|
||||
hash.Add(color.Value(), rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
public static final SolidBrushAdpCache Instance = new SolidBrushAdpCache(); SolidBrushAdpCache() {}
|
||||
}
|
||||
Reference in New Issue
Block a user