IntelliJ plugin: How to show multiline inline text - swing

I want to show multiline inline text inside the IntelliJ editors and I have no clue how to implement it and there is no good documentation or examples in the wild.
I try to use the EditorCustomElementRenderer Interface.
I use the InlayModel.addBlockElement to add/show them.
I can display an inline string just fine, but I want the string to automatically use multiple lines if it is too long.
I try to use a JBTextArea to do it, but the problem is that I have no idea how to paint the textArea, in the paint function below you can see that I use drawString, but I need to draw the whole textArea.
Is this somehow achievable?
My class:
public class MyClass implements EditorCustomElementRenderer {
private JBTextArea textArea;
private Color color;
public MyClass(final String problemMessage, Color color) {
textArea = new JBTextArea(problemMessage);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
this.color = color;
}
#Override
public void paint(#NotNull Inlay inlay, #NotNull Graphics graphics, #NotNull Rectangle targetRegion, #NotNull TextAttributes textAttributes) {
Editor editor = inlay.getEditor();
EditorColorsScheme colorsScheme = editor.getColorsScheme();
graphics.setFont(colorsScheme.getFont(EditorFontType.PLAIN));
graphics.setColor(color);
// todo how to draw the textArea instead of the string?
graphics.drawString(textArea.getText(), targetRegion.x, targetRegion.y + editor.getAscent());
}
I tried to find a solution in the "documentation" of the IntelliJ platform and I searched the code for all implementations of EditorCustomElementRenderer but that did not help.

Related

Vaadin Spring Navbar

I am trying to add a navbar (just like bootstrap's) for a Spring application but am not getting the nav menu to appear on the web page!
Can anyone please tell me what's wrong here?
Below is my code:
private Panel viewContainer;
private HorizontalLayout navbar;
private Button btnHome;
private Button btnNested;
private Button createNavigationButton(String caption, final String viewName) {
Button button = new Button(caption);
button.addStyleName(ValoTheme.BUTTON_SMALL);
// If you didn't choose Java 8 when creating the project, convert this
// to an anonymous listener class
button.addClickListener(event -> getUI().getNavigator().navigateTo(
viewName));
return button;
}
#Override
protected void init(VaadinRequest request) {
final VerticalLayout root = new VerticalLayout();
root.setSizeFull();
navbar = new HorizontalLayout();
navbar.setWidth("100%");
navbar.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
root.addComponent(navbar);
final Label brand = new Label("Nested demo");
brand.addStyleName(ValoTheme.LABEL_H1);
brand.addStyleName(ValoTheme.LABEL_NO_MARGIN);
navbar.addComponent(brand);
navbar.setComponentAlignment(brand, Alignment.MIDDLE_LEFT);
navbar.setExpandRatio(brand, 1);
btnHome = new Button("Home", FontAwesome.HOME);
btnHome.addStyleName(ValoTheme.BUTTON_BORDERLESS);
navbar.addComponent(btnHome);
btnNested = new Button("nested", FontAwesome.COFFEE);
btnNested.addStyleName(ValoTheme.BUTTON_BORDERLESS);
navbar.addComponent(btnNested);
viewContainer = new Panel();
viewContainer.setSizeFull();
root.addComponent(viewContainer);
root.setExpandRatio(viewContainer, 1);
}
Any hint is much appreciated.
Thanks
Henri's comment is almost certainly the correct answer.
Judging by the init(VaadinRequest) code you're using a UI class.
Without setContent(some components with visible stuff in them);
you won't see anything.
'you won't see anything' happens a lot in Vaadin when you're attempting new things, or doing proof of concept stuff. IMHO it's always a good practice to start with really dumb UI stuff e.g. setContent(new Label("TODO - implement this content-xxx"));
Using browser dev-tools is also a great idea. A quick select-element should show you that the UI div is empty, and allow you to start diagnosing.
TL;DR :-
UI is a ComponentContainer, so you need to - either
setContent(myLayoutWithStuff);
or
getContent().addComponent(myStuff);
to show someStuff.

How to display Orchard shape only once?

I have a common shape that renders some HTML code to display an error dialog.
The HTML code needs to be included only once throughout the whole web site. For scripts and styles Orchard provides the Script.Include() and Style.Include() methods.
I wonder whether there is something similar for HTML code, any ideas?
So many options to do this
Can you add your code to Layout.cshtml in the theme
Create a new widget and attach the shape field then create it on the default layer (so on all pages) with the name of your shape in the shape field
Add the shape in a filter, or anywhere else you have access to the WorkContext :)
Code written from memory, may not compile
using System.Linq;
using System.Web.Mvc;
using Orchard;
using Orchard.DisplayManagement;
using Orchard.Mvc.Filters;
using Orchard.UI.Admin;
public class MyFilter : FilterProvider, IResultProvider {
private readonly dynamic _shapeFactory;
private readonly WorkContext _workContext;
public MyFilter(WorkContext workContext, IShapeFactory shapeFactory)
{
_workContext = workContext;
_shapeFactory = shapeFactory;
}
public void OnResultExecuting(ResultExecutingContext filterContext)
{
// should only run on a full view rendering result
if (!(filterContext.Result is ViewResult)) return;
// front end only
if (AdminFilter.IsApplied(new RequestContext(_workContext.HttpContext, new RouteData()))) return;
var body = _workContext.Layout.Body;
body.Add(_shapeFactory.MyShape());
}
public void OnResultExecuted(ResultExecutedContext filterContext) {}
}

custom CellRenderer lose it's style when embeded in the TileList

I have defined a renderer with some Labels, TextInputs and Buttons and call "setStyle" to set their colors and font when i create it.
If i add the renderer in some normal panels, the style works fine.
If i put it in a TileList object, the style will be lost
code like this:
public class MyRenderer extends UIComponent implements ICellRenderer
{
public function MyRenderer()
{
private var m_label = new Label();
m_label.setStyle("textFormat", someTextFormat);
addChild(m_label);
}
}
var m_tileList:TileList = new TileList();
m_tileList.setStyle("cellRenderer", MyRenderer)
m_tileList.addItem({});//the renderer showed but the "someTextFormat" lose
It's definitely more difficult finding information on how to use the fl.controls components since Adobe came out with CS 6. The information on how to use stules with them is here.
Try something like
StyleManager.setComponentStyle(MyRenderer, "textFormat", someTextFormat);

How do you manage this inheritance problem?

Lets's say you have 2 classes ToolBar and DrawingToolBar. ToolBar is to serve as a base class for various other toolbars, for various tools. ToolBar handles the basic 'toolbar-y' stuff like opening, closing, dragging, dropping, etc. The DrawingToolBar adds functionality that is specific to a particular tool - tool-specific buttons, etc.
public class ToolBar extends Sprite {
public var closeBtn:Sprite
public function ToolBar():void {
addChild(closeBtn)
closeBtn.addEventListener(MouseEvent.CLICK, closeBtn_onClick)
}
protected function closeBtn_onClick(e:Event):void {
close()
}
public function open():void {
// blah
}
public function close():void {
// blah
}
}
and:
public class DrawingToolBar extends ToolBar{
public var penBtn: Sprite
public var paintbrushBtn: Sprite
public var colorPicker: ColorPicker
public function DrawingToolBar():void {
super()
}
public function getColour():int {
return colorPicker.color;
}
}
Now, we also have another 2 classes - Tool and DrawingTool. Again, Tool is a base class for various tools (incl. DrawingTool). If I make a ToolBar member in Tool (typed as ToolBar), we can delegate common tasks, eg. when the Tool is enabled, it adds the ToolBar to the stage, etc. The DrawingTool can instantiate the ToolBar as a DrawingToolBar so the correct library asset is used (but the instance is still typed as ToolBar).
public class Tool {
public var toolBar:ToolBar
public function Tool():void {
initToolBar()
}
protected function initToolBar():void {
addChild(toolBar)
}
}
and:
public class DrawingTool extends Tool {
public function DrawingTool():void {
super()
}
override protected function initToolBar():void {
toolbar = new DrawingToolBar() // this is probably very naughty
super.initToolBar()
}
public function getColor():int {
return toolBar.getColor() // this fails because toolBar is type as ToolBar not DrawingToolBar
}
}
The problem comes when, in DrawingTool I want to call a method of DrawingToolBar. Because the toolbar is typed as ToolBar, I can't call methods of DrawingToolBar on it. What do I do?
cast it every time I want to call a method of DrawingToolBar?
create a member in DrawingTool (eg. var drawingToolBar: DrawingToolBar), instantiate that and then make toolBar = drawingToolBar?
The first seems clunky, I don't even know if it would work. The second seems better but it feels a bit 'wrong'.
Is there another way? Or am I mis-using inheritance here?
You are probably mixing too many functionnalities into your toolbar. If you think MVC, you are missing a Model.
More precisely, the color picker should not be a property of your toolbar. The color picker is a property of your tool. Each drawing tool should be self contained and have its own color picker. If all drawing tools need to share the same color, you'll need a Drawing model that is shared by all drawing tools.
I would also change the relation between the Toolbar and its tools in the other direction. A toolbar has tools, but the tools themselves should be self contained and not have a reference to their containing toolbar.
The Java / Swing model is very clean on how it works with toolbars. You could get some inspiration from it : http://download.oracle.com/javase/tutorial/uiswing/components/toolbar.html

Titled frame panel for GWT (using FIELDSET and LEGEND html tags)

I'm trying to create a titled border frame in GWT, which results in this:
This can be done using HTML fieldset and legend tags, such as
<fieldset>
<legend>Connection parameters</legend>
... the rest ...
</fieldset>
I want to create a custom widget in GWT that implements that. I managed to do that, but the problem is that events that happen inside the widget (button click etc) does not get fired although I have added the handler.
My implementation of the widget is as follows:
public class TitledPanel extends Widget {
private Element legend;
private Widget content = null;
public TitledPanel() {
Element fieldset = DOM.createFieldSet();
legend = DOM.createLegend();
DOM.appendChild(fieldset, legend);
setElement(fieldset);
}
public TitledPanel(String title) {
this();
setTitle(title);
}
#Override
public String getTitle() {
return DOM.getInnerHTML(legend);
}
#Override
public void setTitle(String html) {
DOM.setInnerHTML(legend, html);
}
public Widget getContent() {
return content;
}
public void setContent(Widget content) {
if (this.content != null) {
DOM.removeChild(getElement(), this.content.getElement());
}
this.content = content;
DOM.appendChild(getElement(), content.getElement());
}
}
Do I need to extend Composite, or need to manually reroute the events, or is there other ways?
I think you're looking for CaptionPanel:
A panel that wraps its contents in a border with a caption that appears in the upper left corner of the border. This is an implementation of the fieldset HTML element.
I think the problem here is that you just call DOM.appendChild - this doesn't cause the TitledPanel to adopt the Widget. The normal course of action is that you extend Composite and then call initWidget(Widget widget) - inside the hood it calls widget.setParent(this);, which in turn makes the parent adopt this widget and attach it to the browser's document. However com.google.gwt.user.client.ui.Widget.setParent(Widget) is only package-visible so you can't call it from your code (after, for example, DOM.appendChild).
I'd recommend reading Widget Best Practices / Widget Building, especially the Clean up after yourself and/or look at the source code for some GWT Widgets, to get the idea how the GWT sees custom widget creation.
And, as Robert suggested, CaptionPanel is the safer route :)