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.io.*;
31
import javax.swing.*;
32
import javax.swing.border.*;
33
 
34
import avr.device.event.*;
35
import avr.lang.*;
36
 
37
public class JAboutDialog extends JDialog {
38
 
39
   private static final String ABOUT_INFO =
40
      "AVRcamVIEW:<br>" +
41
      "&nbsp;&nbsp;&nbsp;Version: " + AVRSystem.RELEASE_MAJOR + "." + AVRSystem.RELEASE_MINOR + "<br>" +
42
      "&nbsp;&nbsp;&nbsp;Build Date: " + AVRSystem.BUILD_DATE;
43
 
44
   private JLabel aboutL;
45
   private DataListener handler;
46
   private JMessagePanel messageP;
47
 
48
   public JAboutDialog(Frame owner, JMessagePanel messageP) {
49
      super(owner, "About", true);
50
 
51
      this.messageP = messageP;
52
 
53
      Font labelFont = new Font("Dialog", Font.BOLD, 12);
54
 
55
      aboutL = new JLabel("<html>" + ABOUT_INFO + "</html>");
56
      aboutL.setFont(labelFont);
57
      aboutL.setBorder(new EmptyBorder(20, 40, 20, 40));
58
 
59
      Container contentPane = getContentPane();
60
 
61
      JPanel southP = new JPanel();
62
      southP.add(new JButton( new ProxyAction(this, "dispose", "OK", 'o')));
63
 
64
      contentPane.add(aboutL, BorderLayout.CENTER);
65
      contentPane.add(southP, BorderLayout.SOUTH);
66
 
67
      setResizable(false);
68
 
69
      pack();
70
 
71
   }
72
 
73
   public void setVersion(String version) {
74
      StringBuffer builder = new StringBuffer();
75
      builder.append("<html>")
76
             .append(ABOUT_INFO)
77
             .append("<br><br><hr><br>AVRcam")
78
             .append("<BR>&nbsp;&nbsp;&nbsp;&nbsp;")
79
             .append(version)
80
             .append("<html>");
81
      aboutL.setText(builder.toString());
82
      pack();
83
   }
84
 
85
   public void showDialog() {
86
 
87
      setLocationRelativeTo(getOwner());
88
 
89
      if(AVRSystem.DEVICE.isConnected()) {
90
         try {
91
            handler = new DataHandler(this);
92
            AVRSystem.DEVICE.addDataListener(handler);
93
            messageP.append("Get Version");
94
            AVRSystem.DEVICE.sendGetVersion();
95
         } catch(IOException ioe) {
96
            AVRSystem.LOG.severe("Could not get version: " + ioe.getMessage());
97
            AVRSystem.DEVICE.removeDataListener(handler);
98
         }
99
      }
100
      setVisible(true);
101
   }
102
 
103
   public void dispose() {
104
      AVRSystem.DEVICE.removeDataListener(handler);
105
      super.dispose();
106
   }
107
 
108
   private final static class DataHandler extends DataAdapter {
109
 
110
      private JAboutDialog dialog;
111
 
112
      public DataHandler(JAboutDialog dialog) {
113
         this.dialog = dialog;
114
      }
115
 
116
      public void nck() {
117
         AVRSystem.DEVICE.removeDataListener(this);
118
         dialog.setVersion("Unable to retrieve version.");
119
      }
120
 
121
      public void responseTimerExpired() {
122
         AVRSystem.DEVICE.removeDataListener(this);
123
         dialog.setVersion("Response Timer Expired.");
124
      }
125
 
126
      public void version(String version) {
127
         AVRSystem.DEVICE.removeDataListener(this);
128
         dialog.setVersion(version);
129
      }
130
 
131
   }
132
 
133
}