code format, organize imports

This commit is contained in:
Jindra Petřík
2014-10-25 21:32:16 +02:00
parent 8fd683d019
commit bcfb4a1c01
17 changed files with 86 additions and 119 deletions
@@ -16,7 +16,6 @@
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.AppResources;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.lang.reflect.Field;
@@ -30,17 +29,18 @@ import java.util.Map;
* @author JPEXS
*/
public class FontHelper {
/**
* Gets all available fonts in the system
*
* @return Map<FamilyName,Map<FontNAme,Font>>
*/
public static Map<String,Map<String,Font>> getInstalledFonts(){
Map<String,Map<String,Font>> ret = new HashMap<>();
public static Map<String, Map<String, Font>> getInstalledFonts() {
Map<String, Map<String, Font>> ret = new HashMap<>();
Font fonts[] = null;
try {
Class<?> clFmFactory = Class.forName("sun.font.FontManagerFactory");
Class<?> clFmFactory = Class.forName("sun.font.FontManagerFactory");
Object fm = clFmFactory.getDeclaredMethod("getInstance").invoke(null);
Class<?> clFm = Class.forName("sun.font.SunFontManager");
@@ -52,7 +52,7 @@ public class FontHelper {
//Delete cached family names
Field allFamField = clFm.getDeclaredField("allFamilies");
allFamField.setAccessible(true);
allFamField.set(fm,null);
allFamField.set(fm, null);
//Delete cached fonts
Field allFonField = clFm.getDeclaredField("allFonts");
@@ -60,34 +60,34 @@ public class FontHelper {
allFonField.set(fm, null);
fonts = (Font[]) clFm.getDeclaredMethod("getAllInstalledFonts").invoke(fm);
} catch (Throwable ex) {
} catch (Throwable ex) {
//ignore
}
if(fonts == null){
if (fonts == null) {
fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
}
for(Font f:fonts){
}
for (Font f : fonts) {
String fam = f.getFamily(Locale.getDefault());
//Do not want Java logical fonts
if(Arrays.asList("Dialog","DialogInput","Monospaced","Serif","SansSerif").contains(fam)){
if (Arrays.asList("Dialog", "DialogInput", "Monospaced", "Serif", "SansSerif").contains(fam)) {
continue;
}
if(!ret.containsKey(fam)){
if (!ret.containsKey(fam)) {
ret.put(fam, new HashMap<String, Font>());
}
String face = getFontFace(f);
String face = getFontFace(f);
ret.get(f.getFamily()).put(face, f);
}
return ret;
}
public static String getFontFace(Font f){
public static String getFontFace(Font f) {
String fam = f.getFamily(Locale.getDefault());
String face = f.getFontName(Locale.getDefault());
if(face.startsWith(fam)){
if (face.startsWith(fam)) {
face = face.substring(fam.length()).trim();
}
if(face.startsWith(".")){
}
if (face.startsWith(".")) {
face = face.substring(1);
}
return face;