summaryrefslogtreecommitdiff
path: root/src/ComparisonView.java
blob: 631c718e11a112941ce5e2ba5a3f69279f74febf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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(".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();
		new CSVReader(new File("families.csv"));
	}
}