-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FontDialog and FontFamilyDialog load font collections from mac os pre…
…ferences.
- Loading branch information
1 parent
cb4d008
commit 089a1a5
Showing
13 changed files
with
479 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
....jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/fontchooser/FontChooserModelFactories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jhotdraw8.fxcontrols.fontchooser; | ||
|
||
import javafx.application.Platform; | ||
import org.jhotdraw8.annotation.NonNull; | ||
import org.jhotdraw8.os.macos.MacOSPreferencesUtil; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class FontChooserModelFactories { | ||
private static Supplier<FontCollectionsFactory> singleton; | ||
|
||
static { | ||
if (MacOSPreferencesUtil.isMacOs()) singleton = MacOSFontCollectionsFactory::new; | ||
else singleton = DefaultFontCollectionsFactory::new; | ||
} | ||
|
||
private FontChooserModelFactories() { | ||
} | ||
|
||
public static Supplier<FontCollectionsFactory> getSingleton() { | ||
return singleton; | ||
} | ||
|
||
public static void setSingleton(Supplier<FontCollectionsFactory> singleton) { | ||
FontChooserModelFactories.singleton = singleton; | ||
} | ||
|
||
public static @NonNull FontChooserModel create() { | ||
FontChooserModel model = new FontChooserModel(); | ||
if (Platform.isFxApplicationThread()) { | ||
singleton.get().createAsync().thenAccept(m -> { | ||
model.getFontCollections().addAll(m); | ||
}); | ||
} else { | ||
model.getFontCollections().addAll(singleton.get().create()); | ||
} | ||
return model; | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/fontchooser/FontCollectionsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jhotdraw8.fxcontrols.fontchooser; | ||
|
||
import javafx.application.Platform; | ||
import javafx.concurrent.Task; | ||
import org.jhotdraw8.annotation.NonNull; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public interface FontCollectionsFactory { | ||
@NonNull List<FontCollection> create(); | ||
|
||
/** | ||
* Creates a FontChooserModel asynchronously in a worker thread, and completes the returned | ||
* {@link CompletableFuture} on the JavaFX Application Thread. | ||
* | ||
* @return a {@link CompletableFuture}. | ||
*/ | ||
default @NonNull CompletableFuture<List<FontCollection>> createAsync() { | ||
CompletableFuture<List<FontCollection>> future = new CompletableFuture<>(); | ||
Task<List<FontCollection>> task = new Task<List<FontCollection>>() { | ||
@Override | ||
protected List<FontCollection> call() throws Exception { | ||
return create(); | ||
} | ||
|
||
@Override | ||
protected void failed() { | ||
Platform.runLater(() -> future.completeExceptionally(getException())); | ||
} | ||
|
||
@Override | ||
protected void succeeded() { | ||
Platform.runLater(() -> future.complete(getValue())); | ||
} | ||
}; | ||
new Thread(task).start(); | ||
return future; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.