File: MainContext.java

package info (click to toggle)
dicomscope 3.6.0-10
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,948 kB
  • sloc: java: 22,911; cpp: 5,959; sh: 266; makefile: 52
file content (408 lines) | stat: -rw-r--r-- 13,641 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
 *
 *  Copyright (C) 1999, Institute for MicroTherapy
 *
 *  This software and supporting documentation were developed by
 *
 *    University of Witten/Herdecke
 *    Department of Radiology and MicroTherapy
 *    Institute for MicroTherapy
 *    Medical computer science
 *    
 *    Universitaetsstrasse 142
 *    44799 Bochum, Germany
 *    
 *    http://www.microtherapy.de/go/cs
 *    mailto:computer.science@microtherapy.de
 *
 *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND THE INSTITUTE MAKES  NO 
 *  WARRANTY REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY
 *  OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES 
 *  OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY 
 *  AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
 *
 *  Author :      $Author: kleber $
 *  Last update : $Date: 2003/09/08 10:08:20 $
 *  Revision :    $Revision: 1.2 $
 *  State:        $State: Exp $
*/


package main;

import J2Ci.*;
import java.io.*;
import java.awt.*;
import java.util.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.color.*;

/**
 * This class manages the context of DICOMscope. 
 * Some global variables of the programm are available by 
 * methods of this class.
 * It implements the singleton pattern.
 * 
 * @author Klaus Kleber
 * @author Andreas Schroeter
 * @since 30.04.1999
 */

public class MainContext extends java.lang.Object
{   
    //import static library
    static
    {
        System.loadLibrary ("jInterface");
    }

    /**
     * The only instance of this class.
     * 
     * @since 30.04.1999
     */
    private static MainContext theInstance = null;    
    
    

     public static Hashtable profiles = new Hashtable();
    
    
     /**
     * True if the hight quality monitor with the dome board is used.
     * 
     * @since 30.04.1999
     */
    public boolean highQualitySystem = false;
    
    
    
    
    /**
    * Application Name
    * 
    * @since 30.04.1999
    */
		
    //String title = new String ("DICOMscope 3.0");
    String title = new String ("DICOMscope 3.6.0");
    
    
    
    public static final String iconPath = "icons/";
    public static  Font logFont;
    
    /**
    * Contains the ColorModel for drawing the images. The ColorModel depends 
    * from the display system. If the display system the low quality system then 
    * a 8 bit IndexColorModel will used. If the display system is the high 
    * quality system 8 Bit ColorModel loaded from de GraphicsConfiguration will be 
    * used.
    *
    * @since 30.04.1999
    */
    ColorModel usedColorModel;
    
    //static Dimension screenSize;
    
    /**
    * Outputstream for log file
    *
    * @since 30.04.1999
    */
    
    
    public static  Hashtable configurationProps;
    jDVInterface dvi;
    
    /**
     * Return the only instance of a MainContext object. If there is no instance 
     * this methode create this instance.
     * <br> 
     * status: tested
     * 
     * @return The only intance of this class.
     * @since 30.04.1999
     */
    public static MainContext instance()
    {
        if (theInstance == null) theInstance = new MainContext();
        return theInstance;
    }

    public static SRCodeList codeList;
    
    /**
     * Constructor. This class implements the singleton pattern. 
     * This constructor should only called from the 
     * instance() methode of this class.
     * 
     * @since 30.04.1999
     * @see MainContext.instance()
     */
    
    private MainContext()
    {
        //System.out.println("MainContext.iconPath " +MainContext.iconPath );
        //Load deviceColorModell
        loadDeviceInformation();
        codeList = new SRCodeList("/usr/share/dcmtk/codes.dic");
    }
    
    
    
