3f0df21e57d5ec46266aa6c0e2bc0c37e1e79a04
[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.ShortcutKeyMaskExWrapper;
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             ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
140     selectAll.setText(MessageManager.getString("action.select_all"));
141     selectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
142             java.awt.event.KeyEvent.VK_A,
143             ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
144     selectAll.addActionListener(new ActionListener()
145     {
146       @Override
147       public void actionPerformed(ActionEvent e)
148       {
149         selectAll_actionPerformed(e);
150       }
151     });
152     jMenu1.setText(MessageManager.getString("action.file"));
153     save.setText(MessageManager.getString("action.save"));
154     save.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
155             java.awt.event.KeyEvent.VK_S,
156             ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
157     save.addActionListener(new ActionListener()
158     {
159       @Override
160       public void actionPerformed(ActionEvent e)
161       {
162         save_actionPerformed(e);
163       }
164     });
165     copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
166             java.awt.event.KeyEvent.VK_C,
167             ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
168
169     editMenubar.add(jMenu1);
170     editMenubar.add(editMenu);
171     textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 12));
172     textarea.addMouseListener(new java.awt.event.MouseAdapter()
173     {
174       @Override
175       public void mousePressed(MouseEvent e)
176       {
177         textarea_mousePressed(e);
178       }
179
180       @Override
181       public void mouseReleased(MouseEvent e)
182       {
183         textarea_mousePressed(e);
184       }
185     });
186     editMenu.setText(MessageManager.getString("action.edit"));
187     copyItem.setText(MessageManager.getString("action.copy"));
188     copyItem.addActionListener(new ActionListener()
189     {
190       @Override
191       public void actionPerformed(ActionEvent e)
192       {
193         copyItem_actionPerformed(e);
194       }
195     });
196     displaySource
197             .setText(MessageManager.getString("action.show_html_source"));
198     displaySource.setToolTipText(
199             MessageManager.getString("label.select_copy_raw_html"));
200     displaySource.addActionListener(new ActionListener()
201     {
202
203       @Override
204       public void actionPerformed(ActionEvent arg0)
205       {
206         toggleHtml_actionPerformed(arg0);
207       }
208     });
209     editMenu.add(displaySource);
210     this.getContentPane().setLayout(borderLayout2);
211     scrollPane.setBorder(null);
212     scrollPane.getViewport().add(textarea, null);
213     editMenu.add(selectAll);
214     editMenu.add(copyItem);
215     this.getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER);
216     inputButtonPanel.add(ok);
217     inputButtonPanel.add(cancel);
218     jMenu1.add(save);
219     jMenu1.add(close);
220   }
221
222   protected void toggleHtml_actionPerformed(ActionEvent arg0)
223   {
224     // TODO Auto-generated method stub
225
226   }
227
228   /**
229    * DOCUMENT ME!
230    * 
231    * @param e
232    *          DOCUMENT ME!
233    */
234   public void textarea_mousePressed(MouseEvent e)
235   {
236
237   }
238
239   /**
240    * DOCUMENT ME!
241    * 
242    * @param e
243    *          DOCUMENT ME!
244    */
245   public void copyItem_actionPerformed(ActionEvent e)
246   {
247   }
248
249   /**
250    * DOCUMENT ME!
251    * 
252    * @param e
253    *          DOCUMENT ME!
254    */
255   public void ok_actionPerformed(ActionEvent e)
256   {
257   }
258
259   /**
260    * DOCUMENT ME!
261    * 
262    * @param e
263    *          DOCUMENT ME!
264    */
265   public void cancel_actionPerformed(ActionEvent e)
266   {
267   }
268
269   public void selectAll_actionPerformed(ActionEvent e)
270   {
271     textarea.selectAll();
272   }
273
274   public void save_actionPerformed(ActionEvent e)
275   {
276
277   }
278
279   /**
280    * Adds the given stylesheet rule to the Html editor. However note that CSS
281    * support is limited.
282    * 
283    * @param rule
284    * @see javax.swing.text.html.CSS
285    */
286   public void addStylesheetRule(String rule)
287   {
288     EditorKit editorKit = textarea.getEditorKit();
289     if (editorKit != null)
290     {
291       ((HTMLEditorKit) editorKit).getStyleSheet().addRule(rule);
292     }
293   }
294 }