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);
}
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);
}
}
}
}
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;
}
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;
}
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();
}
}
}
Aggregations