use of org.eclipse.swt.graphics.Cursor in project eclipse.platform.swt by eclipse.
the class AddressBook method openAddressBook.
private void openAddressBook() {
FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
fileDialog.setFilterExtensions(new String[] { "*.adr;", "*.*" });
fileDialog.setFilterNames(new String[] { resAddressBook.getString("Book_filter_name") + " (*.adr)", resAddressBook.getString("All_filter_name") + " (*.*)" });
String name = fileDialog.open();
if (name == null)
return;
File file = new File(name);
if (!file.exists()) {
displayError(resAddressBook.getString("File") + file.getName() + " " + resAddressBook.getString("Does_not_exist"));
return;
}
Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
shell.setCursor(waitCursor);
String[] data = new String[0];
try (FileReader fileReader = new FileReader(file.getAbsolutePath());
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
String nextLine = bufferedReader.readLine();
while (nextLine != null) {
String[] newData = new String[data.length + 1];
System.arraycopy(data, 0, newData, 0, data.length);
newData[data.length] = nextLine;
data = newData;
nextLine = bufferedReader.readLine();
}
} catch (FileNotFoundException e) {
displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
return;
} catch (IOException e) {
displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName());
return;
} finally {
shell.setCursor(null);
}
String[][] tableInfo = new String[data.length][table.getColumnCount()];
int writeIndex = 0;
for (String element : data) {
String[] line = decodeLine(element);
if (line != null)
tableInfo[writeIndex++] = line;
}
if (writeIndex != data.length) {
String[][] result = new String[writeIndex][table.getColumnCount()];
System.arraycopy(tableInfo, 0, result, 0, writeIndex);
tableInfo = result;
}
Arrays.sort(tableInfo, new RowComparator(0));
for (String[] element : tableInfo) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(element);
}
shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName());
isModified = false;
this.file = file;
}
use of org.eclipse.swt.graphics.Cursor in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method menuSave.
void menuSave() {
if (image == null)
return;
// stop any animation in progress
animate = false;
// so we have to use 'Save As...'.
if (imageData.type == SWT.IMAGE_UNDEFINED || fileName == null) {
menuSaveAs();
return;
}
Cursor waitCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
shell.setCursor(waitCursor);
imageCanvas.setCursor(waitCursor);
try {
// Save the current image to the current file.
loader.data = new ImageData[] { imageData };
if (imageData.type == SWT.IMAGE_JPEG)
loader.compression = compressionCombo.indexOf(compressionCombo.getText()) + 1;
if (imageData.type == SWT.IMAGE_PNG)
loader.compression = compressionCombo.indexOf(compressionCombo.getText());
loader.save(fileName, imageData.type);
} catch (SWTException e) {
showErrorDialog(bundle.getString("Saving_lc"), fileName, e);
} catch (SWTError e) {
showErrorDialog(bundle.getString("Saving_lc"), fileName, e);
} finally {
shell.setCursor(null);
imageCanvas.setCursor(crossCursor);
}
}
use of org.eclipse.swt.graphics.Cursor in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method menuComposeAlpha.
void menuComposeAlpha(int alpha_op) {
if (image == null)
return;
// stop any animation in progress
animate = false;
Cursor waitCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
shell.setCursor(waitCursor);
imageCanvas.setCursor(waitCursor);
try {
if (alpha_op == ALPHA_CONSTANT) {
imageData.alpha = alpha;
} else {
imageData.alpha = -1;
switch(alpha_op) {
case ALPHA_X:
for (int y = 0; y < imageData.height; y++) {
for (int x = 0; x < imageData.width; x++) {
imageData.setAlpha(x, y, (x + alpha) % 256);
}
}
break;
case ALPHA_Y:
for (int y = 0; y < imageData.height; y++) {
for (int x = 0; x < imageData.width; x++) {
imageData.setAlpha(x, y, (y + alpha) % 256);
}
}
break;
default:
break;
}
}
displayImage(imageData);
} finally {
shell.setCursor(null);
imageCanvas.setCursor(crossCursor);
}
}
use of org.eclipse.swt.graphics.Cursor in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Cursor method test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageDataLorg_eclipse_swt_graphics_ImageDataII.
@Test
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageDataLorg_eclipse_swt_graphics_ImageDataII() {
// Test new Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY)
int numFormats = SwtTestUtil.imageFormats.length;
String fileName = SwtTestUtil.imageFilenames[0];
for (int i = 0; i < numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
ImageLoader loader = new ImageLoader();
try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
ImageData source = loader.load(stream)[0];
ImageData mask = source.getTransparencyMask();
if (mask != null && (source.depth == 1)) {
Cursor cursor = new Cursor(display, source, mask, 0, 0);
cursor.dispose();
}
} catch (IOException e) {
// continue;
}
}
}
use of org.eclipse.swt.graphics.Cursor in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Cursor method test_isDisposed.
@Test
public void test_isDisposed() {
// Test Cursor.isDisposed() false
Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
try {
assertTrue("Cursor should not be disposed", !cursor.isDisposed());
} finally {
// Test Cursor.isDisposed() true
cursor.dispose();
assertTrue("Cursor should be disposed", cursor.isDisposed());
}
}
Aggregations