home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-03 | 3.3 KB | 111 lines |
- package borland.samples.apps.chess.client ;
-
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.WindowEvent;
- import java.awt.event.ActionListener;
-
- /**Displays the Import/Export Dialog. The Import/Export dialog
- * allows the current game to be copied in PGN(Portable game notation) format to the clipboard.
- * From there, they could be saved and used in other programs that understand
- * PGN. Also any PGN file may be copied into the
- * dialogs text field and then displayed by the ChessViewer.
- *@see http://ourworld.compuserve.com/homepages/Manfred_Rosenboom/pgn_spec.htm
- * or
- *@see ftp://chess.onenet.net/pub/chess/PGN/Standard
- */
- public class ImportDlg extends Dialog implements OkCancelDialog{
- Panel dlgPanel = new Panel();
- Button cancelButton = new Button();
- Button okButton = new Button();
- TextArea game = new TextArea();
- BorderLayout dialogLayout = new BorderLayout();
- Panel innerPanel = new Panel();
- BorderLayout innerLayout = new BorderLayout();
- Label instructions = new Label();
- Panel buttonBar = new Panel();
- Label eastSpace = new Label(" ");
- Label westSpace = new Label(" ");
- ChessViewer dlgParent;
-
- public ImportDlg(ChessViewer dlgParent,String data) {
- super(dlgParent.f,CVS.VERY_PRIMITIVE_PGN,false);
- this.dlgParent = dlgParent;
- enableEvents(AWTEvent.WINDOW_EVENT_MASK);
- try {
- dlgParent.statusLine.setText(CVS.COPY_TO_THE_CLIPBOARD);
- dlgParent.setModal(true);
- game.setText(data);
- jbInit();
- add(dlgPanel);
- pack();
- setLocation(300,200);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void jbInit() {
- dlgPanel.setLayout(dialogLayout);
- innerPanel.setLayout(innerLayout);
- game.selectAll();
- instructions.setText(CVS.TO_IMPORT_PASTE_THE);
- westSpace.setText(" ");
- dlgPanel.add(innerPanel,BorderLayout.CENTER);
- instructions.setAlignment(Label.CENTER);
- innerPanel.add(instructions,BorderLayout.NORTH);
- buttonBar.add(okButton);
- okButton.setLabel(CVS.IMPORT);
- buttonBar.add(cancelButton);
- cancelButton.setLabel(CVS.CANCEL);
- okButton.addActionListener(new OkButtonListener(this));
- cancelButton.addActionListener(new CancelButtonListener(this));
- innerPanel.add(game,BorderLayout.CENTER);
- dlgPanel.add(eastSpace,BorderLayout.EAST);
- dlgPanel.add(westSpace,BorderLayout.WEST);
- innerPanel.add(buttonBar,BorderLayout.SOUTH);
- }
-
- public void show() {
- super.show();
- game.requestFocus();
- }
-
- /**So System close acts like cancel
- */
- protected void processWindowEvent(WindowEvent e) {
- if (e.getID() == WindowEvent.WINDOW_CLOSING)
- cancel(null);
- else
- super.processWindowEvent(e);
- }
-
- /**OkButtonListener invokes this OkCancelDialog interface method
- */
- public void ok(ActionEvent evt) {
- try {
- dlgParent.importGame(game.getText());
- dispose();
- dlgParent.setModal(false);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**CancelButtonListener invokes this OkCancelDialog interface method
- */
- public void cancel(ActionEvent evt) {
- try {
- dlgParent.statusLine.setText("");
- dispose();
- dlgParent.setModal(false);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
-