javax.swing.JPopupMenu#getComponent ( )源码实例Demo

下面列出了javax.swing.JPopupMenu#getComponent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: snap-desktop   文件: UIUtils.java
public static JMenu findSubMenu(JPopupMenu popupMenu, String name) {
    int n = popupMenu.getComponentCount();
    for (int i = 0; i < n; i++) {
        Component c = popupMenu.getComponent(i);
        if (c instanceof JMenu) {
            JMenu subMenu = (JMenu) c;
            if (name.equals(subMenu.getName())) {
                return subMenu;
            }
            subMenu = findSubMenu(subMenu.getPopupMenu(), name);
            if (subMenu != null) {
                return subMenu;
            }
        }
    }
    return null;
}
 
源代码2 项目: openstock   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 *
 * @param menu  the menu.
 * @param text  the label.
 *
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码3 项目: ccu-historian   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 *
 * @param menu  the menu.
 * @param text  the label.
 *
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码4 项目: SIMVA-SoS   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 *
 * @param menu  the menu.
 * @param text  the label.
 *
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码5 项目: mzmine2   文件: FontBoxRenderer.java
private void manItemInCombo() {
  if (comboBox.getItemCount() > 0) {
    final Object comp = comboBox.getUI().getAccessibleChild(comboBox, 0);
    if ((comp instanceof JPopupMenu)) {
      final JList list = new JList(comboBox.getModel());
      final JPopupMenu popup = (JPopupMenu) comp;
      final JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
      final JViewport viewport = scrollPane.getViewport();
      final Rectangle rect = popup.getVisibleRect();
      final Point pt = viewport.getViewPosition();
      row = list.locationToIndex(pt);
    }
  }
}
 
源代码6 项目: wpcleaner   文件: AbstractMenuCreator.java
/**
 * Add a separator to a menu if useful.
 * 
 * @param menu Menu.
 * @return Number of items added.
 */
public int addSeparator(JPopupMenu menu) {
  if ((menu == null) || (menu.getComponentCount() == 0)) {
    return 0;
  }
  Component item = menu.getComponent(menu.getComponentCount() - 1);
  if (!(item instanceof JMenuItem)) {
    return 0;
  }
  menu.add(new JSeparator());
  return 1;
}
 
源代码7 项目: ECG-Viewer   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 *
 * @param menu  the menu.
 * @param text  the label.
 *
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码8 项目: astor   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 *
 * @param menu  the menu.
 * @param text  the label.
 *
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码9 项目: astor   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 * 
 * @param menu  the menu.
 * @param text  the label.
 * 
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码10 项目: opensim-gui   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 * 
 * @param menu  the menu.
 * @param text  the label.
 * 
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码11 项目: snap-desktop   文件: UIUtils.java
public static int findMenuItemPosition(JPopupMenu popupMenu, String name) {
    int n = popupMenu.getComponentCount();
    for (int i = 0; i < n; i++) {
        Component c = popupMenu.getComponent(i);
        if (c instanceof JMenuItem) {
            JMenuItem menuItem = (JMenuItem) c;
            if (name.equals(menuItem.getName())) {
                return i;
            }
        }
    }
    return -1;
}
 
