Example usage for java.awt.event MouseAdapter MouseAdapter

List of usage examples for java.awt.event MouseAdapter MouseAdapter

Introduction

In this page you can find the example usage for java.awt.event MouseAdapter MouseAdapter.

Prototype

MouseAdapter

Source Link

Usage

From source file:krasa.cpu.CpuUsagePanel.java

public CpuUsagePanel(Project project) {
    refreshColors();// www.  j a  v  a2 s  .c  om
    this.myProject = project;
    this.projectName = project.getName();

    setOpaque(false);
    setFocusable(false);
    setToolTipText("IDE CPU usage / System CPU usage");

    setBorder(StatusBarWidget.WidgetBorder.INSTANCE);
    updateUI();

    new UiNotifyConnector(this, new Activatable() {

        @Override
        public void showNotify() {
            CpuUsageManager.register(CpuUsagePanel.this);
        }

        @Override
        public void hideNotify() {
            CpuUsageManager.unregister(CpuUsagePanel.this);
        }
    });
    MouseAdapter mouseAdapter = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
                CpuUsageManager.update();
                final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this);
                ActionManager.getInstance().getAction("TakeThreadDump").actionPerformed(new AnActionEvent(e,
                        context, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0));
            } else if (SwingUtilities.isRightMouseButton(e)) {
                final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this);
                ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, getActionGroup(),
                        context, JBPopupFactory.ActionSelectionAid.MNEMONICS, false);

                Dimension dimension = popup.getContent().getPreferredSize();
                Point at = new Point(0, -dimension.height);
                popup.show(new RelativePoint(e.getComponent(), at));
            }
        }
    };
    addMouseListener(mouseAdapter);
}

From source file:com.igormaznitsa.sciareto.ui.tree.ExplorerTree.java

public ExplorerTree(@Nonnull final Context context) {
      super();/*from   w ww .j a va2  s . co m*/
      this.projectTree = new DnDTree();
      this.context = context;
      this.projectTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
      this.projectTree.setDropMode(DropMode.ON);

      this.projectTree.setEditable(true);

      ToolTipManager.sharedInstance().registerComponent(this.projectTree);

      this.projectTree.setCellRenderer(new TreeCellRenderer());
      this.projectTree.setModel(new NodeProjectGroup(context, "."));
      this.projectTree.setRootVisible(false);
      this.setViewportView(this.projectTree);

      this.projectTree.addMouseListener(new MouseAdapter() {
          @Override
          public void mouseClicked(@Nonnull final MouseEvent e) {
              if (e.getClickCount() > 1) {
                  final int selRow = projectTree.getRowForLocation(e.getX(), e.getY());
                  final TreePath selPath = projectTree.getPathForLocation(e.getX(), e.getY());
                  if (selRow >= 0) {
                      final NodeFileOrFolder node = (NodeFileOrFolder) selPath.getLastPathComponent();
                      if (node != null && node.isLeaf()) {
                          final File file = node.makeFileForNode();
                          if (file != null && !context.openFileAsTab(file)) {
                              UiUtils.openInSystemViewer(file);
                          }
                      }
                  }
              }
          }

          @Override
          public void mouseReleased(@Nonnull final MouseEvent e) {
              if (e.isPopupTrigger()) {
                  processPopup(e);
              }
          }

          @Override
          public void mousePressed(@Nonnull final MouseEvent e) {
              if (e.isPopupTrigger()) {
                  processPopup(e);
              }
          }

          private void processPopup(@Nonnull final MouseEvent e) {
              final TreePath selPath = projectTree.getPathForLocation(e.getX(), e.getY());
              if (selPath != null) {
                  projectTree.setSelectionPath(selPath);
                  final Object last = selPath.getLastPathComponent();
                  if (last instanceof NodeFileOrFolder) {
                      makePopupMenu((NodeFileOrFolder) last).show(e.getComponent(), e.getX(), e.getY());
                  }
              }
          }

      });
  }

From source file:mulavito.gui.components.LayerDataPanel.java

public LayerDataPanel(FloatingTabbedPane owner) {
    super("Layer Data", owner);

    textArea = new JTextArea(defaultText);
    textArea.setEditable(false);// w  w  w. j a v a  2  s .  c om
    textArea.setCaretPosition(0); // Scroll up the text area.
    JScrollPane textPane = new JScrollPane(textArea);

    add(textPane, BorderLayout.CENTER);

    // updates the data
    mouseListener = new MouseAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void mouseEntered(MouseEvent e) {
            if (e.getSource() instanceof LayerViewer<?, ?>) {
                LayerViewer<V, E> vv = (LayerViewer<V, E>) e.getSource();
                showData(vv.getLayer());
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            showData(null);
        }
    };

    // adds/removes focus listeners on layers
    graphPanelListener = new PropertyChangeListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("Viewers")) {
                if (evt.getOldValue() instanceof LayerViewer<?, ?> && evt.getNewValue() == null) {
                    // GraphPanel#removeLayer
                    ((LayerViewer<?, ?>) evt.getOldValue()).removeMouseListener(mouseListener);
                } else if (evt.getOldValue() instanceof List<?>) {
                    System.out.println("Replace");
                    for (LayerViewer<?, ?> vv : ((List<LayerViewer<?, ?>>) evt.getOldValue()))
                        vv.removeMouseListener(mouseListener);
                }

                if (evt.getNewValue() instanceof LayerViewer<?, ?> && evt.getOldValue() == null) {
                    // GraphPanel#addLayer
                    ((LayerViewer<?, ?>) evt.getNewValue()).addMouseListener(mouseListener);
                } else if (evt.getNewValue() instanceof List<?>) {
                    // New Layer List on start up
                    for (LayerViewer<?, ?> vv : ((List<LayerViewer<?, ?>>) evt.getNewValue()))
                        vv.addMouseListener(mouseListener);
                }

                showData(current);
            }
        }
    };
}

