View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.gui.misc;
17  
18  import java.awt.Color;
19  import java.awt.Component;
20  
21  import javax.swing.JLabel;
22  import javax.swing.JList;
23  import javax.swing.ListCellRenderer;
24  
25  import p3j.gui.dialogs.EditSetsDialog;
26  import p3j.pppm.parameters.ParameterInstance;
27  import p3j.pppm.sets.Set;
28  
29  /**
30   * Renderer of cells for the parameter list.
31   * 
32   * Created on March 12, 2007
33   * 
34   * @author Christina Bohk
35   * @author Roland Ewald
36   * 
37   */
38  @Deprecated
39  public class ParameterListCellRenderer implements ListCellRenderer {
40  
41  	/** Reference to edit sets dialog. */
42  	private EditSetsDialog dialog;
43  
44  	/** Label to display. */
45  	private JLabel label = new JLabel();
46  	{
47  		label.setOpaque(true);
48  	}
49  
50  	/**
51  	 * Default constructor.
52  	 * 
53  	 * @param dlg
54  	 *          reference to dialog that edits the sets
55  	 */
56  	public ParameterListCellRenderer(EditSetsDialog dlg) {
57  		this.dialog = dlg;
58  	}
59  
60  	@Override
61  	public Component getListCellRendererComponent(JList list, Object value,
62  	    int index, boolean isSelected, boolean cellHasFocus) {
63  
64  		ParameterInstance param = (ParameterInstance) value;
65  
66  		label.setText(param.toString());
67  
68  		label.setForeground(isSelected ? list.getSelectionForeground() : list
69  		    .getForeground());
70  		label.setBackground(isSelected ? list.getSelectionBackground() : list
71  		    .getBackground());
72  
73  		Set currentSet = dialog.getCurrentSet();
74  
75  		if (currentSet.getNumberOfAssignments(param) == 0) {
76  			label.setForeground(Color.GRAY);
77  		}
78  
79  		return label;
80  	}
81  }