forked from eclipse-platform/eclipse.platform.ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Color selector swatches misdrawn at 200% scale eclipse-platform#261
Use a ImageDataProvider to provide the image data at the correct scale based on the current zoom given to us by SWT. Also provides a JFace example snippet for this widget because we didn't have one. Fixes eclipse-platform#261 Signed-off-by: Mat Booth <mat.booth@gmail.com>
- Loading branch information
1 parent
1cda433
commit f6c0a6f
Showing
2 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...clipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet082ColorSelectDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Mat Booth and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.jface.snippets.dialogs; | ||
|
||
import org.eclipse.jface.preference.ColorSelector; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionListener; | ||
import org.eclipse.swt.graphics.Color; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Button; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Label; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
/** | ||
* Demo of the JFace {@link ColorSelector} which is compound widget comprising a | ||
* color swatch button and the native color chooser dialog. | ||
*/ | ||
public class Snippet082ColorSelectDialog { | ||
|
||
public static void main(String[] args) { | ||
Display display = new Display(); | ||
Shell shell = new Shell(display); | ||
shell.setLayout(new GridLayout(2, false)); | ||
shell.setText("Color Select Dialog Demo"); | ||
shell.setSize(320, 240); | ||
shell.setBackgroundMode(SWT.INHERIT_DEFAULT); | ||
|
||
Label bgLabel = new Label(shell, SWT.NONE); | ||
bgLabel.setText("Background Color:"); | ||
ColorSelector bgColorSelector = new ColorSelector(shell); | ||
bgColorSelector.setColorValue(shell.getBackground().getRGB()); | ||
Button bgColorButton = bgColorSelector.getButton(); | ||
|
||
Label fgLabel = new Label(shell, SWT.NONE); | ||
fgLabel.setText("Foreground Color:"); | ||
ColorSelector fgColorSelector = new ColorSelector(shell); | ||
fgColorSelector.setColorValue(shell.getForeground().getRGB()); | ||
Button fgColorButton = fgColorSelector.getButton(); | ||
|
||
bgColorButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { | ||
shell.setBackground(new Color(bgColorSelector.getColorValue())); | ||
})); | ||
|
||
fgColorButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { | ||
Color color = new Color(fgColorSelector.getColorValue()); | ||
shell.setForeground(color); | ||
// On Windows 10, foreground color is not automatically inherited by default | ||
bgLabel.setForeground(color); | ||
fgLabel.setForeground(color); | ||
})); | ||
|
||
shell.open(); | ||
while (!shell.isDisposed()) { | ||
if (!display.readAndDispatch()) { | ||
display.sleep(); | ||
} | ||
} | ||
|
||
display.dispose(); | ||
} | ||
} |