Package javax.swing

Examples of javax.swing.JPopupMenu$AccessibleJPopupMenu


    mExpandListenerIsEnabled = true;
  }

  private void showContextMenu(Point p) {

      JPopupMenu menu = new JPopupMenu();
      int row = getClosestRowForLocation(p.x, p.y);
      if (row >= 0 && row < getRowCount()) {
        setSelectionRow(row);
      }

      TreePath path1 = null;
      int[] selectionRows = getSelectionRows();
      if (selectionRows.length > 0) {
        path1 = getPathForRow(selectionRows[0]);
      }

      if(path1 == null) {
        path1 = new TreePath(mRootNode);
      }

      final TreePath path = path1;
      final FavoriteNode last = (FavoriteNode)path.getLastPathComponent();

      setSelectionPath(path);

      JMenuItem item;

      if(last.isDirectoryNode() && last.getChildCount() > 0) {
        item = new JMenuItem(isExpanded(path) ? mLocalizer.msg("collapse", "Collapse") : mLocalizer.msg("expand", "Expand"));
        item.setFont(item.getFont().deriveFont(Font.BOLD));

        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if(isExpanded(path)) {
              collapsePath(path);
            } else {
              expandPath(path);
            }
          }
        });

        if(!last.equals(mRootNode)) {
          menu.add(item);
        }

        item = new JMenuItem(mLocalizer.msg("expandAll", "Expand all"));

        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            expandAll(last);
          }
        });

        menu.add(item);

        item = new JMenuItem(mLocalizer.msg("collapseAll", "Collapse all"));

        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            collapseAll(last);
          }
        });
        menu.add(item);

        menu.addSeparator();
      }

      if (!last.isDirectoryNode()) {
        item = new JMenuItem(mLocalizer.ellipsisMsg("editFavorite", "Edit favorite '{0}'", last.getFavorite().getName()),
            TVBrowserIcons.edit(TVBrowserIcons.SIZE_SMALL));
        item.setFont(item.getFont().deriveFont(Font.BOLD));

        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ManageFavoritesDialog.getInstance().editSelectedFavorite();
          }
        });
        menu.add(item);
        menu.addSeparator();
      }

      item = new JMenuItem(mLocalizer.msg("newFolder", "New folder"),
          IconLoader.getInstance().getIconFromTheme("actions", "folder-new", 16));

      item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          newFolder(last);
        }
      });
      menu.add(item);

      item = new JMenuItem(mLocalizer.ellipsisMsg("newFavorite", "New Favorite"),
          TVBrowserIcons.newIcon(TVBrowserIcons.SIZE_SMALL));

      item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          ManageFavoritesDialog.getInstance().newFavorite(last.isDirectoryNode() ? last : (FavoriteNode)last.getParent());
        }
      });
      menu.add(item);

      if(last.isDirectoryNode()) {
        if(!last.equals(mRootNode)) {
          item = new JMenuItem(mLocalizer.msg("renameFolder", "Rename folder"),
              TVBrowserIcons.edit(TVBrowserIcons.SIZE_SMALL));

          item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              renameFolder(last);
            }
          });

          menu.add(item);
        }
      }

      FavoriteNode parentSort = null;

      if(!last.isDirectoryNode() && last.getParent().equals(mRootNode) && mRootNode.getChildCount() > 1) {
        parentSort = (FavoriteNode)last.getParent();
      }

      final FavoriteNode sortNode = parentSort == null ? last : parentSort;

      if(last.getChildCount() > 1 || (last.getParent().equals(mRootNode) && mRootNode.getChildCount() > 1 )) {
        menu.addSeparator();

        item = new JMenuItem(mLocalizer.msg("sort", "Sort alphabetically"),
            IconLoader.getInstance().getIconFromTheme("actions", "sort-list", 16));
        final String titleAlpha = item.getText();
        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              FavoriteTreeModel.getInstance().sort(sortNode,FavoriteNodeComparator.getInstance(), titleAlpha);
              reload(sortNode);
          }
        });
        menu.add(item);

        item = new JMenuItem(mLocalizer.msg("sortCount", "Sort by number of programs"),
            IconLoader.getInstance().getIconFromTheme("actions", "sort-list-numerical", 16));
        final String titleCount = item.getText();
        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              FavoriteTreeModel.getInstance().sort(sortNode,FavoriteNodeCountComparator.getInstance(),titleCount);
              reload(sortNode);
          }
        });
        menu.add(item);
      }

      if(parentSort != null) {
        menu.addSeparator();
      }


      item = new JMenuItem(Localizer.getLocalization(Localizer.I18N_DELETE),
          TVBrowserIcons.delete(TVBrowserIcons.SIZE_SMALL));

      item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          delete(last);
        }
      });

      if(!last.equals(mRootNode) && last.getChildCount() < 1) {
        menu.add(item);
      }

      if(!ManageFavoritesDialog.getInstance().programListIsEmpty()) {
        menu.addSeparator();

        item = new JMenuItem(ManageFavoritesDialog.mLocalizer.msg("send", "Send Programs to another Plugin"), TVBrowserIcons.copy(TVBrowserIcons.SIZE_SMALL));
        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
             ManageFavoritesDialog.getInstance().showSendDialog();
          }
        });

        menu.add(item);
      }

      menu.show(this, p.x, p.y);
  }
