示例#1
0
 public ImageIcon getDisplayIcon() {
     if (displayIcon == null) {
         String filename;
         if (singleCharCode == '?') {
             filename = "jobstate_questionmark.gif";
         } else {
             filename = "jobstate_" + singleCharCode + ".gif";
         }
         displayIcon = Utils.loadCustomIcon(filename);
     }
     return displayIcon;
 }
 public void actionPerformed(ActionEvent e) {
     Object source = e.getSource();
     if (source == btnOK) {
         dispose();
     } else if (source == btnDetails) {
         detailState = !detailState;
         if (detailState) {
             contentPane.add(strutStacktrace, "1, 4, 3, 4");
             contentPane.add(scrollStacktrace, "1, 5, 3, 5");
         } else {
             contentPane.remove(strutStacktrace);
             contentPane.remove(scrollStacktrace);
         }
         btnDetails.setText(Utils._("Details") + (detailState ? " <<" : " >>"));
         this.setResizable(detailState);
         this.pack();
     } else if (source == btnCopy) {
         StringSelection contents = new StringSelection(fullMessage);
         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, contents);
     }
 }
示例#3
0
/**
 * @author jonas
 *
 */
public enum JobState implements IconMap {
    UNDEFINED('?', -1, Utils._("Undefined")),
    FAILED('F', 8, Utils._("Failed")),
    SUSPENDED('T', 1, Utils._("Suspended"), Utils._("Suspended (not being scheduled)")),
    PENDING('P', 2, Utils._("Pending"), Utils._("Pending (waiting for the time to send to arrive)")),
    SLEEPING('S', 3, Utils._("Sleeping"), Utils._("Sleeping (waiting for a scheduled timeout such as a delay between attempts to send)")),
    BLOCKED('B', 4, Utils._("Blocked"), Utils._("Blocked (by concurrent activity to the same destination)")),
    WAITING('W', 5, Utils._("Waiting"), Utils._("Waiting (for resources such as a free modem)")),
    RUNNING('R', 6, Utils._("Running")),
    DONE('D', 7, Utils._("Done"))
    ;
    
    private final char singleCharCode;
    private final int queueCode;
    private final String label;
    private final String description;
    private transient ImageIcon displayIcon = null;
    
    private JobState(char singleCharCode, int queueCode, String label) {
        this(singleCharCode, queueCode, label, label);
    }
    
    private JobState(char singleCharCode, int queueCode, String label,
            String description) {
        this.singleCharCode = singleCharCode;
        this.queueCode = queueCode;
        this.label = label;
        this.description = description;
    }

    public char getSingleCharCode() {
        return singleCharCode;
    }
    
    public int getQueueCode() {
        return queueCode;
    }
    
    
    public String getDescription() {
        return description;
    }

    public ImageIcon getDisplayIcon() {
        if (displayIcon == null) {
            String filename;
            if (singleCharCode == '?') {
                filename = "jobstate_questionmark.gif";
            } else {
                filename = "jobstate_" + singleCharCode + ".gif";
            }
            displayIcon = Utils.loadCustomIcon(filename);
        }
        return displayIcon;
    }

    public String getText() {
        return label;
    }
    
    @Override
    public String toString() {
        return label;
    }
        
    //From man doneq:
    // state: The job scheduling state.  Recognized values are:
    // 1 (suspended, not being scheduled),
    public static final int QUEUESTATE_SUSPENDED = 1;
    // 2 (pending, waiting for the time to send), 
    public static final int QUEUESTATE_PENDING = 2;
    // 3 (sleeping,  waiting for a scheduled timeout),
    public static final int QUEUESTATE_SLEEPING = 3;
    // 4 (blocked, waiting for concurrent activity to the same destination to complete),
    public static final int QUEUESTATE_BLOCKED = 4;
    // 5 (ready, ready to be processed except for available resources),
    public static final int QUEUESTATE_READY = 5;
    // 6 (active, actively being processed by HylaFAX),
    public static final int QUEUESTATE_ACTIVE = 6;
    // 7 (done,  processing completed with success).
    public static final int QUEUESTATE_DONE = 7;
    // 8 (failed, processing completed with a failure).
    public static final int QUEUESTATE_FAILED = 8; 
    