    /**
    * Loads and constructs the color model from the  device.
    *
    * @since 30.04.1999
    */
    private void loadDeviceInformation()
    {
            
        //
        GraphicsEnvironment  gr;
        GraphicsDevice gd;
        ColorModel cm;
        GraphicsConfiguration gc;
        
        
        gr = GraphicsEnvironment.getLocalGraphicsEnvironment();
        gd = gr.getDefaultScreenDevice();
        gc = gd.getDefaultConfiguration();
        cm = gc.getColorModel();
        usedColorModel = cm;
       
        
        GrayColorIndex.fillIndexColorModel();
        
        
    }       
    
    
    /**
     * Returns a 8 Bit IndexColorModel
     * 
     * @param A 8 Bit IndexColorModel
     * @since 30.04.1999
     */
    public ColorModel getIndexColorModel()
    {
         return GrayColorIndex.getGrayColorModel();
    }
    
    
    /**
     * Returns the ColorModel used for displaying images. Depends
     * from the system.
     * 
     * @return The ColorModel used for displaying images.
     * @since 30.04.1999
     */
    public ColorModel getUsedColorModel()
    {
        if (highQualitySystem)return usedColorModel;
        else return GrayColorIndex.getGrayColorModel();
    }
    
    
    /**
     * Returns the font for displaying PresentationStateTextObjects.
     * Depends from the system.
     * 
     * @return The  font for displaying PresentationStateTextObjects.
     * @since 30.04.1999
     */
    public Font getFontTextAnnotations()
    {
         return  (Font) configurationProps.get("TextFont");    
    }
    public void initConfiguration(jDVInterface dvi)
    {
        //Browser
        this.dvi = dvi;
		//highQualitySystem = true;
		
        configurationProps= new Hashtable();
	    String fontNameLog =  dvi.getGUIConfigEntry("FONTNAMELOG");
	    String fontSizeLog =  dvi.getGUIConfigEntry("FONTSIZELOG");
	    
        //Fonts
	    String fontSize =  dvi.getGUIConfigEntry("FONTSIZE");
	    String fontName =  dvi.getGUIConfigEntry("FONTNAME");
	    String fontNameText =  dvi.getGUIConfigEntry("FONTNAMETEXT");
	    String fontSizeText =  dvi.getGUIConfigEntry("FONTSIZETEXT");
	    
	    String functionPanelPlacement =  dvi.getGUIConfigEntry("FUNCTIONPANELPLACEMENT");
	    String paintPanelPlacement =  dvi.getGUIConfigEntry("PAINTPANELPLACEMENT");
	    
	    String navigationPanelOn =  dvi.getGUIConfigEntry("NAVIGATIONPANELON");
	    if (navigationPanelOn == null)configurationProps.put("NavigationPanelOn", new Boolean(true));
	    else configurationProps.put("NavigationPanelOn", new Boolean(navigationPanelOn));
	    
	    String signWarning = dvi.getGUIConfigEntry("SIGNWARNING");
	    if (signWarning == null)signWarning = "true";
	    configurationProps.put("SignWarning",new Boolean(signWarning));
	    
	    
	    String autoUpdateStudyBrowser = dvi.getGUIConfigEntry("AUTOUPDATESTUDYBROWSER");
	    if (autoUpdateStudyBrowser == null)autoUpdateStudyBrowser = "true";
	    configurationProps.put("AutoUpdateStudyBrowser",new Boolean(autoUpdateStudyBrowser));
	    String backgroundColor = dvi.getGUIConfigEntry("BACKGROUNDCOLOR");
	    if (backgroundColor!= null) 
	    {
	        try
	        {
	            StringTokenizer st = new StringTokenizer(backgroundColor, "\\");
	            Color color = new Color(new Integer(st.nextToken()).intValue(),
	                                              new Integer(st.nextToken()).intValue(),
	                                              new Integer(st.nextToken()).intValue());
	            configurationProps.put("BrowserBackgroundColor",color);
	                                    
	            
	        }
	        catch (NoSuchElementException  e)
	        {
	            System.out.println("colorn: ");
	            
	        }
	    }
	    
	    
	    
	    if (fontName == null) fontName = "SansSerif";
	    if (fontNameText == null) fontNameText = "SansSerif";
	    if (fontNameLog == null) fontNameLog = "Monospaced";
	    
	    if (dvi.getGUIConfigEntryBool("HIGHRESOLUTIONGRAPHICS", false) == false)
	    {
	        //Default settings fpr font
	        if (fontSize == null) fontSize = "12";
	        if (fontSizeText == null) fontSizeText = "16";
	        if (fontSizeLog == null) fontSizeLog = "12";
	        
	        //Default settings for function panel
	        if (functionPanelPlacement == null)configurationProps.put("FunctionPanelPlacement", "East");
	        else configurationProps.put("FunctionPanelPlacement", functionPanelPlacement);
	        
	        if (paintPanelPlacement == null)configurationProps.put("PaintPanelPlacement", "Integrated");
	        else configurationProps.put("PaintPanelPlacement", paintPanelPlacement);
	        
	        configurationProps.put("ProcessingPanelOn",  new Boolean(true));
	        configurationProps.put("PSPanelOn",  new Boolean(false));
	        
	        
	        configurationProps.put("HighEndSystem", new Boolean(false));
	        
	    }
	    else
	    {
	        if (fontSize == null) fontSize = "30";
	        if (fontSizeText == null) fontSizeText = "48";
	        if (fontSizeLog == null) fontSizeLog = "20";
	        
	        //Default settings for function panel
	        if (functionPanelPlacement == null)configurationProps.put("FunctionPanelPlacement", "North");
	        else configurationProps.put("FunctionPanelPlacement", functionPanelPlacement);
	        
	        if (paintPanelPlacement == null)configurationProps.put("PaintPanelPlacement", "Integrated");
	        else configurationProps.put("PaintPanelPlacement", paintPanelPlacement);
	        configurationProps.put("ProcessingPanelOn",  new Boolean(true));
	        configurationProps.put("PSPanelOn",  new Boolean(false));
	        
	        
	        configurationProps.put("HighEndSystem", new Boolean(true));
	        highQualitySystem = true;
	    }
	    
	    
	    
	    
	    configurationProps.put("GUIFont", new Font(fontName,0,new Integer(fontSize).intValue()));
	    configurationProps.put("TextFont", new Font(fontNameText,0,new Integer(fontSizeText).intValue()));
	    configurationProps.put("LogFont", new Font(fontNameLog,0,new Integer(fontSizeLog).intValue()));
	    logFont = new Font(fontNameLog,0,new Integer(fontSizeLog).intValue());
	    
	    //StudyBrowser
	    configurationProps.put("UID", new Boolean(false));
	    
	    configurationProps.put("Description",  new Boolean(true));
	    configurationProps.put("PatientInfo", new Boolean(true));
	    configurationProps.put("Modality",  new Boolean(true));
	    configurationProps.put("DateTime",  new Boolean(false));
	    configurationProps.put("NewItems",  new Boolean(true));
	    configurationProps.put("Filename",  new Boolean(false));
	    configurationProps.put("Label",  new Boolean(true));
	    configurationProps.put("ButtonOn",  new Boolean(false));
	    configurationProps.put("WarnUnsignedSrDouments",  new Boolean(false));
	    //Viewer
	    String warnUnsignedSrDouments = dvi.getGUIConfigEntry("WARNUNSIGNEDOBJECTSINSR");
	    if (warnUnsignedSrDouments == null)warnUnsignedSrDouments = "true";
	    configurationProps.put("WarnUnsignedSrDouments",new Boolean(warnUnsignedSrDouments));
	    
	    
	        
	    //Settings for TabbedPanel
	    String tabPlacement =  dvi.getGUIConfigEntry("TABPLACEMENT");
	    if (tabPlacement == null)configurationProps.put("TabbedPlacement", "1");
	    else 
	    {
	        if (tabPlacement.equals("North") ) configurationProps.put("TabbedPlacement", "1");
	        if (tabPlacement.equals("East") ) configurationProps.put("TabbedPlacement", "2");
	        if (tabPlacement.equals("South") ) configurationProps.put("TabbedPlacement", "3");
	        if (tabPlacement.equals("West") ) configurationProps.put("TabbedPlacement", "4");
	    }
	    
	    jDoubleByRef ambientValue = new jDoubleByRef();   
	    if (dvi.getAmbientLightValue(ambientValue) == 0)configurationProps.put("AmbientLight", new Double(ambientValue.value).toString());
	    
	    
	    double monitorHeight = dvi.getMonitorPixelHeight();
	    double monitorWidth = dvi.getMonitorPixelWidth();
	    
	    if ( monitorHeight == 0d) monitorHeight = 1d;
	    if ( monitorWidth == 0d) monitorWidth = 1d;
	    configurationProps.put("PixelSizeX",  new Double(monitorWidth).toString());
	    configurationProps.put("PixelSizeY",  new Double(monitorHeight).toString());
        
        configurationProps.put("Title", title);
        
        
	
		if (highQualitySystem)dvi.writeLogMessage(jDVPSLogMessageLevel.DVPSM_informational,"GUI","Very High Resolution Graphics" );
		else dvi.writeLogMessage(jDVPSLogMessageLevel.DVPSM_informational,"GUI","Standard Resolution Graphics" );
	    
        Hashtable srProfile = (Hashtable)configurationProps.clone();   
	    srProfile.put("FunctionPanelPlacement", "None");
	    srProfile.put("PaintPanelPlacement", "Toolbar");
	    srProfile.put("ProcessingPanelOn",  new Boolean(true));
	    srProfile.put("PSPanelOn",  new Boolean(false));
        Hashtable imageProfile = (Hashtable)configurationProps.clone();   
	    imageProfile.put("FunctionPanelPlacement", "East");
	    imageProfile.put("PaintPanelPlacement", "Integrated");
	    imageProfile.put("ProcessingPanelOn",  new Boolean(true));
	    imageProfile.put("PSPanelOn",  new Boolean(true));
	    
          profiles.put("Configuration Profile",(Hashtable)configurationProps.clone());
          profiles.put("Image Profile",imageProfile);
          profiles.put("Structured Report Profile",srProfile);
        
    }
    public Hashtable getConfiguration()
    {
        return configurationProps;
    }
}//FontRenderContext

/*
 *  CVS Log
 *  $Log: MainContext.java,v $
 *  Revision 1.2  2003/09/08 10:08:20  kleber
 *  New version number
 *
 *  Revision 1.1.1.1  2001/06/06 10:32:30  kleber
 *  Init commit for DICOMscope 3.5
 *  Create new CVS
 *
*/