Skip to content

Commit

Permalink
Removing javafx.Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Apr 30, 2021
1 parent e2107cb commit 715facc
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 391 deletions.
3 changes: 0 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
<fileset dir="./build/main">
<include name="**/*.class"/>
</fileset>
<fileset dir="./src/main/resources">
<include name="**/*.js"/>
</fileset>
</jar>
</target>
<target name="compile-test" depends="jar">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
General Public License for more details.
*/

package org.luwrain.graphical.javafx;
package org.luwrain.graphical;

import java.util.concurrent.*;
import javafx.application.Platform;
import javafx.scene.paint.Color;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

import org.luwrain.core.*;
import org.luwrain.base.InteractionParamColor;

public final class FxThread
{
Expand All @@ -37,7 +32,7 @@ static public void ensure()
throw new IllegalStateException("Execution in non-jfx thread");
}

static public Object callInFxThreadSync(Callable callable)
static public Object call(Callable callable)
{
NullCheck.notNull(callable, "callable");
if(Platform.isFxApplicationThread())
Expand All @@ -46,7 +41,7 @@ static public Object callInFxThreadSync(Callable callable)
}
catch(Throwable e)
{
Log.error(LOG_COMPONENT, "callable object thrown an exception:" + e.getClass().getName() + ":" + e.getMessage());
Log.error(LOG_COMPONENT, "callable object thrown an exception: " + e.getClass().getName() + ": " + e.getMessage());
throw new RuntimeException(e);
}
final FutureTask<Object> query=new FutureTask<Object>(callable);
Expand All @@ -61,12 +56,12 @@ static public Object callInFxThreadSync(Callable callable)
}
catch(ExecutionException e)
{
Log.error(LOG_COMPONENT, "execution exception in callable object processing:" + e.getClass().getName() + ":" + e.getMessage());
Log.error(LOG_COMPONENT, "execution exception during processing of the callable object: " + e.getClass().getName() + ": " + e.getMessage());
throw new RuntimeException(e);
}
}

static public void runInFxThreadSync(Runnable runnable)
static public void runSync(Runnable runnable)
{
NullCheck.notNull(runnable, "runnable");
if(Platform.isFxApplicationThread())
Expand Down Expand Up @@ -97,7 +92,7 @@ static public void runInFxThreadSync(Runnable runnable)
}
}

