01: package com.tagtraum.perf.gcviewer.action;
02:
03: import com.tagtraum.perf.gcviewer.GCViewer;
04: import com.tagtraum.perf.gcviewer.RecentURLsModel;
05: import com.tagtraum.perf.gcviewer.util.AutoCompletionComboBox;
06:
07: import javax.swing.*;
08: import java.awt.*;
09: import java.awt.event.ActionEvent;
10: import java.net.URL;
11: import java.net.MalformedURLException;
12:
13: /**
14: *
15: * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
16: * Date: May 20, 2005
17: * Time: 1:48:26 PM
18: *
19: */
20: public class OpenURL extends AbstractAction {
21: private GCViewer gcViewer;
22: private AutoCompletionComboBox autoCompletionComboBox;
23:
24: public OpenURL(final GCViewer gcViewer) {
25: this .gcViewer = gcViewer;
26: this .autoCompletionComboBox = new AutoCompletionComboBox();
27: putValue(NAME, GCViewer.localStrings
28: .getString("main_frame_menuitem_open_url"));
29: putValue(SHORT_DESCRIPTION, GCViewer.localStrings
30: .getString("main_frame_menuitem_hint_open_url"));
31: putValue(MNEMONIC_KEY, new Integer(GCViewer.localStrings
32: .getString("main_frame_menuitem_mnemonic_open_url")
33: .charAt(0)));
34: putValue(ACTION_COMMAND_KEY, "open_url");
35: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('U',
36: Event.CTRL_MASK));
37: putValue(SMALL_ICON, new ImageIcon(Toolkit.getDefaultToolkit()
38: .getImage(
39: gcViewer.getClass().getResource(
40: "images/open_url.png"))));
41: }
42:
43: public void setRecentURLsModel(final RecentURLsModel recentURLsModel) {
44: this .autoCompletionComboBox.setRecentURLsModel(recentURLsModel);
45: }
46:
47: public void actionPerformed(final ActionEvent e) {
48: final JPanel panel = new JPanel(new GridBagLayout());
49: final GridBagConstraints gridBagConstraints = new GridBagConstraints();
50: gridBagConstraints.anchor = GridBagConstraints.WEST;
51: panel.add(autoCompletionComboBox, gridBagConstraints);
52: gridBagConstraints.gridy = 1;
53:
54: final JCheckBox addURLCheckBox = new JCheckBox(
55: GCViewer.localStrings
56: .getString("urlopen_dialog_add_checkbox"),
57: false);
58: final boolean aDocumentIsAlreadyOpen = gcViewer
59: .getSelectedGCDocument() != null;
60: addURLCheckBox.setVisible(aDocumentIsAlreadyOpen);
61: addURLCheckBox.setEnabled(aDocumentIsAlreadyOpen);
62: addURLCheckBox.setToolTipText(GCViewer.localStrings
63: .getString("urlopen_dialog_hint_add_checkbox"));
64: panel.add(addURLCheckBox, gridBagConstraints);
65: final int result = JOptionPane
66: .showConfirmDialog(gcViewer, panel,
67: GCViewer.localStrings
68: .getString("urlopen_dialog_title"),
69: JOptionPane.OK_CANCEL_OPTION,
70: JOptionPane.PLAIN_MESSAGE);
71: if (JOptionPane.OK_OPTION == result) {
72: try {
73: final URL[] urls = new URL[] { new URL(
74: (String) autoCompletionComboBox
75: .getSelectedItem()) };
76: if (addURLCheckBox.isSelected()) {
77: gcViewer.add(urls);
78: } else {
79: gcViewer.open(urls);
80: }
81: } catch (MalformedURLException e1) {
82: // todo: show errormessage
83: e1.printStackTrace();
84: }
85: }
86: }
87:
88: }
|