Пример #1
0
  /**
   * Set the content and visibility of menu items and menu separator, based on the recent file
   * stored user preferences.
   */
  private static void updateMenuItems(List<JComponent> menuItems) {
    // Assume no recent files
    boolean someRecentFiles = false;
    // Update the menu items
    for (int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) {
      // Get the menu item
      JMenuItem recentFile = (JMenuItem) menuItems.get(i);

      // Find and set the file for this recent file command
      String recentFilePath = getRecentFile(i);
      if (recentFilePath != null) {
        File file = new File(recentFilePath);
        StringBuilder sb = new StringBuilder(60);
        if (i < 9) {
          sb.append(i + 1).append(" "); // $NON-NLS-1$
        }
        sb.append(getMenuItemDisplayName(file));
        recentFile.setText(sb.toString());
        recentFile.setToolTipText(recentFilePath);
        recentFile.setEnabled(true);
        recentFile.setVisible(true);
        // At least one recent file menu item is visible
        someRecentFiles = true;
      } else {
        recentFile.setEnabled(false);
        recentFile.setVisible(false);
      }
    }
    // If there are some recent files, we must make the separator visisble
    // The separator is the last item in the list
    JSeparator separator = (JSeparator) menuItems.get(menuItems.size() - 1);
    separator.setVisible(someRecentFiles);
  }
Пример #2
0
  public void setClickable(boolean isClickable) {
    this.isClickable = isClickable;

    if (!isClickable) {
      menuSelect.setVisible(false);
      menuDeselect.setVisible(false);
    }
  }
Пример #3
0
  public ConnectionForm() {
    setContentPane(contentPane);
    setModal(true);
    getRootPane().setDefaultButton(buttonOK);

    JMenuBar menuBar = new JMenuBar();
    menuBar.setVisible(true);

    JMenu menu = new JMenu("Menu");
    menu.setVisible(true);

    JMenuItem statementItem = new JMenuItem("SQL Insert");
    statementItem.setVisible(true);
    statementItem.addActionListener(new SQLImportActionListener());
    statementItem.setEnabled(false);

    JMenuItem importItem = new JMenuItem("Files Import");
    importItem.setEnabled(false);
    importItem.setVisible(true);

    menu.add(statementItem);
    menu.add(importItem);
    menuBar.add(menu);
    setJMenuBar(menuBar);

    buttonOK.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
            int result = fileChooser.showOpenDialog(getParent());
          }
        });

    dbField.addMouseListener(new DBFileMouseListener(getParent()));
    filesField.addMouseListener(new SQLFilesMouseListener(getParent()));

    // call onCancel() when cross is clicked
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            onCancel();
          }
        });

    // call onCancel() on ESCAPE
    contentPane.registerKeyboardAction(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            onCancel();
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
  }
  //    private URI[] getSelectedUriArray() {
  //        URI[] selectedUriArray = new URI[selectedIdentifiers.length];
  //        for (int currentIndex = 0; currentIndex < selectedIdentifiers.length; currentIndex++) {
  //            try {
  //                selectedUriArray[currentIndex] = new
  // URI(graphPanel.getPathForElementId(selectedIdentifiers[currentIndex]));
  //            } catch (URISyntaxException ex) {
  //                bugCatcher.logError(ex);
  //                // todo: warn user with a dialog
  //            }
  //        }
  //        return selectedUriArray;
  //    }
  @Override
  public void show(Component cmpnt, int i, int i1) {
    eventLocation = new Point(i, i1);
    //        System.out.println("ContextMenu: " + i + ":" + i1);
    selectedIdentifiers = graphPanel.getSelectedIds();
    int nonTransientNodeCount = 0;
    int transientNodeCount = 0;
    int graphicsIdentifierCount = 0;
    for (UniqueIdentifier uniqueIdentifier : selectedIdentifiers) {
      // check to see if these selectedIdentifiers are transent nodes and if they are then do not
      // allow the following menu items
      if (uniqueIdentifier.isGraphicsIdentifier()) {
        graphicsIdentifierCount++;
      } else if (uniqueIdentifier.isTransientIdentifier()) {
        transientNodeCount++;
      } else {
        nonTransientNodeCount++;
      }
    }
    boolean showNonTransientMenus;
    if (graphPanel.dataStoreSvg.diagramMode != DiagramMode.FreeForm) {
      duplicateEntitiesMenu.setEnabled(nonTransientNodeCount > 0);
      removeRelationEntityMenu.setEnabled(nonTransientNodeCount > 1);
      mergeEntitiesMenu.setEnabled(nonTransientNodeCount > 1);
      addRelationEntityMenu.setEnabled(nonTransientNodeCount > 1);
      setAsEgoMenuItem.setEnabled(nonTransientNodeCount > 0);
      addAsEgoMenuItem.setEnabled(nonTransientNodeCount > 0);
      removeEgoMenuItem.setEnabled(
          nonTransientNodeCount
              > 0); // todo: set these items based on the state of the selected entities,
                    // //graphPanel.selectionContainsEgo());
      addAsRequiredMenuItem.setEnabled(nonTransientNodeCount > 0);
      removeRequiredMenuItem.setEnabled(nonTransientNodeCount > 0);
      showNonTransientMenus = true;
    } else {
      showNonTransientMenus = false;
    }
    // hide/show the menus based on the diagram type
    removeRelationEntityMenu.setVisible(showNonTransientMenus);
    mergeEntitiesMenu.setVisible(showNonTransientMenus);
    duplicateEntitiesMenu.setVisible(showNonTransientMenus);
    addRelationEntityMenu.setVisible(showNonTransientMenus);
    setAsEgoMenuItem.setVisible(showNonTransientMenus);
    addAsEgoMenuItem.setVisible(showNonTransientMenus);
    removeEgoMenuItem.setVisible(showNonTransientMenus);
    addAsRequiredMenuItem.setVisible(showNonTransientMenus);
    removeRequiredMenuItem.setVisible(showNonTransientMenus);
    addEntityMenu.setVisible(showNonTransientMenus);
    jSeparator2.setVisible(showNonTransientMenus);
    jSeparator3.setVisible(showNonTransientMenus);

    deleteMenu.setEnabled(
        nonTransientNodeCount + graphicsIdentifierCount > 0 && transientNodeCount == 0);
    saveFileMenuItem.setEnabled(dataNodeLoader.nodesNeedSave());

    super.show(cmpnt, i, i1);
  }
  /**
   * When timerUp is started it calls constantly this method to make the JMenu scroll upwards. When
   * the top of menu is reached then upButton is set invisible. When scrollUp starts downButton is
   * setVisible.
   */
  private void scrollUp() {
    closeOpenedSubMenus();

    if (indexVisible == 0) {
      upButton.setVisible(false);

      return;
    } else {
      indexVisible--;
      ((JComponent) subMenus.get(indexVisible + visibleItems)).setVisible(false);
      ((JComponent) subMenus.get(indexVisible)).setVisible(true);
      downButton.setVisible(true);
      if (indexVisible == 0) {
        upButton.setVisible(false);
      }
    }
  }
