tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/java/com/google/scrollview/ui/SVPopupMenu.java
Go to the documentation of this file.
00001 // Copyright 2007 Google Inc. All Rights Reserved.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License"); You may not
00004 // use this file except in compliance with the License. You may obtain a copy of
00005 // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
00006 // applicable law or agreed to in writing, software distributed under the
00007 // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
00008 // OF ANY KIND, either express or implied. See the License for the specific
00009 // language governing permissions and limitations under the License.
00010 
00011 package com.google.scrollview.ui;
00012 
00013 import com.google.scrollview.events.SVEventType;
00014 import com.google.scrollview.ui.SVMenuItem;
00015 import com.google.scrollview.ui.SVWindow;
00016 
00017 import java.awt.Component;
00018 import java.awt.event.ActionEvent;
00019 import java.awt.event.ActionListener;
00020 import java.util.HashMap;
00021 
00022 import javax.swing.JMenu;
00023 import javax.swing.JPopupMenu;
00024 
00034 public class SVPopupMenu implements ActionListener {
00036   private JPopupMenu root;
00038   private HashMap<String, SVAbstractMenuItem> items;
00040   private SVWindow svWindow;
00041 
00047   SVPopupMenu(SVWindow sv) {
00048     root = new JPopupMenu();
00049     svWindow = sv;
00050     items = new HashMap<String, SVAbstractMenuItem>();
00051   }
00052 
00064   public void add(String parent, String name, int id) {
00065     // A duplicate entry - we just throw it away, since its already in.
00066     if (items.get(name) != null) { return; }
00067     // A new submenu at the top-level
00068     if (parent.equals("")) {
00069       JMenu jli = new JMenu(name);
00070       SVAbstractMenuItem mli = new SVSubMenuItem(name, jli);
00071       items.put(name, mli);
00072       root.add(jli);
00073     }
00074     // A new sub-submenu
00075     else if (id == -1) {
00076       SVAbstractMenuItem jmi = items.get(parent);
00077       JMenu jli = new JMenu(name);
00078       SVAbstractMenuItem mli = new SVSubMenuItem(name, jli);
00079       items.put(name, mli);
00080       jmi.add(jli);
00081     }
00082     // A new child entry. Add to appropriate parent.
00083     else {
00084       SVAbstractMenuItem jmi = items.get(parent);
00085       if (jmi == null) {
00086         System.out.println("ERROR: Unknown parent " + parent);
00087         System.exit(1);
00088       }
00089       SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name);
00090       mli.mi.addActionListener(this);
00091       items.put(name, mli);
00092       jmi.add(mli);
00093     }
00094   }
00095 
00111   public void add(String parent, String name, int id, String value, String desc) {
00112     SVAbstractMenuItem jmi = items.get(parent);
00113     SVMenuItem mli = new SVMenuItem(id, name, value, desc);
00114     mli.mi.addActionListener(this);
00115     items.put(name, mli);
00116     if (jmi == null) { // add to root
00117       root.add(mli.mi);
00118     } else { // add to parent
00119       jmi.add(mli);
00120     }
00121   }
00122 
00123 
00124 
00129   public void actionPerformed(ActionEvent e) {
00130 
00131     // Get the corresponding menuitem
00132     SVAbstractMenuItem svm = items.get(e.getActionCommand());
00133 
00134    svm.performAction(svWindow, SVEventType.SVET_POPUP);
00135   }
00136 
00141   public void show(Component Invoker, int x, int y) {
00142     root.show(Invoker, x, y);
00143   }
00144 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines