Java Code Examples for org.eclipse.swt.widgets.ColorDialog#setRGB()

The following examples show how to use org.eclipse.swt.widgets.ColorDialog#setRGB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoxDecoratorImpl.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseDoubleClick(final MouseEvent e) {
	final int x = e.x + boxText.getHorizontalPixel();
	final int y = e.y + boxText.getTopPixel();

	int level = -1;
	for (final Box b : visibleBoxes()) {
		if (contains(b.rec, x, y)) {
			if (level < b.level) {
				level = b.level;
			}
		}
	}
	level++;

	final ColorDialog colorDialog = new ColorDialog(boxText.getShell());
	final Color oldColor1 = settings.getColor(level);
	if (oldColor1 != null) {
		colorDialog.setRGB(oldColor1.getRGB());
	}

	settings.setColor(level, colorDialog.open());
}
 
Example 2
Source File: EditingPane.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: EditingPane.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: FXColorPicker.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: SWTColorChooser.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
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); 
}
 
Example 6
Source File: OptionsDesign.java    From ldparteditor with MIT License 5 votes vote down vote up
@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();
        }
    }
}
 
Example 7
Source File: GamaColorMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
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);
		}
	}
}
 
Example 8
Source File: PageSupport.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: ComboBoxColorCellEditor.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
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;
}