home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / ImportDlg.java < prev    next >
Encoding:
Java Source  |  1997-07-03  |  3.3 KB  |  111 lines

  1. package borland.samples.apps.chess.client  ;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.WindowEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. /**Displays the Import/Export Dialog. The Import/Export dialog
  9. * allows the current game to be copied in PGN(Portable game notation) format to the clipboard.
  10. * From there, they could be saved and used in other programs that understand
  11. * PGN. Also any PGN file may be copied into the
  12. * dialogs text field and then displayed by the ChessViewer.
  13. *@see http://ourworld.compuserve.com/homepages/Manfred_Rosenboom/pgn_spec.htm
  14. * or
  15. *@see ftp://chess.onenet.net/pub/chess/PGN/Standard
  16. */
  17. public class ImportDlg extends Dialog implements OkCancelDialog{
  18.   Panel dlgPanel = new Panel();
  19.   Button cancelButton = new Button();
  20.   Button okButton = new Button();
  21.   TextArea game = new TextArea();
  22.   BorderLayout dialogLayout = new BorderLayout();
  23.   Panel innerPanel = new Panel();
  24.   BorderLayout innerLayout = new BorderLayout();
  25.   Label instructions = new Label();
  26.   Panel buttonBar = new Panel();
  27.   Label eastSpace = new Label("  ");
  28.   Label westSpace = new Label("  ");
  29.   ChessViewer dlgParent;
  30.  
  31.   public ImportDlg(ChessViewer dlgParent,String data)  {
  32.     super(dlgParent.f,CVS.VERY_PRIMITIVE_PGN,false);
  33.     this.dlgParent = dlgParent;
  34.     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  35.     try {
  36.       dlgParent.statusLine.setText(CVS.COPY_TO_THE_CLIPBOARD);
  37.       dlgParent.setModal(true);
  38.       game.setText(data);
  39.       jbInit();
  40.       add(dlgPanel);
  41.       pack();
  42.       setLocation(300,200);
  43.     }
  44.     catch (Exception e) {
  45.       e.printStackTrace();
  46.     }
  47.   }
  48.  
  49.   void jbInit() {
  50.     dlgPanel.setLayout(dialogLayout);
  51.     innerPanel.setLayout(innerLayout);
  52.     game.selectAll();
  53.     instructions.setText(CVS.TO_IMPORT_PASTE_THE);
  54.     westSpace.setText(" ");
  55.     dlgPanel.add(innerPanel,BorderLayout.CENTER);
  56.     instructions.setAlignment(Label.CENTER);
  57.     innerPanel.add(instructions,BorderLayout.NORTH);
  58.     buttonBar.add(okButton);
  59.     okButton.setLabel(CVS.IMPORT);
  60.     buttonBar.add(cancelButton);
  61.     cancelButton.setLabel(CVS.CANCEL);
  62.     okButton.addActionListener(new OkButtonListener(this));
  63.     cancelButton.addActionListener(new CancelButtonListener(this));
  64.     innerPanel.add(game,BorderLayout.CENTER);
  65.     dlgPanel.add(eastSpace,BorderLayout.EAST);
  66.     dlgPanel.add(westSpace,BorderLayout.WEST);
  67.     innerPanel.add(buttonBar,BorderLayout.SOUTH);
  68.   }
  69.  
  70.   public void show() {
  71.     super.show();
  72.     game.requestFocus();
  73.   }
  74.  
  75.   /**So System close acts like cancel
  76.   */
  77.   protected void processWindowEvent(WindowEvent e)  {
  78.     if (e.getID() == WindowEvent.WINDOW_CLOSING)
  79.       cancel(null);
  80.     else
  81.       super.processWindowEvent(e);
  82.   }
  83.  
  84.   /**OkButtonListener invokes this OkCancelDialog interface method
  85.   */
  86.   public void ok(ActionEvent evt) {
  87.     try {
  88.       dlgParent.importGame(game.getText());
  89.       dispose();
  90.       dlgParent.setModal(false);
  91.     }
  92.     catch (Exception e) {
  93.        e.printStackTrace();
  94.     }
  95.   }
  96.  
  97.   /**CancelButtonListener invokes this OkCancelDialog interface method
  98.   */
  99.   public void cancel(ActionEvent evt) {
  100.     try {
  101.       dlgParent.statusLine.setText("");
  102.       dispose();
  103.       dlgParent.setModal(false);
  104.     }
  105.     catch (Exception e) {
  106.       e.printStackTrace();
  107.     }
  108.   }
  109. }
  110.  
  111.