javax.swing.JList#locationToIndex ( )源码实例Demo

下面列出了javax.swing.JList#locationToIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: wpcleaner   文件: AbstractPageListPopupListener.java
/**
 * Show popup menu in response to a mouse event.
 * 
 * @param e Event.
 */
@Override
protected void showPopup(MouseEvent e) {

  // Retrieve information
  if (!(e.getComponent() instanceof JList)) {
    return;
  }
  JList tmpList = (JList) e.getComponent();
  int position = tmpList.locationToIndex(e.getPoint());
  if (position < 0) {
    return;
  }
  Object object = tmpList.getModel().getElementAt(position);
  if (!(object instanceof Page)) {
    return;
  }
  Page link = (Page) object;
  showPopup(tmpList, link, e.getX(), e.getY());
}
 
源代码2 项目: marathonv5   文件: JideCheckBoxListItemElement.java
public static boolean clicksInCheckBox(Point e, JList list) {
    int index = list.locationToIndex(e);
    int hotspot = new JCheckBox().getPreferredSize().width;
    Rectangle bounds = list.getCellBounds(index, index);
    if (bounds != null) {
        if (list.getComponentOrientation().isLeftToRight()) {
            return e.getX() < bounds.x + hotspot;
        } else {
            return e.getX() > bounds.x + bounds.width - hotspot;
        }
    } else {
        return false;
    }
}
 
源代码3 项目: netbeans   文件: ViewTooltips.java
private void showJList (JScrollPane view, Point pt) {
    JList list = (JList) view.getViewport().getView();
    Point p = SwingUtilities.convertPoint(view, pt.x, pt.y, list);
    int row = list.locationToIndex(p);
    if (row == -1) {
        hide();
        return;
    }
    Rectangle bds = list.getCellBounds(row, 
            row);
    //GetCellBounds returns a width that is the
    //full component width;  we want only what
    //the renderer really needs.
    ListCellRenderer ren = list.getCellRenderer();
    Dimension rendererSize = 
            ren.getListCellRendererComponent(list, 
            list.getModel().getElementAt(row), 
            row, false, false).getPreferredSize();
    
    bds.width = rendererSize.width;
    if (bds == null || !bds.contains(p)) {
        hide();
        return;
    }
    if (setCompAndRow (list, row)) {
        Rectangle visible = getShowingRect (view);
        Rectangle[] rects = getRects (bds, visible);
        if (rects.length > 0) {
            ensureOldPopupsHidden();
            painter.configure(
                    list.getModel().getElementAt(row), 
                    view, list, row);
            showPopups (rects, bds, visible, list, view);
        } else {
            hide();
        }
    }
}
 
源代码4 项目: netbeans   文件: EventsBreakpointCustomizer.java
private String getSelectedText(JList list, MouseEvent e) {
    int index = list.locationToIndex(e.getPoint());
    if (index >= 0) {
        int x = e.getX();
        if (x < checkBoxWidth) {
            return (String) list.getModel().getElementAt(index);
        }
    }
    return null;
}
 
源代码5 项目: netbeans   文件: CheckListener.java
@Override
public void mouseClicked(MouseEvent e) {
    if (e.isPopupTrigger()) {
        return;
    }
    if (!(e.getSource() instanceof JList)) {
        return;
    }
    JList list = (JList) e.getSource();
    int index = list.locationToIndex(e.getPoint());
    if (index < 0) {
        return;
    }
    toggle(list.getModel().getElementAt(index));
}
 
源代码6 项目: Bytecoder   文件: SwingUtilities2.java
/**
 * A variation of locationToIndex() which only returns an index if the
 * Point is within the actual bounds of a list item (not just in the cell)
 * and if the JList has the "List.isFileList" client property set.
 * Otherwise, this method returns -1.
 * This is used to make Windows {@literal L&F} JFileChooser act
 * like native dialogs.
 */
public static int loc2IndexFileList(JList<?> list, Point point) {
    int index = list.locationToIndex(point);
    if (index != -1) {
        Object bySize = list.getClientProperty("List.isFileList");
        if (bySize instanceof Boolean && ((Boolean)bySize).booleanValue() &&
            !pointIsInActualBounds(list, index, point)) {
            index = -1;
        }
    }
    return index;
}
 
