001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.core.gui.util;
018:
019: import java.awt.event.ActionEvent;
020: import java.awt.event.ActionListener;
021: import java.net.URL;
022:
023: import javax.swing.JMenuItem;
024: import javax.swing.JPopupMenu;
025:
026: import org.columba.core.desktop.ColumbaDesktop;
027:
028: public class URLController implements ActionListener {
029: private String address;
030: private URL link;
031:
032: //TODO (@author fdietz): i18n
033: public JPopupMenu createContactMenu(String contact) {
034: JPopupMenu popup = new JPopupMenu();
035: JMenuItem menuItem = new JMenuItem("Add Contact to Addressbook");
036: menuItem.addActionListener(this );
037: menuItem.setActionCommand("CONTACT");
038: popup.add(menuItem);
039: menuItem = new JMenuItem("Compose Message for " + contact);
040: menuItem.setActionCommand("COMPOSE");
041: menuItem.addActionListener(this );
042: popup.add(menuItem);
043:
044: return popup;
045: }
046:
047: //TODO (@author fdietz): i18n
048: public JPopupMenu createLinkMenu() {
049: JPopupMenu popup = new JPopupMenu();
050: JMenuItem menuItem = new JMenuItem("Open");
051: menuItem.addActionListener(this );
052: menuItem.setActionCommand("OPEN");
053: popup.add(menuItem);
054: menuItem = new JMenuItem("Open with...");
055: menuItem.setActionCommand("OPEN_WITH");
056: menuItem.addActionListener(this );
057: popup.add(menuItem);
058: popup.addSeparator();
059: menuItem = new JMenuItem("Open with internal browser");
060: menuItem.setActionCommand("OPEN_WITHINTERNALBROWSER");
061: menuItem.addActionListener(this );
062: popup.add(menuItem);
063:
064: return popup;
065: }
066:
067: public void setAddress(String s) {
068: this .address = s;
069: }
070:
071: public String getAddress() {
072: return address;
073: }
074:
075: public URL getLink() {
076: return link;
077: }
078:
079: public void setLink(URL u) {
080: this .link = u;
081: }
082:
083: /**
084: * Composer message for recipient
085: *
086: * @param address email address of recipient
087: */
088: public void compose(String address) {
089: //IServiceManager.getInstance().createService("");
090:
091: // TODO: implement this
092: }
093:
094: /**
095: * Add contact to addressbook.
096: *
097: * @param address new email address
098: */
099: public void contact(String address) {
100: // TODO: implement this
101: }
102:
103: public JPopupMenu createMenu(URL url) {
104: if (url.getProtocol().equalsIgnoreCase("mailto")) {
105: // found email address
106: setAddress(url.getFile());
107:
108: JPopupMenu menu = createContactMenu(url.getFile());
109:
110: return menu;
111: } else {
112: setLink(url);
113:
114: JPopupMenu menu = createLinkMenu();
115:
116: return menu;
117: }
118: }
119:
120: public void open(URL url) {
121: ColumbaDesktop.getInstance().browse(url);
122: }
123:
124: public void actionPerformed(ActionEvent e) {
125: String action = e.getActionCommand();
126:
127: if (action.equals("COMPOSE")) {
128: compose(getAddress());
129: } else if (action.equals("CONTACT")) {
130: contact(getAddress());
131: } else if (action.equals("OPEN")) {
132: open(getLink());
133: } else if (action.equals("OPEN_WITHINTERNALBROWSER")) {
134: //openWithBrowser(getLink());
135: }
136: }
137: }
|