Revision 10945

View differences:

trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/incrementableTask/TestIncrementableTask.java
1
package org.gvsig.gui.beans.incrementableTask;
2

  
3
import org.gvsig.gui.beans.IncrementableTask.IIncrementable;
4
import org.gvsig.gui.beans.IncrementableTask.IncrementableTask;
5

  
6
public class TestIncrementableTask {
7
	class ClassProcess implements IIncrementable {
8
		int i = 0;
9

  
10
		public String getLabel() {
11
			return "Etiqueta " + i;
12
		}
13

  
14
		public String getLog() {
15
			return "Mi log " + i;
16
		}
17

  
18
		public int getPercent() {
19
			i++;
20
			return i/10;
21
		}
22

  
23
		public String getTitle() {
24
			return "TestIncrementTask";
25
		}
26
	}
27

  
28
  ClassProcess ncp = new ClassProcess();
29

  
30
	public TestIncrementableTask() {
31
		super();
32
		initialize();
33
	}
34

  
35
	private void initialize() {
36
		IncrementableTask it = new IncrementableTask(ncp);
37
		it.showWindow();
38
	}
39

  
40
	public static void main(String[] args) {
41
		new TestIncrementableTask();
42
	}
43
}
0 44

  
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/dialogPanel/TestDialogPanel.java
27 27
import javax.swing.UIManager;
28 28

  
29 29
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel;
30
import org.gvsig.gui.beans.defaultButtonsPanel.DefaultButtonsPanel;
30 31
/**
31 32
 * <code>TestDialogPanel</code>. Test para comprobar el funcionamiento de la
32 33
 * clase <code>DialogPanel</code>
......
37 38
public class TestDialogPanel implements ActionListener {
38 39
	private JFrame frame = new JFrame();
39 40

  
40
	class NewComponentDialog extends DialogPanel {
41
	class NewComponentDialog extends DefaultButtonsPanel {
41 42
		private static final long serialVersionUID = 4452922507292538671L;
42 43

  
43 44
		public NewComponentDialog() {
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/progressPanel/TestProgressPanel.java
31 31
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
32 32
 */
