All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codename1.ui.html.MultiComboBox Maven / Gradle / Ivy

There is a newer version: 7.0.161
Show newest version
/*
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores
 * CA 94065 USA or visit www.oracle.com if you need additional information or
 * have any questions.
 */
package com.codename1.ui.html;

import com.codename1.ui.ComboBox;
import com.codename1.ui.Component;
import com.codename1.ui.Display;
import com.codename1.ui.Graphics;
import com.codename1.ui.List;
import com.codename1.ui.list.DefaultListCellRenderer;
import com.codename1.ui.list.DefaultListModel;
import com.codename1.ui.list.ListCellRenderer;
import com.codename1.ui.list.ListModel;
import java.util.Vector;

/**
 * A ComboBox control that allows multiple selection and supports OPTGROUP labels.
 * Note that this does not inherit from ComboBox but rather from List, since basically like an HTML multiple ComboBox we show an open List 
 * The List/Combo size is controlled from the outside in HTMLComponent using a wrapping Container.
 *
 * This class is also used by HTMLComboBox as the list popup when opening the HTMLComboBox (To allow OPTGROUP support)
 *
 * @author Ofir Leitner
 */
class MultiComboBox extends List {

    private boolean multiple; // true if this is a multiple choice combo
    private MultiListModel model; 

    MultiComboBox(boolean multiple) {
        this(null,multiple);
    }


    MultiComboBox(ListModel underlyingModel, boolean multiple) {
        super();
        setUIID("ComboBox");
        this.multiple=multiple;
        setScrollToSelected(!multiple); // In multiple comboboxes we don't scroll to selected, as there can be several
        model=new MultiListModel(underlyingModel,multiple);
        setModel(model);
        MultiCellRenderer multiRenderer=new MultiCellRenderer(model);
        setRenderer(multiRenderer);
        if (underlyingModel!=null) { // Need to scan the existing data since there will be no "addItem" with an optgroup item
            for(int i=0;i0) {
                if (model.getItemAt(selectedIndex-1) instanceof String) {
                    if (selectedIndex==1) { // First item is an optgroup
                        return;
                    }
                    model.setDirection(-1);
                    selectedIndex--;
                    model.setSelectedIndex(selectedIndex);
                }
            }
        } else if (gameAction == keyFwd) {
            if (selectedIndex




© 2015 - 2024 Weber Informatics LLC | Privacy Policy