33import java .awt .BorderLayout ;
44import java .awt .Color ;
55import java .awt .Dimension ;
6+ import java .awt .Toolkit ;
7+
68import javax .swing .JButton ;
79import javax .swing .JComboBox ;
810import javax .swing .JFrame ;
1719public class ContentWindow extends JFrame {
1820
1921 private static final long serialVersionUID = 1L ;
20- private int contentWidth = 900 ;
21- private int arrDisplayHeight = 900 ;
22+ private int arrDisplayHeight ;
23+ private int arrDisplayWidth ;
24+ private int contentWidth ;
25+ private int contentHeight ;
2226 private AlgVisualizer algVisualizer ;
2327 private JPanel arrPanel ;
2428 private ArrDisplay arrDisplay ;
@@ -34,29 +38,54 @@ public class ContentWindow extends JFrame {
3438 private JLabel performanceLabel ;
3539
3640 public ContentWindow (AlgVisualizer algVisualizer ) {
37- super ("Algorithm Visualizer" ); // Set the name of the frame
41+ super ("Algorithm Visualizer" ); // Set the name of the frame
3842 this .algVisualizer = algVisualizer ;
3943 initComponents (); // initialize the components of the frame
40- setFrame (); // Set up the frame and add all of the initialized components
44+ setFrame (); // Set up the frame and add all of the initialized components
4145 }
4246
4347 /*
44- * Initializes all of the components that will be in this frame.
45- * Add the action / change listeners and set their colors.
48+ * Initializes all of the components that will be in this frame. Add the action
49+ * / change listeners and set their colors.
4650 */
4751 public void initComponents () {
4852
53+ Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
54+ double screenWidth = screenSize .getWidth ();
55+ double screenHeight = screenSize .getHeight ();
56+ String [] sizeOptions ;
57+
58+ if (screenHeight > 1080.0 ) { // 4k
59+ arrDisplayHeight = 1000 ;
60+ contentWidth = arrDisplayHeight ;
61+ sizeOptions = new String [] { "10" , "50" , "100" , "250" , "500" , "1000" };
62+ } else if (screenHeight < 1080.0 ) { // too small for original dimensions
63+ arrDisplayHeight = 500 ;
64+ contentWidth = arrDisplayHeight + 400 ;
65+ sizeOptions = new String [] { "10" , "50" , "100" , "250" , "500" };
66+ } else { // Original dimensions
67+ arrDisplayHeight = 900 ;
68+ contentWidth = arrDisplayHeight ;
69+ sizeOptions = new String [] { "10" , "50" , "100" , "300" , "450" , "900" };
70+ }
71+
72+ contentHeight = arrDisplayHeight + 110 ;
73+ arrDisplayWidth = arrDisplayHeight ;
74+ algVisualizer .setSizeOptions (sizeOptions );
75+
4976 arrDisplay = new ArrDisplay (algVisualizer , this );
5077 arrDisplay .setArr (algVisualizer .getArr ());
51- arrDisplay .setPreferredSize (new Dimension (contentWidth , arrDisplayHeight ));
78+ arrDisplay .setPreferredSize (new Dimension (arrDisplayWidth , arrDisplayHeight ));
5279
5380 // Panels in the frame that will hold all components.
5481 // JPanels use the flowLayout to manage their components automatically.
5582 buttonPanel = new JPanel ();
5683 buttonPanel .setBackground (Color .DARK_GRAY );
5784
5885 arrPanel = new JPanel ();
86+ arrPanel .setBackground (Color .DARK_GRAY );
5987 arrPanel .add (arrDisplay );
88+ arrDisplay .setAlignmentX (0 );
6089
6190 // Initialize all components and add action listeners
6291 resetButton = new JButton ("Reset" );
@@ -92,7 +121,8 @@ public void initComponents() {
92121 algVisualizer .getInitFPS ());
93122 FPSslider .addChangeListener (algVisualizer );
94123 FPSslider .setBackground (Color .DARK_GRAY );
95-
124+ //FPSslider.setPreferredSize(new Dimension(75,25));
125+
96126 performanceLabel = new JLabel ();
97127 performanceLabel .setHorizontalAlignment (SwingConstants .CENTER );
98128 }
@@ -110,7 +140,8 @@ public void setFrame() { // Add JButtons / components to button panel
110140 buttonPanel .add (sizeChanger );
111141 buttonPanel .add (FPSslider );
112142 // Initialize and make the frame visible
113- setPreferredSize (new Dimension (contentWidth , arrDisplayHeight + 105 )); // 105 is the height of the performance label and the button panel
143+ setPreferredSize (new Dimension (contentWidth , contentHeight )); // 105 is the height of the performance label and
144+ // the button panel
114145 setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
115146 setResizable (false ); // Cannot be resizable, causes visual issues
116147 add (buttonPanel , BorderLayout .PAGE_START ); // Button panel added to the top of the frame
@@ -138,13 +169,22 @@ public ArrDisplay getArrDisplay() {
138169 return arrDisplay ;
139170 }
140171
141- public int getWidth () {
172+ public int getContentWidth () {
142173 return contentWidth ;
143174 }
144-
175+
176+ public int getContentHeight () {
177+ return contentWidth ;
178+ }
179+
180+ public int getArrDisplayWidth () {
181+ return arrDisplayHeight ;
182+ }
183+
145184 public int getArrDisplayHeight () {
146185 return arrDisplayHeight ;
147186 }
187+
148188
149189 public JButton getBubbleButton () {
150190 return bubbleButton ;
0 commit comments