XML Feeds

.

[java-dev] Re: Re: [sharing is ignorance] contextual menus

Matthew Aidekman puuukeey at comcast.net
Mon Jul 23 04:30:15 MDT 2007


//good call my friend.  attachment and included in post.  sorry for the pomp and let down.

import com.cycling74.max.*;
import java.awt.*; 
import java.awt.event.*; 
import java.awt.MouseInfo;
import javax.swing.*;
import java.util.*;
import javax.swing.Timer;
import javax.swing.plaf.*;
public class contextmenu001 extends MaxObject
{

Frame f;

ArrayList<String> menuItems = new ArrayList<String>();
PointerInfo now ;
int time = 3100;


	Action superdispose = new AbstractAction() {
	public void actionPerformed(ActionEvent e) {
		 dispose();
					
	
		}

	};
 Timer a;



	private static final String[] INLET_ASSIST = new String[]{
		"inlet 1 help"
	};
	private static final String[] OUTLET_ASSIST = new String[]{
		"outlet 1 help"
	};
	
	public contextmenu001(Atom[] args)
	{
		declareInlets(new int[]{DataTypes.ALL});
		declareOutlets(new int[]{DataTypes.ALL});
		
		setInletAssist(INLET_ASSIST);
		setOutletAssist(OUTLET_ASSIST);

	 a= 	new Timer(time, superdispose);
	 a.setRepeats( false) ;
	}



	public void bang()
	{

	if(menuItems.size() < 1 )
	{
		return;
	} 




	if(f==null)
		{
	 	f = new Frame("Hello Java"); 
		}

	f.removeAll();	  	
 	f.setLayout(new BoxLayout(f, BoxLayout.Y_AXIS));
   		
			
	
	for(int i = 0 ; i <menuItems.size();i++)
		f.add(createMatButton ( menuItems.get(i)  ));


	f.setFocusableWindowState(true);
	if(f.isShowing()==false)//almost english
	{
		f.setBackground(new Color(0,0,0,180)) ;
		
		f.setUndecorated(true);
	}	



	

	f.addWindowFocusListener(new WindowAdapter() {

	public void windowLostFocus(WindowEvent evt) {

	if(f!=null)
		{	
		f.toFront();
		}
	}
	});



	now=	MouseInfo.getPointerInfo() ;
	Point myPoint = now.getLocation();


    f.pack(); 
	f.validate();

	int temp = (int)f.getWidth()/2;
	f.setLocation((int)(myPoint.getX()-temp) ,(int)myPoint.getY());

    f.show(); 
	a.stop();
	a.start();
	}




	public void clear()
	{
	menuItems = new ArrayList<String>();
	}



	public void add(Atom[] list )
	{
	String myString= "";

		for(int i = 0 ; i<list.length;i++ )
		{
		myString=	myString+list[i].toString()+" ";
		}
	menuItems.add(myString);

	}
	

	public void createNewFrame()
	{
	 
	}
    
	public void inlet(int i)
	{
	}
    
	public void inlet(float f)
	{
	}
    
    
	public void list(Atom[] list)
	{
	}


	public void setTime(int i )
	{
	time = i;
	}
    

	public void dispose()
	{

	if(f!=null)
	{
		if(f.isShowing() )
		{
			SwingUtilities.invokeLater(new Runnable(){
				public void run()
				{
					f.dispose();
					f=null;
				}
			});	
		}
	}
	}






 class MyActionListener implements ActionListener 
	{ 
	  public void actionPerformed(ActionEvent e) { 
	    // Action Command is not necessarily label 
	   
	


		if( e.getActionCommand().matches("MatsContextualMenu.*"));
			{
			outlet(0, e.getActionCommand().substring(18)); 
			f.dispose();
			}
		}
	

    } 
  
 	class MyMouseMotionListener implements MouseMotionListener
	{


		public void mouseDragged(MouseEvent e) 
		{
			post("drag");
			
		
		}

		public void mouseMoved(MouseEvent e) 
		{
			post("mouseMoved");
			
		
		}

	}

	class MyMouseListener implements MouseListener
	{
	
		public void 	mouseClicked(MouseEvent e){
	//		post("mouseClicked");
		}
		public void 	mouseEntered(MouseEvent e){
	//		post("mouseEntered");
			((JButton)e.getComponent()).setForeground(Color.white);	
        }
		public void 	mouseExited(MouseEvent e){
			((JButton)e.getComponent()).setForeground(Color.gray);
	//		post("mouseExited");
 		}
		public void 	mousePressed(MouseEvent e){

	//		post("mousePressed");
       	} 
		public void 	mouseReleased(MouseEvent e){

	//		post("mouseReleased");
       	}   
	}


  JButton createMatButton (String text) 
	{
	JButton b = new JButton(text); 
	ActionListener al = new MyActionListener(); 
    b.setActionCommand("MatsContextualMenu"+text); 
    b.addActionListener(al); 
//	MouseMotionListener mml = new MyMouseMotionListener(); 
//	b.addMouseMotionListener(mml);
 	MouseListener ml = new MyMouseListener(); 
	b.addMouseListener(ml);
	b.setContentAreaFilled(false);
    b.setBorderPainted(false); 
	b.setForeground(Color.gray);		
	b.setAlignmentX(Component.CENTER_ALIGNMENT);
	return b;	
	}
}



-------------- next part --------------
A non-text attachment was scrubbed...
Name: contextmenu001.java
Type: application/octet-stream
Size: 4084 bytes
Desc: not available
Url : http://www.cycling74.com/pipermail/java-dev/attachments/20070723/83978da2/contextmenu001.obj


More information about the java-dev mailing list