1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/**
* JFractionLab
* Copyright (C) 2005 jochen georges, gnugeo _ at _ gnugeo _ dot _ de
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
package jfractionlab.jflDialogs;
import org.debian.tablelayout.TableLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import jfractionlab.JFractionLab;
import jfractionlab.ResultOfGame;
public class LogSaverDialog extends JDialog implements ActionListener{
static final long serialVersionUID = JFractionLab.serialVersionUID;
private String playersName;
private int ptsCN;
private int ptsNF;
private int ptsCF;
private int ptsEF;
private int ptsRF;
private int ptsIF;
private int ptsMN;
private int ptsFtD;
private int ptsPL;
private int ptsMIN;
private int ptsMF;
private int ptsDFN;
private int ptsDNF;
private int ptsDFF;
private JLabel lb_txt = new JLabel("", JLabel.CENTER);
private JLabel lb_name = new JLabel("", JLabel.CENTER);
private JTextField tf_name = new JTextField(30);//MyJTextField(30);
private JButton btn_reduce = new JButton("");
private JButton btn_OK = new JButton("");
public boolean isSavedSuccessfully = false;
public LogSaverDialog(
int ptsCN,int ptsNF,int ptsCF,int ptsEF,int ptsRF,int ptsIF,
int ptsMN, int ptsFtD,
int ptsPL,int ptsMIN,int ptsMF,int ptsDFN,int ptsDNF,int ptsDFF
){ //neues Spiel machen
setTitle(lang.Messages.getString("save_results"));
setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
setLocale(lang.Messages.getLocale());
lb_txt.setText(lang.Messages.getString("save_results"));
lb_name.setText(lang.Messages.getString("your_name"));
btn_reduce.setText(lang.Messages.getString("cancel"));
btn_OK.setText(lang.Messages.getString("OK"));
//this.playersName = sn;
this.ptsCN = ptsCN;
this.ptsNF = ptsNF;
this.ptsCF = ptsCF;
this.ptsEF = ptsEF;
this.ptsRF = ptsRF;
this.ptsIF = ptsIF;
this.ptsMN = ptsMN;
this.ptsFtD = ptsFtD;
this.ptsPL = ptsPL;
this.ptsMIN = ptsMIN;
this.ptsMF = ptsMF;
this.ptsDFN = ptsDFN;
this.ptsDNF = ptsDNF;
this.ptsDFF = ptsDFF;
setLocation(150, 150);
setSize(250,150);
//Groessenveraenderung verhindern!
setResizable(false);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
makeGUI();
}//Konstruktor
/**
*
*
*/
private void makeGUI(){
double sizes[][] = {{0.5, 0.5},{0.33,0.33,0.33}}; //Spalten / Zeilen
getRootPane().setDefaultButton(btn_OK);
Container content = getContentPane();
content.setLayout(new TableLayout(sizes));
content.setBackground(Color.white);
content.add(lb_txt, "0,0,1,0");
content.add(lb_name, "0,1");
content.add(tf_name, "1,1");
btn_reduce.addActionListener(this);
content.add(btn_reduce, "0,2");
btn_OK.addActionListener(this);
content.add(btn_OK, "1,2");
setVisible(true);
tf_name.requestFocusInWindow();
}//makeGUI
/**
*
*/
public void okAction(){
if(!tf_name.getText().equals("")){
playersName = tf_name.getText();
ResultOfGame sl = new ResultOfGame(
playersName,ptsCN,ptsNF,ptsCF,ptsEF,ptsRF,ptsIF,ptsMN, ptsFtD,
ptsPL,ptsMIN,ptsMF,ptsDFN,ptsDNF,ptsDFF);
String zeitstempel = sl.getTimeStamp();
JFileChooser fc = new JFileChooser();
FileFilter myfilter = new FileNameExtensionFilter("jfl", "JFL");
fc.addChoosableFileFilter(myfilter);
fc.setLocale(lang.Messages.getLocale());
fc.setSelectedFile(new File("JFractionLab_"+playersName+"_"+zeitstempel+".jfl"));
int returnVal = fc.showSaveDialog(LogSaverDialog.this);
// int returnVal = fc.showSaveDialog(fc);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String str = fc.getSelectedFile().toString();
if(!str.toLowerCase().endsWith(".jfl")){
str += ".jfl";
}
try{
FileOutputStream fs = new FileOutputStream(new File(str));
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(sl);
os.close();
isSavedSuccessfully = true;
}catch (IOException ex) {
isSavedSuccessfully = false;
ex.printStackTrace();
}//catch
}
setVisible(false);
dispose();
}else{
JOptionPane.showMessageDialog(null,
lang.Messages.getString("insert_name"));
}
tf_name.requestFocusInWindow();
}//okAction
/**
*
*/
@Override
public void actionPerformed(ActionEvent e){
Object obj = e.getSource();
if (obj == btn_reduce){
setVisible(false);
dispose();
}else if (obj == btn_OK ){
okAction();
}
}//actionPerformed
}
|