/
MainFrame.java
2095 lines (1707 loc) · 62.1 KB
/
MainFrame.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
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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;
// todo: save
//import JSX.ObjIn;
//import JSX.ObjOut;
import com.gallery.GalleryRemote.model.Album;
import com.gallery.GalleryRemote.model.Gallery;
import com.gallery.GalleryRemote.model.Picture;
import com.gallery.GalleryRemote.prefs.PreferencesDialog;
import com.gallery.GalleryRemote.prefs.PropertiesFile;
import com.gallery.GalleryRemote.prefs.URLPanel;
import com.gallery.GalleryRemote.prefs.PreferenceNames;
import com.gallery.GalleryRemote.util.GRI18n;
import com.gallery.GalleryRemote.util.ImageUtils;
import com.gallery.GalleryRemote.util.OsShutdown;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.applet.Applet;
/**
* Description of the Class
*
* @author jackodog
* @author paour
*/
public class MainFrame extends JFrame
implements ActionListener, ItemListener, ListSelectionListener,
ListDataListener, TreeSelectionListener, TreeModelListener, FocusListener,
GalleryRemoteCore, PreferenceNames {
public static final String MODULE = "MainFrame";
public static final String FILE_TYPE = ".grg";
public PreviewFrame previewFrame = null;
private static final String DIALOGTITLE = "Gallery Remote -- ";
/**
* This File is the last opened file or null if the user has not opened
* a file or has just pressed New.
*/
private File lastOpenedFile = null;
/**
* This flag indicates whether the currently loaded file is dirty
* or clean. Dirty means that the logical contents of the file have
* changed and we need to prevent the user from doing something that
* will lose their changes. If we are clean then there is no possibility
* of losing changes.
*/
//private boolean m_isDirty = false;
public DefaultComboBoxModel galleries = null;
//private Gallery currentGallery = null;
//private Album currentAlbum = null;
private boolean inProgress = false;
ThumbnailCache thumbnailCache = new ThumbnailCache();
boolean running = true;
public StatusBar jStatusBar = new StatusBar();
PictureSelection ps = null;
JPanel jTopPanel = new JPanel();
JMenuBar jMenuBar1 = new JMenuBar();
JLabel jLabel1 = new JLabel();
JPanel jBottomPanel = new JPanel();
GridLayout gridLayout1 = new GridLayout();
GridBagLayout gridBagLayout3 = new GridBagLayout();
JPanel jAlbumPanel = new JPanel();
JScrollPane jAlbumScroll = new JScrollPane();
public DroppableTree jAlbumTree = new DroppableTree();
JComboBox jGalleryCombo = new JComboBox();
JButton jNewGalleryButton = new JButton();
JButton jLoginButton = new JButton();
JSplitPane jInspectorDivider = new JSplitPane();
JSplitPane jAlbumPictureDivider = new JSplitPane();
JButton jUploadButton = new JButton();
JButton jBrowseButton = new JButton();
JButton jSortButton = new JButton();
JComboBox jSortCombo = new JComboBox();
JButton jNewAlbumButton = new JButton();
JMenu jMenuFile = new JMenu();
// todo: save
//JMenuItem jMenuItemNew = new JMenuItem();
//JMenuItem jMenuItemOpen = new JMenuItem();
//JMenuItem jMenuItemSave = new JMenuItem();
//JMenuItem jMenuItemSaveAs = new JMenuItem();
//JMenuItem jMenuItemClose = new JMenuItem();
JMenuItem jMenuItemQuit = new JMenuItem();
// todo: save
// Create a Vector to store the MRU menu items. They
// are created dynamically below.
//int m_MRUMenuIndex = 0;
//Vector m_MRUFileList = new Vector();
JMenu jMenuEdit = new JMenu();
JMenuItem jMenuItemCut = new JMenuItem();
JMenuItem jMenuItemCopy = new JMenuItem();
JMenuItem jMenuItemPaste = new JMenuItem();
JMenu jMenuOptions = new JMenu();
JCheckBoxMenuItem jCheckBoxMenuThumbnails = new JCheckBoxMenuItem();
JCheckBoxMenuItem jCheckBoxMenuPreview = new JCheckBoxMenuItem();
JCheckBoxMenuItem jCheckBoxMenuPath = new JCheckBoxMenuItem();
JMenuItem jMenuItemPrefs = new JMenuItem();
JMenuItem jMenuItemClearCache = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuItemAbout = new JMenuItem();
DroppableList jPicturesList = new DroppableList();
JPanel jInspectorPanel = new JPanel();
CardLayout jInspectorCardLayout = new CardLayout();
PictureInspector jPictureInspector = new PictureInspector();
AlbumInspector jAlbumInspector = new AlbumInspector();
JScrollPane jPictureScroll = new JScrollPane();
public Frame activating = null;
public static Image iconImage = new ImageIcon(GalleryRemote.class.getResource("/rar_icon_16.gif")).getImage();
public static final String CARD_PICTURE = "picture";
public static final String CARD_ALBUM = "album";
public void initMainFrame() {
macOSXRegistration();
PropertiesFile p = GalleryRemote._().properties;
// load galleries
galleries = new DefaultComboBoxModel();
if (! GalleryRemote._().isAppletMode()) {
int i = 0;
while (true) {
try {
Gallery g = Gallery.readFromProperties(p, i++, jStatusBar);
if (g == null) {
break;
}
//g.addListDataListener(this);
galleries.addElement(g);
} catch (Exception e) {
Log.log(Log.LEVEL_ERROR, MODULE, "Error trying to load Gallery profile " + i);
Log.logException(Log.LEVEL_ERROR, MODULE, e);
}
}
} else {
//Gallery g = new Gallery(jStatusBar);
Applet applet = GalleryRemote._().getApplet();
GRApplet.AppletInfo info = ((GRApplet) applet).getGRAppletInfo();
info.gallery.addTreeModelListener(this);
galleries.addElement(info.gallery);
//CookieModule.addCookie(new Cookie(cookieName, cookieValue, cookieDomain, cookiePath, null, false));
}
setIconImage(iconImage);
/*if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
// Install shutdown handler only on Mac
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
shutdown(true);
}
});
}*/
}
public void startup() {
try {
jbInit();
jbInitEvents();
} catch (Exception e) {
Log.logException(Log.LEVEL_CRITICAL, MODULE, e);
}
setBounds(GalleryRemote._().properties.getMainBounds());
setJMenuBar(jMenuBar1);
jGalleryCombo.setEditable(false);
jGalleryCombo.setRenderer(new GalleryListRenderer());
jPicturesList.setCellRenderer(new CoreUtils.FileCellRenderer());
jPicturesList.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
jPicturesList.setInputMap(JComponent.WHEN_FOCUSED, null);
jPicturesList.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, null);
jAlbumTree.setMainFrame(this);
jAlbumTree.setRootVisible(false);
jAlbumTree.setScrollsOnExpand(true);
jAlbumTree.setShowsRootHandles(true);
jAlbumTree.setExpandsSelectedPaths(true);
jAlbumTree.setEnabled(true);
jAlbumTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
AlbumTreeRenderer albumTreeRenderer = new AlbumTreeRenderer();
albumTreeRenderer.setLeafIcon(null);
albumTreeRenderer.setOpenIcon(null);
albumTreeRenderer.setClosedIcon(null);
jAlbumTree.setCellRenderer(albumTreeRenderer);
//((JLabel) jAlbumTree.getCellRenderer()).setPreferredSize(new Dimension(GalleryRemote._().properties.getIntProperty("albumPictureDividerLocation"), -1));
ToolTipManager.sharedInstance().registerComponent(jAlbumTree);
//jAlbumTree.setFont(new Font("Arial Unicode MS", Font.PLAIN, 12));
jPictureInspector.setMainFrame(this);
jAlbumInspector.setMainFrame(this);
setGalleries(galleries);
jInspectorDivider.setDividerLocation(GalleryRemote._().properties.getIntProperty("inspectorDividerLocation"));
jAlbumPictureDivider.setDividerLocation(GalleryRemote._().properties.getIntProperty("albumPictureDividerLocation"));
setVisible(true);
previewFrame = new PreviewFrame();
previewFrame.initComponents();
previewFrame.addWindowListener(
new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
jCheckBoxMenuPreview.setState(false);
}
});
if (GalleryRemote._().properties.getShowPreview()) {
previewFrame.setVisible(true);
}
toFront();
readPreferences(GalleryRemote._().properties);
if (GalleryRemote._().isAppletMode()) {
/*Gallery g = getCurrentGallery();
g.getComm(jStatusBar).isLoggedIn = true;*/
fetchAlbums();
}
resetUIState();
// todo: save
// Load a state file
/*if (GalleryRemote._().properties.getLoadLastMRU()) {
String lastMRUFile = GalleryRemote._().properties.getMRUItem(1);
if (null != lastMRUFile) {
openState(lastMRUFile);
}
}*/
//new UploadProgress();
ImageUtils.deferredTasks();
}
private void setGalleries(DefaultComboBoxModel galleries) {
this.galleries = galleries;
jGalleryCombo.setModel(galleries);
galleries.addListDataListener(this);
selectedGalleryChanged();
// We've been initalized, we are now clean.
//setDirtyFlag(false);
}
/**
* Close the window when the close box is clicked
*
* @param e Event
*/
void thisWindowClosing(java.awt.event.WindowEvent e) {
shutdown(false, false);
}
public void shutdown() {
shutdown(false, false);
}
public void shutdown(boolean shutdownOs) {
shutdown(false, shutdownOs);
}
private void shutdown(boolean halt, boolean shutdownOs) {
// check that we don't have galleries with data
if (!shutdownOs) {
// todo: save
if (isDirty()) {
if (JOptionPane.showConfirmDialog(
(JFrame) this,
GRI18n.getString(MODULE, "quitQuestion"),
"Warning",
JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
return;
}
}
}
if (running) {
running = false;
Log.log(Log.LEVEL_INFO, MODULE, "Shutting down GR");
try {
PropertiesFile p = GalleryRemote._().properties;
p.setMainBounds(getBounds());
p.setPreviewBounds(previewFrame.getBounds());
p.setIntProperty("inspectorDividerLocation", jInspectorDivider.getDividerLocation());
p.setIntProperty("albumPictureDividerLocation", jAlbumPictureDivider.getDividerLocation());
p.write();
if (!halt) {
// in halt mode, this crashes the VM
setVisible(false);
dispose();
previewFrame.setVisible(false);
previewFrame.dispose();
}
ImageUtils.purgeTemp();
} catch (Throwable t) {
Log.log(Log.LEVEL_ERROR, MODULE, "Error while closing: " + t);
}
if (shutdownOs) {
OsShutdown.shutdown();
}
Log.log(Log.LEVEL_INFO, MODULE, "Shutting down log");
Log.shutdown();
if (! GalleryRemote._().isAppletMode()) {
if (!halt) {
// no need for this in halt mode
Runtime.getRuntime().exit(0);
}/* else {
Runtime.getRuntime().exit(0);
}*/
} else {
((GRApplet) GalleryRemote._().getApplet()).hasShutdown();
GalleryRemote.shutdownInstance();
}
}
}
public void setInProgress(boolean inProgress) {
this.inProgress = inProgress;
resetUIState();
}
/*
* <p>This method updates the dirty flag and also causes the UI
* to be updated to reflect the new state.
*
* @param newDirtyState the new state (true means the document is dirty).
/*private void setDirtyFlag(boolean newDirtyState) {
m_isDirty = newDirtyState;
resetUIState();
}*/
public boolean isDirty() {
for (int i = galleries.getSize() - 1; i >= 0; i--) {
Gallery g = (Gallery) galleries.getElementAt(i);
if (g.isDirty()) {
return true;
}
}
return false;
}
void resetUIState() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Album currentAlbum = getCurrentAlbum();
Gallery currentGallery = getCurrentGallery();
// if the list is empty or comm, disable upload
boolean uploadEnabled = currentAlbum != null
&& currentAlbum.sizePictures() > 0
&& !inProgress
&& jAlbumTree.getSelectionCount() > 0;
jUploadButton.setEnabled(uploadEnabled);
jSortCombo.setEnabled(uploadEnabled);
jSortButton.setEnabled(uploadEnabled);
// todo: save
/*if (null == lastOpenedFile) {
setTitle(DIALOGTITLE
+ GRI18n.getString(MODULE, "noTitleHeader")
+ (m_isDirty ? "*" : ""));
} else {
setTitle(DIALOGTITLE
+ lastOpenedFile.getName()
+ (m_isDirty ? "*" : ""));
}*/
setTitle("Gallery Remote");
// during comm, don't change Gallery or do any other comm
jLoginButton.setEnabled(!inProgress && currentGallery != null);
jGalleryCombo.setEnabled(!inProgress);
jNewGalleryButton.setEnabled(!inProgress);
// todo: save
/*// Disable New, Open, and Close
//jMenuItemNew.setEnabled(!inProgress);
jMenuItemOpen.setEnabled(!inProgress);
jMenuItemSave.setEnabled(!inProgress);
jMenuItemSaveAs.setEnabled(!inProgress);
//jMenuItemClose.setEnabled(!inProgress
// && null != lastOpenedFile);
// in the event the library we use to save is missing, dim the menus
try {
new JSX.ObjOut();
} catch (Throwable t) {
jMenuItemOpen.setEnabled(false);
jMenuItemSave.setEnabled(false);
jMenuItemSaveAs.setEnabled(false);
}*/
if (currentGallery != null
&& currentGallery.getUsername() != null
&& currentGallery.hasComm()
&& currentGallery.getComm(jStatusBar).isLoggedIn()) {
jLoginButton.setText(GRI18n.getString(MODULE, "Log_out"));
} else {
jLoginButton.setText(GRI18n.getString(MODULE, "Log_in"));
}
jAlbumTree.setEnabled(!inProgress && jAlbumTree.getModel().getRoot() != null && jAlbumTree.getModel().getChildCount(jAlbumTree.getModel().getRoot()) >= 1);
// if the selected album is uploading, disable everything
boolean enabled = !inProgress && currentAlbum != null && jAlbumTree.getModel().getChildCount(jAlbumTree.getModel().getRoot()) >= 1;
jBrowseButton.setEnabled(enabled && currentAlbum.getCanAdd());
jPictureInspector.setEnabled(enabled);
jPicturesList.setEnabled(enabled && currentAlbum.getCanAdd());
jNewAlbumButton.setEnabled(!inProgress && currentGallery != null && currentGallery.hasComm()
&& currentGallery.getComm(jStatusBar).hasCapability(jStatusBar, GalleryCommCapabilities.CAPA_NEW_ALBUM));
// change image displayed
int sel = jPicturesList.getSelectedIndex();
if (currentAlbum != null && currentAlbum.getSize() < 1) {
// if album was just emptied, it takes a while for the pictureList
// to notice...
// this is fixed by using invokeLater [apparently not anymore]
sel = -1;
}
if (GalleryRemote._().properties.getShowPreview() && previewFrame != null) {
if (sel != -1) {
previewFrame.loader.preparePicture(currentAlbum.getPicture(sel), true, true);
} else {
previewFrame.loader.preparePicture(null, true, true);
}
if (!previewFrame.isVisible()) {
previewFrame.setVisible(true);
}
}
// status
if (currentAlbum == null) {
jPictureInspector.setPictures(null);
jStatusBar.setStatus(GRI18n.getString(MODULE, "notLogged"));
} else if (currentAlbum.sizePictures() > 0) {
jPictureInspector.setPictures(jPicturesList.getSelectedValues());
int selN = jPicturesList.getSelectedIndices().length;
if (sel == -1) {
Object[] params = {new Integer(currentAlbum.sizePictures()),
new Integer((int) (currentAlbum.getPictureFileSize() / 1024))};
jStatusBar.setStatus(GRI18n.getString(MODULE, "statusBarNoSel", params));
} else {
Object[] params = {new Integer(selN),
GRI18n.getString(MODULE, (selN == 1) ? "oneSel" : "manySel"),
new Integer((int) Album.getObjectFileSize(jPicturesList.getSelectedValues()) / 1024)};
jStatusBar.setStatus(GRI18n.getString(MODULE, "statusBarSel", params));
}
} else {
jPictureInspector.setPictures(null);
jStatusBar.setStatus(GRI18n.getString(MODULE, "noSelection"));
}
jAlbumInspector.setAlbum(currentAlbum);
jAlbumTree.repaint();
}
});
}
private void selectedGalleryChanged() {
Gallery currentGallery = getCurrentGallery();
Log.log(Log.LEVEL_TRACE, MODULE, "updateGalleryParams: current gallery: " + currentGallery);
if (currentGallery != null && jAlbumTree.getModel() != currentGallery) {
jAlbumTree.setModel(currentGallery);
//currentGallery.addListDataListener(this);
} else {
jAlbumTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
}
if (currentGallery == null || currentGallery.getRoot() == null) {
jAlbumTree.setEnabled(false);
jPicturesList.setEnabled(false);
} else {
jAlbumTree.setEnabled(!inProgress);
}
updatePicturesList();
}
/*private void updateAlbumCombo() {
Gallery currentGallery = getCurrentGallery();
Log.log(Log.LEVEL_TRACE, MODULE, "updateAlbumCombo: current gallery: " + currentGallery);
}*/
private void updatePicturesList() {
Album currentAlbum = getCurrentAlbum();
Log.log(Log.LEVEL_TRACE, MODULE, "updatePicturesList: current album: " + currentAlbum);
if (currentAlbum == null) {
// fake empty album to clear the list
jPicturesList.setModel(new Album(null));
} else {
if (jPicturesList.getModel() != currentAlbum) {
jPicturesList.setModel(currentAlbum);
currentAlbum.addListDataListener(this);
}
jPictureInspector.setPictures(null);
}
resetUIState();
}
/**
* Open a file selection dialog and load the corresponding files
*/
public void browseAddPictures() {
jStatusBar.setStatus(GRI18n.getString(MODULE, "selPicToAdd"));
File[] files = AddFileDialog.addFiles(this);
if (files != null) {
addPictures(files, false);
}
}
public void addPictures(File[] files, boolean select) {
addPictures(null, files, -1, select);
}
public void addPictures(Album album, File[] files, boolean select) {
addPictures(album, files, -1, select);
}
public void addPictures(File[] files, int index, boolean select) {
addPictures(null, files, index, select);
}
public void addPictures(Album album, File[] files, int index, boolean select) {
if (album == null) {
album = getCurrentAlbum();
}
Log.log(Log.LEVEL_TRACE, MODULE, "Adding " + files.length + " pictures to album " + album);
ArrayList newPictures = null;
if (index == -1) {
newPictures = album.addPictures(files);
} else {
newPictures = album.addPictures(files, index);
}
preloadThumbnails(newPictures.iterator());
if (select) {
selectAddedPictures(files, index);
}
// We've been modified, we are now dirty.
//setDirtyFlag(true);
}
public void addPictures(Picture[] pictures, boolean select) {
addPictures(null, pictures, -1, select);
}
public void addPictures(Album album, Picture[] pictures, boolean select) {
addPictures(album, pictures, -1, select);
}
public void addPictures(Picture[] pictures, int index, boolean select) {
addPictures(null, pictures, index, select);
}
public void addPictures(Album album, Picture[] pictures, int index, boolean select) {
if (album == null) {
album = getCurrentAlbum();
}
if (index == -1) {
album.addPictures(Arrays.asList(pictures));
} else {
album.addPictures(Arrays.asList(pictures), index);
}
if (select) {
selectAddedPictures(pictures, index);
}
// We've been modified, we are now dirty.
//setDirtyFlag(true);
}
private void selectAddedPictures(Object[] objects, int index) {
int[] indices = new int[objects.length];
if (index == -1) {
index = getCurrentAlbum().getSize() - 1;
}
for (int i = 0; i < objects.length; i++) {
indices[i] = index + i;
}
jPicturesList.setSelectedIndices(indices);
}
/**
* Upload the files
*/
public void uploadPictures() {
Log.log(Log.LEVEL_INFO, MODULE, "uploadPictures starting");
File f = lastOpenedFile;
if (null == f) {
// No open file, use the default
f = getCurrentGallery().getGalleryDefaultFile();
}
// todo: save
//saveState(f);
getCurrentGallery().doUploadFiles(new UploadProgress(this));
}
/**
* Sort the files alphabetically
*/
public void sortPictures() {
int sortType = GalleryRemote._().properties.getIntProperty(SORT_TYPE);
switch (sortType) {
case SORT_TYPE_FILENAME:
getCurrentAlbum().sortPicturesAlphabetically();
break;
case SORT_TYPE_EXIF_CREATION:
getCurrentAlbum().sortPicturesCreated();
break;
default:
Log.log(Log.LEVEL_ERROR, MODULE, "Bad sort value: " + sortType);
break;
}
// We've been modified, we are now dirty.
//setDirtyFlag(true);
}
public void setSortType(int sortType) {
GalleryRemote._().properties.setIntProperty(SORT_TYPE, sortType);
jSortButton.setText(GRI18n.getString(MODULE, "sortBtnTxt",
new Object[] {GRI18n.getString(MODULE, "sort." + sortType)}));
}
/**
* Fetch Albums from server and update UI
*/
public void fetchAlbums() {
Log.log(Log.LEVEL_INFO, MODULE, "fetchAlbums starting");
getCurrentGallery().doFetchAlbums(jStatusBar);
//updateAlbumCombo();
Object root = jAlbumTree.getModel().getRoot();
if (root != null && jAlbumTree.getModel().getChildCount(root) > 0) {
jAlbumTree.setSelectionPath(null);
}
}
public void fetchAlbumImages() {
Log.log(Log.LEVEL_INFO, MODULE, "fetchAlbumImages starting");
getCurrentAlbum().fetchAlbumImages(jStatusBar, false, 0);
}
public void newAlbum() {
NewAlbumDialog dialog = new NewAlbumDialog(this, getCurrentGallery(), getCurrentAlbum());
//String newAlbumName = dialog.getNewAlbumName();
Album newAlbum = dialog.getNewAlbum();
//Album parentAlbum = dialog.getParentAlbum();
if (newAlbum == null) {
return;
}
String newAlbumName = getCurrentGallery().doNewAlbum(newAlbum, GalleryRemote._().getCore().getMainStatusUpdate());
if (newAlbumName.equals(newAlbum.getName())) {
newAlbum.setName(newAlbumName);
}
// todo: this is too drastic...
getCurrentGallery().reload();
Log.log(Log.LEVEL_TRACE, MODULE, "Album '" + newAlbum + "' created.");
// there is probably a better way... this is needed to give the UI time to catch up
// and load the combo up with the reloaded album list
//new Thread() {
// public void run() {
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// Log.logException(Log.LEVEL_ERROR, MODULE, e);
// }
//SwingUtilities.invokeLater(new Runnable() {
// public void run() {
Log.log(Log.LEVEL_TRACE, MODULE, "Selecting " + newAlbum);
TreePath path = new TreePath(newAlbum.getPath());//new TreePath(getCurrentGallery().getPathToRoot(newAlbum));
//jAlbumTree.expandPath(path.getParentPath());
// todo: this call doesn't seem to have any effect
//jAlbumTree.makeVisible(path);
jAlbumTree.scrollPathToVisible(path);
jAlbumTree.setSelectionPath(path);
//jAlbumTree.repaint();
// }
//});
// }
//}.transitionStart();
// We've been modified, we are now dirty.
//setDirtyFlag(true);
}
public void slideshow() {
SlideshowFrame sf = new SlideshowFrame();
sf.showSlideshow();
sf.start(getCurrentAlbum().getPicturesList());
}
/**
* Show/hide thumbnails
*
* @param show The new showThumbmails value
*/
public void setShowThumbnails(boolean show) {
GalleryRemote._().properties.setShowThumbnails(show);
if (show) {
if (getCurrentAlbum() != null) {
preloadThumbnails(getCurrentAlbum().getPictures());
}
jPicturesList.setFixedCellHeight(GalleryRemote._().properties.getThumbnailSize().height + 4);
} else {
thumbnailCache.cancelLoad();
jPicturesList.setFixedCellHeight(-1);
}
}
/**
* Show/hide preview
*
* @param show The new showPreview value
*/
public void setShowPreview(boolean show) {
GalleryRemote._().properties.setShowPreview(show);
if (show) {
previewFrame.show();
previewFrame.loader.preparePicture((Picture) jPicturesList.getSelectedValue(), true, true);
} else {
previewFrame.hide();
}
}
/**
* Get a thumbnail from the thumbnail cache
*
* @param p picture whose thumbnail is to be fetched
* @return The thumbnail value
*/
public ImageIcon getThumbnail(Picture p) {
if (p == null) {
return null;
}
ImageIcon thumb = thumbnailCache.getThumbnail(p);
if (thumb == null) {
thumb = ImageUtils.defaultThumbnail;
} else {
thumb = ImageUtils.rotateImageIcon(thumb, p.getAngle(), p.isFlipped(), getGlassPane());
}
return thumb;
}
/**
* Callback from thumbnail cache to notify that a new one has been loaded
*/
public void thumbnailLoadedNotify() {
jPicturesList.repaint();
}
/**
* Show About Box
*/
public void showAboutBox() {
try {
AboutBox ab = new AboutBox(this);
ab.setVisible(true);
} catch (Exception err) {
Log.logException(Log.LEVEL_ERROR, MODULE, err);
}
}
public void doCut() {
doCopy();
deleteSelectedPictures();
// We've been modified, we are now dirty.
//setDirtyFlag(true);
}
public void doCopy() {
if (jPicturesList.isEnabled() && jPicturesList.getSelectedIndices().length > 0) {
ps = new PictureSelection(jPicturesList);
}
}
public void doPaste() {
if (jPicturesList.isEnabled() && ps != null && !ps.isEmpty()) {
getCurrentAlbum().addPictures(ps, jPicturesList.getSelectedIndex());
}
// We've been modified, we are now dirty.
//setDirtyFlag(true);
}
private void jbInit()
throws Exception {//{{{
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
getContentPane().setLayout(new GridBagLayout());
jTopPanel.setLayout(new GridBagLayout());
jBottomPanel.setLayout(gridLayout1);
gridLayout1.setHgap(5);
jAlbumPanel.setLayout(new BorderLayout());
jLabel1.setText(GRI18n.getString(MODULE, "Gallery_URL"));
jLoginButton.setText(GRI18n.getString(MODULE, "Log_in"));
jLoginButton.setToolTipText(GRI18n.getString(MODULE, "loginButtonTip"));
jLoginButton.setActionCommand("Fetch");
jLoginButton.setIcon(GalleryRemote.iLogin);
jNewAlbumButton.setText(GRI18n.getString(MODULE, "newAlbmBtnTxt"));
jNewAlbumButton.setToolTipText(GRI18n.getString(MODULE, "newAlbmBtnTip"));
jNewAlbumButton.setActionCommand("NewAlbum");
jNewAlbumButton.setIcon(GalleryRemote.iNewAlbum);
jUploadButton.setText(GRI18n.getString(MODULE, "upldBtnTxt"));
jUploadButton.setActionCommand("Upload");
jUploadButton.setToolTipText(GRI18n.getString(MODULE, "upldBtnTip"));
jInspectorDivider.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
jInspectorDivider.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)), GRI18n.getString(MODULE, "inspDvdr")));
jInspectorDivider.setOneTouchExpandable(true);
jInspectorDivider.setResizeWeight(.66);
jAlbumPictureDivider.setOneTouchExpandable(true);
jAlbumPictureDivider.setResizeWeight(.5);
jTopPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)), GRI18n.getString(MODULE, "panel1")));
jBrowseButton.setText(GRI18n.getString(MODULE, "brwsBtnTxt"));
jBrowseButton.setActionCommand("Browse");
jBrowseButton.setToolTipText(GRI18n.getString(MODULE, "brwsBtnTip"));
//jSortAlternativesButton.setText(GRI18n.getString(MODULE, "sortBtnTxt"));
jSortCombo.setActionCommand("SortAlternative");
jSortCombo.setToolTipText(GRI18n.getString(MODULE, "sortAlternativesBtnTip"));
jSortButton.setActionCommand("Sort");
jSortButton.setToolTipText(GRI18n.getString(MODULE, "sortBtnTip"));
jSortButton.setText(GRI18n.getString(MODULE, "sortBtnTxt"));
jGalleryCombo.setActionCommand("Url");
jGalleryCombo.setToolTipText(GRI18n.getString(MODULE, "gllryCombo"));
jMenuFile.setText(GRI18n.getString(MODULE, "menuFile"));
/*jMenuItemNew.setText(GRI18n.getString(MODULE, "menuNew"));
jMenuItemNew.setActionCommand("File.New");
jMenuItemNew.setIcon(GalleryRemote.iNew);
jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, GalleryRemote.ACCELERATOR_MASK));*/
// todo: save
/*jMenuItemOpen.setText(GRI18n.getString(MODULE, "menuOpen"));
jMenuItemOpen.setActionCommand("File.Open");
jMenuItemOpen.setIcon(GalleryRemote.iOpen);
jMenuItemOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, GalleryRemote.ACCELERATOR_MASK));
jMenuItemSave.setText(GRI18n.getString(MODULE, "menuSave"));
jMenuItemSave.setActionCommand("File.Save");
jMenuItemSave.setIcon(GalleryRemote.iSave);
jMenuItemSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, GalleryRemote.ACCELERATOR_MASK));
jMenuItemSaveAs.setText(GRI18n.getString(MODULE, "menuSaveAs"));
jMenuItemSaveAs.setActionCommand("File.SaveAs");
// todo: saving disabled, since JSX doesn't work with new class structure
// todo: save
jMenuItemOpen.setEnabled(false);
jMenuItemSave.setEnabled(false);
jMenuItemSaveAs.setEnabled(false);*/
/*jMenuItemClose.setText(GRI18n.getString(MODULE, "menuClose"));
jMenuItemClose.setActionCommand("File.Close");
if (GalleryRemote.IS_MAC_OS_X) {
jMenuItemClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, GalleryRemote.ACCELERATOR_MASK));
} else {
jMenuItemClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, GalleryRemote.ACCELERATOR_MASK));
}*/
jMenuItemQuit.setText(GRI18n.getString(MODULE, "menuQuit"));
jMenuItemQuit.setActionCommand("File.Quit");
jMenuItemQuit.setIcon(GalleryRemote.iQuit);
jMenuItemQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, GalleryRemote.ACCELERATOR_MASK));
jMenuEdit.setText(GRI18n.getString(MODULE, "menuEdit"));