From: <oms...@us...> - 2006-05-02 15:28:06
|
Revision: 360 Author: omschaub Date: 2006-05-02 08:27:57 -0700 (Tue, 02 May 2006) ViewCVS: http://svn.sourceforge.net/azsmrc/?rev=360&view=rev Log Message: ----------- Committing progress Modified Paths: -------------- trunk/azsmrc/lbms/tools/i18n/swt/MainWindow.java Modified: trunk/azsmrc/lbms/tools/i18n/swt/MainWindow.java =================================================================== --- trunk/azsmrc/lbms/tools/i18n/swt/MainWindow.java 2006-05-02 14:07:15 UTC (rev 359) +++ trunk/azsmrc/lbms/tools/i18n/swt/MainWindow.java 2006-05-02 15:27:57 UTC (rev 360) @@ -43,7 +43,7 @@ private Shell shell; private Label currentlyOpened; private Table mainTable; - private Button save; + private Button add,save; private Color backgroundC; @@ -53,6 +53,7 @@ private Map<String,String> defaultMap; private Map<String,String> transMap; private boolean isSaved; + private String workingDir; private MainWindow(){ @@ -67,7 +68,7 @@ public void shellClosed(ShellEvent arg0) { if(backgroundC != null && !backgroundC.isDisposed()) backgroundC.dispose(); - + I18NMe.getI18NMe().close(); } @@ -90,7 +91,53 @@ Menu fileSubmenu = new Menu (shell, SWT.DROP_DOWN); fileItem.setMenu (fileSubmenu); + MenuItem menuNew = new MenuItem(fileSubmenu, SWT.PUSH); + menuNew.setText ("&New Default File\tCtrl+N"); + menuNew.setAccelerator (SWT.MOD1 + 'N'); + menuNew.addListener (SWT.Selection, new Listener () { + public void handleEvent (Event e) { + FileDialog dialog = new FileDialog (shell, SWT.SAVE); + dialog.setText("Choose New Default File"); + String fileString = dialog.open(); + if(fileString != null){ + try{ + currentI18NDefaultFile = new File(fileString); + if(currentI18NDefaultFile.isFile()){ + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK | SWT.CANCEL); + mb.setText("File Exists"); + mb.setMessage("Chosen file already exists. Are you sure you want to overwrite it with a blank file?"); + int choice = mb.open(); + if(choice == SWT.CANCEL) return; + currentI18NDefaultFile.delete(); + } + currentI18NDefaultFile.createNewFile(); + currentI18NLocalizedFile = null; + }catch(Exception error){ + error.printStackTrace(); + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); + mb.setText("File Error"); + mb.setMessage("Error writing file. IOError. Please check your settings and try again."); + mb.open(); + } + try { + defaultMap = I18NTools.readFromFile(currentI18NDefaultFile); + transMap = I18NTools.duplicate(defaultMap); + } catch (IOException e1) { + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); + mb.setText("Open Error"); + mb.setMessage("Problems initializing I18N File. IOException error!"); + mb.open(); + e1.printStackTrace(); + } + clearTable(); + setIsSaved(false,true); + } + } + }); + + + //Open MenuItem menuOpen = new MenuItem(fileSubmenu, SWT.PUSH); menuOpen.setText ("&Open Default File\tCtrl+O"); @@ -98,7 +145,7 @@ menuOpen.addListener (SWT.Selection, new Listener () { public void handleEvent (Event e) { FileDialog dialog = new FileDialog (shell, SWT.OPEN); - + dialog.setText("Open Default File"); String fileString = dialog.open(); if(fileString != null){ try{ @@ -117,6 +164,7 @@ } try { + currentI18NLocalizedFile = null; defaultMap = I18NTools.readFromFile(currentI18NDefaultFile); transMap = I18NTools.duplicate(defaultMap); } catch (IOException e1) { @@ -127,18 +175,18 @@ e1.printStackTrace(); } clearTable(); - + setIsSaved(false,true); } } }); final MenuItem menuTransOpen = new MenuItem(fileSubmenu, SWT.PUSH); - menuTransOpen.setText ("&Open Localized File\tCtrl+L"); + menuTransOpen.setText ("Open &Localized File\tCtrl+L"); menuTransOpen.setAccelerator (SWT.MOD1 + 'L'); menuTransOpen.addListener (SWT.Selection, new Listener () { public void handleEvent (Event e) { - FileDialog dialog = new FileDialog (shell, SWT.SAVE); - + FileDialog dialog = new FileDialog (shell, SWT.OPEN); + dialog.setText("Open Localized Default File"); String fileString = dialog.open(); if(fileString != null){ try{ @@ -169,7 +217,7 @@ e1.printStackTrace(); } clearTable(); - setIsSaved(false); + setIsSaved(false, true); } } }); @@ -190,7 +238,7 @@ } }else{ FileDialog dialog = new FileDialog (shell, SWT.SAVE); - + dialog.setText("Save Localized File"); String fileString = dialog.open(); if(fileString != null){ try{ @@ -221,17 +269,58 @@ e1.printStackTrace(); } } + clearTable(); + } + } + }); + final MenuItem menuSaveAs = new MenuItem(fileSubmenu, SWT.PUSH); + menuSaveAs.setText ("Save Localized File &As"); + menuSaveAs.addListener (SWT.Selection, new Listener () { + public void handleEvent (Event e) { + FileDialog dialog = new FileDialog (shell, SWT.SAVE); + dialog.setText("Save Localized File As"); + String fileString = dialog.open(); + if(fileString != null){ + try{ + currentI18NLocalizedFile = new File(fileString); + if(!currentI18NLocalizedFile.exists()) + currentI18NLocalizedFile.createNewFile(); + if(!currentI18NLocalizedFile.isFile() || + !currentI18NLocalizedFile.canRead() || + !currentI18NLocalizedFile.canWrite()){ + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); + mb.setText("Open Error"); + mb.setMessage("Problems reading choosen i18n File. Either File is not a File" + + "or it cannot be read or written to."); + mb.open(); + } + }catch(Exception error){ + error.printStackTrace(); + } + try { + I18NTools.writeToFile(currentI18NLocalizedFile, transMap); + } catch (IOException e1) { + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); + mb.setText("Save Error"); + mb.setMessage("Problems writing I18N File. IOException error!"); + mb.open(); + e1.printStackTrace(); + } clearTable(); } } }); + + + + //Separator new MenuItem(fileSubmenu,SWT.SEPARATOR); @@ -256,10 +345,13 @@ menuTransOpen.setEnabled(true); - if(isSaved || transMap == null) + if(isSaved || transMap == null){ menuSave.setEnabled(false); - else + menuSaveAs.setEnabled(false); + }else{ menuSave.setEnabled(true); + menuSaveAs.setEnabled(true); + } } }); @@ -294,19 +386,45 @@ tableGroup.setLayoutData(gd); Composite bComp = new Composite(tableGroup, SWT.NULL); - bComp.setLayout(new GridLayout(1,false)); + bComp.setLayout(new GridLayout(2,false)); gd = new GridData(GridData.FILL_HORIZONTAL); bComp.setLayoutData(gd); + add = new Button(bComp, SWT.PUSH); + add.setText("Add New Key"); + gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + add.setLayoutData(gd); + add.addListener(SWT.Selection, new Listener(){ + public void handleEvent(Event arg0) { + NewDialog dlog = new NewDialog("Enter New Key and Default Value"); + String[] newKey = dlog.open(); + if(newKey[0] == null) return; //User Cancelled + if(newKey[0].equalsIgnoreCase("")){ + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); + mb.setText("Error"); + mb.setMessage("You did not enter a value for the key, please choose Add again and enter a value for the key."); + mb.open(); + return; + } + + defaultMap.put(newKey[0], newKey[1]); + transMap.put(newKey[0], ""); + clearTable(); + + } + }); + + save = new Button (bComp, SWT.PUSH); - save.setText("Save"); - save.setToolTipText("Delete selected questions"); + save.setText("Save All"); + save.setToolTipText("Quick save all changes"); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); save.setLayoutData(gd); save.addListener(SWT.Selection, new Listener(){ public void handleEvent(Event arg0) { - if(currentI18NLocalizedFile != null){ + if(currentI18NLocalizedFile != null && currentI18NDefaultFile != null){ try { + I18NTools.writeToFile(currentI18NDefaultFile, defaultMap); I18NTools.writeToFile(currentI18NLocalizedFile, transMap); } catch (IOException e1) { MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); @@ -317,7 +435,7 @@ } }else{ FileDialog dialog = new FileDialog (shell, SWT.SAVE); - + dialog.setText("Enter Translated File Name to Save"); String fileString = dialog.open(); if(fileString != null){ try{ @@ -339,6 +457,7 @@ } try { + I18NTools.writeToFile(currentI18NDefaultFile, defaultMap); I18NTools.writeToFile(currentI18NLocalizedFile, transMap); } catch (IOException e1) { MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); @@ -354,6 +473,7 @@ }); + //----Main Table mainTable = new Table(tableGroup, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); gd = new GridData(GridData.FILL_BOTH); @@ -402,7 +522,7 @@ if(tableIndex%2==0) { item.setBackground(getBackgroundColor()); } - + } }); @@ -418,62 +538,135 @@ while (index < mainTable.getItemCount ()) { boolean visible = false; final TableItem item = mainTable.getItem (index); - Rectangle rect = item.getBounds (3); + for (int i=1; i<mainTable.getColumnCount (); i++) { + Rectangle rect = item.getBounds (i); if (rect.contains (pt)) { - final int column = 3; + final int column = i; final Text text = new Text (mainTable, SWT.NONE); Listener textListener = new Listener () { public void handleEvent (final Event e) { + int open = 0; switch (e.type) { - case SWT.FocusOut: - item.setText (column, text.getText ()); - if(!item.getText(2).equalsIgnoreCase(text.getText())){ - transMap.put(item.getText(1), text.getText()); - clearTable(); - setIsSaved(false); + case SWT.FocusOut: + if(column == 1 && !item.getText(1).equalsIgnoreCase(text.getText())){ + if(defaultMap.containsKey(text.getText())){ + if(open != SWT.OPEN){ + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); + mb.setText("Error"); + mb.setMessage("You have entered a key value that is already in the file. Please choose a unique key."); + open = mb.open(); + } + text.setText (item.getText (column)); + text.selectAll (); + text.setFocus (); + break; } - text.dispose (); - break; - case SWT.Traverse: - switch (e.detail) { - case SWT.TRAVERSE_RETURN: - item.setText (column, text.getText ()); - if(!item.getText(2).equalsIgnoreCase(text.getText())){ - transMap.put(item.getText(1), text.getText()); - clearTable(); - setIsSaved(false); - } + + //Key is different! + String key = item.getText(1); + String defaultValue = item.getText(2); + String transValue = item.getText(3); + if(defaultValue.equalsIgnoreCase(transValue)) + transValue = ""; + //remove old keys + if(defaultMap.containsKey(key)) + defaultMap.remove(key); + if(transMap.containsKey(key)) + transMap.remove(key); + //add them back in with new key + String newKey = text.getText(); + defaultMap.put(newKey, defaultValue); + transMap.put(newKey, defaultValue); + + }else if(column == 2 && !item.getText(2).equalsIgnoreCase(text.getText())){ + //default is different! + defaultMap.put(item.getText(1), text.getText()); + }else if(column == 3 && !item.getText(3).equalsIgnoreCase(text.getText())){ + //trans if different! + transMap.put(item.getText(1), text.getText()); + } + clearTable(); + setIsSaved(false, true); + text.dispose (); + break; + case SWT.Traverse: + switch (e.detail) { + case SWT.TRAVERSE_RETURN: + if(column == 1 && !item.getText(1).equalsIgnoreCase(text.getText())){ + if(defaultMap.containsKey(text.getText())){ + if(open != SWT.OPEN){ + MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK); + mb.setText("Error"); + mb.setMessage("You have entered a key value that is already in the file. Please choose a unique key."); + open = mb.open(); + } - //FALL THROUGH - case SWT.TRAVERSE_ESCAPE: - text.dispose (); - e.doit = false; + text.setText (item.getText (column)); + text.selectAll (); + text.setFocus (); + break; + } + + //Key is different! + String key = item.getText(1); + String defaultValue = item.getText(2); + String transValue = item.getText(3); + if(defaultValue.equalsIgnoreCase(transValue)) + transValue = ""; + //remove old keys + if(defaultMap.containsKey(key)) + defaultMap.remove(key); + if(transMap.containsKey(key)) + transMap.remove(key); + //add them back in with new key + String newKey = text.getText(); + defaultMap.put(newKey, defaultValue); + transMap.put(newKey, defaultValue); + + }else if(column == 2 && !item.getText(2).equalsIgnoreCase(text.getText())){ + //default is different! + defaultMap.put(item.getText(1), text.getText()); + }else if(column == 4 && !item.getText(3).equalsIgnoreCase(text.getText())){ + //trans if different! + transMap.put(item.getText(1), text.getText()); } - break; + clearTable(); + setIsSaved(false, true); + + //FALL THROUGH + case SWT.TRAVERSE_ESCAPE: + text.dispose (); + e.doit = false; + } + break; } } }; text.addListener (SWT.FocusOut, textListener); - text.addListener (SWT.Traverse, textListener); - editor.setEditor (text, item, 3); - text.setText (item.getText (3)); + text.addListener (SWT.Traverse, textListener); + editor.setEditor (text, item, i); + text.setText (item.getText (i)); text.selectAll (); text.setFocus (); return; } if (!visible && rect.intersects (clientArea)) { visible = true; - } + } + } if (!visible) return; index++; } } }); + + + //Open the main shell centerShellandOpen(shell); - setIsSaved(false); + setIsSaved(false, false); } @@ -487,12 +680,14 @@ I18NMe.getI18NMe().getDisplay().syncExec(new Runnable(){ public void run() { String defaultName = "None"; - + String transName = "None"; if(currentI18NDefaultFile != null) defaultName = currentI18NDefaultFile.getName(); - + if(currentI18NLocalizedFile != null) + transName = currentI18NLocalizedFile.getName(); if(currentlyOpened != null || !currentlyOpened.isDisposed()) - currentlyOpened.setText("Current Default File: " + defaultName); + currentlyOpened.setText("Current Default File: " + defaultName + + "\nCurrent Localized File: " + transName); if(shell != null || !shell.isDisposed()){ if(defaultName.equalsIgnoreCase("None")) shell.setText("I18NMe"); @@ -546,11 +741,12 @@ } - private void setIsSaved(final boolean bisSaved){ + private void setIsSaved(final boolean bisSaved, final boolean bSaveAddButtons){ I18NMe.getI18NMe().getDisplay().asyncExec(new Runnable(){ public void run() { isSaved = bisSaved; - save.setEnabled(!bisSaved); + save.setEnabled(bSaveAddButtons); + add.setEnabled(bSaveAddButtons); } }); } @@ -576,31 +772,31 @@ //open shell shell.open(); } - + /** * Generate a nice light background color for tables based off of list_background * @return Color */ - public Color getBackgroundColor(){ + public Color getBackgroundColor(){ - if(I18NMe.getI18NMe().getDisplay()==null && I18NMe.getI18NMe().getDisplay().isDisposed()){ - backgroundC = null; - return backgroundC; - } - try{ - backgroundC = new Color(I18NMe.getI18NMe().getDisplay() , - new RGB(I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRed()-20, - I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getGreen()-20, - I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getBlue()-20)); + if(I18NMe.getI18NMe().getDisplay()==null && I18NMe.getI18NMe().getDisplay().isDisposed()){ + backgroundC = null; + return backgroundC; + } + try{ + backgroundC = new Color(I18NMe.getI18NMe().getDisplay() , + new RGB(I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRed()-20, + I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getGreen()-20, + I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getBlue()-20)); - }catch(Exception e){ - backgroundC = I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - } + }catch(Exception e){ + backgroundC = I18NMe.getI18NMe().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); + } - return backgroundC; -} + return backgroundC; + } }//EOF \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |