edu.mit.csail.sdg.alloy4.OurCombobox Maven / Gradle / Ivy
Show all versions of alloy-core Show documentation
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package edu.mit.csail.sdg.alloy4;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;
/**
* Graphical combobox.
*
* Thread Safety: Can be called only by the AWT event thread.
*/
public class OurCombobox extends JComboBox {
/** This ensures the class can be serialized reliably. */
private static final long serialVersionUID = 0;
/**
* This caches a preconstructed JLabel that is used for the rendering of each
* Combo value.
*/
private static JLabel jlabel;
/**
* Subclass can override this method to provide the custom text for any given
* value (It should return "" if no text is needed)
*/
public String do_getText(Object value) {
return String.valueOf(value);
}
/**
* Subclass can override this method to provide the custom icon for any given
* value (It should return null if no icon is needed)
*/
public Icon do_getIcon(Object value) {
return null;
}
/**
* Subclass can override this method to react upon selection change.
*/
public void do_changed(Object newValue) {}
/**
* This helper method makes a copy of the list, and then optionally prepend null
* at the beginning of the list.
*/
private static Vector