static public void runInFxThreadAsync(Runnable runnable)
static public void runAsync(Runnable runnable)
{
NullCheck.notNull(runnable, "runnable");
if(Platform.isFxApplicationThread())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
/*
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
package org.luwrain.graphical.javafx;
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.graphical;

import javafx.scene.canvas.Canvas;
import javafx.scene.layout.StackPane;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/luwrain/interaction/javafx/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import javafx.scene.text.*;

import org.luwrain.core.*;
import org.luwrain.graphical.javafx.*;
import org.luwrain.graphical.*;

public final class App extends Application
{
Expand Down Expand Up @@ -98,7 +98,7 @@ void setInteractionFont(Font font, Font font2)

synchronized boolean initTable()
{
InvalidThreadException.checkThread("MainApp.initTable()");
FxThread.ensure();
double width = canvasWidth;
double height = canvasHeight;
if (width < marginLeft + marginRight)
Expand Down Expand Up @@ -168,7 +168,7 @@ void setMargin(int marginLeft,int marginTop,int marginRight,int marginBottom)

void setSizeAndShow(int width, int height)
{
InvalidThreadException.checkThread("App.setSizeAndShow()");
FxThread.ensure();
this.canvasWidth = width;
this.canvasHeight = height;
this.rootPane.resize(width, height);
Expand All @@ -178,7 +178,7 @@ void setSizeAndShow(int width, int height)

void setUndecoratedSizeAndShow(double width, double height)
{
InvalidThreadException.checkThread("App.setUndecoratedSizeAndShow()");
FxThread.ensure();
this.canvasWidth = width;
this.canvasHeight = height;
this.rootPane.resize(width, height);
Expand Down Expand Up @@ -240,7 +240,7 @@ synchronized void clearRect(int left,int top,int right,int bottom)

synchronized void paint()
{
InvalidThreadException.checkThread("MainApp.paint()");
FxThread.ensure();
final double fontWidth = charBounds.getWidth();
final double fontHeight = charBounds.getHeight();
if(table==null)
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/org/luwrain/interaction/javafx/ColorUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.interaction.javafx;

import javafx.scene.paint.Color;
import org.luwrain.base.InteractionParamColor;

final class ColorUtils
{
static Color InteractionParamColorToFx(InteractionParamColor ipc)
{
if(ipc.getPredefined()==null)
return new Color(ipc.getRed()/256,ipc.getGreen()/256,ipc.getBlue()/256,1);
switch(ipc.getPredefined())
{
case BLACK: return Color.BLACK;
case BLUE: return Color.BLUE;
case CYAN: return Color.CYAN;
case DARK_GRAY: return Color.DARKGRAY;
case GRAY: return Color.GRAY;
case GREEN: return Color.GREEN;
case LIGHT_GRAY:return Color.LIGHTGRAY;
case MAGENTA: return Color.MAGENTA;
case ORANGE: return Color.ORANGE;
case PINK: return Color.PINK;
case RED: return Color.RED;
case WHITE: return Color.WHITE;
case YELLOW: return Color.YELLOW;
// WARN: not predefined colors have opacity = 1
default: return new Color(ipc.getRed()/256,ipc.getGreen()/256,ipc.getBlue()/256,1);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.luwrain.core.*;
import org.luwrain.base.*;
import org.luwrain.util.*;
import org.luwrain.graphical.javafx.*;
import org.luwrain.graphical.*;

public final class JavaFxInteraction implements Interaction
{
Expand Down Expand Up @@ -75,10 +75,10 @@ public final class JavaFxInteraction implements Interaction
int wndHeight = params.wndHeight;
app.setInteractionFont(createFont(currentFontSize),createFont2(currentFontSize));
app.setColors(
Utils.InteractionParamColorToFx(params.fontColor),
Utils.InteractionParamColorToFx(params.font2Color),
Utils.InteractionParamColorToFx(params.bkgColor),
Utils.InteractionParamColorToFx(params.splitterColor));
ColorUtils.InteractionParamColorToFx(params.fontColor),
ColorUtils.InteractionParamColorToFx(params.font2Color),
ColorUtils.InteractionParamColorToFx(params.bkgColor),
ColorUtils.InteractionParamColorToFx(params.splitterColor));
app.setMargin(params.marginLeft,params.marginTop,params.marginRight,params.marginBottom);
this.keyboard = os.getCustomKeyboardHandler("javafx");
app.getStage().addEventHandler(KeyEvent.KEY_PRESSED, (event)->{
Expand Down Expand Up @@ -140,7 +140,7 @@ public final class JavaFxInteraction implements Interaction

@Override public boolean setDesirableFontSize(int size)
{
final Object res = Utils.callInFxThreadSync(()->{
final Object res = FxThread.call(()->{
final Font oldFont = app.getInteractionFont();
final Font oldFont2 = app.getInteractionFont2();
final Font probeFont = createFont(size);
Expand Down Expand Up @@ -200,14 +200,14 @@ public final class JavaFxInteraction implements Interaction
{
drawingInProgress = false;
if (!graphicalMode)
Utils.runInFxThreadAsync(()->app.paint());
FxThread.runAsync(()->app.paint());
}

@Override public void setHotPoint(final int x,final int y)
{
app.setHotPoint(x, y);
if(!drawingInProgress)
Utils.runInFxThreadAsync(()->app.paint());
FxThread.runAsync(()->app.paint());
}

@Override public void drawVerticalLine(int top, int bottom,
Expand Down Expand Up @@ -333,7 +333,7 @@ public void closeBrowser(Browser browser)
void registerCanvas(ResizableCanvas canvas)
{
NullCheck.notNull(canvas, "canvas");
InvalidThreadException.checkThread("JavaFxInteraction.registerBrowser()");
FxThread.ensure();
app.putNew(canvas);
}

Expand Down
Loading

0 comments on commit 715facc

Please sign in to comment.