Esempio n. 1
0
 static {
   HEADING_LIST.put("H1 head line", 35);
   HEADING_LIST.put("H2 head line", 30);
   HEADING_LIST.put("H3 head line", 25);
   HEADING_LIST.put("H4 head line", 20);
   HEADING_LIST.put("H5 head line", 15);
   HEADING_LIST.put("Paragraph", 10);
   HEADING_LIST.put("Quote", 10);
 }
  /**
   * Returns the <code>Format.Field</code> constants associated with the text at <code>offset</code>
   * . If <code>offset</code> is not a valid location into the current text, this will return an
   * empty array.
   *
   * @param offset offset into text to be examined
   * @return Format.Field constants associated with the text at the given position.
   */
  public Format.Field[] getFields(int offset) {
    if (getAllowsInvalid()) {
      // This will work if the currently edited value is valid.
      updateMask();
    }

    Map attrs = getAttributes(offset);

    if (attrs != null && attrs.size() > 0) {
      ArrayList al = new ArrayList();

      al.addAll(attrs.keySet());
      return (Format.Field[]) al.toArray(EMPTY_FIELD_ARRAY);
    }
    return EMPTY_FIELD_ARRAY;
  }
  protected boolean getRegionText(BaleRegion br, int off, int len, Segment text)
      throws BadLocationException {
    int soff = br.getStart();
    int eoff = br.getEnd();

    if (region_map != null) {
      validateRegions();
      RegionData rd = region_map.get(br);
      Segment rtext = new Segment();
      base_document.getText(soff, eoff - soff, rtext);
      return rd.getText(rtext, off, len, text);
    }

    int doff = off + soff;
    int dlen = len;

    boolean lastbad = false;
    if (br.includesEol()) {
      if (doff + dlen > eoff) dlen = eoff - off;
      base_document.getText(doff, len, text);
    } else {
      if (doff + dlen > eoff) dlen = eoff - off + 1;
      base_document.getText(doff, len, text);
      lastbad = (doff + len > eoff); // if last character might be bad
    }

    return lastbad;
  }
Esempio n. 4
0
 private void _setUpResources() {
   DefaultComboBoxModel dlm = new DefaultComboBoxModel();
   Set<String> keys = HEADING_LIST.keySet();
   for (String key : keys) {
     dlm.addElement(key);
   }
   mHeadingComboBox.setModel(dlm);
 }
 private void fixupOffset(BaleRegion br, int off, boolean edit) {
   if (edit && region_map != null) {
     validateRegions();
     RegionData rd = region_map.get(br);
     rd.fixupOffset(br, off);
   }
   validateRegions();
 }
  private void validateRegions() {
    if (region_map == null) return;

    synchronized (region_map) {
      if (regions_valid) return;

      Segment s = new Segment();

      region_map.clear();

      for (BaleRegion br : fragment_regions) {
        RegionData rd = new RegionData(indent_size);
        region_map.put(br, rd);
        int soff = br.getStart();
        int eoff = br.getEnd();
        if (eoff < soff) continue;
        try {
          base_document.getText(soff, eoff - soff, s);
        } catch (BadLocationException e) {
          BoardLog.logE("BALE", "Problem getting region indentation", e);
          continue;
        }
        int ln = s.length();

        LineData ld;
        boolean sol = true;
        for (int i = 0; i < ln; ++i) {
          char c = s.charAt(i);
          if (sol) {
            ld = computeLineData(i, s);
            rd.add(ld);
            sol = false;
          }
          if (c == '\n') sol = true;
        }
        if (!sol) {
          ld = computeLineData(ln, s);
          rd.add(ld);
          ++ln;
        }
      }

      regions_valid = true;
    }
  }
  protected int mapViewOffsetToRegion(BaleRegion br, int offset, boolean edit) {
    if (region_map != null) {
      fixupOffset(br, offset, edit);
      RegionData rd = region_map.get(br);
      return rd.getRegionOffset(br, offset);
    }

    return offset;
  }
  protected int mapRegionOffsetToView(BaleRegion br, int offset) {
    if (region_map != null) {
      validateRegions();
      RegionData rd = region_map.get(br);
      return rd.getViewOffset(offset);
    }

    return offset;
  }
Esempio n. 9
0
  public void refreshErrorDisplay() {
    if (parseErrorHighlightKey != null)
      editor.getHighlighter().removeHighlight(parseErrorHighlightKey);

    /* Mapping for gutter */
    Map<Integer, String> errorLines = new HashMap<Integer, String>();

    if (parseError != null && parseError.hasLineNumbers()) {
      String error = parseError.getMessage();

      // Just the first line.
      errorLines.put(parseError.getBeginLine(), error);

      // If error spans multiple lines, this code will put
      // an error in every line of the gutter.
      /*for (int line = parseError.getBeginLine();
           line <= parseError.getEndLine();
           line++)
      {
      	errorLines.put(line, error);
      }*/
    }

    gutter.setParseErrors(errorLines);

    /* Highlighting errors in editor */
    if (parseError != null && parseError.hasLineNumbers()) {
      /* Remove existing highlight */
      try {
        parseErrorHighlightKey =
            editor
                .getHighlighter()
                .addHighlight(
                    computeDocumentOffset(parseError.getBeginLine(), parseError.getBeginColumn()),
                    computeDocumentOffset(parseError.getEndLine(), parseError.getEndColumn()) + 1,
                    errorHighlightPainter);
      } catch (BadLocationException e) {

      }
    }
  }
  /** ***************************************************************************** */
  protected int getRegionLength(BaleRegion br) {
    int len = br.getEnd() - br.getStart();

    if (!br.includesEol()) len += 1;

    if (region_map != null) {
      validateRegions();
      RegionData rd = region_map.get(br);
      len += rd.getDeltaLength();
    }

    return len;
  }
Esempio n. 11
0
  /**
   * Outputs the maps as elements. Maps are not stored as elements in the document, and as such this
   * is used to output them.
   */
  void writeMaps(Enumeration maps) throws IOException {
    if (maps != null) {
      while (maps.hasMoreElements()) {
        Map map = (Map) maps.nextElement();
        String name = map.getName();

        incrIndent();
        indent();
        write("<map");
        if (name != null) {
          write(" name=\"");
          write(name);
          write("\">");
        } else {
          write('>');
        }
        writeLineSeparator();
        incrIndent();

        // Output the areas
        AttributeSet[] areas = map.getAreas();
        if (areas != null) {
          for (int counter = 0, maxCounter = areas.length; counter < maxCounter; counter++) {
            indent();
            write("<area");
            writeAttributes(areas[counter]);
            write("></area>");
            writeLineSeparator();
          }
        }
        decrIndent();
        indent();
        write("</map>");
        writeLineSeparator();
        decrIndent();
      }
    }
  }
 /** Returns true if <code>attributes</code> is null or empty. */
 boolean isLiteral(Map attributes) {
   return ((attributes == null) || attributes.size() == 0);
 }