Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
157 kaklik 1
/*
2
    AVRcamVIEW: A PC application to test out the functionallity of the
3
     AVRcam real-time image processing engine.
4
    Copyright (C) 2004    Brent A. Taylor
5
 
6
    This program is free software; you can redistribute it and/or
7
    modify it under the terms of the GNU General Public
8
    License as published by the Free Software Foundation; either
9
    version 2 of the License, or (at your option) any later version.
10
 
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
    General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public
17
    License along with this program; if not, write to the Free Software
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
20
   For more information on the AVRcamVIEW, please contact:
21
 
22
   taylorba@comcast.net
23
 
24
   or go to www.jrobot.net for more details regarding the system.
25
*/
26
 
27
package avr.swing;
28
 
29
import java.awt.*;
30
import java.nio.*;
31
import javax.swing.*;
32
import javax.swing.border.*;
33
import javax.swing.plaf.metal.MetalLookAndFeel;
34
 
35
import avr.device.event.*;
36
import avr.lang.*;
37
 
38
public class JMessagePanel extends JPanel {
39
 
40
   private JTextArea messageTA;
41
 
42
   public JMessagePanel() {
43
      super(new BorderLayout());
44
 
45
      JLabel titleL = new JLabel("System Messages", JLabel.CENTER);
46
      titleL.setFont(titleL.getFont().deriveFont(16.0f));
47
 
48
      JButton closeB = new JButton(new ProxyAction(this, "close", UIManager.getIcon("InternalFrame.paletteCloseIcon")));
49
      closeB.setBackground(MetalLookAndFeel.getPrimaryControlShadow());
50
      closeB.setBorder(new EmptyBorder(0, 0, 0, 0));
51
 
52
      messageTA = new JTextArea(6, 20);
53
      messageTA.setEditable(false);
54
 
55
      Box titleBox = new Box(BoxLayout.X_AXIS);
56
      titleBox.setBorder(new EmptyBorder(5, 5, 5, 5));
57
      titleBox.add(titleL);
58
      titleBox.add(Box.createHorizontalGlue());
59
      titleBox.add(closeB);
60
 
61
      JPanel southP = new JPanel(new FlowLayout(FlowLayout.RIGHT));
62
      southP.setBorder(new EtchedBorder());
63
      southP.add(new JButton(new ProxyAction(this, "clear", "Clear", 'c')));
64
 
65
      add(titleBox, BorderLayout.NORTH);
66
      add(new JScrollPane(messageTA), BorderLayout.CENTER);
67
      add(southP, BorderLayout.SOUTH);
68
 
69
      AVRSystem.DEVICE.addDataListener(new DataHandler(messageTA));
70
   }
71
 
72
   public void append(String message) {
73
      messageTA.append(message);
74
      messageTA.append("\n");
75
   }
76
 
77
   public void clear() {
78
      messageTA.setText("");
79
   }
80
 
81
   public void close() {
82
      setVisible(false);
83
   }
84
 
85
   private final static class DataHandler implements DataListener {
86
 
87
      private JTextArea messageTA;
88
 
89
      public DataHandler(JTextArea messageTA) {
90
         this.messageTA = messageTA;
91
      }
92
 
93
      public void ack() {
94
         messageTA.append("ACK\n");
95
      }
96
 
97
      public void nck() {
98
         messageTA.append("NCK\n");
99
      }
100
 
101
      public void version(String version) {
102
         messageTA.append(version);
103
         messageTA.append("\n");
104
      }
105
 
106
      public void responseTimerExpired() {
107
         messageTA.append("Response Timer Expired\n");
108
      }
109
 
110
      public void frameData(ByteBuffer data) {
111
         messageTA.append("Frame Data (" + (data.get() & 0xFF) + ")\n");
112
      }
113
 
114
      public void trackingData(ByteBuffer data) {
115
         messageTA.append("Tracking Data (" + (data.get() & 0xFF) + ")\n");
116
      }
117
 
118
   }
119
 
120
}