Search in sources :

Example 1 with TimingInfo

use of org.loboevolution.info.TimingInfo in project LoboEvolution by LoboEvolution.

the class SVGImageElementImpl method draw.

/**
 * {@inheritDoc}
 */
@Override
public void draw(final Graphics2D graphics) {
    TimingInfo info = new TimingInfo();
    Image image = HttpNetwork.getImage(this, info, false);
    int realWidth = image.getWidth(null);
    int realHeight = image.getHeight(null);
    float drawWidth = getWidth().getAnimVal().getValue();
    float drawHeight = getHeight().getAnimVal().getValue();
    AffineTransform at = new AffineTransform();
    at.translate(getX().getAnimVal().getValue(), getY().getAnimVal().getValue());
    at.scale(drawWidth / realWidth, drawHeight / realHeight);
    graphics.drawImage(image, at, null);
    final HtmlRendererContext htmlRendererContext = this.getHtmlRendererContext();
    final HtmlPanel htmlPanel = htmlRendererContext.getHtmlPanel();
    htmlPanel.getBrowserPanel().getTimingList.add(info);
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) TimingInfo(org.loboevolution.info.TimingInfo) HtmlPanel(org.loboevolution.html.gui.HtmlPanel) AffineTransform(java.awt.geom.AffineTransform) Image(java.awt.Image)

Example 2 with TimingInfo

use of org.loboevolution.info.TimingInfo in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method backgroundApplyStyle.

private void backgroundApplyStyle(RenderState rs) {
    binfo = rs.getBackgroundInfo();
    this.backgroundColor = binfo == null ? null : binfo.getBackgroundColor();
    final URL backgroundImageUri = binfo == null ? null : binfo.getBackgroundImage();
    if (backgroundImageUri == null) {
        this.backgroundImage = null;
        this.lastBackgroundImageUri = null;
    } else if (!backgroundImageUri.equals(this.lastBackgroundImageUri)) {
        this.lastBackgroundImageUri = backgroundImageUri;
        HTMLImageElementImpl img = new HTMLImageElementImpl();
        TimingInfo info = new TimingInfo();
        img.setSrc(lastBackgroundImageUri.toString());
        backgroundImage = HttpNetwork.getImage(img, info, false);
        if (backgroundImage != null) {
            final int w = backgroundImage.getWidth(BaseElementRenderable.this);
            final int h = backgroundImage.getHeight(BaseElementRenderable.this);
            if (w != -1 && h != -1) {
                BaseElementRenderable.this.repaint();
            }
            final HtmlRendererContext htmlRendererContext = img.getHtmlRendererContext();
            if (htmlRendererContext != null) {
                final HtmlPanel htmlPanel = htmlRendererContext.getHtmlPanel();
                htmlPanel.getBrowserPanel().getTimingList.add(info);
            }
        }
    }
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) TimingInfo(org.loboevolution.info.TimingInfo) HtmlPanel(org.loboevolution.html.gui.HtmlPanel) HTMLImageElementImpl(org.loboevolution.html.dom.domimpl.HTMLImageElementImpl) URL(java.net.URL)

Example 3 with TimingInfo

use of org.loboevolution.info.TimingInfo in project LoboEvolution by LoboEvolution.

the class HtmlValues method getListStyleImage.

/**
 * <p>getListStyleImage.</p>
 *
 * @param token a {@link java.lang.String} object.
 * @return a {@link java.awt.Image} object.
 */