Пример #6
0
  @Override
  public void setVisible(boolean visible) {
    super.setVisible(visible);

    if (menuItem != null) {
      menuItem.setVisible(visible);
    }
  }
 /**
  * Adds a new attachment.
  *
  * @param file The attachment to add.
  */
 public void addAttachment(FileAnnotationData file) {
   long userID = MetadataViewerAgent.getUserDetails().getId();
   if (time == null) {
     time = file.getLastModified();
     resultsButton.setToolTipText("Analysis run " + UIUtilities.formatTime(time));
   }
   if (file.getOwner().getId() == userID) deleteButton.setVisible(true);
   if (!attachments.contains(file)) attachments.add(file);
 }
Пример #8
0
  /**
   * Enables or disables the various buttons depending on the passed value. Returns <code>true
   * </code> if some controls are visible, <code>false</code> otherwise.
   *
   * @param enabled Pass <code>true</code> to enable the controls, <code>false</code> otherwise.
   * @return See above.
   */
  private boolean setControlsEnabled(boolean enabled) {
    int count = 0;
    if (infoButton != null) {
      infoButton.setEnabled(true);
      infoButton.setVisible(true);
      count++;
    }
    if (!enabled) {
      if (unlinkButton != null) {
        unlinkButton.setEnabled(false);
        unlinkButton.setVisible(false);
      }
      if (editButton != null) {
        editButton.setEnabled(false);
        editButton.setVisible(false);
      }
      if (downloadButton != null) {
        downloadButton.setEnabled(false);
        downloadButton.setVisible(false);
      }
      return count > 0;
    }
    boolean b = false;
    if (unlinkButton != null) {
      b = model.canDeleteLink(data);
      if (b && isModulo) { // check if it is a modulo annotation. Do not remove.
        b = false;
      }
      unlinkButton.setEnabled(b);
      unlinkButton.setVisible(b);
      if (b) count++;
    }

    if (editButton != null) {
      b = model.canEdit(data);
      editButton.setEnabled(b);
      editButton.setVisible(b);
      if (b) count++;
    }
    if (downloadButton != null) {
      b = true;
      downloadButton.setEnabled(b);
      downloadButton.setVisible(b);
      if (b) count++;
    }
    if (openButton != null) {
      b = true;
      openButton.setEnabled(b);
      openButton.setVisible(b);
      if (b) count++;
    }
    return count > 0;
  }
    public MenuCentral(JMenu mnu, ControleurPanneaux cp) {
      _mnu = mnu;
      mnu.addMenuListener(
          new MenuListener() {
            public void menuSelected(MenuEvent e) {
              majContenuMenu();
            }

            public void menuDeselected(MenuEvent e) {}

            public void menuCanceled(MenuEvent e) {}
          });
      lnkControleurPanneaux = cp;
      jMenuAjouterContenu.setText(
          lnkSysteme.lnkFenetrePrincipale.getLnkLangues().valeurDe("ajoutercontenu"));
      jMenuChangerContenu.setText(
          lnkSysteme.lnkFenetrePrincipale.getLnkLangues().valeurDe("changerdecontenu"));
      jMenuSupprimerContenu.setText(
          lnkSysteme.lnkFenetrePrincipale.getLnkLangues().valeurDe("supprimercontenu"));
      jMenuAjouterGuide.setText(
          lnkSysteme.lnkFenetrePrincipale.getLnkLangues().valeurDe("ajouterguide"));
      jMenuSupprimer.setText(lnkSysteme.lnkFenetrePrincipale.getLnkLangues().valeurDe("supprimer"));

      jMenuAjouterContenu.setVisible(false);
      jMenuChangerContenu.setVisible(false);
      jMenuAjouterGuide.setVisible(false);
      jMenuSupprimerContenu.setVisible(false);
      jMenuSupprimer.setVisible(false);

      jMenuAjouterContenu.addActionListener(this);
      jMenuChangerContenu.addActionListener(this);
      jMenuAjouterGuide.addActionListener(this);
      jMenuSupprimerContenu.addActionListener(this);
      jMenuSupprimer.addActionListener(this);

      _mnu.add(jMenuAjouterContenu);
      _mnu.add(jMenuChangerContenu);
      _mnu.add(jMenuSupprimerContenu);
      _mnu.add(jMenuAjouterGuide);
      _mnu.add(jMenuSupprimer);
    }
