001: /*
002: * SystemOutputPanel.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.executequery.gui;
023:
024: import java.awt.BorderLayout;
025: import java.awt.Font;
026: import java.io.IOException;
027: import javax.swing.BorderFactory;
028: import javax.swing.Icon;
029: import javax.swing.JScrollPane;
030: import javax.swing.JTextArea;
031: import org.apache.log4j.PatternLayout;
032: import org.executequery.Constants;
033: import org.executequery.GUIUtilities;
034: import org.executequery.SystemUtilities;
035: import org.executequery.components.TextAreaLogAppender;
036: import org.executequery.util.Log;
037: import org.underworldlabs.util.FileUtils;
038: import org.underworldlabs.util.SystemProperties;
039:
040: // TODO: NEW STUFF
041:
042: /* ----------------------------------------------------------
043: * CVS NOTE: Changes to the CVS repository prior to the
044: * release of version 3.0.0beta1 has meant a
045: * resetting of CVS revision numbers.
046: * ----------------------------------------------------------
047: */
048:
049: /**
050: *
051: * @author Takis Diakoumis
052: * @version $Revision: 1.7 $
053: * @date $Date: 2006/09/06 09:30:58 $
054: */
055: public class SystemOutputPanel extends AbstractDockedTabPanel {
056:
057: /** This panel's title */
058: public static final String TITLE = "Output Console";
059:
060: /** the output text area */
061: private JTextArea textArea;
062:
063: public SystemOutputPanel() {
064: super (new BorderLayout());
065: try {
066: jbInit();
067: } catch (Exception e) {
068: e.printStackTrace();
069: }
070: }
071:
072: private void jbInit() throws Exception {
073: if (!Log.isLogEnabled()) {
074: Log.init(SystemProperties.getProperty("user",
075: "system.log.level"));
076: }
077:
078: textArea = new JTextArea();
079: textArea.setFont(new Font("dialog", 0, 11));
080: textArea.setEditable(false);
081:
082: TextAreaLogAppender appender = new TextAreaLogAppender(textArea);
083: appender.setLayout(new PatternLayout(Log.PATTERN));
084: Log.addAppender(appender);
085:
086: JScrollPane scroller = new JScrollPane(textArea);
087: //scroller.setBorder(BorderFactory.createLineBorder(Color.GRAY));
088: scroller.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0,
089: GUIUtilities.getDefaultBorderColour()));
090: add(scroller, BorderLayout.CENTER);
091: }
092:
093: /**
094: * Resets the contents of the system log.
095: */
096: public void resetSystemLog() {
097: try {
098: FileUtils.writeFile(SystemUtilities.getSystemLogPath(),
099: Constants.EMPTY);
100: } catch (IOException e) {
101: }
102: }
103:
104: public Icon getIcon() {
105: return GUIUtilities.loadIcon("SystemOutput.gif");
106: }
107:
108: public String toString() {
109: return "Output Console";
110: }
111:
112: // ----------------------------------------
113: // DockedTabView Implementation
114: // ----------------------------------------
115:
116: public static final String MENU_ITEM_KEY = "viewConsole";
117:
118: public static final String PROPERTY_KEY = "system.display.console";
119:
120: /**
121: * Returns the display title for this view.
122: *
123: * @return the title displayed for this view
124: */
125: public String getTitle() {
126: return TITLE;
127: }
128:
129: /**
130: * Returns the name defining the property name for this docked tab view.
131: *
132: * @return the key
133: */
134: public String getPropertyKey() {
135: return PROPERTY_KEY;
136: }
137:
138: /**
139: * Returns the name defining the menu cache property
140: * for this docked tab view.
141: *
142: * @return the preferences key
143: */
144: public String getMenuItemKey() {
145: return MENU_ITEM_KEY;
146: }
147:
148: }
|