1 /*
2  * @(#)AboutBox.java - about box of Project-X, with terms of condition and credits
3  *
4  * Copyright (c) 2004-2005 by pstorch, All Rights Reserved.
5  *
6  * This file is part of ProjectX, a free Java based demux utility.
7  * By the authors, ProjectX is intended for educational purposes only,
8  * as a non-commercial test project.
9  *
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  *
25  */
26 
27 package net.sourceforge.dvb.projectx.gui;
28 
29 import java.awt.BorderLayout;
30 import java.awt.Color;
31 import java.awt.Frame;
32 import java.awt.Point;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.WindowAdapter;
36 import java.awt.event.WindowEvent;
37 
38 import javax.swing.BorderFactory;
39 import javax.swing.BoxLayout;
40 import javax.swing.JButton;
41 import javax.swing.JDialog;
42 import javax.swing.JLabel;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JTextArea;
46 import javax.swing.JViewport;
47 
48 import net.sourceforge.dvb.projectx.common.Resource;
49 import net.sourceforge.dvb.projectx.common.Common;
50 
51 import net.sourceforge.dvb.projectx.gui.CommonGui;
52 
53 
54 /**
55  * AboutBox for Project-X GUI.
56  *
57  * @author Peter Storch
58  */
59 public class AboutBox extends JDialog {
60 
61 	/** Background Color */
62 	private static final Color BACKGROUND_COLOR = new Color(224,224,224);
63 
64 	/**
65 	 * Constructor of AboutBox.
66 	 *
67 	 * @param frame
68 	 */
AboutBox(Frame frame)69 	public AboutBox(Frame frame)
70 	{
71 		super(frame, true);
72 		setTitle(Resource.getString("about.title"));
73 
74 		JPanel container = new JPanel();
75 		container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
76 		container.setBorder( BorderFactory.createEmptyBorder(10,10,10,10));
77 		container.setBackground(BACKGROUND_COLOR);
78 
79 		JLabel logo = new JLabel(CommonGui.loadIcon("px.gif"));
80 		logo.setOpaque(true);
81 		logo.setBackground(BACKGROUND_COLOR);
82 
83 		container.add(new JLabel(Resource.getString("about.credits.label")));
84 
85 		String credits = "\n" + Resource.getString("credits") + "\n";
86 		JTextArea list = new JTextArea(credits, 5, 10);
87 		list.setEnabled(false);
88 		list.setDisabledTextColor(Color.black);
89 		JScrollPane scroll = new JScrollPane(list);
90 		scroll.setBackground(Color.white);
91 		scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
92 		scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
93 		container.add(scroll);
94 
95 		final CreditsScroller creditScroller = new CreditsScroller(scroll);
96 		creditScroller.start();
97 
98 		container.add(new JLabel(" ")); // as spacer
99 
100 		String terms[] = Resource.getStringByLines("terms");
101 
102 		for (int a=0; a<terms.length; a++)
103 			container.add(new JLabel(terms[a]));
104 
105 		JButton ok = new JButton(Resource.getString("about.ok"));
106 		ok.setBackground(BACKGROUND_COLOR);
107 		ok.addActionListener(new ActionListener()
108 		{
109 			public void actionPerformed(ActionEvent arg0) {
110 				creditScroller.stopIt();
111 				dispose();
112 			}
113 		});
114 
115 		JPanel container2 = new JPanel(new BorderLayout());
116 		//container2.setBorder( BorderFactory.createRaisedBevelBorder());
117 		container2.setBackground(BACKGROUND_COLOR);
118 		container2.setOpaque(true);
119 		container2.add(logo, BorderLayout.NORTH);
120 		container2.add(container, BorderLayout.CENTER);
121 		container2.add(ok, BorderLayout.SOUTH);
122 
123 		getContentPane().add(container2);
124 		pack();
125 
126 		setLocation(200,200);
127 		setResizable(false);
128 
129 		addWindowListener (new WindowAdapter() {
130 			public void windowClosing(WindowEvent e) {
131 				creditScroller.stopIt();
132 				dispose();
133 			}
134 		});
135 
136 		setVisible(true);
137 	}
138 
139 	/**
140 	 * A Thread which scrolls a JScrollPane from top to bottom and vice versa
141 	 * until it is stopped by calling stopIt().
142 	 */
143 	private class CreditsScroller extends Thread
144 	{
145 		/** direction up? */
146 		private boolean up = true;
147 
148 		/** should this Thread be stopped? */
149 		private boolean stopIt = false;
150 
151 		/** the JScrollPane to scroll */
152 		private JScrollPane scroll;
153 
154 		/**
155 		 * Constructor of CreditsScroller.
156 		 *
157 		 * @param scroll The JScrollPane of the credits JTextArea
158 		 */
CreditsScroller(JScrollPane scroll)159 		public CreditsScroller(JScrollPane scroll)
160 		{
161 			this.scroll = scroll;
162 		}
163 
164 		/* (non-Javadoc)
165 		 * @see java.lang.Runnable#run()
166 		 */
run()167 		public void run()
168 		{
169 			while (!stopIt)
170 			{
171 				try {
172 					sleep(100);
173 				} catch (InterruptedException e) {
174 				}
175 
176 				JViewport viewport = scroll.getViewport();
177 				int height = viewport.getViewSize().height - viewport.getViewRect().height;
178 				int viewHeight = (int)viewport.getViewPosition().getY();
179 				if (up)
180 				{
181 					if (viewHeight < height)
182 					{
183 						viewHeight++;
184 					}
185 					else
186 					{
187 						viewHeight--;
188 						up = false;
189 					}
190 				}
191 				else
192 				{
193 					if (viewHeight > 0)
194 					{
195 						viewHeight--;
196 					}
197 					else
198 					{
199 						viewHeight++;
200 						up = true;
201 					}
202 				}
203 				viewport.setViewPosition(new Point(0,viewHeight));
204 			}
205 		}
206 
207 		/**
208 		 * Sets the variable stopIt to bring this Thread to an end.
209 		 */
stopIt()210 		public void stopIt()
211 		{
212 			stopIt = true;
213 		}
214 }
215 
216 }
217 
218