KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > slideshow > SlideShow


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
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 GNU
13  * Lesser 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 library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.slideshow;
20
21 import org.lucane.applications.slideshow.gui.FollowerWindow;
22 import org.lucane.applications.slideshow.gui.PreloadDialog;
23 import org.lucane.applications.slideshow.gui.StarterWindow;
24 import org.lucane.applications.slideshow.net.SlideClient;
25 import org.lucane.applications.slideshow.net.SlideServer;
26 import org.lucane.client.*;
27 import org.lucane.client.widgets.DialogBox;
28 import org.lucane.common.*;
29 import org.lucane.common.net.ObjectConnection;
30
31 import java.io.File JavaDoc;
32 import java.util.List JavaDoc;
33
34 import javax.swing.JFileChooser JavaDoc;
35
36 public class SlideShow
37 extends Plugin
38 {
39     //used for starter
40
private ConnectInfo[] friends;
41     private SlideServer slideServer;
42     private StarterWindow starterWindow;
43     
44     //used for follower
45
private SlideClient slideClient;
46     private FollowerWindow followerWindow;
47     
48     public SlideShow()
49     {
50     }
51     
52     public Plugin newInstance(ConnectInfo[] friends)
53     {
54         return new SlideShow(friends);
55     }
56     
57     public SlideShow(ConnectInfo[] friends)
58     {
59         this.friends = friends;
60     }
61     
62     public void load(ObjectConnection oc, ConnectInfo who, String JavaDoc data)
63     {
64         this.friends = new ConnectInfo[] {who};
65         this.slideClient = new SlideClient(this, oc);
66     }
67     
68     public void start()
69     {
70         //-- select directory
71
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
72         chooser.setFileFilter(new ImageFileFilter(true, tr("lbl.images")));
73         if(chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
74         {
75             exit();
76             return;
77         }
78         
79         PreloadDialog dialog = new PreloadDialog(this);
80         dialog.show();
81         
82         //-- read directory
83
File JavaDoc dir = chooser.getCurrentDirectory();
84         File JavaDoc[] files = dir.listFiles(new ImageFileFilter(false, tr("lbl.images")));
85         dialog.setMaxValue(files.length);
86         
87         //-- preload images
88
List JavaDoc list = FileUtils.sortFiles(files);
89         Object JavaDoc[] objects = FileUtils.preloadImages(this, list, dialog);
90             
91         //-- show window
92
starterWindow = new StarterWindow(this);
93         starterWindow.setImages(objects);
94         starterWindow.show();
95         dialog.dispose();
96         
97         slideServer = new SlideServer(this);
98         slideServer.sendInvitations(friends);
99     }
100     
101     public void follow()
102     {
103         String JavaDoc msg = tr("msg.followSlideShow").replaceAll("%1", friends[0].getName());
104         if(DialogBox.question(getTitle(), msg))
105         {
106             followerWindow = new FollowerWindow(this);
107             slideClient.acceptSlideShow();
108             followerWindow.show();
109         }
110         else
111             slideClient.rejectSlideShow();
112     }
113     
114     //--
115

116     public SlideServer getServer()
117     {
118         return slideServer;
119     }
120     
121     public StarterWindow getStarterWindow()
122     {
123         return starterWindow;
124     }
125     
126     public SlideClient getClient()
127     {
128         return slideClient;
129     }
130     
131     public FollowerWindow getFollowerWindow()
132     {
133         return followerWindow;
134     }
135 }
136
137
Popular Tags