001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.activities.parameters; 025 026 import java.awt.GridLayout; 027 import java.awt.event.ActionEvent; 028 import java.awt.event.ActionListener; 029 import java.util.Vector; 030 031 import javax.swing.BorderFactory; 032 import javax.swing.JComboBox; 033 import javax.swing.JPanel; 034 035 import se.liu.ida.critiquer.activities.Activity; 036 037 public class NumberSelectionParameter extends AbstractTaskViewParameter<JPanel,Integer> { 038 039 /** 040 * 041 */ 042 private static final long serialVersionUID = 1L; 043 /** 044 * 045 */ 046 private transient JComboBox numberChooser; 047 private Vector<Integer> range; 048 049 public void initComponent() { 050 component = new JPanel(new GridLayout(1,0)); 051 numberChooser = new JComboBox(range); 052 numberChooser.setSelectedItem(getValue()); 053 numberChooser.addActionListener(new ActionListener() { 054 055 public void actionPerformed(ActionEvent arg0) { 056 Integer num = (Integer) numberChooser.getSelectedItem(); 057 updateBorder(); 058 setValue(num); 059 } 060 061 }); 062 updateBorder(); 063 component.add(numberChooser); 064 } 065 066 private void updateBorder() { 067 component.setBorder(BorderFactory.createTitledBorder(toString())); 068 } 069 070 public NumberSelectionParameter(Activity a,String name,Vector<Integer> range,Integer defaultValue) { 071 super(name, a); 072 this.range=range; 073 this.value=defaultValue; 074 } 075 076 }