hw3: PhotoAlbumView: disable unusable buttons
This commit is contained in:
@@ -64,6 +64,14 @@ public class PhotoAlbumView extends JFrame implements PhotoAlbumModel.ModelChang
|
|||||||
controlPanel.add(deleteButton);
|
controlPanel.add(deleteButton);
|
||||||
controlPanel.add(sortingCombo);
|
controlPanel.add(sortingCombo);
|
||||||
add(controlPanel, BorderLayout.SOUTH);
|
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) {
|
public void setController(PhotoAlbumController controller) {
|
||||||
@@ -89,6 +97,7 @@ public class PhotoAlbumView extends JFrame implements PhotoAlbumModel.ModelChang
|
|||||||
public void onModelChanged() {
|
public void onModelChanged() {
|
||||||
updatePhotoList();
|
updatePhotoList();
|
||||||
updateCurrentPhoto();
|
updateCurrentPhoto();
|
||||||
|
updateNavigationButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePhotoList() {
|
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) {
|
private ImageIcon loadImage(String path) {
|
||||||
try {
|
try {
|
||||||
ImageIcon icon = new ImageIcon(path);
|
ImageIcon icon = new ImageIcon(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user