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.awt.Font;
 import java.io.File;
 import java.util.Set;

Author(s):
Jiri Sedlacek
 
     "LoadGeneratorCustomizer_NameLabelText=&Name:",
     "LoadGeneratorCustomizer_SettingsLabelText=Settings",
     "LoadGeneratorCustomizer_ScriptLabelText=&Script:",
     "LoadGeneratorCustomizer_BrowseButtonText=Br&owse...",
     "LoadGeneratorCustomizer_StopLabelText=Stop:",
     "LoadGeneratorCustomizer_DefineRadioText=&Define",
     "LoadGeneratorCustomizer_StopRadioText=W&hen profiling stops",
    "LoadGeneratorCustomizer_LocationBeginLabelText=Location (start)",
    "LoadGeneratorCustomizer_LocationEndLabelText=Location (stop)",
    "LoadGeneratorCustomizer_ChooseScriptDialogCaption=Choose Load Generator Script",
    "LoadGeneratorCustomizer_ScriptFieldAccessDescr=Script to be executed in Load Generator",
    "LoadGeneratorCustomizer_SupportedFiles=Load Generator Scripts"
})
                                                                           ValidityListenerHelpCtx.Provider {
    private static final String HELP_CTX_KEY = "LoadGeneratorCustomizer.HelpCtx"// NOI18N
    private static final HelpCtx HELP_CTX = new HelpCtx();
    private static int defaultTextComponentHeight = -1;
    private static JFileChooser fileChooser;
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
    private JButton scriptButton;
    private JLabel captionLabel;
    private JLabel nameLabel;
    private JLabel scriptLabel;
    private JLabel settingsHeaderLabel;
    private JLabel stopLabel;
    private JPanel captionPanel;
    private JPanel firstLineCaptionSpacer = new JPanel(new FlowLayout(., 0, 0));
    private JPanel secondLineCaptionSpacer = new JPanel(new FlowLayout(., 0, 0));
    private JPanel thirdLineCaptionSpacer = new JPanel(new FlowLayout(., 0, 0));
    private JRadioButton stopDefineRadio;
    private JRadioButton stopOnStopRadio;
    private JTextField nameTextField;
    private JTextField scriptTextField;
    private Lookup.Provider project;
    //~ Constructors -------------------------------------------------------------------------------------------------------------
    public LoadGeneratorCustomizer(String captionIcon icon) {
        initComponents(captionicon);
        normalizeCaptionAreaWidth();
    }
    //~ Methods ------------------------------------------------------------------------------------------------------------------
    public HelpCtx getHelpCtx() {
        return ;
    }
    public Component getInitialFocusTarget() {
        return ;
    }
    public void setPPEndLocation(CodeProfilingPoint.Location location) {
        if (location == null) {
            .setSelected(true);
        } else {
            .setSelected(true);
            .setPPLocation(location);
        }
    }
        if (.isSelected()) {
            return null;
        } else {
            return .getPPLocation();
        }
    }
    public void setPPName(String ppName) {
        .setText(ppName);
    }
    public String getPPName() {
        return .getText();
    }
    public void setPPStartLocation(CodeProfilingPoint.Location location) {
        .setPPLocation(location);
    }
        return .getPPLocation();
    }
    public int getPreferredCaptionAreaWidth() {
        int ownCaptionAreaWidth = .getPreferredSize(). - 12; // nameLabel starts at 8, locationCustomizer at 20 => -12
        ownCaptionAreaWidth = Math.max(ownCaptionAreaWidth.getPreferredSize().);
        ownCaptionAreaWidth = Math.max(ownCaptionAreaWidth.getPreferredSize().);
        return Math.max(ownCaptionAreaWidth.getPreferredCaptionAreaWidth());
    }
    public void setProject(Lookup.Provider aProject) {
         = aProject;
    }
    public void setScriptFile(String fileName) {
        .setText(fileName);
    }
    public String getScriptFile() {
        return .getText();
    }
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == ) {
            JFileChooser fileChooser = getFileChooser();
            File currentDir = null;
            String scriptPath = .getText();
            if (scriptPath.length() > 0) {
                fileChooser.setCurrentDirectory(new File(scriptPath).getParentFile());
            } else {
                fileChooser.setCurrentDirectory(FileUtil.toFile(ProjectUtilities.getProjectDirectory()));
            }
            if (fileChooser.showOpenDialog(null) == .) {
                .setText(fileChooser.getSelectedFile().getAbsolutePath());
            }
        }
    }
    public void changedUpdate(DocumentEvent e) {
        updateValidity();
    }
    //  private int getDefaultTextComponentHeight() {
    //    if (defaultTextComponentHeight == -1) defaultTextComponentHeight = new JComboBox().getPreferredSize().height;
    //    return defaultTextComponentHeight;
    //  }
    public void initComponents(String captionIcon icon) {
        setLayout(new GridBagLayout());
        GridBagConstraints constraints;
        // captionPanel
         = new JPanel(new BorderLayout(0, 0));
        .setOpaque(true);
        // captionLabel
         = new JLabel(captionicon.);
        .setOpaque(false);
        .setBorder(BorderFactory.createEmptyBorder(6, 8, 6, 6));
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 16, 0);
        add(constraints);
        // --- next row ----------------------------------------------------------
        // nameLabel
         = new JLabel();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LoadGeneratorCustomizer_NameLabelText());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 8, 10, 5);
        add(constraints);
        // firstLineCaptionSpacer
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        add(constraints);
        // nameTextField
         = new JTextField("") { // NOI18N
                public Dimension getPreferredSize() {
                    return (LoadGeneratorCustomizer.this.getParent() instanceof JViewport) ? getMinimumSize()
                                                                                           : new Dimension(400,
                                                                                                           super.getPreferredSize().);
                }
                public Dimension getMinimumSize() {
                    return new Dimension(super.getMinimumSize().super.getPreferredSize().);
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 2;
        constraints.gridy = 1;
        constraints.gridwidth = .;
        constraints.weightx = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 10, 13);
        add(constraints);
        // --- next row ----------------------------------------------------------
        JPanel settingsHeaderContainer = new JPanel(new GridBagLayout());
        // settingsHeaderLabel
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        settingsHeaderContainer.add(constraints);
        // settingsHeaderSeparator
         = new JSeparator() {
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        settingsHeaderContainer.add(constraints);
        // locationHeaderContainer
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 8, 5, 8);
        add(settingsHeaderContainerconstraints);
        // --- next row ----------------------------------------------------------
        JPanel scriptSettingsContainer = new JPanel(new GridBagLayout());
        // scriptLabel
         = new JLabel();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LoadGeneratorCustomizer_ScriptLabelText());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        scriptSettingsContainer.add(constraints);
        // secondLineCaptionSpacer
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        scriptSettingsContainer.add(constraints);
        // scriptTextField
         = new JTextField("") { // NOI18N
                public Dimension getPreferredSize() {
                    return new Dimension(super.getMinimumSize().super.getPreferredSize().);
                }
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 2;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        scriptSettingsContainer.add(constraints);
        // scriptButton
         = new JButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LoadGeneratorCustomizer_BrowseButtonText());
        .addActionListener(this);
        constraints = new GridBagConstraints();
        constraints.gridx = 3;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        scriptSettingsContainer.add(constraints);
        // scriptSettingsContainer
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 3;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 20, 5, 13);
        add(scriptSettingsContainerconstraints);
        // --- next row ----------------------------------------------------------
        ButtonGroup stopRadiosGroup = new ButtonGroup();
        JPanel stopSettingsContainer = new JPanel(new GridBagLayout());
        // stopLabel
         = new JLabel(Bundle.LoadGeneratorCustomizer_StopLabelText());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        stopSettingsContainer.add(constraints);
        // thirdLineCaptionSpacer
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        stopSettingsContainer.add(constraints);
        // stopDefineRadio
         = new JRadioButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LoadGeneratorCustomizer_DefineRadioText());
        stopRadiosGroup.add();
        .addChangeListener(this);
        constraints = new GridBagConstraints();
        constraints.gridx = 2;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        stopSettingsContainer.add(constraints);
        // stopOnStopRadio
         = new JRadioButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LoadGeneratorCustomizer_StopRadioText());
        .addChangeListener(this);
        stopRadiosGroup.add();
        constraints = new GridBagConstraints();
        constraints.gridx = 3;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        stopSettingsContainer.add(constraints);
        // measureSettingsContainer
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 4;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 20, 10, 13);
        add(stopSettingsContainerconstraints);
        // --- next row ----------------------------------------------------------
        JPanel locationBeginHeaderContainer = new JPanel(new GridBagLayout());
        // locationBeginHeaderLabel
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        locationBeginHeaderContainer.add(constraints);
        // locationBeginHeaderSeparator
         = new JSeparator() {
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        locationBeginHeaderContainer.add(constraints);
        // locationBeginHeaderContainer
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 5;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 8, 5, 8);
        add(locationBeginHeaderContainerconstraints);
        // --- next row ----------------------------------------------------------
        // locationBeginCustomizer
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 6;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 20, 12, 13);
        add(constraints);
        // --- next row ----------------------------------------------------------
        JPanel locationEndHeaderContainer = new JPanel(new GridBagLayout());
        // locationEndHeaderLabel
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        locationEndHeaderContainer.add(constraints);
        // locationEndHeaderSeparator
         = new JSeparator() {
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        locationEndHeaderContainer.add(constraints);
        // locationEndHeaderContainer
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 7;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 8, 5, 8);
        add(locationEndHeaderContainerconstraints);
        // --- next row ----------------------------------------------------------
        // locationEndCustomizer
         = new LocationCustomizer();
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 8;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 20, 20, 13);
        add(constraints);
        // --- next row ----------------------------------------------------------
        JPanel fillerPanel = new JPanel(new FlowLayout(., 0, 0));
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 9;
        constraints.weighty = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        add(fillerPanelconstraints);
    }
    public void insertUpdate(DocumentEvent e) {
        updateValidity();
    }

    

