@Override public void mouseClicked(MouseEvent event){
  if (SwingUtilities.isRightMouseButton(event)) {
    JPopupMenu contextMenu=new JPopupMenu();
    if (event.getComponent() == mWaterfallPanel) {
      contextMenu.add(new PauseItem(mWaterfallPanel,"Pause"));
    }
    long frequency=mOverlayPanel.getFrequencyFromAxis(event.getX());
    if (event.getComponent() == mOverlayPanel) {
      ArrayList<Channel> channels=mOverlayPanel.getChannelsAtFrequency(frequency);
      for (      Channel channel : channels) {
        JMenu channelMenu=ChannelUtils.getContextMenu(mChannelModel,mChannelProcessingManager,channel,SpectralDisplayPanel.this);
        if (channelMenu != null) {
          contextMenu.add(channelMenu);
        }
      }
      if (!channels.isEmpty()) {
        contextMenu.add(new JSeparator());
      }
    }
    JMenu frequencyMenu=new JMenu(sCURSOR_FORMAT.format((float)frequency / 1000000.0f));
    JMenu decoderMenu=new JMenu("Add Decoder");
    for (    DecoderType type : DecoderType.getPrimaryDecoders()) {
      decoderMenu.add(new DecoderItem(type,frequency));
    }
    frequencyMenu.add(decoderMenu);
    contextMenu.add(frequencyMenu);
    contextMenu.add(new JSeparator());
    JMenu colorMenu=new JMenu("Color");
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.CHANNEL_CONFIG));
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.CHANNEL_CONFIG_PROCESSING));
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.CHANNEL_CONFIG_SELECTED));
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.SPECTRUM_CURSOR));
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.SPECTRUM_LINE));
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.SPECTRUM_BACKGROUND));
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.SPECTRUM_GRADIENT_BOTTOM));
    colorMenu.add(new ColorSettingMenuItem(mSettingsManager,ColorSettingName.SPECTRUM_GRADIENT_TOP));
    contextMenu.add(colorMenu);
    JMenu displayMenu=new JMenu("Display");
    contextMenu.add(displayMenu);
    if (event.getComponent() != mWaterfallPanel) {
      JMenu averagingMenu=new JMenu("Averaging");
      averagingMenu.add(new AveragingItem(mSpectrumPanel,4));
      displayMenu.add(averagingMenu);
      JMenu channelDisplayMenu=new JMenu("Channel");
      channelDisplayMenu.add(new ChannelDisplayItem(mOverlayPanel,ChannelDisplay.ALL));
      channelDisplayMenu.add(new ChannelDisplayItem(mOverlayPanel,ChannelDisplay.ENABLED));
      channelDisplayMenu.add(new ChannelDisplayItem(mOverlayPanel,ChannelDisplay.NONE));
      displayMenu.add(channelDisplayMenu);
    }
    JMenu fftWidthMenu=new JMenu("FFT Width");
    displayMenu.add(fftWidthMenu);
    for (    DFTSize width : DFTSize.values()) {
      fftWidthMenu.add(new DFTSizeItem(SpectralDisplayPanel.this,width));
    }
    JMenu frameRateMenu=new JMenu("Frame Rate");
    displayMenu.add(frameRateMenu);
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,14));
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,16));
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,18));
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,20));
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,25));
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,30));
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,40));
    frameRateMenu.add(new FrameRateItem(mDFTProcessor,50));
    JMenu fftWindowType=new JMenu("Window Type");
    displayMenu.add(fftWindowType);
    for (    WindowType type : WindowType.values()) {
      fftWindowType.add(new FFTWindowTypeItem(mDFTProcessor,type));
    }
    if (event.getComponent() != mWaterfallPanel) {
      JMenu smoothingMenu=new JMenu("Smoothing");
      if (mSpectrumPanel.getSmoothingType() != SmoothingType.NONE) {
        smoothingMenu.add(new SmoothingItem(mSpectrumPanel,5));
        smoothingMenu.add(new JSeparator());
      }
      smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel,SmoothingType.GAUSSIAN));
      smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel,SmoothingType.TRIANGLE));
      smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel,SmoothingType.RECTANGLE));
      smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel,SmoothingType.NONE));
      displayMenu.add(smoothingMenu);
    }
    JMenuItem zoomMenu=new JMenu("Zoom");
    double windowOffset=(double)event.getX() / (double)getWidth();
    zoomMenu.add(new ZoomItem(frequency,windowOffset));
    contextMenu.add(zoomMenu);
    if (contextMenu != null) {
      if (event.getComponent() == mOverlayPanel) {
        contextMenu.show(mOverlayPanel,event.getX(),event.getY());
      }
 else {
        contextMenu.show(mWaterfallPanel,event.getX(),event.getY());
      }
    }
  }
}