Пример #10
0
  public CardLabel(ImageList list, ApplicationLogic appLogic) {
    this.list = list;
    isOnTable = false;
    isClickable = true;
    menu = new JPopupMenu();
    setComponentPopupMenu(menu);

    menuSelect = new JMenuItem("Select");
    menuDeselect = new JMenuItem("Deselect");

    menuDeselect.setVisible(false);

    menuSelect.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            if (isClickable) {
              if (isOnTable) {
                appLogic.addTableCardID(id);
              } else {
                appLogic.setHandCardID(id);
              }
              // System.out.println("Du har markerat ett kort med ID: " + id);
              menuSelect.setVisible(false);
              menuDeselect.setVisible(true);
            }
          }
        });

    menuDeselect.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            if (isOnTable) {
              appLogic.removeTableCardID(id);
            } else {
              appLogic.removeHandCardID();
            }
            // System.out.println("Du avmarkerade ett kort med ID: " + id);
            menuDeselect.setVisible(false);
            menuSelect.setVisible(true);
          }
        });

    menu.add(menuSelect);
    menu.add(menuDeselect);
  }
  /**
   * When timerDown is started it calls constantly this method to make the JMenu scroll downwards.
   * When the bottom of menu is reached then downButton is set invisible. When scrolldown starts
   * upButton is setVisible.
   */
  private void scrollDown() {
    closeOpenedSubMenus();

    if ((indexVisible + visibleItems) == subMenus.size()) {
      downButton.setVisible(false);

      return;
    } else if ((indexVisible + visibleItems) > subMenus.size()) {
      return;
    } else {
      try {
        ((JComponent) subMenus.get(indexVisible)).setVisible(false);
        ((JComponent) subMenus.get(indexVisible + visibleItems)).setVisible(true);
        upButton.setVisible(true);
        indexVisible++;
        if ((indexVisible + visibleItems) == subMenus.size()) {
          downButton.setVisible(false);
        }
      } catch (Exception eks) {
        eks.printStackTrace();
      }
    }
  }
  /**
   * JMenu's add-method is override to keep track of the added items. If there are more items that
   * JMenu can display, then the added menuitems will be invisible.
   *
   * @param menuItem to be added
   * @return added menuitem
   */
  public Component add(Component menuItem) {
    add(menuItem, subMenus.size() + 1);
    subMenus.add(menuItem);

    menuHeight += menuItem.getPreferredSize().getHeight();

    if (menuHeight > screenHeight) {
      menuItem.setVisible(false);
      downButton.setVisible(true);
    } else {
      visibleItems++;
    }

    return menuItem;
  }
Пример #13
0
  public void updateMkMenu(List<MkMenu> listMenu) {

    HashMap<MkMenu, JMenuItem> listMenuItem = new HashMap<MkMenu, JMenuItem>();

    JMenuBar menuPrincipal = new JMenuBar();
    for (MkMenu mkMenu : listMenu) {
      if (listMenuItem.containsKey(mkMenu.getClass())) {
        throw new IllegalArgumentException("Item duplicado: " + mkMenu.getClass());
      }

      JMenuItem menu;
      if (mkMenu.getPai() == null) {
        menu = new JMenu();
        menu.setMnemonic(mkMenu.getTitulo().charAt(0));
        menuPrincipal.add(menu);
      } else {
        final MkRun acao = mkMenu.getAcao();
        if (acao == null) {
          menu = new JMenu();
        } else {
          menu = new JMenuItem();
          menu.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  acao.execute();
                }
              });
        }

        JMenu menuPai = (JMenu) listMenuItem.get(mkMenu.getPai());
        menuPai.add(menu);
        menu.setVisible(mkMenu.isVisivel());
        if (mkMenu.hasSeparador()) {
          menuPai.addSeparator();
        }
      }

      menu.setText(mkMenu.getTitulo());

      listMenuItem.put(mkMenu, menu);
    }

    this.setJMenuBar(menuPrincipal);
  }
Пример #14
0
    public void show(Component invoker, int x, int y) {
      ViperViewMediator mediator = getMediator();
      Point pnt = new Point(x, y);
      EnhancedTable tab = getTable();
      int row = tab.rowAtPoint(pnt);
      desc = getCurrentModel().getDescriptorAtRow(row);
      int col = tab.columnAtPoint(pnt);
      Object cellValue = tab.getValueAt(row, col);
      if (cellValue instanceof Attribute) {
        attr = (Attribute) cellValue;

        // hide the "Occlusions..." option when we're not dealing with a Textline object
        boolean isTextline = attr.getAttrConfig().getAttrType().endsWith("textline");
        occlusions.setVisible(isTextline);
        occSeparator.setVisible(isTextline);

        Instant now = mediator.getCurrentFrame();
        if (now == null) {
          mediator.getDisplayWRTManager().setAttribute(null, null);
          wrt.setEnabled(false);
          wrt.setSelected(false);
        } else {
          boolean isDwrt = attr == mediator.getDisplayWRTManager().getAttribute();
          boolean dwrtable =
              (attr.getAttrValueAtInstant(now) instanceof HasCentroid
                  && attr.getDescriptor().getValidRange().contains(now));
          wrt.setEnabled(dwrtable);
          wrt.setSelected(isDwrt);
        }
      } else {
        attr = null;
        wrt.setEnabled(false);
        wrt.setSelected(false);
      }
      if (null != desc) {
        PropagateInterpolateModule proper = getMediator().getPropagator();
        p.setSelected(proper.isPropagatingThis(desc));
        v.setSelected(mediator.isThisValidNow(desc));
        resetMarks();
        super.show(invoker, x, y);
      }
    }
