org.vaadin.addon.ewopener.demo.HighlightJS.java Source code

Java tutorial

Introduction

Here is the source code for org.vaadin.addon.ewopener.demo.HighlightJS.java

Source

/*
 * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com)
 *
 * 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 org.vaadin.addon.ewopener.demo;

import com.vaadin.annotations.JavaScript;
import com.vaadin.annotations.StyleSheet;
import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractJavaScriptExtension;

/**
 * Created by marco on 15/06/16.
 */
@JavaScript({ "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/highlight.min.js",
        "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/languages/java.min.js",
        "highlightjs_connector.js" })
@StyleSheet({ "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/styles/atom-one-dark.min.css" })
public class HighlightJS extends AbstractJavaScriptExtension {

    private HighlightJS(AbstractClientConnector component) {
        super(component);
    }

    public static HighlightJS of(AbstractClientConnector component) {
        return component.getExtensions().stream().filter(HighlightJS.class::isInstance).findFirst()
                .map(HighlightJS.class::cast).orElseGet(() -> new HighlightJS(component));
    }
}