33 33
public class TestProgressPanel {
34
	private static final long serialVersionUID = 3008529181447712097L;
35 34

  
36 35
	private tryPanel frame = null;
37 36

  
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/translations/text.properties
1 1
#text.properties
2 2
abrir...=Abrir...
3 3
abrir_archivo=Abrir Archivo
4
acumulado=Acumulado
5 4
a?adir_banda=A?adir banda
6 5
banda=Banda
7 6
bandas=Bandas
8 7
crear_tabla=Crear Tabla
9
datos_visualizados=Datos visualizados
10 8
extraer=Extraer
11 9
filtros=Filtros
12 10
formato_no_numerico=Formato no num?rico
......
32 30
cerrar=Cerrar
33 31
salir=Salir
34 32
verdetalles=Ver detalles
35
ocultardetalles=Ocultar detalles
36
vista_datasource=Extensi?n de la vista
37
imagen_completa=Completo
33
ocultardetalles=Ocultar detalles
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/defaultButtonsPanel/DefaultButtonsPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.gui.beans.defaultButtonsPanel;
20

  
21
import java.awt.Component;
22
import java.awt.LayoutManager;
23

  
24
import javax.swing.JPanel;
25

  
26
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel;
27
/**
28
 * <code>DialogPanel</code> es un Panel que hereda de <code>JPanel</code> con
29
 * el a?adido de poder definir una botonera por defecto.
30
 *
31
 * @version 15/03/2007
32
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
33
 */
34
public class DefaultButtonsPanel extends JPanel {
35
	private static final long serialVersionUID = 1519536113682350563L;
36
	ButtonsPanel bp = null;
37
	JPanel content = null;
38

  
39
	/**
40
	 * Crea el <code>DialogPanel</code> con los botones por defecto.
41
	 */
42
	public DefaultButtonsPanel() {
43
    super.setLayout(new java.awt.BorderLayout(5, 5));
44
		getButtonsPanel().addAccept();
45
		getButtonsPanel().addCancel();
46
		getButtonsPanel().addApply();
47
		super.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
48
		super.add(getContent(), java.awt.BorderLayout.CENTER);
49
	}
50
	
51
	/**
52
	 * Crea el <code>DialogPanel</code> con los botones que definamos de la clase
53
	 * <code>ButtonsPanel</code>
54
	 * 
55
	 * @param buttons Constante para definir que botones se crear?n
56
	 */
57
	public DefaultButtonsPanel(int buttons) {
58
    super.setLayout(new java.awt.BorderLayout(5, 5));		
59
		bp = new ButtonsPanel(buttons);
60
		super.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
61
		super.add(getContent(), java.awt.BorderLayout.CENTER);
62
	}
63
	
64
	/**
65
	 * Obtener el objeto <code>ButtonsPanel</code> del <code>DialogPanel</code>.
66
	 * En caso de no estar creado, lo crear?.
67
	 * 
68
	 * @return El componente bp
69
	 */
70
	public ButtonsPanel getButtonsPanel() {
71
		if (bp == null)
72
			bp = new ButtonsPanel();
73
		return bp;
74
	}
75

  
76
	/**
77
	 * Obtener el contenido del <code>DialogPanel</code>. En caso de no estar creado,
78
	 * lo crear?.
79
	 * 
80
	 * @return El componente content
81
	 */
82
	public JPanel getContent() {
83
		if (content == null)
84
			content = new JPanel();
85
		return content;
86
	}
87

  
88
	/*
89
	 * (non-Javadoc)
90
	 * @see java.awt.Container#getLayout()
91
	 */
92
	public LayoutManager getLayout() {
93
		return getContent().getLayout();
94
	}
95
	
96
	/*
97
	 * (non-Javadoc)
98
	 * @see java.awt.Container#setLayout(java.awt.LayoutManager)
99
	 */
100
	public void setLayout(LayoutManager mgr) {
101
		getContent().setLayout(mgr);
102
	}
103

  
104
	/*
105
	 * (non-Javadoc)
106
	 * @see java.awt.Container#add(java.awt.Component)
107
	 */
108
	public Component add(Component comp) {
109
		return getContent().add(comp);
110
	}
111

  
112
	/*
113
	 * (non-Javadoc)
114
	 * @see java.awt.Container#add(java.awt.Component, int)
115
	 */
116
	public Component add(Component comp, int index) {
117
		return getContent().add(comp, index);
118
	}
119
  
120
	/*
121
	 * (non-Javadoc)
122
	 * @see java.awt.Container#add(java.awt.Component, java.lang.Object)
123
	 */
124
	public void add(Component comp, Object constraints) {
125
		getContent().add(comp, constraints);
126
	}
127
  
128
	/*
129
	 * (non-Javadoc)
130
	 * @see java.awt.Container#add(java.awt.Component, java.lang.Object, int)
131
	 */
132
	public void add(Component comp, Object constraints, int index) {
133
		getContent().add(comp, constraints, index);
134
	}
135
  
136
	/*
137
	 * (non-Javadoc)
138
	 * @see java.awt.Container#add(java.lang.String, java.awt.Component)
139
	 */
140
	public Component add(String name, Component comp) {
141
		return getContent().add(name, comp);
142
	}
143
}
0 144

  
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/progressPanel/LogControl.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.gui.beans.progressPanel;
20
/**
21
 * <code>LogControl</code>. Objeto para un control b?sico de un log. Para a?adir
22
 * y reemplazar la ?ltima l?nea a?adida.
23
 *
24
 * @version 27/03/2007
25
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
26
 */
27
public class LogControl {
28
	String text = "";
29
	
30
	/**
31
	 * A?ade una l?nea al log.
32
	 * @param line
33
	 */
34
	public void addLine(String line) {
35
		if (text.length()>0)
36
			text += "\n";
37
		text += line;
38
	}
39

  
40
	/**
41
	 * Reemplaza la ?ltima l?nea a?adida al log.
42
	 * @param line
43
	 */
44
	public void replaceLastLine(String line) {
45
		int index =  text.lastIndexOf("\n");
46
		if (index<0) index = 0;
47
		text = text.substring(0, index);
48
		addLine(line);
49
	}
50

  
51
	/**
52
	 * Establece el texto completo del log.
53
	 * @param value
54
	 */
55
	public void setText(String value) {
56
		text = value;
57
	}
58
	
59
	/**
60
	 * Devuelve el contenido del log.
61
	 * @return String
62
	 */
63
	public String getText() {
64
		return text;
65
	}
66
}
0 67

  
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/progressPanel/ProgressPanel.java
30 30
import javax.swing.JTextPane;
31 31

  
32 32
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel;
33

  
34 33
/**
35 34
 * <code>ProgressPanel</code>. Muestra una ventana de di?logo para representar
36 35
 * una barra de progreso con su ventana de registro.
......
49 48
	private JProgressBar jProgressBar = null;
50 49
	private JScrollPane jScrollPane = null;
51 50
	private JTextPane jTextPane = null;
52
	private String realText = "";
51
	private LogControl text = new LogControl();
53 52

  
54 53
	/**
55 54
	 * Constructor
56 55
	 */
57 56
	public ProgressPanel() {
58
		// TODO Auto-generated constructor stub
59 57
		initialize();
60 58
	}
61 59

  
......
192 190
		return jTextPane;
193 191
	}
