comparison mupdf-source/thirdparty/tesseract/java/com/google/scrollview/ui/SVMenuBar.java @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright 2007 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); You may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
6 // applicable law or agreed to in writing, software distributed under the
7 // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
8 // OF ANY KIND, either express or implied. See the License for the specific
9 // language governing permissions and limitations under the License.
10
11 package com.google.scrollview.ui;
12
13 import com.google.scrollview.events.SVEventType;
14 import com.google.scrollview.ui.SVWindow;
15
16 import java.awt.event.ActionEvent;
17 import java.awt.event.ActionListener;
18 import java.util.HashMap;
19
20 import javax.swing.JMenu;
21 import javax.swing.JMenuBar;
22
23 /**
24 * The SVMenuBar class provides the functionality to add a menubar to
25 * ScrollView. Each menubar item gets associated with a (client-defined)
26 * command-id, which SVMenuBar will return upon clicking it.
27 *
28 * @author wanke@google.com
29 *
30 */
31 public class SVMenuBar implements ActionListener {
32 /** The root entry to add items to. */
33 private JMenuBar root;
34 /** Contains a map of item name to its actual entry. */
35 private HashMap<String, SVAbstractMenuItem> items;
36 /** The window the menubar belongs to. */
37 private SVWindow svWindow;
38
39 /**
40 * Create a new SVMenuBar and place it at the top of the ScrollView window.
41 *
42 * @param scrollView The window our menubar belongs to.
43 */
44 public SVMenuBar(SVWindow scrollView) {
45 root = new JMenuBar();
46 svWindow = scrollView;
47 items = new HashMap<String, SVAbstractMenuItem>();
48 svWindow.setJMenuBar(root);
49 }
50
51
52 /**
53 * A click on one of the items in our menubar has occurred. Forward it
54 * to the item itself to let it decide what happens.
55 */
56 public void actionPerformed(ActionEvent e) {
57 // Get the corresponding menuitem.
58 SVAbstractMenuItem svm = items.get(e.getActionCommand());
59
60 svm.performAction(svWindow, SVEventType.SVET_MENU);
61 }
62
63 /**
64 * Add a new entry to the menubar.
65 *
66 * @param parent The menu we add our new entry to (should have been defined
67 * before). If the parent is "", we will add the entry to the root
68 * (top-level)
69 * @param name The caption of the new entry.
70 * @param id The Id of the new entry. If it is -1, the entry will be treated
71 * as a menu.
72 */
73 public void add(String parent, String name, int id) {
74 // A duplicate entry - we just throw it away, since its already in.
75 if (items.get(name) != null) { return; }
76 // A new submenu at the top-level
77 if (parent.equals("")) {
78 JMenu jli = new JMenu(name);
79 SVAbstractMenuItem mli = new SVSubMenuItem(name, jli);
80 items.put(name, mli);
81 root.add(jli);
82 }
83 // A new sub-submenu
84 else if (id == -1) {
85 SVAbstractMenuItem jmi = items.get(parent);
86 JMenu jli = new JMenu(name);
87 SVAbstractMenuItem mli = new SVSubMenuItem(name, jli);
88 items.put(name, mli);
89 jmi.add(jli);
90 }
91 // A new child entry. Add to appropriate parent.
92 else {
93 SVAbstractMenuItem jmi = items.get(parent);
94 if (jmi == null) {
95 System.out.println("ERROR: Unknown parent " + parent);
96 System.exit(1);
97 }
98 SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name);
99 mli.mi.addActionListener(this);
100 items.put(name, mli);
101 jmi.add(mli);
102 }
103 }
104
105 /**
106 * Add a new checkbox entry to the menubar.
107 *
108 * @param parent The menu we add our new entry to (should have been defined
109 * before). If the parent is "", we will add the entry to the root
110 * (top-level)
111 * @param name The caption of the new entry.
112 * @param id The Id of the new entry. If it is -1, the entry will be treated
113 * as a menu.
114 * @param b Whether the entry is initially flagged.
115 *
116 */
117
118 public void add(String parent, String name, int id, boolean b) {
119 SVAbstractMenuItem jmi = items.get(parent);
120 if (jmi == null) {
121 System.out.println("ERROR: Unknown parent " + parent);
122 System.exit(1);
123 }
124 SVAbstractMenuItem mli = new SVCheckboxMenuItem(id, name, b);
125 mli.mi.addActionListener(this);
126 items.put(name, mli);
127 jmi.add(mli);
128 }
129
130 }