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

The following are Jave code examples for showing how to use setRGB() of the org.eclipse.swt.widgets.ColorDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: triquetrum   File: EditorUtils.java   View Source Code Vote up 6 votes
/**
 * Opens a dialog to change the color.
 *
 * @param color
 *          the color to change
 * @return the changed color
 */
public static String editColor(Diagram diagram, String colorStr) {
  Color color = null;
  if (colorStr == null) {
    color = Graphiti.getGaService().manageColor(diagram, IColorConstant.BLACK);
  } else {
    color = EditorUtils.buildColorFromString(diagram, colorStr);
  }
  ColorDialog colorDialog = new ColorDialog(Display.getDefault().getActiveShell());
  colorDialog.setText("Choose color");
  colorDialog.setRGB(new RGB(color.getRed(), color.getGreen(), color.getBlue()));

  RGB retRgb = colorDialog.open();
  if (retRgb == null) {
    return colorStr;
  } else {
    return EditorUtils.toString(retRgb);
  }
}
 
Example 2
Project: SecureBPMN   File: SampleUtil.java   View Source Code Vote up 6 votes
/**
 * Opens a dialog to change the color.
 * 
 * @param color
 *            the color to change
 * @return the changed color
 */
public static Color editColor(Color color) {
	if (color != null && color.eContainer() instanceof Diagram) {
		Shell shell = getShell();
		ColorDialog colorDialog = new ColorDialog(shell);
		colorDialog.setText("Choose Color");
		colorDialog.setRGB(new RGB(color.getRed(), color.getGreen(), color.getBlue()));

		RGB retRgb = colorDialog.open();
		if (retRgb == null) {
			return null;
		}

		Diagram diagram = (Diagram) color.eContainer();
		Color newColor = Graphiti.getGaService().manageColor(diagram, retRgb.red, retRgb.green, retRgb.blue);
		return newColor;

	}

	return null;
}
 
Example 3
Project: gama   File: BoxDecoratorImpl.java   View Source Code Vote up 6 votes
@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 4
Project: gef-gwt   File: ColorSelector.java   View Source Code Vote up 6 votes
/**
 * Activate the editor for this selector. This causes the color selection
 * dialog to appear and wait for user input.
 * 
 * @since 3.2
 */
public void open() {
	ColorDialog colorDialog = new ColorDialog(fButton.getShell());
	colorDialog.setRGB(fColorValue);
	RGB newColor = colorDialog.open();
	if (newColor != null) {
	    RGB oldValue = fColorValue;
	    fColorValue = newColor;
	    final Object[] finalListeners = getListeners();
	    if (finalListeners.length > 0) {
	        PropertyChangeEvent pEvent = new PropertyChangeEvent(
	                this, PROP_COLORCHANGE, oldValue, newColor);
	        for (int i = 0; i < finalListeners.length; ++i) {
	            IPropertyChangeListener listener = (IPropertyChangeListener) finalListeners[i];
	            listener.propertyChange(pEvent);
	        }
	    }
	    updateColorImage();
	}
}
 
Example 5
Project: cogtool   File: DefaultInteraction.java   View Source Code Vote up 6 votes
/**
 * Open up a widget color wheel with the specified title.
 * Should be platform specific.
 * the specified integer should be in the following format.
 * lowest order 8 bits red
 * middle order 8 bits green
 * highest order 8 bits blue
 * ie: xxxxxxxx xxxxxxxx  xxxxxxxx
 *     BLUE     GREEN     RED
 */
public Integer selectColor(int oldColor, String dialogTitle)
{
    RGB old = GraphicsUtil.getRGBFromColor(oldColor);

    // Open the platform specific color chooser
    ColorDialog dialog = new ColorDialog(window);
    dialog.setRGB(old);
    if (dialogTitle != null)
    {
        dialog.setText(dialogTitle);
    }
    RGB newColor = dialog.open();

    if (newColor != null) {
        return new Integer(GraphicsUtil.getColorFromRGB(newColor));
    }

    return null;
}
 
Example 6
Project: pmTrans   File: EditingPane.java   View Source Code Vote up 5 votes
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 7
Project: pmTrans   File: EditingPane.java   View Source Code Vote up 5 votes
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 8
Project: team-explorer-everywhere   File: HTMLEditor.java   View Source Code Vote up 5 votes
/**
 * Opens a dialog to let the user pick a color.
 *
 * @param shell
 *        the shell on which to open the dialog (must not be
 *        <code>null</code>)
 * @param initialColor
 *        the initial color to set in the dialog, or <code>null</code> to
 *        use the dialog default
 * @return the color the user picked, or <code>null</code> if the dialog was
 *         cancelled
 */
public String pickColor(final Shell shell, final RGB initialColor) {
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    /*
     * Mac OS X is Extremely Weird Here!
     *
     * On Mac OS X, we open the ColorDialog and it's automatically hooked
     * into the selection in Safari! Changing colors in the dialog while
     * it's open immediately changes the color in the document, before the
     * dialog even closes (we're blocking in this method). We always get
     * null back from dialog.open() when the dialog is closed, so we don't
     * set anything in the document, but that's OK because Safari is
     * magically updating its document for us. Very weird!
     */

    final ColorDialog dialog = new ColorDialog(shell);

    if (initialColor != null) {
        dialog.setRGB(initialColor);
    }

    final RGB rgb = dialog.open();
    if (rgb != null) {
        return String.format("#%1$02x%2$02x%3$02x", rgb.red, rgb.green, rgb.blue); //$NON-NLS-1$
    }
    return null;
}
 
