1   /**
2    * QJ-Pro
3    * Copyright (c) 2004, http://qjpro.sourceforge.net
4    *
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful, but WITHOUT
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13   * details.
14   *
15   * You should have received a copy of the GNU General Public License along with
16   * this program; if not, write to the Free Software Foundation, Inc.,
17   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18   */
19  package com.qasystems.qstudio.java.gui.dialog;
20  
21  import com.qasystems.international.MessageResource;
22  import com.qasystems.qstudio.java.QStudioGlobal;
23  import com.qasystems.qstudio.java.gui.ErrorLog;
24  import com.qasystems.qstudio.java.gui.ErrorLogPane;
25  import com.qasystems.swing.ButtonDialog;
26  
27  import java.awt.Dimension;
28  
29  import javax.swing.event.ChangeEvent;
30  import javax.swing.event.ChangeListener;
31  
32  /**
33   * This class implements a non-modal dialog displaying an error log.
34   *
35   */
36  public class ErrorLogDialog extends ButtonDialog implements ChangeListener {
37    public static final int CLEAR = 0;
38    public static final int SETTINGS = 1;
39    public static final int CLOSE = 2;
40    private static final MessageResource RESOURCES =
41      MessageResource.getClientInstance();
42    private static final String TITLE = RESOURCES.getString("WINDOWTITLE_026");
43    private static final String[] BUTTONS =
44    {
45      RESOURCES.getString("BUTTON_015"), RESOURCES.getString("BUTTON_016"),
46      RESOURCES.getString("BUTTON_007")
47    };
48    private ErrorLogPane logPane = new ErrorLogPane();
49  
50    /**
51     * Default constructor
52     */
53    public ErrorLogDialog() {
54      super(new QStudioGlobal().getFrame());
55  
56      try {
57        jbInit();
58      } catch (Exception ex) {
59        ex.printStackTrace();
60      }
61  
62      pack();
63    }
64  
65    /**
66     * Initialization of panels, buttons, dialog etc. Called by the constructor.
67     *
68     * @throws java.lang.Exception passes all exceptions to the caller
69     */
70    private void jbInit() throws Exception {
71      setModal(false);
72      setResizable(true);
73      setTitle(TITLE);
74      setButtons(BUTTONS);
75      setInitialButton(CLOSE);
76      logPane.setPreferredSize(new Dimension(500, 200));
77      setContent(logPane);
78    }
79  
80    protected void onActionPerformed(int action) {
81      if (action == CLOSE) {
82        close();
83      } else if (action == CLEAR) {
84        clear();
85      } else if (action == SETTINGS) {
86        new DebugLevelDialog(this).show();
87      } else {
88        // action == UNINITIALIZED_VALUE
89      }
90    }
91  
92    private void clear() {
93      logPane.getLog().clear();
94    }
95  
96    private void close() {
97      if (isVisible()) {
98        setVisible(false);
99      }
100   }
101 
102   /**
103    * DOCUMENT ME!
104    *
105    * @param newLog DOCUMENT ME!
106    */
107   public void setLog(ErrorLog newLog) {
108     newLog.addChangeListener(this);
109     logPane.setLog(newLog);
110   }
111 
112   /**
113    * Send to the adaptor by the writer object. Updates the errorlog. Implements
114    * <tt>javax.swing.event.ChangeListener</tt>.
115    *
116    * @param event the change event
117    */
118   public void stateChanged(ChangeEvent event) {
119     setVisible(true);
120     toFront();
121   }
122 }
123