|
| 1 | +package fi.helsinki.cs.tmc.ui; |
| 2 | + |
| 3 | +import java.net.MalformedURLException; |
| 4 | +import java.net.URL; |
| 5 | +import javax.swing.event.HyperlinkEvent; |
| 6 | + |
| 7 | +import org.openide.awt.HtmlBrowser; |
| 8 | +import org.openide.windows.WindowManager; |
| 9 | + |
| 10 | +public class AboutDialog extends javax.swing.JDialog { |
| 11 | + |
| 12 | + public static void display() { |
| 13 | + AboutDialog dialog = new AboutDialog(); |
| 14 | + dialog.setTitle("About"); |
| 15 | + dialog.setLocationRelativeTo(null); |
| 16 | + dialog.setVisible(true); |
| 17 | + } |
| 18 | + |
| 19 | + public AboutDialog() { |
| 20 | + super(WindowManager.getDefault().getMainWindow(), false); |
| 21 | + initComponents(); |
| 22 | + |
| 23 | + this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
| 24 | + |
| 25 | + this.infoTextPane.addHyperlinkListener((HyperlinkEvent e) -> { |
| 26 | + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
| 27 | + try { |
| 28 | + HtmlBrowser.URLDisplayer.getDefault().showURLExternal(new URL("https://mooc.fi/tmc")); |
| 29 | + } catch (MalformedURLException ex) { |
| 30 | + ConvenientDialogDisplayer.getDefault().displayError("Failed to open browser.\n" + ex.getMessage()); |
| 31 | + } |
| 32 | + } |
| 33 | + }); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * This method is called from within the constructor to initialize the form. |
| 38 | + * WARNING: Do NOT modify this code. The content of this method is always |
| 39 | + * regenerated by the Form Editor. |
| 40 | + */ |
| 41 | + @SuppressWarnings("unchecked") |
| 42 | + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
| 43 | + private void initComponents() { |
| 44 | + |
| 45 | + headerLabel = new javax.swing.JLabel(); |
| 46 | + closeButton = new javax.swing.JButton(); |
| 47 | + infoScrollPane = new javax.swing.JScrollPane(); |
| 48 | + infoTextPane = new javax.swing.JTextPane(); |
| 49 | + |
| 50 | + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); |
| 51 | + setMaximumSize(new java.awt.Dimension(466, 260)); |
| 52 | + setMinimumSize(new java.awt.Dimension(466, 260)); |
| 53 | + setResizable(false); |
| 54 | + |
| 55 | + headerLabel.setFont(new java.awt.Font("Ubuntu", 1, 20)); // NOI18N |
| 56 | + org.openide.awt.Mnemonics.setLocalizedText(headerLabel, org.openide.util.NbBundle.getMessage(AboutDialog.class, "AboutDialog.headerLabel.text")); // NOI18N |
| 57 | + |
| 58 | + org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(AboutDialog.class, "AboutDialog.closeButton.text")); // NOI18N |
| 59 | + closeButton.addActionListener(new java.awt.event.ActionListener() { |
| 60 | + public void actionPerformed(java.awt.event.ActionEvent evt) { |
| 61 | + closeButtonActionPerformed(evt); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + infoTextPane.setEditable(false); |
| 66 | + infoTextPane.setContentType("text/html"); // NOI18N |
| 67 | + infoTextPane.setText(org.openide.util.NbBundle.getMessage(AboutDialog.class, "AboutDialog.infoTextPane.text")); // NOI18N |
| 68 | + infoScrollPane.setViewportView(infoTextPane); |
| 69 | + |
| 70 | + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
| 71 | + getContentPane().setLayout(layout); |
| 72 | + layout.setHorizontalGroup( |
| 73 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 74 | + .addGroup(layout.createSequentialGroup() |
| 75 | + .addContainerGap() |
| 76 | + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 77 | + .addComponent(infoScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) |
| 78 | + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() |
| 79 | + .addGap(0, 0, Short.MAX_VALUE) |
| 80 | + .addComponent(closeButton)) |
| 81 | + .addGroup(layout.createSequentialGroup() |
| 82 | + .addComponent(headerLabel) |
| 83 | + .addGap(0, 248, Short.MAX_VALUE))) |
| 84 | + .addContainerGap()) |
| 85 | + ); |
| 86 | + layout.setVerticalGroup( |
| 87 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 88 | + .addGroup(layout.createSequentialGroup() |
| 89 | + .addContainerGap() |
| 90 | + .addComponent(headerLabel) |
| 91 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) |
| 92 | + .addComponent(infoScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) |
| 93 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) |
| 94 | + .addComponent(closeButton) |
| 95 | + .addContainerGap()) |
| 96 | + ); |
| 97 | + |
| 98 | + pack(); |
| 99 | + }// </editor-fold>//GEN-END:initComponents |
| 100 | + |
| 101 | + private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed |
| 102 | + this.setVisible(false); |
| 103 | + this.dispose(); |
| 104 | + }//GEN-LAST:event_closeButtonActionPerformed |
| 105 | + |
| 106 | + // Variables declaration - do not modify//GEN-BEGIN:variables |
| 107 | + private javax.swing.JButton closeButton; |
| 108 | + private javax.swing.JLabel headerLabel; |
| 109 | + private javax.swing.JScrollPane infoScrollPane; |
| 110 | + private javax.swing.JTextPane infoTextPane; |
| 111 | + // End of variables declaration//GEN-END:variables |
| 112 | +} |
0 commit comments