1 package snow.utils.gui; 2 3 import snow.Language.Language; 4 import java.awt.*; 5 import java.awt.event.*; 6 import javax.swing.*; 7 8 11 public final class CloseControlPanel extends JPanel 12 { 13 private final JButton cancelBT = new JButton(Language.translate("Cancel")); 14 15 private final JButton okBT = new JButton(Language.translate("Close")); 16 17 private boolean accepted = false; 18 private boolean cancelled = false; 19 20 public JButton getOkButton() {return okBT;} 21 22 23 public boolean getWasAccepted() { return accepted; } 24 public boolean getWasCancelled() { return cancelled; } 25 26 public boolean shouldCancelCallClose = false; 27 28 public CloseControlPanel( final Object frame, boolean showCancel, 29 boolean shouldCancelCallClose_, final String okText ) 30 { 31 super(new FlowLayout(FlowLayout.RIGHT)); 32 setOpaque(false); 33 this.shouldCancelCallClose = shouldCancelCallClose_; 34 35 add(cancelBT); 36 cancelBT.setMargin(new Insets(0,2,0,2)); 37 if(!showCancel) cancelBT.setVisible(false); 38 39 okBT.setText(okText); 40 add(okBT); 41 okBT.setMargin(new Insets(0,2,0,2)); 42 okBT.setBackground(Color.orange); 43 44 okBT.addActionListener(new ActionListener() 45 { 46 public void actionPerformed(ActionEvent e) 47 { 48 accepted = true; 49 cancelled = false; 50 if(frame instanceof JFrame) 51 { 52 ((JFrame) frame).setVisible(false); 53 ((JFrame) frame).dispose(); 54 } 55 else if(frame instanceof JDialog) 56 { 57 ((JDialog) frame).setVisible(false); 58 ((JDialog) frame).dispose(); 59 } 60 } 61 }); 62 cancelBT.addActionListener(new ActionListener() 63 { 64 public void actionPerformed(ActionEvent e) 65 { 66 cancelled = true; 67 accepted = false; 68 if(shouldCancelCallClose) 69 { 70 if(frame instanceof JFrame) 71 { 72 ((JFrame) frame).setVisible(false); 73 ((JFrame) frame).dispose(); 74 } 75 else if(frame instanceof JDialog) 76 { 77 ((JDialog) frame).setVisible(false); 78 ((JDialog) frame).dispose(); 79 } 80 } 81 } 82 }); 83 84 } 85 86 87 public void _setOkButtonText(String txt) 88 { 89 okBT.setText(txt); 90 } 91 92 public void setOkEnabled(boolean is) 93 { 94 okBT.setEnabled(is); 95 } 96 97 public void setOkBackground(Color c) 98 { 99 okBT.setBackground(c); 100 } 101 102 } | Popular Tags |