File: MainImageViewerPanel.java

package info (click to toggle)
dicomscope 3.6.0-28
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,256 kB
  • sloc: java: 22,911; cpp: 5,957; sh: 270; makefile: 45
file content (379 lines) | stat: -rw-r--r-- 11,870 bytes parent folder | download | duplicates (9)
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
/*
 *
 *  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: 2001/06/06 10:32:30 $
 *  Revision :    $Revision: 1.1.1.1 $
 *  State:        $State: Exp $
*/

package viewer.gui;
import viewer.sr.*;
import java.awt.*;
import java.awt.image.*;

import javax.swing.border.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

import viewer.main.*;
import viewer.presentation.*;
import viewer.controller.*;
import viewer.paint.*;
import main.*;
import jToolkit.gui.*;
import J2Ci.*;

/**
* This class contains the main panel of the image viewer. All other 
* components are integrated in this panel.
* 
* @author Klaus Kleber
* @since 30.04.1999
*/
public class MainImageViewerPanel extends JPanel implements MainListener
{

    
    public JFrame parent;
    
	/**
	 * @since 30.04.1999
	 */
	public ScreenImageHandler screenImageHandler;

    private ScrollListener scrollListener = new ScrollListener();
    SRViewPanel srViewPanel;
    SREditPanel srEditPanel;
    private FunctionPanel functionPanel;
    boolean stackPanelOn = false;
    
    boolean srPanelOn = false;
    
    private String functionPanelOrientation = BorderLayout.NORTH;
    private JPanel main = new JPanel();
    /**
     * Contains the parentFrame of this Panel
     * 
     * @since 30.04.1999
     */
     JScrollBar heightScrollbar;
     JScrollBar widthScrollbar;
     ImageCanvas imageCanvas;
     private StackFunctionPanel stackFunctionPanel = new StackFunctionPanel();
        JSplitPane splitPane = new JSplitPane();
	JPanel scroll = new JPanel();
    /**
     * Constructs a new object.
     * 
     * @param presentationStateGraphicsHandler Contains the current PresentationStateGraphicsHandler.
     * @param parentFrame Contains the parent frame of this Panel
     * @param sl Contains reference of a status bar
     * @since 30.04.1999
     */
    public  MainImageViewerPanel(PresentationStateGraphicsHandler presentationStateGraphicsHandler,Hashtable config, JFrame parent)
    {
         super();
         this.parent = parent;
           setBackground(Color.black);
		   
		   Controller.instance().addMainListener(this);
		   //Init screenImageHandler
		   screenImageHandler = new ScreenImageHandler(this,presentationStateGraphicsHandler, config);
		   srViewPanel = new SRViewPanel(presentationStateGraphicsHandler.dvi,this);
		   srEditPanel = new SREditPanel(presentationStateGraphicsHandler.dvi,this);
		   
		   setBackground(Color.lightGray);
		   setLayout(new BorderLayout(5,5));
           //setFont(MainContext.instance().getUsedFont());
	       
            
            scroll.setLayout(new BorderLayout());
            heightScrollbar = new JScrollBar(JScrollBar.VERTICAL);
            scroll.add(heightScrollbar, BorderLayout.EAST);
            heightScrollbar.setName("height");
            heightScrollbar.addAdjustmentListener(scrollListener);
            widthScrollbar = new JScrollBar(JScrollBar.HORIZONTAL);
            widthScrollbar.setName("width");
            widthScrollbar.addAdjustmentListener(scrollListener);
            scroll.setBorder (new TitledBorder("Image Viewer"));
            scroll.add(widthScrollbar, BorderLayout.SOUTH);
            imageCanvas = new ImageCanvas(screenImageHandler);
             scroll.add(imageCanvas,BorderLayout.CENTER);
            
            main.setLayout(new BorderLayout());
            main.add(scroll,BorderLayout.CENTER);
            splitPane.setRightComponent(srViewPanel);
            splitPane.setOneTouchExpandable(true);
            //splitPane.setLeftComponent(main);
            //add(splitPane, BorderLayout.CENTER);
            add(main, BorderLayout.CENTER);
            int width = parent.getSize().width;
            splitPane.setDividerLocation(width/2);
            
            functionPanel = new FunctionPanel();
           
           setConfiguration(config, true);
           
           //setEnabled(false, this);
    
    }
    public void setNewScrollbarValues(int width,int height, Point values)
    {
        setListeners(false);
        widthScrollbar.setMaximum(width);
        heightScrollbar.setMaximum(height);
        widthScrollbar.setValue(values.x);
        heightScrollbar.setValue(values.y);
        setListeners(true);
    }
    public void setListeners(boolean set)
    {
        if (set)
        {
            heightScrollbar.addAdjustmentListener(scrollListener);
            widthScrollbar.addAdjustmentListener(scrollListener);
        } 
        else
        {
            heightScrollbar.removeAdjustmentListener(scrollListener);
            widthScrollbar.removeAdjustmentListener(scrollListener);
        }
    }

    /**
     * Returns the ImageCanvas which contains the GUI of the image.
     * 
     * @return The imageCanvas which contains the image
     * @since 30.04.1999
     */
    public ImageCanvas getImageCanvas()
    {
        return imageCanvas;
    }
    