View Full Code Here


    // anonymous action listener shows a JTree popup and allows the user
    // to choose the class they want
    setButton.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {

    JPopupMenu popup = getChooseClassPopupMenu();

    // show the popup where the source component is
    if (e.getSource() instanceof Component) {
      Component comp = (Component) e.getSource();
      popup.show(comp, comp.getX(), comp.getY());
      popup.pack();
      popup.repaint();
    }
  }
      });

    return setButton;
View Full Code Here

    }
    tree.getSelectionModel().setSelectionMode
      (TreeSelectionModel.SINGLE_TREE_SELECTION);

    // create the popup
    final JPopupMenu popup = new JTreePopupMenu(tree);

    // respond when the user chooses a class
    tree.addTreeSelectionListener(new TreeSelectionListener() {
  public void valueChanged(TreeSelectionEvent e) {
    GOETreeNode node = (GOETreeNode) tree.getLastSelectedPathComponent();
   
    if (node == null)
      return;
   
    if (node.isLeaf()) {
      classSelected(getClassnameFromPath(tree.getSelectionPath()));
      popup.setVisible(false);
    }
  }
      });
   
    return popup;
View Full Code Here

  /**
   * initializes the popup menus
   */
  private void initPopupMenus() {
    // header popup
    m_PopupHeader  = new JPopupMenu();
    m_PopupHeader.addMouseListener(this);
    m_PopupHeader.add(menuItemMean);
    if (!isReadOnly()) {
      m_PopupHeader.addSeparator();
      m_PopupHeader.add(menuItemSetAllValues);
      m_PopupHeader.add(menuItemSetMissingValues);
      m_PopupHeader.add(menuItemReplaceValues);
      m_PopupHeader.addSeparator();
      m_PopupHeader.add(menuItemRenameAttribute);
      m_PopupHeader.add(menuItemAttributeAsClass);
      m_PopupHeader.add(menuItemDeleteAttribute);
      m_PopupHeader.add(menuItemDeleteAttributes);
      m_PopupHeader.add(menuItemSortInstances);
    }
    m_PopupHeader.addSeparator();
    m_PopupHeader.add(menuItemOptimalColWidth);
    m_PopupHeader.add(menuItemOptimalColWidths);
   
    // row popup
    m_PopupRows = new JPopupMenu();
    m_PopupRows.addMouseListener(this);
    if (!isReadOnly()) {
      m_PopupRows.add(menuItemUndo);
      m_PopupRows.addSeparator();
    }
View Full Code Here

   * @param x the x coordinate for popping up the menu
   * @param y the y coordinate for popping up the menu
   */
  protected void visualizeClusterer(String name, int x, int y) {
    final String selectedName = name;
    JPopupMenu resultListMenu = new JPopupMenu();

    JMenuItem visMainBuffer = new JMenuItem("View in main window");
    if (selectedName != null) {
      visMainBuffer.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      m_History.setSingle(selectedName);
    }
  });
    } else {
      visMainBuffer.setEnabled(false);
    }
    resultListMenu.add(visMainBuffer);

    JMenuItem visSepBuffer = new JMenuItem("View in separate window");
    if (selectedName != null) {
    visSepBuffer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    m_History.openFrame(selectedName);
  }
      });
    } else {
      visSepBuffer.setEnabled(false);
    }
    resultListMenu.add(visSepBuffer);

    JMenuItem saveOutput = new JMenuItem("Save result buffer");
    if (selectedName != null) {
      saveOutput.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      saveBuffer(selectedName);
    }
  });
    } else {
      saveOutput.setEnabled(false);
    }
    resultListMenu.add(saveOutput);
   
    JMenuItem deleteOutput = new JMenuItem("Delete result buffer");
    if (selectedName != null) {
      deleteOutput.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    m_History.removeResult(selectedName);
  }
      });
    } else {
      deleteOutput.setEnabled(false);
    }
    resultListMenu.add(deleteOutput);

    resultListMenu.addSeparator();

    JMenuItem loadModel = new JMenuItem("Load model");
    loadModel.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    loadClusterer();
  }
      });
    resultListMenu.add(loadModel);

    FastVector o = null;
    if (selectedName != null) {
      o = (FastVector)m_History.getNamedObject(selectedName);
    }

    VisualizePanel temp_vp = null;
    String temp_grph = null;
    Clusterer temp_clusterer = null;
    Instances temp_trainHeader = null;
    int[] temp_ignoreAtts = null;
   
    if (o != null) {
      for (int i = 0; i < o.size(); i++) {
  Object temp = o.elementAt(i);
  if (temp instanceof Clusterer) {
    temp_clusterer = (Clusterer)temp;
  } else if (temp instanceof Instances) { // training header
    temp_trainHeader = (Instances)temp;
  } else if (temp instanceof int[]) { // ignored attributes
    temp_ignoreAtts = (int[])temp;
  } else if (temp instanceof VisualizePanel) { // normal errors
    temp_vp = (VisualizePanel)temp;
  } else if (temp instanceof String) { // graphable output
    temp_grph = (String)temp;
  }
      }
    }
     
    final VisualizePanel vp = temp_vp;
    final String grph = temp_grph;
    final Clusterer clusterer = temp_clusterer;
    final Instances trainHeader = temp_trainHeader;
    final int[] ignoreAtts = temp_ignoreAtts;
   
    JMenuItem saveModel = new JMenuItem("Save model");
    if (clusterer != null) {
      saveModel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      saveClusterer(selectedName, clusterer, trainHeader, ignoreAtts);
    }
  });
    } else {
      saveModel.setEnabled(false);
    }
    resultListMenu.add(saveModel);
   
    JMenuItem reEvaluate =
      new JMenuItem("Re-evaluate model on current test set");
    if (clusterer != null && m_TestInstances != null) {
      reEvaluate.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      reevaluateModel(selectedName, clusterer, trainHeader, ignoreAtts);
    }
  });
    } else {
      reEvaluate.setEnabled(false);
    }
    resultListMenu.add(reEvaluate);
   
    resultListMenu.addSeparator();
   
    JMenuItem visClusts = new JMenuItem("Visualize cluster assignments");
    if (vp != null) {
      visClusts.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        visualizeClusterAssignments(vp);
      }
    });
     
    } else {
      visClusts.setEnabled(false);
    }
    resultListMenu.add(visClusts);

    JMenuItem visTree = new JMenuItem("Visualize tree");
    if (grph != null) {
      visTree.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      String title;
      if (vp != null) title = vp.getName();
      else title = selectedName;
      visualizeTree(grph, title);
    }
  });
    } else {
      visTree.setEnabled(false);
    }
    resultListMenu.add(visTree);

   
    // visualization plugins
    JMenu visPlugins = new JMenu("Plugins");
    boolean availablePlugins = false;
   
    // trees
    if (grph != null) {
      // trees
      Vector pluginsVector = GenericObjectEditor.getClassnames(TreeVisualizePlugin.class.getName());
      for (int i = 0; i < pluginsVector.size(); i++) {
  String className = (String) (pluginsVector.elementAt(i));
  try {
    TreeVisualizePlugin plugin = (TreeVisualizePlugin) Class.forName(className).newInstance();
    if (plugin == null)
      continue;
    availablePlugins = true;
    JMenuItem pluginMenuItem = plugin.getVisualizeMenuItem(grph, selectedName);
    Version version = new Version();
    if (pluginMenuItem != null) {
      if (version.compareTo(plugin.getMinVersion()) < 0)
        pluginMenuItem.setText(pluginMenuItem.getText() + " (weka outdated)");
      if (version.compareTo(plugin.getMaxVersion()) >= 0)
        pluginMenuItem.setText(pluginMenuItem.getText() + " (plugin outdated)");
      visPlugins.add(pluginMenuItem);
    }
  }
  catch (Exception e) {
    //e.printStackTrace();
  }
      }
    }

    if (availablePlugins)
      resultListMenu.add(visPlugins);
   
    resultListMenu.show(m_History.getList(), x, y);
  }
