Example usage for javax.swing JPopupMenu getComponent

List of usage examples for javax.swing JPopupMenu getComponent

Introduction

In this page you can find the example usage for javax.swing JPopupMenu getComponent.

Prototype

public Component getComponent(int n) 

Source Link

Document

Gets the nth component in this container.

Usage

From source file:net.sourceforge.processdash.ev.ui.chart.EVHiddenOrShownSeriesXYChartPanel.java

private void reloadSeriesMenus() {
    JPopupMenu menu = getPopupMenu();
    while (menu.getComponent(0) instanceof ShowChartLineMenuItem)
        menu.remove(0);/*from www .  ja  va  2  s. c  o m*/
    XYDataset data = filteredData.getSourceDataset();
    for (int i = data.getSeriesCount(); i-- > 0;)
        menu.insert(new ShowChartLineMenuItem(filteredData, i), 0);
}

From source file:net.sf.mzmine.modules.visualization.ida.IDAPlot.java

IDAPlot(final ActionListener listener, RawDataFile rawDataFile, IDAVisualizerWindow visualizer,
        IDADataSet 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
    );//from ww  w  .j av a  2  s  .c  o m

    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 IDAPlotRenderer();
    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);
}

From source file:net.sf.mzmine.modules.visualization.msms.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
    );//w  w w  .  j a v a2  s .  c o m

    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);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Adds a special key listener to process a RETURN key for selecting and item
 * in the popup list. This is installed only for Windows and Linux.
 * @param popupMenu the popup menu to be altered.
 *//*  w w w  .ja  v  a 2 s .  c om*/
public static void addSpecialKeyListenerForPopup(final JPopupMenu popupMenu) {
    if (!UIHelper.isMacOS()) {
        popupMenu.addKeyListener(new KeyAdapter() {
            //@Override 
            public void keyPressed(KeyEvent e) {
                super.keyPressed(e);

                if (e.getKeyCode() == VK_ENTER) {
                    for (int i = 0; i < popupMenu.getComponentCount(); i++) {
                        Component c = popupMenu.getComponent(i);
                        if (c instanceof JMenuItem) {
                            JMenuItem mi = (JMenuItem) c;
                            if (mi.isArmed()) {
                                mi.doClick();
                                popupMenu.setVisible(false);
                            }
                        }
                    }
                }
            }
        });
    }
}

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Sets the visible tasks in the given 'pane' and 'menu'. The method takes an interval of
 * indices (end index should be -1 to go to the end), as well as a whether they should be set to
 * visible or not-visible.//from www. ja  v a  2 s  .  c o m
 */
public void setVisibleTasks(JXTaskPane pane, JPopupMenu menu, int startIndex, int endIndex, boolean visible) {
    // If the endIndex is -1, disregard it, otherwise stop there.
    for (int i = startIndex; (endIndex == -1 ? true : i <= endIndex)
            && (i < pane.getContentPane().getComponentCount()); i++) {
        // If the component being set visible is in the security list, don't allow it.

        boolean componentVisible = visible;
        String componentTask = getComponentTaskMap().get(pane.getContentPane().getComponent(i));
        if (componentTask != null) {
            if (!AuthorizationControllerFactory.getAuthorizationController().checkTask(pane.getName(),
                    componentTask)) {
                componentVisible = false;
            }
        }

        pane.getContentPane().getComponent(i).setVisible(componentVisible);

        if (menu != null) {
            menu.getComponent(i).setVisible(componentVisible);
        }
    }
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * @return/*  w  ww  .java  2 s .c  om*/
 * @precondition hasComparisonOperator()
 */
public JPopupMenu newComparisonOperatorPopupMenu() {
    if (!hasComparisonOperator()) {
        throw new IllegalStateException();
    }
    final JPopupMenu result = new JPopupMenu(
            getSpringLocaleDelegate().getMessage("AbstractCollectableComponent.16", "Vergleichsoperator"));

    // 1. comparison operators:
    final ButtonGroup btngrpComparisonOperators = new ButtonGroup();

    final ItemListener itemlistener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                final String sOperatorName = ((AbstractButton) ev.getItem()).getActionCommand();
                setComparisonOperator(ComparisonOperator.getInstance(sOperatorName));
                runLocked(new Runnable() {
                    @Override
                    public void run() {
                        updateSearchConditionInModel();
                    }
                });
            }
        }
    };

    ComparisonOperator[] supportedComparisonOperators = getSupportedComparisonOperators();
    if (supportedComparisonOperators == null)
        return null;

    for (ComparisonOperator compop : supportedComparisonOperators) {
        JMenuItem mi = new JRadioButtonMenuItem(
                getSpringLocaleDelegate().getMessage(compop.getResourceIdForLabel(), null));
        mi.setActionCommand(compop.name());
        mi.setToolTipText(getSpringLocaleDelegate().getMessage(compop.getResourceIdForDescription(), null));
        result.add(mi);
        btngrpComparisonOperators.add(mi);
        mi.addItemListener(itemlistener);
    }

    result.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            for (int i = 0, n = result.getComponentCount(); i < n; i++) {
                Component c = result.getComponent(i);
                if (c instanceof JMenuItem && StringUtils.emptyIfNull(((JMenuItem) c).getActionCommand())
                        .equals(getComparisonOperator().name()))
                    ((JMenuItem) c).setSelected(true);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent ev) {
        }
    });

    // 2. right operand (value or other field):
    if (canDisplayComparisonWithOtherField()) {
        addRightOperandToPopupMenu(result, this);
    }

    return result;
}

