package com.compomics.util.gui.error_handlers.notification;
import com.compomics.util.examples.BareBonesBrowserLaunch;
import java.util.ArrayList;
/**
* A simple dialog for displaying notes.
*
* @author Harald Barsnes
*/
public class NotesDialog extends javax.swing.JDialog {
/**
* Creates a new NotesDialog.
*
* @param parent the parent frame
* @param modal if the dialog is to be modal or not
* @param notes list of the notes
*/
public NotesDialog(java.awt.Frame parent, boolean modal, ArrayList<String> notes) {
super(parent, modal);
initComponents();
String allNotes = "";
if (notes.size() > 0) {
for (String note : notes) {
allNotes += note + "<br><br>";
}
} else {
allNotes = "(empty)";
}
notesEditorPane.setText("<html>" + allNotes + "</html>");
notesEditorPane.setCaretPosition(0);
notesScrollPane.getViewport().setOpaque(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
backgroundPanel = new javax.swing.JPanel();
okButton = new javax.swing.JButton();
notesScrollPane = new javax.swing.JScrollPane();
notesEditorPane = new javax.swing.JEditorPane();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setUndecorated(true);
setPreferredSize(new java.awt.Dimension(300, 300));
backgroundPanel.setBackground(new java.awt.Color(255, 255, 255));
backgroundPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
notesScrollPane.setBorder(null);
notesScrollPane.setOpaque(false);
notesEditorPane.setEditable(false);
notesEditorPane.setBorder(null);
notesEditorPane.setContentType("text/html"); // NOI18N
notesEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
notesEditorPaneHyperlinkUpdate(evt);
}
});
notesScrollPane.setViewportView(notesEditorPane);
javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel);
backgroundPanel.setLayout(backgroundPanelLayout);
backgroundPanelLayout.setHorizontalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(notesScrollPane)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
.addGap(0, 329, Short.MAX_VALUE)
.addComponent(okButton)))
.addContainerGap())
);
backgroundPanelLayout.setVerticalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(notesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(okButton)
.addGap(6, 6, 6))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Close the dialog.
*
* @param evt
*/
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
dispose();
}//GEN-LAST:event_okButtonActionPerformed
/**
* Makes the links active.
*
* @param evt
*/
private void notesEditorPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_notesEditorPaneHyperlinkUpdate
if (evt.getEventType().toString().equalsIgnoreCase(
javax.swing.event.HyperlinkEvent.EventType.ENTERED.toString())) {
setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
} else if (evt.getEventType().toString().equalsIgnoreCase(
javax.swing.event.HyperlinkEvent.EventType.EXITED.toString())) {
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
} else if (evt.getEventType().toString().equalsIgnoreCase(
javax.swing.event.HyperlinkEvent.EventType.ACTIVATED.toString())) {
if (evt.getDescription().startsWith("#")) {
notesEditorPane.scrollToReference(evt.getDescription());
} else {
this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
BareBonesBrowserLaunch.openURL(evt.getDescription());
this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
}
}//GEN-LAST:event_notesEditorPaneHyperlinkUpdate
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel backgroundPanel;
private javax.swing.JEditorPane notesEditorPane;
private javax.swing.JScrollPane notesScrollPane;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
}