KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > ipod > panels > LogPanel


1 /**
2  * Copyright (C) 2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package sync4j.syncclient.ipod.panels;
19
20 import java.io.File JavaDoc;
21 import java.io.FileReader JavaDoc;
22 import java.io.BufferedReader JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import java.awt.Color JavaDoc;
26 import java.awt.BorderLayout JavaDoc;
27 import java.awt.GridBagLayout JavaDoc;
28 import java.awt.Dimension JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31
32 import javax.swing.JDialog JavaDoc;
33 import javax.swing.JScrollPane JavaDoc;
34 import javax.swing.JTextArea JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.JButton JavaDoc;
37 import javax.swing.UIManager JavaDoc;
38 import javax.swing.border.*;
39 import javax.swing.SwingConstants JavaDoc;
40
41 import sync4j.syncclient.ipod.MainWindow;
42 import sync4j.syncclient.ipod.utils.*;
43
44 /**
45  * The Logging window.
46  *
47  * @author Luigia Fassina @ Funambol
48  * @version $Id: LogPanel.java,v 1.2 2005/03/22 09:10:26 luigiafassina Exp $
49  */

50 public class LogPanel extends JDialog JavaDoc implements ActionListener JavaDoc, Constants JavaDoc {
51
52     // ------------------------------------------- Private Data
53
private MainWindow mainWindow ;
54     private boolean modal = false ;
55
56     private JButton JavaDoc jbClose ;
57     private JScrollPane JavaDoc jScrollPane1;
58     private JTextArea JavaDoc jTextArea ;
59     private JPanel JavaDoc jPanel ;
60
61     // ------------------------------------------ Public Methods
62

63     /** Creates new form JDialog */
64     public LogPanel(MainWindow mainWindow, boolean modal) {
65         super(mainWindow, modal);
66         this.mainWindow = mainWindow;
67         this.modal = modal ;
68
69         initComponents();
70         getFileLog();
71     }
72
73     /**
74      * This method is called from within the constructor to
75      * initialize the form.
76      */

77     private void initComponents() {
78         jbClose = new JButton JavaDoc() ;
79         jScrollPane1 = new JScrollPane JavaDoc();
80         jTextArea = new JTextArea JavaDoc() ;
81         jPanel = new JPanel JavaDoc() ;
82
83         try {
84             UIManager.setLookAndFeel(lookAndFeel);
85         } catch(Exception JavaDoc e) {
86             e.printStackTrace();
87         }
88
89         //
90
// Set up the window.
91
//
92
getContentPane().setLayout(new BorderLayout JavaDoc(1,1));
93         setTitle(Language.getMessage(Language.LABEL_TITLE_LOGWINDOW));
94         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
95         setSize(600,600);
96         setLocationRelativeTo(null);
97         setFont(font);
98         setName("logDialog");
99         setResizable(true);
100
101         jTextArea.setEditable(false);
102         jTextArea.setFont(font);
103         jTextArea.setBackground(Color.WHITE);
104         jScrollPane1.setAutoscrolls(true);
105         jScrollPane1.setViewportView(jTextArea);
106         getContentPane().add(jScrollPane1, BorderLayout.CENTER);
107
108         jPanel.setLayout(new GridBagLayout JavaDoc());
109         jPanel.setBackground(Color.WHITE);
110         jPanel.setPreferredSize(new Dimension JavaDoc(400, 50));
111         getContentPane().add(jPanel, BorderLayout.SOUTH);
112
113         jbClose.setText(Language.getMessage(Language.BT_CLOSE));
114         jbClose.setPreferredSize(new Dimension JavaDoc(88, 23));
115         jbClose.setVerticalAlignment(SwingConstants.CENTER);
116         jbClose.setHorizontalAlignment(SwingConstants.CENTER);
117         jbClose.addActionListener(this);
118         jbClose.requestFocus(true);
119         jPanel.add(jbClose);
120     }
121
122     public void actionPerformed(ActionEvent JavaDoc evt) {
123         removeAll();
124         setVisible(false);
125     }
126
127     /**
128      * Read the file with logging to show
129      */

130     private void getFileLog() {
131         try {
132             File JavaDoc logfile = mainWindow.getFileLog();
133             if (logfile != null) {
134                 FileReader JavaDoc fr = new FileReader JavaDoc(logfile);
135                 BufferedReader JavaDoc buf = new BufferedReader JavaDoc(fr);
136
137                 String JavaDoc line = null;
138                 while ((line = buf.readLine()) != null) {
139                     jTextArea.append(line);
140                     jTextArea.append("\n");
141                 }
142                 buf.close();
143             }
144         } catch (IOException JavaDoc e) {
145             e.printStackTrace();
146             System.exit(1);
147         }
148     }
149
150 }
151
Popular Tags