1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-06 08:35:26 +02:00

launchbar: fixing colors to be compatible with skinning

it looked awful in dark skin, now it should be inheriting
system colors properly

Change-Id: If963a19651ac30b20c7a2cb100b285f33f799ca9
This commit is contained in:
Alena Laskavaia 2015-11-23 12:16:14 -05:00
parent d5c63d386c
commit 9435e1f802
3 changed files with 42 additions and 39 deletions

View file

@ -62,17 +62,12 @@ public abstract class CSelector extends Composite {
private static final int arrowMax = 2;
private Transition arrowTransition;
private Object selection;
protected final Color backgroundColor;
protected final Color outlineColor;
protected final Color highlightColor;
protected final Color white;
private boolean mouseOver;
private Label currentIcon;
private Label currentLabel;
private Shell popup;
private LaunchBarListViewer listViewer;
private Job delayJob;
private MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseUp(MouseEvent event) {
@ -91,7 +86,6 @@ public abstract class CSelector extends Composite {
}
return control == this;
}
private Listener focusOutListener = new Listener() {
private Job closingJob;
@ -121,7 +115,6 @@ public abstract class CSelector extends Composite {
protected IStatus run(IProgressMonitor monitor) {
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
closePopup();
closingJob = null;
return Status.OK_STATUS;
@ -141,23 +134,20 @@ public abstract class CSelector extends Composite {
}
}
}
};
public CSelector(Composite parent, int style) {
super(parent, style);
backgroundColor = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
outlineColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
highlightColor = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
white = getDisplay().getSystemColor(SWT.COLOR_WHITE);
setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
GridLayout mainButtonLayout = new GridLayout();
setLayout(mainButtonLayout);
addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.setBackground(backgroundColor);
gc.setForeground(outlineColor);
gc.setBackground(getBackground());
gc.setForeground(getOutlineColor());
Point size = getSize();
final int arc = 3;
gc.fillRoundRectangle(0, 0, size.x - 1, size.y - 1, arc, arc);
@ -226,7 +216,7 @@ public abstract class CSelector extends Composite {
buttonLayout.marginHeight = buttonLayout.marginWidth = 0;
buttonComposite.setLayout(buttonLayout);
buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
buttonComposite.setBackground(backgroundColor);
buttonComposite.setBackground(getBackground());
buttonComposite.addMouseListener(mouseListener);
buttonComposite.setToolTipText(toolTipText);
if (element != null) {
@ -253,7 +243,8 @@ public abstract class CSelector extends Composite {
}
};
arrow.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
arrow.setBackground(backgroundColor);
arrow.setBackground(getBackground());
arrow.setForeground(getForeground());
arrowTransition = new Transition(arrow, arrowMax, 80);
arrow.addPaintListener(new PaintListener() {
@Override
@ -275,7 +266,7 @@ public abstract class CSelector extends Composite {
if (editable) {
final EditButton editButton = new EditButton(buttonComposite, SWT.NONE);
editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
editButton.setBackground(backgroundColor);
editButton.setBackground(getBackground());
editButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@ -314,7 +305,7 @@ public abstract class CSelector extends Composite {
}
popup = new Shell(getShell(), SWT.TOOL | SWT.ON_TOP | SWT.RESIZE);
popup.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 0).create());
popup.setBackground(getBackground());
listViewer = new LaunchBarListViewer(popup);
initializeListViewer(listViewer);
listViewer.setFilterVisible(elements.length > 7);
@ -337,7 +328,6 @@ public abstract class CSelector extends Composite {
Rectangle buttonBounds = getBounds();
Point popupLocation = popup.getDisplay().map(this, null, 0, buttonBounds.height);
popup.setLocation(popupLocation.x, popupLocation.y + 5);
restoreShellSize();
popup.setVisible(true);
popup.setFocus();
@ -352,7 +342,6 @@ public abstract class CSelector extends Composite {
getDisplay().removeFilter(SWT.MouseUp, focusOutListener);
saveShellSize();
}
});
}
@ -541,4 +530,11 @@ public abstract class CSelector extends Composite {
// nothing to do here
}
public Color getOutlineColor() {
return getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
}
public Color getHighlightColor() {
return getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
}
}

View file

@ -38,6 +38,7 @@ import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
@ -49,9 +50,9 @@ import org.eclipse.swt.widgets.Label;
public class ConfigSelector extends CSelector {
private LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager();
private DefaultDescriptorLabelProvider defaultProvider;
private static final String[] noConfigs = new String[] { Messages.ConfigSelector_0 };
public ConfigSelector(Composite parent, int style) {
super(parent, style);
@ -173,13 +174,13 @@ public class ConfigSelector extends CSelector {
GridLayout buttonLayout = new GridLayout();
buttonLayout.marginWidth = buttonLayout.marginHeight = 7;
createButton.setLayout(buttonLayout);
createButton.setBackground(backgroundColor);
createButton.setBackground(getBackground());
createButton.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point size = createButton.getSize();
GC gc = e.gc;
gc.setForeground(outlineColor);
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
gc.drawLine(0, 0, size.x, 0);
}
});
@ -187,14 +188,16 @@ public class ConfigSelector extends CSelector {
final Label createLabel = new Label(createButton, SWT.None);
createLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
createLabel.setText(Messages.ConfigSelector_2);
createLabel.setBackground(backgroundColor);
createLabel.setBackground(getBackground());
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
final NewLaunchConfigWizard wizard = new NewLaunchConfigWizard();
WizardDialog dialog = new WizardDialog(getShell(), wizard);
if (dialog.open() == Window.OK) {
new Job(Messages.ConfigSelector_3) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
wizard.getWorkingCopy().doSave();
@ -214,11 +217,13 @@ public class ConfigSelector extends CSelector {
MouseTrackListener mouseTrackListener = new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
Color highlightColor = getHighlightColor();
createButton.setBackground(highlightColor);
createLabel.setBackground(highlightColor);
}
@Override
public void mouseExit(MouseEvent e) {
Color backgroundColor = getBackground();
createButton.setBackground(backgroundColor);
createLabel.setBackground(backgroundColor);
}
@ -238,9 +243,10 @@ public class ConfigSelector extends CSelector {
element = noConfigs[0];
super.setSelection(element);
}
@Override
public void openPopup() {
super.openPopup();
}
}

View file

@ -172,9 +172,6 @@ public class LaunchBarListViewer extends StructuredViewer {
private Label label;
protected EditButton editButton;
private int index;
private Color backgroundColor = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
private Color outlineColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
private Color highlightColor = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
private ILabelProvider labelProvider;
@Override
@ -187,12 +184,13 @@ public class LaunchBarListViewer extends StructuredViewer {
this.index = index;
this.labelProvider = labelProvider;
setData(element);
setBackground(getParent().getBackground());
addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point size = getSize();
GC gc = e.gc;
gc.setForeground(outlineColor);
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
gc.drawLine(0, size.y - 1, size.x, size.y - 1);
if (label == null)
lazyInit();
@ -240,17 +238,17 @@ public class LaunchBarListViewer extends StructuredViewer {
addTraverseListener(listItemTraverseListener);
addKeyListener(lisItemKeyListener);
setBackground(backgroundColor);
layout(true);
}
public void setSelected(boolean selected) {
if (selected) {
setBackground(highlightColor);
setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
int idx = getIndex();
if (idx != selIndex) {
if (selIndex >= 0) {
listItems[selIndex].setBackground(backgroundColor);
listItems[selIndex].setBackground(getParent().getBackground());
scrollBucket = Math.max(Math.min(scrollBucket + idx - selIndex, maxScrollBucket), 0);
} else { // initially
scrollBucket = Math.min(idx, maxScrollBucket);
@ -258,7 +256,7 @@ public class LaunchBarListViewer extends StructuredViewer {
}
selIndex = idx;
} else {
setBackground(backgroundColor);
setBackground(getParent().getBackground());
}
if (editButton != null) {
editButton.setSelected(selected);
@ -340,10 +338,13 @@ public class LaunchBarListViewer extends StructuredViewer {
public LaunchBarListViewer(Composite parent) {
filterControl = new FilterControl(parent);
filterControl.setBackground(parent.getBackground());
listScrolled = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.NO_BACKGROUND);
listScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
listScrolled.setExpandHorizontal(true);
listScrolled.setBackground(parent.getBackground());
listComposite = new Composite(listScrolled, SWT.NONE);
listComposite.setBackground(parent.getBackground());
listScrolled.setContent(listComposite);
listComposite.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 0).create());
selIndex = -1;
@ -394,8 +395,8 @@ public class LaunchBarListViewer extends StructuredViewer {
public void mouseDoubleClick(MouseEvent e) {
// ignore
}
});
sash.setToolTipText(Messages.LaunchBarListViewer_0);
}
@ -577,7 +578,7 @@ public class LaunchBarListViewer extends StructuredViewer {
/**
* Returns top element (provider element) in the begging on non-history list
*
*
* @return
*/
public Object getTopFilteredElement() {
@ -603,7 +604,7 @@ public class LaunchBarListViewer extends StructuredViewer {
/**
* ViewerComparator comparator labels of elements by default
*
*
* @param comp
*/
public void setHistoryComparator(ViewerComparator comp) {