diff options
author | ArghKevin <kagheli@student.sdccd.edu> | 2024-04-29 13:32:18 -0700 |
---|---|---|
committer | ArghKevin <kagheli@student.sdccd.edu> | 2024-04-29 13:32:18 -0700 |
commit | b91b582d8a6c0b2e78a20a517c6e0d3b036725d8 (patch) | |
tree | 615a0ed4830a3ef1b17ec505001771962a5933f1 /src | |
parent | 55669ea76c7a08dfbaca5898070404c0f60d476d (diff) |
Week 2. Stubs. Start of GUI.
Diffstat (limited to 'src')
-rw-r--r-- | src/CSVReader.java | 23 | ||||
-rw-r--r-- | src/ComparisonView.java | 84 | ||||
-rw-r--r-- | src/FontFamily.java | 35 | ||||
-rw-r--r-- | src/JSONReader.java | 26 | ||||
-rw-r--r-- | src/LineGraph.java | 24 | ||||
-rw-r--r-- | src/Reader.java | 49 |
6 files changed, 241 insertions, 0 deletions
diff --git a/src/CSVReader.java b/src/CSVReader.java new file mode 100644 index 0000000..42b6899 --- /dev/null +++ b/src/CSVReader.java @@ -0,0 +1,23 @@ +import java.io.*; + +/* + * @author + * Kian Agheli + * + * References: + * + * Date: + * 2024-04-28 + * + * Purpose of class: + * Read from and interpret CSV files. + */ + +public class CSVReader extends Reader { + String[] header; // A CSV file has-a header. One line, multiple fields. + String[][] body; // A CSV file has-a body. Multiple lines, multiple fields. + + public CSVReader(File file) { + super(file); // Call parent constructor + } +} 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<File> 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<File> fileList = new ArrayList<File>(); + try { + walk(new File("."), fileList); + } catch (Exception e) { + System.out.println(e.getMessage()); // Print error message + System.exit(1); // Exit with error + } + + ArrayList<File> metadataList = new ArrayList<File>(); + /* 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(); + } +} diff --git a/src/FontFamily.java b/src/FontFamily.java new file mode 100644 index 0000000..54e174f --- /dev/null +++ b/src/FontFamily.java @@ -0,0 +1,35 @@ +import java.util.ArrayList; +import java.util.HashMap; + +/* + * @author + * Kian Agheli + * + * References: + * + * Date: + * 2024-04-28 + * + * Purpose of class: + * Store and operate on font family metadata. + */ + +public class FontFamily { + /* The directory containing the associated METADATA.pb */ + private String directoryName; + /* Taken from first line of METADATA.pb */ + private String familyName; + /* Taken from fonts/tags/all/families.csv */ + private ArrayList<String> styles; + /* Taken from top level of METADATA.pb */ + private String dateAdded; + /* Average glyph count of every font file specified in METADATA.pb */ + private int glyphCount; + /* Average file size of every font file specified in METADATA.pb */ + private int fileSize; + /* Author from METADATA.pb */ + private String author; + /* total views, 7day views, 30day views, 90day views, year views. + Taken from popularity.json. */ + private HashMap<String,Long> views; +} diff --git a/src/JSONReader.java b/src/JSONReader.java new file mode 100644 index 0000000..52edf3a --- /dev/null +++ b/src/JSONReader.java @@ -0,0 +1,26 @@ +import java.io.*; + +/* + * @author + * Kian Agheli + * + * References: + * https://jqlang.github.io/jq/manual/ + * + * Date: + * 2024-04-28 + * + * Purpose of class: + * Read from and interpret JSON files. + */ + +public class JSONReader extends Reader { + public JSONReader(File file) { + super(file); + } + + /* Something akin to jq's field selection. */ + public String getField(String field) { + return null; + } +} diff --git a/src/LineGraph.java b/src/LineGraph.java new file mode 100644 index 0000000..b9642fb --- /dev/null +++ b/src/LineGraph.java @@ -0,0 +1,24 @@ +import javax.swing.*; + +/* + * @author + * Kian Agheli + * + * References: + * + * Date: + * 2024-04-28 + * + * Purpose of class: + * Draw a line graph. + */ + +public class LineGraph { + int[][] coordinates; // A line graph has-a set of coordinates + public LineGraph() { + coordinates = null; + } + + void setCoordinates(int y, int x) { + } +} diff --git a/src/Reader.java b/src/Reader.java new file mode 100644 index 0000000..934bf5f --- /dev/null +++ b/src/Reader.java @@ -0,0 +1,49 @@ +import java.io.*; +import java.util.Scanner; + +/* + * @author + * Kian Agheli + * + * References: + * + * Date: + * 2024-04-28 + * + * Purpose of class: + * Read from a file. + */ + +class Reader { + private File file; // A Reader has-a file. + private String contents; // A Reader has-a set of contents. + + public Reader(File file) { + this.file = file; + contents = null; + Scanner scan = null; + try { + /* Scan over the contents of the input file. */ + scan = new Scanner(file); + /* Save to object. */ + while (scan.hasNextLine()) { + contents += scan.nextLine(); + } + /* On exception, exit. */ + } catch (Exception e) { + System.out.println(e.getMessage()); + System.exit(1); + } finally { + if (scan != null) { + scan.close(); + } + } + } + + /* + * @return the contents of the file. + */ + String getContents() { + return contents; + } +} |