Skip to content

Commit

Permalink
feat: drop LabelHelper#text(UILabel)
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Nov 8, 2024
1 parent 1bf5231 commit 4330513
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 67 deletions.
15 changes: 6 additions & 9 deletions src/main/java/viewtify/preference/PreferenceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Set;

import org.controlsfx.glyphfont.FontAwesome;
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;

import javafx.collections.ObservableList;
import javafx.scene.Node;
Expand Down Expand Up @@ -80,8 +81,8 @@ protected ViewDSL declareUI() {
});
$(vbox, style.right, () -> {
$(hbox, style.bar, () -> {
$(importer);
$(exporter);
$(importer, style.icon);
$(exporter, style.icon);
$(search, FormStyles.Column5, style.search);
});
$(scroll, FormStyles.Preferences, () -> {
Expand Down Expand Up @@ -143,7 +144,7 @@ interface style extends StyleDSL {
};

Style icon = () -> {
font.size(18, px).family("FontAwesome").color("-fx-mid-text-color");
font.size(13, px).color("-fx-mid-text-color");
padding.size(6, px);
cursor.pointer();

Expand All @@ -158,12 +159,8 @@ interface style extends StyleDSL {
*/
@Override
protected void initialize() {
importer.text(FontAwesome.Glyph.DOWNLOAD, style.icon)
.tooltip(en("Import preferences from file"))
.when(User.LeftClick, this::importPrefernces);
exporter.text(FontAwesome.Glyph.UPLOAD, style.icon)
.tooltip(en("Export the current preferences"))
.when(User.LeftClick, this::exportPreferences);
importer.text(FontAwesomeSolid.DOWNLOAD).tooltip(en("Import preferences from file")).when(User.LeftClick, this::importPrefernces);
exporter.text(FontAwesomeSolid.UPLOAD).tooltip(en("Export the current preferences")).when(User.LeftClick, this::exportPreferences);

search.placeholder(en("Search from preferences")).clearable().prefix(FontAwesome.Glyph.SEARCH).observe().to(text -> {
text = text.strip().toLowerCase();
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/viewtify/ui/calendar/CalendarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import org.controlsfx.glyphfont.FontAwesome;
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;

import kiss.I;
import kiss.Managed;
Expand Down Expand Up @@ -78,9 +78,9 @@ protected ViewDSL declareUI() {
$(selectToday, Styles.today, FormStyles.Column2);

$(hbox, Styles.headerCenter, () -> {
$(selectPrevious);
$(selectPrevious, Styles.selector);
$(current, Styles.current);
$(selectNext);
$(selectNext, Styles.selector);
});

$(hbox, Styles.headerRight, () -> {
Expand All @@ -106,8 +106,8 @@ interface Styles extends StyleDSL {
};

Style selector = () -> {
font.size(20, px).color("-fx-mid-text-color").family("FontAwesome");
padding.horizontal(6, px).top(-4, px);
font.color("-fx-mid-text-color").size(14, px);
padding.horizontal(8, px).vertical(2, px);
};

Style current = () -> {
Expand Down Expand Up @@ -154,16 +154,16 @@ interface Styles extends StyleDSL {
protected void initialize() {
CalendarSetting setting = Preferences.of(CalendarSetting.class);

selectNext.text(FontAwesome.Glyph.ANGLE_RIGHT, Styles.selector).action(() -> currentView.next());
selectPrevious.text(FontAwesome.Glyph.ANGLE_LEFT, Styles.selector).action(() -> currentView.previous());
selectNext.text(FontAwesomeSolid.ANGLE_RIGHT).action(() -> currentView.next());
selectPrevious.text(FontAwesomeSolid.ANGLE_LEFT).action(() -> currentView.previous());
selectToday.text(I.translate("Today")).action(() -> currentView.today());

switchToDay.text(I.translate("Day")).action(() -> show(DayView.class, currentDate));
switchToWeek.text(I.translate("Week")).action(() -> show(WeekView.class, currentDate));
switchToMonth.text(I.translate("Month")).action(() -> show(MonthView.class, currentDate));
switchToYear.text(I.translate("Year")).action(() -> show(YearView.class, currentDate));

preference.text(FontAwesome.Glyph.GEAR).popup(CalendarSettingView::new);
preference.text(FontAwesomeSolid.COG).popup(CalendarSettingView::new);

show(setting.initialView.v, LocalDate.now());

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/viewtify/ui/calendar/Visualizers.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
package viewtify.ui.calendar;

import org.controlsfx.glyphfont.FontAwesome;
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;

import javafx.scene.Node;
import kiss.Managed;
Expand Down Expand Up @@ -230,9 +230,9 @@ interface Styles extends StyleDSL {
*/
@Override
protected void initialize() {
edit.text(FontAwesome.Glyph.PENCIL).tooltip(en("Edit")).enable(event.isEditable());
delete.text(FontAwesome.Glyph.TRASH).tooltip(en("Delete")).enable(event.isEditable());
close.text(FontAwesome.Glyph.CLOSE).tooltip(en("Close")).when(User.LeftClick, ViewtyDialog::close);
edit.text(FontAwesomeSolid.PEN).tooltip(en("Edit")).enable(event.isEditable());
delete.text(FontAwesomeSolid.TRASH).tooltip(en("Delete")).enable(event.isEditable());
close.text(FontAwesomeSolid.CROSS).tooltip(en("Close")).when(User.LeftClick, ViewtyDialog::close);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/viewtify/ui/dock/DockSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.concurrent.TimeUnit;
import java.util.function.UnaryOperator;

import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand Down Expand Up @@ -48,9 +50,6 @@
import javafx.stage.StageStyle;
import javafx.stage.Window;
import javafx.stage.WindowEvent;

import org.controlsfx.glyphfont.FontAwesome;

import kiss.I;
import kiss.Managed;
import kiss.Signal;
Expand Down Expand Up @@ -326,7 +325,7 @@ private static void openNewWindow(RootArea area, Bounds bounds, EventHandler<Win
*/
public static void initialize() {
initialize(icon -> {
icon.text(FontAwesome.Glyph.BARS).behaveLikeButton().context(menus -> {
icon.text(FontAwesomeSolid.BARS).behaveLikeButton().context(menus -> {
menus.menu(I.translate("Open new page"), sub -> {
for (DockProvider provider : I.find(DockProvider.class)) {
for (Dock item : provider.findDocks()) {
Expand Down
57 changes: 19 additions & 38 deletions src/main/java/viewtify/ui/helper/LabelHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import org.controlsfx.glyphfont.Glyph;
import org.controlsfx.glyphfont.INamedCharacter;
import org.kordamp.ikonli.Ikon;
import org.kordamp.ikonli.javafx.FontIcon;

import javafx.collections.ObservableList;
import javafx.geometry.Insets;
Expand All @@ -32,7 +34,6 @@
import stylist.value.Color;
import viewtify.StyleManipulator;
import viewtify.Viewtify;
import viewtify.ui.UILabel;
import viewtify.ui.UserInterfaceProvider;
import viewtify.util.FXUtils;

Expand Down Expand Up @@ -78,72 +79,52 @@ default Self text(Variable text) {
}

/**
* Set text.
*
* @param text A text {@link Variable} to set.
* @return Chainable API.
*/
default Self text(INamedCharacter text) {
return text(text, (Style[]) null);
}

/**
* Set text.
* Set icon.
*
* @param text A text {@link Variable} to set.
* @param icon An icon font.
* @return Chainable API.
*/
default Self text(INamedCharacter text, Style... iconStyle) {
if (text != null) {
Glyph glyph = new Glyph("FontAwesome", text);
StyleHelper.of(glyph).style(iconStyle);
text(glyph);
default Self text(Ikon icon) {
if (icon != null) {
FontIcon font = new FontIcon(icon);
font.iconColorProperty().bind(property(Type.TextFill));
text(font);
}
return (Self) this;
}

/**
* Set honrizontal styled text.
* Set the specified {@link Node} as literal component.
*
* @param texts The text list.
* @param items A literal component to set.
* @return Chainable API.
*/
default Self text(UILabel... texts) {
default Self text(UserInterfaceProvider<? extends Node>... items) {
HBox box = new HBox();
box.setAlignment(Pos.CENTER);

for (int i = 0; i < texts.length; i++) {
box.getChildren().add(texts[i].ui);
for (UserInterfaceProvider<? extends Node> item : items) {
box.getChildren().add(item.ui().getStyleableNode());
}
return text(box);
}

/**
* Set vertical styled text.
* Set the specified {@link Node} as literal component.
*
* @param texts The text list.
* @param items A literal component to set.
* @return Chainable API.
*/
default Self textV(UILabel... texts) {
default Self textV(UserInterfaceProvider<? extends Node>... items) {
VBox box = new VBox();
box.setAlignment(Pos.CENTER);

for (int i = 0; i < texts.length; i++) {
box.getChildren().add(texts[i].ui);
for (UserInterfaceProvider<? extends Node> item : items) {
box.getChildren().add(item.ui());
}
return text(box);
}

/**
* Set the specified {@link Node} as literal component.
*
* @param text A literal component to set.
* @return Chainable API.
*/
default Self text(UserInterfaceProvider text) {
return text(text.ui().getStyleableNode());
}

/**
* Set the specified {@link Node} as literal component.
*
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/viewtify/ui/toast/Toast.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;

import javafx.beans.value.WritableDoubleValue;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand All @@ -27,9 +29,6 @@
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Popup;

import org.controlsfx.glyphfont.FontAwesome;

import kiss.Disposable;
import kiss.I;
import kiss.Signal;
Expand Down Expand Up @@ -487,7 +486,8 @@ private synchronized Popup ui() {
* @return
*/
private Node showCloseButton(Node node) {
UILabel label = new UILabel(null).text(FontAwesome.Glyph.CLOSE, styles.icon)
UILabel label = new UILabel(null).text(FontAwesomeSolid.TIMES)
.style(styles.icon)
.tooltip(I.translate("Stop this task."))
.when(User.LeftClick, () -> {
remove(this);
Expand Down Expand Up @@ -529,6 +529,7 @@ private static interface styles extends StyleDSL {

Style icon = () -> {
cursor.pointer();
padding.size(2, px);

$.hover(() -> {
font.color("-fx-focus-color");
Expand Down
2 changes: 2 additions & 0 deletions src/project/java/viewtify/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class Project extends bee.api.Project {
require("org.testfx", "openjfx-monocle", "jdk-12.0.1+2");
require("org.controlsfx", "controlsfx");
require("com.catwithawand", "BorderlessSceneFX");
require("org.kordamp.ikonli", "ikonli-javafx");
require("org.kordamp.ikonli", "ikonli-fontawesome5-pack");

versionControlSystem("https://github.com/teletha/viewtify");
}
Expand Down

0 comments on commit 4330513

Please sign in to comment.