Skip to content

Commit

Permalink
Initial App files
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Pozhidaev committed Oct 13, 2018
1 parent 155db39 commit 93d6a8d
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/main/java/org/luwrain/app/viewer/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[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.app.viewer;

import java.util.*;
import java.io.*;

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

class App implements Application
{
private Luwrain luwrain = null;
private Strings strings = null;
private NavigationArea area = null;
private final File arg;

App()
{
arg = null;
}

App(File arg)
{
NullCheck.notNull(arg, "arg");
this.arg = arg;
}

@Override public InitResult onLaunchApp(Luwrain luwrain)
{
NullCheck.notNull(luwrain, "luwrain");
final Object o = luwrain.i18n().getStrings(Strings.NAME);
if (o == null || !(o instanceof Strings))
return new InitResult(InitResult.Type.NO_STRINGS_OBJ, Strings.NAME);
this.strings = (Strings)o;
this.luwrain = luwrain;
createArea();
return new InitResult();
}

private void createArea()
{
this.area = new NavigationArea(new DefaultControlEnvironment(luwrain)) {
@Override public String getLine(int index)
{
return "";
}
@Override public int getLineCount()
{
return 1;
}
@Override public boolean onInputEvent(KeyboardEvent event)
{
NullCheck.notNull(event, "event");
if (event.isSpecial() && !event.isModified())
switch(event.getSpecial())
{
case ESCAPE:
closeApp();
return true;
}
return super.onInputEvent(event);
}
@Override public boolean onSystemEvent(EnvironmentEvent event)
{
NullCheck.notNull(event, "event");
if (event.getType() != EnvironmentEvent.Type.REGULAR)
return super.onSystemEvent(event);
switch(event.getCode())
{
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()
{
return arg.getName();
}
};
}

@Override public void closeApp()
{
luwrain.closeApp();
}

@Override public AreaLayout getAreaLayout()
{
return new AreaLayout(area);
}

@Override public String getAppName()
{
return strings.appName();
}
}
24 changes: 24 additions & 0 deletions src/main/java/org/luwrain/app/viewer/Strings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[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.app.viewer;

public interface Strings
{
static final String NAME = "luwrain.viewer";

String appName();
}

0 comments on commit 93d6a8d

Please sign in to comment.