Search in sources :

Example 6 with HashMap

use of org.apache.pivot.collections.HashMap in project pivot by apache.

the class BindTest method testUntypedMap.

/**
 * Tests returning an untyped map.
 *
 * @throws IOException
 * @throws SerializationException
 */
@Test
public void testUntypedMap() throws IOException, SerializationException {
    JSONSerializer mapSerializer = new JSONSerializer(HashMap.class);
    @SuppressWarnings("unchecked") HashMap<String, ?> map = (HashMap<String, ?>) mapSerializer.readObject(new StringReader("{a:1, b:2, c:'3'}"));
    assertEquals(map.get("a"), 1);
}
Also used : HashMap(org.apache.pivot.collections.HashMap) StringReader(java.io.StringReader) JSONSerializer(org.apache.pivot.json.JSONSerializer) Test(org.junit.Test)

Example 7 with HashMap

use of org.apache.pivot.collections.HashMap in project pivot by apache.

the class BindTest method testTypedMap.

/**
 * Tests returning a typed map using
 * {@code org.apache.pivot.util.TypeLiteral}.
 *
 * @throws IOException
 * @throws SerializationException
 */
@Test
public void testTypedMap() throws IOException, SerializationException {
    JSONSerializer typedMapSerializer = new JSONSerializer((new TypeLiteral<HashMap<String, SampleBean2>>() {
    }).getType());
    @SuppressWarnings("unchecked") HashMap<String, SampleBean2> map = (HashMap<String, SampleBean2>) typedMapSerializer.readObject(new StringReader("{foo: {a:1, b:2, c:'3'}}"));
    assertTrue(JSON.get(map, "foo") instanceof SampleBean2);
    assertEquals(JSON.get(map, "foo.c"), "3");
}
Also used : HashMap(org.apache.pivot.collections.HashMap) StringReader(java.io.StringReader) JSONSerializer(org.apache.pivot.json.JSONSerializer) Test(org.junit.Test)

Example 8 with HashMap

use of org.apache.pivot.collections.HashMap in project pivot by apache.

the class SheetExampleWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    editGreetingButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            HashMap<String, Object> context = new HashMap<>();
            store(context);
            editGreetingSheet.load(context);
            editGreetingSheet.open(SheetExampleWindow.this, new SheetCloseListener() {

                @Override
                public void sheetClosed(Sheet sheet) {
                    if (sheet.getResult()) {
                        HashMap<String, Object> contextLocal = new HashMap<>();
                        editGreetingSheet.store(contextLocal);
                        load(contextLocal);
                    }
                }
            });
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) HashMap(org.apache.pivot.collections.HashMap) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) Sheet(org.apache.pivot.wtk.Sheet)

Example 9 with HashMap

use of org.apache.pivot.collections.HashMap in project pivot by apache.

the class TerraTheme method load.

