Example #1
0
  private void showContextMenu(JList characterList, MouseEvent mouseEvent) {
    // TODO: handle right-click outside of selected range correctly (should treat as single
    // selection, but not deselect)
    boolean multipleSelected = herolabsCharacterList.getSelectedValues().length > 1;
    if (mouseEvent.isPopupTrigger() && mouseEvent.getClickCount() == 1) {
      if (!multipleSelected) {
        herolabsCharacterList.setSelectedIndex(
            herolabsCharacterList.locationToIndex(mouseEvent.getPoint()));
      }

      if (contextMenuEnabled) {
        JPopupMenu menu = new JPopupMenu();
        JMenuItem menuItem;

        menuItem = new JMenuItem("Configure character" + (multipleSelected ? "s" : "") + "...");
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                configureSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menuItem = new JMenuItem("Configure using portfolio defaults");
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                resetToDefaultsForSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menuItem = new JMenuItem("Export character" + (multipleSelected ? "s" : ""));
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                exportSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menuItem = new JMenuItem("Clear configuration" + (multipleSelected ? "s" : ""));
        menuItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {
                clearConfigForSelectedCharacters();
              }
            });
        menu.add(menuItem);

        menu.show(characterList, mouseEvent.getX(), mouseEvent.getY());
      }
    }
  }
Example #2
0
 @Override
 public void mousePressed(MouseEvent e) {
   JList list = (JList) e.getComponent();
   Point pt = e.getPoint();
   int index = list.locationToIndex(pt);
   if (index >= 0) {
     JButton button = getButton(list, pt, index);
     if (Objects.nonNull(button)) {
       listRepaint(list, list.getCellBounds(index, index));
     }
   }
 }
Example #3
0
 @Override
 public void mousePressed(MouseEvent e) {
   // JList list = (JList) e.getComponent();
   Point pt = e.getPoint();
   int index = list.locationToIndex(pt);
   if (index >= 0) {
     JButton button = getButton(list, pt, index);
     if (Objects.nonNull(button)) {
       ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer();
       renderer.pressedIndex = index;
       renderer.button = button;
       listRepaint(list, list.getCellBounds(index, index));
     }
   }
 }
Example #4
0
 @Override
 public void mouseMoved(MouseEvent e) {
   JList list = (JList) e.getComponent();
   Point pt = e.getPoint();
   int index = list.locationToIndex(pt);
   if (!list.getCellBounds(index, index).contains(pt)) {
     if (prevIndex >= 0) {
       Rectangle r = list.getCellBounds(prevIndex, prevIndex);
       listRepaint(list, r);
     }
     index = -1;
     prevButton = null;
     return;
   }
   if (index >= 0) {
     JButton button = getButton(list, pt, index);
     ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer();
     if (Objects.nonNull(button)) {
       renderer.rolloverIndex = index;
       if (!button.equals(prevButton)) {
         Rectangle r = list.getCellBounds(prevIndex, index);
         listRepaint(list, r);
       }
     } else {
       renderer.rolloverIndex = -1;
       Rectangle r = null;
       if (prevIndex == index) {
         if (prevIndex >= 0 && Objects.nonNull(prevButton)) {
           r = list.getCellBounds(prevIndex, prevIndex);
         }
       } else {
         r = list.getCellBounds(index, index);
       }
       listRepaint(list, r);
       prevIndex = -1;
     }
     prevButton = button;
   }
   prevIndex = index;
 }
Example #5
0
 public void mouseClicked(MouseEvent e) {
   if (e.getSource() == userList && e.getClickCount() == 2) {
     int index = userList.locationToIndex(e.getPoint());
     if (index > -1) {
       String userInfo = (String) ((DefaultListModel) userList.getModel()).get(index);
       link.running = false;
       userInfo = userInfo.substring(userInfo.indexOf("@") - 1);
       link =
           new LeetClient(
               userInfo.substring(userInfo.indexOf("@") + 1, userInfo.indexOf(":")),
               Integer.parseInt(userInfo.substring(userInfo.indexOf(":") + 1)),
               address,
               directory);
       link.setPasv(portItem.getState());
       link.command = "LIST";
       link.start();
     }
   }
   if (e.getSource() == fileList && e.getClickCount() == 2) {
     int index = fileList.locationToIndex(e.getPoint());
     if (index > -1) {
       String fileName = (String) ((DefaultListModel) fileList.getModel()).get(index);
       if (fileName.indexOf(" ") > -1) {
         fileName = fileName.substring(0, fileName.indexOf(" "));
       }
       link.command = "RETR " + fileName;
       System.out.println(link.command);
     }
   }
   if (e.getSource() == connectButton) {
     if (connectButton.getText().equals("Disconnect")) {
       active.running = false;
       connectButton.setText("Connect");
     } else {
       active =
           new LeetActive(
               serverTextField.getText(),
               Integer.parseInt(portTextField.getText()),
               SERVER_PORT);
       active.setUserName(nameTextField.getText());
       active.start();
       connectButton.setText("Disconnect");
     }
   }
   if (e.getSource() == searchInit) {
     search = new SearchUsers();
     search.start();
   }
   if (e.getSource() == searchList && e.getClickCount() == 2) {
     int index = searchList.locationToIndex(e.getPoint());
     if (index > -1) {
       String fileInfo = (String) ((DefaultListModel) searchList.getModel()).get(index);
       link.running = false;
       String userInfo = fileInfo.substring(fileInfo.indexOf("@") + 1);
       userInfo = userInfo.substring(userInfo.indexOf("@") - 1);
       fileInfo = fileInfo.substring(0, fileInfo.indexOf("@"));
       link =
           new LeetClient(
               userInfo.substring(userInfo.indexOf("@") + 1, userInfo.indexOf(":")),
               Integer.parseInt(userInfo.substring(userInfo.indexOf(":") + 1)),
               address,
               directory);
       link.setPasv(portItem.getState());
       link.command = "RETR " + fileInfo;
       link.start();
     }
   }
 }