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