Parameters:
args the command line arguments
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); //NOI18N
                                                                                            //      UIManager.setLookAndFeel("plaf.metal.MetalLookAndFeel"); //NOI18N
                                                                                            //      UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); //NOI18N
                                                                                            //      UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); //NOI18N
        } catch (Exception e) {
        }
        ;
        LoadGeneratorCustomizer main = new LoadGeneratorCustomizer("Load Generator"null); // NOI18N
        main.addValidityListener(new ValidityListener() {
                public void validityChanged(boolean isValid) {
                    ..println(">>> Validity changed to " + isValid);
                } // NOI18N
            });
        JFrame frame = new JFrame("Customize Profiling Point"); // NOI18N
        frame.getContentPane().add(main);
        frame.pack();
        frame.setVisible(true);
    }
    public void normalizeCaptionAreaWidth() {
        int requiredCaptionAreaWidth1 = .getPreferredSize(). - 12; // nameLabel starts at 8, locationCustomizer at 20 => -12
        int diffCaptionAreaWidth1 = getPreferredCaptionAreaWidth() - requiredCaptionAreaWidth1;
        int normalizedCaptionAreaWidth1 = (diffCaptionAreaWidth1 > 0) ? diffCaptionAreaWidth1 : 0;
        int requiredCaptionAreaWidth2 = .getPreferredSize().;
        int diffCaptionAreaWidth2 = getPreferredCaptionAreaWidth() - requiredCaptionAreaWidth2;
        int normalizedCaptionAreaWidth2 = (diffCaptionAreaWidth2 > 0) ? diffCaptionAreaWidth2 : 0;
        int requiredCaptionAreaWidth3 = .getPreferredSize().;
        int diffCaptionAreaWidth3 = getPreferredCaptionAreaWidth() - requiredCaptionAreaWidth3;
        int normalizedCaptionAreaWidth3 = (diffCaptionAreaWidth3 > 0) ? diffCaptionAreaWidth3 : 0;
        .setBorder(BorderFactory.createEmptyBorder(0, normalizedCaptionAreaWidth1, 0, 0));
        .setBorder(BorderFactory.createEmptyBorder(0, normalizedCaptionAreaWidth2, 0, 0));
        .setBorder(BorderFactory.createEmptyBorder(0, normalizedCaptionAreaWidth3, 0, 0));
    }
    public void removeUpdate(DocumentEvent e) {
        updateValidity();
    }
    public void stateChanged(ChangeEvent e) {
        if ((e.getSource() == ) || (e.getSource() == )) {
            boolean selected = .isSelected();
            .setEnabled(selected);
            .setEnabled(selected);
            .setEnabled(selected);
            updateValidity();
        }
    }
    public void validityChanged(boolean isValid) {
        updateValidity();
    }
    private JFileChooser getFileChooser() {
        if ( == null) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(.);
            chooser.setMultiSelectionEnabled(false);
            chooser.setDialogType(.);
            chooser.setDialogTitle(Bundle.LoadGeneratorCustomizer_ChooseScriptDialogCaption());
    
            chooser.setFileFilter(new FileFilter() {
                    private Set<Stringextensions = new HashSet<String>();
                    {
                        LoadGenPlugin lg = Lookup.getDefault().lookup(LoadGenPlugin.class);
                         = lg.getSupportedExtensions();
                    }
                    public boolean accept(File f) {
                        return f.isDirectory() || .contains(FileUtil.getExtension(f.getPath()));
                    }
                    public String getDescription() {
                        return Bundle.LoadGeneratorCustomizer_SupportedFiles();
                    }
                });
             = chooser;
        }
        return ;
    }
    private boolean isNameEmpty() {
        return .getText().trim().length() == 0;
    }
    private boolean isScriptValid() {
        String fileName = .getText();
        File file = new File(fileName);
        if (file.exists() && file.isFile()) {
            LoadGenPlugin lg = Lookup.getDefault().lookup(LoadGenPlugin.class);
            if (lg == null) {
                return false;
            }
            String ext = FileUtil.getExtension(.getText());
            return lg.getSupportedExtensions().contains(ext);
        }
        return false;
    }
    private boolean areEndLocationSettingsValid() {
    }
    private void updateValidity() {
        boolean isValid = !isNameEmpty() && isScriptValid() && .areSettingsValid()
                          && areEndLocationSettingsValid();
        if (isValid != areSettingsValid()) {
            fireValidityChanged(isValid);
        }
    }