tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/java/com/google/scrollview/ui/SVMenuBar.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.SVWindow;
00015 
00016 import java.awt.event.ActionEvent;
00017 import java.awt.event.ActionListener;
00018 import java.util.HashMap;
00019 
00020 import javax.swing.JMenu;
00021 import javax.swing.JMenuBar;
00022 
00031 public class SVMenuBar implements ActionListener {
00033   private JMenuBar root;
00035   private HashMap<String, SVAbstractMenuItem> items;
00037   private SVWindow svWindow;
00038 
00044   public SVMenuBar(SVWindow scrollView) {
00045     root = new JMenuBar();
00046     svWindow = scrollView;
00047     items = new HashMap<String, SVAbstractMenuItem>();
00048     svWindow.setJMenuBar(root);
00049   }
00050 
00051 
00056   public void actionPerformed(ActionEvent e) {
00057     // Get the corresponding menuitem.
00058     SVAbstractMenuItem svm = items.get(e.getActionCommand());
00059 
00060     svm.performAction(svWindow, SVEventType.SVET_MENU);
00061   }
00062 
00073   public void add(String parent, String name, int id) {
00074     // A duplicate entry - we just throw it away, since its already in.
00075     if (items.get(name) != null) { return; }
00076     // A new submenu at the top-level
00077     if (parent.equals("")) {
00078       JMenu jli = new JMenu(name);
00079       SVAbstractMenuItem mli = new SVSubMenuItem(name, jli);
00080       items.put(name, mli);
00081       root.add(jli);
00082     }
00083     // A new sub-submenu
00084     else if (id == -1) {
00085       SVAbstractMenuItem jmi = items.get(parent);
00086       JMenu jli = new JMenu(name);
00087       SVAbstractMenuItem mli = new SVSubMenuItem(name, jli);
00088       items.put(name, mli);
00089       jmi.add(jli);
00090     }
00091     // A new child entry. Add to appropriate parent.
00092     else {
00093       SVAbstractMenuItem jmi = items.get(parent);
00094       if (jmi == null) {
00095         System.out.println("ERROR: Unknown parent " + parent);
00096         System.exit(1);
00097       }
00098       SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name);
00099       mli.mi.addActionListener(this);
00100       items.put(name, mli);
00101       jmi.add(mli);
00102     }
00103   }
00104 
00118   public void add(String parent, String name, int id, boolean b) {
00119     SVAbstractMenuItem jmi = items.get(parent);
00120     if (jmi == null) {
00121       System.out.println("ERROR: Unknown parent " + parent);
00122       System.exit(1);
00123     }
00124     SVAbstractMenuItem mli = new SVCheckboxMenuItem(id, name, b);
00125     mli.mi.addActionListener(this);
00126     items.put(name, mli);
00127     jmi.add(mli);
00128   }
00129 
00130 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines