org.eclipse.swt.widgets.ColorDialog#open ( )源码实例Demo

下面列出了org.eclipse.swt.widgets.ColorDialog#open ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: nebula   文件: PTColorEditor.java
@Override
protected void openWindow(final PTWidget widget, final Item item, final PTProperty property) {
	final ColorDialog dialog = new ColorDialog(widget.getWidget().getShell());
	final RGB result = dialog.open();
	if (result != null) {
		property.setValue(result);

		final Color bgColor = getBackgroundColor(property);
		if (bgColor != null) {
			if (item instanceof TableItem) {
				((TableItem) item).setBackground(1, bgColor);
			}
			if (item instanceof TreeItem) {
				((TreeItem) item).setBackground(1, bgColor);
			}
			SWTGraphicUtil.addDisposer(item, bgColor);
		}

		if (item instanceof TableItem) {
			((TableItem) item).setText(1, getTextFor(property));

		} else {
			((TreeItem) item).setText(1, getTextFor(property));
		}
	}
}
 
源代码2 项目: pmTrans   文件: EditingPane.java
public void changeBackgroundColor() {
	ColorDialog cd = new ColorDialog(getShell());
	cd.setRGB(text.getBackground().getRGB());
	cd.setText("Choose a color");

	RGB newColor = cd.open();
	if (newColor != null)
		Config.getInstance().setValue(Config.BACKGROUND_COLOR,
				new Color(Display.getCurrent(), newColor));
	updateFont();
}
 
源代码3 项目: pmTrans   文件: EditingPane.java
public void changeFontColor() {
	ColorDialog cd = new ColorDialog(getShell());
	cd.setRGB(text.getBackground().getRGB());
	cd.setText("Choose a color");

	RGB newColor = cd.open();
	if (newColor != null)
		Config.getInstance().setValue(Config.FONT_COLOR,
				new Color(Display.getCurrent(), newColor));
	updateFont();
}
 
源代码4 项目: gef   文件: FXColorPicker.java
/**
 * Opens a {@link ColorDialog} to let the user pick a {@link Color}. Returns
 * the picked {@link Color}, or <code>null</code> if no color was picked.
 *
 * @param shell
 *            The {@link Shell} which serves as the parent for the
 *            {@link ColorDialog}.
 * @param initial
 *            The initial {@link Color} to display in the
 *            {@link ColorDialog}.
 * @return The picked {@link Color}, or <code>null</code>.
 */
protected static Color pickColor(Shell shell, Color initial) {
	ColorDialog cd = new ColorDialog(shell);
	RGB rgb = new RGB((int) (255 * initial.getRed()),
			(int) (255 * initial.getGreen()),
			(int) (255 * initial.getBlue()));
	cd.setRGB(rgb);
	RGB newRgb = cd.open();
	if (newRgb != null) {
		return Color.rgb(newRgb.red, newRgb.green, newRgb.blue);
	}
	return null;
}
 
源代码5 项目: tuxguitar   文件: SWTColorChooser.java
public void choose(UIColorChooserHandler selectionHandler) {
	ColorDialog dlg = new ColorDialog(this.window.getControl());
	if( this.text != null ) {
		dlg.setText(this.text);
	}
	if( this.defaultModel != null ) {
		dlg.setRGB(new RGB(this.defaultModel.getRed(), this.defaultModel.getGreen(), this.defaultModel.getBlue()));
	}
	
	RGB rgb = dlg.open();
	
	selectionHandler.onSelectColor(rgb != null ? new UIColorModel(rgb.red, rgb.green, rgb.blue) : null); 
}
 
源代码6 项目: ldparteditor   文件: OptionsDesign.java
@Override
public void mouseDoubleClick(MouseEvent e) {
    final TreeItem selection;
    if (tree.getSelectionCount() == 1 && (selection = tree.getSelection()[0]).getData() != null) {
        ColorDialog dlg = new ColorDialog(getShell());
        // Change the title bar text
        dlg.setText(selection.getText(0));
        dlg.setRGB(selection.getParent().getMapInv().get(selection).getBackground(1).getRGB());
        // Open the dialog and retrieve the selected color
        RGB rgb = dlg.open();
        if (rgb != null) {
            GColour refCol = new GColour(-1, rgb.red / 255f, rgb.green / 255f, rgb.blue / 255f, 1f);
            tree.getMapInv().get(selection).setBackground(1, SWTResourceManager.getColor(rgb));
            Object[] colourObj = (Object[]) selection.getData();
            ColourType type = (ColourType) colourObj[0];
            switch (type) {
            case OPENGL_COLOUR:
                ((float[]) ((Object[]) colourObj[1])[0])[0] = refCol.getR();
                ((float[]) ((Object[]) colourObj[1])[1])[0] = refCol.getG();
                ((float[]) ((Object[]) colourObj[1])[2])[0] = refCol.getB();
                break;
            case SWT_COLOUR:
                ((Color[]) colourObj[1])[0] = SWTResourceManager.getColor(rgb) ;
                break;
            default:
                break;
            }

            for (EditorTextWindow w : Project.getOpenTextWindows()) {
                for (CTabItem t : w.getTabFolder().getItems()) {
                    ((CompositeTab) t).updateColours();
                }
            }
            tree.build();
            tree.update();
        }
    }
}
 
源代码7 项目: gama   文件: GamaColorMenu.java
public static void openView(final IColorRunnable runnable, final RGB initial) {
	final Shell shell = new Shell(WorkbenchHelper.getDisplay(), SWT.MODELESS);
	final ColorDialog dlg = new ColorDialog(shell, SWT.MODELESS);
	dlg.setText("Choose a custom color");
	dlg.setRGB(initial);
	final RGB rgb = dlg.open();
	// final int a = StringUtils.INDEX_NOT_FOUND;
	if (rgb != null) {
		if (runnable != null) {
			runnable.run(rgb.red, rgb.green, rgb.blue);
		}
	}
}
 
源代码8 项目: slr-toolkit   文件: PageSupport.java
protected static RGB openAndGetColor(Composite parent, Label label) {
	
	ColorDialog dlg = new ColorDialog(parent.getShell());
	dlg.setRGB(label.getBackground().getRGB());
	dlg.setText("Choose a Color");
	RGB rgb = dlg.open();
       label.setBackground(new Color(parent.getShell().getDisplay(), rgb));
       
	return rgb;
}
 
源代码9 项目: birt   文件: ComboBoxColorCellEditor.java
protected Object openDialogBox( Control cellEditorWindow )
{
	Shell shell = new Shell( Display.getCurrent( ), SWT.SHELL_TRIM );
	shell.setLocation( cellEditorWindow.toDisplay( 0, 0 ).x
			+ cellEditorWindow.getBounds( ).width,
			cellEditorWindow.toDisplay( 0, 0 ).y
					- cellEditorWindow.getBounds( ).height );
	ColorDialog dialog = new ColorDialog( shell, SWT.APPLICATION_MODAL );
	RGB[] rgbs = ReportPlugin.getDefault( ).getCustomColorsPreference( );
	if ( rgbs != null )
	{
		dialog.setRGBs( rgbs );
	}
	Object value = getValue( );

	try
	{
		int color;

		if ( value instanceof String )
		{
			color = ColorUtil.parseColor( (String) value );
		}
		else
		{
			color = ( (Integer) value ).intValue( );
		}

		dialog.setRGB( DEUtil.getRGBValue( color ) );

	}
	catch ( Exception e )
	{
		// ignore.
	}

	value = dialog.open( );
	ReportPlugin.getDefault( )
			.setCustomColorsPreference( dialog.getRGBs( ) );
	if ( value != null && dialog.getRGB( ) != null )
	{
		deactivate( );
		return ColorUtil.format( ColorUtil.formRGB( dialog.getRGB( ).red,
				dialog.getRGB( ).green,
				dialog.getRGB( ).blue ), ColorUtil.HTML_FORMAT );
	}
	comboBox.setFocus( );
	shell.dispose( );
	return value;
}
 
 同类方法