ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
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
package com.vci.client.ui.swing.components.table.test;
 
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
 
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
 
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJDialog;
import com.vci.client.ui.swing.components.VCIJPanel;
 
public class SpecialCharChooseDialog extends VCIJDialog implements ActionListener{
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    private JTextComponent textField = null;
    public SpecialCharChooseDialog(Frame frame, boolean modal, JTextComponent textField){
        super(frame, modal);
        this.init(textField);
    }
    public SpecialCharChooseDialog(Dialog dialog, boolean modal, JTextComponent textField){
        super(dialog, modal);
        this.init(textField);
    }
    
    private void init(JTextComponent textField){
        this.textField = textField;
        setTitle("特殊字符选择");
        
        setLayout(new BorderLayout());
        setLocationRelativeTo(null);
        setSize(new Dimension(400, 300));
        
        VCIJPanel palBtn = new VCIJPanel();
        VCIJButton btn = new VCIJButton("选择");
        palBtn.add(btn);
        btn.addActionListener(this);
        add(palBtn, BorderLayout.SOUTH);
    }
 
    public void actionPerformed(ActionEvent e) {
        String newString = String.valueOf(new Random().nextDouble());
        try {
            javax.swing.text.Document doc = textField.getDocument();
            String text = textField.getText();
            int start = textField.getSelectionStart();
            int end = textField.getSelectionEnd();
            if(start != end){
                text = text.substring(0, start) + text.substring(end);
                textField.setText(text);
                textField.select(start, start);
            }
            doc.insertString(textField.getSelectionStart(), newString, null);
        } catch (BadLocationException e1) {
        }
        setDialogResult(DialogResult.OK);
        setVisible(false);
        dispose();
    }
}