View Full Code Here

      if(listItem instanceof SelectableItem) {
        final Object item = ((SelectableItem)listItem).getItem();

        if(item instanceof SoftwareUpdateItem) {
          if(((SoftwareUpdateItem)item).getWebsite() != null) {
            JPopupMenu menu = new JPopupMenu();

            JMenuItem menuItem = new JMenuItem(mLocalizer.msg("openWebsite","Open website"), TVBrowserIcons.webBrowser(TVBrowserIcons.SIZE_SMALL));
            menuItem.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                Launch.openURL(((SoftwareUpdateItem)item).getWebsite());
              }
            });

            menu.add(menuItem);

            menu.show(e.getComponent(), e.getX(), e.getY());
          }
        }
      }
    }
  }
View Full Code Here

  void showPopupMenu(final Action item) {
    final AbstractButton btn = (AbstractButton) item
        .getValue(ToolBar.ACTION_VALUE);

    JPopupMenu popup = null;

    if (item == mFilterAction) {
      ScrollableMenu menu = new SelectFilterPopup(MainFrame.getInstance());
      popup = menu.getPopupMenu();
    } else if (item == mGoToDateAction) {
      popup = new JPopupMenu();

      Date curDate = Date.getCurrentDate().addDays(-1);

      if(TvDataBase.getInstance().dataAvailable(curDate)) {
        popup.add(createDateMenuItem(curDate));
      }

      curDate = curDate.addDays(1);

      Date maxDate = TvDataBase.getInstance().getMaxSupportedDate();
      while (maxDate.getNumberOfDaysSince(curDate) >= 0) {
        if(!TvDataBase.getInstance().dataAvailable(curDate)) {
          break;
        }
        if (curDate.isFirstDayOfWeek()) {
          popup.addSeparator();
        }

        popup.add(createDateMenuItem(curDate));
        curDate = curDate.addDays(1);
      }
    } else if (item == mScrollToChannelAction) {
      ScrollableMenu menu = new ScrollableMenu();
      popup = menu.getPopupMenu();

      Channel[] channels = Settings.propSubscribedChannels.getChannelArray();
      for (Channel channel : channels) {
        menu.add(createChannelMenuItem(channel, btn));
      }
    } else if (item == mScrollToTimeAction) {
      popup = new JPopupMenu();

      int[] array = Settings.propTimeButtons.getIntArray();

      for (int element : array) {
        popup.add(createTimeMenuItem(element, btn));
      }

      if (popup.getComponentCount() > 0) {
        popup.addSeparator();
      }

      JMenuItem menuItem = new JMenuItem(TVBrowserActions.scrollToNow.getValue(Action.NAME).toString());
      menuItem.setHorizontalTextPosition(SwingConstants.CENTER);

      menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          MainFrame.getInstance().scrollToNow();
          btn.setSelected(false);
          MainFrame.getInstance().updateToolbar();
        }
      });
      popup.add(menuItem);
    }

    if (popup != null) {
      popup.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuCanceled(PopupMenuEvent e) {  }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
          AbstractButton button = (AbstractButton) item
              .getValue(ToolBar.ACTION_VALUE);
          if (item == mFilterAction) {
            button.setSelected(!FilterManagerImpl.getInstance().getCurrentFilter().equals(FilterManagerImpl.getInstance().getDefaultFilter()));
            setFilterButtonSelected(button.isSelected());
          }
          if (item == mGoToDateAction) {
            button.setSelected(false);
          }

          MainFrame.getInstance().updateToolbar();
        }

        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {}
      });

      Point p = new Point(0, 0);
      p.y = btn.getHeight() + 1;

      popup.show(btn, p.x, p.y);
    }
  }
