Because of a lapse in government funding, the information on this website may not be up to date, transactions submitted via the website may not be processed, and the agency may not be able to respond to inquiries until appropriations are enacted. The NIH Clinical Center (the research hospital of NIH) is open. For more details about its operating status, please visit cc.nih.gov. Updates regarding government operating status and resumption of normal operations can be found at OPM.gov.

Visual Tagging Tool

DefaultStyledDocument

Java Swing class JTextPane is used for the core operation of VTT.

  • Scrollable:
    JTextPane is added to JScollPane for scrollability
    The hierarchy of GUI objects is:
    • MainFrame (JFrame)
      • MainPanel (JPanel)
        • scrollPane (JScrollPane)
          • textPane_ (JTextPane)
            • setEditable(false)
            • setCaretPosition(int)

            • setSelectionStart(int)
            • setSelectionEnd(int)
            • setSelectedTextColor(color)
            • setSelectionColor(color)

            • print()

            • (DefaultStyledDocument) doc (StyledDocument)
              • set style change in doc
  • Controller (listeners):
    MouseListener and CaretListener are added in JTextPane for mouse control and caret control.
  • StyledDocument
    JTextPane.getStyledDocument( ) is used for core operations of changing color, style, size, font, etc.. The sample code is implemented in VttDocument.java as follows:

    // get doc
    DefaultStyledDocument doc
    	= (DefaultStyledDocument) JTextPane.getStyledDocument( );
    
    // set SimpleAttibuteSet by StyleConstants
    SimpleAttributeSet sas = new SimpleAttributeSet();
    StyleConstants.setBold(sas, tag.IsBold());
    StyleConstants.setItalic(sas, tag.IsItalic());
    StyleConstants.setUnderline(sas, tag.IsUnderline());
    
    StyleConstants.setForeground(sas, TEXT_COLOR);
    StyleConstants.setBackground(sas, TEXT_BG_COLOR);
    
    StyleConstants.setFontFamily(sas, tag.GetFontFamily());
    StyleConstants.setFontSize(sas, tag.GetFontSize());
    
    // init/load doc
    doc.remove(0, doc.getLength());
    doc.insertString(doc.getLength(), tagDocument.GetText(), sas);
    
    // set style to doc
    doc.setCharacterAttributes(offset, length, sas, false);