public void setAvailable(boolean a) { _value.setVisible(a); for (ComboCheckBox c : comboCBs) { c.setVisible(a); } for (VarComboBox c : comboVars) { c.setVisible(a); } for (ComboRadioButtons c : comboRBs) { c.setVisible(a); } super.setAvailable(a); }
public Component getNewRep(String format) { // sort on format type if (format.equals("checkbox")) { // this only makes sense if there are exactly two options ComboCheckBox b = new ComboCheckBox(_value, this); comboCBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("radiobuttons")) { ComboRadioButtons b = new ComboRadioButtons(_value, this); comboRBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("onradiobutton")) { ComboRadioButtons b = new ComboOnRadioButton(_value, this); comboRBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("offradiobutton")) { ComboRadioButtons b = new ComboOffRadioButton(_value, this); comboRBs.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } else if (format.equals("tree")) { DefaultTreeModel dModel = new DefaultTreeModel(treeNodes.getFirst()); JTree dTree = new JTree(dModel); trees.add(dTree); JScrollPane dScroll = new JScrollPane(dTree); dTree.setRootVisible(false); dTree.setShowsRootHandles(true); dTree.setScrollsOnExpand(true); dTree.setExpandsSelectedPaths(true); dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); // arrange for only leaf nodes can be selected dTree.addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath[] paths = e.getPaths(); for (int i = 0; i < paths.length; i++) { DefaultMutableTreeNode o = (DefaultMutableTreeNode) paths[i].getLastPathComponent(); if (o.getChildCount() > 0) { ((JTree) e.getSource()).removeSelectionPath(paths[i]); } } // now record selection if (paths.length >= 1) { if (paths[0].getLastPathComponent() instanceof TreeLeafNode) { // update value of Variable setValue(_valueArray[((TreeLeafNode) paths[0].getLastPathComponent()).index]); } } } }); // select initial value TreePath path = _pathArray[_value.getSelectedIndex()]; dTree.setSelectionPath(path); // ensure selection is in visible portion of JScrollPane dTree.scrollPathToVisible(path); if (getReadOnly()) { log.error("read only variables cannot use tree format: {}", item()); } updateRepresentation(dScroll); return dScroll; } else { // return a new JComboBox representing the same model VarComboBox b = new VarComboBox(_value.getModel(), this); comboVars.add(b); if (getReadOnly()) { b.setEnabled(false); } updateRepresentation(b); return b; } }