1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-06-13 12:54:14 +00:00
gnosygnu_xowa/150_gfui/src/gplx/gfui/draws/FontAdp.java

66 lines
3.3 KiB
Java
Raw Normal View History

2015-07-13 01:10:02 +00:00
/*
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/>.
*/
2016-06-20 03:58:10 +00:00
package gplx.gfui.draws; import gplx.*; import gplx.gfui.*;
2015-07-13 01:10:02 +00:00
import java.awt.Font;
import java.awt.Toolkit;
2016-06-20 03:58:10 +00:00
import gplx.core.strings.*; import gplx.core.envs.*; import gplx.gfui.controls.gxws.*;
public class FontAdp implements Gfo_invk {
2015-07-13 01:10:02 +00:00
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;
2016-06-20 03:58:10 +00:00
public Font UnderFont() {if (font == null) InitUnder(); return font;} Font font = null;
2015-07-13 01:10:02 +00:00
void InitUnder() {
if (Env_.Mode_testing()) return; // WORKAROUND/.NET: NUnit will randomlyly throw exceptions
2015-10-19 02:17:57 +00:00
font = FontAdpCache.Instance.GetNativeFont(this);
2015-07-13 01:10:02 +00:00
if (ownerGxwCore != null) ownerGxwCore.TextFont_set(this);
}
2016-06-20 03:58:10 +00:00
public FontAdp OwnerGxwCore_(GxwCore_base v) {ownerGxwCore = v; return this;} GxwCore_base ownerGxwCore;
2015-07-13 01:10:02 +00:00
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));
}
2016-06-20 03:58:10 +00:00
else return Gfo_invk_.Rv_unhandled;
2015-07-13 01:10:02 +00:00
} static final String Invk_name_ = "name_", Invk_size_ = "size_", Invk_style_ = "style_";
2015-08-17 06:09:16 +00:00
@Override public String toString() {return String_bldr_.new_().Add_kv("name", name).Add_kv_obj("size", size).Add_kv_obj("style", style).To_str();}
2015-07-13 01:10:02 +00:00
2016-06-20 03:58:10 +00:00
public static final FontAdp NullPtr = null;
2015-07-13 01:10:02 +00:00
public static FontAdp as_(Object obj) {return obj instanceof FontAdp ? (FontAdp)obj : null;}
2015-08-31 02:57:59 +00:00
public static FontAdp cast(Object obj) {try {return (FontAdp)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, FontAdp.class, obj);}}
2015-07-13 01:10:02 +00:00
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;
}
}