mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Simplify FontAwesome class
This commit is contained in:
parent
6468415592
commit
10c0034d64
@ -1,11 +1,41 @@
|
|||||||
package com.annimon.hotarufx.ui;
|
package com.annimon.hotarufx.ui;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.util.Pair;
|
||||||
|
|
||||||
public class FontAwesome {
|
public enum FontAwesome {
|
||||||
|
|
||||||
|
CLIPBOARD("\uf0ea", "clipboard"),
|
||||||
|
COPYRIGHT("\uf1f9", "copyright"),
|
||||||
|
FONT_AWESOME("\uf2b4", "font-awesome"),
|
||||||
|
GITHUB("\uf09b", "github"),
|
||||||
|
GLOBE("\uf0ac", "earth", "globe"),
|
||||||
|
PENCIL("\uf040", "pencil"),
|
||||||
|
PLAY("\uf04b", "play"),
|
||||||
|
REDO("\uf01e", "redo"),
|
||||||
|
UNDO("\uf0e2", "undo");
|
||||||
|
|
||||||
|
private final String symbol;
|
||||||
|
private final List<String> names;
|
||||||
|
|
||||||
|
FontAwesome(String symbol, String name, String... aliases) {
|
||||||
|
this.symbol = symbol;
|
||||||
|
names = new ArrayList<>();
|
||||||
|
names.add(name);
|
||||||
|
if (aliases.length > 0) {
|
||||||
|
names.addAll(Arrays.asList(aliases));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getIcon(String name) {
|
||||||
|
return MAPPING.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
static final Font FONT;
|
static final Font FONT;
|
||||||
static {
|
static {
|
||||||
@ -13,30 +43,10 @@ public class FontAwesome {
|
|||||||
FONT = Font.loadFont(resource.toExternalForm(), 16);
|
FONT = Font.loadFont(resource.toExternalForm(), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String
|
|
||||||
CLIPBOARD = "\uf0ea",
|
|
||||||
COPYRIGHT = "\uf1f9",
|
|
||||||
FONT_AWESOME = "\uf2b4",
|
|
||||||
GITHUB = "\uf09b",
|
|
||||||
GLOBE = "\uf0ac",
|
|
||||||
PENCIL = "\uf040",
|
|
||||||
PLAY = "\uf04b",
|
|
||||||
REDO = "\uf01e",
|
|
||||||
UNDO = "\uf0e2"
|
|
||||||
;
|
|
||||||
|
|
||||||
static final Map<String, String> MAPPING;
|
static final Map<String, String> MAPPING;
|
||||||
static {
|
static {
|
||||||
MAPPING = new HashMap<>();
|
MAPPING = Arrays.stream(FontAwesome.values())
|
||||||
MAPPING.put("clipboard", CLIPBOARD);
|
.flatMap(f -> f.names.stream().map(name -> new Pair<>(name, f.symbol)))
|
||||||
MAPPING.put("copyright", COPYRIGHT);
|
.collect(Collectors.toMap(Pair::getKey, Pair::getValue));
|
||||||
MAPPING.put("earth", GLOBE);
|
|
||||||
MAPPING.put("font-awesome", FONT_AWESOME);
|
|
||||||
MAPPING.put("github", GITHUB);
|
|
||||||
MAPPING.put("globe", GLOBE);
|
|
||||||
MAPPING.put("pencil", PENCIL);
|
|
||||||
MAPPING.put("play", PLAY);
|
|
||||||
MAPPING.put("redo", REDO);
|
|
||||||
MAPPING.put("undo", UNDO);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class FontAwesomeIcon extends Text {
|
|||||||
setFont(FontAwesome.FONT);
|
setFont(FontAwesome.FONT);
|
||||||
getStyleClass().add("fa-icon");
|
getStyleClass().add("fa-icon");
|
||||||
icon.addListener((observable, oldValue, newValue) -> {
|
icon.addListener((observable, oldValue, newValue) -> {
|
||||||
String faIcon = FontAwesome.MAPPING.get(newValue);
|
String faIcon = FontAwesome.getIcon(newValue);
|
||||||
if (faIcon != null) {
|
if (faIcon != null) {
|
||||||
setText(faIcon);
|
setText(faIcon);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user