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.io.File;

Author(s):
Jiri Sedlacek
 
     "LocationCustomizer_FileLabelText=F&ile:",
     "LocationCustomizer_BrowseButtonText=Bro&wse...",
     "LocationCustomizer_CurrentLineButtonText=&Current\nLine",
     "LocationCustomizer_LineLabelText=&Line:",
     "LocationCustomizer_BeginRadioText=Be&gin",
     "LocationCustomizer_EndRadioText=&End",
     "LocationCustomizer_OffsetRadioText=&Offset:",
     "LocationCustomizer_ChooseFileDialogCaption=Choose Java Source File",
     "LocationCustomizer_FileDialogFilterName=Java Sources (*.java)"
})
                                                                      HierarchyListener {
    //~ Inner Classes ------------------------------------------------------------------------------------------------------------
    private static class HTMLButton extends JButton {
        //~ Methods --------------------------------------------------------------------------------------------------------------
        public void setEnabled(boolean enabled) {
            setForeground(enabled ? . : .);
            super.setEnabled(enabled);
        }
        //    public HTMLButton(String text) {
        //      super("<html><center>" + text.replaceAll("\\n", "<br>") + "</center></html>"); // NOI18N
        //      getAccessibleContext().setAccessibleName(text);
        //    }
        public void setText(String value) {
            super.setText("<html><center><nobr>" + value.replace("\\n""<br>") + "</nobr></center></html>"); // NOI18N
            getAccessibleContext().setAccessibleName(value);
        }
    }
    // --- Implementation --------------------------------------------------------
    private static int defaultTextComponentHeight = -1;
    private static JFileChooser fileChooser;
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
    private JButton fileButton;
    private JButton fromEditorButton;
    private JLabel fileLabel;
    private JLabel lineLabel;
    private JPanel firstLineCaptionSpacer = new JPanel(new FlowLayout(., 0, 0));
    private JPanel secondLineCaptionSpacer = new JPanel(new FlowLayout(., 0, 0));
    private JRadioButton lineBeginRadio;
    private JRadioButton lineEndRadio;
    private JRadioButton lineOffsetRadio;
    private JSpinner lineNumberSpinner;
    private JSpinner lineOffsetSpinner;
    private JTextField fileTextField;
    //~ Constructors -------------------------------------------------------------------------------------------------------------
    public LocationCustomizer() {
        initComponents();
    }
    //~ Methods ------------------------------------------------------------------------------------------------------------------
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled(enabled);
        .setEnabled((enabled == false) ? false : .isSelected());
        .setEnabled(enabled);
    }
    public void setPPLocation(CodeProfilingPoint.Location location) {
        .setText(location.getFile());
        .setValue(location.getLine());
        int offset = location.getOffset();
        if (offset == ..) {
            .setSelected(true);
        } else if (offset == ..) {
            .setSelected(true);
        } else {
            .setSelected(true);
            .setValue(offset);
        }
    }
        int offset = ((Integer.getValue()).intValue();
        if (.isSelected()) {
            offset = ..;
        } else if (.isSelected()) {
            offset = ..;
        }
                                               offset);
    }
    public int getPreferredCaptionAreaWidth() {
    }
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == ) {
            JFileChooser fileChooser = getFileChooser();
            fileChooser.setCurrentDirectory(new File(.getText()));
            if (fileChooser.showOpenDialog(null) == .) {
                .setText(fileChooser.getSelectedFile().getAbsolutePath());
            }
        } else if (e.getSource() == ) {
            if (.isSelected()) {
            } else if (.isSelected()) {
            } else {
                setPPLocation(Utils.getCurrentLocation(((Integer.getValue()).intValue()));
            }
        }
    }
    public void changedUpdate(DocumentEvent e) {
        updateValidity();
    }
    public void hierarchyChanged(HierarchyEvent e) {
        if ((e.getChangeFlags() & .) != 0) {
            Window window = SwingUtilities.getWindowAncestor(this);
            if (window instanceof Dialog && !((Dialogwindow).isModal()) {
                showFromEditor();
            } else {
                hideFromEditor();
            }
        }
    }
    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) {
        }
        ;
        LocationCustomizer main = new LocationCustomizer();
        //    main.addValidityListener(new ValidityListener() {
        //      public void validityChanged(boolean isValid) { System.err.println(">>> Validity changed to " + isValid); }
        //    });
        JFrame frame = new JFrame("Customize Profiling Point"); // NOI18N
        frame.getContentPane().add(main);
        frame.pack();
        frame.setVisible(true);
    }
    public void normalizeCaptionAreaWidth(int captionAreaWidth) {
        int requiredCaptionAreaWidth = getPreferredCaptionAreaWidth();
        int diffCaptionAreaWidth = captionAreaWidth - requiredCaptionAreaWidth;
        int normalizedCaptionAreaWidth = (diffCaptionAreaWidth > 0) ? diffCaptionAreaWidth : 0;
        .setBorder(BorderFactory.createEmptyBorder(0, normalizedCaptionAreaWidth, 0, 0));
        .setBorder(BorderFactory.createEmptyBorder(0, normalizedCaptionAreaWidth, 0, 0));
    }
    public void removeUpdate(DocumentEvent e) {
        updateValidity();
    }
    public void resetMnemonic() {
        .setMnemonic(0);
        .setMnemonic(0);
        .setMnemonic(0);
        .setMnemonic(0);
        .setMnemonic(0);
    }
    public void stateChanged(ChangeEvent e) {
        if (e.getSource() == ) {
        }
    }
    private JFileChooser getFileChooser() {
        if ( == null) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(.);
            chooser.setMultiSelectionEnabled(false);
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.setDialogType(.);
            chooser.setDialogTitle(Bundle.LocationCustomizer_ChooseFileDialogCaption());
            chooser.setFileFilter(new FileFilter() {
                    public boolean accept(File f) {
                        return f.isDirectory() || f.getName().toLowerCase().endsWith(".java");
                    } // NOI18N
                    public String getDescription() {
                        return Bundle.LocationCustomizer_FileDialogFilterName();
                    }
                });
             = chooser;
        }
        return ;
    }
    private boolean isFileValid() {
        File file = new File(.getText());
        return file.exists() && file.isFile();
    }
    private void hideFromEditor() {
        .setVisible(false);
        .setVisible(false);
    }
    //  private int getDefaultTextComponentHeight() {
    //    if (defaultTextComponentHeight == -1) defaultTextComponentHeight = new JComboBox().getPreferredSize().height;
    //    return defaultTextComponentHeight;
    //  }
    private void initComponents() {
        setLayout(new GridBagLayout());
        GridBagConstraints constraints;
        // fileLabel
         = new JLabel();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LocationCustomizer_FileLabelText());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 5, 5);
        add(constraints);
        // firstLineCaptionSpacer
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        add(constraints);
        // fileTextField
         = 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, 5, 5);
        add(constraints);
        // fileButton
         = new JButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LocationCustomizer_BrowseButtonText());
        .addActionListener(this);
        constraints = new GridBagConstraints();
        constraints.gridx = 3;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 5, 0);
        add(constraints);
        // fromEditorSeparator
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 4;
        constraints.gridy = 0;
        constraints.gridheight = 2;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 8, 0, 0);
        add(constraints);
        // fromEditorButton
         = new HTMLButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LocationCustomizer_CurrentLineButtonText());
        .addActionListener(this);
        constraints = new GridBagConstraints();
        constraints.gridx = 5;
        constraints.gridy = 0;
        constraints.gridheight = 2;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 8, 0, 0);
        add(constraints);
        // --- next row ----------------------------------------------------------
        ButtonGroup lineRadiosGroup = new ButtonGroup();
        // lineLabel
         = new JLabel();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LocationCustomizer_LineLabelText());
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 5);
        add(constraints);
        // secondLineCaptionSpacer
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        add(constraints);
        JPanel lineSettingsContainer = new JPanel(new GridBagLayout());
        // lineNumberSpinner
         = new JExtendedSpinner() {
                public Dimension getPreferredSize() {
                    return new Dimension(Math.max(super.getPreferredSize()., 55),
                                         getDefaultSpinnerHeight());
                }
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 10);
        lineSettingsContainer.add(constraints);
        // lineBeginRadio
         = new JRadioButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LocationCustomizer_BeginRadioText());
        lineRadiosGroup.add();
        constraints = new GridBagConstraints();
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 3);
        lineSettingsContainer.add(constraints);
        // lineEndRadio
         = new JRadioButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LocationCustomizer_EndRadioText());
        lineRadiosGroup.add();
        constraints = new GridBagConstraints();
        constraints.gridx = 2;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 3);
        lineSettingsContainer.add(constraints);
        // lineOffsetRadio
         = new JRadioButton();
        org.openide.awt.Mnemonics.setLocalizedText(, Bundle.LocationCustomizer_OffsetRadioText());
        lineRadiosGroup.add();
        .addChangeListener(this);
        constraints = new GridBagConstraints();
        constraints.gridx = 3;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        //      lineSettingsContainer.add(lineOffsetRadio, constraints);
        // Placeholder for lineOffsetRadio and lineOffsetSpinner
        lineSettingsContainer.add(new JPanel(new FlowLayout(., 0, 0)) {
                public Dimension getPreferredSize() {
                    return new Dimension(.getPreferredSize(). + .getPreferredSize().,
                                         Math.max(.getPreferredSize().,
                                                  .getPreferredSize().));
                }
            }, constraints);
        // lineOffsetSpinner
         = new JExtendedSpinner() {
                public Dimension getPreferredSize() {
                    return new Dimension(Math.max(super.getPreferredSize()., 55),
                                         getDefaultSpinnerHeight());
                }
                public Dimension getMinimumSize() {
                    return getPreferredSize();
                }
            };
        constraints = new GridBagConstraints();
        constraints.gridx = 4;
        constraints.gridy = 0;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        //      lineSettingsContainer.add(lineOffsetSpinner, constraints);
        constraints = new GridBagConstraints();
        constraints.gridx = 2;
        constraints.gridy = 1;
        constraints.gridwidth = 2;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        add(lineSettingsContainerconstraints);
        // --- next row ----------------------------------------------------------
        JPanel fillerPanel = new JPanel(new FlowLayout(., 0, 0));
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.weighty = 1;
        constraints.anchor = .;
        constraints.fill = .;
        constraints.insets = new Insets(0, 0, 0, 0);
        add(fillerPanelconstraints);
        addHierarchyListener(this);
    }
    private void showFromEditor() {
        .setVisible(true);
        .setVisible(true);
    }
    private void updateValidity() {
        boolean isValid = isFileValid();
        .setForeground(isValid ? UIManager.getColor("TextField.foreground") : .); // NOI18N
        if (isValid != LocationCustomizer.this.areSettingsValid()) {
            fireValidityChanged(isValid);
        }
    }