-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make palette selection and hover colors customizable
This defines a new ColorPalette interface that can be set in the PaletteViewer. The colors provided by this interface are then used in the palette figure for e.g. the tool entries. Clients can extend the DefaultColorPalette to define their own colors and therefore change the look of the palette.
- Loading branch information
Showing
21 changed files
with
390 additions
and
65 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
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
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
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
51 changes: 51 additions & 0 deletions
51
...se.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/action/ColorPaletteAction.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,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.examples.shapes.action; | ||
|
||
import org.eclipse.ui.IEditorPart; | ||
|
||
import org.eclipse.gef.GraphicalViewer; | ||
import org.eclipse.gef.ui.actions.EditorPartAction; | ||
import org.eclipse.gef.ui.palette.PaletteViewer; | ||
|
||
import org.eclipse.gef.examples.shapes.palette.ShapesColorPalette; | ||
|
||
/** | ||
* Flips between the custom and the default color palette whenever executed. | ||
*/ | ||
public class ColorPaletteAction extends EditorPartAction { | ||
public static final String ID = "Color Palette"; //$NON-NLS-1$ | ||
|
||
public ColorPaletteAction(IEditorPart editor) { | ||
super(editor); | ||
setId(ID); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
GraphicalViewer graphicalViewer = getEditorPart().getAdapter(GraphicalViewer.class); | ||
PaletteViewer paletteViewer = graphicalViewer.getEditDomain().getPaletteViewer(); | ||
if (isChecked()) { | ||
paletteViewer.setColorPalette(new ShapesColorPalette()); | ||
} else { | ||
paletteViewer.setColorPalette(null); | ||
} | ||
paletteViewer.getControl().redraw(); | ||
} | ||
|
||
@Override | ||
protected boolean calculateEnabled() { | ||
return true; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...xamples.shapes/src/org/eclipse/gef/examples/shapes/action/ColorPaletteRetargetAction.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,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.examples.shapes.action; | ||
|
||
import org.eclipse.ui.actions.RetargetAction; | ||
|
||
import org.eclipse.gef.examples.shapes.Messages; | ||
|
||
/** | ||
* Delegates the action event from the menu contribution to the editor. | ||
*/ | ||
public class ColorPaletteRetargetAction extends RetargetAction { | ||
public ColorPaletteRetargetAction() { | ||
super(ColorPaletteAction.ID, Messages.ColorPaletteRetargetAction_Text, AS_CHECK_BOX); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...e.gef.examples.shapes/src/org/eclipse/gef/examples/shapes/palette/ShapesColorPalette.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,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.examples.shapes.palette; | ||
|
||
import org.eclipse.swt.graphics.Color; | ||
|
||
import org.eclipse.draw2d.ColorConstants; | ||
|
||
import org.eclipse.gef.ui.palette.DefaultColorPalette; | ||
|
||
/** | ||
* Defines arbitrary colors that distinguish themselves from the default | ||
* palette. | ||
*/ | ||
public class ShapesColorPalette extends DefaultColorPalette { | ||
@Override | ||
public Color getSelectedColor() { | ||
return ColorConstants.darkGreen; | ||
} | ||
|
||
@Override | ||
public Color getHoverColor() { | ||
return ColorConstants.cyan; | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
org.eclipse.gef.tests/src/org/eclipse/gef/test/swtbot/utils/SWTBotGefPalette.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,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.test.swtbot.utils; | ||
|
||
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; | ||
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefViewer; | ||
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; | ||
|
||
import org.eclipse.gef.ui.palette.ColorPalette; | ||
import org.eclipse.gef.ui.palette.PaletteViewer; | ||
|
||
/** | ||
* Convenience class to create an SWTBot instance over the palette viewer. | ||
*/ | ||
public class SWTBotGefPalette extends SWTBotGefViewer { | ||
|
||
public SWTBotGefPalette(SWTBotGefViewer gefViewer) throws WidgetNotFoundException { | ||
super(getPaletteViewer(gefViewer)); | ||
} | ||
|
||
private static PaletteViewer getPaletteViewer(SWTBotGefViewer gefViewer) { | ||
SWTBotGefEditPart gefEditPart = gefViewer.rootEditPart(); | ||
return gefEditPart.part().getViewer().getEditDomain().getPaletteViewer(); | ||
} | ||
|
||
public PaletteViewer getPaletteViewer() { | ||
return (PaletteViewer) graphicalViewer; | ||
} | ||
|
||
public ColorPalette getColorPalette() { | ||
return getPaletteViewer().getColorPalette(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.