/*
* JDialogSystem.java
*
* Created on 8. M�rz 2005, 16:27
*/
package xplanetconfigurator.gui;
import java.util.*;
import java.awt.*;
import xplanetconfigurator.util.OwnPreferences;
/**
*
* @author wiedthom
*/
public class JDialogSystem extends javax.swing.JDialog {
private static String FRAME_X = "dialog_system_info_x";
private static String FRAME_Y = "dialog_system_info_y";
private static String FRAME_HEIGHT = "dialog_system_info_h";
private static String FRAME_WITH = "dialog_system_info_w";
/** Creates new form JDialogSystem */
public JDialogSystem(java.awt.Frame parent) {
super(parent, true);
initComponents();
this.getRootPane().setDefaultButton(this.jButtonClose);
this.loadUserPrefs();
this.loadText();
this.jButtonClose.requestFocus();
}
/** 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 Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jPanelMain = new javax.swing.JPanel();
jScrollPane = new javax.swing.JScrollPane();
jEditorPane = new javax.swing.JEditorPane();
jButtonClose = new javax.swing.JButton();
setTitle("System Info");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getContentPane().setLayout(new java.awt.GridBagLayout());
jPanelMain.setLayout(new java.awt.GridBagLayout());
jEditorPane.setEditable(false);
jScrollPane.setViewportView(jEditorPane);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
jPanelMain.add(jScrollPane, gridBagConstraints);
jButtonClose.setMnemonic('C');
jButtonClose.setText("Close");
jButtonClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCloseActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
jPanelMain.add(jButtonClose, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
getContentPane().add(jPanelMain, gridBagConstraints);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCloseActionPerformed
// Add your handling code here:
this.closeMySelf();
}//GEN-LAST:event_jButtonCloseActionPerformed
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
this.closeMySelf();
}//GEN-LAST:event_exitForm
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new JDialogSystem(new Frame()).setVisible(true);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonClose;
private javax.swing.JEditorPane jEditorPane;
private javax.swing.JPanel jPanelMain;
private javax.swing.JScrollPane jScrollPane;
// End of variables declaration//GEN-END:variables
private void loadText() {
StringBuffer buf = new StringBuffer();
buf.append("<table border='1'>");
Object[] keys = System.getProperties().keySet().toArray();
Arrays.sort(keys);
int length = keys.length;
for (int i = 0; i < length; i++) {
buf.append("<tr>");
buf.append("<td valign='top'>");
String key = (String) keys[i];
buf.append(key);
buf.append("</td>");
buf.append("<td valign='top'>");
String value = (String) System.getProperty(key);
buf.append(value);
buf.append("</td>");
buf.append("</tr>");
}
buf.append("</table>");
this.jEditorPane.setContentType("text/html");
this.jEditorPane.setText(buf.toString());
this.jEditorPane.setCaretPosition(1);
}
private void storeUserPrefs() {
int x = this.getX();
int y = this.getY();
Dimension d = this.getSize();
int h = (int) d.getHeight();
int w = (int) d.getWidth();
OwnPreferences prefs =
OwnPreferences.userNodeForPackage(this.getClass());
prefs.putInt(FRAME_X, x);
prefs.putInt(FRAME_Y, y);
prefs.putInt(FRAME_HEIGHT, h);
prefs.putInt(FRAME_WITH, w);
}
private void loadUserPrefs() {
OwnPreferences prefs =
OwnPreferences.userNodeForPackage(this.getClass());
int x = prefs.getInt(FRAME_X, 10);
int y = prefs.getInt(FRAME_Y, 10);
int h = prefs.getInt(FRAME_HEIGHT, 500);
int w = prefs.getInt(FRAME_WITH, 400);
this.setSize(new Dimension(w, h));
// System.out.println("Start info = " + info);
if (x == 10 && y == 10) // First use
{
// System.out.println("Start info in if() = " + info);
this.setLocationRelativeTo(null); //center it
} else {
this.setLocation(x, y);
}
}
private void closeMySelf() {
this.storeUserPrefs();
this.setVisible(false);
this.dispose();
}
}