Skip to content

Commit

Permalink
Opening a PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Pozhidaev committed Oct 13, 2018
1 parent 3f597a2 commit f09b72b
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions src/main/java/org/luwrain/app/viewer/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
import org.luwrain.core.*;
import org.luwrain.core.events.*;
import org.luwrain.controls.*;
import org.luwrain.interaction.graphical.*;

class App implements Application
class App implements Application, Pdf.Listener
{
private Luwrain luwrain = null;
private Strings strings = null;
private NavigationArea area = null;

private final File arg;
private Pdf pdf = null;
private String[] text = new String[0];

App()
{
Expand Down Expand Up @@ -58,11 +62,11 @@ private void createArea()
this.area = new NavigationArea(new DefaultControlEnvironment(luwrain)) {
@Override public String getLine(int index)
{
return "";
return index < text.length?text[index]:"";
}
@Override public int getLineCount()
{
return 1;
return text.length > 0?text.length:1;
}
@Override public boolean onInputEvent(KeyboardEvent event)
{
Expand All @@ -86,30 +90,41 @@ private void createArea()
case CLOSE:
closeApp();
return true;
/*
{
try {
luwrain.createPdfPreview((ev)->{
return false;
}, new File("/tmp/pr.pdf"));
}
catch(Exception e)
{
luwrain.crash(e);
}
return true;
*/
default:
return super.onSystemEvent(event);
}
}
@Override public String getAreaName()
@Override public String getAreaName()
{
return arg.getName();
return arg != null?arg.getName():strings.appName();
}
};
}

private void loadFile(File file)
{
NullCheck.notNull(file, "file");
try {
this.pdf = luwrain.createPdfPreview(this, file);
}
catch(Exception e)
{
this.text = new String[]{
"",
"ERROR:",
e.getClass().getName(),
e.getMessage(),
};
luwrain.onAreaNewContent(area);
}
}

@Override public boolean onInputEvent(KeyboardEvent event)
{
NullCheck.notNull(event, "event");
return false;
}

@Override public void closeApp()
{
luwrain.closeApp();
Expand Down

0 comments on commit f09b72b

Please sign in to comment.