Skip to content

Commit

Permalink
Cleaning OnScreenLineTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Apr 29, 2021
1 parent 371b859 commit 7409f61
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 357 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/luwrain/interaction/javafx/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javafx.scene.text.*;

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

public final class App extends Application
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.luwrain.base.*;
import org.luwrain.util.*;
import org.luwrain.interaction.javafx.browser.Browser;
import org.luwrain.graphical.javafx.*;

public final class JavaFxInteraction implements Interaction
{
Expand Down Expand Up @@ -244,6 +245,15 @@ private Font createFont2(int desirableFontSize)
return res;
}

@Override public void showGraphical(Object obj)
{
NullCheck.notNull(obj, "obj");
if (!(obj instanceof javafx.scene.Node))
throw new ClassCastException("The object must be an instance of javafx.scene.Node");
app.putNew((javafx.scene.Node)obj);
this.graphicalMode = true;
}

@Override public GraphicalMode openGraphicalMode(String modeName, GraphicalMode.Params params)
{
NullCheck.notEmpty(modeName, "modeName");
Expand Down Expand Up @@ -277,9 +287,12 @@ private Font createFont2(int desirableFontSize)
return null;
}
case "PDF": {
/*
final PdfPreview preview = new PdfPreview(this, params);
preview.init();
return preview;
*/
return null;
}
default:
Log.error(LOG_COMPONENT, "unknown graphical mode name: " + modeName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -17,34 +17,34 @@

package org.luwrain.interaction.javafx;

import java.util.Vector;
import org.luwrain.core.Log;
import java.util.*;

public class OnScreenLineTracker
import org.luwrain.core.*;

public final class OnScreenLineTracker
{
class Vertex
final class Vertex
{
public int pos = 0;
public boolean followed = false;

public Vertex(int pos, boolean followed)
final int pos;
boolean followed;
Vertex(int pos, boolean followed)
{
this.pos = pos;
this.followed = followed;
}
}

private Vector<Vertex> vertices = new Vector<Vertex>();
private ArrayList<Vertex> vertices = new ArrayList();

public void cover(int pos1, int pos2)
void cover(int pos1, int pos2)
{
if (pos1 < 0 || pos1 > pos2)
return;
addVertex(pos1);
addVertex(pos2 + 1);
for(int i = 0;i < vertices.size();i++)
{
Vertex v = vertices.get(i);
final Vertex v = vertices.get(i);
if (v.pos >= pos1 && v.pos <= pos2)
v.followed = true;
if (v.pos > pos2)
Expand All @@ -53,7 +53,7 @@ public void cover(int pos1, int pos2)
removeNeedless();
}

public void uncover(int pos1, int pos2)
void uncover(int pos1, int pos2)
{
if (pos1 < 0 || pos1 > pos2)
return;
Expand All @@ -70,7 +70,7 @@ public void uncover(int pos1, int pos2)
removeNeedless();
}

public void clear()
void clear()
{
vertices.clear();
}
Expand All @@ -79,7 +79,7 @@ public OnScreenLine[] getLines()
{
if (vertices.size() < 2)
return new OnScreenLine[0];
OnScreenLine[] lines = new OnScreenLine[vertices.size() / 2];
final OnScreenLine[] lines = new OnScreenLine[vertices.size() / 2];
for(int i = 0;i < vertices.size() / 2;i++)
{
if (!vertices.get(2 * i).followed || vertices.get((2 * i) + 1).followed ||
Expand Down Expand Up @@ -119,9 +119,9 @@ private void removeNeedless()
}
if (offset > 0)
{
for(int i = offset;i < vertices.size();i++)
vertices.set(i - offset, vertices.get(i));
vertices.setSize(vertices.size() - offset);
final List<Vertex> t = vertices.subList(offset, vertices.size());
vertices.clear();
vertices.addAll(t);
}
if (vertices.size() < 2)
return;
Expand All @@ -133,7 +133,9 @@ private void removeNeedless()
offset++; else
vertices.set(i - offset, vertices.get(i));
}
vertices.setSize(vertices.size() - offset);
final List<Vertex> t = vertices.subList(0, vertices.size() - offset);
vertices.clear();
vertices.addAll(t);
if (!vertices.isEmpty() && (vertices.size() % 2) != 0)
{
Log.warning("interaction", "on screen lines tracking has odd vertex count:" + vertices.size() + ", clearing content");
Expand Down
Loading

0 comments on commit 7409f61

Please sign in to comment.