mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-06-13 12:54:14 +00:00
95 lines
4.4 KiB
Java
95 lines
4.4 KiB
Java
|
/*
|
||
|
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.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
|
||
|
import gplx.core.envs.*; import gplx.gfui.kits.core.*; import gplx.gfui.envs.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.standards.*;
|
||
|
public class GfuiStatusBox extends GfuiTextBox implements UsrMsgWkr { public GfuiStatusBox Active_(boolean v) {active = v; return this;} private boolean active = true;
|
||
|
public GfuiStatusBox VisibilityDuration_(int v) {timer.Interval_(v); visibilityDuration = v; return this;} int visibilityDuration;
|
||
|
@Override public void Opened_cbk() {
|
||
|
super.Opened_cbk();
|
||
|
UsrDlg_.Instance.Reg(UsrMsgWkr_.Type_Note, this);
|
||
|
}
|
||
|
public void ExecUsrMsg(int type, UsrMsg umsg) {
|
||
|
if ( !active
|
||
|
|| !this.OwnerElem().Visible() // WORKAROUND.WINFORMS: else application hangs on Invoke
|
||
|
|| !this.Opened_done()
|
||
|
) return;
|
||
|
this.CreateControlIfNeeded(); // WORKAROUND.WINFORMS: else will sometimes throw: Cannot call Invoke or InvokeAsync on a control until the window handle has been created
|
||
|
this.VisibilityDuration_(umsg.VisibilityDuration());
|
||
|
String text = String_.Replace(umsg.To_str(), Op_sys.Cur().Nl_str(), " "); // replace NewLine with " " since TextBox cannot show NewLine
|
||
|
Invoke(Gfo_invk_cmd.New_by_val(this, Invk_WriteText, text));
|
||
|
}
|
||
|
public void WriteText(String text) {
|
||
|
if (!this.Visible()) {
|
||
|
this.Visible_set(true);
|
||
|
this.Zorder_front();
|
||
|
}
|
||
|
this.Text_(text);
|
||
|
timer.Enabled_off().Enabled_on(); // Enabled_off().Enabled_on() resets timer; timer can be at second 1 of 3, and this will reset back to timer 0
|
||
|
GfuiEnv_.DoEvents(); // WORKAROUND.WINFORMS: needed, else text will not refresh (ex: splash screen); NOTE!!: will cause other timers to fire! (ex: mediaPlaylistMgr)
|
||
|
}
|
||
|
@Override public void Focus() {
|
||
|
this.Focus_able_(true);
|
||
|
super.Focus();
|
||
|
this.Focus_able_(false);
|
||
|
}
|
||
|
@Override public boolean DisposeCbk() {
|
||
|
super.DisposeCbk();
|
||
|
timer.Rls();
|
||
|
UsrDlg_.Instance.RegOff(UsrMsgWkr_.Type_Note, this);
|
||
|
if (timerCmd != null) timerCmd.Rls();
|
||
|
return true;
|
||
|
}
|
||
|
void HideWindow() {
|
||
|
timer.Enabled_off();
|
||
|
Text_("");
|
||
|
this.Visible_set(false);
|
||
|
this.Zorder_back();
|
||
|
}
|
||
|
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||
|
if (ctx.Match(k, Invk_HideWindow)) HideWindow();
|
||
|
else if (ctx.Match(k, Invk_Text_empty)) {timer.Enabled_off(); Text_(GfuiTextBox_.NewLine + Text());}
|
||
|
else if (ctx.Match(k, Invk_WriteText)) WriteText(m.ReadStr("v"));
|
||
|
else return super.Invk(ctx, ikey, k, m);
|
||
|
return this;
|
||
|
} static final String Invk_HideWindow = "HideWindow", Invk_WriteText = "WriteText", Invk_Text_empty = "Text_empty";
|
||
|
TimerAdp timer;
|
||
|
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
|
||
|
super.ctor_GfuiBox_base(ctorArgs);
|
||
|
this.Border_on_(false);
|
||
|
this.Focus_able_(false);
|
||
|
this.Visible_set(false);
|
||
|
timer = TimerAdp.new_(this, Invk_HideWindow, 2000, false);
|
||
|
}
|
||
|
@Override public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
|
||
|
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
|
||
|
this.Border_on_(false);
|
||
|
this.Focus_able_(false);
|
||
|
this.Visible_set(true);
|
||
|
timerCmd = kit.New_cmd_sync(this);
|
||
|
timer = TimerAdp.new_(timerCmd, GfuiInvkCmd_.Invk_sync, 2000, false);
|
||
|
} GfuiInvkCmd timerCmd;
|
||
|
public void ctor_kit_GfuiElemBase_drd(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
|
||
|
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
|
||
|
this.Border_on_(false);
|
||
|
this.Focus_able_(false);
|
||
|
this.Visible_set(true);
|
||
|
timerCmd = kit.New_cmd_sync(this);
|
||
|
// timer = TimerAdp.new_(timerCmd, GfuiInvkCmd_.Invk_sync, 2000, false);
|
||
|
}
|
||
|
}
|