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);
}
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");
}
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);
}
}
});
}
});
}
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);
}
}
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);
}
}
}
}
Aggregations