Search in sources :

Example 6 with Resources

use of org.apache.pivot.util.Resources in project pivot by apache.

the class RowEditorDemo method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    String language = properties.get(LANGUAGE_KEY);
    Locale locale = (language == null) ? Locale.getDefault() : new Locale(language);
    Resources resources = new Resources(RESOURCE_NAME, locale);
    System.out.println("Loaded Resources from: " + resources.getBaseName() + ", for locale " + locale);
    // Search for a font that can support the sample string
    String title = (String) resources.get("title");
    System.out.println("Title from Resources file is: \"" + title + "\"");
    // print if the theme has transitions enabled
    System.out.println("Theme has transitions enabled: " + Theme.getTheme().isTransitionEnabled());
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(RowEditorDemo.class.getResource("row_editor_demo.bxml"), resources);
    window.open(display);
}
Also used : Locale(java.util.Locale) Resources(org.apache.pivot.util.Resources) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 7 with Resources

use of org.apache.pivot.util.Resources in project pivot by apache.

the class ParentResourcesTest method before.

@Before
public void before() throws Exception {
    parent = new Resources(getClass().getName() + "Parent");
    assertNotNull("From parent", parent.get("parentKeyString"));
    main = new Resources(parent, getClass().getName(), Locale.ENGLISH);
}
Also used : Resources(org.apache.pivot.util.Resources) Before(org.junit.Before)

Example 8 with Resources

use of org.apache.pivot.util.Resources in project pivot by apache.

the class ScriptApplication method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    // Get the location of the source file
    String src = properties.get(SRC_KEY);
    if (src == null) {
        if (sourceDefault == null) {
            throw new IllegalArgumentException(SRC_KEY + " argument is required.");
        }
        src = sourceDefault;
    }
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL location = classLoader.getResource(src.substring(1));
    if (location == null) {
        // If the source file isn't in the resources, try finding it as a local file
        File localFile = new File(src);
        if (localFile.exists() && localFile.isFile() && localFile.canRead()) {
            try {
                location = localFile.toURI().toURL();
            } catch (MalformedURLException mue) {
            }
        }
    }
    if (location == null) {
        throw new IllegalArgumentException("Cannot find source file \"" + src + "\".");
    }
    Resources resources;
    if (properties.containsKey(RESOURCES_KEY)) {
        resources = new Resources(properties.get(RESOURCES_KEY));
    } else {
        resources = null;
    }
    if (properties.containsKey(STYLESHEET_KEY)) {
        String stylesheet = properties.get(STYLESHEET_KEY);
        if (!stylesheet.startsWith("/")) {
            throw new IllegalArgumentException("Value for " + STYLESHEET_KEY + " argument must start with a slash character.");
        }
        ApplicationContext.applyStylesheet(stylesheet);
    }
    // Load the file and open the window
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Component component = (Component) bxmlSerializer.readObject(location, resources);
    if (component instanceof Sheet || component instanceof Palette) {
        window = new Window();
        window.setMaximized(true);
        window.open(display);
        Window auxWindow = (Window) component;
        auxWindow.open(window);
        auxWindow.requestFocus();
    } else {
        if (component instanceof Window) {
            window = (Window) component;
        } else {
            window = new Window();
            window.setContent(component);
        }
        window.open(display);
        Component content = window.getContent();
        if (content != null) {
            content.requestFocus();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Resources(org.apache.pivot.util.Resources) File(java.io.File) URL(java.net.URL) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 9 with Resources

use of org.apache.pivot.util.Resources in project pivot by apache.

the class StockTracker method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    String language = properties.get(LANGUAGE_KEY);
    Locale locale = (language == null) ? Locale.getDefault() : new Locale(language);
    Resources resources = new Resources(StockTrackerWindow.class.getName(), locale);
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (StockTrackerWindow) bxmlSerializer.readObject(getClass().getResource("stock_tracker_window.bxml"), resources);
    window.open(display);
}
Also used : Locale(java.util.Locale) Resources(org.apache.pivot.util.Resources) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

Resources (org.apache.pivot.util.Resources)9 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)4 URL (java.net.URL)3 Locale (java.util.Locale)3 MalformedURLException (java.net.MalformedURLException)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 Font (java.awt.Font)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Dictionary (org.apache.pivot.collections.Dictionary)1 Theme (org.apache.pivot.wtk.Theme)1 Before (org.junit.Before)1 Test (org.junit.Test)1