1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.netsdk.demo.customize.surfaceEventDemo.frame;
 
import com.netsdk.demo.customize.surfaceEventDemo.frame.basic.SwingUtil;
 
import javax.swing.*;
import java.awt.*;
 
/**
 * 播放控制面板
 *
 * @author 47040
 * @since Created in 2021/3/25 19:41
 */
public class ControlPanel extends JPanel {
 
    private final JComboBox<String> channelComboBox = new JComboBox<>(new String[]{" 通道号:   1 "});
 
    private final JButton playBtn = new JButton("开始播放");
    private final JButton stopPlayBtn = new JButton("结束播放");
 
    private final JButton attachBtn = new JButton("全订阅");
    private final JButton detachBtn = new JButton("全退订");
    private final JButton clearBtn = new JButton("清空数据");
 
    public ControlPanel() {
        SwingUtil.setBorderEx(this, "控制", 2);
        setLayout(new GridLayout(3, 1));
        Dimension dim = getPreferredSize();
        dim.setSize(340, 120);
        setPreferredSize(dim);
 
        JLabel channelLabel = new JLabel("选择通道: ");
 
        JPanel placeHolder01 = new JPanel();
        placeHolder01.setLayout(new FlowLayout(FlowLayout.LEFT));
        placeHolder01.add(channelLabel);
        placeHolder01.add(channelComboBox);
 
        JLabel realPlayLabel = new JLabel("视频预览: ");
        JPanel placeHolder02 = new JPanel();
        placeHolder02.setLayout(new FlowLayout(FlowLayout.LEFT));
        placeHolder02.add(realPlayLabel);
        placeHolder02.add(playBtn);
        placeHolder02.add(stopPlayBtn);
 
        JLabel attachLabel = new JLabel("事件订阅: ");
        JPanel placeHolder03 = new JPanel();
        placeHolder03.setLayout(new FlowLayout(FlowLayout.LEFT));
        placeHolder03.add(attachLabel);
        placeHolder03.add(attachBtn);
        placeHolder03.add(detachBtn);
        placeHolder03.add(clearBtn);
 
        add(placeHolder01);
        add(placeHolder02);
        add(placeHolder03);
    }
 
    public JComboBox<?> getChannelComboBox() {
        return channelComboBox;
    }
 
    public int getSelectedSDKChannel() {
        return channelComboBox.getSelectedIndex();
    }
 
    public JButton getPlayBtn() {
        return playBtn;
    }
 
    public JButton getStopPlayBtn() {
        return stopPlayBtn;
    }
 
    public JButton getAttachBtn() {
        return attachBtn;
    }
 
    public JButton getDetachBtn() {
        return detachBtn;
    }
 
    public JButton getClearBtn() {
        return clearBtn;
    }
 
    public void resetChannelComboBox(int channelCount) {
        String[] channelLists = new String[channelCount];
        for (int i = 0; i < channelCount; i++) {
            channelLists[i] = String.format(" 通道号: %3d ", i + 1);
        }
        channelComboBox.setModel(new DefaultComboBoxModel<>(channelLists));
        channelComboBox.setSelectedIndex(0);
    }
 
    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        channelComboBox.setSelectedIndex(0);
        SwingUtil.SetEnableAllInnerComponent(this, enabled);
    }
}