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-2008 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.i18n;
 
 
 
 import static javax.swing.GroupLayout.Alignment.BASELINE;
 import static javax.swing.GroupLayout.Alignment.TRAILING;
 import static javax.swing.LayoutStyle.ComponentPlacement.RELATED;


Panel which provides GUI for i18n action. Customizes I18nString object and is used by I18nSupport for i18n-izing one source.

Author(s):
Peter Zavadsky
 
 public class I18nPanel extends JPanel {
 
     private static final String CONTENT_FORM = "form visible";          //NOI18N
     private static final String CONTENT_MESG = "message visible";       //NOI18N
 
     private final boolean withButtons;

    
 
     private final CardLayout cardLayout = new CardLayout();

    
I18nString cusomized in this panel.
 
     private I18nString i18nString;
    
    
Helper bundle used for i18n-zing strings in this source.
 
     private ResourceBundle bundle;

    
Helper property change support.
 
    private PropertyChangeListener propListener;
    
    
Generated serial version ID.
    static final long serialVersionUID =-6982482491017390786L;
    private Project project;
    private FileObject file;
    
    private static final long ALL_BUTTONS    = ~0;
    private static final long NO_BUTTONS     = 0;
    private static final long REPLACE_BUTTON = 1 << 0;
    private static final long SKIP_BUTTON    = 1 << 1;
    private static final long IGNORE_BUTTON  = 1 << 2;
    private static final long INFO_BUTTON    = 1 << 3;
    private static final long CANCEL_BUTTON  = 1 << 4;
    private static final long HELP_BUTTON    = 1 << 5;


    
    
Creates new I18nPanel. In order to correctly localize classpath for property bundle chooser, the dialog must know the project and a file to choose the bundle for.

Parameters:
propertyPanel panel for customizing i18n strings
project the Project to choose bundles from
file the FileObject to choose bundles for
    public I18nPanel(PropertyPanel propertyPanelProject projectFileObject file) {
        this(propertyPaneltrueprojectfile);
    }

    
Creates i18n panel.

Parameters:
propertyPanel panel for customizing i18n strings
withButtons if panel with replace, skip ect. buttons should be added
project the Project to choose bundles from
file the FileObject to choose bundles for
    public I18nPanel(PropertyPanel propertyPanelboolean withButtonsProject projectFileObject file) {
        this. = project;
        this. = file;
        this. = propertyPanel;
        this..setFile(file);
        this..setEnabled(project != null);
        this. = new EmptyPropertyPanel();
        // Init bundle.
         = I18nUtil.getBundle();
        
        this. = withButtons;
        initComponents();
        myInitComponents();
        initAccessibility();        
        
        showBundleMessage("TXT_SearchingForStrings");                   //NOI18N
    }
    private boolean contentsShown;
    public void showBundleMessage(String bundleKey) {
        .setBundleText(bundleKey);
         = false;
        buttonsEnableDisable();
    }
    public void showPropertyPanel() {
         = true;
        buttonsEnableDisable();        
    }


    
    
Reset associated project to a new value
//    public void setProject(Project project) {
////        ((ResourcePanel)resourcePanel).setProject(project);
//        propertyPanel.setEnabled(project != null);
//
//    }
//
//    public Project getProject() { 
//        return ((ResourcePanel)resourcePanel).getProject();
//    }
    
    
Sets the file associated with this panel -- the one, which is localized
 
    public void setFile(FileObject file) {
//        ((ResourcePanel)resourcePanel).setFile(file);
        .setFile(file);
    }
    
    
Gets the file associated with this panel -- the one, which is localized
 
    public FileObject getFile() {
//        return ((ResourcePanel)resourcePanel).getFile();
        return .getFile();
    }

    
    
Overrides superclass method to set default button.
    @Override
    public void addNotify() {
        super.addNotify();
        
        if () {
            if (SwingUtilities.isDescendingFrom(this)) {
                getRootPane().setDefaultButton();
            }
        }
    }
    
    
Getter for i18nString.
    public I18nString getI18nString() {
        return ;
    }
    
    
Setter for i18nString property.
    public void setI18nString(I18nString i18nString) {
        this. = i18nString;
        .setI18nString(i18nString);
//        ((ResourcePanel)resourcePanel).setI18nString(i18nString);        
        
        showPropertyPanel();
    }

    
Replace button accessor.
        assert ;
        return ;
    }
    
    
