Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit c2faa04

Browse files
ExplvExplv
authored andcommitted
Refactor ResourceManager, add FontManager & ImageManager
Add Roboto-Regular font, and use everywhere Button panel border redesign
1 parent ce02546 commit c2faa04

File tree

12 files changed

+220
-97
lines changed

12 files changed

+220
-97
lines changed
168 KB
Binary file not shown.

AIO/src/org/aio/gui/Gui.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import org.aio.gui.utils.ColourScheme;
88
import org.aio.tasks.Task;
99
import org.aio.tasks.TaskType;
10+
import org.aio.util.file_managers.FontManager;
1011
import org.json.simple.JSONObject;
1112

1213
import javax.swing.*;
14+
import javax.swing.border.Border;
15+
import javax.swing.border.EtchedBorder;
1316
import javax.swing.border.TitledBorder;
1417
import java.awt.*;
1518
import java.awt.event.ActionListener;
@@ -37,7 +40,7 @@ public Gui() {
3740
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 10));
3841

3942
final JLabel titleLabel = new StyledJLabel();
40-
titleLabel.setFont(new Font("Trebuchet MS", Font.BOLD, 26));
43+
titleLabel.setFont(FontManager.ROBOTO_REGULAR.deriveFont(Font.BOLD, 26));
4144
titleLabel.setForeground(ColourScheme.WHITE);
4245
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
4346
titleLabel.setText("<html><span color='#33b5e5'>Explv</span>'s AIO</html>");
@@ -52,7 +55,16 @@ public Gui() {
5255
saveLoadPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
5356
saveLoadPanel.setBackground(DARK_GREY);
5457
controlsPanel.add(saveLoadPanel);
55-
saveLoadPanel.setBorder(BorderFactory.createTitledBorder(null, "Save / Load", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, ColourScheme.WHITE));
58+
saveLoadPanel.setBorder(
59+
BorderFactory.createTitledBorder(
60+
BorderFactory.createEtchedBorder(),
61+
"Save / Load",
62+
TitledBorder.CENTER,
63+
TitledBorder.TOP,
64+
new Font("Roboto-Regular", Font.PLAIN, 12),
65+
ColourScheme.WHITE
66+
)
67+
);
5668

5769
saveLoadPanel.add(createButtonPanel(
5870
"Save",
@@ -84,7 +96,16 @@ public Gui() {
8496
addTaskPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
8597
addTaskPanel.setBackground(DARK_GREY);
8698
controlsPanel.add(addTaskPanel);
87-
addTaskPanel.setBorder(BorderFactory.createTitledBorder(null, "Add a Task", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, ColourScheme.WHITE));
99+
addTaskPanel.setBorder(
100+
BorderFactory.createTitledBorder(
101+
BorderFactory.createEtchedBorder(),
102+
"Add a Task",
103+
TitledBorder.CENTER,
104+
TitledBorder.TOP,
105+
FontManager.ROBOTO_REGULAR,
106+
ColourScheme.WHITE
107+
)
108+
);
88109

89110
addTaskPanel.add(createButtonPanel(
90111
"Level",
@@ -147,7 +168,16 @@ public Gui() {
147168
startPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
148169
startPanel.setBackground(DARK_GREY);
149170
controlsPanel.add(startPanel);
150-
startPanel.setBorder(BorderFactory.createTitledBorder(null, "Start", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, ColourScheme.WHITE));
171+
startPanel.setBorder(
172+
BorderFactory.createTitledBorder(
173+
BorderFactory.createEtchedBorder(),
174+
"Start",
175+
TitledBorder.CENTER,
176+
TitledBorder.TOP,
177+
FontManager.ROBOTO_REGULAR,
178+
ColourScheme.WHITE
179+
)
180+
);
151181

152182
startPanel.add(createButtonPanel(
153183
"Start",

AIO/src/org/aio/gui/IconButton.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.aio.gui;
22

3-
import org.aio.util.ResourceManager;
3+
import org.aio.util.file_managers.ImageManager;
4+
import org.aio.util.file_managers.ResourceManager;
45

56
import javax.swing.*;
67
import java.awt.*;
@@ -13,12 +14,12 @@ public static JButton createButton(final String toolTip, final String icon, fina
1314
button.setBackground(Color.BLACK);
1415
button.setToolTipText(toolTip);
1516

16-
BufferedImage iconImage = ResourceManager.getImage(icon);
17+
BufferedImage iconImage = ImageManager.loadImage(icon);
1718
if (iconImage != null) {
1819
button.setIcon(new ImageIcon(iconImage));
1920
}
2021

21-
BufferedImage rolloverIconImage = ResourceManager.getImage(rolloverIcon);
22+
BufferedImage rolloverIconImage = ImageManager.loadImage(rolloverIcon);
2223
if (rolloverIconImage != null) {
2324
button.setRolloverIcon(new ImageIcon(rolloverIconImage));
2425
}

AIO/src/org/aio/gui/styled_components/StyledJCheckBox.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package org.aio.gui.styled_components;
22

33
import org.aio.gui.utils.ColourScheme;
4+
import org.aio.util.file_managers.FontManager;
45

56
import javax.swing.*;
7+
import java.awt.*;
68

79
public class StyledJCheckBox extends JCheckBox {
810

911
public StyledJCheckBox(final String text) {
1012
super(text);
1113
setBackground(ColourScheme.PANEL_BACKGROUND_GREY);
1214
setForeground(ColourScheme.WHITE);
15+
16+
setFont(FontManager.ROBOTO_REGULAR);
1317
}
1418

1519
public StyledJCheckBox() {

AIO/src/org/aio/gui/styled_components/StyledJComboBox.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.aio.gui.styled_components;
22

33
import org.aio.gui.utils.ColourScheme;
4+
import org.aio.util.file_managers.FontManager;
45

56
import javax.swing.*;
67
import javax.swing.plaf.ComponentUI;
78
import javax.swing.plaf.basic.BasicComboBoxUI;
9+
import java.awt.*;
810

911
public class StyledJComboBox<E> extends JComboBox<E> {
1012

@@ -23,6 +25,7 @@ public StyledJComboBox() {
2325
}
2426

2527
private void setStyle() {
28+
setFont(FontManager.ROBOTO_REGULAR);
2629
setUI(new CustomComboBoxUI());
2730
setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
2831
setBackground(ColourScheme.PANEL_BACKGROUND_GREY.darker());

AIO/src/org/aio/gui/styled_components/StyledJLabel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.aio.gui.styled_components;
22

33
import org.aio.gui.utils.ColourScheme;
4+
import org.aio.util.file_managers.FontManager;
45

56
import javax.swing.*;
67
import java.awt.*;
@@ -10,6 +11,7 @@ public class StyledJLabel extends JLabel {
1011
public StyledJLabel(final String text) {
1112
super(text);
1213
setForeground(ColourScheme.WHITE);
14+
setFont(FontManager.ROBOTO_REGULAR);
1315
}
1416

1517
public StyledJLabel() {

AIO/src/org/aio/gui/styled_components/StyledJTextField.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.aio.gui.styled_components;
22

33
import org.aio.gui.utils.ColourScheme;
4+
import org.aio.util.file_managers.FontManager;
45

56
import javax.swing.*;
7+
import java.awt.*;
68

79
public class StyledJTextField extends JTextField {
810

@@ -16,6 +18,7 @@ public StyledJTextField() {
1618
}
1719

1820
protected void setStyle() {
21+
setFont(FontManager.ROBOTO_REGULAR);
1922
setBackground(ColourScheme.PANEL_BACKGROUND_GREY.darker());
2023
setForeground(ColourScheme.WHITE);
2124
setCaretColor(ColourScheme.WHITE);

AIO/src/org/aio/script/AIO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.aio.tasks.Task;
1010
import org.aio.tasks.TutorialIslandTask;
1111
import org.aio.tasks.task_executor.TaskExecutor;
12+
import org.aio.util.file_managers.FontManager;
1213
import org.aio.util.SkillTracker;
1314
import org.aio.util.event.EnableFixedModeEvent;
1415
import org.aio.util.event.ToggleRoofsHiddenEvent;
@@ -30,7 +31,7 @@
3031
@ScriptManifest(author = "Explv", name = "Explv's AIO " + AIO.VERSION, info = "AIO", version = 0, logo = "http://i.imgur.com/58Zz0fb.png")
3132
public class AIO extends Script {
3233

33-
static final String VERSION = "v2.3.2";
34+
static final String VERSION = "v2.4.0";
3435

3536
private Gui gui;
3637
private Paint paint;

AIO/src/org/aio/util/ResourceManager.java

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.aio.util.file_managers;
2+
3+
import java.awt.*;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
7+
public class FontManager extends ResourceManager {
8+
9+
private static final String FONT_DIR = "fonts/";
10+
11+
private static final String[] FONT_FILES = {
12+
"Roboto-Regular.ttf"
13+
};
14+
15+
static {
16+
loadFonts();
17+
}
18+
19+
public static Font ROBOTO_REGULAR = new Font("Roboto-Regular", Font.PLAIN, 12);
20+
21+
private static void loadFonts() {
22+
for (String font : FONT_FILES) {
23+
String relativeFontPath = FONT_DIR + font;
24+
25+
if (!loadFont(relativeFontPath)) {
26+
System.out.println("Failed to laod font: " + font);
27+
}
28+
}
29+
}
30+
31+
private static boolean loadFont(final String relativeFontPath) {
32+
try (InputStream fontInputStream = loadFile(relativeFontPath)) {
33+
34+
if (fontInputStream == null) {
35+
return false;
36+
}
37+
38+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
39+
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, fontInputStream));
40+
return true;
41+
42+
} catch (IOException | FontFormatException e) {
43+
e.printStackTrace();
44+
}
45+
46+
return false;
47+
}
48+
}

0 commit comments

Comments
 (0)