|
Lines 13-18
Link Here
|
| 13 |
|
13 |
|
| 14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
| 15 |
import java.io.InputStream; |
15 |
import java.io.InputStream; |
|
|
16 |
import java.lang.ref.WeakReference; |
| 16 |
import java.text.MessageFormat; |
17 |
import java.text.MessageFormat; |
| 17 |
import java.util.*; |
18 |
import java.util.*; |
| 18 |
import java.util.List; |
19 |
import java.util.List; |
|
Lines 128-133
Link Here
|
| 128 |
= Display.class.getName() + "#appName"; |
129 |
= Display.class.getName() + "#appName"; |
| 129 |
private static final String APP_VERSION |
130 |
private static final String APP_VERSION |
| 130 |
= Display.class.getName() + "#appVersion"; |
131 |
= Display.class.getName() + "#appVersion"; |
|
|
132 |
private static final String DISPLAYS |
| 133 |
= Display.class.getName() + "#displays"; |
| 131 |
|
134 |
|
| 132 |
|
135 |
|
| 133 |
/* Package Name */ |
136 |
/* Package Name */ |
|
Lines 233-238
Link Here
|
| 233 |
SWT.error( SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]" ); |
236 |
SWT.error( SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]" ); |
| 234 |
} |
237 |
} |
| 235 |
RWTLifeCycle.setSessionDisplay( this ); |
238 |
RWTLifeCycle.setSessionDisplay( this ); |
|
|
239 |
register( this); |
| 236 |
shells = new ArrayList(); |
240 |
shells = new ArrayList(); |
| 237 |
readInitialBounds(); |
241 |
readInitialBounds(); |
| 238 |
readScrollBarSize(); |
242 |
readScrollBarSize(); |
|
Lines 690-695
Link Here
|
| 690 |
// TODO [rh] zero fields |
694 |
// TODO [rh] zero fields |
| 691 |
} |
695 |
} |
| 692 |
|
696 |
|
|
|
697 |
protected void destroy () { |
| 698 |
deregister( this ); |
| 699 |
} |
| 700 |
|
| 693 |
private void sendDisposeEvent() { |
701 |
private void sendDisposeEvent() { |
| 694 |
Event event = new Event(); |
702 |
Event event = new Event(); |
| 695 |
event.display = this; |
703 |
event.display = this; |
|
Lines 1880-1885
Link Here
|
| 1880 |
session.setAttribute( APP_VERSION, version ); |
1888 |
session.setAttribute( APP_VERSION, version ); |
| 1881 |
} |
1889 |
} |
| 1882 |
|
1890 |
|
|
|
1891 |
/** |
| 1892 |
* Returns the display which the given thread is the |
| 1893 |
* user-interface thread for, or null if the given thread |
| 1894 |
* is not a user-interface thread for any display. Specifying |
| 1895 |
* <code>null</code> as the thread will return <code>null</code> |
| 1896 |
* for the display. |
| 1897 |
* |
| 1898 |
* @param thread the user-interface thread |
| 1899 |
* @return the display for the given thread |
| 1900 |
* |
| 1901 |
* @since 1.3 |
| 1902 |
*/ |
| 1903 |
public static Display findDisplay( final Thread thread ) { |
| 1904 |
synchronized( Device.class ) { |
| 1905 |
Display result = null; |
| 1906 |
ISessionStore session = ContextProvider.getSession(); |
| 1907 |
WeakReference[] displaysRef |
| 1908 |
= ( WeakReference[] )session.getAttribute( DISPLAYS ); |
| 1909 |
if( displaysRef != null ) { |
| 1910 |
for( int i = 0; i < displaysRef.length && result == null; i++ ) { |
| 1911 |
WeakReference currentRef = displaysRef[ i ]; |
| 1912 |
if( currentRef != null ) { |
| 1913 |
Display display = ( Display )currentRef.get(); |
| 1914 |
if( display != null && display.thread == thread ) { |
| 1915 |
result = display; |
| 1916 |
} |
| 1917 |
} |
| 1918 |
} |
| 1919 |
} |
| 1920 |
return result; |
| 1921 |
} |
| 1922 |
} |
| 1923 |
|
| 1924 |
private static void register( final Display display ) { |
| 1925 |
synchronized( Device.class ) { |
| 1926 |
ISessionStore session = ContextProvider.getSession(); |
| 1927 |
WeakReference[] displaysRef |
| 1928 |
= ( WeakReference[] )session.getAttribute( DISPLAYS ); |
| 1929 |
if( displaysRef == null ) { |
| 1930 |
displaysRef = new WeakReference[ 4 ]; |
| 1931 |
} |
| 1932 |
boolean registered = false; |
| 1933 |
for( int i = 0; i < displaysRef.length && !registered; i++ ) { |
| 1934 |
if( displaysRef[ i ] == null ) { |
| 1935 |
displaysRef[ i ] = new WeakReference( display ); |
| 1936 |
registered = true; |
| 1937 |
} |
| 1938 |
} |
| 1939 |
if( !registered ) { |
| 1940 |
WeakReference[] newDisplaysRef |
| 1941 |
= new WeakReference[ displaysRef.length + 4 ]; |
| 1942 |
System.arraycopy( displaysRef, |
| 1943 |
0, |
| 1944 |
newDisplaysRef, |
| 1945 |
0, |
| 1946 |
displaysRef.length ); |
| 1947 |
newDisplaysRef[ displaysRef.length ] = new WeakReference( display ); |
| 1948 |
displaysRef = newDisplaysRef; |
| 1949 |
} |
| 1950 |
session.setAttribute( DISPLAYS, displaysRef ); |
| 1951 |
} |
| 1952 |
} |
| 1953 |
|
| 1954 |
private static void deregister( final Display display ) { |
| 1955 |
synchronized( Device.class ) { |
| 1956 |
ISessionStore session = ContextProvider.getSession(); |
| 1957 |
WeakReference[] displaysRef |
| 1958 |
= ( WeakReference[] )session.getAttribute( DISPLAYS ); |
| 1959 |
if( displaysRef != null ) { |
| 1960 |
boolean empty = true; |
| 1961 |
for( int i = 0; i < displaysRef.length; i++ ) { |
| 1962 |
WeakReference currentRef = displaysRef[ i ]; |
| 1963 |
if( currentRef != null && display == currentRef.get() ) { |
| 1964 |
displaysRef[ i ] = null; |
| 1965 |
} |
| 1966 |
if( displaysRef[ i ] != null ) { |
| 1967 |
empty = false; |
| 1968 |
} |
| 1969 |
} |
| 1970 |
if( empty ) { |
| 1971 |
displaysRef = null; |
| 1972 |
} |
| 1973 |
} |
| 1974 |
session.setAttribute( DISPLAYS, displaysRef ); |
| 1975 |
} |
| 1976 |
} |
| 1977 |
|
| 1883 |
///////////////////// |
1978 |
///////////////////// |
| 1884 |
// Consistency checks |
1979 |
// Consistency checks |
| 1885 |
|
1980 |
|