Horus Doc || Java GUI Reference || Doxygen's quick Index  

PopMenu Class Reference

List of all members.

Public Methods

 PopMenu (JComponent parent)
 PopMenu (JComponent parent, String[] labels)
void addLabel (String label)
void addLabels (String[] newLabels)
void addMenu (JMenu m)
void addSeparator ()
void insertSeparator (int index)
void setEnabled (boolean b, String label)
void show (int x, int y)
void actionPerformed (ActionEvent event)

Constructor & Destructor Documentation

PopMenu::PopMenu JComponent    parent [inline]
 

00031     {
00032         this.parent = parent;
00033         this.labels = new String[0];
00034         pum = new JPopupMenu();
00035     }

PopMenu::PopMenu JComponent    parent,
String    labels[]
[inline]
 

00039     {
00040         this.parent = parent;
00041         this.labels = labels;
00042         pum = new JPopupMenu();
00043         addLabels(labels);
00044     }


Member Function Documentation

void PopMenu::addLabel String    label [inline]
 

00051     {
00052         String[] tmp = new String[1];
00053         tmp[0] = label;
00054         addLabels(tmp);
00055     }

void PopMenu::addLabels String    newLabels[] [inline]
 

00059     {
00060         if (newLabels != null) {
00061             String[] tmp = new String[labels.length + newLabels.length];
00062             for (int i=0; i < labels.length + newLabels.length; i++) {
00063                 if (i < labels.length) {
00064                     tmp[i] = labels[i];
00065                 } else {
00066                     tmp[i] = newLabels[i - labels.length];
00067 
00068                     JMenuItem mi = new JMenuItem(tmp[i]);
00069 
00070                     mi.setActionCommand(tmp[i]);
00071                     mi.addActionListener(this);
00072                     pum.add(mi);
00073                 }
00074             }
00075             labels = tmp;
00076         }
00077     }

void PopMenu::addMenu JMenu    m [inline]
 

00081     {
00082         pum.add(m);
00083 
00084         String[] tmp = new String[labels.length + 1];
00085         for (int i=0; i < labels.length; i++) {
00086             tmp[i] = labels[i];
00087         }
00088         tmp[labels.length] = m.getLabel();
00089         labels = tmp;
00090     }

void PopMenu::addSeparator   [inline]
 

00094     {
00095         pum.addSeparator();
00096 
00097         String[] tmp = new String[labels.length + 1];
00098         for (int i=0; i < labels.length; i++) {
00099             tmp[i] = labels[i];
00100         }
00101         tmp[labels.length] = "";
00102         labels = tmp;
00103     }

void PopMenu::insertSeparator int    index [inline]
 

00107     {
00108         if (index >= labels.length) {
00109             addSeparator();
00110         }
00111 
00112         JSeparator sep = new JSeparator();
00113         pum.insert(sep, index);
00114 
00115         String[] tmp = new String[labels.length + 1];
00116         for (int i=0; i < labels.length + 1; i++) {
00117             if (i < index) {
00118                 tmp[i] = labels[i];
00119             } else if (i == index) {
00120                 tmp[i] = "";
00121             } else {
00122                 tmp[i] = labels[i-1];
00123             }
00124         }
00125         labels = tmp;
00126     }

void PopMenu::setEnabled boolean    b,
String    label
[inline]
 

00130     {
00131         for (int i=0; i<labels.length; i++) {
00132             if (labels[i].equals(label)) {
00133                 pum.getComponentAtIndex(i).setEnabled(b);
00134                 return;
00135             }
00136         }
00137     }

void PopMenu::show int    x,
int    y
[inline]
 

00141     {
00142         parent.add(pum);
00143         pum.show(parent, x, y);
00144     }

void PopMenu::actionPerformed ActionEvent    event [inline]
 

00151     {
00152         ((ActionListener)parent).actionPerformed(event);
00153     }


The documentation for this class was generated from the following file:
Generated on Mon Jan 27 15:11:24 2003 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001