2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.jbgui;
23 import jalview.gui.JvSwingUtils;
24 import jalview.util.MessageManager;
25 import jalview.util.Platform;
27 import java.awt.BorderLayout;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.MouseEvent;
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;
51 public class GCutAndPasteHtmlTransfer extends JInternalFrame
53 protected JEditorPane textarea = new JEditorPane("text/html", "");
55 protected JScrollPane scrollPane = new JScrollPane();
57 BorderLayout borderLayout1 = new BorderLayout();
59 JMenuBar editMenubar = new JMenuBar();
61 JMenu editMenu = new JMenu();
63 JMenuItem copyItem = new JMenuItem();
65 protected JCheckBoxMenuItem displaySource = new JCheckBoxMenuItem();
67 BorderLayout borderLayout2 = new BorderLayout();
69 protected JPanel inputButtonPanel = new JPanel();
71 protected JButton ok = new JButton();
73 JButton cancel = new JButton();
75 JMenuItem close = new JMenuItem();
77 JMenuItem selectAll = new JMenuItem();
79 JMenu jMenu1 = new JMenu();
81 JMenuItem save = new JMenuItem();
84 * Creates a new GCutAndPasteTransfer object.
86 public GCutAndPasteHtmlTransfer()
90 textarea.setEditorKit(new HTMLEditorKit());
91 setJMenuBar(editMenubar);
105 private void jbInit() throws Exception
107 scrollPane.setBorder(null);
108 ok.setFont(JvSwingUtils.getLabelFont());
109 ok.setText(MessageManager.getString("label.new_window"));
110 ok.addActionListener(new ActionListener()
113 public void actionPerformed(ActionEvent e)
115 ok_actionPerformed(e);
118 cancel.setText(MessageManager.getString("action.close"));
119 cancel.addActionListener(new ActionListener()
122 public void actionPerformed(ActionEvent e)
124 cancel_actionPerformed(e);
127 textarea.setBorder(null);
128 close.setText(MessageManager.getString("action.close"));
129 close.addActionListener(new ActionListener()
132 public void actionPerformed(ActionEvent e)
134 cancel_actionPerformed(e);
137 close.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
138 java.awt.event.KeyEvent.VK_W,
139 Platform.SHORTCUT_KEY_MASK,
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,
146 selectAll.addActionListener(new ActionListener()
149 public void actionPerformed(ActionEvent e)
151 selectAll_actionPerformed(e);
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,
160 save.addActionListener(new ActionListener()
163 public void actionPerformed(ActionEvent e)
165 save_actionPerformed(e);
168 copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
169 java.awt.event.KeyEvent.VK_C,
170 Platform.SHORTCUT_KEY_MASK,
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()
179 public void mousePressed(MouseEvent e)
181 textarea_mousePressed(e);
185 public void mouseReleased(MouseEvent e)
187 textarea_mousePressed(e);
190 editMenu.setText(MessageManager.getString("action.edit"));
191 copyItem.setText(MessageManager.getString("action.copy"));
192 copyItem.addActionListener(new ActionListener()
195 public void actionPerformed(ActionEvent e)
197 copyItem_actionPerformed(e);
201 .setText(MessageManager.getString("action.show_html_source"));
202 displaySource.setToolTipText(
203 MessageManager.getString("label.select_copy_raw_html"));
204 displaySource.addActionListener(new ActionListener()
208 public void actionPerformed(ActionEvent arg0)
210 toggleHtml_actionPerformed(arg0);
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);
226 protected void toggleHtml_actionPerformed(ActionEvent arg0)
228 // TODO Auto-generated method stub
238 public void textarea_mousePressed(MouseEvent e)
249 public void copyItem_actionPerformed(ActionEvent e)
259 public void ok_actionPerformed(ActionEvent e)
269 public void cancel_actionPerformed(ActionEvent e)
273 public void selectAll_actionPerformed(ActionEvent e)
275 textarea.selectAll();
278 public void save_actionPerformed(ActionEvent e)
284 * Adds the given stylesheet rule to the Html editor. However note that CSS
285 * support is limited.
288 * @see javax.swing.text.html.CSS
290 public void addStylesheetRule(String rule)
292 EditorKit editorKit = textarea.getEditorKit();
293 if (editorKit != null)
295 ((HTMLEditorKit) editorKit).getStyleSheet().addRule(rule);