Search in sources :

Example 1 with AnnisBaseUI

use of annis.libgui.AnnisBaseUI in project ANNIS by korpling.

the class ExportPanel method attach.

@Override
public void attach() {
    super.attach();
    this.ui = UI.getCurrent();
    if (this.ui instanceof AnnisBaseUI) {
        PluginManagerUtil util = new PluginManagerUtil(((AnnisBaseUI) getUI()).getPluginManager());
        for (ExporterPlugin e : util.getPlugins(ExporterPlugin.class)) {
            exporterClassContainer.addItem(e.getClass());
        }
    }
    exporterClassContainer.sort(new Object[] { "simpleName" }, new boolean[] { true });
    cbExporter.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    cbExporter.setItemCaptionPropertyId("simpleName");
    if (exporterClassContainer.size() > 0) {
        cbExporter.setValue(exporterClassContainer.getIdByIndex(0));
    }
}
Also used : ExporterPlugin(annis.libgui.exporter.ExporterPlugin) PluginManagerUtil(net.xeoh.plugins.base.util.PluginManagerUtil) AnnisBaseUI(annis.libgui.AnnisBaseUI)

Example 2 with AnnisBaseUI

use of annis.libgui.AnnisBaseUI in project ANNIS by korpling.

the class MainToolbar method attach.

@Override
public void attach() {
    super.attach();
    UI ui = UI.getCurrent();
    if (ui instanceof AnnisBaseUI) {
        ((AnnisBaseUI) ui).getLoginDataLostBus().register(this);
    }
    IDGenerator.assignIDForFields(MainToolbar.this, btAboutAnnis, btOpenSource);
}
Also used : UI(com.vaadin.ui.UI) AnnisBaseUI(annis.libgui.AnnisBaseUI) AnnisBaseUI(annis.libgui.AnnisBaseUI)

Example 3 with AnnisBaseUI

use of annis.libgui.AnnisBaseUI in project ANNIS by korpling.

the class MainToolbar method detach.

@Override
public void detach() {
    UI ui = UI.getCurrent();
    if (ui instanceof AnnisBaseUI) {
        ((AnnisBaseUI) ui).getLoginDataLostBus().unregister(this);
    }
    super.detach();
}
Also used : UI(com.vaadin.ui.UI) AnnisBaseUI(annis.libgui.AnnisBaseUI) AnnisBaseUI(annis.libgui.AnnisBaseUI)

Example 4 with AnnisBaseUI

use of annis.libgui.AnnisBaseUI in project ANNIS by korpling.

the class HTMLVis method injectCSS.

private void injectCSS(String visConfigName, String corpusName, String wrapperClassName) {
    InputStream inStreamCSSRaw = null;
    if (visConfigName == null) {
        inStreamCSSRaw = HTMLVis.class.getResourceAsStream("htmlvis.css");
    } else {
        WebResource resBinary = Helper.getAnnisWebResource().path("query/corpora/").path(corpusName).path(corpusName).path("binary").path(visConfigName + ".css");
        ClientResponse response = resBinary.get(ClientResponse.class);
        if (response.getStatus() == ClientResponse.Status.OK.getStatusCode()) {
            inStreamCSSRaw = response.getEntityInputStream();
        }
    }
    if (inStreamCSSRaw != null) {
        try (InputStream inStreamCSS = inStreamCSSRaw) {
            String cssContent = IOUtils.toString(inStreamCSS);
            UI currentUI = UI.getCurrent();
            if (currentUI instanceof AnnisBaseUI) {
                // do not add identical CSS files
                ((AnnisBaseUI) currentUI).injectUniqueCSS(cssContent, wrapperClassName);
            }
        } catch (IOException ex) {
            log.error("Could not parse the HTML visualizer CSS file", ex);
            Notification.show("Could not parse the HTML visualizer CSS file", ex.getMessage(), Notification.Type.ERROR_MESSAGE);
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UI(com.vaadin.ui.UI) AnnisBaseUI(annis.libgui.AnnisBaseUI) InputStream(java.io.InputStream) WebResource(com.sun.jersey.api.client.WebResource) IOException(java.io.IOException) AnnisBaseUI(annis.libgui.AnnisBaseUI)

Example 5 with AnnisBaseUI

use of annis.libgui.AnnisBaseUI in project ANNIS by korpling.

the class HTMLVis method injectWebFonts.

private void injectWebFonts(String visConfigName, String corpusName) {
    InputStream inStreamJSONRaw = null;
    if (visConfigName != null) {
        WebResource resBinary = Helper.getAnnisWebResource().path("query/corpora/").path(corpusName).path(corpusName).path("binary").path(visConfigName + ".fonts.json");
        ClientResponse response = resBinary.get(ClientResponse.class);
        if (response.getStatus() == ClientResponse.Status.OK.getStatusCode()) {
            inStreamJSONRaw = response.getEntityInputStream();
        }
    }
    if (inStreamJSONRaw != null) {
        try (InputStream inStreamJSON = inStreamJSONRaw) {
            ObjectMapper mapper = createJsonMapper();
            WebFontList fontConfigList = mapper.readValue(inStreamJSON, WebFontList.class);
            for (WebFont fontConfig : fontConfigList.getWebFonts()) {
                if (fontConfig != null && fontConfig.getName() != null) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("@font-face {\n");
                    sb.append("  font-family: '" + fontConfig.getName() + "';\n");
                    sb.append("  font-weight: '" + fontConfig.getWeight() + "';\n");
                    sb.append("  font-style: '" + fontConfig.getStyle() + "';\n");
                    List<String> sourceDefs = new LinkedList<>();
                    for (Map.Entry<String, String> src : fontConfig.getSources().entrySet()) {
                        sourceDefs.add("url('" + src.getValue() + "') format('" + src.getKey() + "')");
                    }
                    if (!sourceDefs.isEmpty()) {
                        sb.append("  src: ");
                        sb.append(Joiner.on(",\n    ").join(sourceDefs));
                        sb.append(";\n");
                    }
                    sb.append("}\n");
                    UI currentUI = UI.getCurrent();
                    if (currentUI instanceof AnnisBaseUI) {
                        // do not add identical CSS files
                        ((AnnisBaseUI) currentUI).injectUniqueCSS(sb.toString());
                    }
                }
            }
        } catch (IOException ex) {
            log.error("Could not parse the HTML visualizer web-font configuration file", ex);
            Notification.show("Could not parse the HTML visualizer web-font configuration file", ex.getMessage(), Notification.Type.ERROR_MESSAGE);
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputStream(java.io.InputStream) WebResource(com.sun.jersey.api.client.WebResource) IOException(java.io.IOException) AnnisBaseUI(annis.libgui.AnnisBaseUI) LinkedList(java.util.LinkedList) UI(com.vaadin.ui.UI) AnnisBaseUI(annis.libgui.AnnisBaseUI) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

AnnisBaseUI (annis.libgui.AnnisBaseUI)5 UI (com.vaadin.ui.UI)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ExporterPlugin (annis.libgui.exporter.ExporterPlugin)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 PluginManagerUtil (net.xeoh.plugins.base.util.PluginManagerUtil)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1