예제 #1
0
 /**
  * @param findMode mode to be found
  * @return true if given mode is present in this toolbar
  */
 public boolean containsMode(int findMode) {
   Vector<ToolbarItem> toolbarVec;
   if (dockPanel != null) {
     toolbarVec = ToolBar.parseToolbarString(dockPanel.getToolbarString());
   } else {
     toolbarVec =
         ToolBar.parseToolbarString(((GuiManagerD) app.getGuiManager()).getToolbarDefinition());
   }
   for (int i = 0; i < toolbarVec.size(); i++) {
     ToolbarItem item = toolbarVec.get(i);
     if (item.getMode() != null && item.getMode() == findMode) return true;
     if (item.getMenu() != null) {
       for (Integer m : item.getMenu()) {
         if (m == findMode) return true;
       }
     }
   }
   return false;
 }
예제 #2
0
  /**
   * Adds the given modes to a two-dimensional toolbar. The toolbar definition string looks like "0
   * , 1 2 | 3 4 5 || 7 8 9" where the int values are mode numbers, "," adds a separator within a
   * menu, "|" starts a new menu and "||" adds a separator before starting a new menu.
   *
   * @param modes
   * @param tb
   * @param bg
   */
  private void addCustomModesToToolbar(ModeToggleButtonGroup bg) {
    Vector<ToolbarItem> toolbarVec;
    try {
      if (dockPanel != null) {
        toolbarVec = ToolBar.parseToolbarString(dockPanel.getToolbarString());
      } else {
        toolbarVec =
            ToolBar.parseToolbarString(((GuiManagerD) app.getGuiManager()).getToolbarDefinition());
      }
    } catch (Exception e) {
      if (dockPanel != null) {
        App.debug("invalid toolbar string: " + dockPanel.getToolbarString());
      } else {
        App.debug(
            "invalid toolbar string: "
                + ((GuiManagerD) app.getGuiManager()).getToolbarDefinition());
      }
      toolbarVec = ToolBar.parseToolbarString(getDefaultToolbarString());
    }

    // set toolbar
    boolean firstButton = true;

    // make the loop go backwards for eg Hebrew / Arabic
    int first = app.isRightToLeftReadingOrder() ? toolbarVec.size() - 1 : 0;
    int increment = app.isRightToLeftReadingOrder() ? -1 : 1;

    // for (int i = 0; i < toolbarVec.size(); i++) {
    for (int i = first; i >= 0 && i < toolbarVec.size(); i += increment) {
      ToolbarItem ob = toolbarVec.get(i);

      // separator between menus
      if (ob.getMode() == ToolBar.SEPARATOR) {
        addSeparator();
        continue;
      }

      // new menu
      Vector<Integer> menu = ob.getMenu();
      ModeToggleMenu tm = new ModeToggleMenu(app, this, bg);
      modeToggleMenus.add(tm);

      for (int k = 0; k < menu.size(); k++) {
        // separator
        int addMode = menu.get(k).intValue();
        if (addMode < 0) {
          // separator within menu:
          tm.addSeparator();
        } else { // standard case: add mode

          // check mode
          if (!"".equals(app.getToolName(addMode))) {
            tm.addMode(addMode);
            if (i == 0 && firstButton) {
              tm.getJToggleButton().setSelected(true);
              firstButton = false;
            }
          }
        }
      }

      if (tm.getToolsCount() > 0) add(tm);
    }
  }