Пример #15
0
    public void majContenuMenu() {
      ElementPresentation ep = lnkPanneauDetail.get_elementCourant();

      jMenuSupprimerContenu.setVisible(true);
      if (ep != null && ep.getContenu() == null) {
        jMenuAjouterContenu.setVisible(true);
        jMenuChangerContenu.setVisible(false);
        jMenuSupprimerContenu.setEnabled(false);
      } else {
        jMenuAjouterContenu.setVisible(false);
        jMenuChangerContenu.setVisible(true);
        jMenuSupprimerContenu.setEnabled(true);
      }

      if (_dernierPanneau.equals("DGuide")) {
        jMenuAjouterGuide.setVisible(false);
        jMenuSupprimer.setVisible(true);
      } else {
        jMenuAjouterGuide.setVisible(true);
        jMenuSupprimer.setVisible(
            _dernierPanneau.equals("DElementPresentation")
                && !ep.get_id()
                    .equals(
                        getLnkSysteme()
                            .getlnkControleurPresentation()
                            .getlnkPresentation()
                            .getIdRacine()));
      }

      jMenuAjouterGuide.removeAll();
      if (ep != null) {
        Iterator vTypes =
            this.lnkControleurPanneaux.getLnkSysteme().getLnkControleurGuide().types();
        while (vTypes.hasNext()) {
          String value = (String) vTypes.next();
          JMenuItem mi = new JMenuItem(value);
          mi.addActionListener(
              new listenerSousMenusGuides(value, lnkPanneauDetail, this.lnkControleurPanneaux));
          jMenuAjouterGuide.add(mi);
        }
      }
    }
Пример #16
0
  /** Called if the user changes the selected items. */
  public void updateSelection() {
    int layer = getSelectedLayer();

    /* layer values:
     *  -1 means nothing selected
     *  -2 means different layers selected
     */

    boolean justCreated =
        !(app.getActiveEuclidianView().getEuclidianController().getJustCreatedGeos().isEmpty());

    copyAction.setEnabled(!app.getSelectedGeos().isEmpty());
    pasteAction.setEnabled(!CopyPaste.isEmpty());

    deleteAction.setEnabled(layer != -1 || justCreated);
    deleteItem.setVisible(layer != -1 || justCreated);
    deleteSeparator.setVisible(layer != -1 || justCreated);

    showhideAction.setEnabled(layer != -1);
    showhideItem.setVisible(layer != -1);

    showhideLabelsAction.setEnabled(layer != -1);
    showhideLabelsItem.setVisible(layer != -1);

    // exactly one layer selected
    selectCurrentLayerAction.setEnabled(getSelectedLayer() >= 0);
    selectCurrentLayerItem.setVisible(getSelectedLayer() >= 0);

    boolean haveSelection = !app.getSelectedGeos().isEmpty();
    invertAction.setEnabled(haveSelection);
    invertItem.setVisible(haveSelection);
    selectAllDescendantsAction.setEnabled(haveSelection);
    selectAllDescendantsItem.setVisible(haveSelection);
    selectAllAncestorsAction.setEnabled(haveSelection);
    selectAllAncestorsItem.setVisible(haveSelection);
    selectionSeparator.setVisible(haveSelection);

    Kernel kernel = app.getKernel();
    propertiesAction.setEnabled(!kernel.isEmpty());
    selectAllAction.setEnabled(!kernel.isEmpty());
  }
Пример #17
0
  private void updateSelectedAlgorithm() {

    m_Alg = null;
    m_Action = null;

    if (m_Path != null) {
      menuItemExecuteAsBatch.setVisible(false);
      menuItemExecuteAsBatchFromGIS.setVisible(false);
      menuItemExecute.setVisible(false);
      menuItemShowHelp.setVisible(false);
      for (int i = 0; i < menuItemExecuteIterative.length; i++) {
        menuItemExecuteIterative[i].setVisible(false);
      }
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode) m_Path.getLastPathComponent();
      if (!(node.getUserObject() instanceof GeoAlgorithm)) {
        if ((node.getUserObject() instanceof ToolboxAction)) {
          m_Action = (ToolboxAction) node.getUserObject();
        }
        return;
      }
      m_Alg = ((GeoAlgorithm) node.getUserObject());
      menuItemExecuteAsBatch.setVisible(true);
      menuItemShowHelp.setVisible(true);
      menuItemExecute.setVisible(true);
      final Object[] objs = SextanteGUI.getInputFactory().getDataObjects();
      menuItemExecuteAsBatchFromGIS.setVisible(true);
      final boolean bMeets = m_Alg.meetsDataRequirements(objs);
      menuItemExecuteAsBatchFromGIS.setEnabled(bMeets);
      menuItemExecute.setEnabled(bMeets);

      final IToolboxRightButtonAction[] actions = SextanteGUI.getToolboxRightButtonActions();
      for (int i = 0; i < menuItemToolboxAction.length; i++) {
        menuItemToolboxAction[i].setVisible(actions[i].canBeExecutedOnAlgorithm(m_Alg));
      }

      if (bMeets && m_Alg.requiresIndividualVectorLayers()) {
        m_iExecuteIterativeMenuCount = 0;
        final int iParams = m_Alg.getParameters().getNumberOfParameters();
        for (int i = 0; i < iParams; i++) {
          final Parameter param = m_Alg.getParameters().getParameter(i);
          if (param instanceof ParameterVectorLayer) {
            final ParameterVectorLayer pvl = (ParameterVectorLayer) param;
            boolean bMandatory;
            try {
              bMandatory =
                  ((AdditionalInfoVectorLayer) pvl.getParameterAdditionalInfo()).getIsMandatory();
              if (bMandatory) {
                menuItemExecuteIterative[m_iExecuteIterativeMenuCount].setText(
                    Sextante.getText("Run_iterative")
                        + " ("
                        + param.getParameterDescription()
                        + ")");
                menuItemExecuteIterative[m_iExecuteIterativeMenuCount].setVisible(true);
                m_iExecuteIterativeMenuCount++;
              }
            } catch (final NullParameterAdditionalInfoException e) {
            }
          }
        }
      }
    }
  }
