Package javax.swing.text

Examples of javax.swing.text.StyledDocument


  /**
   * Creates the annotation display.
   */
  private void displayAnnotations() {
    // for speed, detach document from text pane before updating
    StyledDocument doc = (StyledDocument) textPane.getDocument();
    Document blank = new DefaultStyledDocument();
    textPane.setDocument(blank);

    // make sure annotationCheckboxPanel is showing
    if (legendScrollPane.getViewport().getView() != annotationCheckboxPanel) {
      legendScrollPane.setViewportView(annotationCheckboxPanel);
    }

    // add text from CAS
    try {
      doc.remove(0, doc.getLength());
      doc.insertString(0, mCAS.getDocumentText(), new SimpleAttributeSet());
    } catch (BadLocationException e) {
      throw new RuntimeException(e);
    }

    // Iterate over annotations
    FSIterator iter = mCAS.getAnnotationIndex().iterator();
    Hashtable checkBoxes = new Hashtable();
    HashSet checkBoxesDone = new HashSet();
    while (iter.isValid()) {
      AnnotationFS fs = (AnnotationFS) iter.get();
      iter.moveToNext();

      Type type = fs.getType();

      // have we seen this type before?
      JCheckBox checkbox = (JCheckBox) mTypeToCheckboxMap.get(type);
      if (checkbox == null) {
        // check that type should be displayed
        if ((mDisplayedTypeNames == null || typeNamesContains(mDisplayedTypeNames, type.getName()))
                && !typeNamesContains(mHiddenTypeNames, type.getName())) {
          // if mTypeNameToColorMap exists, get color from there
          Color c = (Color) mTypeNameToColorMap.get(type.getName());
          if (c == null) // assign next available color
          {
            c = COLORS[mTypeNameToColorMap.size() % COLORS.length];
            mTypeNameToColorMap.put(type.getName(), c);
          }
          // This next section required until priorities work properly
          // HashSet noCheckSet = new HashSet();
          String noCheckArray[] = {
          // "org.apache.jresporator.PROPER",
          // "DOCSTRUCT_ANNOT_TYPE",
          // "VOCAB_ANNOT_TYPE"
          };
          for (int i = 0; i < noCheckArray.length; i++) {
            noCheckSet.add(noCheckArray[i]);
          }
          // end of section

          // should type be initially selected?
          boolean selected = ((mInitiallySelectedTypeNames == null &&
          // document annotation is not initially selected in default case
                  !CAS.TYPE_NAME_DOCUMENT_ANNOTATION.equals(type.getName()) && !noCheckSet
                  .contains(type.getName()) // priorities JMP
          ) || (mInitiallySelectedTypeNames != null && typeNamesContains(
                  mInitiallySelectedTypeNames, type.getName())));

          // add checkbox
          checkbox = new JCheckBox(type.getShortName(), selected);
          checkbox.setToolTipText(type.getName());
          checkbox.addActionListener(this);
          checkbox.setBackground(c);
          // annotationCheckboxPanel.add(checkbox); do it later JMP
          checkBoxes.put(type.getName(), checkbox);
          checkBoxesDone.add(checkbox);
          // add to (Type, Checkbox) map
          mTypeToCheckboxMap.put(type, checkbox);
        } else {
          // this type is not hidden, skip it
          continue;
        }
      }
      // if checkbox is checked, assign color to text
      if (checkbox.isSelected()) {
        int begin = fs.getBegin();
        int end = fs.getEnd();

        // Be careful of 0-length annotations and annotations that span the
        // entire document. In either of these cases, if we try to set
        // background color, it will set the input text style, which is not
        // what we want.
        if (begin == 0 && end == mCAS.getDocumentText().length()) {
          end--;
        }

        if (begin < end) {
          MutableAttributeSet attrs = new SimpleAttributeSet();
          StyleConstants.setBackground(attrs, checkbox.getBackground());
          doc.setCharacterAttributes(begin, end - begin, attrs, false);
        }
      }
    }

    // now populate panel with checkboxes in order specified in user file. JMP
View Full Code Here


       
        FindReplaceUtility.registerTextComponent(this);
    }

    public int getNumberOfPages() {
        StyledDocument doc = (StyledDocument)getDocument();
       
        Paper paper = PAGE_FORMAT.getPaper();
       
        numPages =
            (int)Math.ceil(getSize().getHeight() / paper.getImageableHeight());
View Full Code Here

    }
   
    public int print(Graphics graphics, PageFormat pageFormat, int page)
        throws PrinterException {
        if (page < numPages) {
            StyledDocument doc = (StyledDocument)getDocument();
            Paper paper = pageFormat.getPaper();

            // initialize the PRINT_PANE (need this so that wrapping
            // can take place)
            PRINT_PANE.setDocument(getDocument());
View Full Code Here

       
  }
 
  public void highlight(NfoField field) {
   
    StyledDocument doc = getStyledDocument();
    if (highlightedResult != null) {
      doc.setCharacterAttributes(highlightedResult.getStart(),
          highlightedResult.getEnd() - highlightedResult.getStart(),
          getStyle(styleKey(highlightedResult.getStatus(), false)), true);
      // turn off old highlighting
      highlightedResult = null;
    }
    if (filteredMatchMap == null) {
      return;
    }
    MatchResult m = filteredMatchMap.get(field);
    if (m == null) {
      return;     
    }
    highlightedResult = m; 
           
    doc.setCharacterAttributes(m.getStart(), m.getEnd() - m.getStart(),
        getStyle(styleKey(highlightedResult.getStatus(), true)), true);
    setCaretPosition(m.getStart());
  }
View Full Code Here

     */
  public void init(NfoLyzeResult result, MatchResult.Source source) { 
    // get match results by source & order by match end position
    filteredMatches = result.getMatchResults(source);   
    highlightedResult = null;
    StyledDocument doc = getStyledDocument();
 
    try {
      doc.remove(0, doc.getLength());
      // set nfo text
      switch(source) {
        case NFO:
          doc.insertString(0, result.getContent(), getStyle(STYLE_NORMAL));         
          break;
        case PATH:
          doc.insertString(0, result.getPath().pathString(), getStyle(STYLE_NORMAL));
      }

    } catch (BadLocationException e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }
    
   
   
    buildFilteredMap(); // build map from matches
    Collections.sort(filteredMatches, new Comparator<Entry<NfoField, MatchResult>>() {
      @Override public int compare(Entry<NfoField, MatchResult> o1,
          Entry<NfoField, MatchResult> o2) {       
        if(o1.getValue().getEnd() < o2.getValue().getEnd()) {
          return -1;
        } else if(o1.getValue().getEnd() > o2.getValue().getEnd()) {
          return 1;
        } else {
          return 0;
        }
      }});
   
    // mark results
    MatchResult m;
    int offs = 0;
    for (Entry<NfoField, MatchResult> e : filteredMatches) {
      m = e.getValue();
//      System.out.println(m); 
      if (m.getMatch().isEmpty()) {
        continue;
      }     
      doc.setCharacterAttributes(m.getStart() + offs, m.getEnd() - m.getStart(),
          getStyle(styleKey(m.getStatus(), false)), true);
      try {
        // adapt the MatchResults' positions
        m.setStart(m.getStart() + offs);
        m.setEnd(m.getEnd() + offs);
       
        doc.insertString(m.getEnd(), Integer.toString(e.getKey().ordinal()), getStyle(STYLE_SUPER));
        offs++;
      } catch (BadLocationException e1) {       
        e1.printStackTrace();
      }
    }
View Full Code Here

         
          int start = txtInvoer.getSelectionStart();
          int end = txtInvoer.getSelectionEnd();
          if (end != start)
          {
            StyledDocument doc = (StyledDocument) txtInvoer.getDocument();
            doc.setCharacterAttributes(start, end - start, attr, false);
          }
          else txtInvoer.setParagraphAttributes(attr, false);
          txtInvoer.requestFocus();
        }
      }
    });
    pnlControl.add(btnFont);

    //color
    //btnColor = new JButton(StatusIcons.getImage("plugins/xhtml.jar!/nu/fw/jeti/plugins/xhtml/color.gif"));
    btnColor = new JButton(new ImageIcon(getClass().getResource("color.gif")));
    btnColor.setToolTipText(I18N.gettext("xhtml.Color"));
    btnColor.setMargin(new Insets(0, 0, 0, 0));
    btnColor.setPreferredSize(new Dimension(23, 23));
    btnColor.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        Color color = JColorChooser.showDialog(txtInvoer.getTopLevelAncestor(), I18N.gettext("xhtml.Color"), null);
        if (color != null)
        {
          int start = txtInvoer.getSelectionStart();
          int end = txtInvoer.getSelectionEnd();
          MutableAttributeSet set = new SimpleAttributeSet();
          set.addAttribute(StyleConstants.Foreground, color);
          if (end != start)
          {
            StyledDocument doc = (StyledDocument) txtInvoer.getDocument();
            //System.out.println(set);
            doc.setCharacterAttributes(start, end - start, set, false);
          }
          else txtInvoer.setParagraphAttributes(set, false);
          txtInvoer.requestFocus();
        }
      }
