hw3: PhotoAlbumModel: remove sortingStrategy from constructor

This commit is contained in:
Yuri Tatishchev 2025-03-25 00:32:23 -07:00
parent b12cf9f6d2
commit 0fb5fd0654
Signed by: CaZzzer
GPG Key ID: E0EBF441EA424369
3 changed files with 6 additions and 13 deletions

View File

@ -6,7 +6,7 @@ import view.PhotoAlbumView;
public class PhotoAlbumApp {
public static void main(String[] args) {
// Create MVC components
PhotoAlbumModel model = new PhotoAlbumModel(new SortByDate());
PhotoAlbumModel model = new PhotoAlbumModel();
PhotoAlbumView view = new PhotoAlbumView();
PhotoAlbumController controller = new PhotoAlbumController(model, view);

View File

@ -11,7 +11,6 @@ import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;
import java.util.Date;
import java.util.List;
public class PhotoAlbumController {
private final PhotoAlbumModel model;
@ -78,12 +77,4 @@ public class PhotoAlbumController {
break;
}
}
public void handlePhotoSelection(int index) {
// Reset iterator and loop to the selected index
List<Photo> photos = model.getPhotos();
for (int i = 0; i < index; i++) {
model.next();
}
}
}

View File

@ -15,11 +15,10 @@ public class PhotoAlbumModel {
void onModelChanged();
}
public PhotoAlbumModel(SortingStrategy<Photo> sortingStrategy) {
public PhotoAlbumModel() {
photos = new ArrayList<>();
listeners = new ArrayList<>();
iterator = new PhotoIterator(photos);
this.sortingStrategy = sortingStrategy;
}
public void addPhoto(Photo photo) {
@ -48,7 +47,10 @@ public class PhotoAlbumModel {
}
private void sortPhotos() {
photos = sortingStrategy.sort(photos);
if (sortingStrategy != null) {
photos = sortingStrategy.sort(photos);
iterator = new PhotoIterator(photos);
}
}
public void addListener(ModelChangeListener listener) {