/* package com.SoftWoehr.JTOpenContrib.MEU.example; */
import java.awt.event.*;
import java.util.*;
import com.SoftWoehr.JTOpenContrib.MEU.MEU;
import com.SoftWoehr.JTOpenContrib.MEU.MEUStockDialog;
/**
*
* @author jax
* @version
*/
public class PopupExample extends javax.swing.JFrame {
private MEU meu = null;
/** Creates new form PopupExample */
public PopupExample() {
initComponents ();
pack ();
initMouseListener();
}
/** 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 FormEditor.
*/
private void initComponents () {
jPopupMenu1 = new javax.swing.JPopupMenu ();
meuMenuItem = new javax.swing.JMenuItem ();
jTextArea1 = new javax.swing.JTextArea ();
meuMenuItem.setToolTipText ("Open
an MEU instance on the selected server name and IFS path.");
meuMenuItem.setText ("MEU");
meuMenuItem.addActionListener (new
java.awt.event.ActionListener () {
public void actionPerformed
(java.awt.event.ActionEvent evt) {
meuMenuItemActionPerformed
(evt);
}
}
);
jPopupMenu1.add (meuMenuItem);
setTitle ("ENTER A SERVER NAME AND AN IFS PATH
THEN HIGHLIGHT AND USE POPUP MENU");
addWindowListener (new java.awt.event.WindowAdapter
() {
public void windowClosing (java.awt.event.WindowEvent
evt) {
exitForm (evt);
}
}
);
jTextArea1.setPreferredSize (new java.awt.Dimension(400,
200));
jTextArea1.setMinimumSize (new java.awt.Dimension(400,
200));
getContentPane ().add (jTextArea1, java.awt.BorderLayout.CENTER);
}
private void meuMenuItemActionPerformed (java.awt.event.ActionEvent
evt) {
// Add your handling code here:
String s = jTextArea1.getSelectedText();
String server = null;
String ifsPath = null;
// Get spec, if any.
if (null != s) {
StringTokenizer st = new StringTokenizer(s);
if (st.hasMoreTokens()) {
server = st.nextToken();
}
if (st.hasMoreTokens()) {
ifsPath = st.nextToken();
}
}
if (null != server && null != ifsPath)
{ // Try the spec.
meuSession(server,ifsPath);
}
else { // Don't try the spec if nulls exist.
MEUStockDialog.showErrorMessageDialog
(this,
"Enter a server name and a fully-qualified
IFS Path,\n" +
"then select them with mouse and
use popup menu to launch MEU.",
"MEU Popup Example Usage");
}
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit (0);
}
/**
* @param args the command line arguments
*/
public static void main (String args[]) {
new PopupExample ().show ();
}
// Variables declaration - do not modify
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JMenuItem meuMenuItem;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
public void initMouseListener() {
jTextArea1.addMouseListener(new MouseListener
() {
public void mouseClicked (MouseEvent
e) {
}
public void mouseEntered(MouseEvent
e) {
}
public void mouseExited(MouseEvent
e) {
}
public void mousePressed(MouseEvent
e)
{
if (e.isPopupTrigger())
{
jPopupMenu1.show(e.getComponent(),
e.getX(),
e.getY());
}
}
public void mouseReleased(MouseEvent
e)
{
if (e.isPopupTrigger())
{
jPopupMenu1.show(e.getComponent(),
e.getX(),
e.getY());
}
}
});
}
/** Open an MEU window, using extant MEU instance if present.
*/
private void meuSession (String serverName, String ifsPath)
{
if (null != meu) {
meu.newFrame(null, serverName, ifsPath);
}
else {
meu = new MEU(null, serverName,
ifsPath);
meu.setAllowedToExit(false); //
So MEU itself can't close the demo.
}
}
}