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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
|
/*
*
* 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.sr;
import viewer.gui.*;
import java.util.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import de.microtherapy.tools.text.document.dicom.*;
import main.*;
import J2Ci.*;
/**
* This class contains the GUI vizualizing a Dicom Structured Report
* as an HTML document.
*
* @author Klaus Kleber
* @since 08.11.2000
*/
public class SRViewPanel extends JPanel implements HyperlinkListener
{
/**
* Contains the names of the loaded SR Objects.
*/
private JComboBox loadedSRNamesBox;
/**
* ActionListener for the loadedSRNamesBox
*/
private NameBoxActionListener nameBoxActionListener= new NameBoxActionListener();
/**
* The loaded SR Objects will be cached in this object
*/
private Vector cachedObjects = new Vector();
/**
* Contains the SOP Instance UIDs of the loaded SR objects
*/
private Vector cachedInstances = new Vector();
/**
*Contains the current loded DICOMinstance
*/
DICOMInstance currentDicomInstance = null;
/**
*Contains the current loded DICOMinstance
*/
DICOMInstance changedDicomInstance = null;
/**
* Contains the JSrcollPane for the JEditorPane.
*/
private JScrollPane scroll;
/**
* Property name for the sr-type. This property can be part of a link in a HTML-Side
*/
private static final String SR_TYPE = "srtype";
/**
* Property name for the SOP Class UID. This property can be part of a link in a HTML-Side
*/
private static final String SOP_CLASS_UID = "SOP Class UID";
/**
* Property name for the SOP Instance UID. This property can be part of a link in a HTML-Side
*/
private static final String SOP_INSTANCE_UID = "SOP Instance UID";
/**
* Property name for the Haost. This property can be part of a link in a HTML-Side
*/
public static final String TYPE_IMAGE = "image";
public static final String TYPE_FRAME = "frame";
public static final String TYPE_COMPOSITE = "composite";
public static final String TYPE_PSTATE = "pstate";
public static final String TYPE_WAVEFORM = "waveform";
private static final String HOST = "host";
/**
* Contains a virtual URL. If the JEditorPane
* will be initialized with a String anchor in the
* HTML side cannot be resolved. Futhermore there HyperlinksEvents
* doesn't contain any URL. For this reason we set this ULR as base for
* the HTMLDocument in the JEditorPane
*/
private String helpCodeBase = "file://help/text.html";
JButton verificationButton;
JButton completeButton;
JButton saveButton;
JButton resetButton;
JButton editButton;
JButton hackerEditButton;
JButton revisedButton;
JPanel buttonPanel;
/**
* JEditorPane displaying the HTML document
*/
private JReferenceEditorPane editorPane = new JReferenceEditorPane();
/**
* HTMLEditorKit in editorPane
*/
private HTMLEditorKit eKit;
/**
* HTMLDocument in editorPane
*/
private HTMLDocument doc ;
/**
* Tilted Boder containing the name of the SR Object
*/
private TitledBorder titledBorder = new TitledBorder("Structured Report");
/**
* Current DVI Interface
*/
private jDVInterface dvi;
public MainImageViewerPanel mainView;
/**
* Constructor
*
* @param dvi jDVInterface
*/
public SRViewPanel(jDVInterface dvi, MainImageViewerPanel mainView )
{
this.dvi = dvi;
this.mainView = mainView;
setLayout(new BorderLayout());
setBorder(new TitledBorder("Structured Report Viewer"));
//CenterPanel
JPanel centerPanel = new JPanel(new BorderLayout());
centerPanel.setBorder(titledBorder);
add (centerPanel, BorderLayout.CENTER);
buttonPanel = new JPanel();
//JEditorPane
editorPane.setEditable(false);
scroll = new JScrollPane(editorPane);
centerPanel.add (scroll, BorderLayout.CENTER);
editorPane.setContentType("text/html");
editorPane.addHyperlinkListener(this);
editorPane.setEditable(false);
eKit = new HTMLEditorKit();
editorPane.setEditorKit(eKit);
//Set Base
doc = (HTMLDocument)editorPane.getDocument();
try
{
doc.setBase(new URL(helpCodeBase));
}
catch (Exception e)
{
System.err.println("Er: " + e);
}
//North
JPanel northPanel = new JPanel(new BorderLayout(5,5));
add(northPanel, BorderLayout.NORTH);
Action[] act = editorPane.getActions();
Hashtable actions;
actions = new Hashtable();
for (int i = 0; i < act.length; i++)
{
actions.put(act[i].getValue(Action.NAME), act[i]);
//System.err.println("name: " + act[i].getValue(Action.NAME));
}
northPanel.add(buttonPanel,BorderLayout.EAST);
GuiComponents gui = GuiComponents.getInstance();
JButton beginButton = gui.srViewBeginButton;
beginButton.setToolTipText("Goto Begin");
//buttonPanel.add(beginButton);
beginButton.addActionListener(new BeginAction());
JButton endButton =gui.srViewEndButton;
endButton.setToolTipText("Goto End");
// buttonPanel.add(endButton);
endButton.addActionListener((Action)actions.get("selection-end"));
JButton pageUpButton =gui.srViewUpButton;
pageUpButton.setToolTipText("Page Up");
//buttonPanel.add(pageUpButton);
pageUpButton.addActionListener((Action)actions.get("page-up"));
JButton pageDownButton= gui.srViewDownButton;
pageDownButton.setToolTipText("Page Down");
//buttonPanel.add(pageDownButton);
pageDownButton.addActionListener((Action)actions.get("page-down"));
buttonPanel.add(Box.createHorizontalStrut(5));
JButton copyButton = gui.srViewCopyButton;
copyButton.setToolTipText("Copy to Clipboard");
buttonPanel.add(copyButton);
copyButton.addActionListener((Action)actions.get("copy-to-clipboard"));
editButton = gui.srEditButton;
editButton.setToolTipText("Edit");
buttonPanel.add(editButton);
editButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
editSR(false);
}
});
ActionListener a = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
editSR(true);
}
};
registerKeyboardAction(a,
KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.ALT_MASK, false),
JComponent.WHEN_IN_FOCUSED_WINDOW);
revisedButton = gui.srRevisedButton;
revisedButton.setToolTipText("Revise");
//buttonPanel.add(revisedButton);
revisedButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
revised(false);
}
});
buttonPanel.add(Box.createHorizontalStrut(5));
completeButton= gui.srCompleteButton;
completeButton.setToolTipText("Complete Document");
buttonPanel.add(completeButton);
completeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setComplete();
}
});
completeButton.setEnabled(false);
verificationButton= gui.srVerificationButton;
verificationButton.setToolTipText("Verify Document");
verificationButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVerification();
}
});
buttonPanel.add(verificationButton);
verificationButton.setEnabled(false);
saveButton= gui.srSaveButton;
saveButton.setToolTipText("Save Document to database");
saveButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
save();
}
});
buttonPanel.add(saveButton);
resetButton= gui.srResetButton;
resetButton.setToolTipText("Reset Document");
resetButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
reset();
}
});
buttonPanel.add(resetButton);
saveButton.setEnabled(false);
resetButton.setEnabled(false);
Box box = new Box(BoxLayout.X_AXIS );
box.add(new JLabel("Loaded SR Objects: "));
box.add(box.createHorizontalStrut(5));
loadedSRNamesBox = new JComboBox();
loadedSRNamesBox.addActionListener(nameBoxActionListener);
//box.add(loadedSRNamesBox);
loadedSRNamesBox.setAlignmentX(0.5f);
loadedSRNamesBox.setAlignmentY(0.5f);
northPanel.add(loadedSRNamesBox,BorderLayout.CENTER);
}
private void setVerification()
{
VerificationDialog vd = new VerificationDialog( dvi, mainView,saveButton.isEnabled());
vd.setVisible(true);
if (vd.isVerified())
{
setChangedSR();
}
}
public void revised(boolean hackerMode)
{
jDSRDocument sr = dvi.getCurrentReport();
if (!saveButton.isEnabled())
{
sr.createRevisedVersion();
sr.setSpecificCharacterSetType(jDSRE_CharacterSet.CS_Latin1);
}
else
{
int res= JOptionPane.showConfirmDialog(loadedSRNamesBox,
"Only saved documents can be revised.\nDo you want to save this document?",
"Message",
JOptionPane.YES_NO_OPTION );
if (res == JOptionPane.NO_OPTION) return;
save();
}
mainView.addEditSR(hackerMode);
}
public void setComplete()
{
CompleteDialog cd = new CompleteDialog(mainView.parent);
cd.setVisible(true);
if (cd.cancelAction == false)
{
//setComplete();
jDSRDocument sr = dvi.getCurrentReport();
if (!saveButton.isEnabled())
{
sr.createNewSOPInstance();
sr.setSpecificCharacterSetType(jDSRE_CharacterSet.CS_Latin1);
//System.err.println("Revised: ");
}
int status = sr.completeDocument(cd.descriptionText.getText());
if (status != 0) System.err.println("Can't complete document. Status: " + status);
setChangedSR();
}
}
public void setRevisedButton()
{
Component[] c = buttonPanel.getComponents();
for (int i = 0; i < c.length; i++)
{
if (c[i] == editButton)
{
buttonPanel.remove(editButton);
buttonPanel.add(revisedButton, i);
buttonPanel.revalidate();
buttonPanel.repaint();
return;
}
}
}
public void setEditButton()
{
Component[] c = buttonPanel.getComponents();
for (int i = 0; i < c.length; i++)
{
if (c[i] == revisedButton)
{
buttonPanel.remove(revisedButton);
buttonPanel.add(editButton, i);
buttonPanel.revalidate();
buttonPanel.repaint();
return;
}
}
}
public void save()
{
Controller.instance().fireEvent(new DbActionEvent(this,DbActionEvent.SAVE_DB_SR));
saveButton.setEnabled(false);
resetButton.setEnabled(false);
}
public void reset()
{
saveButton.setEnabled(false);
resetButton.setEnabled(false);
loadedSRNamesBox.removeActionListener(nameBoxActionListener);
int index = loadedSRNamesBox.getSelectedIndex();
loadedSRNamesBox.removeItemAt(index);
cachedInstances.removeElementAt(index);
cachedObjects.removeElementAt(index);
loadedSRNamesBox.addActionListener(nameBoxActionListener);
int instanceIndex = isInstanceInCache(changedDicomInstance.sopInstanceUid);
loadedSRNamesBox.setSelectedIndex(instanceIndex);
loadObject((Properties)cachedObjects.elementAt(instanceIndex));
}
public void delete()
{
//Controller.instance().fireEvent(new DbActionEvent(this,DbActionEvent.SAVE_DB_SR));
saveButton.setEnabled(false);
resetButton.setEnabled(false);
loadedSRNamesBox.removeActionListener(nameBoxActionListener);
int index = isInstanceInCache(currentDicomInstance.sopInstanceUid);
loadedSRNamesBox.removeItemAt(index);
cachedInstances.removeElementAt(index);
cachedObjects.removeElementAt(index);
loadedSRNamesBox.addActionListener(nameBoxActionListener);
}
public void editSR(boolean hackerMode)
{
jDSRDocument sr = dvi.getCurrentReport();
if (!saveButton.isEnabled())
{
if (!hackerMode)
{
sr.createNewSOPInstance();
}
sr.setSpecificCharacterSetType(jDSRE_CharacterSet.CS_Latin1);
}
mainView.addEditSR(hackerMode);
}
/**
* Sets the specified instance visible.
* @param Specifies the index of the instance in cacheHTML and loadedSRNamesBox.
*/
private void setInstanceVisible(int index)
{
//setString((String)cacheHTML.elementAt(index));
// System.err.println("setInstanceVisible index "+index);
loadObject((Properties)cachedObjects.elementAt(index) );
}
/**
* Not used yet
*/
public void setConfiguration(Hashtable config, String orient)
{
}
/**
* Handles the received HyperlinkEvents.
*
*/
public void hyperlinkUpdate(HyperlinkEvent e)
{
//System.err.println(e.getEventType() );
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
//Gets the selected URL
URL url = e.getURL();
//System.err.println("url: " + url);
if (url != null)
{
//Check if URL in contains an anchor
int index = url.toString().indexOf("#");
if (index!= -1)
{
//Switch to anchor
editorPane.scrollToReference(url.toString().substring(index+1));
}
//Load referenced object
else
{
Properties currentProperties = getTokens(url.toString());
if (currentProperties != null)
{
loadObject(currentProperties);
}
}
}
}
else if(e.getEventType() ==HyperlinkEvent.EventType.ENTERED)
{
Cursor c = new Cursor (Cursor.HAND_CURSOR);
editorPane.setCursor(c);
}
else if(e.getEventType() == HyperlinkEvent.EventType.EXITED)
{
Cursor c = new Cursor(Cursor.DEFAULT_CURSOR);
editorPane.setCursor(c);
}
}
public void loadObject(Properties prop)
{
//Gets Properties form URL
String srtype = prop.getProperty(SR_TYPE);
//Request Image
//Request Image
if (srtype.equals(TYPE_WAVEFORM))
{
JOptionPane.showMessageDialog(this, "References to Waveform objects not supported.");
}
//Request PS
else if (srtype.equals(TYPE_PSTATE))
{
DICOMInstance instance = (DICOMInstance)prop.get(TYPE_PSTATE);
DICOMInstance instanceImage = (DICOMInstance)prop.get(TYPE_IMAGE);
Controller.instance().fireEvent(new DbActionEvent(
this,
DbActionEvent.LOAD_IMAGE_FOR_SR,
instanceImage.sopClassUid,
instanceImage.sopInstanceUid,
instance.sopClassUid,
instance.sopInstanceUid,
(int[])prop.get(TYPE_FRAME)));
}
else if (srtype.equals(TYPE_IMAGE))
{
DICOMInstance instance = (DICOMInstance)prop.get(TYPE_IMAGE);
Controller.instance().fireEvent(new DbActionEvent(
this,
DbActionEvent.LOAD_IMAGE_FOR_SR,
instance.sopClassUid,
instance.sopInstanceUid,
(int[])prop.get(TYPE_FRAME)));
}
else if (srtype.equals(TYPE_COMPOSITE))
{
DICOMInstance instance = (DICOMInstance)prop.get(TYPE_COMPOSITE);
if ( instance.sopClassUid.equals(DICOMSOPClassUID.BASIC_TEXT_SR_UID)||
instance.sopClassUid.equals(DICOMSOPClassUID.ENHANCED_SR_UID)||
instance.sopClassUid.equals(DICOMSOPClassUID.COMPREHENSIVE_SR_UID))
{
if (saveButton.isEnabled()==true)
{
int res= JOptionPane.showConfirmDialog(loadedSRNamesBox,
"The current report is not yet saved. Save it now?",
"Warning",
JOptionPane.YES_NO_OPTION );
if (res ==JOptionPane.OK_OPTION) save();
else delete();
}
Controller.instance().fireEvent(new DbActionEvent(this,DbActionEvent.LOAD_SR_FOR_SR,instance.sopClassUid,instance.sopInstanceUid, null ));
}
else if(instance.sopClassUid.equals(DICOMSOPClassUID.PS_UID))
{
Controller.instance().fireEvent(new DbActionEvent(this,DbActionEvent.LOAD_PS_FOR_SR,instance.sopClassUid,instance.sopInstanceUid ,null));
}
else JOptionPane.showMessageDialog(this, "References to " + instance.sopClassUid +" objects not supported.");
}
else JOptionPane.showMessageDialog(this, "SOP Class " + srtype + " not supported");
}
/**
* Checks if the specified SOP Instance UID is cached
* and returns the index in the cache.
* @param sopInstanceUID The SOP Instance UID.
* @return The index of the SOP Instance UID in the cache or -1 in not available
*/
private int isInstanceInCache(String sopInstanceUID)
{
if (sopInstanceUID == null ||cachedInstances == null) return -1;
for (int i = 0; i <cachedInstances.size(); i++)
{
if (sopInstanceUID.equals((String)cachedInstances.elementAt(i))) return i;
}
return -1;
}
/**
* Loads a new SR object with the specified SOP Instance UID
* @param sopInstanceUID SOP Instance UID
*/
public void setNewSR()
{
saveButton.setEnabled(false);
resetButton.setEnabled(false);
loadedSRNamesBox.removeAllItems();
cachedObjects = new Vector();
cachedInstances = new Vector();
setSR();
}
/**
* Loads a new SR object with the specified SOP Instance UID
* @param sopInstanceUID SOP Instance UID
*/
public void setChangedSR()
{
if (!saveButton.isEnabled())
{
changedDicomInstance = currentDicomInstance;
saveButton.setEnabled(true);
resetButton.setEnabled(true);
}
setSR();
}
/**
* Sets the SR and returns the Tilte of this Object
*/
private void setSR()
{
jDSRDocument sr = dvi.getCurrentReport();
String value = sr.getPatientsName();
jStringByRef s = new jStringByRef();
int status = sr.renderHTML(s, 0);
verificationButton.setEnabled(false);
int completeStatus = sr.getCompletionFlag();
if (completeStatus == jDSRE_CompletionFlag.CF_invalid)
{
setEditButton();
System.err.println("undefined complete flag");
}
else if (completeStatus == jDSRE_CompletionFlag.CF_Partial)
{
completeButton.setEnabled(true);
setEditButton();
}
else
{
setRevisedButton();
completeButton.setEnabled(false);
int verifyStatus = sr.getVerificationFlag();
if (verifyStatus == jDSRE_VerificationFlag.VF_invalid)
{
System.err.println("undefined verification flag");
}
else verificationButton.setEnabled(true);
}
if (status != 0) JOptionPane.showMessageDialog( SwingUtilities.getRoot(this),"Can't create HTML document. Please check log file", "Error", JOptionPane.ERROR_MESSAGE);
DICOMInstance dicomInstance =new DICOMInstance(sr.getSOPClassUID(),sr.getSOPInstanceUID());
int index = isInstanceInCache(dicomInstance.sopInstanceUid);
loadedSRNamesBox.removeActionListener(nameBoxActionListener);
String title= setString(s.value);
if (index== -1)
{
Properties p = new Properties();
p.put(SR_TYPE,TYPE_COMPOSITE);
p.put(TYPE_COMPOSITE,dicomInstance);
cachedInstances.add(dicomInstance.sopInstanceUid);
cachedObjects.add(p);
loadedSRNamesBox.addItem(new String(title + "/" + dicomInstance.sopInstanceUid ));
loadedSRNamesBox.setSelectedIndex(loadedSRNamesBox.getItemCount()-1);
}
else
{
loadedSRNamesBox.setSelectedIndex(index);
}
currentDicomInstance = dicomInstance;
loadedSRNamesBox.addActionListener(nameBoxActionListener);
}
private String setString(String s)
{
if (s == null) return "";
editorPane.setText(s);
String title = doc.getProperty(Document.TitleProperty).toString();
titledBorder.setTitle(title);
editorPane.select(0,0);
JScrollBar v = scroll.getVerticalScrollBar();
v.setValue(0);
v.repaint();
if (title == null) title = "untitled";
return title;
}
/**
* Loads a Composite SR object with the specified SOP Instance UID
*/
public void setNewCompositeSR()
{
setSR();
}
/**
* Splits the URL into his components and returns a Property object
* containing the values. Each URL contains of 4 values after the protocol type
* (e.g http://): The values can be accessed by the following keys:
* <i>"host", "srtype", "SOP Class UID", "SOP Instance UID"</i>.
* @param s String containing the URL
* @return The comonets of the URL. NULL if error;
*/
public Properties getTokens(String s)
{
Properties returnValue = new Properties();
int index = s.indexOf("?")+1;
if (index >= s.length())
{
System.err.println("Error in link: " + s);
return null;
}
String parse = s.substring(index);
StringTokenizer st = new StringTokenizer (parse, "&");
while (st.hasMoreTokens())
{
String token = st.nextToken();
String type =null;
if (token.startsWith(TYPE_IMAGE)) type = TYPE_IMAGE;
else if (token.startsWith(TYPE_FRAME)) type = TYPE_IMAGE;
else if (token.startsWith(TYPE_COMPOSITE)) type = TYPE_COMPOSITE;
else if (token.startsWith(TYPE_PSTATE)) type = TYPE_PSTATE;
else if (token.startsWith(TYPE_WAVEFORM)) type = TYPE_WAVEFORM;
if (type == null)
{
System.err.println("Error in link: " + s);
return null;
}
returnValue.put(SR_TYPE,type);
if (type != TYPE_FRAME)
{
int index1 = token.indexOf("+");
String classUID = token.substring(type.length()+1,index1);
String instanceUID = token.substring(index1+1);
//System.err.println("Type: " + type +" SOP Class UID" + classUID + " SOP Instance UID:" + instanceUID);
returnValue.put(type,new DICOMInstance(classUID,instanceUID));
}
else
{
StringTokenizer fTokenizer = new StringTokenizer(token.substring(type.length()+1), "+");
try
{
int[] frameIds = new int[fTokenizer.countTokens()];
int i = 0;
while (fTokenizer.hasMoreTokens())
{
String fToken = fTokenizer.nextToken();
frameIds[i] = new Integer(fToken).intValue();
i++;
}
returnValue.put(type,frameIds);
}
catch (Exception e)
{
System.err.println("Error in link: " + s+ "\n" +e);
return null;
}
}
}
return returnValue;
}
/**
* Return the position of an anchor or -1 if the anchor is not in the HTML code
* @param anchor HTML Anchor name
* @return GetStartOffset of the HTML anchor or -1 if not found
*/
public int getAnchorPositon(String anchor)
{
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid())
{
AttributeSet as =it.getAttributes();
String thisref = (String) as.getAttribute(HTML.Attribute.NAME);
if (thisref != null &&thisref.equals(anchor))
{
return it.getStartOffset();
}
it.next();
}
return -1;
}
/**
* Go to the begin of the HTMLDocument
*/
private class BeginAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
editorPane.select(0,0);
JScrollBar v = scroll.getVerticalScrollBar();
v.setValue(0);
v.repaint();
}
}
public class CompleteDialog extends JDialog
{
public JTextArea descriptionText = new JTextArea(4,16);
public boolean cancelAction = true;
public CompleteDialog(Component parent)
{
super((JFrame)(null), "Complete Document", true);
getContentPane().setLayout(new BorderLayout(5,5));
Point p = completeButton.getLocationOnScreen();
//System.err.println(p);
setLocation(new Point(p.x-100, p.y+100));
JButton okButton = new JButton("Complete");
okButton.setToolTipText ("Set Completion Flag");
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
cancelAction = false;
dispose();
}
});
JButton cancelButton = new JButton("Cancel");
cancelButton.setToolTipText ("Cancel");
cancelButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
dispose();
}
});
JPanel centerPanel = new JPanel(new BorderLayout(5,5));
centerPanel.setBorder(new TitledBorder("Description"));
descriptionText.setDocument(new LODocument());
descriptionText.setLineWrap(true);
descriptionText.setWrapStyleWord(true);
centerPanel.add(descriptionText, BorderLayout.CENTER);
getContentPane().add(centerPanel, BorderLayout.CENTER);
JPanel bPanel = new JPanel();
bPanel.add(okButton);
bPanel.add(cancelButton);
getContentPane().add(bPanel, BorderLayout.SOUTH);
pack();
}
}
public class NameBoxActionListener implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
//System.err.println("actionPerformed");
if (loadedSRNamesBox.getItemCount() > 1)
{
setInstanceVisible(loadedSRNamesBox.getSelectedIndex());
}
}
}
public Dimension getPreferredSize()
{
return new Dimension (10,10);
}
public Dimension getMinimumSize()
{
return new Dimension (10,10);
}
public Dimension getMaximumSize()
{
return new Dimension (10,10);
}
}
/*
* CVS Log
* $Log: SRViewPanel.java,v $
* Revision 1.1.1.1 2001/06/06 10:32:30 kleber
* Init commit for DICOMscope 3.5
* Create new CVS
*
*/
|