Search in sources :

Example 1 with ColoredLabel

use of name.abuchen.portfolio.ui.util.swt.ColoredLabel in project portfolio by buchen.

the class LimitExceededWidget method createItemControl.

@Override
protected Composite createItemControl(Composite parent, LimitItem item) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FormLayout());
    Label logo = new Label(composite, SWT.NONE);
    logo.setImage(LogoManager.instance().getDefaultColumnImage(item.getSecurity(), getClient().getSettings()));
    Label name = new Label(composite, SWT.NONE);
    name.setText(item.getSecurity().getName());
    ColoredLabel price = new ColoredLabel(composite, SWT.RIGHT);
    // determine colors
    LimitPriceSettings settings = new LimitPriceSettings(item.attributeType.getProperties());
    price.setBackdropColor(item.limit.getRelationalOperator().isGreater() ? settings.getLimitExceededPositivelyColor(Colors.theme().greenBackground()) : settings.getLimitExceededNegativelyColor(Colors.theme().redBackground()));
    price.setText(Values.Quote.format(item.getSecurity().getCurrencyCode(), item.price.getValue()));
    Label limit = new Label(composite, SWT.NONE);
    limit.setText(settings.getFullLabel(item.limit, item.price));
    composite.addMouseListener(mouseUpAdapter);
    name.addMouseListener(mouseUpAdapter);
    limit.addMouseListener(mouseUpAdapter);
    price.addMouseListener(mouseUpAdapter);
    FormDataFactory.startingWith(logo).thenRight(name).right(new FormAttachment(100)).thenBelow(price).thenRight(limit);
    return composite;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) LimitPriceSettings(name.abuchen.portfolio.model.LimitPriceSettings) Composite(org.eclipse.swt.widgets.Composite) StyledLabel(name.abuchen.portfolio.ui.util.swt.StyledLabel) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Label(org.eclipse.swt.widgets.Label) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 2 with ColoredLabel

use of name.abuchen.portfolio.ui.util.swt.ColoredLabel in project portfolio by buchen.

the class AbstractHeatmapWidget method fillTable.

private void fillTable(HeatmapModel<N> model, Composite table, DashboardResources resources) {
    addHeaderRow(table, model);
    DoubleFunction<Color> coloring = optionallyGet(ColorSchemaConfig.class).map(s -> s.getValue().buildColorFunction(resources.getResourceManager())).orElse(null);
    Values<N> formatter = model.getFormatter();
    model.getRows().forEach(row -> {
        Label label = new Label(table, SWT.CENTER);
        label.setBackground(table.getBackground());
        label.setText(row.getLabel());
        if (row.getToolTip() != null)
            InfoToolTip.attach(label, row.getToolTip());
        row.getData().forEach(data -> {
            Control lbl = null;
            if (data != null) {
                ColoredLabel dataLabel = new ColoredLabel(table, SWT.CENTER);
                dataLabel.setData(UIConstants.CSS.CLASS_NAME, UIConstants.CSS.DATAPOINT);
                dataLabel.setText(formatter.format(data));
                if (coloring != null)
                    dataLabel.setBackdropColor(coloring.apply((double) data));
                lbl = dataLabel;
            } else {
                lbl = new Label(table, SWT.LEFT);
            }
            if (model.getCellToolTip() != null)
                InfoToolTip.attach(lbl, model.getCellToolTip().apply(data));
        });
    });
    SimpleGridLayout layout = new SimpleGridLayout();
    layout.setNumColumns(model.getHeaderSize() + 1);
    layout.setNumRows((int) model.getRows().count() + 1);
    layout.setRowHeight(SWTHelper.lineHeight(table) + 6);
    table.setLayout(layout);
    table.layout(true);
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Values(name.abuchen.portfolio.money.Values) DoubleFunction(java.util.function.DoubleFunction) ReportingPeriodConfig(name.abuchen.portfolio.ui.views.dashboard.ReportingPeriodConfig) Supplier(java.util.function.Supplier) Widget(name.abuchen.portfolio.model.Dashboard.Widget) WidgetDelegate(name.abuchen.portfolio.ui.views.dashboard.WidgetDelegate) TextUtil(name.abuchen.portfolio.util.TextUtil) Locale(java.util.Locale) Composite(org.eclipse.swt.widgets.Composite) DashboardResources(name.abuchen.portfolio.ui.views.dashboard.DashboardResources) UIConstants(name.abuchen.portfolio.ui.UIConstants) InfoToolTip(name.abuchen.portfolio.ui.util.InfoToolTip) TextStyle(java.time.format.TextStyle) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) List(java.util.List) Color(org.eclipse.swt.graphics.Color) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) DashboardData(name.abuchen.portfolio.ui.views.dashboard.DashboardData) SWTHelper(name.abuchen.portfolio.ui.util.SWTHelper) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) Control(org.eclipse.swt.widgets.Control) Color(org.eclipse.swt.graphics.Color) CLabel(org.eclipse.swt.custom.CLabel) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Label(org.eclipse.swt.widgets.Label) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel)

Example 3 with ColoredLabel

use of name.abuchen.portfolio.ui.util.swt.ColoredLabel in project portfolio by buchen.

the class AbstractIndicatorWidget method createControl.

@Override
public Composite createControl(Composite parent, DashboardResources resources) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setBackground(parent.getBackground());
    GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(container);
    title = new Label(container, SWT.NONE);
    title.setText(TextUtil.tooltip(getWidget().getLabel()));
    title.setBackground(Colors.theme().defaultBackground());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(title);
    indicator = new ColoredLabel(container, SWT.NONE);
    indicator.setData(UIConstants.CSS.CLASS_NAME, UIConstants.CSS.KPI);
    indicator.setBackground(Colors.theme().defaultBackground());
    // $NON-NLS-1$
    indicator.setText("");
    GridDataFactory.fillDefaults().grab(true, false).applyTo(indicator);
    return container;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Label(org.eclipse.swt.widgets.Label) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel)