Пример #18
0
  private JPopupMenu createPopup(MouseEvent e) {
    final ResourceBundle loc = NbBundle.getBundle(AnnotationBar.class);
    final JPopupMenu popupMenu = new JPopupMenu();

    final JMenuItem diffMenu =
        new JMenuItem(loc.getString("CTL_MenuItem_DiffToRevision")); // NOI18N

    // annotation for target line
    AnnotateLine al = null;
    if (!elementAnnotations.isEmpty()) {
      al = getAnnotateLine(getLineFromMouseEvent(e));
    }
    // revision previous to target line's revision
    final String revisionPerLine = al == null ? null : al.getRevision();
    final String changesetIdPerLine = al == null ? null : al.getId();
    final int lineNumber = al == null ? -1 : al.getPreviousLineNumber();
    // used in menu Revert
    final File file = getCurrentFile();
    // used in diff menu, repository root set while computing revision
    // denotes the path of the file in the showing revision
    final File originalFile = al == null ? null : new File(repositoryRoot, al.getFileName());
    final boolean revisionCanBeRolledBack =
        al == null || referencedFile != null ? false : al.canBeRolledBack();

    diffMenu.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final PreviousRevisionInvoker pri =
                new PreviousRevisionInvoker(revisionPerLine, originalFile);
            pri.runWithRevision(
                new Runnable() {
                  @Override
                  public void run() {
                    DiffAction.diff(
                        pri.getOriginalFile(),
                        pri.getPreviousRevision(),
                        originalFile,
                        new HgRevision(changesetIdPerLine, revisionPerLine));
                  }
                },
                true);
          }
        });
    popupMenu.add(diffMenu);

    JMenuItem rollbackMenu = new JMenuItem(loc.getString("CTL_MenuItem_Revert")); // NOI18N
    rollbackMenu.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            revert(file, revisionPerLine);
          }
        });
    popupMenu.add(rollbackMenu);
    rollbackMenu.setEnabled(revisionCanBeRolledBack);

    // an action showing annotation for line's revisions
    final JMenuItem annotationsForSelectedItem =
        new JMenuItem(
            NbBundle.getMessage(
                AnnotationBar.class,
                "CTL_MenuItem_ShowAnnotationsPrevious",
                revisionPerLine)); // NOI18N
    annotationsForSelectedItem.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Mercurial.getInstance()
                .getRequestProcessor()
                .post(
                    new Runnable() {
                      @Override
                      public void run() {
                        try {
                          HgUtils.openInRevision(
                              originalFile,
                              lineNumber > 0 ? lineNumber - 1 : -1,
                              new HgRevision(changesetIdPerLine, revisionPerLine),
                              true);
                        } catch (IOException ex) {
                          //
                        }
                      }
                    });
          }
        });
    popupMenu.add(annotationsForSelectedItem);

    // an action showing annotation for previous revisions
    final JMenuItem previousAnnotationsMenu = new JMenuItem();
    previousAnnotationsMenu.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final PreviousRevisionInvoker pri =
                new PreviousRevisionInvoker(revisionPerLine, originalFile);
            pri.runWithRevision(
                new Runnable() {
                  @Override
                  public void run() {
                    try {
                      HgUtils.openInRevision(
                          pri.getOriginalFile(),
                          -1,
                          pri.getPreviousRevision(),
                          !"-1".equals(pri.getPreviousRevision().getRevisionNumber())); // NOI18N
                    } catch (IOException ex) {
                      //
                    }
                  }
                },
                false);
          }
        });
    popupMenu.add(previousAnnotationsMenu);

    if (isKenai() && al != null) {
      String author = al.getAuthor();
      final int lineNr = al.getLineNum();
      final KenaiUser ku = kenaiUsersMap.get(author);
      if (ku != null) {
        popupMenu.addSeparator();
        JMenuItem chatMenu =
            new JMenuItem(NbBundle.getMessage(AnnotationBar.class, "CTL_MenuItem_Chat", author));
        chatMenu.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                ku.startChat(KenaiUser.getChatLink(getCurrentFileObject(), lineNr));
              }
            });
        popupMenu.add(chatMenu);
      }
    }

    JMenuItem menu;
    menu = new JMenuItem(loc.getString("CTL_MenuItem_CloseAnnotations")); // NOI18N
    menu.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            hideBar();
          }
        });
    JSeparator separator = new JPopupMenu.Separator();
    popupMenu.add(separator);
    popupMenu.add(menu);

    diffMenu.setVisible(false);
    annotationsForSelectedItem.setVisible(false);
    previousAnnotationsMenu.setVisible(false);
    rollbackMenu.setVisible(false);
    separator.setVisible(false);
    if (revisionPerLine != null) {
      String key = getPreviousRevisionKey(originalFile.getAbsolutePath(), revisionPerLine);
      HgRevision previousRevision = getPreviousRevisions().get(key); // get from cache
      if (al.canBeRolledBack()
          && (previousRevision != null || !getPreviousRevisions().containsKey(key))) {
        if (!getPreviousRevisions().containsKey(key)) {
          // get revision in a bg thread and cache the value
          Mercurial.getInstance()
              .getRequestProcessor()
              .post(
                  new Runnable() {
                    @Override
                    public void run() {
                      getParentRevision(originalFile, revisionPerLine);
                    }
                  });
        }
        String format = loc.getString("CTL_MenuItem_DiffToRevision"); // NOI18N
        String previousRevisionNumber =
            previousRevision == null ? null : previousRevision.getRevisionNumber();
        diffMenu.setText(
            MessageFormat.format(
                format,
                new Object[] {
                  revisionPerLine,
                  previousRevisionNumber == null
                      ? loc.getString("LBL_PreviousRevision")
                      : previousRevisionNumber
                })); // NOI18N
        diffMenu.setVisible(originalFile != null);
        rollbackMenu.setVisible(true);
        separator.setVisible(true);
        format = loc.getString("CTL_MenuItem_ShowAnnotationsPrevious"); // NOI18N
        previousAnnotationsMenu.setText(
            MessageFormat.format(
                format,
                new Object[] {
                  previousRevisionNumber == null
                      ? loc.getString("LBL_PreviousRevision")
                      : previousRevisionNumber
                })); // NOI18N
        previousAnnotationsMenu.setVisible(originalFile != null);
        previousAnnotationsMenu.setEnabled(!"-1".equals(previousRevisionNumber)); // NOI18N
        annotationsForSelectedItem.setVisible(
            originalFile != null
                && revisionPerLine != null
                && !revisionPerLine.equals(annotatedRevision));
      }
    }

    return popupMenu;
  }
 /** Hides the scrollButtons. */
 public void hideButtons() {
   upButton.setVisible(false);
   downButton.setVisible(false);
 }
