Forums > Java

[sharing is ignorance] contextual menus

July 23, 2007 | 6:44 am

is it so wrong that I feel I am one with the divine when I pull this crap off? (just let me soak in my ignorance. )

this hasn’t been tested on other computers so watch out for crashes. one day I’ll do a real version of it.

four messages:

bang: bring up contextual menu (if there are stored menu items)
add (any arguments): similar to append in umenu. (appends menu items)
clear: clears menu items
dispose: gets rid of menu before time-out (3.1 sec)

-matt


July 23, 2007 | 6:54 am

ps heres how to use it

#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P comment 1131 195 65 196622 click me;
#P window setfont "Sans Serif" 9.;
#P newex 1183 92 97 196617 r fromcontextmenu;
#P newex 1183 337 90 196617 send contextmenu;
#P button 1169 175 15 0;
#P message 1183 302 148 196617 face eyes ears nose mouth lips;
#P newex 1183 115 56 196617 route face;
#P newex 1183 140 62 196617 prepend set;
#P message 1183 174 53 196617 ears;
#P newex 882 97 97 196617 r fromcontextmenu;
#P newex 530 232 63 196617 prepend add;
#P newex 531 204 25 196617 iter;
#P newex 532 169 54 196617 t b l clear;
#P newex 439 449 97 196617 s fromcontextmenu;
#P newex 439 403 62 196617 prepend set;
#P newex 662 180 62 196617 prepend set;
#P newex 491 137 51 196617 zl slice 1;
#P newex 662 137 51 196617 zl slice 1;
#P newex 491 82 75 196617 r contextmenu;
#P newex 882 342 90 196617 send contextmenu;
#P button 868 180 15 0;
#P message 882 307 172 196617 moo cows swine ducks horses sheep;
#P newex 882 120 55 196617 route moo;
#P newex 882 145 62 196617 prepend set;
#P message 882 179 53 196617 sheep;
#P newex 439 339 64 196617 fromsymbol;
#P newex 439 298 106 196617 mxj contextmenu001;
#P window setfont "Sans Serif" 14.;
#P comment 837 202 65 196622 click me;
#P connect 9 0 11 0;
#P connect 9 0 10 0;
#P connect 4 0 3 0;
#P connect 5 0 4 0;
#P connect 7 0 6 0;
#P connect 10 0 12 0;
#P connect 13 0 14 0;
#P connect 11 1 15 0;
#P fasten 15 2 1 0 581 266 444 266;
#P connect 15 1 16 0;
#P connect 16 0 17 0;
#P fasten 17 0 1 0 535 266 444 266;
#P fasten 15 0 1 0 537 191 444 191;
#P fasten 12 0 13 0 667 380 444 380;
#P connect 18 0 5 0;
#P connect 6 0 8 0;
#P connect 1 0 2 0;
#P connect 2 0 13 0;
#P connect 22 0 24 0;
#P connect 23 0 22 0;
#P connect 20 0 19 0;
#P connect 21 0 20 0;
#P connect 25 0 21 0;
#P window clipboard copycount 27;


July 23, 2007 | 9:09 am

Hi matt,

• error: java.lang.NoClassDefFoundError: contextmenu001$1
• error: at contextmenu001.(contextmenu001.java:19)
• error: (mxj) unable to construct instance of contextmenu001

You have to share a file called contextmenu001$1.class.
There may be other contextmenu001$N too.

IMHO Sharing your java file is the solution.

Thanks

Léo


July 23, 2007 | 10:30 am

//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 menuItems = new ArrayList();
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

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();
}

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

for(int i = 0 ; 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;
}
}


July 23, 2007 | 11:33 am


July 23, 2007 | 12:15 pm

Oops, didn’t see the followup message, thanks Matt!

Dan

At 7:33 AM -0400 7/23/07, Dan Nigrin wrote:
>Same here for me Matt – thanks in advance!


Dan Nigrin
Defective Records
202 Hack / PC-1600 User / VSTi Host / OMS Convert / Jack OS X / Major
Malfunction
http://www.defectiverecords.com

http://www.jackosx.com


July 23, 2007 | 12:35 pm


July 23, 2007 | 1:03 pm


July 23, 2007 | 4:09 pm

more than welcome. glad to see it actually works one more than one computer.

maybe I’ll cross post in so the non developers can see…



jbm
July 26, 2007 | 9:04 am

ooh, that’s nice!

Works as expected on G5 dual 1.8, OS X 10.4.10, Max 4.6.3, Java 1.5.

Great work.

J.


Viewing 10 posts - 1 through 10 (of 10 total)