View Full Code Here

        Action[] actions = DefaultToolBarModel.getInstance().getActions();

        Rectangle visibleRect = toolbar.getVisibleRect();
        for(int i = 0; i<comp.length; i++){
            if(!isVisible(comp[i], visibleRect)){
                mPopupMenu = new JPopupMenu();
                for(; i<comp.length; i++){
                    if(comp[i] instanceof AbstractButton) {
                      if(actions[i] != null) {
                        mPopupMenu.add(actions[i]);
                      }
View Full Code Here

  public ContextMenu(JComponent component) {
    if(ToolBarDragAndDropSettings.getInstance() != null) {
      return;
    }
    mComponent = component;
    mMenu = new JPopupMenu();
  }
View Full Code Here

      private JPopupMenu getPopupMenu(String search, final boolean actorFavorite) {
        if (search != null) {
          search = search.trim();
        }
        final String searchText = search;
        JPopupMenu popupMenu = new JPopupMenu();
        if (searchText != null && searchText.length() > 0) {
          String value = ProgramInfo.getInstance().getSettings()
              .getActorSearch();

          JMenuItem item = searchTextMenuItem(searchText);

          if (value.equals("internalSearch")) {
            item.setFont(item.getFont().deriveFont(Font.BOLD));
          }

          popupMenu.add(item);

          item = new JMenuItem(mLocalizer.msg("searchWikipedia",
              "Search in Wikipedia"));
          item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              searchWikipedia(searchText);
            }
          });

          if (value.equals("internalWikipedia")) {
            item.setFont(item.getFont().deriveFont(Font.BOLD));
          }

          popupMenu.add(item);

          final PluginAccess webPlugin = PluginManagerImpl.getInstance()
              .getActivatedPluginForId("java.webplugin.WebPlugin");

          if (webPlugin != null && webPlugin.canReceiveProgramsWithTarget()) {
            ProgramReceiveTarget[] targets = webPlugin
                .getProgramReceiveTargets();

            if (targets != null && targets.length > 0) {
              final JMenu subMenu = new JMenu(webPlugin.getInfo().getName());
              subMenu.setIcon(webPlugin.getMarkIcon());
              popupMenu.add(subMenu);

              for (final ProgramReceiveTarget target : targets) {
                item = new JMenuItem(target.toString());
                item.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                    searchWebPlugin(searchText, target);
                  }
                });

                if (value.endsWith(target.getTargetId())) {
                  item.setFont(item.getFont().deriveFont(Font.BOLD));
                }

                subMenu.add(item);
              }
            }
          }

          popupMenu.addSeparator();
          popupMenu.add(addFavoriteMenuItem(searchText, actorFavorite));
          popupMenu.addSeparator();
        }
        JMenu subMenu = ContextMenuManager.getInstance()
            .createContextMenuItems(ProgramInfoProxy.getInstance(), mProgram,
                true);
        subMenu.setText(Localizer.getLocalization(Localizer.I18N_PROGRAM));
        popupMenu.add(subMenu);
        return popupMenu;
      }

      private void handleEvent(MouseEvent e, boolean popupEvent) {
        JEditorPane editor = (JEditorPane) e.getSource();

        Point pt = new Point(e.getX(), e.getY());
        int pos = editor.viewToModel(pt);
        if (pos >= 0) {
          String link = getLink(pos, editor);

          if (link != null
              && link.startsWith(ProgramTextCreator.TVBROWSER_URL_PROTOCOL)) {
            final String searchText = link
                .substring(ProgramTextCreator.TVBROWSER_URL_PROTOCOL.length());

            if (popupEvent) {
              JPopupMenu popupMenu = getPopupMenu(searchText, true);
              popupMenu.show(e.getComponent(), e.getX(), e.getY());
            } else {
              String value = ProgramInfo.getInstance().getSettings()
                  .getActorSearch();

              boolean found = false;

              if (value.contains("#_#_#")) {
                String[] keys = value.split("#_#_#");

                PluginAccess webPlugin = PluginManagerImpl.getInstance()
                    .getActivatedPluginForId(keys[0]);

                if (webPlugin != null
                    && webPlugin.canReceiveProgramsWithTarget()) {
                  ProgramReceiveTarget[] targets = webPlugin
                      .getProgramReceiveTargets();

                  if (targets != null) {

                    for (ProgramReceiveTarget target : targets) {
                      if (target.getTargetId().equals(keys[1])) {
                        searchWebPlugin(searchText, target);
                        found = true;
                      }
                    }
                  }
                }
              }

              if (!found) {
                if (value.equals("internalSearch")) {
                  internalSearch(searchText);
                } else {
                  searchWikipedia(searchText);
                }
              }
            }
          } else if (popupEvent){
            String selection = getSelection(pos, editor);
            JPopupMenu popupMenu = getPopupMenu(selection, false);
            TextComponentPopupEventQueue.addStandardContextMenu(mInfoEP,
                popupMenu);
            popupMenu.show(e.getComponent(), e.getX(), e.getY());
          }
        }
      }

      private JMenuItem searchTextMenuItem(final String desc) {
        JMenuItem item = new JMenuItem(mLocalizer.msg("searchTvBrowser",
            "Search in TV-Browser"), IconLoader.getInstance().getIconFromTheme(
            "actions", "edit-find"));
        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            internalSearch(desc);
          }
        });
        return item;
      }

      private JMenuItem addFavoriteMenuItem(final String desc,
          final boolean actor) {
        JMenuItem item;
        item = new JMenuItem(mLocalizer.ellipsisMsg("addFavorite",
            "Create favorite"), IconLoader.getInstance().getIconFromTheme(
            "emblems", "emblem-favorite"));
        item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (actor) {
              FavoritesPlugin.getInstance().showCreateActorFavoriteWizard(
                  mProgram, desc);
            } else {
              FavoritesPlugin.getInstance().showCreateTopicFavoriteWizard(
                  mProgram, desc);
            }
          }
        });
        return item;
      }

      private void searchWebPlugin(String desc, ProgramReceiveTarget target) {
        target.getReceifeIfForIdOfTarget().receiveValues(new String[] { desc },
            target);
      }

      private void searchWikipedia(String desc) {
        DontShowAgainOptionBox
            .showOptionDialog(
                "programInfoDialog.newActorSearch",
                mDialog,
                ProgramInfo.mLocalizer
                    .msg(
                        "newActorSearchText",
                        "This function was changed for TV-Browser 2.7. The search type is now\nchangeable in the settings of the Program details, additional now available\nis a context menu for the actor search."),
                ProgramInfo.mLocalizer
                    .msg("newActorSearch", "New actor search"));

        try {
          String url = URLEncoder.encode(desc, "UTF-8").replace("+", "%20");
          url = mLocalizer.msg("wikipediaLink",
              "http://en.wikipedia.org/wiki/{0}", url);
          Launch.openURL(url);
        } catch (UnsupportedEncodingException e1) {
          e1.printStackTrace();
        }
      }

      private void internalSearch(String desc) {
        desc = desc.replaceAll("  ", " ").replaceAll(" ", " AND ");
        SearchFormSettings settings = new SearchFormSettings(desc);
        settings.setSearchIn(SearchFormSettings.SEARCH_IN_ALL);
        settings.setSearcherType(PluginManager.SEARCHER_TYPE_BOOLEAN);
        settings.setNrDays(-1);
        SearchHelper.search(mInfoEP, settings, null, true);
      }

      private String getLink(int pos, JEditorPane html) {
        Document doc = html.getDocument();
        if (doc instanceof HTMLDocument) {
          HTMLDocument hdoc = (HTMLDocument) doc;
          Element e = hdoc.getCharacterElement(pos);
          AttributeSet a = e.getAttributes();
          AttributeSet anchor = (AttributeSet) a.getAttribute(HTML.Tag.A);

          if (anchor != null) {
            return (String) anchor.getAttribute(HTML.Attribute.HREF);
          }
        }
        return null;
      }

      private String getSelection(int pos, JEditorPane html) {
        Caret caret = html.getCaret();
        if (caret != null) {
          try {
            int start = Math.min(caret.getDot(), caret.getMark());
            int length = Math.abs(caret.getDot() - caret.getMark());
            return html.getDocument().getText(start, length);
          } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        return null;
      }

    });

    mInfoEP.addHyperlinkListener(new HyperlinkListener() {
      private String mTooltip;

      public void hyperlinkUpdate(HyperlinkEvent evt) {
        if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
          mTooltip = mInfoEP.getToolTipText();
          mInfoEP.setToolTipText(getLinkTooltip(evt));
        }
        if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
          mInfoEP.setToolTipText(mTooltip);
        }
        if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
          URL url = evt.getURL();
          if (url != null) {
            Launch.openURL(url.toString());
          }
        }
      }
    });

    mFindAsYouType = new TextComponentFindAction(mInfoEP, true);

    final JScrollPane scrollPane = new JScrollPane(mInfoEP);
    scrollPane.getVerticalScrollBar().setUnitIncrement(30);

    // ScrollActions
    mUpAction = new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        scrollPane.getVerticalScrollBar().setValue(
            scrollPane.getVerticalScrollBar().getValue()
                - scrollPane.getVerticalScrollBar().getUnitIncrement());
      }
    };

    mDownAction = new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        scrollPane.getVerticalScrollBar().setValue(
            scrollPane.getVerticalScrollBar().getValue()
                + scrollPane.getVerticalScrollBar().getUnitIncrement());
      }
    };

    mPluginsPane = new JTaskPane();
    mPluginsPane.add(mFunctionGroup);

    mActionsPane = new JScrollPane(mPluginsPane);

    mConfigBtn = new JButton(mLocalizer.msg("config", "Configure view"));
    mConfigBtn.setIcon(TVBrowserIcons.preferences(TVBrowserIcons.SIZE_SMALL));

    ButtonBarBuilder2 buttonBuilder = new ButtonBarBuilder2();

    buttonBuilder.addButton(mConfigBtn);
    mConfigBtn.setVisible(showSettings);

    if (pluginsSize == null) {
      mActionsPane.setPreferredSize(new Dimension(250, 500));
    } else {
      mActionsPane.setPreferredSize(pluginsSize);
    }

    if (ProgramInfo.getInstance().getSettings().getShowFunctions()) {
      JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
      split.setDividerSize(5);
      split.setContinuousLayout(true);
      split.setDividerLocation(mActionsPane.getPreferredSize().width + 1);
      split.setLeftComponent(mActionsPane);
      split.setRightComponent(scrollPane);
      mMainPanel.add(split, BorderLayout.CENTER);
      mFindAsYouType.installKeyListener(split);
    } else {
      final JButton functions = new JButton(mLocalizer.msg("functions",
          "Functions"));
      functions.setFocusable(false);

      functions.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          if (e.getClickCount() == 1) {
            JPopupMenu popupMenu = PluginProxyManager.createPluginContextMenu(
                mProgram, ProgramInfoProxy.getInstance());
            popupMenu.show(functions, e.getX(), e.getY()
                - popupMenu.getPreferredSize().height);
          }
        }
      });

      buttonBuilder.addUnrelatedGap();
View Full Code Here

TOP

Related Classes of javax.swing.JPopupMenu$AccessibleJPopupMenu

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.