Search in sources :

Example 31 with SWTException

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

Example 32 with SWTException

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

Example 33 with SWTException

use of org.eclipse.swt.SWTException in project ACS by ACS-Community.

the class PopulateEventList method getThreadForEventList.

Thread getThreadForEventList() {
    Runnable eventListRunnable = new Runnable() {

        public Runnable r = new Runnable() {

            private long totalNumberDrained;

            public void run() {
                //final Display display = viewer.getControl().getDisplay();
                if (!display.isDisposed()) {
                    ArrayList c = new ArrayList(QUEUE_DRAIN_LIMIT);
                    int numberDrained = queue.drainTo(c, QUEUE_DRAIN_LIMIT);
                    if (numberDrained == 0)
                        return;
                    totalNumberDrained += numberDrained;
                    synchronized (this) {
                        // TODO -- figure out why this doesn't work; need same lock on display everywhere?
                        if (!display.isDisposed())
                            viewer.add(c.toArray());
                    }
                    if (cycles++ % CHECK_MEMORY_FREQUENCY == 0) {
                        StopWatch sw = new StopWatch(logger);
                        freeMemoryIfNecessary();
                        sw.logLapTime("Check free memory");
                        logger.fine("Total rows processed so far: " + totalNumberDrained);
                        String rateStr;
                        if (threadName.equals("NC Events"))
                            rateStr = String.format("Average event rate from all subscribed channels: %.2f events/s", EventData.getAverageRate());
                        else
                            rateStr = String.format("Average archiving rate: %.2f monitor points/s", ArchiveEventData.getAverageRate());
                        statusLineWriter.setMessage(rateStr);
                    }
                }
            }
        };

        public void run() {
            while (!Thread.currentThread().isInterrupted()) {
                if (display.isDisposed())
                    return;
                try {
                    display.syncExec(r);
                    //display.asyncExec(r);
                    Thread.sleep(1000);
                //					System.out.println("Event list iteration " + ++i);
                //					System.out.println("Queue has "
                //							+ Application.equeue.remainingCapacity()
                //							+ " slots left.");
                } catch (InterruptedException e) {
                    // TODO: Change thread model, as this happens at shutdown
                    System.out.println("Event monitoring was interrupted!");
                    break;
                // Application.setMonitoring(false);
                // startMonitoringAction.setEnabled(true);
                } catch (SWTException e) {
                    // eat it
                    break;
                }
            }
        // Application.setMonitoring(false);
        // startMonitoringAction.setEnabled(true);
        }
    };
    final Thread th = new Thread(eventListRunnable, threadName);
    return th;
}
Also used : SWTException(org.eclipse.swt.SWTException) ArrayList(java.util.ArrayList) StopWatch(alma.acs.util.StopWatch)

Example 34 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Region method test_addLorg_eclipse_swt_graphics_Rectangle.

@Test
public void test_addLorg_eclipse_swt_graphics_Rectangle() {
    Region reg = new Region(display);
    // add a rectangle
    reg.add(new Rectangle(0, 0, 100, 50));
    // add a second rectangle
    reg.add(new Rectangle(200, 200, 10, 10));
    try {
        reg.add((Rectangle) null);
        fail("no exception thrown for adding a null rectangle");
    } catch (IllegalArgumentException e) {
    }
    reg.dispose();
    try {
        reg.add(new Rectangle(20, 30, 10, 5));
        fail("no exception thrown for adding a rectangle after Region got disposed");
    } catch (SWTException e) {
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 35 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Region method test_addLorg_eclipse_swt_graphics_Region.

@Test
public void test_addLorg_eclipse_swt_graphics_Region() {
    Region reg1 = new Region(display);
    // make a second region and add it to the first one
    Region reg2 = new Region(display);
    reg2.add(new Rectangle(40, 50, 10, 20));
    reg1.add(reg2);
    reg2.dispose();
    try {
        reg1.add((Region) null);
        fail("no exception thrown for adding a null region");
    } catch (IllegalArgumentException e) {
    }
    try {
        reg2 = new Region(display);
        reg2.add(new Rectangle(1, 1, 100, 200));
        reg2.dispose();
        reg1.add(reg2);
        fail("no exception thrown for adding to a Region a Region which got disposed");
    } catch (IllegalArgumentException e) {
    }
    reg1.dispose();
    try {
        reg2 = new Region(display);
        reg2.add(new Rectangle(1, 1, 100, 200));
        reg1.add(reg2);
        fail("no exception thrown for adding a Region to a Region which got disposed");
    } catch (SWTException e) {
    } finally {
        if (reg2 != null)
            reg2.dispose();
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Aggregations

SWTException (org.eclipse.swt.SWTException)57 Test (org.junit.Test)29 Image (org.eclipse.swt.graphics.Image)21 Rectangle (org.eclipse.swt.graphics.Rectangle)14 ImageData (org.eclipse.swt.graphics.ImageData)13 IOException (java.io.IOException)8 Region (org.eclipse.swt.graphics.Region)8 Display (org.eclipse.swt.widgets.Display)8 SWTError (org.eclipse.swt.SWTError)7 PaletteData (org.eclipse.swt.graphics.PaletteData)7 RGB (org.eclipse.swt.graphics.RGB)7 InputStream (java.io.InputStream)6 Point (org.eclipse.swt.graphics.Point)6 MessageBox (org.eclipse.swt.widgets.MessageBox)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Cursor (org.eclipse.swt.graphics.Cursor)4 ImageLoader (org.eclipse.swt.graphics.ImageLoader)4 FileDialog (org.eclipse.swt.widgets.FileDialog)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Shell (org.eclipse.swt.widgets.Shell)3