Showing posts with label Swing-based tools. Show all posts
Showing posts with label Swing-based tools. Show all posts

Wednesday, May 9, 2007

A JVM Properties Viewer


This is mostly a bare-bones version of a basic Swing application that was created using Eclipse's visual editor. In it there is a single method to present the contents of the JVM properties into a text area.

See the method loadJVMData().

The whole application has been listed here so that you can cut-n-paste into your own editor and run it.




/*
* Modification History
*
* Date Project Pgmr Description
* -------- --------- ---- ---------------------------------------------------
* 02242004 Utilities BF Initial release
* 10072005 Utilities BF Refactored to use
* Properties properties = System.getProperties();
* to get entire list of properties.
*
*
*
*/
package com.utilities.ui;

import java.net.InetAddress;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;

import javax.swing.JDialog;
import javax.swing.JFrame;

import com.utilities.general.StringRoutines;

/**
* @author
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class JVMProperties extends JDialog {

private javax.swing.JPanel jContentPane = null;

private javax.swing.JPanel jPanel = null;
private javax.swing.JPanel jPanel1 = null;
private javax.swing.JPanel jPanel2 = null;
private javax.swing.JLabel jLabel = null;
private javax.swing.JButton jButton = null;
private javax.swing.JList jList = null;

private javax.swing.JScrollPane jScrollPane = null;
//private static JVMProperties jvmProps = null;

/**
* This is the most-always empty Main()
*/
public static void main(String[] args) {
JVMProperties jvmp = new JVMProperties(null,true);
jvmp.show();
System.exit(0);
}


/**
* This is the default constructor. It calls the process to perform
*/
public JVMProperties(JFrame parent, boolean modal) {

super(parent, modal);
initialize();
if (parent != null) {
this.setLocationRelativeTo(parent.getContentPane());
} else {
this.setLocationRelativeTo(null);
}

this.process();
}


/**
* This is the processor-controller
*/
public void process() {

this.loadJVMData();

}


/**
* This method was created in VisualAge.
*/
public void loadJVMData() {

String CR = System.getProperty("line.separator");
Vector vector = new Vector();

//Get the internet address of the machine in which this is running
try {
InetAddress inetAddr = InetAddress.getLocalHost();

String key = "Internet host name / address";
String nameAddr = inetAddr.getHostName() + "/" + inetAddr.getHostAddress();
int n = 30 - key.length();
if (n <= 0) n = 1;
String rightPad = StringRoutines.padStringLeft(">", n);

vector.add(key + rightPad + nameAddr);
} catch (Exception e) {
}

//Now get the rest of the proerties and add them to the list
Properties properties = System.getProperties();
Set set = properties.keySet();
Iterator setIter = set.iterator();
while(setIter.hasNext()) {
String key = (String)setIter.next();
String value = properties.getProperty(key);

int n = 30 - key.length();
if (n <= 0) n = 1;
String rightPad = StringRoutines.padStringLeft(">", n);
//System.out.println(key + rightEdge + value);
vector.add(key + rightPad + value);
}

//vector.add("java.naming.factory.initial>"+System.getProperty("java.naming.factory.initial"));
jList.setListData(vector);
//AppLog.debug(vector);

}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(604, 372);
this.setContentPane(getJContentPane());
this.setLocation(100, 200);
this.setTitle("Java Virtual Machine Properties Viewer");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new javax.swing.JPanel();
java.awt.GridBagConstraints consGridBagConstraints11 = new java.awt.GridBagConstraints();
java.awt.GridBagConstraints consGridBagConstraints10 = new java.awt.GridBagConstraints();
java.awt.GridBagConstraints consGridBagConstraints12 = new java.awt.GridBagConstraints();
consGridBagConstraints11.fill = java.awt.GridBagConstraints.BOTH;
consGridBagConstraints11.weighty = 200.0D;
consGridBagConstraints11.weightx = 1.0;
consGridBagConstraints11.gridx = 0;
consGridBagConstraints11.gridy = 1;
consGridBagConstraints10.fill = java.awt.GridBagConstraints.BOTH;
consGridBagConstraints10.weighty = 1.0;
consGridBagConstraints10.weightx = 1.0;
consGridBagConstraints10.gridy = 0;
consGridBagConstraints10.gridx = 0;
consGridBagConstraints12.fill = java.awt.GridBagConstraints.BOTH;
consGridBagConstraints12.weighty = 1.0;
consGridBagConstraints12.weightx = 1.0;
consGridBagConstraints12.gridx = 0;
consGridBagConstraints12.gridy = 2;
jContentPane.setLayout(new java.awt.GridBagLayout());
jContentPane.add(getJPanel(), consGridBagConstraints10);
jContentPane.add(getJPanel1(), consGridBagConstraints11);
jContentPane.add(getJPanel2(), consGridBagConstraints12);
}
return jContentPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJPanel() {
if(jPanel == null) {
jPanel = new javax.swing.JPanel();
java.awt.FlowLayout layFlowLayout13 = new java.awt.FlowLayout();
layFlowLayout13.setAlignment(java.awt.FlowLayout.LEFT);
jPanel.setLayout(layFlowLayout13);
jPanel.add(getJLabel(), null);
}
return jPanel;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJPanel1() {
if(jPanel1 == null) {
jPanel1 = new javax.swing.JPanel();
jPanel1.setLayout(new java.awt.BorderLayout());
jPanel1.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
jPanel1.setPreferredSize(new java.awt.Dimension(200,200));
}
return jPanel1;
}
/**
* This method initializes jPanel2
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJPanel2() {
if(jPanel2 == null) {
jPanel2 = new javax.swing.JPanel();
java.awt.FlowLayout layFlowLayout14 = new java.awt.FlowLayout();
layFlowLayout14.setAlignment(java.awt.FlowLayout.RIGHT);
jPanel2.setLayout(layFlowLayout14);
jPanel2.add(getJButton(), null);
}
return jPanel2;
}
/**
* This method initializes jLabel
*
* @return javax.swing.JLabel
*/
private javax.swing.JLabel getJLabel() {
if(jLabel == null) {
jLabel = new javax.swing.JLabel();
jLabel.setText("JVM Properties");
}
return jLabel;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private javax.swing.JButton getJButton() {
if(jButton == null) {
jButton = new javax.swing.JButton();
jButton.setText("Close");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
hide();
}
});
}
return jButton;
}
/**
* This method initializes jList
*
* @return javax.swing.JList
*/
private javax.swing.JList getJList() {
if(jList == null) {
jList = new javax.swing.JList();
jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jList.setPreferredSize(new java.awt.Dimension(800,800));
jList.setVisibleRowCount(5);
jList.setFont(new java.awt.Font("Courier New", java.awt.Font.PLAIN, 12));
}
return jList;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private javax.swing.JScrollPane getJScrollPane() {
if(jScrollPane == null) {
jScrollPane = new javax.swing.JScrollPane();
jScrollPane.setViewportView(getJList());
jScrollPane.setPreferredSize(new java.awt.Dimension(274,300));
}
return jScrollPane;
}
} // @jve:visual-info decl-index=0 visual-constraint="10,10"

Thursday, May 3, 2007

Swing based Font Properties Editor


Here's a utility to allow for quick selection of font properties showing the results in a phrase containing all letters of the alphabet. In addition, the developer can copy the resulting Java statement and paste it into their project code.

Rather than post the 500+ lines here, the code is available for the asking. Just post a request to this post (below) with an email address where I can send the .java source file. (I have no interests in using the address other than to send the code, so know that your address will not be used for any other purpose.)