~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to javax/swing/MenuSelectionManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
216
216
  public boolean isComponentPartOfCurrentMenu(Component c)
217
217
  {
218
218
    MenuElement[] subElements;
219
 
      for (int i = 0; i < selectedPath.size(); i++)
 
219
    boolean ret = false;
 
220
    for (int i = 0; i < selectedPath.size(); i++)
220
221
      {
221
 
         subElements = ((MenuElement) selectedPath.get(i)).getSubElements();
222
 
         for (int j = 0; j < subElements.length; j++)
223
 
         {
224
 
            MenuElement me = subElements[j]; 
225
 
            if (me != null && (me.getComponent()).equals(c))
226
 
               return true;
227
 
         }
 
222
        // Check first element.
 
223
        MenuElement first = (MenuElement) selectedPath.get(i);
 
224
        if (SwingUtilities.isDescendingFrom(c, first.getComponent()))
 
225
          {
 
226
            ret = true;
 
227
            break;
 
228
          }
 
229
        else
 
230
          {
 
231
            // Check sub elements.
 
232
            subElements = first.getSubElements();
 
233
            for (int j = 0; j < subElements.length; j++)
 
234
              {
 
235
                MenuElement me = subElements[j]; 
 
236
                if (me != null
 
237
                    && (SwingUtilities.isDescendingFrom(c, me.getComponent())))
 
238
                  {
 
239
                    ret = true;
 
240
                    break;
 
241
                  }
 
242
              }
 
243
          }
228
244
      }
229
245
 
230
 
      return false;
 
246
      return ret;
231
247
  }
232
248
 
233
249
  /**
234
 
   * DOCUMENT ME!
 
250
   * Processes key events on behalf of the MenuElements. MenuElement
 
251
   * instances should always forward their key events to this method and
 
252
   * get their {@link MenuElement#processKeyEvent(KeyEvent, MenuElement[],
 
253
   * MenuSelectionManager)} eventually called back.
235
254
   *
236
 
   * @param e DOCUMENT ME!
 
255
   * @param e the key event
237
256
   */
238
257
  public void processKeyEvent(KeyEvent e)
239
258
  {
240
 
    throw new UnsupportedOperationException("not implemented");
 
259
    MenuElement[] selection = (MenuElement[])
 
260
                    selectedPath.toArray(new MenuElement[selectedPath.size()]);
 
261
    MenuElement[] path;
 
262
    for (int index = selection.length - 1; index >= 0; index--)
 
263
      {
 
264
        MenuElement el = selection[index];
 
265
        // This method's main purpose is to forward key events to the
 
266
        // relevant menu items, so that they can act in response to their
 
267
        // mnemonics beeing typed. So we also need to forward the key event
 
268
        // to all the subelements of the currently selected menu elements
 
269
        // in the path.
 
270
        MenuElement[] subEls = el.getSubElements();
 
271
        path = null;
 
272
        for (int subIndex = 0; subIndex < subEls.length; subIndex++)
 
273
          {
 
274
            MenuElement sub = subEls[subIndex];
 
275
            // Skip elements that are not showing or not enabled.
 
276
            if (sub == null || ! sub.getComponent().isShowing()
 
277
                || ! sub.getComponent().isEnabled())
 
278
              {
 
279
                continue;
 
280
              }
 
281
 
 
282
            if (path == null)
 
283
              {
 
284
                path = new MenuElement[index + 2];
 
285
                System.arraycopy(selection, 0, path, 0, index + 1);
 
286
              }
 
287
            path[index + 1] = sub;
 
288
            sub.processKeyEvent(e, path, this);
 
289
            if (e.isConsumed())
 
290
              break;
 
291
          }
 
292
        if (e.isConsumed())
 
293
          break;
 
294
      }
 
295
 
 
296
    // Dispatch to first element in selection if it hasn't been consumed.
 
297
    if (! e.isConsumed())
 
298
      {
 
299
        path = new MenuElement[1];
 
300
        path[0] = selection[0];
 
301
        path[0].processKeyEvent(e, path, this);
 
302
      }
241
303
  }
242
304
 
243
305
  /**
303
365
        return;
304
366
      }
305
367
 
306
 
    int i;
307
 
    int minSize = path.length; // size of the smaller path. 
308
 
 
309
 
    if (path.length > selectedPath.size())
310
 
      {
311
 
        minSize = selectedPath.size();
312
 
 
313
 
        // if new selected path contains more elements then current
314
 
        // selection then first add all elements at 
315
 
        // the indexes > selectedPath.size 
316
 
        for (i = selectedPath.size(); i < path.length; i++)
317
 
          {
318
 
            selectedPath.add(path[i]);
319
 
            path[i].menuSelectionChanged(true);
320
 
          }
321
 
      }
322
 
 
323
 
    else if (path.length < selectedPath.size())
324
 
      {
325
 
        // if new selected path contains less elements then current 
326
 
        // selection then first remove all elements from the selection
327
 
        // at the indexes > path.length
328
 
        for (i = selectedPath.size() - 1; i >= path.length; i--)
329
 
          {
330
 
            ((MenuElement) selectedPath.get(i)).menuSelectionChanged(false);
331
 
            selectedPath.remove(i);
332
 
          }
333
 
 
334
 
        minSize = path.length;
335
 
      }
336
 
 
337
 
    // Now compare elements in new and current selection path at the 
338
 
    // same location and adjust selection until 
339
 
    // same menu elements will be encountered at the
340
 
    // same index in both current and new selection path.
341
 
    MenuElement oldSelectedItem;
342
 
 
343
 
    for (i = minSize - 1; i >= 0; i--)
344
 
      {
345
 
        oldSelectedItem = (MenuElement) selectedPath.get(i);
346
 
 
347
 
        if (path[i].equals(oldSelectedItem))
348
 
          break;
349
 
 
350
 
        oldSelectedItem.menuSelectionChanged(false);
351
 
        path[i].menuSelectionChanged(true);
352
 
        selectedPath.setElementAt(path[i], i);
 
368
    int minSize = path.length; // size of the smaller path.
 
369
    int currentSize = selectedPath.size();
 
370
    int firstDiff = 0;
 
371
 
 
372
    // Search first item that is different in the current and new path.
 
373
    for (int i = 0; i < minSize; i++)
 
374
      {
 
375
        if (i < currentSize && (MenuElement) selectedPath.get(i) == path[i])
 
376
          firstDiff++;
 
377
        else
 
378
          break;
 
379
      }
 
380
 
 
381
    // Remove items from selection and send notification.
 
382
    for (int i = currentSize - 1; i >= firstDiff; i--)
 
383
      {
 
384
        MenuElement el = (MenuElement) selectedPath.get(i);
 
385
        selectedPath.remove(i);
 
386
        el.menuSelectionChanged(false);
 
387
      }
 
388
 
 
389
    // Add new items to selection and send notification.
 
390
    for (int i = firstDiff; i < minSize; i++)
 
391
      {
 
392
        if (path[i] != null)
 
393
          {
 
394
            selectedPath.add(path[i]);
 
395
            path[i].menuSelectionChanged(true);
 
396
          }
353
397
      }
354
398
 
355
399
    fireStateChanged();