1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-19 23:58:10 -04:00
parent 96636f3161
commit d4e8590345
1960 changed files with 20790 additions and 9272 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.envs; import gplx.*; import gplx.gfui.*;
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.*; import gplx.core.envs.*;
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 Err_.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.To_str();
// rv = String_.Replace(rv, "\n", Env_.NewLine);
}
return rv;
}
}

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.envs; import gplx.*; import gplx.gfui.*;
import org.junit.*; import gplx.gfui.envs.*;
public class ClipboardAdp__tst {
@Test public void Basic() {
ClipboardAdp_.SetText("test");
Tfds.Eq(true, ClipboardAdp_.IsText());
Tfds.Eq("test", ClipboardAdp_.GetText());
}
}

View File

@@ -0,0 +1,39 @@
/*
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.envs; import gplx.*; import gplx.gfui.*;
import gplx.gfui.controls.gxws.*;
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 Err_.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,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.envs; import gplx.*; import gplx.gfui.*;
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,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.envs; import gplx.*; import gplx.gfui.*;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import gplx.gfui.controls.gxws.*;
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 Err_.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 Err_.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 Err_.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,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.envs; import gplx.*; import gplx.gfui.*;
import org.junit.*; import gplx.gfui.envs.*;
public class ScreenAdp_tst {
@Test public void parse() {
ScreenAdp actl = ScreenAdp_.parse("{screen{0}");
Tfds.Eq(0, actl.Index());
}
@Test public void opposite_() {
ScreenAdp actl = ScreenAdp_.from_point_(PointAdp_.new_(2000, 2000));
Tfds.Eq(0, actl.Index());
}
}

View File

@@ -0,0 +1,54 @@
/*
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.envs; import gplx.*; import gplx.gfui.*;
import javax.swing.Timer;
import java.awt.event.ActionListener;
import gplx.core.envs.*;
public class TimerAdp implements Rls_able {
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_(Gfo_invk 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) {
Gfo_invk_.Invk_by_key(invk, key);
}
Gfo_invk invk; String key;
public TimerActionListener(Gfo_invk invk, String key) {
this.invk = invk; this.key = key;
}
}