I created a panel with a polar chart, and was requested to remove zoom in, zoom out and autorange from the popup menu. With any other ChartPanel, I could accomplish with arguments to the constructor. However, the constructor for PolarChartPanel does not support this.
The createPopupMenu method supports turning off these items, but it is protected. Otherwise I would just call it to create the desired popup menu and then set that as the menu.
My application is for someone who is happy to take the software and the full JFreeChart distribution unmodified from what I download from http://www.jfree.org, but unwilling to accept a JFreeChart version I customize.
Is there some way to either get a popup menu with just the options: properties, copy, save as and print included or to remove options from an existing popup?
I have used setDomainZoomable( false ) and setRangeZoomable( false ), so zooming does not happen. But they are still on the menu of the popup.
Customizing Popup menu for PolarChartPanel
-
- Posts: 18
- Joined: Sat Jun 02, 2012 6:12 pm
- antibot: No, of course not.
-
- Posts: 18
- Joined: Sat Jun 02, 2012 6:12 pm
- antibot: No, of course not.
Re: Customizing Popup menu for PolarChartPanel
So far, I am thinking I need to make an all new menu. This is close to the default menu, except that I am not seeing methods to save to SVG or PDF format, only PNG. So if someone knows what they are, I'd appreciate the help.
Code: Select all
JPopupMenu menu = new JPopupMenu();
JMenuItem menuitem = new JMenuItem( "Properties..." );
menuitem.addActionListener( new ChartPropertiesListener() );
menu.add( menuitem );
menu.add( new JSeparator() );
menuitem = new JMenuItem( "Copy" );
menuitem.addActionListener( new ChartCopyListener() );
menu.add( menuitem );
menuitem = new JMenuItem( "Save as" );
menuitem.addActionListener( new ChartSaveasListener() );
menu.add( menuitem );
menu.add( new JSeparator() );
menuitem = new JMenuItem( "Print..." );
menuitem.addActionListener( new ChartPrintListener() );
menu.add( menuitem );
panel.setPopupMenu( menu );
Code: Select all
/**
* Listener for chart properties
*
*/
class ChartPropertiesListener implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
panel.doEditChartProperties();
}
}
/**
* Listener for chart copy
*
*/
class ChartCopyListener implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
panel.doCopy();
}
}
/**
* Listener for chart save as
*
*/
class ChartSaveasListener implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
try
{
panel.doSaveAs();
}
catch ( IOException ioe )
{
System.out.println( "Could not save chart" );
}
}
}
/**
* Listener for chart print
*
*/
class ChartPrintListener implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
panel.createChartPrintJob();
}
}
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Customizing Popup menu for PolarChartPanel
For the PDF and SVG export options, there is some code in ChartPanel that is auto-detecting if OrsonPDF and JFreeSVG are on the class path, and adding the menu items only if they are there. It looks like the PolarChartPanel class skips this code entirely, so there is some work to do to add these.
I'm wondering if it would be possible to integrate the special case handling in PolarChartPanel directly into ChartPanel, since it only relates to the zooming functions. I won't have time to analyse that in depth though, at least for a while.
I'm wondering if it would be possible to integrate the special case handling in PolarChartPanel directly into ChartPanel, since it only relates to the zooming functions. I won't have time to analyse that in depth though, at least for a while.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

