View Javadoc

1   package com.explosion.expf.menusandtools.menu.popup;
2   
3   import java.awt.Component;
4   import java.awt.event.MouseEvent;
5   
6   import javax.swing.JPopupMenu;
7   
8   import com.explosion.expf.ExpConstants;
9   import com.explosion.expf.menusandtools.menu.InvalidOrUnknownSegmentException;
10  import com.explosion.expf.menusandtools.menu.segmented.ExpMenuSegment;
11  import com.explosion.expf.menusandtools.menu.segmented.ExpSegmentedMenu;
12  import com.explosion.expf.menusandtools.menu.segmented.SegmentedMenuHelper;
13  
14  
15  /* =============================================================================
16   *       
17   *     Copyright 2004 Stephen Cowx
18   *
19   *     Licensed under the Apache License, Version 2.0 (the "License");
20   *     you may not use this file except in compliance with the License.
21   *     You may obtain a copy of the License at
22   *
23   *     http://www.apache.org/licenses/LICENSE-2.0
24   *
25   *     Unless required by applicable law or agreed to in writing, software
26   *     distributed under the License is distributed on an "AS IS" BASIS,
27   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28   *     See the License for the specific language governing permissions and
29   *     limitations under the License.
30   * 
31   * =============================================================================
32   */
33  
34  /***
35   * This class is used to support generic right click menu functions across components
36   * in Expf applicaitons
37   * 
38   * I have repeated a lot of the code between this class and the ExpMenu class, this is unfortunate
39   * but neccessary (for now) as the JPopupMenu and the JMenu do not share a handy inheritance
40   * @author Stephen Cowx
41   * Created on 03-Mar-2005
42   */
43  public class ExpPopupableMenu extends JPopupMenu implements ExpSegmentedMenu
44  {
45  
46      private static org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(ExpPopupableMenu.class);
47      private SegmentedMenuHelper menuHelper;
48      
49      public ExpPopupableMenu() 
50      {
51        super(ExpConstants.COMPNAME_EXPPOPUPMENU);
52        this.setName(ExpConstants.COMPNAME_EXPPOPUPMENU);
53        this.menuHelper = new SegmentedMenuHelper(this,this);
54      }
55      /***
56       * Creates a new segment in this menu
57       */
58      public ExpMenuSegment createNewSegment(int relativePositionOfSegmentOnMenu) throws Exception
59      {
60         return menuHelper.createNewSegment(relativePositionOfSegmentOnMenu);
61      }
62  
63      /***
64       * @param segment
65       * @param item
66       * @throws InvalidOrUnknownSegmentException
67       */
68      public void addElementToSegment(ExpMenuSegment segment, Component item) throws InvalidOrUnknownSegmentException
69      {
70          menuHelper.addElementToSegment(segment, item);
71      }
72      
73      /***
74       * Removes all the elements except the separator from this menu 
75       * @param segment
76       * @param item
77       * @throws InvalidOrUnknownSegmentException
78       */
79      public void removeSegment(ExpMenuSegment segment) throws InvalidOrUnknownSegmentException
80      {
81      	menuHelper.removeSegment(segment);
82      }
83      
84      /***
85       * Shows this component
86       * @param event
87       */
88      public void show(MouseEvent event)
89      {
90          show(event.getComponent(), event.getX(), event.getY());
91      }
92      
93  }