	public boolean processEvent (DSEvent e)
	{
	    if (e instanceof ChangeOptionsEvent)
	    {
                setConfiguration(((ChangeOptionsEvent)e).getConfig(), false);
	    }
	    if (e instanceof ImageActionEvent)
	    {
	        ImageActionEvent  ima = (ImageActionEvent)e;
	        if (ima.type == ImageActionEvent.ACTION_SETNEWIMAGE)
	        {
	            if (ima.numberOfFrames > 1 || ima.numberOfImages > 1)
	            {
                    if (!stackPanelOn)
                    {
                        main.add(stackFunctionPanel, BorderLayout.NORTH);
                        stackPanelOn = true;
                    }
                }
                else
                {
                    if (stackPanelOn)
                    {
                        main.remove(stackFunctionPanel);
                        stackPanelOn = false;
                    }
                            
                }
	            
	        }
	        
	        if (ima.type == ImageActionEvent.ACTION_SETNEW_SR)
	        {
	            setSRPanel(true);
	            removeEditSR();
	            screenImageHandler.clear();
	            srViewPanel.setNewSR();
	            
	        }
	        if (ima.type == ImageActionEvent.ACTION_COMPOSITE_SR)
	        {
	            removeEditSR();
	            screenImageHandler.clear();
	            srViewPanel.setNewCompositeSR();
	            
	        }
	        
	        return false;
	    }
	    return false;
	}
	
	
	
	public void setConfiguration(Hashtable config, boolean init)
	{
        String paintPanelPlacement=null;
        if (config.containsKey("PaintPanelPlacement")) paintPanelPlacement  = (String)config.get("SeparateImagePanelPlacement");
        if (!functionPanel.imagePanelOrientation.equals("None")) remove (functionPanel.paintPanel);
        if (config.containsKey("FunctionPanelPlacement")) 
        {
            if (!init) 
            {   
                main.remove(functionPanel);
            }
            String orient = (String)config.get("FunctionPanelPlacement");
            if (!orient.equals("None")) 
            {
                functionPanel.setConfiguration(config,orient);
                if (orient.equals(BorderLayout.EAST)) 
                {
                    main.add(functionPanel,BorderLayout.EAST);
                }
                else add(functionPanel,orient);
            }
            if (!functionPanel.imagePanelOrientation.equals("None"))add(functionPanel.paintPanel,functionPanel.imagePanelOrientation);
            
	}
	//config.put("NavigationPanelOn", new Boolean(true));
       /*
        if (config.containsKey("NavigationPanelOn")) 
        {
            if (((Boolean)(config.get("NavigationPanelOn"))).booleanValue())
            {
                if (!stackPanelOn)
                {
                    main.add(stackFunctionPanel, BorderLayout.NORTH);
                    stackPanelOn = true;
                }
            }
            else
            {
                if (stackPanelOn)
                {
                    main.remove(stackFunctionPanel);
                    stackPanelOn = false;
                }
                
            }
        }
        */
        updateUI();
    }
    
    public class ScrollListener implements AdjustmentListener
    {
        public void adjustmentValueChanged(AdjustmentEvent e)
        {  
            JScrollBar sb = (JScrollBar)e.getSource();
            if (sb.getName().equals("width"))screenImageHandler.setNewImagePartWidth(e.getValue());
            else screenImageHandler.setNewImagePartHeight(e.getValue());
        }
    }

        public static void setEnabled(boolean flag, Container container)
        {
            if (container!= null)
            {
                container.setEnabled(flag);
                int count = container.getComponentCount(); 
                for (int i = 0; i < count ; i++)
                {
                    Component c = container.getComponent(i);
                    if (c instanceof Container) setEnabled(flag, (Container) c);
                    else c.setEnabled(flag);
                }
                
            }
        }
    public void enabledImageView(boolean flag)
    {
        setEnabled(flag, functionPanel);
        setEnabled(flag, stackFunctionPanel);
        setEnabled(flag, scroll);
    }
    public void addEditSR(boolean hackerMode)
    {
        
        if (splitPane.getRightComponent() != srEditPanel)
        {
            int dividerLocation = splitPane.getDividerLocation();
            splitPane.remove(splitPane.getRightComponent());
            splitPane.setRightComponent(srEditPanel);
            splitPane.setDividerLocation(dividerLocation);
            srEditPanel.update(hackerMode);
            
        }
    }
   
    public void editSRClose()
    {
        removeEditSR();
        srViewPanel.setChangedSR();
    }
   
    public void removeEditSR()
    {
        if (splitPane.getRightComponent() == srEditPanel)
        {
            int dividerLocation = splitPane.getDividerLocation();
            splitPane.remove(srEditPanel);
            splitPane.setRightComponent(srViewPanel);
            splitPane.setDividerLocation(dividerLocation);
        }
    }
    public void setSRPanel (boolean enabled)
    {
        if (enabled)
        {
            if(srPanelOn)return;
            else
            {
                remove(main);
                splitPane.setLeftComponent(main);
                add(splitPane, BorderLayout.CENTER);
                splitPane.setRightComponent(srViewPanel);
                int width = parent.getSize().width;
                splitPane.setDividerLocation(width/2);
                
            }
        }
        else
        {
            if (!srPanelOn) return;
            else
           {
                splitPane.remove(main);
                remove(splitPane);
                add(main, BorderLayout.CENTER);
            
            }
        }
        updateUI();
    }
}

/*
 *  CVS Log
 *  $Log: MainImageViewerPanel.java,v $
 *  Revision 1.1.1.1  2001/06/06 10:32:30  kleber
 *  Init commit for DICOMscope 3.5
 *  Create new CVS
 *
*/