View Full Code Here

    @SuppressWarnings("boxing")
    public void setupTabPane() {
        // Clear all data before display a new
        this.clearData();
        StyledDocument statsDoc = stats.getStyledDocument();
        try {
            if (userObject instanceof SampleResult) {
                sampleResult = (SampleResult) userObject;
                // We are displaying a SampleResult
                setupTabPaneForSampleResult();
                requestPanel.setSamplerResult(sampleResult);               

                final String samplerClass = sampleResult.getClass().getName();
                String typeResult = samplerClass.substring(1 + samplerClass.lastIndexOf('.'));
               
                StringBuilder statsBuff = new StringBuilder(200);
                statsBuff.append(JMeterUtils.getResString("view_results_thread_name")).append(sampleResult.getThreadName()).append(NL); //$NON-NLS-1$
                String startTime = dateFormat.format(new Date(sampleResult.getStartTime()));
                statsBuff.append(JMeterUtils.getResString("view_results_sample_start")).append(startTime).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytes()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_size_headers_in_bytes")).append(sampleResult.getHeadersSize()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_size_body_in_bytes")).append(sampleResult.getBodySize()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL); //$NON-NLS-1$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                statsBuff.setLength(0); // reset for reuse

                String responseCode = sampleResult.getResponseCode();

                int responseLevel = 0;
                if (responseCode != null) {
                    try {
                        responseLevel = Integer.parseInt(responseCode) / 100;
                    } catch (NumberFormatException numberFormatException) {
                        // no need to change the foreground color
                    }
                }

                Style style = null;
                switch (responseLevel) {
                case 3:
                    style = statsDoc.getStyle(STYLE_REDIRECT);
                    break;
                case 4:
                    style = statsDoc.getStyle(STYLE_CLIENT_ERROR);
                    break;
                case 5:
                    style = statsDoc.getStyle(STYLE_SERVER_ERROR);
                    break;
                default: // quieten Findbugs
                    break; // default - do nothing
                }

                statsBuff.append(JMeterUtils.getResString("view_results_response_code")).append(responseCode).append(NL); //$NON-NLS-1$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), style);
                statsBuff.setLength(0); // reset for reuse

                // response message label
                String responseMsgStr = sampleResult.getResponseMessage();

                statsBuff.append(JMeterUtils.getResString("view_results_response_message")).append(responseMsgStr).append(NL); //$NON-NLS-1$
                statsBuff.append(NL);
                statsBuff.append(JMeterUtils.getResString("view_results_response_headers")).append(NL); //$NON-NLS-1$
                statsBuff.append(sampleResult.getResponseHeaders()).append(NL);
                statsBuff.append(NL);
                statsBuff.append(typeResult + " "+ JMeterUtils.getResString("view_results_fields")).append(NL); //$NON-NLS-1$ $NON-NLS-2$
                statsBuff.append("ContentType: ").append(sampleResult.getContentType()).append(NL); //$NON-NLS-1$
                statsBuff.append("DataEncoding: ").append(sampleResult.getDataEncodingNoDefault()).append(NL); //$NON-NLS-1$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                statsBuff = null; // Done
               
                // Tabbed results: fill table
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_thread_name"), sampleResult.getThreadName())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_start"), startTime)); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_headers_in_bytes"), sampleResult.getHeadersSize())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_body_in_bytes"), sampleResult.getBodySize())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_message"), responseMsgStr)); //$NON-NLS-1$
               
                // Parsed response headers
                LinkedHashMap<String, String> lhm = JMeterUtils.parseHeaders(sampleResult.getResponseHeaders());
                Set<Entry<String, String>> keySet = lhm.entrySet();
                for (Entry<String, String> entry : keySet) {
                    resHeadersModel.addRow(new RowResult(entry.getKey(), entry.getValue()));
                }
               
                // Fields table
                resFieldsModel.addRow(new RowResult("Type Result ", typeResult)); //$NON-NLS-1$
                //not sure needs I18N?
                resFieldsModel.addRow(new RowResult("ContentType", sampleResult.getContentType())); //$NON-NLS-1$
                resFieldsModel.addRow(new RowResult("DataEncoding", sampleResult.getDataEncodingNoDefault())); //$NON-NLS-1$
               
                // Reset search
                if (activateSearchExtension) {
                    searchTextExtension.resetTextToFind();
                }

            } else if (userObject instanceof AssertionResult) {
                assertionResult = (AssertionResult) userObject;

                // We are displaying an AssertionResult
                setupTabPaneForAssertionResult();

                StringBuilder statsBuff = new StringBuilder(100);
                statsBuff.append(JMeterUtils.getResString("view_results_assertion_error")).append(assertionResult.isError()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_assertion_failure")).append(assertionResult.isFailure()).append(NL); //$NON-NLS-1$
                statsBuff.append(JMeterUtils.getResString("view_results_assertion_failure_message")).append(assertionResult.getFailureMessage()).append(NL); //$NON-NLS-1$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
            }
        } catch (BadLocationException exc) {
            stats.setText(exc.getLocalizedMessage());
        }
    }
