1
2
3
4
5
6 package org.astrogrid.ui;
7
8 import java.awt.Dimension;
9 import java.awt.datatransfer.Clipboard;
10 import java.awt.event.ActionListener;
11 import javax.swing.JButton;
12 import javax.swing.JComboBox;
13 import javax.swing.JTextField;
14
15 /***
16 * A button that pastes whatever is on the clipboard into the related
17 * text field
18 *
19 * @author M Hill
20 */
21
22
23 public class JPasteButton extends JButton implements ActionListener
24 {
25 JTextField textField = null;
26 JHistoryComboBox comboBox = null;
27
28 private JPasteButton(int defHeight)
29 {
30 super(IconFactory.getIcon("Paste"));
31
32 this.setToolTipText("Replaces text with clipboard contents");
33 this.addActionListener(this);
34
35 if (getIcon()==null)
36 {
37 setText("Paste");
38 }
39 else
40 {
41 setBorder(null);
42 setPreferredSize(new Dimension(defHeight, defHeight));
43 }
44 }
45
46 public JPasteButton(JTextField aField)
47 {
48 this(aField.getPreferredSize().height);
49
50 this.textField = aField;
51 }
52
53 public JPasteButton(JHistoryComboBox aField)
54 {
55 this(aField.getPreferredSize().height);
56
57 this.comboBox = aField;
58 }
59
60 public void actionPerformed(java.awt.event.ActionEvent e)
61 {
62 if (textField != null)
63 {
64 textField.selectAll();
65 textField.paste();
66 }
67
68 if (comboBox != null)
69 {
70
71 JTextField temp = new JTextField();
72 temp.selectAll();
73 temp.paste();
74
75 comboBox.setItem(temp.getText());
76 }
77 }
78
79
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98