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); } } }