/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Notification.java * * Created on 06/09/2010, 17:32:41 */ package modmanager.gui.developing; import modmanager.gui.l10n.L10n; import java.awt.Dimension; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractButton; import javax.swing.DefaultListModel; import javax.swing.JOptionPane; /** * * @author Shirkit */ public class Notification extends javax.swing.JDialog { public static final int OK_OPTION = 0; public static final int YES_NO_OPTION = 1; public static final int OK_CANCEL_OPTION = 2; private static Frame parentFrame = null; private DefaultListModel listModel = new DefaultListModel(); private int returnValue = -5; private static Notification instance = null; public Notification(Frame parent) { parentFrame = parent; } private Notification(String title, String text, String details, int option) { super(parentFrame, true); initComponents(); setTitle(title); detailsEditorPane.setText(details); labelEditorPane.setText(text); if (option == OK_CANCEL_OPTION) { buttonLeft.setText(L10n.getString("button.ok")); buttonRight.setText(L10n.getString("button.cancel")); buttonRight.addActionListener(new CancelNoActionListener()); } else if (option == YES_NO_OPTION) { buttonLeft.setText(L10n.getString("button.yes")); buttonRight.setText(L10n.getString("button.no")); } else { buttonLeft.setText(L10n.getString("button.ok")); buttonLeft.addActionListener(new CancelNoActionListener()); buttonRight.setVisible(false); } detailsEditorPane.setVisible(false); if (details == null) { buttonDetails.setVisible(false); jScrollPane3.setVisible(false); this.setBounds(this.getX(), this.getY(), this.getWidth(), this.getHeight() - 35); } else { } listModel.addElement("ME CHUPA"); //jList1.paint(jList1.getGraphics()); setVisible(true); } private static Notification getInstance() { return instance; } public static void singleDetailedError(String title, String text, String details) { new Notification(title, text, details, OK_OPTION); } public static void error(String title, String text) { JOptionPane.showMessageDialog(parentFrame, title, text, JOptionPane.ERROR_MESSAGE); } public static int yesNoError(String title, String text) { return JOptionPane.showConfirmDialog(parentFrame, title, text, JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); } public static void info(String title, String text) { JOptionPane.showMessageDialog(parentFrame, title, text, JOptionPane.INFORMATION_MESSAGE); } public static int yesNoInfo(String title, String text) { return JOptionPane.showConfirmDialog(parentFrame, title, text, JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); } /** 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() { jScrollPane3 = new javax.swing.JScrollPane(); detailsEditorPane = new javax.swing.JEditorPane(); buttonDetails = new javax.swing.JToggleButton(); jScrollPane1 = new javax.swing.JScrollPane(); labelEditorPane = new javax.swing.JEditorPane(); buttonLeft = new javax.swing.JButton(); buttonRight = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(Notification.class); setTitle(resourceMap.getString("title")); // NOI18N setModal(true); setName(""); // NOI18N jScrollPane3.setName("jScrollPane3"); // NOI18N detailsEditorPane.setContentType(resourceMap.getString("detailsEditorPane.contentType")); // NOI18N detailsEditorPane.setAutoscrolls(false); detailsEditorPane.setName("detailsEditorPane"); // NOI18N jScrollPane3.setViewportView(detailsEditorPane); buttonDetails.setText(L10n.getString("notification.button.showdetails")); buttonDetails.setName("buttonDetails"); // NOI18N buttonDetails.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonDetailsActionPerformed(evt); } }); jScrollPane1.setBorder(null); jScrollPane1.setName("jScrollPane1"); // NOI18N labelEditorPane.setBorder(null); labelEditorPane.setEditable(false); labelEditorPane.setFocusable(false); labelEditorPane.setName("labelEditorPane"); // NOI18N labelEditorPane.setOpaque(false); jScrollPane1.setViewportView(labelEditorPane); buttonLeft.setText(resourceMap.getString("buttonLeft.text")); // NOI18N buttonLeft.setName("buttonLeft"); // NOI18N buttonRight.setText(resourceMap.getString("buttonRight.text")); // NOI18N buttonRight.setName("buttonRight"); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(buttonLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonRight, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 203, Short.MAX_VALUE) .addComponent(buttonDetails))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonDetails) .addComponent(buttonLeft) .addComponent(buttonRight)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void buttonDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDetailsActionPerformed AbstractButton but = (AbstractButton) buttonDetails; // This means if he clicked to select the button if (but.isSelected()) { detailsEditorPane.setVisible(true); this.setBounds(this.getX(), this.getY(), this.getWidth(), this.getHeight() + 300); detailsEditorPane.setPreferredSize(new Dimension(detailsEditorPane.getWidth(), detailsEditorPane.getHeight() + 300)); buttonDetails.setText(L10n.getString("notification.button.hidedetails")); } else { // Click to unselect buttonDetails.setText(L10n.getString("notification.button.showdetails")); this.setBounds(this.getX(), this.getY(), this.getWidth(), this.getHeight() - 300); detailsEditorPane.setPreferredSize(new Dimension(detailsEditorPane.getWidth(), detailsEditorPane.getHeight() - 300)); detailsEditorPane.setVisible(false); } }//GEN-LAST:event_buttonDetailsActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JToggleButton buttonDetails; private javax.swing.JButton buttonLeft; private javax.swing.JButton buttonRight; private javax.swing.JEditorPane detailsEditorPane; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JEditorPane labelEditorPane; // End of variables declaration//GEN-END:variables public static void main(String[] args) { try { L10n.load(); } catch (IOException ex) { Logger.getLogger(Notification.class.getName()).log(Level.SEVERE, null, ex); } singleDetailedError("Titulo", "TEXTO", "detalhes"); } class CancelNoActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { returnValue = 0; getInstance().dispose(); } } }