Пример #20
0
 public void setSelectable(boolean b) {
   menuSelect.setVisible(b);
   menuDeselect.setVisible(!b);
 }
Пример #21
0
  public void setID(int id) {
    this.id = id;

    menuDeselect.setVisible(false);
    menuSelect.setVisible(true);
  }
  private void showPopupMenu(int row, int x, int y) {
    HeapWalkerNode node =
        (HeapWalkerNode) fieldsListTable.getTree().getPathForRow(row).getLastPathComponent();

    if (node instanceof HeapWalkerInstanceNode && ((HeapWalkerInstanceNode) node).isLoop()) {
      showLoopOriginItem.setVisible(true);
    } else {
      showLoopOriginItem.setVisible(false);
    }

    if (node.isRoot()) {
      showInstanceItem.setEnabled(false);
      copyPathFromRootItem.setEnabled(false);
    } else {
      showInstanceItem.setEnabled(
          node instanceof HeapWalkerInstanceNode
              && !(node instanceof HeapWalkerFieldNode && ((HeapWalkerFieldNode) node).isStatic()));
      copyPathFromRootItem.setEnabled(true);
    }

    //        showClassItem.setEnabled(node instanceof HeapWalkerInstanceNode || node instanceof
    // ClassNode);
    showGcRootItem.setEnabled(
        node instanceof HeapWalkerInstanceNode
            && (!node.currentlyHasChildren()
                || (node.getNChildren() != 1
                    || !HeapWalkerNodeFactory.isMessageNode(node.getChild(0))))); // #124306
    if (showSourceItem != null) showSourceItem.setEnabled(node instanceof HeapWalkerInstanceNode);
    showInThreadsItem.setEnabled(false);
    if (node instanceof HeapWalkerInstanceNode) {
      Instance rootInstance = ((HeapWalkerInstanceNode) node).getInstance();
      Heap heap =
          referencesBrowserController
              .getReferencesControllerHandler()
              .getHeapFragmentWalker()
              .getHeapFragment();
      GCRoot gcRoot = heap.getGCRoot(rootInstance);

      if (gcRoot != null && GCRoot.JAVA_FRAME.equals(gcRoot.getKind())) {
        // make sure that thread information is available
        JavaFrameGCRoot frameVar = (JavaFrameGCRoot) gcRoot;

        if (frameVar.getFrameNumber() != -1) {
          showInThreadsItem.setEnabled(true);
        }
      }
    }

    if ((x == -1) || (y == -1)) {
      Rectangle rowBounds = fieldsListTable.getCellRect(row, 0, true);

      if (x == -1) {
        x = rowBounds.x + (rowBounds.width / 2);
      }

      if (y == -1) {
        y = rowBounds.y + (rowBounds.height / 2);
      }
    }

    tablePopup.show(fieldsListTable, x, y);
  }
