Skip to content

Commit

Permalink
Adding the package org.luwrain.interaction.javafx.browser
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Jul 20, 2020
1 parent c981dd1 commit 09f4b5b
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 44 deletions.
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<fileset dir="../lib"><include name="**/*.jar"/></fileset>
<fileset dir="../base/jar"><include name="**/*.jar"/></fileset>
<fileset dir="../luwrain/jar"><include name="**/*.jar"/></fileset>
<fileset dir="../browser/jar"><include name="**/*.jar"/></fileset>
<fileset dir="../io/jar"><include name="**/*.jar"/></fileset>
</path>
<path id="mainjar">
<pathelement location="."/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -21,12 +21,12 @@

public final class InvalidThreadException extends RuntimeException
{
InvalidThreadException(String message)
public InvalidThreadException(String message)
{
super(message);
}

static void checkThread(String funcName)
static public void checkThread(String funcName)
{
if(!Platform.isFxApplicationThread())
throw new InvalidThreadException(funcName + " runs in the invalid thread");
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/org/luwrain/interaction/javafx/JavaFxInteraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@

import org.luwrain.core.*;
import org.luwrain.base.*;
import org.luwrain.browser.*;
//import org.luwrain.browser.*;
import org.luwrain.util.*;

import org.luwrain.interaction.javafx.browser.*;

public final class JavaFxInteraction implements Interaction
{
static final String LOG_COMPONENT = "javafx";
Expand All @@ -47,8 +49,8 @@ public final class JavaFxInteraction implements Interaction
private String fontName = "Monospaced";
private MainApp app = null;

private final List<BrowserImpl> browsers = new Vector();
private BrowserImpl currentBrowser = null;
private final List<org.luwrain.interaction.javafx.browser.BrowserImpl> browsers = new Vector();
private org.luwrain.interaction.javafx.browser.BrowserImpl currentBrowser = null;
private boolean graphicalMode = false;

@Override public boolean init(final InteractionParams params,final OperatingSystem os)
Expand Down Expand Up @@ -242,18 +244,23 @@ private Font createFont2(int desirableFontSize)
return res;
}

@Override public Browser createBrowser()
@Override public GraphicalMode openGraphicalMode(String modeName, GraphicalMode.Params params)
{
NullCheck.notEmpty(modeName, "modeName");
NullCheck.notNull(params, "params");
switch(modeName.toUpperCase())
{
case "BROWSER":
return new BrowserImpl(this);
}

@Override public org.luwrain.interaction.graphical.Pdf createPdfPreview(org.luwrain.interaction.graphical.Pdf.Listener listener, File file) throws Exception
{
NullCheck.notNull(listener, "listener");
NullCheck.notNull(file, "file");
final PdfPreview preview = new PdfPreview(this, listener, file);
case "PDF": {
final PdfPreview preview = new PdfPreview(this, params);
preview.init();
return preview;
}
default:
Log.error(LOG_COMPONENT, "unknown graphical mode name: " + modeName);
return null;
}
}

// change current page to curPage, if it null, change previous current page to not visible
Expand All @@ -266,7 +273,7 @@ private void setCurrentBrowser(BrowserImpl newCurrentBrowser, boolean visibility
currentBrowser.setVisibility(visibility);
}

void registerBrowser(BrowserImpl browser, WebView webView)
public void registerBrowser(BrowserImpl browser, WebView webView)
{
NullCheck.notNull(browser, "browser");
NullCheck.notNull(webView, "webView");
Expand All @@ -278,7 +285,7 @@ void registerBrowser(BrowserImpl browser, WebView webView)
setCurrentBrowser(browser, false);
}

boolean closeBrowser(BrowserImpl browser)
public boolean closeBrowser(BrowserImpl browser)
{
NullCheck.notNull(browser, "browser");
final int pos = browsers.indexOf(browser);
Expand All @@ -303,12 +310,12 @@ void closeCanvas(ResizableCanvas canvas)
app.root.getChildren().remove(canvas);
}

void enableGraphicalMode()
public void enableGraphicalMode()
{
this.graphicalMode = true;
}

void disableGraphicalMode()
public void disableGraphicalMode()
{
this.graphicalMode = false;
app.stage.requestFocus();
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/luwrain/interaction/javafx/PdfPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
import org.apache.pdfbox.rendering.PDFRenderer;

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

final class PdfPreview implements org.luwrain.interaction.graphical.Pdf
final class PdfPreview implements org.luwrain.graphical.Pdf
{
static final String LOG_COMPONENT = "pdf";

private final JavaFxInteraction interaction;
private ResizableCanvas canvas = null;
private final org.luwrain.interaction.graphical.Pdf.Listener listener;
private final org.luwrain.graphical.Pdf.Listener listener;

private final PDDocument doc;
private final PDFRenderer rend;
Expand All @@ -55,14 +56,13 @@ final class PdfPreview implements org.luwrain.interaction.graphical.Pdf
private double offsetX = 0;
private double offsetY = 0;

PdfPreview(JavaFxInteraction interaction, org.luwrain.interaction.graphical.Pdf.Listener listener, File file) throws Exception
PdfPreview(JavaFxInteraction interaction, GraphicalMode.Params params)
{
NullCheck.notNull(interaction, "interaction");
NullCheck.notNull(listener, "listener");
NullCheck.notNull(params, "params");
this.interaction = interaction;
this.listener = listener;
this.doc = PDDocument.load(file);
Log.debug(LOG_COMPONENT, "PDF file " + file.getAbsolutePath() + " loaded");
this.listener = null;//listener;
this.doc = null;//PDDocument.load(file);
this.rend = new PDFRenderer(doc);
Log.debug(LOG_COMPONENT, "PDF renderer created");
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/luwrain/interaction/javafx/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand Down Expand Up @@ -27,17 +27,17 @@
import org.luwrain.core.*;
import org.luwrain.base.InteractionParamColor;

class Utils
public class Utils
{
static private final String LOG_COMPONENT = JavaFxInteraction.LOG_COMPONENT;

static void ensureFxThread()
static public void ensureFxThread()
{
if(!Platform.isFxApplicationThread())
throw new RuntimeException("Execution in non-jfx thread");
}

static Object callInFxThreadSync(Callable callable)
static public Object callInFxThreadSync(Callable callable)
{
NullCheck.notNull(callable, "callable");
if(Platform.isFxApplicationThread())
Expand Down Expand Up @@ -66,7 +66,7 @@ static Object callInFxThreadSync(Callable callable)
}
}

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

static void runInFxThreadAsync(Runnable runnable)
static public void runInFxThreadAsync(Runnable runnable)
{
NullCheck.notNull(runnable, "runnable");
if(Platform.isFxApplicationThread())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -15,7 +15,7 @@
General Public License for more details.
*/

package org.luwrain.interaction.javafx;
package org.luwrain.interaction.javafx.browser;

import java.util.*;

Expand All @@ -32,6 +32,7 @@
import com.sun.webkit.dom.DOMWindowImpl;

import org.luwrain.core.*;
import org.luwrain.interaction.javafx.*;
import org.luwrain.browser.BrowserEvents;

abstract class BrowserBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -15,7 +15,7 @@
General Public License for more details.
*/

package org.luwrain.interaction.javafx;
package org.luwrain.interaction.javafx.browser;

import java.awt.Rectangle;
import java.io.*;
Expand All @@ -37,16 +37,17 @@

import org.luwrain.core.*;
import org.luwrain.browser.*;
import org.luwrain.interaction.javafx.*;

final class BrowserImpl extends BrowserBase implements Browser
public final class BrowserImpl extends BrowserBase implements Browser
{
static private final String RESCAN_RESOURCE_PATH = "org/luwrain/interaction/javafx/injection.js";
static final int LAST_MODIFIED_SCAN_INTERVAL = 100; // lastModifiedTime rescan interval in milliseconds
static final String LUWRAIN_NODE_TEXT="luwrain_node_text"; // javascript window's property names for using in executeScrypt

private final JavaFxInteraction interaction;

BrowserImpl(JavaFxInteraction interaction)
public BrowserImpl(JavaFxInteraction interaction)
{
super(readTextResource(RESCAN_RESOURCE_PATH));
NullCheck.notNull(interaction, "interaction");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -15,7 +15,7 @@
General Public License for more details.
*/

package org.luwrain.interaction.javafx;
package org.luwrain.interaction.javafx.browser;

import java.awt.Rectangle;
import java.util.*;
Expand All @@ -27,6 +27,7 @@

import org.luwrain.core.*;
import org.luwrain.browser.*;
import org.luwrain.interaction.javafx.*;

final class IteratorImpl implements BrowserIterator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -15,13 +15,13 @@
General Public License for more details.
*/

package org.luwrain.interaction.javafx;
package org.luwrain.interaction.javafx.browser;

import org.luwrain.core.*;

class MyConsole
{
static private final String LOG_COMPONENT = JavaFxInteraction.LOG_COMPONENT;
static private final String LOG_COMPONENT = "web";

void log(Object text)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -15,7 +15,7 @@
General Public License for more details.
*/

package org.luwrain.interaction.javafx;
package org.luwrain.interaction.javafx.browser;

import org.w3c.dom.Node;
import java.awt.Rectangle;
Expand Down

0 comments on commit 09f4b5b

Please sign in to comment.