Skip to content

Commit

Permalink
Added menus to export diagram and adjust range, zoom in/out
Browse files Browse the repository at this point in the history
Issue: #42
  • Loading branch information
buchen committed Jul 12, 2014
1 parent 9ebef16 commit 31342b2
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 11 deletions.
Expand Up @@ -133,15 +133,28 @@ protected void addButtons(ToolBar toolBar)
{}

protected final void hookContextMenu(Control control, IMenuListener listener)
{
doCreateContextMenu(control, true, listener);
}

protected final Menu createContextMenu(Control control, IMenuListener listener)
{
return doCreateContextMenu(control, false, listener);
}

private final Menu doCreateContextMenu(Control control, boolean hook, IMenuListener listener)
{
MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(listener);

Menu contextMenu = menuMgr.createContextMenu(control);
control.setMenu(contextMenu);
if (hook)
control.setMenu(contextMenu);

contextMenus.add(contextMenu);

return contextMenu;
}

public void dispose()
Expand Down
Expand Up @@ -301,9 +301,13 @@ public class Messages extends NLS
public static String LabelWithoutClassification;
public static String LabelYes;
public static String MenuAddAll;
public static String MenuChartAdjustRange;
public static String MenuChartZoomIn;
public static String MenuChartZoomOut;
public static String MenuConfigureChart;
public static String MenuExportChartData;
public static String MenuExportData;
public static String MenuExportDiagram;
public static String MenuOpenSecurityOnSite;
public static String MenuRemoveAll;
public static String MenuResetChartSeries;
Expand Down
Expand Up @@ -591,17 +591,25 @@ LabelYes = Yes

MenuAddAll = Add all

MenuChartAdjustRange = Adjust Range

MenuChartZoomIn = Zoom in

MenuChartZoomOut = Zoom out

MenuConfigureChart = Configure Chart

MenuExportChartData = Export chart data

MenuExportData = Export data

MenuExportDiagram = Export diagram

MenuOpenSecurityOnSite = Open in browser

MenuRemoveAll = Remove all

MenuResetChartSeries = Reset
MenuResetChartSeries = Reset data series

MenuResetColumns = Reset columns

Expand Down
Expand Up @@ -591,17 +591,25 @@ LabelYes = Ja

MenuAddAll = Alle hinzuf\u00FCgen

MenuChartAdjustRange = Originalgr\u00F6\u00DFe

MenuChartZoomIn = Vergr\u00F6\u00DFern

MenuChartZoomOut = Verkleinern

MenuConfigureChart = Diagramm konfigurieren

MenuExportChartData = Diagrammdaten exportieren

MenuExportData = Daten exportieren

MenuExportDiagram = Diagramm exportieren

MenuOpenSecurityOnSite = Im Browser \u00F6ffnen

MenuRemoveAll = Alle entfernen

MenuResetChartSeries = Zur\u00FCcksetzen
MenuResetChartSeries = Datenreihen zur\u00FCcksetzen

MenuResetColumns = Spalten zur\u00FCcksetzen

Expand Down
Expand Up @@ -7,8 +7,11 @@
import java.util.Date;
import java.util.List;

import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.PortfolioPlugin;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.swt.SWT;
Expand All @@ -21,6 +24,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Tracker;
import org.swtchart.Chart;
Expand Down Expand Up @@ -204,6 +208,8 @@ private MarkerLine(Date date, RGB color, String label)
}
}

private static final String[] EXTENSIONS = new String[] { "*.jpeg", "*.jpg", "*.png" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

private List<MarkerLine> markerLines = new ArrayList<MarkerLine>();
private TimelineChartToolTip toolTip;
private final LocalResourceManager resources;
Expand Down Expand Up @@ -387,4 +393,65 @@ private void paintMarkerLines(PaintEvent e)
e.gc.drawText(marker.label, textX, e.height - 20 - labelStackY, true);
}
}

public void configMenuAboutToShow(IMenuManager manager)
{
manager.add(new Action(Messages.MenuChartAdjustRange)
{
@Override
public void run()
{
getAxisSet().adjustRange();
redraw();
}
});

manager.add(new Action(Messages.MenuChartZoomIn)
{
@Override
public void run()
{
getAxisSet().zoomIn();
redraw();
}
});

manager.add(new Action(Messages.MenuChartZoomOut)
{
@Override
public void run()
{
getAxisSet().zoomOut();
redraw();
}
});
}

