Package javax.swing

Examples of javax.swing.ListModel


  public void paint(Graphics g, JComponent component) {
    if (component != view || view.getModel() == null)
      return;
    Graphics2D g2 = (Graphics2D) g;

    ListModel model = view.getModel();
    Rectangle paintBounds = g.getClipBounds();
    Insets insets = view.getInsets();
    Dimension size = view.getSize();
    int modelSize = model.getSize();
    int xcell = view.getXCellSize(), ycell = view.getYCellSize(), counter = 0;
    metrics = g.getFontMetrics(view.getFont());
   
    if (metrics == null) {
      throw new RuntimeException("Could not resolve font metrics");
    }

    textHeight = metrics.getHeight();

    /* Fix sizes */
    if (paintBounds.x < insets.left)
      paintBounds.x = insets.left;
    if (paintBounds.width > size.width - insets.left - insets.right)
      paintBounds.width = size.width - insets.left - insets.right;
    if (paintBounds.y < insets.top)
      paintBounds.y = insets.top;
    if (view.getParent() instanceof JViewport) {
      paintBounds.height += 2 * ycell;
      if (paintBounds.height > size.height - insets.top - insets.bottom + ycell)
        paintBounds.height = size.height - insets.top - insets.bottom + ycell;
    } else {
      if (paintBounds.height > size.height - insets.top - insets.bottom)
        paintBounds.height = size.height - insets.top - insets.bottom;
    }

    /* Clear background */
    g.setColor(view.getBackground());
    g.fillRect(paintBounds.x, paintBounds.y, paintBounds.width, paintBounds.height);
    g.setColor(view.getForeground());

    int result[] = new int[(paintBounds.width / xcell) * (paintBounds.height / ycell)];
    for (int y = paintBounds.y; y < paintBounds.y + paintBounds.height; y += ycell) {
      for (int x = paintBounds.x; x <= paintBounds.x + paintBounds.width; x += xcell) {
        int index = getIndexForXY(x, y);
        if (index == -1)
          continue;
        int pos[] = getRowColumnForIndex(index);
        int xpos = convertColumnToX(pos[1]);
        int ypos = convertRowToY(pos[0]);
        IconElement element = (IconElement) model.getElementAt(index);
        ImageIcon icon = element.getIcon();
        String name = element.getText();
        int stringWidth = metrics.stringWidth(name);
        int iconHeight = icon.getIconHeight();
        int spacing = view.getIconTextSpacing();
View Full Code Here


    public void setSelectedModule(int index) {
      moduleList.setSelectedModule(index);
    }
   
    public void rebuild() {
        ListModel model = moduleList.getModel();
        if (model instanceof DefaultListModel) {
            ((DefaultListModel) model).clear();   
        } else {
            moduleList.setModel(new DefaultListModel());
        }
View Full Code Here

                deselect();

                int[] indicies = resultsList.getSelectedIndices();
                ImageTile[] selectedTiles = new ImageTile[indicies.length];
                if (indicies.length > 0) {
                    ListModel listModel = getListModel();
                    for (int i = 0; i < indicies.length; i++) {
                        selectedTiles[i] = (ImageTile) listModel.getElementAt(indicies[i]);
                    }
                }
                setSelectedTiles(selectedTiles);
            }
        }
View Full Code Here

    if (notUseColsList.getModel().getSize() == 0) {
      _editWhereCols.put(_unambiguousTableName, null);
    }
    else {
      // some cols are not to be used
      ListModel useColsModel = useColsList.getModel();
     
      // do not let user remove everything from the list
      if (useColsModel.getSize() == 0) {
        JOptionPane.showMessageDialog(this,
          // i18n[editWhereColsPanel.cannotRemoveAllCols=You cannot remove all of the fields from the 'use columns' list.]
          s_stringMgr.getString("editWhereColsPanel.cannotRemoveAllCols"));
        return false;
      }
     
      // create the HashMap of names to use and put it in EditWhereCols
      HashMap<String, String> useColsMap =
                new HashMap<String, String>(useColsModel.getSize());
     
      for (int i=0; i< useColsModel.getSize(); i++) {
        useColsMap.put((String)useColsModel.getElementAt(i),
                               (String)useColsModel.getElementAt(i));
      }
     
      _editWhereCols.put(_unambiguousTableName, useColsMap);
    }
    return true;
View Full Code Here

   * Move selected fields from "used" to "not used"
   */
  private void moveToNotUsed() {
   
    // get the values from the "not use" list and convert to sorted set
    ListModel notUseColsModel = notUseColsList.getModel();
    SortedSet<String> notUseColsSet = new TreeSet<String>();
    for (int i=0; i<notUseColsModel.getSize(); i++)
      notUseColsSet.add((String)notUseColsModel.getElementAt(i));
   
    // get the values from the "use" list
    ListModel useColsModel = useColsList.getModel();
   
    // create an empty set for the "use" list
    SortedSet<Object> useColsSet = new TreeSet<Object>();

    // for each element in the "use" set, if selected then add to "not use",
    // otherwise add to new "use" set
    for (int i=0; i<useColsModel.getSize(); i++) {
      String colName = (String)useColsModel.getElementAt(i);
      if (useColsList.isSelectedIndex(i))
        notUseColsSet.add(colName);
      else useColsSet.add(colName);
    }
   
View Full Code Here

  /**
   * Move selected fields from "not used" to "used"
   */
  private void moveToUsed() {
    // get the values from the "use" list and convert to sorted set
    ListModel useColsModel = useColsList.getModel();
    SortedSet<String> useColsSet = new TreeSet<String>();
    for (int i=0; i<useColsModel.getSize(); i++)
      useColsSet.add((String)useColsModel.getElementAt(i));
   
    // get the values from the "not use" list
    ListModel notUseColsModel = notUseColsList.getModel();
   
    // create an empty set for the "not use" list
    SortedSet<Object> notUseColsSet = new TreeSet<Object>();

    // for each element in the "not use" set, if selected then add to "use",
    // otherwise add to new "not use" set
    for (int i=0; i<notUseColsModel.getSize(); i++) {
      String colName = (String)notUseColsModel.getElementAt(i);
      if (notUseColsList.isSelectedIndex(i))
        useColsSet.add(colName);
      else notUseColsSet.add(colName);
    }
   
View Full Code Here

            PrimaryKeyInfo pkInfo = primaryKeyInfos[i];
            pkCols.add(pkInfo.getColumnName());
        }
       
        ArrayList<String> newNotUseList = new ArrayList<String>();
        ListModel useColsModel = useColsList.getModel();
        ListModel notUseColsModel = notUseColsList.getModel();
       
        for (int i=0; i<useColsModel.getSize(); i++) {
            Object colName = useColsModel.getElementAt(i);
            if (!pkCols.contains(colName)) {
                newNotUseList.add(colName.toString());
            }
        }       
       
        for (int i=0; i<notUseColsModel.getSize(); i++) {
            Object colName = notUseColsModel.getElementAt(i);
            if (!pkCols.contains(colName)) {
                newNotUseList.add(colName.toString());
            }
        }
       
View Full Code Here

        }
        this.bold.setSelected(font.isBold());
        this.italic.setSelected(font.isItalic());

        final String fontName = font.getName();
        ListModel model = this.fontlist.getModel();
        this.fontlist.clearSelection();
        for (int i = 0; i < model.getSize(); i++) {
            if (fontName.equals(model.getElementAt(i))) {
                this.fontlist.setSelectedIndex(i);
                break;
            }
        }

        final String fontSize = String.valueOf(font.getSize());
        model = this.sizelist.getModel();
        this.sizelist.clearSelection();
        for (int i = 0; i < model.getSize(); i++) {
            if (fontSize.equals(model.getElementAt(i))) {
                this.sizelist.setSelectedIndex(i);
                break;
            }
        }
View Full Code Here

    }
   
    this.catalogFurnitureList.clearSelection();
    List<CatalogPieceOfFurniture> selectedFurniture = controller.getSelectedFurniture();
    if (selectedFurniture.size() > 0) {
      ListModel model = this.catalogFurnitureList.getModel();
      List<Integer> selectedIndices = new ArrayList<Integer>();
      for (CatalogPieceOfFurniture piece : selectedFurniture) {
        for (int i = 0, n = model.getSize(); i < n; i++) {
          if (piece == model.getElementAt(i)) {
            selectedIndices.add(i);
            break;         
          }
        }
      }
View Full Code Here

        SELECTION_MODES.get(list.getSelectionMode()), list.isEnabled(), list.isVisible(), list.isShowing());
  }

  private @Nonnull Object[] contentsOf(JList list) {
    List<Object> contents = newArrayList();
    ListModel model = list.getModel();
    int size = model.getSize();
    for (int i = 0; i < size; i++) {
      contents.add(model.getElementAt(i));
    }
    return contents.toArray();
  }
View Full Code Here

TOP

Related Classes of javax.swing.ListModel

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.