KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > mail > NewsCommands


1 /*
2  * NewsCommands.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: NewsCommands.java,v 1.2 2002/11/15 20:20:21 piso Exp $
6  *
7  * This program 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 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j.mail;
23
24 import org.armedbear.j.Buffer;
25 import org.armedbear.j.Editor;
26 import org.armedbear.j.InputDialog;
27
28 public final class NewsCommands
29 {
30     public static void news()
31     {
32         if (!Editor.checkExperimental())
33             return;
34         final Editor editor = Editor.currentEditor();
35         NntpSession session = NntpSession.getSession();
36         if (session != null) {
37             News news = new News(session);
38             editor.makeNext(news);
39             editor.activate(news);
40         }
41     }
42
43     public static void news(String JavaDoc host)
44     {
45         if (!Editor.checkExperimental())
46             return;
47         final Editor editor = Editor.currentEditor();
48         NntpSession session = NntpSession.getSession(host);
49         if (session != null) {
50             News news = new News(session);
51             editor.makeNext(news);
52             editor.activate(news);
53         }
54     }
55
56     public static void openGroupAtDot()
57     {
58         final Editor editor = Editor.currentEditor();
59         final Buffer buffer = editor.getBuffer();
60         if (buffer instanceof News && editor.getDot() != null) {
61             String JavaDoc groupName = editor.getDotLine().getText();
62             NntpSession session =
63                 NntpSession.getSession(((News)buffer).getHost());
64             NewsGroupSummary summary = new NewsGroupSummary(session, groupName);
65             editor.makeNext(summary);
66             editor.activate(summary);
67         }
68     }
69
70     public static void openGroup()
71     {
72         if (!Editor.checkExperimental())
73             return;
74         final Editor editor = Editor.currentEditor();
75         String JavaDoc groupName =
76             InputDialog.showInputDialog(editor, "Group:","Open Group", null);
77         if (groupName == null || groupName.length() == 0)
78             return;
79         editor.repaintNow();
80         NntpSession session = NntpSession.getSession();
81         NewsGroupSummary summary = new NewsGroupSummary(session, groupName);
82         editor.makeNext(summary);
83         editor.activate(summary);
84     }
85
86     public static void readArticle()
87     {
88         readArticle(false);
89     }
90
91     public static void readArticleOtherWindow()
92     {
93         readArticle(true);
94     }
95
96     private static void readArticle(boolean useOtherWindow)
97     {
98         final Editor editor = Editor.currentEditor();
99         final Buffer buffer = editor.getBuffer();
100         if (buffer instanceof NewsGroupSummary && editor.getDot() != null)
101             ((NewsGroupSummary)buffer).readArticle(editor,
102                 editor.getDotLine(), useOtherWindow);
103     }
104 }
105
Popular Tags