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: ConsoleFrame.java,v $ 023 Revision 1.11 2004/05/12 19:12:05 markl 024 comment block updates 025 026 Revision 1.10 2004/03/16 06:43:39 markl 027 LocaleManager method change 028 029 Revision 1.9 2004/03/15 05:43:04 markl 030 refactored into two classes. 031 032 Revision 1.8 2003/01/19 09:46:47 markl 033 replaced JScrollPane instances with KScrollPane. 034 035 Revision 1.7 2002/08/11 09:50:30 markl 036 Javadoc fix. 037 038 Revision 1.6 2001/03/20 00:54:52 markl 039 Fixed deprecated calls. 040 041 Revision 1.5 2001/03/12 09:27:53 markl 042 Source code and Javadoc cleanup. 043 044 Revision 1.4 1999/04/19 05:59:04 markl 045 I18N changes. 046 047 Revision 1.3 1999/02/02 07:56:30 markl 048 Fixed the close button to only hide the frame, not dispose it. 049 050 Revision 1.2 1999/01/10 01:00:58 markl 051 added GPL header & RCS tag 052 ---------------------------------------------------------------------------- 053*/ 054 055package kiwi.ui; 056 057import java.awt.*; 058import java.awt.event.*; 059import javax.swing.*; 060import javax.swing.border.*; 061 062import kiwi.util.*; 063 064/** A GUI console window. This class implements the 065 * <code>LoggingEndpoint</code> interface and as such can be used as the 066 * destination of log messages sent using that interface. 067 * 068 * <p><center> 069 * <img src="snapshot/ConsoleFrame.gif"><br> 070 * <i>An example ConsoleFrame.</i> 071 * </center> 072 * 073 * @author Mark Lindner 074 */ 075 076public class ConsoleFrame extends KFrame implements LoggingEndpoint 077 { 078 private KButton b_clear, b_dismiss; 079 private ConsolePanel console; 080 081 082 /** Construct a new <code>ConsoleFrame</code> with a default title. 083 * 084 */ 085 086 public ConsoleFrame() 087 { 088 this(""); 089 } 090 091 /** Construct a new <code>ConsoleFrame</code>. 092 * 093 * @param title The title for the console window. 094 */ 095 096 public ConsoleFrame(String title) 097 { 098 super(title); 099 100 ActionListener actionListener = new ActionListener() 101 { 102 public void actionPerformed(ActionEvent evt) 103 { 104 Object o = evt.getSource(); 105 106 if(o == b_clear) 107 console.clear(); 108 else if(o == b_dismiss) 109 setVisible(false); 110 } 111 }; 112 113 LocaleData loc = LocaleManager.getDefault().getLocaleData("KiwiDialogs"); 114 115 KPanel main = getMainContainer(); 116 117 main.setLayout(new BorderLayout(5, 5)); 118 main.setBorder(KiwiUtils.defaultBorder); 119 120 console = new ConsolePanel(); 121 main.add("Center", console); 122 123 // buttons 124 125 ButtonPanel buttons = new ButtonPanel(); 126 127 b_clear = new KButton(loc.getMessage("kiwi.button.clear")); 128 b_clear.addActionListener(actionListener); 129 buttons.addButton(b_clear); 130 131 b_dismiss = new KButton(loc.getMessage("kiwi.button.dismiss")); 132 b_dismiss.addActionListener(actionListener); 133 buttons.addButton(b_dismiss); 134 135 main.add("South", buttons); 136 137 if(getTitle().length() == 0) 138 setTitle(loc.getMessage("kiwi.dialog.title.console")); 139 140 pack(); 141 } 142 143 /** Set the number of save lines. 144 * 145 * @param lines The number of lines of text that are saved by the console. 146 */ 147 148 public void setSaveLines(int lines) 149 { 150 console.setSaveLines(lines); 151 } 152 153 /** Get the number of save lines. 154 * 155 * @return The number of lines of text that are saved by the console. 156 */ 157 158 public int getSaveLines() 159 { 160 return(console.getSaveLines()); 161 } 162 163 /** Log a message to the console. 164 * 165 * @param type The message type 166 * @param message The message proper. 167 * 168 * @see kiwi.util.LoggingEndpoint 169 */ 170 171 public void logMessage(int type, String message) 172 { 173 console.logMessage(type, message); 174 } 175 176 /** Close the console. 177 * 178 * @see kiwi.util.LoggingEndpoint 179 */ 180 181 public void close() 182 { 183 setVisible(false); 184 dispose(); 185 } 186 187 } 188 189/* end of source file */