This is a followup to Items decorations in a TreeViewer: I have a TreeView with my own Objects. I already have a LabelProvider that supplies Icons and Texts. Now I want to decorate the images with other images depending on some conditions. How can I do this? The referenced question uses ComposedImage, which I suppose is org.eclipse.emf.edit.provider.
Is there a way to do this with SWT/JFace in Eclipse 4.3?
I already tried using a ILightweightLabelDecorator (using the idea from the FAQ), but gave up wrapping that round my LabelProvider.
ILightweightLabelDecorator is really the best way to do this. Wrap your label provider with a DecoratingLabelProvider as described in this answer: Using a ILightweightLabelDecorator decorator Use the org.eclipse.ui.decorators extension point to declare your lightweight decorator.
you may want to look at org.eclipse.jface.viewers.DecorationOverlayIcon which is basically used by decoration providers.
Related
I have a Swing custom control which serves an almost identical function to a JLabel. It's not accessible by default for people who use assistive technology, like a screen reader. I'm working on the Megamek GitHub Project, and trying to figure out how to associate the PMSimpleLabel class with other objects, as in the JLabel class's setLabelFor method.
The approach taken so far seems to be to more or less ape the JLabel's accessibility implementation. I'm not sure if this is the right way to go about it, there seem to be some elements in the latter I'm not understanding.
The problem turns out to be largely because of the custom components. The AccessibleJComponent class has a fallback mechanism to name controls which don't ohterwise have accessible names, but this is hard-coded to look for a JLabel and not a custom label class.
There are a few work-arounds for this, such as modifying the get/setAccessibleName methods, or switching to using the accessible description instead.
The solution in the long term is probably to use regular Swing components where possible
I have been writing some basic code for an application I am designing. I have learned the basics and gotten some simple database connection working with RPC calls etc. What I need to do now and am completely lost (as I am traditionally a c# developer with windows forms).
In c# if I wanted a new form I would just create it, and then call the show method.
How does one create multiple pages in GWT, and switch between them?
Thanks in advance,
Chris
The simplest way would be to
Make a new java class (GwtHome.java, GwtHelp.java etc)
Extend these classes by using the Composite class
Make the equivalent of a Master Page and add it to the rootPanel as a class with the appropriate headers, menu, footer and Content Placeholder (Could be any of the AbsolutePanel, VerticalPanel, HorizontalPanel objects provided by the GWT Framework)
By clicking on the menu clear the Placeholder and add the appropriate object of GwtHome, GwtHelp etc.
After getting aquanted with the above procedure, you might want to break up the code in many files using a design pattern as suggested by Andrei.
Simply clear the root panel (RootPanel.get().clear()) and add the widget for your new "page", the same way you added your first one.
If you're using LayoutPanels, do RootLayoutPanel.get().clear() instead.
Look at Activities and Places design pattern: https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
I highly recommend it for a multipage GWT app. It explains pretty well how you create different "views", that are driven by their "activities", and tied to specific "places" (pages) that users can navigate.
Typically you use a LayoutPanel as your "page" container that occupies the entire available browser window. You split this LayoutPanel into 2-3 layers (zones), like top menu, side menu, main area. Each area contains one widget, usually a ScrollPanel, FlowPanel, or HtmlPanel. Then you use different widgets or HTML inside each of these widgets to display whatever you need. You may also create your own composite widgets that you can reuse in different pages.
Tooltips in my application can be quite long, therefore I'd like them to have line breaks.
I don't want to use html as I'd prefer to set a (max) width of my tooltips instead and have the line breaks dynamically.
In the accepted answer the this similar question Multi-line tooltips in Java? I read about JMultiLineToolTip. Unfortunately the provided link doesn't work anymore and there are many different JMultiLineToolTip out there. Therefore my two questions:
Which JMultiLineToolTip is a good one to use?
How can I use such a class to represent all of the tooltips in my application?
EDIT: as everyone seems to recommend the use of html, is there a way to define the width of my tooltip in pixels (or some other unit than number of characters) using html?
If you are not afraid of extending swing tool tip, you can create your own JMultiLineToolTip:
Extend JTooltip In the extended Tool tip component implementation,
set a custom tool tip UI In customUI implementation
Implementpaint() method to write given string in multi line
Here is an example - it shows how to use it as well
However, to answer your questions:
Which JMultiLineToolTip is a good one to use?
Use <html>
How can I use such a class to represent all of the tooltips in my application?
Per compopnent, it is easy but tedious to achieve as you will have to override creatreToolTip() API. But if you want to change it globally, you may:
(i)Simple way - Register your custom tooltip UI with the UIManager at the beginning of your execution.
UIManager.put( "ToolTipUI", "SeNormToolTipUI" );
UIManager.put( "SeNormToolTipUI",Class.forName( multiLineToolTipUIClassName ) );
(ii) complex way
You will have to start implementing your own look and feel. In the look and feel implementation, you would provide defaults for ToolTipUI as your UI implementation and then set that look and feel to the application you are running. For instance take a look at the MetalLookAndFeel implementation. You may just extend that part and implement your on lnf.
So, it is better to use <html>
1) Html is easiest of ways for plain JToolTip
2) use JWindow(un_decorated JDialog) with JTextArea, better would be JTextPane (supporting stylled text),
the disadvantage is you have to manually set window to the Point, you have to manually set for setInitialDelay and setDismissDelay (Swing Timer), setVisible(true/false)
the advantage is that you using full manageable top level container with definitions for own parent
3) I use JLabel with Html formatted and stylled text added to the GlassPane, notice easiest alternative is use non_opaque JLayeredPane (Java6) or JLayer (Java7)
jframe to default show rectangle.
i want to know if it possible we show it similar to a circle?
and how?
It is possible to have non-rectangular JFrames. The simple way to do this is to use AWTUtilities.setWindowShape(Window, Shape). Read the page below for more details.
Someone else mentioned that it's possible to do this using the Robot class, but that unnecessary. Java now supports this natively where possible.
http://today.java.net/pub/a/today/2008/03/18/translucent-and-shaped-swing-windows.html
This article describes a clever hack that allows you to implement non-rectangular and translucent frames. You can apparently do it (non-portably of course) using native code hacks.
I will explain my question clearly.
I need to zoom in/zoom out the world map.
When I click on the particular country in map, control should redirected to new page with respective the country.
I dont have any idea about this in java. Please explain the steps to acheive the above task.
As the question is quite general, here is a general answer: Zooming often means, that you want to display a certain percentage of somethin, and not the whole, where your size of the displayed will not change.
But in your case it seems more like a "find a mouse click in a polygon" thing. So you have to add a selection/click listener to whatever widgets you use (Swt? swing? ....?) where you change what your program renders.
It sounds like you may be trying to reinvent the wheel. Google etc have already solved this problem rather well. It might be better to incorporate an existing solution into your application. Have a look at GoogleEarth inside Java Swing.