Search in sources :

Example 1 with ClassResource

use of com.vaadin.server.ClassResource in project v-leaflet by mstahv.

the class LayerGroupTest method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.setCenter(60.4525, 22.301);
    leafletMap.setZoomLevel(15);
    leafletMap.setControls(new ArrayList<Control>(Arrays.asList(Control.values())));
    LPolyline leafletPolyline = null;
    // Adding to layergroup
    // Not creating a name -> not added to the
    llg = new LLayerGroup();
    // overlay controller
    leafletPolyline = new LPolyline(new Point(60.45, 22.295), new Point(60.4555, 22.301), new Point(60.45, 22.307));
    leafletPolyline.setColor("#FF0000");
    leafletPolyline.setFill(true);
    leafletPolyline.setFillColor("#FFFFFF");
    leafletPolyline.addClickListener(listener);
    llg.addComponent(leafletPolyline);
    leafletPolyline = new LPolyline(new Point(60.45 + 0.005, 22.295 + 0.005), new Point(60.4555 + 0.005, 22.301 + 0.005), new Point(60.45 + 0.005, 22.307 + 0.005));
    leafletPolyline.setColor("#FFFFFF");
    leafletPolyline.setFill(true);
    leafletPolyline.setFillColor("#FF0000");
    leafletPolyline.addClickListener(listener);
    llg.addComponent(leafletPolyline);
    LCircle leafletCircle = new LCircle(60.4525 + 0.005, 22.301 + 0.005, 200);
    leafletCircle.setColor("#FF0000");
    llgNested = new LLayerGroup();
    llgNested.addComponent(leafletCircle);
    llg.addComponent(llgNested);
    llg2 = new LLayerGroup();
    leafletCircle = new LCircle(60.4525 - 0.005, 22.301 - 0.005, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletCircle = new LCircle(60.4525 - 0.008, 22.301 - 0.008, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletCircle = new LCircle(60.4525 - 0.011, 22.301 - 0.011, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletCircle = new LCircle(60.4525 - 0.014, 22.301 - 0.014, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletMap.addOverlay(llg, null);
    leafletMap.addOverlay(llg2, "Small circles group");
    leafletCircle = new LCircle(60.4525, 22.301, 300);
    leafletCircle.setColor("#00FFFF");
    // leafletCircle.addClickListener(listener);
    leafletMap.addComponent(leafletCircle);
    LMarker leafletMarker = new LMarker(60.4525, 22.301);
    leafletMarker.addClickListener(listener);
    leafletMap.addComponent(leafletMarker);
    leafletMarker = new LMarker(60.4525, 22.301);
    leafletMarker.setIcon(new ClassResource("testicon.png"));
    leafletMarker.setIconSize(new Point(57, 52));
    leafletMarker.setIconAnchor(new Point(57, 26));
    leafletMarker.addClickListener(listener);
    leafletMap.addComponent(leafletMarker);
    leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
    leafletMap.addClickListener(listener);
    leafletMap.addMoveEndListener(new LeafletMoveEndListener() {

        @Override
        public void onMoveEnd(LeafletMoveEndEvent event) {
            Bounds b = event.getBounds();
            Notification.show(String.format("New viewport (%.4f,%.4f ; %.4f,%.4f)", b.getSouthWestLat(), b.getSouthWestLon(), b.getNorthEastLat(), b.getNorthEastLon()), Type.TRAY_NOTIFICATION);
        }
    });
    return leafletMap;
}
Also used : ClassResource(com.vaadin.server.ClassResource) LPolyline(org.vaadin.addon.leaflet.LPolyline) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) Bounds(org.vaadin.addon.leaflet.shared.Bounds) LeafletMoveEndEvent(org.vaadin.addon.leaflet.LeafletMoveEndEvent) Point(org.vaadin.addon.leaflet.shared.Point) LMarker(org.vaadin.addon.leaflet.LMarker) LLayerGroup(org.vaadin.addon.leaflet.LLayerGroup) Control(org.vaadin.addon.leaflet.shared.Control) LeafletMoveEndListener(org.vaadin.addon.leaflet.LeafletMoveEndListener) LMap(org.vaadin.addon.leaflet.LMap) LCircle(org.vaadin.addon.leaflet.LCircle)

Example 2 with ClassResource

use of com.vaadin.server.ClassResource in project ANNIS by korpling.

the class ReducingStringComparator method readMappings.

private void readMappings() {
    ALLOGRAPHS = new HashMap<>();
    ClassResource cr = new ClassResource(ReducingStringComparator.class, MAPPING_FILE);
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document mappingD = db.parse(cr.getStream().getStream());
        NodeList mappings = mappingD.getElementsByTagName("mapping");
        for (int i = 0; i < mappings.getLength(); i++) {
            Element mapping = (Element) mappings.item(i);
            String mappingName = mapping.getAttribute("name");
            HashMap<Character, Character> mappingMap = initAlphabet();
            NodeList variants = mapping.getElementsByTagName("variant");
            for (int j = 0; j < variants.getLength(); j++) {
                Element var = (Element) variants.item(j);
                char varvalue = var.getAttribute("value").charAt(0);
                Element character = (Element) var.getParentNode();
                char charactervalue = character.getAttribute("value").charAt(0);
                mappingMap.put(varvalue, charactervalue);
            }
            ALLOGRAPHS.put(mappingName, mappingMap);
        }
    } catch (SAXException e) {
        e = null;
        Notification.show(READING_ERROR_MESSAGE);
    } catch (IOException e) {
        e = null;
        Notification.show(READING_ERROR_MESSAGE);
    } catch (ParserConfigurationException e) {
        e = null;
        Notification.show(READING_ERROR_MESSAGE);
    }
}
Also used : ClassResource(com.vaadin.server.ClassResource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with ClassResource

use of com.vaadin.server.ClassResource in project ANNIS by korpling.

the class AnnisBaseUI method initLogging.

protected final void initLogging() {
    try {
        List<File> logbackFiles = getAllConfigLocations("gui-logback.xml");
        InputStream inStream = null;
        if (!logbackFiles.isEmpty()) {
            try {
                inStream = new FileInputStream(logbackFiles.get(logbackFiles.size() - 1));
            } catch (FileNotFoundException ex) {
            // well no logging no error...
            }
        }
        if (inStream == null) {
            ClassResource res = new ClassResource(AnnisBaseUI.class, "logback.xml");
            inStream = res.getStream().getStream();
        }
        if (inStream != null) {
            LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
            JoranConfigurator jc = new JoranConfigurator();
            jc.setContext(context);
            context.reset();
            context.putProperty("webappHome", VaadinService.getCurrent().getBaseDirectory().getAbsolutePath());
            // load config file
            jc.doConfigure(inStream);
        }
    } catch (JoranException ex) {
        log.error("init logging failed", ex);
    }
}
Also used : ClassResource(com.vaadin.server.ClassResource) JoranException(ch.qos.logback.core.joran.spi.JoranException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) LoggerContext(ch.qos.logback.classic.LoggerContext) FileInputStream(java.io.FileInputStream)

Example 4 with ClassResource

use of com.vaadin.server.ClassResource in project v-leaflet by mstahv.

the class BasicTest method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.setCenter(60.4525, 22.301);
    leafletMap.setZoomLevel(15);
    leafletMap.setControls(new ArrayList<Control>(Arrays.asList(Control.values())));
    LPolyline leafletPolyline = new LPolyline(new Point(60.45, 22.295), new Point(60.4555, 22.301), new Point(60.45, 22.307));
    leafletPolyline.setColor("#FF00FF");
    leafletPolyline.setFill(true);
    leafletPolyline.setFillColor("#00FF00");
    leafletPolyline.setClickable(false);
    leafletPolyline.setWeight(8);
    leafletPolyline.setOpacity(0.5);
    leafletPolyline.setDashArray("15, 10, 5, 10, 15");
    leafletPolyline.addClickListener(listener);
    leafletMap.addComponent(leafletPolyline);
    LPolygon leafletPolygon = new LPolygon(new Point(60.455, 22.300), new Point(60.456, 22.302), new Point(60.50, 22.308));
    leafletPolygon.setColor("#FF00FF");
    leafletPolygon.setFill(true);
    leafletPolygon.setFillColor("#00FF00");
    leafletPolygon.addClickListener(listener);
    leafletMap.addComponent(leafletPolygon);
    Bounds bounds = new Bounds(new Point(60.45, 22.295), new Point(60.4509, 22.300));
    LRectangle rect = new LRectangle(bounds);
    rect.addClickListener(listener);
    rect.setFillColor("yellow");
    leafletMap.addLayer(rect);
    LCircle leafletCircle = new LCircle(60.4525, 22.301, 300);
    leafletCircle.setColor("#00FFFF");
    // leafletCircle.addClickListener(listener);
    leafletMap.addComponent(leafletCircle);
    leafletCircle.addClickListener(listener);
    LCircleMarker leafletCircleMarker = new LCircleMarker(60.4525, 22.301, 5);
    leafletCircleMarker.setColor("#FFFF00");
    leafletMap.addComponent(leafletCircleMarker);
    leafletCircleMarker.addClickListener(listener);
    leafletMarker = new LMarker(60.4525, 22.301);
    leafletMarker.addClickListener(listener);
    leafletMarker.setTitle("this is marker two!");
    // leafletMarker
    // .setDivIcon("this is a <h1>fabulous</h1> <span style=\"color:red\">icon</span>");
    leafletMarker.setPopup("Hello <b>world</b>");
    leafletMap.addComponent(leafletMarker);
    leafletMarker = new LMarker(60.4525, 22.301);
    leafletMarker.setIcon(new ClassResource("testicon.png"));
    leafletMarker.setIconSize(new Point(57, 52));
    leafletMarker.setIconAnchor(new Point(57, 26));
    leafletMarker.addClickListener(listener);
    leafletMarker.setTitle("this is marker one!");
    leafletMarker.setPopup("Hello <b>Vaadin World</b>!");
    leafletMarker.setPopupAnchor(new Point(-28, -26));
    leafletMap.addComponent(leafletMarker);
    leafletMap.setAttributionPrefix("Powered by Leaflet with v-leaflet");
    LPolyline roadOverlay = new LPolyline(new Point(61.42, 21.245), new Point(60.4655, 22.321), new Point(60.45, 22.307));
    leafletMap.addOverlay(roadOverlay, "Road overlay");
    LMarker point1 = new LMarker(61.441, 21.2442);
    LMarker point2 = new LMarker(61.445, 21.2441);
    LMarker point3 = new LMarker(61.447, 21.2445);
    LLayerGroup layerGroup = new LLayerGroup(point1, point2, point3);
    leafletMap.addOverlay(layerGroup, "Points overlay");
    leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "CloudMade");
    // This will make everything sharper on "retina devices", but also text
    // quite small
    // baselayer.setDetectRetina(true);
    LTileLayer pk = new LTileLayer();
    pk.setUrl("https://{s}.kartat.kapsi.fi/peruskartta/{z}/{x}/{y}.png");
    pk.setAttributionString("Maanmittauslaitos, hosted by kartat.kapsi.fi");
    pk.setMaxZoom(18);
    pk.setSubDomains("tile2");
    pk.setDetectRetina(true);
    leafletMap.addBaseLayer(pk, "Peruskartta");
    leafletMap.addBaseLayerChangeListener(new LeafletBaseLayerChangeListener() {

        @Override
        public void onBaseLayerChange(LeafletBaseLayerChangeEvent event) {
            Notification.show(event.getName() + " base layer was activated!");
        }
    });
    leafletMap.addOverlayAddListener(new LeafletOverlayAddListener() {

        @Override
        public void onOverlayAdd(LeafletOverlayAddEvent event) {
            Notification.show(event.getName() + " overlay was added!");
        }
    });
    leafletMap.addOverlayRemoveListener(new LeafletOverlayRemoveListener() {

        @Override
        public void onOverlayRemove(LeafletOverlayRemoveEvent event) {
            Notification.show(event.getName() + " overlay was removed!");
        }
    });
    leafletMap.addClickListener(listener);
    leafletMap.addMoveEndListener(new LeafletMoveEndListener() {

        @Override
        public void onMoveEnd(LeafletMoveEndEvent event) {
            Bounds b = event.getBounds();
            Notification.show(String.format("New viewport (%.4f,%.4f ; %.4f,%.4f)", b.getSouthWestLat(), b.getSouthWestLon(), b.getNorthEastLat(), b.getNorthEastLon()), Type.TRAY_NOTIFICATION);
        }
    });
    return leafletMap;
}
Also used : ClassResource(com.vaadin.server.ClassResource) Bounds(org.vaadin.addon.leaflet.shared.Bounds) Point(org.vaadin.addon.leaflet.shared.Point) Control(org.vaadin.addon.leaflet.shared.Control)

Aggregations

ClassResource (com.vaadin.server.ClassResource)4 Bounds (org.vaadin.addon.leaflet.shared.Bounds)2 Control (org.vaadin.addon.leaflet.shared.Control)2 Point (org.vaadin.addon.leaflet.shared.Point)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 LCircle (org.vaadin.addon.leaflet.LCircle)1 LLayerGroup (org.vaadin.addon.leaflet.LLayerGroup)1 LMap (org.vaadin.addon.leaflet.LMap)1 LMarker (org.vaadin.addon.leaflet.LMarker)1 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)1