public void addStyledText(String text, String style, boolean index) {
    Style s = _hexStyledDoc.getStyle(style);
    if (s == null) {
      PacketSamurai.getUserInterface().log("WARNING: Missing style for partType: " + style);
      style = "base";
    }

    try {
      _hexStyledDoc.insertString(_hexStyledDoc.getLength(), text, _hexStyledDoc.getStyle(style));
    } catch (BadLocationException e) {
      e.printStackTrace();
    }
  }
  public void highlightSelectedPart(DataPartNode node) {
    Style style = _hexStyledDoc.getStyle("selected");

    try {
      String text = _hexStyledDoc.getText(node.getOffset(), node.getLength());
      // _hexStyledDoc.remove(node.getOffset(), node.getLength());
      // _hexStyledDoc.insertString(node.getOffset(), text, style);
      _hexStyledDoc.replace(node.getOffset(), node.getLength(), text, style);
      _hexDumpArea.setCaretPosition(node.getOffset());
    } catch (BadLocationException e) {
      e.printStackTrace();
    }
  }
 private void addLineBreaksToHexDump(byte[] id, byte[] data) {
   // add linefeeds to the dump
   int lnCount = _hexDumpArea.getText().length() / 48;
   int rest = _hexDumpArea.getText().length() % 48;
   for (int i = 1; i <= lnCount; i++) {
     int pos = i * 67 - 20;
     try {
       int idx = i - 1;
       String ansci =
           idx == 0
               ? (Util.toAnsci(id, 0, id.length) + Util.toAnsci(data, 0, 16 - id.length))
               : Util.toAnsci(data, idx * 16 - id.length, idx * 16 + 16 - id.length);
       _hexStyledDoc.replace(pos, 1, "   " + ansci + "\n", _hexStyledDoc.getStyle("base"));
       // _hexStyledDoc.remove(pos,1);
       // _hexStyledDoc.insertString(pos, "\n", _hexStyledDoc.getStyle("base"));
     } catch (BadLocationException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
   }
   // rest
   if (rest != 0) {
     try {
       int pos = lnCount * 67 + rest;
       String space = "";
       int spaceCount = 48 - rest;
       while (spaceCount-- > 0) space += " ";
       String ansci =
           lnCount == 0
               ? (Util.toAnsci(id, 0, id.length) + Util.toAnsci(data, 0, data.length - id.length))
               : Util.toAnsci(data, lnCount * 16 - id.length, data.length - id.length);
       _hexStyledDoc.insertString(pos, space + "  " + ansci, _hexStyledDoc.getStyle("base"));
     } catch (BadLocationException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
   }
 }