Package javax.swing

Examples of javax.swing.ListModel


      }
    }
  }

  private void addToPrograms() {
    ListModel list = getModel();
    addToPrograms(0, list.getSize() - 1);
  }
View Full Code Here


    ListModel list = getModel();
    addToPrograms(0, list.getSize() - 1);
  }

  private void addToPrograms(int indexFirst, int indexLast) {
    ListModel list = getModel();
    for (int i = indexFirst; i <= indexLast; i++) {
      Object element = list.getElementAt(i);
      if (element instanceof Program) {
        Program prg = (Program) element;
        prg.addChangeListener(this);
        mPrograms.add(prg);
      }
View Full Code Here

            } catch (Exception e) {
                logger.error(e, e);
            }

            ListCellRenderer renderer = list.getCellRenderer();
            ListModel dataModel = list.getModel();
            ListSelectionModel selModel = list.getSelectionModel();
            if ((renderer == null) || (dataModel.getSize() == 0))
                return;

            // Compute the area we're going to paint in terms of the affected
            // columns/rows (firstPaintColumn, firstPaintRow, lastPaintColumn,
            // lastPaintRow), and the clip bounds.
            Rectangle paintBounds = g.getClipBounds();
  
            int firstPaintColumn = convertXToColumn(paintBounds.x);
            int firstPaintRow = convertYToRow(paintBounds.y);
            int lastPaintColumn = convertXToColumn((paintBounds.x+ paintBounds.width) - 1);
            int lastPaintRow = convertYToRow((paintBounds.y + paintBounds.height) - 1);
  
            if (firstPaintRow == -1)
                firstPaintRow = 0;

            if (lastPaintRow == -1)
                lastPaintRow = (dataModel.getSize()-1)/columnsPerRow;
           
            if (firstPaintColumn == -1)
                firstPaintColumn = 0;

            if (lastPaintColumn == -1)
                lastPaintColumn = columnsPerRow-1;
  
            Rectangle itemBounds = getCellBoundsPerColumnRow(list, firstPaintColumn, firstPaintRow);
            if (itemBounds == null)
                return;
  
            int leadIndex = list.getLeadSelectionIndex();
            int startItemBoundX = itemBounds.x;
  
            for(int row = firstPaintRow; row <= lastPaintRow; row++) {
                itemBounds.x = startItemBoundX;

                for(int column = firstPaintColumn; column <= lastPaintColumn; column++) {
                    int index = row * columnsPerRow + column;
                    if(index >= dataModel.getSize())
                        break;
                   
                    itemBounds.width  = getItemWidth(index);
                    itemBounds.height = getItemHeight(index);
  
View Full Code Here

            // scanning through the entire model.  Note: if the renderer is
            // null, we just set cellWidth and cellHeights[*] to zero,
            // if they're not set already.
            if ((fixedCellWidth == -1) || (fixedCellHeight == -1)) {
       
                ListModel dataModel = list.getModel();
                int dataModelSize = dataModel.getSize();
                ListCellRenderer renderer = list.getCellRenderer();
       
                if (renderer != null) {
                    for(int index = 0; index < dataModelSize; index++) {
                        Object value = dataModel.getElementAt(index);
                        Component c = renderer.getListCellRendererComponent(list, value, index, false, false);
                        rendererPane.add(c);
                        Dimension cellSize = c.getPreferredSize();
                        int column = index%columnsPerRow;
                        int row    = index/columnsPerRow;
View Full Code Here

            int fixedCellWidth  = list.getFixedCellWidth();
           
            if (fixedCellWidth != -1) {
                maxColumns = width/fixedCellWidth;
            } else {
                ListModel dataModel = list.getModel();
                int nItems = dataModel.getSize();
                ListCellRenderer renderer = list.getCellRenderer();
       
                if (renderer != null) {
                    Dimension[] cellDims = new Dimension[nItems];
                    for(int index = 0; index < nItems; index++) {
                        Object value = dataModel.getElementAt(index);
                        Component c = renderer.getListCellRendererComponent(list, value, index, false, false);
                        rendererPane.add(c);
                        cellDims[index] = c.getPreferredSize();
                    }
   
View Full Code Here

  private class PropertyChangeHandler implements PropertyChangeListener {
    public void propertyChange(PropertyChangeEvent event) {
      String name = event.getPropertyName();
      if (name.equals(JIconView.MODEL_PROPERTY)) {
        ListModel model = (ListModel) event.getOldValue();
        if (model != null)
          model.removeListDataListener(dataListener);
        model = (ListModel) event.getNewValue();
        if (model != null) {
          dataListener = new ListDataHandler();
          model.addListDataListener(dataListener);
        }
      } else if (
        name.equals(JIconView.XCELLSIZE_PROPERTY)
          || name.equals(JIconView.YCELLSIZE_PROPERTY)
          || name.equals(JIconView.ICONTEXTSPACING_PROPERTY)) {
View Full Code Here

    }
  }

  public void setProperty(String name, Object value) throws GUIException {
    if (name.startsWith("item.")) {
      ListModel model = list.getModel();
      if (!(model instanceof DefaultListModel))
        list.setModel(new DefaultListModel());
      ((DefaultListModel) model).addElement(value);
    } else if ("indexkey".equals(name)) {
      indexKey = (String) value;
View Full Code Here

  }

  /* ========== Model ========== */

  public void setModel(ListModel model) {
    ListModel old = this.model;
    this.model = model;
    firePropertyChange(MODEL_PROPERTY, old, model);
  }
View Full Code Here

    return new IconViewUI();
  }

  public void installUI(JComponent component) {
    view = (JIconView) component;
    ListModel model = view.getModel();
    if (model != null) {
      dataListener = new ListDataHandler();
      model.addListDataListener(dataListener);
    }
    changeListener = new PropertyChangeHandler();
    mouseListener = new MouseInputHandler();
    focusListener = new FocusHandler();
    selectionListener = new ListSelectionHandler();
View Full Code Here

    view.removePropertyChangeListener(changeListener);
    view.removeFocusListener(focusListener);
    view.removeMouseListener(mouseListener);
    view.removeListSelectionListener(selectionListener);
    view.removeMouseMotionListener(motionListener);
    ListModel model = view.getModel();
    if (model != null)
      model.removeListDataListener(dataListener);
    view.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0));
    view.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0));
    view.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
    view.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
  }
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.