Search in sources :

Example 31 with Resources

use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.

the class GameCanvasImplementation method installNativeTheme.

/**
 * @inheritDoc
 */
public void installNativeTheme() {
    InputStream i = getResourceAsStream(getClass(), "/nokia_touch_theme.res");
    if (i == null) {
        i = getResourceAsStream(getClass(), "/nokia_non_touch.res");
    }
    if (i == null) {
        i = getResourceAsStream(getClass(), "/nokia_asha_theme.res");
    }
    if (i == null) {
        i = getResourceAsStream(getClass(), "/nativeJ2METheme.res");
    }
    if (i != null) {
        try {
            Resources r = Resources.open(i);
            UIManager.getInstance().setThemeProps(r.getTheme(r.getThemeResourceNames()[0]));
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(com.codename1.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) Resources(com.codename1.ui.util.Resources)

Example 32 with Resources

use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.

the class ComponentTreeInspector method editStyle.

// GEN-LAST:event_unselectedActionPerformed
private void editStyle() {
    File cn1dir = new File(System.getProperty("user.home"), ".codenameone");
    if (!cn1dir.exists()) {
        JOptionPane.showMessageDialog(this, "Please open the designer once by opening the theme.res file", "Error Opening Designer", JOptionPane.ERROR_MESSAGE);
        return;
    }
    File resourceEditor = new File(cn1dir, "designer_1.jar");
    if (!resourceEditor.exists()) {
        resourceEditor = new File(cn1dir, "designer.jar");
    }
    if (!resourceEditor.exists()) {
        JOptionPane.showMessageDialog(this, "Please open the designer once by opening the theme.res file", "Error Opening Designer", JOptionPane.ERROR_MESSAGE);
        return;
    }
    File javaBin = new File(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java.exe");
    if (!javaBin.exists()) {
        javaBin = new File(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
    }
    final File javaExe = javaBin;
    final File resourceEditorFinal = resourceEditor;
    final String themeFile = themePaths.get(themes.getSelectedIndex());
    final String themeName = themeNames.get(themes.getSelectedIndex());
    final String uiid = componentUIID.getText();
    new Thread() {

        @Override
        public void run() {
            try {
                ProcessBuilder pb = new ProcessBuilder(javaExe.getAbsolutePath(), "-jar", resourceEditorFinal.getAbsolutePath(), "-style", themeFile, uiid, themeName).inheritIO();
                Process proc = pb.start();
                proc.waitFor();
                Display.getInstance().callSerially(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Resources res = Resources.open(new FileInputStream(themeFile));
                            UIManager.getInstance().addThemeProps(res.getTheme(themeName));
                            Display.getInstance().getCurrent().refreshTheme();
                            Display.getInstance().getCurrent().revalidate();
                        } catch (Exception err) {
                            err.printStackTrace();
                        }
                    }
                });
            } catch (Exception err) {
                err.printStackTrace();
            }
        }
    }.start();
}
Also used : Resources(com.codename1.ui.util.Resources) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)15 Resources (com.codename1.ui.util.Resources)14 FileInputStream (java.io.FileInputStream)6 Hashtable (java.util.Hashtable)6 Container (com.codename1.ui.Container)5 Form (com.codename1.ui.Form)5 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)5 InputStream (java.io.InputStream)5 EditableResources (com.codename1.ui.util.EditableResources)4 BufferedInputStream (com.codename1.io.BufferedInputStream)3 Command (com.codename1.ui.Command)3 Component (com.codename1.ui.Component)3 EncodedImage (com.codename1.ui.EncodedImage)3 Image (com.codename1.ui.Image)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)3 Button (com.codename1.ui.Button)2 RadioButton (com.codename1.ui.RadioButton)2 AnimationObject (com.codename1.ui.animations.AnimationObject)2 DataInputStream (java.io.DataInputStream)2