1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.sound.sampled;
27
28 /**
29 * A {@code CompoundControl}, such as a graphic equalizer, provides control over
30 * two or more related properties, each of which is itself represented as a
31 * {@code Control}.
32 *
33 * @author Kara Kytle
34 * @since 1.3
35 */
36 public abstract class CompoundControl extends Control {
37
38 /**
39 * The set of member controls.
40 */
41 private final Control[] controls;
42
43 /**
44 * Constructs a new compound control object with the given parameters.
45 *
46 * @param type the type of control represented this compound control object
47 * @param memberControls the set of member controls
48 */
49 protected CompoundControl(Type type, Control[] memberControls) {
50 super(type);
51 this.controls = memberControls;
52 }
53
54 /**
55 * Returns the set of member controls that comprise the compound control.
56 *
57 * @return the set of member controls
58 */
59 public Control[] getMemberControls() {
60 return controls.clone();
61 }
62
63 /**
64 * Provides a string representation of the control.
65 *
66 * @return a string description
67 */
68 @Override
69 public String toString() {
70
71 StringBuilder sb = new StringBuilder();
72 for (int i = 0; i < controls.length; i++) {
73 if (i != 0) {
74 sb.append(", ");
75 if ((i + 1) == controls.length) {
76 sb.append("and ");
77 }
78 }
79 sb.append(controls[i].getType());
80 }
81
82 return new String(getType() + " Control containing " + sb + " Controls.");
83 }
84
85 /**
86 * An instance of the {@code CompoundControl.Type} inner class identifies
87 * one kind of compound control.
88 *
89 * @author Kara Kytle
90 * @since 1.3
91 */
92 public static class Type extends Control.Type {
93
94 /**
95 * Constructs a new compound control type.
96 *
97 * @param name the name of the new compound control type
98 */
99 protected Type(final String name) {
100 super(name);
101 }
102 }
|
1 /*
2 * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.sound.sampled;
27
28 import java.util.StringJoiner;
29
30 /**
31 * A {@code CompoundControl}, such as a graphic equalizer, provides control over
32 * two or more related properties, each of which is itself represented as a
33 * {@code Control}.
34 *
35 * @author Kara Kytle
36 * @since 1.3
37 */
38 public abstract class CompoundControl extends Control {
39
40 /**
41 * The set of member controls.
42 */
43 private final Control[] controls;
44
45 /**
46 * Constructs a new compound control object with the given parameters.
47 *
48 * @param type the type of control represented this compound control object
49 * @param memberControls the set of member controls
50 */
51 protected CompoundControl(Type type, Control[] memberControls) {
52 super(type);
53 this.controls = memberControls;
54 }
55
56 /**
57 * Returns the set of member controls that comprise the compound control.
58 *
59 * @return the set of member controls
60 */
61 public Control[] getMemberControls() {
62 return controls.clone();
63 }
64
65 /**
66 * Returns a string representation of the compound control.
67 *
68 * @return a string representation of the compound control
69 */
70 @Override
71 public String toString() {
72 StringJoiner controls = new StringJoiner(", ", "[", "]");
73 for (Control control : getMemberControls()) {
74 controls.add(control.getType().toString());
75 }
76 return String.format("%s containing %s controls", super.toString(),
77 controls);
78 }
79
80 /**
81 * An instance of the {@code CompoundControl.Type} inner class identifies
82 * one kind of compound control.
83 *
84 * @author Kara Kytle
85 * @since 1.3
86 */
87 public static class Type extends Control.Type {
88
89 /**
90 * Constructs a new compound control type.
91 *
92 * @param name the name of the new compound control type
93 */
94 protected Type(final String name) {
95 super(name);
96 }
97 }
|