From source file:org.rdv.viz.spectrum.SpectrumViz.java

/**
 * Initializes the popup menu. This takes the popup menu from the chart and
 * adds on to it.//from www. j  a va  2s.  c o  m
 */
private void initPopupMenu() {
    JPopupMenu popupMenu = spectrumAnalyzerPanel.getPopupMenu();

    JMenuItem propertiesMenuItem = (JMenuItem) popupMenu.getComponent(0);
    propertiesMenuItem.setText("Chart Properties...");

    popupMenu.add(new JPopupMenu.Separator());

    showPropertiesMenuItem = new JCheckBoxMenuItem("Show properties", true);
    showPropertiesMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setPropertiesVisible(showPropertiesMenuItem.isSelected());
        }
    });
    popupMenu.add(showPropertiesMenuItem);

    panel.setComponentPopupMenu(popupMenu);
}

From source file:org.ut.biolab.medsavant.client.view.genetics.variantinfo.VariantFrequencyAggregatePane.java

public void setVariantRecords(Set<VariantRecord> records) {
    innerPanel.removeAll();//from w w  w  .j  a v  a  2 s . c o m
    //This function executes quickly, no need for waitPanel.
    //innerPanel.add(new WaitPanel("Loading DNA Ids..."));
    tableModel.setValues(records);
    aggregateTable = new AggregateTable(tableModel) {
        @Override
        //Necessary to enable buttons within the table.
        public boolean isCellEditable(int rowIndex, int colIndex) {
            return colIndex == buttonIndex;
        }

        //"Disables" selection within the aggregateTable.
        @Override
        public TableCellRenderer getCellRenderer(final int rowIndex, final int columnIndex) {
            final TableCellRenderer renderer = super.getCellRenderer(rowIndex, columnIndex);
            return new TableCellRenderer() {
                @Override
                public Component getTableCellRendererComponent(JTable jtable, final Object o, boolean bln,
                        boolean bln1, int i, int i1) {
                    return renderer.getTableCellRendererComponent(jtable, o, false, false, i, i1);
                }
            };
        }

        //This overridden method, together with the custom mouse listener on the 
        //AggregateTable header, disallows moving the first column, and columns
        //>= dnaIDIndex                    
        @Override
        protected AggregateTable.DraggingHandler createDraggingColumnPropertyChangeListener() {
            return new AggregateTable.DraggingHandler() {
                @Override
                public void columnMoved(TableColumnModelEvent e) {
                    if (fromColumnIndex == -1) {
                        fromColumnIndex = e.getFromIndex();
                    }
                    toColumnIndex = e.getToIndex();
                }

            };
        }
    };

    header = new AggregateTableHeader(aggregateTable);
    header.addMouseListener(new MouseAdapter() {
        //Disable moving the first column, or columns with index
        //>=dnaIDIndex
        @Override
        public void mouseReleased(MouseEvent e) {
            if (toColumnIndex != -1 && ((toColumnIndex == 0 || fromColumnIndex == 0)
                    || (toColumnIndex >= dnaIDIndex || fromColumnIndex >= dnaIDIndex))) {
                aggregateTable.moveColumn(toColumnIndex, fromColumnIndex);
                String msg = "This column cannot be moved.";
                DialogUtils.displayMessage(msg);
            } else {
                for (int columnHeaderIndex = 0; columnHeaderIndex < header.getColumnModel().getColumnCount()
                        - 2; columnHeaderIndex++) {
                    String columnTitle = (String) header.getColumnModel().getColumn(columnHeaderIndex)
                            .getHeaderValue();
                    aggregateColumns[columnHeaderIndex] = columnTitle;
                }
                reaggregate();
            }
            //aggregateTable.aggregate(this.aggregateColumns);
            fromColumnIndex = -1;
            toColumnIndex = -1;
            //expandAllButLast();
        }
    });

    header.setAutoFilterEnabled(false);
    header.setReorderingAllowed(true);
    header.setFont(TABLE_FONT_LARGE);
    aggregateTable.setTableHeader(header);
    aggregateTable.setAutoResizeMode(AggregateTable.AUTO_RESIZE_ALL_COLUMNS);
    aggregateTable.setFont(TABLE_FONT_LARGE);

    //Setup a custom "summary".  This is what calculates frequencies when cells are
    //collapsed
    PivotField f = aggregateTable.getAggregateTableModel().getField(BasicVariantColumns.DNA_ID.getAlias());
    f.setSummaryType(PivotConstants.SUMMARY_RESERVED_MAX + 1);
    aggregateTable.getAggregateTableModel().setSummaryCalculator(new SummaryCalculator() {
        private Set<String> collapsedDNAIDs = new HashSet<String>();
        private Values lastRowValues;
        private int valueCount = 0;
        private final int SUMMARY_FREQ = PivotConstants.SUMMARY_RESERVED_MAX + 1;

        @Override
        public void addValue(PivotValueProvider dataModel, PivotField field, Values rowValues,
                Values columnValues, Object object) {
            //this gets called multiple times for all the cells that disappear when 
            //something is collapsed.  
            // row[0] is the value of the corresponding first column: e.g. a Cohort or Family. 
            // columnValues can be ignored (blank)
            // Object is the value of the item in the cell that disappeared. (i.e. those cells which are being summarized)
            // field.getName() is the column name corresponding to Object

            // Useful Debugging code:                      
            //if(field.getName().equals(BasicVariantColumns.DNA_ID.getAlias())){

            /*
             System.out.println("==========");
             System.out.println("Field : " + field.getName());
             System.out.println("Row values: ");
                    
             for (int i = 0; i < rowValues.getCount(); ++i) {
             System.out.println("\trow[" + i + "] = " + rowValues.getValueAt(i).getValue());
                    
             }
                    
             System.out.println("Column values: ");
             for (int i = 0; i < columnValues.getCount(); ++i) {
             System.out.println("\tcol[" + i + "] = " + columnValues.getValueAt(i).getValue());
             }
                    
             System.out.println("Object: ");
             System.out.println("\t" + object);
             System.out.println("==========");
             */

            // }
            if (field.getName().equals(BasicVariantColumns.DNA_ID.getAlias())) {
                collapsedDNAIDs.add((String) object);
                lastRowValues = rowValues;
            } else {
                lastRowValues = null;
            }
            valueCount++;
        }

        //Should never be called
        @Override
        public void addValue(Object o) {
            LOG.error("Unexpected method invocation in OtherIndividualsSubInspector (1)");
        }

        //Should never be called
        @Override
        public void addValue(IPivotDataModel ipdm, PivotField pf, int i, int i1, Object o) {
            LOG.error("Unexpected method invocation in OtherIndividualsSubInspector (2)");
        }

        //Should never be called
        @Override
        public void addValue(PivotValueProvider pvp, PivotField pf, Object o) {
            LOG.error("Unexpected method invocation in OtherIndividualsSubInspector (3)");
        }

        @Override
        public void clear() {
            collapsedDNAIDs.clear();
            valueCount = 0;
            lastRowValues = null;
        }

        @Override
        public Object getSummaryResult(int type) {
            //if null, then we're not in the DNAId column.  Return null
            //to show a blank in this cell
            if (lastRowValues == null) {
                return null;
            }

            int numIndividuals = getNumberOfIndividualsInGroup(lastRowValues.getValueAt(0));

            return new Frequency(collapsedDNAIDs.size(), numIndividuals);
        }

        private int getNumberOfIndividualsInGroup(Value v) {
            if (aggregateColumns[0].equals("Cohort")) {
                //LOG.debug("Getting number of individuals in group " + v.getValue());
                Set<String> dnaIds = cohortDNAIDMap.get((Cohort) v.getValue());
                //for (String id : dnaIds) {
                //LOG.debug("\tGot id " + id);
                //}
                return cohortDNAIDMap.get((Cohort) v.getValue()).size();
            } else if (aggregateColumns[0].equals(BasicPatientColumns.FAMILY_ID.getAlias())) {
                return familyIDdnaIDMap.get((String) v.getValue()).size();
            } else {
                LOG.error("Invalid first column");
                return -1;
            }
        }

        @Override
        public long getCount() {
            return valueCount;
        }

        @Override
        public int getNumberOfSummaries() {
            return 1;
        }

        @Override
        public String getSummaryName(Locale locale, int i) {
            return "Frequency";
        }

        @Override
        public int[] getAllowedSummaries(Class<?> type) {
            return new int[] { SUMMARY_FREQ };
        }

        @Override
        public int[] getAllowedSummaries(Class<?> type, ConverterContext cc) {
            return new int[] { SUMMARY_FREQ };
        }
    });

    //Sets up the context menu for clicking column headers.  This will probably not be used
    //frequently.  Limit the available operations to collapsing, expanding, and grouping.
    TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(aggregateTable);
    installer.addTableHeaderPopupMenuCustomizer(new AggregateTablePopupMenuCustomizer() {
        @Override
        public void customizePopupMenu(JTableHeader header, JPopupMenu popup, int clickingColumn) {
            super.customizePopupMenu(header, popup, clickingColumn);
            for (int i = 0; i < popup.getComponentCount(); i++) {
                String menuItemName = popup.getComponent(i).getName();
                if (!(CONTEXT_MENU_COLLAPSE.equals(menuItemName)
                        || CONTEXT_MENU_COLLAPSE_ALL.equals(menuItemName)
                        || CONTEXT_MENU_EXPAND.equals(menuItemName)
                        || CONTEXT_MENU_EXPAND_ALL.equals(menuItemName)
                        || CONTEXT_MENU_GROUP.equals(menuItemName)
                        || CONTEXT_MENU_UNGROUP.equals(menuItemName))) {

                    popup.remove(popup.getComponent(i));

                }
            }
        }
    });

    aggregateTable.getAggregateTableModel().setSummaryMode(true);

    aggregateTable.aggregate(aggregateColumns);
    aggregateTable.setShowContextMenu(false);

    expandAllButLast();
    setupButtonColumn();

    JScrollPane jsp = new JScrollPane(aggregateTable);
    jsp.setPreferredSize(PREFERRED_SIZE);

    JPanel bp = new JPanel();

    bp.setLayout(new BoxLayout(bp, BoxLayout.X_AXIS));
    JButton closeButton = new JButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE));
    closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            unsplitScreen();
        }
    });
    bp.add(Box.createHorizontalGlue());
    bp.add(title);
    bp.add(Box.createHorizontalGlue());
    bp.add(closeButton);
    innerPanel.add(bp);
    innerPanel.add(jsp);
    reaggregate();
    innerPanel.revalidate();
    innerPanel.repaint();
}

