001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: ConsolePanel.java,v $ 023 Revision 1.2 2004/05/12 19:04:16 markl 024 comment block updates 025 026 Revision 1.1 2004/03/15 05:43:04 markl 027 refactored into two classes. 028 ---------------------------------------------------------------------------- 029*/ 030 031package kiwi.ui; 032 033import java.awt.*; 034import javax.swing.*; 035 036import kiwi.util.*; 037 038/** A GUI console panel. This class implements the 039 * <code>LoggingEndpoint</code> interface and as such can be used as the 040 * destination of log messages sent using that interface. 041 * 042 * @author Mark Lindner 043 * @since Kiwi 2.0 044 * @see kiwi.ui.ConsoleFrame 045 */ 046 047public class ConsolePanel extends KPanel implements LoggingEndpoint 048 { 049 private ScrollbackView buffer; 050 /** The message type-to-color mapping. */ 051 protected Color types[] = { Color.green, Color.yellow, Color.orange, 052 Color.red }; 053 054 /** Construct a new <code>ConsolePanel</code>. 055 */ 056 057 public ConsolePanel() 058 { 059 setLayout(new GridLayout(1, 0)); 060 061 buffer = new ScrollbackView(); 062 063 buffer.setCellRenderer(new ColoredCellRenderer()); 064 buffer.setBackground(Color.black); 065 066 KScrollPane sp = new KScrollPane(buffer); 067 068 add(sp); 069 } 070 071 /** Set the background color for the component. 072 * 073 * @param color The new background color. 074 */ 075 076 public void setBackground(Color color) 077 { 078 if(buffer != null) 079 buffer.setBackground(color); 080 super.setBackground(color); 081 } 082 083 /** Clear the console panel. All messages displayed in the panel are removed. 084 */ 085 086 public void clear() 087 { 088 buffer.clear(); 089 } 090 091 /** Set the number of save lines. 092 * 093 * @param lines The number of lines of text that are saved by the console. 094 */ 095 096 public void setSaveLines(int lines) 097 { 098 buffer.setSaveLines(lines); 099 } 100 101 /** Get the number of save lines. 102 * 103 * @return The number of lines of text that are saved by the console. 104 */ 105 106 public int getSaveLines() 107 { 108 return(buffer.getSaveLines()); 109 } 110 111 /** Log a message to the console. 112 * 113 * @param type The message type 114 * @param message The message proper. 115 * 116 * @see kiwi.util.LoggingEndpoint 117 */ 118 119 public void logMessage(int type, String message) 120 { 121 buffer.addItem(new ColoredString(message, types[type])); 122 } 123 124 /** Close the console. 125 * 126 * @see kiwi.util.LoggingEndpoint 127 */ 128 129 public void close() 130 { 131 // no-op 132 } 133 134 } 135 136/* end of source file */