Skip to content

Commit 36ac6de

Browse files
committed
Fixed #15
Now have 3 different sizes(4k, 1080p, <1080p), each having their own array size options
1 parent f821140 commit 36ac6de

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

src/com/example/algorithmvisualizer/ArrDisplay.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public ArrDisplay(AlgVisualizer algVisualizer, ContentWindow frame) {
5454
public void paintComponent(Graphics g) {
5555
Graphics2D graphics2d = (Graphics2D) g;
5656
graphics2d.setColor(Color.DARK_GRAY);
57-
graphics2d.fillRect(0, 0, frame.getWidth(), frame.getArrDisplayHeight());
57+
graphics2d.fillRect(0, 0, frame.getArrDisplayWidth(), frame.getArrDisplayHeight());
5858
if (algVisualizer.getSort().equals("Not Sorting") || isComplete) {
5959
swappedIndex1 = -1;
6060
swappedIndex2 = -1;
@@ -65,7 +65,7 @@ public void paintComponent(Graphics g) {
6565
}
6666
// Iterate through the array and drawn every index
6767
for (int i = 0; i < arr.length; i++) {
68-
int width = (int) (frame.getWidth() / (double) arr.length);
68+
int width = (int) (frame.getArrDisplayWidth() / (double) arr.length);
6969
int height = arr[i] * (frame.getArrDisplayHeight() / arr.length);
7070
int x = i * width;
7171
int y = frame.getArrDisplayHeight() - height;

src/com/example/algorithmvisualizer/ContentWindow.java

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.awt.BorderLayout;
44
import java.awt.Color;
55
import java.awt.Dimension;
6+
import java.awt.Toolkit;
7+
68
import javax.swing.JButton;
79
import javax.swing.JComboBox;
810
import javax.swing.JFrame;
@@ -17,8 +19,10 @@
1719
public 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

Comments
 (0)