/
AboutBox.java
274 lines (230 loc) · 8.05 KB
/
AboutBox.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* Gallery Remote - a File Upload Utility for Gallery
*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2001 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.gallery.GalleryRemote;
import com.gallery.GalleryRemote.util.DialogUtil;
import com.gallery.GalleryRemote.util.GRI18n;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.net.URL;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.UIManager;
import javax.swing.border.MatteBorder;
/**
* Gallery Remote About Box
*
*@author paour
*@created August 18, 2002
*/
public class AboutBox extends JDialog {
public static final String MODULE = "About";
public static int TOP = 5;
public static int BOTTOM = 105;
public static GRI18n grRes = GRI18n.getInstance();
/**
* Constructor for the AboutBox object
*/
public AboutBox() {
super();
init();
}
/**
* Constructor for the AboutBox object
*
*@param owner Description of Parameter
*/
public AboutBox( Frame owner ) {
super( owner );
init();
}
private void init() {
setModal( true );
getContentPane().add( new AboutPanel(), BorderLayout.CENTER );
setTitle( grRes.getString(MODULE, "title") );
pack();
DialogUtil.center(this);
addMouseListener(
new java.awt.event.MouseAdapter() {
public void mouseClicked( MouseEvent e ) {
thisWindowClosing();
}
} );
addWindowListener(
new java.awt.event.WindowAdapter() {
public void windowClosing( MouseEvent e ) {
thisWindowClosing();
}
} );
}
// Close the window when the box is clicked
void thisWindowClosing() {
setVisible( false );
dispose();
}
/**
* AboutPanel: scrolling panel of credits for About boxes
*
*@author paour
*@created August 16, 2002
*/
public class AboutPanel extends JComponent {
ImageIcon image;
Vector text;
int scrollPosition;
AnimationThread thread;
int maxWidth;
FontMetrics fm;
int initialPosition;
/**
* Constructor for the AboutPanel object
*/
public AboutPanel() {
setFont( UIManager.getFont( "Label.font" ) );
fm = getFontMetrics( getFont() );
URL imu = getClass().getResource( "/rar_about_gr1.png" );
Log.log(Log.LEVEL_TRACE, MODULE, "Looking for splash screen in " + imu.toString());
image = new ImageIcon( imu );
setBorder( new MatteBorder( 1, 1, 1, 1, Color.gray ) );
text = new Vector( );
StringTokenizer st = new StringTokenizer(
GalleryRemote.getInstance().properties.getProperty( "aboutText" ), "\n" );
while ( st.hasMoreTokens() ) {
String line = st.nextToken();
text.addElement( line );
maxWidth = Math.max( maxWidth,
fm.stringWidth( line ) + 10 );
}
initialPosition = getHeight() - BOTTOM /*- BOTTOM*/ - TOP - TOP;
scrollPosition = initialPosition;
thread = new AnimationThread();
}
/**
* Gets the preferredSize attribute of the AboutPanel object
*
*@return The preferredSize value
*@since
*/
public Dimension getPreferredSize() {
return new Dimension( 1 + image.getIconWidth(),
1 + image.getIconHeight() );
}
/**
* Description of the Method
*
*@param g Description of Parameter
*@since
*/
public void paintComponent( Graphics g ) {
//g.setColor(new Color(96, 96, 96));
image.paintIcon( this, g, 1, 1 );
FontMetrics fm = g.getFontMetrics();
String version = GalleryRemote.getInstance().properties.getProperty( "version" );
g.drawString( version, ( getWidth() - fm.stringWidth( version ) ) / 2,
getHeight() - 5 );
g = g.create( ( getWidth() - maxWidth ) / 2, TOP, maxWidth,
getHeight() - TOP - BOTTOM );
int height = fm.getHeight();
int firstLine = scrollPosition / height;
int firstLineOffset = height - scrollPosition % height;
int lines = ( getHeight() - TOP - BOTTOM ) / height;
int y = firstLineOffset;
g.setColor(new Color(255, 255, 255));
for ( int i = 0; i <= lines; i++ ) {
if ( i + firstLine >= 0 && i + firstLine < text.size() ) {
String line = (String) text.get( i + firstLine );
g.drawString( line, ( maxWidth - fm.stringWidth( line ) ) / 2, y );
}
y += fm.getHeight();
}
}
/**
* Adds a feature to the Notify attribute of the AboutPanel object
*
*@since
*/
public void addNotify() {
super.addNotify();
thread.start();
}
/**
* Description of the Method
*
*@since
*/
public void removeNotify() {
super.removeNotify();
thread.kill();
}
/**
* Animation thread
*
*@author paour
*@created August 16, 2002
*/
class AnimationThread extends Thread {
private boolean running = true;
AnimationThread() {
super( grRes.getString(MODULE, "aboutAnim") );
setPriority( Thread.MIN_PRIORITY );
}
/**
* Description of the Method
*
*@since
*/
public void kill() {
running = false;
}
/**
* Main processing method for the AnimationThread object
*
*@since
*/
public void run() {
FontMetrics fm = getFontMetrics( getFont() );
int max = ( text.size() * fm.getHeight() );
while ( running ) {
long start = System.currentTimeMillis();
scrollPosition += 2;
if ( scrollPosition > max ) {
scrollPosition = initialPosition;
}
try {
Thread.sleep( 100 );
} catch ( Exception e ) {
}
repaint( getWidth() / 2 - maxWidth,
TOP, maxWidth * 2,
getHeight() - TOP - BOTTOM );
}
}
}
}
}