diff --git a/com/gallery/GalleryRemote/MainFrame.java b/com/gallery/GalleryRemote/MainFrame.java index 932a222..4825579 100644 --- a/com/gallery/GalleryRemote/MainFrame.java +++ b/com/gallery/GalleryRemote/MainFrame.java @@ -31,7 +31,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.text.NumberFormat; -import java.util.Vector; import javax.swing.*; import javax.swing.filechooser.FileFilter; @@ -48,6 +47,7 @@ import com.gallery.GalleryRemote.model.Gallery; import com.gallery.GalleryRemote.model.Picture; import com.gallery.GalleryRemote.util.ImageUtils; +import com.gallery.GalleryRemote.prefs.PreferencesDialog; import JSX.ObjOut; import JSX.ObjIn; @@ -109,6 +109,7 @@ public class MainFrame extends javax.swing.JFrame 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(); @@ -135,22 +136,22 @@ public MainFrame() { try { String username = p.getProperty( "username." + i ); String password = p.getBase64Property( "password." + i ); - + Log.log(Log.INFO, MODULE, "loaded saved URL: " + url + " (" + username + "/******)" ); - + Gallery g = new Gallery( new URL( url ), username, password, /* TEMPORARY */this); - + galleries.addElement(g); } catch (Exception e) { Log.log(Log.ERROR, MODULE, "Error trying to load profile"); Log.logException(Log.ERROR, MODULE, e); } } - + if ( galleries.getSize() == 0 ) { galleries.addElement( new Gallery() ); } - + setIconImage(GalleryRemote.iconImage); } @@ -182,13 +183,9 @@ public void initComponents() gallery.setModel( galleries ); updateGalleryParams(); - + resetUIState(); - jCheckBoxMenuThumbnails.setSelected( GalleryRemote.getInstance().properties.getShowThumbnails() ); - jCheckBoxMenuPreview.setSelected( GalleryRemote.getInstance().properties.getShowPreview() ); - jCheckBoxMenuPath.setSelected( GalleryRemote.getInstance().properties.getShowPath() ); - setShowThumbnails( GalleryRemote.getInstance().properties.getShowThumbnails() ); inspectorDivider.setDividerLocation( GalleryRemote.getInstance().properties.getIntProperty( "inspectorDividerLocation" ) ); setVisible( true ); @@ -198,6 +195,8 @@ public void initComponents() } toFront(); + + readPreferences(GalleryRemote.getInstance().properties); } @@ -211,30 +210,30 @@ void thisWindowClosing( java.awt.event.WindowEvent e ) { PropertiesFile p = GalleryRemote.getInstance().properties; for (int i = 0; i < galleries.getSize(); i++) { Gallery g = (Gallery) galleries.getElementAt(i); - + String url = g.getUrlString(); if ( url != null) { p.setProperty( "url." + i, url ); - + if (g.getUsername() != null) { p.setProperty( "username." + i, g.getUsername() ); } - + if (p.getBooleanProperty("savePasswords") && g.getPassword() != null) { p.setBase64Property( "password." + i, g.getPassword() ); } } } - + p.setMainBounds( getBounds() ); p.setPreviewBounds( previewFrame.getBounds() ); p.setIntProperty( "inspectorDividerLocation", inspectorDivider.getDividerLocation() ); - + p.write(); setVisible( false ); dispose(); - + ImageUtils.purgeTemp(); } catch (Throwable t) { Log.log(Log.ERROR, MODULE, "Error while closing: " + t); @@ -250,17 +249,17 @@ void resetUIState() { public void run() { // if the list is empty or comm, disable upload upload.setEnabled( mAlbum != null - && mAlbum.sizePictures() > 0 + && mAlbum.sizePictures() > 0 && !mInProgress && album.getSelectedIndex() >= 0 ); - + // during comm, don't change Gallery or do any other comm fetch.setEnabled( !mInProgress ); gallery.setEnabled( !mInProgress ); newGallery.setEnabled( !mInProgress ); username.setEnabled( !mInProgress ); password.setEnabled( !mInProgress ); - + if (currentGallery.getUsername() != null && currentGallery.hasComm() && currentGallery.getComm(MainFrame.this).isLoggedIn()) { @@ -268,7 +267,7 @@ public void run() { } else { fetch.setText("Log in"); } - + // if the selected album is uploading, disable everything boolean enabled = ! mInProgress && mAlbum != null && album.getModel().getSize() >= 1; browse.setEnabled( enabled ); @@ -277,7 +276,7 @@ public void run() { album.setEnabled( enabled ); newAlbum.setEnabled( enabled && currentGallery.hasComm() && currentGallery.getComm(MainFrame.this).hasCapability(GalleryCommCapabilities.CAPA_NEW_ALBUM)); - + // change image displayed int sel = picturesList.getSelectedIndex(); /*if (mAlbum != null && mAlbum.getSize() < 1) { @@ -286,7 +285,7 @@ public void run() { // this is fixed by using invokeLater sel = -1; }*/ - + if ( GalleryRemote.getInstance().properties.getShowPreview() ) { if ( sel != -1 ) { String filename = ( mAlbum.getPicture( sel ).getSource() ).getPath(); @@ -294,22 +293,22 @@ public void run() { } else { previewFrame.displayFile( null ); } - + if ( !previewFrame.isVisible() ) { previewFrame.setVisible( true ); } } - + // status if ( mAlbum == null) { pictureInspector.setPictures( null ); - + setStatus( "Select a Gallery URL and click Log in..." ); } else if ( mAlbum.sizePictures() > 0 ) { pictureInspector.setPictures( picturesList.getSelectedValues() ); - + int selN = picturesList.getSelectedIndices().length; - + if ( sel == -1 ) { setStatus( mAlbum.sizePictures() + " pictures / " + NumberFormat.getInstance().format( @@ -323,7 +322,7 @@ public void run() { } } else { pictureInspector.setPictures( null ); - + setStatus( "No selection" ); } }}); @@ -332,7 +331,7 @@ public void run() { private void updateGalleryParams() { currentGallery = (Gallery) gallery.getSelectedItem(); - + Log.log(Log.TRACE, MODULE, "current gallery: " + currentGallery); if ( currentGallery.getUsername() != null ) { username.setText( currentGallery.getUsername() ); @@ -345,7 +344,7 @@ private void updateGalleryParams() { } else { password.setText(""); } - + updateAlbumCombo(); resetUIState(); } @@ -353,24 +352,24 @@ private void updateGalleryParams() { private void updateAlbumCombo() { album.setModel( currentGallery ); - + if (album.getModel().getSize() < 1) { album.setEnabled( false ); picturesList.setEnabled( false ); - + updatePicturesList( null ); } else { // album.setSelectedIndex(0); album.setEnabled( ! mInProgress ); - + updatePicturesList( (Album) album.getSelectedItem() ); } } - + private void updatePicturesList( Album album ) { mAlbum = album; - + if (mAlbum == null) { // fake empty album to clear the list picturesList.setModel( new Album() ); @@ -381,8 +380,8 @@ private void updatePicturesList( Album album ) { pictureInspector.setPictures( null ); } } - - + + public void setStatus( String message ) { if (! progressOn) { // prevent progress message from being overriden @@ -411,7 +410,7 @@ public int startProgress( int min, int max, String message, boolean undetermined progress.setValue(min); progress.setMaximum(max); //progress.setStringPainted( true ); - + if (undetermined && undeterminedThread == null) { undeterminedThread = new Thread() { public void run() { @@ -422,9 +421,9 @@ public void run() { } else if (progress.getValue() <= progress.getMinimum()) { forward = true; } - + updateProgressValue(progressId, progress.getValue() + (forward?1:-1)); - + try { sleep(500); } catch (InterruptedException e) {} @@ -477,7 +476,7 @@ public void stopProgress( int progressId, String message ) if ( progressId == this.progressId ) { progressOn = false; - + if (undeterminedThread != null) { undeterminedThread.interrupt(); undeterminedThread = null; @@ -491,19 +490,19 @@ public void stopProgress( int progressId, String message ) Log.log(Log.TRACE, MODULE, "Wrong progressId when stopping progress"); } } - + public void setInProgress(boolean inProgress) { mInProgress = inProgress; - + resetUIState(); } - - + + public void error (String message ) { JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); } - - + + /** * Open a file selection dialog and load the corresponding files @@ -558,7 +557,7 @@ public boolean equals( Object o1, Object o2 ) return ( f1.equals( f2 ) ); } } );*/ - thumbnailCache.preloadThumbnails( files ); + thumbnailCache.preloadThumbnailFiles( files ); //resetUIState(); } @@ -585,12 +584,12 @@ public void uploadPictures() { */ public void fetchAlbums() { Log.log(Log.INFO, MODULE, "fetchAlbums starting"); - + currentGallery.fetchAlbums( this ); - + updateAlbumCombo(); } - + public void newAlbum() { new NewAlbumDialog(this, currentGallery, mAlbum); } @@ -601,7 +600,7 @@ public void newAlbum() { */ public void deleteSelectedPictures() { int[] indices = picturesList.getSelectedIndices(); - + mAlbum.removePictures( indices ); } @@ -648,7 +647,7 @@ public void setShowThumbnails( boolean show ) { if ( mAlbum != null ) { thumbnailCache.preloadThumbnailFiles( mAlbum.getPictures() ); } - + picturesList.setFixedCellHeight( GalleryRemote.getInstance().properties.getThumbnailSize().height + 4 ); } else { thumbnailCache.cancelLoad(); @@ -763,9 +762,11 @@ private void jbInit() jMenuFile.setText( "File" ); jMenuItemQuit.setText( "Quit" ); jMenuItemQuit.setActionCommand( "File.Quit" ); - jMenuItemSave.setText( "Save" ); + jMenuItemSave.setText( "Save..." ); jMenuItemSave.setActionCommand( "File.Save" ); - jMenuItemOpen.setText( "Open" ); + jMenuItemPrefs.setText( "Preferences..." ); + jMenuItemPrefs.setActionCommand( "File.Prefs" ); + jMenuItemOpen.setText( "Open..." ); jMenuItemOpen.setActionCommand( "File.Open" ); jMenuHelp.setText( "Help" ); jMenuItemAbout.setActionCommand( "Help.About" ); @@ -824,13 +825,20 @@ private void jbInit() ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0) ); jPanel1.add(newGallery, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0)); + jMenuBar1.add( jMenuFile ); jMenuBar1.add( jMenuOptions ); jMenuBar1.add( jMenuHelp ); - jMenuFile.add( jMenuItemSave ); + jMenuFile.add( jMenuItemOpen ); + jMenuFile.add( jMenuItemSave ); + jMenuFile.addSeparator(); + jMenuFile.add( jMenuItemPrefs ); + jMenuFile.addSeparator(); jMenuFile.add( jMenuItemQuit ); + jMenuHelp.add( jMenuItemAbout ); + jMenuOptions.add( jCheckBoxMenuThumbnails ); jMenuOptions.add( jCheckBoxMenuPreview ); jMenuOptions.add( jCheckBoxMenuPath ); @@ -846,6 +854,7 @@ private void jbInitEvents() { gallery.addActionListener( this ); username.addCaretListener( this ); password.addCaretListener( this ); + jMenuItemPrefs.addActionListener( this ); jMenuItemSave.addActionListener( this ); jMenuItemOpen.addActionListener( this ); jMenuItemQuit.addActionListener( this ); @@ -895,13 +904,15 @@ 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( "File.Prefs" ) ) { + showPreferencesDialog(); } else if ( command.equals( "Help.About" ) ) { showAboutBox(); } else if ( command.equals( "Fetch" ) ) { @@ -913,7 +924,7 @@ public void actionPerformed( ActionEvent e ) { mAlbum.clearPictures(); } mAlbum = null; - + resetUIState(); } else { // the first part of this "if" may have tried to reconnect and failed @@ -936,15 +947,15 @@ public void actionPerformed( ActionEvent e ) { command.equals( "comboBoxEdited" ) ) { //Log.log(Log.TRACE, MODULE, "modifiers: " + e.getModifiers()); //Log.log(Log.TRACE, MODULE, "paramString: " + e.paramString()); - Log.log(Log.TRACE, MODULE, "selected: " + gallery.getSelectedItem().toString() + Log.log(Log.TRACE, MODULE, "selected: " + gallery.getSelectedItem().toString() + " (" + gallery.getSelectedIndex() + ")"); - + if (gallery.getSelectedItem() instanceof String) { // text of a url edited try { currentGallery.setUrlString((String) gallery.getSelectedItem()); } catch ( MalformedURLException mue ) { - + JOptionPane.showMessageDialog(this, "Malformed URL", "Error", JOptionPane.ERROR_MESSAGE); } } else { @@ -958,15 +969,36 @@ public void actionPerformed( ActionEvent e ) { } } + private void showPreferencesDialog() { + new PreferencesDialog(this); + } + + public void readPreferences(PropertiesFile op) { + PropertiesFile p = GalleryRemote.getInstance().properties; + + jCheckBoxMenuThumbnails.setSelected( p.getShowThumbnails() ); + jCheckBoxMenuPreview.setSelected( p.getShowPreview() ); + jCheckBoxMenuPath.setSelected( p.getShowPath() ); + setShowThumbnails( p.getShowThumbnails() ); + + previewFrame.setVisible( p.getShowPreview() ); + + setShowThumbnails( p.getShowThumbnails() ); + + if (!op.getThumbnailSize().equals(p.getThumbnailSize())) { + thumbnailCache.reload(); + } + } + static FileFilter galleryFileFilter = new FileFilter() { - public boolean accept(File f) { - return f.isDirectory() || f.getName().endsWith(FILE_TYPE); - } + public boolean accept(File f) { + return f.isDirectory() || f.getName().endsWith(FILE_TYPE); + } - public String getDescription() { - return "GalleryRemote galleries"; - } - }; + public String getDescription() { + return "GalleryRemote galleries"; + } + }; private void saveState() { JFileChooser fc = new JFileChooser(); @@ -1090,7 +1122,7 @@ public void valueChanged( ListSelectionEvent e ) { */ public void contentsChanged( ListDataEvent e ) { Object source = e.getSource(); - + if (source == picturesList) { // Also tell MainFrame (ugly, but works around bug in Swing where when // the list data changes (and nothing remains to be selected), no @@ -1105,7 +1137,7 @@ public void intervalRemoved(ListDataEvent e) {} public void caretUpdate(CaretEvent e) { Object c = e.getSource(); //Log.log(Log.TRACE, MODULE, "caretUpdate: " + e + " (" + c + ")"); - + if (c == username) { currentGallery.setUsername(username.getText()); resetUIState(); @@ -1165,17 +1197,17 @@ public Component getListCellRendererComponent( JList list, Object value, int index, boolean selected, boolean hasFocus ) { super.getListCellRendererComponent( list, value, index, selected, hasFocus ); - + if (value != null && index != -1) { Picture p = mAlbum.getPicture( index ); File f = p.getSource(); - + if ( GalleryRemote.getInstance().properties.getShowThumbnails() ) { ImageIcon icon = getThumbnail( p ); setIcon( icon ); setIconTextGap( 4 + GalleryRemote.getInstance().properties.getThumbnailSize().width - icon.getIconWidth() ); } - + StringBuffer text = new StringBuffer(); text.append("

"); @@ -1194,7 +1226,7 @@ public Component getListCellRendererComponent( } else { setText("dummy"); } - + return this; } } diff --git a/com/gallery/GalleryRemote/prefs/GeneralPanel.java b/com/gallery/GalleryRemote/prefs/GeneralPanel.java new file mode 100644 index 0000000..7dfb256 --- /dev/null +++ b/com/gallery/GalleryRemote/prefs/GeneralPanel.java @@ -0,0 +1,156 @@ +package com.gallery.GalleryRemote.prefs; + +import com.gallery.GalleryRemote.GalleryProperties; +import com.gallery.GalleryRemote.Log; + +import javax.swing.*; +import java.awt.*; +import javax.swing.border.*; + +/** + * Created by IntelliJ IDEA. + * User: paour + * Date: May 8, 2003 + */ +public class GeneralPanel extends PreferencePanel { + public static final String MODULE = "GeneralPa"; + + JLabel icon = new JLabel("General"); + + GridBagLayout gridBagLayout1 = new GridBagLayout(); + JPanel jPanel1 = new JPanel(); + JLabel jLabel1 = new JLabel(); + JTextField thumbnailWidth = new JTextField(); + JLabel jLabel2 = new JLabel(); + JTextField thumbnailHeight = new JTextField(); + JPanel jPanel2 = new JPanel(); + JCheckBox savePasswords = new JCheckBox(); + GridBagLayout gridBagLayout2 = new GridBagLayout(); + JLabel jLabel3 = new JLabel(); + JComboBox logLevel = new JComboBox(new String[] {"Only critical errors", "Critical and normal errors", + "Also print information messages", "detailed, very verbose log"}); + JPanel jPanel3 = new JPanel(); + JPanel jPanel4 = new JPanel(); + JCheckBox updateCheck = new JCheckBox(); + JCheckBox updateCheckBeta = new JCheckBox(); + GridBagLayout gridBagLayout3 = new GridBagLayout(); + JPanel jPanel5 = new JPanel(); + GridBagLayout gridBagLayout4 = new GridBagLayout(); + JPanel jPanel6 = new JPanel(); + JPanel jPanel7 = new JPanel(); + JCheckBox showThumbnails = new JCheckBox(); + + public JLabel getIcon() { + return icon; + } + + public void buildUI() { + } + + public void readProperties(GalleryProperties props) { + showThumbnails.setSelected(props.getBooleanProperty("showThumbnails")); + thumbnailWidth.setText("" + (int) props.getDimensionProperty("thumbnailSize").getWidth()); + thumbnailHeight.setText("" + (int) props.getDimensionProperty("thumbnailSize").getHeight()); + + savePasswords.setSelected(props.getBooleanProperty("savePasswords")); + logLevel.setSelectedIndex(props.getIntProperty("logLevel")); + + updateCheck.setSelected(props.getBooleanProperty("updateCheck")); + updateCheckBeta.setSelected(props.getBooleanProperty("updateCheckBeta")); + } + + public void writeProperties(GalleryProperties props) { + props.setBooleanProperty("showThumbnails", showThumbnails.isSelected()); + + try { + Dimension d = new Dimension(Integer.parseInt(thumbnailWidth.getText()), Integer.parseInt(thumbnailHeight.getText())); + props.setDimensionProperty("thumbnailSize", d); + } catch (Exception e) { + Log.log(Log.ERROR, MODULE, "Thumbnail size should be integer numbers"); + } + + savePasswords.setSelected(props.getBooleanProperty("savePasswords")); + logLevel.setSelectedIndex(props.getIntProperty("logLevel")); + + updateCheck.setSelected(props.getBooleanProperty("updateCheck")); + updateCheckBeta.setSelected(props.getBooleanProperty("updateCheckBeta")); + } + + public GeneralPanel() { + try { + jbInit(); + } + catch(Exception e) { + e.printStackTrace(); + } + } + + private void jbInit() throws Exception { + this.setLayout(gridBagLayout1); + jLabel1.setText("Thumbnail size"); + jPanel1.setLayout(gridBagLayout4); + thumbnailWidth.setMinimumSize(new Dimension(25, 21)); + thumbnailWidth.setPreferredSize(new Dimension(25, 21)); + thumbnailWidth.setToolTipText("Thumbnail width"); + jLabel2.setText("x"); + thumbnailHeight.setMinimumSize(new Dimension(25, 21)); + thumbnailHeight.setPreferredSize(new Dimension(25, 21)); + thumbnailHeight.setToolTipText("Thumbnail height"); + jPanel1.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Thumbnails")); + jPanel2.setLayout(gridBagLayout2); + savePasswords.setToolTipText("Save passwords in the preferences file. They are not encrypted, so " + + "this is a security risk"); + savePasswords.setText("Save passwords"); + jPanel2.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Logging and privacy")); + jLabel3.setText("Log level"); + logLevel.setToolTipText("Gallery Remote generates a log in \"log.txt\" in the application directory. " + + "This sets how verbose the log is."); + logLevel.setActionCommand("comboBoxChanged"); + logLevel.setSelectedIndex(-1); + jPanel4.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Version checks")); + jPanel4.setMaximumSize(new Dimension(32767, 32767)); + jPanel4.setLayout(gridBagLayout3); + updateCheck.setToolTipText("Checking for updates will send an HTTP request to the Gallery community " + + "site whenever Gallery Remote is launched"); + updateCheck.setText("Check for updates"); + updateCheckBeta.setToolTipText("Beta updates are much more frequent than regular releases"); + updateCheckBeta.setText("Check for beta updates"); + showThumbnails.setToolTipText("Show thumbnails in the list of pictures to upload"); + showThumbnails.setText("Show thumbnails"); + this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); + jPanel1.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0)); + jPanel1.add(thumbnailWidth, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + jPanel1.add(jLabel2, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0)); + jPanel1.add(thumbnailHeight, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + jPanel1.add(jPanel6, new GridBagConstraints(4, 1, 1, 1, 1.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + jPanel1.add(showThumbnails, new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + this.add(jPanel2, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); + jPanel2.add(savePasswords, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + jPanel2.add(jLabel3, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0)); + jPanel2.add(logLevel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + jPanel2.add(jPanel3, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + this.add(jPanel4, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + jPanel4.add(updateCheck, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + jPanel4.add(updateCheckBeta, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + jPanel4.add(jPanel5, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + this.add(jPanel7, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0 + ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + } +} + diff --git a/com/gallery/GalleryRemote/prefs/PreferencePanel.java b/com/gallery/GalleryRemote/prefs/PreferencePanel.java new file mode 100644 index 0000000..c66df23 --- /dev/null +++ b/com/gallery/GalleryRemote/prefs/PreferencePanel.java @@ -0,0 +1,22 @@ +package com.gallery.GalleryRemote.prefs; + +import com.gallery.GalleryRemote.GalleryProperties; + +import javax.swing.*; + +/** + * Interface for Preference Panels + * User: paour + * Date: May 8, 2003 + */ +public abstract class PreferencePanel extends JPanel { + public JPanel panel = new JPanel(); + + public abstract JLabel getIcon(); + + public abstract void buildUI(); + + public abstract void readProperties(GalleryProperties props); + + public abstract void writeProperties(GalleryProperties props); +} diff --git a/com/gallery/GalleryRemote/prefs/PreferencesDialog.java b/com/gallery/GalleryRemote/prefs/PreferencesDialog.java new file mode 100644 index 0000000..2bca68c --- /dev/null +++ b/com/gallery/GalleryRemote/prefs/PreferencesDialog.java @@ -0,0 +1,208 @@ +package com.gallery.GalleryRemote.prefs; + +import com.gallery.GalleryRemote.PropertiesFile; +import com.gallery.GalleryRemote.Log; +import com.gallery.GalleryRemote.GalleryRemote; +import com.gallery.GalleryRemote.MainFrame; + +import javax.swing.*; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.util.Properties; +import java.util.ArrayList; +import java.util.Enumeration; +import java.io.IOException; + +/** + * The Preferences dialog + * User: paour + * Date: May 8, 2003 + */ + +public class PreferencesDialog extends JDialog implements ListSelectionListener, ActionListener { + public static final String MODULE = "PrefsDlog"; + + DefaultListModel panels = new DefaultListModel(); + PropertiesFile oldProperties = null; + + JPanel jPanel1 = new JPanel(); + JScrollPane jScrollPane1 = new JScrollPane(); + JList jIcons = new JList(); + JPanel jPanels = new JPanel(); + GridBagLayout gridBagLayout1 = new GridBagLayout(); + CardLayout jPanelsLayout = new CardLayout(); + JPanel jPanel2 = new JPanel(); + JButton jOK = new JButton(); + GridLayout gridLayout1 = new GridLayout(); + JButton jRevert = new JButton(); + JButton jCancel = new JButton(); + + public PreferencesDialog(Frame owner) { + super(owner, true); + oldProperties = (PropertiesFile) GalleryRemote.getInstance().properties.clone(); + + try { + jbInit(); + } catch(Exception e) { + Log.logException(Log.ERROR, MODULE, e); + } + + loadPanes(); + + jIcons.setSelectedIndex(0); + + pack(); + Dimension s = owner.getSize(); + setLocation( (int) ( s.getWidth() - getWidth() ) / 2, (int) ( s.getHeight() - getHeight() ) / 2 ); + + setVisible( true ); + } + + private void loadPanes() { + Properties panes = new Properties(); + try { + panes.load(getClass().getResourceAsStream("panes.properties")); + + int i = 1; + String className = null; + while ((className = panes.getProperty("pane." + i++)) != null) { + try { + PreferencePanel pp = (PreferencePanel) Class.forName(className).newInstance(); + + pp.buildUI(); + pp.readProperties(GalleryRemote.getInstance().properties); + + panels.addElement(pp); + + jPanels.add(className, pp); + } catch (Exception e) { + Log.log(Log.ERROR, MODULE, "Bad panel: " + className); + Log.logException(Log.ERROR, MODULE, e); + } + } + + jIcons.setModel(panels); + } catch (IOException e) { + Log.logException(Log.ERROR, MODULE, e); + } + } + + private void jbInit() throws Exception { + jPanel1.setLayout(gridBagLayout1); + jScrollPane1.setAlignmentY((float) 0.5); + jScrollPane1.setPreferredSize(new Dimension(100, 200)); + jPanels.setLayout(jPanelsLayout); + this.setTitle("Gallery Remote preferences"); + jOK.setMnemonic('0'); + jOK.setText("OK"); + jPanel2.setLayout(gridLayout1); + jRevert.setText("Revert"); + jCancel.setText("Cancel"); + gridLayout1.setHgap(5); + this.getContentPane().add(jPanel1, BorderLayout.CENTER); + jPanel1.add(jScrollPane1, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0 + ,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(10, 10, 0, 0), 0, 0)); + jPanel1.add(jPanels, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0 + ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 0, 10), 0, 0)); + jPanel1.add(jPanel2, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); + jPanel2.add(jOK, null); + jScrollPane1.getViewport().add(jIcons, null); + jPanel2.add(jCancel, null); + jPanel2.add(jRevert, null); + + jIcons.setCellRenderer(new IconsCellRenderer()); + jIcons.addListSelectionListener(this); + jOK.addActionListener(this); + jCancel.addActionListener(this); + jRevert.addActionListener(this); + + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + } + + public void valueChanged(ListSelectionEvent e) { + String className = jIcons.getSelectedValue().getClass().getName(); + Log.log(Log.TRACE, MODULE, "Showing panel: " + className); + + jPanelsLayout.show(jPanels, className); + + pack(); + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + Log.log(Log.INFO, MODULE, "Command selected " + cmd); + + if (cmd.equals("OK")) { + GalleryRemote.getInstance().properties.uncache(); + + Enumeration enum = panels.elements(); + while (enum.hasMoreElements()) { + PreferencePanel pp = (PreferencePanel) enum.nextElement(); + + pp.writeProperties(GalleryRemote.getInstance().properties); + } + + setVisible(false); + + Log.log(Log.TRACE, MODULE, "Updating preferences"); + ((MainFrame) getOwner()).readPreferences(oldProperties); + } else if (cmd.equals("Cancel")) { + setVisible(false); + } else if (cmd.equals("Revert")) { + Enumeration enum = panels.elements(); + while (enum.hasMoreElements()) { + PreferencePanel pp = (PreferencePanel) enum.nextElement(); + + pp.readProperties(GalleryRemote.getInstance().properties); + } + } + } + + /** + * Cell renderer + * + *@author paour + *@created 11 août 2002 + */ + public class IconsCellRenderer extends DefaultListCellRenderer + { + public IconsCellRenderer() { + super(); + setHorizontalTextPosition(JLabel.CENTER); + setVerticalTextPosition(JLabel.BOTTOM); + setHorizontalAlignment(JLabel.CENTER); + } + + /** + * Gets the listCellRendererComponent attribute of the FileCellRenderer + * object + * + *@param list Description of Parameter + *@param value Description of Parameter + *@param index Description of Parameter + *@param selected Description of Parameter + *@param hasFocus Description of Parameter + *@return The listCellRendererComponent value + *@since + */ + public Component getListCellRendererComponent( + JList list, Object value, int index, + boolean selected, boolean hasFocus ) { + super.getListCellRendererComponent( list, value, index, selected, hasFocus ); + + if (value != null && index != -1) { + PreferencePanel pp = (PreferencePanel) value; + setText(pp.getIcon().getText()); + setIcon(pp.getIcon().getIcon()); + } else { + setText("dummy"); + } + + return this; + } + } +} diff --git a/com/gallery/GalleryRemote/prefs/panes.properties b/com/gallery/GalleryRemote/prefs/panes.properties new file mode 100644 index 0000000..2b4dd10 --- /dev/null +++ b/com/gallery/GalleryRemote/prefs/panes.properties @@ -0,0 +1 @@ +pane.1=com.gallery.GalleryRemote.prefs.GeneralPanel \ No newline at end of file