/
MainFrame.java
1285 lines (1070 loc) · 39 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;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.*;
import java.text.NumberFormat;
import java.util.Collections;
import java.lang.reflect.Method;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.gallery.GalleryRemote.model.Album;
import com.gallery.GalleryRemote.model.Gallery;
import com.gallery.GalleryRemote.model.Picture;
import com.gallery.GalleryRemote.util.ImageUtils;
import com.gallery.GalleryRemote.util.GRI18n;
import com.gallery.GalleryRemote.util.OsShutdown;
import com.gallery.GalleryRemote.prefs.PreferencesDialog;
import com.gallery.GalleryRemote.prefs.PropertiesFile;
import com.gallery.GalleryRemote.prefs.URLPanel;
import JSX.ObjOut;
import JSX.ObjIn;
/**
* Description of the Class
*
*@author jackodog
*@author paour
*@created August 16, 2002
*/
public class MainFrame extends javax.swing.JFrame
implements ActionListener, ItemListener, ListSelectionListener,
ListDataListener {
public static final String MODULE = "MainFrame";
public static final String FILE_TYPE = ".grg";
PreviewFrame previewFrame = null;
public DefaultComboBoxModel galleries = null;
//private Gallery currentGallery = null;
//private Album currentAlbum = null;
private boolean inProgress = false;
ThumbnailCache thumbnailCache = new ThumbnailCache( this );
boolean running = true;
public StatusBar jStatusBar = new StatusBar(this);
JPanel jPanel1 = new JPanel();
JMenuBar jMenuBar1 = new JMenuBar();
JLabel jLabel1 = new JLabel();
JLabel jLabel7 = new JLabel();
JPanel jPanel3 = new JPanel();
GridLayout gridLayout1 = new GridLayout();
GridBagLayout gridBagLayout3 = new GridBagLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JList jPicturesList = new DroppableList();
JComboBox jAlbumCombo = new JComboBox();
JComboBox jGalleryCombo = new JComboBox();
JButton jNewGalleryButton = new JButton();
JButton jLoginButton = new JButton();
JButton jNewAlbumButton = new JButton();
JSplitPane jInspectorDivider = new JSplitPane();
PictureInspector jPictureInspector = new PictureInspector();
JButton jUploadButton = new JButton();
JButton jBrowseButton = new JButton();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuItemQuit = new JMenuItem();
JMenuItem jMenuItemSave = new JMenuItem();
JMenuItem jMenuItemOpen = new JMenuItem();
JMenuItem jMenuItemPrefs = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuItemAbout = new JMenuItem();
JMenu jMenuOptions = new JMenu();
JCheckBoxMenuItem jCheckBoxMenuThumbnails = new JCheckBoxMenuItem();
JCheckBoxMenuItem jCheckBoxMenuPreview = new JCheckBoxMenuItem();
JCheckBoxMenuItem jCheckBoxMenuPath = new JCheckBoxMenuItem();
public static ImageIcon iLogin;
public static ImageIcon iNewGallery;
public static ImageIcon iAbout;
public static ImageIcon iSave;
public static ImageIcon iOpen;
public static ImageIcon iPreferences;
public static ImageIcon iNewAlbum;
public static ImageIcon iQuit;
public static ImageIcon iUp;
public static ImageIcon iDown;
public static ImageIcon iDelete;
public static ImageIcon iRight;
public static ImageIcon iLeft;
public static ImageIcon iFlip;
public static ImageIcon iComputer;
public static ImageIcon iUploading;
public static boolean IS_MAC_OS_X = (System.getProperty("mrj.version") != null);
//final static int MENU_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
public static GRI18n grRes = GRI18n.getInstance();
/**
* Constructor for the MainFrame object
*/
public MainFrame() {
macOSXRegistration();
PropertiesFile p = GalleryRemote.getInstance().properties;
// load galleries
galleries = new DefaultComboBoxModel();
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.ERROR, MODULE, "Error trying to load Gallery profile " + i);
Log.logException(Log.ERROR, MODULE, e);
}
}
// if no galleries available, create a blank one
/*if ( galleries.getSize() == 0 ) {
Gallery g = new Gallery(this);
galleries.addElement( g );
}*/
setIconImage(GalleryRemote.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);
}
});
}
}
/**
* Initialize the graphical components
*
*@exception Exception Description of Exception
*/
public void initComponents()
throws Exception {
try {
jbInit();
jbInitEvents();
} catch ( Exception e ) {
Log.logException(Log.CRITICAL, MODULE, e);
}
setBounds( GalleryRemote.getInstance().properties.getMainBounds() );
setJMenuBar( jMenuBar1 );
setTitle( "Gallery Remote" );
jPicturesList.setCellRenderer( new FileCellRenderer() );
( (DroppableList) jPicturesList ).setMainFrame( this );
jPictureInspector.setMainFrame( this );
setGalleries(galleries);
jInspectorDivider.setDividerLocation( GalleryRemote.getInstance().properties.getIntProperty( "inspectorDividerLocation" ) );
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.getInstance().properties.getShowPreview() ) {
previewFrame.setVisible( true );
}
toFront();
readPreferences(GalleryRemote.getInstance().properties);
//new UploadProgress();
}
private void setGalleries(DefaultComboBoxModel galleries) {
this.galleries = galleries;
jGalleryCombo.setModel( galleries );
galleries.addListDataListener(this);
updateGalleryParams();
}
/**
* 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) {
if (running) {
running = false;
Log.log(Log.INFO, MODULE, "Shutting down GR");
try {
PropertiesFile p = GalleryRemote.getInstance().properties;
p.setMainBounds( getBounds() );
p.setPreviewBounds( previewFrame.getBounds() );
p.setIntProperty( "inspectorDividerLocation", jInspectorDivider.getDividerLocation() );
p.write();
if (!halt) {
// in halt mode, this crashes the VM
setVisible( false );
dispose();
}
ImageUtils.purgeTemp();
} catch (Throwable t) {
Log.log(Log.ERROR, MODULE, "Error while closing: " + t);
}
if (shutdownOs) {
OsShutdown.shutdown();
}
Log.log(Log.INFO, MODULE, "Shutting down log");
Log.shutdown();
if (!halt) {
// no need for this in halt mode
Runtime.getRuntime().exit(0);
}/* else {
Runtime.getRuntime().exit(0);
}*/
}
}
void setInProgress(boolean inProgress) {
this.inProgress = inProgress;
resetUIState();
}
void resetUIState() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// if the list is empty or comm, disable upload
jUploadButton.setEnabled( getCurrentAlbum() != null
&& getCurrentAlbum().sizePictures() > 0
&& !inProgress
&& jAlbumCombo.getSelectedIndex() >= 0 );
Gallery currentGallery = getCurrentGallery();
// during comm, don't change Gallery or do any other comm
jLoginButton.setEnabled( !inProgress && currentGallery != null);
jGalleryCombo.setEnabled( !inProgress );
jNewGalleryButton.setEnabled( !inProgress );
if (currentGallery != null
&& currentGallery.getUsername() != null
&& currentGallery.hasComm()
&& currentGallery.getComm(jStatusBar).isLoggedIn()) {
jLoginButton.setText(grRes.getString(MODULE, "Log_out"));
} else {
jLoginButton.setText(grRes.getString(MODULE, "Log_in"));
}
// if the selected album is uploading, disable everything
boolean enabled = ! inProgress && getCurrentAlbum() != null && jAlbumCombo.getModel().getSize() >= 1;
jBrowseButton.setEnabled( enabled && getCurrentAlbum().getCanAdd());
jPictureInspector.setEnabled( enabled );
jPicturesList.setEnabled( enabled && getCurrentAlbum().getCanAdd());
jAlbumCombo.setEnabled( enabled );
jNewAlbumButton.setEnabled( !inProgress && currentGallery != null && currentGallery.hasComm()
&& currentGallery.getComm(jStatusBar).hasCapability(GalleryCommCapabilities.CAPA_NEW_ALBUM));
// change image displayed
int sel = jPicturesList.getSelectedIndex();
/*if (mAlbum != null && mAlbum.getSize() < 1) {
// if album was just emptied, it takes a while for the pictureList
// to notice...
// this is fixed by using invokeLater
sel = -1;
}*/
if ( GalleryRemote.getInstance().properties.getShowPreview() && previewFrame != null ) {
if ( sel != -1 ) {
previewFrame.displayFile( getCurrentAlbum().getPicture( sel ) );
} else {
previewFrame.displayFile( null );
}
if ( !previewFrame.isVisible() ) {
previewFrame.setVisible( true );
}
}
// status
if ( getCurrentAlbum() == null) {
jPictureInspector.setPictures( null );
jStatusBar.setStatus(grRes.getString(MODULE, "notLogged") );
} else if ( getCurrentAlbum().sizePictures() > 0 ) {
jPictureInspector.setPictures( jPicturesList.getSelectedValues() );
int selN = jPicturesList.getSelectedIndices().length;
String statusMsg;
Object [] params = {new Integer(getCurrentAlbum().sizePictures()),
new Integer((int)(getCurrentAlbum().getPictureFileSize() / 1024))};
if ( sel == -1 ) {
jStatusBar.setStatus(grRes.getString(MODULE, "statusBarNoSel", params ));
} else {
jStatusBar.setStatus("Selected " + selN + ((selN == 1)?" picture / ":" pictures / ")
+ NumberFormat.getInstance().format(
( (int) Album.getObjectFileSize( jPicturesList.getSelectedValues() ) / 1024 ) )
+ " K" );
}
} else {
jPictureInspector.setPictures( null );
jStatusBar.setStatus("No selection" );
}
}});
}
private void updateGalleryParams() {
Log.log(Log.TRACE, MODULE, "updateGalleryParams: current gallery: " + getCurrentGallery());
updateAlbumCombo();
}
private void updateAlbumCombo() {
Gallery currentGallery = getCurrentGallery();
Log.log(Log.TRACE, MODULE, "updateAlbumCombo: current gallery: " + currentGallery);
if (currentGallery != null && jAlbumCombo.getModel() != currentGallery) {
jAlbumCombo.setModel( currentGallery );
currentGallery.addListDataListener(this);
}
if (currentGallery == null || currentGallery.getSize() < 1) {
jAlbumCombo.setEnabled( false );
jPicturesList.setEnabled( false );
updatePicturesList();
} else {
jAlbumCombo.setEnabled( ! inProgress );
updatePicturesList();
}
}
private void updatePicturesList() {
Album currentAlbum = getCurrentAlbum();
Log.log(Log.TRACE, MODULE, "updatePicturesList: current album: " + currentAlbum);
if (currentAlbum == null) {
// fake empty album to clear the list
jPicturesList.setModel( new Album() );
} 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("Select pictures to add to the list" );
File[] files = AddFileDialog.addFiles( this );
if ( files != null ) {
addPictures( files );
}
//resetUIState();
}
/**
* Adds a feature to the Pictures attribute of the MainFrame object
*
*@param files The feature to be added to the Pictures attribute
*/
public void addPictures( File[] files ) {
addPictures( files, -1 );
//resetUIState();
}
/**
* Adds a feature to the Pictures attribute of the MainFrame object
*
*@param files The feature to be added to the Pictures attribute
*@param index The index in the list of Pictures at which to begin adding
*/
public void addPictures( File[] files, int index ) {
if (index == -1) {
getCurrentAlbum().addPictures( files );
} else {
getCurrentAlbum().addPictures( files, index );
}
/*Arrays.sort( items,
new Comparator()
{
public int compare( Object o1, Object o2 )
{
String f1 = ( (File) o1 ).getAbsolutePath();
String f2 = ( (File) o2 ).getAbsolutePath();
return ( f1.compareToIgnoreCase( f2 ) );
}
public boolean equals( Object o1, Object o2 )
{
String f1 = ( (File) o1 ).getAbsolutePath();
String f2 = ( (File) o2 ).getAbsolutePath();
return ( f1.equals( f2 ) );
}
} );*/
thumbnailCache.preloadThumbnailFiles( files );
//resetUIState();
}
/**
* Upload the files
*/
public void uploadPictures() {
Log.log(Log.INFO, MODULE, "uploadPictures starting");
File f = new File(System.getProperty("user.home")
+ File.separator + ".GalleryRemote"
+ File.separator + "backup.grg");
saveState(f);
getCurrentGallery().uploadFiles( new UploadProgress(this) );
}
/**
* Fetch Albums from server and update UI
*/
public void fetchAlbums() {
Log.log(Log.INFO, MODULE, "fetchAlbums starting");
getCurrentGallery().fetchAlbums( jStatusBar );
//updateAlbumCombo();
if (jAlbumCombo.getModel().getSize() > 0) {
jAlbumCombo.setSelectedIndex(0);
}
}
public void newAlbum() {
NewAlbumDialog dialog = new NewAlbumDialog(this, getCurrentGallery(), getCurrentAlbum());
final String newAlbumName = dialog.getNewAlbumName();
Log.log(Log.TRACE, MODULE, "Album '" + newAlbumName + "' created. Selecting it...");
// 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) {
e.printStackTrace();
}
jAlbumCombo.setSelectedItem(getCurrentGallery().getAlbumByName(newAlbumName));
}
}.start();
}
/**
* Delete Pictures that are selected in the list
*/
public void deleteSelectedPictures() {
int[] indices = jPicturesList.getSelectedIndices();
getCurrentAlbum().removePictures( indices );
}
/**
* Move selected Pictures up
*/
public void movePictureUp() {
int sel = jPicturesList.getSelectedIndex();
if ( sel > 0 ) {
Picture buf = getCurrentAlbum().getPicture( sel );
getCurrentAlbum().setPicture( sel, getCurrentAlbum().getPicture( sel - 1 ) );
getCurrentAlbum().setPicture( sel - 1, buf );
jPicturesList.setSelectedIndex( sel - 1 );
}
}
/**
* Move selected Pictures down
*/
public void movePictureDown() {
int sel = jPicturesList.getSelectedIndex();
if ( sel < getCurrentAlbum().sizePictures() - 1 ) {
Picture buf = getCurrentAlbum().getPicture( sel );
getCurrentAlbum().setPicture( sel, getCurrentAlbum().getPicture( sel + 1 ) );
getCurrentAlbum().setPicture( sel + 1, buf );
jPicturesList.setSelectedIndex( sel + 1 );
}
}
public void selectNextPicture() {
int i = jPicturesList.getSelectedIndex();
if (i < jPicturesList.getModel().getSize() - 1) {
jPicturesList.setSelectedIndex(i + 1);
}
}
public void selectPrevPicture() {
int i = jPicturesList.getSelectedIndex();
if (i > 0) {
jPicturesList.setSelectedIndex(i - 1);
}
}
/**
* Show/hide thumbnails
*
*@param show The new showThumbmails value
*/
public void setShowThumbnails( boolean show ) {
GalleryRemote.getInstance().properties.setShowThumbnails( show );
if ( show ) {
if ( getCurrentAlbum() != null ) {
thumbnailCache.preloadThumbnailPictures( getCurrentAlbum().getPictures() );
}
jPicturesList.setFixedCellHeight( GalleryRemote.getInstance().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.getInstance().properties.setShowPreview( show );
if ( show ) {
previewFrame.show();
} else {
previewFrame.hide();
}
}
/**
* Get a thumbnail from the thumbnail cache
*
*@param filename Description of Parameter
*@return The thumbnail value
*/
public ImageIcon getThumbnail( String filename ) {
if ( filename == null ) {
return null;
}
ImageIcon r = thumbnailCache.getThumbnail( filename );
if ( r == null ) {
r = ImageUtils.defaultThumbnail;
}
return r;
}
/**
* 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 ) {
ImageIcon thumb = getThumbnail( p.getSource().getPath() );
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 ) {
err.printStackTrace();
}
}
private void jbInit()
throws Exception {//{{{
this.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
this.getContentPane().setLayout( new GridBagLayout() );
jPanel1.setLayout( new GridBagLayout() );
jLabel1.setText( grRes.getString(MODULE, "Gallery_URL") );
jLabel7.setText( grRes.getString(MODULE, "Select_Album") );
jLoginButton.setText( "Log in" );
jLoginButton.setToolTipText("Connect or disconnect from the selected Gallery. " +
"You can be connected to more than one Gallery simultaneously.");
//jLoginButton.setNextFocusableComponent( jNewAlbumButton );
jLoginButton.setActionCommand( "Fetch" );
jLoginButton.setIcon(iLogin);
jNewAlbumButton.setText("New Album..." );
jNewAlbumButton.setToolTipText("Create a new Album in the selected Gallery");
//jNewAlbumButton.setNextFocusableComponent( jAlbumCombo );
jNewAlbumButton.setActionCommand( "NewAlbum" );
jNewAlbumButton.setIcon(iNewAlbum);
jPanel3.setLayout( gridLayout1 );
jUploadButton.setAlignmentX( (float) 2.0 );
jUploadButton.setText( "Upload pictures" );
jUploadButton.setActionCommand( "Upload" );
jUploadButton.setToolTipText( "Upload images that have been added to any and all " +
"albums, even if they are not currently showing" );
jInspectorDivider.setBorder( new TitledBorder( BorderFactory.createEtchedBorder( Color.white, new Color( 148, 145, 140 ) ), "Pictures to Upload (Drag and Drop files into this panel)" ) );
jPanel1.setBorder( new TitledBorder( BorderFactory.createEtchedBorder( Color.white, new Color( 148, 145, 140 ) ), "Destination Gallery" ) );
jBrowseButton.setAlignmentX( (float) 1.0 );
jBrowseButton.setText( "Add pictures..." );
jBrowseButton.setActionCommand( "Browse" );
jBrowseButton.setToolTipText("Find images to add to the currently selected album.\n" +
"This button is disabled, if the currently selected album " +
"is read-only or you're not logged in.");
jGalleryCombo.setActionCommand("Url");
jGalleryCombo.setToolTipText("Select a Gallery to which you want to log in");
gridLayout1.setHgap( 5 );
jMenuFile.setText( "File" );
jMenuItemQuit.setText( "Quit" );
jMenuItemQuit.setActionCommand( "File.Quit" );
jMenuItemQuit.setIcon(iQuit);
jMenuItemSave.setText( "Save..." );
jMenuItemSave.setActionCommand( "File.Save" );
jMenuItemSave.setIcon(iSave);
jMenuItemPrefs.setText( "Preferences..." );
jMenuItemPrefs.setActionCommand( "Options.Prefs" );
jMenuItemPrefs.setIcon(iPreferences);
jMenuItemOpen.setText( "Open..." );
jMenuItemOpen.setActionCommand( "File.Open" );
jMenuItemOpen.setIcon(iOpen);
jMenuHelp.setText( "Help" );
jMenuItemAbout.setActionCommand( "Help.About" );
jMenuItemAbout.setText( "About Gallery Remote..." );
jMenuItemAbout.setIcon(iAbout);
jMenuOptions.setText( "Options" );
jCheckBoxMenuThumbnails.setActionCommand( "Options.Thumbnails" );
jCheckBoxMenuThumbnails.setText( "Show Thumbnails" );
jCheckBoxMenuPreview.setActionCommand( "Options.Preview" );
jCheckBoxMenuPreview.setText( "Show Preview" );
jCheckBoxMenuPath.setActionCommand( "Options.Path" );
jCheckBoxMenuPath.setText( "Show Path" );
jScrollPane1.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
jNewGalleryButton.setText("Add Gallery URL...");
jNewGalleryButton.setActionCommand("NewGallery");
jNewGalleryButton.setIcon(iNewGallery);
jAlbumCombo.setActionCommand("Album");
jAlbumCombo.setToolTipText("Select an Album here and add pictures to it. The number in parenthesis " +
"after the name of the album is the number of pictures that you've added to it.");
this.getContentPane().add( jPanel1, new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0
, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets( 2, 2, 2, 2 ), 0, 0 ) );
jPanel1.add( jLabel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 5 ), 0, 0 ) );
this.getContentPane().add( jInspectorDivider, new GridBagConstraints( 0, 1, 1, 1, 1.0, 1.0
, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 0, 2, 2, 2 ), 0, 0 ) );
jInspectorDivider.add( jPictureInspector, JSplitPane.BOTTOM );
jInspectorDivider.add( jScrollPane1, JSplitPane.TOP );
jScrollPane1.getViewport().add( jPicturesList, null );
this.getContentPane().add( jPanel3, new GridBagConstraints( 0, 2, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 5, 5, 5, 5 ), 0, 0 ) );
jPanel3.add( jBrowseButton, null );
jPanel3.add( jUploadButton, null );
this.getContentPane().add( jStatusBar, new GridBagConstraints( 0, 3, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) );
jPanel1.add( jGalleryCombo, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0) );
jPanel1.add(jNewGalleryButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0));
jPanel1.add(jLabel7, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
jPanel1.add(jAlbumCombo, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
jPanel1.add(jLoginButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
jPanel1.add(jNewAlbumButton, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
jMenuBar1.add( jMenuFile );
jMenuBar1.add( jMenuOptions );
jMenuBar1.add( jMenuHelp );
jMenuFile.add( jMenuItemOpen );
jMenuFile.add( jMenuItemSave );
// 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);
}
if (!IS_MAC_OS_X) {
jMenuFile.addSeparator();
jMenuFile.add( jMenuItemQuit );
jMenuHelp.add( jMenuItemAbout );
}
jMenuOptions.add( jCheckBoxMenuThumbnails );
jMenuOptions.add( jCheckBoxMenuPreview );
jMenuOptions.add( jCheckBoxMenuPath );
if (!IS_MAC_OS_X) {
jMenuOptions.addSeparator();
jMenuOptions.add( jMenuItemPrefs );
}
}//}}}
private void jbInitEvents() {
jLoginButton.addActionListener( this );
jNewAlbumButton.addActionListener( this );
jUploadButton.addActionListener( this );
jBrowseButton.addActionListener( this );
jNewGalleryButton.addActionListener( this );
//jGalleryCombo.addActionListener( this );
jMenuItemPrefs.addActionListener( this );
jMenuItemSave.addActionListener( this );
jMenuItemOpen.addActionListener( this );
jMenuItemQuit.addActionListener( this );
jMenuItemAbout.addActionListener( this );
jCheckBoxMenuThumbnails.addItemListener( this );
jCheckBoxMenuPreview.addItemListener( this );
jCheckBoxMenuPath.addItemListener( this );
// in Swing 1.3, using an ItemListener for a JComboBox doesn't work,
// using ActionListener instead
//album.addItemListener( this );
//jAlbumCombo.addActionListener( this );
jPicturesList.addListSelectionListener( this );
addWindowListener(
new java.awt.event.WindowAdapter()
{
public void windowClosing( java.awt.event.WindowEvent e ) {
thisWindowClosing( e );
}
} );
jPicturesList.addKeyListener(
new KeyAdapter()
{
public void keyPressed( KeyEvent e ) {
jListKeyPressed( e );
}
} );
}
// Event handling
/**
* Menu, button and field handling
*
*@param e Action event
*/
public void actionPerformed( ActionEvent e ) {
String command = e.getActionCommand();
Log.log(Log.INFO, MODULE, "Command selected " + command);
//Log.log(Log.TRACE, MODULE, " event " + e );
if ( command.equals( "File.Quit" ) ) {
thisWindowClosing( null );
} else if ( command.equals( "File.Save" ) ) {
saveState();
} else if ( command.equals( "File.Open" ) ) {
openState();
} else if ( command.equals( "Options.Prefs" ) ) {
showPreferencesDialog();
} else if ( command.equals( "Help.About" ) ) {
showAboutBox();
} else if ( command.equals( "Fetch" ) ) {
if (getCurrentGallery().hasComm() && getCurrentGallery().getComm(jStatusBar).isLoggedIn()) {
// we're currently logged in: log out
getCurrentGallery().logOut();
//if (getCurrentAlbum() != null) {
// getCurrentAlbum().clearPictures();
//}
//setCurrentAlbum(null);
//jAlbumCombo.setModel(new Gallery(this));
//resetUIState();
} else {
// login may have failed and caused getComm to be null.
GalleryComm comm = getCurrentGallery().getComm(jStatusBar);
// may have tried to connect and failed
if (comm != null && !GalleryComm.wasAuthFailure()) {
fetchAlbums();
}
}
} else if ( command.equals( "NewAlbum" ) ) {
newAlbum();
} else if ( command.equals( "Browse" ) ) {
browseAddPictures();
} else if ( command.equals( "Upload" ) ) {
uploadPictures();
} else if ( command.equals( "NewGallery" ) ) {
showPreferencesDialog(URLPanel.class.getName());
//} else if ( command.equals( "Url" ) ) {
//Object selectedGallery = jGalleryCombo.getSelectedItem();
//if (selectedGallery != null) {
//Log.log(Log.TRACE, MODULE, "selected: " + selectedGallery.toString()
// + " (" + jGalleryCombo.getSelectedIndex() + ")");
// new url chosen in the popup
// updateGalleryParams();
// } else {
// Log.log(Log.TRACE, MODULE, "Deselected gallery");
// }
//} else if ( command.equals( "Album" ) ) {
//Object selectedAlbum = jAlbumCombo.getSelectedItem();
// Log.log(Log.TRACE, MODULE, "selected: " + selectedAlbum.toString()
// + " (" + jAlbumCombo.getSelectedIndex() + ")");
//updatePicturesList( /*(Album) ( (JComboBox) e.getSource() ).getSelectedItem()*/);
} else {
Log.log(Log.ERROR, MODULE, "Unhandled command " + command );
}
}
public void showPreferencesDialog() {
showPreferencesDialog(null);
}
private void showPreferencesDialog(String panel) {
PropertiesFile oldProperties = (PropertiesFile) GalleryRemote.getInstance().properties.clone();
PreferencesDialog pd = new PreferencesDialog(this);
if (panel != null) {
pd.setPanel(panel);
}
// modal dialog
pd.setVisible(true);
// user clicked OK
if (pd.isOK()) {
readPreferences(oldProperties);
}
}
public void readPreferences(PropertiesFile op) {
PropertiesFile p = GalleryRemote.getInstance().properties;
p.write();
jCheckBoxMenuThumbnails.setSelected( p.getShowThumbnails() );
jCheckBoxMenuPreview.setSelected( p.getShowPreview() );
jCheckBoxMenuPath.setSelected( p.getShowPath() );
previewFrame.setVisible( p.getShowPreview() );
setShowThumbnails( p.getShowThumbnails() );
if (!op.getThumbnailSize().equals(p.getThumbnailSize())) {
thumbnailCache.reload();
}
Log.setMaxLevel();
}
static FileFilter galleryFileFilter = new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().endsWith(FILE_TYPE);
}
public String getDescription() {
return "GalleryRemote galleries";
}
};
private void saveState() {
JFileChooser fc = new JFileChooser();
fc.setAcceptAllFileFilterUsed(false);
fc.setFileFilter(galleryFileFilter);
int returnVal = fc.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
String name = fc.getSelectedFile().getPath();
if (! name.endsWith(FILE_TYPE) ) {
name += FILE_TYPE;
}
saveState(new File(name));