@ Override public void mouseClicked ( MouseEvent event ) { if ( SwingUtilities . isRightMouseButton ( event ) ) { JPopupMenu contextMenu = new JPopupMenu ( ) ; if ( event . getComponent ( ) == mWaterfallPanel ) { contextMenu . add ( new PauseItem ( mWaterfallPanel , "Pause" ) ) ; } long frequency = mOverlayPanel . getFrequencyFromAxis ( event . getX ( ) ) ; if ( event . getComponent ( ) == mOverlayPanel ) { ArrayList < Channel > channels = mOverlayPanel . getChannelsAtFrequency ( frequency ) ; for ( Channel channel : channels ) { JMenu channelMenu = ChannelUtils . getContextMenu ( mChannelModel , mChannelProcessingManager , channel , SpectralDisplayPanel . this ) ; if ( channelMenu != null ) { contextMenu . add ( channelMenu ) ; } } if ( ! channels . isEmpty ( ) ) { contextMenu . add ( new JSeparator ( ) ) ; } } JMenu frequencyMenu = new JMenu ( sCURSOR_FORMAT . format ( ( float ) frequency / 1000000.0f ) ) ; JMenu decoderMenu = new JMenu ( "Add Decoder" ) ; for ( DecoderType type : DecoderType . getPrimaryDecoders ( ) ) { decoderMenu . add ( new DecoderItem ( type , frequency ) ) ; } frequencyMenu . add ( decoderMenu ) ; contextMenu . add ( frequencyMenu ) ; contextMenu . add ( new JSeparator ( ) ) ; JMenu colorMenu = new JMenu ( "Color" ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . CHANNEL_CONFIG ) ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . CHANNEL_CONFIG_PROCESSING ) ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . CHANNEL_CONFIG_SELECTED ) ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . SPECTRUM_CURSOR ) ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . SPECTRUM_LINE ) ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . SPECTRUM_BACKGROUND ) ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . SPECTRUM_GRADIENT_BOTTOM ) ) ; colorMenu . add ( new ColorSettingMenuItem ( mSettingsManager , ColorSettingName . SPECTRUM_GRADIENT_TOP ) ) ; contextMenu . add ( colorMenu ) ; JMenu displayMenu = new JMenu ( "Display" ) ; contextMenu . add ( displayMenu ) ; if ( event . getComponent ( ) != mWaterfallPanel ) { JMenu averagingMenu = new JMenu ( "Averaging" ) ; averagingMenu . add ( new AveragingItem ( mSpectrumPanel , 4 ) ) ; displayMenu . add ( averagingMenu ) ; JMenu channelDisplayMenu = new JMenu ( "Channel" ) ; channelDisplayMenu . add ( new ChannelDisplayItem ( mOverlayPanel , ChannelDisplay . ALL ) ) ; channelDisplayMenu . add ( new ChannelDisplayItem ( mOverlayPanel , ChannelDisplay . ENABLED ) ) ; channelDisplayMenu . add ( new ChannelDisplayItem ( mOverlayPanel , ChannelDisplay . NONE ) ) ; displayMenu . add ( channelDisplayMenu ) ; } JMenu fftWidthMenu = new JMenu ( "FFT Width" ) ; displayMenu . add ( fftWidthMenu ) ; for ( DFTSize width : DFTSize . values ( ) ) { fftWidthMenu . add ( new DFTSizeItem ( SpectralDisplayPanel . this , width ) ) ; } JMenu frameRateMenu = new JMenu ( "Frame Rate" ) ; displayMenu . add ( frameRateMenu ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 14 ) ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 16 ) ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 18 ) ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 20 ) ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 25 ) ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 30 ) ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 40 ) ) ; frameRateMenu . add ( new FrameRateItem ( mDFTProcessor , 50 ) ) ; JMenu fftWindowType = new JMenu ( "Window Type" ) ; displayMenu . add ( fftWindowType ) ; for ( WindowType type : WindowType . values ( ) ) { fftWindowType . add ( new FFTWindowTypeItem ( mDFTProcessor , type ) ) ; } if ( event . getComponent ( ) != mWaterfallPanel ) { JMenu smoothingMenu = new JMenu ( "Smoothing" ) ; if ( mSpectrumPanel . getSmoothingType ( ) != SmoothingType . NONE ) { smoothingMenu . add ( new SmoothingItem ( mSpectrumPanel , 5 ) ) ; smoothingMenu . add ( new JSeparator ( ) ) ; } smoothingMenu . add ( new SmoothingTypeItem ( mSpectrumPanel , SmoothingType . GAUSSIAN ) ) ; smoothingMenu . add ( new SmoothingTypeItem ( mSpectrumPanel , SmoothingType . TRIANGLE ) ) ; smoothingMenu . add ( new SmoothingTypeItem ( mSpectrumPanel , SmoothingType . RECTANGLE ) ) ; smoothingMenu . add ( new SmoothingTypeItem ( mSpectrumPanel , SmoothingType . NONE ) ) ; displayMenu . add ( smoothingMenu ) ; } JMenuItem zoomMenu = new JMenu ( "Zoom" ) ; double windowOffset = ( double ) event . getX ( ) / ( double ) getWidth ( ) ; zoomMenu . add ( new ZoomItem ( frequency , windowOffset ) ) ; contextMenu . add ( zoomMenu ) ; if ( contextMenu != null ) { if ( event . getComponent ( ) == mOverlayPanel ) { contextMenu . show ( mOverlayPanel , event . getX ( ) , event . getY ( ) ) ; } else { contextMenu . show ( mWaterfallPanel , event . getX ( ) , event . getY ( ) ) ; } } } }
displays the context menu .
