Customizing Selection Handles of GEF figures - eclipse-gef

Whenever a figure is selected in the GEF Editor, by default, we see a black,filled rectangle resize handles and a black border outlining the figure. I am implementing a feature where i am explicitly(through code) applying handles to a figure.
Following are some issues i am facing :
1) The handles are not placed close to the figure. They are placed leaving some space between handle and figure
2) I want to change the color filled from black to red
I am new to this kind of development so any examples of customizing these handles will be really use full.
Thanking in advance.

The handles are created by the SelectionHandlesEditPolicy (this is an abstract class, the implementation is done in ResizableEditPolicy). This policy is added by GEF to a child figure when it is added to a parent that has a ConstrainedLayoutEditPolicy (i.e. XYLayoutEditPolicy).
What you can do is inherit from your container's edit policy (i.e. XYLayoutEditPolicy) and override the createChildEditPolicy method to return a SelectionHandlesEditPolicy that you implement that creates the handles the way you want them to look.

Related

How to get correct background and control colors in property pages?

I'm trying to handle background color properly in a dynamically generated property sheet in dynamically generated property pages in win32 api using MFC (though I expect my question is general, and not restricted to MFC, but since my code and examples use it, it's germane to my question anyway).
So we have a:
CPropertySheet
containing multiple
CPropertyPage
I generate the contents of any given page dynamically - from file resources using a custom dialog definition language - all irrelevant other than to say - a list of controls and their coordinates is created within a given page, and the page is resized to accommodate them. This logic is working beautifully.
However, what doesn't work is that the controls and background of each page draws using the dialog default color/brush.
I've tried a number of ways to attempt to force it to draw using the white color/brush that a hard-coded property sheet / page would.
There are two important pieces to this:
Page Background
Control (on the page) background
For #1, I've tried:
acquire the background brush from parent window class (it's dialog bkgrd) (same is true if I do this and ask the tab control)
change the property page to use WS_EX_TRANSPARENT (PreCreateWindow is not called by the framework when generating a page viz PropertySheet::AddPage)
For #2, I've tried:
overriding OnWndMsg / WM_CTLCOLORSTATIC to forward that request to (A) the parent (sheet), and (B) to the tab control (which is what wants the white in the first place).
However, anytime I use any of the above "ask for the background / forward the request" up the chain to either the sheet or the tab control - I get the dialog background color, never the white I'd expect.
Using Spy64, I can see that for a fully hardcoded property sheet / page - that the only discernable differences I can see is that the dialog window created in AddPage (or its moral equivalent) has WS_CHILD instead of mine which has WS_POPUP (the rest of the styles appear to be the same, such as WS_VISIBLE|DS_3DLOOK|DS_FIXEDSYS|DS_SETFONT|DS_CONTROL and WS_EX_CONTROLPARENT.
So, other than the WS_CHILD, I see no significant differences from what I'm creating and from another property sheet that works properly from a standard resource (i.e. hard coded).
I'm also flummoxed as to how this works normally anyway - since forwarding things like the ctrlcolor message doesn't respond correctly - and asking for the windows background colors similar doesn't - then how is it in a standard case the background colors of controls and pages comes out as white, and not dialog background?
Any ideas or help would be appreciated - I'm kind of running out of ideas...
When Visual Styles were added in Windows XP they really wanted to show off this new feature so they made the tab background a gradient (really a stretched image) instead of a single color and this caused problems in old applications that did custom drawing with the dialog brush as the background.
Because of this, only applications with a comctl32 v6 manifest got the new look but there was a problem; old propertysheet shell extensions would load in new applications (including Explorer) and things would look wrong.
To work around this they also require you (or your UI framework) to call EnableThemeDialogTexture(.., ETDT_ENABLETAB) to get the correct tab page look.
As if things are not tricky enough, there is a undocumented requirement that you also need a button or a static control on the page!
If you have custom controls they have to call DrawThemeParentBackground when you draw if they are partially transparent.
Turns out my old code had defined an ON_WM_ERASEBKGND handler - and removing that (and all of my above attempts) makes it work.
So simply doing NOTHING is the correct answer. D'oh!!!
I'm leaving my shame here in case someone else trips on this! [Whoops!]
(Still interested if anyone has deeper insight into how this mechanism works under the hood)

Fast way to obtain underlying java component for controls in matlab

I'd like to obtain a reference to underlying java components for the controls I have in my GUI so as to customize their appearance.
I know about findjobj from Yair Altman which works really well:
myLink = uicontrol('String', '<html><u>Button that looks like a link.</u></html>');
jObj = findjobj(myLink);
jObj.setContentAreaFilled(0);
Unfortunately this solution is quite slow when there are a "lot" of controls to customize (because it has to parse the full hierarchy of objects in the figure and this for each control to customize).
Moreover the figure must be visible (else controls are not instantiated and java references cannot be found). Plus it must be moved of screen to avoid users to touch it while findjobj is running (sometimes make things crash because findjobj somehow relies on position of controls to find them while internally calling also drawnow which updates positions) ...
On some machines, even with only a few controls to customize, it can be up to 10 seconds before to have the figure to appear (most of the time is spent in findjobj).
I also know about uicomponent again from Yair Altman to directly create controls and get the handle to the underlying java component in one shot:
[myLink, jObj] = uicomponent('Style', 'JButton', 'String', '<html><u>Button that looks like a link.</u></html>');
jObj.setContentAreaFilled(0);
Unfortunately here the parent property can only be a figure and of course my controls are placed in gui layout containers to handle resizing and many other things nicely (and gui layout containter are not valid hg-handles for uicomponent to work)...
So was wondering if there could be any other fast solution to get underlying java components for controls in my GUI ? ... NB: I mainly only need to have buttons that looks like hyperlinks or animated gif (i.e. borderless buttons with htlm text/img inside).
This isn't a direct answer to your question, but I've built several GUIs that are based around GUI Layout Toolbox and that contain Java swing components. I typically arrange things so that the GUI Layout container (HBox, VBox, Grid etc) has a uipanel as a child, and then the uipanel has the Java swing component as a child.
You can typically parent a Java component to the uipanel in exactly the same way as parenting it to a figure (unlike a GUI Layout container), and it's no problem to parent a uipanel to a GUI Layout container.
So, for example, to add a button with a dropdown menu (no menu items, so it won't do anything, but just to illustrate):
>> u = uipanel;
>> ddbuttonclass = 'com.mathworks.widgets.DropdownButton';
>> ddbutton = javaObjectEDT(ddbuttonclass);
>> [jddbutton, hjddbutton] = javacomponent(ddbutton, [30,30, 60, 30], u);
Now you can parent u to a GUI Layout container, and you get all the nice resizing.
I'm not that familiar with Yair's uicomponent, but if you can get the handle of the java component somehow, you should be able to use something like the above.
PS If you want his direct input, #Yair is sometimes active on SO - he may get notified if I mention his name. If you're doing a lot of Java/MATLAB GUI work, I'd also recommend buying his book.
UICOMPONENT was designed to be a direct replacement of both Matlab's built-in UICONTROL and JAVACOMPONENT functions. This means that you can directly place a UICOMPONENT within panels, even those created by the GUI Layout toolbox.
You might need to cast the layout panel's handle to double (double(hPanel)) on some Matlab releases but that's about it:
[myLink, jObj] = uicomponent('Parent',hPanel, ...);
[myLink, jObj] = uicomponent('Parent',double(hPanel), ...); % on some Matlab releases
You could also use JAVACOMPONENT directly, but it doesn't really give you any benefits over UICOMPONENT, since UICOMPONENT uses JAVACOMPONENT under the hood and also adds important functionality (such as ensuring the component is placed on the EDT, and merging important properties from the Matlab wrapper).
As for FINDJOBJ, you can speed it up a bit by specifying the target object class using the 'class' parameter. But if your figure contains hundreds of controls it might still be slow. To this day, close to 10 years after my first version of FINDJOBJ, I still do not know of a direct way to get the underlying Java object. I assume there is one that is used internally by MathWorks, but I do not know it.
As #SamRoberts mentioned, this is all discussed in my book...

How to place a windowless control on top of a windows control?

Say, I have an Image control (which seems to be a window-less control) and I want to make sure that it is on top of a TextBox. No matter what I do, the Image control will not appear on top of the Text box.
Is there a way?
P.S. I know I can use a PictureBox, but it does not support transparency, thus I must have the Image control.
There is no way to place an image control over a normal textbox as they are drawn onto the form itself so will always be below any other windowed components.
If you have VB6 installation media there are drawn (windowless) versions of controls including a TextBox you can use that will (probably) do what you want; http://support.microsoft.com/kb/184687
A custom usercontrol of some kind if probably better .. what is it exactly you want to overlay the textbox with?
The Image Control is considered a graphical control, like shapes, so it is always inferior to text controls. If you really want a transparent image, you can use a Microsoft 2.0 Form instead(only if you have it). Images there can be on top of textboxes, and you can make it transparent by setting the Backstyle to Transparent(0).
Completely different approach to my other answer (hence the seperate Answer), but you can set AutRedraw and ClipControls on your Form to false and it will allow the Image control to render on the same layer as a windowed control. You can get some flakey redrawing in some cases but for a quick solution you could try it.
http://msdn.microsoft.com/en-us/library/aa733621(v=vs.60)
I've created a tranparent overlay control to add a kind of annotation layer on top of a VB6 app. I'll attempt to describe it from memory, and if that doesn't provide enough information then you can post back and I'll try to dig up the code.
First, add a new USerControl to you application. Give it a name like ImageEx, PictureEx, or TransparntImage. There are several properties that you will need to use. Ensure the control is Windowed, so it can sit on top of other windowed controls. Locate the MaskColor property and set it to Cyan (or whatever color you elect to use to indicate a tranparent area. There might be an addition property enable the masking behavior, just browse the properties. Set the control background color to that of the MaskColor. At this point you have an invisible control. In my control I painted on top of the surface for annotations, but you can PaintPicture or maybe even set the image property for a really simple approach.
Of course, to make this a re-usable control, you will want to code in your own properties that allow the MaskColor and image, etc to be set so that you can the drop one of these on any form you want.
Some links:
MaskColor Property
MackPicture Property
1) Remove all your textboxes , labels and ... (But memorize their name and location in the form)
2) Go to (project > components) and mark the (Microsoft Forms 2.0 Object Library) then click ok
3) Now you can see new controls under your default controls in your toolbox...
4) Use its textbox and label controls instead of the default controls
5) Right click on your Image Control then click (Bring To Front)

