Source code: plugins/YabbifierService/YabbMsg.java
1 /*
2 This file is part of DeXter - Java Internet Communication Solution
3 Copyright (c) 2002 Tobias Riemer
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 /*
21 * YabbMsg.java
22 *
23 * Created on 19. September 2002, 16:35
24 */
25
26 package plugins.YabbifierService;
27
28 import dexter.core.DefaultEntry;
29 import dexter.core.Dexter;
30 import java.io.*;
31 import javax.swing.JMenu;
32 import javax.swing.JPopupMenu;
33 import javax.swing.JMenuItem;
34 /**
35 *
36 * @author Tobias Riemer
37 */
38 public class YabbMsg extends DefaultEntry {
39
40 String url;
41 String msg;
42 String browser;
43 boolean read = false;
44 //javax.swing.ImageIcon onlineIcon = new javax.swing.ImageIcon(getClass().getResource("/dexter/images/green.gif"));
45 /** Creates a new instance of YabbMsg */
46 public YabbMsg(String msg, String url, String browser) {
47 this.url = url;
48 this.msg = msg;
49 this.browser = browser;
50 JMenuItem menuItem = new JMenuItem("Mark as Read");
51
52 menuItem.addActionListener(new java.awt.event.ActionListener() {
53 public void actionPerformed(java.awt.event.ActionEvent evt) {
54 read = true;
55 }
56 });
57 popup = new JPopupMenu();
58 popup.add(menuItem);
59 }
60
61 public String getToolTipText() {
62 return url;
63 }
64
65 public void fireSelected2() {
66 read = true;
67 try {
68 BufferedWriter out = new BufferedWriter(new FileWriter(Dexter.getInstance().getHomeDir() + "yabb.html"));
69 String str;
70 out.write("<html> <head> <meta http-equiv=\"refresh\" content=\"0; URL=" + url + "\"> </head> </html>");
71 out.flush();
72 out.close();
73 } catch (IOException e) {
74 }
75 try {
76 String line;
77 Process p = Runtime.getRuntime().exec(Dexter.getInstance().getHomeDir() + "yabb.bat");
78 BufferedReader input =
79 new BufferedReader
80 (new InputStreamReader(p.getInputStream()));
81 while ((line = input.readLine()) != null) {
82 System.out.println(line);
83 }
84 input.close();
85 }
86 catch (Exception err) {
87 err.printStackTrace();
88 }
89
90 }
91
92 public void fireSelected() {
93 try {
94 Process p = Runtime.getRuntime().exec(browser + " " + url);
95 read = true;
96 } catch (Exception err) {
97 err.printStackTrace();
98 }
99 }
100
101
102
103 public void firePropertiesChanged() {
104 }
105
106 public String getMsg() {
107 return msg;
108 }
109
110 public String getUrl() {
111 return url;
112 }
113
114 public String toString() {
115 return msg ;
116 }
117
118 public String write() {
119 return msg + "::" + url + "::" + read;
120 }
121
122 public void read(String str) {
123 int index = str.indexOf("::");
124 if (index >= 0) {
125 msg = str.substring(0,index);
126 int index2 = str.indexOf("::", index + 2);
127 if (index2 >= 0) {
128 url = str.substring(index+2,index2);
129 read = Boolean.valueOf(str.substring(index2+2)).booleanValue();
130 } else url = str.substring(index+2);
131
132
133 }
134 else
135 msg = str;
136 }
137
138
139 public javax.swing.ImageIcon getIcon() {
140 return null;
141 }
142
143 public boolean isRead() {
144 return read;
145 }
146
147
148 public java.awt.Font getFont() {
149 javax.swing.JLabel l = new javax.swing.JLabel();
150 if (read) {
151 return l.getFont();
152 }
153 return l.getFont().deriveFont(java.awt.Font.BOLD);
154 }
155
156 /** Setter for property read.
157 * @param read New value of property read.
158 */
159 public void setRead(boolean read) {
160 this.read = read;
161 }
162
163 }