use of org.eclipse.jface.resource.DeviceResourceException in project statecharts by Yakindu.
the class XtextDirectEditManager method getZoomLevelFont.
/**
* This method obtains the fonts that are being used by the figure at its
* zoom level.
*
* @param gep
* the associated <code>GraphicalEditPart</code> of the figure
* @param actualFont
* font being used by the figure
* @param display
* @return <code>actualFont</code> if zoom level is 1.0 (or when there's an
* error), new Font otherwise.
*/
private Font getZoomLevelFont(Font actualFont, Display display) {
Object zoom = getEditPart().getViewer().getProperty(ZoomManager.class.toString());
if (zoom != null) {
double zoomLevel = ((ZoomManager) zoom).getZoom();
if (zoomLevel == 1.0f)
return actualFont;
FontData[] fd = new FontData[actualFont.getFontData().length];
FontData tempFD = null;
for (int i = 0; i < fd.length; i++) {
tempFD = actualFont.getFontData()[i];
fd[i] = new FontData(tempFD.getName(), (int) (zoomLevel * tempFD.getHeight()), tempFD.getStyle());
}
try {
FontDescriptor fontDescriptor = FontDescriptor.createFrom(fd);
cachedFontDescriptors.add(fontDescriptor);
return getResourceManager().createFont(fontDescriptor);
} catch (DeviceResourceException e) {
Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "getZoomLevelFonts", // $NON-NLS-1$
e);
Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "getZoomLevelFonts", // $NON-NLS-1$
e);
return actualFont;
}
} else
return actualFont;
}
use of org.eclipse.jface.resource.DeviceResourceException in project statecharts by Yakindu.
the class XtextDirectEditManager method getScaledFont.
/**
* Given a label figure object, this will calculate the correct Font needed
* to display into screen coordinates, taking into account the current
* mapmode. This will typically be used by direct edit cell editors that
* need to display independent of the zoom or any coordinate mapping that is
* taking place on the drawing surface.
*
* @param label
* the label to use for the font calculation
* @return the <code>Font</code> that is scaled to the screen coordinates.
* Note: the returned <code>Font</code> should not be disposed since
* it is cached by a common resource manager.
*/
protected Font getScaledFont(IFigure label) {
Font scaledFont = label.getFont();
FontData data = scaledFont.getFontData()[0];
Dimension fontSize = new Dimension(0, MapModeUtil.getMapMode(label).DPtoLP(data.getHeight()));
label.translateToAbsolute(fontSize);
if (Math.abs(data.getHeight() - fontSize.height) < 2)
fontSize.height = data.getHeight();
try {
FontDescriptor fontDescriptor = FontDescriptor.createFrom(data);
cachedFontDescriptors.add(fontDescriptor);
return getResourceManager().createFont(fontDescriptor);
} catch (DeviceResourceException e) {
Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "getScaledFont", // $NON-NLS-1$
e);
// $NON-NLS-1$
Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "getScaledFont", e);
}
return JFaceResources.getDefaultFont();
}
use of org.eclipse.jface.resource.DeviceResourceException in project epp.mpc by eclipse.
the class MarketplaceDiscoveryResources method safeCreateImage.
private Image safeCreateImage(String imagePath, URL url) {
try {
ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
Image image = resourceManager.createImage(descriptor);
return image;
} catch (DeviceResourceException ex) {
logFailedLoadingImage(imagePath, url, ex);
} catch (SWTException ex) {
logFailedLoadingImage(imagePath, url, ex);
}
return null;
}
use of org.eclipse.jface.resource.DeviceResourceException in project liferay-ide by liferay.
the class WorkingSetGroup method _createControl.
private void _createControl(Composite container) {
addToWorkingSetButton = new Button(container, SWT.CHECK);
GridData gd_addToWorkingSetButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
gd_addToWorkingSetButton.verticalIndent = 12;
addToWorkingSetButton.setLayoutData(gd_addToWorkingSetButton);
addToWorkingSetButton.setSelection(true);
addToWorkingSetButton.setData("name", "addToWorkingSetButton");
addToWorkingSetButton.setText("Add project to working set");
addToWorkingSetButton.setSelection(false);
final Label workingsetLabel = new Label(container, SWT.NONE);
GridData gd_workingsetLabel = new GridData();
gd_workingsetLabel.horizontalIndent = 10;
workingsetLabel.setLayoutData(gd_workingsetLabel);
workingsetLabel.setEnabled(false);
workingsetLabel.setData("name", "workingsetLabel");
workingsetLabel.setText("Working set:");
Combo workingsetCombo = new Combo(container, SWT.READ_ONLY);
workingsetCombo.setEnabled(false);
workingsetCombo.setData("name", "workingsetCombo");
workingsetCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
_workingsetComboViewer = new ComboViewer(workingsetCombo);
_workingsetComboViewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public Object[] getElements(Object input) {
if (input instanceof IWorkingSet[]) {
return (IWorkingSet[]) input;
} else if (input instanceof List<?>) {
return new Object[] { input };
} else if (input instanceof Set<?>) {
return ((Set<?>) input).toArray();
}
return new IWorkingSet[0];
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
_workingsetComboViewer.setLabelProvider(new LabelProvider() {
public void dispose() {
_images.dispose();
super.dispose();
}
@SuppressWarnings("deprecation")
public Image getImage(Object element) {
if (element instanceof IWorkingSet) {
ImageDescriptor imageDescriptor = ((IWorkingSet) element).getImage();
if (imageDescriptor != null) {
try {
return (Image) _images.create(imageDescriptor);
} catch (DeviceResourceException dre) {
return null;
}
}
}
return super.getImage(element);
}
public String getText(Object element) {
if (element instanceof IWorkingSet) {
return ((IWorkingSet) element).getLabel();
} else if (element instanceof List<?>) {
StringBuffer sb = new StringBuffer();
for (Object o : (List<?>) element) {
if (o instanceof IWorkingSet) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(((IWorkingSet) o).getLabel());
}
}
return sb.toString();
}
return super.getText(element);
}
private ResourceManager _images = new LocalResourceManager(JFaceResources.getResources());
});
_workingsetComboViewer.setComparator(new ViewerComparator());
final Button newWorkingSetButton = new Button(container, SWT.NONE);
newWorkingSetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
newWorkingSetButton.setData("name", "configureButton");
newWorkingSetButton.setText("More...");
newWorkingSetButton.setEnabled(false);
newWorkingSetButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
IWorkingSetSelectionDialog dialog = workingSetManager.createWorkingSetSelectionDialog(_shell, true, _working_set_ids.toArray(new String[0]));
if (dialog.open() == Window.OK) {
IWorkingSet[] workingSets = dialog.getSelection();
selectWorkingSets(Arrays.asList(workingSets));
}
}
});
if (selectWorkingSets(_workingSets)) {
addToWorkingSetButton.setSelection(true);
workingsetLabel.setEnabled(true);
_workingsetComboViewer.getCombo().setEnabled(true);
newWorkingSetButton.setEnabled(true);
}
addToWorkingSetButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean addToWorkingingSet = addToWorkingSetButton.getSelection();
workingsetLabel.setEnabled(addToWorkingingSet);
_workingsetComboViewer.getCombo().setEnabled(addToWorkingingSet);
newWorkingSetButton.setEnabled(addToWorkingingSet);
if (addToWorkingingSet) {
updateConfiguration();
} else {
_workingSets.clear();
}
}
});
_workingsetComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateConfiguration();
}
});
}
Aggregations