private void load(URL location) {
    Utils.checkNull(location, "location");
    try (InputStream inputStream = location.openStream()) {
        JSONSerializer serializer = new JSONSerializer();
        @SuppressWarnings("unchecked") Map<String, ?> properties = (Map<String, ?>) serializer.readObject(inputStream);
        font = Font.decode((String) properties.get(FONT_PROPERTY));
        String defaultStylesName = (String) properties.get(DEFAULT_STYLES_PROPERTY);
        if (defaultStylesName != null && !defaultStylesName.isEmpty()) {
            defaultStylesFile = defaultStylesName;
        }
        String namedStylesName = (String) properties.get(NAMED_STYLES_PROPERTY);
        if (namedStylesName != null && !namedStylesName.isEmpty()) {
            namedStylesFile = namedStylesName;
        }
        @SuppressWarnings("unchecked") List<String> colorCodes = (List<String>) properties.get(COLORS_PROPERTY);
        numberOfPaletteColors = colorCodes.getLength();
        int numberOfColors = numberOfPaletteColors * 3;
        colors = new ArrayList<>(numberOfColors);
        Double mult = (Double) properties.get(COLOR_MULTIPLIER_PROPERTY);
        if (mult != null) {
            colorMultiplier = mult.floatValue();
        }
        themeIsDark = properties.getBoolean(THEME_IS_DARK_PROPERTY, false);
        themeIsFlat = properties.getBoolean(THEME_IS_FLAT_PROPERTY, false);
        transitionEnabled = properties.getBoolean(TRANSITION_ENABLED_PROPERTY, true);
        for (String colorCode : colorCodes) {
            Color baseColor = GraphicsUtilities.decodeColor(colorCode, "baseColor");
            colors.add(darken(baseColor));
            colors.add(baseColor);
            colors.add(brighten(baseColor));
        }
        @SuppressWarnings("unchecked") Map<String, String> messageIconNames = (Map<String, String>) properties.get(MESSAGE_ICONS_PROPERTY);
        messageIcons = new HashMap<>();
        loadMessageIcons(messageIconNames, messageIcons);
        @SuppressWarnings("unchecked") Map<String, String> smallMessageIconNames = (Map<String, String>) properties.get(SMALL_MESSAGE_ICONS_PROPERTY);
        smallMessageIcons = new HashMap<>();
        loadMessageIcons(smallMessageIconNames, smallMessageIcons);
        if ((defaultBackgroundColor = getColorProperty(properties, DEFAULT_BACKGROUND_COLOR_PROPERTY)) == null) {
            defaultBackgroundColor = super.getDefaultBackgroundColor();
        }
        if ((defaultForegroundColor = getColorProperty(properties, DEFAULT_FOREGROUND_COLOR_PROPERTY)) == null) {
            defaultForegroundColor = super.getDefaultForegroundColor();
        }
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) InputStream(java.io.InputStream) Color(java.awt.Color) IOException(java.io.IOException) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Map(org.apache.pivot.collections.Map) HashMap(org.apache.pivot.collections.HashMap) JSONSerializer(org.apache.pivot.json.JSONSerializer)

Example 10 with HashMap

use of org.apache.pivot.collections.HashMap in project pivot by apache.

the class ComponentPropertyInspectorSkin method sourceChanged.

@Override
public void sourceChanged(ComponentInspector componentInspector, Component previousSource) {
    Component source = componentInspector.getSource();
    clearControls();
    Form.SectionSequence sections = form.getSections();
    sections.remove(0, sections.getLength());
    if (previousSource != null) {
        beanMonitor.getPropertyChangeListeners().remove(propertyChangeListener);
    }
    if (source == null) {
        beanMonitor = null;
    } else {
        beanMonitor = new BeanMonitor(source);
        beanMonitor.getPropertyChangeListeners().add(propertyChangeListener);
        Class<?> sourceType = source.getClass();
        HashMap<Class<?>, List<String>> declaringClassPartitions = new HashMap<>(classComparator);
        // Partition the properties by their declaring class
        BeanAdapter beanAdapter = new BeanAdapter(source);
        for (String propertyName : beanAdapter) {
            if (beanMonitor.isNotifying(propertyName) && !beanAdapter.isReadOnly(propertyName)) {
                Method method = BeanAdapter.getGetterMethod(sourceType, propertyName);
                Class<?> declaringClass = method.getDeclaringClass();
                List<String> propertyNames = declaringClassPartitions.get(declaringClass);
                if (propertyNames == null) {
                    propertyNames = new ArrayList<>(nameComparator);
                    declaringClassPartitions.put(declaringClass, propertyNames);
                }
                propertyNames.add(propertyName);
            }
        }
        // Add the controls
        for (Class<?> declaringClass : declaringClassPartitions) {
            Form.Section section = new Form.Section();
            section.setHeading(declaringClass.getSimpleName());
            sections.add(section);
            List<String> propertyNames = declaringClassPartitions.get(declaringClass);
            for (String propertyName : propertyNames) {
                Class<?> type = beanAdapter.getType(propertyName);
                addControl(beanAdapter, propertyName, type, section);
            }
        }
    }
}
Also used : BeanMonitor(org.apache.pivot.beans.BeanMonitor) Form(org.apache.pivot.wtk.Form) HashMap(org.apache.pivot.collections.HashMap) Method(java.lang.reflect.Method) List(org.apache.pivot.collections.List) ArrayList(org.apache.pivot.collections.ArrayList) BeanAdapter(org.apache.pivot.beans.BeanAdapter) Component(org.apache.pivot.wtk.Component)

Aggregations

HashMap (org.apache.pivot.collections.HashMap)11 ArrayList (org.apache.pivot.collections.ArrayList)6 List (org.apache.pivot.collections.List)4 JSONSerializer (org.apache.pivot.json.JSONSerializer)3 Sheet (org.apache.pivot.wtk.Sheet)3 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)3 StringReader (java.io.StringReader)2 Method (java.lang.reflect.Method)2 TaskAdapter (org.apache.pivot.wtk.TaskAdapter)2 Test (org.junit.Test)2 Color (java.awt.Color)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 BeanAdapter (org.apache.pivot.beans.BeanAdapter)1 BeanMonitor (org.apache.pivot.beans.BeanMonitor)1 Map (org.apache.pivot.collections.Map)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 PostQuery (org.apache.pivot.web.PostQuery)1