Skip to content

Commit

Permalink
Renamed updateUI() to resetUIState(). updateUI() already exists in Sw…
Browse files Browse the repository at this point in the history
…ing components for the purposes of PLAF changing. Not nice to shadow it.

Now tracking what goes on in the list selection, so we can update the inspector when a picture is deleted.
  • Loading branch information
Pierre-Luc Paour committed Sep 4, 2002
1 parent aa0121c commit 7cca4f0
Showing 1 changed file with 46 additions and 28 deletions.
74 changes: 46 additions & 28 deletions com/gallery/GalleryRemote/MainFrame.java
Expand Up @@ -41,7 +41,8 @@
*@created August 16, 2002
*/
public class MainFrame extends javax.swing.JFrame
implements ActionListener, ItemListener, ListSelectionListener
implements ActionListener, ItemListener, ListSelectionListener,
ListDataListener
{
public static final String MODULE = "MainFrame";

Expand Down Expand Up @@ -135,13 +136,14 @@ public void initComponents()

picturesList.setModel( mAlbum );
picturesList.setCellRenderer( new FileCellRenderer() );
picturesList.getModel().addListDataListener( this );
( (DroppableList) picturesList ).setMainFrame( this );

pictureInspector.setMainFrame( this );

previewFrame.initComponents();

updateUI();
resetUIState();

jCheckBoxMenuThumbnails.setSelected( GalleryRemote.getInstance().properties.getShowThumbnails() );
jCheckBoxMenuPreview.setSelected( GalleryRemote.getInstance().properties.getShowPreview() );
Expand Down Expand Up @@ -195,29 +197,32 @@ void thisWindowClosing( java.awt.event.WindowEvent e ) {
}


void updateUI() {
void resetUIState() {
//-- if the list is empty, disable the Upload ---
upload.setEnabled( ( mAlbum.sizePictures() > 0 ) &&
!mInProgress &&
( album.getSelectedIndex() >= 0 ) );
browse.setEnabled( !mInProgress );
fetch.setEnabled( !mInProgress );

pictureInspector.setPictures( picturesList.getSelectedValues() );

int sel = picturesList.getSelectedIndex();
int selN = picturesList.getSelectedIndices().length;

if ( sel == -1 ) {
setStatus( mAlbum.sizePictures() + " pictures, "
if (mAlbum.sizePictures() > 0) {
pictureInspector.setPictures( picturesList.getSelectedValues() );

int sel = picturesList.getSelectedIndex();
int selN = picturesList.getSelectedIndices().length;

if ( sel == -1 ) {
setStatus( mAlbum.sizePictures() + " pictures, "
+ ( (int) mAlbum.getPictureFileSize() / 1024 ) + " K" );
} else {
setStatus( "Selected " + selN + ((selN == 1)?" picture, ":" pictures, ")
} else {
setStatus( "Selected " + selN + ((selN == 1)?" picture, ":" pictures, ")
+ ( (int) mAlbum.getObjectFileSize(picturesList.getSelectedValues()) / 1024 ) + " K" );
}
} else {
pictureInspector.setPictures( null );

setStatus( "No selection" );
}

//jButtonUp.setEnabled( selN == 1 );
//jButtonDown.setEnabled( selN == 1 );
}


Expand Down Expand Up @@ -320,7 +325,7 @@ public void browseAddPictures() {
addPictures( files );
}

updateUI();
resetUIState();
}

/**
Expand All @@ -330,7 +335,7 @@ public void browseAddPictures() {
*/
public void addPictures( File[] files ) {
addPictures( files, -1 );
updateUI();
resetUIState();
}


Expand Down Expand Up @@ -364,7 +369,7 @@ public boolean equals( Object o1, Object o2 )
} );*/
thumbnailCache.preloadThumbnails( files );

updateUI();
resetUIState();
}


Expand All @@ -385,7 +390,7 @@ public void uploadPictures() {
mGalleryComm.uploadFiles( mAlbum.getFileList() );

mInProgress = true;
updateUI();
resetUIState();

int pId = startProgress(0, mAlbum.sizePictures(), "Uploading pictures");

Expand All @@ -403,7 +408,7 @@ public void actionPerformed( ActionEvent evt ) {
mAlbum.clearPictures();
mInProgress = false;
picturesList.enable();
updateUI();
resetUIState();

Log.log(Log.INFO, MODULE, "uploadPictures finished");
}
Expand All @@ -430,7 +435,7 @@ public void fetchAlbums() {
mGalleryComm.fetchAlbums();

mInProgress = true;
updateUI();
resetUIState();

int pId = startProgress(0, 0, "Fetching albums");

Expand All @@ -448,7 +453,7 @@ public void actionPerformed( ActionEvent evt ) {
mAlbumList = mGalleryComm.getAlbumList();
mInProgress = false;
updateAlbumCombo();
updateUI();
resetUIState();
}
}

Expand Down Expand Up @@ -581,8 +586,6 @@ public void thumbnailLoadedNotify() {
public void showAboutBox() {
try {
AboutBox ab = new AboutBox(this);
//ab.initComponents();
//ab.setVersionString( APP_VERSION_STRING );
ab.setVisible( true );
} catch ( Exception err ) {
err.printStackTrace();
Expand Down Expand Up @@ -737,8 +740,6 @@ public void actionPerformed( ActionEvent e ) {
showAboutBox();
} else if ( command.equals( "Fetch" ) ) {
fetchAlbums();
//} else if ( command.equals( "Delete" ) ) {
// deleteSelectedPictures();
} else if ( command.equals( "Browse" ) ) {
browseAddPictures();
} else if ( command.equals( "Upload" ) ) {
Expand Down Expand Up @@ -780,6 +781,8 @@ public void itemStateChanged( ItemEvent e ) {
*@param e ListSelection event
*/
public void valueChanged( ListSelectionEvent e ) {
Log.log(Log.TRACE, MODULE, "List selection changed");

int sel = picturesList.getSelectedIndex();

if ( GalleryRemote.getInstance().properties.getShowPreview() ) {
Expand All @@ -796,11 +799,26 @@ public void valueChanged( ListSelectionEvent e ) {
}
}

updateUI();
resetUIState();
}


/**
* Implementation of the ListDataListener
*
*@param e ListSelection event
*/
public void contentsChanged( ListDataEvent e ) {
// Also tell MainFrame (ugly, but works around bug in Swing where when
// the list data changes (and nothing remains to be selected), no
// selection change events are fired.
resetUIState();
}
public void intervalAdded(ListDataEvent e) {}
public void intervalRemoved(ListDataEvent e) {}


/**
/**
* Listen for key events
*
*@param e Key event
Expand Down

0 comments on commit 7cca4f0

Please sign in to comment.