public static Image getListStyleImage(String token) {
    Image image;
    String start = "url(";
    int startIdx = start.length();
    int closingIdx = token.lastIndexOf(')');
    String quotedUri = token.substring(startIdx, closingIdx);
    String[] items = { "http", "https", "file" };
    TimingInfo info = new TimingInfo();
    HTMLImageElementImpl img = new HTMLImageElementImpl();
    if (Strings.containsWords(quotedUri, items)) {
        try {
            img.setSrc(quotedUri);
            image = HttpNetwork.getImage(img, info, false);
        } catch (Exception e) {
            image = null;
        }
    } else {
        try {
            img.setSrc(quotedUri);
            image = HttpNetwork.getImage(img, info, true);
        } catch (Exception e) {
            image = null;
        }
    }
    if (image != null) {
        final HtmlRendererContext htmlRendererContext = img.getHtmlRendererContext();
        final HtmlPanel htmlPanel = htmlRendererContext.getHtmlPanel();
        htmlPanel.getBrowserPanel().getTimingList.add(info);
    }
    return image;
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) TimingInfo(org.loboevolution.info.TimingInfo) HtmlPanel(org.loboevolution.html.gui.HtmlPanel) HTMLImageElementImpl(org.loboevolution.html.dom.domimpl.HTMLImageElementImpl)

Example 4 with TimingInfo

use of org.loboevolution.info.TimingInfo in project LoboEvolution by LoboEvolution.

the class ImagePageUI method mediaContent.

private Component mediaContent(List<MetaInfo> mediaList) {
    try {
        final Object[] columnNames = { "" };
        final List<String[]> values = new ArrayList<>();
        for (final MetaInfo info : mediaList) {
            if (Strings.isNotBlank(info.getName())) {
                values.add(new String[] { info.getName() });
            }
        }
        final DefaultTableModel model = new DefaultTableModel(values.toArray(new Object[][] {}), columnNames);
        final JTable jtable = new JTable(model);
        jtable.setPreferredSize(new Dimension(400, 380));
        jtable.setPreferredScrollableViewportSize(jtable.getPreferredSize());
        jtable.setTableHeader(null);
        jtable.setShowGrid(false);
        jtable.setColumnSelectionAllowed(true);
        jtable.setCellSelectionEnabled(true);
        final JPanel jPanelImg = new JPanel();
        final ListSelectionModel cellSelectionModel = jtable.getSelectionModel();
        cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        cellSelectionModel.addListSelectionListener(e -> {
            jPanelImg.removeAll();
            final int[] selectedRow = jtable.getSelectedRows();
            final int[] selectedColumns = jtable.getSelectedColumns();
            for (final int element : selectedRow) {
                for (final int selectedColumn : selectedColumns) {
                    final String href = (String) jtable.getValueAt(element, selectedColumn);
                    HTMLImageElementImpl img = new HTMLImageElementImpl();
                    img.setSrc(href);
                    jPanelImg.add(new JLabel(new ImageIcon(HttpNetwork.getImage(img, new TimingInfo(), false))));
                    jPanelImg.repaint();
                }
            }
        });
        final JPanel tablePanel = new JPanel();
        tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.Y_AXIS));
        tablePanel.add(jtable);
        tablePanel.add(jPanelImg);
        return new JScrollPane(tablePanel);
    } catch (final Exception e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}
Also used : TimingInfo(org.loboevolution.info.TimingInfo) DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) MetaInfo(org.loboevolution.info.MetaInfo) HTMLImageElementImpl(org.loboevolution.html.dom.domimpl.HTMLImageElementImpl)

Example 5 with TimingInfo

use of org.loboevolution.info.TimingInfo in project LoboEvolution by LoboEvolution.

the class HTMLScriptElementImpl method processScript.

/**
 * <p>processScript.</p>
 */
