hw3: PhotoAlbumView: disable unusable buttons
This commit is contained in:
parent
63864e4e25
commit
528254c9bc
@ -64,6 +64,14 @@ public class PhotoAlbumView extends JFrame implements PhotoAlbumModel.ModelChang
|
||||
controlPanel.add(deleteButton);
|
||||
controlPanel.add(sortingCombo);
|
||||
add(controlPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Disable navigation buttons by default
|
||||
previousButton.setEnabled(false);
|
||||
nextButton.setEnabled(false);
|
||||
deleteButton.setEnabled(false);
|
||||
|
||||
// Select default sorting option
|
||||
sortingCombo.setSelectedIndex(1);
|
||||
}
|
||||
|
||||
public void setController(PhotoAlbumController controller) {
|
||||
@ -89,6 +97,7 @@ public class PhotoAlbumView extends JFrame implements PhotoAlbumModel.ModelChang
|
||||
public void onModelChanged() {
|
||||
updatePhotoList();
|
||||
updateCurrentPhoto();
|
||||
updateNavigationButtons();
|
||||
}
|
||||
|
||||
private void updatePhotoList() {
|
||||
@ -116,6 +125,12 @@ public class PhotoAlbumView extends JFrame implements PhotoAlbumModel.ModelChang
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNavigationButtons() {
|
||||
previousButton.setEnabled(model.hasPrevious());
|
||||
nextButton.setEnabled(model.hasNext());
|
||||
deleteButton.setEnabled(model.getCurrentPhoto() != null);
|
||||
}
|
||||
|
||||
private ImageIcon loadImage(String path) {
|
||||
try {
|
||||
ImageIcon icon = new ImageIcon(path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user