Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.
   *
   * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common
  * Development and Distribution License("CDDL") (collectively, the
  * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Oracle in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * Contributor(s):
  * The Original Software is NetBeans. The Initial Developer of the Original
  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  * Microsystems, Inc. All Rights Reserved.
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  */
 
 package org.netbeans.modules.profiler.ppoints.ui;
 
 import java.util.List;

Author(s):
Jiri Sedlacek
 
     "WizardPanel1UI_SelectProjectString=<Select Profiling Point project>",
     "WizardPanel1UI_PpTypeString=Profiling point &type:",
     "WizardPanel1UI_PpProjectString=Profiling point &project:",
     "WizardPanel1UI_DescriptionLabelText=Description:",
     "WizardPanel1UI_SupportedModesLabelText=Supported modes:",
     "WizardPanel1UI_MonitorModeString=Monitor",
     "WizardPanel1UI_CpuModeString=CPU",
     "WizardPanel1UI_MemoryModeString=Memory",
     "WizardPanel1UI_PpListAccessName=List of available Profiling Points",
     "WizardPanel1UI_ProjectsListAccessName=List of open projects"
 })
 public class WizardPanel1UI extends ValidityAwarePanel implements HelpCtx.Provider {
     //~ Inner Classes ------------------------------------------------------------------------------------------------------------
 
    private class PPointTypeTableModel extends DefaultTableModel {
        //~ Methods --------------------------------------------------------------------------------------------------------------
        public boolean isCellEditable(int rowIndexint columnIndex) {
            return false;
        }
        public Class getColumnClass(int columnIndex) {
            if (columnIndex == 0) {
                return Integer.class;
            } else {
                return String.class;
            }
        } // TODO: enable once Scope is implemented
          //    public Class getColumnClass(int columnIndex) { return String.class; }
        public int getColumnCount() {
            return 2;
        } // TODO: enable once Scope is implemented
          //    public int getColumnCount() { return 1; }
        public int getRowCount() {
            return .;
        }
        public Object getValueAt(int rowIndexint columnIndex) {
            return [rowIndex];
        }
    }
    //~ Static fields/initializers -----------------------------------------------------------------------------------------------
    private static final String HELP_CTX_KEY = "PPointsWizardPanel1UI.HelpCtx"// NOI18N
    private static final HelpCtx HELP_CTX = new HelpCtx();
    private static final Icon MONITOR_ICON = Icons.getIcon(.);
    private static final Icon CPU_ICON = Icons.getIcon(.);
    private static final Icon MEMORY_ICON = Icons.getIcon(.);
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
    private Dimension initialMinSize;
    private JComboBox ppointProjectCombo;
    private JLabel ppointProjectLabel;
    
    private boolean hasDefaultScope = false;
    //~ Constructors -------------------------------------------------------------------------------------------------------------
    public WizardPanel1UI() {
        initComponents();
    }
    //~ Methods ------------------------------------------------------------------------------------------------------------------
    public HelpCtx getHelpCtx() {
        return ;
    }
    public Dimension getMinSize() {
        return ;
    }
    public void setSelectedIndex(int index) {
        if (index == -1) {
            .clearSelection();
        } else {
            .setRowSelectionInterval(indexindex);
        }
    }
    public int getSelectedIndex() {
        return .getSelectedRow();
    }
    public void setSelectedProject(Lookup.Provider project) {
        if (project != null) {
            .setSelectedItem(project);
        }
        
        if ((project == null || !project.equals(.getSelectedItem())) && (!Bundle.WizardPanel1UI_SelectProjectString().equals(.getItemAt(0)))) {
        }
    }
    public Lookup.Provider getSelectedProject() {
        if (.getSelectedItem() instanceof Lookup.Provider) {
            return (Lookup.Provider.getSelectedItem();
        } else {
            return null;
        }
    }
    
    public boolean hasDefaultScope() {
        return ;
    }
    public void init(final ProfilingPointFactory[] ppFactories) {
        this. = ppFactories;
        initProjectsCombo();
                       .setMaxWidth(Math.max(..getIconWidth(),
                                             ..getIconWidth()) + 25); // TODO: enable once Scope is implemented
        refresh();
    }
    private void initComponents() {
        setLayout(new GridBagLayout());
        GridBagConstraints constraints;
         = new JLabel();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.WizardPanel1UI_PpTypeString());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 5, 10);
        add(constraints);
         = new PPointTypeTableModel();
        .setTableHeader(null);
                public void valueChanged(ListSelectionEvent e) {
                    refresh();
                }
            });
        .setRowHeight(UIUtils.getDefaultRowHeight() + 2);
        .setDefaultRenderer(Integer.class, Utils.getScopeRenderer()); // TODO: enable once Scope is implemented
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 15, 12, 10);
        add(new JExtendedTablePanel(), constraints);
         = new JLabel();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.WizardPanel1UI_PpProjectString());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 5, 10);
        add(constraints);
         = new JComboBox(new Object[] { Bundle.WizardPanel1UI_SelectProjectString()}) {
                public Dimension getMaximumSize() {
                    return getPreferredSize();
                }
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
                ;
            };
                public void actionPerformed(ActionEvent e) {
                    refresh();
                }
            });
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 3;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 15, 12, 10);
        add(constraints);
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 4;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 5, 10);
        add(constraints);
         = new JTextArea();
        .setOpaque(false);
        .setLineWrap(true);
        .setEnabled(false);
        .setFont(UIManager.getFont("Label.font")); //NOI18N
        .setDisabledTextColor(UIManager.getColor("Label.foreground")); //NOI18N
        int rows = .getRows();
        .setRows(4);
        final int height = .getPreferredSize().;
        .setRows(rows);
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 5;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 15, 12, 10);
        JScrollPane ppointDescriptionAreaScroll = new JScrollPane(,
                                                                  .,
                                                                  .) {
            public Dimension getPreferredSize() {
                return new Dimension(super.getPreferredSize().height);
            }
            public Dimension getMinimumSize() {
                return new Dimension(super.getMinimumSize().height);
            }
        };
        ppointDescriptionAreaScroll.setBorder(BorderFactory.createEmptyBorder());
        ppointDescriptionAreaScroll.setViewportBorder(BorderFactory.createEmptyBorder());
        ppointDescriptionAreaScroll.setOpaque(false);
        ppointDescriptionAreaScroll.getViewport().setOpaque(false);
        add(ppointDescriptionAreaScrollconstraints);
        int maxHeight = .getPreferredSize().;
        maxHeight = Math.max(maxHeight.getIconHeight());
        maxHeight = Math.max(maxHeight.getIconHeight());
        maxHeight = Math.max(maxHeight.getIconHeight());
        final int mheight = maxHeight;
        JPanel effectiveModesContainer = new JPanel(new GridBagLayout());
                public Dimension getPreferredSize() {
                    return new Dimension(super.getPreferredSize().mheight);
                }
                public Dimension getMinimumSize() {
                    return new Dimension(super.getMinimumSize().mheight);
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 10);
        effectiveModesContainer.add(constraints);
        .setVisible(false); // TODO: remove once Monitor mode will support Profiling Points
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 10);
        effectiveModesContainer.add(constraints);
        constraints = new GridBagConstraints();
        constraints.gridx = 2;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 10);
        effectiveModesContainer.add(constraints);
        constraints = new GridBagConstraints();
        constraints.gridx = 3;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 10);
        effectiveModesContainer.add(constraints);
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 6;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        add(effectiveModesContainerconstraints);
         = getMinimumSize();
    }
    private void initProjectsCombo() {
        
        ProfilingPointsManager manager = ProfilingPointsManager.getDefault();
        
        Lookup.Provider defaultScope = null;
        List<Lookup.ProviderprovidedScopes = manager.getProvidedScopes();
        for (Lookup.Provider providedScope : providedScopes) {
            if (providedScope != null) {
                if (defaultScope == null && manager.isDefaultScope(providedScope))
                    defaultScope = providedScope;
                .addItem(providedScope);
            }
        }
        Lookup.Provider[] projects =
                ProjectUtilities.getSortedProjects(ProjectUtilities.getOpenedProjects());
        for (Lookup.Provider project : projects) {
            .addItem(project);
        }
         = defaultScope != null;
        setSelectedProject( ? defaultScope : Utils.getCurrentProject());
    }
    private void refresh() {
        }
        int selectedIndex = .getSelectedRow();
        if (selectedIndex != -1) {
            ProfilingPointFactory ppFactory = [selectedIndex];
            .setText(ppFactory.getDescription());
            .setVisible(ppFactory.supportsMonitor());
            .setVisible(ppFactory.supportsCPU());
            .setVisible(ppFactory.supportsMemory());
        } else {
            .setText(""); // NOI18N
            .setVisible(false);
            .setVisible(false);
            .setVisible(false);
        }
        boolean ppointTypeSelected = selectedIndex != -1;
        boolean ppointProjectSelected = (.getSelectedItem() != null)
                                        && .getSelectedItem() instanceof Lookup.Provider;
        boolean isValid = ppointTypeSelected && ppointProjectSelected;
        if (isValid) {
            if (!areSettingsValid()) {
                fireValidityChanged(true);
            }
        } else {
            if (areSettingsValid()) {
                fireValidityChanged(false);
            }
        }
    }
New to GrepCode? Check out our FAQ X