@Override
public void mouseClicked(MouseEvent e) {
WebTextPane textPane = (WebTextPane) e.getComponent();
StyledDocument doc = textPane.getStyledDocument();
Element elem = doc.getCharacterElement(textPane.viewToModel(e.getPoint()));
if (!elem.getAttributes().isDefined(URL_ATT_NAME))
// not a link
return;
int len = elem.getEndOffset() - elem.getStartOffset();
final String url;
try {
url = doc.getText(elem.getStartOffset(), len);
} catch (BadLocationException ex) {
LOGGER.log(Level.WARNING, "can't get URL", ex);
return;
}
Runnable run = new Runnable() {
@Override
public void run() {
WebUtils.browseSiteSafely(fixProto(url));
}
};
new Thread(run, "Link Browser").start();
}
@Override
public void mouseMoved(MouseEvent e) {
WebTextPane textPane = (WebTextPane) e.getComponent();
StyledDocument doc = textPane.getStyledDocument();
Element elem = doc.getCharacterElement(textPane.viewToModel(e.getPoint()));
if (elem.getAttributes().isDefined(URL_ATT_NAME)) {
textPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} else {
textPane.setCursor(Cursor.getDefaultCursor());
}
}
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
final WebTextPane textPane = new WebTextPane ( getStyleId () );
textPane.setInputPrompt ( getPreviewLanguagePrefix () + "prompt" );
return CollectionUtils.asList ( new WebScrollPane ( textPane ).setPreferredSize ( 200, 100 ) );
}
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
final WebTextPane textPane = new WebTextPane ( getStyleId () );
textPane.setText ( "Sample\nmultiline\ntext" );
return CollectionUtils.asList ( textPane.setPreferredWidth ( 200 ) );
}
public AboutDialog(JFrame frame)
{
super(frame, "About Spade");
this.setIconImage(GUIManager.ICON);
this.center(400, 300);
this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
WebTextPane area = new WebTextPane();
StyledDocument doc = area.getStyledDocument();
addStylesToDocument(doc);
append(doc, "Spade", "large");
append(doc, "\n Version: ", "bold");
append(doc, Spade.getVersion().toString(), "regular");
append(doc, "\n Build Type: ", "bold");
append(doc, Spade.BUILD_TYPE, "regular");
append(doc, "\n Released on: ", "bold");
append(doc, Spade.RELEASED, "regular");
append(doc, "\n\n", "regular");
append(doc, "Spade is an open-source cross-platform raster graphics editor inspired by Paint.NET.", "regular");
append(doc, "It was started, and is currently maintained by HeroesGrave.\n", "regular");
append(doc, "\n", "regular");
append(doc, "Links:\n", "large");
append(doc, " Github Repo:\n", "bold");
append(doc, " " + Spade.REPO_URL + "\n", "italic");
append(doc, " HeroesGrave Development:\n", "bold");
append(doc, " http://heroesgrave.github.io/\n", "italic");
append(doc, "\n", "regular");
append(doc, "Credits:\n", "large");
append(doc, " HeroesGrave\n", "regular");
append(doc, " Longor1996\n", "regular");
append(doc, " BurntPizza\n", "regular");
append(doc, " SuperDisk\n", "regular");
append(doc, " Gef4k\n", "regular");
append(doc, " MarkBernard\n", "regular");
append(doc, " pwnedary\n", "regular");
area.setEditable(false);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
this.setResizable(false);
}