From b91b582d8a6c0b2e78a20a517c6e0d3b036725d8 Mon Sep 17 00:00:00 2001 From: ArghKevin Date: Mon, 29 Apr 2024 13:32:18 -0700 Subject: Week 2. Stubs. Start of GUI. --- src/ComparisonView.java | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/ComparisonView.java (limited to 'src/ComparisonView.java') diff --git a/src/ComparisonView.java b/src/ComparisonView.java new file mode 100644 index 0000000..ca5929e --- /dev/null +++ b/src/ComparisonView.java @@ -0,0 +1,84 @@ +import java.util.ArrayList; +import java.io.*; +import javax.swing.*; +import java.awt.*; + +/* + * @author + * Kian Agheli + * + * References: + * https://zetcode.com/java/listdirectory/ + * https://stackoverflow.com/questions/4871051/how-to-get-the-current-working-directory-in-java + * + * Date: + * 2024-04-28 + * + * Purpose of class: + * Provide a view for comparing font families. + */ + +public class ComparisonView extends JFrame { + private final int WINDOW_MIN_WIDTH = 960; + private final int WINDOW_MIN_HEIGHT = 540; + + /* + * Walk the file tree. + */ + static void walk(File dir, ArrayList list) { + File[] dirContents = dir.listFiles(); + for (int i = 0; i < dirContents.length; i++) { + if (dirContents[i].isFile()) { + if (dirContents[i] != null) { + list.add(dirContents[i]); + } + } else if (dirContents[i].isDirectory()) { + walk(dirContents[i], list); + } + /* Otherwise, an irregular file. Ignore it. */ + } + } + + /* Initialize GUI and comparison. */ + public ComparisonView() { + setTitle("Google Fonts Style vs. Popularity"); // Window title + setMinimumSize(new Dimension(WINDOW_MIN_WIDTH, + WINDOW_MIN_HEIGHT)); // Minimum window size + /* On window close, kill the program. */ + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + pack(); // Pack the GUI + setVisible(true); // Make the window visible + + /* In $(find . | grep METADATA.pb), each + family is described in JSON. Human name is provided on first line. + For each METADATA.pb, instantiate a FontFamily object, keep + in an ArrayList. */ + //System.out.println(System.getProperty("user.dir")); + ArrayList fileList = new ArrayList(); + try { + walk(new File("."), fileList); + } catch (Exception e) { + System.out.println(e.getMessage()); // Print error message + System.exit(1); // Exit with error + } + + ArrayList metadataList = new ArrayList(); + /* Enhanced for loop. */ + for (File file : fileList) { + if (file.getPath().endsWith("METADATA.pb")) { + metadataList.add(file); + } + } + + /* Create FontFamily objects from each METADATA.pb file. + Not done yet. */ + for (File file : metadataList) { + System.out.println(file.getPath()); + } + } + + public static void main(String[] argv) { + new ComparisonView(); + } +} -- cgit v1.2.3