/** * @param image * @param width * @param height * @return */ private Image resize(Image image, int width) { int height = (int) (width / ((float) image.getImageData().width / (float) image.getImageData().height)); Image scaled = new Image(Display.getDefault(), width, height); GC gc = new GC(scaled); gc.setAntialias(SWT.ON); gc.setInterpolation(SWT.HIGH); gc.drawImage( image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, width, height); gc.dispose(); image.dispose(); return scaled; }
/** Instantiates a new server GUI window. */ public ServerGui() { display = new Display(); shell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); shell.setText("Server GUI"); GridLayout layout = new GridLayout(2, false); shell.setLayout(layout); Image image = new Image(display, "./Pictures/green_power_button.jpg"); Image scaled = new Image(Display.getDefault(), 233, 100); GC gc = new GC(scaled); gc.setAntialias(SWT.ON); gc.setInterpolation(SWT.HIGH); gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, 200, 100); gc.dispose(); image.dispose(); image = new Image(display, "./Pictures/stop_button.jpg"); Image scaled2 = new Image(Display.getDefault(), 233, 100); gc = new GC(scaled2); gc.setAntialias(SWT.ON); gc.setInterpolation(SWT.HIGH); gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, 200, 100); gc.dispose(); image.dispose(); Button powerOnButton = new Button(shell, SWT.PUSH); powerOnButton.setImage(scaled); powerOnButton.setText("Power On"); Button powerOffButton = new Button(shell, SWT.PUSH); powerOffButton.setImage(scaled2); powerOffButton.setText("Power off"); powerOnButton.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { ServerProperties p = setProperties(); if (p == null) { commandsArray.add("start"); setChanged(); notifyObservers(commandsArray); commandsArray.clear(); } else { commandsArray.add("start"); commandsArray.add(String.valueOf(p.getNumOfClients())); commandsArray.add(String.valueOf(p.getPort())); setChanged(); notifyObservers(commandsArray); commandsArray.clear(); } serverOn = true; powerOnButton.setEnabled(false); } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); powerOffButton.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { commandsArray.add("stop"); setChanged(); notifyObservers(commandsArray); commandsArray.clear(); } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); Composite composite2 = new Composite(shell, SWT.NULL); list = new List(composite2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); GridLayout gridLayout2 = new GridLayout(1, false); gridLayout2.marginWidth = 0; gridLayout2.marginHeight = 0; gridLayout2.verticalSpacing = 0; gridLayout2.horizontalSpacing = 0; composite2.setLayout(gridLayout2); GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, false); gridData2.heightHint = 9 * ((List) list).getItemHeight(); gridData2.widthHint = 280; list.setLayoutData(gridData2); Composite composite = new Composite(shell, SWT.NULL); GridLayout gridLayout = new GridLayout(1, false); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; gridLayout.verticalSpacing = 0; gridLayout.horizontalSpacing = 0; composite.setLayout(gridLayout); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); composite.setLayoutData(gridData); Button deleteClient = new Button(composite, SWT.PUSH); deleteClient.setText("Disconnect Client"); list.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { deleteClient.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg1) { if (serverOn == true && list.getSelectionIndex() != -1) { commandsArray.add("deleteClient"); commandsArray.add(list.getItem(list.getSelectionIndex())); list.remove(list.getSelectionIndex()); setChanged(); notifyObservers(commandsArray); } } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); Composite composite3 = new Composite(composite, SWT.NULL); new Label(composite3, SWT.LEFT | SWT.BORDER | SWT.BOLD).setText("Number of solutions cached:"); GridLayout solutionsLayoutInfo = new GridLayout(2, false); composite3.setLayout(solutionsLayoutInfo); composite3.setLayoutData(gridData); solutionsSize = new List(composite3, SWT.NULL); GridLayout solutionsLayout = new GridLayout(1, false); solutionsLayout.marginWidth = 0; solutionsLayout.marginHeight = 0; solutionsLayout.verticalSpacing = 0; solutionsLayout.horizontalSpacing = 0; }
public static /* synchronized */ Image resize( final Display display, final Image srcImage, final int newWidth, final int newHeight, final int antialias, final int interpolation, final Rotation exifRotation) { if (srcImage == null) { return null; } final Rectangle originalImageBounds = srcImage.getBounds(); final int originalWidth = originalImageBounds.width; final int originalHeight = originalImageBounds.height; final int srcWidth = originalWidth; final int srcHeight = originalHeight; final int destWidth = newWidth; final int destHeight = newHeight; int imgWidth = newWidth; int imgHeight = newHeight; // OSX is rotating the image automatically boolean isNoAutoRotate = UI.IS_OSX == false; isNoAutoRotate |= _isRotateImageAutomatically == false; if (isNoAutoRotate) { if (exifRotation == Rotation.CW_90 || exifRotation == Rotation.CW_270) { // swap width/height imgWidth = newHeight; imgHeight = newWidth; } } final Image scaledImage = new Image(display, imgWidth, imgHeight); final GC gc = new GC(scaledImage); Transform transformation = null; try { gc.setAdvanced(true); gc.setAntialias(antialias); gc.setInterpolation(interpolation); // gc.setAntialias(SWT.ON); // gc.setInterpolation(SWT.LOW); int destX = 0; int destY = 0; if (exifRotation != null && isNoAutoRotate) { final int imgWidth2 = imgWidth / 2; final int imgHeight2 = imgHeight / 2; transformation = new Transform(display); transformation.translate(imgWidth2, imgHeight2); if (exifRotation == Rotation.CW_90) { transformation.rotate(90); destX = -imgHeight2; destY = -imgWidth2; } else if (exifRotation == Rotation.CW_180) { // this case is not yet tested transformation.rotate(180); destX = -imgWidth2; destY = -imgHeight2; } else if (exifRotation == Rotation.CW_270) { transformation.rotate(270); destX = -imgHeight2; destY = -imgWidth2; } gc.setTransform(transformation); } gc.drawImage( srcImage, // 0, 0, srcWidth, srcHeight, // destX, destY, destWidth, destHeight); } finally { // ensure resources are disposed when an error occures gc.dispose(); if (transformation != null) { transformation.dispose(); } } return scaledImage; }