@Override protected void wasAdded () { super.wasAdded(); // update our layer when the texture is regenerated _conn = _texture.connectNotify(new Slot<Texture>() { @Override public void onEmit (Texture tex) { update(tex); invalidate(); } }); }
/** Creates a label with the supplied text and icon. */ public Label (String text, Icon icon) { this.text.update(text); this.text.connect(textDidChange()); // update after connect so we trigger iconDidChange, in case our icon is a not-ready-image this.icon.connect(iconDidChange()); this.icon.update(icon); }
public Slider (float value, float min, float max) { this.value = Value.create(value); range = Value.create(new Range(min, max)); // update our display if the slider value is changed externally UnitSlot updateThumb = new UnitSlot () { @Override public void onEmit () { updateThumb(); }}; this.value.connect(updateThumb); range.connect(updateThumb); }
/** Updates the text displayed by this label. */ public Label setText (String text) { this.text.update(text); return this; }
/** Gets the displayed name of the tab. This is a convenience for accessing the text of * the {@link #button}. */ public String name () { return button.text.get(); }
public Field (String initialText, Styles styles) { setStyles(styles); text = Value.create(""); _finishedEditing = Signal.create(); if (hasNative()) { _finishedEditing.connect(new Slot<Boolean>() { @Override public void onEmit (Boolean event) { if (!_fullTimeNative) updateMode(false); } }); } this.text.update(initialText); this.text.connect(textDidChange()); }
_textComp.setText(element.field().text.get()); _textComp.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate (DocumentEvent event) { _textComp.setAutoscrolls(true); _textConnection = _element.field().text.connectNotify(new Slot<String>() { @Override public void onEmit (final String value) { EventQueue.invokeLater(new Runnable() {
protected Group hookup (String name, Selector sel) { final Label label = new Label(); sel.selected.connect(new Slot<Element<?>>() { @Override public void onEmit (Element<?> event) { update(label, (ToggleButton)event); } }); update(label, (ToggleButton)sel.selected.get()); return new Group(AxisLayout.horizontal()).add(new Label(name), label); }
protected Group buttonsSection (Image squares) { ToggleButton toggle3 = new ToggleButton("Toggle Enabled"); Button disabled = new Button("Disabled"); toggle3.selected().connectNotify(disabled.enabledSlot()); toggle3.selected().map(new Function<Boolean,String>() { public String apply (Boolean selected) { return selected ? "Enabled" : "Disabled"; } }).connectNotify(disabled.text.slot());
/** Create a selector with a null initial selection. */ public Selector () { selected.connect(new ValueView.Listener<Element<?>> () { @Override public void onChange (Element<?> selected, Element<?> deselected) { if (deselected != null) get(deselected).update(false); if (selected != null) get(selected).update(true); } }); }
/** * Exposes the size of this collection as a value. */ public synchronized ValueView<Integer> sizeView () { if (_sizeView == null) { _sizeView = Value.create(size()); } return _sizeView; }
public Closeable connect () { return iconV.connectNotify(icon.slot()); } @Override public String toString () {
/** * Updates this instance with the supplied value. Registered listeners are notified only if the * value differs from the current value, as determined via {@link Object#equals}. * @return the previous value contained by this instance. */ public T update (T value) { return updateAndNotifyIf(value); }
/** Updates the icon displayed by this label. */ public Label setIcon (Icon icon) { this.icon.update(icon); return this; }
@Override protected Icon icon () { return icon.get(); } }
/** * Exposes the specified property as a {@link Value}. The supplied default value will be used * if the property has no current value. Updates to the value will be written back to the * storage system. Note that each call to this method yields a new {@link Value} and those * values will not coordinate with one another, so the caller must be sure to only call this * method once for a given property and share that value properly. */ public <E extends Enum<E>> Value<E> valueFor (final String key, E defval) { Value<E> value = Value.create(get(key, defval)); value.connect(new Slot<E>() { @Override public void onEmit (E value) { set(key, value); } }); return value; }
/** Creates a sound board which will play sounds via {@code plat} and connect to {@code paint} * to receive per-frame updates. */ public SoundBoard (Platform plat, Signal<Clock> paint) { this.plat = plat; paint.connect(new Slot<Clock>() { public void onEmit (Clock clock) { update(clock.dt); } }); volume.connect(new Slot<Float>() { @Override public void onEmit (Float volume) { for (LoopImpl active : _active) active.updateVolume(volume); }}); muted.connect(new Slot<Boolean>() { @Override public void onEmit (Boolean muted) { for (LoopImpl active : _active) active.fadeForMute(muted); }}); }
/** * Exposes the size of this collection as a value. */ public synchronized ValueView<Integer> sizeView () { if (_sizeView == null) { _sizeView = Value.create(size()); } return _sizeView; }