SUGGESTED FIX
Name: rpC71689 Date: 12/19/98
prs@russia 12.19.98
Just implemented getting that message from resource bundle.
awtLocalization.properties
***************
*** 5,7 ****
--- 5,10 ----
# Default font size for Menus and MenuItems
menuFont=SansSerif-plain-11
+
+ # Value for "All files" for FileDialog
+ allFiles=All Files
WFileDialogPeer.java
***************
*** 17,22 ****
--- 17,24 ----
import java.awt.peer.*;
import sun.awt.ScreenUpdater;
import java.io.FilenameFilter;
+ import java.util.ResourceBundle;
+ import java.util.MissingResourceException;
public class WFileDialogPeer extends WWindowPeer implements FileDialogPeer {
***************
*** 26,31 ****
--- 28,36 ----
public void setFile(String file) {}
public void setTitle(String title) {}
+ //Needed to fix 4152317
+ private static native void setFilterString(String allFilter);
+
public void setFilenameFilter(FilenameFilter filter) {
// We can set the filter, but can't do anything with it yet.
System.err.println("setFilenameFilter not implemented\n");
***************
*** 73,78 ****
--- 78,96 ----
((FileDialog)target).setVisible(false);
}
+ //This whole static block is a part of 4152317 fix
+ static {
+ try {
+ ResourceBundle rb = ResourceBundle.getBundle("sun.awt.windows.awtLocalization");
+ String filterString = rb.getString("allFiles");
+ setFilterString(filterString);
+ } catch (MissingResourceException e) {
+ System.out.println(e.getMessage());
+ System.out.println("Using non-localized message in FileDialog\n");
+ setFilterString("All Files");
+ }
+ }
+
// unused methods.
public void beginValidate() {}
public void endValidate() {}
awt_FileDialog.cpp
***************
*** 25,30 ****
--- 25,59 ----
#include <sun_awt_windows_WFileDialogPeer.h>
#include <commdlg.h>
+ //Localized filter string will be stored here
+ static char *FileFilterString = NULL;
+ //Non-localized suffix of the filter string
+ static const char AdditionalString[] = " (*.*)\0*.*\0\0";
+
+ //This function is a part of fix for 4152317
+ void
+ sun_awt_windows_WFileDialogPeer_setFilterString(
+ Hsun_awt_windows_WFileDialogPeer *, Hjava_lang_String *filterDescription)
+ {
+ if (FileFilterString == NULL) {
+ int length = javaStringLength(filterDescription);
+ FileFilterString = new char[length * 2 + sizeof(AdditionalString)];
+ //check for out of memory
+ if (FileFilterString == NULL) {
+ SignalError(0, JAVAPKG "OutOfMemoryError", 0);
+ return;
+ }
+ AwtFont::javaString2multibyte(filterDescription, FileFilterString, length);
+ char *s = FileFilterString;
+ //AdditionalString should be terminated by two NULL characters (Windows
+ //requirement), so we have to organize the following cycle and use memcpy
+ //unstead of, for example, strcat.
+ while (*s)
+ ++s;
+ memcpy(s, AdditionalString, sizeof(AdditionalString));
+ }
+ }
+
void
sun_awt_windows_WFileDialogPeer_show(
struct Hsun_awt_windows_WFileDialogPeer *hPeer)
***************
*** 59,73 ****
fileBuffer[0] = '\0';
}
- // No one knows what a filename filter is yet (Macs prevent just using
- // extensions), so accept all files for now.
- const char filter[] = "All Files (*.*)\0*.*\0\0";
-
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
! ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.hwndOwner = parent ? parent->GetHWnd() : NULL;
ofn.lpstrFile = fileBuffer;
--- 88,98 ----
fileBuffer[0] = '\0';
}
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
! ofn.lpstrFilter = FileFilterString;
ofn.nFilterIndex = 1;
ofn.hwndOwner = parent ? parent->GetHWnd() : NULL;
ofn.lpstrFile = fileBuffer;
======================================================================
|
EVALUATION
We hardcoded the string for the drop-down filter list into awt_FileDialog.cpp. We should get the string from a resource bundle instead.
robi.khan@eng 1998-12-01
----------------------------------------------------------------
This bug was verified as fixed via manual testing using jdk118h.
al.smith@eng 1999-02-26
NOTE: The code was changed to load the string from a resource file instead of having it directly hardcoded in the program. However, a decision was made that it was too expensive to localize just this one string, so while the text is loaded at runtime, we've only provided the english version.
Licensees who require the string be localized will be asked to localize the resource properties files themselves for different locales. This will not require any changes to the binary code.
robi.khan@eng 1999-03-02
|