FileDocCategorySizeDatePackage
BoardOptions.javaAPI DocExample9364Sat Sep 12 03:01:00 BST 1998borland.samples.apps.chess.client

BoardOptions

public class BoardOptions extends Dialog implements OkCancelDialog
Dialog for modifying the appearance of the Chessboard

Fields Summary
ResourceBundle
res
borland.jbcl.control.ColorChooserPanel
lightColorPanel
borland.jbcl.control.ColorChooserPanel
darkColorPanel
Panel
dlgPanel
Choice
pieces
ChessViewer
myParent
Chessboard
board
Frame
theframe
URL[]
imageNames
Checkbox
switchSides
Label
eastLabel
Label
westLabel
Label
temp
Label
centerTitleText
Label
centerTitleText2
Panel
northPanel
Panel
internalPanel
Panel
centerPanel
Panel
centerTitle
Panel
bottomPanel
Panel
buttonBar
Panel
buttonBarGrid
GridLayout
buttonBarGridLayout
FlowLayout
buttonBarLayout
Button
okButton
Button
cancelButton
BorderLayout
internalPanelBorderLayout
BorderLayout
dialogBorderLayout
GridLayout
northPanelGridLayout
GridLayout
centerTitleGridLayout
GridLayout
centerPanelGridLayout
GridLayout
bottomPanelGridLayout
String
text
Constructors Summary
public BoardOptions(ChessViewer myParent, Frame theframe, URL[] imageNames, Chessboard board)
Constructor

param
ChessViewer myParent gives access back to the Applet
param
Frame theframe the frame that parents this dialog
URL[]
imageNames an array of Chesspiece image files Image files are 6 by 2 squares in size in Rook,Knight,Bishop,Queen,King,Pawn order. The first row has the white pieces, the second has the black pieces. all pieces have the same background color which is not otherwise used in the image. The Chessboard Object makes this background transparent when rendering the pieces.

                                                                                      

         
    super(theframe,"",false);
    try {
      setTitle(res.getString("CHESSBOARD_OPTIONS"));
      System.out.println("BoardOptions xtor...");
      this.myParent = myParent;
      this.board = board;
      this.theframe = theframe;
      this.imageNames = imageNames;
      myParent.setModal(true);
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);


      if (board.isBlackOnTop())
        text = res.getString("WHITE_AT_TOP") ;
      jbInit();
      add(dlgPanel);
      lightColorPanel.setColorValue(board.getLightSquareColor());
      darkColorPanel.setColorValue(board.getDarkSquareColor());

    }
    catch (Exception e) {
      System.out.println("BoardOptions xtor" + e);
      e.printStackTrace();
    }
  
Methods Summary
public voidcancel(java.awt.event.ActionEvent evt)
this OkCancelDialog interface method is called by the CancelButtonListener when it receives an ActionEvent

    dispose();
    myParent.setModal(false);
  
private voidjbInit()

    //Color lightColor = board.getLightSquareColor();
    //Color darkColor = board.getDarkSquareColor();
    lightColorPanel = new ColorChooserPanel() ;
    darkColorPanel  = new ColorChooserPanel() ;
    dlgPanel.setLayout(dialogBorderLayout);
    northPanelGridLayout.setRows(3);
    northPanelGridLayout.setColumns(1);
    centerTitleGridLayout.setRows(1) ;
    centerTitleGridLayout.setColumns(2) ;
    centerPanelGridLayout.setRows(1) ;
    centerPanelGridLayout.setColumns(2) ;
    bottomPanelGridLayout.setRows(2) ;
    bottomPanelGridLayout.setColumns(1) ;
    internalPanel.setLayout(internalPanelBorderLayout);
    centerPanel.setLayout(centerPanelGridLayout);
    bottomPanel.setLayout(bottomPanelGridLayout);
    buttonBar.setLayout(buttonBarLayout);
    buttonBarGridLayout.setColumns(2);
    buttonBarGridLayout.setHgap(6);
    buttonBarGrid.setLayout(buttonBarGridLayout);

    northPanel.setLayout(northPanelGridLayout);
    temp.setText(res.getString("PIECES_"));
    northPanel.add(temp);
    northPanel.add(pieces);
    for (int i = 0; i< imageNames.length;i++)
      pieces.addItem(imageNames[i].toString());
    centerTitle.setLayout(centerTitleGridLayout );
    centerTitleText.setText(res.getString("LIGHT_SQUARES"));
    centerTitle.add(centerTitleText);
    centerTitleText2.setText(res.getString("DARK_SQUARES"));
    centerTitle.add(centerTitleText2);
    northPanel.add(centerTitle);
    lightColorPanel.setColorValue(Color.red);
    darkColorPanel.setColorValue(Color.yellow );
    centerPanel.add(lightColorPanel);
    centerPanel.add(darkColorPanel);
    System.out.println("BoardOptions xtor1");
    buttonBarGrid.add(okButton);
    okButton.addActionListener(new OkButtonListener(this));
    buttonBarGrid.add(cancelButton);
    cancelButton.setLabel(res.getString("CANCEL"));
    okButton.setLabel(res.getString("OK"));
    cancelButton.addActionListener(new CancelButtonListener(this));
    buttonBar.add(buttonBarGrid);
    System.out.println("BoardOptions xtor2");

    switchSides.setLabel(text);
    bottomPanel.add(switchSides);
    bottomPanel.add(buttonBar);
    internalPanel.add(northPanel,BorderLayout.NORTH);
    internalPanel.add(bottomPanel,BorderLayout.SOUTH);
    internalPanel.add(centerPanel,BorderLayout.CENTER);
    eastLabel.setText("  ");
    westLabel.setText("  ");
    dlgPanel.add(eastLabel,BorderLayout.EAST);
    dlgPanel.add(westLabel,BorderLayout.WEST);
    dlgPanel.add(internalPanel,BorderLayout.CENTER);
  
public voidok(java.awt.event.ActionEvent evt)
this OkCancelDialog interface method is called by the OkButtonListener when it receives an ActionEvent

    try {
      if (lightColorPanel.isChanged())
        board.setLightSquareColor(lightColorPanel.getColorValue());
      if (darkColorPanel.isChanged())
        board.setDarkSquareColor(darkColorPanel.getColorValue());
      int index = pieces.getSelectedIndex();
      dispose();
      if (index > 0){
        board.setImageURL(imageNames[index]);
        System.out.println("resize frame to" + theframe.getPreferredSize());
        theframe.setSize(theframe.getPreferredSize());
      }  
      else
        board.setPosition();
      if (switchSides.getState())
        myParent.switchSides();
      theframe.validate();
      myParent.setModal(false);
    }
    catch (Exception e) {
      String message = e.toString() ;
      e.printStackTrace();
    }
  
protected voidprocessWindowEvent(java.awt.event.WindowEvent e)


    if (e.getID() == WindowEvent.WINDOW_CLOSING)
      cancel(null);
    else
      super.processWindowEvent(e);
  
public voidsetVisible(boolean isVisible)

    super.setVisible(isVisible);
    if (isVisible)
      pieces.requestFocus();