/** * triggers a repaint of the styled text of the containing editor whenever the text has changed. * * <p>The repaint will update the positions of all of the embedded controls. * * <p>XXX this method is being called too many times. It is being called more than once after each * cursor change. I need to take a good look at this and determine exactly when and where it * should be called */ public void paint(int reason) { if (reason != TEXT_CHANGE && reason != ContainingEditor.EMBEDDED_REPAINT) { return; } List<ContainedEditorManager> toRemove = new LinkedList<ContainedEditorManager>(); for (final ContainedEditorManager c : editorPositionMap.keySet()) { Position model = editorPositionMap.get(c); if (!model.isDeleted()) { // map from the model to the actual display (takes into account folding) Position projected = modelToProjected(model); if (projected == null) { // position is hidden behind folding c.getControl().setVisible(false); } else { try { Point location = styledText.getLocationAtOffset(projected.offset); location.x += ContainingEditor.MARGIN; location.y += ContainingEditor.MARGIN; c.getControl().setVisible(true); c.getControl().setLocation(location); } catch (IllegalArgumentException e) { EmbeddedCALPlugin.logError("Error repainting", e); } } } else { toRemove.add(c); } } for (final ContainedEditorManager c : toRemove) { removeControl(c, true); } styledText.getParent().getParent().redraw(); }
/** * creates the style range of the StyledText for the range of the contained editor * * <p>XXX problem will occur if there is a newline in the position. Working on this! code folding. */ private StyleRange[] createStyleRange(ContainedEditorManager c, Position p) { int offset = p.offset; int length = p.length; Rectangle rect = c.getControl().getBounds(); int ascent = rect.height - 4; int descent = 4; // use two style ranges // first style range covers the entire size of the contained editor StyleRange first = new StyleRange(); first.start = offset; first.length = Math.min(1, length); first.background = this.containingEditor.colorManager.getColor(new RGB(255, 255, 255)); first.metrics = new GlyphMetrics( ascent + ContainingEditor.MARGIN, descent + ContainingEditor.MARGIN, rect.width + 2 * ContainingEditor.MARGIN); // this style range is hidden. the height and width are 0 StyleRange second = new StyleRange(); second.start = offset + 1; second.length = length - 1; second.background = this.containingEditor.colorManager.getColor(new RGB(255, 255, 255)); second.metrics = new GlyphMetrics(0, 0, 0); second.font = TINY_FONT; return new StyleRange[] {first, second}; }