Package PieContext

Source Code of PieContext.PieContextMenu

package PieContext;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JLayeredPane;
import javax.swing.JPopupMenu;
 

@SuppressWarnings("serial")
public class PieContextMenu extends JPopupMenu implements MouseMotionListener, MouseListener{

  private JComponent parent;
  private JLayeredPane container;
  private List<PieItem> items; 
 
  public PieContextMenu(JComponent arg0){   
    super();
    parent = arg0;
    items = new LinkedList<PieItem>();
    setPopupSize(200, 200);
    setBorderPainted(false);
    setOpaque(false);
    container = new JLayeredPane();
    container.setSize(getSize())
    container.setOpaque(false);;
    container.setBounds(0, 0, 200, 200);
   
    addMouseListener(this);
    addMouseMotionListener(this);
    add(container);   
         
  }
 
 
  public void show(int posX, int posY){ 
    System.out.println(posX + " -- " + posY);
    show(parent,
        (int) (posX - 45),
        (int) (posY) - 80);
  }
 
  public void addPieItem(PieItem item){
    items.add(item);
    container.add(item, new Integer(1));
    double angle = 360.0/items.size();
    double startAngle = 0;
    for(int i=0; i<items.size();i++){     
      startAngle = i*angle;     
      items.get(i).configureItem1((int)getPreferredSize().getWidth()-20,
          (int)getPreferredSize().getHeight()-20,startAngle, angle);
         
    }
  }
 
  public void addPieMenu(PieMenu menu){
    items.add(menu);
    container.add(menu, new Integer(1));
    double angle = 360.0/items.size();
    double startAngle = 0;
    for(int i=0; i<items.size();i++){
      startAngle = i*angle;
      items.get(i).configureItem((int)getPreferredSize().getWidth()-20,
          (int)getPreferredSize().getHeight()-20,startAngle, angle);             
    }
    angle = 50.0;
    startAngle = 0;
    for(int i=0; i<menu.items.size();i++){
      startAngle = i*angle;
      container.add(menu.items.get(i), new Integer(2));
      menu.items.get(i).configureItem((int)getPreferredSize().getWidth()+120,
          (int)getPreferredSize().getHeight()-20,startAngle, angle);             
    }
  }
 
  public void mouseDragged(MouseEvent e) {}
  public void mouseMoved(MouseEvent e) {
    for(int i=0; i<items.size();i++){
      if(items.get(i).getArcZone().contains(e.getX(),e.getY())){
        items.get(i).setSelected(true);       
      }
      else{
        items.get(i).setSelected(false);
      }     
    }
  }
  public void mouseClicked(MouseEvent e) {
    for(int i=0; i<items.size();i++){
      if(items.get(i).getArcZone().contains(e.getX(),e.getY())){
        items.get(i).getItem().doClick();     
      }
    }
  }
  public void mouseEntered(MouseEvent e) {}
  public void mouseExited(MouseEvent e) {}
  public void mousePressed(MouseEvent e) {
    System.out.println(e.getPoint());
  }
  public void mouseReleased(MouseEvent e) {}
 
}
TOP

Related Classes of PieContext.PieContextMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.