From source file:org.yccheok.jstock.gui.AjaxAutoCompleteJComboBox.java

private void adjustScrollBar() {
    final int max_search = 8;
    // i < max_search is just a safe guard when getAccessibleChildrenCount
    // returns an arbitary large number. 8 is magic number
    JPopupMenu popup = null;
    for (int i = 0, count = this.getUI().getAccessibleChildrenCount(this); i < count && i < max_search; i++) {
        Object o = this.getUI().getAccessibleChild(this, i);
        if (o instanceof JPopupMenu) {
            popup = (JPopupMenu) o;
            break;
        }/* w  w  w  .j a v  a 2  s.com*/
    }
    if (popup == null) {
        return;
    }
    JScrollPane scrollPane = null;
    for (int i = 0, count = popup.getComponentCount(); i < count && i < max_search; i++) {
        Component c = popup.getComponent(i);
        if (c instanceof JScrollPane) {
            scrollPane = (JScrollPane) c;
            break;
        }
    }
    if (scrollPane == null) {
        return;
    }
    scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL));
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}

From source file:studio.ui.Studio.java

private void rebuildMenus(TabIndexChanged event) {
    AppMenuBar appMenubar = getJMenuBar() instanceof AppMenuBar ? (AppMenuBar) getJMenuBar() : null;
    ToolBarActions toolBar = null;//from w ww .  j  av a 2  s.  c o m
    ActionMenu menuBar = null;
    if (appToolbar == null && appMenubar == null) {
        appToolbar = new ToolBarActions();
        getContentPane().add(appToolbar, BorderLayout.NORTH);
        appMenubar = new AppMenuBar();
        setJMenuBar(appMenubar);
        toolBar = new ToolBarActions("File");
        menuBar = new ActionMenu("File", 'f', "File operations", (MouseAdapter) null);
        Action action = new NewFileAction(tabEditors, tabConsoles);

        JPopupMenu popupMenu = new JPopupMenu();

        JMenuItem item = new JMenuItem("Script");
        item.setToolTipText("New script");
        item.addMouseListener(new ActionHintsListener(tabEditors, "Create new script"));
        item.addActionListener(action);
        popupMenu.add(item);

        item = new JMenuItem("Project");
        item.setToolTipText("New project");
        item.addMouseListener(new ActionHintsListener(tabEditors, "Create new project"));
        try {
            item.addActionListener(new AddProjectAction(treeProjects));
            popupMenu.add(item);
        } catch (StudioException ex) {
        }

        JButton button = new DropDownButton(action, popupMenu);
        if (button instanceof DataListener) {
            tabEditors.addFireDataListener((DataListener) button);
        }
        button.addMouseListener(new ActionHintsListener(tabEditors, action));
        toolBar.add(button);
        menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));

        action = new OpenFileAction(tabEditors, tabConsoles);
        menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        popupMenu = null;
        if (studioConfig.getOpenedFiles() != null && !studioConfig.getOpenedFiles().isEmpty()) {
            popupMenu = new JPopupMenu();
            int pos = 0;
            for (EditorFile file : studioConfig.getOpenedFiles()) {
                item = new JMenuItem((char) (pos + 48) + " " + file.getPath(), pos + 48);
                item.addMouseListener(new ActionHintsListener(tabEditors, "Open file " + file));
                popupMenu.add(item);
                if (++pos > 9) {
                    break;
                }
            }
        }
        button = new DropDownButton(action, popupMenu);
        if (button instanceof DataListener) {
            tabEditors.addFireDataListener((DataListener) button);
        }
        button.addMouseListener(new ActionHintsListener(tabEditors, action));
        toolBar.add(button);
        appToolbar.add(toolBar);
        appMenubar.add(menuBar);

        appToolbar.add(new ToolBarActions("KDB+"));
        appMenubar.add(new ActionMenu("KDB+", 'k', "KDB+ databse operations", (MouseAdapter) null));
        appToolbar.add(new ToolBarActions("Edit"));
        appMenubar.add(new ActionMenu("Edit", 'E', "Editor operations", (MouseAdapter) null));
        toolBar = new ToolBarActions("Options");
        appToolbar.add(toolBar);
        menuBar = new ActionMenu("Tools", 'T', "Tools", (MouseAdapter) null);
        ActionMenu opMenuBar = new ActionMenu("Options", 'O', "Studio settings", (MouseAdapter) null);
        ActionMenu lfMenuBar = new ActionMenu("Look and feel", 'L', "L&F", (MouseAdapter) null);
        LookAndFeelAction.getActionLookAndFeel(this, lfMenuBar, studioConfig);
        opMenuBar.add(lfMenuBar);
        opMenuBar.addSeparator();
        action = new EditorSettingsAction(this);
        opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        action = new TokensSettingsAction(this);
        opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        opMenuBar.addSeparator();
        action = new ConsoleSettingsAction(this);
        opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        opMenuBar.addSeparator();
        action = new ConnectionsSettingsAction(treeConnections);
        opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        menuBar.add(opMenuBar);
        opMenuBar.addSeparator();
        action = new GlobalSettingsAction(this);
        opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        appMenubar.add(menuBar);
        opMenuBar.addSeparator();
        action = new ProjectSettingsAction(this);
        opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        appMenubar.add(menuBar);
        menuBar = new ActionMenu("Help", 'H', "Help...", (MouseAdapter) null);
        action = new VisitKxAction();
        menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        menuBar.addSeparator();
        action = new VisitWroclawAction();
        menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        menuBar.addSeparator();
        action = new KeyListAction(tabEditors);
        menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        menuBar.addSeparator();
        action = new AboutAction(tabEditors);
        menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        appMenubar.add(menuBar);
        menuBar.addSeparator();
        action = new CheckUpdate(this);
        menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action)));
        appMenubar.add(menuBar);
        toolBar = null;

        this.setJMenuBar(appMenubar);
    }

    appToolbar.getToolBar("Edit").setVisible(event != null && event.getData() != -1);
    appToolbar.getToolBar("Options").setVisible(event != null && event.getData() != -1);
    appToolbar.getToolBar("KDB+").setVisible(event != null && event.getData() != -1);
    appToolbar.getToolBar("File").setVisible(event != null && event.getData() != -1);

    appMenubar.getMenu("Edit").setVisible(event != null && event.getData() != -1);
    appMenubar.getMenu("Tools").setVisible(event != null && event.getData() != -1);
    appMenubar.getMenu("KDB+").setVisible(event != null && event.getData() != -1);
    appMenubar.getMenu("File").setVisible(event != null && event.getData() != -1);

    if (event != null && event.getSource() instanceof EditorsTabbedPane && event.getData() != -1) {
        Editor editor = ((EditorsTabbedPane) event.getSource()).getEditor(event.getData());
        if (editor != null) {
            JPopupMenu menu = editor.getComponentPopupMenu();
            if (menu != null) {
                for (int count = 0; count < menu.getComponentCount(); count++) {
                    if (menu.getComponent(count) instanceof JMenuItem) {
                        JMenuItem menuItem = (JMenuItem) menu.getComponent(count);
                        if (menuItem.getAction().getClass() == SaveAction.class) {
                            appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(), true);
                            appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true);
                        } else {
                            if (menuItem.getAction().getClass() == SaveAsAction.class
                                    || menuItem.getAction().getClass() == SaveAllAction.class) {
                                appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction());
                                appMenubar.getMenu("File").update(tabEditors, menuItem.getAction());
                            } else {
                                if (menuItem.getAction().getClass() == CloseAction.class) {
                                    appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(),
                                            true);
                                    appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true);
                                } else {
                                    if (menuItem.getAction().getClass() == CloseAllAction.class) {
                                        appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction());
                                        appMenubar.getMenu("File").update(tabEditors, menuItem.getAction());
                                    } else {
                                        if (menuItem.getAction().getClass() == RunAction.class
                                                || menuItem.getAction().getClass() == RunLineAction.class
                                                || menuItem.getAction().getClass() == CancelRunAction.class) {
                                            appToolbar.getToolBar("KDB+").update(tabEditors,
                                                    menuItem.getAction());
                                            appMenubar.getMenu("KDB+").update(tabEditors, menuItem.getAction());
                                        } else {
                                            if (menuItem.getAction().getClass() == ExtKit.ReplaceAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == ActionFactory.RedoAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == ActionFactory.UndoAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == BaseKit.CopyAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == BaseKit.PasteAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == ExtKit.GotoAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == BaseKit.SelectAllAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == BaseKit.SelectLineAction.class
                                                    || menuItem.getAction()
                                                            .getClass() == BaseKit.CutAction.class) {
                                                appToolbar.getToolBar("Edit").update(tabEditors,
                                                        menuItem.getAction());
                                                if (menuItem.getAction().getClass() == ExtKit.GotoAction.class
                                                        || menuItem.getAction()
                                                                .getClass() == BaseKit.CopyAction.class
                                                        || menuItem.getAction()
                                                                .getClass() == BaseKit.SelectAllAction.class) {
                                                    appMenubar.getMenu("Edit").update(tabEditors,
                                                            menuItem.getAction(), true);
                                                } else {
                                                    appMenubar.getMenu("Edit").update(tabEditors,
                                                            menuItem.getAction());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (event != null && event.getData() != -1 && event.getSource() instanceof EditorsTabbedPane
            && ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()) != null) {
        ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()).requestFocus();
    }
}