Search in sources :

Example 1 with MTGStoryListRenderer

use of org.magic.gui.renderer.MTGStoryListRenderer in project MtgDesktopCompanion by nicho92.

the class StoriesGUI method initGUI.

private void initGUI() {
    JScrollPane scrollList = new JScrollPane();
    JScrollPane scrollEditor = new JScrollPane();
    setLayout(new BorderLayout(0, 0));
    resultListModel = new DefaultListModel<>();
    listResult = new JList<>(resultListModel);
    listResult.setCellRenderer(new MTGStoryListRenderer());
    listResult.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listResult.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 1) {
                evt.consume();
                ThreadManager.getInstance().execute(() -> {
                    lblLoading.setVisible(true);
                    try {
                        editorPane.setText(Jsoup.connect(listResult.getSelectedValue().getUrl().toString()).get().select("div#content-detail-page-of-an-article").html());
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
                    }
                    lblLoading.setVisible(false);
                }, "Load story");
            } else {
                try {
                    Desktop.getDesktop().browse(listResult.getSelectedValue().getUrl().toURI());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e.getMessage(), MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });
    scrollList.setViewportView(listResult);
    JPanel panel = new JPanel();
    add(panel, BorderLayout.NORTH);
    JButton btnLoadNext = new JButton("Load Next");
    btnLoadNext.addActionListener(ae -> initStories());
    panel.add(btnLoadNext);
    lblLoading = new JLabel(MTGConstants.ICON_LOADING);
    lblLoading.setVisible(false);
    panel.add(lblLoading);
    editorPane = new JEditorPane();
    editorPane.setEditable(false);
    editorPane.setContentType("text/html");
    HTMLEditorKit kit = new HTMLEditorKit();
    editorPane.setEditorKit(kit);
    Document doc = kit.createDefaultDocument();
    editorPane.setDocument(doc);
    scrollEditor.setViewportView(editorPane);
    JSplitPane splitPane = new JSplitPane();
    splitPane.setLeftComponent(scrollList);
    splitPane.setRightComponent(scrollEditor);
    add(splitPane, BorderLayout.CENTER);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) MTGStoryListRenderer(org.magic.gui.renderer.MTGStoryListRenderer) MouseAdapter(java.awt.event.MouseAdapter) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Document(javax.swing.text.Document) IOException(java.io.IOException) BorderLayout(java.awt.BorderLayout) JEditorPane(javax.swing.JEditorPane) JSplitPane(javax.swing.JSplitPane)

Aggregations

BorderLayout (java.awt.BorderLayout)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 JButton (javax.swing.JButton)1 JEditorPane (javax.swing.JEditorPane)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JSplitPane (javax.swing.JSplitPane)1 Document (javax.swing.text.Document)1 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)1 MTGStoryListRenderer (org.magic.gui.renderer.MTGStoryListRenderer)1