[FEATURE] Changed layout of VerboseLoader

This commit is contained in:
Emmastone
2016-04-28 02:01:32 +01:00
parent 72b1fcdc78
commit c1e9ce4a49
9 changed files with 106 additions and 0 deletions
@@ -0,0 +1,64 @@
package org.parabot.core.ui.fonts;
import org.parabot.core.ui.utils.Fonts;
import java.awt.*;
import java.io.IOException;
/**
* @author Capslock
*/
public class ParabotFont {
private String name;
private String location;
private Font font;
public ParabotFont(String location, float size) {
if (!location.toLowerCase().startsWith("/storage/fonts/")){
location = "/storage/fonts/" + location;
}
this.location = location;
try {
this.font = createFont(size);
} catch (FontFormatException | IOException e) {
e.printStackTrace();
}
}
private Font createFont(float size) throws IOException, FontFormatException {
return Font.createFont(Font.TRUETYPE_FONT, Fonts.class.getResourceAsStream(this.location)).deriveFont(size);
}
public float getSize() {
return font.getSize();
}
public String getLocation() {
return location;
}
public String getName() {
return name;
}
public Font getFont() {
return font;
}
@Override
public boolean equals(Object obj) {
if (obj != null) {
if (obj instanceof ParabotFont) {
ParabotFont otherFont = (ParabotFont) obj;
if (otherFont.getName().equalsIgnoreCase(this.getName())) {
if (otherFont.getSize() == this.getSize()) {
return true;
}
}
}
}
return false;
}
}
@@ -0,0 +1,42 @@
package org.parabot.core.ui.utils;
import org.parabot.core.ui.fonts.ParabotFont;
import java.awt.*;
import java.util.*;
/**
* Created by Capslock
* On 28/04/16
* With IntelliJ
*/
public class Fonts {
private static final java.util.List<ParabotFont> FONT_CACHE = new ArrayList<>();
/**
* Calls the getResource with the default size of 12
*
* @param resource
* @return
*/
public static Font getResource(final String resource){
return getResource(resource, 12f);
}
public static Font getResource(final String fileName, float size) {
ParabotFont parabotFont = null;
for (ParabotFont font : FONT_CACHE) {
if (font.getLocation().equalsIgnoreCase(fileName) && font.getSize() == size){
parabotFont = font;
}
}
if (parabotFont == null){
parabotFont = new ParabotFont(fileName, size);
FONT_CACHE.add(parabotFont);
}
return parabotFont.getFont();
}
}