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;
26 import java.awt.BorderLayout;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.MouseEvent;
32 import javax.swing.JButton;
33 import javax.swing.JCheckBoxMenuItem;
34 import javax.swing.JEditorPane;
35 import javax.swing.JInternalFrame;
36 import javax.swing.JMenu;
37 import javax.swing.JMenuBar;
38 import javax.swing.JMenuItem;
39 import javax.swing.JPanel;
40 import javax.swing.JScrollPane;
41 import javax.swing.text.EditorKit;
42 import javax.swing.text.html.HTMLEditorKit;
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
106 scrollPane.setBorder(null);
107 ok.setFont(JvSwingUtils.getLabelFont());
108 ok.setText(MessageManager.getString("label.new_window"));
109 ok.addActionListener(new ActionListener()
112 public void actionPerformed(ActionEvent e)
114 ok_actionPerformed(e);
117 cancel.setText(MessageManager.getString("action.close"));
118 cancel.addActionListener(new ActionListener()
121 public void actionPerformed(ActionEvent e)
123 cancel_actionPerformed(e);
126 textarea.setBorder(null);
127 close.setText(MessageManager.getString("action.close"));
128 close.addActionListener(new ActionListener()
131 public void actionPerformed(ActionEvent e)
133 cancel_actionPerformed(e);
136 close.setAccelerator(
137 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W,
138 jalview.util.ShortcutKeyMaskExWrapper
139 .getMenuShortcutKeyMaskEx(),
141 selectAll.setText(MessageManager.getString("action.select_all"));
144 javax.swing.KeyStroke
145 .getKeyStroke(java.awt.event.KeyEvent.VK_A,
146 jalview.util.ShortcutKeyMaskExWrapper
147 .getMenuShortcutKeyMaskEx(),
149 selectAll.addActionListener(new ActionListener()
152 public void actionPerformed(ActionEvent e)
154 selectAll_actionPerformed(e);
157 jMenu1.setText(MessageManager.getString("action.file"));
158 save.setText(MessageManager.getString("action.save"));
160 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
161 jalview.util.ShortcutKeyMaskExWrapper
162 .getMenuShortcutKeyMaskEx(),
164 save.addActionListener(new ActionListener()
167 public void actionPerformed(ActionEvent e)
169 save_actionPerformed(e);
172 copyItem.setAccelerator(
173 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C,
174 jalview.util.ShortcutKeyMaskExWrapper
175 .getMenuShortcutKeyMaskEx(),
178 editMenubar.add(jMenu1);
179 editMenubar.add(editMenu);
180 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 12));
181 textarea.addMouseListener(new java.awt.event.MouseAdapter()
184 public void mousePressed(MouseEvent e)
186 textarea_mousePressed(e);
190 public void mouseReleased(MouseEvent e)
192 textarea_mousePressed(e);
195 editMenu.setText(MessageManager.getString("action.edit"));
196 copyItem.setText(MessageManager.getString("action.copy"));
197 copyItem.addActionListener(new ActionListener()
200 public void actionPerformed(ActionEvent e)
202 copyItem_actionPerformed(e);
206 .setText(MessageManager.getString("action.show_html_source"));
207 displaySource.setToolTipText(
208 MessageManager.getString("label.select_copy_raw_html"));
209 displaySource.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent arg0)
215 toggleHtml_actionPerformed(arg0);
218 editMenu.add(displaySource);
219 this.getContentPane().setLayout(borderLayout2);
220 scrollPane.setBorder(null);
221 scrollPane.getViewport().add(textarea, null);
222 editMenu.add(selectAll);
223 editMenu.add(copyItem);
224 this.getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER);
225 inputButtonPanel.add(ok);
226 inputButtonPanel.add(cancel);
231 protected void toggleHtml_actionPerformed(ActionEvent arg0)
233 // TODO Auto-generated method stub
243 public void textarea_mousePressed(MouseEvent e)
254 public void copyItem_actionPerformed(ActionEvent e)
264 public void ok_actionPerformed(ActionEvent e)
274 public void cancel_actionPerformed(ActionEvent e)
278 public void selectAll_actionPerformed(ActionEvent e)
280 textarea.selectAll();
283 public void save_actionPerformed(ActionEvent e)
289 * Adds the given stylesheet rule to the Html editor. However note that CSS
290 * support is limited.
293 * @see javax.swing.text.html.CSS
295 public void addStylesheetRule(String rule)
297 EditorKit editorKit = textarea.getEditorKit();
298 if (editorKit != null)
300 ((HTMLEditorKit) editorKit).getStyleSheet().addRule(rule);