1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
/*
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; import gplx.*;
import gplx.core.strings.*;
public class GfuiBorderMgr {
public PenAdp All() {return all;} public GfuiBorderMgr All_(PenAdp v) {SyncPens(true); all = v; return this;} PenAdp all;
public PenAdp Left() {return left;} public GfuiBorderMgr Left_(PenAdp v) {SyncPens(false); left = v; return this;} PenAdp left;
public PenAdp Right() {return right;} public GfuiBorderMgr Right_(PenAdp v) {SyncPens(false); right = v; return this;} PenAdp right;
public PenAdp Top() {return top;} public GfuiBorderMgr Top_(PenAdp v) {SyncPens(false); top = v; return this;} PenAdp top;
public PenAdp Bot() {return bot;} public GfuiBorderMgr Bot_(PenAdp v) {SyncPens(false); bot = v; return this;} PenAdp bot;
public void Bounds_sync(RectAdp v) {bounds = v;} RectAdp bounds = RectAdp_.Zero;
public void DrawData(GfxAdp gfx) {
if (all != null)
gfx.DrawRect(all, bounds);
else {
if (left != null) gfx.DrawLine(left, bounds.CornerBL(), bounds.CornerTL());
if (right != null) gfx.DrawLine(right, bounds.CornerTR(), bounds.CornerBR());
if (top != null) gfx.DrawLine(top, bounds.CornerTL(), bounds.CornerTR());
if (bot != null) gfx.DrawLine(bot, bounds.CornerBR(), bounds.CornerBL());
}
}
public GfuiBorderMgr None_() {Edge_set(GfuiBorderEdge.All, null); return this;}
public void Edge_setObj(Object o) {
if (o == null)
this.None_();
else {
Object[] ary = (Object[])o;
this.Edge_set(GfuiBorderEdge.All, PenAdp_.new_((ColorAdp)ary[1], Float_.cast_(ary[0])));
}
}
public void Edge_set(GfuiBorderEdge edge, PenAdp pen) {
int val = edge.Val();
if (val == GfuiBorderEdge.All.Val()) {all = pen; return;}
else if (val == GfuiBorderEdge.Left.Val()) {left = pen; return;}
else if (val == GfuiBorderEdge.Right.Val()) {right = pen; return;}
else if (val == GfuiBorderEdge.Top.Val()) {top = pen; return;}
else if (val == GfuiBorderEdge.Bot.Val()) {bot = pen; return;}
else throw Exc_.new_unhandled(edge);
}
void SyncPens(boolean isAll) {
if (isAll) {
left = null; right = null; top = null; bot = null;
}
else {
if (all != null) {
left = all.Clone(); right = all.Clone(); top = all.Clone(); bot = all.Clone();
}
all = null;
}
}
public String XtoStr() {return String_bldr_.new_().Add_kv_obj("all", all).Add_kv_obj("left", left).Add_kv_obj("right", right).Add_kv_obj("top", top).Add_kv_obj("bot", bot).XtoStr();}
@Override public String toString() {return XtoStr();}
public static GfuiBorderMgr new_() {return new GfuiBorderMgr();} GfuiBorderMgr() {}
}

View File

@@ -0,0 +1,29 @@
/*
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; import gplx.*;
public interface GfxAdp extends RlsAble {
void DrawLine(PenAdp pen, PointAdp src, PointAdp trg);
void DrawRect(PenAdp pen, int x, int y, int width, int height);
void DrawRect(PenAdp pen, PointAdp location, SizeAdp size);
void DrawRect(PenAdp pen, RectAdp rect);
void FillRect(SolidBrushAdp brush, int x, int y, int width, int height);
void DrawImage(ImageAdp image, PointAdp location);
void DrawImage(ImageAdp img, int trg_x, int trg_y, int trg_w, int trg_h, int src_x, int src_y, int src_w, int src_h);
void DrawStringXtn(String s, FontAdp font, SolidBrushAdp brush, float x, float y, float width, float height, GfxStringData sd);
float[] MeasureStringXtn(String s, FontAdp font, GfxStringData sd);
}

View File

@@ -0,0 +1,107 @@
/*
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; import gplx.*;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
public class GfxAdpBase implements GfxAdp {
public void DrawLine(PenAdp pen, PointAdp src, PointAdp trg) {
gfx.setColor(ColorAdpCache._.GetNativeColor(pen.Color()));
gfx.setStroke(pen.UnderStroke());
gfx.drawLine(src.X(), src.Y(), trg.X(), trg.Y());
}
public void DrawRect(PenAdp pen, PointAdp pos, SizeAdp size) {this.DrawRect(pen, pos.X(), pos.Y(), size.Width(), size.Height());}
public void DrawRect(PenAdp pen, RectAdp rect) {this.DrawRect(pen, rect.X(), rect.Y(), rect.Width(), rect.Height());}
public void DrawRect(PenAdp pen, int x, int y, int width, int height) {
gfx.setPaint(ColorAdpCache._.GetNativeColor(pen.Color()));
gfx.setStroke(pen.UnderStroke());
gfx.drawRect(x, y, width, height);
}
public void FillRect(SolidBrushAdp brush, int x, int y, int width, int height) {
gfx.setPaint(ColorAdpCache._.GetNativeColor(brush.Color()));
gfx.fillRect(x, y, width, height);
}
public void DrawStringXtn(String s, FontAdp font, SolidBrushAdp brush, float x, float y, float width, float height, GfxStringData sd) {
gfx.setPaint(ColorAdpCache._.GetNativeColor(brush.Color()));
// height = y - ascent + descent -> rect.y - rect.height [assume ascent] + 2 [assume descent]
gfx.setClip((int)x, (int)y - (int)height + 2, (int)width, (int)height);
if (sd == null || sd.mnemonicString == null) {
gfx.setFont(font.UnderFont());
gfx.drawString(s, x, y - 2);
}
else {
gfx.drawString(sd.mnemonicString.getIterator(), x, y - 2);
}
gfx.setClip(null);
}
public float[] MeasureStringXtn(String s, FontAdp font, GfxStringData sd) {
FontMetrics fontMetrics = gfx.getFontMetrics(font.UnderFont());
Rectangle2D stringMetrics = fontMetrics.getStringBounds(s, gfx);
float width = (float)stringMetrics.getWidth();
int height = fontMetrics.getHeight();
int descent = fontMetrics.getDescent();
return new float[] {width, height, descent};
}
public static float[] GetStringBounds(String s, FontAdp font, Object o) {
JComponent jcomponent = (JComponent)o;
Graphics2D gfx = (Graphics2D)jcomponent.getGraphics();
FontMetrics fontMetrics = gfx.getFontMetrics(font.UnderFont());
Rectangle2D stringMetrics = fontMetrics.getStringBounds(s, gfx);
float width = (float)stringMetrics.getWidth();
int height = fontMetrics.getHeight();
int descent = fontMetrics.getDescent();
return new float[] {width, height, descent};
}
public void DrawImage(ImageAdp image, PointAdp pt) {
if (image == ImageAdp_.Null) return;
gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gfx.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
gfx.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gfx.drawImage((java.awt.Image)image.Under(), pt.X(), pt.Y(), null);
// gfx.drawImage(image.UnderImage(),pt.X(),pt.Y(),
// pt.X()+image.Width(),pt.Y()+image.Height(),
// pt.X(),pt.Y(),
// pt.X()+image.Width(),pt.Y()+image.Height(),
// null);
}
public void DrawImage(ImageAdp img, int trg_x, int trg_y, int trg_w, int trg_h, int src_x, int src_y, int src_w, int src_h) {
if (img == ImageAdp_.Null) return;
gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gfx.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
gfx.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gfx.drawImage((java.awt.Image)img.Under(), trg_x, trg_y, trg_x + trg_w, trg_y + trg_h, src_x, src_y, src_x + src_w, src_y + src_h, null);
}
public void Rls() {gfx.dispose();}
public Object Under() {return gfx;}
Graphics2D gfx;
@gplx.Internal protected static GfxAdpBase new_(Graphics2D gfx) {
GfxAdpBase rv = new GfxAdpBase();
rv.gfx = gfx;
return rv;
} GfxAdpBase() {}
}

View File

@@ -0,0 +1,26 @@
/*
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; import gplx.*;
import java.awt.Graphics2D;
public class GfxAdp_ {
@gplx.Internal protected static GfxAdp new_(Graphics2D graphics) {return GfxAdpBase.new_(graphics);}
public static GfxAdp image_(ImageAdp image) {
Graphics2D graphics = (Graphics2D)((java.awt.Image)image.Under()).getGraphics();
return GfxAdpBase.new_(graphics);
}
}

View File

@@ -0,0 +1,115 @@
/*
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; import gplx.*;
import java.awt.font.TextAttribute;
import java.text.AttributedString;
public class GfxStringData {
public String Val() {
if (ownerElem == null) return val;
if (ownerElem.TextVal() == null) return "";
return ownerElem.TextVal();
} String val = "";
public GfuiAlign AlignH() {return alignH;} GfuiAlign alignH;
public GfxStringData AlignH_(GfuiAlign val) {
alignH = val;
if (ownerElem != null) GfoInvkAble_.InvkCmd_val(ownerElem, GxwElem_lang.AlignH_cmd, alignH); // needed for TextBox, since its Paint is not overriden
TextRect_setNull();
return this;
}
public GfuiAlign AlignV() {return alignV;} public GfxStringData AlignV_(GfuiAlign val) {alignV = val; return this;} GfuiAlign alignV = GfuiAlign_.Mid;
public ColorAdp Color() {return brush.Color();}
public SolidBrushAdp UnderBrush() {return brush;} SolidBrushAdp brush;
public AttributedString MnemonicString() {return mnemonicString;} AttributedString mnemonicString;
String drawn = "";
public void MnemonicString_sync() {
int pos = GfuiWinKeyCmdMgr.ExtractPosFromText(this.Val()); if (pos == String_.Find_none) return;
drawn = String_.MidByLen(this.Val(), 0, pos) + String_.Mid(this.Val(), pos + 1); // rebuild string without &
mnemonicString = new AttributedString(drawn);
mnemonicString.addAttribute(TextAttribute.FONT, font.UnderFont());
mnemonicString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, pos, pos + 1);
}
public GfxStringData Color_(ColorAdp val) {
brush = SolidBrushAdp_.new_(val);
if (ownerElem != null) ownerElem.Core().ForeColor_set(val);
TextRect_setNull();
return this;
}
public FontAdp Font() {return font;} FontAdp font;
public GfxStringData Font_(FontAdp val) {
font = val;
if (!Env_.Mode_testing() && ownerElem != null) ownerElem.Core().TextFont_set(font);
TextRect_setNull();
MnemonicString_sync();
return this;
}
public RectAdpF TextRect() {return textRect;} public void TextRect_set(RectAdpF val) {textRect = val;} public void TextRect_setNull() {textRect = RectAdpF.Null;} RectAdpF textRect = RectAdpF.Null;
public RectAdpF TextRect_setX(int x) {
textRect = RectAdpF.new_(x, textRect.Y(), textRect.Width(), textRect.Height());
return textRect;
}
@gplx.Internal protected SizeAdp OwnerSize() {return ownerSize;}
public void OwnerSize_sync(SizeAdp val) {
ownerSize = val; TextRect_setNull();
ownerElem.Core().Invalidate(); // NOTE: force redraw; this may be redundant in WINFORMS but needed in SWING especially when windowOpened causes resize; SWING seems to execute windowOpened -> resize -> paint -> componentResized
} SizeAdp ownerSize = SizeAdp_.new_(20, 20);
@gplx.Internal protected GxwElem UnderElem() {return owner.UnderElem();}
public void DrawData(GfxAdp gfx) {
if (textRect.Eq(RectAdpF.Null)) {textRect = TextRect_calc(gfx);}
gfx.DrawStringXtn(this.Val(), font, brush, textRect.X(), textRect.Y(), textRect.Width(), textRect.Height(), this);
}
@gplx.Internal protected void Text_set(String v) {
if (this.Val() == v) return;
if (ownerElem != null) {
ownerElem.TextVal_set(v);
if (owner.CustomDraw()) ownerElem.Core().Invalidate();
}
else
this.val = v;
TextRect_setNull();
MnemonicString_sync();
}
public RectAdpF TextRect_calc(GfxAdp gfx) {
float[] sizeAry = gfx.MeasureStringXtn(drawn == "" ? this.Val() : drawn, font, this);
float width = sizeAry[0], height = sizeAry[1], descent = sizeAry[2];
// if (String_.Eq("opal.gfds 0.0.1", this.Val())) {
// Tfds.Write(this.Val(), alignH.Val(), (int)width, ownerSize.Width());
// }
float x = GfuiAlign_.CalcInsideOfAxis(alignH.Val(), (int)width, ownerSize.Width());
float y = 0; int alignVVal = alignV.Val(); float ownerHeight = ownerSize.Height();
if (alignVVal == GfuiAlign_.Null.Val()) y = Int_.MinValue;
else if (alignVVal == GfuiAlign_.Lo.Val()) y = height - descent;
else if (alignVVal == GfuiAlign_.Mid.Val()) y = (ownerHeight - (ownerHeight - height) / 2);// - descent; // COMMENT: subtracting descent is theoretically correct, but practically results in text shifted up
else if (alignVVal == GfuiAlign_.Hi.Val()) y = ownerHeight - descent;
if (width > ownerElem.Core().Width()) width = ownerElem.Core().Width(); // clip to elem size or else text overflows; EX: tab buttons
if (x < 0) x = 0; if (y < 0) y = 0; // occurs when text is larger than elem; do not allow negative values
return RectAdpF.new_(x, y, width, height);
} GfuiElemBase owner; GxwElem ownerElem;
public static GfxStringData new_(GfuiElemBase owner, GxwElem ownerElem) {
GfxStringData rv = new GfxStringData();
rv.brush = SolidBrushAdp_.Black;
rv.alignH = GfuiAlign_.Left;
rv.owner = owner;
rv.ownerElem = ownerElem;
// WORKAROUND:.NET: setting font on textBox causes odd selection behavior for MediaTimeBox
rv.Font_(FontAdp.new_("Arial", 8, FontStyleAdp_.Plain)); // needed for TextBox, since its Paint is not overriden, and .Font property must be set
return rv;
} GfxStringData() {}
public static final GfxStringData Null = null;
}

View File

@@ -0,0 +1,29 @@
/*
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; import gplx.*;
public class PaintArgs {
public GfxAdp Graphics() {return graphics;} GfxAdp graphics;
public RectAdp ClipRect() {return clipRect;} RectAdp clipRect;
public static PaintArgs cast_(Object obj) {try {return (PaintArgs)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, PaintArgs.class, obj);}}
public static PaintArgs new_(GfxAdp graphics, RectAdp clipRect) {
PaintArgs rv = new PaintArgs();
rv.graphics = graphics; rv.clipRect = clipRect;
return rv;
}
}