chrome-like status bar in qt

I'm not big on creating GUI's, and generally my philosophy is: I don't create them, or I make them as simple as possible (and convince myself that it's better for usability :)
For my current project, I'm using Qt from Python (PyQt), and I want to start adding some GUI elements without cluttering the interface.
My idea is to create these elements as sort of floating-shaped-widgets that only appear when necessary; pretty much like the status bar (and find bar) in chrome.
Is there any standard api that enables creating this kind of interface?
This is not very complicated. If you want something like the status bar in Chrome you just need to have a QFrame at the bottom of your windows and show or hide it when you need it.
You have 2 options here, add is as part of your window layout so all the items move up when it is shown. Or you can have if floating, so it will be shown on top of the items. For the second option you need to create the QFrame with the window as parent and then in the window resizeEvent set the geometry of the frame.
This is an example of the second approach:
void MyWindow::resizeEvent(QResizeEvent* event)
{
frame.setGeometry(0, this->height() - frame.sizeHint().height(), this->width(), frame.sizeHint().height());
}
I hope this helps.

Talking Among GWT Panels using UIBinder Layout

New to GWT here...
I'm using the UIBinder approach to layout an app, somewhat in the style of the GWT Mail sample. The app starts with a DockLayoutPanel added to RootLayoutPanel within the onModuleLoad() method. The DockLayoutPanel has a static North and a static South, using a custom center widget defined like:
public class BigLayoutWidget extends ResizeComposite {
...
}
This custom widget is laid out using BigLayoutWidget.ui.xml, which in turn consists of a TabLayoutPanel (3 tabs), the first of which contains a SplitLayoutPanel divided into WEST (Shortcuts.ui.xml) and CENTER (Workpanel.ui.xml). Shortcuts, in turn, consists of a StackLayoutPanel with 3 stacks, each defined in its own ui.xml file.
I want click events within one of Shortcuts' individual stacks to change the contents of Workpanel, but so far I've only been able to manipulate widgets within the same class. Using the simplest case, I can't get a button click w/in Shortcuts to clear the contents of Workpanel or make WorkPanel non-visible.
A few questions...
Is ResizeComposite the right type of class to extend for this? I'm following the approach from the Mail example for TopPanel, MailList, etc, so maybe not?
How can I make these clicks manipulate the contents of panels in which they do NOT reside?
Are listeners no longer recommended for handling events? I thought I saw somewhere during compilation that ClickHandlers are used these days, and the click listener "subscription" approach is being deprecated (I'm mostly using #UiHandler annotations)
Is there an easy way to get a handle to specific elements in my app/page? (Applying the "ID" field in the UI.XML file generates a deprecation warning). I'm looking for something like a document.getElementById() that get me a handle to specific elements. If that exists, how do I set the handle/ID on the element, and how can I then call that element by name/id?
Note that I have the layout itself pretty well nailed; it's the interaction from one ui.xml modularized panel to the next that I can't quite get.
Thanks in advance.
If you don't have a use for resizing events than just use Composite
What you want is what the GWT devs called message bus (implemented as HandlerManager). You can get a nice explanation in the widely discussed (for example, on the GWT Google Group, just search for 'mvp') presentation by Ray Ryan from Google I/O 2009 which can be found here. Basically, you "broadcast" an event on that message bus and then a Widget listening for that event gets the message and does its stuff.
Yep, *Handlers are the current way of handling events - the usage is basically the same so migration shouldn't be a problem (docs). They changed it so that they could introduce custom fields in the future, without breaking existing code.
If you've set an id for any DOM element (for Widgets I use someWidget.getElement().setId(id), usually in combination with DOM.createUniqueId()) you can get it via GWT.get(String id). You'll get then a RootPanel which you'll have to cast to the right Widget class - as you can see it can get a little 'hackish' (what if you change the type of the Widget by that id? Exceptions, or worse), so I'd recommend sticking with MVP (see the first point) and communicating via the message bus. Remember however, that sometimes it's also good to aggregate - not everything has to be handled via the message bus :)
Bottom line is I'd recommend embracing MVP (and History) as soon as possible - it makes GWT development much easier and less messy :) (I know from experience, that with time the code starts to look like a nightmare, if you don't divide it into presentation, view, etc.)

Resources