Example 9
Project: TranskribusSwtGui   File: BindColorToButtonListener.java   View Source Code Vote up 5 votes
private void updatePropertyFromWidget() {
	ColorDialog cd = new ColorDialog(Display.getCurrent().getActiveShell());
	cd.setText("Choose color");
	cd.setRGB(getValueOfProperty().getRGB());
	RGB newColor = cd.open();
	if (newColor == null)
		return;
			
	try {
		BeanUtils.setProperty(bean, property, Colors.createColor(newColor));
	} catch (IllegalAccessException | InvocationTargetException e) {
		throw new RuntimeException(e);
	}	
}
 
Example 10
Project: ForgedUI-Eclipse   File: ColorCellEditor2.java   View Source Code Vote up 5 votes
protected Object openDialogBox(Control cellEditorWindow) {
	ColorDialog dialog = new ColorDialog(cellEditorWindow.getShell());
       Object value = getValue();
       if (value != null) {
		dialog.setRGB((RGB) value);
	}
       value = dialog.open();
       RGB rgb = dialog.getRGB();//return the same if cancelled
       if (rgb != null){
       	return rgb;//rgbToString(rgb);
       }
       return null;
}
 
Example 11
Project: scouter   File: SetColorAction.java   View Source Code Vote up 5 votes
public void run() {
	if (window != null) {
		ColorDialog dlg = new ColorDialog(window.getShell());
		AgentObject agent = AgentModelThread.getInstance().getAgentObject(objHash);
		dlg.setRGB(agent.getColor().getRGB());
		dlg.setText("Choose a Color");
		RGB rgb = dlg.open();
		if (rgb != null) {
			Color color = AgentColorManager.getInstance().changeColor(objHash, rgb);
			//agent.setColor(color);
		}
	}
}
 
Example 12
Project: org.csstudio.display.builder   File: RGBCellEditor.java   View Source Code Vote up 5 votes
/** Opens the color dialog. */
@Override
public void activate()
{
    final ColorDialog dialog = new ColorDialog(shell);
    if (value != null)
        dialog.setRGB(value);
    value = dialog.open();
    if (value != null)
        fireApplyEditorValue();
}
 
Example 13
Project: ldparteditor   File: OptionsDesign.java   View Source Code Vote up 5 votes
@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 14
Project: gama   File: GamaColorMenu.java   View Source Code Vote up 5 votes
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 15
Project: gef-gwt   File: ColorCellEditor.java   View Source Code Vote up 5 votes
protected Object openDialogBox(Control cellEditorWindow) {
      ColorDialog dialog = new ColorDialog(cellEditorWindow.getShell());
      Object value = getValue();
      if (value != null) {
	dialog.setRGB((RGB) value);
}
      value = dialog.open();
      return dialog.getRGB();
  }
 
Example 16
Project: birt   File: ComboBoxColorCellEditor.java   View Source Code Vote up 4 votes
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;
}
 
Example 17
Project: birt   File: ColorSelector.java   View Source Code Vote up 4 votes
/**
 * Activate the editor for this selector. This causes the color selection
 * dialog to appear and wait for user input.
 * 
 * @since 3.2
 */
public void open( )
{
	/*
	 * Bugzilla #269139 - Issue about color editor dialog in Highlight
	 * Editor dialog. (After the fixing of Bugizlla #223759, the change is
	 * not applicable on Linux and causes #269139. The workaround is to
	 * detect what type the OS is and only appply the change of #223759 on
	 * Windows.)
	 */
	Shell shell = null;
	Boolean isWin32 = Platform.getOS( ).equals( Platform.OS_WIN32 );
	if ( isWin32 )
	{
		shell = new Shell( Display.getCurrent( ), SWT.SHELL_TRIM );
		shell.setLocation( fButton.toDisplay( 0, 0 ).x
				+ fButton.getBounds( ).width,
				fButton.toDisplay( 0, 0 ).y - fButton.getBounds( ).height );
	}
	ColorDialog colorDialog = new ColorDialog( isWin32 ? shell
			: fButton.getShell( ), SWT.APPLICATION_MODAL );
	RGB[] rgbs = ReportPlugin.getDefault( ).getCustomColorsPreference( );
	if ( rgbs != null )
	{
		colorDialog.setRGBs( rgbs );
	}
	colorDialog.setRGB( fColorValue );
	colorDialog.setText( Messages.getString( "ColorSelector.ColorDialog.Title" ) ); //$NON-NLS-1$
	RGB newColor = colorDialog.open( );
	ReportPlugin.getDefault( )
			.setCustomColorsPreference( colorDialog.getRGBs( ) );
	if ( newColor != null )
	{
		RGB oldValue = fColorValue;
		fColorValue = newColor;
		final Object[] finalListeners = getListeners( );
		if ( finalListeners.length > 0 )
		{
			PropertyChangeEvent pEvent = new PropertyChangeEvent( this,
					PROP_COLORCHANGE,
					oldValue,
					newColor );
			for ( int i = 0; i < finalListeners.length; ++i )
			{
				IPropertyChangeListener listener = (IPropertyChangeListener) finalListeners[i];
				listener.propertyChange( pEvent );
			}
		}
		updateColorImage( );
	}
	if ( isWin32 )
	{
		shell.dispose( );
	}
}