Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/java/com/google/scrollview/ui/SVPopupMenu.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.SVMenuItem; | |
| 15 import com.google.scrollview.ui.SVWindow; | |
| 16 | |
| 17 import java.awt.Component; | |
| 18 import java.awt.event.ActionEvent; | |
| 19 import java.awt.event.ActionListener; | |
| 20 import java.util.HashMap; | |
| 21 | |
| 22 import javax.swing.JMenu; | |
| 23 import javax.swing.JPopupMenu; | |
| 24 | |
| 25 /** | |
| 26 * The SVPopupMenu class provides the functionality to add a popup menu to | |
| 27 * ScrollView. Each popup menu item gets associated with a (client-defined) | |
| 28 * command-id, which SVPopupMenu will return upon clicking it. | |
| 29 * | |
| 30 * @author wanke@google.com | |
| 31 * | |
| 32 */ | |
| 33 | |
| 34 public class SVPopupMenu implements ActionListener { | |
| 35 /** The root entry to add items to. */ | |
| 36 private JPopupMenu root; | |
| 37 /** Contains a map of item name to its actual entry. */ | |
| 38 private HashMap<String, SVAbstractMenuItem> items; | |
| 39 /** The window the menubar belongs to. */ | |
| 40 private SVWindow svWindow; | |
| 41 | |
| 42 /** | |
| 43 * Create a new SVPopupMenu and associate it with a ScrollView window. | |
| 44 * | |
| 45 * @param sv The window our popup menu belongs to. | |
| 46 */ | |
| 47 SVPopupMenu(SVWindow sv) { | |
| 48 root = new JPopupMenu(); | |
| 49 svWindow = sv; | |
| 50 items = new HashMap<String, SVAbstractMenuItem>(); | |
| 51 } | |
| 52 | |
| 53 /** | |
| 54 * Add a new entry to the menubar. For these items, the server will poll the | |
| 55 * client to ask what to do. | |
| 56 * | |
| 57 * @param parent The menu we add our new entry to (should have been defined | |
| 58 * before). If the parent is "", we will add the entry to the root | |
| 59 * (top-level). | |
| 60 * @param name The caption of the new entry. | |
| 61 * @param id The Id of the new entry. If it is -1, the entry will be treated | |
| 62 * as a menu. | |
| 63 */ | |
| 64 public void add(String parent, String name, int id) { | |
| 65 // A duplicate entry - we just throw it away, since its already in. | |
| 66 if (items.get(name) != null) { return; } | |
| 67 // A new submenu at the top-level. | |
| 68 if (parent.equals("")) { | |
| 69 JMenu jli = new JMenu(name); | |
| 70 SVAbstractMenuItem mli = new SVSubMenuItem(name, jli); | |
| 71 items.put(name, mli); | |
| 72 root.add(jli); | |
| 73 } | |
| 74 // A new sub-submenu. | |
| 75 else if (id == -1) { | |
| 76 SVAbstractMenuItem jmi = items.get(parent); | |
| 77 JMenu jli = new JMenu(name); | |
| 78 SVAbstractMenuItem mli = new SVSubMenuItem(name, jli); | |
| 79 items.put(name, mli); | |
| 80 jmi.add(jli); | |
| 81 } | |
| 82 // A new child entry. Add to appropriate parent. | |
| 83 else { | |
| 84 SVAbstractMenuItem jmi = items.get(parent); | |
| 85 if (jmi == null) { | |
| 86 System.out.println("ERROR: Unknown parent " + parent); | |
| 87 System.exit(1); | |
| 88 } | |
| 89 SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name); | |
| 90 mli.mi.addActionListener(this); | |
| 91 items.put(name, mli); | |
| 92 jmi.add(mli); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 /** | |
| 97 * Add a new entry to the menubar. In this case, we also know its value and | |
| 98 * possibly even have a description. For these items, the server will not poll | |
| 99 * the client to ask what to do, but just show an input dialog and send a | |
| 100 * message with the new value. | |
| 101 * | |
| 102 * @param parent The menu we add our new entry to (should have been defined | |
| 103 * before). If the parent is "", we will add the entry to the root | |
| 104 * (top-level). | |
| 105 * @param name The caption of the new entry. | |
| 106 * @param id The Id of the new entry. If it is -1, the entry will be treated | |
| 107 * as a menu. | |
| 108 * @param value The value of the new entry. | |
| 109 * @param desc The description of the new entry. | |
| 110 */ | |
| 111 public void add(String parent, String name, int id, String value, String desc) { | |
| 112 SVAbstractMenuItem jmi = items.get(parent); | |
| 113 SVMenuItem mli = new SVMenuItem(id, name, value, desc); | |
| 114 mli.mi.addActionListener(this); | |
| 115 items.put(name, mli); | |
| 116 if (jmi == null) { // add to root | |
| 117 root.add(mli.mi); | |
| 118 } else { // add to parent | |
| 119 jmi.add(mli); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 | |
| 124 | |
| 125 /** | |
| 126 * A click on one of the items in our menubar has occurred. Forward it | |
| 127 * to the item itself to let it decide what happens. | |
| 128 */ | |
| 129 public void actionPerformed(ActionEvent e) { | |
| 130 | |
| 131 // Get the corresponding menuitem | |
| 132 SVAbstractMenuItem svm = items.get(e.getActionCommand()); | |
| 133 | |
| 134 svm.performAction(svWindow, SVEventType.SVET_POPUP); | |
| 135 } | |
| 136 | |
| 137 /** | |
| 138 * Gets called by the SVEventHandler of the window to actually show the | |
| 139 * content of the popup menu. | |
| 140 */ | |
| 141 public void show(Component Invoker, int x, int y) { | |
| 142 root.show(Invoker, x, y); | |
| 143 } | |
| 144 } |
