KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > util > URLController


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.core.gui.util;
18
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.ActionListener JavaDoc;
21 import java.net.URL JavaDoc;
22
23 import javax.swing.JMenuItem JavaDoc;
24 import javax.swing.JPopupMenu JavaDoc;
25
26 import org.columba.core.desktop.ColumbaDesktop;
27
28 public class URLController implements ActionListener JavaDoc {
29     private String JavaDoc address;
30     private URL JavaDoc link;
31
32     //TODO (@author fdietz): i18n
33
public JPopupMenu JavaDoc createContactMenu(String JavaDoc contact) {
34         JPopupMenu JavaDoc popup = new JPopupMenu JavaDoc();
35         JMenuItem JavaDoc menuItem = new JMenuItem JavaDoc("Add Contact to Addressbook");
36         menuItem.addActionListener(this);
37         menuItem.setActionCommand("CONTACT");
38         popup.add(menuItem);
39         menuItem = new JMenuItem JavaDoc("Compose Message for " + contact);
40         menuItem.setActionCommand("COMPOSE");
41         menuItem.addActionListener(this);
42         popup.add(menuItem);
43
44         return popup;
45     }
46
47     //TODO (@author fdietz): i18n
48
public JPopupMenu JavaDoc createLinkMenu() {
49         JPopupMenu JavaDoc popup = new JPopupMenu JavaDoc();
50         JMenuItem JavaDoc menuItem = new JMenuItem JavaDoc("Open");
51         menuItem.addActionListener(this);
52         menuItem.setActionCommand("OPEN");
53         popup.add(menuItem);
54         menuItem = new JMenuItem JavaDoc("Open with...");
55         menuItem.setActionCommand("OPEN_WITH");
56         menuItem.addActionListener(this);
57         popup.add(menuItem);
58         popup.addSeparator();
59         menuItem = new JMenuItem JavaDoc("Open with internal browser");
60         menuItem.setActionCommand("OPEN_WITHINTERNALBROWSER");
61         menuItem.addActionListener(this);
62         popup.add(menuItem);
63
64         return popup;
65     }
66
67     public void setAddress(String JavaDoc s) {
68         this.address = s;
69     }
70
71     public String JavaDoc getAddress() {
72         return address;
73     }
74
75     public URL JavaDoc getLink() {
76         return link;
77     }
78
79     public void setLink(URL JavaDoc u) {
80         this.link = u;
81     }
82
83     /**
84      * Composer message for recipient
85      *
86      * @param address email address of recipient
87      */

88     public void compose(String JavaDoc address) {
89         //IServiceManager.getInstance().createService("");
90

91        // TODO: implement this
92
}
93
94     /**
95      * Add contact to addressbook.
96      *
97      * @param address new email address
98      */

99     public void contact(String JavaDoc address) {
100         // TODO: implement this
101
}
102
103     public JPopupMenu JavaDoc createMenu(URL JavaDoc url) {
104         if (url.getProtocol().equalsIgnoreCase("mailto")) {
105             // found email address
106
setAddress(url.getFile());
107
108             JPopupMenu JavaDoc menu = createContactMenu(url.getFile());
109
110             return menu;
111         } else {
112             setLink(url);
113
114             JPopupMenu JavaDoc menu = createLinkMenu();
115
116             return menu;
117         }
118     }
119
120     public void open(URL JavaDoc url) {
121         ColumbaDesktop.getInstance().browse(url);
122     }
123
124     public void actionPerformed(ActionEvent JavaDoc e) {
125         String JavaDoc 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 }
138
Popular Tags