Bug 178054 - [api] Make HTMLPrinter api
Summary: [api] Make HTMLPrinter api
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2007-03-19 09:48 EDT by Jon Shavor CLA
Modified: 2018-01-29 17:19 EST (History)
5 users (show)

See Also:


Attachments
derived from HTMLPrinter (6.89 KB, application/octet-stream)
2007-03-19 09:50 EDT, Jon Shavor CLA
no flags Details
dervied from Strings.java (8.10 KB, application/octet-stream)
2007-03-19 09:51 EDT, Jon Shavor CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Shavor CLA 2007-03-19 09:48:19 EDT
Build ID: eclipse-SDK-3.2.2-win32.zip

Steps To Reproduce:
The attached are derivation work because of restrictive access to private classes.    The attached file is provided
to provide a means where customers can access the source so that the EPL is upheld, and perhaps encourage the powers that be loosen restrictions so the class can be subclassed.

More information:
Comment 1 Jon Shavor CLA 2007-03-19 09:50:44 EDT
Created attachment 61279 [details]
derived from HTMLPrinter
Comment 2 Jon Shavor CLA 2007-03-19 09:51:16 EDT
Created attachment 61280 [details]
dervied from Strings.java
Comment 3 Dani Megert CLA 2009-07-16 02:14:39 EDT
I'm marking this as WONTFIX because
- we don't make that particular class API as a whole, rather we would make
  BrowserInformationControl (bug 218482) and/or HTML2TextReader (bug 241896).
- this bug contains two different proposed APIs from different components.
Comment 4 Mickael Istria CLA 2018-01-24 09:38:49 EST
@Ed: you recently expressed the wish for HTMLPrinter to be API. As per comment 2, could you please elaborate why you need it in a way that BrowserInformationControl or HTML2TextReader don't help? I imagine if there are decent reasons, we can reopen this issue.
Comment 5 Ed Merks CLA 2018-01-24 10:13:31 EST
Here is what each project is doing.

EMF and Oomph do this:

      protected void computeInformation()
      {
        MouseEvent hoverEvent = getHoverEvent();
        Event event = new Event();
        event.x = hoverEvent.x;
        event.y = hoverEvent.y;
        if (shouldCreateToolTip(event))
        {
          StringBuffer buffer = new StringBuffer(text);
          String styleSheet = getStyleSheet();
          FontData fontData = JFaceResources.getFontRegistry().getFontData(getSymbolicFont())[0];
          styleSheet = HTMLPrinter.convertTopLevelFont(styleSheet, fontData);
          HTMLPrinter.insertPageProlog(buffer, 0, foregroundColor == null ? null : foregroundColor.getRGB(), backgroundColor == null ? null : backgroundColor.getRGB(), styleSheet);
          HTMLPrinter.addPageEpilog(buffer);
          final String html = buffer.toString();

          setInformation
            (new BrowserInformationControlInput(null)
             {
               @Override
               public String getHtml()
               {
                 return html;
               }

               @Override
               public String getInputName()
               {
                 return "";
               }

               @Override
               public Object getInputElement()
               {
                 return text;
               }
             },
             currentCell.getBounds());

          currentCell = null;
        }
        else
        {
          setInformation(null, null);
        }
      }

JDT does this:

	protected void doSetInput(Object input) {
		String javadocHtml;
		if (input instanceof String) {
			javadocHtml= (String) input;
		} else {
			StringBuffer buffer= new StringBuffer();
			HTMLPrinter.insertPageProlog(buffer, 0, null, fBackgroundColorRGB, fgStyleSheet);
			HTMLPrinter.addPageEpilog(buffer);
			javadocHtml= buffer.toString();
		}
		fOriginalInput= javadocHtml;

		if (fInputSelectionProvider != null) {
			IJavaElement inputElement= getOrignalInput();
			StructuredSelection selection= inputElement == null ? StructuredSelection.EMPTY : new StructuredSelection(inputElement);
			fInputSelectionProvider.setSelection(selection);
		}

		if (fOpenBrowserAction != null)
			fOpenBrowserAction.setEnabled(input != null);

		if (fIsUsingBrowserWidget) {
			if (javadocHtml != null && javadocHtml.length() > 0) {
				boolean RTL= (getSite().getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0;
				if (RTL) {
					StringBuffer buffer= new StringBuffer(javadocHtml);
					HTMLPrinter.insertStyles(buffer, new String[] { "direction:rtl" } ); //$NON-NLS-1$
					javadocHtml= buffer.toString();
				}
			}
			fBrowser.setText(javadocHtml);
		} else {
			fPresentation.clear();
			Rectangle size=  fText.getClientArea();

			try {
				javadocHtml= fPresenter.updatePresentation(fText, javadocHtml, fPresentation, size.width, size.height);
			} catch (IllegalArgumentException ex) {
				// the javadoc might no longer be valid
				return;
			}
			fText.setText(javadocHtml);
			TextPresentation.applyTextPresentation(fPresentation, fText);
		}
	}

and this:

	protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion,
			XtextBrowserInformationControlInput previous) {
		String html = getHoverInfoAsHtml(element);
		if (html != null) {
			StringBuffer buffer = new StringBuffer(html);
			ColorRegistry registry = JFaceResources.getColorRegistry();
			RGB fgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
			RGB bgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
			if (fgRGB != null && bgRGB != null) {
				HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, getStyleSheet());
			} else {
				HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
			}
			HTMLPrinter.addPageEpilog(buffer);
			html = buffer.toString();
			return new XtextBrowserInformationControlInput(previous, element, html, labelProvider);
		}
		return null;
	}

Xtext does this:

	protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion,
			XtextBrowserInformationControlInput previous) {
		//TODO remove this check when the typesystem works without a java project
		if (isValidationDisabled(element))
			return null;
		EObject objectToView = getObjectToView(element);
		if(objectToView == null || objectToView.eIsProxy())
			return null;
		String html = getHoverInfoAsHtml(element, objectToView, hoverRegion);
		if (html != null) {
			StringBuffer buffer = new StringBuffer(html);
			ColorRegistry registry = JFaceResources.getColorRegistry();
			RGB fgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
			RGB bgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
			if (fgRGB != null && bgRGB != null) {
				HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, getStyleSheet());
			} else {
				HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
			}
			HTMLPrinter.addPageEpilog(buffer);
			html = buffer.toString();
			IJavaElement javaElement = null;
			if (objectToView != element && objectToView instanceof JvmIdentifiableElement) {
				javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) objectToView);
			}
			return new XbaseInformationControlInput(previous, objectToView, javaElement, html, labelProvider);
		}
		return null;
	}

The methods HTMLPrinter do the job. I think adding static methods to some class that is not internal would suffice, leaving the internal class where it is would suffice.
Comment 6 Matthias Becker CLA 2018-01-29 11:56:16 EST
I would also like to see the static methods of HTMLPrinter as API.
We also use them in SAP's ABAP Development Tools