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 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
|
/*
*
* 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:29 $
* Revision : $Revision: 1.1.1.1 $
* State: $State: Exp $
*/
package dicomPrint;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import main.*;
import javax.swing.border.*;
import J2Ci.*;
/**
* This class contains the GUI for a page of a print job.
* This page can have the orientation portrait ( portrait = true)
* or landscape (portrait = false) and will be drawn in a JPanel.
* The page have a table of PrintImagePreviews.
* @author Klaus Kleber
*/
public class PreviewPanel extends JPanel
{
/**
* Contains the PrintImagePreview of this page
*/
private PrintImagePreview[] printImagePreviewList;
/**
* Contains the current jDVPSStoredPrint
*/
private jDVPSStoredPrint storedPrint;
/**
* Contains the x -coordiante for the page
*/
private int x;
/**
* Contains the y - coordinate for the page
*/
private int y;
/**
* Contains the height of the page
*/
private int h;
/**
* Contains the width of the page
*/
private int w;
/**
* Width of a film box
*/
private double filmBoxWidth ;
/**
* Height of a film box
*/
private double filmBoxHeight;
/**
* Default width of a film box
*/
private double defaultFilmBoxWidth = 11;
/**
* Default height of a film box
*/
private double defaultFilmBoxHeight = 14;
/**
* DVI Interface
*/
private jDVInterface dvi;
/**
* Contains the current page
*/
private JPanel page = new JPanel();
/**
* if true the page will be portrait, esle landscape
*/
private boolean portrait = true;
/**
* Contains the minimum border size
*/
private int border = 10;
/**
* Conatins the distance between the PrintImagePreview
*/
private int gaps = 5;
/**
* Contains the current number of cols
*/
private int cols = 1;
/**
* Contains the current number of rows
*/
private int rows = 1;
/**
* Contains the current MouseHandler.
*/
private PreviewMouseHandler previewMouseHandler;
/**
* Contains the current size for the PreviewPanel
*/
private Dimension size = new Dimension();
/**
* Default value for the empty image
*/
private Color defaultEmptyImageColor = Color.black;
/**
* Contains the color of the film
*/
private Color emptyImageColor = defaultEmptyImageColor;
/**
* Default value for the film
*/
private Color defaultFilmColor = Color.black;
/**
* Contains the color of the film
*/
private Color filmColor = defaultFilmColor;
/**
* true, if last page should be displayed, else the first page will be displayed;
*/
private boolean showLastPage = false;
/**
* True if the PrintImagePreview should displayed as Hardcopy.
* If false the PrintImagePreview will displayed as Softcopy
*/
private boolean printLUT = true;
private boolean notifyBrowser = false;
/**
* Constructor.
* @param previewMouseHandler Contains the current MouseHandler.
* @param cols Contains the number of cols.
* @param rows Contains the number of rows.
* @param storedPrint Contains the current jDVPSStoredPrint Object.
* @param dvi Contains the current jDVInterface Object.
*/
public PreviewPanel(PreviewMouseHandler previewMouseHandler, int cols, int rows,jDVPSStoredPrint storedPrint, jDVInterface dvi)
{
this.storedPrint = storedPrint;
this.dvi = dvi;
setLayout(null);
//setBackground(backgroundColor);
this.previewMouseHandler= previewMouseHandler;
this.cols = cols;
this.rows = rows;
filmBoxWidth = defaultFilmBoxWidth;
filmBoxHeight = defaultFilmBoxHeight;
}
/**
* Paints the component in the specified Graphics object
* @param g Graphics
*/
public synchronized void paintComponent(Graphics g)
{
if (! size.equals(getSize()))
{
size = getSize();
calculatePage();
}
page.validate();
super.paintComponent(g);
}
/**
* Calculates the the page
*/
private void calculatePage()
{
//Removes all obejcts
removeAll();
page.removeAll();
//Calculates the sizes for portrait
if (portrait)
{
h = size.height-border;
w = (int)(h*(filmBoxWidth/filmBoxHeight));
if (w > size.width-border)
{
double scaling = (double)w/(double)(size.width-border);
h = (int)(h/scaling);
w = size.width-border;
}
}
//Calculates the size for landscape
else
{
w = size.width-border;
h = (int)(w*(filmBoxWidth/filmBoxHeight));
if (h > size.height-border)
{
double scaling = (double)h/(double)(size.height-border);
w = (int)(w/scaling);
h= size.height-border;
}
}
//Sets the size of the page
page.setSize(new Dimension(w, h));
//Sets the location of the page
x = (size.width-w)/2;
y = (size.height-h)/2;
page.setLocation(x,y);
page.setBackground(filmColor);
page.setBorder(new EmptyBorder(gaps, gaps,gaps,gaps));
page.setLayout(new GridLayout(rows,cols,gaps,gaps));
printImagePreviewList = new PrintImagePreview[rows*cols];
int numberOfVisible = Math.min(rows*cols, storedPrint.getNumberOfImages());
int pagesInJob = storedPrint.getNumberOfImages()/printImagePreviewList.length;
if (storedPrint.getNumberOfImages()%printImagePreviewList.length>0)pagesInJob++;
int offset = 0;
for (int i = 0; i <printImagePreviewList.length; i++)
{
PrintImagePreview im = new PrintImagePreview(offset+i,emptyImageColor, filmColor, dvi, printLUT);
if ((i <numberOfVisible)|| ((numberOfVisible ==0)&& (storedPrint.getNumberOfImages()!= 0)))
{
im.setReferToImage();
im.setParameter(havePrintSettings(offset+i));
}
printImagePreviewList[i] = im;
im.addMouseListener(previewMouseHandler);
page.add(im);
}
if (notifyBrowser)
{
if ((printImagePreviewList!=null) &&(printImagePreviewList.length >0))
{
//Zero ist the last printed Componenet
//Bad hack
printImagePreviewList[0].notifyBrowser = true;
}
notifyBrowser = false;
}
add(page);
}
/**
* Sets the orentation of the page. If portrait = true the page will be displayed in
* portrait else in landscape.
*
* @param portrait If portrait = true the page will be displayed in
* portrait else in landscape.
*/
public synchronized void setOrientation(boolean portrait)
{
if (this.portrait != portrait)
{
this.portrait = portrait;
calculatePage();
repaint();
page.updateUI();
}
}
/**
* Sets rows and cols of the page
* @param rows Number of cols of the page
* @param cols Number of cols of the page
*/
public synchronized void setRowsCols(int rows, int cols)
{
this.cols = cols;
this.rows = rows;
calculatePage();
repaint();
page.updateUI();
}
/**
* Updates the Print Preview
*/
public synchronized void updatePrintPreview()
{
calculatePage();
repaint();
page.updateUI();
}
/**
* Updates the Print Preview
*/
public synchronized void instertPrint()
{
if (printImagePreviewList== null)
{
calculatePage();
}
else
{
int index = storedPrint.getNumberOfImages();
if (index<= rows*cols)
{
PrintImagePreview im = printImagePreviewList[index-1];
im.setReferToImage();
im.setParameter(havePrintSettings(index-1));
}
}
repaint();
page.updateUI();
}
/**
* True if the PrintImagePreview should displayed as Hardcopy.
* If false the PrintImagePreview will displayed as Softcopy
*/
public void setPrintLUT(boolean printLUT)
{
this.printLUT = printLUT;
}
/**
* Updates the Print Preview.
*@param storedPrint
* @param portrait
* @param rows Number of cols of the page
* @param cols Number of cols of the page
*/
public synchronized void updatePrintPreview( jDVPSStoredPrint storedPrint, boolean portrait, int rows, int cols)
{
this.storedPrint = storedPrint;
this.portrait = portrait;
this.rows = rows;
this.cols = cols;
notifyBrowser = true;
calculatePage();
repaint();
page.updateUI();
}
/**
* Sets the film size.
* @param filmBoxWidth width of the film box.
* @param filmBoxHeight height of the film box.
*/
public void setFilmSize(double filmBoxWidth, double filmBoxHeight)
{
this.filmBoxHeight = filmBoxHeight;
this.filmBoxWidth = filmBoxWidth;
updatePrintPreview();
}
/**
* Sets the film size of the default value.
*/
public void setDefaultFilmSize()
{
filmBoxWidth = defaultFilmBoxWidth;
filmBoxHeight = defaultFilmBoxHeight;
updatePrintPreview();
}
/**
* Sets the color of the film
*/
public void setFilmColor(int grayValue)
{
if (grayValue == -1) filmColor = defaultFilmColor;
else filmColor = new Color(grayValue, grayValue, grayValue);
updatePrintPreview();
}
/**
* Sets the film box color and the empty image color without any update. Only gray colors can be set by a single
* gray color value.
* @param fc Gray color value of the film box.
* @param eic Gray color value of empfy image boxes
*/
public void setFilmAndEmptyImageColorWithoutUpdate(int fc, int eic)
{
if (fc == -1) filmColor = defaultFilmColor;
else filmColor = new Color(fc, fc, fc);
if (eic == -1) emptyImageColor = defaultEmptyImageColor;
else emptyImageColor = new Color(eic, eic, eic);
}
/**
* Sets the film box color and the empty image color. Only gray colors can be set by a single
* gray color value.
* @param fc Gray color value of the film box.
* @param eic Gray color value of empfy image boxes
*/
public void setFilmAndEmptyImageColor(int fc, int eic)
{
if (fc == -1) filmColor = defaultFilmColor;
else filmColor = new Color(fc, fc, fc);
if (eic == -1) emptyImageColor = defaultEmptyImageColor;
else emptyImageColor = new Color(eic, eic, eic);
updatePrintPreview();
}
/**
* Sets the color of the film to the default value (black).
*/
public void setDefaultFilmColor()
{
filmColor = defaultFilmColor;
updatePrintPreview();
}
/**
* Sets the color of the film. Only gray colors can be set by a single
* gray color value.
* @param grayValue
*/
public void setEmptyImageColor(int grayValue)
{
if (grayValue == -1) emptyImageColor = defaultEmptyImageColor;
else emptyImageColor = new Color(grayValue, grayValue, grayValue);
updatePrintPreview();
}
/**
* Sets the color of the film to the default value (black)
*/
public void setDefaultEmptyImageColor()
{
emptyImageColor = defaultEmptyImageColor;
updatePrintPreview();
}
/**
* Sets a new jDVPSStoredPrint
* @param storedPrint New jDVPSStoredPrint.
*/
public void setStoredPrint(jDVPSStoredPrint storedPrint)
{
this.storedPrint = storedPrint;
}
/**
* Check if the image with the specified index have his own print settings
* @param index Index of the image
* @return true if the image has his own print settings
*/
public boolean havePrintSettings(int index)
{
if (index <= storedPrint.getNumberOfImages())
{
if ( (storedPrint.getImageConfigurationInformation(index) ==null)&&
(storedPrint.getImageSmoothingType(index)== null)&&
(storedPrint.getImageMagnificationType(index)== null)) return false;
else return true;
}
return false;
}
}
/*
* CVS Log
* $Log: PreviewPanel.java,v $
* Revision 1.1.1.1 2001/06/06 10:32:29 kleber
* Init commit for DICOMscope 3.5
* Create new CVS
*
*/
|