|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.nand.util.i18n.gui.PropertiesTranslatorEditor
public class PropertiesTranslatorEditor
Property file editor for translators (side-by-side source and destination languages). Presents the source and destination language keys and values. Highlights values that still need to be translated into the destination. Saves in the ISO-8859-1 encoding required for .properties files, escaping unicode characters where needed.
The main startup class for this package is PTEMain
, which has buttons for New, Open, About, etc.
Work in progress. Current limitations:
TODO
for other minor items
Nested Class Summary | |
---|---|
private class |
PropertiesTranslatorEditor.CellEditorMouseListener
Listener to double-click while editing cell text, to bring up a larger edit dialog. |
static class |
PropertiesTranslatorEditor.CellStatus
Return types for PropertiesTranslatorEditor.PTSwingTableModel.getCellStatus(int, int) |
private static class |
PropertiesTranslatorEditor.PTCellRenderer
Rendering model (background colors, etc) for jtab . |
private class |
PropertiesTranslatorEditor.PTSwingTableModel
Data model for viewing/editing data in jtab . |
class |
PropertiesTranslatorEditor.SearchPanel
JPanel for the text search bar. |
Field Summary | |
---|---|
private static java.util.regex.Pattern |
_regex_findBaseAndLang
Initialized and used in findBaseAndLangInFilename(String) |
private javax.swing.JButton |
bFind
Find button, shows search panel sPan at bottom of window |
private javax.swing.JButton |
bHelp
Help button, brings up a brief text message dialog |
private javax.swing.JButton |
bSaveDest
Save button for properties file from current editor contents; disabled until changes are made |
private javax.swing.JButton |
bSaveSrc
Save button for properties file from current editor contents; disabled until changes are made |
private PropertiesTranslatorEditor.CellEditorMouseListener |
cellListener
Listener to double-click while editing cell text, to bring up a larger edit dialog. |
private boolean |
isDestNew
If true, setDestIsNew(List) has been called |
private javax.swing.JFrame |
jfra
main window, set up in init() |
private javax.swing.JScrollPane |
jpane
main window's pane with jtab , created in init() , populated in #showPairInPane() |
private javax.swing.JTable |
jtab
mainwindow's data table, shown within jpane , created and populated in #showPairInPane() |
private int |
jtabClickedCol
Last-clicked model column number in jtab , or -1. |
private int |
jtabClickedRow
Last-clicked row number in jtab , or -1 |
private javax.swing.JMenuItem |
menuAddAbove
Menu items to add a line above or below this line |
private javax.swing.JMenuItem |
menuAddBelow
Menu items to add a line above or below this line |
private javax.swing.JMenuItem |
menuCopyToClip
Menu item to copy cell contents to clipboard, or null if not allowed. |
private PropertiesTranslatorEditor.PTSwingTableModel |
mod
data model for JTable |
private javax.swing.JPopupMenu |
mTablePopup
Context popup menu within table. |
private java.util.List<java.lang.String> |
newDestComments
If isDestNew , optional set of header comments, or null. |
private ParsedPropsFilePair |
pair
Pair of properties files being edited, and their contents. |
private PropertiesTranslatorEditor.SearchPanel |
sPan
Text search panel, not always visible, at bottom of window below jtab |
(package private) static StringManager |
strings
i18n text strings; if null, call initStringManager() to initialize. |
Constructor Summary | |
---|---|
PropertiesTranslatorEditor(java.io.File dest)
Editor where the source filename will be derived from the destination filename. |
|
PropertiesTranslatorEditor(java.io.File src,
java.io.File dest)
Editor with source and destination files specified. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent ae)
Handle button clicks. |
boolean |
checkUnsavedBeforeDispose()
Checks for unsaved changes ( pair .unsavedSrc
|| pair .unsavedDest ) and if any, ask the
user if they want to save before closing. |
void |
doMouseEvent(java.awt.event.MouseEvent e,
boolean isPress)
Handle mouse clicks in table cells, including context-menu popup trigger; will set currently selected cell at mousePressed before showing popup. |
void |
doSearchHotkey()
Show and focus the Search bar when its hotkey (Ctrl-F 'Find') is pressed. |
static java.lang.String[] |
findBaseAndLangInFilename(java.lang.String propsFilename)
Given a properties file name, try to determine its base name and language if any. |
boolean |
hasUnsavedChanges()
Are there any unsaved changes in the destination and/or source properties files? |
void |
init()
Continue GUI startup, once constructor has set pair or left it null. |
(package private) static void |
initStringManager()
Initialize strings with the properties bundle at net/nand/util/i18n/gui/strings/pte.properties
in the default locale. |
private void |
insertRow(java.awt.event.ActionEvent ae,
boolean beforeRow)
Add/insert a row before or after the row that was right-clicked on, which was stored at click time in jtabClickedRow . |
static void |
main(java.lang.String[] args)
'Local' main program; the package's actual main is PTEMain . |
static java.io.File |
makeParentFilename(java.lang.String destFilename)
Given a more-specific destination locale filename, calculate the less-specific source filename by removing _xx suffix(es) and check whether that source exists. |
void |
mouseClicked(java.awt.event.MouseEvent e)
|
void |
mouseEntered(java.awt.event.MouseEvent e)
|
void |
mouseExited(java.awt.event.MouseEvent e)
|
void |
mousePressed(java.awt.event.MouseEvent e)
|
void |
mouseReleased(java.awt.event.MouseEvent e)
|
private static void |
runUnitTests()
A few quick unit tests |
void |
saveChangesToAny()
Save any unsaved changes to the destination and/or source properties files. |
void |
saveChangesToDest()
Save changes to the destination file, and clear the pair.unsavedDest flag. |
void |
saveChangesToSrc()
Save changes to the source file, and clear the pair.unsavedSrc flag. |
void |
setDestIsNew(java.util.List<java.lang.String> comments)
Indicate that the destination is new (not yet existing): init() will then ignore FileNotFoundException for destination. |
private void |
updateSaveButtonsForEditing(boolean startEditing,
boolean isSrc)
Enable/disable the Save Src or Save Dest button while editing a cell. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static StringManager strings
initStringManager()
to initialize.
private ParsedPropsFilePair pair
pair.srcFile
and pair.destFile
.
null
if we start with no parameters, and wait for a file-open dialog from PTEMain
.
private boolean isDestNew
setDestIsNew(List)
has been called
private java.util.List<java.lang.String> newDestComments
isDestNew
, optional set of header comments, or null.
Same format as PropsFileParser.KeyPairLine#comment
.
Set to null during init()
to free up the reference for gc.
private javax.swing.JFrame jfra
init()
private javax.swing.JScrollPane jpane
jtab
, created in init()
, populated in #showPairInPane()
private javax.swing.JButton bFind
sPan
at bottom of window
private javax.swing.JButton bHelp
private javax.swing.JButton bSaveSrc
private javax.swing.JButton bSaveDest
private javax.swing.JPopupMenu mTablePopup
init()
.
private javax.swing.JMenuItem menuAddAbove
private javax.swing.JMenuItem menuAddBelow
private javax.swing.JMenuItem menuCopyToClip
init()
calls SecurityManager.checkSystemClipboardAccess()
to check if allowed.
private javax.swing.JTable jtab
jpane
, created and populated in #showPairInPane()
private PropertiesTranslatorEditor.SearchPanel sPan
jtab
private PropertiesTranslatorEditor.PTSwingTableModel mod
private int jtabClickedRow
jtab
, or -1
private int jtabClickedCol
jtab
, or -1.
Columns stretch to fit the table width, so a click will always be in a column.
private PropertiesTranslatorEditor.CellEditorMouseListener cellListener
JTable.prepareEditor(TableCellEditor, int, int)
/ JTable.removeEditor()
.
private static java.util.regex.Pattern _regex_findBaseAndLang
findBaseAndLangInFilename(String)
Constructor Detail |
---|
public PropertiesTranslatorEditor(java.io.File src, java.io.File dest)
init()
to bring up the GUI and parse the properties files.
src
- Source language/locale properties filedest
- Destination language/locale properties filepublic PropertiesTranslatorEditor(java.io.File dest) throws java.lang.IllegalArgumentException, java.io.FileNotFoundException
init()
to bring up the GUI and parse the properties files.
dest
- Destination language properties file, full or relative path.
Its filename must end with "_xx.properties" and the
source will be the same filename without the "_xx" part.
(The "_xx" part can be any length, not limited to 2 letters.)
This constructor will call
makeParentFilename
({@link File#getPath() dest.getPath()).
java.lang.IllegalArgumentException
- Unless destFilename ends with _xx.properties
(xx = any code 2 or more chars long)
java.io.FileNotFoundException
- if no existing parent of dest
can be found on disk
by makeParentFilename(String)
Method Detail |
---|
public void setDestIsNew(java.util.List<java.lang.String> comments)
init()
will then ignore FileNotFoundException for destination.
Optionally provide header comments to place in the destination.
comments
- any comment lines to use as the initial contents;
same format as PropsFileParser.KeyPairLine#comment
. Otherwise null
.public void init()
pair
or left it null.
Will start the GUI and then parse pair
's files from its srcFile and destFile fields.
If the destination is new (not yet existing), call setDestIsNew(List)
before this method.
public void actionPerformed(java.awt.event.ActionEvent ae)
actionPerformed
in interface java.awt.event.ActionListener
public void doSearchHotkey()
private void updateSaveButtonsForEditing(boolean startEditing, boolean isSrc)
PropertiesTranslatorEditor.PTSwingTableModel.setValueAt(Object, int, int)
which will set the file's unsaved flag and enable the button again.
startEditing
- True if the user just started editing the cell, false if they just finished editingisSrc
- True for source column, false for destination. Ignored unless startEditing
because the JTable method called after editing doesn't give the column, so we check both buttons.private void insertRow(java.awt.event.ActionEvent ae, boolean beforeRow)
jtabClickedRow
.
ae
- Menu popup action, with right-click locationbeforeRow
- If true, insert before (above), otherwise add after (below) this linepublic boolean hasUnsavedChanges()
checkUnsavedBeforeDispose()
,
saveChangesToAny()
public void saveChangesToAny()
public void saveChangesToDest()
pair.unsavedDest
flag.
If pair.unsavedInsRows
is set, calls
pair.convertInsertedRows()
before saving.
Will save even if the pair.unsavedDest
flag is false.
public void saveChangesToSrc()
pair.unsavedSrc
flag.
If pair.unsavedInsRows
is set, calls
pair.convertInsertedRows()
before saving.
Will save even if the pair.unsavedSrc
flag is false.
public boolean checkUnsavedBeforeDispose()
pair
.unsavedSrc
|| pair
.unsavedDest
) and if any, ask the
user if they want to save before closing. Calls saveChangesToAny()
if user clicks yes.
hasUnsavedChanges()
public static java.io.File makeParentFilename(java.lang.String destFilename) throws java.lang.IllegalArgumentException, java.lang.NullPointerException
destFilename
- Destination language properties file, full or relative path.
This filename must end with "_xx.properties" and the
source will be the same filename without the "_xx" part.
(The "_xx" part can be any length, not limited to 2 letters.)
java.lang.IllegalArgumentException
- Unless destFilename ends with _xx.properties
(xx = any code 2 or more chars long)
java.lang.NullPointerException
- if destFilename
is nullpublic static java.lang.String[] findBaseAndLangInFilename(java.lang.String propsFilename) throws java.lang.NullPointerException
Assumes the base name won't contain 2 or 3 lowercase letters between underscores, which looks like a language suffix. This is more strict than the spec for java identifiers (thus classes/props file base names) which allows underscores.
Process:
.properties
, return null
.properties
as the base name
null
propsFilename
- Properties filename to examine; see above for assumptions and process
null
.
If the base name can't be determined, returns null
instead of an array.
java.lang.NullPointerException
- if propsFilename
is nullpublic void doMouseEvent(java.awt.event.MouseEvent e, boolean isPress)
isPress
- True for mousePressed, to change selected cellpublic void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
private static void runUnitTests()
static void initStringManager()
strings
with the properties bundle at net/nand/util/i18n/gui/strings/pte.properties
in the default locale.
public static void main(java.lang.String[] args) throws java.lang.IllegalStateException, java.io.IOException
PTEMain
.
This main will bring up the PTEMain
main menu, or an
editor for .properties filename(s) on the command line,
or run a few unit tests.
args
- Path/Filename of destination .properties, or source and destination.
If destination only, filename must end with "_xx.properties" and the
source will be the same filename without the "_xx" part.
Or, can contain --test
to run a few unit tests.
java.io.IOException
- if a properties file does not exist or cannot be read
java.lang.IllegalStateException
- if any call-sequence errors occur
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |