⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageanalyzer.java

📁 SUN公司eclipse3.2.2经典例子
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		display.syncExec(new Runnable() {			public void run() {				// Change the label of the Animate button to 'Stop'.				animateButton.setText(bundle.getString("Stop"));								// Disable anything we don't want the user				// to select during the animation.				previousButton.setEnabled(false);				nextButton.setEnabled(false);				backgroundCombo.setEnabled(false);				scaleXCombo.setEnabled(false);				scaleYCombo.setEnabled(false);				alphaCombo.setEnabled(false);				incrementalCheck.setEnabled(false);				transparentCheck.setEnabled(false);				maskCheck.setEnabled(false);				// leave backgroundCheck enabled							// Reset the scale combos and scrollbars.				resetScaleCombos();				resetScrollBars();			}		});	}	/*	 * Post animation reset.	 */	void postAnimation() {		display.syncExec(new Runnable() {			public void run() {				// Enable anything we disabled before the animation.				previousButton.setEnabled(true);				nextButton.setEnabled(true);				backgroundCombo.setEnabled(true);				scaleXCombo.setEnabled(true);				scaleYCombo.setEnabled(true);				alphaCombo.setEnabled(true);				incrementalCheck.setEnabled(true);				transparentCheck.setEnabled(true);				maskCheck.setEnabled(true);							// Reset the label of the Animate button.				animateButton.setText(bundle.getString("Animate"));							if (animate) {					// If animate is still true, we finished the					// full number of repeats. Leave the image as-is.					animate = false;				} else {					// Redisplay the current image and its palette.					displayImage(imageDataArray[imageDataIndex]);				}			}		});	}	/*	 * Called when the Previous button is pressed.	 * Display the previous image in a multi-image file.	 */	void previous() {		if (image != null && imageDataArray.length > 1) {			if (imageDataIndex == 0) {				imageDataIndex = imageDataArray.length;			}			imageDataIndex = imageDataIndex - 1;			displayImage(imageDataArray[imageDataIndex]);		}		}	/*	 * Called when the Next button is pressed.	 * Display the next image in a multi-image file.	 */	void next() {		if (image != null && imageDataArray.length > 1) {			imageDataIndex = (imageDataIndex + 1) % imageDataArray.length;			displayImage(imageDataArray[imageDataIndex]);		}		}	void displayImage(ImageData newImageData) {		resetScaleCombos();		if (incremental && incrementalThread != null) {			// Tell the incremental thread to stop drawing.			synchronized (this) {				incrementalEvents = null;			}						// Wait until the incremental thread is done.			while (incrementalThread.isAlive()) {				if (!display.readAndDispatch()) display.sleep();			}		}							// Dispose of the old image, if there was one.		if (image != null) image.dispose();		try {			// Cache the new image and imageData.			image = new Image(display, newImageData);			imageData = newImageData;		} catch (SWTException e) {			showErrorDialog(bundle.getString("Creating_from") + " ", currentName, e);			image = null;			return;		}		// Update the widgets with the new image info.		String string = createMsg(bundle.getString("Analyzer_on"), currentName);		shell.setText(string);		if (imageDataArray.length > 1) {			string = createMsg(bundle.getString("Type_index"), 			                   new Object[] {fileTypeString(imageData.type),			                                 new Integer(imageDataIndex + 1),			                                 new Integer(imageDataArray.length)});		} else {			string = createMsg(bundle.getString("Type_string"), fileTypeString(imageData.type));		}		typeLabel.setText(string);		string = createMsg(bundle.getString("Size_value"), 					 new Object[] {new Integer(imageData.width),							   new Integer(imageData.height)});		sizeLabel.setText(string);		string = createMsg(bundle.getString("Depth_value"), new Integer(imageData.depth));		depthLabel.setText(string);		string = createMsg(bundle.getString("Transparent_pixel_value"), pixelInfo(imageData.transparentPixel));		transparentPixelLabel.setText(string);		string = createMsg(bundle.getString("Time_to_load_value"), new Long(loadTime));		timeToLoadLabel.setText(string);		string = createMsg(bundle.getString("Animation_size_value"), 		                      new Object[] {new Integer(loader.logicalScreenWidth),								new Integer(loader.logicalScreenHeight)});		screenSizeLabel.setText(string);		string = createMsg(bundle.getString("Background_pixel_value"), pixelInfo(loader.backgroundPixel));		backgroundPixelLabel.setText(string);		string = createMsg(bundle.getString("Image_location_value"), 		                      new Object[] {new Integer(imageData.x), new Integer(imageData.y)});		locationLabel.setText(string);		string = createMsg(bundle.getString("Disposal_value"),		                      new Object[] {new Integer(imageData.disposalMethod),							      disposalString(imageData.disposalMethod)});		disposalMethodLabel.setText(string);		int delay = imageData.delayTime * 10;		int delayUsed = visibleDelay(delay);		if (delay != delayUsed) {			string = createMsg(bundle.getString("Delay_value"), 			                   new Object[] {new Integer(delay), new Integer(delayUsed)});		} else {			string = createMsg(bundle.getString("Delay_used"), new Integer(delay));		}		delayTimeLabel.setText(string);		if (loader.repeatCount == 0) {			string = createMsg( bundle.getString("Repeats_forever"), new Integer(loader.repeatCount));		} else {			string = createMsg(bundle.getString("Repeats_value"), new Integer(loader.repeatCount));		}		repeatCountLabel.setText(string);		if (imageData.palette.isDirect) {			string = bundle.getString("Palette_direct");		} else {			string = createMsg(bundle.getString("Palette_value"), new Integer(imageData.palette.getRGBs().length));		}		paletteLabel.setText(string);		string = createMsg(				bundle.getString("Pixel_data_value"),				new Object[] {						new Integer(imageData.bytesPerLine),						new Integer(imageData.scanlinePad),						depthInfo(imageData.depth),						(imageData.alphaData != null && imageData.alphaData.length > 0) ?								bundle.getString("Scroll_for_alpha") : "" });		dataLabel.setText(string);		String data = dataHexDump(dataText.getLineDelimiter());		dataText.setText(data);				// bold the first column all the way down		int index = 0;		while((index = data.indexOf(':', index+1)) != -1) {			int start = index - INDEX_DIGITS;			int length = INDEX_DIGITS;			if (Character.isLetter(data.charAt(index-1))) {				start = index - ALPHA_CHARS;				length = ALPHA_CHARS;			}			dataText.setStyleRange(new StyleRange(start, length, dataText.getForeground(), dataText.getBackground(), SWT.BOLD));		}		statusLabel.setText("");		// Redraw both canvases.		resetScrollBars();		paletteCanvas.redraw();		imageCanvas.redraw();	}	void paintImage(PaintEvent event) {		GC gc = event.gc;		Image paintImage = image;				/* If the user wants to see the transparent pixel in its actual color,		 * then temporarily turn off transparency.		 */		int transparentPixel = imageData.transparentPixel;		if (transparentPixel != -1 && !transparent) {			imageData.transparentPixel = -1;			paintImage = new Image(display, imageData);		}				/* Scale the image when drawing, using the user's selected scaling factor. */		int w = Math.round(imageData.width * xscale);		int h = Math.round(imageData.height * yscale);				/* If any of the background is visible, fill it with the background color. */		Rectangle bounds = imageCanvas.getBounds();		if (imageData.getTransparencyType() != SWT.TRANSPARENCY_NONE) {			/* If there is any transparency at all, fill the whole background. */			gc.fillRectangle(0, 0, bounds.width, bounds.height);		} else {			/* Otherwise, just fill in the backwards L. */			if (ix + w < bounds.width) gc.fillRectangle(ix + w, 0, bounds.width - (ix + w), bounds.height);			if (iy + h < bounds.height) gc.fillRectangle(0, iy + h, ix + w, bounds.height - (iy + h));		}				/* Draw the image */		gc.drawImage(			paintImage,			0,			0,			imageData.width,			imageData.height,			ix + imageData.x,			iy + imageData.y,			w,			h);				/* If there is a mask and the user wants to see it, draw it. */		if (showMask && (imageData.getTransparencyType() != SWT.TRANSPARENCY_NONE)) {			ImageData maskImageData = imageData.getTransparencyMask();			Image maskImage = new Image(display, maskImageData);			gc.drawImage(				maskImage,				0,				0,				imageData.width,				imageData.height,				w + 10 + ix + imageData.x,				iy + imageData.y,				w,				h);			maskImage.dispose();		}				/* If transparency was temporarily disabled, restore it. */		if (transparentPixel != -1 && !transparent) {			imageData.transparentPixel = transparentPixel;			paintImage.dispose();		}	}	void paintPalette(PaintEvent event) {		GC gc = event.gc;		gc.fillRectangle(paletteCanvas.getClientArea());		if (imageData.palette.isDirect) {			// For a direct palette, display the masks.			int y = py + 10;			int xTab = 50;			gc.drawString("rMsk", 10, y, true);			gc.drawString(toHex4ByteString(imageData.palette.redMask), xTab, y, true);			gc.drawString("gMsk", 10, y+=12, true);			gc.drawString(toHex4ByteString(imageData.palette.greenMask), xTab, y, true);			gc.drawString("bMsk", 10, y+=12, true);			gc.drawString(toHex4ByteString(imageData.palette.blueMask), xTab, y, true);			gc.drawString("rShf", 10, y+=12, true);			gc.drawString(Integer.toString(imageData.palette.redShift), xTab, y, true);			gc.drawString("gShf", 10, y+=12, true);			gc.drawString(Integer.toString(imageData.palette.greenShift), xTab, y, true);			gc.drawString("bShf", 10, y+=12, true);			gc.drawString(Integer.toString(imageData.palette.blueShift), xTab, y, true);		} else {			// For an indexed palette, display the palette colors and indices.			RGB[] rgbs = imageData.palette.getRGBs();			if (rgbs != null) {				int xTab1 = 40, xTab2 = 100;				for (int i = 0; i < rgbs.length; i++) {					int y = (i+1) * 10 + py;					gc.drawString(String.valueOf(i), 10, y, true);					gc.drawString(toHexByteString(rgbs[i].red) + toHexByteString(rgbs[i].green) + toHexByteString(rgbs[i].blue), xTab1, y, true);					Color color = new Color(display, rgbs[i]);					gc.setBackground(color);					gc.fillRectangle(xTab2, y+2, 10, 10);					color.dispose();				}			}		}	}		void resizeShell(ControlEvent event) {		if (image == null || shell.isDisposed())			return;		resizeScrollBars();	}	// Reset the scale combos to 1.	void resetScaleCombos() {		xscale = 1; yscale = 1;		scaleXCombo.select(scaleXCombo.indexOf("1"));		scaleYCombo.select(scaleYCombo.indexOf("1"));	}		// Reset the scroll bars to 0.	void resetScrollBars() {		if (image == null) return;		ix = 0; iy = 0; py = 0;		resizeScrollBars();		imageCanvas.getHorizontalBar().setSelection(0);		imageCanvas.getVerticalBar().setSelection(0);		paletteCanvas.getVerticalBar().setSelection(0);	}		void resizeScrollBars() {		// Set the max and thumb for the image canvas scroll bars.		ScrollBar horizontal = imageCanvas.getHorizontalBar();		ScrollBar vertical = imageCanvas.getVerticalBar();		Rectangle canvasBounds = imageCanvas.getClientArea();		int width = Math.round(imageData.width * xscale);		if (width > canvasBounds.width) {			// The image is wider than the canvas.			horizontal.setEnabled(true);			horizontal.setMaximum(width);			horizontal.setThumb(canvasBounds.width);			horizontal.setPageIncrement(canvasBounds.width);		} else {			// The canvas is wider than the image.			horizontal.setEnabled(false);			if (ix != 0) {				// Make sure the image is completely visible.				ix = 0;				imageCanvas.redraw();			}		}		int height = Math.round(imageData.height * yscale);		if (height > canvasBounds.height) {			// The image is taller than the canvas.			vertical.setEnabled(true);			vertical.setMaximum(height);			vertical.setThumb(canvasBounds.height);			vertical.setPageIncrement(canvasBounds.height);		} else {			// The canvas is taller than the image.			vertical.setEnabled(false);			if (iy != 0) {				// Make sure the image is completely visible.				iy = 0;				imageCanvas.redraw();			}		}		// Set the max and thumb for the palette canvas scroll bar.		vertical = paletteCanvas.getVerticalBar();		if (imageData.palette.isDirect) {			vertical.setEnabled(false);		} else { // indexed palette			canvasBounds = paletteCanvas.getClientArea();			int paletteHeight = imageData.palette.getRGBs().length * 10 + 20; // 10 pixels each index + 20 for margins.			vertical.setEnabled(true);			vertical.setMaximum(paletteHeight);			vertical.setThumb(canvasBounds.height);			vertical.setPageIncrement(canvasBounds.height);		}	}	/*	 * Called when the image canvas' horizontal scrollbar is selected.	 */	void scrollHorizontally(ScrollBar scrollBar) {		if (image == null) return;		Rectangle canvasBounds = imageCanvas.getClientArea();		int width = Math.round(imageData.width * xscale);		int he

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -