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;
|
||||
|
||||
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.stream.Collectors;
|
||||
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 {
|
||||
@ -13,30 +43,10 @@ public class FontAwesome {
|
||||
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 {
|
||||
MAPPING = new HashMap<>();
|
||||
MAPPING.put("clipboard", CLIPBOARD);
|
||||
MAPPING.put("copyright", COPYRIGHT);
|
||||
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);
|
||||
MAPPING = Arrays.stream(FontAwesome.values())
|
||||
.flatMap(f -> f.names.stream().map(name -> new Pair<>(name, f.symbol)))
|
||||
.collect(Collectors.toMap(Pair::getKey, Pair::getValue));
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class FontAwesomeIcon extends Text {
|
||||
setFont(FontAwesome.FONT);
|
||||
getStyleClass().add("fa-icon");
|
||||
icon.addListener((observable, oldValue, newValue) -> {
|
||||
String faIcon = FontAwesome.MAPPING.get(newValue);
|
||||
String faIcon = FontAwesome.getIcon(newValue);
|
||||
if (faIcon != null) {
|
||||
setText(faIcon);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user