b40deb8d71ef599a850d1db1d67cfd37c0dd299a
[fleet.git] / src / de / mud / telnet / CharDisplayTest.java
1 package de.mud.telnet;
2 /* "In case you would like to use the packages as libraries please
3  *  apply the GNU Library General Public License as documented in the
4  *  file COPYING.LIB." (from Telnet/Documentation/index.html)
5  */
6
7 /**
8  * CharDisplayTest
9  * --
10  * $Id: CharDisplayTest.java,v 1.1.1.1 1997/03/05 13:35:16 leo Exp $
11  * $timestamp: Mon Feb 17 20:11:20 1997 by Matthias L. Jugel :$
12  *
13  * This file is part of "The Java Telnet Applet".
14  *
15  * This is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2, or (at your option)
18  * any later version.
19  *
20  * "The Java Telnet Applet" is distributed in the hope that it will be 
21  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this software; see the file COPYING.  If not, write to the
27  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28  * Boston, MA 02111-1307, USA.
29  */
30
31 import java.applet.Applet;
32 import java.awt.Button;
33 import java.awt.Panel;
34 import java.awt.Event;
35 import java.awt.FlowLayout;
36 import java.awt.BorderLayout;
37 import java.awt.Choice;
38 import java.awt.TextField;
39 import java.awt.Font;
40
41 import de.mud.telnet.display.CharDisplay;
42
43 /**
44  * CharDisplayTest -- a test applet to show the display/CharDisplay features
45  * --
46  * @version     $Id: CharDisplayTest.java,v 1.1.1.1 1997/03/05 13:35:16 leo Exp $
47  * @author      Matthias L. Jugel, Marcus Meißner
48  */
49 public class CharDisplayTest extends Applet
50 {
51   CharDisplay display = new CharDisplay(80, 24, "Courier", 14);
52
53   Panel buttons = new Panel();
54   Button info = new Button("Information");
55   Button chars = new Button("Character Table");
56   Button attr = new Button("Attributes");
57   Choice fonts = new Choice();
58   TextField from = new TextField("0", 4);
59
60   public void init()
61   {
62     setLayout(new BorderLayout());
63     fonts.addItem("Helvetica");
64     fonts.addItem("TimesRoman");
65     fonts.addItem("Courier");
66     fonts.addItem("Dialog");
67     fonts.addItem("DialogInput");
68     fonts.addItem("ZapfDingBats");
69     fonts.addItem("default");
70     buttons.add(info);
71     buttons.add(chars);
72     buttons.add(attr);
73     buttons.add(fonts);
74     buttons.add(from);
75     add("North", buttons);
76     display.setResizeStrategy(CharDisplay.RESIZE_FONT);
77     add("Center", display);
78     Info();
79   }
80   
81   public boolean handleEvent(Event evt)
82   {
83     if(evt.target == info) { Info(); return true; }
84     if(evt.target == chars) { CharacterTable(); return true; }
85     if(evt.target == attr) { Attributes(); return true; }
86     if(evt.id == Event.ACTION_EVENT && 
87        (evt.target == fonts || evt.target == from))
88     {
89       remove(display);
90       display = new CharDisplay(80, 24, fonts.getSelectedItem(), 12);
91       add("Center", display);
92       CharacterTable();
93       layout();
94       return true;
95     }
96     return false;
97   }
98
99   private void Clear()
100   {
101     display.deleteArea(0, 0, 80, 24);
102   }
103     
104   private void Info()
105   {
106     Clear();
107     display.putString(4, 1, "CharDisplay.class Information", CharDisplay.INVERT);
108     display.putString(4, 3, "Version: "+display.version, CharDisplay.BOLD);
109     display.putString(4, 5, "This class implements several hardware features needed to implement");
110     display.putString(4, 6, "a video terminal.");
111     display.putString(4, 7, "This includes simple operations, such as putting and inserting single");
112     display.putString(4, 8, "characters or strings on the screen, character attributes and colors.");
113     display.putString(4, 9, "Special features like inserting lines, scrolling text up or down and");
114     display.putString(4,10, "defining scrollareas help implementing terminal emulations.");
115     display.redraw();
116   }
117     
118   private void CharacterTable()
119   {
120     int ch = (new Integer(from.getText())).intValue();
121     
122     Clear();
123     display.putString( 4, 1, "Character Table", CharDisplay.INVERT);
124     for(int c = 1; c < 80; c += 6)
125       for(int l = 3; l < 23; l++)
126       {
127         display.putString(c, l, ""+ch, CharDisplay.INVERT);
128         display.putChar(c+4, l, (char)ch++);
129       }
130     display.markLine(3, 20);
131     display.redraw();
132   }
133
134   private void Attributes()
135   {
136     int c = 4, l = 8;
137     
138     Clear();
139     display.putString( 4, 1, "Character attributes", CharDisplay.INVERT);
140     display.putString( 4, 3, "Normal", CharDisplay.NORMAL);
141     display.putString(22, 3, "Bold", CharDisplay.BOLD);
142     display.putString(40, 3, "Underline", CharDisplay.UNDERLINE);
143     display.putString(58, 3, "Invert", CharDisplay.INVERT);
144
145     display.putString( 4, 5, "Black", 1 << 3 | 8 << 7);
146     display.putString(13, 5, "Red", 2 << 3);
147     display.putString(22, 5, "Green", 3 << 3);
148     display.putString(31, 5, "Yellow", 4 << 3);
149     display.putString(40, 5, "Blue", 5 << 3);
150     display.putString(49, 5, "Magenta", 6 << 3);
151     display.putString(58, 5, "Cyan", 7 << 3);
152     display.putString(67, 5, "LightGray", 8 << 3);
153     
154     for(int bg = 1; bg <= 8; bg++)
155     {
156       for(int fg = 1; fg <= 8; fg++)
157       {
158         for(int a = 0; a <= 7; a++)
159         {
160           display.putChar(c++, l, '@', (fg << 3) | (bg << 7) | a);
161           display.redraw();
162         }
163         c++;
164       }
165       l += 2; c = 4;
166     }
167     
168   }
169 }