194 192
	
193
	private void updateLog() {
194
		jTextPane.setText(text.getText());
195
	}
196

  
195 197
	public void addLineLog(String line) {
196
		realText = jTextPane.getText();
197
		jTextPane.setText(realText + line + "\n");
198
		
198
		text.addLine(line);
199
		updateLog();
199 200
	}
200 201

  
201 202
	public void replaceLastLineLog(String line) {
202
		jTextPane.setText(realText + line + "\n");
203
		text.replaceLastLine(line);
204
		updateLog();
203 205
	}
204
	
206

  
207
	public void setLog(String value) {
208
		text.setText(value);
209
		updateLog();
210
	}
211

  
205 212
	public int getPercent() {
206 213
		return jProgressBar.getValue();
207 214
	}
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/IncrementableTask/IncrementableTask.java
1
package org.gvsig.gui.beans.IncrementableTask;
2

  
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5
import java.awt.event.WindowAdapter;
6
import java.awt.event.WindowEvent;
7

  
8
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel;
9
import org.gvsig.gui.beans.progressPanel.ProgressPanel;
10

  
11
public class IncrementableTask extends Thread implements ActionListener {
12
	IIncrementable iIncrementable;
13
	ProgressPanel progressPanel = null;
14
	
15
	public IncrementableTask(IIncrementable incrementable) {
16
		iIncrementable = incrementable;
17
	}
18

  
19
	/**
20
	 * Este thread va leyendo el porcentaje hasta que se completa el histograma.
21
	 */
22
	public synchronized void run(){
23
		while(true){
24
			showWindow();
25
			while (iIncrementable.getPercent() < 100){
26
				getProgressPanel().setLabel(iIncrementable.getLabel());
27
				getProgressPanel().setPercent(iIncrementable.getPercent());
28
				getProgressPanel().setTitle(iIncrementable.getTitle());
29
				getProgressPanel().setLog(iIncrementable.getLog());
30
				try {
31
					sleep(100);
32
				} catch (InterruptedException e) {
33
					e.printStackTrace();
34
				}
35
			}
36
			//Cerramos la ventana
37

  
38
			handleClose();
39
			
40
			this.suspend();
41
		}
42
	}
43

  
44
	private void handleClose() {
45
		getProgressPanel().setVisible(false);
46
		getProgressPanel().hide();
47
		progressPanel = null;
48
		System.out.println("Cerrado");
49
	}
50
	/**
51
	 * Muestra la ventana de incremento con el porcentaje de la construcci?n del
52
	 * histograma.
53
	 */
54
	public void showWindow(){
55
		getProgressPanel().setTitle(iIncrementable.getTitle());
56
		getProgressPanel().showLog(false);
57
		getProgressPanel().show();
58
		
59
		if(this.isAlive())
60
			this.resume();
61
		else
62
			this.start();
63
	}
64
	
65
	private ProgressPanel getProgressPanel() {
66
		if (progressPanel == null) {
67
			progressPanel = new ProgressPanel();
68
			progressPanel.getButtonsPanel().addActionListener(this);
69
			progressPanel.addWindowListener( new WindowAdapter() {
70
        public void windowClosing(WindowEvent e)
71
        {
72
          handleClose();
73
        }
74
      });
75
		}
76
		return progressPanel;
77
	}
78

  
79
	public void actionPerformed(ActionEvent e) {
80
		if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "") == 0) {
81
			handleClose();
82
		}
83
	}
84
}
0 85

  
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/IncrementableTask/IIncrementable.java
1
package org.gvsig.gui.beans.IncrementableTask;
2

  
3
public interface IIncrementable {
4
	/**
5
	 * Devuelve el titulo de la ventana IncrementableTask
6
	 * @return String
7
	 */
8
	public String getTitle();
9

  
10
	/**
11
	 * Devuelve el contenido del log de la ventana IncrementableTask
12
	 * @return String
13
	 */
14
	public String getLog();
15

  
16
	/**
17
	 * Devuelve la etiqueta de la ventana IncrementableTask
18
	 * @return String
19
	 */
20
	public String getLabel();
21

  
22
	/**
23
	 * Devuelve el porcentaje de 0 a 100 de la ventana IncrementableTask
24
	 * @return int
25
	 */
26
	public int getPercent();
27
}
0 28

  

Also available in: Unified diff