Java tutorial
/* This Source Code Form is subject to the terms of the Mozilla * Public License, v. 2.0. If a copy of the MPL was not distributed * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2017 Ilya Zemskov */ package ru.develgame.jflickrorganizer.DataModel; import javax.swing.DefaultComboBoxModel; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import ru.develgame.jflickrorganizer.Common.LocaleMessages; import ru.develgame.jflickrorganizer.DataModel.VisibilityComboBoxDataModel.WrapperVisibility; /** * * @author Ilya Zemskov */ @Component @Scope("prototype") public class VisibilityComboBoxDataModel extends DefaultComboBoxModel<WrapperVisibility> { public VisibilityComboBoxDataModel() { WrapperVisibility wrapperVisibility = new WrapperVisibility(VisibilityFilter.VISIBILITY_ALL); addElement(wrapperVisibility); addElement(new WrapperVisibility(VisibilityFilter.VISIBILITY_PUBLIC)); addElement(new WrapperVisibility(VisibilityFilter.VISIBILITY_PRIVATE)); setSelectedItem(wrapperVisibility); } public static class WrapperVisibility { private int visibility; public int getVisibility() { return visibility; } public WrapperVisibility(int visibility) { this.visibility = visibility; } public String toString() { if (visibility == VisibilityFilter.VISIBILITY_PUBLIC) return LocaleMessages.getMessage("MainForm.Table.Value.Public"); else if (visibility == VisibilityFilter.VISIBILITY_PRIVATE) return LocaleMessages.getMessage("MainForm.Table.Value.Private"); else if (visibility == VisibilityFilter.VISIBILITY_ALL) return LocaleMessages.getMessage("Visibility.All"); return ""; } } }