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
|
/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Lo�c Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
*
* 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 2 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, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
* during his Bachelor thesis at the computer science department of ETH Z�rich,
* in the year 2013 and/or during future work.
*
* It is a reengineered version of XLogo written by Lo�c Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
* Contents of this file were initially written by Lo�c Le Coq,
* modifications, extensions, refactorings migh have been applied by Marko Zivkovic
*/
package xlogo.gui.translation;
import javax.swing.JFrame;
import javax.swing.JFileChooser;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.*;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;
import xlogo.Logo;
import xlogo.messages.async.dialog.DialogMessenger;
import xlogo.storage.WSManager;
import xlogo.storage.workspace.Language;
import xlogo.utils.Utils;
import xlogo.gui.SearchFrame;
/**
* Modifications made by Marko: <br>
* IO error is displayed through DialogMessenger (singleton) instead of {@link Application#ecris()}. Result: This class is completely decoupled from the Application class.
* @author lo�c Le Coq, slightly modified by Marko Zivkovic
*/
public class TranslateXLogo extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private String id="";
private String action;
protected static final String OK="ok";
protected static final String SEND="send";
protected static final String SEARCH="search";
protected static final String CONSULT="0";
protected static final String MODIFY="1";
protected static final String CREATE="2";
protected static final String COMPLETE="3";
private FirstPanel first;
private TopPanel top;
private BottomPanel bottom;
private SearchFrame sf=null;
public TranslateXLogo(){
initGui();
}
private void initGui(){
setIconImage(Toolkit.getDefaultToolkit().createImage(
Utils.class.getResource("icone.png")));
setTitle(Logo.messages.getString("menu.help.translatexlogo"));
first=new FirstPanel(this);
getContentPane().add(first);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
String cmd=e.getActionCommand();
if (cmd.equals(TranslateXLogo.OK)){
action=first.getAction();
if (null==action) return;
else if (action.equals(TranslateXLogo.MODIFY)) id=first.getLang();
else if (action.equals(TranslateXLogo.COMPLETE)) id=first.getLang();
//else if (action.equals(TranslateXLogo.CREATE)) id=first.getNewLang();
remove(first);
bottom=new BottomPanel(this,action,id);
getContentPane().setLayout(new BorderLayout());
if (!action.equals(TranslateXLogo.CONSULT)){
top=new TopPanel(this);
getContentPane().add(top,BorderLayout.NORTH);
}
getContentPane().add(bottom,BorderLayout.CENTER);
this.getContentPane().validate();
}
else if (cmd.equals(TranslateXLogo.SEND)){
String path="";
JFileChooser jf=new JFileChooser(Utils.SortieTexte(WSManager.getUserConfig().getDefaultFolder()));
int retval=jf.showDialog(this,Logo.messages
.getString("menu.file.save"));
if (retval==JFileChooser.APPROVE_OPTION){
path=jf.getSelectedFile().getPath();
StringBuffer sb=new StringBuffer();
try {
Locale locale=null;
if (action.equals(TranslateXLogo.CREATE)){
locale = Language.getLanguage(0).getLocale();
}
else if (!action.equals(TranslateXLogo.CONSULT)){
locale = Language.getLanguage(Integer.parseInt(id)).getLocale();
}
java.util.Vector<String> v=bottom.getPrimTable().getKeys();
ResourceBundle rb = ResourceBundle.getBundle("primitives", locale);
for (int i=0;i<v.size();i++) {
String key=v.get(i);
if (action.equals(TranslateXLogo.CREATE)){
writeLine(sb,key,bottom.getPrimValue(i,0));
}
else if (!action.equals(TranslateXLogo.CONSULT)){
String element=bottom.getPrimValue(i, Integer.parseInt(id));
// System.out.println(element+" clé "+key);
if (!rb.getString(key).equals(element)) writeLine(sb,key,element);
}
}
sb.append("\n---------------------------------------\n");
v=bottom.getMessageTable().getKeys();
rb = ResourceBundle.getBundle("langage", locale);
for(int i=0;i<v.size();i++){
String key=v.get(i);
if (action.equals(TranslateXLogo.CREATE)){
writeLine(sb,key,bottom.getMessageValue(i,0).replaceAll("\\n","\\\\n"));
}
else if (!action.equals(TranslateXLogo.CONSULT)){
String element=bottom.getMessageValue(i, Integer.parseInt(id));
if (!rb.getString(key).equals(element)) writeLine(sb,key,element.replaceAll("\\n","\\\\n"));
}
}
Utils.writeLogoFile(path,sb.toString());
}
catch(NullPointerException e3){System.out.println("annulation");} //Si l'utilisateur annule
catch(IOException e2){
DialogMessenger.getInstance().dispatchError("general.error.title", Logo.messages.getString("error.ioecriture"));
}
}
}
else if (cmd.equals(TranslateXLogo.SEARCH)){
if (null==sf) {
sf=new SearchFrame(this,bottom.getVisibleTable());
sf.setSize(350, 350);
sf.setVisible(true);
}
}
}
protected void resetSearchFrame(){
sf=null;
}
private void writeLine(StringBuffer sb,String key, String value){
sb.append(key);
sb.append("=");
sb.append(value);
sb.append("\n");
}
protected void processWindowEvent(WindowEvent e){
super.processWindowEvent(e);
if (e.getID()==WindowEvent.WINDOW_CLOSING){
//app.close_TranslateXLogo(); TODO Application does not need this. Maybe in settings @ welcome
}
}
}
|