Пример #23
0
  public void createNewMenuBars(
      javax.swing.JMenuBar targetMenuBar,
      javax.swing.JMenuBar payrollMenuBar,
      javax.swing.JMenuBar stockMenuBar,
      javax.swing.MenuElement subElements[],
      javax.swing.JComponent popupNodes,
      javax.swing.JComponent reportsMenuBar,
      java.lang.String reportNodeTitle,
      java.lang.String utilitiesNodeTitle,
      javax.swing.ButtonGroup targetButtonGroup,
      javax.swing.ButtonGroup reportsButtonGroup) {

    final javax.swing.JMenuBar jmenubar1 = targetMenuBar;
    // subNodes = new javax.swing.tree.DefaultMutableTreeNode[subElements.length];

    // parentNode = treeNodes;

    for (int i = 0; i < subElements.length; i++) {
      // System.out.println(subElements[i]);
      if (subElements[i].getClass().getName() != "javax.swing.JPopupMenu") {

        // System.out.println("Element printing");

        javax.swing.JMenuItem abstractButton = (javax.swing.JMenuItem) subElements[i];

        //   javax.swing.tree.DefaultMutableTreeNode parentTreeNode =

        //                   System.out.println(subElements[i]);
        //   System.out.println(i);

        if (subElements[i].getClass().getName() == "javax.swing.JSeparator") {

          popupNodes.add(subElements[i].getComponent());
        }

        if (subElements[i].getClass().getName() == "javax.swing.JMenu") {

          popupMenu = new javax.swing.JMenu(abstractButton.getText());

          if (popupNodes != null) {

            if (popupMenu.getText() != "Feel") {

              popupNodes.add(popupMenu);
            }
          }

          if (abstractButton.getText() == "System") {

            if (stockMenuBar != null) {

              System.out.println("Doing system" + popupMenu.getName());

              popupMenu.setText("Control");

              //  popupReports.add(popupMenu, 4);
              //  if (stockMenuBar != null && payrollMenuBar != null) {

              stockMenuBar.add(popupMenu);
            }
          }
          if (abstractButton.getText() == "System") {

            if (payrollMenuBar != null) {

              System.out.println("Doing system" + popupMenu.getName());

              popupMenu.setText("Control");

              //  popupReports.add(popupMenu, 4);
              //  if (stockMenuBar != null && payrollMenuBar != null) {

              payrollMenuBar.add(popupMenu);
            }
          }
          if (abstractButton.getText() == "System") {

            if (reportsMenuBar != null) {

              System.out.println("Doing system" + popupMenu.getName());

              popupMenu.setText("Control");

              //  popupReports.add(popupMenu, 4);
              //  if (stockMenuBar != null && payrollMenuBar != null) {

              reportsMenuBar.add(popupMenu);
            }
          }

          if (abstractButton.getText() == "Reports") {

            if (reportsMenuBar != null) {

              popupMenu.setText(reportNodeTitle);

              reportsMenuBar.add(popupMenu);
            }
          }

          if (abstractButton.getText() == "Utility") {

            if (reportsMenuBar != null) {

              popupMenu.setText(utilitiesNodeTitle);

              reportsMenuBar.add(popupMenu);
            }
          }
        }
        if (subElements[i].getClass().getName() == "javax.swing.JMenuItem") {

          popupMenuItem = new javax.swing.JMenuItem(abstractButton.getText());

          popupMenuItem.addActionListener(
              new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                  System.out.println(
                      "Action Taking Place for action : [" + evt.getActionCommand() + "].");

                  getTargetMenuItem(jmenubar1.getSubElements(), evt.getActionCommand());

                  // componentActionPerformed(targetMenuBar, actionComponent.getText());

                }
              });
          //  registerActionListener(popupMenuItem, targetMenuBar);

          // popupMenuItem = abstractButton;

          popupNodes.add(popupMenuItem);

          // popupMenuItem.addActionListener(abstractButton.actionListener);

          if (!abstractButton.isEnabled()) {

            popupMenuItem.setVisible(false);
          }

          /* if (abstractButton.getText() == "Reports") {

              popupMenuItem.setText(reportNodeTitle);

              popupReports.add(popupMenuItem);

          }

          if ( abstractButton.getText() == "Utility") {

              popupMenuItem.setText(utilitiesNodeTitle);

              popupReports.add(popupMenuItem);

          }
          */
          // }

          // }
          //  System.out.println("Node : "+ subNodes[i].toString());

          //  System.out.println(tabString + abstractButton.getText());

        }

        if (subElements[i].getClass().getName() == "javax.swing.JRadioButtonMenuItem") {

          popupRadioButtonMenuItem = new javax.swing.JRadioButtonMenuItem(abstractButton.getText());

          popupRadioButtonMenuItem.addActionListener(
              new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                  System.out.println(
                      "Action Taking Place for action : [" + evt.getActionCommand() + "].");

                  getTargetMenuItem(jmenubar1.getSubElements(), evt.getActionCommand());

                  // componentActionPerformed(targetMenuBar, actionComponent.getText());

                }
              });
          // popupRadioButtonMenuItem = (javax.swing.JRadioButtonMenuItem)abstractButton;

          popupNodes.add(popupRadioButtonMenuItem);

          if (targetButtonGroup != null) {

            targetButtonGroup.add(popupRadioButtonMenuItem);
          }

          if (reportsButtonGroup != null) {

            reportsButtonGroup.add(popupRadioButtonMenuItem);
          }
          // popupMenuItem.addActionListener(abstractButton.actionListener);

          if (!abstractButton.isEnabled()) {

            popupMenuItem.setEnabled(false);
          }

          /* if (abstractButton.getText() == "Reports") {

              popupMenuItem.setText(reportNodeTitle);

              popupReports.add(popupMenuItem);

          }

          if ( abstractButton.getText() == "Utility") {

              popupMenuItem.setText(utilitiesNodeTitle);

              popupReports.add(popupMenuItem);

          }
          */
        }

        // }
        //  System.out.println("Node : "+ subNodes[i].toString());

        //  System.out.println(tabString + abstractButton.getText());

        // }

        if (subElements[i].getClass().getName() == "javax.swing.JCheckBoxMenuItem") {

          popupCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem(abstractButton.getText());

          popupCheckBoxMenuItem.addActionListener(
              new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                  System.out.println(
                      "Action Taking Place for action : [" + evt.getActionCommand() + "].");

                  getTargetMenuItem(jmenubar1.getSubElements(), evt.getActionCommand());

                  // componentActionPerformed(targetMenuBar, actionComponent.getText());

                }
              });
          // popupCheckBoxMenuItem = (javax.swing.JCheckBoxMenuItem)abstractButton;

          popupNodes.add(popupCheckBoxMenuItem);

          if (targetButtonGroup != null) {

            targetButtonGroup.add(popupCheckBoxMenuItem);
          }

          if (reportsButtonGroup != null) {

            reportsButtonGroup.add(popupCheckBoxMenuItem);
          }

          // popupMenuItem.addActionListener(abstractButton.actionListener);

          if (!abstractButton.isEnabled()) {

            popupMenuItem.setEnabled(false);
          }

          /* if (abstractButton.getText() == "Reports") {

              popupMenuItem.setText(reportNodeTitle);

              popupReports.add(popupMenuItem);

          }

          if ( abstractButton.getText() == "Utility") {

              popupMenuItem.setText(utilitiesNodeTitle);

              popupReports.add(popupMenuItem);

          }
          */
        }

        // }
        //  System.out.println("Node : "+ subNodes[i].toString());

        //  System.out.println(tabString + abstractButton.getText());
      }
      // }
      // System.out.println(abstractButton.getText());

      if (subElements[i].getSubElements().length > 0) {

        // tabString = tabString + " ";

        // parentNode = siblingNode;

        // System.out.println("See this!");

        createNewMenuBars(
            targetMenuBar,
            payrollMenuBar,
            stockMenuBar,
            subElements[i].getSubElements(),
            popupMenu,
            reportsMenuBar,
            reportNodeTitle,
            utilitiesNodeTitle,
            targetButtonGroup,
            reportsButtonGroup);

        /* if (treeNodes.isLeaf()) {


            javax.swing.tree.DefaultMutableTreeNode parentNode = (javax.swing.tree.DefaultMutableTreeNode)siblingNode.getParent();

            //                   System.out.println("Parent : ["+parentNode.getUserObject()+"]");// and Sibling : ["+siblingNode.getUserObject()+"]");

            siblingNode.removeFromParent();
            //                    parentNode.remove(siblingNode);

        }

        */
        // tabString = tabString + "\b";

      }

      // System.out.println("Element Closing");
    }

    //    parentNode = siblingNode;
    /* treeNodes = (javax.swing.tree.DefaultMutableTreeNode)treeNodes.getParent();

    if (treeNodes != null) {

        System.out.println(treeNodes.getUserObject().toString());

    }
    */

  }
  private void showPopup() {
    if (isEnabled()) {
      if (popup.isVisible()) {
        popup.setVisible(false);
      } else {
        Component[] components = popup.getComponents();
        if (components != null) {
          for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof Item) ((Item) components[i]).removeActionListener(this);
            else if (components[i] instanceof MenuItem) {
              Component[] subcomponents = ((MenuItem) components[i]).getComponents();
              for (int j = 0; j < components.length; j++) {
                if (components[j] instanceof Item)
                  ((Item) components[j]).removeActionListener(this);
              }
            }
          }
        }
        popup.removeAll();
        if (values == null) return;
        for (int i = 0; i < values.length; i++) {
          JMenuItem item = null;
          if (values[i] instanceof ListDescriptor) {
            ListDescriptor descriptor = (ListDescriptor) values[i];
            Icon icon = descriptor.getIcon();
            item = new Item(values[i].toString(), icon, i);
            item.addActionListener(this);
          } else if (values[i] instanceof AddElement) {
            AddElement element = (AddElement) values[i];
            Icon icon = element.getIcon();

            Object[] choiceValues = element.getChoiceValues();
            if (choiceValues != null) {
              item = new MenuItem(element.toString(), icon, i);
              for (int j = 0; j < choiceValues.length; j++) {
                if (choiceValues[j] == null) {
                  ((JMenu) item).addSeparator();
                  continue;
                }
                Item subItem = new Item(choiceValues[j].toString(), j);
                ((JMenu) item).add(subItem);
                subItem.setParentIndex(i);
                subItem.addActionListener(this);
              }
            } else {
              item = new Item(element.toString(), icon, i);
              item.addActionListener(this);
            }
            item.setVisible(element.isVisible());
            item.setEnabled(element.isEnabled());
          } else {
            if (values[i] != null) {
              item = new Item(values[i].toString(), i);
              item.addActionListener(this);
            }
          }
          if (item != null) {
            popup.add(item);
          } else popup.addSeparator();
        }
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                AwtUtil.showPopupPanel(PopupMenuButton.this, popup);
              }
            });
      }
    }
  }
Пример #25
0
 /**
  * Set the MenuItem Visibility (See bug #7368)
  *
  * @param status true if the MenuItem is visible
  * @see org.scilab.modules.gui.menu.SimpleMenu#setVisible()
  */
 public void setVisible(boolean status) {
   super.setVisible(status);
   if (meAsACheckBoxMenuItem != null) {
     meAsACheckBoxMenuItem.setVisible(status);
   }
 }