Back to index

wims  3.65+svn20090927
SortDialog.java
Go to the documentation of this file.
00001 /*
00002  * @(#)SortDialog.java
00003  *
00004  * $Id: SortDialog.java,v 1.15 2001/05/27 22:28:58 huaz Exp $
00005  *
00006  * Created on November 16, 2000, 12:00 AM
00007  */
00008 package SharpTools;
00009 import java.util.*;
00010 import java.util.Vector;
00011 import javax.swing.*;
00012 import java.awt.*;
00013 import javax.swing.BorderFactory;
00014 import javax.swing.border.Border;
00015 import java.awt.event.*;
00016 
00025 public class SortDialog extends SharpDialog {
00026     
00027     private JLabel label;
00028     private JFrame frame;
00029     private JComboBox primary;
00030     private JComboBox tiebreaker;
00031     private boolean ascending1 = true;
00032     private boolean ascending2 = true;
00033     private int criteriaA = -1;
00034     private int criteriaB = -1;
00035     final ImageIcon sortIcon=new ImageIcon(getClass().getResource("/images/sort32.gif")); 
00036     //final private static ImageIcon sortIcon = SharpTools.getImageIcon("sort32.gif");
00037     
00038     final private ButtonGroup group = new ButtonGroup();       
00039     final private ButtonGroup group2 = new ButtonGroup();
00040     final private String ascending_1 = "ascending_1";
00041     final private String descending_1 = "decending_1";
00042     final private String ascending_2 = "ascending_2";
00043     final private String descending_2 = "decending_2";
00044 
00045     public SortDialog(JFrame aFrame, Vector first, Vector second) {
00046        super(aFrame, "Sort", true);       
00047                
00048         primary = new JComboBox(first);
00049         primary.setSelectedIndex(0);
00050         
00051         tiebreaker = new JComboBox(second);
00052         tiebreaker.setSelectedIndex(0);
00053         
00054        JRadioButton[] radioButtons = new JRadioButton[4];
00055        JButton enter = null;
00056        JButton close = null;
00057        JPanel box = new JPanel();
00058        
00059        radioButtons[0] = new JRadioButton(SharpTools.translation.getProperty("Ascending"));
00060         radioButtons[0].setActionCommand(ascending_1);
00061        
00062         radioButtons[1] = new JRadioButton(SharpTools.translation.getProperty("Descending"));
00063         radioButtons[1].setActionCommand(descending_1);
00064        
00065         radioButtons[2] = new JRadioButton(SharpTools.translation.getProperty("Ascending"));
00066         radioButtons[2].setActionCommand(ascending_2);
00067        
00068         radioButtons[3] = new JRadioButton(SharpTools.translation.getProperty("Descending"));
00069         radioButtons[3].setActionCommand(descending_2);
00070 
00071        
00072        radioButtons[0].setSelected(true);
00073        group.add(radioButtons[0]);
00074         group.add(radioButtons[1]);
00075 
00076        
00077        radioButtons[2].setSelected(true);
00078        group2.add(radioButtons[2]);
00079        group2.add(radioButtons[3]);
00080        
00081        
00082         box.setLayout(new GridLayout(0, 3, 10, 5));
00083 
00084        // define key shortcut
00085         JLabel sortLabel = new JLabel(SharpTools.translation.getProperty("Sort_By:"));
00086        sortLabel.setLabelFor(primary);
00087        sortLabel.setDisplayedMnemonic(KeyEvent.VK_S);
00088        radioButtons[0].setMnemonic(KeyEvent.VK_A);
00089        radioButtons[1].setMnemonic(KeyEvent.VK_D);
00090        
00091        box.add(sortLabel);
00092        box.add(new JLabel(""));
00093        box.add(new JLabel(""));
00094        box.add(primary);
00095        box.add(radioButtons[0]);
00096        box.add(radioButtons[1]);
00097 
00098        // define key shortcut
00099        sortLabel = new JLabel(SharpTools.translation.getProperty("Then_By:"));
00100        sortLabel.setLabelFor(tiebreaker);
00101        sortLabel.setDisplayedMnemonic(KeyEvent.VK_T);
00102        radioButtons[2].setMnemonic(KeyEvent.VK_C);
00103        radioButtons[3].setMnemonic(KeyEvent.VK_E);      
00104 
00105        box.add(sortLabel);
00106        box.add(new JLabel(""));
00107        box.add(new JLabel(""));
00108        box.add(tiebreaker);
00109        box.add(radioButtons[2]);
00110        box.add(radioButtons[3]);
00111        
00112        Border padding = BorderFactory.createEmptyBorder(20,20,20,0);
00113        box.setBorder(padding);
00114        
00115        
00116        Object setting = box;
00117        
00118        setOptionPane(box, 
00119                     JOptionPane.PLAIN_MESSAGE,
00120                     JOptionPane.YES_NO_OPTION,
00121                     sortIcon);
00122        
00123 
00124         
00125         primary.addActionListener(new ActionListener() {
00126               public void actionPerformed(ActionEvent e) {
00127                   JComboBox cb = (JComboBox)e.getSource();
00128                   criteriaA = cb.getSelectedIndex();
00129               }
00130            });
00131        
00132        
00133        
00134        tiebreaker.addActionListener(new ActionListener() {
00135               public void actionPerformed(ActionEvent e) {
00136                   JComboBox cb = (JComboBox)e.getSource();
00137                   criteriaB = cb.getSelectedIndex();
00138               }
00139            });
00140 
00141     }
00142 
00143     private JPanel setPanel(){
00144        return null;
00145     }
00146  
00147     public boolean firstAscending(){
00148        return ascending1;          
00149     }
00150     
00151     public boolean secondAscending(){
00152        return ascending2;
00153     }
00154     
00155     public int getCriteriaA(){
00156        return criteriaA;
00157     }
00158     
00159     public int getCriteriaB(){
00160        return criteriaB;
00161     }
00162     
00163     void setLabel(String newText) {
00164         label.setText(newText);
00165     }
00166 
00167     
00168     protected boolean onOK() {
00169        criteriaA = primary.getSelectedIndex();
00170        criteriaB = tiebreaker.getSelectedIndex();
00171        String command = group.getSelection().getActionCommand();
00172        String command2 = group2.getSelection().getActionCommand();
00173                   
00174        //Set the sort order of the first column
00175        if (command == ascending_1) {
00176            ascending1 = true;
00177        } else if (command == descending_1) {
00178            ascending1 = false;
00179            // Set the sort order of the scond column
00180        }
00181        
00182        if (command2 == ascending_2) {
00183            ascending2 = true;
00184            
00185        } else if (command2 == descending_2) {
00186            ascending2 = false;
00187        }
00188        
00189        return true;
00190     }
00191 
00192     protected boolean onCancel() {
00193        criteriaA = -1;
00194        criteriaB = -1;
00195        return true;
00196     }
00197 
00198 }
00199 
00200