Search in sources :

Example 1 with MetaInfo

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

the class HtmlContent method getMediaList.

/**
 * <p>getMediaList.</p>
 *
 * @return a {@link java.util.List} object.
 */
public List<MetaInfo> getMediaList() {
    final List<MetaInfo> infoList = new ArrayList<>();
    final HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
    HTMLCollectionImpl nodeList = (HTMLCollectionImpl) doc.getElementsByTagName("img");
    if (nodeList == null) {
        return null;
    }
    nodeList.forEach(node -> {
        if (node instanceof HTMLElement) {
            final HTMLElement element = (HTMLElement) node;
            String src = element.getAttribute("src");
            if (Strings.isNotBlank(src)) {
                if (!Urls.isAbsolute(src)) {
                    src = doc.getFullURL(src).toString();
                }
                if (src.startsWith("//")) {
                    src = "http:" + src;
                }
                infoList.add(MetaInfo.builder().name(src).build());
            }
        }
    });
    nodeList = (HTMLCollectionImpl) doc.getElementsByTagName("link");
    nodeList.forEach(node -> {
        if (node instanceof HTMLElement) {
            final HTMLElement element = (HTMLElement) node;
            final String rel = element.getAttribute("rel");
            String href = element.getAttribute("href");
            if ("icon".equalsIgnoreCase(rel) && Strings.isNotBlank(href)) {
                if (!Urls.isAbsolute(href)) {
                    href = doc.getFullURL(href).toString();
                }
                if (href.startsWith("//")) {
                    href = "http:" + href;
                }
                infoList.add(MetaInfo.builder().name(href).build());
            }
        }
    });
    return infoList;
}
Also used : HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) HTMLElement(org.loboevolution.html.dom.HTMLElement) MetaInfo(org.loboevolution.info.MetaInfo) ArrayList(java.util.ArrayList) HTMLCollectionImpl(org.loboevolution.html.dom.domimpl.HTMLCollectionImpl)

Example 2 with MetaInfo

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

the class ContentPageUI method content.

private JScrollPane content(List<MetaInfo> infoList, String syntax) {
    try {
        final Object[] columnNames = { "" };
        final List<String[]> values = new ArrayList<>();
        for (final MetaInfo info : infoList) {
            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 RSyntaxTextArea textArea = new RSyntaxTextArea();
        textArea.setHighlightCurrentLine(true);
        textArea.setAnimateBracketMatching(true);
        textArea.setAntiAliasingEnabled(true);
        textArea.setEditable(false);
        textArea.setSyntaxEditingStyle(syntax);
        final ListSelectionModel cellSelectionModel = jtable.getSelectionModel();
        cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        cellSelectionModel.addListSelectionListener(e -> {
            final int[] selectedRow = jtable.getSelectedRows();
            final int[] selectedColumns = jtable.getSelectedColumns();
            for (final int element : selectedRow) {
                for (final int selectedColumn : selectedColumns) {
                    try {
                        final String href = (String) jtable.getValueAt(element, selectedColumn);
                        textArea.setText(HttpNetwork.getSource(href));
                        textArea.repaint();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        });
        final JPanel tablePanel = new JPanel();
        tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.Y_AXIS));
        tablePanel.add(jtable);
        tablePanel.add(textArea);
        return new JScrollPane(tablePanel);
    } catch (final Exception e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) MetaInfo(org.loboevolution.info.MetaInfo) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea)

Example 3 with MetaInfo

use of org.loboevolution.info.MetaInfo 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 4 with MetaInfo

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

the class InfoPageUI method infoContent.

private JScrollPane infoContent(List<MetaInfo> infoList) {
    try {
        final Object[] columnNames = { "Key", "Value" };
        final List<String[]> values = new ArrayList<>();
        for (final MetaInfo info : infoList) {
            if (Strings.isNotBlank(info.getName())) {
                values.add(new String[] { info.getName(), info.getContent() });
            } else if (Strings.isNotBlank(info.getItemprop())) {
                values.add(new String[] { info.getItemprop(), info.getContent() });
            } else if (Strings.isNotBlank(info.getProperty())) {
                values.add(new String[] { info.getProperty(), info.getContent() });
            } else if (Strings.isNotBlank(info.getHttpEqui())) {
                values.add(new String[] { info.getHttpEqui(), info.getContent() });
            }
        }
        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.setShowGrid(false);
        return new JScrollPane(jtable);
    } catch (final Exception e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) MetaInfo(org.loboevolution.info.MetaInfo)

Example 5 with MetaInfo

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

the class HtmlContent method getStyleList.

/**
 * <p>getStyleList.</p>
 *
 * @return a {@link java.util.List} object.
 */
public List<MetaInfo> getStyleList() {
    final List<MetaInfo> infoList = new ArrayList<>();
    final HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
    final HTMLCollectionImpl nodeList = (HTMLCollectionImpl) doc.getElementsByTagName("link");
    if (nodeList == null) {
        return null;
    }
    nodeList.forEach(node -> {
        if (node instanceof HTMLElement) {
            final HTMLElement element = (HTMLElement) node;
            final String rel = element.getAttribute("rel");
            String href = element.getAttribute("href");
            if ("stylesheet".equalsIgnoreCase(rel) && Strings.isNotBlank(href)) {
                if (!Urls.isAbsolute(href)) {
                    href = doc.getFullURL(href).toString();
                }
                if (href.startsWith("//")) {
                    href = "http:" + href;
                }
                infoList.add(MetaInfo.builder().name(href).build());
            }
        }
    });
    return infoList;
}
Also used : HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) HTMLElement(org.loboevolution.html.dom.HTMLElement) MetaInfo(org.loboevolution.info.MetaInfo) ArrayList(java.util.ArrayList) HTMLCollectionImpl(org.loboevolution.html.dom.domimpl.HTMLCollectionImpl)

Aggregations

ArrayList (java.util.ArrayList)7 MetaInfo (org.loboevolution.info.MetaInfo)7 HTMLElement (org.loboevolution.html.dom.HTMLElement)4 HTMLCollectionImpl (org.loboevolution.html.dom.domimpl.HTMLCollectionImpl)4 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)4 DefaultTableModel (javax.swing.table.DefaultTableModel)3 RSyntaxTextArea (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea)1 HTMLImageElementImpl (org.loboevolution.html.dom.domimpl.HTMLImageElementImpl)1 TimingInfo (org.loboevolution.info.TimingInfo)1