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.Color;
 import java.awt.Font;

Author(s):
Jiri Sedlacek
 
     "StopwatchCustomizer_NameLabelText=&Name:",
     "StopwatchCustomizer_SettingsLabelText=Settings",
     "StopwatchCustomizer_MeasureLabelText=Measure:",
     "StopwatchCustomizer_TimestampRadioText=&Timestamp",
     "StopwatchCustomizer_DurationRadioText=Timestamp and &duration",
     "StopwatchCustomizer_BeginLocationLabelText=Location (start)",
     "StopwatchCustomizer_EndLocationLabelText=Location (stop)"
 })
                                                                        HelpCtx.Provider {
     //~ Static fields/initializers -----------------------------------------------------------------------------------------------
 
     private static final String HELP_CTX_KEY = "StopwatchCustomizer.HelpCtx"// NOI18N
     private static final HelpCtx HELP_CTX = new HelpCtx();
     private static int defaultTextComponentHeight = -1;
 
     //~ Instance fields ----------------------------------------------------------------------------------------------------------
    private JLabel captionLabel;
    private JLabel measureLabel;
    private JLabel nameLabel;
    private JLabel settingsHeaderLabel;
    private JPanel captionPanel;
    private JPanel firstLineCaptionSpacer = new JPanel(new FlowLayout(., 0, 0));
    private JTextField nameTextField;
    //~ Constructors -------------------------------------------------------------------------------------------------------------
    public StopwatchCustomizer(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 name) {
        .setText(name);
    }
    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
        return Math.max(ownCaptionAreaWidth.getPreferredCaptionAreaWidth());
    }
    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.StopwatchCustomizer_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 (StopwatchCustomizer.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 ----------------------------------------------------------
        ButtonGroup measureRadiosGroup = new ButtonGroup();
        JPanel measureSettingsContainer = new JPanel(new GridBagLayout());
        // measureLabel
         = new JLabel(Bundle.StopwatchCustomizer_MeasureLabelText());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 8);
        measureSettingsContainer.add(constraints);
        // measureTimestampRadio
         = new JRadioButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.StopwatchCustomizer_TimestampRadioText());
        measureRadiosGroup.add();
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 3);
        measureSettingsContainer.add(constraints);
        // measureTimestampDurationRadio
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.StopwatchCustomizer_DurationRadioText());
        measureRadiosGroup.add();
        constraints = new GridBagConstraints();
        constraints.gridx = 2;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        measureSettingsContainer.add(constraints);
        // measureSettingsContainer
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 3;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 20, 10, 13);
        add(measureSettingsContainerconstraints);
        // --- 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 = 4;
        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 = 5;
        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 = 6;
        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 = 7;
        constraints.gridwidth = .;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 20, 0, 13);
        add(constraints);
        // --- next row ----------------------------------------------------------
        JPanel fillerPanel = new JPanel(new FlowLayout(., 0, 0));
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 8;
        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) {
        }
        ;
        StopwatchCustomizer main = new StopwatchCustomizer("Stopwatch"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 requiredCaptionAreaWidth = .getPreferredSize(). - 12; // nameLabel starts at 8, locationCustomizer at 20 => -12
        int diffCaptionAreaWidth = getPreferredCaptionAreaWidth() - requiredCaptionAreaWidth;
        int normalizedCaptionAreaWidth = (diffCaptionAreaWidth > 0) ? diffCaptionAreaWidth : 0;
        .setBorder(BorderFactory.createEmptyBorder(0, normalizedCaptionAreaWidth, 0, 0));
    }
    public void removeUpdate(DocumentEvent e) {
        updateValidity();
    }
    public void stateChanged(ChangeEvent e) {
        if (e.getSource() == ) {
            updateValidity();
        }
        if (e.getSource() == ) {
            boolean selected = .isSelected();
            .setEnabled(selected);
            .setEnabled(selected);
            .setEnabled(selected);
            CodeProfilingPoint.Location endLocation = getPPEndLocation();
            if (selected && (endLocation != null) && (endLocation.getFile().trim().length() == 0)) {
                CodeProfilingPoint.Location startLocation = getPPStartLocation();
                CodeProfilingPoint.Location newEndLocation = new CodeProfilingPoint.Location(startLocation.getFile(),
                                                                                             startLocation.getLine() + 1,
                                                                                             ..);
                .setPPLocation(newEndLocation);
            }
            updateValidity();
        }
    }
    public void validityChanged(boolean isValid) {
        updateValidity();
    }
    private boolean isNameEmpty() {
        return .getText().trim().length() == 0;
    }
    private boolean areEndLocationSettingsValid() {
    }
    private void updateValidity() {
        boolean isValid = !isNameEmpty() && .areSettingsValid() && areEndLocationSettingsValid();
        if (isValid != areSettingsValid()) {
            fireValidityChanged(isValid);
        }
    }
New to GrepCode? Check out our FAQ X