use of org.apache.pivot.beans.BeanAdapter in project pivot by apache.
the class Component method setSkin.
/**
* Sets the skin, replacing any previous skin.
*
* @param skin The new skin.
*/
@SuppressWarnings("unchecked")
protected void setSkin(Skin skin) {
Utils.checkNull(skin, "skin");
if (this.skin != null) {
throw new IllegalStateException("Skin is already installed.");
}
this.skin = skin;
styles = new BeanAdapter(skin);
skin.install(this);
// Apply any defined type styles
LinkedList<Class<?>> styleTypes = new LinkedList<>();
Class<?> type = getClass();
while (type != Object.class) {
styleTypes.insert(type, 0);
type = type.getSuperclass();
}
for (Class<?> styleType : styleTypes) {
Map<String, ?> stylesMap = typedStyles.get((Class<? extends Component>) styleType);
if (stylesMap != null) {
setStyles(stylesMap);
}
}
invalidate();
repaint();
}
use of org.apache.pivot.beans.BeanAdapter in project pivot by apache.
the class DataBinding method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
form = (Form) namespace.get("form");
loadJavaButton = (PushButton) namespace.get("loadJavaButton");
loadJSONButton = (PushButton) namespace.get("loadJSONButton");
clearButton = (PushButton) namespace.get("clearButton");
sourceLabel = (Label) namespace.get("sourceLabel");
loadJavaButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
form.load(new BeanAdapter(CONTACT));
sourceLabel.setText("Java");
}
});
loadJSONButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
JSONSerializer serializer = new JSONSerializer();
try (InputStream inputStream = getClass().getResourceAsStream("contact.json")) {
form.load(serializer.readObject(inputStream));
sourceLabel.setText("JSON");
} catch (Exception exception) {
System.err.println(exception);
}
button.setEnabled(true);
}
});
clearButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
form.clear();
sourceLabel.setText("");
}
});
}
use of org.apache.pivot.beans.BeanAdapter 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);
}
}
}
}
use of org.apache.pivot.beans.BeanAdapter in project pivot by apache.
the class StockTrackerWindow method refreshDetail.
private void refreshDetail() {
StockQuote stockQuote = null;
int firstSelectedIndex = stocksTableView.getFirstSelectedIndex();
if (firstSelectedIndex != -1) {
int lastSelectedIndex = stocksTableView.getLastSelectedIndex();
if (firstSelectedIndex == lastSelectedIndex) {
@SuppressWarnings("unchecked") List<StockQuote> tableData = (List<StockQuote>) stocksTableView.getTableData();
stockQuote = tableData.get(firstSelectedIndex);
} else {
stockQuote = new StockQuote();
}
} else {
stockQuote = new StockQuote();
}
detailPane.load(new BeanAdapter(stockQuote));
}
Aggregations