StatusLineContributionItem image not displaying? [message #160069] |
Fri, 21 November 2003 09:35 |
Eclipse User |
|
|
|
Originally posted by: adamh.us.ibm.com
I have created a custom StatusLineContributionItem similar to the one
found at org.eclipse.ui.texteditor.StatusLineContributionItem. I have one
view using an instance of my StatusLineContributionItem, and the text
assigned to the item appears. Unfortunately, the image I requested does
not get displayed.
I have attached the caller and receiver code, and any help would greatly
be appreciated.
CALLER:
StatusLineContributionItem item = new
StatusLineContributionItem("new.item");
SubStatusLineManager slm = new
SubStatusLineManager(getStatusLineManager());
slm.add(item);
slm.setVisible(true);
...
item.setImage(UIUtility.getImage("myImage"));
item.setText(store.getDescription());
RECEIVER:
public class StatusLineContributionItem extends ContributionItem
implements IStatusField {
/**
* Left and right margin used in CLabel.
*/
private static final int INDENT = 3;
/**
* Number of characters that should fit into the item.
*/
private static final int LENGTH = 14;
/**
* Precomputed label width hint.
*/
private int fixedWidth_ = -1;
/** The label text */
private String text_;
/** The label image */
private Image image_;
/** The status line label widget */
private CLabel label_;
/**
* Creates a new item with the given id.
*
* @param id the item's id
*/
public StatusLineContributionItem(String id) {
super(id);
}
/**
* @see org.eclipse.ui.texteditor.IStatusField#setText(String)
*/
public void setText(String text) {
text_ = text;
if (label_ != null && !label_.isDisposed()) {
label_.setText(text_);
}
}
/**
* @see org.eclipse.ui.texteditor.IStatusField#setImage(Image)
*/
public void setImage(Image image) {
image_= image;
if (label_ != null && !label_.isDisposed()) {
label_.setImage(image_);
}
}
/**
* Creates a status line consisting of a label which is used to hold an
icon and a combo box
*
* @see IContributionItem#fill(Composite)
*/
public void fill(Composite parent) {
label_ = new CLabel(parent, SWT.SHADOW_IN);
StatusLineLayoutData data = new StatusLineLayoutData();
data.widthHint= getWidthHint(parent);
label_.setLayoutData(data);
if (text_ != null) {
label_.setText(text_);
}
}
/**
* Returns the width hint for this label.
*
* @param control the root control of this label
* @return the width hint for this label
*/
private int getWidthHint(Composite control) {
if (fixedWidth_ < 0) {
GC gc = new GC(control);
gc.setFont(control.getFont());
fixedWidth_ = gc.getFontMetrics().getAverageCharWidth() * LENGTH;
fixedWidth_ += INDENT * 2;
gc.dispose();
}
return fixedWidth_;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02860 seconds