use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_TableColumn method test_setMoveableZ.
@Test
public void test_setMoveableZ() {
assertFalse(":a:", tableColumn.getMoveable());
tableColumn.setMoveable(true);
assertTrue(":b:", tableColumn.getMoveable());
tableColumn.setMoveable(true);
assertTrue(":c:", tableColumn.getMoveable());
tableColumn.setMoveable(false);
assertFalse(":d:", tableColumn.getMoveable());
TableColumn tableColumn2 = new TableColumn(tableColumn.getParent(), SWT.NONE);
tableColumn2.dispose();
try {
tableColumn2.getMoveable();
fail("No exception thrown for widget is Disposed");
} catch (SWTException ex) {
}
try {
tableColumn2.setMoveable(true);
fail("No exception thrown for widget is Disposed");
} catch (SWTException ex) {
}
}
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 cogtool by cogtool.
the class FrameUIModel method addFrameChangeListeners.
/**
* Add listeners for when things change on the frame.
*/
protected void addFrameChangeListeners() {
AlertHandler frameChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.WidgetChange chg = (Frame.WidgetChange) alert;
IWidget chgWidget = chg.getChangeElement();
if (chg != null) {
// action dictated by the change.
switch(chg.action) {
// Add the graphical representation of the widget
case Frame.WidgetChange.ELEMENT_ADD:
createGraphicalWidget(chgWidget);
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
break;
// Remove the graphical representation of the widget
case Frame.WidgetChange.ELEMENT_DELETE:
removeWidget(chgWidget);
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
break;
// Update all existing widgets to the new color
case Frame.WidgetChange.WIDGET_COLORS_CHANGED:
Iterator<GraphicalWidget<?>> gws = figureList.values().iterator();
// Update graphical widgets
while (gws.hasNext()) {
GraphicalWidget<?> gw = gws.next();
gw.setColor(frame.getWidgetColor());
// gw.setFastMode(false);
}
// Update potential temporary widget
contents.setWidgetColor(frame.getWidgetColor());
break;
}
}
// Draw the viewable widgets.
// Adds any new items from the lists.. or moves them
drawWidgets();
}
};
// Add the new handler for frame changes to the list of things to
// alert to changes on the frame
frame.addHandler(this, Frame.WidgetChange.class, frameChangeHandler);
// A separate handler is required to take care of changes of the
// background on the frame.
AlertHandler frameBackgroundChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.BackgroundImageChange chg = (Frame.BackgroundImageChange) alert;
if (chg != null) {
// Dispose the old background image if there was one
if (backgroundImage.getImage() != null) {
backgroundImage.getImage().dispose();
}
byte[] bgImg = frame.getBackgroundImage();
// If the image is null, don't create it.
if (bgImg != null) {
// the cache is probably out of date
try {
Image img = new Image(null, new ByteArrayInputStream(bgImg));
// AUIModel.imageCache.put(frame, img);
// set the new image to the background
backgroundImage.setImage(img);
// get the size of the image
org.eclipse.swt.graphics.Rectangle bounds = img.getBounds();
// resize background image with the new bounds
backgroundImage.setSize(bounds.width, bounds.height);
} catch (SWTException ex) {
throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
}
} else {
// Clear the background image.
backgroundImage.setImage(null);
backgroundImage.setSize(0, 0);
}
}
drawWidgets();
// Need to raise Alert after draw widgets since
// the alert call seems to reset the "bounds"
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, null));
}
};
// Add this handler to the list for changes in the background image
frame.addHandler(this, Frame.BackgroundImageChange.class, frameBackgroundChangeHandler);
}
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);
}
Aggregations