From source file:net.openbyte.gui.WelcomeFrame.java

public WelcomeFrame() {
    listItems.clear();//from   ww w.j a va  2  s. c om
    Launch.projectNames.clear();
    Launch.nameToSolution.clear();
    initComponents();
    list1.setModel(listItems);
    try {
        xImagePanel1
                .setImage(ImageIO.read(getClass().getClassLoader().getResourceAsStream("openbytelogo.png")));
    } catch (IOException e) {
        e.printStackTrace();
    }
    File[] projectFiles = Files.WORKSPACE_DIRECTORY.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".openproj");
        }
    });
    for (File projectFile : projectFiles) {
        OpenProjectSolution solution = OpenProjectSolution.getProjectSolutionFromFile(projectFile);
        Launch.nameToSolution.put(solution.getProjectName(), solution);
        Launch.projectNames.add(solution.getProjectName());
    }
    for (String projectName : Launch.projectNames) {
        WelcomeFrame.listItems.addElement(projectName);
    }
    list1.addMouseListener(new MouseAdapter() {

        int lastSelectedIndex;

        public void mouseClicked(MouseEvent e) {

            int index = list1.locationToIndex(e.getPoint());

            if (index != -1 && index == lastSelectedIndex) {
                list1.clearSelection();
            }

            lastSelectedIndex = list1.getSelectedIndex();
        }
    });
}

From source file:com.floreantpos.bo.ui.explorer.ModifierExplorer.java

public ModifierExplorer() {
    setLayout(new BorderLayout(5, 5));

    currencySymbol = CurrencyUtil.getCurrencySymbol();
    tableModel = new ModifierExplorerModel();
    table = new JXTable(tableModel);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setDefaultRenderer(Object.class, new CustomCellRenderer());
    add(new JScrollPane(table));

    createActionButtons();// w  w w .  j  a va2s.co m
    add(buildSearchForm(), BorderLayout.NORTH);

    updateModifierList();

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            if (me.getClickCount() == 2) {
                doEditSelectedMenuModifier();
            }
        }
    });
}

From source file:gui.SpamPanel.java

public void generate() {
    Message[] arrMsg = GmailAPI.Spam.toArray(new Message[GmailAPI.Spam.size()]);
    SpamList = new JList(arrMsg);
    SpamList.setCellRenderer(new DefaultListCellRenderer() { // Setting the DefaultListCellRenderer
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Message message = (Message) value; // Using value we are getting the object in JList
            Map<String, String> map = null;
            try {
                map = GmailAPI.getMessageDetails(message.getId());
            } catch (MessagingException ex) {
                Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex);
            }/*  w  ww . j ava 2s . c o  m*/
            String sub = map.get("subject");
            if (map.get("subject").length() > 22) {
                sub = map.get("subject").substring(0, 20) + "...";
            }
            setText(sub); // Setting the text
            //setIcon( shape.getImage() ); // Setting the Image Icon
            return this;
        }
    });
    SpamList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    SpamList.setLayoutOrientation(JList.VERTICAL);
    SpamList.setVisibleRowCount(-1);
    jScrollPane1.setViewportView(SpamList);

    SpamList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            try {
                JList list = (JList) evt.getSource();
                int index = list.locationToIndex(evt.getPoint());
                String id = arrMsg[index].getId();
                Map<String, String> map = GmailAPI.getMessageDetails(id);
                jTextField1.setText(map.get("from"));
                jTextField2.setText(map.get("subject"));
                dateTextField.setText(map.get("senddate"));
                BodyTextPane.setText(map.get("body"));
                BodyTextPane.setContentType("text/html");
                //BodyTextArea.setCo
            } catch (IOException ex) {
                Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MessagingException ex) {
                Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:com.limegroup.gnutella.gui.CurrentAudioStatusComponent.java

private void initComponents() {
    Dimension dimension = new Dimension(220, 22);
    setPreferredSize(dimension);/* www.java 2  s.c o  m*/
    setMinimumSize(dimension);

    speakerIcon = GUIMediator.getThemeImage("speaker");

    text = new JLabel();
    Font f = new Font("DIALOG", Font.BOLD, 10);
    text.setFont(f);
    text.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (MediaPlayer.instance().getCurrentSong().getFile() != null
                    || MediaPlayer.instance().getCurrentSong().getPlaylistItem() != null
                    || MediaPlayer.instance().getCurrentSong() instanceof InternetRadioAudioSource
                    || MediaPlayer.instance().getCurrentSong() instanceof DeviceAudioSource) {
                showCurrentSong();
            } else if (MediaPlayer.instance().getCurrentSong() instanceof StreamAudioSource) {
                StreamAudioSource audioSource = (StreamAudioSource) MediaPlayer.instance().getCurrentSong();
                if (audioSource.getDetailsUrl() != null) {
                    GUIMediator.openURL(audioSource.getDetailsUrl());
                }
            } else if (MediaPlayer.instance().getCurrentSong().getURL() != null) {
                GUIMediator.instance().setWindow(GUIMediator.Tabs.LIBRARY);
            }
        }
    });

    shareButton = new MediaButton(I18n.tr("Send this file to a friend"), "share", "share");
    shareButton.addActionListener(new SendToFriendActionListener());
    shareButton.setVisible(false);

    //Share Button
    setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.insets = new Insets(0, 0, 0, 3);
    add(shareButton, c);//, BorderLayout.LINE_END);

    //Go to Current Audio Control
    c.gridx = 0;
    c.gridx = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.EAST;
    c.insets = new Insets(0, 0, 0, 0);
    add(text, c);//, BorderLayout.LINE_END);
}

From source file:com.willwinder.ugs.nbp.core.services.SettingsChangedNotificationService.java

private JComponent createRestartNotificationDetails() {
    JPanel panel = new JPanel(new BorderLayout(10, 10));
    panel.setOpaque(false);//from   www.  j  ava  2 s .  c  o m

    JLabel label = new JLabel(Localization.getString("platform.window.restart.changed.settings")); //NOI18N
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    panel.add(label, BorderLayout.CENTER);

    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (null != restartNotification) {
                restartNotification.clear();
                restartNotification = null;
            }

            LifecycleManager.getDefault().markForRestart();
            LifecycleManager.getDefault().exit();
        }
    });
    return panel;
}

From source file:model.SignatureValidation.java

public SignatureValidation(String filename, String name, PdfPKCS7 pdfPkcs7, boolean changed,
        boolean coversEntireDocument, int revision, int numRevisions, int documentCertificationLevel,
        CertificateStatus ocspCertificateStatus, CertificateStatus crlCertificateStatus, boolean validTimeStamp,
        List<AcroFields.FieldPosition> posList, SignaturePermissions signaturePermissions, boolean valid) {
    this.filename = filename;
    this.name = name;
    this.pdfPkcs7 = pdfPkcs7;
    this.changed = changed;
    this.coversEntireDocument = coversEntireDocument;
    this.revision = revision;
    this.numRevisions = numRevisions;
    this.signaturePermissions = signaturePermissions;
    this.valid = valid;
    this.ocspCertificateStatus = ocspCertificateStatus;
    this.crlCertificateStatus = crlCertificateStatus;
    this.validTimeStamp = validTimeStamp;
    this.posList = posList;
    this.panel = new JPanel();

    this.panel.setBackground(new Color(0, 0, 0, 0));
    this.panel.setToolTipText(name);
    this.panel.addMouseListener(new MouseAdapter() {
        @Override//from  w  w  w  .j a v  a2  s  .co  m
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (SwingUtilities.isLeftMouseButton(evt)) {
                if (listener != null) {
                    listener.onSignatureClick(SignatureValidation.this);
                }
            }
        }
    });
}

From source file:de.tor.tribes.ui.components.GroupSelectionList.java

public GroupSelectionList(String pResourceURL) {
    super(pResourceURL);

    setCellRenderer(renderer);/*www  . j  av a2s  . c o  m*/

    addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                fireDecrementEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                fireIncrementEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                fireResetEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_O) {
                fireSetStateEvent(ListItem.RELATION_TYPE.OR);
            } else if (e.getKeyCode() == KeyEvent.VK_U) {
                fireSetStateEvent(ListItem.RELATION_TYPE.AND);
            } else if (e.getKeyCode() == KeyEvent.VK_N) {
                fireSetStateEvent(ListItem.RELATION_TYPE.NOT);
            } else if (e.getKeyCode() == KeyEvent.VK_I) {
                fireSetStateEvent(ListItem.RELATION_TYPE.DISABLED);
            } else if (e.getKeyCode() == KeyEvent.VK_H) {
                JOptionPaneHelper.showInformationBox(GroupSelectionList.this, getRelationAsPlainText(),
                        "Information");
            }
        }
    });
    addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    fireClickedEvent(e.getPoint());
                } else {
                    fireResetEvent(e.getPoint());
                }
            }
        }
    });
    TagManager.getSingleton().addManagerListener(GroupSelectionList.this);
}