Skip button accessor.
        assert ;
        return ;
    }

    
Ignore button accessor.
        assert ;
        return ;
    }

    
Info button accessor.
        assert ;
        return ;
    }
    
    
Cancel/Close button accessor.
        assert ;
        return ;
    }
    
    
Enables/disables buttons based on the contents of the dialog.
    private void buttonsEnableDisable() {
        if (!) {
            return;
        }
        if () {
            enableButtons();
            boolean isBundle = ( != null)
                               && (.getSupport().getResourceHolder().getResource() != null);
            boolean keyEmpty = (getI18nString() == null)
                               || (getI18nString().getKey() == null)
                               || (getI18nString().getKey().trim().length() == 0);
            .setEnabled(isBundle && !keyEmpty);
        } else {
            enableButtons( | );
        }
    }
    public void setDefaultResource(DataObject dataObject) {
        if (dataObject != null) {
            // look for peer Bundle.properties
            FileObject fo = dataObject.getPrimaryFile();
            ClassPath cp = ClassPath.getClassPath(fo.);
            if (cp != null) {
                FileObject folder = cp.findResource(cp.getResourceName(fo.getParent()));
                while (folder != null && cp.contains(folder)) {
                
                    String rn = cp.getResourceName(folder) + "/Bundle.properties"// NOI18N
                
                    FileObject peer = cp.findResource(rn);
                    if (peer == null) {
                        //Try to find any properties file
                        Enumeration<? extends FileObjectdata = Enumerations.filter(folder.getData(false), new Enumerations.Processor(){
                            public Object process(Object objCollection alwaysNull) {
                                if (obj instanceof FileObject &&
                                        "properties".equals( ((FileObject)obj).getExt())){ //NOI18N
                                    return obj;
                                } else {
                                    return null;
                                }
                            }
                        });
                        if (data.hasMoreElements()) {
                            peer = data.nextElement();
                        }
                    }
                    if (peer != null) {
                        try {
                            DataObject peerDataObject = DataObject.find(peer);
//                          ((ResourcePanel)resourcePanel).setResource(peerDataObject);
                            .setResource(peerDataObject);
                            return;
                        } catch (IOException ex) {
                            // no default resource
                        }
                    }
                    folder = folder.getParent();
                }
            }
        }
    }        
    
    
Creates ResourcePanel.
//    private JPanel createResourcePanel() {
//        return new ResourcePanel(project, file);
//    }
    
    private void initAccessibility() {
                .getString("ACS_I18nPanel"));                     //NOI18N
        if () {
                    .getString("ACS_CTL_SkipButton"));            //NOI18N
                    .getString("ACS_CTL_IgnoreButton"));            //NOI18N
            .setToolTipText(.getString("TT_IgnoreButton"));            //NOI18N
                    .getString("ACS_CTL_CancelButton"));          //NOI18N
                    .getString("ACS_CTL_ReplaceButton"));         //NOI18N
                    .getString("ACS_CTL_InfoButton"));            //NOI18N
                    .getString("ACS_CTL_HelpButton"));            //NOI18N
        }
    }
    
    
