ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package com.vci.client.portal.NewUI;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;
import java.util.Map;
 
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
 
import com.vci.client.LogonApplication;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.common.resource.CommonProperties;
 
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JComboBox;
 
public class ClickEventInfoPanel extends JPanel {
    private JTextField eventValueTxt;
    private JButton addBtn;
    private JButton delBtn;
    private JButton mupBtn;
    private JButton mDownBtn;
    private JList list;
    private DefaultListModel listModel;
    private JComboBox eventKeyCmb;
    public DefaultListModel getListModel() {
        return listModel;
    }
    public void setListModel(DefaultListModel listModel) {
        this.listModel = listModel;
    }
    /**
     * Create the panel.
     */
    public ClickEventInfoPanel() {
        init();
        initeventKeyCmb();
        initAction();
    }
    private void init() {
        setLayout(new BorderLayout(0, 0));
        
        JScrollPane scrollPane = new JScrollPane();
        add(scrollPane, BorderLayout.NORTH);
        
        JPanel panel = new JPanel();
        scrollPane.setViewportView(panel);
        GridBagLayout gbl_panel = new GridBagLayout();
        gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0};
        gbl_panel.rowHeights = new int[]{0, 0, 0};
        gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
        gbl_panel.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
        panel.setLayout(gbl_panel);
        
        JLabel lblNewLabel = new JLabel("EventKey");
        GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
        gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
        gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
        gbc_lblNewLabel.gridx = 0;
        gbc_lblNewLabel.gridy = 0;
        panel.add(lblNewLabel, gbc_lblNewLabel);
        
        eventKeyCmb = new JComboBox();
        GridBagConstraints gbc_eventKeyCmb = new GridBagConstraints();
        gbc_eventKeyCmb.insets = new Insets(0, 0, 5, 5);
        gbc_eventKeyCmb.fill = GridBagConstraints.HORIZONTAL;
        gbc_eventKeyCmb.gridx = 1;
        gbc_eventKeyCmb.gridy = 0;
        panel.add(eventKeyCmb, gbc_eventKeyCmb);
        
        JLabel lblNewLabel_1 = new JLabel("EventValue");
        GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
        gbc_lblNewLabel_1.fill = GridBagConstraints.HORIZONTAL;
        gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
        gbc_lblNewLabel_1.gridx = 2;
        gbc_lblNewLabel_1.gridy = 0;
        panel.add(lblNewLabel_1, gbc_lblNewLabel_1);
        
        eventValueTxt = new JTextField();
        GridBagConstraints gbc_eventValueTxt = new GridBagConstraints();
        gbc_eventValueTxt.insets = new Insets(0, 0, 5, 0);
        gbc_eventValueTxt.fill = GridBagConstraints.HORIZONTAL;
        gbc_eventValueTxt.gridx = 3;
        gbc_eventValueTxt.gridy = 0;
        panel.add(eventValueTxt, gbc_eventValueTxt);
        eventValueTxt.setColumns(10);
        
        JPanel panel_1 = new JPanel();
        GridBagConstraints gbc_panel_1 = new GridBagConstraints();
        gbc_panel_1.gridwidth = 4;
        gbc_panel_1.fill = GridBagConstraints.BOTH;
        gbc_panel_1.gridx = 0;
        gbc_panel_1.gridy = 1;
        panel.add(panel_1, gbc_panel_1);
        
        addBtn = new JButton("创建");
        panel_1.add(addBtn);
        
        delBtn = new JButton("删除");
        panel_1.add(delBtn);
        
        mupBtn = new JButton("上移");
        panel_1.add(mupBtn);
        
        mDownBtn = new JButton("下移");
        panel_1.add(mDownBtn);
        
        JPanel panel_2 = new JPanel();
        add(panel_2, BorderLayout.CENTER);
        panel_2.setLayout(new BorderLayout(0, 0));
        
        JScrollPane scrollPane_1 = new JScrollPane();
        panel_2.add(scrollPane_1, BorderLayout.CENTER);
        
        list = new JList();
        listModel = new DefaultListModel();
        list.setModel(listModel);
        scrollPane_1.setViewportView(list);
    }
    private void initAction() {
        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                super.mouseClicked(arg0);
                String selectedValue = (String) list.getSelectedValue();
                if(selectedValue!=null){
                    String[] split = selectedValue.split(":");
                    eventKeyCmb.setSelectedItem(split[0]);
                    eventValueTxt.setText(split[1]);
                }
            }
        });
        addBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String eventKey = (String) eventKeyCmb.getSelectedItem();
                String eventValue = eventValueTxt.getText();
                if(eventKey==null||"".equals(eventKey)){
                    VCIOptionPane.showMessage(LogonApplication.frame, "请输入eventKey值!");
                    return;
                }
                if(eventValue==null||"".equals(eventValue)){
                    VCIOptionPane.showMessage(LogonApplication.frame, "请输入eventValue值!");
                    return;
                }
                listModel.addElement(eventKey+":"+eventValue);
            }
        });
        delBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String selectedValue = (String) list.getSelectedValue();
                if (VCIOptionPane.showQuestion(LogonApplication.frame,
                        "确定要删除记录吗?") != 0) {
                    return;
                }
                listModel.removeElement(selectedValue);
            }
        });
        mupBtn.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent arg0) {
                String selectedValue = (String) list.getSelectedValue();
                int selectedIndex = list.getSelectedIndex();
                if(selectedIndex==0){
                    return;
                }
                listModel.add(selectedIndex-1, selectedValue);
                listModel.remove(selectedIndex+1);
                list.setSelectedIndex(selectedIndex-1);
            }
        });
        mDownBtn.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent arg0) {
                String selectedValue = (String) list.getSelectedValue();
                int selectedIndex = list.getSelectedIndex();
                if(selectedIndex==listModel.getSize()-1){
                    return;
                }
                listModel.add(selectedIndex+2, selectedValue);
                listModel.remove(selectedIndex);
                list.setSelectedIndex(selectedIndex+1);
            }
        });
    }
    private void initeventKeyCmb(){
        String eventkey = CommonProperties.getStringProperty("uidesign.eventKey");
        String[] split = eventkey.split(",");
        for(String s : split){
            eventKeyCmb.addItem(s);
        }
    }
}