    // Unknown
    public static final int QUEUESTATE_UNKNOWN = -1;
    
    /**
     * Returns the job state corresponding to the given queue code
     * @param intState
     * @return
     */
    public static JobState getJobStateFromQueueCode(int intState) {
        switch (intState) { // Map to sent job one character code
        case QUEUESTATE_ACTIVE:
            return RUNNING;
        case QUEUESTATE_BLOCKED:
            return  BLOCKED;
        case QUEUESTATE_DONE:
            return  DONE;
        case QUEUESTATE_FAILED:
            return FAILED;
        case QUEUESTATE_PENDING:
            return PENDING;
        case QUEUESTATE_READY:
            return WAITING;
        case QUEUESTATE_SLEEPING:
            return SLEEPING;
        case QUEUESTATE_SUSPENDED:
            return SUSPENDED;
        default:
            return UNDEFINED;
        }
    }

    public static final char JOBSTATE_UNDEFINED = '?';
    public static final char JOBSTATE_FAILED = 'F';
    public static final char JOBSTATE_SUSPENDED = 'T';
    public static final char JOBSTATE_PENDING = 'P';
    public static final char JOBSTATE_SLEEPING = 'S';
    public static final char JOBSTATE_BLOCKED = 'B';
    public static final char JOBSTATE_WAITING = 'W';
    public static final char JOBSTATE_RUNNING = 'R';
    public static final char JOBSTATE_DONE = 'D';
    
    /**
     * Returns the job state for the given single character code
     * @param state
     * @return the job state 
     */
    public static JobState getJobStateFromCharCode(char state) {
        switch (state) {
        case JOBSTATE_BLOCKED:
            return BLOCKED;
        case JOBSTATE_DONE:
            return DONE;
        case JOBSTATE_FAILED:
            return FAILED;
        case JOBSTATE_PENDING:
            return PENDING;
        case JOBSTATE_RUNNING:
            return RUNNING;
        case JOBSTATE_SLEEPING:
            return SLEEPING;
        case JOBSTATE_SUSPENDED:
            return SUSPENDED;
        case JOBSTATE_UNDEFINED:
        default:
            return UNDEFINED;
        case JOBSTATE_WAITING:
            return WAITING;
        }
    }
}
    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);
        }
    }
    public static void showExceptionDialog(Component owner, String title, String message, Exception exc) {
        if (SwingUtilities.isEventDispatchThread()) {
            ExceptionDialog eDlg;
            if (!(owner instanceof Window)) {
                if (owner != null) {
                    owner = SwingUtilities.getWindowAncestor(owner);
                }
                if (owner == null) {
                    owner = Launcher2.application.getFrame();
                }
            }


            if (owner instanceof Dialog) {
                eDlg = new ExceptionDialog((Dialog)owner, title, message, exc);
            } else if (owner instanceof Frame) {
                eDlg = new ExceptionDialog((Frame)owner, title, message, exc);
            } else {
                JOptionPane.showMessageDialog(owner, message + "\n" + exc.getMessage(), Utils._("Error"), JOptionPane.ERROR_MESSAGE);
                return;
            }
            eDlg.setVisible(true);
        } else {
            try {
                SwingUtilities.invokeAndWait(new DisplayRunnable(owner, title, message, exc));
            } catch (InterruptedException e) {
                log.log(Level.WARNING, "Error showing exception dialog.", e);
            } catch (InvocationTargetException e) {
                log.log(Level.WARNING, "Error showing exception dialog.", e);
            }
        }
    }
 public static void showExceptionDialog(Component owner, String message, Exception exc) {
     showExceptionDialog(owner, Utils._("Error"), message, exc);
 }