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,59 @@
/*
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.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import gplx.core.strings.*;
public class ClipboardAdp_ {
public static void SetText(String text) {
StringSelection data = new StringSelection(text);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(data, data);
}
public static boolean IsText() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
return clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor);
}
public static String GetText() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
String rv = "";
try {rv = clipboard.getData(DataFlavor.stringFlavor).toString();}
catch (Exception e) {throw Exc_.new_exc(e, "ui", "clipboard get_data failed");}
if (Op_sys.Cur().Tid_is_wnt()) { // WORKAROUND:JAVA: On Windows, Clipboard will have \r\n, but Java automatically converts to \n
String_bldr remake = String_bldr_.new_();
for (int i = 0; i < String_.Len(rv); i++) {
char c = String_.CharAt(rv, i);
if (c == '\n' && i > 0) {
char prev = String_.CharAt(rv, i - 1);
if (prev != '\r') {
remake.Add(String_.CrLf);
continue;
}
}
remake.Add(c);
}
rv = remake.XtoStr();
// rv = String_.Replace(rv, "\n", Env_.NewLine);
}
return rv;
}
}

View 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; import gplx.*;
public class CursorAdp {
public static PointAdp Pos() {
if (testing) return testing_pos;
return GxwCore_lang.XtoPointAdp(java.awt.MouseInfo.getPointerInfo().getLocation());
}
public static void Pos_set(PointAdp p) {
if (testing) // while in testing mode, never set Cursor.Position
testing_pos = p;
else {
java.awt.Robot robot = null;
try {robot = new java.awt.Robot();}
catch (java.awt.AWTException e) {throw Exc_.new_exc(e, "ui", "cursor pos set failed");}
robot.mouseMove(p.X(), p.Y());
}
}
@gplx.Internal protected static void Pos_set_for_tests(PointAdp point) {
testing = point != PointAdp_.Null;
testing_pos = point;
} static PointAdp testing_pos = PointAdp_.Null; static boolean testing = false;
}

View File

@@ -0,0 +1,45 @@
/*
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 javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.Image;
import java.net.MalformedURLException;
import java.net.URL;
public class IconAdp {
public Icon UnderIcon() {return icon;} final Icon icon;
public Image XtoImage() {return ((ImageIcon)icon).getImage();}
public Io_url Url() {return url;} Io_url url = Io_url_.Empty;
IconAdp(Icon icon) {this.icon = icon;}
public static IconAdp new_(Icon icon) {return new IconAdp(icon);}
public static IconAdp file_(Io_url url) {
Icon icon = new ImageIcon(url.Xto_api());
IconAdp rv = new IconAdp(icon);
rv.url = url;
return rv;
}
public static void regy_loadDir_(Io_url imgDir) {GfoRegy._.RegDir(imgDir, "*.png", true, "_", ".");}
public static void regy_loadDir_shallow(Io_url imgDir) {GfoRegy._.RegDir(imgDir, "*.png", false, "_", ".");}
public static IconAdp regy_(String key) {
GfoRegyItm itm = GfoRegy._.FetchOrNull(key);
if (itm == null) {UsrDlg_._.Warn("missing icon; key={0}", key); return null;}
if (itm.ValType() != GfoRegyItm.ValType_Url) throw Exc_.new_("regyItm should be of type url", "key", key);
return IconAdp.file_(itm.Url());
}
public static IconAdp as_(Object obj) {return obj instanceof IconAdp ? (IconAdp)obj : null;}
}

View File

@@ -0,0 +1,50 @@
/*
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.Image;
public interface ImageAdp extends RlsAble {
Gfui_kit Kit();
SizeAdp Size();
int Width();
int Height();
Io_url Url(); ImageAdp Url_(Io_url v);
Object Under();
boolean Disposed();
void SaveAsBmp(Io_url url);
void SaveAsPng(Io_url url);
ImageAdp Resize(int width, int height);
ImageAdp Extract_image(RectAdp src_rect, SizeAdp trg_size);
ImageAdp Extract_image(int src_x, int src_y, int src_w, int src_h, int trg_w, int trg_h);
}
class ImageAdp_txt implements ImageAdp {
public Gfui_kit Kit() {return Swing_kit._;}
public SizeAdp Size() {return size;} SizeAdp size;
public int Width() {return size.Width();}
public int Height() {return size.Height();}
public Io_url Url() {return url;} public ImageAdp Url_(Io_url v) {url = v; return this;} Io_url url;
public Object Under() {return null;}
public boolean Disposed() {return disposed;} private boolean disposed = false;
public void Rls() {disposed = true;}
public void SaveAsBmp(Io_url url) {SaveAs(url, ".bmp");}
public void SaveAsPng(Io_url url) {SaveAs(url, ".png");}
void SaveAs(Io_url url, String ext) {Io_mgr.I.SaveFilStr(url.GenNewExt(ext), size.XtoStr());}
public ImageAdp Extract_image(RectAdp src_rect, SizeAdp trg_size) {return Extract_image(src_rect.X(), src_rect.Y(), src_rect.Width(), src_rect.Height(), trg_size.Width(), trg_size.Height());}
public ImageAdp Extract_image(int src_x, int src_y, int src_w, int src_h, int trg_w, int trg_h) {return ImageAdp_.txt_mem_(Io_url_.Empty, SizeAdp_.new_(trg_w, trg_h));}
public ImageAdp Resize(int width, int height) {return ImageAdp_.txt_mem_(Io_url_.Empty, SizeAdp_.new_(width, height));}
public ImageAdp_txt(Io_url url, SizeAdp size) {this.url = url; this.size = size;}
}

View File

@@ -0,0 +1,126 @@
/*
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.primitives.*;
import gplx.ios.*; /*IoStream*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class ImageAdp_ {
public static ImageAdp as_(Object obj) {return obj instanceof ImageAdp ? (ImageAdp)obj : null;}
public static ImageAdp cast_(Object obj) {try {return (ImageAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, ImageAdp.class, obj);}}
public static final ImageAdp Null = new_(10, 10);
public static ImageAdp new_(int width, int height) {
// BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // JAVA: must be TYPE_INT_RGB or else ImageIO.write("bmp") will fail
BufferedImage img = getCompatibleImage(width, height);
return new ImageAdp_base(img);
}
public static ImageAdp txt_mem_(Io_url url, SizeAdp size) {return new ImageAdp_txt(url, size);}
public static ImageAdp txt_fil_(Io_url url) {
String raw = Io_mgr.I.LoadFilStr(url);
SizeAdp size = null;
if (String_.Eq(raw, "")) size = SizeAdp_.Zero;
else if (String_.Eq(url.Ext(), ".svg")) size = SizeOf_svg(url);
else size = SizeAdp_.parse_(raw);
return new ImageAdp_txt(url, size);
}
public static SizeAdp SizeOf_svg(Io_url url) {return Gfui_svg_util.QuerySize(url);}
public static ImageAdp file_(Io_url url) {
if (url.EqNull()) throw Exc_.new_("cannot load image from null url");
if (String_.Eq(url.Info().Key(), IoUrlInfo_.Mem.Key())) return txt_fil_(url);
if (!Io_mgr.I.ExistsFil(url)) return Null;
BufferedImage img = null;
try {
File f = new File(url.Xto_api());
img = ImageIO.read(f);
}
catch (IOException e) {throw Exc_.new_exc(e, "ui", "image load failed", "url", url.Xto_api());}
// FileInputStream istream = new FileInputStream(new File(url.Xto_api()));
// JPEGImageDecoder dec = JPEGCodec.createJPEGDecoder(istream);
// BufferedImage im = dec.decodeAsBufferedImage();
// try {img = ImageIO.read(new File());}
// catch (IOException e) {}
return new ImageAdp_base(img).Url_(url);
}
private static BufferedImage getCompatibleImage(int w, int h)
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(w, h);
// System.out.println("compatible image type = " + image.getType());
return image;
}
public static int MemorySize(ImageAdp image) {
int areaInPixels = image.Height() * image.Width();
BufferedImage bufferedImage = (BufferedImage)image.Under();
int bitsPerPixel = BitsPerPixelCalc(bufferedImage.getType(), image.Url());
// int bitsPerPixel = 4;
return areaInPixels * (bitsPerPixel / 8); // 8 bits per byte
}
static int BitsPerPixelCalc(int imageType, Io_url url) { // REF:http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferedImage.html
if (imageType == BufferedImage.TYPE_3BYTE_BGR) return 24;
else if (imageType == BufferedImage.TYPE_4BYTE_ABGR) return 32;
else if (imageType == BufferedImage.TYPE_4BYTE_ABGR_PRE) return 32;
else if (imageType == BufferedImage.TYPE_BYTE_BINARY) return 8; //?
else if (imageType == BufferedImage.TYPE_BYTE_GRAY) return 8; //?
else if (imageType == BufferedImage.TYPE_BYTE_INDEXED) return 8; //?
else if (imageType == BufferedImage.TYPE_CUSTOM) return 8; //?
else if (imageType == BufferedImage.TYPE_INT_ARGB) return 32; //?
else if (imageType == BufferedImage.TYPE_INT_ARGB_PRE) return 32; //?
else if (imageType == BufferedImage.TYPE_INT_BGR) return 32; //?
else if (imageType == BufferedImage.TYPE_INT_RGB) return 32; //?
else if (imageType == BufferedImage.TYPE_USHORT_555_RGB) return 16; //?
else if (imageType == BufferedImage.TYPE_USHORT_565_RGB) return 16; //?
else if (imageType == BufferedImage.TYPE_USHORT_GRAY) return 16; //?
else {UsrDlg_._.Warn("unknown bits per pixel", "imageType", imageType, "url", url.Xto_api()); return 8;}
}
}
class Gfui_svg_util {
public static SizeAdp QuerySize(Io_url url) {
try {
// NOTE: not using XmlDoc b/c invalid doctypes can cause xml to hang; <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"><!-- Created with Inkscape (http://www.inkscape.org/) --> <svg xmlns="http://www.w3.org/2000/svg"
String xml = Io_mgr.I.LoadFilStr(url);
int pos = String_.FindFwd(xml, "<svg", 0); if (pos == -1) return null;
Int_obj_ref pos_ref = Int_obj_ref.new_(pos);
double w = ParseAtr(xml, pos_ref, "width");
double h = ParseAtr(xml, pos_ref, "height");
return SizeAdp_.new_((int)w, (int)h);
} catch (Exception e) {Exc_.Noop(e); return SizeAdp_.Null;}
}
static double ParseAtr(String xml, Int_obj_ref pos_ref, String atr) {
int pos = String_.FindFwd(xml, atr, pos_ref.Val()); if (pos == -1) return -1;
int bgn = String_.FindFwd(xml, "\"", pos); if (bgn == -1) return -1;
++bgn; // place after quote
int end = String_.FindFwd(xml, "\"", bgn); if (end == -1) return -1;
int px = String_.FindBwd(xml, "px", end); // handle width="20px"
if (px != -1) end = px;
String str = String_.Mid(xml, bgn, end);
pos_ref.Val_(end);
return Double_.parse_(str);
}
}

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 java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageAdp_base implements ImageAdp, RlsAble {
@gplx.Internal protected ImageAdp_base(Image img) {this.under = img;}
public Gfui_kit Kit() {return kit;} public void Kit_(Gfui_kit v) {this.kit = v;} Gfui_kit kit;
public SizeAdp Size() {
if (this == ImageAdp_.Null) return SizeAdp_.Null;
if (size == null) {
size = SizeAdp_.new_(this.Width(), this.Height());
}
return size;
} SizeAdp size = null;
public int Width() {return under.getWidth(null);}
public int Height() {return under.getHeight(null);}
public Io_url Url() {return url;} public ImageAdp Url_(Io_url v) {url = v; return this;} Io_url url = Io_url_.Empty;
public Object Under() {return under;} Image under;
public boolean Disposed() {return disposed;} private boolean disposed = false;
public void Rls() {disposed = true; under.flush();}
public void SaveAsBmp(Io_url url) {SaveAs(url, "bmp");}
public void SaveAsPng(Io_url url) {SaveAs(url, "png");}
void SaveAs(Io_url url, String fmtStr) {
Io_mgr.I.CreateDirIfAbsent(url.OwnerDir());
File fil = new File(url.Xto_api());
// String[] formatNames = ImageIO.getWriterFormatNames();
// for (String s : formatNames)
// Tfds.Write(s);
boolean success = false;
try {success = ImageIO.write((BufferedImage)under, fmtStr, fil);}
catch (IOException e) {}
if (!success) throw Exc_.new_w_type("gplx.gfui.imgs.SaveImageFailed", "save image failed", "srcUrl", url.Xto_api(), "trgFil", fil, "fmt", fmtStr);
//#@endif
}
public ImageAdp Extract_image(RectAdp src_rect, SizeAdp trg_size) {return Extract_image(src_rect.X(), src_rect.Y(), src_rect.Width(), src_rect.Height(), trg_size.Width(), trg_size.Height());}
public ImageAdp Extract_image(int src_x, int src_y, int src_w, int src_h, int trg_w, int trg_h) {
if (this == ImageAdp_.Null) return ImageAdp_.Null; // TODO: create ImageAdpNull class (along with ImageAdp interface)
if (disposed) return ImageAdp_.new_(1, 1);
ImageAdp rv = ImageAdp_.new_(trg_w, trg_h);
GfxAdp gfx = GfxAdp_.image_(rv);
gfx.DrawImage(this, 0, 0, trg_w, trg_h, src_x, src_y, src_w, src_h);
gfx.Rls();
return rv;
}
public ImageAdp Resize(int width, int height) {return Extract_image(0, 0, this.Width(), this.Height(), width, height);}
}

View File

@@ -0,0 +1,34 @@
/*
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 ImageAdp_null implements ImageAdp {
public Gfui_kit Kit() {return Gfui_kit_.Mem();}
public SizeAdp Size() {return SizeAdp_.Zero;}
public int Width() {return 0;}
public int Height() {return 0;}
public Io_url Url() {return Io_url_.Empty;} public ImageAdp Url_(Io_url v) {return this;}
public Object Under() {return null;}
public boolean Disposed() {return disposed;} private boolean disposed = false;
public void Rls() {disposed = true;}
public void SaveAsBmp(Io_url url) {}
public void SaveAsPng(Io_url url) {}
public ImageAdp Extract_image(RectAdp src_rect, SizeAdp trg_size) {return Extract_image(src_rect.X(), src_rect.Y(), src_rect.Width(), src_rect.Height(), trg_size.Width(), trg_size.Height());}
public ImageAdp Extract_image(int src_x, int src_y, int src_w, int src_h, int trg_w, int trg_h) {return this;}
public ImageAdp Resize(int width, int height) {return this;}
public static final ImageAdp_null _ = new ImageAdp_null(); ImageAdp_null() {}
}

View File

@@ -0,0 +1,32 @@
/*
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 ScreenAdp {
public int Index() {return index;} int index;
public RectAdp Rect() {return bounds;} RectAdp bounds = RectAdp_.Zero;
public SizeAdp Size() {return bounds.Size();}
public int Width() {return bounds.Width();}
public int Height() {return bounds.Height();}
public PointAdp Pos() {return bounds.Pos();}
public int X() {return bounds.X();}
public int Y() {return bounds.Y();}
@gplx.Internal protected ScreenAdp(int index, RectAdp bounds) {
this.index = index; this.bounds = bounds;
}
}

View 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; import gplx.*;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
public class ScreenAdp_ {
public static final ScreenAdp Primary = screen_(0);
public static ScreenAdp as_(Object obj) {return obj instanceof ScreenAdp ? (ScreenAdp)obj : null;}
public static ScreenAdp cast_(Object obj) {try {return (ScreenAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, ScreenAdp.class, obj);}}
public static ScreenAdp parse_(String raw) { // ex: {screen{1}
try {
raw = String_.Replace(raw, "{screen{", "");
raw = String_.Replace(raw, "}", "");
return ScreenAdp_.screen_(Int_.parse_(raw));
} catch(Exception exc) {throw Exc_.new_parse_exc(exc, ScreenAdp.class, raw);}
}
public static ScreenAdp from_point_(PointAdp pos) {// NOTE: not using FromPoint b/c of plat_wce
if (ScreenAdp_.Count() == 1) return Primary;
ScreenAdp screen0 = screen_(0), screen1 = screen_(1);
return pos.X() < screen1.X() ? screen0 : screen1;
}
public static ScreenAdp opposite_(int idx) {
if (ScreenAdp_.Count() == 1) return Primary;
int opposite = idx == 0 ? 1 : 0; // will ignore all screens with index > 1
return screen_(opposite);
}
public static int Count() {
return GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length;
// return 1;//Screen.AllScreens.Length;
}
public static ScreenAdp screen_(int index) {
if (index >= ScreenAdp_.Count()) throw Exc_.new_missing_idx(index, ScreenAdp_.Count());
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devs = env.getScreenDevices();
GraphicsConfiguration conf = devs[index].getDefaultConfiguration();
ScreenAdp sd = new ScreenAdp(index, GxwCore_lang.XtoRectAdp(conf.getBounds()));
return sd;
}
//#@endif
static ScreenAdp new_(int index, RectAdp rect) {return new ScreenAdp(index, rect);}
}

View 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; import gplx.*;
import javax.swing.Timer;
import java.awt.event.ActionListener;
public class TimerAdp implements RlsAble {
public TimerAdp Interval_(int interval) {
underTimer.setInitialDelay(interval);
underTimer.setDelay(interval);
return this;
}
public TimerAdp Enabled_on() {return Enabled_(true);} public TimerAdp Enabled_off() {return Enabled_(false);}
public TimerAdp Enabled_(boolean val) {
if (!Env_.Mode_testing()) {
if (val) underTimer.start();
else underTimer.stop();
}
return this;
}
public void Rls() {underTimer.stop();}
Timer underTimer;
public static TimerAdp new_(GfoInvkAble invk, String msgKey, int interval, boolean enabled) {
TimerAdp rv = new TimerAdp();
rv.underTimer = new Timer(interval, new TimerActionListener(invk, msgKey));
rv.Interval_(interval).Enabled_(enabled);
return rv;
}
}
class TimerActionListener implements ActionListener {
public void actionPerformed(java.awt.event.ActionEvent arg0) {
GfoInvkAble_.InvkCmd(invk, key);
}
GfoInvkAble invk; String key;
public TimerActionListener(GfoInvkAble invk, String key) {
this.invk = invk; this.key = key;
}
}