Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow administrator-defined embedded fonts #90

Merged
merged 15 commits into from
Mar 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions annis-gui/src/main/java/annis/gui/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public class QueryController implements PagingCallback
private ResultViewPanel lastResultView;
private AnnisResultQuery resultFetcher;
private MatchAndDocumentCount lastCount;


public QueryController(SearchUI ui)
{
this.ui = ui;
this.history = new ListOrderedSet<HistoryEntry>();

}

public void updateCorpusSetList()
Expand Down Expand Up @@ -173,7 +173,7 @@ public void executeQuery(boolean executeCount, boolean executeResult)
{
ui.getMainTab().removeComponent(lastResultView);
}
lastResultView = new ResultViewPanel(this, ui);
lastResultView = new ResultViewPanel(this, ui, ui.getInstanceConfig());
ui.getMainTab().addTab(lastResultView, "Query Result");
ui.getMainTab().setSelectedTab(lastResultView);

Expand Down
40 changes: 37 additions & 3 deletions annis-gui/src/main/java/annis/gui/SearchUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import annis.libgui.InstanceConfig;
import annis.libgui.Helper;
import annis.gui.components.ScreenshotMaker;
import annis.gui.components.VirtualKeyboard;
import annis.gui.controlpanel.ControlPanel;
import annis.libgui.media.MediaController;
import annis.libgui.media.MimeTypeErrorListener;
Expand Down Expand Up @@ -59,6 +60,7 @@
import net.xeoh.plugins.base.util.uri.ClassURI;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.vaadin.cssinject.CSSInject;

