root / tags / v1_0_2_Build_906 / libraries / libIverUtiles / src / com / iver / utiles / console / test / JConsoleTest.java @ 10972
History | View | Annotate | Download (3.95 KB)
1 |
/*
|
---|---|
2 |
* Created on 31-ene-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
21 |
USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.utiles.console.test; |
46 |
|
47 |
import javax.swing.JButton; |
48 |
import javax.swing.JFrame; |
49 |
import javax.swing.UIManager; |
50 |
|
51 |
import com.iver.utiles.console.JConsole; |
52 |
import com.iver.utiles.console.JDockPanel; |
53 |
import com.iver.utiles.console.ResponseListener; |
54 |
public class JConsoleTest extends JFrame { |
55 |
|
56 |
private javax.swing.JPanel jContentPane = null; |
57 |
|
58 |
private JConsole jConsole = null; |
59 |
private JButton jButton = null; |
60 |
/**
|
61 |
* This is the default constructor
|
62 |
*/
|
63 |
public JConsoleTest() {
|
64 |
super();
|
65 |
initialize(); |
66 |
} |
67 |
/**
|
68 |
* This method initializes this
|
69 |
*
|
70 |
* @return void
|
71 |
*/
|
72 |
private void initialize() { |
73 |
this.setSize(300,200); |
74 |
this.setContentPane(getJContentPane());
|
75 |
this.setTitle("JFrame"); |
76 |
} |
77 |
/**
|
78 |
* This method initializes jContentPane
|
79 |
*
|
80 |
* @return javax.swing.JPanel
|
81 |
*/
|
82 |
private javax.swing.JPanel getJContentPane() {
|
83 |
if(jContentPane == null) { |
84 |
jContentPane = new javax.swing.JPanel();
|
85 |
jContentPane.setLayout(new java.awt.BorderLayout());
|
86 |
JDockPanel dock = new JDockPanel(getJConsole());
|
87 |
jContentPane.add(dock, java.awt.BorderLayout.SOUTH); |
88 |
} |
89 |
return jContentPane;
|
90 |
} |
91 |
/**
|
92 |
* This method initializes jConsole
|
93 |
*
|
94 |
* @return com.iver.utiles.console.JConsole
|
95 |
*/
|
96 |
private JConsole getJConsole() {
|
97 |
if (jConsole == null) { |
98 |
jConsole = new JConsole();
|
99 |
// jConsole.add(getJButton(), java.awt.BorderLayout.NORTH);
|
100 |
} |
101 |
return jConsole;
|
102 |
} |
103 |
/**
|
104 |
* This method initializes jButton
|
105 |
*
|
106 |
* @return javax.swing.JButton
|
107 |
*/
|
108 |
private JButton getJButton() { |
109 |
if (jButton == null) { |
110 |
jButton = new JButton(); |
111 |
jButton.setPreferredSize(new java.awt.Dimension(34,25)); |
112 |
} |
113 |
return jButton;
|
114 |
} |
115 |
|
116 |
public static void main(String[] args) { |
117 |
MyBoolean responsed = new MyBoolean();
|
118 |
|
119 |
//Se pone el lookAndFeel
|
120 |
try {
|
121 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
122 |
} catch (Exception e) { |
123 |
|
124 |
} |
125 |
|
126 |
|
127 |
JConsoleTest ct = new JConsoleTest();
|
128 |
ct.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
129 |
ct.show(); |
130 |
ResponseHandler listener = new ResponseHandler(responsed, ct);
|
131 |
ct.getJConsole().addResponseListener(listener); |
132 |
while (true){ |
133 |
responsed.value = false;
|
134 |
ct.getJConsole().addText("Como vas? ",JConsole.MESSAGE);
|
135 |
|
136 |
while (!responsed.value){
|
137 |
|
138 |
} |
139 |
} |
140 |
} |
141 |
|
142 |
private static class MyBoolean{ |
143 |
public boolean value; |
144 |
} |
145 |
|
146 |
private static class ResponseHandler implements ResponseListener { |
147 |
|
148 |
private MyBoolean responsed;
|
149 |
private JConsoleTest ct;
|
150 |
|
151 |
public ResponseHandler(MyBoolean responsed, JConsoleTest ct){
|
152 |
this.responsed = responsed;
|
153 |
this.ct = ct;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* @throws InvalidResponseException
|
158 |
* @see com.iver.utiles.console.ResponseListener#acceptResponse(java.lang.String)
|
159 |
*/
|
160 |
public void acceptResponse(String response){ |
161 |
ct.jButton.setText(response); |
162 |
responsed.value = true;
|
163 |
} |
164 |
|
165 |
} |
166 |
} |