home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
ImportDlg.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
5KB
|
134 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
package borland.samples.apps.chess.client ;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
/**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{
ResourceBundle res = ResourceBundle.getBundle("borland.samples.apps.chess.client.Res");
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,"",false);
setTitle(res.getString("VERY_PRIMITIVE_PGN"));
this.dlgParent = dlgParent;
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
dlgParent.statusLine.setText(res.getString("COPY_TO_THE_CLIPBOARD"));
dlgParent.setModal(true);
game.setText(data);
jbInit();
add(dlgPanel);
pack();
setLocation(300,200);
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() {
dlgPanel.setLayout(dialogLayout);
innerPanel.setLayout(innerLayout);
game.selectAll();
instructions.setText(res.getString("TO_IMPORT_PASTE_THE"));
westSpace.setText(" "); //from the days before I learned how to use GridBagLayout <g>
dlgPanel.add(innerPanel,BorderLayout.CENTER);
instructions.setAlignment(Label.CENTER);
innerPanel.add(instructions,BorderLayout.NORTH);
buttonBar.add(okButton);
okButton.setLabel(res.getString("IMPORT"));
buttonBar.add(cancelButton);
cancelButton.setLabel(res.getString("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 setVisible(boolean isVisible) {
super.setVisible(isVisible);
if (isVisible)
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();
}
}
}