Permalink
Browse files

Improved TreeBox control

The treebox control now raises the correct events and displays reacts better on interaction with the displayed entries.
Also the test application was updated to show the capabilities of the updated control
  • Loading branch information...
1 parent a03b19c commit 0d1c6e984bc026cff7c617f7096778f7eeda487d @mkaring mkaring committed Nov 10, 2012
@@ -10,10 +10,10 @@
<attributes childLayout="horizontal" height="24px" />
</style>
<style id="nifty-treebox-item#closed">
- <attributes filename="treebox/closed.png" height="13px" width="8px" visibleToMouse="true" />
+ <attributes filename="treebox/closed.png" height="13px" width="8px" />
</style>
<style id="nifty-treebox-item#opened">
- <attributes filename="treebox/opened.png" height="8px" width="13px" visibleToMouse="true" />
+ <attributes filename="treebox/opened.png" height="8px" width="13px" />
</style>
<style id="nifty-treebox-item#leaf">
<attributes height="0px" width="0px" visible="false" />
@@ -1,45 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package de.lessvoid.nifty.controls;
-
-import de.lessvoid.nifty.NiftyEvent;
-import de.lessvoid.nifty.controls.treebox.TreeBoxControl;
-
-/**
- *
- * @author ractoc
- */
-@SuppressWarnings("rawtypes")
-public class TreeItemSelectedEvent implements NiftyEvent {
-
- private TreeBoxControl treeBoxControl;
- private TreeItem treeItem;
-
- public TreeItemSelectedEvent(TreeBoxControl treeBoxControl, TreeItem treeItem) {
- this.treeBoxControl = treeBoxControl;
- this.treeItem = treeItem;
- }
-
- public TreeItemSelectedEvent(TreeItem treeItem) {
- this.treeItem = treeItem;
- }
-
- public TreeBoxControl getTreeBoxControl() {
- return treeBoxControl;
- }
-
- public void setTreeBoxControl(TreeBoxControl treeBoxControl) {
- this.treeBoxControl = treeBoxControl;
- }
-
- public TreeItem getTreeItem() {
- return treeItem;
- }
-
- public void setTreeItem(TreeItem treeItem) {
- this.treeItem = treeItem;
- }
-
-}
@@ -0,0 +1,28 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.lessvoid.nifty.controls;
+
+import de.lessvoid.nifty.NiftyEvent;
+import de.lessvoid.nifty.controls.treebox.TreeBoxControl;
+
+/**
+ *
+ * @author Martin Karing
+ */
+@SuppressWarnings("rawtypes")
+public class TreeItemSelectionChangedEvent<T> extends ListBoxSelectionChangedEvent<TreeItem<T>> {
+
+ private TreeBox treeBoxControl;
+
+ public TreeItemSelectionChangedEvent(final TreeBoxControl<T> treeBoxControl,
+ final ListBoxSelectionChangedEvent<TreeItem<T>> org) {
+ super(treeBoxControl, org.getSelection(), org.getSelectionIndices());
+ this.treeBoxControl = treeBoxControl;
+ }
+
+ public TreeBox<T> getTreeBoxControl() {
+ return treeBoxControl;
+ }
+}
@@ -8,12 +8,7 @@
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
-import de.lessvoid.nifty.controls.AbstractController;
-import de.lessvoid.nifty.controls.ListBox;
-import de.lessvoid.nifty.controls.ListBoxSelectionChangedEvent;
-import de.lessvoid.nifty.controls.TreeBox;
-import de.lessvoid.nifty.controls.TreeItem;
-import de.lessvoid.nifty.controls.TreeItemSelectedEvent;
+import de.lessvoid.nifty.controls.*;
import de.lessvoid.nifty.controls.listbox.ListBoxControl;
import de.lessvoid.nifty.controls.listbox.ListBoxItemController;
import de.lessvoid.nifty.controls.listbox.ListBoxItemProcessor;
@@ -103,6 +98,13 @@ private void updateList() {
}
}
+ @Override
+ public void publish(final ListBoxSelectionChangedEvent<TreeItem<T>> event) {
+ if (getElement().getId() != null) {
+ nifty.publishEvent(getElement().getId(), new TreeItemSelectionChangedEvent<T>(this, event));
+ }
+ }
+
private void addListItem(final ListBox<TreeItem<T>> list, final TreeItem<T> currentItem, final int currentIndent) {
list.addItem(currentItem);
currentItem.setIndent(currentIndent);
@@ -12,7 +12,7 @@
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.xml.xpp3.Attributes;
-public class TreeBoxItemController<T> extends ListBoxItemController<TreeItem<T>> implements EventTopicSubscriber<NiftyMousePrimaryClickedEvent> {
+public class TreeBoxItemController<T> extends ListBoxItemController<TreeItem<T>> {
@SuppressWarnings("deprecation")
private TreeBoxControl<T> parentControl;
@@ -24,18 +24,14 @@ public void bind(
final Properties properties,
final Attributes controlDefinitionAttributes) {
super.bind(niftyParam, screenParam, newElement, properties, controlDefinitionAttributes);
-
- niftyParam.subscribe(screenParam, newElement.findElementByName("#tree-item-icon").getId(),
- NiftyMousePrimaryClickedEvent.class, this);
}
@SuppressWarnings("deprecation")
void setParentControl(final TreeBoxControl<T> control) {
parentControl = control;
}
- @Override
- public void onEvent(final String topic, final NiftyMousePrimaryClickedEvent data) {
+ public void expandButtonClicked() {
final TreeItem<T> item = getItem();
if (item.isLeaf()) {
return;
@@ -5,6 +5,7 @@
<panel childLayout="horizontal" width="100%" align="center">
<panel id="#tree-item-spacer" visibleToMouse="false" />
<panel id="#tree-item-icon-container" style="#tree-item-icon-container">
+ <interact onClick="expandButtonClicked()" />
<image id="#tree-item-icon" />
</panel>
<panel id="#tree-item-content" style="#content" childLayout="horizontal" width="*" />
@@ -4,11 +4,7 @@
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
-import de.lessvoid.nifty.controls.Controller;
-import de.lessvoid.nifty.controls.TextField;
-import de.lessvoid.nifty.controls.TreeBox;
-import de.lessvoid.nifty.controls.TreeItem;
-import de.lessvoid.nifty.controls.TreeItemSelectedEvent;
+import de.lessvoid.nifty.controls.*;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.input.NiftyInputEvent;
import de.lessvoid.nifty.render.NiftyImage;
@@ -81,8 +77,11 @@ public boolean inputEvent(final NiftyInputEvent inputEvent) {
}
@NiftyEventSubscriber(id="tree-box")
- public void treeItemSelected(final String id, final TreeItemSelectedEvent event) {
- nifty.getCurrentScreen().findNiftyControl("selectedItemText", TextField.class).setText(event.getTreeItem()
- .getValue().toString());
+ public void treeItemSelected(final String id, final TreeItemSelectionChangedEvent<String> event) {
+ final TextField text = nifty.getCurrentScreen().findNiftyControl("selectedItemText", TextField.class);
+
+ if (!event.getSelection().isEmpty()) {
+ text.setText(event.getSelection().get(0).getValue());
+ }
}
}

0 comments on commit 0d1c6e9

Please sign in to comment.