use of org.eclipse.swt.SWTException in project cogtool by cogtool.
the class DictionaryEditorUI method updateView.
protected void updateView() {
Table dictTable = view.getDictTable();
int selectionCount = 0;
try {
selectionCount = dictTable.getSelectionCount();
} catch (SWTException e) {
return;
}
if (selectionCount == 1) {
int index = dictTable.getSelectionIndex();
DictEntry entry = dictionary.getEntry(index);
if (entry != null) {
String url = null;
String space = null;
if (entry.algorithm instanceof ISitedTermSimilarity) {
url = ((ISitedTermSimilarity) entry.algorithm).getContextSite();
view.setURLEnabled(true);
view.setSpaceEnabled(false);
} else if (entry.algorithm instanceof LSASimilarity) {
LSASimilarity lsa = (LSASimilarity) entry.algorithm;
space = lsa.getSpace();
url = lsa.getURL();
if (url == null) {
url = LSASimilarity.DEFAULT_LSA_URL;
}
view.setURLEnabled(true);
view.setSpaceEnabled(true);
} else if (entry.algorithm instanceof GensimLSASimilarity) {
GensimLSASimilarity lsa = (GensimLSASimilarity) entry.algorithm;
space = lsa.getSpace();
url = lsa.getURL();
if (url == null) {
url = GensimLSASimilarity.DEFAULT_LSA_URL;
}
view.setURLEnabled(true);
view.setSpaceEnabled(true);
} else {
view.setURLEnabled(false);
view.setSpaceEnabled(false);
}
view.setURL(url);
view.setSpace(space);
} else {
TableItem row = dictTable.getItem(index);
Combo c = (Combo) row.getData();
int seln = c.getSelectionIndex();
boolean isLSA = (seln == DictionaryEditorUIModel.LSA_INDEX);
view.setURLEnabled((seln == DictionaryEditorUIModel.GOOGLE_WORD_INDEX) || (seln == DictionaryEditorUIModel.GOOGLE_PHRASE_INDEX) || isLSA);
view.setSpaceEnabled(isLSA);
}
} else {
// disable if 0 or more than 1 are selected
view.setURL(null);
view.setSpace(null);
view.setURLEnabled(false);
view.setSpaceEnabled(false);
}
}
use of org.eclipse.swt.SWTException in project cogtool by cogtool.
the class DictionaryEditorUI method setViewEnabledState.
protected void setViewEnabledState(Boolean context) {
try {
Table dictTable = view.getDictTable();
int selectionCount = dictTable.getSelectionCount();
boolean pendingSelected = dictTable.isSelected(dictTable.getItemCount() - 1);
boolean enabled = !pendingSelected && (selectionCount >= 1);
setEnabled(CogToolLID.Delete, context, enabled);
enabled = selectionCount == 1;
setEnabled(DictionaryEditorLID.SetSimilarity, context, enabled);
setEnabled(DictionaryEditorLID.SetGoalString, context, enabled);
setEnabled(DictionaryEditorLID.SetSearchString, context, enabled);
} catch (SWTException e) {
// ignore
}
}
use of org.eclipse.swt.SWTException in project cogtool by cogtool.
the class GraphicsUtil method getImageBounds.
/**
* A utility to load an image and then dispose it from a byte array.
* This utility returns the size of the image.
* This is not a good function to call often. its SLOW.
*
* If the image is null, then returns a new rectangle (0,0,0,0);
* TODO: should this return null
* @param image
* @return
*/
public static DoubleRectangle getImageBounds(byte[] image) {
if (image == null) {
return new DoubleRectangle(0, 0, 0, 0);
}
try {
Image img = new Image(null, new ByteArrayInputStream(image));
Rectangle rect = img.getBounds();
img.dispose();
return new DoubleRectangle(rect.x, rect.y, rect.width, rect.height);
} catch (SWTException ex) {
throw new ImageException("Failed to get image bounds.", ex);
}
}
use of org.eclipse.swt.SWTException in project tdi-studio-se by Talend.
the class CodeGeneratorProgressMonitor method runEventLoop.
/**
* Runs an event loop.
*/
private void runEventLoop() {
// Only run the event loop so often, as it is expensive on some platforms
// (namely Motif).
final long t = System.currentTimeMillis();
if (t - lastTime < tTHRESH) {
return;
}
lastTime = t;
// Run the event loop.
if (CommonUIPlugin.isFullyHeadless()) {
return;
}
final Display disp = DisplayUtils.getDisplay();
if (disp == null) {
return;
}
disp.syncExec(new Runnable() {
@Override
public void run() {
for (; ; ) {
try {
if (!disp.readAndDispatch()) {
break;
}
} catch (SWTException se) {
// do nothing;
}
// constantly generating events.
if (System.currentTimeMillis() - t > tMAX) {
break;
}
}
}
});
}
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);
}
Aggregations