/** Display the forwards window history in a menu. */
  private void onShowForwardHistory() {

    UIScrollableMenu hist =
        new UIScrollableMenu(
            LanguageProperties.getString(
                LanguageProperties.TOOLBARS_BUNDLE, "UIToolBarMain.forwardHistory"),
            0); //$NON-NLS-1$

    Vector views = history.getForwardHistory();
    int currentIndex = history.getCurrentPosition();

    int count = views.size();
    if (count == 0) return;

    JMenuItem item = null;
    for (int i = 0; i < count; i++) {
      View view = (View) views.elementAt(i);
      item = new JMenuItem(view.getLabel());

      final View fview = view;
      final int fi = (currentIndex + 1) + i;
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              if (history.goToHistoryItem(fi)) oParent.addViewToDesktop(fview, fview.getLabel());
            }
          });

      hist.add(item);
    }

    JPopupMenu pop = hist.getPopupMenu();
    pop.pack();

    Point loc = pbShowForwardHistory.getLocation();
    Dimension size = pbShowForwardHistory.getSize();
    Dimension popsize = hist.getPreferredSize();
    Point finalP = SwingUtilities.convertPoint(tbrToolBar.getParent(), loc, oParent.getDesktop());

    int x = 0;
    int y = 0;
    if (oManager.getLeftToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x + size.width;
      y = finalP.y;
    } else if (oManager.getRightToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x - popsize.width;
      y = finalP.y;
    } else if (oManager.getTopToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x;
      y = finalP.y + size.width;
    } else if (oManager.getBottomToolBarController().containsBar(tbrToolBar)) {
      x = finalP.x;
      y = finalP.y - popsize.height;
    }

    hist.setPopupMenuVisible(true);
    pop.show(oParent.getDesktop(), x, y);
  }
    public void actionPerformed(ActionEvent event) {

      JMenuItem mi;
      String label = "";

      if (warningPopup == null) {
        warningPopup = new WarningDialog(textViewerFrame);
      }
      if ((editor1 == null) || (editor1.getDocument() == null)) {
        String errstr = "TextViewer:editor1 or document is null";
        warningPopup.display(errstr);
        return;
      }
      String actionStr = event.getActionCommand(); // is not makeing anysense
      // when keystrokes typed
      if ((event.getSource() instanceof JMenuItem)) {
        mi = (JMenuItem) event.getSource();
        label = mi.getText();
      } else if ((event.getSource() instanceof JTextArea)) { // keystroke
        label = "FindAgain"; // just set it to findagain
      } else {
        System.err.println("Debug:TextViewer:" + actionStr);
        System.err.println("Debug:TextViewer:" + event.getSource().toString());
        String errstr =
            "TextViewer:FindAction: "
                + event.getSource().toString()
                + " not an instance of JMenuItem or JTextArea";
        warningPopup.display(errstr);
        return;
      }

      if (label.equals("FindAgain")) {
        isFindAgain = true;
        lastFindStr = lastFindStr;
      } else {
        isFindAgain = false;
        lastFindStr = "";
      }
      StringBoolean content = new StringBoolean(lastFindStr, forwardFindDirection);

      boolean okPressed = mySearchDialog.display(content);
      if (!okPressed) {
        return;
      }
      lastFindStr = content.mystring;
      forwardFindDirection = content.myboolean;

      if (forwardFindDirection) {
        lastFindIndex = searchForward(lastFindStr);
        //		System.out.println("Debug:TextViewer: lastFindIndex:"+lastFindIndex);

      } else {
        lastFindIndex = searchBackward(lastFindStr);
        //		System.out.println("Debug:TextViewer: lastFindIndex:"+lastFindIndex);
      }
    }
Beispiel #3
0
 public void propertyChange(PropertyChangeEvent e) {
   String propertyName = e.getPropertyName();
   if (e.getPropertyName().equals(Action.NAME)) {
     String text = (String) e.getNewValue();
     menuItem.setText(text);
   } else if (propertyName.equals("enabled")) {
     Boolean enabledState = (Boolean) e.getNewValue();
     menuItem.setEnabled(enabledState.booleanValue());
   }
 }
 public void propertyChange(PropertyChangeEvent e) {
   String propertyName = e.getPropertyName();
   if (e.getPropertyName().equals(Action.NAME)) {
     String text = (String) e.getNewValue();
     menuItem.setText(text);
   } else if (propertyName.equals("enabled")) {
     // System.out.println("Debug:TextViewer: ActionChangedListener enabled");
     Boolean enabledState = (Boolean) e.getNewValue();
     menuItem.setEnabled(enabledState.booleanValue());
   }
 }
 /**
  * This is the hook through which all menu items are created. It registers the result with the
  * menuitem hashtable so that it can be fetched with getMenuItem().
  *
  * @see #getMenuItem
  */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getResourceString(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action myaction = getAction(astr); // if this is a known action
   if (myaction != null) {
     mi.addActionListener(myaction);
     myaction.addPropertyChangeListener(createActionChangeListener(mi));
     // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled());
     mi.setEnabled(myaction.isEnabled());
   } else {
     System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr);
     // causes the item to be greyed out
     mi.setEnabled(false);
   }
   menuItems.put(cmd, mi);
   return mi;
 }
Beispiel #6
0
 /** This is the hook through which all menu items are created. */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getProperty(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action a = getAction(astr);
   if (a != null) {
     mi.addActionListener(a);
     a.addPropertyChangeListener(createActionChangeListener(mi));
     mi.setEnabled(a.isEnabled());
   } else {
     mi.setEnabled(false);
   }
   return mi;
 }