View Javadoc

1   /*
2      $Id: JPasteButton.java,v 1.5 2004/04/15 16:34:53 mch Exp $
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           //botch bit
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  $Log: JPasteButton.java,v $
84  Revision 1.5  2004/04/15 16:34:53  mch
85  Tidied up, introduced stuff from datacenter ui
86  
87  Revision 1.1  2004/03/03 17:40:58  mch
88  Moved ui package
89  
90  Revision 1.1  2004/02/17 16:04:06  mch
91  New Desktop GUI
92  
93  Revision 1.2  2004/02/15 23:25:30  mch
94  Datacenter and MySpace desktop client GUIs
95  
96   */
97  
98