[sharing is ignorance] contextual menus


    Jul 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

    • Jul 23 2007 | 6:54 am
      ps heres how to use it
    • Jul 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
    • Jul 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; } }
    • Jul 23 2007 | 11:33 am
    • Jul 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
    • Jul 23 2007 | 1:03 pm
    • Jul 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...
    • Jul 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.