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

net.anwiba.commons.swing.combobox.ObjectComboBoxComponentBuilder Maven / Gradle / Ivy

/*
 * #%L
 *
 * %%
 * Copyright (C) 2007 - 2017 Andreas W. Bartels ([email protected])
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */
package net.anwiba.commons.swing.combobox;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import javax.swing.border.Border;

import net.anwiba.commons.swing.list.ObjectListConfigurationBuilder;
import net.anwiba.commons.swing.ui.IObjectUi;

public class ObjectComboBoxComponentBuilder {

  final ObjectListConfigurationBuilder configurationBuilder = new ObjectListConfigurationBuilder<>();
  private IComboBoxModel model;

  public ObjectComboBoxComponentBuilder setObjectUi(final IObjectUi objectUi) {
    this.configurationBuilder.setObjectUi(objectUi);
    return this;
  }

  public ObjectComboBoxComponentBuilder setSingleSelectionMode() {
    this.configurationBuilder.setSingleSelectionMode();
    return this;
  }

  public ObjectComboBoxComponentBuilder setSingleIntervalSelectionMode() {
    this.configurationBuilder.setSingleIntervalSelectionMode();
    return this;
  }

  public ObjectComboBoxComponentBuilder setMultiSelectionMode() {
    this.configurationBuilder.setMultiSelectionMode();
    return this;
  }

  public ObjectComboBoxComponentBuilder setIconTextGap(final int iconTextGap) {
    this.configurationBuilder.setIconTextGap(iconTextGap);
    return this;
  }

  public ObjectComboBoxComponentBuilder setVerticalTextPosition(final int verticalTextPosition) {
    this.configurationBuilder.setVerticalTextPosition(verticalTextPosition);
    return this;
  }

  public ObjectComboBoxComponentBuilder setHorizontalTextPosition(final int horizontalTextPosition) {
    this.configurationBuilder.setHorizontalTextPosition(horizontalTextPosition);
    return this;
  }

  public ObjectComboBoxComponentBuilder setHorizontalAlignment(final int horizontalAlignment) {
    this.configurationBuilder.setHorizontalAlignment(horizontalAlignment);
    return this;
  }

  public ObjectComboBoxComponentBuilder setBorder(final Border border) {
    this.configurationBuilder.setBorder(border);
    return this;
  }

  public ObjectComboBoxComponentBuilder setVisibleRowCount(final int visibleRowCount) {
    this.configurationBuilder.setVisibleRowCount(visibleRowCount);
    return this;
  }

  public ObjectComboBoxComponentBuilder setModel(final IComboBoxModel model) {
    this.model = model;
    return this;
  }

  public ObjectComboBoxComponentBuilder setValues(final T[] values) {
    setValues(Arrays.asList(values));
    return this;
  }

  public ObjectComboBoxComponentBuilder setValues(final List values) {
    this.model = new ObjectComboBoxComponentModel<>(values);
    return this;
  }

  public ObjectComboBoxComponent build() {
    this.model = Optional
        .ofNullable(this.model)
        .orElseGet(() -> new ObjectComboBoxComponentModel<>(new ArrayList()));
    this.model.setSelectedItem(null);
    return new ObjectComboBoxComponent<>(this.configurationBuilder.build(), this.model);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy