- update root_bus on structure change
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@164 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -23,10 +23,19 @@ import ch.ntb.usb.Usb_Interface_Descriptor;
|
|||||||
public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||||
|
|
||||||
private Usb_Bus rootBus;
|
private Usb_Bus rootBus;
|
||||||
|
|
||||||
private JTextArea textArea;
|
private JTextArea textArea;
|
||||||
|
|
||||||
private Vector<TreeModelListener> treeModelListeners = new Vector<TreeModelListener>();
|
private Vector<TreeModelListener> treeModelListeners = new Vector<TreeModelListener>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.<br>
|
||||||
|
*
|
||||||
|
* @param rootBus
|
||||||
|
* the root bus from which the data is read
|
||||||
|
* @param textArea
|
||||||
|
* the text area to which the data is written
|
||||||
|
*/
|
||||||
public UsbTreeModel(Usb_Bus rootBus, JTextArea textArea) {
|
public UsbTreeModel(Usb_Bus rootBus, JTextArea textArea) {
|
||||||
this.rootBus = rootBus;
|
this.rootBus = rootBus;
|
||||||
this.textArea = textArea;
|
this.textArea = textArea;
|
||||||
@@ -142,12 +151,12 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
|||||||
* The only event raised by this model is TreeStructureChanged with the root
|
* The only event raised by this model is TreeStructureChanged with the root
|
||||||
* as path, i.e. the whole tree has changed.
|
* as path, i.e. the whole tree has changed.
|
||||||
*/
|
*/
|
||||||
protected void fireTreeStructureChanged(Usb_Bus oldRootBus) {
|
protected void fireTreeStructureChanged(Usb_Bus newRootBus) {
|
||||||
|
rootBus = newRootBus;
|
||||||
int len = treeModelListeners.size();
|
int len = treeModelListeners.size();
|
||||||
TreeModelEvent e = new TreeModelEvent(this, new Object[] { oldRootBus });
|
TreeModelEvent e = new TreeModelEvent(this, new Object[] { newRootBus });
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
((TreeModelListener) treeModelListeners.elementAt(i))
|
treeModelListeners.elementAt(i).treeStructureChanged(e);
|
||||||
.treeStructureChanged(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,8 +397,8 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
|||||||
sb.append("\tbmAttributes: 0x"
|
sb.append("\tbmAttributes: 0x"
|
||||||
+ Integer.toHexString(epDesc.bmAttributes & 0xFF) + "\n");
|
+ Integer.toHexString(epDesc.bmAttributes & 0xFF) + "\n");
|
||||||
sb.append("\twMaxPacketSize: 0x"
|
sb.append("\twMaxPacketSize: 0x"
|
||||||
+ Integer.toHexString(epDesc.wMaxPacketSize & 0xFFFF) + " ("
|
+ Integer.toHexString(epDesc.wMaxPacketSize & 0xFFFF)
|
||||||
+ epDesc.wMaxPacketSize + ")\n");
|
+ " (" + epDesc.wMaxPacketSize + ")\n");
|
||||||
sb.append("\tbInterval: 0x" + Integer.toHexString(epDesc.bInterval)
|
sb.append("\tbInterval: 0x" + Integer.toHexString(epDesc.bInterval)
|
||||||
+ "\n");
|
+ "\n");
|
||||||
sb.append("\tbRefresh: 0x" + Integer.toHexString(epDesc.bRefresh)
|
sb.append("\tbRefresh: 0x" + Integer.toHexString(epDesc.bRefresh)
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public class UsbView extends JFrame {
|
|||||||
|
|
||||||
private JTextArea jPropertiesArea = null;
|
private JTextArea jPropertiesArea = null;
|
||||||
|
|
||||||
|
UsbTreeModel treeModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the default constructor
|
* This is the default constructor
|
||||||
*/
|
*/
|
||||||
@@ -97,7 +99,7 @@ public class UsbView extends JFrame {
|
|||||||
if (commandsMenu == null) {
|
if (commandsMenu == null) {
|
||||||
commandsMenu = new JMenu();
|
commandsMenu = new JMenu();
|
||||||
commandsMenu.setText("Commands");
|
commandsMenu.setText("Commands");
|
||||||
commandsMenu.add(getSaveMenuItem());
|
commandsMenu.add(getUpdateMenuItem());
|
||||||
commandsMenu.add(getExitMenuItem());
|
commandsMenu.add(getExitMenuItem());
|
||||||
}
|
}
|
||||||
return commandsMenu;
|
return commandsMenu;
|
||||||
@@ -126,7 +128,7 @@ public class UsbView extends JFrame {
|
|||||||
*
|
*
|
||||||
* @return javax.swing.JMenuItem
|
* @return javax.swing.JMenuItem
|
||||||
*/
|
*/
|
||||||
private JMenuItem getSaveMenuItem() {
|
private JMenuItem getUpdateMenuItem() {
|
||||||
if (updateMenuItem == null) {
|
if (updateMenuItem == null) {
|
||||||
updateMenuItem = new JMenuItem();
|
updateMenuItem = new JMenuItem();
|
||||||
updateMenuItem.setText("Update");
|
updateMenuItem.setText("Update");
|
||||||
@@ -142,10 +144,7 @@ public class UsbView extends JFrame {
|
|||||||
|
|
||||||
Usb_Bus bus = LibusbWin.usb_get_busses();
|
Usb_Bus bus = LibusbWin.usb_get_busses();
|
||||||
if (bus != null) {
|
if (bus != null) {
|
||||||
UsbTreeModel treeModel = new UsbTreeModel(bus,
|
treeModel.fireTreeStructureChanged(bus);
|
||||||
jPropertiesArea);
|
|
||||||
usbTree.setModel(treeModel);
|
|
||||||
usbTree.addTreeSelectionListener(treeModel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -167,7 +166,7 @@ public class UsbView extends JFrame {
|
|||||||
|
|
||||||
Usb_Bus bus = LibusbWin.usb_get_busses();
|
Usb_Bus bus = LibusbWin.usb_get_busses();
|
||||||
|
|
||||||
UsbTreeModel treeModel = new UsbTreeModel(bus, jPropertiesArea);
|
treeModel = new UsbTreeModel(bus, jPropertiesArea);
|
||||||
usbTree = new JTree(treeModel);
|
usbTree = new JTree(treeModel);
|
||||||
usbTree.addTreeSelectionListener(treeModel);
|
usbTree.addTreeSelectionListener(treeModel);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user