Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 
 package org.apache.cayenne.modeler.dialog;
 
 import  org.apache.cayenne.util.Util;
 import  org.scopemvc.util.UIStrings;
 
 import javax.swing.*;
 import java.awt.*;
Displays CayenneModeler exceptions and warning messages.
 
 public class ErrorDebugDialog extends CayenneDialog implements ActionListener {
     private static Log logObj = LogFactory.getLog(ErrorDebugDialog.class);
    
    
Sole instance of error/warning dialog to disallow showing of multiple dialogs
 
     private static ErrorDebugDialog instance;
     
     protected JButton close;
     protected JButton showHide;
     protected JTextArea exText = new JTextArea();
     protected JPanel exPanel;
     protected Throwable throwable;
     protected boolean detailed;

    
Shows an error dialog with stack trace
 
     public static void guiException(Throwable th) {
         if (th != null) {
             .error("CayenneModeler Error"th);
         }
 
         ErrorDebugDialog dialog =
             new ErrorDebugDialog(Application.getFrame(), "CayenneModeler Error"thtruefalse);
         showDialog(dialog);
     }

    
Shows an warning dialog with stack trace
 
     public static void guiWarning(Throwable thString message) {
         if (th != null) {
             .warn("CayenneModeler Warning"th);
         }
 
         WarningDialog dialog = new WarningDialog(Application.getFrame(), messagethfalsefalse);
         showDialog(dialog);
     }
    
    
Shows an error/warning dialog, closing existing if needed
 
     private static void showDialog(ErrorDebugDialog dialog) {
         if ( != null) {
             .dispose();
         }
         
          = dialog;
         dialog.setVisible(true);
     }

    
Constructor for ErrorDebugDialog.
    protected ErrorDebugDialog(
    CayenneModelerFrame owner,
        String title,
        Throwable throwable,
        boolean detailed)
        throws HeadlessException {
        this(ownertitlethrowabledetailedtrue);
    }
    
    
Constructor for ErrorDebugDialog, allowing to specify 'modal' property
    protected ErrorDebugDialog(
    CayenneModelerFrame owner,
        String title,
        Throwable throwable,
        boolean detailed,
        boolean modal)
        throws HeadlessException {
        super(ownertitlemodal);
        setThrowable(Util.unwindException(throwable));
        setDetailed(detailed);
        init();
    }
    protected void init() {
        setResizable(false);
        Container pane = this.getContentPane();
        pane.setLayout(new BorderLayout());
        // info area
        JEditorPane infoText = new JEditorPane("text/html"infoHTML());
        infoText.setBackground(pane.getBackground());
        infoText.setEditable(false);
        // popup hyperlinks
        infoText.addHyperlinkListener(this);
        JPanel infoPanel = new JPanel();
        infoPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        infoPanel.add(infoText);
        pane.add(infoPanel.);
        // exception area
        if ( != null) {
            .setEditable(false);
            .setLineWrap(true);
            .setWrapStyleWord(true);
            .setRows(16);
            .setColumns(40);
            JScrollPane exScroll =
                new JScrollPane(
                    ,
                    .,
                    .);
             = new JPanel();
            .setLayout(new BorderLayout());
            .setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            .add(exScroll.);
            // buttons
             = new JButton("");
            .addActionListener(this);
            if (isDetailed()) {
                showDetails();
            } else {
                hideDetails();
            }
        }
         = new JButton("Close");
        .addActionListener(this);
        JButton[] buttons = ( != null) ? new JButton[] {  }
        : new JButton[] {  };
        pane.add(PanelFactory.createButtonPanel(buttons), .);
        
        //add a listener to clear static variables, not to produce garbage
        addWindowListener(new WindowAdapter() {
           public void windowClosing(WindowEvent e) {
                = null;
           }
        });
        // prepare to display
        this.pack();
        this.centerWindow();
    }
    protected String infoHTML() {
        String bugreportURL = UIStrings.get("cayenne.bugreport.url");
        return "<b><font face='Arial,Helvetica' size='+1' color='red'>"
            + getTitle()
            + "</font></b><br>"
            + "<font face='Arial,Helvetica' size='-1'>Please copy the message below and "
            + "report this error by going to <br>"
            + "<a href='"
            + bugreportURL
            + "'>"
            + bugreportURL
            + "</a></font>";
    }
    protected void setThrowable(Throwable throwable) {
        this. = throwable;
        String text = null;
        if (throwable != null) {
            StringWriter str = new StringWriter();
            PrintWriter out = new PrintWriter(str);
            // first add extra diagnostics
            String version = UIStrings.get("cayenne.version");
            version = (version != null) ? version : "(unknown)";
            String buildDate = UIStrings.get("cayenne.build.date");
            buildDate = (buildDate != null) ? buildDate : "(unknown)";
            out.println("CayenneModeler Info");
            out.println("Version: " + version);
            out.println("Build Date: " + buildDate);
            out.println("Exception: ");
            out.println("=================================");
            buildStackTrace(outthrowable);
            try {
                out.close();
                str.close();
            } catch (IOException ioex) {
                // this should never happen
            }
            text = str.getBuffer().toString();
        }
        .setText(text);
    }
    protected void buildStackTrace(PrintWriter outThrowable th) {
        if (th == null) {
            return;
        }
        th.printStackTrace(out);
        Throwable cause = th.getCause();
        if (cause != null) {
            out.println("Caused by:");
            buildStackTrace(outcause);
        }
    }
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == ) {
            this.dispose();
        } else if (e.getSource() == ) {
            if (isDetailed()) {
                hideDetails();
            } else {
                showDetails();
            }
            this.pack();
            this.centerWindow();
        }
    }
    protected void hideDetails() {
        getContentPane().remove();
        .setText("Show Details");
        setDetailed(false);
    }
    protected void showDetails() {
        .setText("Hide Details");
        setDetailed(true);
    }

    
Returns the detailed.

Returns:
boolean
    public boolean isDetailed() {
        return ;
    }

    
Sets the detailed.

Parameters:
detailed The detailed to set
    public void setDetailed(boolean detailed) {
        this. = detailed;
    }
New to GrepCode? Check out our FAQ X