Archived
0

Add glyph font support

This commit is contained in:
iMoHax
2014-08-01 15:49:51 +04:00
parent 0c2622fb80
commit e469f91a01
3 changed files with 59 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ import javafx.stage.Stage;
import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialogs;
import ru.trader.model.*;
import ru.trader.view.support.CustomBuilderFactory;
import java.io.IOException;
import java.net.URL;
@@ -28,8 +29,14 @@ public class Screeners {
private static OffersEditorController oEditorController;
private static OrdersController ordersController;
private static FXMLLoader initLoader(URL url){
FXMLLoader loader = new FXMLLoader(url);
loader.setBuilderFactory(new CustomBuilderFactory());
return loader;
}
public static Parent newScreeners(URL main, String stylesheet) throws IOException {
FXMLLoader loader = new FXMLLoader(main);
FXMLLoader loader = initLoader(main);
mainScreen = loader.load();
if (stylesheet!=null)
mainScreen.getStylesheets().add(stylesheet);
@@ -42,14 +49,14 @@ public class Screeners {
}
public static void loadItemDescStage(URL fxml) throws IOException {
FXMLLoader loader = new FXMLLoader(fxml);
FXMLLoader loader = initLoader(fxml);
itemDescScreen = loader.load();
addStylesheet(itemDescScreen);
itemDescController = loader.getController();
}
public static void loadVEditorStage(URL fxml) throws IOException {
FXMLLoader loader = new FXMLLoader(fxml);
FXMLLoader loader = initLoader(fxml);
vEditorScreen = loader.load();
addStylesheet(vEditorScreen);
vEditorController = loader.getController();
@@ -58,7 +65,7 @@ public class Screeners {
}
public static void loadAddOfferStage(URL fxml) throws IOException {
FXMLLoader loader = new FXMLLoader(fxml);
FXMLLoader loader = initLoader(fxml);
editOffersScreen = loader.load();
addStylesheet(editOffersScreen);
oEditorController = loader.getController();
@@ -67,7 +74,7 @@ public class Screeners {
}
public static void loadOrdersStage(URL fxml) throws IOException {
FXMLLoader loader = new FXMLLoader(fxml);
FXMLLoader loader = initLoader(fxml);
ordersScreen = loader.load();
addStylesheet(ordersScreen);
ordersController = loader.getController();

View File

@@ -0,0 +1,23 @@
package ru.trader.view.support;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.util.Builder;
import javafx.util.BuilderFactory;
import org.controlsfx.glyphfont.Glyph;
public class CustomBuilderFactory implements BuilderFactory {
private BuilderFactory baseFactory;
public CustomBuilderFactory() {
baseFactory = new JavaFXBuilderFactory();
}
@Override
public Builder<?> getBuilder(Class<?> aClass) {
if (Glyph.class.equals(aClass)) {
return new GlyphBuilder();
} else {
return baseFactory.getBuilder(aClass);
}
}
}

View File

@@ -0,0 +1,24 @@
package ru.trader.view.support;
import javafx.util.Builder;
import org.controlsfx.glyphfont.Glyph;
import org.controlsfx.glyphfont.GlyphFontRegistry;
public class GlyphBuilder implements Builder<Glyph> {
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
private String text;
@Override
public Glyph build() {
return (Glyph) GlyphFontRegistry.glyph(text);
}
}