View Javadoc

1   package de.desy.acop.displayers.chart;
2   
3   import java.awt.Component;
4   
5   import javax.swing.DefaultListCellRenderer;
6   import javax.swing.JList;
7   
8   import de.desy.acop.chart.AcopGraphStyleEnum;
9   
10  /**
11   * 
12   * <code>StyleComboRenderer</code> is renderer to be used in combination
13   * with the lists displaying {@link AcopGraphStyleEnum}. This renderer
14   * only displays the second part of the enumeration (only the y axis style).
15   *
16   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
17   *
18   */
19  public class StyleComboRenderer extends DefaultListCellRenderer {
20  
21  	private static final long serialVersionUID = 1L;
22  
23  	/*
24  	 * (non-Javadoc)
25  	 * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
26  	 */
27  	@Override
28  	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
29  		if (value instanceof AcopGraphStyleEnum) {
30  			AcopGraphStyleEnum style = (AcopGraphStyleEnum)value;
31  			String name = style.name();
32  			String n = name.toLowerCase();
33  			if (n.startsWith("time")) {
34  				name = name.substring(4);
35  			} else if (n.startsWith("lin") || n.startsWith("log")) {
36  				name = name.substring(3);
37  			}
38  			value = name;
39  		}
40  		return super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
41  		
42  	}
43  }