Exemplo n.º 1
0
    private void initialize(String message, Exception exc) {
        double[][] dLay = {
                { border, TableLayout.PREFERRED, border, TableLayout.FILL, border },
                { border, TableLayout.PREFERRED, border, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL, border, TableLayout.PREFERRED, border }
        };
        
        contentPane = new JPanel(new TableLayout(dLay));
        
        boxButtons = Box.createHorizontalBox();
        btnOK = new JButton(Utils._("OK"));
        btnOK.addActionListener(this);
        btnDetails = new JButton(Utils._("Details") + " >>");
        btnDetails.addActionListener(this);
        btnCopy = new JButton(Utils._("Copy"), Utils.loadIcon("general/Copy"));
        btnCopy.addActionListener(this);
        
        boxButtons.add(Box.createHorizontalGlue());
        boxButtons.add(btnOK);
        boxButtons.add(Box.createHorizontalStrut(border));
        boxButtons.add(btnDetails);
        boxButtons.add(Box.createHorizontalStrut(border));
        boxButtons.add(btnCopy);
        boxButtons.add(Box.createHorizontalGlue());
        
        JLabel lblIcon = new JLabel(UIManager.getIcon("OptionPane.errorIcon"));
        
        lblText = new JLabel("<html>" + message + "</html>");
        adjustTextLabelSize(lblText);
        
        String localizedMessage = exc.getLocalizedMessage();
        if (localizedMessage == null) {
            localizedMessage = exc.getMessage();
        }
        if (localizedMessage != null) {
            lblExceptionText = new JLabel("<html>" + localizedMessage + "</html>");
            lblExceptionText.setVerticalAlignment(SwingConstants.TOP);
            adjustTextLabelSize(lblExceptionText);
        } else {
            lblExceptionText = null;
        }
        
        strutStacktrace = Box.createVerticalStrut(20);
        
        StringWriter stringBuf = new StringWriter();
        exc.printStackTrace(new PrintWriter(stringBuf));
        
        //Append some system info:
        stringBuf.append("\n\n");
        stringBuf.append(Utils.AppShortName).append(' ').append(Utils.AppVersion).append('\n');
        stringBuf.append("Java ")
            .append(System.getProperty("java.version")).append(" (")
            .append(System.getProperty("java.vendor")).append(")\n")
            .append(System.getProperty("java.runtime.name")).append(' ')
            .append(System.getProperty("java.runtime.version")).append('\n')
            .append(System.getProperty("java.vm.name")).append('\n');
        stringBuf
            .append(System.getProperty("os.name")).append(' ')
            .append(System.getProperty("os.version")).append(" (")
            .append(System.getProperty("os.arch")).append(")\n");
        
        String stacktrace = stringBuf.toString();
        
        StringBuilder sb = new StringBuilder();
        sb.append(message).append('\n');
        if (localizedMessage != null)
            sb.append(localizedMessage).append('\n');
        sb.append('\n');
        sb.append(stacktrace);
        fullMessage = sb.toString();
        
        textStacktrace = new JTextArea(stacktrace);
        textStacktrace.setFont(new Font("DialogInput", Font.PLAIN, 12));
        textStacktrace.setEditable(false);
        textStacktrace.addMouseListener(ClipboardPopup.DEFAULT_POPUP);
        textStacktrace.setRows(8);
        //textStacktrace.setColumns(40);
        
        scrollStacktrace = new JScrollPane(textStacktrace, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        
        /*
        boxLabels = Box.createVerticalBox();
        boxLabels.add(lblText);
        boxLabels.add(Box.createVerticalStrut(border));
        if (lblExceptionText != null) {
            boxLabels.add(lblExceptionText);
            boxLabels.add(Box.createVerticalStrut(border));
        }
        boxLabels.add(scrollStacktrace);
        boxLabels.add(strutStacktrace);
        boxLabels.add(boxButtons); 
        
        contentPane.add(Box.createVerticalStrut(border), BorderLayout.NORTH);
        contentPane.add(Box.createVerticalStrut(border), BorderLayout.SOUTH);
        contentPane.add(Box.createHorizontalStrut(border), BorderLayout.WEST);
        contentPane.add(Box.createHorizontalStrut(border), BorderLayout.EAST);
        contentPane.add(boxLabels, BorderLayout.CENTER); */
        
        contentPane.add(lblIcon, "1, 1, 1, 3");
        contentPane.add(lblText, "3, 1");
        if (lblExceptionText != null)
            contentPane.add(lblExceptionText, "3, 3");
        contentPane.add(boxButtons, "1, 7, 3, 7");
        
        this.setResizable(false);
        this.getRootPane().getRootPane().setDefaultButton(btnOK);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        this.setContentPane(contentPane);
        //this.setLocationByPlatform(true);
        
        this.pack();
//        lblText.addComponentListener(this);
//        if (lblExceptionText != null)
//            lblExceptionText.addComponentListener(this);
        
        if (Utils.debugMode) {
//            Utils.debugOut.println("EXCEPTION occured: " + message);
//            exc.printStackTrace(Utils.debugOut);
            log.log(Level.WARNING, "Exception occurred: " + message, exc);
        }
    }