use of org.eclipse.swt.SWTException in project cogtool by cogtool.
the class FrameUIModel method setUpFrameContents.
/**
* Set up the contents of the frame.
* This creates the scalable figure and sets the initial scaling.
*
* The layout manager is also created with an XYLayout to allow absolute
* positioning of elements.
*
* All structures needed to support drawing and selecting objects are
* created here.
*
* @param double Scale: used to set the initial size of the contents.
*/
protected void setUpFrameContents(double scale) {
// Set up the content pane
// Create the underlying contents pane.
// And set the contents pane's default widget color.
contents = new ScalableFrameFigure(frame.getWidgetColor());
contents.setScale(scale);
contents.setLayoutManager(new XYLayout());
// Create a new graphical widget for each widget in Frame.
Iterator<IWidget> modelWidgets = frame.getWidgets().iterator();
while (modelWidgets.hasNext()) {
IWidget w = modelWidgets.next();
createGraphicalWidget(w);
}
// Initialize the background image
backgroundImage = new ImageFigure();
final byte[] bgImg = frame.getBackgroundImage();
if (bgImg != null) {
if (lazyLoading) {
// Use a thread to load the image, then set it later
ThreadManager.IWorkThread imageLoadThread = new CogToolWorkThread() {
protected Image img = null;
public void doWork() {
// Performed by the scheduled thread
img = new Image(null, new ByteArrayInputStream(bgImg));
}
@Override
public void doneCallback() {
// Performed by the main UI thread
if (img != null) {
if (isDisposed) {
img.dispose();
} else {
backgroundImage.setImage(img);
}
}
// TODO: We might want to add a real logging package
if (exBucket.containsExceptions()) {
// TODO: It is unclear what to do here. Maybe
// we should just replace failed images with red
// Xs rather than popping up a dialog box
System.err.println(exBucket);
// RcvrExceptionHandler.recoverWorkThread(this,
// interaction);
}
}
};
ThreadManager.startNewThread(imageLoadThread, 2);
} else {
try {
// = AUIModel.imageCache.get(frame);
Image img = null;
if (img == null) {
img = new Image(null, new ByteArrayInputStream(bgImg));
// AUIModel.imageCache.put(frame, img);
}
backgroundImage.setImage(img);
} catch (SWTException ex) {
throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
}
}
backgroundImage.setBounds(PrecisionUtilities.getDraw2DRectangle(frame.getBackgroundBounds()));
}
// Always align the picture to top left corner
backgroundImage.setAlignment(PositionConstants.NORTH | PositionConstants.WEST);
// Resize to preferred size.
DoubleSize s = getPreferredSize();
// Set the size of the contents area to fit all elements.
contents.setSize(PrecisionUtilities.round(s.width), PrecisionUtilities.round(s.height));
// Draw all widgets.
drawWidgets();
}
use of org.eclipse.swt.SWTException in project cogtool by cogtool.
the class GraphicalDevice method paintFigure.
/**
* Override to perform drawing tasks common to all graphical sources
*/
@Override
protected void paintFigure(Graphics g) {
Dimension size = getSize();
// Workaround Draw2D's inability to draw 0-size images.
int width = size.width;
if (width == 0) {
width = 1;
}
int height = size.height;
if (height == 0) {
height = 1;
}
Image scaled = null;
try {
// Draw foreground sheen (not selected)
foreground.setAlpha(0, 0, displayAlpha.determineAlpha(false));
// TODO: Can this be cached more efficiently?
scaled = new Image(null, foreground.scaledTo(width, height));
Point location = getLocation();
g.drawImage(scaled, location.x, location.y);
} catch (SWTException ex) {
throw new RcvrImageException("Drawing device foreground image failed", ex);
} finally {
if (scaled != null) {
scaled.dispose();
}
}
super.paintFigure(g);
button.paintFigure(g);
}
use of org.eclipse.swt.SWTException in project jop by jop-devel.
the class JOPBoardConfigurationTab method handleQuartusProjectButtonSelected.
/**
* Handle selection of the Quartus project file button.
*
*/
protected void handleQuartusProjectButtonSelected() {
FileDialog dialog = new FileDialog(getShell());
IPath rootPath = fQuartusProjectLocation != null ? fQuartusProjectLocation.removeLastSegments(1) : ResourcesPlugin.getWorkspace().getRoot().getLocation();
dialog.setFilterPath(rootPath.toString());
dialog.setFilterExtensions(new String[] { "*.qpf" });
try {
dialog.open();
if (dialog.getFileName().equals("")) {
return;
}
IPath filterPath = new Path(dialog.getFilterPath());
IPath fileName = new Path(dialog.getFileName());
fQuartusProjectLocation = filterPath.append(fileName);
fQuartusProjectText.setText(fQuartusProjectLocation.toString());
} catch (SWTException e) {
}
}
use of org.eclipse.swt.SWTException in project dbeaver by serge-rider.
the class ImageEditor method loadImage.
@Override
public boolean loadImage(InputStream inputStream) {
super.loadImage(inputStream);
try {
SWTException lastError = getLastError();
if (lastError != null) {
messageLabel.setText(lastError.getMessage());
messageLabel.setForeground(redColor);
return false;
} else {
messageLabel.setText(getImageDescription());
messageLabel.setForeground(blackColor);
return true;
}
} finally {
updateActions();
}
}
use of org.eclipse.swt.SWTException in project dbeaver by serge-rider.
the class ImageViewCanvas method loadImage.
/**
* Reload image from a file
* @return swt image created from image file
*/
public Image loadImage(InputStream inputStream) {
if (sourceImage != null && !sourceImage.isDisposed()) {
sourceImage.dispose();
sourceImage = null;
imageData = null;
}
this.error = null;
if (inputStream != null) {
try {
imageData = new ImageData(inputStream);
sourceImage = new Image(getDisplay(), imageData);
} catch (SWTException e) {
this.error = e;
}
}
showOriginal();
return sourceImage;
}
Aggregations