@Override public final String toString() { if (contents==null) { final StringBuilder contentBuilder=new StringBuilder(); for (int loop=0; loop<indent; loop++) contentBuilder.append('\t'); contentBuilder.append(subject.toString()); if (subject instanceof CompoundControl) { for (final Control member : ((CompoundControl)subject).getMemberControls()) { contentBuilder.append(System.getProperty("line.separator")); contentBuilder.append(new ControlDescription(member, indent+1).toString()); } } contents=contentBuilder.toString(); } return contents; }
private void enableControls(Control[] controls, boolean enable) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof BoolCtrl) { ((BoolCtrl) controls[i]).closed = !enable; } else if (controls[i] instanceof FloatCtrl) { ((FloatCtrl) controls[i]).closed = !enable; } else if (controls[i] instanceof CompoundControl) { enableControls(((CompoundControl) controls[i]).getMemberControls(), enable); } } }
public static void main(String args[]) throws Exception { System.out.println(); System.out.println(); System.out.println("4629190: CompoundControl: getMemberControls() and toString() throw NullPointerException"); String firstControlTypeName = "first_Control_Type_Name"; String secondControlTypeName = "second_Control_Type_Name"; String thirdControlTypeName = "third_Control_Type_Name"; Control.Type firstControlType = new TestControlType(firstControlTypeName); Control.Type secondControlType = new TestControlType(secondControlTypeName); Control.Type thirdControlType = new TestControlType(thirdControlTypeName); Control firstControl = new TestControl(firstControlType); Control secondControl = new TestControl(secondControlType); Control thirdControl = new TestControl(thirdControlType); String testCompoundControlTypeName = "CompoundControl_Type_Name"; CompoundControl.Type testCompoundControlType = new TestCompoundControlType(testCompoundControlTypeName); Control[] setControls = { firstControl, secondControl, thirdControl }; CompoundControl testedCompoundControl = new TestCompoundControl(testCompoundControlType, setControls); // this may throw exception if bug applies Control[] producedControls = testedCompoundControl.getMemberControls(); System.out.println("Got "+producedControls.length+" member controls."); // this may throw exception if bug applies String producedString = testedCompoundControl.toString(); System.out.println("toString() returned: "+producedString); System.out.println("Test passed."); }
public Control find(final Control... in) { for (final Control element : in) { if (locate.equals(element.getType())) return element; if (element instanceof CompoundControl) { final Control found=find(((CompoundControl)element).getMemberControls()); if (found!=null) return found; } } return null; }
@Test public void findIndirectDescendantSuccessfully() { final CompoundControl mockParentControl=Mockito.mock(CompoundControl.class); Mockito.when(mockLine.getControls()).thenReturn(new Control[]{mockParentControl}); Mockito.when(mockParentControl.getMemberControls()).thenReturn(new Control[]{mockVolume}); Assert.assertEquals(mockVolume, new ControlLocator(testType).find(mockLine)); }
private static Control findControl(Type type, Control[] controls) { if (controls == null || controls.length == 0) return null; for (int i = 0; i < controls.length; i++) { Control control = controls[i]; if (control.getType().equals(type)) return control; if (control instanceof CompoundControl) { CompoundControl compoundControl = (CompoundControl) control; Control member = findControl(type, compoundControl.getMemberControls()); if (member != null) return member; } } return null; }
private static List<FloatControl> getVolumeControls(Control control) { List<FloatControl> result = new ArrayList<FloatControl>(); if (control instanceof CompoundControl) { Control[] controls = ((CompoundControl) control).getMemberControls(); for (Control c : controls) { result.addAll(getVolumeControls(c)); } } else if (control instanceof FloatControl) { FloatControl fc = (FloatControl) control; if (fc.getType() == FloatControl.Type.VOLUME) { result.add(fc); } } return result; }
private void createControlChildren(JavaMixer.ControlNode controlNode) { if (controlNode.getControl() instanceof CompoundControl) { CompoundControl control = (CompoundControl) controlNode.getControl(); Control[] aControls = control.getMemberControls(); for (Control con : aControls) { JavaMixer.ControlNode conNode = new JavaMixer.ControlNode(con); createControlChildren(conNode); controlNode.add(conNode); } } }
public static void main(String[] args) { final JavaMixer sm = new JavaMixer(); final JFrame jf = new JFrame("Mixer Test"); final JPanel jp = new JPanel(); jf.add(jp); jp.add(sm.getTree()); jf.setSize(600, 500); jf.setVisible(true); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); sm.getTree().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getPath(); if (path.getLastPathComponent() instanceof JavaMixer.ControlNode) { JavaMixer.ControlNode controlNode = (JavaMixer.ControlNode) path.getLastPathComponent(); if (!(controlNode.getControl() instanceof CompoundControl)) { if (jp.getComponentCount() > 1) jp.remove(1); jp.add(controlNode.getComponent(), 1); jp.repaint(); } } } }); jp.add(sm.getPrefferedMasterVolume()); jp.add(sm.getPrefferedMasterVolume()); jp.add(sm.getPrefferedInputVolume()); jp.repaint(); sm.setMicrophoneInput(); sm.setMuteForMicrophoneOutput(); }
TestCompoundControl(CompoundControl.Type type, Control[] memberControls) { super(type, memberControls); }