Package java.awt.event

Examples of java.awt.event.MouseAdapter


    mSearchButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        showConfigureDialog(mText);
      };
    });
    mSearchButton.addMouseListener(new MouseAdapter() {

      @Override
      public void mousePressed(MouseEvent e) {
        showConfigureDialog(mText);
      }
View Full Code Here


  }

  private void createList() {
    mList = new SortableItemList();

    mList.getList().addMouseListener(new MouseAdapter() {
      @Override
      public void mouseReleased(MouseEvent evt) {
        if (evt.getX() < mSelectionWidth) {
          int index = mList.getList().locationToIndex(evt.getPoint());
          if (index != -1) {
View Full Code Here

      pb.setDefaultDialogBorder();

      mConfigurations = new SortableItemList("",GlobalPluginProgramFormatingManager.getInstance().getAvailableGlobalPluginProgramFormatings());
      mConfigurations.getList().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      mConfigurations.getList().addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
          if(SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2) {
            LocalPluginProgramFormatingSettingsDialog.createInstance(UiUtilities.getLastModalChildOf(MainFrame.getInstance()), (AbstractPluginProgramFormating)mConfigurations.getList().getSelectedValue(), GlobalPluginProgramFormatingManager.getDefaultConfiguration(), true, true);
            mConfigurations.getList().repaint();
          }
View Full Code Here

          return comp.getLocation().y+comp.getHeight() <=rect.getHeight();
        }
    }

    private static void addMouseAdapter(final JComponent c) {
      c.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
          if(e.isPopupTrigger()) {
            ContextMenu menu = new ContextMenu(c);
            menu.show(e.getX(), e.getY());
          }
View Full Code Here

    setMainframeMenusEnabled(false);
    init();
  }

  private void addMouseAdapterForHandCursorToComponent(final JComponent c) {
    c.addMouseListener(new MouseAdapter() {
      public void mouseEntered(MouseEvent e) {
        getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      }

      public void mouseExited(MouseEvent e) {
View Full Code Here

    mModel = model;
    loadSettings();
    mContextMenu = new ContextMenu(this);
    setFloatable(false);
    update();
    addMouseListener(new MouseAdapter() {

      public void mousePressed(MouseEvent e) {
        if (e.isPopupTrigger()) {
          mContextMenu.show(e.getX(), e.getY());
        }
View Full Code Here

    Boolean isSelected = (Boolean) action.getValue(ACTION_IS_SELECTED);
    if (isSelected != null) {
      button.setSelected(isSelected.booleanValue());
    }
    button.setBorderPainted(isSelected != null && isSelected.booleanValue());
    button.addMouseListener(new MouseAdapter() {
      public void mouseEntered(MouseEvent e) {
        if (!button.isSelected()) {
          button.setBorderPainted(true);
        }
      }
View Full Code Here

    if(action.equals(((DefaultToolBarModel)mModel).getUpdateAction())) {
      mUpdateButton = button;
    }

    button.addMouseListener(new MouseAdapter() {
      public void mouseEntered(MouseEvent e) {
        button.setBorderPainted(true);
      }

      public void mouseExited(MouseEvent e) {
View Full Code Here

  /**
   * Adds a mouse listener to the channel list
   */
  private void restoreForPopup() {
    final MouseAdapter listener = new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        if (SwingUtilities.isRightMouseButton(e)) {
          final ChannelJList channelJList = (ChannelJList) e.getSource();
          channelJList.setSelectedIndex(channelJList
              .locationToIndex(e.getPoint()));
View Full Code Here

    mDoc = (ExtendedHTMLDocument) mInfoEP.getDocument();

    mInfoEP.setEditable(false);

    mInfoEP.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        if (SwingUtilities.isLeftMouseButton(e) && (e.getClickCount() == 1)
            && e.getModifiersEx() == 0) {
          handleEvent(e, false);
        }
      }

      public void mousePressed(MouseEvent e) {
        if (e.isPopupTrigger()) {
          handleEvent(e, true);
        }
      }

      public void mouseReleased(MouseEvent e) {
        if (e.isPopupTrigger()) {
          handleEvent(e, true);
        }
      }

      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());
View Full Code Here

TOP

Related Classes of java.awt.event.MouseAdapter

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.