Revision 26604 tmp/trunk/cliente/WorkSpace_WPSClient/extWPSCallejero/src/es/logex/gvsig/streetsmap/ui/SwingWorker.java

View differences:

SwingWorker.java
1
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2008 Logica Extrema, S.L. 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ibáñez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Logica Extrema, S.L.
34
 *   Edif. Sorolla Center
35
 *   Avgda. De les Corts Valencianes, 158 Of.1007
36
 *   46015 Valencia
37
 *   Spain
38
 *
39
 *   +34 963462375
40
 *   info@logex.es
41
 */
1 42
package es.logex.gvsig.streetsmap.ui;
2 43

  
3 44
import javax.swing.SwingUtilities;
......
9 50
 * instructions on using this class, see:
10 51
 * 
11 52
 * http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
12
 *
53
 * 
13 54
 * Note that the API changed slightly in the 3rd version:
14 55
 * You must now invoke start() on the SwingWorker after
15 56
 * creating it.
16 57
 */
17 58
public abstract class SwingWorker {
59
    
60
    /** The value. */
18 61
    private Object value;  // see getValue(), setValue()
19
    /** 
62
    
63
    /**
20 64
     * Class to maintain reference to current worker thread
21 65
     * under separate synchronization control.
22 66
     */
23 67
    private static class ThreadVar {
68
        
69
        /** The thread. */
24 70
        private Thread thread;
71
        
72
        /**
73
         * Instantiates a new thread var.
74
         * 
75
         * @param t the t
76
         */
25 77
        ThreadVar(Thread t) { thread = t; }
78
        
79
        /**
80
         * Gets the.
81
         * 
82
         * @return the thread
83
         */
26 84
        synchronized Thread get() { return thread; }
85
        
86
        /**
87
         * Clear.
88
         */
27 89
        synchronized void clear() { thread = null; }
28 90
    }
29 91

  
92
    /** The thread var. */
30 93
    private ThreadVar threadVar;
31 94

  
32
    /** 
33
     * Get the value produced by the worker thread, or null if it 
95
    /**
96
     * Get the value produced by the worker thread, or null if it
34 97
     * hasn't been constructed yet.
98
     * 
99
     * @return the value
35 100
     */
36 101
    protected synchronized Object getValue() { 
37 102
        return value; 
38 103
    }
39 104

  
40
    /** 
41
     * Set the value produced by worker thread 
105
    /**
106
     * Set the value produced by worker thread.
107
     * 
108
     * @param x the x
42 109
     */
43 110
    private synchronized void setValue(Object x) { 
44 111
        value = x; 
45 112
    }
46 113

  
47
    /** 
48
     * Compute the value to be returned by the <code>get</code> method. 
114
    /**
115
     * Compute the value to be returned by the <code>get</code> method.
116
     * 
117
     * @return the object
49 118
     */
50 119
    public abstract Object construct();
51 120

  
......
69 138
    }
70 139

  
71 140
    /**
72
     * Return the value created by the <code>construct</code> method.  
141
     * Return the value created by the <code>construct</code> method.
73 142
     * Returns null if either the constructing thread or the current
74 143
     * thread was interrupted before a value was produced.
75 144
     * 

Also available in: Unified diff