Package net.sf.jpluck.apps.jpluckx.ui

Source Code of net.sf.jpluck.apps.jpluckx.ui.AboutDialog$SystemInfo

package net.sf.jpluck.apps.jpluckx.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

import net.sf.jpluck.VersionInfo;
import net.sf.jpluck.http.HttpClient;
import net.sf.jpluck.swing.GUIUtil;
import net.sf.jpluck.swing.TableList;
import net.sf.jpluck.swing.TableListModel;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;


public class AboutDialog extends JDialog {
  public AboutDialog(JFrame owner) {
    super(owner);
    initComponents();
  }

  private void initComponents() {
    setTitle("About JPluck");
    setModal(true);
    setResizable(false);

    JButton closeButton = new JButton("Close");
    Action closeAction = new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        hide();
      }
    };
    closeButton.addActionListener(closeAction);
    GUIUtil.configureEscapeKey(getRootPane(), closeAction);

    JTabbedPane tabbedPane = new JTabbedPane();
    FormLayout formLayout = new FormLayout("center:pref", "pref:grow, 4dlu, pref");
    PanelBuilder panelBuilder = new PanelBuilder(formLayout);
    panelBuilder.setDefaultDialogBorder();
    panelBuilder.add(tabbedPane, new CellConstraints(1, 1));

    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder();
    buttonBarBuilder.addGridded(closeButton);
    panelBuilder.add(buttonBarBuilder.getPanel(), new CellConstraints(1, 3));
    getContentPane().add(panelBuilder.getPanel(), BorderLayout.CENTER);

    formLayout = new FormLayout("0dlu, center:pref, 0dlu", "0dlu, center:pref, 4dlu, pref, 0dlu");
    panelBuilder = new PanelBuilder(formLayout);

    JLabel label = new JLabel(
      new ImageIcon(this.getClass().getClassLoader().getResource("net/sf/jpluck/res/jpluckx.jpg")));
    panelBuilder.add(label, new CellConstraints(2, 2));
    panelBuilder.addLabel("Version " + VersionInfo.VERSION + " (" + VersionInfo.RELEASE_DATE + ")",
                new CellConstraints(2, 4));
    panelBuilder.setBorder(Borders.TABBED_DIALOG_BORDER);
    tabbedPane.add("Version", panelBuilder.getPanel());

    formLayout = new FormLayout("fill:10dlu:grow", "fill:10dlu:grow");
    panelBuilder = new PanelBuilder(formLayout);

    TableList tableList = new TableList(new SystemInfo());
    tableList.setEnabled(false);
    tableList.optimizeWidths(4);
    panelBuilder = new PanelBuilder(new FormLayout("fill:pref:grow", "fill:pref:grow"));
    panelBuilder.setBorder(Borders.TABBED_DIALOG_BORDER);
    JScrollPane scrollPane = new JScrollPane(tableList);
    scrollPane.setPreferredSize(new Dimension(10,10));
    panelBuilder.add(scrollPane, "1,1");
    tabbedPane.addTab("System", panelBuilder.getPanel());

    List charsetList = new ArrayList();
    Map map = Charset.availableCharsets();
    for (Iterator it = map.values().iterator(); it.hasNext();) {
      Charset charset = (Charset) it.next();
      charsetList.add(charset.displayName());
    }

    JList list = new JList(charsetList.toArray());
    panelBuilder = new PanelBuilder(new FormLayout("fill:pref:grow", "fill:pref:grow"));
    panelBuilder.setBorder(Borders.TABBED_DIALOG_BORDER);
    panelBuilder.add(new JScrollPane(list), "1,1");
    tabbedPane.addTab("Charsets", panelBuilder.getPanel());

    panelBuilder = new PanelBuilder(new FormLayout("fill:pref:grow", "fill:pref:grow"));
    panelBuilder.setBorder(Borders.TABBED_DIALOG_BORDER);
    panelBuilder.add(getText("net/sf/jpluck/res/credits.txt"));
    tabbedPane.addTab("Credits", panelBuilder.getPanel());

    panelBuilder = new PanelBuilder(new FormLayout("fill:pref:grow", "fill:pref:grow"));
    panelBuilder.setBorder(Borders.TABBED_DIALOG_BORDER);
    panelBuilder.add(getText("net/sf/jpluck/res/license.txt"));
    tabbedPane.addTab("License", panelBuilder.getPanel());

    pack();
  }

  private static class SystemInfo extends TableListModel {
    private List systemPropertyList = new ArrayList();
    private String[] columnNames = { "System Property", "Value" };

    public SystemInfo() {
      Properties properties = System.getProperties();
      Set keySet = properties.keySet();
      for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
        String key = (String) iterator.next();
        if (key.equals(HttpClient.PROXY_USER_KEY) || key.equals(HttpClient.PROXY_PASSWORD_KEY)) {
          continue;
        }

        String value = properties.getProperty(key);
        SystemProperty systemProperty = new SystemProperty(key, value);
        systemPropertyList.add(systemProperty);
      }
      Collections.sort(systemPropertyList);
    }

    public int getColumnCount() {
      return 2;
    }

    public String getColumnName(int i) {
      return columnNames[i];
    }

    public Object getElementAt(int index) {
      return systemPropertyList.get(index);
    }

    public int getSize() {
      return systemPropertyList.size();
    }

    public Object getValue(Object o, int i) {
      SystemProperty systemProperty = (SystemProperty) o;
      if (i == 0) {
        return systemProperty.name;
      } else {
        return systemProperty.value;
      }
    }

    public void sortByColumn(int i, boolean b) {
    }
  }

  private static class SystemProperty implements Comparable {
    private String name;
    private String value;

    public SystemProperty(String name, String value) {
      this.name = name;
      this.value = value;
    }

    public int compareTo(Object o) {
      SystemProperty systemProperty = (SystemProperty) o;
      return (name.compareTo(systemProperty.name));
    }
  }
 
  private JScrollPane getText(String path) {
    try {
      JTextArea creditsText = new JTextArea();
      creditsText.setColumns(10);
      creditsText.setRows(10);

      StringBuffer credits = new StringBuffer();
      InputStream in = AboutDialog.class.getClassLoader().getResourceAsStream(path);
      LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in));
      for (String line; (line = rdr.readLine()) != null;) {
        credits.append(line + "\n");
      }
      rdr.close();
      creditsText.setText(credits.toString());
      creditsText.setEditable(false);
      creditsText.setLineWrap(true);
      creditsText.setWrapStyleWord(true);
      creditsText.setCaretPosition(0);

      JScrollPane scrollPane = new JScrollPane(creditsText);
      scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      return scrollPane;
    } catch (IOException e) {
      return null;
    }
  }
}
TOP

Related Classes of net.sf.jpluck.apps.jpluckx.ui.AboutDialog$SystemInfo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.