-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the dark and light theme and move the values in the css handler
Issue: #3621 #3614 Signed-off-by: Nirus2000 <[email protected]> [removed unnecessary changes due to format changes; rebased to master] Signed-off-by: Andreas Buchen <[email protected]>
- Loading branch information
Showing
5 changed files
with
152 additions
and
22 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
55 changes: 50 additions & 5 deletions
55
name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/theme/SecuritiesChartCSSHandler.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 |
---|---|---|
@@ -1,34 +1,79 @@ | ||
package name.abuchen.portfolio.ui.theme; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; | ||
import org.eclipse.e4.ui.css.core.engine.CSSEngine; | ||
import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; | ||
import org.eclipse.swt.graphics.Color; | ||
import org.w3c.dom.css.CSSValue; | ||
|
||
import name.abuchen.portfolio.ui.util.Colors; | ||
import name.abuchen.portfolio.ui.views.SecuritiesChart; | ||
|
||
/** | ||
* The SecuritiesChartCSSHandler class is responsible for customizing the visual | ||
* appearance of SecuritiesChart elements using CSS properties. It uses a | ||
* mapping of CSS properties to color setters to apply the specified colors to | ||
* corresponding elements within the chart. | ||
*/ | ||
@SuppressWarnings("restriction") | ||
public class SecuritiesChartCSSHandler implements ICSSPropertyHandler | ||
{ | ||
private interface ColorSetter | ||
{ | ||
/** | ||
* Sets the color on the SecuritiesChart element. | ||
*/ | ||
void setColor(SecuritiesChart chart, CSSValue value); | ||
} | ||
|
||
private final Map<String, ColorSetter> propertyMap = new HashMap<>(); | ||
|
||
public SecuritiesChartCSSHandler() | ||
{ | ||
initializePropertyMap(); | ||
} | ||
|
||
private void initializePropertyMap() | ||
{ | ||
propertyMap.put("quote-color", (chart, value) -> chart.setQuoteColor(getColor(value))); //$NON-NLS-1$ | ||
propertyMap.put("quote-area-positive-color", (chart, value) -> chart.setQuoteAreaPositive(getColor(value))); //$NON-NLS-1$ | ||
propertyMap.put("quote-area-negative-color", (chart, value) -> chart.setQuoteAreaNegative(getColor(value))); //$NON-NLS-1$ | ||
propertyMap.put("purchase-event-color", (chart, value) -> chart.setPurchaseColor(getColor(value))); //$NON-NLS-1$ | ||
propertyMap.put("sale-event-color", (chart, value) -> chart.setSaleColor(getColor(value))); //$NON-NLS-1$ | ||
propertyMap.put("dividend-event-color", (chart, value) -> chart.setDividendColor(getColor(value))); //$NON-NLS-1$ | ||
propertyMap.put("extreme-marker-high-color", //$NON-NLS-1$ | ||
(chart, value) -> chart.setExtremeMarkerHighColor(getColor(value))); | ||
propertyMap.put("extreme-marker-low-color", (chart, value) -> chart.setExtremeMarkerLowColor(getColor(value))); //$NON-NLS-1$ | ||
propertyMap.put("non-trading-color", (chart, value) -> chart.setNonTradingColor(getColor(value))); //$NON-NLS-1$ | ||
} | ||
|
||
@Override | ||
public boolean applyCSSProperty(Object element, String property, CSSValue value, String pseudo, CSSEngine engine) | ||
throws Exception | ||
{ | ||
if (element instanceof SecuritiesChartElementAdapter adapter) | ||
{ | ||
SecuritiesChart chart = adapter.getSecuritiesChart(); | ||
ColorSetter colorSetter = propertyMap.get(property); | ||
|
||
switch (property) | ||
if (colorSetter != null) | ||
{ | ||
case "quote-color": //$NON-NLS-1$ | ||
chart.setQuoteColor(Colors.getColor(CSSSWTColorHelper.getRGBA(value).rgb)); | ||
break; | ||
default: | ||
colorSetter.setColor(chart, value); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Converts a CSSValue to a Color. | ||
*/ | ||
private Color getColor(CSSValue value) | ||
{ | ||
return Colors.getColor(CSSSWTColorHelper.getRGBA(value).rgb); | ||
} | ||
|
||
} |
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