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 java.awt.BorderLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.MouseEvent;
29 import javax.swing.JButton;
30 import javax.swing.JCheckBoxMenuItem;
31 import javax.swing.JEditorPane;
32 import javax.swing.JInternalFrame;
33 import javax.swing.JMenu;
34 import javax.swing.JMenuBar;
35 import javax.swing.JMenuItem;
36 import javax.swing.JPanel;
37 import javax.swing.JScrollPane;
38 import javax.swing.text.EditorKit;
39 import javax.swing.text.html.HTMLEditorKit;
41 import jalview.gui.JvSwingUtils;
42 import jalview.util.MessageManager;
50 public class GCutAndPasteHtmlTransfer extends JInternalFrame
52 protected JEditorPane textarea = new JEditorPane("text/html", "");
54 protected JScrollPane scrollPane = new JScrollPane();
56 BorderLayout borderLayout1 = new BorderLayout();
58 JMenuBar editMenubar = new JMenuBar();
60 JMenu editMenu = new JMenu();
62 JMenuItem copyItem = new JMenuItem();
64 protected JCheckBoxMenuItem displaySource = new JCheckBoxMenuItem();
66 BorderLayout borderLayout2 = new BorderLayout();
68 protected JPanel inputButtonPanel = new JPanel();
70 protected JButton ok = new JButton();
72 JButton cancel = new JButton();
74 JMenuItem close = new JMenuItem();
76 JMenuItem selectAll = new JMenuItem();
78 JMenu jMenu1 = new JMenu();
80 JMenuItem save = new JMenuItem();
83 * Creates a new GCutAndPasteTransfer object.
85 public GCutAndPasteHtmlTransfer()
89 textarea.setEditorKit(new HTMLEditorKit());
90 setJMenuBar(editMenubar);
104 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(
138 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W,
139 jalview.util.ShortcutKeyMaskExWrapper
140 .getMenuShortcutKeyMaskEx(),
142 selectAll.setText(MessageManager.getString("action.select_all"));
145 javax.swing.KeyStroke
146 .getKeyStroke(java.awt.event.KeyEvent.VK_A,
147 jalview.util.ShortcutKeyMaskExWrapper
148 .getMenuShortcutKeyMaskEx(),
150 selectAll.addActionListener(new ActionListener()
153 public void actionPerformed(ActionEvent e)
155 selectAll_actionPerformed(e);
158 jMenu1.setText(MessageManager.getString("action.file"));
159 save.setText(MessageManager.getString("action.save"));
161 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
162 jalview.util.ShortcutKeyMaskExWrapper
163 .getMenuShortcutKeyMaskEx(),
165 save.addActionListener(new ActionListener()
168 public void actionPerformed(ActionEvent e)
170 save_actionPerformed(e);
173 copyItem.setAccelerator(
174 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C,
175 jalview.util.ShortcutKeyMaskExWrapper
176 .getMenuShortcutKeyMaskEx(),
179 editMenubar.add(jMenu1);
180 editMenubar.add(editMenu);
181 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 12));
182 textarea.addMouseListener(new java.awt.event.MouseAdapter()
185 public void mousePressed(MouseEvent e)
187 textarea_mousePressed(e);
191 public void mouseReleased(MouseEvent e)
193 textarea_mousePressed(e);
196 editMenu.setText(MessageManager.getString("action.edit"));
197 copyItem.setText(MessageManager.getString("action.copy"));
198 copyItem.addActionListener(new ActionListener()
201 public void actionPerformed(ActionEvent e)
203 copyItem_actionPerformed(e);
207 .setText(MessageManager.getString("action.show_html_source"));
208 displaySource.setToolTipText(
209 MessageManager.getString("label.select_copy_raw_html"));
210 displaySource.addActionListener(new ActionListener()
214 public void actionPerformed(ActionEvent arg0)
216 toggleHtml_actionPerformed(arg0);
219 editMenu.add(displaySource);
220 this.getContentPane().setLayout(borderLayout2);
221 scrollPane.setBorder(null);
222 scrollPane.getViewport().add(textarea, null);
223 editMenu.add(selectAll);
224 editMenu.add(copyItem);
225 this.getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER);
226 inputButtonPanel.add(ok);
227 inputButtonPanel.add(cancel);
232 protected void toggleHtml_actionPerformed(ActionEvent arg0)
234 // TODO Auto-generated method stub
244 public void textarea_mousePressed(MouseEvent e)
255 public void copyItem_actionPerformed(ActionEvent e)
265 public void ok_actionPerformed(ActionEvent e)
275 public void cancel_actionPerformed(ActionEvent e)
279 public void selectAll_actionPerformed(ActionEvent e)
281 textarea.selectAll();
284 public void save_actionPerformed(ActionEvent e)
290 * Adds the given stylesheet rule to the Html editor. However note that CSS
291 * support is limited.
294 * @see javax.swing.text.html.CSS
296 public void addStylesheetRule(String rule)
298 EditorKit editorKit = textarea.getEditorKit();
299 if (editorKit != null)
301 ((HTMLEditorKit) editorKit).getStyleSheet().addRule(rule);