This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the FormEditor.
    // <editor-fold defaultstate="collapsed" desc="UI Initialization Code">
    private void initComponents() {
         = new JPanel();
        if () {
             = new JButton();
             = new JButton();
             = new JButton();
             = new JButton();
             = new JButton();
             = new JButton();
            Mnemonics.setLocalizedText(.getString("CTL_ReplaceButton")); // NOI18N
            Mnemonics.setLocalizedText(.getString("CTL_SkipButton")); // NOI18N
            Mnemonics.setLocalizedText(.getString("CTL_IgnoreButton")); // NOI18N
            Mnemonics.setLocalizedText(.getString("CTL_InfoButton")); // NOI18N
            Mnemonics.setLocalizedText(.getString("CTL_CloseButton")); // NOI18N
            Mnemonics.setLocalizedText(.getString("CTL_HelpButton")); // NOI18N
            .addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    helpButtonActionPerformed(evt);
                }
            });
        }
        GroupLayout layout;
        setLayout (layout = new GroupLayout(this));
        GroupLayout.SequentialGroup horizGroup = layout.createSequentialGroup();
        horizGroup.addContainerGap();
        if () {
            horizGroup.addGroup(
                    layout.createParallelGroup()
                    .addComponent()
                    .addGroup(layout.createSequentialGroup()
                        .addComponent()
                        .addPreferredGap()
                        .addComponent()
                        .addPreferredGap()
                        .addComponent()
                        .addPreferredGap()
                        .addComponent()
                        .addPreferredGap()
                        .addComponent()
                        .addPreferredGap()
                        .addComponent()));
            layout.linkSize(.,
                                             ,
                                             ,
                                             ,
                                             ,
                                             );
        } else {
            horizGroup.addComponent();
        }
        horizGroup.addContainerGap();
        layout.setHorizontalGroup(horizGroup);
        GroupLayout.SequentialGroup vertGroup = layout.createSequentialGroup();
        vertGroup.addContainerGap();
        vertGroup.addComponent();
        if () {
            vertGroup
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup()
                .addComponent()
                .addComponent()
                .addComponent()
                .addComponent()
                .addComponent()
                .addComponent());
        }
        vertGroup.addContainerGap();
        layout.setVerticalGroup(vertGroup);
    }// </editor-fold>
    private void myInitComponents() {
//        resourcePanel = createResourcePanel();
//        contentsPanel = new JPanel();
//        contentsPanel.setLayout(new BoxLayout(contentsPanel, BoxLayout.Y_AXIS));
//        contentsPanel.add(resourcePanel);
//        contentsPanel.add(propertyPanel);
         = true;
        
        if () {
                    .
                    new PropertyChangeListener() {
                        public void propertyChange(PropertyChangeEvent evt) {
                            buttonsEnableDisable();
                        }
                    });
            
                    .,
    //                WeakListeners.propertyChange(
                        new PropertyChangeListener() {
                            public void propertyChange(PropertyChangeEvent evt) {
                                if(..equals(evt.getPropertyName())) {
                                    buttonsEnableDisable();
        //                            ((PropertyPanel)propertyPanel).updateAllValues();
                                }
                            }
                        }
    //                },resourcePanel
    //               )
            );
        }
        
    }
  private void helpButtonActionPerformed(ActionEvent evt) {
      assert ;
      HelpCtx help = new HelpCtx(.);
      
      String sysprop = System.getProperty("org.openide.actions.HelpAction.DEBUG"); // NOI18N
      
      if ("true".equals(sysprop) || "full".equals(sysprop)) { // NOI18N
          ..println ("I18n module: Help button showing: " + help); // NOI18N, please do not comment out
      }
      help.display();
  }
    private void enableButtons(long buttonMask) {
        assert ;
        .setEnabled((buttonMask & ) != 0);
        .setEnabled((buttonMask & ) != 0);
        .setEnabled((buttonMask & ) != 0);
        .setEnabled((buttonMask & ) != 0);
        .setEnabled((buttonMask & ) != 0);
        .setEnabled((buttonMask & ) != 0);               
    }
        
    // Variables declaration
    private JButton cancelButton;
    private JButton helpButton;
    private JButton infoButton;
    private JButton replaceButton;
    private JButton skipButton;
    private JButton ignoreButton;
    // End of variables declaration
//    private JPanel resourcePanel;
    private PropertyPanel propertyPanel;
//    private JPanel contentsPanel;
New to GrepCode? Check out our FAQ X