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;
 
 import javax.swing.*;

Author(s):
Jiri Sedlacek
 
     "ProfilingPointWizard_AnotherPpEditedMsg=Another Profiling Point is currently being edited!",
     "ProfilingPointWizard_NoPpsFoundMsg=No registered Profiling Points found!",
     "ProfilingPointWizard_WizardTitle=New Profiling Point",
     "ProfilingPointWizard_WizardStep1Caption=Choose Type & Project",
     "ProfilingPointWizard_WizardStep2Caption=Customize Properties"
 })
 public class ProfilingPointWizard implements WizardDescriptor.Iterator {
     //~ Inner Classes ------------------------------------------------------------------------------------------------------------
 
     // --- WizardPanel for selecting Profiling Point type & Project --------------
     class WizardPanel1 extends WizardPanel {
         //~ Instance fields ------------------------------------------------------------------------------------------------------
 
         private Lookup.Provider selectedProjectRef;
         private int selectedPPFactoryIndexRef;
 
         //~ Methods --------------------------------------------------------------------------------------------------------------
 
         public HelpCtx getHelp() {
             Component customizer = getComponent();
 
             if ((customizer == null) || !(customizer instanceof HelpCtx.Provider)) {
                 return null;
             }
 
             return ((HelpCtx.Providercustomizer).getHelpCtx();
         }
 
         public String getName() {
             return Bundle.ProfilingPointWizard_WizardStep1Caption();
         }
        public Component createComponent() {
            WizardPanel1UI component = new WizardPanel1UI();
            component.addValidityListener(this);
            component.init();
            setValid(component.areSettingsValid());
            
            if (component.hasDefaultScope())
                 = component.getSelectedProject();
            return component;
        }
        public void hiding(boolean cancelled) {
            if ( != ) {
                 = true;
            }
            if (( == null) || !.equals()) {
                 = true;
            }
        }
        public void showing() {
             = ;
            if ( == null) {
                 = Utils.getCurrentProject();
            }
        }
    }
    // --- WizardPanel for customizing Profiling Point properties ----------------
    class WizardPanel2 extends WizardPanel {
        //~ Instance fields ------------------------------------------------------------------------------------------------------
        private ValidityAwarePanel customizer;
        //~ Methods --------------------------------------------------------------------------------------------------------------
        public HelpCtx getHelp() {
            if (( == null) || !( instanceof HelpCtx.Provider)) {
                return null;
            }
            return ((HelpCtx.Provider).getHelpCtx();
        }
        public String getName() {
            return Bundle.ProfilingPointWizard_WizardStep2Caption();
        }
        public Component createComponent() {
            JScrollPane customizerScrollPane = new JScrollPane(.,
                                                               .);
            customizerScrollPane.setBorder(BorderFactory.createEmptyBorder());
            customizerScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
            customizerScrollPane.setOpaque(false);
            customizerScrollPane.getViewport().setOpaque(false);
            String hint = [].getHint();
            if (hint != null && !hint.isEmpty()) {
                JPanel panel = new JPanel(new BorderLayout(0, 0));
                panel.setOpaque(false);
                panel.add(customizerScrollPane.);
                JTextArea area = new JTextArea(hint);
                area.setOpaque(false);
                area.setWrapStyleWord(true);
                area.setLineWrap(true);
                area.setEnabled(false);
                area.setFont(UIManager.getFont("Label.font")); //NOI18N
                area.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
                panel.add(area.);
                return panel;
            } else {
                return customizerScrollPane;
            }
        }
        public void hiding(boolean cancelled) {
            if (!cancelled &&  != null &&  != null) {
                .setValues();
            }
            unregisterCustomizerListener();
        }
        public void notifyClosed(boolean cancelled) {
            releaseCurrentCustomizer();
             = null;
        }
        public void showing() {
            if (( == null) || ) {
                releaseCurrentCustomizer();
                createNewCustomizer();
                 = false;
            }
            setValid(.areSettingsValid());
            registerCustomizerListener();
        }
        private void createNewCustomizer() {
            // TODO: selectedPPFactoryIndex or selectedProject could be -1/null, create() can return null
             = .getCustomizer();
            getContainer().setViewportView();
        }
        private void registerCustomizerListener() {
            if ( != null) {
                .addValidityListener(this);
            }
        }
        private void releaseCurrentCustomizer() {
            resetComponent();
             = null;
        }
        private void unregisterCustomizerListener() {
            if ( != null) {
                .removeValidityListener(this);
            }
        }
        
        private JScrollPane getContainer() {
            Component container = getComponent();
            if (!(container instanceof JScrollPane))
                container = ((JComponent)container).getComponent(0);
            if (!(container instanceof JScrollPane))
                container = ((JComponent)getComponent()).getComponent(1);
            return (JScrollPane)container;
        }
    }
    // --- Abstract WizardPanel implementation -----------------------------------
    private abstract class WizardPanel implements WizardDescriptor.PanelValidityListener {
        //~ Instance fields ------------------------------------------------------------------------------------------------------
        protected boolean valid = true;
        private Component component;
        private EventListenerList listenerList = new EventListenerList();
        //~ Methods --------------------------------------------------------------------------------------------------------------
        public abstract String getName();
        public Component getComponent() {
            if ( == null) {
                 = createComponent();
                .setName(getName());
                .setPreferredSize();
            }
            return ;
        }
        
        protected void resetComponent() {
             = null;
        }
        public void setValid(boolean valid) {
            if (this. != valid) {
                this. = valid;
                fireChangeListenerStateChanged(this);
            }
            ;
        }
        public boolean isValid() {
            return ;
        }
        public abstract Component createComponent();

        
Registers ChangeListener to receive events.

Parameters:
listener The listener to register.
        public synchronized void addChangeListener(ChangeListener listener) {
            .add(ChangeListener.classlistener);
        }
        public void hiding(boolean cancelled) {
        }
        public void notifyClosed(boolean cancelled) {
        }
        public void readSettings(Object settings) {
        }

        
Removes ChangeListener from the list of listeners.

Parameters:
listener The listener to remove.
        public synchronized void removeChangeListener(ChangeListener listener) {
            .remove(ChangeListener.classlistener);
        }
        public void showing() {
        }
        public void storeSettings(Object settings) {
        }
        public void validityChanged(boolean isValid) {
            setValid(isValid);
        }

        
Notifies all registered listeners about the event.

Parameters:
param Parameter #1 of the ChangeEvent constructor.
        protected void fireChangeListenerStateChanged(Object param) {
            ChangeEvent e = null;
            Object[] listeners = .getListenerList();
            for (int i = listeners.length - 2; i >= 0; i -= 2) {
                if (listeners[i] == ChangeListener.class) {
                    if (e == null) {
                        e = new ChangeEvent(param);
                    }
                    ((ChangeListenerlisteners[i + 1]).stateChanged(e);
                }
            }
        }
    }
    //~ Static fields/initializers -----------------------------------------------------------------------------------------------
    private static ProfilingPointWizard defaultInstance;
    private static final Dimension DEFAULT_PREFERRED_PANEL_SIZE = new Dimension(440, 330);
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
    private Dimension preferredPanelSize = null;
    // --- Wizard runtime implementation -----------------------------------------
    private WizardPanel[] wizardPanels;
    private String[] wizardSteps;
    private boolean settingsChanged;
    private int currentPanel;
    private int selectedPPFactoryIndex;
    //~ Constructors -------------------------------------------------------------------------------------------------------------
    private ProfilingPointWizard() {
    }
    //~ Methods ------------------------------------------------------------------------------------------------------------------
    private static class Singleton {
        final private static ProfilingPointWizard INSTANCE = new ProfilingPointWizard();
    }
    
    public static ProfilingPointWizard getDefault() {
        return .;
    }
        return getWizardDescriptor(null);
    }
        ValidityAwarePanel showingCustomizer = ProfilingPointsManager.getDefault().getShowingCustomizer();
        if (showingCustomizer != null) {
            ProfilerDialogs.displayWarning(
                    Bundle.ProfilingPointWizard_AnotherPpEditedMsg());
            SwingUtilities.getWindowAncestor(showingCustomizer).requestFocus();
            showingCustomizer.requestFocusInWindow();
            return null;
        } else {
            //      profilingPoint = null;
             = true;
             = 0;
             = 0;
             = project;
            initWizardDescriptor();
            initWizardPanels();
            if (. > 0) {
                getCurrentWizardPanel().showing();
                return ;
            } else {
                ProfilerDialogs.displayError(
                        Bundle.ProfilingPointWizard_NoPpsFoundMsg());
                return null;
            }
        }
    }
    // --- WizardDescriptor.Iterator implementation ------------------------------
    public synchronized void addChangeListener(javax.swing.event.ChangeListener listener) {
    }
    public WizardDescriptor.Panel current() {
        return getCurrentWizardPanel();
    }
    public ProfilingPoint finish(boolean cancelled) {
        ProfilingPoint result = cancelled ? null : ;
        if ( != null) {
            [].hiding(cancelled);
            for (int i = 0; i < .i++) {
                [i].notifyClosed(cancelled); // Will invoke profilingPoint = null
            }
        }
        return result;
    }
    public boolean hasNext() {
        return  < (. - 1);
    }
    public boolean hasPrevious() {
        return  > 0;
    }
    public String name() {
        return getCurrentWizardPanel().getName();
    }
    public void nextPanel() {
        getCurrentWizardPanel().hiding(false);
        getCurrentWizardPanel().showing();
    }
    public void previousPanel() {
        getCurrentWizardPanel().hiding(false);
        getCurrentWizardPanel().showing();
    }
    public synchronized void removeChangeListener(javax.swing.event.ChangeListener listener) {
    }
    private WizardPanel getCurrentWizardPanel() {
        return [];
    }
    private void initWizardDescriptor() {
         = new WizardDescriptor(this);
        .setTitleFormat(new MessageFormat("{0}")); // NOI18N
    }
    private void initWizardPanels() {
         = ProfilingPointsManager.getDefault().getProfilingPointFactories();
         = new WizardPanel[] { new WizardPanel1(), new WizardPanel2() };
         = new String[.];
        for (int i = 0; i < .i++) {
            [i] = [i].getName();
        }
        if ( == null) {
            Dimension firstPanelSize = ((WizardPanel1UI) ([0].getComponent())).getMinSize();
            . = Math.max(.firstPanelSize.width);
            . = Math.max(.firstPanelSize.height);
        }
    }
New to GrepCode? Check out our FAQ X