Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / console / test / JConsoleTest.java @ 40561

History | View | Annotate | Download (3.67 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * 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
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.utils.console.test;
26

    
27
import javax.swing.JButton;
28
import javax.swing.JFrame;
29
import javax.swing.UIManager;
30

    
31
import org.gvsig.utils.console.JConsole;
32
import org.gvsig.utils.console.JDockPanel;
33
import org.gvsig.utils.console.ResponseListener;
34

    
35
public class JConsoleTest extends JFrame {
36

    
37
        private javax.swing.JPanel jContentPane = null;
38

    
39
        private JConsole jConsole = null;
40
        private JButton jButton = null;
41
        /**
42
         * This is the default constructor
43
         */
44
        public JConsoleTest() {
45
                super();
46
                initialize();
47
        }
48
        /**
49
         * This method initializes this
50
         *
51
         * @return void
52
         */
53
        private void initialize() {
54
                this.setSize(300,200);
55
                this.setContentPane(getJContentPane());
56
                this.setTitle("JFrame");
57
        }
58
        /**
59
         * This method initializes jContentPane
60
         *
61
         * @return javax.swing.JPanel
62
         */
63
        private javax.swing.JPanel getJContentPane() {
64
                if(jContentPane == null) {
65
                        jContentPane = new javax.swing.JPanel();
66
                        jContentPane.setLayout(new java.awt.BorderLayout());
67
                        JDockPanel dock = new JDockPanel(getJConsole());
68
                        jContentPane.add(dock, java.awt.BorderLayout.SOUTH);
69
                }
70
                return jContentPane;
71
        }
72
        /**
73
         * This method initializes jConsole
74
         *
75
         * @return com.iver.utiles.console.JConsole
76
         */
77
        private JConsole getJConsole() {
78
                if (jConsole == null) {
79
                        jConsole = new JConsole();
80
                        // jConsole.add(getJButton(), java.awt.BorderLayout.NORTH);
81
                }
82
                return jConsole;
83
        }
84
        /**
85
         * This method initializes jButton
86
         *
87
         * @return javax.swing.JButton
88
         */
89
        private JButton getJButton() {
90
                if (jButton == null) {
91
                        jButton = new JButton();
92
                        jButton.setPreferredSize(new java.awt.Dimension(34,25));
93
                }
94
                return jButton;
95
        }
96

    
97
        public static void main(String[] args) {
98
                MyBoolean responsed = new MyBoolean();
99
                
100
                //Se pone el lookAndFeel
101
                try {
102
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
103
                } catch (Exception e) {
104

    
105
                }
106

    
107

    
108
                JConsoleTest ct = new JConsoleTest();
109
                ct.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
110
                ct.show();
111
                ResponseHandler listener = new ResponseHandler(responsed, ct);
112
                ct.getJConsole().addResponseListener(listener);
113
                while (true){
114
                        responsed.value = false;
115
                        ct.getJConsole().addText("Como vas? ",JConsole.MESSAGE);
116

    
117
                        while (!responsed.value){
118

    
119
                        }
120
                }
121
        }
122

    
123
        private static class MyBoolean{
124
                public boolean value;
125
        }
126

    
127
        private static class ResponseHandler implements ResponseListener {
128

    
129
                private MyBoolean responsed;
130
                private JConsoleTest ct;
131

    
132
                public ResponseHandler(MyBoolean responsed, JConsoleTest ct){
133
                        this.responsed = responsed;
134
                        this.ct = ct;
135
                }
136

    
137
                /**
138
                 * @throws InvalidResponseException
139
                 * @see org.gvsig.utils.console.ResponseListener#acceptResponse(java.lang.String)
140
                 */
141
                public void acceptResponse(String response){
142
                        ct.jButton.setText(response);
143
                        responsed.value = true;
144
                }
145

    
146
        }
147
  }