View Full Code Here

        stats = new JTextPane();
        stats.setEditable(false);
        stats.setBackground(backGround);

        // Add styles to use for different types of status messages
        StyledDocument doc = (StyledDocument) stats.getDocument();

        Style style = doc.addStyle(STYLE_REDIRECT, null);
        StyleConstants.setForeground(style, REDIRECT_COLOR);

        style = doc.addStyle(STYLE_CLIENT_ERROR, null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);

        style = doc.addStyle(STYLE_SERVER_ERROR, null);
        StyleConstants.setForeground(style, SERVER_ERROR_COLOR);

        paneRaw = GuiUtils.makeScrollPane(stats);
        paneRaw.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
View Full Code Here

  }

  public void appendText(String text) {
    String style;
    boolean eraseControl;
    StyledDocument doc = a.getStyledDocument();
    if (text.startsWith("\u3000")) {
      style = "error";
      eraseControl = true;
    } else if (text.startsWith("\u3001")) {
      style = "tryagain";
      eraseControl = true;
    } else if (text.startsWith("\u3002")) {
      style = "pending";
      eraseControl = true;
    } else if (text.startsWith("\u3003")) {
      style = "done";
      eraseControl = true;
    } else if (text.startsWith("\u3004")) {
      style = "regular";
      eraseControl = true;
    } else {
      style = "";
      eraseControl = false;
    }

    if (eraseControl) {
      text = text.substring(1);
    }
    try {
      doc.insertString(doc.getLength(), text + '\n', doc.getStyle(style));
    } catch (BadLocationException ex) {
    }
  }
View Full Code Here

  }

  public void appendText(String text) {
    String style;
    boolean eraseControl;
    StyledDocument doc = a.getStyledDocument();
    if (text.startsWith("\u3000")) {
      style = "error";
      eraseControl = true;
    } else if (text.startsWith("\u3001")) {
      style = "tryagain";
      eraseControl = true;
    } else if (text.startsWith("\u3002")) {
      style = "pending";
      eraseControl = true;
    } else if (text.startsWith("\u3003")) {
      style = "done";
      eraseControl = true;
    } else if (text.startsWith("\u3004")) {
      style = "regular";
      eraseControl = true;
    } else {
      style = "";
      eraseControl = false;
    }

    if (eraseControl) {
      text = text.substring(1);
    }
    try {
      doc.insertString(doc.getLength(), text + '\n', doc.getStyle(style));
    } catch (BadLocationException ex) {
    }
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.StyledDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.