Search in sources :

Example 56 with Cursor

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;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Cursor(org.eclipse.swt.graphics.Cursor) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 57 with Cursor

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);
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) SWTException(org.eclipse.swt.SWTException) Cursor(org.eclipse.swt.graphics.Cursor)

Example 58 with Cursor

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);
    }
}
Also used : Cursor(org.eclipse.swt.graphics.Cursor) Point(org.eclipse.swt.graphics.Point)

Example 59 with Cursor

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;
        }
    }
}
Also used : InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) IOException(java.io.IOException) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Cursor(org.eclipse.swt.graphics.Cursor) Test(org.junit.Test)

Example 60 with Cursor

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());
    }
}
Also used : Cursor(org.eclipse.swt.graphics.Cursor) Test(org.junit.Test)

Aggregations

Cursor (org.eclipse.swt.graphics.Cursor)64 DisposeEvent (org.eclipse.swt.events.DisposeEvent)26 DisposeListener (org.eclipse.swt.events.DisposeListener)26 Image (org.eclipse.swt.graphics.Image)24 GridData (org.eclipse.swt.layout.GridData)23 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 ToolBar (org.eclipse.swt.widgets.ToolBar)22 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)21 ToolItem (org.eclipse.swt.widgets.ToolItem)20 ImageData (org.eclipse.swt.graphics.ImageData)8 Composite (org.eclipse.swt.widgets.Composite)8 SWTException (org.eclipse.swt.SWTException)7 Point (org.eclipse.swt.graphics.Point)7 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 SWTError (org.eclipse.swt.SWTError)5 ImageLoader (org.eclipse.swt.graphics.ImageLoader)5 FileDialog (org.eclipse.swt.widgets.FileDialog)5 IOException (java.io.IOException)4 URL (java.net.URL)4