KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > slideshow > gui > StarterWindow


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.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Dimension JavaDoc;
23 import java.awt.Image JavaDoc;
24 import java.awt.event.WindowEvent JavaDoc;
25 import java.awt.event.WindowListener JavaDoc;
26
27 import javax.swing.JLabel JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JProgressBar JavaDoc;
31 import javax.swing.JScrollPane JavaDoc;
32 import javax.swing.JSplitPane JavaDoc;
33 import javax.swing.event.ListSelectionEvent JavaDoc;
34 import javax.swing.event.ListSelectionListener JavaDoc;
35
36 import org.lucane.applications.slideshow.SlideShow;
37 import org.lucane.client.widgets.ManagedWindow;
38
39 public class StarterWindow extends ManagedWindow
40 implements ListSelectionListener JavaDoc, WindowListener JavaDoc
41 {
42     private SlideShow plugin;
43     private JList JavaDoc thumbnails;
44     private JList JavaDoc users;
45     private ImageComponent image;
46     private JSplitPane JavaDoc split;
47     private JLabel JavaDoc statusLabel;
48     private JProgressBar JavaDoc statusBar;
49     
50     public StarterWindow(SlideShow owner)
51     {
52         super(owner, owner.getTitle());
53         setName("starter");
54         setExitPluginOnClose(true);
55         addWindowListener(this);
56         
57         this.plugin = owner;
58         
59         
60         thumbnails = new JList JavaDoc();
61         thumbnails.setCellRenderer(new ImageRenderer());
62         thumbnails.addListSelectionListener(this);
63         getContentPane().add(new JScrollPane JavaDoc(thumbnails), BorderLayout.WEST);
64         
65         image = new ImageComponent();
66         users = new JList JavaDoc();
67         split = new JSplitPane JavaDoc(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane JavaDoc(image), new JScrollPane JavaDoc(users));
68         split.setName("startersplit");
69         getContentPane().add(split, BorderLayout.CENTER);
70         manageWidget(split);
71         
72         statusLabel = new JLabel JavaDoc();
73         statusLabel.setHorizontalAlignment(JLabel.RIGHT);
74         statusBar = new JProgressBar JavaDoc();
75         JPanel JavaDoc status = new JPanel JavaDoc(new BorderLayout JavaDoc());
76         status.add(statusLabel, BorderLayout.CENTER);
77         status.add(statusBar, BorderLayout.EAST);
78         getContentPane().add(status, BorderLayout.SOUTH);
79         
80
81         split.setDividerLocation(300);
82         setPreferredSize(new Dimension JavaDoc(600, 400));
83     }
84     
85     public void setImages(Object JavaDoc[] images)
86     {
87         thumbnails.setListData(images);
88     }
89     
90     public void setUsers(Object JavaDoc[] names)
91     {
92         users.setListData(names);
93
94         //remove 1 because we don't sent to ourself
95
//double because there are 2 event notifications : start & end
96
statusBar.setMaximum((names.length-1)*2);
97     }
98     
99     public void initStatus(String JavaDoc msg)
100     {
101         statusLabel.setText(msg);
102         statusBar.setValue(0);
103     }
104     
105     public void doProgress()
106     {
107         statusBar.setValue(statusBar.getValue()+1);
108         if(statusBar.getValue() == statusBar.getMaximum())
109             initStatus("");
110     }
111     
112     //-- listeners
113

114     public void valueChanged(ListSelectionEvent JavaDoc lse)
115     {
116         if(thumbnails.getSelectedIndex() >= 0)
117         {
118             Image JavaDoc picture = (Image JavaDoc)thumbnails.getSelectedValue();
119             if(image.getImage() != picture)
120             {
121                 image.setImage(picture);
122                 image.repaint();
123                 plugin.getServer().sendImage(picture);
124             }
125         }
126     }
127
128     public void windowActivated(WindowEvent JavaDoc e) {}
129     public void windowClosed(WindowEvent JavaDoc e) {}
130     public void windowDeactivated(WindowEvent JavaDoc e) {}
131     public void windowDeiconified(WindowEvent JavaDoc e) {}
132     public void windowIconified(WindowEvent JavaDoc e) {}
133     public void windowOpened(WindowEvent JavaDoc e) {}
134     public void windowClosing(WindowEvent JavaDoc e)
135     {
136         plugin.getServer().disconnect();
137     }
138 }
Popular Tags