Example 4 with ColoredLabel

use of name.abuchen.portfolio.ui.util.swt.ColoredLabel in project portfolio by buchen.

the class TimelineChartToolTip method createComposite.

@Override
protected void createComposite(Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.center = true;
    container.setLayout(layout);
    Composite data = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(data);
    Label left = new Label(data, SWT.NONE);
    left.setText(categoryEnabled ? getChart().getAxisSet().getXAxis(0).getTitle().getText() : Messages.ColumnDate);
    Label right = new Label(data, SWT.NONE);
    right.setText(formatXAxisData(getFocusedObject()));
    List<Pair<ISeries, Double>> values = computeValues(getChart().getSeriesSet().getSeries());
    if (reverseLabels)
        Collections.reverse(values);
    if (isAltPressed())
        Collections.sort(values, (l, r) -> r.getValue().compareTo(l.getValue()));
    for (Pair<ISeries, Double> value : values) {
        ISeries series = value.getKey();
        Color color = series instanceof ILineSeries ? ((ILineSeries) series).getLineColor() : ((IBarSeries) series).getBarColor();
        ColoredLabel cl = new ColoredLabel(data, SWT.NONE);
        cl.setBackdropColor(color);
        cl.setText(series.getId());
        GridDataFactory.fillDefaults().grab(true, false).applyTo(cl);
        right = new Label(data, SWT.RIGHT);
        DecimalFormat valueFormat = overrideValueFormat.getOrDefault(series.getId(), defaultValueFormat);
        right.setText(valueFormat.format(value.getRight()));
        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(right);
    }
    Object focus = getFocusedObject();
    extraInfoProvider.forEach(provider -> provider.accept(container, focus));
    Label hint = new Label(data, SWT.NONE);
    hint.setText(Messages.TooltipHintPressAlt);
    hint.setFont(this.resourceManager.createFont(FontDescriptor.createFrom(data.getFont()).increaseHeight(-3).withStyle(SWT.ITALIC)));
    GridDataFactory.fillDefaults().span(2, 1).applyTo(hint);
}
Also used : Arrays(java.util.Arrays) Values(name.abuchen.portfolio.money.Values) Date(java.util.Date) IAxis(org.swtchart.IAxis) HashMap(java.util.HashMap) JFaceResources(org.eclipse.jface.resource.JFaceResources) ISeries(org.swtchart.ISeries) Function(java.util.function.Function) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Chart(org.swtchart.Chart) Calendar(java.util.Calendar) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) ILineSeries(org.swtchart.ILineSeries) Pair(name.abuchen.portfolio.util.Pair) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) DecimalFormat(java.text.DecimalFormat) Set(java.util.Set) IBarSeries(org.swtchart.IBarSeries) ZoneId(java.time.ZoneId) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) List(java.util.List) RowLayout(org.eclipse.swt.layout.RowLayout) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Collections(java.util.Collections) Label(org.eclipse.swt.widgets.Label) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) ILineSeries(org.swtchart.ILineSeries) DecimalFormat(java.text.DecimalFormat) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Label(org.eclipse.swt.widgets.Label) ISeries(org.swtchart.ISeries) RowLayout(org.eclipse.swt.layout.RowLayout) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Pair(name.abuchen.portfolio.util.Pair)

Example 5 with ColoredLabel

use of name.abuchen.portfolio.ui.util.swt.ColoredLabel in project portfolio by buchen.

the class ScatterChartToolTip method createComposite.

@Override
protected void createComposite(Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setBackgroundMode(SWT.INHERIT_FORCE);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(container);
    IAxis xAxis = getChart().getAxisSet().getXAxis(0);
    IAxis yAxis = getChart().getAxisSet().getYAxis(0);
    ILineSeries closest = (ILineSeries) getFocusedObject();
    // header
    Label left = new Label(container, SWT.NONE);
    // $NON-NLS-1$
    left.setText("");
    Label middle = new Label(container, SWT.NONE);
    middle.setText(xAxis.getTitle().getText());
    Label right = new Label(container, SWT.NONE);
    right.setText(yAxis.getTitle().getText());
    // values
    ColoredLabel cl = new ColoredLabel(container, SWT.NONE);
    cl.setBackdropColor(closest.getSymbolColor());
    cl.setText(closest.getId());
    middle = new Label(container, SWT.RIGHT);
    middle.setText(xAxis.getTick().getFormat().format(closest.getXSeries()[0]));
    GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(middle);
    right = new Label(container, SWT.RIGHT);
    right.setText(yAxis.getTick().getFormat().format(closest.getYSeries()[0]));
    GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(right);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ILineSeries(org.swtchart.ILineSeries) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Label(org.eclipse.swt.widgets.Label) IAxis(org.swtchart.IAxis) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel)

Aggregations

ColoredLabel (name.abuchen.portfolio.ui.util.swt.ColoredLabel)5 Composite (org.eclipse.swt.widgets.Composite)5 Label (org.eclipse.swt.widgets.Label)5 List (java.util.List)2 Values (name.abuchen.portfolio.money.Values)2 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)2 GridLayoutFactory (org.eclipse.jface.layout.GridLayoutFactory)2 SWT (org.eclipse.swt.SWT)2 Color (org.eclipse.swt.graphics.Color)2 DecimalFormat (java.text.DecimalFormat)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 TextStyle (java.time.format.TextStyle)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1