/
SlideshowFrame.java
921 lines (746 loc) · 25.2 KB
/
SlideshowFrame.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
package com.gallery.GalleryRemote;
import com.gallery.GalleryRemote.model.Picture;
import com.gallery.GalleryRemote.util.*;
import com.gallery.GalleryRemote.prefs.PreferenceNames;
import com.gallery.GalleryRemote.prefs.PropertiesFile;
import javax.swing.*;
import java.awt.*;
import java.awt.image.MemoryImageSource;
import java.awt.image.BufferedImage;
import java.awt.geom.Rectangle2D;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class SlideshowFrame extends PreviewFrame
implements Runnable, PreferenceNames, CancellableTransferListener, MouseMotionListener {
public static final String MODULE = "SlideFrame";
List pictures = null;
List wantDownloaded = Collections.synchronizedList(new ArrayList());
Picture userPicture = null;
SlideshowPane slideshowPane;
int wantIndex = -1;
int sleepTime = 3000;
int skipTime = 500;
boolean running = false;
boolean shutdown = false;
long pictureShownTime = 0;
String caption = null;
String progress = null;
String extra = null;
String url = null;
String skipping = null;
public static final int STATE_NO_CHANGE = 0;
public static final int STATE_PREPARING = 0;
public static final int STATE_DOWNLOADING = 1;
public static final int STATE_PROCESSING = 2;
public static final int STATE_NEXTREADY = 3;
public static final int STATE_SKIPPING = 4;
public static final int STATE_SHOWING = 5;
public static final int STATE_ERROR = 6;
public static final int FEEDBACK_NONE = 0;
public static final int FEEDBACK_HELP = 1;
public static final int FEEDBACK_PREV = 2;
public static final int FEEDBACK_NEXT = 4;
public static final int FEEDBACK_PAUSE_PLAY = 8;
public int dataTransferred = 0;
public int dataOverall = 0;
public int feedback = FEEDBACK_NONE;
public int state = STATE_PREPARING;
long feedbackUntil = 0;
long dontShowUntil = 0;
Thread feedbackThread = null;
public static Cursor transparentCursor = null;
int transitionDuration = -1;
boolean enableTransitions;
public SlideshowFrame() {
setUndecorated(true);
setResizable(false);
initComponents();
}
public void showSlideshow() {
//try {
/*if (GalleryRemote.IS_MAC_OS_X) {
// on the Mac, using a maximized window doesn't take care of the menu bar
// Java 1.4 only
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (! gd.isFullScreenSupported()) {
throw new NoSuchMethodError();
}
Log.log(Log.LEVEL_TRACE, MODULE, "Switching to full-screen mode");
DialogUtil.maxSize(this);
setVisible(true);
// unfortunately, this doesn't work on Mac 1.4.2...
// gd.setFullScreenWindow(this);
} else {*/
DialogUtil.maxSize(this);
//setBounds(600, 100, 1000, 1000);
setVisible(true);
//}
/*} catch (Throwable e) {
Log.log(Log.LEVEL_TRACE, MODULE, "No full-screen mode: using maximized window");
DialogUtil.maxSize(this);
setVisible(true);
}*/
Log.log(Log.LEVEL_TRACE, MODULE, "Showing slideshow frame");
// todo: this is a hack to prevent painting problems (the status bar paints
// on top of the slide show)
Frame mainFrame = GalleryRemote._().getMainFrame();
if (mainFrame != null) {
mainFrame.setVisible(false);
}
}
public void hide() {
Log.log(Log.LEVEL_TRACE, MODULE, "Stopping slideshow");
running = false;
shutdown = true;
if (!isShowing()) {
return;
}
showCursor();
//GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
//gd.setFullScreenWindow(null);
super.hide();
if (GalleryRemote._() != null) {
Frame mainFrame = GalleryRemote._().getMainFrame();
if (mainFrame != null) {
mainFrame.setVisible(true);
}
}
ImageUtils.deferredTasks();
}
public void initComponents() {
addMouseListener(new MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {
Log.log(Log.LEVEL_TRACE, MODULE, "Got click");
nextAsync();
}
});
addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
Log.log(Log.LEVEL_TRACE, MODULE, "Got wheel: " + e);
if (e.getWheelRotation() > 0) {
nextAsync();
} else {
previousAsync();
}
}
});
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int vKey = e.getKeyCode();
Log.log(Log.LEVEL_TRACE, MODULE, "Got key: " + e);
switch (vKey) {
case KeyEvent.VK_ESCAPE:
hide();
break;
case KeyEvent.VK_LEFT:
case KeyEvent.VK_UP:
previousAsync();
break;
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_DOWN:
nextAsync();
break;
case KeyEvent.VK_H:
updateFeedback(FEEDBACK_HELP);
break;
case KeyEvent.VK_SPACE:
if (running) {
running = false;
} else {
new Thread(SlideshowFrame.this).start();
}
updateFeedback(FEEDBACK_PAUSE_PLAY);
updateProgress(loader.pictureShowNow, STATE_SHOWING);
break;
}
}
});
addMouseMotionListener(this);
slideshowPane = new SlideshowPane();
setContentPane(slideshowPane);
PropertiesFile pf = GalleryRemote._().properties;
sleepTime = pf.getIntProperty(SLIDESHOW_DELAY) * 1000;
loader = new ImageLoaderUtil(5, this);
loader.setTransferListener(this);
}
public void start(ArrayList pictures) {
if (GalleryRemote._().properties.getBooleanProperty(SLIDESHOW_RANDOM)) {
this.pictures = new ArrayList(pictures);
Collections.shuffle(this.pictures);
} else {
this.pictures = pictures;
}
new Thread(this).start();
if (GalleryRemote._().properties.getBooleanProperty(SLIDESHOW_PRELOADALL)) {
Thread t = new Thread() {
public void run() {
Log.log(Log.LEVEL_TRACE, MODULE, "Preload thread starting");
for (Iterator it = SlideshowFrame.this.pictures.iterator(); it.hasNext();) {
if (shutdown) {
break;
}
Picture picture = (Picture) it.next();
Log.log(Log.LEVEL_TRACE, MODULE, "Preloading " + picture);
ImageUtils.download(picture, getRootPane().getSize(), GalleryRemote._().getCore().getMainStatusUpdate(), null);
}
Log.log(Log.LEVEL_TRACE, MODULE, "Preload thread done");
}
};
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
}
public void run() {
running = true;
while (running && !shutdown) {
if (!next(false)) {
// the slideshow is over
hide();
break;
}
try {
long sleep;
if (sleepTime > 0) {
while ((sleep = sleepTime - (System.currentTimeMillis() - pictureShownTime)) > 0) {
Thread.sleep(sleep);
}
}
//Log.log(Log.LEVEL_TRACE, MODULE, "sleepTime: " + sleepTime + " - " + (System.currentTimeMillis() - pictureShownTime));
//Thread.sleep(1000);
} catch (InterruptedException e) {
Log.logException(Log.LEVEL_ERROR, MODULE, e);
}
}
}
private void previousAsync() {
new Thread() {
public void run() {
updateFeedback(FEEDBACK_PREV);
previous(true);
}
}.start();
}
private void nextAsync() {
new Thread() {
public void run() {
updateFeedback(FEEDBACK_NEXT);
next(true);
}
}.start();
}
public boolean next(boolean user) {
if (loader.pictureShowWant != null
&& wantDownloaded.contains(loader.pictureShowWant)
&& (loader.pictureShowWant != userPicture || user)) {
// we no longer want the current picture
wantDownloaded.remove(loader.pictureShowWant);
}
Picture picture;
if (userPicture != null && !user) {
// automatic move trying to move away from user-chosen picture
// add delay to prevent endless loop
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
return true;
}
synchronized(this) {
if (userPicture != null && !user) {
// don't delay in critical section
return true;
}
wantIndex++;
if (wantIndex >= pictures.size()) {
if (GalleryRemote._().properties.getBooleanProperty(SLIDESHOW_LOOP)) {
wantIndex = 0;
} else {
wantIndex = pictures.size() - 1;
return false;
}
}
// display next picture
picture = (Picture) pictures.get(wantIndex);
Log.log(Log.LEVEL_TRACE, MODULE, "Next picture: " + picture);
}
if (user) {
userPicture = picture;
updateProgress(picture, STATE_SKIPPING);
Log.log(Log.LEVEL_TRACE, MODULE, "Skipping sleep");
try {
Thread.sleep(skipTime);
} catch (InterruptedException e) {}
Log.log(Log.LEVEL_TRACE, MODULE, "Skipping wake");
// if user moved to a different picture in the meantime, cancel
if (userPicture != picture) {
Log.log(Log.LEVEL_TRACE, MODULE, "User skipped again, not even loading " + picture);
return true;
}
}
wantDownloaded.add(picture);
updateProgress(picture, STATE_PREPARING);
loader.preparePicture(picture, false, true);
// and cache the one after it
if (wantIndex + 1< pictures.size() && (loader.images.get(picture = (Picture) pictures.get(wantIndex + 1))) == null) {
wantDownloaded.add(picture);
loader.imageLoader.loadPicture(picture, false);
}
return true;
}
public boolean previous(boolean user) {
if (loader.pictureShowWant != null && wantDownloaded.contains(loader.pictureShowWant) && (loader.pictureShowWant != userPicture || user)) {
// we no longer want the current picture
wantDownloaded.remove(loader.pictureShowWant);
}
Picture picture;
synchronized (this) {
wantIndex--;
if (wantIndex < 0) {
if (GalleryRemote._().properties.getBooleanProperty(SLIDESHOW_LOOP)) {
wantIndex = pictures.size() - 1;
} else {
wantIndex = 0;
return false;
}
}
// display previous picture
picture = (Picture) pictures.get(wantIndex);
}
Log.log(Log.LEVEL_TRACE, MODULE, "Previous picture: " + picture);
if (user) {
userPicture = picture;
updateProgress(picture, STATE_SKIPPING);
try {
Thread.sleep(skipTime);
} catch (InterruptedException e) {}
// if user moved to a different picture in the meantime, cancel
if (userPicture != picture) {
Log.log(Log.LEVEL_TRACE, MODULE, "User skipped again, not even loading " + picture);
return true;
}
} else if (userPicture != null && userPicture != picture) {
// automatic move trying to move away from user-chosen picture
return true;
}
wantDownloaded.add(picture);
updateProgress(picture, STATE_PREPARING);
loader.preparePicture(picture, false, true);
// and cache the one after it
if (wantIndex - 1 > 0 && (loader.images.get(picture = (Picture) pictures.get(wantIndex - 1))) == null) {
wantDownloaded.add(picture);
loader.imageLoader.loadPicture(picture, false);
}
return true;
}
public boolean blockPictureReady(Image image, Picture picture) {
Log.log(Log.LEVEL_TRACE, MODULE, "blockPictureReady: " + picture + " - pictureShowWant: " + loader.pictureShowWant);
if (picture == userPicture) {
userPicture = null;
}
if (picture != loader.pictureShowWant) {
Log.log(Log.LEVEL_TRACE, MODULE, "We wanted " + loader.pictureShowWant + ": ignoring");
updateProgress(loader.pictureShowWant, STATE_NEXTREADY);
return true;
}
if (picture != null) {
if (picture.getCaption() != null) {
caption = ImageLoaderUtil.stripTags(HTMLEscaper.unescape(picture.getCaption())).trim();
} else {
caption = null;
}
extra = picture.getExtraFieldsString().trim();
if (picture.isOnline()) {
url = picture.safeGetUrlFull().toString();
// update view count on Gallery
picture.getParentAlbum().getGallery().incrementViewCount(picture, GalleryRemote._().getCore().getMainStatusUpdate());
} else {
url = picture.getSource().toString();
}
updateProgress(picture, STATE_SHOWING);
}
pictureShownTime = System.currentTimeMillis();
return false;
}
public void pictureStartDownloading(Picture picture) {
if (picture == loader.pictureShowWant || picture == userPicture) {
updateProgress(picture, STATE_DOWNLOADING);
}
}
public void pictureStartProcessing(Picture picture) {
if (picture == loader.pictureShowWant || picture == userPicture) {
updateProgress(picture, STATE_PROCESSING);
}
}
public void pictureLoadError(Picture picture) {
if (picture == loader.pictureShowWant || picture == userPicture) {
updateProgress(picture, STATE_ERROR);
}
loader.reduceMemory();
}
private void updateProgress(Picture picture, int state) {
if (picture == null) {
return;
}
Object[] params = new Object[] {picture.getName(),
new Integer(pictures.indexOf(picture) + 1),
new Integer(pictures.size())};
switch (state) {
case STATE_SHOWING:
if (! running) {
progress = GRI18n.getString(MODULE, "paused", params);
} else {
progress = GRI18n.getString(MODULE, "showing", params);
}
break;
case STATE_PREPARING:
progress = GRI18n.getString(MODULE, "preparing", params);
break;
case STATE_DOWNLOADING:
progress = GRI18n.getString(MODULE, "downloading", params);
break;
case STATE_PROCESSING:
progress = GRI18n.getString(MODULE, "processing", params);
break;
case STATE_NEXTREADY:
progress = GRI18n.getString(MODULE, "nextReady", params);
break;
case STATE_ERROR:
progress = GRI18n.getString(MODULE, "error", params);
break;
case STATE_SKIPPING:
progress = GRI18n.getString(MODULE, "skipping", params);
skipping = GRI18n.getString(MODULE, "skippingController", params);
break;
}
Log.log(Log.LEVEL_TRACE, MODULE, "updateProgress: " + progress);
repaint();
hideCursor();
}
public boolean dataTransferred(int transferred, int overall, double kbPerSecond, Picture p) {
if (! wantDownloaded.contains(p) || shutdown) {
return false;
}
dataTransferred = transferred;
dataOverall = overall;
if (transferred == overall) {
repaint();
} else {
slideshowPane.paintProgress((Graphics2D) slideshowPane.getGraphics());
}
return true;
}
public void updateFeedback(int feedback) {
if (feedback != FEEDBACK_NONE) {
feedbackUntil = System.currentTimeMillis()
+ (feedback == FEEDBACK_HELP?6000: 1500);
synchronized(this) {
if (feedbackThread == null) {
feedbackThread = new Thread() {
public void run() {
boolean running = true;
while (running) {
try {
Thread.sleep(feedbackUntil - System.currentTimeMillis());
synchronized(this) {
if (System.currentTimeMillis() >= feedbackUntil) {
running = false;
feedbackThread = null;
SlideshowFrame.this.feedback = FEEDBACK_NONE;
repaint();
}
}
} catch (InterruptedException e) {}
}
}
};
feedbackThread.start();
}
}
}
if ((this.feedback & FEEDBACK_HELP) == FEEDBACK_HELP) {
this.feedback = feedback | FEEDBACK_HELP;
} else if (feedback == FEEDBACK_HELP) {
this.feedback |= FEEDBACK_HELP;
} else {
this.feedback = feedback;
}
repaint();
}
public void hideCursor() {
if (transparentCursor == null) {
int[] pixels = new int[16 * 16];
Image image = Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(16, 16, pixels, 0, 16));
transparentCursor =
Toolkit.getDefaultToolkit().createCustomCursor
(image, new Point(0, 0), "invisiblecursor");
}
setCursor(transparentCursor);
}
public void showCursor() {
setCursor(Cursor.getDefaultCursor());
}
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {
showCursor();
}
public void initTransitionDuration() {
boolean accelerated = ((Graphics2D) getGraphics()).getDeviceConfiguration().getImageCapabilities().isAccelerated();
Log.log(Log.LEVEL_TRACE, MODULE, "Is graphics accelerated: " + accelerated);
enableTransitions = accelerated
|| GalleryRemote._().properties.getBooleanProperty(UNACCELERATED_TRANSITION, false);
transitionDuration = enableTransitions?
GalleryRemote._().properties.getIntProperty(SLIDESHOW_TRANSITION_DURATION, 3000):0;
if (transitionDuration == 0) {
enableTransitions = false;
}
}
class SlideshowPane extends JPanel implements ActionListener {
Color background = new Color(100, 100, 100, 150);
Color normal = new Color(180, 180, 180, 180);
Color hilight = new Color(255, 255, 255, 180);
boolean firstPaint = true;
BufferedImage feedbackCache = null;
int cachedFeedback = 0;
Point feedbackLocation = new Point();
int feedbackWidth = 535;
int feedbackHeight = 220;
BufferedImage[] infoCache = new BufferedImage[4];
String[] cachedInfo = new String[4];
Point[] infoLocation = new Point[4];
BufferedImage[] previousInfoCache = new BufferedImage[4];
Point[] previousInfoLocation = new Point[4];
Image currentImage = null;
Image currentImageSrc = null;
Image previousImage = null;
Rectangle previousRect = null;
Timer timer = new Timer(1000/60, this);
long transitionStart = System.currentTimeMillis() - 5000;
float imageAlpha = 0;
public void actionPerformed(ActionEvent e) {
long now = System.currentTimeMillis();
if (now - transitionStart > transitionDuration) {
timer.stop();
imageAlpha = 1;
// flush previous, no longer needed
previousImage = null;
for (int id = 0; id < previousInfoCache.length; id++) {
if (previousInfoCache[id] != null) {
previousInfoCache[id].flush();
}
previousInfoCache[id] = null;
}
} else {
imageAlpha = ((float) (now - transitionStart)) / transitionDuration;
}
repaint();
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (firstPaint) {
firstPaint = false;
ImageLoaderUtil.setSlideshowFont(this);
initTransitionDuration();
}
if (feedback == FEEDBACK_NONE && feedbackUntil <= System.currentTimeMillis()) {
skipping = null;
}
paintPicture(g2);
paintInfo(g2);
paintFeedback(g2);
paintSkipping(g2);
paintProgress(g2);
}
public void paintPicture(Graphics2D g) {
Color c = GalleryRemote._().properties.getColorProperty(SLIDESHOW_COLOR);
if (c != null) {
g.setColor(c);
} else {
g.setColor(getBackground());
}
g.fillRect(0, 0, getSize().width, getSize().height);
if (loader.imageShowNow != null && loader.pictureShowWant != null) {
if (loader.imageShowNow != currentImageSrc) {
Log.log(Log.LEVEL_TRACE, MODULE, "New image: " + loader.imageShowNow + " - " + currentImageSrc);
previousImage = currentImage;
previousRect = currentRect;
currentImage = ImageUtils.rotateImage(loader.imageShowNow, loader.pictureShowWant.getAngle(),
loader.pictureShowWant.isFlipped(), this);
currentRect = new Rectangle(getLocation().x + (getWidth() - currentImage.getWidth(this)) / 2,
getLocation().y + (getHeight() - currentImage.getHeight(this)) / 2,
currentImage.getWidth(this), currentImage.getHeight(this));
currentImageSrc = loader.imageShowNow;
if (enableTransitions) {
imageAlpha = 0;
transitionStart = System.currentTimeMillis();
if (! timer.isRunning()) {
timer.start();
}
}
}
Composite composite = g.getComposite();
if (imageAlpha != 1 && previousImage != null) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1 - imageAlpha));
g.drawImage(previousImage, previousRect.x, previousRect.y, getContentPane());
}
if (imageAlpha != 0) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, imageAlpha));
g.drawImage(currentImage, currentRect.x, currentRect.y, getContentPane());
}
g.setComposite(composite);
}
}
public void paintInfo(Graphics2D g) {
PropertiesFile pf = GalleryRemote._().properties;
paintInfo(g, 0, caption, pf.getIntProperty(SLIDESHOW_CAPTION), true);
paintInfo(g, 1, progress, pf.getIntProperty(SLIDESHOW_PROGRESS), false);
paintInfo(g, 2, extra, pf.getIntProperty(SLIDESHOW_EXTRA), true);
paintInfo(g, 3, url, pf.getIntProperty(SLIDESHOW_URL), true);
}
public void paintFeedback(Graphics2D g) {
if (feedback == FEEDBACK_NONE) {
return;
}
if (feedbackCache == null || cachedFeedback != feedback) {
cachedFeedback = feedback;
Dimension d = getSize();
feedbackLocation.x = d.width / 2 - feedbackWidth / 2;
feedbackLocation.y = d.height / 3 * 2 - feedbackHeight / 2;
int x = 30;
int y = 20;
if (feedbackCache != null) {
feedbackCache.flush();
}
feedbackCache = new BufferedImage(
feedbackWidth + 60,
feedbackHeight + 70,
BufferedImage.TYPE_INT_ARGB);
Graphics2D gc = (Graphics2D) feedbackCache.getGraphics();
gc.setFont(g.getFont().deriveFont(18.0F));
FontMetrics fm = gc.getFontMetrics();
// background
gc.setColor(background);
gc.fillRoundRect(0, 0, feedbackWidth,
feedbackHeight + ((feedback & FEEDBACK_HELP) == FEEDBACK_HELP?0:-30),
30, 30);
gc.setColor(normal);
gc.drawRoundRect(0, 0, feedbackWidth,
feedbackHeight + ((feedback & FEEDBACK_HELP) == FEEDBACK_HELP?0:-30),
30, 30);
// left arrow
gc.setColor((feedback & FEEDBACK_PREV) == FEEDBACK_PREV?hilight:normal);
gc.fillPolygon(new int[] {x + 100, x + 100, x + 50, x + 50, x, x + 50, x + 50},
new int[] {y + 60, y + 90, y + 90, y + 125, y + 75, y + 25, y + 60}, 7);
drawHelp(gc, hilight, fm, x + 50, y + 160, GRI18n.getString(MODULE, "controller.left"));
drawHelp(gc, hilight, fm, x + 107, y + 180, GRI18n.getString(MODULE, "controller.mousewheel"));
x += 115;
// right arrow
gc.setColor((feedback & FEEDBACK_NEXT) == FEEDBACK_NEXT?hilight:normal);
gc.fillPolygon(new int[] {x, x, x + 50, x + 50, x + 100, x + 50, x + 50},
new int[] {y + 60, y + 90, y + 90, y + 125, y + 75, y + 25, y + 60}, 7);
drawHelp(gc, hilight, fm, x + 50, y + 160, GRI18n.getString(MODULE, "controller.right"));
x += 130;
// play/pause
gc.setColor((feedback & FEEDBACK_PAUSE_PLAY) == FEEDBACK_PAUSE_PLAY?hilight:normal);
if (running) {
gc.fillPolygon(new int[] {x, x, x + 100},
new int[] {y + 10, y + 140, y + 75}, 3);
} else {
gc.fillPolygon(new int[] {x, x, x + 30, x + 30},
new int[] {y + 10, y + 140, y + 140, y + 10}, 4);
gc.fillPolygon(new int[] {x + 70, x + 70, x + 100, x + 100},
new int[] {y + 10, y + 140, y + 140, y + 10}, 4);
}
drawHelp(gc, hilight, fm, x + 50, y + 160, GRI18n.getString(MODULE, "controller.space"));
x += 130;
// stop
gc.setColor(normal);
gc.fillPolygon(new int[] {x, x, x + 30, x + 70, x + 100, x + 100, x + 70, x + 30},
new int[] {y + 55, y + 95, y + 125, y + 125, y + 95, y + 55, y + 25, y + 25}, 8);
drawHelp(gc, hilight, fm, x + 50, y + 160, GRI18n.getString(MODULE, "controller.escape"));
}
g.drawImage(feedbackCache, feedbackLocation.x, feedbackLocation.y, this);
}
public void paintSkipping(Graphics2D g) {
if (skipping != null) {
Dimension d = getSize();
int x = d.width / 2;
int y = d.height / 3 * 2 - feedbackHeight / 2;
g.setFont(getFont().deriveFont(48.0F));
FontMetrics fm = g.getFontMetrics();
g.setColor(hilight);
Rectangle2D bounds = fm.getStringBounds(skipping, g);
g.drawString(skipping, (int) (x - bounds.getWidth() / 2),
y + ((feedback & FEEDBACK_HELP) == FEEDBACK_HELP?270:240));
}
}
public void paintProgress(Graphics2D g) {
if (dataTransferred < dataOverall) {
g.setColor(Color.yellow);
float r = ((float) dataTransferred) / dataOverall;
g.drawLine(0, 0, (int) (getWidth() * r), 0);
}
}
public void paintInfo(Graphics2D g, int id, String text, int position, boolean transition) {
if (position == 0) return;
if (text == null) text = "";
if (!text.equals(cachedInfo[id])) {
previousInfoCache[id] = infoCache[id];
previousInfoLocation[id] = infoLocation[id];
cachedInfo[id] = text;
Dimension d = getSize();
g.setFont(getFont());
int x;
int y;
int inset = 5;
switch (position % 10) {
case 2:
default:
x = inset;
break;
case 0:
x = d.width / 2;
break;
case 4:
x = d.width - inset;
break;
}
switch (position / 10) {
case 1:
default:
y = inset;
break;
case 2:
y = d.height / 2;
break;
case 3:
y = d.height - inset;
break;
}
ImageLoaderUtil.WrapInfo wrapInfo = ImageLoaderUtil.wrap(g, text, d.width);
infoCache[id] = new BufferedImage(wrapInfo.width + 2, wrapInfo.height + 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) infoCache[id].getGraphics();
g2.setFont(g.getFont());
infoLocation[id] = ImageLoaderUtil.paintAlignedOutline(
g2, x, y, 1, position, wrapInfo, true);
Log.log(Log.LEVEL_TRACE, MODULE, "Cached info " + id + " - " + text);
}
Composite composite = g.getComposite();
if (transition && imageAlpha != 1 && previousInfoCache[id] != null) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1 - imageAlpha));
g.drawImage(previousInfoCache[id], previousInfoLocation[id].x, previousInfoLocation[id].y, this);
}
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transition?imageAlpha:1));
g.drawImage(infoCache[id], infoLocation[id].x, infoLocation[id].y, this);
g.setComposite(composite);
}
private void drawHelp(Graphics g, Color hilight, FontMetrics fm, int x, int y, String text) {
if ((feedback & FEEDBACK_HELP) != FEEDBACK_HELP) return;
g.setColor(hilight);
Rectangle2D bounds = fm.getStringBounds(text, g);
g.drawString(text, (int) (x - bounds.getWidth() / 2), y);
}
}
}