1 /* 2 * (C) 2001 by Argonne National Laboratory 3 * See COPYRIGHT in top-level directory. 4 */ 5 6 /* 7 * @author Anthony Chan 8 */ 9 10 package viewer.legends; 11 12 import java.net.URL; 13 import java.util.Comparator; 14 import java.awt.event.ActionEvent; 15 import java.awt.event.ActionListener; 16 import javax.swing.Icon; 17 import javax.swing.ImageIcon; 18 import javax.swing.JPopupMenu; 19 import javax.swing.JMenuItem; 20 import javax.swing.JTable; 21 22 import viewer.common.Const; 23 /* 24 Class to simulate a JMenuBar header editor for a JTable with String value 25 */ 26 public class OperationNumberMenu extends JPopupMenu 27 { 28 private static final long serialVersionUID = 2800L; 29 30 private static String count_order_icon_path 31 = Const.IMG_PATH 32 + "checkbox/CountOrder.gif"; 33 34 private JTable table_view; 35 private LegendTableModel table_model; 36 private int cell_column; // index where String.class is 37 private Comparator cell_comparator; 38 OperationNumberMenu( JTable in_table, int in_column )39 public OperationNumberMenu( JTable in_table, int in_column ) 40 { 41 super(); 42 table_view = in_table; 43 table_model = (LegendTableModel) table_view.getModel(); 44 cell_column = in_column; 45 46 super.setLabel( table_model.getColumnName( cell_column ) ); 47 super.setToolTipText( table_model.getColumnToolTip( cell_column ) ); 48 switch ( cell_column ) { 49 case LegendTableModel.COUNT_COLUMN : 50 cell_comparator = LegendComparators.COUNT_ORDER; 51 break; 52 case LegendTableModel.INCL_RATIO_COLUMN : 53 cell_comparator = LegendComparators.INCL_RATIO_ORDER; 54 break; 55 case LegendTableModel.EXCL_RATIO_COLUMN : 56 cell_comparator = LegendComparators.EXCL_RATIO_ORDER; 57 break; 58 default: 59 cell_comparator = LegendComparators.INDEX_ORDER; 60 } 61 this.addMenuItems(); 62 } 63 addMenuItems()64 private void addMenuItems() 65 { 66 JMenuItem menu_item; 67 URL icon_URL; 68 Icon icon; 69 70 71 icon_URL = null; 72 icon_URL = getURL( count_order_icon_path ); 73 if ( icon_URL != null ) 74 icon = new ImageIcon( icon_URL ); 75 else 76 icon = null; 77 menu_item = new JMenuItem( "9 ... 1", icon ); 78 menu_item.addActionListener( 79 new ActionListener() { 80 public void actionPerformed( ActionEvent evt ) 81 { table_model.reverseOrder( cell_comparator ); } 82 } ); 83 super.add( menu_item ); 84 85 icon_URL = null; 86 icon_URL = getURL( count_order_icon_path ); 87 if ( icon_URL != null ) 88 icon = new ImageIcon( icon_URL ); 89 else 90 icon = null; 91 menu_item = new JMenuItem( "1 ... 9", icon ); 92 menu_item.addActionListener( 93 new ActionListener() { 94 public void actionPerformed( ActionEvent evt ) 95 { table_model.arrangeOrder( cell_comparator ); } 96 } ); 97 super.add( menu_item ); 98 } 99 getURL( String filename )100 private URL getURL( String filename ) 101 { 102 return getClass().getResource( filename ); 103 } 104 } 105