/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pentestsuite;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextPane;
/**
*
* @author svenfreihofer
*/
public class HelpDialog {
boolean helpDialogOpened;
JDialog helpDialog = new JDialog();
// get screen size
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Dimension min = new Dimension((int) (d.width / 5), 200);
Dimension max = new Dimension((int) (d.width / 5), (int) (d.height));
public HelpDialog(String title, String startparameter) {
if(helpDialogOpened == false) {
// set title
helpDialog.setTitle(title);
// set help dialog size min / max
helpDialog.setMinimumSize(min);
helpDialog.setMaximumSize(max);
// set position on screen (upper right corner of the screen)
helpDialog.setBounds(
d.width - helpDialog.getWidth(), // x-Coord
0, // y-Coord
helpDialog.getWidth(), // helpDialog width
helpDialog.getHeight() // helpDialog height
);
// closing behaviour
helpDialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// help text
JTextPane helpText = new JTextPane();
// set text for help
helpText.setBackground(helpDialog.getBackground());
helpText.setText(startparameter);
helpText.setEditable(false);
// add JTextPane to JDialog
helpDialog.add(helpText);
// show helpDialog
showHelpDialog();
helpDialogOpened = true;
// close helpDialog
closeHelpDialog();
}
} // end constructor HelpDialog
public void showHelpDialog() {
if(!helpDialogOpened) {
helpDialog.setVisible(true);
}
helpDialogOpened = true;
} // end method showHelpDialog
public void closeHelpDialog() {
// close help dialog on window event
helpDialog.addWindowListener(new WindowListener() {
public void windowOpened(WindowEvent e) {
// nothing implemented
}
public void windowClosing(WindowEvent e) {
helpDialogOpened = false;
}
public void windowClosed(WindowEvent e) {
// nothing implemented
}
public void windowIconified(WindowEvent e) {
// nothing implemented
}
public void windowDeiconified(WindowEvent e) {
// nothing implemented
}
public void windowActivated(WindowEvent e) {
// nothing implemented
}
public void windowDeactivated(WindowEvent e) {
// nothing implemented
}
});
} // end method closeHelpDialog
} // end class HelpDialog