You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gnosygnu_xowa/150_gfui/src_600_adp/gplx/gfui/IconAdp.java

48 lines
2.1 KiB

9 years ago
/*
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;
9 years ago
import gplx.core.gfo_regys.*;
9 years ago
public class IconAdp {
9 years ago
public Icon UnderIcon() {return icon;} private final Icon icon;
9 years ago
public Image XtoImage() {return ((ImageIcon)icon).getImage();}
9 years ago
public Io_url Url() {return url;} private Io_url url = Io_url_.Empty;
9 years ago
IconAdp(Icon icon) {this.icon = icon;}
public static IconAdp new_(Icon icon) {return new IconAdp(icon);}
9 years ago
public static IconAdp file_or_blank(Io_url url) {return file_(url);}
9 years ago
public static IconAdp file_(Io_url url) {
Icon icon = new ImageIcon(url.Xto_api());
IconAdp rv = new IconAdp(icon);
rv.url = url;
return rv;
}
9 years ago
public static void regy_loadDir_(Io_url imgDir) {GfoRegy.Instance.RegDir(imgDir, "*.png", true, "_", ".");}
public static void regy_loadDir_shallow(Io_url imgDir) {GfoRegy.Instance.RegDir(imgDir, "*.png", false, "_", ".");}
9 years ago
public static IconAdp regy_(String key) {
9 years ago
GfoRegyItm itm = GfoRegy.Instance.FetchOrNull(key);
if (itm == null) {UsrDlg_.Instance.Warn("missing icon; key={0}", key); return null;}
9 years ago
if (itm.ValType() != GfoRegyItm.ValType_Url) throw Err_.new_wo_type("regyItm should be of type url", "key", key);
9 years ago
return IconAdp.file_(itm.Url());
}
public static IconAdp as_(Object obj) {return obj instanceof IconAdp ? (IconAdp)obj : null;}
}