📄 terminalwindow.java
字号:
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.anchor = GridBagConstraints.WEST;
i.top = marg;
i.right = 0;
makeIt(p1, gbl, gbc, new Label("Domain name:"));
i.right = marg;
i.left = midh;
gbc.gridwidth = GridBagConstraints.REMAINDER;
makeIt(p1, gbl, gbc, domain);
gbc.gridwidth = 1;
i.top = midv;
i.left = marg;
i.bottom = 2;
i.right = 0;
makeIt(p1, gbl, gbc, new Label("Nickname:"));
i.right = marg;
i.left = midh;
gbc.gridwidth = GridBagConstraints.REMAINDER;
makeIt(p1, gbl, gbc, nickname);
gbc.gridwidth = 1;
i.top = midv;
i.left = marg;
i.bottom = 2;
i.right = 0;
makeIt(p1, gbl, gbc, new Label("Type of server:"));
i.right = marg;
i.left = midh;
gbc.gridwidth = GridBagConstraints.REMAINDER;
makeIt(p1, gbl, gbc, type);
gbc.gridwidth = 1;
i.top = midv;
i.left = marg;
i.bottom = marg;
i.right = 0;
makeIt(p1, gbl, gbc, new Label("Port number:"));
i.right = marg;
i.left = midh;
gbc.gridwidth = GridBagConstraints.REMAINDER;
makeIt(p1, gbl, gbc, port);
add("Center", p1);
Panel p3 = new Panel();
p3.setLayout(new FlowLayout(FlowLayout.RIGHT));
p3.add(savep);
p3.add(okButton);
p3.add(cancelButton);
add("South", p3);
//Initialize this dialog to its preferred size.
if (Util.isWindows())
setSize(250, 125);
else
pack();
}
public void itemStateChanged (ItemEvent e) {
String item = (String) e.getItem();
if ("NNGS".equals(item))
port.setText("9696");
else if ("IGS".equals(item))
port.setText("6969");
}
// GridBagLayout utility function, perhaps move to some global utility class.
// And give it a reasonable name.
void makeIt (Container co, GridBagLayout gbl, GridBagConstraints gbc,
Component c) {
gbl.setConstraints(c, gbc);
co.add(c);
}
public void actionPerformed (ActionEvent event) {
Object source = event.getSource();
int dlen = domain.getText().trim().length();
if (source == cancelButton) {
close();
}
else if (source == okButton) {
if (dlen == 0) {
String[] msg = {"You must enter a domain name."};
new InformDialog(TerminalWindow.this, "Error",
ColumnLayout.LEFT, msg).open();
}
else {
String dname = domain.getText().trim();
String stype = type.getSelectedItem();
String pstring = port.getText().trim();
int pnum = 9696;
String nname = nickname.getText().trim();
// deal with unspecified inputs
if ("".equals(nname)) {
int i = dname.indexOf(".");
if (i != -1)
nname = dname.substring(0, i);
}
try {
pnum = Integer.parseInt(pstring);
} catch (NumberFormatException ex) {}
GoServer gs = new GoServer(dname, pnum, nname, stype);
goConnectSubmenu.add(new GoServerMenuItem(gs));
if (savep.getState()) {
// Add the new server to the options so it gets saved in init file.
try {
int nservers = opser.getOptionSize(serverString);
opser.updateOption(serverString, nservers, gs);
} catch (ErgoException e) {
displayString(">>> Ergo: New server will not be saved in init file: "
+ e);
}
}
close();
}
}
}
} // end inner class NewServerDialog
class ObserveDialog extends ErgoDialog implements ActionListener {
TextField gameNumber = new TextField(4);
Button observeButton = new Button(" Observe ");
Button cancelButton = new Button(" Cancel ");
ServerConnection conn;
ObserveDialog (TerminalWindow window, ServerConnection conn) {
super(window, "Observe Game", true);
this.conn = conn;
observeButton.addActionListener(this);
cancelButton.addActionListener(this);
gameNumber.addActionListener(this);
Panel p1 = new Panel();
Label label = new Label("Enter Game number:");
p1.add(label);
p1.add(gameNumber);
add("Center", p1);
Panel p2 = new Panel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
p2.add(observeButton);
p2.add(cancelButton);
add("South", p2);
//Initialize this dialog to its preferred size.
if (Util.isWindows())
setSize(250, 100); // Pack doesn't work in Java for Windows?
else
pack();
}
public void actionPerformed (ActionEvent e) {
if (e.getSource() == observeButton || e.getSource() == gameNumber)
conn.send("observe " + gameNumber.getText());
close();
}
} // end inner class ObserveDialog
class AboutDialog extends ErgoDialog implements ActionListener {
private Button okButton = new Button(" OK ");
AboutDialog (Frame frame, String title) {
super(frame, title, true); // modal
okButton.addActionListener(this);
Panel c = new Panel();
ColumnLayout cl = new ColumnLayout(ColumnLayout.LEFT, 0, 10, false);
c.setLayout(cl); // vspace, margin
// +++ Should put an image to the left of the version.
Label version = new Label("Ergo " + Ergo.version());
version.setFont(new Font("sansserif", Font.PLAIN, 18));
c.add(version, cl.makeConstraint(ColumnLayout.CENTER, 0, false));
c.add(new Label(""), null);
c.add(new Label("Carl Gay (sigue@thecia.net)"), null);
c.add(new Label("Antranig Basman"), null);
c.add(new Label(""), null);
c.add(new Label("See http://www.thecia.net/users/sigue/ergo/ for documentation."));
add("North", c);
Panel p = new Panel();
p.add(okButton);
add("South", p);
}
public void actionPerformed (ActionEvent e) {
close();
}
} // end inner class AboutDialog
/**
* For entering all the parameters for a local game.
*/
class LocalGameDialog extends ErgoDialog implements ActionListener {
private boolean done = false;
TerminalWindow window;
private Panel topPanel = new Panel();
private Panel bottomPanel = new Panel();
TextField whiteName = new TextField("White", 15);
TextField blackName = new TextField("Black", 15);
TextField komi = new TextField("5.5", 5);
TextField time = new TextField("15", 5);
TextField byotime = new TextField("15", 5);
TextField size = new TextField("19", 5);
Button doneButton = new Button("Done");
Button cancelButton = new Button("Cancel");
Choice timingChooser = new Choice();
LocalGameDialog (TerminalWindow window) {
super(window, "Local Game", true);
this.window = window;
doneButton.addActionListener(this);
cancelButton.addActionListener(this);
timingChooser.addItem("timed");
timingChooser.addItem("untimed");
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
Label label;
topPanel.setLayout(gridbag);
// White player row
label = new Label("White Player Name:");
c.gridwidth = 2;
c.gridx = 0;
c.gridy = 0;
gridbag.setConstraints(label, c);
topPanel.add(label);
c.gridx = 2;
gridbag.setConstraints(whiteName, c);
topPanel.add(whiteName);
// Black player row
label = new Label("Black Player Name:");
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(label, c);
topPanel.add(label);
c.gridx = 2;
gridbag.setConstraints(blackName, c);
topPanel.add(blackName);
// Game size row
label = new Label("Game Size:");
c.anchor = GridBagConstraints.EAST;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 2;
gridbag.setConstraints(label, c);
topPanel.add(label);
c.anchor = GridBagConstraints.CENTER;
c.gridx = 1;
gridbag.setConstraints(size, c);
topPanel.add(size);
// Komi row
label = new Label("Komi:");
c.anchor = GridBagConstraints.EAST;
c.gridx = 0;
c.gridy = 3;
gridbag.setConstraints(label, c);
topPanel.add(label);
c.anchor = GridBagConstraints.CENTER;
c.gridx = 1;
gridbag.setConstraints(komi, c);
topPanel.add(komi);
// Game type row
label = new Label("Game will be");
c.anchor = GridBagConstraints.EAST;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 4;
gridbag.setConstraints(label, c);
topPanel.add(label);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
gridbag.setConstraints(timingChooser, c);
topPanel.add(timingChooser);
// initial time limit row
label = new Label("Initial time limit:");
c.gridwidth = 2;
c.gridx = 1;
c.gridy = 5;
gridbag.setConstraints(label, c);
topPanel.add(label);
c.gridx = 3;
gridbag.setConstraints(time, c);
topPanel.add(time);
// Byo-yomi time row
label = new Label("Byo-yomi time:");
c.gridx = 1;
c.gridy = 6;
gridbag.setConstraints(label, c);
topPanel.add(label);
c.gridx = 3;
gridbag.setConstraints(byotime, c);
topPanel.add(byotime);
add("North", topPanel);
// Set up the bottom panel (Done and Cancel buttons).
bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
bottomPanel.add(doneButton);
bottomPanel.add(cancelButton);
add("South", bottomPanel);
//Initialize this dialog to its preferred size.
if (Util.isWindows())
setSize(400, 220); // pack() doesn't work in Java for Windows?
else // Nor in OS/2 AMB.
pack();
}
public String whiteName () {
String wname = whiteName.getText();
if (wname.equals(""))
wname = "White";
return wname;
}
public String blackName () {
String bname = blackName.getText();
if (bname.equals(""))
bname = "Black";
return bname;
}
public double komi () {
String s = komi.getText();
try {
return new Double(s).doubleValue(); }
catch (NumberFormatException e) {
return 5.5; }
}
public int gameSize () {
String s = size.getText().trim();
try {
return Integer.parseInt(s);
} catch (NumberFormatException nfe) {}
return -1;
}
public boolean isTimed () {
return timingChooser.getSelectedItem().equalsIgnoreCase("timed");
}
public int initialTimeLimit () {
try {
return Integer.parseInt(time.getText()); }
catch (NumberFormatException e) {
return 15; }
}
public int byoTime () {
try {
return Integer.parseInt(byotime.getText()); }
catch (NumberFormatException e) {
return 15; }
}
public void actionPerformed (ActionEvent event) {
String cmd = event.getActionCommand();
done = true;
close();
if ("done".equalsIgnoreCase(cmd)) {
try {
GameWindow gwin = new GameWindow(gameSize(), whiteName(), null,
blackName(), null, komi(), window);
window.addGameWindow(gwin);
}
catch (ErgoException e) {
Debug.backtrace(e);
}
}
}
} // end class LocalGameDialog
} // end class TerminalWindow
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -