-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.java
More file actions
157 lines (128 loc) · 4.77 KB
/
Copy pathMainWindow.java
File metadata and controls
157 lines (128 loc) · 4.77 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package woftracker;
import woftracker.record.RecordPanel;
import woftracker.stats.StatPanel;
import woftracker.main.MainPanel;
import woftracker.readout.ReadoutPanel;
import woftracker.puzzle.PuzzleFinderPanel;
import woftracker.util.DebugPanel;
import woftracker.util.GameAnalyses;
import woftracker.search.SearchOptionPanel;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.UIManager.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*; //http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html
public final class MainWindow {
private MainWindow() {}
public static final int WINDOW_WIDTH = 1250, WINDOW_HEIGHT = 550;
private static JFrame window;
private static RecordPanel rP;
private static MainPanel mP;
private static JTabbedPane tp;
public static final String CSC_FILENAME = "woftracker\\log\\colorscheme.ser", SYSERR_FILENAME = "woftracker\\log\\syserr_log.txt", SYSOUT_FILENAME = "woftracker\\log\\sysout_log.txt";
public static void openWindow(boolean b) {
window = new JFrame("Wheel of Fortune Tracker");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tp = new JTabbedPane();
tp.addTab("Welcome", (mP = new MainPanel(b)));
//tp.addTab("Record Game", (rP = new RecordPanel()));
tp.addTab("Readout", new ReadoutPanel());
tp.addTab("Stats", new StatPanel());
tp.addTab("Puzzle Finder", new PuzzleFinderPanel());
tp.addTab("Search", new SearchOptionPanel());
tp.setEnabledAt(2, false); //stats
tp.setEnabledAt(3, false); //search
tp.setEnabledAt(4, false); //puzzle finder
window.getContentPane().add(tp);
window.pack(); //makes frame displayable, causing errors above
window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
//window.setResizable(false);
window.setLocationRelativeTo(null);
GameAnalyses.initGameCount();
window.setVisible(true);
}
private static int gameCount = 0, goal;
public static void updateGAProgress() {
mP.updateBar(++gameCount);
if(gameCount == goal) {
tp.setEnabledAt(2, true); //stats
tp.setEnabledAt(3, true); //search
tp.setEnabledAt(4, true); //puzzle finder
tp.addTab("Debug", new DebugPanel()); //allow errors in getting the window open to go to console before said window is available
//window.pack();
}
}
public static void setGAGoal(int g) {
mP.setBar(goal = g);
}
public static void main(String[] args) {
//recommended way to start a Swing application (event-handling thread)
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
ColorScheme cSC = null;
Color c = null;
try(FileInputStream colorReader = new FileInputStream(CSC_FILENAME); ObjectInputStream persistanceIn = new ObjectInputStream(colorReader)) {
cSC = (ColorScheme) persistanceIn.readObject();
c = cSC.getChoice();
} catch(Exception e) { //more laziness, ain't it great?
e.printStackTrace();
cSC = new ColorScheme();
}
if(cSC.doShow()) {
do {
cSC.setChoice(JColorChooser.showDialog(null, "Choose color scheme", c != null ? c : new Color(188, 143, 143)));
c = cSC.getChoice();
} while(c == null);
}
try(FileOutputStream colorWriter = new FileOutputStream(CSC_FILENAME); ObjectOutputStream persistanceOut = new ObjectOutputStream(colorWriter)) {
persistanceOut.writeObject(cSC);
}
//Nimbus modification
UIManager.put("nimbusBase", c.darker());
UIManager.put("nimbusBlueGrey", c);
UIManager.put("nimbusLightBackground", c.brighter());
UIManager.put("control", c);
mainColor = c;
//from Java tutorial
for(LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
openWindow(cSC.doShow());
//rP.setAllBorders(BorderFactory.createLineBorder(c.darker(), 2));
} catch (Exception e) { e.printStackTrace(); } //a lot of various errors can happen here, maybe make a clean debugging later, but yes, this is lazy
}
});
}
private static Color mainColor;
public static Color getMainColor() {
return mainColor;
}
public static class ColorScheme implements Serializable { //public for needing to be accessed in MainPanel... I need to reorganize sometime
private static final long serialVersionUID = 1L; //version number.
private Color c;
private boolean doShow = true;
public void setChoice(Color c) {
this.c = c;
}
public Color getChoice() {
return c;
}
public void setShow(boolean b) {
doShow = b;
}
public boolean doShow() {
return doShow;
}
}
public static void resetRP() {
rP.reset();
}
public static JFrame getWindow() {
return window;
}
}