源代码12 项目: buffer_bci   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 *
 * @param menu  the menu.
 * @param text  the label.
 *
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码13 项目: buffer_bci   文件: PolarChartPanel.java
/**
 * Returns the index of an item in a popup menu.
 *
 * @param menu  the menu.
 * @param text  the label.
 *
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
源代码14 项目: gate-core   文件: AnnotationSetsView.java
@Override
public void actionPerformed(ActionEvent evt){
  if(annotationEditor == null) return;
  //this action either creates a new annotation or starts editing an 
  //existing one. In either case we need first to make sure that the current
  //annotation is finished editing.
  if(!annotationEditor.editingFinished()) return;
  if(textLocation == -1) return;
  JPopupMenu popup = new JPopupMenu();

  //check for selection hovering
  if(textPane.getSelectedText() != null
      && textPane.getSelectionStart() <= textLocation
      && textPane.getSelectionEnd() >= textLocation){
    //add 'New annotation' to the popup menu
    popup.add(new NewAnnotationAction(textPane.getSelectedText()));
    popup.addSeparator();
  }

  //check for annotations at location
  for(SetHandler setHandler : setHandlers) {
    for(Annotation ann : setHandler.set.get(
          Math.max(0l, textLocation-1),
          Math.min(document.getContent().size(), textLocation+1))) {
      if(setHandler.getTypeHandler(ann.getType()).isSelected()) {
        AnnotationDataImpl annotAtPoint =
          new AnnotationDataImpl(setHandler.set, ann);
        //add annotations to edit to the popup menu
        popup.add(new HighlightMenuItem(
          new EditAnnotationAction(annotAtPoint),
          annotAtPoint.getAnnotation().getStartNode().getOffset().intValue(),
          annotAtPoint.getAnnotation().getEndNode().getOffset().intValue(),
          popup));
      }
    }
  }

  if (popup.getComponentCount() == 0) {
    // nothing to do
  } else if(popup.getComponentCount() == 1
    || (popup.getComponentCount() == 2
     && popup.getComponent(1) instanceof JSeparator)) {
    //only one annotation, start the editing directly
    //or only one selection, add new annotation
    ((JMenuItem)popup.getComponent(0)).getAction().actionPerformed(evt);
  } else { //mouse hover a selection AND annotation(s)
    try{
      Rectangle rect =  textPane.modelToView(textLocation);
      //display the popup
      popup.show(textPane, rect.x + 10, rect.y);
    }catch(BadLocationException ble){
      throw new GateRuntimeException(ble);
    }
  }
}
 
源代码15 项目: mzmine2   文件: MsMsPlot.java
MsMsPlot(final ActionListener listener, RawDataFile rawDataFile, MsMsVisualizerWindow visualizer,
    MsMsDataSet dataset, Range<Double> rtRange, Range<Double> mzRange) {

  super(null, true);

  this.visualizer = visualizer;
  this.rawDataFile = rawDataFile;
  this.rtRange = rtRange;
  this.mzRange = mzRange;

  // initialize the chart by default time series chart from factory
  chart = ChartFactory.createXYLineChart("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // create legend
      false, // generate tooltips
      false // generate URLs
  );

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // Set the domain log axis
  xAxis = new NumberAxis("Retention time (min)");
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.01);
  xAxis.setLowerMargin(0.01);
  plot.setDomainAxis(xAxis);

  // Set the range log axis
  yAxis = new NumberAxis("Precursor m/z");
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);
  yAxis.setUpperMargin(0.1);
  yAxis.setLowerMargin(0.1);
  plot.setRangeAxis(yAxis);

  // Set crosshair properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  // Create renderers
  mainRenderer = new MsMsPlotRenderer();
  plot.setRenderer(0, mainRenderer);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // Add data sets;
  plot.setDataset(0, dataset);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  peakDataRenderer = new PeakDataRenderer();

  // Add EMF and EPS options to the save as menu
  JPopupMenu popupMenu = getPopupMenu();
  JMenuItem saveAsMenu = (JMenuItem) popupMenu.getComponent(3);
  GUIUtils.addMenuItem(saveAsMenu, "EMF...", this, "SAVE_EMF");
  GUIUtils.addMenuItem(saveAsMenu, "EPS...", this, "SAVE_EPS");

  // Register for mouse-wheel events
  addMouseWheelListener(this);

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
源代码16 项目: mzmine2   文件: ScatterPlotChart.java
public ScatterPlotChart(ScatterPlotWindow window, ScatterPlotTopPanel topPanel,
    PeakList peakList) {

  super(null, true);

  this.window = window;
  this.peakList = peakList;
  this.topPanel = topPanel;

  // initialize the chart by default time series chart from factory
  chart = ChartFactory.createXYLineChart("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      false, // create legend
      false, // generate tooltips
      false // generate URLs
  );

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // Set the domain log axis
  LogAxis logAxisDomain = new LogAxis();
  logAxisDomain.setMinorTickCount(1);
  logAxisDomain.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());
  logAxisDomain.setAutoRange(true);
  plot.setDomainAxis(logAxisDomain);

  // Set the range log axis
  LogAxis logAxisRange = new LogAxis();
  logAxisRange.setMinorTickCount(1);
  logAxisRange.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());
  logAxisRange.setAutoRange(true);
  plot.setRangeAxis(logAxisRange);

  // Set crosshair properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  // Create data sets;
  mainDataSet = new ScatterPlotDataSet(peakList);
  plot.setDataset(0, mainDataSet);
  diagonalLineDataset = new DiagonalLineDataset();
  plot.setDataset(1, diagonalLineDataset);

  // Create renderers
  mainRenderer = new ScatterPlotRenderer();
  plot.setRenderer(0, mainRenderer);
  diagonalLineRenderer = new DiagonalLineRenderer();
  plot.setRenderer(1, diagonalLineRenderer);

  // Set tooltip properties
  ttm = new ComponentToolTipManager();
  ttm.registerComponent(this);
  setDismissDelay(Integer.MAX_VALUE);
  setInitialDelay(0);

  // add items to popup menu TODO: add other Show... items
  JPopupMenu popupMenu = getPopupMenu();
  popupMenu.addSeparator();
  GUIUtils.addMenuItem(popupMenu, "Show Chromatogram", this, "TIC");

  // Add EMF and EPS options to the save as menu
  JMenuItem saveAsMenu = (JMenuItem) popupMenu.getComponent(3);
  GUIUtils.addMenuItem(saveAsMenu, "EMF...", this, "SAVE_EMF");
  GUIUtils.addMenuItem(saveAsMenu, "EPS...", this, "SAVE_EPS");

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
源代码17 项目: mzmine2   文件: TwoDPlot.java
TwoDPlot(RawDataFile rawDataFile, TwoDVisualizerWindow visualizer, TwoDDataSet dataset,
    Range<Double> rtRange, Range<Double> mzRange, String whichPlotTypeStr) {

  super(null, true);

  this.rawDataFile = rawDataFile;
  this.rtRange = rtRange;
  this.mzRange = mzRange;

  setBackground(Color.white);
  setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

  // set the X axis (retention time) properties
  xAxis = new NumberAxis("Retention time");
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0);
  xAxis.setLowerMargin(0);

  // set the Y axis (intensity) properties
  yAxis = new NumberAxis("m/z");
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);
  yAxis.setUpperMargin(0);
  yAxis.setLowerMargin(0);

  // set the plot properties
  if (whichPlotTypeStr == "default") {
    plot = new TwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  } else if (whichPlotTypeStr == "point2D") {
    plot = new PointTwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  }
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // chart properties
  chart = new JFreeChart("", titleFont, plot, false);
  chart.setBackgroundPaint(Color.white);

  setChart(chart);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);

  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set crosshair (selection) properties
  plot.setRangeCrosshairVisible(false);
  plot.setDomainCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  peakDataRenderer = new PeakDataRenderer();

  JMenuItem plotTypeMenuItem = new JMenuItem("Toggle centroid/continuous mode");
  plotTypeMenuItem.addActionListener(visualizer);
  plotTypeMenuItem.setActionCommand("SWITCH_PLOTMODE");
  add(plotTypeMenuItem);

  JPopupMenu popupMenu = getPopupMenu();
  popupMenu.addSeparator();
  popupMenu.add(plotTypeMenuItem);

  // Add EMF and EPS options to the save as menu
  JMenuItem saveAsMenu = (JMenuItem) popupMenu.getComponent(3);
  GUIUtils.addMenuItem(saveAsMenu, "EMF...", this, "SAVE_EMF");
  GUIUtils.addMenuItem(saveAsMenu, "EPS...", this, "SAVE_EPS");


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}