com-sun-tools-visualvm-jmx

16:33:53.130 INFO  jd.cli.Main - Decompiling com-sun-tools-visualvm-jmx.jar
package com.sun.tools.visualvm.jmx;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.Storage;
import java.util.Map;

public class CredentialsProvider$Custom
  extends CredentialsProvider
{
  private final String username;
  private final char[] password;
  private final boolean persistent;
  
  public CredentialsProvider$Custom(String username, char[] password, boolean persistent)
  {
    this.username = username;
    this.password = CredentialsProvider.access$000(password);
    this.persistent = persistent;
  }
  
  public Map<String, ?> getEnvironment(Application application, Storage storage)
  {
    return CredentialsProvider.access$100(username, password != null ? new String(password) : null);
  }
  
  public String getEnvironmentId(Storage storage)
  {
    if (username != null) {
      return username;
    }
    return super.getEnvironmentId(storage);
  }
  
  public void saveEnvironment(Storage storage)
  {
    if (!persistent) {
      return;
    }
    storage.setCustomProperty("prop_credentials_username", username);
    storage.setCustomProperty("prop_credentials_password", new String(password));
  }
  
  String getUsername(Storage storage)
  {
    return username;
  }
  
  boolean hasPassword(Storage storage)
  {
    return (password != null) && (password.length > 0);
  }
  
  boolean isPersistent(Storage storage)
  {
    return persistent;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.CredentialsProvider.Custom
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.Storage;
import java.util.Map;

public class CredentialsProvider$Persistent
  extends CredentialsProvider
{
  public Map<String, ?> getEnvironment(Application application, Storage storage)
  {
    String username = storage.getCustomProperty("prop_credentials_username");
    String password = storage.getCustomProperty("prop_credentials_password");
    return CredentialsProvider.access$100(username, password);
  }
  
  public String getEnvironmentId(Storage storage)
  {
    if (storage != null)
    {
      String username = storage.getCustomProperty("prop_credentials_username");
      if (username != null) {
        return username;
      }
    }
    return super.getEnvironmentId(storage);
  }
  
  String getUsername(Storage storage)
  {
    return storage.getCustomProperty("prop_credentials_username");
  }
  
  boolean hasPassword(Storage storage)
  {
    String password = storage.getCustomProperty("prop_credentials_password");
    return (password != null) && (password.length() > 0);
  }
  
  boolean isPersistent(Storage storage)
  {
    return (getUsername(storage) != null) || (hasPassword(storage));
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.CredentialsProvider.Persistent
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.datasupport.Utils;
import java.util.HashMap;
import java.util.Map;

public abstract class CredentialsProvider
  extends EnvironmentProvider
{
  private static final String PROPERTY_USERNAME = "prop_credentials_username";
  private static final String PROPERTY_PASSWORD = "prop_credentials_password";
  private static Persistent PERSISTENT_PROVIDER;
  
  static synchronized Persistent persistent()
  {
    if (PERSISTENT_PROVIDER == null) {
      PERSISTENT_PROVIDER = new Persistent();
    }
    return PERSISTENT_PROVIDER;
  }
  
  public String getId()
  {
    return CredentialsProvider.class.getName();
  }
  
  abstract String getUsername(Storage paramStorage);
  
  abstract boolean hasPassword(Storage paramStorage);
  
  abstract boolean isPersistent(Storage paramStorage);
  
  public static class Custom
    extends CredentialsProvider
  {
    private final String username;
    private final char[] password;
    private final boolean persistent;
    
    public Custom(String username, char[] password, boolean persistent)
    {
      this.username = username;
      this.password = CredentialsProvider.encodePassword(password);
      this.persistent = persistent;
    }
    
    public Map<String, ?> getEnvironment(Application application, Storage storage)
    {
      return CredentialsProvider.createMap(username, password != null ? new String(password) : null);
    }
    
    public String getEnvironmentId(Storage storage)
    {
      if (username != null) {
        return username;
      }
      return super.getEnvironmentId(storage);
    }
    
    public void saveEnvironment(Storage storage)
    {
      if (!persistent) {
        return;
      }
      storage.setCustomProperty("prop_credentials_username", username);
      storage.setCustomProperty("prop_credentials_password", new String(password));
    }
    
    String getUsername(Storage storage)
    {
      return username;
    }
    
    boolean hasPassword(Storage storage)
    {
      return (password != null) && (password.length > 0);
    }
    
    boolean isPersistent(Storage storage)
    {
      return persistent;
    }
  }
  
  public static class Persistent
    extends CredentialsProvider
  {
    public Map<String, ?> getEnvironment(Application application, Storage storage)
    {
      String username = storage.getCustomProperty("prop_credentials_username");
      String password = storage.getCustomProperty("prop_credentials_password");
      return CredentialsProvider.createMap(username, password);
    }
    
    public String getEnvironmentId(Storage storage)
    {
      if (storage != null)
      {
        String username = storage.getCustomProperty("prop_credentials_username");
        if (username != null) {
          return username;
        }
      }
      return super.getEnvironmentId(storage);
    }
    
    String getUsername(Storage storage)
    {
      return storage.getCustomProperty("prop_credentials_username");
    }
    
    boolean hasPassword(Storage storage)
    {
      String password = storage.getCustomProperty("prop_credentials_password");
      return (password != null) && (password.length() > 0);
    }
    
    boolean isPersistent(Storage storage)
    {
      return (getUsername(storage) != null) || (hasPassword(storage));
    }
  }
  
  private static Map<String, ?> createMap(String username, String password)
  {
    Map map = new HashMap();
    if ((username != null) || (password != null)) {
      map.put("jmx.remote.credentials", new String[] { username, decodePassword(password) });
    }
    return map;
  }
  
  private static char[] encodePassword(char[] password)
  {
    if (password == null) {
      return null;
    }
    return Utils.encodePassword(new String(password)).toCharArray();
  }
  
  private static String decodePassword(String password)
  {
    if (password == null) {
      return null;
    }
    return Utils.decodePassword(password);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.CredentialsProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import javax.swing.JCheckBox;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

class DefaultCustomizer$CustomizerUI$1
  implements Runnable
{
  DefaultCustomizer$CustomizerUI$1(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void run()
  {
    String username = this$0.getUsername();
    String url = this$0.getConnectionString();
    if (!DefaultCustomizer.CustomizerUI.access$000(this$0).isSelected())
    {
      DefaultCustomizer.CustomizerUI.access$102(this$0, true);
      DefaultCustomizer.CustomizerUI.access$200(this$0).setText(((username == null) || (username.isEmpty()) ? "" : new StringBuilder().append(username).append("@").toString()) + url);
      
      DefaultCustomizer.CustomizerUI.access$102(this$0, false);
    }
    String displayname = this$0.getDisplayName();
    DefaultCustomizer.CustomizerUI.access$200(this$0).setEnabled(DefaultCustomizer.CustomizerUI.access$000(this$0).isSelected());
    
    DefaultCustomizer.CustomizerUI.access$400(this$0).setEnabled(DefaultCustomizer.CustomizerUI.access$300(this$0).isSelected());
    DefaultCustomizer.CustomizerUI.access$500(this$0).setEnabled(DefaultCustomizer.CustomizerUI.access$300(this$0).isSelected());
    DefaultCustomizer.CustomizerUI.access$600(this$0).setEnabled(DefaultCustomizer.CustomizerUI.access$300(this$0).isSelected());
    
    DefaultCustomizer.CustomizerUI.access$700(this$0, (DefaultCustomizer.isValidConnectionString(url)) && (displayname.length() > 0));
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

class DefaultCustomizer$CustomizerUI$2
  implements DocumentListener
{
  DefaultCustomizer$CustomizerUI$2(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void insertUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void removeUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void changedUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class DefaultCustomizer$CustomizerUI$3
  implements ActionListener
{
  DefaultCustomizer$CustomizerUI$3(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void actionPerformed(ActionEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

class DefaultCustomizer$CustomizerUI$4
  implements DocumentListener
{
  DefaultCustomizer$CustomizerUI$4(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void insertUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void removeUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void changedUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.4
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class DefaultCustomizer$CustomizerUI$5
  implements ActionListener
{
  DefaultCustomizer$CustomizerUI$5(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void actionPerformed(ActionEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.5
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

class DefaultCustomizer$CustomizerUI$6
  implements DocumentListener
{
  DefaultCustomizer$CustomizerUI$6(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void insertUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void removeUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void changedUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.6
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

class DefaultCustomizer$CustomizerUI$7
  implements DocumentListener
{
  DefaultCustomizer$CustomizerUI$7(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void insertUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void removeUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
  
  public void changedUpdate(DocumentEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.7
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class DefaultCustomizer$CustomizerUI$8
  implements ActionListener
{
  DefaultCustomizer$CustomizerUI$8(DefaultCustomizer.CustomizerUI paramCustomizerUI) {}
  
  public void actionPerformed(ActionEvent e)
  {
    DefaultCustomizer.CustomizerUI.access$800(this$0);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI.8
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.explorer.ExplorerSupport;
import com.sun.tools.visualvm.core.properties.PropertiesPanel;
import com.sun.tools.visualvm.core.ui.components.Spacer;
import com.sun.tools.visualvm.host.Host;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Set;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import org.openide.awt.Mnemonics;
import org.openide.util.NbBundle;

public class DefaultCustomizer$CustomizerUI
  extends PropertiesPanel
{
  public DefaultCustomizer$CustomizerUI()
  {
    initComponents();
    initDefaults();
    update();
  }
  
  public final String getConnectionString()
  {
    return connectionField.getText().trim();
  }
  
  public final String getDisplayName()
  {
    return displaynameField.getText().trim();
  }
  
  public final String getUsername()
  {
    return !securityCheckbox.isSelected() ? null : usernameField.getText().trim();
  }
  
  public final char[] getPassword()
  {
    return !securityCheckbox.isSelected() ? null : passwordField.getPassword();
  }
  
  public final boolean getSaveCredentials()
  {
    return !securityCheckbox.isSelected() ? false : saveCheckbox.isSelected();
  }
  
  private void initDefaults()
  {
    Set<DataSource> selectedDataSources = ExplorerSupport.sharedInstance().getSelectedDataSources();
    if (selectedDataSources.size() != 1) {
      return;
    }
    DataSource selectedDataSource = (DataSource)selectedDataSources.iterator().next();
    if (!(selectedDataSource instanceof Host)) {
      return;
    }
    Host host = (Host)selectedDataSource;
    connectionField.setText(host.getHostName() + ":");
  }
  
  private void update()
  {
    if (internalChange) {
      return;
    }
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        String username = getUsername();
        String url = getConnectionString();
        if (!displaynameCheckbox.isSelected())
        {
          internalChange = true;
          displaynameField.setText(((username == null) || (username.isEmpty()) ? "" : new StringBuilder().append(username).append("@").toString()) + url);
          
          internalChange = false;
        }
        String displayname = getDisplayName();
        displaynameField.setEnabled(displaynameCheckbox.isSelected());
        
        usernameField.setEnabled(securityCheckbox.isSelected());
        passwordField.setEnabled(securityCheckbox.isSelected());
        saveCheckbox.setEnabled(securityCheckbox.isSelected());
        
        setSettingsValid((DefaultCustomizer.isValidConnectionString(url)) && (displayname.length() > 0));
      }
    });
  }
  
  private void initComponents()
  {
    setLayout(new GridBagLayout());
    
    connectionLabel = new JLabel();
    Mnemonics.setLocalizedText(connectionLabel, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Connection"));
    
    GridBagConstraints constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 0;
    gridwidth = 1;
    fill = 0;
    anchor = 13;
    insets = new Insets(0, 0, 0, 0);
    add(connectionLabel, constraints);
    
    connectionField = new JTextField();
    connectionLabel.setLabelFor(connectionField);
    connectionField.setPreferredSize(new Dimension(250, connectionField.getPreferredSize().height));
    
    connectionField.getDocument().addDocumentListener(new DocumentListener()
    {
      public void insertUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void removeUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void changedUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
    });
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 0;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(0, 5, 0, 0);
    add(connectionField, constraints);
    
    Font normalLabelFont = connectionLabel.getFont();
    Font smallLabelFont = normalLabelFont.deriveFont(normalLabelFont.getSize2D() - 1.0F);
    
    usageLabel = new JLabel(NbBundle.getMessage(DefaultCustomizer.class, "LBL_Usage"));
    usageLabel.setFont(smallLabelFont);
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 1;
    gridwidth = 0;
    fill = 0;
    anchor = 17;
    insets = new Insets(0, 5, 0, 0);
    add(usageLabel, constraints);
    
    displaynameCheckbox = new JCheckBox();
    Mnemonics.setLocalizedText(displaynameCheckbox, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Display_name"));
    
    displaynameCheckbox.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
    });
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 2;
    gridwidth = 1;
    fill = 0;
    anchor = 13;
    insets = new Insets(8, 4, 0, 0);
    add(displaynameCheckbox, constraints);
    
    displaynameField = new JTextField();
    displaynameField.setPreferredSize(new Dimension(250, displaynameField.getPreferredSize().height));
    
    displaynameField.getDocument().addDocumentListener(new DocumentListener()
    {
      public void insertUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void removeUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void changedUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
    });
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 2;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(8, 5, 0, 0);
    add(displaynameField, constraints);
    
    securityCheckbox = new JCheckBox();
    Mnemonics.setLocalizedText(securityCheckbox, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Use_security_credentials"));
    
    securityCheckbox.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
    });
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 3;
    gridwidth = 0;
    fill = 0;
    anchor = 17;
    insets = new Insets(15, 0, 0, 0);
    add(securityCheckbox, constraints);
    
    usernameLabel = new JLabel();
    Mnemonics.setLocalizedText(usernameLabel, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Username"));
    
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 4;
    gridwidth = 1;
    fill = 0;
    anchor = 13;
    insets = new Insets(5, 0, 0, 0);
    add(usernameLabel, constraints);
    
    usernameField = new JTextField();
    usernameLabel.setLabelFor(usernameField);
    usernameField.setPreferredSize(new Dimension(320, usernameField.getPreferredSize().height));
    
    usernameField.getDocument().addDocumentListener(new DocumentListener()
    {
      public void insertUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void removeUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void changedUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
    });
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 4;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(5, 5, 0, 0);
    add(usernameField, constraints);
    
    passwordLabel = new JLabel();
    Mnemonics.setLocalizedText(passwordLabel, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Password"));
    
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 5;
    gridwidth = 1;
    fill = 0;
    anchor = 13;
    insets = new Insets(8, 0, 0, 0);
    add(passwordLabel, constraints);
    
    passwordField = new JPasswordField();
    passwordLabel.setLabelFor(passwordField);
    passwordField.setPreferredSize(new Dimension(200, passwordField.getPreferredSize().height));
    
    passwordField.getDocument().addDocumentListener(new DocumentListener()
    {
      public void insertUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void removeUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
      
      public void changedUpdate(DocumentEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
    });
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 5;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(8, 5, 0, 0);
    add(passwordField, constraints);
    
    saveCheckbox = new JCheckBox();
    Mnemonics.setLocalizedText(saveCheckbox, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Save_security_credentials"));
    
    saveCheckbox.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        DefaultCustomizer.CustomizerUI.this.update();
      }
    });
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 6;
    gridwidth = 0;
    fill = 2;
    anchor = 13;
    insets = new Insets(8, 30, 0, 0);
    add(saveCheckbox, constraints);
    
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 7;
    weightx = 1.0D;
    weighty = 1.0D;
    gridwidth = 0;
    fill = 1;
    anchor = 18;
    insets = new Insets(10, 0, 0, 0);
    add(Spacer.create(), constraints);
    
    displaynameCheckbox.setBorder(connectionLabel.getBorder());
  }
  
  private boolean internalChange = false;
  private JLabel connectionLabel;
  private JTextField connectionField;
  private JLabel usageLabel;
  private JCheckBox displaynameCheckbox;
  private JTextField displaynameField;
  private JCheckBox securityCheckbox;
  private JLabel usernameLabel;
  private JTextField usernameField;
  private JLabel passwordLabel;
  private JPasswordField passwordField;
  private JCheckBox saveCheckbox;
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.CustomizerUI
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.properties.PropertiesPanel;
import com.sun.tools.visualvm.core.ui.components.Spacer;
import com.sun.tools.visualvm.jmx.impl.JmxApplication;
import com.sun.tools.visualvm.jmx.impl.JmxApplicationProvider;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import org.openide.awt.Mnemonics;
import org.openide.util.NbBundle;

public class DefaultCustomizer$PropertiesUI
  extends PropertiesPanel
{
  private JLabel connectionLabel;
  private JTextField connectionField;
  private JCheckBox securityCheckbox;
  private JLabel usernameLabel;
  private JTextField usernameField;
  private JLabel passwordLabel;
  private JPasswordField passwordField;
  private JCheckBox saveCheckbox;
  
  public DefaultCustomizer$PropertiesUI(Application application)
  {
    initComponents();
    setValues(application);
  }
  
  private void setValues(Application application)
  {
    JmxApplication app = (JmxApplication)application;
    String connectionString = JmxApplicationProvider.getConnectionString(app);
    
    Storage storage = application.getStorage();
    CredentialsProvider provider = (CredentialsProvider)app.getEnvironmentProvider();
    String username = provider.getUsername(storage);
    boolean password = provider.hasPassword(storage);
    boolean persistent = provider.isPersistent(storage);
    
    connectionField.setText(connectionString);
    connectionField.setCaretPosition(0);
    securityCheckbox.setSelected((username != null) || (password));
    usernameField.setText(username);
    usernameField.setCaretPosition(0);
    passwordField.setText(password ? "----------" : "");
    passwordField.setCaretPosition(0);
    saveCheckbox.setSelected(persistent);
  }
  
  private void initComponents()
  {
    setLayout(new GridBagLayout());
    
    Color checkboxForeground = UIManager.getColor("CheckBox.foreground");
    Color checkboxText = new Color(checkboxForeground.getRGB());
    
    connectionLabel = new JLabel();
    Mnemonics.setLocalizedText(connectionLabel, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Connection"));
    
    GridBagConstraints constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 0;
    gridwidth = 1;
    fill = 0;
    anchor = 17;
    insets = new Insets(3, 0, 3, 0);
    add(connectionLabel, constraints);
    
    connectionField = new JTextField();
    connectionLabel.setLabelFor(connectionField);
    connectionField.setEditable(false);
    Dimension size = connectionField.getPreferredSize();
    width = 1;
    connectionField.setPreferredSize(size);
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 0;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(3, 5, 3, 0);
    add(connectionField, constraints);
    
    securityCheckbox = new JCheckBox();
    Mnemonics.setLocalizedText(securityCheckbox, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Use_security_credentials"));
    
    securityCheckbox.setEnabled(false);
    securityCheckbox.setOpaque(false);
    securityCheckbox.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    securityCheckbox.setForeground(checkboxText);
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 3;
    gridwidth = 0;
    fill = 0;
    anchor = 17;
    insets = new Insets(15, 0, 3, 0);
    add(securityCheckbox, constraints);
    
    usernameLabel = new JLabel();
    Mnemonics.setLocalizedText(usernameLabel, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Username"));
    
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 4;
    gridwidth = 1;
    fill = 0;
    anchor = 17;
    insets = new Insets(3, 20, 3, 0);
    add(usernameLabel, constraints);
    
    usernameField = new JTextField();
    usernameLabel.setLabelFor(usernameField);
    usernameField.setEditable(false);
    size = usernameField.getPreferredSize();
    width = 1;
    usernameField.setPreferredSize(size);
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 4;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(3, 5, 3, 0);
    add(usernameField, constraints);
    
    passwordLabel = new JLabel();
    Mnemonics.setLocalizedText(passwordLabel, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Password"));
    
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 5;
    gridwidth = 1;
    fill = 0;
    anchor = 17;
    insets = new Insets(3, 20, 3, 0);
    add(passwordLabel, constraints);
    
    passwordField = new JPasswordField();
    passwordLabel.setLabelFor(passwordField);
    passwordField.setEditable(false);
    passwordField.setFocusable(false);
    size = passwordField.getPreferredSize();
    width = 1;
    passwordField.setPreferredSize(size);
    constraints = new GridBagConstraints();
    gridx = 1;
    gridy = 5;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(3, 5, 3, 0);
    add(passwordField, constraints);
    
    saveCheckbox = new JCheckBox();
    Mnemonics.setLocalizedText(saveCheckbox, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Save_security_credentials"));
    
    saveCheckbox.setEnabled(false);
    saveCheckbox.setOpaque(false);
    saveCheckbox.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 3));
    saveCheckbox.setForeground(checkboxText);
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 6;
    gridwidth = 0;
    fill = 2;
    anchor = 17;
    insets = new Insets(3, 20, 3, 0);
    add(saveCheckbox, constraints);
    
    constraints = new GridBagConstraints();
    gridx = 0;
    gridy = 7;
    weightx = 1.0D;
    weighty = 1.0D;
    gridwidth = 0;
    fill = 1;
    anchor = 18;
    insets = new Insets(0, 0, 0, 0);
    add(Spacer.create(), constraints);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.jmx.DefaultCustomizer.PropertiesUI
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.jmx;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.explorer.ExplorerSupport;
import com.sun.tools.visualvm.core.properties.PropertiesPanel;
import com.sun.tools.visualvm.core.ui.components.Spacer;
import com.sun.tools.visualvm.host.Host;
import com.sun.tools.visualvm.jmx.impl.JmxApplication;
import com.sun.tools.visualvm.jmx.impl.JmxApplicationProvider;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import org.openide.awt.Mnemonics;
import org.openide.util.NbBundle;
import sun.net.util.IPAddressUtil;

public class DefaultCustomizer
  extends JmxConnectionCustomizer
{
  DefaultCustomizer()
  {
    super(NbBundle.getMessage(DefaultCustomizer.class, "LBL_Default_jmx_connection_name"), NbBundle.getMessage(DefaultCustomizer.class, "LBL_Default_jmx_connection_descr"), 1, false);
  }
  
  public boolean providesProperties(Application application)
  {
    if (!(application instanceof JmxApplication)) {
      return false;
    }
    EnvironmentProvider provider = ((JmxApplication)application).getEnvironmentProvider();
    
    return (provider != null) && ((provider instanceof CredentialsProvider));
  }
  
  public PropertiesPanel createPanel(Application application)
  {
    if (application == null) {
      return new CustomizerUI();
    }
    return new PropertiesUI(application);
  }
  
  public JmxConnectionCustomizer.Setup getConnectionSetup(PropertiesPanel customizerPanel)
  {
    if (!(customizerPanel instanceof CustomizerUI)) {
      throw new IllegalArgumentException("Panel must be DefaultCustomizer.CustomizerUI");
    }
    CustomizerUI panel = (CustomizerUI)customizerPanel;
    
    String connectionString = panel.getConnectionString();
    String displayName = panel.getDisplayName();
    EnvironmentProvider provider = new CredentialsProvider.Custom(panel.getUsername(), panel.getPassword(), panel.getSaveCredentials());
    
    boolean persistent = true;
    
    return new JmxConnectionCustomizer.Setup(connectionString, displayName, provider, persistent);
  }
  
  protected static boolean isValidConnectionString(String jmxurl)
  {
    boolean valid = false;
    if (jmxurl != null)
    {
      jmxurl = jmxurl.trim();
      if (jmxurl.startsWith("service:jmx:"))
      {
        if (jmxurl.length() > "service:jmx:".length()) {
          valid = true;
        }
      }
      else if (jmxurl.startsWith("["))
      {
        int index = jmxurl.indexOf("]:");
        if (index != -1)
        {
          String address = jmxurl.substring(1, index);
          if (IPAddressUtil.isIPv6LiteralAddress(address)) {
            try
            {
              String portStr = jmxurl.substring(index + 2);
              int port = Integer.parseInt(portStr);
              if ((port >= 0) && (port <= 65535)) {
                valid = true;
              }
            }
            catch (NumberFormatException ex)
            {
              valid = false;
            }
          }
        }
      }
      else
      {
        String[] s = jmxurl.split(":");
        if (s.length == 2) {
          try
          {
            int port = Integer.parseInt(s[1]);
            if ((port >= 0) && (port <= 65535)) {
              valid = true;
            }
          }
          catch (NumberFormatException ex)
          {
            valid = false;
          }
        }
      }
    }
    return valid;
  }
  
  public static class CustomizerUI
    extends PropertiesPanel
  {
    public CustomizerUI()
    {
      initComponents();
      initDefaults();
      update();
    }
    
    public final String getConnectionString()
    {
      return connectionField.getText().trim();
    }
    
    public final String getDisplayName()
    {
      return displaynameField.getText().trim();
    }
    
    public final String getUsername()
    {
      return !securityCheckbox.isSelected() ? null : usernameField.getText().trim();
    }
    
    public final char[] getPassword()
    {
      return !securityCheckbox.isSelected() ? null : passwordField.getPassword();
    }
    
    public final boolean getSaveCredentials()
    {
      return !securityCheckbox.isSelected() ? false : saveCheckbox.isSelected();
    }
    
    private void initDefaults()
    {
      Set<DataSource> selectedDataSources = ExplorerSupport.sharedInstance().getSelectedDataSources();
      if (selectedDataSources.size() != 1) {
        return;
      }
      DataSource selectedDataSource = (DataSource)selectedDataSources.iterator().next();
      if (!(selectedDataSource instanceof Host)) {
        return;
      }
      Host host = (Host)selectedDataSource;
      connectionField.setText(host.getHostName() + ":");
    }
    
    private void update()
    {
      if (internalChange) {
        return;
      }
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          String username = getUsername();
          String url = getConnectionString();
          if (!displaynameCheckbox.isSelected())
          {
            internalChange = true;
            displaynameField.setText(((username == null) || (username.isEmpty()) ? "" : new StringBuilder().append(username).append("@").toString()) + url);
            
            internalChange = false;
          }
          String displayname = getDisplayName();
          displaynameField.setEnabled(displaynameCheckbox.isSelected());
          
          usernameField.setEnabled(securityCheckbox.isSelected());
          passwordField.setEnabled(securityCheckbox.isSelected());
          saveCheckbox.setEnabled(securityCheckbox.isSelected());
          
          setSettingsValid((DefaultCustomizer.isValidConnectionString(url)) && (displayname.length() > 0));
        }
      });
    }
    
    private void initComponents()
    {
      setLayout(new GridBagLayout());
      
      connectionLabel = new JLabel();
      Mnemonics.setLocalizedText(connectionLabel, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Connection"));
      
      GridBagConstraints constraints = new GridBagConstraints();
      gridx = 0;
      gridy = 0;
      gridwidth = 1;
      fill = 0;
      anchor = 13;
      insets = new Insets(0, 0, 0, 0);
      add(connectionLabel, constraints);
      
      connectionField = new JTextField();
      connectionLabel.setLabelFor(connectionField);
      connectionField.setPreferredSize(new Dimension(250, connectionField.getPreferredSize().height));
      
      connectionField.getDocument().addDocumentListener(new DocumentListener()
      {
        public void insertUpdate(DocumentEvent e)
        {
          DefaultCustomizer.CustomizerUI.this.update();
        }
        
        public void removeUpdate(DocumentEvent e)
        {
          DefaultCustomizer.CustomizerUI.this.update();
        }
        
        public void changedUpdate(DocumentEvent e)
        {
          DefaultCustomizer.CustomizerUI.this.update();
        }
      });
      constraints = new GridBagConstraints();
      gridx = 1;
      gridy = 0;
      gridwidth = 0;
      fill = 2;
      anchor = 17;
      insets = new Insets(0, 5, 0, 0);
      add(connectionField, constraints);
      
      Font normalLabelFont = connectionLabel.getFont();
      Font smallLabelFont = normalLabelFont.deriveFont(normalLabelFont.getSize2D() - 1.0F);
      
      usageLabel = new JLabel(NbBundle.getMessage(DefaultCustomizer.class, "LBL_Usage"));
      usageLabel.setFont(smallLabelFont);
      constraints = new GridBagConstraints();
      gridx = 1;
      gridy = 1;
      gridwidth = 0;
      fill = 0;
      anchor = 17;
      insets = new Insets(0, 5, 0, 0);
      add(usageLabel, constraints);
      
      displaynameCheckbox = new JCheckBox();
      Mnemonics.setLocalizedText(displaynameCheckbox, NbBundle.getMessage(DefaultCustomizer.class, "LBL_Display_name"));
      
      displaynameCheckbox.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          DefaultCustomizer.CustomizerUI.this.update();
        }
      });
      constraints = new GridBagConstraints();
      gridx = 0;
      gridy = 2;
      gridwidth = 1;
      fill = 0;
      anchor = 13;
      insets = new Insets(8, 4, 0, 0);
      add(displaynameCheckbox, constraints);
      
      displaynameField = new JTextField();
      displaynameField.setPreferredSize(new Dimension(250, displaynameField.getPreferred
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd