⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javamixer.java

📁 开源项目openfire的完整源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Returns whether the type of a FloatControl is BALANCE or PAN.     *     * @param control FloatControl control     * @return boolean is Balance or Pan     */    private static boolean isBalanceOrPan(FloatControl control) {        Control.Type type = control.getType();        return type.equals(FloatControl.Type.PAN) || type.equals(FloatControl.Type.BALANCE);    }    public class MixerNode extends DefaultMutableTreeNode {        Mixer mixer;        public MixerNode(Mixer mixer) {            super(mixer.getMixerInfo(), true);            this.mixer = mixer;        }        public Mixer getMixer() {            return mixer;        }    }    public class PortNode extends DefaultMutableTreeNode {        Line port;        public PortNode(Line port) {            super(port.getLineInfo(), true);            this.port = port;        }        public Line getPort() {            return port;        }    }    public class ControlNode extends DefaultMutableTreeNode {        Control control;        Component component;        public ControlNode(Control control) {            super(control.getType(), true);            this.control = control;            if (control instanceof BooleanControl) {                component = createControlComponent((BooleanControl) control);            } else if (control instanceof EnumControl) {                component = createControlComponent((EnumControl) control);            } else if (control instanceof FloatControl) {                component = createControlComponent((FloatControl) control);            } else {                component = null;            }        }        public Control getControl() {            return control;        }        public Component getComponent() {            return component;        }        private JComponent createControlComponent(BooleanControl control) {            AbstractButton button;            String strControlName = control.getType().toString();            ButtonModel model = new JavaMixer.BooleanControlButtonModel(control);            button = new JCheckBox(strControlName);            button.setModel(model);            return button;        }        private JComponent createControlComponent(EnumControl control) {            JPanel component = new JPanel();            String strControlName = control.getType().toString();            component.setBorder(new TitledBorder(new EtchedBorder(), strControlName));            return component;        }        private JComponent createControlComponent(FloatControl control) {            int orientation = isBalanceOrPan(control) ? JSlider.HORIZONTAL : JSlider.VERTICAL;            BoundedRangeModel model = new JavaMixer.FloatControlBoundedRangeModel(control);            JSlider slider = new JSlider(model);            slider.setOrientation(orientation);            slider.setPaintLabels(true);            slider.setPaintTicks(true);            slider.setSize(10, 50);            return slider;        }    }    public class BooleanControlButtonModel extends DefaultButtonModel {        private BooleanControl control;        public BooleanControlButtonModel(BooleanControl control) {            this.control = control;            this.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) {                    setSelected(!isSelected());                }            });        }        public void setSelected(boolean bSelected) {            control.setValue(bSelected);        }        public boolean isSelected() {            return control.getValue();        }    }    public class FloatControlBoundedRangeModel extends DefaultBoundedRangeModel {        private FloatControl control;        private float factor;        public FloatControlBoundedRangeModel(FloatControl control) {            this.control = control;            float range = 100;            float steps = range / 100;            factor = range / steps;            int min = (int) (control.getMinimum() * factor);            int max = (int) (control.getMaximum() * factor);            int value = (int) (control.getValue() * factor);            setRangeProperties(value, 0, min, max, false);        }        private float getScaleFactor() {            return factor;        }        public void setValue(int nValue) {            super.setValue(nValue);            control.setValue((float) nValue / getScaleFactor());        }        public int getValue() {            return (int) (control.getValue() * getScaleFactor());        }    }    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();    }    public TreePath find(TreePath path, Object[] nodes) {        return find2(path, nodes, 0, false);    }    public TreePath findByName(TreePath path, String[] names) {        return find2(path, names, 0, true);    }    private TreePath find2(TreePath parent, Object[] nodes, int depth, boolean byName) {        TreeNode node = (TreeNode) parent.getLastPathComponent();        if (depth > nodes.length - 1) {            return parent;        }        if (node.getChildCount() >= 0) {            for (Enumeration e = node.children(); e.hasMoreElements();) {                TreeNode n = (TreeNode) e.nextElement();                TreePath path = parent.pathByAddingChild(n);                boolean find;                if (byName) {                    find = n.toString().toUpperCase().indexOf(nodes[depth].toString().toUpperCase()) > -1;                } else {                    find = n.equals(nodes[depth]);                }                if (find) {                    TreePath result = find2(path, nodes, depth + 1, byName);                    if (result != null) {                        return result;                    }                } else {                    TreePath result = find2(path, nodes, depth, byName);                    if (result != null) {                        return result;                    }                }            }        }        return null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -