/** * Adds a highlight to the view. Returns a tag that can be used to refer to the highlight. * * @param p0 the start offset of the range to highlight >= 0 * @param p1 the end offset of the range to highlight >= p0 * @param p the painter to use to actually render the highlight * @return an object that can be used as a tag to refer to the highlight * @exception BadLocationException if the specified location is invalid */ public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p) throws BadLocationException { if (p0 < 0) { throw new BadLocationException("Invalid start offset", p0); } if (p1 < p0) { throw new BadLocationException("Invalid end offset", p1); } Document doc = component.getDocument(); HighlightInfo i = (getDrawsLayeredHighlights() && (p instanceof LayeredHighlighter.LayerPainter)) ? new LayeredHighlightInfo() : new HighlightInfo(); i.painter = p; i.p0 = doc.createPosition(p0); i.p1 = doc.createPosition(p1); highlights.addElement(i); safeDamageRange(p0, p1); return i; }
/** * Renders the highlights. * * @param g the graphics context */ public void paint(Graphics g) { // PENDING(prinz) - should cull ranges not visible int len = highlights.size(); for (int i = 0; i < len; i++) { HighlightInfo info = highlights.elementAt(i); if (!(info instanceof LayeredHighlightInfo)) { // Avoid allocing unless we need it. Rectangle a = component.getBounds(); Insets insets = component.getInsets(); a.x = insets.left; a.y = insets.top; a.width -= insets.left + insets.right; a.height -= insets.top + insets.bottom; for (; i < len; i++) { info = highlights.elementAt(i); if (!(info instanceof LayeredHighlightInfo)) { Highlighter.HighlightPainter p = info.getPainter(); p.paint(g, info.getStartOffset(), info.getEndOffset(), a, component); } } } } }
/** * Changes a highlight. * * @param tag the highlight tag * @param p0 the beginning of the range >= 0 * @param p1 the end of the range >= p0 * @exception BadLocationException if the specified location is invalid */ public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException { if (p0 < 0) { throw new BadLocationException("Invalid beginning of the range", p0); } if (p1 < p0) { throw new BadLocationException("Invalid end of the range", p1); } Document doc = component.getDocument(); if (tag instanceof LayeredHighlightInfo) { LayeredHighlightInfo lhi = (LayeredHighlightInfo) tag; if (lhi.width > 0 && lhi.height > 0) { component.repaint(lhi.x, lhi.y, lhi.width, lhi.height); } // Mark the highlights region as invalid, it will reset itself // next time asked to paint. lhi.width = lhi.height = 0; lhi.p0 = doc.createPosition(p0); lhi.p1 = doc.createPosition(p1); safeDamageRange(Math.min(p0, p1), Math.max(p0, p1)); } else { HighlightInfo info = (HighlightInfo) tag; int oldP0 = info.p0.getOffset(); int oldP1 = info.p1.getOffset(); if (p0 == oldP0) { safeDamageRange(Math.min(oldP1, p1), Math.max(oldP1, p1)); } else if (p1 == oldP1) { safeDamageRange(Math.min(p0, oldP0), Math.max(p0, oldP0)); } else { safeDamageRange(oldP0, oldP1); safeDamageRange(p0, p1); } info.p0 = doc.createPosition(p0); info.p1 = doc.createPosition(p1); } }
public void populateVersionTable() throws SamFSException { CCActionTableModel model = getTableModel(VERSION_TABLE); model.clear(); HttpSession session = RequestManager.getRequestContext().getRequest().getSession(); HashMap myHashMap = (HashMap) session.getAttribute(Constants.SessionAttributes.VERSION_HIGHLIGHT); if (myHashMap == null) { // Start parsing the XML file try { SAXHandler.parseIt(); } catch (SamFSException ex) { // Failed to parse version highlight XML file SamUtil.setErrorAlert( getParentViewBean(), ServerCommonViewBeanBase.CHILD_COMMON_ALERT, "VersionHighlight.error", ex.getSAMerrno(), ex.getMessage(), ""); return; } // Retrieve the HashMap after parsing the XML file myHashMap = SAXHandler.getHashMap(); // Save hashMap into Session session.setAttribute(Constants.SessionAttributes.VERSION_HIGHLIGHT, myHashMap); } for (int i = 0; i < myHashMap.size(); i++) { if (i > 0) { model.appendRow(); } HighlightInfo highlightInfo = (HighlightInfo) myHashMap.get(new Integer(i)); String featureType = highlightInfo.getFeatureType(); featureType = featureType == null ? "" : featureType; // pre-populate blank images into the model, // overwrite them later if necessary model.setValue("FirstImage", Constants.Image.ICON_BLANK); model.setValue("SecondImage", Constants.Image.ICON_BLANK); model.setValue("ThirdImage", Constants.Image.ICON_BLANK); model.setValue("SupportText", ""); // populate the feature name if (featureType.equals("summary")) { model.setValue( "NameText", new NonSyncStringBuffer("<b>") .append(SamUtil.getResourceString(highlightInfo.getFeatureName())) .append("</b>") .toString()); } else { String heading = "---- "; if (featureType.equals("detail")) { heading = "-- "; } model.setValue( "NameText", new NonSyncStringBuffer(heading) .append(SamUtil.getResourceString(highlightInfo.getFeatureName())) .toString()); model.setValue("SupportText", highlightInfo.getServerVersion()); String[] versionInfoArray = highlightInfo.getVersionInfo().split("###"); for (int j = 0; j < versionInfoArray.length; j++) { String[] versionInfo = versionInfoArray[j].split(","); if (versionInfo[0].equals("version.highlight.versionnumber.50")) { model.setValue("FirstImage", getImage(versionInfo[1])); } else if (versionInfo[0].equals("version.highlight.versionnumber.46")) { model.setValue("SecondImage", getImage(versionInfo[1])); model.setValue("FirstImage", Constants.Image.ICON_AVAILABLE); } else if (versionInfo[0].equals("version.highlight.versionnumber.45")) { model.setValue("ThirdImage", getImage(versionInfo[1])); model.setValue("FirstImage", Constants.Image.ICON_AVAILABLE); model.setValue("SecondImage", Constants.Image.ICON_AVAILABLE); } else { model.setValue("ThirdImage", Constants.Image.ICON_AVAILABLE); model.setValue("FirstImage", Constants.Image.ICON_AVAILABLE); model.setValue("SecondImage", Constants.Image.ICON_AVAILABLE); } } } } }