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

📄 paintexample.java

📁 eclipse 的程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		label.setText(getResourceString("settings.AirbrushRadius.text"));		final Scale airbrushRadiusScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);		airbrushRadiusScale.setMinimum(5);		airbrushRadiusScale.setMaximum(50);		airbrushRadiusScale.setSelection(toolSettings.airbrushRadius);		airbrushRadiusScale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));		airbrushRadiusScale.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(SelectionEvent e) {				toolSettings.airbrushRadius = airbrushRadiusScale.getSelection();				updateToolSettings();			}		});		label = new Label(toolSettingsFrame, SWT.NONE);		label.setText(getResourceString("settings.AirbrushIntensity.text"));		final Scale airbrushIntensityScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);		airbrushIntensityScale.setMinimum(1);		airbrushIntensityScale.setMaximum(100);		airbrushIntensityScale.setSelection(toolSettings.airbrushIntensity);		airbrushIntensityScale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));		airbrushIntensityScale.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(SelectionEvent e) {				toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection();				updateToolSettings();			}		});	}			/**	 * Disposes of all resources associated with a particular	 * instance of the PaintExample.	 */		public void dispose() {		if (paintSurface != null) paintSurface.dispose();				if (paintColors != null) {			for (int i = 0; i < paintColors.length; ++i) {				final Color color = paintColors[i];				if (color != null) color.dispose();			}		}		paintDefaultFont = null;		paintColors = null;		paintSurface = null;		freeResources();	}	/**	 * Frees the resource bundle resources.	 */	public void freeResources() {		for (int i = 0; i < tools.length; ++i) {			Tool tool = tools[i];			final Image image = tool.image;			if (image != null) image.dispose();			tool.image = null;		}	}		/**	 * Returns the Display.	 * 	 * @return the display we're using	 */	public Display getDisplay() {		return mainComposite.getDisplay();	}		/**	 * Gets a string from the resource bundle.	 * We don't want to crash because of a missing String.	 * Returns the key if not found.	 */	public static String getResourceString(String key) {		try {			return resourceBundle.getString(key);		} catch (MissingResourceException e) {			return key;		} catch (NullPointerException e) {			return "!" + key + "!";		}				}	/**	 * Gets a string from the resource bundle and binds it	 * with the given arguments. If the key is not found,	 * return the key.	 */	public static String getResourceString(String key, Object[] args) {		try {			return MessageFormat.format(getResourceString(key), args);		} catch (MissingResourceException e) {			return key;		} catch (NullPointerException e) {			return "!" + key + "!";		}	}	/**	 * Initialize colors, fonts, and tool settings.	 */	private void init() {		Display display = mainComposite.getDisplay();				paintColorWhite = new Color(display, 255, 255, 255);		paintColorBlack = new Color(display, 0, 0, 0);				paintDefaultFont = display.getSystemFont();		paintColors = new Color[numPaletteCols * numPaletteRows];		paintColors[0] = paintColorBlack;		paintColors[1] = paintColorWhite;		for (int i = 2; i < paintColors.length; i++) {			paintColors[i] = new Color(display,				((i*7)%255),((i*23)%255), ((i*51)%255));		}		toolSettings = new ToolSettings();		toolSettings.commonForegroundColor = paintColorBlack;		toolSettings.commonBackgroundColor = paintColorWhite;		toolSettings.commonFont = paintDefaultFont;	}	/**	 * Sets the action field of the tools	 */	private void initActions() {		for (int i = 0; i < tools.length; ++i) {			final Tool tool = tools[i];			String group = tool.group;			if (group.equals("tool")) {				tool.action = new Runnable() {					public void run() {						setPaintTool(tool.id);					}				};			} else if (group.equals("fill")) {				tool.action = new Runnable() {					public void run() {						setFillType(tool.id);					}				};			} else if (group.equals("linestyle")) {				tool.action = new Runnable() {					public void run() {						setLineStyle(tool.id);					}				};			} else if (group.equals("options")) {				tool.action = new Runnable() {					public void run() {						FontDialog fontDialog = new FontDialog(paintSurface.getShell(), SWT.PRIMARY_MODAL);						FontData[] fontDatum = toolSettings.commonFont.getFontData();						if (fontDatum != null && fontDatum.length > 0) {							fontDialog.setFontList(fontDatum);						}						fontDialog.setText(getResourceString("options.Font.dialog.title"));						paintSurface.hideRubberband();						FontData fontData = fontDialog.open();						paintSurface.showRubberband();						if (fontData != null) {							try {								Font font = new Font(mainComposite.getDisplay(), fontData);								toolSettings.commonFont = font;								updateToolSettings();							} catch (SWTException ex) {							}						}					}				};			}		}	}	/**	 * Loads the image resources.	 */	public void initResources() {		final Class clazz = PaintExample.class;		if (resourceBundle != null) {			try {				for (int i = 0; i < tools.length; ++i) {					Tool tool = tools[i];					String id = tool.group + '.' + tool.name;					InputStream sourceStream = clazz.getResourceAsStream(getResourceString(id + ".image"));					ImageData source = new ImageData(sourceStream);					ImageData mask = source.getTransparencyMask();					tool.image = new Image(null, source, mask);					try {						sourceStream.close();					} catch (IOException e) {						e.printStackTrace();					}				}				return;			} catch (Throwable t) {			}		}		String error = (resourceBundle != null) ?			getResourceString("error.CouldNotLoadResources") :			"Unable to load resources";		freeResources();		throw new RuntimeException(error);	}	/**	 * Grabs input focus.	 */	public void setFocus() {		mainComposite.setFocus();	}		/**	 * Sets the tool foreground color.	 * 	 * @param color the new color to use	 */	public void setForegroundColor(Color color) {		if (activeForegroundColorCanvas != null)			activeForegroundColorCanvas.setBackground(color);		toolSettings.commonForegroundColor = color;		updateToolSettings();	}	/**	 * Set the tool background color.	 * 	 * @param color the new color to use	 */	public void setBackgroundColor(Color color) {		if (activeBackgroundColorCanvas != null)			activeBackgroundColorCanvas.setBackground(color);		toolSettings.commonBackgroundColor = color;		updateToolSettings();	}	/**	 * Selects a tool given its ID.	 */	public void setPaintTool(int id) {		PaintTool paintTool = (PaintTool) tools[id].data;		paintSurface.setPaintSession(paintTool);		updateToolSettings();	}		/**	 * Selects a filltype given its ID.	 */	public void setFillType(int id) {		Integer fillType = (Integer) tools[id].data;		toolSettings.commonFillType = fillType.intValue();		updateToolSettings();			}	/**	 * Selects line type given its ID.	 */	public void setLineStyle(int id) {		Integer lineType = (Integer) tools[id].data;		toolSettings.commonLineStyle = lineType.intValue();		updateToolSettings();			}	/**	 * Sets the size of the shell to it's "packed" size,	 * unless that makes it bigger than the display,	 * in which case set it to 9/10 of display size.	 */	private static void setShellSize (Display display, Shell shell) {		Rectangle bounds = display.getBounds();		Point size = shell.computeSize (SWT.DEFAULT, SWT.DEFAULT);		if (size.x > bounds.width) size.x = bounds.width * 9 / 10;		if (size.y > bounds.height) size.y = bounds.height * 9 / 10;		shell.setSize (size);	}	/**	 * Notifies the tool that its settings have changed.	 */	private void updateToolSettings() {		final PaintTool activePaintTool = paintSurface.getPaintTool();		if (activePaintTool == null) return;				activePaintTool.endSession();		activePaintTool.set(toolSettings);		activePaintTool.beginSession();	}}

⌨️ 快捷键说明

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