use of javafx.scene.text.Font in project JFoenix by jfoenixadmin.
the class JFXSliderSkinOLD method initialize.
private void initialize() {
isHorizontal = getSkinnable().getOrientation() == Orientation.HORIZONTAL;
thumb = new Circle();
thumb.setStrokeWidth(2);
thumb.setRadius(7);
thumb.setFill(thumbColor);
thumb.setStroke(thumbColor);
thumb.getStyleClass().setAll("thumb");
track = new Line();
track.setStroke(trackColor);
track.setStrokeWidth(3);
track.getStyleClass().setAll("track");
coloredTrack = new Line();
coloredTrack.strokeProperty().bind(thumb.strokeProperty());
coloredTrack.strokeWidthProperty().bind(track.strokeWidthProperty());
sliderValue = new Text();
sliderValue.setStroke(Color.WHITE);
sliderValue.setFont(new Font(10));
sliderValue.getStyleClass().setAll("sliderValue");
animatedThumb = new StackPane();
animatedThumb.getChildren().add(sliderValue);
getChildren().clear();
getChildren().addAll(track, coloredTrack, animatedThumb, thumb);
}
use of javafx.scene.text.Font in project fxexperience2 by EricCanull.
the class WebFontEncoder method loadFont.
/**
* Load a font from Google Web Fonts Service
*
* Note: this is only designed to work with simple stylesheets with single
* font in them.
*
* @param googleFontCssUrl The url to css stylesheet with @fontface
* definition
* @return The name of the font family, or "System" if there was a error
* @throws java.net.MalformedURLException
*/
public static String loadFont(String googleFontCssUrl) throws MalformedURLException {
String fontName = "System";
try {
URL cssUrl = new URL(googleFontCssUrl);
URLConnection con = cssUrl.openConnection();
InputStream in = con.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
String fontUrl = null;
StringBuilder srcs = new StringBuilder();
while ((line = reader.readLine()) != null) {
// System.out.println(line);
if (line.contains("src:")) {
Matcher matcher = TTF_PATTERN.matcher(line);
if (matcher.find()) {
fontUrl = matcher.group(0);
// System.out.println("FOUND fontUrl = " + fontUrl);
break;
}
matcher = OTF_PATTERN.matcher(line);
if (matcher.find()) {
fontUrl = matcher.group(0);
// System.out.println("FOUND fontUrl = " + fontUrl);
break;
}
srcs.append(line);
srcs.append('\n');
}
}
if (fontUrl != null) {
Font font = Font.loadFont(fontUrl, 10);
fontName = font.getFamily();
} else {
System.err.println("Failed to find any supported fonts " + "(TTF or OTF) in CSS src:\n" + srcs.toString());
}
} catch (IOException ex) {
Logger.getLogger(WebFontEncoder.class.getName()).log(Level.SEVERE, null, ex);
}
return fontName;
}
use of javafx.scene.text.Font in project aima-java by aimacode.
the class MapEnvironmentViewCtrl method update.
protected void update() {
envStateView.getChildren().clear();
if (env != null) {
double scale = adjustTransform();
Map map = env.getMap();
// print connections
for (String loc1 : map.getLocations()) {
Point2D pt1 = map.getPosition(loc1);
for (String loc2 : map.getPossibleNextLocations(loc1)) {
Point2D pt2 = map.getPosition(loc2);
Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
line.setStroke(Color.LIGHTGRAY);
envStateView.getChildren().add(line);
}
}
// print track of first agent
if (!env.getAgents().isEmpty()) {
String aLoc = env.getAgentLocation(env.getAgents().get(0));
if (track.isEmpty() || !Objects.equals(track.get(track.size() - 1), aLoc))
track.add(aLoc);
for (int i = 1; i < track.size(); i++) {
Point2D pt1 = map.getPosition(track.get(i - 1));
Point2D pt2 = map.getPosition(track.get(i));
Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
line.setStroke(Color.RED);
line.setStrokeWidth(2);
envStateView.getChildren().add(line);
}
}
// print locations
for (String loc : map.getLocations()) {
Point2D point = map.getPosition(loc);
Text text = new Text(point.getX() + 10 / scale, point.getY(), loc);
text.setFont(new Font(12.0 / scale));
envStateView.getChildren().add(text);
envStateView.getChildren().add(new Circle(point.getX(), point.getY(), 2 / scale));
}
// print agent locations
for (Agent agent : env.getAgents()) {
String loc = env.getAgentLocation(agent);
if (loc != null) {
Point2D pt = map.getPosition(loc);
envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 8 / scale, Color.RED));
}
}
// print goal
if (goal != null) {
Point2D pt = map.getPosition(goal);
envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 6 / scale, Color.GREEN));
}
}
}
use of javafx.scene.text.Font in project aima-java by aimacode.
the class TicTacToeApp method createRootPane.
/** Simple pane to control the game. */
@Override
public Pane createRootPane() {
BorderPane root = new BorderPane();
ToolBar toolBar = new ToolBar();
clearBtn = new Button("Clear");
clearBtn.setOnAction(ev -> initialize());
strategyCombo = new ComboBox<String>();
strategyCombo.getItems().addAll("Minimax", "Alpha-Beta", "Iterative Deepening Alpha-Beta", "Iterative Deepening Alpha-Beta (log)");
strategyCombo.getSelectionModel().select(0);
proposeBtn = new Button("Propose Move");
proposeBtn.setOnAction(ev -> proposeMove());
toolBar.getItems().addAll(clearBtn, new Separator(), strategyCombo, proposeBtn);
root.setTop(toolBar);
StackPane stateViewPane = new StackPane();
GridPane gridPane = new GridPane();
gridPane.maxWidthProperty().bind(Bindings.min(stateViewPane.widthProperty(), stateViewPane.heightProperty()).subtract(20));
gridPane.maxHeightProperty().bind(Bindings.min(stateViewPane.widthProperty(), stateViewPane.heightProperty()).subtract(20));
RowConstraints c1 = new RowConstraints();
c1.setPercentHeight(100.0 / 3);
ColumnConstraints c2 = new ColumnConstraints();
c2.setPercentWidth(100.0 / 3);
gridPane.setHgap(10);
gridPane.setVgap(10);
for (int i = 0; i < 3; i++) {
gridPane.getRowConstraints().add(c1);
gridPane.getColumnConstraints().add(c2);
}
Font font = Font.font(40);
for (int i = 0; i < 9; i++) {
Button btn = new Button();
btn.setOnAction(this::handleSquareButtonEvent);
btn.setFont(font);
btn.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
squareBtns[i] = btn;
gridPane.add(btn, i % 3, i / 3);
}
stateViewPane.getChildren().add(gridPane);
root.setCenter(stateViewPane);
statusLabel = new Label();
statusLabel.setMaxWidth(Double.MAX_VALUE);
statusLabel.setMaxWidth(Double.MAX_VALUE);
statusLabel.setAlignment(Pos.CENTER);
statusLabel.setFont(Font.font(16));
root.setBottom(statusLabel);
return root;
}
use of javafx.scene.text.Font in project processing by processing.
the class PGraphicsFX2D method handleTextFont.
/**
* FX specific. When setting font or size, new font has to
* be created. Both textFontImpl and textSizeImpl call this one.
* @param which font to be set, not null
* @param size size to be set, greater than zero
*/
protected void handleTextFont(PFont which, float size) {
textFont = which;
String fontName = which.getName();
String fontPsName = which.getPostScriptName();
textFontInfo = fontCache.get(fontName, size);
if (textFontInfo == null) {
Font font = null;
if (which.isStream()) {
// Load from ttf or otf file
String filename = fontCache.nameToFilename.get(fontName);
font = Font.loadFont(parent.createInput(filename), size);
}
if (font == null) {
// Look up font name
font = new Font(fontName, size);
if (!fontName.equalsIgnoreCase(font.getName())) {
// Look up font postscript name
font = new Font(fontPsName, size);
if (!fontPsName.equalsIgnoreCase(font.getName())) {
// Done with it
font = null;
}
}
}
if (font == null && which.getNative() != null) {
// Ain't got nothing, but AWT has something, so glyph images are not
// going to be used for this font; go with the default font then
font = new Font(size);
}
textFontInfo = fontCache.createFontInfo(font);
fontCache.put(fontName, size, textFontInfo);
}
context.setFont(textFontInfo.font);
}
Aggregations