/**
* GUI for searching in corpora.
Expand Down Expand Up @@ -91,6 +93,7 @@ public class SearchUI extends AnnisBaseUI
private QueryController queryController;
private String lastQueriedFragment;
private InstanceConfig instanceConfig;
private CSSInject css;

public final static int CONTROL_PANEL_WIDTH = 360;

Expand All @@ -115,6 +118,8 @@ protected void init(VaadinRequest request)

final ScreenshotMaker screenshot = new ScreenshotMaker(this);
addExtension(screenshot);

css = new CSSInject(this);

HorizontalLayout layoutToolbar = new HorizontalLayout();
layoutToolbar.setWidth("100%");
Expand All @@ -132,15 +137,15 @@ protected void init(VaadinRequest request)

@Override
public void buttonClick(ClickEvent event)
{
{
Window w = new AboutWindow();
w.setCaption("About ANNIS");
w.setModal(true);
w.setResizable(true);
w.setWidth("500px");
w.setHeight("500px");
addWindow(w);
w.center();
//addWindow(w);
//w.center();
}
});

Expand Down Expand Up @@ -313,11 +318,35 @@ public boolean handleRequest(VaadinSession session, VaadinRequest request,

getSession().setAttribute(MediaController.class, new MediaControllerImpl());

loadInstanceFonts();
checkCitation(request);
lastQueriedFragment = "";
evaluateFragment(getPage().getUriFragment());
}

private void loadInstanceFonts()
{
if(instanceConfig != null && css != null && instanceConfig.getFont() != null)
{
FontConfig cfg = instanceConfig.getFont();
css.setStyles(
"@import url(" + cfg.getUrl() + ");\n"
+ ".corpus-font-force {font-family: '" + cfg.getName() + "', monospace !important;}\n"
+ ".corpus-font {font-family: '" + cfg.getName() + "', monospace;}\n"
// this one is for the virtual keyboard
+ "#keyboardInputMaster tbody tr td table tbody tr td {\n"
+ " font-family: '" + cfg.getName() + "', 'Lucida Console','Arial Unicode MS',monospace;"
+ "}");
}
else
{
css.setStyles(
// use original font definition from keyboard.css if no font given
"#keyboardInputMaster tbody tr td table tbody tr td {\n"
+ " font-family: 'Lucida Console','Arial Unicode MS',monospace;"
+ "}");
}
}

private InstanceConfig getInstanceConfig(VaadinRequest request)
{
Expand Down Expand Up @@ -515,6 +544,11 @@ public ControlPanel getControlPanel()
return controlPanel;
}

public InstanceConfig getInstanceConfig()
{
return instanceConfig;
}

@Override
public void screenshotReceived(byte[] imageData, String mimeType)
{
Expand Down
92 changes: 92 additions & 0 deletions annis-gui/src/main/java/annis/gui/components/VirtualKeyboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2013 Corpuslinguistic working group Humboldt University Berlin.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package annis.gui.components;

import com.vaadin.annotations.JavaScript;
import com.vaadin.annotations.StyleSheet;
import com.vaadin.server.AbstractJavaScriptExtension;
import com.vaadin.server.ClientConnector;
import com.vaadin.shared.JavaScriptExtensionState;
import com.vaadin.ui.JavaScriptFunction;
import com.vaadin.ui.TextArea;
import org.json.JSONArray;
import org.json.JSONException;

/**
*
* @author Thomas Krause <[email protected]>
*/
@StyleSheet({"keyboard.css"})
@JavaScript({"jquery-1.9.1.min.js","keyboard.js", "virtualkeyboard.js"})
public class VirtualKeyboard extends AbstractJavaScriptExtension
{
public VirtualKeyboard()
{
addFunction("updateLang", new JavaScriptFunction() {

@Override
public void call(JSONArray arguments) throws JSONException
{
((VKState) getState()).setKeyboardLayout(arguments.getString(0));
}
});
}

@Override
protected Class<? extends ClientConnector> getSupportedParentType()
{
return TextArea.class;
}

public void extend(TextArea target)
{
super.extend(target);

}

@Override
protected VKState getState()
{
return (VKState) super.getState();
}

public void show()
{
callFunction("show");
}

public void setKeyboardLayout(String layout)
{
getState().setKeyboardLayout(layout);
}

public static class VKState extends JavaScriptExtensionState
{
private String keyboardLayout = "";

public String getKeyboardLayout()
{
return keyboardLayout;
}

public void setKeyboardLayout(String keyboardLayout)
{
this.keyboardLayout = keyboardLayout;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ControlPanel(QueryController controller, InstanceConfig instanceConfig)

searchOptions = new SearchOptionsPanel();

queryPanel = new QueryPanel(controller);
queryPanel = new QueryPanel(controller, instanceConfig);
queryPanel.setHeight("-1px");
queryPanel.setWidth("100%");

Expand Down
46 changes: 40 additions & 6 deletions annis-gui/src/main/java/annis/gui/controlpanel/QueryPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@
import annis.gui.HistoryPanel;
import annis.gui.QueryController;
import annis.gui.beans.HistoryEntry;
import annis.gui.components.VirtualKeyboard;
import annis.gui.model.Query;
import annis.libgui.InstanceConfig;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.event.FieldEvents;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.server.ClassResource;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.*;
import com.vaadin.ui.themes.ChameleonTheme;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -63,7 +68,7 @@ public class QueryPanel extends GridLayout implements TextChangeListener,
private List<HistoryEntry> history;
private Window historyWindow;

public QueryPanel(final QueryController controller)
public QueryPanel(final QueryController controller, InstanceConfig instanceConfig)
{
super(2,3);
this.controller = controller;
Expand All @@ -82,14 +87,26 @@ public QueryPanel(final QueryController controller)

txtQuery = new TextArea();
txtQuery.addStyleName("query");
txtQuery.addStyleName("corpus-font");
txtQuery.addStyleName("keyboardInput");
txtQuery.setWidth("100%");
txtQuery.setHeight(10f, Unit.EM);
txtQuery.setTextChangeTimeout(1000);
txtQuery.addTextChangeListener((TextChangeListener) this);


addComponent(txtQuery, 1, 0);


final VirtualKeyboard virtualKeyboard;
if(instanceConfig.getKeyboardLayout() == null)
{
virtualKeyboard = null;
}
else
{
virtualKeyboard = new VirtualKeyboard();
virtualKeyboard.setKeyboardLayout(instanceConfig.getKeyboardLayout());
virtualKeyboard.extend(txtQuery);
}
VerticalLayout panelStatusLayout = new VerticalLayout();
panelStatusLayout.setHeight(3.5f, Unit.EM);
panelStatusLayout.setWidth(100f, Unit.PERCENTAGE);
Expand Down Expand Up @@ -119,8 +136,8 @@ public QueryPanel(final QueryController controller)


btShowResult = new Button("Show Result");
btShowResult.setWidth(100f, UNITS_PERCENTAGE);
btShowResult.addListener(new ShowResultClickListener());
btShowResult.setWidth("100%");
btShowResult.addClickListener(new ShowResultClickListener());
btShowResult.setDescription("<strong>Show Result</strong><br />Ctrl + Enter");
btShowResult.setClickShortcut(KeyCode.ENTER, ModifierKey.CTRL);

Expand Down Expand Up @@ -169,12 +186,29 @@ public void buttonClick(ClickEvent event)
historyListLayout.setExpandRatio(btShowMoreHistory, 0.0f);

btHistory = new PopupButton("History");
btHistory.setWidth(100f, Unit.PERCENTAGE);
btHistory.setContent(historyListLayout);
btHistory.setDescription("<strong>Show History</strong><br />"
+ "Either use the short overview (arrow down) or click on the button "
+ "for the extended view.");
buttonLayout.addComponent(btHistory);

if(virtualKeyboard != null)
{
Button btShowKeyboard = new Button();
btShowKeyboard.setDescription("Click to show a virtual keyboard");
btShowKeyboard.addStyleName(ChameleonTheme.BUTTON_ICON_ONLY);
btShowKeyboard.setIcon(new ClassResource(VirtualKeyboard.class, "keyboard.png"));
btShowKeyboard.addClickListener(new Button.ClickListener() {

@Override
public void buttonClick(ClickEvent event)
{
virtualKeyboard.show();
}
});
buttonLayout.addComponent(btShowKeyboard);
}
buttonLayout.setExpandRatio(btShowResult, 1.0f);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import annis.CommonHelper;
import annis.libgui.Helper;
import annis.libgui.InstanceConfig;
import annis.libgui.PluginSystem;
import annis.resolver.ResolverEntry;
import annis.resolver.ResolverEntry.ElementType;
Expand Down Expand Up @@ -72,8 +73,9 @@ public class ResultSetPanel extends Panel implements ResolverProvider
private ProgressIndicator indicator;
private VerticalLayout indicatorLayout;
private CssLayout layout;
private InstanceConfig instanceConfig;

public ResultSetPanel(List<Match> matches, PluginSystem ps,
public ResultSetPanel(List<Match> matches, PluginSystem ps, InstanceConfig instanceConfig,
int contextLeft, int contextRight,
String segmentationName,
ResultViewPanel parent, int firstMatchOffset)
Expand All @@ -85,6 +87,7 @@ public ResultSetPanel(List<Match> matches, PluginSystem ps,
this.parent = parent;
this.matches = Collections.synchronizedList(matches);
this.firstMatchOffset = firstMatchOffset;
this.instanceConfig = instanceConfig;

resultPanelList =
Collections.synchronizedList(new LinkedList<SingleResultPanel>());
Expand Down Expand Up @@ -195,7 +198,7 @@ private List<SingleResultPanel> createPanels(SaltProject p, int offset)
for (SCorpusGraph corpusGraph : p.getSCorpusGraphs())
{
SingleResultPanel panel = new SingleResultPanel(corpusGraph.getSDocuments().get(0),
i + offset, this, ps, tokenAnnotationLevelSet, segmentationName);
i + offset, this, ps, tokenAnnotationLevelSet, segmentationName, instanceConfig);
i++;

panel.setWidth("100%");
Expand Down
Loading