121917e0381e10b474557ace67ac5711586ec631
[jalview.git] / src / jalview / jbgui / GCutAndPasteHtmlTransfer.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.jbgui;
22
23 import jalview.gui.JvSwingUtils;
24 import jalview.util.MessageManager;
25 import jalview.util.Platform;
26
27 import java.awt.BorderLayout;
28 import java.awt.Font;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.MouseEvent;
32
33 import javax.swing.JButton;
34 import javax.swing.JCheckBoxMenuItem;
35 import javax.swing.JEditorPane;
36 import javax.swing.JInternalFrame;
37 import javax.swing.JMenu;
38 import javax.swing.JMenuBar;
39 import javax.swing.JMenuItem;
40 import javax.swing.JPanel;
41 import javax.swing.JScrollPane;
42 import javax.swing.text.EditorKit;
43 import javax.swing.text.html.HTMLEditorKit;
44
45 /**
46  * DOCUMENT ME!
47  * 
48  * @author $author$
49  * @version $Revision$
50  */
51 public class GCutAndPasteHtmlTransfer extends JInternalFrame
52 {
53   protected JEditorPane textarea = new JEditorPane("text/html", "");
54
55   protected JScrollPane scrollPane = new JScrollPane();
56
57   BorderLayout borderLayout1 = new BorderLayout();
58
59   JMenuBar editMenubar = new JMenuBar();
60
61   JMenu editMenu = new JMenu();
62
63   JMenuItem copyItem = new JMenuItem();
64
65   protected JCheckBoxMenuItem displaySource = new JCheckBoxMenuItem();
66
67   BorderLayout borderLayout2 = new BorderLayout();
68
69   protected JPanel inputButtonPanel = new JPanel();
70
71   protected JButton ok = new JButton();
72
73   JButton cancel = new JButton();
74
75   JMenuItem close = new JMenuItem();
76
77   JMenuItem selectAll = new JMenuItem();
78
79   JMenu jMenu1 = new JMenu();
80
81   JMenuItem save = new JMenuItem();
82
83   /**
84    * Creates a new GCutAndPasteTransfer object.
85    */
86   public GCutAndPasteHtmlTransfer()
87   {
88     try
89     {
90       textarea.setEditorKit(new HTMLEditorKit());
91       setJMenuBar(editMenubar);
92       jbInit();
93     } catch (Exception e)
94     {
95       e.printStackTrace();
96     }
97   }
98
99   /**
100    * DOCUMENT ME!
101    * 
102    * @throws Exception
103    *           DOCUMENT ME!
104    */
105   private void jbInit() throws Exception
106   {
107     scrollPane.setBorder(null);
108     ok.setFont(JvSwingUtils.getLabelFont());
109     ok.setText(MessageManager.getString("label.new_window"));
110     ok.addActionListener(new ActionListener()
111     {
112       @Override
113       public void actionPerformed(ActionEvent e)
114       {
115         ok_actionPerformed(e);
116       }
117     });
118     cancel.setText(MessageManager.getString("action.close"));
119     cancel.addActionListener(new ActionListener()
120     {
121       @Override
122       public void actionPerformed(ActionEvent e)
123       {
124         cancel_actionPerformed(e);
125       }
126     });
127     textarea.setBorder(null);
128     close.setText(MessageManager.getString("action.close"));
129     close.addActionListener(new ActionListener()
130     {
131       @Override
132       public void actionPerformed(ActionEvent e)
133       {
134         cancel_actionPerformed(e);
135       }
136     });
137     close.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
138             java.awt.event.KeyEvent.VK_W,
139             Platform.SHORTCUT_KEY_MASK,
140             false));
141     selectAll.setText(MessageManager.getString("action.select_all"));
142     selectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
143             java.awt.event.KeyEvent.VK_A,
144             Platform.SHORTCUT_KEY_MASK,
145             false));
146     selectAll.addActionListener(new ActionListener()
147     {
148       @Override
149       public void actionPerformed(ActionEvent e)
150       {
151         selectAll_actionPerformed(e);
152       }
153     });
154     jMenu1.setText(MessageManager.getString("action.file"));
155     save.setText(MessageManager.getString("action.save"));
156     save.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
157             java.awt.event.KeyEvent.VK_S,
158             Platform.SHORTCUT_KEY_MASK,
159             false));
160     save.addActionListener(new ActionListener()
161     {
162       @Override
163       public void actionPerformed(ActionEvent e)
164       {
165         save_actionPerformed(e);
166       }
167     });
168     copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
169             java.awt.event.KeyEvent.VK_C,
170             Platform.SHORTCUT_KEY_MASK,
171             false));
172
173     editMenubar.add(jMenu1);
174     editMenubar.add(editMenu);
175     textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 12));
176     textarea.addMouseListener(new java.awt.event.MouseAdapter()
177     {
178       @Override
179       public void mousePressed(MouseEvent e)
180       {
181         textarea_mousePressed(e);
182       }
183
184       @Override
185       public void mouseReleased(MouseEvent e)
186       {
187         textarea_mousePressed(e);
188       }
189     });
190     editMenu.setText(MessageManager.getString("action.edit"));
191     copyItem.setText(MessageManager.getString("action.copy"));
192     copyItem.addActionListener(new ActionListener()
193     {
194       @Override
195       public void actionPerformed(ActionEvent e)
196       {
197         copyItem_actionPerformed(e);
198       }
199     });
200     displaySource
201             .setText(MessageManager.getString("action.show_html_source"));
202     displaySource.setToolTipText(
203             MessageManager.getString("label.select_copy_raw_html"));
204     displaySource.addActionListener(new ActionListener()
205     {
206
207       @Override
208       public void actionPerformed(ActionEvent arg0)
209       {
210         toggleHtml_actionPerformed(arg0);
211       }
212     });
213     editMenu.add(displaySource);
214     this.getContentPane().setLayout(borderLayout2);
215     scrollPane.setBorder(null);
216     scrollPane.getViewport().add(textarea, null);
217     editMenu.add(selectAll);
218     editMenu.add(copyItem);
219     this.getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER);
220     inputButtonPanel.add(ok);
221     inputButtonPanel.add(cancel);
222     jMenu1.add(save);
223     jMenu1.add(close);
224   }
225
226   protected void toggleHtml_actionPerformed(ActionEvent arg0)
227   {
228     // TODO Auto-generated method stub
229
230   }
231
232   /**
233    * DOCUMENT ME!
234    * 
235    * @param e
236    *          DOCUMENT ME!
237    */
238   public void textarea_mousePressed(MouseEvent e)
239   {
240
241   }
242
243   /**
244    * DOCUMENT ME!
245    * 
246    * @param e
247    *          DOCUMENT ME!
248    */
249   public void copyItem_actionPerformed(ActionEvent e)
250   {
251   }
252
253   /**
254    * DOCUMENT ME!
255    * 
256    * @param e
257    *          DOCUMENT ME!
258    */
259   public void ok_actionPerformed(ActionEvent e)
260   {
261   }
262
263   /**
264    * DOCUMENT ME!
265    * 
266    * @param e
267    *          DOCUMENT ME!
268    */
269   public void cancel_actionPerformed(ActionEvent e)
270   {
271   }
272
273   public void selectAll_actionPerformed(ActionEvent e)
274   {
275     textarea.selectAll();
276   }
277
278   public void save_actionPerformed(ActionEvent e)
279   {
280
281   }
282
283   /**
284    * Adds the given stylesheet rule to the Html editor. However note that CSS
285    * support is limited.
286    * 
287    * @param rule
288    * @see javax.swing.text.html.CSS
289    */
290   public void addStylesheetRule(String rule)
291   {
292     EditorKit editorKit = textarea.getEditorKit();
293     if (editorKit != null)
294     {
295       ((HTMLEditorKit) editorKit).getStyleSheet().addRule(rule);
296     }
297   }
298 }