Source Code Cross Referenced for Translator.java in  » Development » jrc-editor » org » zaval » tools » i18n » translator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » jrc editor » org.zaval.tools.i18n.translator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         *     Caption: Zaval Java Resource Editor
0003:         *     $Revision: 0.37 $
0004:         *     $Date: 2002/03/28 9:24:42 $
0005:         *
0006:         *     @author:     Victor Krapivin
0007:         *     @version:    2.0
0008:         *
0009:         * Zaval JRC Editor is a visual editor which allows you to manipulate 
0010:         * localization strings for all Java based software with appropriate 
0011:         * support embedded.
0012:         * 
0013:         * For more info on this product read Zaval Java Resource Editor User's Guide
0014:         * (It comes within this package).
0015:         * The latest product version is always available from the product's homepage:
0016:         * http://www.zaval.org/products/jrc-editor/
0017:         * and from the SourceForge:
0018:         * http://sourceforge.net/projects/zaval0002/
0019:         *
0020:         * Contacts:
0021:         *   Support : support@zaval.org
0022:         *   Change Requests : change-request@zaval.org
0023:         *   Feedback : feedback@zaval.org
0024:         *   Other : info@zaval.org
0025:         * 
0026:         * Copyright (C) 2001-2002  Zaval Creative Engineering Group (http://www.zaval.org)
0027:         * 
0028:         * This program is free software; you can redistribute it and/or
0029:         * modify it under the terms of the GNU General Public License
0030:         * (version 2) as published by the Free Software Foundation.
0031:         * 
0032:         * This program is distributed in the hope that it will be useful,
0033:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0034:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0035:         * GNU General Public License for more details.
0036:         * 
0037:         * You should have received a copy of the GNU General Public License
0038:         * along with this program; if not, write to the Free Software
0039:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0040:         * 
0041:         */package org.zaval.tools.i18n.translator;
0042:
0043:        import java.io.*;
0044:        import java.awt.*;
0045:        import java.awt.event.KeyEvent;
0046:        import java.util.*;
0047:        import java.util.zip.*;
0048:
0049:        import org.zaval.io.*;
0050:        import org.zaval.awt.*;
0051:        import org.zaval.awt.peer.TreeNode;
0052:        import org.zaval.awt.dialog.*;
0053:        import org.zaval.util.SafeResourceBundle;
0054:
0055:        import org.apache.regexp.RE;
0056:
0057:        public class Translator extends Frame implements  TranslatorConstants,
0058:                java.awt.event.AWTEventListener {
0059:            private MessageBox2 closeDialog = null;
0060:            private MessageBox2 delDialog = null;
0061:            private MessageBox2 errDialog = null;
0062:            private MessageBox2 repDialog = null;
0063:
0064:            private EmulatedTextField keyName = null;
0065:            private IELabel keyLabel = null;
0066:            private Button keyInsertButton = null;
0067:            private Button keyDeleteButton = null;
0068:            private Button dropComment = null;
0069:            private GridBagLayout textLayout = null;
0070:            private IELabel commLab = null;
0071:            private IELabel keynLab = null;
0072:            private GraphTree tree = null;
0073:            private Panel textPanel = null;
0074:            private Vector langStates = new Vector();
0075:            private String lastDirectory = ".";
0076:
0077:            // Options
0078:            private boolean keepLastDir = true; // Keep last directory
0079:            private boolean omitSpaces = true; // remove spaces in keys
0080:            private boolean autoExpandTF = true; // auto-expand text areas
0081:            private boolean allowDot = true;
0082:            private boolean allowUScore = true;
0083:
0084:            private MenuItem newBundleMenu, openBundleMenu, openBundleMenuP,
0085:                    saveBundleMenu, saveAsBundleMenu, genMenu, parseMenu,
0086:                    saveXmlBundleMenu, saveUtfBundleMenu, loadXmlBundleMenu,
0087:                    loadUtfBundleMenu, saveXmlBundleMenuP, saveUtfBundleMenuP,
0088:                    loadXmlBundleMenuP, loadUtfBundleMenuP, loadJarMenu,
0089:                    closeMenu, exitMenu;
0090:            private MenuItem newLangMenu;
0091:            private Menu langMenu, fileMenu;
0092:            private MenuItem delMenu, insMenu, renMenu, editCopyMenu,
0093:                    editCutMenu, editPasteMenu, editDeleteMenu, searchMenu,
0094:                    searchAgainMenu, replaceToMenu;
0095:            private MenuItem aboutMenu;
0096:            private MenuItem expandTreeMenu, collapseTreeMenu, expandNodeMenu,
0097:                    collapseNodeMenu;
0098:            private CheckboxMenuItem hideTransMenu;
0099:            private MenuItem statisticsMenu;
0100:            private Menu optionsMenu;
0101:            private CheckboxMenuItem showNullsMenu;
0102:
0103:            // Options
0104:            private CheckboxMenuItem keepLastDirMenu, omitSpacesMenu,
0105:                    autoExpandTFMenu, allowDotMenu, allowUScoreMenu;
0106:
0107:            // Context menus
0108:            private MenuItem ctNewMenu, ctNodeExpandMenu, ctNodeCollapseMenu,
0109:                    ctNodeDeleteMenu, ctNodeRenameMenu;
0110:
0111:            private EmulatedTextField commField = null;
0112:            private IELabel sbl1, sbl2;
0113:
0114:            private ToolkitResolver imgres = null;
0115:            private boolean exitInitiated = true;
0116:            private boolean isDirty = false;
0117:            private String wasSelectedKey = null;
0118:            private String SYS_DIR;
0119:            private BundleManager bundle = new BundleManager();
0120:            private Panel pane = new Panel();
0121:            private Toolbar tool;
0122:            private SimpleScrollPanel scrPanel;
0123:
0124:            private String[] CLOSE_BUTTONS = new String[3];
0125:            private String[] YESNO_BUTTONS = new String[2];
0126:            private String[] DELETE_BUTTONS = new String[3];
0127:            private String[] DELETE_BUTTONS2 = new String[2];
0128:            private String[] DELETE_BUTTONS3 = new String[2];
0129:            private String[] REPLACE_BUTTONS = new String[3];
0130:
0131:            private MenuItem[] tbar2menu;
0132:
0133:            private static final int MAX_PICK_LENGTH = 40;
0134:            private Vector pickList = new Vector(8);
0135:            private int nullsCount = 0;
0136:            private int notCompletedCount = 0;
0137:
0138:            // search
0139:            private String searchCriteria = null;
0140:            private String lastKeyFound = null;
0141:            private boolean searchRegex = false;
0142:            private boolean searchData = true;
0143:            private boolean searchMask = false;
0144:            private boolean searchCase = true;
0145:            private boolean replacePrompt = true;
0146:            private boolean replaceAll = false;
0147:            private String replaceTo = null;
0148:            private BundleItem curItemForReplace = null;
0149:            private LangItem curLangForReplace = null;
0150:
0151:            private Vector tabOrder = new Vector();
0152:
0153:            public Translator(String s, SafeResourceBundle res) {
0154:                init(s, res);
0155:                onNewBundle();
0156:            }
0157:
0158:            public Translator(String s, SafeResourceBundle res,
0159:                    String bundleName) {
0160:                init(s, res);
0161:                clear();
0162:                readResources(bundleName, false);
0163:            }
0164:
0165:            private void init(String s, SafeResourceBundle res) {
0166:                SYS_DIR = s;
0167:                rcTable = res;
0168:
0169:                Toolkit.getDefaultToolkit().addAWTEventListener(this ,
0170:                        AWTEvent.KEY_EVENT_MASK);
0171:
0172:                CLOSE_BUTTONS[0] = RC("dialog.button.yes");
0173:                CLOSE_BUTTONS[1] = RC("dialog.button.no");
0174:                CLOSE_BUTTONS[2] = RC("dialog.button.cancel");
0175:
0176:                REPLACE_BUTTONS[0] = RC("dialog.button.yes");
0177:                REPLACE_BUTTONS[1] = RC("dialog.button.no");
0178:                REPLACE_BUTTONS[2] = RC("dialog.button.cancel");
0179:
0180:                YESNO_BUTTONS[0] = RC("dialog.button.yes");
0181:                YESNO_BUTTONS[1] = RC("dialog.button.no");
0182:
0183:                DELETE_BUTTONS[0] = RC("dialog.button.delete.all");
0184:                DELETE_BUTTONS[1] = RC("dialog.button.delete.this");
0185:                DELETE_BUTTONS[2] = RC("dialog.button.cancel");
0186:
0187:                DELETE_BUTTONS2[0] = DELETE_BUTTONS[0];
0188:                DELETE_BUTTONS2[1] = DELETE_BUTTONS[2];
0189:                DELETE_BUTTONS3[0] = DELETE_BUTTONS[1];
0190:                DELETE_BUTTONS3[1] = DELETE_BUTTONS[2];
0191:
0192:                imgres = new ToolkitResolver();
0193:                this .setLayout(new BorderLayout(0, 0));
0194:                add("Center", pane);
0195:
0196:                tool = new Toolbar();
0197:                tool.add(91, new IELabel(RC("menu.file") + ":"));
0198:                tool.add(0, new SpeedButton(imgres.getImage(
0199:                        SYS_DIR + "new.gif", this )));
0200:                tool.add(1, new SpeedButton(imgres.getImage(SYS_DIR
0201:                        + "load.gif", this )));
0202:                tool.add(2, new SpeedButton(imgres.getImage(SYS_DIR
0203:                        + "save.gif", this )));
0204:                tool.add(3, new SpeedButton(imgres.getImage(SYS_DIR
0205:                        + "saveas.gif", this )));
0206:                tool.add(92, new IELabel("+"));
0207:                tool.add(4, new SpeedButton(imgres.getImage(SYS_DIR
0208:                        + "deploy.gif", this )));
0209:                tool.add(5, new SpeedButton(imgres.getImage(SYS_DIR
0210:                        + "import.gif", this )));
0211:                tool.add(93, new IELabel(RC("menu.edit") + ":"));
0212:                tool.add(6, new SpeedButton(imgres.getImage(SYS_DIR
0213:                        + "newlang.gif", this )));
0214:                tool.add(7, new SpeedButton(imgres.getImage(
0215:                        SYS_DIR + "del.gif", this )));
0216:                tool.add(94, new IELabel(RC("menu.help") + ": "));
0217:                tool.add(8, new SpeedButton(imgres.getImage(SYS_DIR
0218:                        + "about.gif", this )));
0219:                add("North", tool);
0220:
0221:                setIconImage(imgres.getImage(SYS_DIR + "jrc-editor.gif"));
0222:
0223:                StatusBar panel3 = new StatusBar/*Panel*/();
0224:                panel3.add(new StatusBarElement(sbl1 = new IELabel(), 20));
0225:                panel3.add(new StatusBarElement(sbl2 = new IELabel(), 80));
0226:                StatusBarElement se = new StatusBarStubbElement(new Panel(), 0,
0227:                        new Dimension(22, 19));
0228:                se.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 2));
0229:                se.setType(0);
0230:                panel3.add(se);
0231:                add("South", panel3);
0232:
0233:                tree = new GraphTree();
0234:                tree.setResolver(imgres);
0235:                tree.setBackground(Color.white);
0236:                ContextMenuBar mbar = new ContextMenuBar(this );
0237:
0238:                ContextMenu _ctNewMenu = new ContextMenu("");
0239:                _ctNewMenu.add(ctNewMenu = new MenuItem(
0240:                        RC("tools.translator.menu.insert")));
0241:                mbar.add(_ctNewMenu);
0242:
0243:                ContextMenu _ctNodeMenu = new ContextMenu("");
0244:                _ctNodeMenu.add(ctNewMenu = new MenuItem(
0245:                        RC("tools.translator.menu.insert")));
0246:                _ctNodeMenu.add(ctNodeExpandMenu = new MenuItem(
0247:                        RC("tools.translator.menu.expand")));
0248:                _ctNodeMenu.add(ctNodeCollapseMenu = new MenuItem(
0249:                        RC("tools.translator.menu.collapse")));
0250:                _ctNodeMenu.add(ctNodeDeleteMenu = new MenuItem(
0251:                        RC("tools.translator.menu.delete")));
0252:                _ctNodeMenu.add(ctNodeRenameMenu = new MenuItem(
0253:                        RC("tools.translator.menu.rename")));
0254:                mbar.add(_ctNodeMenu);
0255:                tree.setMenuBar(mbar);
0256:
0257:                pane.setLayout(new BorderLayout());
0258:                Panel mainPanel = new BorderedPanel(BorderedPanel.RAISED2/*SUNKEN*/);
0259:                GridBagLayout gbl = new GridBagLayout();
0260:                Panel keyPanel = new Panel(gbl);
0261:
0262:                keyLabel = new IELabel(RC("tools.translator.label.key"));
0263:                constrain(keyPanel, keyLabel, 0, 0, 1, 1,
0264:                        GridBagConstraints.NORTH, GridBagConstraints.NONE, 0.0,
0265:                        0.0, 5, 5, 5, 5);
0266:
0267:                keyName = new EmulatedTextField();
0268:                keyName.setBackground(Color.white);
0269:                constrain(keyPanel, keyName, 1, 0, 1, 1,
0270:                        GridBagConstraints.NORTH, GridBagConstraints.BOTH, 1.0,
0271:                        1.0, 5, 5, 5, 5);
0272:
0273:                keyInsertButton = new Button(
0274:                        RC("tools.translator.label.insert"));
0275:                constrain(keyPanel, keyInsertButton, 2, 0, 1, 1,
0276:                        GridBagConstraints.NORTH, GridBagConstraints.NONE, 0.0,
0277:                        0.0, 5, 5, 5, 5);
0278:
0279:                keyDeleteButton = new Button(
0280:                        RC("tools.translator.label.delete"));
0281:                constrain(keyPanel, keyDeleteButton, 3, 0, 1, 1,
0282:                        GridBagConstraints.NORTH, GridBagConstraints.NONE, 0.0,
0283:                        0.0, 5, 5, 5, 5);
0284:
0285:                pane.add(keyPanel, "South");
0286:                pane.add(mainPanel, "Center");
0287:                ResizeLayout resizeLayout = new ResizeLayout();
0288:                Resizer rss = new Resizer();
0289:                textPanel = new Panel();
0290:                scrPanel = new SimpleScrollPanel(textPanel);
0291:                setBackground(Color.lightGray);
0292:                mainPanel.setLayout(resizeLayout);
0293:                mainPanel.add(tree);
0294:                mainPanel.add(scrPanel);
0295:                mainPanel.add(rss);
0296:                textLayout = new GridBagLayout();
0297:                textPanel.setLayout(textLayout);
0298:
0299:                tabOrder.add(tree);
0300:                tabOrder.add(keyName);
0301:                tabOrder.add(keyInsertButton);
0302:                tabOrder.add(keyDeleteButton);
0303:
0304:                MenuBar menuBar = new MenuBar();
0305:                fileMenu = new Menu(RC("menu.file"));
0306:                newBundleMenu = new MenuItem(
0307:                        RC("tools.translator.menu.new.bundle"),
0308:                        new MenuShortcut(KeyEvent.VK_N));
0309:                openBundleMenu = new MenuItem(RC("tools.translator.menu.open"),
0310:                        new MenuShortcut(KeyEvent.VK_O));
0311:                saveBundleMenu = new MenuItem(RC("tools.translator.menu.save"),
0312:                        new MenuShortcut(KeyEvent.VK_S));
0313:                saveBundleMenu.disable();
0314:                saveAsBundleMenu = new MenuItem(
0315:                        RC("tools.translator.menu.saveas"));
0316:                saveAsBundleMenu.disable();
0317:                closeMenu = new MenuItem(RC("tools.translator.menu.close"));
0318:                closeMenu.disable();
0319:                exitMenu = new MenuItem(RC("menu.exit"));
0320:
0321:                Menu editMenu = new Menu(RC("menu.edit"));
0322:
0323:                editCopyMenu = new MenuItem(
0324:                        RC("tools.translator.menu.edit.copy") /* , new MenuShortcut(KeyEvent.VK_C) */);
0325:                editCutMenu = new MenuItem(RC("tools.translator.menu.edit.cut") /* , new MenuShortcut(KeyEvent.VK_X) */);
0326:                editPasteMenu = new MenuItem(
0327:                        RC("tools.translator.menu.edit.paste") /* , new MenuShortcut(KeyEvent.VK_V) */);
0328:                editDeleteMenu = new MenuItem(
0329:                        RC("tools.translator.menu.edit.delete"));
0330:                searchMenu = new MenuItem(RC("menu.search"));
0331:                searchAgainMenu = new MenuItem(RC("menu.searchagain"),
0332:                        new MenuShortcut(KeyEvent.VK_F));
0333:                replaceToMenu = new MenuItem(RC("menu.replace"));
0334:
0335:                newLangMenu = new MenuItem(
0336:                        RC("tools.translator.menu.new.lang"), new MenuShortcut(
0337:                                KeyEvent.VK_L));
0338:                delMenu = new MenuItem(RC("tools.translator.menu.delete"),
0339:                        new MenuShortcut(KeyEvent.VK_D));
0340:                insMenu = new MenuItem(RC("tools.translator.menu.insert"),
0341:                        new MenuShortcut(KeyEvent.VK_I));
0342:                renMenu = new MenuItem(RC("tools.translator.menu.rename"),
0343:                        new MenuShortcut(KeyEvent.VK_R));
0344:
0345:                Menu treeMenu = new Menu(RC("menu.tree"));
0346:                expandNodeMenu = new MenuItem(
0347:                        RC("tools.translator.menu.node.expand") /*, new MenuShortcut(KeyEvent.VK_PLUS)*/);
0348:                collapseNodeMenu = new MenuItem(
0349:                        RC("tools.translator.menu.node.collapse") /*, new MenuShortcut(KeyEvent.VK_MINUS)*/);
0350:                expandTreeMenu = new MenuItem(
0351:                        RC("tools.translator.menu.expand"));
0352:                collapseTreeMenu = new MenuItem(
0353:                        RC("tools.translator.menu.collapse"));
0354:                hideTransMenu = new CheckboxMenuItem(
0355:                        RC("tools.translator.menu.hide.completed"));
0356:
0357:                Menu viewMenu = new Menu(RC("menu.options"));
0358:                statisticsMenu = new MenuItem(
0359:                        RC("tools.translator.menu.statistics"));
0360:                showNullsMenu = new CheckboxMenuItem(
0361:                        RC("tools.translator.menu.nulls"), false);
0362:                langMenu = new Menu(RC("tools.translator.menu.showres"));
0363:                langMenu.disable();
0364:                optionsMenu = new Menu/*Item*/(
0365:                        RC("tools.translator.menu.options"));
0366:                keepLastDirMenu = new CheckboxMenuItem(
0367:                        RC("tools.translator.menu.options.keeplastdir"), true);
0368:                omitSpacesMenu = new CheckboxMenuItem(
0369:                        RC("tools.translator.menu.options.omitspaces"), true);
0370:                autoExpandTFMenu = new CheckboxMenuItem(
0371:                        RC("tools.translator.menu.options.autofit"), true);
0372:                allowDotMenu = new CheckboxMenuItem(
0373:                        RC("tools.translator.menu.options.allowdot"), true);
0374:                allowUScoreMenu = new CheckboxMenuItem(
0375:                        RC("tools.translator.menu.options.allowuscore"), true);
0376:                omitSpacesMenu.disable();
0377:
0378:                Menu helpMenu = new Menu(RC("menu.help"));
0379:                aboutMenu = new MenuItem(RC("menu.about"));
0380:
0381:                Menu toolMenu = new Menu(RC("tools.translator.menu.tools"));
0382:                genMenu = new MenuItem(RC("tools.translator.menu.generate"));
0383:                genMenu.disable();
0384:                parseMenu = new MenuItem(RC("tools.translator.menu.parse"));
0385:                saveXmlBundleMenu = new MenuItem(
0386:                        RC("tools.translator.menu.save.xml"));
0387:                saveUtfBundleMenu = new MenuItem(
0388:                        RC("tools.translator.menu.save.utf"));
0389:                loadXmlBundleMenu = new MenuItem(
0390:                        RC("tools.translator.menu.load.xml"));
0391:                loadUtfBundleMenu = new MenuItem(
0392:                        RC("tools.translator.menu.load.utf"));
0393:
0394:                saveXmlBundleMenuP = new MenuItem(
0395:                        RC("tools.translator.menu.save.xml.part"));
0396:                saveUtfBundleMenuP = new MenuItem(
0397:                        RC("tools.translator.menu.save.utf.part"));
0398:                loadXmlBundleMenuP = new MenuItem(
0399:                        RC("tools.translator.menu.load.xml.part"));
0400:                loadUtfBundleMenuP = new MenuItem(
0401:                        RC("tools.translator.menu.load.utf.part"));
0402:                openBundleMenuP = new MenuItem(
0403:                        RC("tools.translator.menu.load.part"));
0404:
0405:                loadJarMenu = new MenuItem(RC("tools.translator.menu.load.jar"));
0406:
0407:                fileMenu.add(newBundleMenu);
0408:                fileMenu.add(openBundleMenu);
0409:                fileMenu.add(saveBundleMenu);
0410:                fileMenu.add(saveAsBundleMenu);
0411:                fileMenu.add(closeMenu);
0412:                fileMenu.addSeparator();
0413:
0414:                editMenu.add(newLangMenu);
0415:                editMenu.addSeparator();
0416:                editMenu.add(editCopyMenu);
0417:                editMenu.add(editCutMenu);
0418:                editMenu.add(editPasteMenu);
0419:                editMenu.add(editDeleteMenu);
0420:                editMenu.addSeparator();
0421:                editMenu.add(insMenu);
0422:                editMenu.add(delMenu);
0423:                editMenu.add(renMenu);
0424:                editMenu.addSeparator();
0425:                editMenu.add(searchMenu);
0426:                editMenu.add(searchAgainMenu);
0427:                editMenu.add(replaceToMenu);
0428:
0429:                treeMenu.add(expandNodeMenu);
0430:                treeMenu.add(collapseNodeMenu);
0431:                treeMenu.addSeparator();
0432:                treeMenu.add(expandTreeMenu);
0433:                treeMenu.add(collapseTreeMenu);
0434:                treeMenu.add(hideTransMenu);
0435:
0436:                viewMenu.add(langMenu);
0437:                viewMenu.add(showNullsMenu);
0438:                viewMenu.add(statisticsMenu);
0439:                viewMenu.addSeparator();
0440:                viewMenu.add(optionsMenu);
0441:
0442:                optionsMenu.add(keepLastDirMenu);
0443:                optionsMenu.add(omitSpacesMenu);
0444:                optionsMenu.add(autoExpandTFMenu);
0445:                optionsMenu.add(allowDotMenu);
0446:                optionsMenu.add(allowUScoreMenu);
0447:
0448:                toolMenu.add(loadJarMenu);
0449:                toolMenu.addSeparator();
0450:                toolMenu.add(loadXmlBundleMenu);
0451:                toolMenu.add(loadUtfBundleMenu);
0452:                toolMenu.add(saveXmlBundleMenu);
0453:                toolMenu.add(saveUtfBundleMenu);
0454:                toolMenu.addSeparator();
0455:                toolMenu.add(openBundleMenuP);
0456:                toolMenu.add(loadXmlBundleMenuP);
0457:                toolMenu.add(loadUtfBundleMenuP);
0458:                toolMenu.add(saveXmlBundleMenuP);
0459:                toolMenu.add(saveUtfBundleMenuP);
0460:                toolMenu.addSeparator();
0461:                toolMenu.add(genMenu);
0462:                toolMenu.add(parseMenu);
0463:
0464:                helpMenu.add(aboutMenu);
0465:
0466:                menuBar.add(fileMenu);
0467:                menuBar.add(editMenu);
0468:                menuBar.add(viewMenu);
0469:                menuBar.add(treeMenu);
0470:                menuBar.add(toolMenu);
0471:                menuBar.add(helpMenu);
0472:                setMenuBar(menuBar);
0473:
0474:                delDialog = new MessageBox2(this );
0475:                delDialog.setIcon(imgres.getImage(SYS_DIR + "ogo.gif",
0476:                        delDialog));
0477:                delDialog.setTitle(RC("dialog.title.warning"));
0478:                delDialog.setButtons(DELETE_BUTTONS);
0479:                delDialog.addListener(this );
0480:
0481:                closeDialog = new MessageBox2(this );
0482:                closeDialog.setText(RC("tools.translator.message.save"));
0483:                closeDialog.setTitle(RC("dialog.title.warning"));
0484:                closeDialog.setIcon(imgres.getImage(SYS_DIR + "ogo.gif",
0485:                        closeDialog));
0486:                closeDialog.setButtons(CLOSE_BUTTONS);
0487:                closeDialog.addListener(this );
0488:
0489:                repDialog = new MessageBox2(this );
0490:                repDialog.setText("");
0491:                repDialog.setTitle(RC("dialog.title.warning"));
0492:                repDialog.setIcon(imgres.getImage(SYS_DIR + "ogo.gif",
0493:                        repDialog));
0494:                repDialog.setButtons(REPLACE_BUTTONS);
0495:                repDialog.addListener(this );
0496:
0497:                errDialog = new MessageBox2(this );
0498:                errDialog.setText("");
0499:                errDialog.setTitle(RC("dialog.title.warning"));
0500:                errDialog.setIcon(imgres.getImage(SYS_DIR + "Stop.gif",
0501:                        errDialog));
0502:                String[] OK_BUT = { RC("dialog.button.ok") };
0503:                errDialog.setButtons(OK_BUT);
0504:
0505:                MenuItem[] _tbar2menu = { newBundleMenu, openBundleMenu,
0506:                        saveBundleMenu, saveAsBundleMenu, genMenu, parseMenu,
0507:                        newLangMenu, delMenu, aboutMenu };
0508:                tbar2menu = _tbar2menu;
0509:            }
0510:
0511:            public boolean handleEvent(Event e) {
0512:                if (e.id == Event.WINDOW_DESTROY) {
0513:                    onClose();
0514:                    return true;
0515:                }
0516:
0517:                if (e.target == tree) {
0518:                    if (e.id == REMOVE_REQUIRED)
0519:                        onDeleteKey();
0520:                    if (e.target == tree
0521:                            && wasSelectedKey != tree.getSelectedText()) {
0522:                        setTranslations();
0523:                        invokeAutoFit();
0524:                    }
0525:                    // actually, we should just list all events that tree can handle itself.
0526:                    // if ( e.key != (int)'\t' && e.key != Event.F4 && e.key != Event.F10) return true;
0527:                }
0528:                return super .handleEvent(e);
0529:            }
0530:
0531:            public void eventDispatched(AWTEvent event) {
0532:                if (event.getID() != java.awt.event.KeyEvent.KEY_TYPED)
0533:                    return;
0534:                if (!(event instanceof  java.awt.event.KeyEvent))
0535:                    return;
0536:                java.awt.event.KeyEvent ke = (java.awt.event.KeyEvent) event;
0537:                if (ke.getKeyChar() != '\t')
0538:                    return;
0539:                moveFocus();
0540:            }
0541:
0542:            public boolean keyDown(Event e, int key) {
0543:                if (e.target == keyName && key == Event.ENTER) {
0544:                    onInsertKey();
0545:                    return true;
0546:                } else if (e.target instanceof  Button && key == Event.ENTER) {
0547:                    action(e, null);
0548:                    return true;
0549:                }
0550:                // to be corrected if keyName wants to receive "Enter" from JTextField
0551:                return false;
0552:            }
0553:
0554:            public boolean action(Event e, Object arg) {
0555:                if (e.target instanceof  Toolbar) {
0556:                    int pos = Integer.parseInt((String) arg);
0557:                    if (pos < 0 || pos >= tbar2menu.length)
0558:                        return false;
0559:                    e.target = tbar2menu[pos];
0560:                }
0561:
0562:                if (e.target == statisticsMenu)
0563:                    onStatistics();
0564:                if (e.target == searchMenu)
0565:                    onSearch();
0566:                if (e.target == searchAgainMenu)
0567:                    onSearchAgain();
0568:                if (e.target == replaceToMenu)
0569:                    onReplace();
0570:
0571:                if (e.target == expandNodeMenu || e.target == ctNodeExpandMenu)
0572:                    expand(tree.getSelectedNode());
0573:                if (e.target == collapseNodeMenu
0574:                        || e.target == ctNodeCollapseMenu)
0575:                    collapse(tree.getSelectedNode());
0576:                if (e.target == expandTreeMenu) {
0577:                    tree.expandAll();
0578:                    tree.repaint();
0579:                }
0580:                if (e.target == collapseTreeMenu) {
0581:                    tree.collapseAll();
0582:                    tree.repaint();
0583:                }
0584:                if (e.target == hideTransMenu)
0585:                    hideTranslated(hideTransMenu.getState());
0586:                if (e.target == dropComment) {
0587:                    commField.setText("");
0588:                    setTranslations();
0589:                }
0590:
0591:                if (e.target == editCopyMenu) {
0592:                    Component ccur = getFocusOwner();
0593:                    if (ccur instanceof  EmulatedTextField) {
0594:                        EmulatedTextField cur = (EmulatedTextField) ccur;
0595:                        cur.blCopy();
0596:                    } else if (ccur instanceof  TextField) {
0597:                        TextField cur = (TextField) ccur;
0598:                        java.awt.datatransfer.Clipboard c = java.awt.Toolkit
0599:                                .getDefaultToolkit().getSystemClipboard();
0600:                        java.awt.datatransfer.StringSelection s2 = new java.awt.datatransfer.StringSelection(
0601:                                cur.getSelectedText());
0602:                        c.setContents(s2, s2);
0603:                    }
0604:                }
0605:                if (e.target == editCutMenu) {
0606:                    Component ccur = getFocusOwner();
0607:                    if (ccur instanceof  EmulatedTextField) {
0608:                        EmulatedTextField cur = (EmulatedTextField) ccur;
0609:                        cur.blCopy();
0610:                        cur.blDelete();
0611:                    } else if (ccur instanceof  TextField) {
0612:                        TextField cur = (TextField) ccur;
0613:                        java.awt.datatransfer.Clipboard c = java.awt.Toolkit
0614:                                .getDefaultToolkit().getSystemClipboard();
0615:                        java.awt.datatransfer.StringSelection s2 = new java.awt.datatransfer.StringSelection(
0616:                                cur.getSelectedText());
0617:                        c.setContents(s2, s2);
0618:                        if (cur.getSelectedText().length() > 0)
0619:                            cur.setText(cur.getText().substring(0,
0620:                                    cur.getSelectionStart())
0621:                                    + cur.getText().substring(
0622:                                            cur.getSelectionEnd()));
0623:                    }
0624:                }
0625:                if (e.target == editPasteMenu) {
0626:                    Component ccur = getFocusOwner();
0627:                    if (ccur instanceof  EmulatedTextField) {
0628:                        EmulatedTextField cur = (EmulatedTextField) ccur;
0629:                        cur.blPaste();
0630:                    } else if (ccur instanceof  TextField) {
0631:                        TextField cur = (TextField) ccur;
0632:
0633:                        java.awt.datatransfer.Clipboard c = java.awt.Toolkit
0634:                                .getDefaultToolkit().getSystemClipboard();
0635:                        java.awt.datatransfer.Transferable t = c
0636:                                .getContents("e");
0637:
0638:                        String nt = "";
0639:                        if (t
0640:                                .isDataFlavorSupported(java.awt.datatransfer.DataFlavor.stringFlavor))
0641:                            try {
0642:                                nt = (String) t
0643:                                        .getTransferData(java.awt.datatransfer.DataFlavor.stringFlavor);
0644:                            } catch (Exception ex) {
0645:                            }
0646:
0647:                        if (cur.getSelectedText().length() > 0)
0648:                            cur.setText(cur.getText().substring(0,
0649:                                    cur.getSelectionStart())
0650:                                    + nt
0651:                                    + cur.getText().substring(
0652:                                            cur.getSelectionEnd()));
0653:                        else
0654:                            cur.setText(cur.getText().substring(0,
0655:                                    cur.getCaretPosition())
0656:                                    + nt
0657:                                    + cur.getText().substring(
0658:                                            cur.getCaretPosition()));
0659:                    }
0660:                }
0661:                if (e.target == editDeleteMenu) {
0662:                    Component ccur = getFocusOwner();
0663:                    if (ccur instanceof  EmulatedTextField) {
0664:                        EmulatedTextField cur = (EmulatedTextField) ccur;
0665:                        cur.blDelete();
0666:                    } else if (ccur instanceof  TextField) {
0667:                        TextField cur = (TextField) ccur;
0668:                        if (cur.getSelectedText().length() > 0)
0669:                            cur.setText(cur.getText().substring(0,
0670:                                    cur.getSelectionStart())
0671:                                    + cur.getText().substring(
0672:                                            cur.getSelectionEnd()));
0673:                    }
0674:                }
0675:
0676:                if (e.target == newLangMenu)
0677:                    onNewResource();
0678:                if (e.target == insMenu || e.target == ctNewMenu)
0679:                    onNewKey();
0680:                if (e.target == renMenu || e.target == ctNodeRenameMenu)
0681:                    onRenameKey();
0682:                if (e.target == newBundleMenu)
0683:                    onNewBundle();
0684:                if (e.target == closeMenu) {
0685:                    exitInitiated = false;
0686:                    onClose();
0687:                }
0688:                if (e.target == openBundleMenu)
0689:                    onOpen(false);
0690:                if (e.target == saveBundleMenu)
0691:                    onSave();
0692:                if (e.target == saveAsBundleMenu)
0693:                    onSaveAs();
0694:                if (e.target == exitMenu)
0695:                    onClose();
0696:                if (e.target == keyInsertButton)
0697:                    onInsertKey();
0698:                if (e.target == keyDeleteButton || e.target == delMenu
0699:                        || e.target == ctNodeDeleteMenu)
0700:                    onDeleteKey();
0701:                if (e.target == genMenu)
0702:                    onGenCode();
0703:                if (e.target == parseMenu)
0704:                    onParseCode();
0705:                if (e.target == aboutMenu)
0706:                    onAbout();
0707:                if (e.target == optionsMenu)
0708:                    onOptions();
0709:
0710:                if (e.target == loadXmlBundleMenu)
0711:                    onLoadXml(false);
0712:                if (e.target == saveXmlBundleMenu)
0713:                    onSaveXml(false);
0714:                if (e.target == loadUtfBundleMenu)
0715:                    onLoadUtf(false);
0716:                if (e.target == saveUtfBundleMenu)
0717:                    onSaveUtf(false);
0718:
0719:                if (e.target == openBundleMenuP)
0720:                    onOpen(true);
0721:                if (e.target == loadXmlBundleMenuP)
0722:                    onLoadXml(true);
0723:                if (e.target == saveXmlBundleMenuP)
0724:                    onSaveXml(true);
0725:                if (e.target == loadUtfBundleMenuP)
0726:                    onLoadUtf(true);
0727:                if (e.target == saveUtfBundleMenuP)
0728:                    onSaveUtf(true);
0729:
0730:                if (e.target == loadJarMenu)
0731:                    onLoadJar();
0732:
0733:                if (e.target instanceof  CheckboxMenuItem
0734:                        && e.target == showNullsMenu) {
0735:                    setIndicators(tree.getRootNode());
0736:                    tree.repaint();
0737:                }
0738:                if (e.target instanceof  CheckboxMenuItem)
0739:                    for (int i = 0; i < langStates.size(); i++) {
0740:                        LangState ls = getLangState(i);
0741:                        if (e.target == ls.box) {
0742:                            ls.hidden = !ls.hidden;
0743:                            ls.tf.setVisible(!ls.hidden);
0744:                            ls.label.setVisible(!ls.hidden);
0745:                            setIndicators(tree.getRootNode());
0746:                            textPanel.invalidate();
0747:                            validate();
0748:                        }
0749:                        ls.box.setState(!ls.hidden);
0750:                    }
0751:                if (e.target == closeDialog && e.arg instanceof  Button) {
0752:                    if (!((Button) e.arg).getLabel().equals(CLOSE_BUTTONS[2])) {
0753:                        if (((Button) e.arg).getLabel()
0754:                                .equals(CLOSE_BUTTONS[0]))
0755:                            onSave();
0756:                        if (exitInitiated)
0757:                            finish();
0758:                        else
0759:                            clear();
0760:                    }
0761:                    exitInitiated = true;
0762:                }
0763:                if (e.target == delDialog
0764:                        && e.arg instanceof  Button
0765:                        && ((Button) e.arg).getLabel()
0766:                                .equals(DELETE_BUTTONS[0])) {
0767:                    String key = tree.getSelectedText();
0768:                    // remove all subkeys
0769:                    if (key != null) {
0770:                        isDirty = true;
0771:                        TreeNode tn = tree.getNode(key);
0772:                        if (tn != null)
0773:                            tn = tn.parent;
0774:                        bundle.getBundle().removeKeysBeginningWith(key);
0775:
0776:                        tree.remove(key); // kill children
0777:                        removeLeafs(key); // clean leafs out of model
0778:                        adjustIndicator(tn);
0779:                        tree.repaint();
0780:                        wasSelectedKey = null;
0781:                        setTranslations();
0782:                    }
0783:                }
0784:                if (e.target == delDialog
0785:                        && e.arg instanceof  Button
0786:                        && ((Button) e.arg).getLabel()
0787:                                .equals(DELETE_BUTTONS[1])) {
0788:                    // Only this
0789:                    String key = tree.getSelectedText();
0790:                    if (key != null) {
0791:                        isDirty = true;
0792:                        TreeNode tn = tree.getNode(key);
0793:                        if (tn == null)
0794:                            return true;
0795:
0796:                        // Not an leaf => don't touch tree but update model
0797:                        bundle.getBundle().removeKey(key);
0798:                        if (tree.enumChild(tn) == null
0799:                                || tree.enumChild(tn).length == 0) {
0800:                            tree.remove(key);
0801:                            removeLeafs(key);
0802:                        }
0803:                        tree.selectNode(tn.parent);
0804:
0805:                        adjustIndicator(tn);
0806:                        tree.repaint();
0807:
0808:                        wasSelectedKey = null;
0809:                        setTranslations();
0810:                        textPanel.invalidate();
0811:                        validate();
0812:                    }
0813:                }
0814:
0815:                if (e.target == repDialog) {
0816:                    if (e.arg instanceof  Button
0817:                            && ((Button) e.arg).getLabel().equals(
0818:                                    REPLACE_BUTTONS[0]))
0819:                        makeReplaceImpl();
0820:                    else if (e.arg instanceof  Button
0821:                            && ((Button) e.arg).getLabel().equals(
0822:                                    REPLACE_BUTTONS[2]))
0823:                        replaceTo = null;
0824:                }
0825:
0826:                if (e.target == keepLastDirMenu)
0827:                    keepLastDir = keepLastDirMenu.getState();
0828:                if (e.target == omitSpacesMenu)
0829:                    omitSpaces = omitSpacesMenu.getState();
0830:                if (e.target == autoExpandTFMenu)
0831:                    autoExpandTF = autoExpandTFMenu.getState();
0832:                if (e.target == allowDotMenu)
0833:                    allowDot = allowDotMenu.getState();
0834:                if (e.target == allowUScoreMenu)
0835:                    allowUScore = allowUScoreMenu.getState();
0836:
0837:                if (e.target instanceof  MenuItem) {
0838:                    String lbl = ((MenuItem) e.target).getLabel();
0839:                    for (int j = 0; j < pickList.size(); ++j) {
0840:                        String path = (String) pickList.elementAt(j);
0841:                        String patz = stretchPath(path);
0842:                        if (patz.equals(lbl)) {
0843:                            clear();
0844:                            readResources(path, false);
0845:                            break;
0846:                        }
0847:                    }
0848:                }
0849:                sbl1.setText(" " + getVisLangCount() + "/"
0850:                        + bundle.getBundle().getLangCount() + ", "
0851:                        + bundle.getBundle().getItemCount() + " ");
0852:                return true;
0853:            }
0854:
0855:            private void setTranslations() {
0856:                String newKey = tree.getSelectedText();
0857:                setTranslations(newKey);
0858:            }
0859:
0860:            private void setTranslations(String newKey) {
0861:                if (wasSelectedKey != null) {
0862:                    for (int i = 0; i < langStates.size(); i++) {
0863:                        LangState ls = getLangState(i);
0864:                        if (ls.hidden)
0865:                            continue;
0866:                        String trans = ls.tf.getText();
0867:                        BundleItem bi = bundle.getBundle().getItem(
0868:                                wasSelectedKey);
0869:                        if (bi == null) {
0870:                            // do not add the translation implicitely - disable
0871:                            // the language field
0872:                            ls.tf.setVisible(false);
0873:                            ls.label.setVisible(false);
0874:                            commField.setEnabled(false);
0875:                        } else {
0876:                            if (bi.getTranslation(ls.name) == null
0877:                                    || !bi.getTranslation(ls.name)
0878:                                            .equals(trans))
0879:                                isDirty = true;
0880:                            bundle.getBundle().updateValue(wasSelectedKey,
0881:                                    ls.name, trans);
0882:                        }
0883:                    }
0884:                    String comm = commField == null ? null : commField
0885:                            .getText();
0886:                    if (comm != null && comm.trim().length() == 0)
0887:                        comm = null;
0888:                    //if ( comm!=null ) {
0889:                    BundleItem bi = bundle.getBundle().getItem(wasSelectedKey);
0890:                    if (bi != null)
0891:                        bi.setComment(comm);
0892:                    //}
0893:                    adjustIndicator(tree.getNode(wasSelectedKey));
0894:                    setIndicators(tree.getNode(wasSelectedKey));
0895:                    tree.repaint();
0896:                }
0897:                if (newKey == null)
0898:                    return;
0899:
0900:                BundleItem bi = bundle.getBundle().getItem(newKey);
0901:                for (int i = 0; i < langStates.size(); i++) {
0902:                    LangState ls = getLangState(i);
0903:                    String ss = bi == null ? null : bi.getTranslation(ls.name);
0904:                    if (ss == null)
0905:                        ss = "";
0906:                    if (bi == null) {
0907:                        ls.tf.setVisible(false);
0908:                        ls.label.setVisible(false);
0909:                        commField.setEnabled(false);
0910:                    } else {
0911:                        ls.tf.setVisible(!ls.hidden);
0912:                        ls.label.setVisible(!ls.hidden);
0913:                        commField.setEnabled(true);
0914:                    }
0915:                    ls.tf.setText(ss);
0916:                }
0917:                String commText = bi == null ? " ** "
0918:                        + RC("tools.translator.message.noentry") + " **" : bi
0919:                        .getComment();
0920:                if (commField != null)
0921:                    commField.setText(commText == null ? "" : commText);
0922:                keynLab.setText("Key: " + newKey);
0923:                keynLab.repaint();
0924:                sbl2.setText(newKey);
0925:                adjustIndicator(tree.getNode(newKey));
0926:
0927:                String startValue = "";
0928:                wasSelectedKey = newKey;
0929:                if (wasSelectedKey != null)
0930:                    startValue = wasSelectedKey + ".";
0931:                keyName.setText(startValue);
0932:                tree.repaint();
0933:
0934:                /*if(bi==null){ 
0935:                    ctNodeRenameMenu.disable();
0936:                    ctNodeDeleteMenu.disable();
0937:                    renMenu.disable();
0938:                  }
0939:                  else{
0940:                    ctNodeDeleteMenu.enable();
0941:                    renMenu.enable();
0942:                    ctNodeRenameMenu.enable();
0943:                  }*/
0944:            }
0945:
0946:            public String getValidKey() {
0947:                String key = keyName.getText();
0948:                if (key == null)
0949:                    return null;
0950:                while (key.endsWith("."))
0951:                    key = key.substring(0, key.length() - 1);
0952:                if (key.length() <= 0)
0953:                    return null;
0954:                String illegalChar = "";
0955:                if (key.indexOf('=') >= 0)
0956:                    illegalChar = "=";
0957:                if (key.indexOf('#') >= 0)
0958:                    illegalChar = "#";
0959:                if (illegalChar.length() == 0)
0960:                    return bundle.replace(key, "..", "");
0961:                MessageBox2 mess = new MessageBox2(this );
0962:                mess.setTitle(RC("dialog.title.warning"));
0963:                mess.setText(bundle.replace(
0964:                        RC("tools.translator.message.illchar"), "[%illchar%]",
0965:                        illegalChar));
0966:                mess.setIcon(imgres.getImage(SYS_DIR + "stop.gif", mess));
0967:                mess.setButtons(RC("dialog.button.ok"));
0968:                mess.show();
0969:                return null;
0970:            }
0971:
0972:            public void onInsertKey() {
0973:                if (bundle.getBundle().getLangCount() == 0)
0974:                    return;
0975:                String key = getValidKey();
0976:                if (key != null) {
0977:                    addToTree(key);
0978:                    bundle.getBundle().addKey(key);
0979:                    bundle.getBundle().resort();
0980:                    commField.setText("");
0981:                    isDirty = true;
0982:                    tree.selectNodeAndOpen(key);
0983:                    tree.repaint();
0984:                    setTranslations();
0985:                    saveBundleMenu.enable();
0986:                    saveAsBundleMenu.enable();
0987:                    genMenu.enable();
0988:                    setIndicators(tree.getRootNode());
0989:                    isDirty = true;
0990:
0991:                    textPanel.invalidate();
0992:                    validate();
0993:                }
0994:                syncToolbar();
0995:            }
0996:
0997:            public void onDeleteKey() {
0998:                String key = tree.getSelectedText();
0999:                if (key == null)
1000:                    return;
1001:                delDialog.setText(bundle.replace(
1002:                        RC("tools.translator.message.delkey"), "[%key%]", key));
1003:
1004:                TreeNode tn = tree.getNode(key);
1005:                if (tn == null)
1006:                    return;
1007:                boolean hasChilds = tree.enumChild(tn) != null
1008:                        && tree.enumChild(tn).length != 0;
1009:                BundleItem bi = bundle.getBundle().getItem(key);
1010:                if (bi != null && hasChilds)
1011:                    delDialog.setButtons(DELETE_BUTTONS);
1012:                else if (bi != null && !hasChilds)
1013:                    delDialog.setButtons(DELETE_BUTTONS3);
1014:                else if (bi == null)
1015:                    delDialog.setButtons(DELETE_BUTTONS2);
1016:                delDialog.show();
1017:            }
1018:
1019:            public void onClose() {
1020:                setTranslations();
1021:                if (isDirty)
1022:                    closeDialog.show();
1023:                else if (exitInitiated)
1024:                    finish();
1025:                else {
1026:                    clear();
1027:                    exitInitiated = true;
1028:                }
1029:            }
1030:
1031:            public void finish() {
1032:                hide();
1033:                saveIni();
1034:                System.exit(0);
1035:            }
1036:
1037:            public void onSave() {
1038:                if (bundle.getBundle().getLangCount() == 0)
1039:                    return;
1040:                String fn = bundle.getBundle().getLanguage(0).getLangFile();
1041:                if (fn == null) {
1042:                    onSaveAs();
1043:                    return;
1044:                }
1045:                setTranslations();
1046:                try {
1047:                    bundle.store(null);
1048:                } catch (Exception e) {
1049:                    infoException(e);
1050:                }
1051:                isDirty = false;
1052:            }
1053:
1054:            public void clear() {
1055:                setTitle(null);
1056:                if (keyName != null)
1057:                    keyName.setText("");
1058:                if (keynLab != null)
1059:                    keynLab.setText("");
1060:                wasSelectedKey = null;
1061:                textPanel.removeAll();
1062:                langMenu.removeAll();
1063:                if (tree.getRootNode() != null)
1064:                    tree.remove(tree.getRootNode());
1065:                tree.repaint();
1066:                textPanel.invalidate();
1067:                validate();
1068:                isDirty = false;
1069:                bundle = new BundleManager();
1070:                langStates = new Vector();
1071:
1072:                closeMenu.disable();
1073:                saveBundleMenu.disable();
1074:                saveAsBundleMenu.disable();
1075:                genMenu.disable();
1076:                langMenu.disable();
1077:            }
1078:
1079:            private LangState getLangState(int idx) {
1080:                return (LangState) langStates.elementAt(idx);
1081:            }
1082:
1083:            private int getVisLangCount() {
1084:                int c = 0;
1085:                for (int i = 0; i < langStates.size(); i++) {
1086:                    LangState ls = getLangState(i);
1087:                    if (!ls.hidden)
1088:                        ++c;
1089:                }
1090:                return c;
1091:            }
1092:
1093:            private void setAllIndicators() {
1094:                for (int i = 0; i < langStates.size(); i++) {
1095:                    LangState ls = getLangState(i);
1096:                    ls.hidden = false;
1097:                    ls.box.setState(true);
1098:                }
1099:                // Fire it async as it take large time
1100:                hideTransMenu.disable();
1101:                (new Thread(new Runnable() {
1102:                    public void run() {
1103:                        setIndicatorsInit();
1104:                    }
1105:                })).start();
1106:            }
1107:
1108:            private void setIndicatorsInit() {
1109:                sbl2.setText(RC("tools.translator.progress.indicator"));
1110:                sbl2.repaint();
1111:                setIndicators(tree.getRootNode());
1112:                hideTransMenu.enable();
1113:                sbl2.setText("");
1114:                sbl2.repaint();
1115:            }
1116:
1117:            private boolean setIndicators(TreeNode tn) {
1118:                if (tn == null)
1119:                    return false;
1120:                boolean res = setIndicators(tn.sibling);
1121:                return setIndicator(tn, setIndicators(tn.child)) || res;
1122:            }
1123:
1124:            private boolean setIndicator(TreeNode tn, boolean childOn) {
1125:                if (tn == null)
1126:                    return false;
1127:                if (getVisLangCount() < 2) {
1128:                    tn.setIndicator(null);
1129:                    return false;
1130:                }
1131:                if (childOn) {
1132:                    tn.setIndicator(SYS_DIR + WARN_IMAGE);
1133:                    return true;
1134:                }
1135:                boolean isAbs = false;
1136:                boolean isPres = false;
1137:
1138:                BundleItem bi = bundle.getBundle().getItem(tn.getText());
1139:                if (bi == null) {
1140:                    tn.setIndicator(null);
1141:                    return false;
1142:                }
1143:                for (int i = 0; i < langStates.size(); i++) {
1144:                    LangState ls = getLangState(i);
1145:                    if (ls.hidden)
1146:                        continue;
1147:                    String ts = bi.getTranslation(ls.name);
1148:                    if (ts != null && ts.trim().length() == 0)
1149:                        ts = null;
1150:                    isAbs |= ts == null;
1151:                    isPres |= ts != null;
1152:                }
1153:                tn.setIndicator(null);
1154:                if (isAbs && isPres) {
1155:                    tree.setIndicator(tn.getText(), SYS_DIR + WARN_IMAGE);
1156:                    notCompletedCount++;
1157:                } else {
1158:                    if (isAbs) {
1159:                        nullsCount++;
1160:                        if (showNullsMenu.getState()) {
1161:                            tn.setIndicator(SYS_DIR + WARN_IMAGE);
1162:                            return true;
1163:                        }
1164:                    }
1165:                }
1166:                return isAbs && isPres;
1167:            }
1168:
1169:            private void adjustIndicator(TreeNode tn) {
1170:                if (tn == null)
1171:                    return;
1172:                setIndicator(tn, isSetInSiblings(tn.child));
1173:                adjustIndicator(tn.parent);
1174:            }
1175:
1176:            private boolean isSetInSiblings(TreeNode tn) {
1177:                if (tn == null)
1178:                    return false;
1179:                if (tn.getIndicator() != null)
1180:                    return true;
1181:                return isSetInSiblings(tn.sibling);
1182:            }
1183:
1184:            private void createNewFile(String filename) {
1185:                try {
1186:                    FileOutputStream f = new FileOutputStream(filename);
1187:                    f.close();
1188:                } catch (Exception e) {
1189:                    infoException(e);
1190:                }
1191:            }
1192:
1193:            private void onSearch() {
1194:                SearchDialog ed = new SearchDialog(this ,
1195:                        RC("tools.translator.label.search.caption"), true, this );
1196:                ed.setLabelCaption(RC("tools.translator.label.search.label"));
1197:                ed.setButtonsCaption(RC("dialog.button.ok"), CLOSE_BUTTONS[2]);
1198:
1199:                ed.setKVGroupLabels(RC("tools.translator.label.search.inkeys"),
1200:                        RC("tools.translator.label.search.invalues"));
1201:                ed.setRMEGroupLabels(RC("tools.translator.label.search.regex"),
1202:                        RC("tools.translator.label.search.mask"),
1203:                        RC("tools.translator.label.search.exact"));
1204:                ed.setCaseLabel(RC("tools.translator.label.search.case"));
1205:
1206:                ed.doModal();
1207:                String text = ed.getText();
1208:                if (text.length() <= 0 || !ed.isApply())
1209:                    return;
1210:
1211:                searchCriteria = text;
1212:                searchRegex = ed.isRegexMatching();
1213:                searchData = !ed.isKeyMatching();
1214:                searchMask = ed.isMaskMatching();
1215:                searchCase = ed.isCaseSensitive();
1216:                replaceTo = null;
1217:                if (!searchRegex && !searchMask && !searchCase)
1218:                    searchCriteria = searchCriteria.toLowerCase();
1219:
1220:                lastKeyFound = null;
1221:                onSearchAgain();
1222:                ed.dispose();
1223:            }
1224:
1225:            private void onReplace() {
1226:                ReplaceDialog ed = new ReplaceDialog(this ,
1227:                        RC("tools.translator.label.replace.caption"), true,
1228:                        this );
1229:                ed.setLabelCaption(RC("tools.translator.label.search.label"));
1230:                ed.setButtonsCaption(RC("dialog.button.ok"), CLOSE_BUTTONS[2]);
1231:                ed.setReplaceLabel(RC("tools.translator.label.replace.label"));
1232:
1233:                ed.setRMGroupLabels(RC("tools.translator.label.search.regex"),
1234:                        RC("tools.translator.label.search.exact"));
1235:                ed.setCPALabels(RC("tools.translator.label.search.case"),
1236:                        RC("tools.translator.label.replace.prompt"),
1237:                        RC("tools.translator.label.replace.all"));
1238:
1239:                ed.doModal();
1240:                String text = ed.getText();
1241:                if (text.length() <= 0 || !ed.isApply())
1242:                    return;
1243:
1244:                searchCriteria = text;
1245:                searchRegex = ed.isRegexMatching();
1246:                searchData = true;
1247:                searchMask = false;
1248:                searchCase = ed.isCaseSensitive();
1249:                replacePrompt = ed.isPromptRequired();
1250:                replaceAll = ed.isReplaceAll();
1251:                replaceTo = ed.getReplaceTo();
1252:
1253:                if (!searchRegex && !searchMask && !searchCase)
1254:                    searchCriteria = searchCriteria.toLowerCase();
1255:
1256:                lastKeyFound = null;
1257:                onSearchAgain();
1258:            }
1259:
1260:            private boolean isMatchedWith(String what) {
1261:                if (what == null)
1262:                    return false;
1263:                if (searchRegex)
1264:                    return match_regex(searchCriteria, what, !searchCase);
1265:                else if (searchMask)
1266:                    return match_mask(searchCriteria, what, !searchCase);
1267:                else {
1268:                    if (searchCase)
1269:                        return what.indexOf(searchCriteria) != -1;
1270:                    else
1271:                        return what.toLowerCase().indexOf(searchCriteria) != -1;
1272:                }
1273:            }
1274:
1275:            private void makeReplaceImpl()
1276:            /*
1277:                BundleItem curItemForReplace
1278:                LangItem curLangForReplace
1279:                String searchCriteria
1280:                String replaceTo
1281:             */
1282:            {
1283:                String lang = curLangForReplace.getLangId();
1284:                String val = curItemForReplace.getTranslation(lang);
1285:                if (searchRegex) {
1286:                    try {
1287:                        RE re = new RE(searchCriteria,
1288:                                searchCase ? RE.MATCH_NORMAL
1289:                                        : RE.MATCH_CASEINDEPENDENT);
1290:                        val = re.subst(val, replaceTo,
1291:                                replaceAll ? RE.REPLACE_ALL
1292:                                        : RE.REPLACE_FIRSTONLY);
1293:                    } catch (org.apache.regexp.RESyntaxException e) {
1294:                        infoException(e);
1295:                        replaceTo = null;
1296:                    }
1297:                } else {
1298:                    if (replaceAll)
1299:                        val = bundle.replace(val, searchCriteria, replaceTo);
1300:                    else {
1301:                        int j1 = val.indexOf(searchCriteria);
1302:                        if (j1 > 0)
1303:                            val = val.substring(0, j1)
1304:                                    + replaceTo
1305:                                    + val.substring(j1
1306:                                            + searchCriteria.length());
1307:                        else if (j1 == 0)
1308:                            val = replaceTo
1309:                                    + val.substring(searchCriteria.length());
1310:                    }
1311:                }
1312:                // System.err.println("["+lang+"] '"+curItemForReplace.getTranslation(lang)+"' => '"+val+"'");
1313:                curItemForReplace.setTranslation(lang, val);
1314:
1315:                if (tree.getSelectedText().equals(curItemForReplace.getId())) {
1316:                    int k = bundle.getBundle().getLangIndex(lang);
1317:                    LangState ls = getLangState(k);
1318:                    if (ls != null) {
1319:                        ls.tf.setText(val);
1320:                        ls.tf.getControl().requestFocus();
1321:                    }
1322:                }
1323:                isDirty = true;
1324:            }
1325:
1326:            private void makeReplace(BundleItem bi, LangItem li) {
1327:                curItemForReplace = bi;
1328:                curLangForReplace = li;
1329:                if (replacePrompt) {
1330:                    if (replacePrompt && replaceAll) {
1331:                        setTranslations();
1332:                        tree.selectNode(curItemForReplace.getId());
1333:                        tree.openToNode(curItemForReplace.getId());
1334:                        setTranslations(curItemForReplace.getId());
1335:                        textPanel.invalidate();
1336:                        validate();
1337:                        tree.repaint();
1338:                    }
1339:                    repDialog.setModal(replaceAll);
1340:                    String mess = RC("tools.translator.message.found");
1341:                    mess = bundle.replace(mess, "[%found%]", searchCriteria);
1342:                    mess = bundle.replace(mess, "[%subst%]", replaceTo);
1343:                    repDialog.setText(mess);
1344:                    repDialog.show();
1345:                } else
1346:                    makeReplaceImpl();
1347:            }
1348:
1349:            private void onSearchAgain() {
1350:                int i, j = 0;
1351:                if (searchCriteria == null) {
1352:                    onSearch();
1353:                    return;
1354:                }
1355:                boolean first = lastKeyFound == null;
1356:
1357:                if (lastKeyFound != null)
1358:                    j = bundle.getBundle().getItemIndex(lastKeyFound) + 1;
1359:                if (!searchData) { // Key names
1360:                    for (i = j; i < bundle.getBundle().getItemCount(); ++i) {
1361:                        BundleItem bi = bundle.getBundle().getItem(i);
1362:                        String val = bi.getId();
1363:                        if (isMatchedWith(val)) {
1364:                            lastKeyFound = val;
1365:                            tree.selectNode(bi.getId());
1366:                            tree.openToNode(bi.getId());
1367:                            setTranslations(bi.getId());
1368:                            textPanel.invalidate();
1369:                            validate();
1370:                            tree.requestFocus();
1371:                            tree.repaint();
1372:                            return;
1373:                        }
1374:                    }
1375:                    lastKeyFound = null;
1376:                    if (first)
1377:                        searchCriteria = null;
1378:                    errDialog
1379:                            .setText(first ? RC("tools.translator.label.search.nokeys")
1380:                                    : RC("tools.translator.label.search.nomorekeys"));
1381:                    errDialog.show();
1382:                    return;
1383:                }
1384:
1385:                int replacements = 0;
1386:                for (i = j; i < bundle.getBundle().getItemCount(); ++i) {
1387:                    BundleItem bi = bundle.getBundle().getItem(i);
1388:                    for (int k = 0; k < bundle.getBundle().getLangCount(); ++k) {
1389:                        LangItem li = bundle.getBundle().getLanguage(k);
1390:                        String val = bi.getTranslation(li.getLangId());
1391:                        if (isMatchedWith(val)) {
1392:                            lastKeyFound = bi.getId();
1393:
1394:                            if (replaceTo == null
1395:                                    || (replaceTo != null && !replaceAll)) {
1396:                                tree.selectNode(bi.getId());
1397:                                tree.openToNode(bi.getId());
1398:                                setTranslations(bi.getId());
1399:                                tree.repaint();
1400:
1401:                                if (replaceTo != null)
1402:                                    makeReplace(bi, li);
1403:
1404:                                textPanel.invalidate();
1405:                                validate();
1406:                                if (replaceTo == null) {
1407:                                    textPanel.requestFocus();
1408:                                    LangState ls = getLangState(k);
1409:                                    ls.tf.getControl().requestFocus();
1410:                                }
1411:                                return;
1412:                            }
1413:                            makeReplace(bi, li);
1414:                            ++replacements;
1415:                            if (replaceTo == null)
1416:                                break;
1417:                        }
1418:                    }
1419:                }
1420:                lastKeyFound = null;
1421:                if (first)
1422:                    searchCriteria = null;
1423:                if (replacements > 0)
1424:                    errDialog.setText(bundle.replace(
1425:                            RC("tools.translator.label.replaced.count"),
1426:                            "[%replaced%]", Integer.toString(replacements)));
1427:                else
1428:                    errDialog
1429:                            .setText(first ? RC("tools.translator.label.search.nokeys")
1430:                                    : RC("tools.translator.label.search.nomorekeys"));
1431:                errDialog.show();
1432:            }
1433:
1434:            private void onNewResource() {
1435:                EditDialog ed = new EditDialog(this ,
1436:                        RC("tools.translator.label.newrestitle"), true, this );
1437:                ed.setLabelCaption(RC("tools.translator.label.filesuff"));
1438:                ed.setButtonsCaption(RC("dialog.button.ok"), CLOSE_BUTTONS[2]);
1439:                ed.doModal();
1440:                String text = ed.getText();
1441:                if (text.length() <= 0 || !ed.isApply())
1442:                    return;
1443:                bundle.getBundle().addLanguage(text);
1444:                syncLanguage(text);
1445:
1446:                for (int i = 0; i < langStates.size(); i++) {
1447:                    LangState ls = getLangState(i);
1448:                    CheckboxMenuItem cmi = ls.box;
1449:                    boolean show = cmi.getState();
1450:                    ls.tf.setVisible(show);
1451:                    ls.hidden = !show;
1452:                    ls.label.setVisible(show);
1453:                }
1454:                setAllIndicators();
1455:                textPanel.invalidate();
1456:                validate();
1457:            }
1458:
1459:            public void onNewBundle() {
1460:                clear();
1461:                initControls();
1462:                bundle.getBundle().addLanguage("en");
1463:                bundle.getBundle().addKey("creationDate");
1464:                bundle.getBundle().updateValue("creationDate", "en",
1465:                        (new Date()).toLocaleString());
1466:                bundle.getBundle().resort();
1467:                initData(false);
1468:                setTitle(null);
1469:                isDirty = false;
1470:            }
1471:
1472:            private SafeResourceBundle rcTable = null;
1473:
1474:            private String RC(String key) {
1475:                return rcTable.getString(key);
1476:            }
1477:
1478:            public void setTitle(String filename) {
1479:                String add = "";
1480:                if (filename != null)
1481:                    add = " [" + filename + "]";
1482:                super .setTitle("Zaval JRC Editor" + add);
1483:                sbl2.setText(filename == null ? "" : filename);
1484:            }
1485:
1486:            private void join(BundleManager bundle2, boolean part) {
1487:                if (part) {
1488:                    BundleSet set = bundle2.getBundle();
1489:                    int items = set.getItemCount();
1490:                    for (int i = 0; i < items; ++i) {
1491:                        BundleItem bi = set.getItem(i);
1492:                        BundleItem bi2 = bundle.getBundle().addKey(bi.getId());
1493:                        Enumeration en = bi.getLanguages();
1494:                        while (en.hasMoreElements()) {
1495:                            String lang = (String) en.nextElement();
1496:                            bundle.getBundle().addLanguage(lang);
1497:                            bi2.setTranslation(lang, bi.getTranslation(lang));
1498:                        }
1499:                    }
1500:                    set.resort();
1501:                } else
1502:                    bundle = bundle2;
1503:            }
1504:
1505:            class Loader implements  Runnable {
1506:                private String fileName;
1507:                private boolean part;
1508:
1509:                Loader(String fileName, boolean part) {
1510:                    this .fileName = fileName;
1511:                    this .part = part;
1512:                }
1513:
1514:                public void run() {
1515:                    setCursor(Cursor.WAIT_CURSOR);
1516:                    sbl2.setText(RC("tools.translator.progress.loadfiles"));
1517:                    sbl2.repaint();
1518:                    try {
1519:                        // long t1 = System.currentTimeMillis();
1520:                        BundleManager bundle2 = new BundleManager(fileName);
1521:                        // long t2 = System.currentTimeMillis();
1522:                        join(bundle2, part);
1523:                        // long t3 = System.currentTimeMillis();
1524:                        // System.err.println("    ...parse = " + (t2 - t1 ) + "ms");
1525:                        // System.err.println("    ...join = " + (t3 - t2 ) + "ms");
1526:                    } catch (Exception e) {
1527:                        infoException(e);
1528:                    }
1529:                    sbl2.setText(RC("tools.translator.progress.maketree"));
1530:                    sbl2.repaint();
1531:
1532:                    // long t4 = System.currentTimeMillis();
1533:                    if (!part)
1534:                        initControls();
1535:                    else
1536:                        wasSelectedKey = null;
1537:                    // long t5 = System.currentTimeMillis();
1538:                    // System.err.println("    ...init controls = " + (t5 - t4 ) + "ms");
1539:
1540:                    // long t6 = System.currentTimeMillis();
1541:                    initData(part);
1542:                    // long t7 = System.currentTimeMillis();
1543:                    // System.err.println("    ...init data = " + (t7 - t6 ) + "ms");
1544:                }
1545:            };
1546:
1547:            public void readResources(String fileName, boolean part) {
1548:                File f = new File(fileName);
1549:                if (!f.canRead()) {
1550:                    errDialog.setText(fileName + ":" + RC("no.file.found"));
1551:                    errDialog.show();
1552:                    return;
1553:                }
1554:
1555:                (new Thread(new Loader(fileName, part))).start();
1556:                setTitle(fileName);
1557:                addToPickList(fileName);
1558:            }
1559:
1560:            private void initControls() {
1561:                commLab = new IELabel(RC("tools.translator.label.comments"));
1562:                constrain(textPanel, commLab, 0, 0, 1, 1,
1563:                        GridBagConstraints.NORTH, GridBagConstraints.NONE, 0.0,
1564:                        0.0, 10, 3, 0, 15);
1565:
1566:                commField = new EmulatedTextField();
1567:                commField.setBackground(Color.lightGray);
1568:                constrain(textPanel, commField, 1, 0, 1, 1,
1569:                        GridBagConstraints.NORTH, GridBagConstraints.BOTH, 1.0,
1570:                        1.0, 3, 3, 5, 15);
1571:
1572:                dropComment = new Button(
1573:                        RC("tools.translator.label.dropcomment"));
1574:                constrain(textPanel, dropComment, 2, 0, 1, 1,
1575:                        GridBagConstraints.NORTH, GridBagConstraints.NONE, 0.0,
1576:                        0.0, 3, 3, 5, 15);
1577:
1578:                keynLab = new IELabel("");
1579:                constrain(textPanel, keynLab, 0, 1, 3, 1,
1580:                        GridBagConstraints.NORTH,
1581:                        GridBagConstraints.HORIZONTAL, 1.0, 0.0, 10, 3, 0, 15);
1582:                langMenu.enable();
1583:            }
1584:
1585:            private void syncLanguage(String lang) {
1586:                LangItem lang2 = bundle.getBundle().getLanguage(lang);
1587:                int i = bundle.getBundle().getLangIndex(lang);
1588:
1589:                String langLab = lang2.getLangDescription();
1590:                LangState ls = new LangState();
1591:                ls.name = lang2.getLangId();
1592:                ls.box = new CheckboxMenuItem(langLab, false);
1593:                ls.box.setState(true);
1594:                ls.label = new IELabel(langLab + ":", IELabel.LEFT);
1595:                ls.tf = new TextAreaWrap();
1596:                ls.tf.getControl().setBackground(Color.white);
1597:                ls.tf.setLocale(new Locale(lang, ""));
1598:                ls.tf.getControl().addKeyListener(
1599:                        new java.awt.event.KeyAdapter() {
1600:                            public void keyPressed(KeyEvent ke) {
1601:                                if (!ke.isActionKey()
1602:                                        && ke.getKeyChar() == '\n') {
1603:                                    invokeAutoFit();
1604:                                }
1605:                                checkForScrolling(ke.getComponent());
1606:                            }
1607:                        });
1608:
1609:                langStates.addElement(ls);
1610:                langMenu.add(ls.box);
1611:
1612:                constrain(textPanel, ls.label, 0, i + 2, 1, 1,
1613:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
1614:                        0.0, 0.0, 10, 3, 0, 3);
1615:                constrain(textPanel, ls.tf.getControl(), 1, i + 2, 2, 1,
1616:                        GridBagConstraints.NORTHWEST,
1617:                        GridBagConstraints.HORIZONTAL, 1.0, 1.0, 3, 3, 5, 3);
1618:            }
1619:
1620:            private void addToTree(String s) {
1621:                TreeNode tnew = tree.getNode(s);
1622:                if (tnew != null)
1623:                    return;
1624:                int ind = allowDot ? s.lastIndexOf(KEY_SEPARATOR) : -1;
1625:                int ind2 = allowUScore ? s.lastIndexOf(KEY_SEPARATOR_2) : -1;
1626:                if (ind2 > ind)
1627:                    ind = ind2;
1628:
1629:                tnew = new TreeNode(s, SYS_DIR + OPEN_IMAGE, SYS_DIR
1630:                        + CLOSE_IMAGE);
1631:                if (ind < 0) {
1632:                    tnew.caption = s;
1633:                    tree.insertRoot(s);
1634:                    tnew = tree.getNode(s);
1635:                    tnew.setExpandedImage(SYS_DIR + OPEN_IMAGE);
1636:                    tnew.setCollapsedImage(SYS_DIR + CLOSE_IMAGE);
1637:                } else {
1638:                    String tname = s.substring(0, ind);
1639:                    addToTree(tname);
1640:                    TreeNode ttpar = tree.getNode(tname);
1641:                    tnew.caption = s.substring(ind + 1);
1642:                    tree.insert(tnew, ttpar, LevelTree.CHILD);
1643:                    tnew = tree.getNode(s);
1644:                }
1645:                tnew.setContextMenu(1);
1646:            }
1647:
1648:            private String lookupFileForLoad(String mask) {
1649:                FileDialog openFileDialog1 = new FileDialog(this ,
1650:                        RC("tools.translator.label.opentitle"), FileDialog.LOAD);
1651:                openFileDialog1.setDirectory(lastDirectory);
1652:                openFileDialog1.setFile(mask);
1653:                openFileDialog1.show();
1654:
1655:                String filename = openFileDialog1.getFile();
1656:                if (filename != null) {
1657:                    if (keepLastDir)
1658:                        lastDirectory = openFileDialog1.getDirectory();
1659:                    return openFileDialog1.getDirectory() + filename;
1660:                }
1661:                return null;
1662:            }
1663:
1664:            private String lookupFileForStore(String mask, String fileName) {
1665:                FileDialog openFileDialog1 = new FileDialog(this ,
1666:                        RC("tools.translator.label.saveastitle"),
1667:                        FileDialog.SAVE);
1668:                openFileDialog1.setDirectory(lastDirectory);
1669:                openFileDialog1.setFile(fileName);
1670:                openFileDialog1.show();
1671:
1672:                String filename = openFileDialog1.getFile();
1673:                if (filename != null && keepLastDir) {
1674:                    lastDirectory = openFileDialog1.getDirectory();
1675:                    return openFileDialog1.getDirectory() + filename;
1676:                }
1677:                return filename;
1678:            }
1679:
1680:            public void onSaveAs() {
1681:                String mask = "*" + RES_EXTENSION;
1682:                String fn = bundle.getBundle().getLanguage(0).getLangFile();
1683:                if (fn == null)
1684:                    fn = "autosaved";
1685:                fn += RES_EXTENSION;
1686:
1687:                String filename = lookupFileForStore(mask, fn);
1688:                if (filename != null)
1689:                    try {
1690:                        bundle.store(filename);
1691:                        addToPickList(filename);
1692:                        setTitle(filename);
1693:                        isDirty = false;
1694:                    } catch (Exception e) {
1695:                        infoException(e);
1696:                    }
1697:            }
1698:
1699:            private void infoException(Exception e) {
1700:                e.printStackTrace();
1701:                try {
1702:                    ByteArrayOutputStream ba = new ByteArrayOutputStream();
1703:                    PrintStream p = new PrintStream(ba);
1704:                    e.printStackTrace(p);
1705:                    p.close();
1706:                    String msg = new String(ba.toByteArray(), 0);
1707:
1708:                    String hdr = e.getMessage() == null ? e.toString() : e
1709:                            .getMessage();
1710:                    hdr = hdr + "\n" + msg;
1711:                    errDialog.setText(hdr);
1712:                    errDialog.show();
1713:                } catch (Exception z) {
1714:                }
1715:            }
1716:
1717:            private void onAbout() {
1718:                MessageBox2 aboutDialog = new MessageBox2(this );
1719:                aboutDialog.setText(RC("tools.translator.copyright"));
1720:                aboutDialog.setTitle(RC("dialog.title.info"));
1721:                aboutDialog.setIcon(imgres.getImage(SYS_DIR + "ZavalCE.gif",
1722:                        aboutDialog));
1723:                String[] OK_BUT = { RC("dialog.button.ok") };
1724:                aboutDialog.setButtons(OK_BUT);
1725:                aboutDialog.show();
1726:            }
1727:
1728:            private void onStatistics() {
1729:                MessageBox2 sDialog = new MessageBox2(this );
1730:                String text;
1731:                nullsCount = 0;
1732:                notCompletedCount = 0;
1733:                setIndicators(tree.getRootNode());
1734:                text = RC("tools.translator.label.statistics.lang")
1735:                        + bundle.getBundle().getLangCount() + "\n";
1736:                text = text + RC("tools.translator.label.statistics.record")
1737:                        + bundle.getBundle().getItemCount() + "\n";
1738:                text = text + RC("tools.translator.label.statistics.nulls")
1739:                        + nullsCount + "\n";
1740:                text = text
1741:                        + RC("tools.translator.label.statistics.notcompleted")
1742:                        + notCompletedCount;
1743:                sDialog.setText(text);
1744:                sDialog.setTitle(RC("dialog.title.info"));
1745:                String[] OK_BUT = { RC("dialog.button.ok") };
1746:                sDialog.setButtons(OK_BUT);
1747:
1748:                ResultField rf = sDialog.getTextContainer();
1749:                TextAlignArea area = rf.getAlignArea();
1750:                area.setAlign(Align.FIT | Align.TOP);
1751:                sDialog.show();
1752:            }
1753:
1754:            private void onGenCode() {
1755:                try {
1756:                    String mask = "*.java";
1757:                    String fn = bundle.getBundle().getLangCount() == 0
1758:                            || bundle.getBundle().getLanguage(0).getLangFile() == null ? "Sample"
1759:                            : bundle.baseName(bundle.getBundle().getLanguage(0)
1760:                                    .getLangFile());
1761:                    fn = fn.substring(0, 1).toUpperCase() + fn.substring(1);
1762:
1763:                    String filename = lookupFileForStore(mask, fn
1764:                            + "ResourceMapped.java");
1765:                    if (filename != null) {
1766:                        SrcGenerator srcgen = new SrcGenerator(bundle.replace(
1767:                                filename, "\\", "/"));
1768:                        srcgen.perform(bundle.getBundle());
1769:                    }
1770:                } catch (Exception e) {
1771:                    infoException(e);
1772:                }
1773:            }
1774:
1775:            private void onParseCode() {
1776:                try {
1777:                    String mask = "*.java";
1778:                    String filename = lookupFileForLoad(mask);
1779:                    if (filename != null) {
1780:                        filename = bundle.replace(filename, "\\", "/");
1781:                        JavaParser parser = new JavaParser(new FileInputStream(
1782:                                filename));
1783:                        Hashtable ask = parser.parse();
1784:                        if (ask.size() == 0)
1785:                            ask.put("empty", "");
1786:
1787:                        clear();
1788:                        initControls();
1789:                        bundle.getBundle().addLanguage("en");
1790:                        String rlng = bundle.getBundle().getLanguage(0)
1791:                                .getLangId();
1792:
1793:                        Enumeration en = ask.keys();
1794:                        while (en.hasMoreElements()) {
1795:                            String key = (String) en.nextElement();
1796:                            BundleItem bi = bundle.getBundle().addKey(key);
1797:                            bi.setTranslation(rlng, (String) ask.get(key));
1798:                        }
1799:                        bundle.getBundle().resort();
1800:                        initData(false);
1801:                        setTitle(filename);
1802:                    }
1803:                } catch (Exception e) {
1804:                    infoException(e);
1805:                }
1806:            }
1807:
1808:            private void initData(boolean part) {
1809:                /* Initialize language set */
1810:                for (int i = 0; i < bundle.getBundle().getLangCount(); ++i) {
1811:                    LangItem lang2 = bundle.getBundle().getLanguage(i);
1812:                    syncLanguage(lang2.getLangId());
1813:                }
1814:                hideTransMenu.setState(false);
1815:
1816:                /* Add all keys in tree view ... */
1817:                BundleItem bi = bundle.getBundle().getItem(0);
1818:                addToTree(bi.getId());
1819:
1820:                // Fire tree filling asynchronously
1821:                // (new Thread(new Runnable(){
1822:                //     public void run(){
1823:                // long t1 = System.currentTimeMillis();
1824:                for (int i = 1; i < bundle.getBundle().getItemCount(); ++i) {
1825:                    BundleItem bi2 = bundle.getBundle().getItem(i);
1826:                    addToTree(bi2.getId());
1827:                    if (i % 250 == 0) {
1828:                        sbl2.setText("    " + i + " "
1829:                                + RC("tools.translator.progress.addkeys"));
1830:                        sbl2.repaint();
1831:                    }
1832:                }
1833:                // long t2 = System.currentTimeMillis();
1834:                // System.err.println("    ... add keys into tree = " + (t2-t1) + "ms");
1835:                setAllIndicators();
1836:                sbl2.setText("");
1837:                sbl2.repaint();
1838:                setCursor(Cursor.DEFAULT_CURSOR);
1839:                //     }
1840:                // })).start();
1841:
1842:                /* ... and make all keys closed by default */
1843:
1844:                /* ... find first key, open it and select */
1845:                if (bundle.getBundle().getItemCount() > 0) {
1846:                    String id = bundle.getBundle().getItem(0).getId();
1847:                    tree.selectNodeAndOpen(id);
1848:                    wasSelectedKey = null;
1849:                    setTranslations();
1850:                }
1851:
1852:                tree.requestFocus();
1853:
1854:                closeMenu.enable();
1855:                saveBundleMenu.enable();
1856:                saveAsBundleMenu.enable();
1857:                genMenu.enable();
1858:
1859:                textPanel.invalidate();
1860:                validate();
1861:                repaint();
1862:                //  isDirty = true;
1863:                syncToolbar();
1864:                if (!part)
1865:                    loadPickList();
1866:            }
1867:
1868:            private void invokeAutoFit() {
1869:                if (autoExpandTF) {
1870:                    textPanel.invalidate();
1871:                    validate();
1872:                }
1873:            }
1874:
1875:            private void expand(TreeNode tn) {
1876:                if (tn != null) {
1877:                    TreeNode[] children = tree.enumChild(tn);
1878:                    if (children != null)
1879:                        for (int i = 0; i < children.length; i++)
1880:                            expand(children[i]);
1881:                    tree.openNode(tn.getText());
1882:                }
1883:            }
1884:
1885:            private void collapse(TreeNode tn) {
1886:                if (tn != null) {
1887:                    TreeNode[] children = tree.enumChild(tn);
1888:                    if (children != null)
1889:                        for (int i = 0; i < children.length; i++)
1890:                            collapse(children[i]);
1891:                    tree.closeNode(tn.getText());
1892:                }
1893:            }
1894:
1895:            private void syncToolbar() {
1896:                for (int j = 0; j < tbar2menu.length; ++j) {
1897:                    tool.setEnabled(j, tbar2menu[j].isEnabled());
1898:                }
1899:            }
1900:
1901:            private void linkPickList() {
1902:                for (int j = 0; j < pickList.size(); ++j) {
1903:                    String patz = stretchPath((String) pickList.elementAt(j));
1904:                    MenuItem item = new MenuItem(patz);
1905:                    fileMenu.add(item);
1906:                }
1907:                if (pickList.size() > 0)
1908:                    fileMenu.addSeparator();
1909:                fileMenu.add(exitMenu);
1910:            }
1911:
1912:            private void removePickList() {
1913:                if (pickList.size() == 0)
1914:                    return;
1915:
1916:                int j, q;
1917:                String s1 = stretchPath((String) pickList.elementAt(0));
1918:                for (j = 0; j < fileMenu.countItems(); ++j) {
1919:                    String patz = fileMenu.getItem(j).getLabel();
1920:                    if (patz.equals(s1))
1921:                        break;
1922:                }
1923:                pickList = new Vector();
1924:                if (j >= fileMenu.countItems())
1925:                    return;
1926:                for (; j < fileMenu.countItems();)
1927:                    fileMenu.remove(j); //fileMenu.countItems()-1);
1928:            }
1929:
1930:            private String stretchPath(String name) {
1931:                if (name.length() < MAX_PICK_LENGTH)
1932:                    return name;
1933:                return name.substring(0, 4)
1934:                        + "..."
1935:                        + name.substring(name.length()
1936:                                - Math.min(name.length() - 7,
1937:                                        MAX_PICK_LENGTH - 7));
1938:            }
1939:
1940:            private void loadPickList() {
1941:                removePickList();
1942:                String path = System.getProperty("user.home")
1943:                        + "/.jrc-editor.conf";
1944:                try {
1945:                    InputIniFile ini = new InputIniFile(new FileInputStream(
1946:                            path));
1947:                    Hashtable tbl = ini.getTable();
1948:                    ini.close();
1949:
1950:                    Enumeration e = tbl.keys();
1951:                    while (e.hasMoreElements()) {
1952:                        String key = (String) e.nextElement();
1953:                        String val = (String) tbl.get(key);
1954:                        if (!key.startsWith("picklist."))
1955:                            continue;
1956:                        try {
1957:                            key = key.substring(key.indexOf('.') + 1);
1958:                            int pickLevel = Integer.parseInt(key);
1959:                            while (pickList.size() <= pickLevel)
1960:                                pickList.addElement(null);
1961:                            pickList.setElementAt(val, pickLevel);
1962:                        } catch (Exception error) {
1963:                            error.printStackTrace();
1964:                            continue;
1965:                        }
1966:                    }
1967:
1968:                    keepLastDir = tbl.get("keepLastDir") == null
1969:                            || tbl.get("keepLastDir").equals("Y");
1970:                    omitSpaces = tbl.get("omitSpaces") == null
1971:                            || tbl.get("omitSpaces").equals("Y");
1972:                    autoExpandTF = tbl.get("autoExpandTF") == null
1973:                            || tbl.get("autoExpandTF").equals("Y");
1974:                    allowDot = tbl.get("allowDot") == null
1975:                            || tbl.get("allowDot").equals("Y");
1976:                    allowUScore = tbl.get("allowUScore") == null
1977:                            || tbl.get("allowUScore").equals("Y");
1978:
1979:                    keepLastDirMenu.setState(keepLastDir);
1980:                    omitSpacesMenu.setState(omitSpaces);
1981:                    autoExpandTFMenu.setState(autoExpandTF);
1982:                    allowDotMenu.setState(allowDot);
1983:                    allowUScoreMenu.setState(allowUScore);
1984:                } catch (Exception e1) {
1985:                }
1986:
1987:                for (int j = 0; j < pickList.size(); ++j) {
1988:                    Object obj = pickList.elementAt(j);
1989:                    if (obj == null) {
1990:                        pickList.removeElementAt(j);
1991:                        --j;
1992:                    }
1993:                }
1994:                linkPickList();
1995:            }
1996:
1997:            private void addToPickList(String name) {
1998:                int j = 0;
1999:                if (name == null)
2000:                    return;
2001:                for (; j < pickList.size(); ++j) {
2002:                    String v1 = (String) pickList.elementAt(j);
2003:                    if (v1.equals(name)) {
2004:                        pickList.removeElementAt(j);
2005:                        --j;
2006:                    }
2007:                }
2008:
2009:                pickList.insertElementAt(name, 0);
2010:                while (pickList.size() >= 8)
2011:                    pickList.removeElementAt(7);
2012:                saveIni();
2013:            }
2014:
2015:            private void saveIni() {
2016:                try {
2017:                    String path = System.getProperty("user.home")
2018:                            + "/.jrc-editor.conf";
2019:                    IniFile ini = new IniFile(path);
2020:                    for (int j = 0; j < pickList.size(); ++j)
2021:                        ini.putString("picklist." + j, (String) pickList
2022:                                .elementAt(j));
2023:
2024:                    ini.putString("keepLastDir", keepLastDir ? "Y" : "N");
2025:                    ini.putString("omitSpaces", omitSpaces ? "Y" : "N");
2026:                    ini.putString("autoExpandTF", autoExpandTF ? "Y" : "N");
2027:                    ini.putString("allowDot", allowDot ? "Y" : "N");
2028:                    ini.putString("allowUScore", keepLastDir ? "Y" : "N");
2029:                    ini.close();
2030:                } catch (Exception e) {
2031:                }
2032:            }
2033:
2034:            private String[] getLangSet() {
2035:                LangDialog ed = new LangDialog(this ,
2036:                        RC("tools.translator.label.choosetitle"), true, this );
2037:                ed.setLabelCaption(RC("tools.translator.label.chooselabel"));
2038:                ed.setButtonsCaption(RC("dialog.button.ok"), CLOSE_BUTTONS[2]);
2039:
2040:                LangItem[] lset = new LangItem[bundle.getBundle()
2041:                        .getLangCount()];
2042:                for (int i = 0; i < lset.length; ++i)
2043:                    lset[i] = bundle.getBundle().getLanguage(i);
2044:                ed.setList(lset);
2045:
2046:                ed.doModal();
2047:                String[] ask = ed.getList();
2048:                if (ask == null || ask.length <= 0 || !ed.isApply())
2049:                    return null;
2050:                for (int i = 0; i < ask.length; ++i)
2051:                    if (ask[i].indexOf(':') > 0)
2052:                        ask[i] = ask[i].substring(0, ask[i].indexOf(':'))
2053:                                .trim();
2054:                return ask;
2055:            }
2056:
2057:            public void onOpen(boolean part) {
2058:                String mask = "*" + RES_EXTENSION + ";" + "*" + INI_EXTENSION;
2059:                String filename = lookupFileForLoad(mask);
2060:                if (filename != null) {
2061:                    if (!part)
2062:                        clear();
2063:                    readResources(filename, part);
2064:                }
2065:            }
2066:
2067:            public void onSaveXml(boolean part) {
2068:                String[] parts = part ? getLangSet() : null;
2069:                if (part && (parts == null || parts.length < 2))
2070:                    return;
2071:                String mask = "*.xml";
2072:                String fn = bundle.getBundle().getLanguage(0).getLangFile();
2073:                if (fn == null)
2074:                    fn = "autosaved";
2075:
2076:                String filename = lookupFileForStore(mask, bundle.baseName(fn)
2077:                        + ".xml");
2078:                if (filename != null)
2079:                    try {
2080:                        DataOutputStream out = new DataOutputStream(
2081:                                new FileOutputStream(filename));
2082:                        BundleSet set = bundle.getBundle();
2083:                        int items = set.getItemCount();
2084:                        out.writeChar((char) 0xFEFF);
2085:                        out.writeChars("<xml>\n");
2086:                        for (int i = 0; i < items; ++i) {
2087:                            BundleItem bi = set.getItem(i);
2088:                            Enumeration en = bi.getLanguages();
2089:                            out.writeChars("\t<key name=\"" + bi.getId()
2090:                                    + "\">\n");
2091:                            while (en.hasMoreElements()) {
2092:                                String lang = (String) en.nextElement();
2093:                                if (part && !inArray(parts, lang))
2094:                                    continue;
2095:                                out.writeChars("\t\t<value lang=\"" + lang
2096:                                        + "\">" + bi.getTranslation(lang)
2097:                                        + "</value>\n");
2098:                            }
2099:                            out.writeChars("\t</key>\n");
2100:                        }
2101:                        out.writeChars("</xml>\n");
2102:                        out.close();
2103:                    } catch (Exception e) {
2104:                        infoException(e);
2105:                    }
2106:            }
2107:
2108:            public void onSaveUtf(boolean part) {
2109:                String[] parts = part ? getLangSet() : null;
2110:                if (part && (parts == null || parts.length < 2))
2111:                    return;
2112:
2113:                String mask = "*.txt";
2114:                String fn = bundle.getBundle().getLanguage(0).getLangFile();
2115:                if (fn == null)
2116:                    fn = "autosaved";
2117:
2118:                String filename = lookupFileForStore(mask, bundle.baseName(fn)
2119:                        + ".txt");
2120:                if (filename != null)
2121:                    try {
2122:                        DataOutputStream out = new DataOutputStream(
2123:                                new FileOutputStream(filename));
2124:                        BundleSet set = bundle.getBundle();
2125:                        int items = set.getItemCount();
2126:                        out.writeChar((char) 0xFEFF);
2127:                        out
2128:                                .writeChars("#JRC Editor: do not modify this line\r\n\r\n");
2129:                        for (int i = 0; i < items; ++i) {
2130:                            BundleItem bi = set.getItem(i);
2131:                            Enumeration en = bi.getLanguages();
2132:                            out.writeChars("KEY=\"" + bi.getId() + "\":\r\n");
2133:                            while (en.hasMoreElements()) {
2134:                                String lang = (String) en.nextElement();
2135:                                if (part && !inArray(parts, lang))
2136:                                    continue;
2137:                                out.writeChars("\t\"" + lang + "\"=\""
2138:                                        + bi.getTranslation(lang) + "\"\r\n");
2139:                            }
2140:                            out.writeChars("\r\n");
2141:                        }
2142:                        out.close();
2143:                    } catch (Exception e) {
2144:                        infoException(e);
2145:                    }
2146:            }
2147:
2148:            private boolean inArray(String[] array, String lang) {
2149:                for (int j = 0; j < array.length; ++j)
2150:                    if (array[j].equalsIgnoreCase(lang))
2151:                        return true;
2152:                return false;
2153:            }
2154:
2155:            /*
2156:                Reading unicode (UCS16) file stream into memory
2157:             */
2158:            private String getBody(String file) throws IOException {
2159:                char ch;
2160:                DataInputStream in = new DataInputStream(new FileInputStream(
2161:                        file));
2162:                StringBuffer buf = new StringBuffer(in.available());
2163:
2164:                try {
2165:                    in.readChar(); // skip UCS16 marker FEFF
2166:                    for (;;) {
2167:                        ch = in.readChar();
2168:                        buf.append(ch);
2169:                    }
2170:                } catch (EOFException eof) {
2171:                }
2172:                return buf.toString();
2173:            }
2174:
2175:            private void fillTable(Hashtable tbl) {
2176:                Enumeration en = tbl.keys();
2177:                while (en.hasMoreElements()) {
2178:                    String k = (String) en.nextElement();
2179:                    StringTokenizer st = new StringTokenizer(k, "!");
2180:                    String key = st.nextToken();
2181:                    if (!st.hasMoreTokens())
2182:                        continue;
2183:                    String lang = st.nextToken();
2184:
2185:                    if (bundle.getBundle().getLanguage(lang) == null)
2186:                        bundle.getBundle().addLanguage(lang);
2187:
2188:                    bundle.getBundle().addKey(key);
2189:                    bundle.getBundle().updateValue(key, lang,
2190:                            (String) tbl.get(k));
2191:                }
2192:                bundle.getBundle().resort();
2193:            }
2194:
2195:            public void onLoadXml(boolean part) {
2196:                String mask = "*.xml";
2197:                String filename = lookupFileForLoad(mask);
2198:                if (filename != null) {
2199:                    if (!part)
2200:                        clear();
2201:                    if (!part)
2202:                        initControls();
2203:                    bundle.getBundle().addLanguage("en");
2204:
2205:                    try {
2206:                        XmlReader xml = new XmlReader(getBody(filename));
2207:                        Hashtable tbl = xml.getTable();
2208:                        fillTable(tbl);
2209:                    } catch (Exception e) {
2210:                        infoException(e);
2211:                    }
2212:                    initData(part);
2213:                    setTitle(filename);
2214:                }
2215:            }
2216:
2217:            public void onLoadUtf(boolean part) {
2218:                String mask = "*.txt";
2219:                String filename = lookupFileForLoad(mask);
2220:                if (filename != null) {
2221:                    if (!part)
2222:                        clear();
2223:                    if (!part)
2224:                        initControls();
2225:                    bundle.getBundle().addLanguage("en");
2226:                    try {
2227:                        UtfParser parser = new UtfParser(new StringReader(
2228:                                getBody(filename)));
2229:                        Hashtable tbl = parser.parse();
2230:                        fillTable(tbl);
2231:                    } catch (Exception e) {
2232:                        infoException(e);
2233:                    }
2234:                    initData(part);
2235:                    setTitle(filename);
2236:                }
2237:            }
2238:
2239:            private void onNewKey() {
2240:                EditDialog ed = new EditDialog(this ,
2241:                        RC("tools.translator.label.newkeytitle"), true, this );
2242:                ed.setLabelCaption(RC("tools.translator.label.insert"));
2243:                ed.setButtonsCaption(RC("dialog.button.ok"), CLOSE_BUTTONS[2]);
2244:                ed.doModal();
2245:                String text = ed.getText();
2246:                if (text.length() <= 0 || !ed.isApply())
2247:                    return;
2248:                keyName.setText(text);
2249:                onInsertKey();
2250:            }
2251:
2252:            private void infoError(String error) {
2253:                errDialog.setText(error);
2254:                errDialog.show();
2255:            }
2256:
2257:            private void moveFocus() {
2258:                Window wnd = null;
2259:                Component p = this ;
2260:                while (p != null && !(p instanceof  Window))
2261:                    p = p.getParent();
2262:                if (p == null)
2263:                    return;
2264:                wnd = (Window) p;
2265:
2266:                Component focused = wnd.getFocusOwner();
2267:                int idx = tabOrder.indexOf(focused);
2268:                if (idx >= 0) {
2269:                    if (idx + 1 < tabOrder.size()) {
2270:                        Component c = (Component) tabOrder.elementAt(idx + 1);
2271:                        c.requestFocus();
2272:                        return;
2273:                    }
2274:                }
2275:                int i;
2276:                for (i = 0; i < langStates.size(); i++) {
2277:                    LangState ls = getLangState(i);
2278:                    if (ls.hidden)
2279:                        continue;
2280:                    if (ls.tf.getControl() == focused)
2281:                        break;
2282:                }
2283:
2284:                if (i < langStates.size()) {
2285:                    for (++i; i < langStates.size(); ++i) {
2286:                        LangState ls = getLangState(i);
2287:                        if (ls.hidden)
2288:                            continue;
2289:                        ls.tf.requestFocus();
2290:                        return;
2291:                    }
2292:                    tree.requestFocus();
2293:                    return;
2294:                }
2295:                for (i = 0; i < langStates.size(); ++i) {
2296:                    LangState ls = getLangState(i);
2297:                    if (ls.hidden)
2298:                        continue;
2299:                    ls.tf.requestFocus();
2300:                    return;
2301:                }
2302:                tree.requestFocus();
2303:            }
2304:
2305:            private void removeLeafs(String key) {
2306:                // Don't touch hier if key/childs are exists
2307:                if (bundle.getBundle().getItem(key) != null)
2308:                    return;
2309:                TreeNode tn = tree.getNode(key);
2310:                if (tn != null) {
2311:                    if (tree.enumChild(tn) != null
2312:                            && tree.enumChild(tn).length > 0)
2313:                        return;
2314:                    tree.remove(key);
2315:                }
2316:
2317:                int j1 = allowDot ? key.lastIndexOf(KEY_SEPARATOR) : -1;
2318:                int j2 = allowUScore ? key.lastIndexOf(KEY_SEPARATOR_2) : -1;
2319:                j1 = Math.max(j1, j2);
2320:                if (j1 <= 0)
2321:                    return;
2322:                removeLeafs(key.substring(0, j1));
2323:            }
2324:
2325:            void onRenameKey() {
2326:                String oldKeyName = keyName.getText();
2327:                if (oldKeyName.endsWith("."))
2328:                    oldKeyName = oldKeyName.substring(0,
2329:                            oldKeyName.length() - 1);
2330:
2331:                EditDialog ed = new EditDialog(this ,
2332:                        RC("tools.translator.label.rename.caption"), true, this );
2333:                ed.setLabelCaption(RC("tools.translator.label.rename.label"));
2334:                ed.setButtonsCaption(RC("dialog.button.ok"), CLOSE_BUTTONS[2]);
2335:                ed.setText(oldKeyName);
2336:                ed.doModal();
2337:
2338:                String newKeyName = ed.getText();
2339:                if (newKeyName.trim().length() <= 0 || !ed.isApply())
2340:                    return;
2341:                if (oldKeyName.equals(newKeyName))
2342:                    return;
2343:
2344:                BundleItem biOldAlone = bundle.getBundle().getItem(oldKeyName);
2345:                Enumeration en = bundle.getBundle().getKeysBeginningWith(
2346:                        oldKeyName);
2347:                while (en.hasMoreElements()) {
2348:                    BundleItem biOld = (BundleItem) en.nextElement();
2349:
2350:                    String newKey = newKeyName;
2351:                    if (biOldAlone == null) // Mass rename
2352:                        newKey = newKeyName
2353:                                + biOld.getId().substring(oldKeyName.length());
2354:
2355:                    Hashtable oldValues = new Hashtable();
2356:                    int k = bundle.getBundle().getLangCount();
2357:                    BundleItem biNew = bundle.getBundle().getItem(newKey);
2358:                    if (biNew != null) {
2359:                        errDialog
2360:                                .setText(RC("tools.translator.label.rename.dup"));
2361:                        errDialog.show();
2362:                        return;
2363:                    }
2364:
2365:                    // Keep old values
2366:                    for (int j = 0; j < k; ++j) {
2367:                        String lang = bundle.getBundle().getLanguage(j)
2368:                                .getLangId();
2369:                        String value = biOld.getTranslation(lang);
2370:                        if (value != null)
2371:                            oldValues.put(lang, value);
2372:                    }
2373:                    bundle.getBundle().removeKey(biOld.getId());
2374:
2375:                    // Add new key
2376:                    keyName.setText(newKey);
2377:                    addToTree(newKey);
2378:                    biNew = bundle.getBundle().addKey(newKey);
2379:                    for (int j = 0; j < k; ++j) {
2380:                        String lang = bundle.getBundle().getLanguage(j)
2381:                                .getLangId();
2382:                        String value = (String) oldValues.get(lang);
2383:                        if (value != null)
2384:                            biNew.setTranslation(lang, value);
2385:                    }
2386:                }
2387:                isDirty = true;
2388:
2389:                // Remove old key
2390:                tree.remove(oldKeyName);
2391:                removeLeafs(oldKeyName);
2392:                bundle.getBundle().resort();
2393:
2394:                tree.selectNodeAndOpen(newKeyName);
2395:                tree.repaint();
2396:                setTranslations();
2397:                setIndicators(tree.getSelectedNode());
2398:            }
2399:
2400:            private void onLoadJar() {
2401:                String mask = "*.jar";
2402:                String filename = lookupFileForLoad(mask);
2403:                if (filename != null) {
2404:                    clear();
2405:                    initControls();
2406:                    bundle.getBundle().addLanguage("en");
2407:                    try {
2408:                        ZipFile zip = new ZipFile(filename);
2409:                        Enumeration en = zip.entries();
2410:                        while (en.hasMoreElements()) {
2411:                            ZipEntry ze = (ZipEntry) en.nextElement();
2412:                            if (ze.getName().endsWith(".properties")) {
2413:                                String lang = bundle.determineLanguage(ze
2414:                                        .getName());
2415:                                InputStream in = zip.getInputStream(ze);
2416:                                bundle.appendResource(in, lang);
2417:                            }
2418:                        }
2419:                        initData(false);
2420:                        // Force new file name for storage
2421:                        bundle.getBundle().getLanguage(0).setLangFile(null);
2422:                        setTitle(filename);
2423:                    } catch (Exception e) {
2424:                        infoException(e);
2425:                    }
2426:                }
2427:            }
2428:
2429:            private void hideTranslated(boolean hide) {
2430:                hideTranslated(tree.getRootNode(), hide);
2431:                tree.invalidate();
2432:                validate();
2433:                tree.repaint();
2434:            }
2435:
2436:            private void hideTranslated(TreeNode tn, boolean hide) {
2437:                while (tn != null) {
2438:                    if (tn.getIndicator() == null)
2439:                        tn.setHide(hide);
2440:                    hideTranslated(tn.child, hide);
2441:                    tn = tn.sibling;
2442:                }
2443:            }
2444:
2445:            private void onOptions() {
2446:            }
2447:
2448:            private void constrain(Container c, Component p, int x, int y,
2449:                    int width, int height, int anchor, int fill,
2450:                    double weightx, double weighty, int insetLeft,
2451:                    int insetTop, int insetRight, int insetBottom) {
2452:                GridBagConstraints cc = new GridBagConstraints();
2453:
2454:                cc.gridx = x;
2455:                cc.gridy = y;
2456:                cc.gridwidth = width;
2457:                cc.gridheight = height;
2458:
2459:                cc.fill = fill;
2460:                cc.anchor = anchor;
2461:                cc.weightx = weightx;
2462:                cc.weighty = weighty;
2463:
2464:                if (insetTop + insetBottom + insetLeft + insetRight > 0)
2465:                    cc.insets = new Insets(insetTop, insetLeft, insetBottom,
2466:                            insetRight);
2467:                LayoutManager lm = c.getLayout();
2468:                GridBagLayout gbl = (GridBagLayout) lm;
2469:                gbl.setConstraints(p, cc);
2470:                c.add(p);
2471:            }
2472:
2473:            private boolean match_regex(String mask, String val,
2474:                    boolean matchCase) {
2475:                try {
2476:                    RE re = new RE(mask, matchCase ? RE.MATCH_NORMAL
2477:                            : RE.MATCH_CASEINDEPENDENT);
2478:                    return re.match(val);
2479:                } catch (org.apache.regexp.RESyntaxException e) {
2480:                    infoException(e);
2481:                }
2482:                return false;
2483:            }
2484:
2485:            private boolean match_mask(String mask, String val,
2486:                    boolean matchCase) {
2487:                return match_mask(mask.toCharArray(), 0, val.toCharArray(), 0,
2488:                        matchCase);
2489:            }
2490:
2491:            private boolean match_mask(char[] s, int sp, char[] t, int tp,
2492:                    boolean matchCase) {
2493:                int vp;
2494:
2495:                if (sp == s.length && tp == t.length)
2496:                    return true;
2497:                if (tp == t.length && s[sp] == '*')
2498:                    return match_mask(s, sp + 1, t, tp, matchCase);
2499:                if (tp == t.length && sp != s.length)
2500:                    return false;
2501:                if (sp == s.length && tp != t.length)
2502:                    return false;
2503:
2504:                if (s[sp] == '?')
2505:                    return match_mask(s, sp + 1, t, tp + 1, matchCase);
2506:                if (!matchCase
2507:                        && (Character.toLowerCase(s[sp]) == Character
2508:                                .toLowerCase(t[tp])))
2509:                    return match_mask(s, sp + 1, t, tp + 1, matchCase);
2510:                if (matchCase && s[sp] == t[tp])
2511:                    return match_mask(s, sp + 1, t, tp + 1, matchCase);
2512:
2513:                if (s[sp] != '?' && s[sp] != '*') {
2514:                    if (!matchCase
2515:                            && Character.toLowerCase(s[sp]) != Character
2516:                                    .toLowerCase(t[tp]))
2517:                        return false;
2518:                    if (matchCase && s[sp] != t[tp])
2519:                        return false;
2520:                }
2521:                if (s[sp] == '*' && s.length == sp + 1)
2522:                    return true;
2523:                for (vp = tp; vp < t.length; ++vp)
2524:                    if (match_mask(s, sp + 1, t, vp, matchCase))
2525:                        return true;
2526:                return match_mask(s, sp + 1, t, tp, matchCase);
2527:            }
2528:
2529:            private void checkForScrolling(Component what) {
2530:                if (what instanceof  EmulatedTextField) {
2531:                    Rectangle r1 = what.getBounds();
2532:                    Rectangle r2 = ((EmulatedTextField) what).getCursorShape();
2533:                    if (r1 == null || r2 == null)
2534:                        return;
2535:                    r1.x += r2.x;
2536:                    r1.y += r2.y;
2537:                    r1.width = r2.width + 25;
2538:                    r1.height = r2.height + 25;
2539:
2540:                    // Now R1 contains top/right cursor position
2541:                    Dimension s1 = scrPanel.size();
2542:                    s1.width -= scrPanel.getVScrollbar().isVisible() ? scrPanel
2543:                            .getVScrollbar().size().width : 0;
2544:                    s1.height -= scrPanel.getHScrollbar().isVisible() ? scrPanel
2545:                            .getHScrollbar().size().height
2546:                            : 0;
2547:                    // Now s1 contains view rect area
2548:
2549:                    int curHS = scrPanel.getHScrollbar().isVisible() ? scrPanel
2550:                            .getHScrollbar().getValue() : 0;
2551:                    int curVS = scrPanel.getVScrollbar().isVisible() ? scrPanel
2552:                            .getVScrollbar().getValue() : 0;
2553:
2554:                    //   System.out.println("ETF AS:" + 
2555:                    //       "shape=("+r1.x+","+r1.y+";"+r1.width+"x"+r1.height+"); "+ 
2556:                    //       "viewport=("+s1.width+"x"+s1.height+"); " +
2557:                    //       "curS=(h="+curHS+",v="+curVS+") " );
2558:
2559:                    if (r1.x + r1.width >= s1.width + curHS
2560:                            || r1.y + r1.height >= s1.height + curVS
2561:                            || r1.x < curHS || r1.y < curVS) {
2562:
2563:                        int newX = curHS;
2564:                        int newY = curVS;
2565:                        Dimension s2 = scrPanel.getScrollableObject()
2566:                                .preferredSize();
2567:                        if (r1.x + r1.width >= s1.width)
2568:                            newX = Math.min(r1.x + r1.width - s1.width,
2569:                                    s2.width - s1.width);
2570:                        if (r1.y + r1.height >= s1.height)
2571:                            newY = Math.min(r1.y + r1.height - s1.height,
2572:                                    s2.height - s1.height);
2573:                        if (r1.x < curHS)
2574:                            newX = r1.x;
2575:                        if (r1.y < curVS)
2576:                            newX = r1.y;
2577:
2578:                        //        System.out.println("\tnewX="+newX+", newY="+newY + " of ["+s2.width+"x"+s2.height+"]");
2579:                        scrPanel.scroll(newX, newY);
2580:                    }
2581:                }
2582:            }
2583:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.