public class EditorPane extends javax.swing.JPanel {
/**
* Creates new form EditorPane
*/
public EditorPane() {
initComponents();
}
private void launchHyperLink(HyperlinkEvent e) {
try {
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
String cmdFileLocation = System.getenv("windir") + File.separator + "system32" + File.separator + "cmd.exe";
Runtime.getRuntime().exec(new String[]{cmdFileLocation, "/c", "start", e.getDescription()});
}
} catch (IOException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void initEditorPane(JEditorPane editorPane) {
editorPane.setBorder(null);
editorPane.setContentType("text/html");
editorPane.setEditable(false);
editorPane.setOpaque(false);
editorPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
launchHyperLink(e);
}
}
});
}
I am trying to re-use the above EditorPane across a number of different GUIs, as they have various hyperlinks which act the same way.
But I am not sure how to call the initEditorPane
method in the GUIs calling it.
Here's What I mean:
public class MainMenu extends javax.swing.JFrame {
private AcademicDTO ac;
public MainMenu(AcademicDTO academicDTO) {
this.ac = academicDTO;
initComponents();
searchTable.init(GUIStaticDataHelper.ACADEMIC_SUMMARY_COLUMNS);
myContactTable.init(GUIStaticDataHelper.CONTACT_SUMMARY_COLUMNS);
initEditorPane(emailTxtComp);
initEditorPane(pageTxtComp);
initComponentsWithData();
initListeners();
}
public void initComponentsWithData() {
nameLabel.setText("" + ac.getTitle() + " " + ac.getForename() + " " + ac.getSurname());
roleLabel.setText(ac.getRole());
roomLabel.setText("Room: " + ac.getRoom());
pageLabel.setText("Page:");
pageTxtComp.setText("<html> <a href='" + ac.getPage() + "'>" + ac.getPage() + "</a> </html>");
hoursLabel.setText("Hours: " + ac.getHours());
phoneLabel.setText("Phone: " + ac.getPhone());
mobileLabel.setText("Mobile: " + ac.getMobile());
emailLabel.setText("Email:");
myContactTable.setData(ac.getContacts());
if (ac.getImage() != null) {
imageLabel.setIcon(new ImageIcon(ac.getImage()));
}
emailTxtComp.setText("<html> <a href='mailto://" + ac.getEmail() + "'>" + ac.getEmail() + "</a> </html> ");
}
emailTxtComp
and pageTxtComp
are both now type EditorPane
instead of JEditorPane
. so the method initEditorPane(JEditorPane editorPane)
can't be used.
also the lines
initEditorPane(emailTxtComp);
initEditorPane(pageTxtComp);
what do I change them to?