hw3: init

This commit is contained in:
Yuri Tatishchev 2025-03-24 01:38:54 -07:00
parent 593840bd51
commit 81abdd064d
Signed by: CaZzzer
GPG Key ID: 28BE602058C08557
12 changed files with 176 additions and 0 deletions

29
hw3/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
hw3/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

6
hw3/.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
hw3/.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/hw3.iml" filepath="$PROJECT_DIR$/hw3.iml" />
</modules>
</component>
</project>

6
hw3/.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

79
hw3/README.md Normal file
View File

@ -0,0 +1,79 @@
## Objectives
Design and implement a desktop-based photo album manager using Java Swing. The application should demonstrate the use of the Iterator pattern, the MVC pattern, and the Strategy pattern to allow flexible behavior for sorting and displaying images.
## Problem Statement
Create a photo album manager application that allows users to:
- Add, view, and delete photos in the album.
- Navigate through the album using next/previous buttons.
- Display the photos in three different sorting orders by name, date added, and file size.
- The sorting should be implemented using the Strategy pattern, allowing different sorting strategies to be selected.
- The album should be iterated through using the Iterator pattern.
- The application should follow the MVC (Model-View-Controller) pattern to separate business logic, user interface, and control flow.
## Functional Requirements
- Photo Management:
- The program manages real images.
- Users should be able to add new photos (with a name, file path, and date).
- Users can delete photos by name from the album.
- Display a list of photos (name and thumbnail preview).
- Display the current photo.
- Navigation:
- The "Next" and "Previous" buttons change the current photo to the next photo and the previous photo, respectively. The next and previous photo are determined by the current sorting order of the list of photos.
- The application must implement an Iterator to traverse the photo collection.
- Sorting Photos:
- Users can sort the list of photos by name, date added, or file size.
- The sorting behavior should be dynamic and implemented using the Strategy pattern.
- The system should handle the following edge cases: empty photo albums (e.g. can't delete from an empty photo album) and non-existent file paths.
## Use of Patterns
### MVC
- Model (`PhotoAlbumModel`) Represents the photo collection and the current state of the album. Notifies the view when there is a change in the photo collection (by adding or deleting). Photo class contains attributes like name, file path, and date added.
- View (`PhotoAlbumView`) A Swing-based UI that displays the up-to-date list of photos in the order of date by default and the current photo.
- Controller (`PhotoAlbumController`) Provides controls (buttons for adding, deleting, sorting, navigating). Has buttons like "Add Photo", "Delete Photo", "Next", "Previous", and "Sort By" (Name/Date/Size). Responds to user actions and modifies the model accordingly. Manages the connection between user input (e.g., button clicks) and the photo album (model).
### Iterator Pattern
Implement an AlbumIterator class (class that implements the AlbumIterator interface) to iterate over the photos in the album.
### Strategy Pattern
Create three different sorting strategies, specifically SortByName, SortByDate, SortBySize for sorting the photos. The user can select different strategies dynamically to change the sorting order of the photos.
## Rough Layout of the User Interface
You should adhere to the layout provided below as closely as possible, but some reasonable flexibility is allowed.
![Photo Manager](photomanager.png)
## Submission
Submit hw3.zip through the course web site. The file hw3.zip should contain the following:
- All source files
- PhotoAlbumApp.java (with main), Photo.java, PhotoAlbumController.java, PhotoAlbumModel.java, PhotoAlbumView.java, SortByDate.java, SortByName.java, SortBySize.java, SortingStrategy.java.
- Put javadoc comments in the source codes.
- Remove all package statements from the source files.
- All .java files (not .class files)
- googledoc.txt: In this text file, specify a link to your google doc, titled as CS151_HW3_YOUR ID. Be sure to make this document available to ANYONE WHO HAS THE LINK (There will be point deductions if this requirement is not met.) The google doc should not be modified after the due date . The followings are required to present in the google document.
- Screen 1: Initial screen without any photos.
- Screen 2: After adding the first photo, the list and the current photo change.
- Screen 3: After adding the second photo, the list updates. Photos are displayed in order of date, with the first photo in the list set as the current photo.
- Screen 4: After adding the third photo, the list updates. Photos are displayed in order of date, with the first photo in the list set as the current photo.
- Screen 5: After sorting the list by name, both the list and the current photo change.
- Screen 6: After sorting the list by size, both the list and the current photo change.
- Screen 7: After sorting the list by date, both the list and the current photo change.
- Screen 8: After the next button is clicked, the list remains the same but the current photo changes.
- Screen 9: After the previous button is clicked, the list remains the same but the current photo changes.
- Screen 10: After deleting one of the photos by name. The list changes. The current photo only changes if the deleted photo was the current one. If so, the first photo in the updated list becomes the new current photo.
- Show the correct use of patterns (copy and paste the specified code from your Java programs and label them clearly):
- MVC Pattern
- Controller: The action listener code for the "Add" button, which calls the mutator of the model.
- Model: The data structure and the mutator that updates the data structure and notifies the view.
- View: The code that calls the model's accessor and triggers a repaint.
- Strategy Pattern: A class diagram documenting the use of the Strategy pattern. One interface and three concrete classes are expected.
- Iterator Pattern: The Iterator class. (That is, a class that implements the AlbumnIterator class.)

11
hw3/hw3.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

BIN
hw3/photomanager.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

View File

@ -0,0 +1,7 @@
public interface AlbumIterator {
boolean hasNext(); // to check if there is a next element
boolean hasPrevious(); // to check if there is a previous element
Photo current(); // to get the photo at the current position
Photo next(); // to advance the iterator to the next position
Photo previous(); // to advance the iterator to the previous position
}

10
hw3/src/Photo.java Normal file
View File

@ -0,0 +1,10 @@
import java.util.Date;
public class Photo {
private String name;
private String filePath;
private Date dateAdded;
private long fileSize;
// Constructor, getters, and setters
}

View File

@ -0,0 +1,6 @@
import java.util.List;
public interface SortingStrategy<T> {
List<T> sort(List<T> photos);
}