protected final void processScript() {
    final UserAgentContext bcontext = getUserAgentContext();
    if (bcontext == null) {
        throw new IllegalStateException("No user agent context.");
    }
    final Document doc = this.document;
    final Scriptable scope = (Scriptable) doc.getUserData(Executor.SCOPE_KEY);
    if (scope == null) {
        throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using " + Executor.SCOPE_KEY);
    }
    if (bcontext.isScriptingEnabled()) {
        final Context ctx = Executor.createContext(getDocumentURL(), bcontext);
        ctx.setLanguageVersion(Context.VERSION_1_8);
        ctx.setOptimizationLevel(-1);
        final String src = getSrc();
        Instant start = Instant.now();
        try {
            if (Strings.isNotBlank(src)) {
                TimingInfo info = new TimingInfo();
                final URL scriptURL = ((HTMLDocumentImpl) doc).getFullURL(src);
                final String scriptURI = scriptURL == null ? src : scriptURL.toExternalForm();
                final URL u = new URL(scriptURI);
                info.setName(u.getFile());
                final HttpURLConnection connection = (HttpURLConnection) u.openConnection();
                connection.setRequestProperty("User-Agent", UserAgent.getUserAgent());
                try (InputStream in = HttpNetwork.openConnectionCheckRedirects(connection);
                    Reader reader = new InputStreamReader(in, "utf-8")) {
                    BufferedReader br = new BufferedReader(reader);
                    ctx.evaluateReader(scope, br, scriptURI, 1, null);
                } catch (SocketTimeoutException e) {
                    info.setHttpResponse(connection.getResponseCode());
                    logger.log(Level.SEVERE, "More than " + connection.getConnectTimeout() + " elapsed.");
                } catch (Exception e) {
                    if (e instanceof MissingResourceException) {
                        logger.log(Level.INFO, e.getMessage());
                    } else {
                        logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                } finally {
                    Instant finish = Instant.now();
                    long timeElapsed = Duration.between(start, finish).toMillis();
                    info.setTimeElapsed(timeElapsed);
                    info.setPath(scriptURI);
                    info.setType(connection.getContentType());
                    info.setHttpResponse(connection.getResponseCode());
                    final HtmlRendererContext htmlRendererContext = this.getHtmlRendererContext();
                    final HtmlPanel htmlPanel = htmlRendererContext.getHtmlPanel();
                    htmlPanel.getBrowserPanel().getTimingList.add(info);
                }
            } else {
                String scriptURI = doc.getBaseURI();
                text = getText();
                ctx.evaluateString(scope, text, scriptURI, 1, null);
            }
        } catch (final RhinoException ecmaError) {
            final String error = ecmaError.sourceName() + ":" + ecmaError.lineNumber() + ": " + ecmaError.getMessage();
            logger.log(Level.WARNING, "Javascript error at " + error, ecmaError.getMessage());
        } catch (MissingResourceException mre) {
            logger.log(Level.WARNING, mre.getMessage());
        } catch (final Throwable err) {
            logger.log(Level.WARNING, "Unable to evaluate Javascript code", err);
        } finally {
            Context.exit();
        }
    }
}
Also used : UserAgentContext(org.loboevolution.http.UserAgentContext) Context(org.mozilla.javascript.Context) HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) UserAgentContext(org.loboevolution.http.UserAgentContext) TimingInfo(org.loboevolution.info.TimingInfo) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Instant(java.time.Instant) MissingResourceException(java.util.MissingResourceException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Document(org.loboevolution.html.node.Document) Scriptable(org.mozilla.javascript.Scriptable) URL(java.net.URL) RhinoException(org.mozilla.javascript.RhinoException) SocketTimeoutException(java.net.SocketTimeoutException) MissingResourceException(java.util.MissingResourceException) HttpURLConnection(java.net.HttpURLConnection) SocketTimeoutException(java.net.SocketTimeoutException) HtmlPanel(org.loboevolution.html.gui.HtmlPanel) BufferedReader(java.io.BufferedReader) RhinoException(org.mozilla.javascript.RhinoException)

Aggregations

TimingInfo (org.loboevolution.info.TimingInfo)8 HtmlPanel (org.loboevolution.html.gui.HtmlPanel)6 HtmlRendererContext (org.loboevolution.http.HtmlRendererContext)6 HTMLImageElementImpl (org.loboevolution.html.dom.domimpl.HTMLImageElementImpl)4 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Image (java.awt.Image)2 AffineTransform (java.awt.geom.AffineTransform)2 Instant (java.time.Instant)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 UserAgentContext (org.loboevolution.http.UserAgentContext)2 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1