public void exportMenuAboutToShow(IMenuManager manager, final String label)
{
manager.add(new Action(Messages.MenuExportDiagram)
{
@Override
public void run()
{
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
dialog.setFileName(label);
dialog.setFilterExtensions(EXTENSIONS);

String filename = dialog.open();
if (filename == null) { return; }

int format;
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg")) //$NON-NLS-1$ //$NON-NLS-2$
format = SWT.IMAGE_JPEG;
else if (filename.endsWith(".png")) //$NON-NLS-1$
format = SWT.IMAGE_PNG;
else
format = SWT.IMAGE_UNDEFINED;

if (format != SWT.IMAGE_UNDEFINED)
save(filename, format);
}
});
}
}
Expand Up @@ -518,7 +518,7 @@ private void widgetDisposed()
store.dispose();
}

private void configMenuAboutToShow(IMenuManager manager)
public void configMenuAboutToShow(IMenuManager manager)
{
for (final DataSeries series : selectedSeries)
{
Expand Down
Expand Up @@ -29,12 +29,14 @@
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolBar;
import org.swtchart.ISeries;

Expand All @@ -53,16 +55,30 @@ protected void addButtons(ToolBar toolBar)
{
super.addButtons(toolBar);
addExportButton(toolBar);
addConfigButton(toolBar);
}

private void addExportButton(ToolBar toolBar)
{
Action export = new Action()
{
private Menu menu;

@Override
public void run()
{
new TimelineChartCSVExporter(chart).export(getTitle() + ".csv"); //$NON-NLS-1$
if (menu == null)
{
menu = createContextMenu(getActiveShell(), new IMenuListener()
{
@Override
public void menuAboutToShow(IMenuManager manager)
{
exportMenuAboutToShow(manager);
}
});
}
menu.setVisible(true);
}
};
export.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_EXPORT));
Expand All @@ -71,6 +87,48 @@ public void run()
new ActionContributionItem(export).fill(toolBar, -1);
}

private void exportMenuAboutToShow(IMenuManager manager)
{
manager.add(new Action(Messages.MenuExportChartData)
{
@Override
public void run()
{
new TimelineChartCSVExporter(chart).export(getTitle() + ".csv"); //$NON-NLS-1$
}
});
manager.add(new Separator());
chart.exportMenuAboutToShow(manager, getTitle());
}

private void addConfigButton(ToolBar toolBar)
{
Action config = new Action()
{
private Menu menu;

@Override
public void run()
{
if (menu == null)
{
menu = createContextMenu(getActiveShell(), new IMenuListener()
{
@Override
public void menuAboutToShow(IMenuManager manager)
{
chart.configMenuAboutToShow(manager);
}
});
}
menu.setVisible(true);
}
};
config.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_CONFIG));
config.setToolTipText(Messages.MenuConfigureChart);
new ActionContributionItem(config).fill(toolBar, -1);
}

@Override
public void notifyModelUpdated()
{
Expand Down
Expand Up @@ -33,13 +33,16 @@

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolBar;
import org.swtchart.IBarSeries;
import org.swtchart.ILineSeries;
Expand Down Expand Up @@ -85,10 +88,25 @@ public void run()

Action config = new Action()
{
private Menu menu;

@Override
public void run()
{
picker.showMenu(getActiveShell());
if (menu == null)
{
menu = createContextMenu(getActiveShell(), new IMenuListener()
{
@Override
public void menuAboutToShow(IMenuManager manager)
{
picker.configMenuAboutToShow(manager);
manager.add(new Separator());
chart.configMenuAboutToShow(manager);
}
});
}
menu.setVisible(true);
}
};
config.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_CONFIG));
Expand Down Expand Up @@ -412,6 +430,9 @@ public void run()
if (exportTypes.contains(series.getType()))
addMenu(manager, series.getInstance(), series.getLabel());
}

manager.add(new Separator());
chart.exportMenuAboutToShow(manager, getTitle());
}

private void addMenu(IMenuManager manager, final Object instance, final String label)
Expand Down

0 comments on commit 31342b2

Please sign in to comment.