use of com.codename1.ui.util.xml.Theme in project CodenameOne by codenameone.
the class ResourceEditorApp method importRes.
private static Hashtable importRes(EditableResources res, String file) {
InputStream is = ResourceEditorApp.class.getResourceAsStream("/templates/" + file + ".res");
Hashtable theme = new Hashtable();
if (is != null) {
try {
EditableResources r = new EditableResources();
r.openFile(is);
is.close();
if (r.getThemeResourceNames().length > 0) {
theme = r.getTheme(r.getThemeResourceNames()[0]);
}
ResourceEditorView.checkDuplicateResourcesLoop(r, res.getImageResourceNames(), r.getImageResourceNames(), "Rename Image", "Image ", true, null);
ResourceEditorView.checkDuplicateResourcesLoop(r, res.getL10NResourceNames(), r.getL10NResourceNames(), "Rename Localization", "Localization ", true, null);
ResourceEditorView.checkDuplicateResourcesLoop(r, res.getDataResourceNames(), r.getDataResourceNames(), "Rename Data", "Data ", true, null);
ResourceEditorView.checkDuplicateResourcesLoop(r, res.getUIResourceNames(), r.getUIResourceNames(), "Rename GUI", "GUI ", true, null);
ResourceEditorView.checkDuplicateResourcesLoop(r, res.getFontResourceNames(), r.getFontResourceNames(), "Rename Font", "Font ", true, null);
for (String s : r.getImageResourceNames()) {
if (r.isMultiImage(s)) {
res.setMultiImage(s, (EditableResources.MultiImage) r.getResourceObject(s));
} else {
res.setImage(s, r.getImage(s));
}
}
for (String s : r.getL10NResourceNames()) {
res.setL10N(s, (Hashtable) r.getResourceObject(s));
}
for (String s : r.getDataResourceNames()) {
res.setData(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getUIResourceNames()) {
res.setUi(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getFontResourceNames()) {
res.setFont(s, r.getFont(s));
}
} catch (IOException err) {
err.printStackTrace();
}
}
return theme;
}
use of com.codename1.ui.util.xml.Theme in project CodenameOne by codenameone.
the class JavaSEPort method loadSkinFile.
private void loadSkinFile(InputStream skin, final JFrame frm) {
try {
ZipInputStream z = new ZipInputStream(skin);
ZipEntry e = z.getNextEntry();
final Properties props = new Properties();
BufferedImage map = null;
BufferedImage landscapeMap = null;
// if we load the native theme imediately the multi-image's will be loaded with the size of the old skin
byte[] nativeThemeData = null;
nativeThemeRes = null;
nativeTheme = null;
while (e != null) {
String name = e.getName();
if (name.equals("skin.png")) {
portraitSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header.png")) {
header = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header_l.png")) {
headerLandscape = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin.properties")) {
props.load(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_l.png")) {
landscapeSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map.png")) {
map = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map_l.png")) {
landscapeMap = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.endsWith(".res")) {
long esize = e.getSize();
if (esize > 0) {
nativeThemeData = new byte[(int) esize];
readFully(z, nativeThemeData);
} else {
ByteArrayOutputStream b = new ByteArrayOutputStream();
Util.copyNoClose(z, b, 8192);
nativeThemeData = b.toByteArray();
}
e = z.getNextEntry();
continue;
}
if (name.endsWith(".ttf")) {
try {
java.awt.Font result = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, z);
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(result);
} catch (FontFormatException ex) {
ex.printStackTrace();
}
e = z.getNextEntry();
continue;
}
e = z.getNextEntry();
}
z.close();
String ppi = props.getProperty("ppi");
if (ppi != null) {
double ppiD = Double.valueOf(ppi);
pixelMilliRatio = ppiD / 25.4;
} else {
String pix = props.getProperty("pixelRatio");
if (pix != null && pix.length() > 0) {
try {
pixelMilliRatio = Double.valueOf(pix);
} catch (NumberFormatException err) {
err.printStackTrace();
pixelMilliRatio = null;
}
} else {
pixelMilliRatio = null;
}
}
portraitSkinHotspots = new HashMap<Point, Integer>();
portraitScreenCoordinates = new Rectangle();
landscapeSkinHotspots = new HashMap<Point, Integer>();
landscapeScreenCoordinates = new Rectangle();
if (props.getProperty("roundScreen", "false").equalsIgnoreCase("true")) {
portraitScreenCoordinates.x = Integer.parseInt(props.getProperty("displayX"));
portraitScreenCoordinates.y = Integer.parseInt(props.getProperty("displayY"));
portraitScreenCoordinates.width = Integer.parseInt(props.getProperty("displayWidth"));
portraitScreenCoordinates.height = Integer.parseInt(props.getProperty("displayHeight"));
landscapeScreenCoordinates.x = portraitScreenCoordinates.y;
landscapeScreenCoordinates.y = portraitScreenCoordinates.x;
landscapeScreenCoordinates.width = portraitScreenCoordinates.height;
landscapeScreenCoordinates.height = portraitScreenCoordinates.width;
roundedSkin = true;
} else {
initializeCoordinates(map, props, portraitSkinHotspots, portraitScreenCoordinates);
initializeCoordinates(landscapeMap, props, landscapeSkinHotspots, landscapeScreenCoordinates);
}
platformName = props.getProperty("platformName", "se");
platformOverrides = props.getProperty("overrideNames", "").split(",");
String ua = null;
if (platformName.equals("and")) {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
} else if (platformName.equals("rim")) {
ua = "Mozilla/5.0 (BlackBerry; U; BlackBerry 9860; en-GB) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.296 Mobile Safari/534.11+";
} else if (platformName.equals("ios")) {
if (isTablet()) {
ua = "Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5";
} else {
ua = "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5";
}
} else if (platformName.equals("me")) {
ua = "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124";
} else {
if (platformName.equals("win")) {
ua = "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)";
} else {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
}
}
Display.getInstance().setProperty("User-Agent", ua);
isIOS = props.getProperty("systemFontFamily", "Arial").toLowerCase().contains("helvetica");
setFontFaces(props.getProperty("systemFontFamily", "Arial"), props.getProperty("proportionalFontFamily", "SansSerif"), props.getProperty("monospaceFontFamily", "Monospaced"));
int med;
int sm;
int la;
if (pixelMilliRatio == null) {
float factor = ((float) getDisplayHeightImpl()) / 480.0f;
med = (int) (15.0f * factor);
sm = (int) (11.0f * factor);
la = (int) (19.0f * factor);
} else {
med = (int) Math.round(2.6 * pixelMilliRatio.doubleValue());
sm = (int) Math.round(2 * pixelMilliRatio.doubleValue());
la = (int) Math.round(3.3 * pixelMilliRatio.doubleValue());
}
setFontSize(Integer.parseInt(props.getProperty("mediumFontSize", "" + med)), Integer.parseInt(props.getProperty("smallFontSize", "" + sm)), Integer.parseInt(props.getProperty("largeFontSize", "" + la)));
tablet = props.getProperty("tablet", "false").equalsIgnoreCase("true");
rotateTouchKeysOnLandscape = props.getProperty("rotateKeys", "false").equalsIgnoreCase("true");
touchDevice = props.getProperty("touch", "true").equalsIgnoreCase("true");
keyboardType = Integer.parseInt(props.getProperty("keyboardType", "0"));
softkeyCount = Integer.parseInt(props.getProperty("softbuttonCount", "1"));
if (softkeyCount < 2) {
// the values of the static variables to be correct!
try {
Field f = com.codename1.ui.MenuBar.class.getDeclaredField("leftSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F1);
f = com.codename1.ui.MenuBar.class.getDeclaredField("rightSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F2);
} catch (Throwable t) {
t.printStackTrace();
}
}
final byte[] nativeThemeFinalData = nativeThemeData;
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (nativeThemeFinalData != null) {
try {
nativeThemeRes = Resources.open(new ByteArrayInputStream(nativeThemeFinalData));
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
try {
boolean isJ2me = props.getProperty("platformName", "").equals("me");
String t = props.getProperty("nativeThemeAttribute", null);
if (t != null) {
Properties cnop = new Properties();
File cnopFile = new File("codenameone_settings.properties");
if (cnopFile.exists()) {
cnop.load(new FileInputStream(cnopFile));
int themeConst = Integer.parseInt(cnop.getProperty("codename1.j2me.nativeThemeConst", "3"));
t = cnop.getProperty(t, null);
if (isJ2me && themeConst == 3 && t != null && new File(t).exists()) {
nativeThemeRes = Resources.open(new FileInputStream(t));
}
}
}
} catch (IOException ioErr) {
ioErr.printStackTrace();
}
}
}
});
installMenu(frm, false);
} catch (IOException err) {
err.printStackTrace();
}
}
use of com.codename1.ui.util.xml.Theme in project CodenameOne by codenameone.
the class Dialog method showPopupDialog.
/**
* A popup dialog is shown with the context of a component and its selection, it is disposed seamlessly if the back button is pressed
* or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
* dialog has the PopupDialog style by default.
*
* @param c the context component which is used to position the dialog and can also be pointed at
* @return the command that might have been triggered by the user within the dialog if commands are placed in the dialog
*/
public Command showPopupDialog(Component c) {
Rectangle componentPos = c.getSelectedRect();
componentPos.setX(componentPos.getX() - c.getScrollX());
componentPos.setY(componentPos.getY() - c.getScrollY());
return showPopupDialog(componentPos);
}
use of com.codename1.ui.util.xml.Theme in project CodenameOne by codenameone.
the class Form method createStatusBar.
/**
* Subclasses can override this method to control the creation of the status bar component.
* Notice that this method will only be invoked if the paintsTitleBarBool theme constant is true
* which it is on iOS by default
* @return a Component that represents the status bar if the OS requires status bar spacing
*/
protected Component createStatusBar() {
if (getUIManager().isThemeConstant("statusBarScrollsUpBool", true)) {
Button bar = new Button();
bar.setShowEvenIfBlank(true);
bar.setUIID("StatusBar");
bar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Component c = findScrollableChild(getContentPane());
if (c != null) {
c.scrollRectToVisible(new Rectangle(0, 0, 10, 10), c);
}
}
});
return bar;
} else {
Container bar = new Container();
bar.setUIID("StatusBar");
return bar;
}
}
use of com.codename1.ui.util.xml.Theme in project CodenameOne by codenameone.
the class AndroidImplementation method installNativeTheme.
/**
* Installs the native theme, this is only applicable if hasNativeTheme()
* returned true. Notice that this method might replace the
* DefaultLookAndFeel instance and the default transitions.
*/
public void installNativeTheme() {
hasNativeTheme();
if (nativeThemeAvailable) {
try {
InputStream is;
if (android.os.Build.VERSION.SDK_INT < 14 && !isTablet() || Display.getInstance().getProperty("and.hololight", "false").equals("true")) {
is = getResourceAsStream(getClass(), "/androidTheme.res");
} else {
is = getResourceAsStream(getClass(), "/android_holo_light.res");
}
Resources r = Resources.open(is);
Hashtable h = r.getTheme(r.getThemeResourceNames()[0]);
h.put("@commandBehavior", "Native");
UIManager.getInstance().setThemeProps(h);
is.close();
Display.getInstance().setCommandBehavior(Display.COMMAND_BEHAVIOR_NATIVE);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Aggregations