源代码7 项目: megamek   文件: CommonSettingsDialog.java
@Override
public void mouseDragged(MouseEvent e) {
    Object src = e.getSource();
    if (mouseDragging && (src instanceof JList)) {
        JList<?> srcList = (JList<?>) src;
        DefaultListModel<?> srcModel = (DefaultListModel<?>) srcList.getModel();
        int currentIndex = srcList.locationToIndex(e.getPoint());
        if (currentIndex != dragSourceIndex) {
            int dragTargetIndex = srcList.getSelectedIndex();
            moveElement(srcModel, dragSourceIndex, dragTargetIndex);
            dragSourceIndex = currentIndex;
        }
    }
}
 
源代码8 项目: megamek   文件: WeaponPanel.java
@Override
public void mouseDragged(MouseEvent e) {
    removeListeners();
    
    Object src = e.getSource();
    // Check to see if we are in a state we care about
    if (!mouseDragging || !(src instanceof JList)) {
        return;
    }
    JList<?> srcList = (JList<?>) src;
    WeaponListModel srcModel = (WeaponListModel) srcList.getModel();
    int currentIndex = srcList.locationToIndex(e.getPoint());
    if (currentIndex != dragSourceIndex) {
        int dragTargetIndex = srcList.getSelectedIndex();
        Mounted weap1 = srcModel.getWeaponAt(dragSourceIndex);
        srcModel.swapIdx(dragSourceIndex, dragTargetIndex);
        dragSourceIndex = currentIndex;
        Entity ent = weap1.getEntity();
        // Is the sort order custom?
        int customId = Entity.WeaponSortOrder.CUSTOM.ordinal();
        // Update weap sort order drop down
        if (weapSortOrder.getSelectedIndex() != customId) {
            // Set the order to custom
            ent.setWeaponSortOrder(Entity.WeaponSortOrder.CUSTOM);
            weapSortOrder.setSelectedIndex(customId);
        }
        // Update custom order
        for (int i = 0; i < srcModel.getSize(); i++) {
            Mounted m = srcModel.getWeaponAt(i);
            ent.setCustomWeaponOrder(m, i);
        }
        if (unitDisplay.getClientGUI() != null) {
            unitDisplay.getClientGUI().getMenuBar()
                    .updateSaveWeaponOrderMenuItem();
        }
    }
    addListeners();
}
 
源代码9 项目: mzmine2   文件: FontBoxRenderer.java
private void manItemInCombo() {
  if (comboBox.getItemCount() > 0) {
    final Object comp = comboBox.getUI().getAccessibleChild(comboBox, 0);
    if ((comp instanceof JPopupMenu)) {
      final JList list = new JList(comboBox.getModel());
      final JPopupMenu popup = (JPopupMenu) comp;
      final JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
      final JViewport viewport = scrollPane.getViewport();
      final Rectangle rect = popup.getVisibleRect();
      final Point pt = viewport.getViewPosition();
      row = list.locationToIndex(pt);
    }
  }
}
 
源代码10 项目: wpcleaner   文件: PageListAnalyzeListener.java
@Override
public void mouseClicked(MouseEvent e) {
  if (e.getButton() != MouseEvent.BUTTON1) {
    return;
  }
  if (e.getClickCount() != 2) {
    return;
  }
  if (!(e.getComponent() instanceof JList)) {
    return;
  }
  JList list = (JList) e.getComponent();
  int position = list.locationToIndex(e.getPoint());
  if (position < 0) {
    return;
  }
  Object object = list.getModel().getElementAt(position);
  if (!(object instanceof Page)) {
    return;
  }
  Page page = (Page) object;
  ArrayList<Page> knownPages = null;
  if ((pageWindow != null) && (pageWindow.getPage() != null)) {
    Page basePage = pageWindow.getPage();
    knownPages = new ArrayList<Page>(1);
    knownPages.add(basePage);
    for (Page backLink : basePage.getAllLinksToPage()) {
      PageRedirect redirects = backLink.getRedirects();
      if ((redirects != null) &&
          (redirects.isRedirect()) &&
          (Page.areSameTitle(basePage.getTitle(), redirects.getTitle()))) {
        knownPages.add(backLink);
      }
    }
  }
  OnePageAnalysisWindow.createAnalysisWindow(page.getTitle(), knownPages, wikipedia);
}
 
源代码11 项目: yeti   文件: ForwardLookupInit.java
public void mouseClicked(MouseEvent event) {
    JList list = (JList) event.getSource();
    int index = list.locationToIndex(event.getPoint());
    CheckListItem item = (CheckListItem) list.getModel().getElementAt(index);
    item.setSelected(!item.isSelected());
    list.repaint(list.getCellBounds(index, index));
}
 
源代码12 项目: marathonv5   文件: JListJavaElement.java
public static int getIndexAt(JList list, Point point) {
    if (point == null)
        return list.getSelectedIndex();
    return list.locationToIndex(point);
}