From: Jirka Kosek Date: Tue, 4 Dec 2007 21:53:30 +0000 (+0000) Subject: Moving to proper place X-Git-Tag: release/1.79.1~6^2~1596 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27b6ff41afb678bb586e8000b2478d9616c9dbfd;p=docbook-dsssl Moving to proper place --- diff --git a/contrib/tools/fo-editor/build.xml b/contrib/tools/fo-editor/build.xml new file mode 100644 index 000000000..ead7be77b --- /dev/null +++ b/contrib/tools/fo-editor/build.xml @@ -0,0 +1,123 @@ + + + + + Create distribution for FO parameter editor. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/tools/fo-editor/configuration/attributes.xml b/contrib/tools/fo-editor/configuration/attributes.xml new file mode 100644 index 000000000..020953e88 --- /dev/null +++ b/contrib/tools/fo-editor/configuration/attributes.xml @@ -0,0 +1,71 @@ + + + + space-before + space-before.optimum + space-before.minimum + space-before.maximum + + + + space-after + space-after.optimum + space-after.minimum + space-after.maximum + + + + start-indent + end-indent + line-height + hyphenate + text-align + + + + font-family + font-weight + font-size + font-style + + + + + margin + margin-left + margin-right + margin-bottom + margin-top + + + + padding + padding-left + padding-right + padding-bottom + padding-top + + + + width + border-width + border-color + border-style + border-collapse + table-layout + + + + keep-with-next.within-column + keep-with-next.within-line + keep-with-next.within-page + wrap-option + + + + color + background-color + + + + diff --git a/contrib/tools/fo-editor/configuration/config.xml b/contrib/tools/fo-editor/configuration/config.xml new file mode 100644 index 000000000..f3741ea37 --- /dev/null +++ b/contrib/tools/fo-editor/configuration/config.xml @@ -0,0 +1,574 @@ + + +
+ + + paper.type + page.orientation + double.sided + toc.html + + + page.width + page.height + page.width.portrait + page.height.portrait + + + page.margin.inner + page.margin.outer + page.margin.top + page.margin.bottom + body.margin.top + body.margin.bottom + region.before.extent + region.after.extent + + + + + body.start.indent + body.end.indent + + + line-height + alignment + hyphenate + normal.para.spacing + + + superscript.properties + subscript.properties + + + + + marker.section.level + + + headers.on.blank.pages + header.rule + header.column.widths + header.table.height + header.content.properties + + + footers.on.blank.pages + footer.rule + footer.column.widths + footer.table.height + footer.content.properties + + + + + body.font.family + title.font.family + monospace.font.family + dingbat.font.family + sans.font.family + symbol.font.family + + + body.font.master + body.font.size + footnote.font.size + + + monospace.properties + verbatim.properties + + + + + list.block.properties + + + list.block.spacing + list.item.spacing + compact.list.item.spacing + + + variablelist.max.termlength + variablelist.as.blocks + variablelist.term.separator + variablelist.term.break.after + + + itemizedlist.label.width + itemizedlist.properties + itemizedlist.label.properties + + + orderedlist.label.width + orderedlist.properties + orderedlist.label.properties + + + segmentedlist.as.table + + + + + column.count.back + column.count.body + column.count.front + column.count.index + column.count.lot + column.count.titlepage + + + column.gap.back + column.gap.body + column.gap.front + column.gap.index + column.gap.lot + column.gap.titlepage + + + + + chapter.autolabel + appendix.autolabel + preface.autolabel + reference.autolabel + + + part.autolabel + label.from.part + component.label.includes.part.label + + + section.autolabel + section.label.includes.component.label + section.autolabel.max.depth + + + + + title.margin.left + + + formal.title.placement + + + component.title.properties + formal.title.properties + article.appendix.title.properties + + +
+ +
+ + + pgwide.properties + + + formal.object.properties + informal.object.properties + + + figure.properties + informalfigure.properties + + + example.properties + informalexample.properties + + + abstract.properties + abstract.title.properties + + + blockquote.properties + + + revhistory.table.properties + revhistory.table.cell.properties + revhistory.title.properties + + + + + admon.textlabel + admonition.title.properties + admonition.properties + nongraphical.admonition.properties + + + admon.graphics + admon.graphics.path + admon.graphics.extension + graphical.admonition.properties + + + + + callout.defaultcolumn + callouts.extension + + + callout.graphics + callout.graphics.path + callout.graphics.extension + callout.graphics.number.limit + + + callout.unicode + callout.unicode.font + callout.unicode.number.limit + callout.unicode.start.character + + + + + sidebar.properties + sidebar.title.properties + sidebar.float.type + sidebar.float.width + + + margin.note.properties + margin.note.title.properties + margin.note.float.type + margin.note.width + + + + + section.title.properties + section.title.level1.properties + section.title.level2.properties + section.title.level3.properties + section.title.level4.properties + section.title.level5.properties + section.title.level6.properties + + + section.properties + section.level1.properties + section.level2.properties + section.level3.properties + section.level4.properties + section.level5.properties + section.level6.properties + + + + + table.table.properties + table.properties + informaltable.properties + + + default.table.width + nominal.table.width + + + table.frame.border.thickness + table.frame.border.style + table.frame.border.color + + + table.cell.border.thickness + table.cell.border.style + table.cell.border.color + table.cell.padding + + + + + generate.toc + autotoc.label.separator + toc.line.properties + + + toc.max.depth + toc.section.depth + generate.section.toc.level + + + process.empty.source.toc + process.source.toc + + + bridgehead.in.toc + simplesect.in.toc + + + toc.indent.width + toc.margin.properties + + + + + qandadiv.autolabel + qanda.inherit.numeration + qanda.defaultlabel + + + qanda.title.properties + qanda.title.level1.properties + qanda.title.level2.properties + qanda.title.level3.properties + qanda.title.level4.properties + qanda.title.level5.properties + qanda.title.level6.properties + + + + + bibliography.numbered + bibliography.collection + + + biblioentry.item.separator + biblioentry.properties + + + + + glossentry.show.acronym + glossary.as.blocks + glosslist.as.blocks + glossterm.separation + glossterm.width + + + glossary.collection + glossterm.auto.link + firstterm.only.link + + + + + footnote.properties + footnote.mark.properties + footnote.sep.leader.properties + + + footnote.number.format + footnote.number.symbols + + + table.footnote.number.format + table.footnote.number.symbols + table.footnote.properties + + + + + refentry.generate.name + refentry.generate.title + refentry.title.properties + refentry.pagebreak + refentry.xref.manvolnum + refclass.suppress + + + function.parens + + + funcsynopsis.decoration + funcsynopsis.style + + + + + default.float.class + formal.procedures + procedure.properties + + + highlight.default.language + highlight.source + + + menuchoice.separator + menuchoice.menu.separator + + + shade.verbatim + hyphenate.verbatim + hyphenate.verbatim.characters + shade.verbatim.style + monospace.verbatim.properties + + + linenumbering.everyNth + linenumbering.extension + linenumbering.separator + linenumbering.width + + +
+ +
+ + + show.comments + + + rootid + root.properties + + + draft.watermark.image + draft.mode + + + ebnf.assignment + ebnf.statement.terminator + + + crop.marks + crop.mark.width + crop.mark.offset + crop.mark.bleed + + + runinhead.default.title.end.punct + runinhead.title.end.punct + email.delimiters.enabled + + + + + l10n.gentext.default.language + l10n.gentext.language + l10n.gentext.use.xref.language + l10n.lang.value.rfc.compliant + + + + + make.single.year.ranges + make.year.ranges + author.othername.in.middle + punct.honorific + + + + + insert.xref.page.number + insert.link.page.number + xref.with.number.and.title + use.role.as.xrefstyle + xref.properties + + + xref.label-title.separator + xref.label-page.separator + xref.title-page.separator + + + ulink.show + ulink.hyphenate + ulink.hyphenate.chars + ulink.footnotes + + + + + arbortext.extensions + axf.extensions + fop.extensions + fop1.extensions + xep.extensions + + + use.extensions + tablecolumns.extension + + + textinsert.extension + textdata.default.encoding + + + + + passivetex.extensions + tex.math.in.alt + tex.math.delims + + + equation.properties + informalequation.properties + + + + + generate.index + make.index.markup + index.on.type + index.on.role + index.method + + + index.number.separator + index.range.separator + index.term.separator + + + index.preferred.page.properties + index.entry.properties + index.div.title.properties + xep.index.item.properties + + + + + use.svg + graphic.default.extension + img.src.path + keep.relative.image.uris + + + default.image.width + ignore.image.scaling + + + preferred.mediaobject.role + use.role.for.mediaobject + + + + + current.docid + collect.xref.targets + insert.olink.page.number + insert.olink.pdf.frag + olink.base.uri + olink.debug + olink.doctitle + olink.lang.fallback.sequence + olink.properties + prefer.internal.olink + target.database.document + targets.filename + use.local.olink.style + + + + + profile.arch + profile.condition + profile.conformance + profile.lang + profile.os + profile.revision + profile.revisionflag + profile.role + profile.security + profile.userlevel + profile.vendor + profile.attribute + profile.value + profile.separator + + +
+ +
+ diff --git a/contrib/tools/fo-editor/configuration/graphics.xml b/contrib/tools/fo-editor/configuration/graphics.xml new file mode 100644 index 000000000..dc89fa163 --- /dev/null +++ b/contrib/tools/fo-editor/configuration/graphics.xml @@ -0,0 +1,7 @@ + + +
+ page.width + page.height +
+
diff --git a/contrib/tools/fo-editor/configuration/parameters.xml b/contrib/tools/fo-editor/configuration/parameters.xml new file mode 100644 index 000000000..2d1f177c7 --- /dev/null +++ b/contrib/tools/fo-editor/configuration/parameters.xml @@ -0,0 +1,1380 @@ + + + + USletter + USlandscape + 4A0 + 2A0 + A0 + A1 + A2 + A3 + A4 + A4landscape + A5 + A6 + A7 + A8 + A9 + A10 + B0 + B1 + B2 + B3 + B4 + B5 + B6 + B7 + B8 + B9 + B10 + C0 + C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 + C9 + C10 + USletter + combo-box + + + + in + 8.5 + spinner-float + + + + in + 11 + spinner-float + + + + in + 11 + spinner-float + + + + in + 8.5 + spinner-float + + + + portrait + landscape + portrait + combo-box + + + + in + 1 + spinner-float + + + + in + 1 + spinner-float + + + + in + 0.5 + spinner-float + + + + in + 0.5 + spinner-float + + + + 0 + check-box + + + + in + 0.4 + spinner-float + + + + in + 0.4 + spinner-float + + + + 1 + check-box + + + + 1 + check-box + + + + 1 + check-box + + + + 1 + check-box + + + + 1 1 1 + text-field + + + + 1 1 1 + text-field + + + + in + 0.5 + spinner-float + + + + in + 0.5 + spinner-float + + + + pc + 4 + spinner-float + + + + pt + 0 + spinner-float + + + + pt + 0 + spinner-float + + + + figure before +example before +equation before +table before +procedure before +task before + text-area + + + + 12.5 + spinner-float + + + + justify + center + left + right + justify + combo-box + + + + true + check-box + + + + font + serif + combo-box-edit + + + + font + sans-serif + combo-box-edit + + + + font + monospace + combo-box-edit + + + + font + serif + combo-box-edit + + + + font + sans-serif + combo-box-edit + + + + Symbol,ZapfDingbats + text-field + + + + 10 + spinner-float + + + + pt + 10 + spinner-float + + + + pt + 8 + spinner-float + + + + 0 + 1 + A + a + I + i + 1 + radio-button + + + + 0 + 1 + A + a + I + i + I + radio-button + + + + 0 + 1 + A + a + I + i + A + radio-button + + + + 0 + 1 + A + a + I + i + 0 + radio-button + + + + 0 + 1 + A + a + I + i + I + radio-button + + + + 0 + 1 + A + a + I + i + 0 + radio-button + + + + 0 + check-box + + + + 0 + check-box + + + + 0 + check-box + + + + + + text-field + + + + in + 6 + spinner-float + + + + pt + 0.5 + spinner-float + + + + pt + 0.5 + spinner-float + + + + none + solid + dotted + dashed + double + groove + ridge + inset + outset + solid + combo-box + + + + none + solid + dotted + dashed + double + groove + ridge + inset + outset + solid + combo-box + + + + color + black + color-chooser + + + + color + black + color-chooser + + + + 0 + check-box + + + + 0 + check-box + + + + 0 + check-box + + + + 0 + check-box + + + + 0 + check-box + + + + 1 + check-box + + + + 1 + check-box + + + + yes + no + maybe + no + radio-button + + + + yes + no + maybe + no + radio-button + + + + 1 + check-box + + + + 0 + check-box + + + + http://docbook.sourceforge.net/release/images/draft.png + text-field + + + + 1 + check-box + + + + 0 + check-box + + + + 0 + check-box + + + + /appendix toc,title +article/appendix nop +/article toc,title +book toc,title,figure,table,example,equation +/chapter toc,title +part toc,title +/preface toc,title +qandadiv toc +qandaset toc +reference toc,title +/sect1 toc +/sect2 toc +/sect3 toc +/sect4 toc +/sect5 toc +/section toc +set toc,title + text-area + + + + 2 + spinner-int + + + + 8 + spinner-int + + + + 0 + spinner-int + + + + 0 + check-box + + + + .png + text-field + + + + 1 + check-box + + + + 5 + spinner-int + + + + 1 + check-box + + + + + text-field + + + + 3 + spinner-int + + + + 1 + check-box + + + + + text-field + + + + 8 + spinner-int + + + + 1 + check-box + + + + ansi + kr + kr + combo-box + + + + 0 + check-box + + + + 1 + check-box + + + + 0 + check-box + + + + 1 + check-box + + + + 1 + check-box + + + + 1 + check-box + + + + 1 + check-box + + + + number + qanda + none + number + combo-box + + + + . + text-field + + + + http://docbook.sourceforge.net/release/bibliography/bibliography.xml + text-field + + + + 24 + spinner-int + + + + : + text-field + + + + + text-field + + + + + text-field + + + + 0 + check-box + + + + 0 + check-box + + + + + text-field + + + + in + 0.25 + spinner-float + + + + in + 2 + spinner-float + + + + 0 + check-box + + + + 0 + check-box + + + + no + yes + primary + no + combo-box + + + + 60 + spinner-int + + + + 1 + check-box + + + + .png + text-field + + + + 15 + spinner-int + + + + images/callouts/ + file-chooser + + + + 0 + check-box + + + + ZapfDingbats + text-field + + + + 10 + spinner-int + + + + 10102 + spinner-int + + + + 1 + check-box + + + + . + text-field + + + + 0 + check-box + + + + 0 + check-box + + + + 24 + spinner-float + + + + 0 + check-box + + + + 0 + check-box + + + + 1 + check-box + + + + 0 + check-box + + + + 0 + check-box + + + + 0 + check-box + + + + + plain + latex + + combo-box + + + + 1 + check-box + + + + yes + no + maybe + maybe + radio-button + + + + 2 + spinner-int + + + + 1 + A + a + I + i + 1 + radio-button + + + + 1 + A + a + I + i + a + radio-button + + + + + text-field + + + + + text-field + + + + 0 + check-box + + + + + text-field + + + + 1 + check-box + + + + + text-field + + + + 0 + check-box + + + + 0 + check-box + + + + 1 + check-box + + + + + text-field + + + + + + text-field + + + + before + text-field + + + + 1 + check-box + + + + . + text-field + + + + .!?: + text-field + + + + . + text-field + + + + 0 + check-box + + + + 0 + check-box + + + + 1 + check-box + + + + + text-field + + + + images/ + file-chooser + + + + 1 + check-box + + + + + text-field + + + + + + text-field + + + + + text-field + + + + 1 + check-box + + + + 0 + check-box + + + + + file-chooser + + + + 1 + spinner-int + + + + 1 + spinner-int + + + + 1 + spinner-int + + + + 2 + spinner-int + + + + 1 + spinner-int + + + + 1 + spinner-int + + + + pt + 12 + spinner-float + + + + pt + 12 + spinner-float + + + + pt + 12 + spinner-float + + + + pt + 12 + spinner-float + + + + pt + 12 + spinner-float + + + + pt + 12 + spinner-float + + + + none + before + left + start + right + end + inside + outside + none + combo-box + + + + in + 1 + spinner-float + + + + none + before + left + start + right + end + inside + outside + none + combo-box + + + + in + 1 + spinner-float + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + + text-field + + + + ; + text-field + + + + + text-field + + + + en + text-field + + + + 0 + check-box + + + + 1 + check-box + + + + + text-field + + + + no + yes + only + no + combo-box + + + + no + yes + maybe + no + combo-box + + + + 0 + check-box + + + + + text-field + + + + 0 + check-box + + + + no + yes + maybe + no + combo-box + + + + + text-field + + + + 0 + check-box + + + + + text-field + + + + target.db + text-field + + + + 0 + check-box + + + + ::= + text-field + + + + + text-field + + + + , + text-field + + + + 0 + check-box + + + + em + 1.0 + spinner-float + + + + em + 1.2 + spinner-float + + + + 0 + check-box + + + + pt + 0.5 + spinner-float + + + + pt + 24 + spinner-float + + + + pt + 6 + spinner-float + + + + 1 + check-box + + + + pt + 14 + spinner-float + + + + 1 + check-box + + + + pt + 14 + spinner-float + + + + 0 + check-box + + + + + text-field + + + + basic + kosek + kimber + basic + combo-box + + + + + text-field + + + + + text-field + + + + + text-field + + + + '' + text-field + + + + 1 + check-box + + + + 0 + check-box + + + + / + text-field + + diff --git a/contrib/tools/fo-editor/configuration/types.xml b/contrib/tools/fo-editor/configuration/types.xml new file mode 100644 index 000000000..226e095a9 --- /dev/null +++ b/contrib/tools/fo-editor/configuration/types.xml @@ -0,0 +1,37 @@ + + + + #00FFFF + #000000 + #0000FF + #FF00FF + #808080 + #008000 + #00FF00 + #800000 + #000080 + #808000 + #800080 + #FF0000 + #C0C0C0 + #008080 + #FFFFFF + #FFFF00 + + + cm + mm + in + pt + pc + px + em + % + + + + serif + sans-serif + monospace + + diff --git a/contrib/tools/fo-editor/lib/help.jar b/contrib/tools/fo-editor/lib/help.jar new file mode 100644 index 000000000..a58ddb62a Binary files /dev/null and b/contrib/tools/fo-editor/lib/help.jar differ diff --git a/contrib/tools/fo-editor/lib/jh.jar b/contrib/tools/fo-editor/lib/jh.jar new file mode 100644 index 000000000..2d143007a Binary files /dev/null and b/contrib/tools/fo-editor/lib/jh.jar differ diff --git a/contrib/tools/fo-editor/lib/log4j-1.2.14.jar b/contrib/tools/fo-editor/lib/log4j-1.2.14.jar new file mode 100644 index 000000000..625130719 Binary files /dev/null and b/contrib/tools/fo-editor/lib/log4j-1.2.14.jar differ diff --git a/contrib/tools/fo-editor/scripts/README b/contrib/tools/fo-editor/scripts/README new file mode 100644 index 000000000..1b079d4f6 --- /dev/null +++ b/contrib/tools/fo-editor/scripts/README @@ -0,0 +1,68 @@ +============================== +Installing FO Parameter Editor +============================== + + ------------ + Requirements + ------------ + + * Sun or Apple Java[tm] runtime 1.5.0 or above. + + FO Parameter Editor is officially supported on Windows XP and Linux. + + + ------------------ + Install on Windows + ------------------ + + 1. Make sure that you have a Java™ 1.5.0+ runtime installed on your machine. + To check this, open a command window and type "java -version" followed by Enter. + You should get something looking like this: + + C:\> java -version + java version "1.5.0_04" + Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05) + Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing) + + 2. Use a tool like WinZip (http://www.winzip.com/), 7-Zip (http://www.7-zip.org/) + or Info-Zip (http://www.info-zip.org/) to unzip the FO Parameter Editor distribution + inside any directory you want: + + C:\> unzip FOeditor-1_0.zip + + 3. FO Parameter Editor is intended to be used directly from the FOeditor-1_0 directory. + That is, you can start FO Parameter Editor by + - simply clicking on FOEditor.jar + - or by executing: C:\> FOeditor-1_0\run.bat + + After that, you may want to add a shortcut to "C:\FOeditor\run.bat" or + "C:\FOeditor\FOEditor.jar" on your desktop. + Errors occuring during the editor run are written down in a log file error.log. + + + ------------------ + Install on Linux + ------------------ + + 1. Make sure that you have a Java™ 1.5.0+ runtime installed on your machine. + To check this, open a command window and type "java -version" followed by Enter. + You should get something looking like this: + + # java -version + java version "1.5.0_04" + Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05) + Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing) + + 2. Unzip the FO Parameter Editor distribution inside any directory you want: + + # unzip FOeditor-1_0.zip + + 3. FO Parameter Editor is intended to be used directly from the FOeditor-1_0 directory. + That is, you can start FO Parameter Editor by + - simply clicking on FOEditor.jar + - or by executing: # FOeditor-1_0\run.sh + + After that, you may want to add a shortcut to "..\FOeditor\run.sh" or + "..\FOeditor\FOEditor.jar" on your desktop. + Errors occuring during the editor run are written down in a log file error.log. + \ No newline at end of file diff --git a/contrib/tools/fo-editor/scripts/run.bat b/contrib/tools/fo-editor/scripts/run.bat new file mode 100644 index 000000000..fa2d0697e --- /dev/null +++ b/contrib/tools/fo-editor/scripts/run.bat @@ -0,0 +1,5 @@ +@echo off + +start javaw -jar FOEditor.jar + +exit \ No newline at end of file diff --git a/contrib/tools/fo-editor/scripts/run.sh b/contrib/tools/fo-editor/scripts/run.sh new file mode 100644 index 000000000..abf069d59 --- /dev/null +++ b/contrib/tools/fo-editor/scripts/run.sh @@ -0,0 +1 @@ +java -jar FOEditor.jar diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/ConfigData.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/ConfigData.java new file mode 100644 index 000000000..10db3e89d --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/ConfigData.java @@ -0,0 +1,83 @@ +package cz.zcu.fav.kiv.editor.beans; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.beans.sections.Section; + +/** + * The ConfigData class represents main structure containing the list of parameter + * sections and lists of predefined type values. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ConfigData { + /** The list of sections */ + private List
sectionList; + + /** The list of parameters - keys are parameter names */ + private Map parameterList; + + /** The list of properties - keys are property names */ + private Map propertyList; + + /** + * Clear values (sets default values) of all sections. + */ + public void clearValues() { + for (Section section : sectionList) + section.clearValues(); + } + + /** + * Search for an parameter with specified name. + * + * @param name + * a name of serched parameter. + * @return the found parameter with specified name. + */ + public Parameter searchParameter(String name) { + return parameterList.get(name); + } + + /** + * Search for a property with specified name. + * + * @param name + * a name of serched property. + * @return the found property with specified name. + */ + public Property searchProperty(String name) { + return propertyList.get(name); + } + + @SuppressWarnings("unchecked") + public List
getSectionList() { + return sectionList != null? sectionList : Collections.EMPTY_LIST; + } + + public void setSectionList(List
sectionList) { + this.sectionList = sectionList; + } + + public Map getParameterList() { + return parameterList; + } + + public void setParameterList(Map parameterList) { + this.parameterList = parameterList; + } + + public Map getPropertyList() { + return propertyList; + } + + public void setPropertyList(Map propertyList) { + this.propertyList = propertyList; + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/OpenFile.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/OpenFile.java new file mode 100644 index 000000000..c42ae48c7 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/OpenFile.java @@ -0,0 +1,87 @@ +package cz.zcu.fav.kiv.editor.beans; + +import org.w3c.dom.Document; + +import cz.zcu.fav.kiv.editor.graphics.MainFrame; +import cz.zcu.fav.kiv.editor.stylesheet.XslParser; + +/** + * The OpenFile class represents an open XSL stylesheet file. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OpenFile { + /** The supported file extension */ + private static final String extension = ".xsl"; + + /** The DOM structure of open stylesheet file */ + private Document wholeFile; + + /** The path to the open file */ + private String openFilePath; + + /** The flag indicating changes in the open file */ + private boolean fileChanged; + + /** + * Initializes a newly created empty OpenFile. Assignes the + * wholeFile to the new empty DOM XSL stylesheet structure. Sets the newly + * created file as not changed (fileChanged). + */ + public OpenFile() { + this.wholeFile = XslParser.createXsltFile(); + this.fileChanged = false; + } + + public Document getWholeFile() { + return wholeFile; + } + + /** + * Sets the new DOM structure wholeFile of newly opened file. Sets the opened + * file as not changed. + * + * @param wholeFile + * DOM structure of the opened file. + */ + public void setWholeFile(Document wholeFile) { + this.wholeFile = wholeFile; + setFileChanged(false); + } + + public String getOpenFilePath() { + return openFilePath; + } + + /** + * Sets the new openFilePath of the opened file. If the file hasn't the extension + * XSL, then the extension is added. + * + * @param openFilePath + * a new path to the opened file. + */ + public void setOpenFilePath(String openFilePath) { + if (openFilePath != null) { + if (!openFilePath.trim().endsWith(extension)) + openFilePath = openFilePath + extension; + } + this.openFilePath = openFilePath; + } + + public boolean isFileChanged() { + return fileChanged; + } + + /** + * Sets if the opened file is changed or not. According to changes sets the status information + * about the file. + * + * @param fileChanged + * true, if the file has changed. + */ + public void setFileChanged(boolean fileChanged) { + this.fileChanged = fileChanged; + MainFrame.getInstance().changeTitle(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/GeneralElement.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/GeneralElement.java new file mode 100644 index 000000000..064cacaae --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/GeneralElement.java @@ -0,0 +1,57 @@ +package cz.zcu.fav.kiv.editor.beans.common; + +import java.util.Observable; + +import org.w3c.dom.Node; + +/** + * The GeneralElement class represents a parent common for all elements like + * Parameter, Property or Attribute. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class GeneralElement extends Observable { + /** The name of the element */ + protected String name; + + /** The node associated with the element */ + protected Node node; + + /** + * Initializes a newly created emptyGeneralElement. + */ + public GeneralElement() { + } + + /** + * Initializes a newly created emptyGeneralElement with the specified name. The + * name argument is the name of the element. + * + * @param name + * a name of the element. + */ + public GeneralElement(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Node getNode() { + return node; + } + + public void setNode(Node node) { + this.node = node; + } + + public boolean equals(Object obj) { + return ((GeneralElement) obj).getName().equals(this.getName()); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/ParentParameter.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/ParentParameter.java new file mode 100644 index 000000000..1fbf1e1c6 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/ParentParameter.java @@ -0,0 +1,96 @@ +package cz.zcu.fav.kiv.editor.beans.common; + +/** + * The ParentParameter class represents a parent common for all elements like + * Parameter or Property. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParentParameter extends GeneralElement implements Comparable { + /** The description of the element */ + protected String description; + + /** The purpose of the element */ + protected String purpose; + + /** The flag specifying whether the element is chosen or not */ + protected boolean chosen; + + protected int lineNumber; + + /** + * Initializes a newly created emptyParentParameter. + */ + public ParentParameter() { + } + + /** + * Initializes a newly created emptyParentParameter with the specified name. The + * name argument is the name of the element. + * + * @param name + * a name of the element. + */ + public ParentParameter(String name) { + this.name = name; + } + + public ParentParameter(String name, int lineNumber) { + this.name = name; + this.lineNumber = lineNumber; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getPurpose() { + return purpose; + } + + public void setPurpose(String purpose) { + this.purpose = purpose; + } + + /** + * Clear values (sets default values) of the element + * and notifies its observers. + */ + public void clearValues() { + setNode(null); + this.chosen = false; + setChanged(); + notifyObservers(false); + } + + public Boolean isChosen() { + return chosen; + } + + public void setChosen(Boolean isChosen) { + this.chosen = isChosen; + } + + /** + * Choses the element - sets the flag chosen to true. + * At the same time notifies its observers. + */ + public void setChosen() { + this.chosen = true; + setChanged(); + notifyObservers(true); + } + + public int compareTo(Object obj) { + return ((GeneralElement) obj).getName().compareTo(this.getName()); + } + + public int getLineNumber() { + return lineNumber; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/ParentSection.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/ParentSection.java new file mode 100644 index 000000000..a6fd44591 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/common/ParentSection.java @@ -0,0 +1,28 @@ +package cz.zcu.fav.kiv.editor.beans.common; + +/** + * The ParentSection class represents a parent for all + * classes representing a group of items. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParentSection { + /** The title of the group */ + protected String title; + + /** + * Initializes a newly created ParentSection with + * the specified name. The title argument is the + * title of the group. + * + * @param title a title of the group. + */ + public ParentSection(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/graphics/Figure.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/graphics/Figure.java new file mode 100644 index 000000000..0a5642bf5 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/graphics/Figure.java @@ -0,0 +1,49 @@ +package cz.zcu.fav.kiv.editor.beans.graphics; + +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; + +/** + * The Figure class represents a graphics figure used for illustrating values of some + * parameters. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Figure { + /** The name of the figure */ + private String name; + + /** The class name asociated with the figure */ + private String className; + + /** The list of parameters associated with the figure */ + private Parameter[] parameterList; + + public Figure(String name) { + this.name = name; + } + + public String getClassName() { + return className; + } + + public String getName() { + return name; + } + + public Parameter[] getParameterList() { + return parameterList; + } + + public void setParameterList(Parameter[] parameters) { + this.parameterList = parameters; + } + + public boolean equals(Object obj) { + return ((Figure) obj).getName().equals(this.getName()); + } + + public void setClassName(String className) { + this.className = className; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/Parameter.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/Parameter.java new file mode 100644 index 000000000..52e397c42 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/Parameter.java @@ -0,0 +1,59 @@ +package cz.zcu.fav.kiv.editor.beans.parameters; + +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; + +/** + * The Parameter class represents an element parameter. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Parameter extends ParentParameter { + /** The type of the parameter */ + private TypeParam type; + + /** + * Initializes a newly created Parameter with the specified name. Parameter is + * marked as not chosen. The name argument is the name of the parameter. + * + * @param name + * a name of the parameter. + */ + + public Parameter(String name, int lineNumber) { + super(name, lineNumber); + this.chosen = false; + this.type = new TypeParam(this); + } + + public Parameter(String name) { + super(name); + this.chosen = false; + this.type = new TypeParam(this); + } + + public TypeParam getType() { + return type; + } + + public void setType(TypeParam type) { + this.type = type; + } + + /** + * Clear values (sets default values) of the parameter type and notify its observers. + */ + public void clearValues() { + this.getType().setDefault(); + super.clearValues(); + } + + /** + * Update the value of the Figures associated with the parameter. + */ + public void updateFigure() { + setChanged(); + notifyObservers(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/TypeParam.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/TypeParam.java new file mode 100644 index 000000000..68998d514 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/TypeParam.java @@ -0,0 +1,66 @@ +package cz.zcu.fav.kiv.editor.beans.parameters; + +import cz.zcu.fav.kiv.editor.beans.types.Type; + +/** + * The TypeParam class represents a type of parameter. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TypeParam extends Type { + + /** The reference to the parametet of the type */ + private Parameter parameter; + + /** + * Initializes a newly created TypeParam with reference to the appropriate + * parameter. + * + * @param param + * a reference to the type parameter. + */ + public TypeParam(Parameter param) { + super(); + this.parameter = param; + } + + /** + * Sets the new value of the type, marks the parameter as chosen and update + * parameter graphics figures. + * + * @param value + * a new value of the type. + */ + @Override + public void changeValue(String value) { + this.value = value; + parameter.setChosen(); + parameter.updateFigure(); + } + + /** + * Sets the new value of the type and notifies its observers. + */ + @Override + public void updateValue() { + setChanged(); + notifyObservers(this.value); + if (unit != null) + unit.updateValue(); + } + + /** + * Sets the default value of the type and its unit. Notifies its observers. + */ + public void setDefault() { + super.setDefault(); + setChanged(); + notifyObservers(value); + } + + @Override + public String getOwnerName() { + return parameter.getName(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/UnitParam.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/UnitParam.java new file mode 100644 index 000000000..6d58ca3d0 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/parameters/UnitParam.java @@ -0,0 +1,69 @@ +package cz.zcu.fav.kiv.editor.beans.parameters; + +import java.util.List; + +import cz.zcu.fav.kiv.editor.beans.types.Unit; + +/** + * The UnitParam class represents a unit of parameter type. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class UnitParam extends Unit { + /** The reference to the parametet of the unit */ + private Parameter parameter; + + /** + * Initializes a newly created UnitParam with the specified value, predefined + * units and reference to the appropriate parameter. The value argument is the + * value of the unit. The unitList is a list of predefined units. The + * parameter argument is an appropriate parameter. + * + * @param value + * a value of the unit. + * @param unitList + * a list of predefined units. + * @param parameter + * a reference to the unit parameter. + */ + public UnitParam(String value, List unitList, Parameter parameter) { + super(value, unitList); + this.parameter = parameter; + } + + public UnitParam(List unitList, Parameter parameter) { + super(unitList); + this.parameter = parameter; + } + + /** + * Sets the new value of unit and notifies its observers. + */ + @Override + public void updateValue() { + setChanged(); + notifyObservers(value); + } + + /** + * Sets the new value of unit and marks its parameter as chosen. + * + * @param value + * a new value of the unit. + */ + @Override + public void changeValue(String value) { + this.value = value; + parameter.setChosen(); + } + + /** + * Sets the default value of the unit - assignes the default value to the main value and notifies its observers. + */ + public void setDefault() { + super.setDefault(); + setChanged(); + notifyObservers(value); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/Attribute.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/Attribute.java new file mode 100644 index 000000000..ddb43ef8d --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/Attribute.java @@ -0,0 +1,112 @@ +package cz.zcu.fav.kiv.editor.beans.properties; + +import cz.zcu.fav.kiv.editor.beans.common.GeneralElement; +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The Attribute class represents an atribute of property. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Attribute extends GeneralElement implements Cloneable { + /** The list of attribute types */ + private TypeAttr type; + + /** The flag specifying whether the attribute is chosen or not */ + private boolean chosen; + + /** The temporary value of the attribute */ + private boolean temporaryChosen; + + public Attribute(String name) { + this.name = name; + } + + /** + * Initializes a newly created Attribute with the specified name and the + * type. Marks the attribute as not chosen. The name argument is the name of the + * attribute. The type argument is the type of attribute. + * + * @param name + * a name of attribute. + * @param type + * a type of attribute. + */ + public Attribute(String name, TypeAttr type) { + super(name); + this.type = type; + this.chosen = false; + } + + public Boolean isChosen() { + return chosen; + } + + /** + * Sets the attribute chosen parameter according the input argument and assignes + * the value to the temporaryChosen. + * + * @param isChosen + * a value specifying whether the attribute is chosen or not. + */ + public void setChosen(Boolean isChosen) { + this.chosen = isChosen; + this.temporaryChosen = isChosen; + } + + public void setChosen() { + this.temporaryChosen = true; + setChanged(); + notifyObservers(true); + } + + /** + * Sets the temporaryChosen parameter according the input argument. + * + * @param isChosen + * a value specifying whether the attribute is chosen or not. + */ + public void changeChosen(Boolean isChosen) { + this.temporaryChosen = isChosen; + } + + public Object clone() { + Attribute attribute = null; + try { + attribute = (Attribute) super.clone(); + attribute.setName(this.name); + + attribute.setType((TypeAttr)this.type.clone()); + } catch (CloneNotSupportedException ex) { + Log.error(ex); + } + return attribute; + } + + /** + * Clear values (sets default values) of the attribute types. + */ + public void clearValues() { + type.setDefault(); + this.chosen = false; + this.node = null; + } + + /** + * Sets values of all types after their temporary values. Sets chosen after + * temporaryChosen. + */ + public void setValuesFromTemporary() { + type.setValuesFromTemporary(); + this.chosen = temporaryChosen; + } + + public void setType(TypeAttr type) { + this.type = type; + } + + public TypeAttr getType() { + return type; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/AttributeGroup.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/AttributeGroup.java new file mode 100644 index 000000000..89762134b --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/AttributeGroup.java @@ -0,0 +1,76 @@ +package cz.zcu.fav.kiv.editor.beans.properties; + +import java.util.ArrayList; +import java.util.List; + +import cz.zcu.fav.kiv.editor.beans.common.ParentSection; +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The AttributeGroup class represents a group of atributes. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AttributeGroup extends ParentSection implements Cloneable { + + /** The list of attributes in the group */ + private List attributeList; + + /** + * Initializes a newly created Attribute with the specified name and description. + * The title argument is the name of the attribute group. + * + * @param title + * a name of the attribute group. + */ + public AttributeGroup(String title) { + super(title); + } + + public void setTitle(String title){ + this.title = title; + } + + public Object clone() { + AttributeGroup group = null; + try { + group = (AttributeGroup) super.clone(); + group.setTitle(this.title); + + List newAttributes = new ArrayList(); + for (int i = 0; i < attributeList.size(); i++) { + newAttributes.add((Attribute) attributeList.get(i).clone()); + } + group.setAttributeList(newAttributes); + } catch (CloneNotSupportedException ex) { + Log.error(ex); + } + return group; + } + + public List getAttributeList() { + return attributeList; + } + + public void setAttributeList(List attributes) { + this.attributeList = attributes; + } + + /** + * Clear values (sets default values) of all attribute types in the group. + */ + public void clearValues() { + for (Attribute attr : this.attributeList) { + attr.clearValues(); + } + } + + /** + * Sets values of all attribute types in the group after their temporary values. + */ + public void setValuesFromTemporary() { + for (Attribute at : this.getAttributeList()) + at.setValuesFromTemporary(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/Property.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/Property.java new file mode 100644 index 000000000..f4a4b61bf --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/Property.java @@ -0,0 +1,67 @@ +package cz.zcu.fav.kiv.editor.beans.properties; + +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; + +/** + * The Property class represents an element property. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Property extends ParentParameter { + /** The list of attribute groups */ + private AttributeGroup[] attributeGroupList; + + /** + * Initializes a newly created Attribute with the specified name and the list of + * attribute groups. The name argument is the name of the property. The + * attributeGroups argument is the list of AttributeGroups. + * + * @param name + * a name of the property. + * @param attributeGroups + * a list of attribute groups. + */ + public Property(String name, AttributeGroup[] attributeGroups, int lineNumber) { + super(name, lineNumber); + this.attributeGroupList = attributeGroups; + } + + public AttributeGroup[] getAttributeGroupList() { + return attributeGroupList; + } + + /** + * Search for an attribute with specified name. + * + * @param name + * a name of serched attribute. + * @return the found attribute with specified name. + */ + public Attribute searchAttribute(String name) { + for (AttributeGroup group : attributeGroupList) { + int ind = group.getAttributeList().indexOf(new Attribute(name)); + if (ind >= 0) + return group.getAttributeList().get(ind); + } + return null; + } + + /** + * Sets values of all groups of types after their temporary values. + */ + public void setValuesFromTemporary() { + for (AttributeGroup pan : attributeGroupList) + pan.setValuesFromTemporary(); + } + + /** + * Clear values (sets default values) of all groups of types. + */ + public void clearValues() { + super.clearValues(); + for (AttributeGroup group : this.attributeGroupList) { + group.clearValues(); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/TypeAttr.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/TypeAttr.java new file mode 100644 index 000000000..b7e71e8ee --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/TypeAttr.java @@ -0,0 +1,74 @@ +package cz.zcu.fav.kiv.editor.beans.properties; + +import cz.zcu.fav.kiv.editor.beans.types.Type; + +/** + * The TypeAttr class represents a type of attribute. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TypeAttr extends Type { + /** The temporary value of the attribute type */ + private String temporaryValue; + + /** The reference to the attribute of the type */ + private Attribute attribute; + + /** + * Initializes a newly created empty TypeAttr. + */ + public TypeAttr() { + super(); + } + + /** + * Sets values of the type and its unit after their temporary values. + */ + public void setValuesFromTemporary() { + if (this.temporaryValue != null) + this.value = this.temporaryValue; + if (this.unit != null) + ((UnitAttr) this.unit).setValuesFromTemporary(); + } + + /** + * Sets the new value of the type (standard and temporary value) and marks the + * attribute as chosen. + * + * @param value + * a new value of the type. + */ + @Override + public void changeValue(String value) { + this.temporaryValue = value; + this.attribute.setChosen(); + } + + /** + * Sets the new temporary value of the type. + */ + @Override + public void updateValue() { + this.temporaryValue = this.value; + if (unit != null) + unit.updateValue(); + } + + public void setAttr(Attribute attr) { + this.attribute = attr; + } + + /** + * Sets the default and temporary value of the type and its unit. + */ + public void setDefault() { + super.setDefault(); + this.temporaryValue = this.getDefaultValue().getDefaultValue(); + } + + @Override + public String getOwnerName() { + return attribute.getName(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/UnitAttr.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/UnitAttr.java new file mode 100644 index 000000000..234567663 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/properties/UnitAttr.java @@ -0,0 +1,75 @@ +package cz.zcu.fav.kiv.editor.beans.properties; + +import java.util.List; + +import cz.zcu.fav.kiv.editor.beans.types.Unit; + +/** + * The UnitAttr class represents a unit of attribute type. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class UnitAttr extends Unit { + /** The temporary value of the attribute unit */ + protected String temporaryValue; + + /** The reference to the attribute of the unit */ + protected Attribute attribute; + + /** + * Initializes a newly created UnitAttr with the specified value and predefined + * units. The value argument is the value of the unit. The unitList + * is a list of predefined units. + * + * @param value + * a value of the unit. + * @param unitList + * a list of predefined units. + */ + public UnitAttr(String value, List unitList) { + super(value, unitList); + } + + public UnitAttr(List unitList) { + super(unitList); + } + + /** + * Sets the new value of unit and marks its attribute as chosen. + * + * @param value + * a new value of the unit. + */ + public void changeValue(String value) { + this.temporaryValue = value; + this.attribute.setChosen(); + } + + /** + * Sets the new temporary value of unit. + */ + public void updateValue() { + this.temporaryValue = this.value; + } + + /** + * Sets values of the unit after its temporary value. + */ + public void setValuesFromTemporary() { + if (temporaryValue != null) + this.value = temporaryValue; + } + + public void setAttribute(Attribute attribute) { + this.attribute = attribute; + } + + /** + * Sets the default and temporary value of the unit. + */ + public void setDefault() { + super.setDefault(); + this.temporaryValue = this.defaultValue; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Group.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Group.java new file mode 100644 index 000000000..9eb907bee --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Group.java @@ -0,0 +1,62 @@ +package cz.zcu.fav.kiv.editor.beans.sections; + +import java.util.List; + +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; +import cz.zcu.fav.kiv.editor.beans.common.ParentSection; +import cz.zcu.fav.kiv.editor.beans.graphics.Figure; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.Property; + +/** + * The Group class represents a group of parameters and properties. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Group extends ParentSection { + /** The graphics figure defined for parameters in the group */ + private Figure figure; + + /** The list of parameters and properties in the group */ + private List elementList; + + /** + * Initializes a newly created Group with the specified name. The + * title argument is the title of the group. + * + * @param title + * a title of the group. + */ + public Group(String title) { + super(title); + } + + /** + * Clear values (sets default values) of all parameters and properties. + */ + public void clearValues() { + for (ParentParameter elem : this.elementList) { + if (elem instanceof Property) + ((Property) elem).clearValues(); + if (elem instanceof Parameter) + ((Parameter) elem).clearValues(); + } + } + + public List getElementList() { + return elementList; + } + + public void setElementList(List parameterList) { + this.elementList = parameterList; + } + + public Figure getFigure() { + return figure; + } + + public void setFigure(Figure figure) { + this.figure = figure; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Section.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Section.java new file mode 100644 index 000000000..c389198f8 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Section.java @@ -0,0 +1,46 @@ +package cz.zcu.fav.kiv.editor.beans.sections; + +import java.util.List; + +import cz.zcu.fav.kiv.editor.beans.common.ParentSection; + +/** + * The Section class represents a section of editor. It contains a list of + * Subsections. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Section extends ParentSection { + /** The list of subsections in the section */ + private List subsectionList; + + /** + * Initializes a newly created Section with the specified name. The + * title argument is the title of the section. + * + * @param title + * a title of the section. + */ + public Section(String title) { + super(title); + } + + public List getSubsectionList() { + return subsectionList; + } + + public void setSubsectionList(List subsectionList) { + this.subsectionList = subsectionList; + } + + /** + * Clear values (sets default values) of all subsections. + */ + public void clearValues() { + for (Subsection subsection : subsectionList) { + subsection.clearValues(); + subsection.setComment(null); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Subsection.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Subsection.java new file mode 100644 index 000000000..8860ac892 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/sections/Subsection.java @@ -0,0 +1,57 @@ +package cz.zcu.fav.kiv.editor.beans.sections; + +import java.util.List; + +import org.w3c.dom.Comment; + +import cz.zcu.fav.kiv.editor.beans.common.ParentSection; + +/** + * The Subsection class represents a subsection of a Section. It + * contains a list of Groups. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Subsection extends ParentSection { + /** The list of group in the subsection */ + private List groupList; + + /** The comment associated with the subsection */ + private Comment comment; + + /** + * Initializes a newly created Subsection with the specified name. The + * title argument is the title of the subsection. + * + * @param title + * a title of the subsection. + */ + public Subsection(String title) { + super(title); + } + + public List getGroupList() { + return groupList; + } + + public void setGroupList(List groupList) { + this.groupList = groupList; + } + + /** + * Clear values (sets default values) of all groups. + */ + public void clearValues() { + for (Group group : groupList) + group.clearValues(); + } + + public Comment getComment() { + return comment; + } + + public void setComment(Comment comment) { + this.comment = comment; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/CommonTypes.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/CommonTypes.java new file mode 100644 index 000000000..bea09c291 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/CommonTypes.java @@ -0,0 +1,33 @@ +package cz.zcu.fav.kiv.editor.beans.types; + +import java.util.List; +import java.util.Map; + +public class CommonTypes { + /** The list of unit values */ + private List units; + + /** The list of font values */ + private Map fonts; + + /** The list of color values */ + private Map colors; + + public CommonTypes(List units, Map colors, Map fonts){ + this.units = units; + this.colors = colors; + this.fonts = fonts; + } + + public Map getColors() { + return colors; + } + + public Map getFonts() { + return fonts; + } + + public List getUnits() { + return units; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/DefaultType.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/DefaultType.java new file mode 100644 index 000000000..d9eabfbea --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/DefaultType.java @@ -0,0 +1,60 @@ +package cz.zcu.fav.kiv.editor.beans.types; + +import java.util.Iterator; +import java.util.Map; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +public class DefaultType implements Cloneable { + + /** The default value of the type */ + protected String defaultValue; + + /** The list of predefined values of the type */ + protected Map valueList; + + public Object clone() { + DefaultType type = null; + try { + type = (DefaultType) super.clone(); + type.setDefaultValue(defaultValue); + type.setValueList(this.valueList); + } catch (CloneNotSupportedException ex) { + Log.error(ex); + } + return type; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + public void setValueList(Map valueList) { + this.valueList = valueList; + } + + public String getDefaultValue() { + return defaultValue; + } + + public Map getValueList() { + return valueList; + } + + /** + * Returns the key for input value it it is contained in the list of predefined values. + * + * @param value + * a value of the searched value contained in the list of predefined values. + * @return a key belonging to the input value contained in the list of predefined values. + */ + public String getKeyFromValue(String value) { + if (valueList != null) + for (Iterator it = valueList.entrySet().iterator(); it.hasNext();) { + Map.Entry e = (Map.Entry) it.next(); + if (e.getValue().equals(value)) + return e.getKey().toString(); + } + return null; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/Type.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/Type.java new file mode 100644 index 000000000..7ffbabd18 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/Type.java @@ -0,0 +1,156 @@ +package cz.zcu.fav.kiv.editor.beans.types; + +import java.util.Map; +import java.util.Observable; + +import cz.zcu.fav.kiv.editor.config.constants.TypeEnum; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.utils.TagControl; + +/** + * The Type class represents a parent for types of all elements. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public abstract class Type extends Observable implements Cloneable { + /** The name of the type */ + protected TypeEnum name; + + /** The default value of the type */ + protected DefaultType defaultValue; + + /** The value of the type */ + protected String value; + + /** The unit of the type */ + protected Unit unit; + + public void setUnit(Unit unit) { + this.unit = unit; + } + + /** + * Initializes a newly created emptyType. + */ + public Type() { + defaultValue = new DefaultType(); + } + + public Type(TypeEnum name) { + this.name = name; + defaultValue = new DefaultType(); + } + + public void setDefaultValue(DefaultType defaultValue) { + this.defaultValue = defaultValue; + } + + public void setName(TypeEnum name) { + this.name = name; + } + + public String getValue() { + return value; + } + + /** + * Sets the new value of the type with notifying of graphics items. + */ + public abstract void updateValue(); + + + /** + * Sets the new value of the type without notifying of graphics items. + * @param value a new value of the type. + */ + public abstract void changeValue(String value); + + public Map getValueList() { + return defaultValue.getValueList(); + } + + public void setValueList(Map values) { + this.defaultValue.setValueList(values); + } + + /** + * Returns the key for input value it it is contained in the list of predefined values. + * + * @param value + * a value of the searched value contained in the list of predefined values. + * @return a key belonging to the input value contained in the list of predefined values. + */ + public String getKeyFromValue(String value) { + return defaultValue.getKeyFromValue(value); + } + + public Object clone() { + Type type = null; + try { + type = (Type) super.clone(); + type.setName(this.name); + type.setDefaultValue((DefaultType)this.defaultValue.clone()); + type.setValue(this.value); + if (this.unit != null) + type.setUnit((Unit) this.unit.clone()); + } catch (CloneNotSupportedException ex) { + Log.error(ex); + } + return type; + } + + /** + * Sets the default value of the type and its unit. + */ + public void setDefault() { + this.value = this.defaultValue.getDefaultValue(); + if (this.unit != null) + this.unit.setDefault(); + } + + public Unit getUnit() { + return unit; + } + + public DefaultType getDefaultValue() { + return defaultValue; + } + + public TypeEnum getName() { + return name; + } + + /** + * Assigns the new loaded value (from file, template). + * @param value the new type value. + * @throws ParserException if the value is invalid. + */ + public void setLoadedValue(String value) throws ParserException { + TagControl.controlSetTypeValue(this, value); + updateValue(); + } + + public void setValue(String value) { + this.value = value; + } + + /** + * Assigns the default value same as value. + * + */ + public void assignDefaultFromValue() { + this.defaultValue.defaultValue = value; + if (this.unit != null) + this.unit.assignDefaultFromValue(); + } + + /** + * Return the name of the owner element - parameter or attribute. + * + */ + public abstract String getOwnerName(); +} + + diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/Unit.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/Unit.java new file mode 100644 index 000000000..0c4b54099 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/beans/types/Unit.java @@ -0,0 +1,100 @@ +package cz.zcu.fav.kiv.editor.beans.types; + +import java.util.List; +import java.util.Observable; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The Unit class represents a parent for unit of elements. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public abstract class Unit extends Observable implements Cloneable { + /** The value of the unit */ + protected String value; + + /** The default value of the unit */ + protected String defaultValue; + + /** The list of predefined values of the unit */ + protected List valueList; + + /** + * Initializes a newly created Unit with the specified value and predefined + * units. The value argument is the value of the unit. The unitList + * is a list of predefined units. + * + * @param value + * a value of the unit. + * @param unitList + * a list of predefined units. + */ + public Unit(String value, List unitList) { + this.value = value; + this.defaultValue = value; + this.valueList = unitList; + } + + public Unit(List unitList) { + this.valueList = unitList; + this.value = ""; + this.defaultValue = ""; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + /** + * Sets the default value of the unit - assignes the default value to the main value. + */ + public void setDefault() { + this.value = defaultValue; + } + + public String getValue() { + return value; + } + + public abstract void updateValue(); + + public abstract void changeValue(String value); + + public Object clone() { + Unit unit = null; + try { + unit = (Unit) super.clone(); + unit.setValue(this.value); + unit.setDefaultValue(this.defaultValue); + } catch (CloneNotSupportedException ex) { + Log.error(ex); + } + return unit; + } + + /** + * Assigns the default value from value. + */ + public void assignDefaultFromValue() { + this.defaultValue = this.value; + } + + public List getValueList() { + return valueList; + } + + public void setValueList(List values) { + this.valueList = values; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ConfigController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ConfigController.java new file mode 100644 index 000000000..8d84b4845 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ConfigController.java @@ -0,0 +1,119 @@ +package cz.zcu.fav.kiv.editor.config; + +import java.io.File; +import java.util.Map; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.graphics.Figure; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.AttributeGroup; +import cz.zcu.fav.kiv.editor.beans.types.CommonTypes; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ConfigException; +import cz.zcu.fav.kiv.editor.controller.errors.FileNotFoundException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The ConfigController class contains methods for reading configuration files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ConfigController { + /** The data loaded from configuration files */ + private static ConfigData data; + + private static CommonTypes commonTypes; + + /** The parser of configuration files */ + private ConfigParser parser; + + /** The list of attribute groups */ + private AttributeGroup[] attributeGroupList; + + /** The list of graphics figures - keys are figure names */ + private Map figureList; + + /** + * Initializes a newly created ConfigController. Simultaneously initializes new + * ConfigParser and ConfigData. + */ + public ConfigController() { + data = new ConfigData(); + MessageWriter.writeTitle(ResourceController.getMessage("parser.config_file.title")); + File directory = new File(OptionItems.XML_DEFINITION_PATH); + if (!directory.exists()) + MessageWriter.writeError(ResourceController + .getMessage("parser.xml_definition_file.invalid_directory")); + + parser = new ConfigParser(); + } + + /** + * Reads the configuration file with graphics figures - graphics.xml. + * + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + */ + public void readFigures(Map parsedParameterList) throws FileNotFoundException, ConfigException { + if (!figureList.isEmpty()) + parser.readFigures(parsedParameterList, figureList); + Log.info("info.progress_control.load_file", FileConst.CONF_FILE_FIGURES); + } + + /** + * Reads the configuration file with attributes - attributes.xml. + * + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + */ + public void readAttributes() throws ConfigException, FileNotFoundException { + this.attributeGroupList = parser.readAttributes(commonTypes); + Log.info("info.progress_control.load_file", FileConst.CONF_FILE_ATTRIBUTES); + } + + /** + * Reads the configuration file with layout of parameters and attribute-sets - config.xml. + * + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + */ + public void readConfig() throws ConfigException, FileNotFoundException { + figureList = parser.readConfig(data, attributeGroupList); + Log.info("info.progress_control.load_file", FileConst.CONF_FILE_CONFIG); + } + + /** + * Reads the configuration file with types - types.xml. + * + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + */ + public void readTypes() throws ConfigException, FileNotFoundException { + commonTypes = parser.readTypes(); + Log.info("info.progress_control.load_file", FileConst.CONF_FILE_TYPE); + } + + public ConfigData getData() { + return data; + } + + public CommonTypes getCommonTypes() { + return commonTypes; + } + + public Map getFigureList() { + return figureList; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ConfigParser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ConfigParser.java new file mode 100644 index 000000000..f49aad256 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ConfigParser.java @@ -0,0 +1,190 @@ +package cz.zcu.fav.kiv.editor.config; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.graphics.Figure; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.AttributeGroup; +import cz.zcu.fav.kiv.editor.beans.types.CommonTypes; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.handlers.AttributeXmlHandler; +import cz.zcu.fav.kiv.editor.config.handlers.ConfigXmlHandler; +import cz.zcu.fav.kiv.editor.config.handlers.FigureXmlHandler; +import cz.zcu.fav.kiv.editor.config.handlers.TypeXmlHandler; +import cz.zcu.fav.kiv.editor.controller.errors.ConfigException; +import cz.zcu.fav.kiv.editor.controller.errors.FileNotFoundException; +import cz.zcu.fav.kiv.editor.controller.errors.XslParserException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The ConfigParser class contains methods for parsing configuration files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ConfigParser { + + /** The parser key defining XML schema language */ + private static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; + + /** The constants defining XML schema language */ + private static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; + + /** The key defining XML schema */ + private static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; + + /** The XML parser used for reading configuration files */ + private XMLReader parser; + + /** + * Initializes a newly created ConfigParser. Sets up the SAX parser used for + * parsing. + */ + public ConfigParser() { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(true); + spf.setNamespaceAware(true); + + try { + SAXParser sp = spf.newSAXParser(); + sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); + parser = sp.getXMLReader(); + parser.setErrorHandler(new XslParserException()); + } catch (Exception ex) { + Log.error(ex); + } + } + + /** + * Parses the configuration file with graphics figures - graphics.xml. + * + * @param parameterList + * the list of loaded parameters. + * @param figureList + * the list of loaded figures. + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + */ + public void readFigures(Map parameterList, Map figureList) + throws ConfigException, FileNotFoundException { + InputStream xsdFile = ConfigParser.class + .getResourceAsStream(FileConst.CONF_FILE_FIGURES_XSD); + if (xsdFile == null) + throw new FileNotFoundException(FileConst.CONF_FILE_FIGURES_XSD); + + FigureXmlHandler handler = new FigureXmlHandler(parameterList, figureList); + parser.setContentHandler(handler); + try { + parser.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); + parser.parse(FileConst.CONF_FILE_FIGURES); + } catch (IOException ex) { + throw new FileNotFoundException(FileConst.CONF_FILE_FIGURES); + } catch (SAXException ex) { + throw new ConfigException(FileConst.CONF_FILE_FIGURES, ex.getMessage()); + } + } + + /** + * Parses the configuration file with attributes - attributes.xml. + * + * @param commonTypes + * common types of parameters. + * @return a list of loaded attributes - key is attribute name. + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + */ + public AttributeGroup[] readAttributes(CommonTypes commonTypes) throws ConfigException, + FileNotFoundException { + InputStream xsdFile = ConfigParser.class + .getResourceAsStream(FileConst.CONF_FILE_ATTRIBUTES_XSD); + if (xsdFile == null) + throw new FileNotFoundException(FileConst.CONF_FILE_ATTRIBUTES_XSD); + + AttributeXmlHandler handler = new AttributeXmlHandler(commonTypes); + parser.setContentHandler(handler); + try { + parser.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); + parser.parse(FileConst.CONF_FILE_ATTRIBUTES); + return handler.getAttrGroupList(); + } catch (IOException ex) { + throw new FileNotFoundException(FileConst.CONF_FILE_ATTRIBUTES); + } catch (SAXException ex) { + throw new ConfigException(FileConst.CONF_FILE_ATTRIBUTES, ex.getMessage()); + } + } + + /** + * Parses the configuration file with layout of parameters and attribute-sets - config.xml. + * + * @param configData + * so far loaded data from configuration files. + * @param attributeGroupList + * the list of attribute groups. + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + */ + public Map readConfig(ConfigData configData, AttributeGroup[] attributeGroupList) + throws ConfigException, FileNotFoundException { + InputStream xsdFile = ConfigParser.class + .getResourceAsStream(FileConst.CONF_FILE_CONFIG_XSD); + if (xsdFile == null) + throw new FileNotFoundException(FileConst.CONF_FILE_CONFIG_XSD); + + ConfigXmlHandler handler = new ConfigXmlHandler(attributeGroupList); + parser.setContentHandler(handler); + try { + parser.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); + parser.parse(FileConst.CONF_FILE_CONFIG); + configData.setSectionList(handler.getSections()); + configData.setPropertyList(handler.getPropertyList()); + configData.setParameterList(handler.getParameterList()); + return handler.getFigureList(); + } catch (IOException ex) { + throw new FileNotFoundException(FileConst.CONF_FILE_CONFIG); + } catch (SAXException ex) { + throw new ConfigException(FileConst.CONF_FILE_CONFIG, ex.getMessage()); + } + } + + /** + * Parses the configuration file with types - types.xml. + * + * @throws ConfigException + * if the configuration file or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the configuration file or its XML schema doesn't exist. + */ + public CommonTypes readTypes() throws ConfigException, FileNotFoundException { + InputStream xsdFile = ConfigParser.class.getResourceAsStream(FileConst.CONF_FILE_TYPE_XSD); + if (xsdFile == null) + throw new FileNotFoundException(FileConst.CONF_FILE_TYPE_XSD); + + TypeXmlHandler handler = new TypeXmlHandler(); + parser.setContentHandler(handler); + try { + parser.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); + + parser.parse(FileConst.CONF_FILE_TYPE); + return new CommonTypes(handler.getUnitList(), handler.getColorList(), handler.getFontList()); + } catch (IOException ex) { + throw new FileNotFoundException(FileConst.CONF_FILE_TYPE); + } catch (SAXException ex) { + throw new ConfigException(FileConst.CONF_FILE_TYPE, ex.getMessage()); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParamController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParamController.java new file mode 100644 index 000000000..1fe5314cc --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParamController.java @@ -0,0 +1,124 @@ +package cz.zcu.fav.kiv.editor.config; + +import java.io.File; +import java.util.Iterator; +import java.util.Map; +import java.util.regex.Pattern; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; +import cz.zcu.fav.kiv.editor.beans.graphics.Figure; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.beans.sections.Group; +import cz.zcu.fav.kiv.editor.beans.sections.Section; +import cz.zcu.fav.kiv.editor.beans.sections.Subsection; +import cz.zcu.fav.kiv.editor.beans.types.CommonTypes; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; + +/** + * The ParamController class contains method for reading XML definitions of + * parameters and properties. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParamController { + /** The model pattern used for parsing $param */ + public static final String REGEX_PARAM = "\\$[\\w\\.]+"; + + /** The model pattern used for parsing $param */ + public static Pattern patternParam = Pattern.compile(REGEX_PARAM); + + /** The parser of XML parameter definitions */ + private ParameterParser parameterParserXML = null; + + /** The parser of XML property definitions */ + private PropertyParser propertyParserXML = null; + + /** The data loaded from configuration files */ + private ConfigData configData; + + /** + * Initializes a newly created ParamController. Simultaneously initializes new + * ParameterParser and PropertyParser. + */ + public ParamController(ConfigData configData, CommonTypes types) { + parameterParserXML = new ParameterParser(types); + propertyParserXML = new PropertyParser(); + this.configData = configData; + } + + /** + * Reads XML files for all parameters. Processes the complex paramater values that depends on + * other parameter values. + */ + public void readParameters() { + File directory = new File(OptionItems.XML_DEFINITION_PATH); + if (directory.exists()) { + parameterParserXML.readParameterDefinition(configData.getParameterList()); + parameterParserXML.processParameterDependency(); + } + + Log.info("info.progress_control.load_parameter_description"); + } + + /** + * Reads XML files for all properties. Processes the complex attribute values that depends on + * other parameter values. + */ + public void readProperties() { + File directory = new File(OptionItems.XML_DEFINITION_PATH); + if (directory.exists()) { + propertyParserXML.readPropertyDefinition(configData.getPropertyList()); + propertyParserXML.processPropertyDependency(); + } + Log.info("info.progress_control.load_property_description"); + } + + /** + * Removes all parameters and properties that couldn't be parsed. + * + * @param figureList + * the list with graphics figures. + */ + public void removeInvalidParam(Map figureList) { + for (Section section : configData.getSectionList()) { + Iterator subsectionIter = section.getSubsectionList().iterator(); + while (subsectionIter.hasNext()) { + Subsection subsection = subsectionIter.next(); + Iterator groupIter = subsection.getGroupList().iterator(); + while (groupIter.hasNext()) { + Group group = groupIter.next(); + // parameters and properties + Iterator elementIter = group.getElementList().iterator(); + while (elementIter.hasNext()) { + ParentParameter element = elementIter.next(); + if (element instanceof Parameter) { + if (!parameterParserXML.getParsedParameterList().containsKey( + element.getName())) + elementIter.remove(); + } + if (element instanceof Property) { + if (!propertyParserXML.getParsedPropertyList().containsKey( + element.getName())) + elementIter.remove(); + } + } + // figures - remove invalid figures + if (group.getFigure() != null) { + if (!figureList.containsKey(group.getFigure().getName())) + group.setFigure(null); + } + if (group.getElementList().size() == 0) + groupIter.remove(); + } + } + } + } + + public Map getParsedParameterList() { + return parameterParserXML.getParsedParameterList(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterDependencyParser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterDependencyParser.java new file mode 100644 index 000000000..0069a0f77 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterDependencyParser.java @@ -0,0 +1,311 @@ +package cz.zcu.fav.kiv.editor.config; + +import java.text.DecimalFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.utils.TagControl; + +/** + * The ParameterDependencyParser class contains methods for parsing parameter complex + * values that contains references to other parameter values. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParameterDependencyParser { + /** The sign asterisk */ + private static final String SIGN_ASTERISK = "*"; + + /** The sign plus left */ + private static final String SIGN_PLUS_LEFT = "+L"; + + /** The sign plus right */ + private static final String SIGN_PLUS_RIGHT = "+R"; + + /** The sign equal */ + private static final String SIGN_EQUAL = "="; + + /** The sign not equal */ + private static final String SIGN_NOT_EQUAL = "!="; + + /** The name contains */ + private static final String CONTAINS = "contains"; + + /** The format for formating double numbers */ + private static final DecimalFormat formatDouble = new DecimalFormat("0.##"); + + /** The parser of XML parameter definitions */ + private ParameterParser paramParser; + + /** The actually parsed parameter */ + private Parameter parameter; + + /** The flag indicating if the parameter value is valid */ + private boolean valid; + + /** + * Initializes a newly created ParameterDependencyParser. + * + * @param parser + * the parser of XML parameter definitions. + */ + public ParameterDependencyParser(ParameterParser parser) { + this.paramParser = parser; + } + + /** + * Parses the complex value of the parameter. + * + * @param parameter + * the parsed parameter. + * @return true if the parameter value is successfully parsed. + */ + public boolean parseParameterDependency(Parameter parameter) { + this.parameter = parameter; + valid = false; + + processXslChoose(parameter.getType().getValue()); + + if (!valid) + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.parameters.invalid_value", FileConst.CONF_FILE_CONFIG, parameter + .getName(), parameter.getLineNumber())); + return valid; + } + + /** + * Parses simple complex value. + * + * @param simpleValue + * the complex parameter value. + */ + private void parseSimpleValue(String simpleValue) { + parseSimpleValue(simpleValue, ""); + } + + /** + * Parses simple complex value. + * + * @param complexValue + * the complex parameter value. + * @param secondAddValue + * the string creating the end of parameter value. + */ + private void parseSimpleValue(String complexValue, String secondAddValue) { + // $param * number + if (complexValue.matches("\\$[\\w\\.]+\\s*\\*\\s*[\\d\\.]+")) { + String[] valueParts = complexValue.split("\\*"); + evaluateSimpleValue(valueParts[0], valueParts[1], SIGN_ASTERISK, secondAddValue); + return; + } + // number * $param + if (complexValue.matches("\\d+\\s*\\*\\s*\\$[\\w\\.]+")) { + String[] valueParts = complexValue.split("\\*"); + evaluateSimpleValue(valueParts[1], valueParts[0], SIGN_ASTERISK, secondAddValue); + return; + } + // $param + if (complexValue.matches("\\$[\\w\\.]+")) { + evaluateSimpleValue(complexValue, null, null, secondAddValue); + return; + } + + // concat('..', $param) + if (complexValue.matches("concat\\('\\w+',\\s*\\$[\\w\\.]+\\)")) { + String[] valueParts = complexValue.split("[(,)]"); + evaluateSimpleValue(valueParts[2].trim(), valueParts[1].replaceAll("'", ""), + SIGN_PLUS_LEFT, secondAddValue); + return; + } + // concat($param, '..') + if (complexValue.matches("concat\\(\\$[\\w\\.]+,\\s*'\\w+'\\)")) { + String[] valueParts = complexValue.split("[(,)]"); + evaluateSimpleValue(valueParts[1].trim(), valueParts[2].replaceAll("'", ""), + SIGN_PLUS_RIGHT, secondAddValue); + return; + } + setParameterValue(complexValue); + } + + /** + * Parsed the structure .... + * + * @param complexValue + * the complex parameter value. + */ + private void processXslValueOf(String complexValue) { + String lineValue = complexValue.replaceAll("\n", "").trim(); + if (lineValue + .matches("(.+?)?")) { + Pattern patternXslValueOf = Pattern + .compile("((.+?))?"); + Matcher matcherXslValueOf = patternXslValueOf.matcher(complexValue); + if (matcherXslValueOf.find()) { + parseSimpleValue(matcherXslValueOf.group(1), + ((matcherXslValueOf.group(3) != null) ? matcherXslValueOf.group(3) : "")); + } + return; + } + parseSimpleValue(complexValue); + } + + /** + * Parsed the structure .... + * + * @param complexValue + * the complex parameter value. + */ + private void processXslChoose(String complexValue) { + String lineValue = complexValue.replaceAll("\n", ""); + if (lineValue.matches(".*")) { + Pattern patternWhen = Pattern.compile("(.+?)"); + Matcher matcherWhen = patternWhen.matcher(lineValue); + boolean testResult = false; + while (matcherWhen.find()) { + testResult = parseXslWhenTest(matcherWhen.group(1)); + if (testResult) { + processXslValueOf(matcherWhen.group(2)); + break; + } + } + if (!testResult) { + Pattern patternOtherwise = Pattern.compile("(.*)"); + Matcher matcherOtherwise = patternOtherwise.matcher(lineValue); + while (matcherOtherwise.find()) { + processXslValueOf(matcherOtherwise.group(1)); + } + } + return; + } + processXslValueOf(complexValue); + } + + /** + * Parses the condition test of the structure . + * + * @param testAttribute + * the content of attribute test. + * @return true if the condition in the test attribute is true. + */ + private boolean parseXslWhenTest(String testAttribute) { + // $param = 'value' or $param != 'value' + if (testAttribute.startsWith("$")) { + // control pattern: $param = 'value' or $param = value + Pattern pattern = Pattern.compile("\\$(.+?) ?(!?=) ?('?.++'?)"); + Matcher matcher = pattern.matcher(testAttribute); + if (matcher.find()) { + return evaluateXslWhenTest(matcher.group(1), matcher.group(2), matcher.group(3) + .replaceAll("'", "")); + } + } + + // contains($param, 'value') + if (testAttribute.startsWith(TagDefinition.ParameterTags.CONTAINS)) { + Pattern pattern = Pattern.compile("contains\\(\\$(\\$.+?), *('?.+?'?)\\)"); + Matcher matcher = pattern.matcher(testAttribute); + if (matcher.find()) { + return evaluateXslWhenTest(matcher.group(1), CONTAINS, matcher.group(2).replaceAll( + "'", "")); + } + } + return false; + } + + /** + * Evaluate the condition in the test attribute. + * + * @param param + * the name of parameter. + * @param sign + * the sign of the condition. + * @param value + * the value of the parameter. + * @return true if the condition is true. + */ + private boolean evaluateXslWhenTest(String param, String sign, String value) { + Parameter testParam = paramParser.getParsedParameterList().get(param); + if (sign.equals(SIGN_NOT_EQUAL)) { + return !testParam.getType().getValue().equals(value); + } + if (sign.equals(SIGN_EQUAL)) { + return testParam.getType().getValue().equals(value); + } + if (sign.equals(CONTAINS)) { + return testParam.getType().getValue().contains(value); + } + return false; + } + + /** + * Evaluates the content of the simple complex value and assigns the new value to the parameter. + * + * @param param + * the parameter on which the parameter is dependent. + * @param addValue + * the value added to the parameter value. + * @param sign + * the sign used for adding the value to the parameter value. + * @param secondAddValue + * the second value added to the parameter value. + */ + private void evaluateSimpleValue(String param, String addValue, String sign, + String secondAddValue) { + // parameter name without $ + String paramName = param.trim().substring(1); + // control parameter + Parameter par = paramParser.getParsedParameterList().get(paramName); + if (par == null) { + return; + } + String endValue = secondAddValue + + ((par.getType().getUnit() != null) ? par.getType().getUnit().getValue() : ""); + // only param value + if ((addValue == null) && (sign == null)) { + setParameterValue(par.getType().getValue() + endValue); + return; + } + + // * -> addValue must be number + if (sign.equals(SIGN_ASTERISK)) { + try { + Double result = Double.valueOf(addValue.trim()) + * Double.valueOf(par.getType().getValue()); + setParameterValue(formatDouble.format(result) + endValue); + } catch (NumberFormatException ex) { + } + return; + } + + // + -> addValue is string + if (sign.equals(SIGN_PLUS_LEFT)) { + setParameterValue(addValue + par.getType().getValue() + endValue); + } + if (sign.equals(SIGN_PLUS_RIGHT)) { + setParameterValue(par.getType().getValue() + addValue + endValue); + } + } + + /** + * Sets the new value to the parameter. + * + * @param newValue + * the new parameter value. + */ + private void setParameterValue(String newValue) { + try { + TagControl.controlSetTypeValue(parameter.getType(), newValue); + parameter.getType().assignDefaultFromValue(); + valid = true; + } catch (ParserException ex) { + valid = false; + } + + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterParser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterParser.java new file mode 100644 index 000000000..98a27b54d --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterParser.java @@ -0,0 +1,199 @@ +package cz.zcu.fav.kiv.editor.config; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.types.CommonTypes; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.handlers.ParameterXmlHandler; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.ProgressControl; +import cz.zcu.fav.kiv.editor.controller.errors.XslParserException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The ParameterParser class contains methods for parsing files with XML definitions + * of parameters. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParameterParser { + + /** The max number of dependency nesting - to avoid cycle dependency **/ + private static final int LIMIT_LOOP = 5; + + /** The XML parser used for reading XML files */ + private XMLReader parser; + + /** The list of parsed parameters */ + private Map parsedParameterList; + + /** The list of unparsed parameters */ + private Map unparsedParameterList; + + /** The list of invalid parameters */ + private List invalidParameterList; + + /** The list of common types */ + private static CommonTypes commonTypes; + + /** The parser used for parsing parameter value dependencies */ + private ParameterDependencyParser paramDependencyParser; + + /** + * Initializes a newly created ParameterParser. Sets up the SAX parser used for + * parsing. + */ + public ParameterParser(CommonTypes types) { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(false); + + SAXParser saxParser = spf.newSAXParser(); + parser = saxParser.getXMLReader(); + parser.setErrorHandler(new XslParserException()); + + commonTypes = types; + + unparsedParameterList = new HashMap(); + parsedParameterList = new HashMap(); + invalidParameterList = new ArrayList(); + } catch (Exception ex) { + Log.error(ex); + } + } + + /** + * In sequence parses for every parameter its XML definition file. + * + * @param parameterList + * the list of parameter names loaded from the main configuration file. + */ + public void readParameterDefinition(Map parameterList) { + Iterator> iter = parameterList.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry param = iter.next(); + //inform about file loading + ProgressControl.addStatMessage(ResourceController.getMessage("frame.intro.progress.read_file", OptionItems.XML_DEFINITION_PATH + File.separator + param.getValue().getName()+".xml")); + parseParameter(param.getValue()); + } + } + + /** + * For input parameter parses its XML definition file. + * + * @param element + * the parameter which XML file is parsed. + */ + private void parseParameter(Parameter element) { + try { + ParameterXmlHandler handler = new ParameterXmlHandler(element, commonTypes); + parser.setContentHandler(handler); + parser.parse(OptionItems.XML_DEFINITION_PATH + File.separator + element.getName() + + ".xml"); + if (!handler.isValid()) { + invalidParameterList.add(element.getName()); + } else { + if (handler.isParsed()) + parsedParameterList.put(element.getName(), element); + else + unparsedParameterList.put(element.getName(), element); + } + } catch (IOException ex) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.xml_definition_file.missing_file", element.getName(), + OptionItems.XML_DEFINITION_PATH)); + invalidParameterList.add(element.getName()); + } catch (SAXException ex) { + Log.warn("error.param_parser.parser_error", ex); + invalidParameterList.add(element.getName()); + } + } + + /** + * Process values of parameters from unparsedParameterList. + */ + public void processParameterDependency() { + paramDependencyParser = new ParameterDependencyParser(this); + Map innerUnparsedParameterList = null; + StringBuilder message = new StringBuilder(); + int limitLoop = 0; + while(!unparsedParameterList.isEmpty()) { + innerUnparsedParameterList = unparsedParameterList; + unparsedParameterList = new HashMap(); + Iterator it = innerUnparsedParameterList.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry param = (Map.Entry)it.next(); + if (limitLoop == LIMIT_LOOP) { + message.append(param.getKey() + ","); + } else { + //parse + parseParameterValue((Parameter)param.getValue(), innerUnparsedParameterList); + } + } + //to avoid cycle dependency + if (limitLoop == LIMIT_LOOP) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.parameters.dependency_cycle", FileConst.CONF_FILE_CONFIG, message)); + break; + } + limitLoop++; + } + } + + public Map getParsedParameterList() { + return parsedParameterList; + } + + /** + * Parses parameter value that contains references to others parameters. + * @param param the parsed parameter. + * @param innerUnparsedParameterList the list of unparsed parameters. + */ + private void parseParameterValue(Parameter param, Map innerUnparsedParameterList) { + Matcher matcher = ParamController.patternParam.matcher(param.getType().getValue()); + boolean canBeParsed = true; + while(matcher.find()) { + String paramName = matcher.group().substring(1); + if (invalidParameterList.contains(paramName)) { + //parameter is invalid -> the depending parameter is invalid + invalidParameterList.add(param.getName()); + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.parameters.invalid_value", FileConst.CONF_FILE_CONFIG, param + .getName(), param.getLineNumber())); + return; + } + if (!parsedParameterList.containsKey(paramName)) { + //param is not yet parsed + if (!innerUnparsedParameterList.containsKey(paramName)) + parseParameter(new Parameter(paramName)); + canBeParsed = false; + } + } + if (!canBeParsed) { + unparsedParameterList.put(param.getName(), param); + } else { + //parse parameter value + if (paramDependencyParser.parseParameterDependency(param)) + parsedParameterList.put(param.getName(), param); + else + invalidParameterList.add(param.getName()); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterTransformation.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterTransformation.java new file mode 100644 index 000000000..8aa5df415 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/ParameterTransformation.java @@ -0,0 +1,43 @@ +package cz.zcu.fav.kiv.editor.config; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.StringReader; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +public class ParameterTransformation { + /** + * Transform text description in DocBook to HTML format. + * + * @param input + * the text in DocBook. + * @return the input text transformed to HTML. + */ + public static String htmlTransform(String input) { + try { + InputStream convertFile = ConfigParser.class + .getResourceAsStream(FileConst.CONF_FILE_CONVERT); + + TransformerFactory trf = TransformerFactory.newInstance(); + Transformer transformer = trf.newTransformer(new StreamSource(convertFile)); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + String tempStr = new String(input.getBytes(), "windows-1250"); + transformer.transform(new StreamSource(new StringReader(tempStr)), + new StreamResult(out)); + + return out.toString(); + } catch (Throwable ex) { + Log.warn("error.param_parser.transformation_error", ex); + } + return null; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/PropertyParser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/PropertyParser.java new file mode 100644 index 000000000..a84f97665 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/PropertyParser.java @@ -0,0 +1,120 @@ +package cz.zcu.fav.kiv.editor.config; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.config.handlers.PropertyXmlHandler; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.ProgressControl; +import cz.zcu.fav.kiv.editor.controller.errors.XslParserException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The PropertyParser class contains methods for parsing files with XML definitions + * of properties. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class PropertyParser { + /** The XML parser used for reading XML files */ + private XMLReader parser; + + /** The list of parsed properties */ + private Map parsedPropertyList; + + /** The list of unparsed attributes */ + private Map unparsedAttributeList; + + /** + * Initializes a newly created PropertyParser. Sets up the SAX parser used for + * parsing. + */ + public PropertyParser() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(false); + + SAXParser saxParser = spf.newSAXParser(); + parser = saxParser.getXMLReader(); + parser.setErrorHandler(new XslParserException()); + + unparsedAttributeList = new HashMap(); + parsedPropertyList = new HashMap(); + } catch (Exception ex) { + Log.error(ex); + } + } + + /** + * In sequence parses for every property its XML definition file. + * + * @param propertyList + * the list of property names loaded from the main configuration file. + */ + public void readPropertyDefinition(Map propertyList) { + Iterator> iter = propertyList.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry prop = iter.next(); + ProgressControl.addStatMessage(ResourceController.getMessage("frame.intro.progress.read_file", OptionItems.XML_DEFINITION_PATH + File.separator + prop.getValue().getName()+".xml")); + parseProperty(prop.getValue()); + } + } + + /** + * For input property parses its XML definition file. + * + * @param element + * the property which XML file is parsed. + */ + private void parseProperty(Property element) { + try { + PropertyXmlHandler handler = new PropertyXmlHandler(element); + parser.setContentHandler(handler); + parser.parse(OptionItems.XML_DEFINITION_PATH + File.separator + element.getName() + + ".xml"); + if (handler.isValid()) { + parsedPropertyList.put(element.getName(), element); + } + //unparsed attributes + if (handler.getUnparsedAttributeList().size() > 0) + unparsedAttributeList.putAll(handler.getUnparsedAttributeList()); + } catch (IOException ex) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.xml_definition_file.missing_file", element.getName(), + OptionItems.XML_DEFINITION_PATH)); + } catch (SAXException ex) { + Log.warn("error.param_parser.parser_error", ex); + } + } + + /** + * Process values of parameters from unparsedAttributeList. + */ + public void processPropertyDependency() { +//TODO parse complicated dependent attribute values +// Iterator it = unparsedAttributeList.entrySet().iterator(); +// while (it.hasNext()) { +// Map.Entry pairs = (Map.Entry)it.next(); +// pairs.getKey() (Attribute)pairs.getValue() +// } + } + + public Map getParsedPropertyList() { + return parsedPropertyList; + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/FileConst.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/FileConst.java new file mode 100644 index 000000000..213153ebd --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/FileConst.java @@ -0,0 +1,46 @@ +package cz.zcu.fav.kiv.editor.config.constants; + +import java.io.File; + +/** + * The FileConst class contains paths and names of configuration files and their XSL + * schemas. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class FileConst { + + /** The directory where configuration files are stored */ + public static final String CONF_FILE_XML_DIR = "configuration" + File.separator; + + /** The directory where XML schemas of configuration files are stored */ + public static final String CONF_FILE_XSD_DIR = '\u002f' + "schemas" + '\u002f'; + + /** The configuration file describing layout of parameters and attribute-sets */ + public static final String CONF_FILE_CONFIG = CONF_FILE_XML_DIR + "config.xml"; + + /** The XML schema of the configuration file describing layout of parameters and attribute-sets */ + public static final String CONF_FILE_CONFIG_XSD = CONF_FILE_XSD_DIR + "config.xsd"; + + /** The configuration file describing attributes */ + public static final String CONF_FILE_ATTRIBUTES = CONF_FILE_XML_DIR + "attributes.xml"; + + /** The XML schema of the configuration file describing attributes */ + public static final String CONF_FILE_ATTRIBUTES_XSD = CONF_FILE_XSD_DIR + "attributes.xsd"; + + /** The configuration file describing types */ + public static final String CONF_FILE_TYPE = CONF_FILE_XML_DIR + "types.xml"; + + /** The XML schema of the configuration file describing types */ + public static final String CONF_FILE_TYPE_XSD = CONF_FILE_XSD_DIR + "types.xsd"; + + /** The configuration file describing graphics figures */ + public static final String CONF_FILE_FIGURES = CONF_FILE_XML_DIR + "graphics.xml"; + + /** The XML schema of the configuration file describing graphics figures */ + public static final String CONF_FILE_FIGURES_XSD = CONF_FILE_XSD_DIR + "graphics.xsd"; + + /** The XSL file used for converting text in DocBook to HTML format */ + public static final String CONF_FILE_CONVERT = CONF_FILE_XSD_DIR + "convert.xsl"; +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/TagDefinition.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/TagDefinition.java new file mode 100644 index 000000000..745b286fc --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/TagDefinition.java @@ -0,0 +1,177 @@ +package cz.zcu.fav.kiv.editor.config.constants; + +/** + * The TagDefinition class contains enumarated lists of elements used in + * configuration files and XML parameter definition files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TagDefinition { + /** The size of buffer used for reading element contents */ + public static int BUFFER_SIZE = 300; + + /** The size of buffer used for reading contents of elements with descriptions */ + public static int BUFFER_SIZE_DESCRIPTION = 500; + + /** + * The enumerated list of elements used in the configuration file with layout of parameters and + * attribute-sets - config.xml. + */ + public static enum ConfigTags { + SECTION("section"), SUBSECTION("subsection"), GROUP("group"), PARAMETER("parameter"), ATTRIBUTE_SET("attribute-set"), NULL(""); + + private String value; + + ConfigTags(String value) { + this.value = value; + } + + /** + * Returns predefined constant of element according to the element name. + * + * @param key + * the name of element. + * @return a constant of element with defined name. + */ + public static ConfigTags getValue(String key) { + for (ConfigTags conf : values()) { + if (conf.value.equals(key)) + return conf; + } + return NULL; + } + } + + /** + * The enumerated list of elements used in the configuration file with attributes - + * attributes.xml. + */ + public static enum AttributeTags { + GROUP("group"), ATTRIBUTE("attribute"), NAME("name"), TYPE("type"), VALUES("values"), + COMPONENT("component"), DEFAULT("default"), UNIT("unit"), NULL(""); + private String value; + + AttributeTags(String value) { + this.value = value; + } + + /** + * Returns predefined constant of element according to the element name. + * + * @param key + * the name of element. + * @return a constant of element with defined name. + */ + public static AttributeTags getValue(String key) { + for (AttributeTags attr : values()) { + if (attr.value.equals(key)) + return attr; + } + return NULL; + } + + public String toString() { + return this.name().toLowerCase(); + } + } + + /** + * The enumerated list of elements used in files with XML parameter definitions. + */ + public static enum ParameterTags { + REFSECTION("refsection"), REFPURPOSE("refpurpose"), REFMISCINFO("refmiscinfo"), REFMETA("refmeta"), + DATATYPE("datatype"), VALUE("value"), ALT("alt"), LIST_TYPE("list-type"), NULL(""), XSL_PARAM("xsl:param"), + XSL_ATTRIBUTE("xsl:attribute"); + + //type + public static final String OPEN = "open"; + public static final String OTHERCLASS = "otherclass"; + public static final String FO = "fo"; + + //value + public static final String CONDITION = "condition"; + public static final String SELECT = "select"; + public static final String TEST = "test"; + public static final String CONTAINS = "contains"; + public static final String NAME = "name"; + + private String value; + ParameterTags(String value) { + this.value = value; + } + /** + * Returns predefined constant of element according to the element name. + * + * @param key + * the name of element. + * @return a constant of element with defined name. + */ + public static ParameterTags getEnumValue(String key) { + for (ParameterTags param : values()) { + if (param.value.equals(key)) + return param; + } + return NULL; + } + + public String toString() { + return this.value; + } + public String getValue() { + return value; + } + } + + /** + * The enumerated list of elements used in the configuration file with graphics figures - + * graphics.xml. + */ + public static enum FigureTags { + FIGURE, PARAMETER, NULL; + + /** + * Returns predefined constant of element according to the element name. + * + * @param key + * the name of element. + * @return a constant of element with defined name. + */ + public static FigureTags getValue(String key) { + try { + return FigureTags.valueOf(key.toUpperCase()); + } catch (IllegalArgumentException ex) { + return NULL; + } + } + } + + /** + * The enumerated list of elements used in the configuration file with types - types.xml. + */ + public static enum TypeTags { + COLOR("color"), UNIT("unit"), FONT("font"), NULL(""); + + private String value; + + + TypeTags(String value) { + this.value = value; + } + /** + * Returns predefined constant of element according to the element name. + * + * @param key + * the name of element. + * @return a constant of element with defined name. + */ + public static TypeTags getValue(String key) { + for (TypeTags type : values()) { + if (type.value.equals(key)) + return type; + } + return NULL; + } + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/TypeEnum.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/TypeEnum.java new file mode 100644 index 000000000..2814b17af --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/constants/TypeEnum.java @@ -0,0 +1,56 @@ +package cz.zcu.fav.kiv.editor.config.constants; + + +/** + * The ComponentEnum class is the enumerated list of GUI components supported by the + * application. Components are used for displaying parameter Types. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public enum TypeEnum { + BOOLEAN("boolean"), STRING("string"), INTEGER("integer"), TABLE("table"), FLOAT("float"), LIST("list"), + LIST_OPEN("list-open"), LENGTH("length"), URI("uri"), NUMBER("number"), COLOR("color"), + FILENAME("filename"), RTF("rtf"), FONT("font"), ATTRIBUTE_SET("attribute set"); + + String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Returns ComponentEnum object for the corresponding name. If the input + * component is not supported then the DUMMY component is returned. + * + * @param name + * the name of the component. + * @return the component for the input name. + */ + public static TypeEnum getValue(String name){ + for (TypeEnum type : values()) { + if (type.value.equals(name)) + return type; + } + return null; + } + + /** + * Specifies if the input component is among predefined components ComponentEnum. + * + * @param name + * the name of the component. + * @return true if the component is among predefined components. + */ + public static boolean contains(String name) { + for (TypeEnum type : values()) { + if (type.value.equals(name)) + return true; + } + return false; + } + + public String toString() { + return this.value; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/AttributeXmlHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/AttributeXmlHandler.java new file mode 100644 index 000000000..31c7c46c7 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/AttributeXmlHandler.java @@ -0,0 +1,184 @@ +package cz.zcu.fav.kiv.editor.config.handlers; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.beans.properties.AttributeGroup; +import cz.zcu.fav.kiv.editor.beans.properties.TypeAttr; +import cz.zcu.fav.kiv.editor.beans.properties.UnitAttr; +import cz.zcu.fav.kiv.editor.beans.types.CommonTypes; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.config.constants.TypeEnum; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition.AttributeTags; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.utils.TagControl; + +/** + * The AttributeXmlHandler class is used for parsing the configuration file with + * attributes - attributes.xml. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AttributeXmlHandler extends DefaultHandler { + /** The locator specifying actual line number */ + private Locator locator; + + /** The data containing editor data structure */ + private CommonTypes commonTypes; + + /** The list of attributes of one group */ + private List atrributeList; + + /** The list of groups containing attributes */ + private List attributeGroupList; + + /** The group containing attributes */ + private AttributeGroup attrGroup; + + /** The attribute type */ + private TypeAttr type; + + /** The flag specifying whether the parser is inside value element */ + private boolean insideAttributeElement = false; + + /** The string buffer for content of value element */ + private StringBuffer attributeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** + * Initializes a newly created AttributeXmlHandler with ConfigData. + * + * @param commonTypes + * the common types of parameters. + */ + public AttributeXmlHandler(CommonTypes commonTypes) { + attributeGroupList = new ArrayList(); + this.commonTypes = commonTypes; + } + + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { + AttributeTags enumTag = TagDefinition.AttributeTags.getValue(qName); + switch (enumTag) { + case GROUP: + attrGroup = new AttributeGroup(atts.getValue(0)); + atrributeList = new ArrayList(); + break; + case ATTRIBUTE: + type = controlAttribute(atts.getValue(AttributeTags.TYPE.toString()), atts + .getValue(AttributeTags.DEFAULT.toString()), atts.getValue(AttributeTags.VALUES + .toString())); + insideAttributeElement = true; + attributeBuffer.setLength(0); + break; + } + } + + @Override + public void endElement(String namespaceURI, String localName, String qName) { + AttributeTags enumTag = TagDefinition.AttributeTags.getValue(qName); + switch (enumTag) { + case GROUP: + attrGroup.setAttributeList(atrributeList); + attributeGroupList.add(attrGroup); + break; + case ATTRIBUTE: + if (type != null) + atrributeList.add(new Attribute(attributeBuffer.toString(), type)); + insideAttributeElement = false; + break; + } + } + + @Override + public void characters(char[] ch, int start, int length) { + if (insideAttributeElement) { + attributeBuffer.append(ch, start, length); + } + } + + /** + * Assignes predefined type values to the attribute type that has defined a name of predefined + * values. + */ + private void addTypeValues(TypeAttr type) { + switch (type.getName()) { + case FONT: + type.setValueList(commonTypes.getFonts()); + break; + case COLOR: + type.setValueList(commonTypes.getColors()); + break; + } + } + + /** + * Controls if the type, values and default value of the attribute are valid. + * + * @return TypeAttr if the attribute is valid. + */ + private TypeAttr controlAttribute(String typeName, String defaultValue, String values) { + type = new TypeAttr(); + TypeEnum typeEnum = TypeEnum.getValue(typeName); + if (typeEnum == null) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.attributes.invalid_attribute_type", + FileConst.CONF_FILE_ATTRIBUTES, this.locator.getLineNumber())); + return null; + } + type.setName(typeEnum); + // values + if (values != null) { + try { + String[] valueList = values.split(","); + Map valueMap = new LinkedHashMap(); + for (String val : valueList) { + valueMap.put(val.trim(), val.trim()); + } + type.setValueList(valueMap); + } catch (Exception ex) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.attributes.invalid_attribute_value", + FileConst.CONF_FILE_ATTRIBUTES, this.locator.getLineNumber())); + return null; + } + } + // add unit + if (type.getName().equals(TypeEnum.LENGTH)) { + type.setUnit(new UnitAttr(commonTypes.getUnits())); + } + + // add common types values + addTypeValues(type); + + // default value + try { + TagControl.controlSetTypeValue(type, defaultValue); + type.assignDefaultFromValue(); + } catch (ParserException ex){ + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.attributes.invalid_attribute_default_value", FileConst.CONF_FILE_ATTRIBUTES, + this.locator.getLineNumber())); + return null; + } + return type; + } + + public void setDocumentLocator(Locator locator) { + this.locator = locator; + } + + public AttributeGroup[] getAttrGroupList() { + return attributeGroupList.toArray(new AttributeGroup[0]); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/ConfigXmlHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/ConfigXmlHandler.java new file mode 100644 index 000000000..cb2ae4ef2 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/ConfigXmlHandler.java @@ -0,0 +1,215 @@ +package cz.zcu.fav.kiv.editor.config.handlers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; +import cz.zcu.fav.kiv.editor.beans.graphics.Figure; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.AttributeGroup; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.beans.sections.Group; +import cz.zcu.fav.kiv.editor.beans.sections.Section; +import cz.zcu.fav.kiv.editor.beans.sections.Subsection; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition.ConfigTags; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The ConfigXmlHandler class is used for parsing the configuration file with layout + * of parameters and attribute-sets - config.xml. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ConfigXmlHandler extends DefaultHandler { + /** The locator specifying actual line number */ + private Locator locator; + + /** The list of parameters - key is parameter name */ + private Map parameterList; + + /** The list of groups containing attributes */ + private AttributeGroup[] attributeGroupList; + + /** The list of properties - key is property name */ + private Map propertyList; + + /** The list of graphics figures */ + private Map figureList = null; + + /** The group */ + private Group group; + + /** The list of sections */ + private List
sectionList; + + /** The section */ + private Section section; + + /** The list of subsections */ + private List subsectionList; + + /** The subsection */ + private Subsection subsection; + + /** The list of groups */ + private List groupList; + + /** The list of elements - Parameter and Property */ + private List elementList; + + /** The flag specifying whether the parser is inside parameter element */ + private boolean insideParameterElement = false; + + /** The flag specifying whether the parser is inside property element */ + private boolean insidePropertyElement = false; + + /** The string buffer for content of parameter element */ + private StringBuffer parameterBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of property element */ + private StringBuffer propertyBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** + * Initializes a newly created ConfigXmlHandler with list of + * AttributeGroups. + * + * @param attributeGroupList + * the list of attribute groups. + */ + public ConfigXmlHandler(AttributeGroup[] attributeGroupList) { + sectionList = new ArrayList
(); + this.parameterList = new TreeMap(); + this.attributeGroupList = attributeGroupList; + this.propertyList = new TreeMap(); + this.figureList = new TreeMap(); + } + + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { + ConfigTags enumTag = TagDefinition.ConfigTags.getValue(qName); + switch (enumTag) { + case SECTION: + section = new Section(atts.getValue(0)); + subsectionList = new ArrayList(); + break; + case SUBSECTION: + subsection = new Subsection(atts.getValue(0)); + groupList = new ArrayList(); + break; + case GROUP: + group = new Group(atts.getValue(0)); + if (atts.getValue(1) != null) { + Figure fig = new Figure(atts.getValue(1)); + group.setFigure(fig); + figureList.put(atts.getValue(1), fig); + } + elementList = new ArrayList(); + break; + case PARAMETER: + insideParameterElement = true; + parameterBuffer.setLength(0); + break; + case ATTRIBUTE_SET: + insidePropertyElement = true; + propertyBuffer.setLength(0); + break; + } + } + + @Override + public void endElement(String namespaceURI, String localName, String qName) { + ConfigTags enumTag = TagDefinition.ConfigTags.getValue(qName); + switch (enumTag) { + case SECTION: + if (subsectionList.size() != 0) { + section.setSubsectionList(subsectionList); + sectionList.add(section); + } + break; + case SUBSECTION: + if (groupList.size() != 0) { + subsection.setGroupList(groupList); + subsectionList.add(subsection); + } + break; + case GROUP: + if (elementList.size() != 0) { + group.setElementList(elementList); + groupList.add(group); + } + break; + case PARAMETER: + insideParameterElement = false; + Parameter newParameter = new Parameter(parameterBuffer.toString(), locator.getLineNumber()); + if (!parameterList.containsKey(parameterBuffer.toString())) { + parameterList.put(parameterBuffer.toString(), newParameter); + elementList.add(newParameter); + } else { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.config.duplicate_parameter", + FileConst.CONF_FILE_CONFIG, parameterBuffer.toString(), this.locator.getLineNumber())); + } + break; + case ATTRIBUTE_SET: + insidePropertyElement = false; + Property newProperty = new Property(propertyBuffer.toString(), cloneGroups(attributeGroupList), locator.getLineNumber()); + propertyList.put(propertyBuffer.toString(), newProperty); + elementList.add(newProperty); + break; + } + } + + @Override + public void characters(char[] ch, int start, int length) { + if (insideParameterElement) { + parameterBuffer.append(ch, start, length); + } else if (insidePropertyElement) { + propertyBuffer.append(ch, start, length); + } + } + + /** + * Makes copies of all attribute groups. + * + * @param groupList + * the list of atribute groups. + * @return a copy of the input list of attribute groups. + */ + private AttributeGroup[] cloneGroups(AttributeGroup[] groupList) { + AttributeGroup[] newGroups = new AttributeGroup[groupList.length]; + for (int i = 0; i < groupList.length; i++) { + newGroups[i] = (AttributeGroup) groupList[i].clone(); + } + return newGroups; + } + + public void setDocumentLocator(Locator locator) { + this.locator = locator; + } + + public List
getSections() { + return sectionList; + } + + public Map getPropertyList() { + return propertyList; + } + + public Map getParameterList() { + return parameterList; + } + + public Map getFigureList() { + return figureList; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/FigureXmlHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/FigureXmlHandler.java new file mode 100644 index 000000000..8e75da00a --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/FigureXmlHandler.java @@ -0,0 +1,137 @@ +package cz.zcu.fav.kiv.editor.config.handlers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.beans.graphics.Figure; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition.FigureTags; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.displays.GraphicsFigure; + +/** + * The FigureXmlHandler class is used for parsing the configuration file with + * graphics figures - graphics.xml. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class FigureXmlHandler extends DefaultHandler { + /** The locator specifying actual line number */ + private Locator locator; + + /** The number of the line with figure element */ + private int figureLine; + + /** The list of all figures - key is the figure name */ + private Map figureList; + + /** The graphics figure */ + private Figure figure; + + private Boolean valid; + + /** The list of parameters that belongs to a graphics figure */ + private List classParameterList; + + /** The list of all parameters - key is the parameter name */ + private Map allParameterList; + + /** The flag specifying whether the parser is inside parameter element */ + private boolean insideParameterElement = false; + + /** The string buffer for content of parameter element */ + private StringBuffer parameterBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** + * Initializes a newly created FigureXmlHandler with list of + * Parameters. + * + * @param parameterList + * the list of all parameters. + */ + public FigureXmlHandler(Map parameterList, Map figList) { + figureList = figList; + this.allParameterList = parameterList; + } + + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { + FigureTags enumTag = TagDefinition.FigureTags.getValue(qName); + switch (enumTag) { + case FIGURE: + figure = figureList.get(atts.getValue(0)); + if (figure != null) + figure.setClassName(atts.getValue(1)); + classParameterList = new ArrayList(); + this.figureLine = this.locator.getLineNumber(); + valid = true; + break; + case PARAMETER: + insideParameterElement = true; + parameterBuffer.setLength(0); + break; + } + } + + @Override + public void endElement(String namespaceURI, String localName, String qName) { + FigureTags enumTag = TagDefinition.FigureTags.getValue(qName); + switch (enumTag) { + case FIGURE: + if (figure != null) { + if (!valid) { + // invalid figure + figureList.remove(figure.getName()); + return; + } + try { + GraphicsFigure graphicsFigure = (GraphicsFigure) Class.forName( + figure.getClassName()).newInstance(); + graphicsFigure.setInputs(classParameterList.toArray(new Parameter[0])); + + figure.setParameterList(classParameterList.toArray(new Parameter[0])); + } catch (Exception ex) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.figures.invalid_class", FileConst.CONF_FILE_FIGURES, figure + .getName(), figureLine, figure.getClassName())); + figureList.remove(figure.getName()); + } + } + break; + case PARAMETER: + insideParameterElement = false; + if (figure != null) { + if (allParameterList.containsKey(parameterBuffer.toString())) + classParameterList.add(allParameterList.get(parameterBuffer.toString())); + else { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.figures.invalid_parameter_value", FileConst.CONF_FILE_FIGURES, + figure.getName(), figureLine, parameterBuffer.toString())); + valid = false; + } + } + break; + } + } + + @Override + public void characters(char[] ch, int start, int length) { + if (insideParameterElement) { + parameterBuffer.append(ch, start, length); + } + } + + public void setDocumentLocator(Locator locator) { + this.locator = locator; + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/ParameterXmlHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/ParameterXmlHandler.java new file mode 100644 index 000000000..046b41904 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/ParameterXmlHandler.java @@ -0,0 +1,348 @@ +package cz.zcu.fav.kiv.editor.config.handlers; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.regex.Matcher; + +import org.xml.sax.Attributes; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.parameters.TypeParam; +import cz.zcu.fav.kiv.editor.beans.parameters.UnitParam; +import cz.zcu.fav.kiv.editor.beans.types.CommonTypes; +import cz.zcu.fav.kiv.editor.config.ParamController; +import cz.zcu.fav.kiv.editor.config.ParameterTransformation; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.config.constants.TypeEnum; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition.ParameterTags; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.utils.TagControl; + +/** + * The ParameterXmlHandler class is used for parsing files with XML definitions of + * parameters. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParameterXmlHandler extends DefaultHandler { + + /** The parameter which XML file is parsed */ + private Parameter parameter; + + /** The list of common types */ + private static CommonTypes commonTypes; + + /** The flag indicating if the actually parsed parameter XML is valid */ + private boolean valid = true; + + /** + * The flag indicating if the actually parsed parameter value can be parsed without dependencies + * on other parameters + */ + private boolean parsed = false; + + /** The list of default values of the parameter */ + private Map valueList; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefsection = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefpurpose = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefmiscinfoDatatype = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefmiscinfoValue = false; + + /** + * The flag specifying whether the parser is inside + * element + */ + private boolean insideRefmiscinfoValueAlt = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefmiscinfoListType = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideXslParam = false; + + /** The string buffer for content of description element */ + private StringBuffer descriptionBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE_DESCRIPTION); + + /** The string buffer for content of element */ + private StringBuffer purposeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE_DESCRIPTION); + + /** The string buffer for content of element */ + private StringBuffer insideXslParamBuffer = new StringBuffer( + TagDefinition.BUFFER_SIZE_DESCRIPTION); + + /** The string buffer for content of element */ + private StringBuffer refmiscinfoDatatypeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of element */ + private StringBuffer refmiscinfoValueBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of element */ + private StringBuffer refmiscinfoValueAltBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of element */ + private StringBuffer refmiscinfoListTypeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** + * Initializes a newly created empty ParameterXmlHandler. + */ + public ParameterXmlHandler(Parameter parameter, CommonTypes types) { + this.parameter = parameter; + commonTypes = types; + } + + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { + if (insideXslParam) { + insideXslParamBuffer.append("<" + qName); + for (int i = 0; i < atts.getLength(); i++) { + insideXslParamBuffer.append(" " + atts.getQName(i) + "=\"" + atts.getValue(i) + + "\""); + } + insideXslParamBuffer.append(">"); + } + ParameterTags enumTag = ParameterTags.getEnumValue(qName); + switch (enumTag) { + case REFMETA: + valueList = new LinkedHashMap(); + break; + case REFSECTION: + insideRefsection = true; + descriptionBuffer.setLength(0); + break; + case REFPURPOSE: + insideRefpurpose = true; + purposeBuffer.setLength(0); + break; + case REFMISCINFO: + ParameterTags attrOtherClass = ParameterTags.getEnumValue(atts + .getValue(ParameterTags.OTHERCLASS)); + switch (attrOtherClass) { + case DATATYPE: + insideRefmiscinfoDatatype = true; + break; + case VALUE: + insideRefmiscinfoValue = true; + refmiscinfoValueBuffer.setLength(0); + break; + case LIST_TYPE: + insideRefmiscinfoListType = true; + break; + } + break; + case ALT: + insideRefmiscinfoValueAlt = true; + refmiscinfoValueAltBuffer.setLength(0); + break; + case XSL_PARAM: + insideXslParamBuffer.setLength(0); + // parse select + if (valid) + insideXslParam = parseXslParamSelect(atts); + break; + } + + if (insideRefsection) { + descriptionBuffer.append("<" + qName + ">"); + } + } + + @Override + public void endElement(String namespaceURI, String localName, String qName) { + if (insideRefsection) { + descriptionBuffer.append(""); + } + ParameterTags enumTag = ParameterTags.getEnumValue(qName); + switch (enumTag) { + case REFMETA: + controlType(); + break; + case REFSECTION: + insideRefsection = false; + if (descriptionBuffer.length() != 0) + parameter.setDescription(ParameterTransformation.htmlTransform(descriptionBuffer + .toString().trim())); + break; + case REFPURPOSE: + insideRefpurpose = false; + parameter.setPurpose(purposeBuffer.toString()); + break; + case REFMISCINFO: + if (insideRefmiscinfoDatatype) { + insideRefmiscinfoDatatype = false; + } + if (insideRefmiscinfoListType) { + insideRefmiscinfoListType = false; + } + if (insideRefmiscinfoValue) { + insideRefmiscinfoValue = false; + if (refmiscinfoValueAltBuffer.length() != 0) + valueList.put(refmiscinfoValueBuffer.toString(), refmiscinfoValueAltBuffer + .toString() + + " (" + refmiscinfoValueBuffer.toString() + ")"); + else + valueList.put(refmiscinfoValueBuffer.toString(), refmiscinfoValueBuffer + .toString()); + } + break; + case ALT: + insideRefmiscinfoValueAlt = false; + break; + case XSL_PARAM: + if ((valid) && (insideXslParam)) + controlXslParamValue(); + insideXslParam = false; + break; + } + if (insideXslParam) + insideXslParamBuffer.append(""); + } + + @Override + public void characters(char[] ch, int start, int length) { + if (insideRefsection) { + String nextPart = new String(ch, start, length); + nextPart = nextPart.replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", + "&"); + descriptionBuffer.append(nextPart); + } else if (insideRefpurpose) { + purposeBuffer.append(ch, start, length); + } else if (insideRefmiscinfoDatatype) { + refmiscinfoDatatypeBuffer.append(ch, start, length); + } else if (insideRefmiscinfoValue) { + if (insideRefmiscinfoValueAlt) + refmiscinfoValueAltBuffer.append(ch, start, length); + else + refmiscinfoValueBuffer.append(ch, start, length); + } else if (insideRefmiscinfoListType) { + refmiscinfoListTypeBuffer.append(ch, start, length); + } else if (insideXslParam) { + String nextPart = new String(ch, start, length); + nextPart = nextPart.replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", + "&"); + insideXslParamBuffer.append(nextPart); + } + } + + /** + * Controls if the parameter type definition is valid. Assigns to paramter type the list of + * predefined values. + */ + private void controlType() { + TypeEnum typeName = TypeEnum.getValue(refmiscinfoDatatypeBuffer.toString()); + if (typeName == null) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.parameters.invalid_type", FileConst.CONF_FILE_CONFIG, parameter + .getName(), parameter.getLineNumber())); + valid = false; + return; + } + parameter.getType().setName(typeName); + // open list + if ((parameter.getType().getName().equals(TypeEnum.LIST)) + && (refmiscinfoListTypeBuffer.toString().equals(ParameterTags.OPEN))) + parameter.getType().setName(TypeEnum.LIST_OPEN); + + // length - assigne units + if (parameter.getType().getName().equals(TypeEnum.LENGTH)) + parameter.getType().setUnit(new UnitParam(commonTypes.getUnits(), parameter)); + + // list values + if ((parameter.getType().getName().equals(TypeEnum.LIST) || (parameter.getType().getName() + .equals(TypeEnum.LIST_OPEN))) + && (valueList.size() != 0)) + parameter.getType().getDefaultValue().setValueList(valueList); + addTypeValues(parameter.getType()); + } + + /** + * Assigns to the parameter a list of default values. + * + * @param type + * the parameter type. + */ + private void addTypeValues(TypeParam type) { + switch (type.getName()) { + case FONT: + type.setValueList(commonTypes.getFonts()); + break; + case COLOR: + type.setValueList(commonTypes.getColors()); + break; + } + } + + public boolean isValid() { + return valid; + } + + /** + * Assignes the content of the attribute select of the element to the + * insideXslParamBuffer. Controls whether the parameter has no other condition + * than 'FO'. + * + * @param atts + * the attributes of the element . + * @return true if the has no other condition than 'FO'. + */ + private boolean parseXslParamSelect(Attributes atts) { + // condition="fo" + if ((atts.getValue(ParameterTags.CONDITION) != null) + && (!atts.getValue(ParameterTags.CONDITION).equals(ParameterTags.FO))) + return false; + // select + if ((atts.getValue(ParameterTags.SELECT)) != null) { + insideXslParamBuffer.append(atts.getValue(ParameterTags.SELECT)); + } + return true; + } + + /** + * Controls the content of the element . If the content is not simple (cannot be + * parsed without others parameters) then parsed is set to false. If the content + * is not valid then valid is set to false. + */ + private void controlXslParamValue() { + String paramValue = insideXslParamBuffer.toString(); + // rtf + if (parameter.getType().getName().equals(TypeEnum.RTF)) { + parameter.getType().setValue(paramValue.trim()); + parameter.getType().assignDefaultFromValue(); + parsed = true; + return; + } + Matcher matcher = ParamController.patternParam.matcher(paramValue); + if (!matcher.find()) { + // raw value + try { + TagControl.controlSetTypeValue(parameter.getType(), paramValue.replaceAll("'", "") + .replaceAll("<[//]?xsl:text>", "")); + parameter.getType().assignDefaultFromValue(); + parsed = true; + } catch (ParserException ex) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.parameters.invalid_value", FileConst.CONF_FILE_CONFIG, parameter + .getName(), parameter.getLineNumber())); + valid = false; + } + } else { + parameter.getType().setValue(paramValue.trim()); + } + } + + public boolean isParsed() { + return parsed; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/PropertyXmlHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/PropertyXmlHandler.java new file mode 100644 index 000000000..39e76e0ee --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/PropertyXmlHandler.java @@ -0,0 +1,209 @@ +package cz.zcu.fav.kiv.editor.config.handlers; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; + +import org.xml.sax.Attributes; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.config.ParamController; +import cz.zcu.fav.kiv.editor.config.ParameterTransformation; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.config.constants.TypeEnum; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition.ParameterTags; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.utils.TagControl; + +/** + * The PropertyXmlHandler class is used for parsing files with XML definitions of + * properties. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class PropertyXmlHandler extends DefaultHandler { + + /** The property which XML file is parsed */ + private Property property; + + /** The flag indicating if the actually parsed proeperty XML is valid */ + private boolean valid = true; + + /** The name of actually parsed attribute */ + private String attributeName; + + /** The list of attributes that cannot be parsed */ + private Map unparsedAttributeList; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefsection = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefpurpose = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideRefmiscinfoDatatype = false; + + /** The flag specifying whether the parser is inside element */ + private boolean insideXslAttribute = false; + + /** The string buffer for content of description element */ + private StringBuffer descriptionBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE_DESCRIPTION); + + /** The string buffer for content of purpose element */ + private StringBuffer purposeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE_DESCRIPTION); + + /** The string buffer for content of element */ + private StringBuffer refmiscinfoDatatypeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of purpose element */ + private StringBuffer xslAttributeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** + * Initializes a newly created empty PropertyXmlHandler. + */ + public PropertyXmlHandler(Property property) { + this.property = property; + unparsedAttributeList = new HashMap(); + } + + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { + if (insideXslAttribute) { + xslAttributeBuffer.append("<" + qName); + for (int i = 0; i < atts.getLength(); i++) { + xslAttributeBuffer.append(" " + atts.getQName(i) + "=\"" + atts.getValue(i) + "\""); + } + xslAttributeBuffer.append(">"); + } + ParameterTags enumTag = TagDefinition.ParameterTags.getEnumValue(qName); + switch (enumTag) { + case REFSECTION: + insideRefsection = true; + descriptionBuffer.setLength(0); + break; + case REFPURPOSE: + insideRefpurpose = true; + purposeBuffer.setLength(0); + break; + case REFMISCINFO: + if (atts.getType(ParameterTags.OTHERCLASS).equals(ParameterTags.DATATYPE.toString())) { + insideRefmiscinfoDatatype = true; + refmiscinfoDatatypeBuffer.setLength(0); + } + break; + case XSL_ATTRIBUTE: + insideXslAttribute = true; + attributeName = atts.getValue(ParameterTags.NAME); + xslAttributeBuffer.setLength(0); + break; + } + + if (insideRefsection) { + descriptionBuffer.append("<" + qName + ">"); + } + } + + @Override + public void endElement(String namespaceURI, String localName, String qName) { + if (insideRefsection) { + descriptionBuffer.append(""); + } + ParameterTags enumTag = TagDefinition.ParameterTags.getEnumValue(qName); + switch (enumTag) { + case REFSECTION: + insideRefsection = false; + if (descriptionBuffer.length() != 0) + property.setDescription(ParameterTransformation.htmlTransform(descriptionBuffer + .toString())); + break; + case REFPURPOSE: + insideRefpurpose = false; + property.setPurpose(purposeBuffer.toString()); + break; + case REFMISCINFO: + if (insideRefmiscinfoDatatype) { + insideRefmiscinfoDatatype = false; + if (!TypeEnum.ATTRIBUTE_SET.toString().equals(refmiscinfoDatatypeBuffer.toString())) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.property.invalid_type", FileConst.CONF_FILE_CONFIG, property + .getName(), property.getLineNumber())); + valid = false; + } + } + break; + case XSL_ATTRIBUTE: + insideXslAttribute = true; + // save attribute value + // TODO parsing attribute values for each property according to its .xml + // if (attributeName != null) + // controlXslAttributeValue(); + break; + } + if (insideXslAttribute) + xslAttributeBuffer.append(""); + } + + @Override + public void characters(char[] ch, int start, int length) { + if (insideRefsection) { + String nextPart = new String(ch, start, length); + nextPart = nextPart.replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", + "&"); + descriptionBuffer.append(nextPart); + } else if (insideRefpurpose) { + purposeBuffer.append(ch, start, length); + } else if (insideRefmiscinfoDatatype) { + refmiscinfoDatatypeBuffer.append(ch, start, length); + } else if (insideXslAttribute) { + xslAttributeBuffer.append(ch, start, length); + } + } + + public boolean isValid() { + return valid; + } + + /** + * Controls if the actually parsed attribute value can be parsed - is supported and if it is + * valid and can be parsed without other parameters. If the attribute cannot be parsed, it is + * assignes to the unparsedAttributeList. + */ + private void controlXslAttributeValue() { + Attribute attr = property.searchAttribute(attributeName); + if (attr == null) { + // unsupported attribute + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.property.unsupported_attribute", FileConst.CONF_FILE_CONFIG, property + .getName(), property.getLineNumber(), attributeName)); + return; + } + String paramValue = xslAttributeBuffer.toString().trim(); + Matcher matcher = ParamController.patternParam.matcher(paramValue); + if (!matcher.find()) { + // raw value + try { + TagControl.controlSetTypeValue(attr.getType(), paramValue.replaceAll("'", "") + .replaceAll("<[//]?xsl:text>", "")); + attr.getType().assignDefaultFromValue(); + } catch (ParserException ex) { + MessageWriter.writeWarning(ResourceController.getMessage( + "parser.property.invalid_value", FileConst.CONF_FILE_CONFIG, property + .getName(), property.getLineNumber(), attributeName)); + } + } else { + attr.getType().setValue(paramValue); + unparsedAttributeList.put(attributeName, attr); + } + } + + public Map getUnparsedAttributeList() { + return unparsedAttributeList; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/TypeXmlHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/TypeXmlHandler.java new file mode 100644 index 000000000..113faff1b --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/config/handlers/TypeXmlHandler.java @@ -0,0 +1,122 @@ +package cz.zcu.fav.kiv.editor.config.handlers; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.xml.sax.Attributes; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition.TypeTags; + +/** + * The TypeXmlHandler class is used for parsing the configuration file with types - + * types.xml. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TypeXmlHandler extends DefaultHandler { + /** The list of units */ + private List unitList; + + /** The list of font - key is font name or font itself */ + private Map fontList; + + /** The list of font - key is color name or color itself */ + private Map colorList; + + /** The key of actually parsed element */ + private String key; + + /** The flag specifying whether the parser is inside unit element */ + private boolean insideUnitElement = false; + + /** The flag specifying whether the parser is inside color element */ + private boolean insideColorElement = false; + + /** The flag specifying whether the parser is inside font element */ + private boolean insideFontElement = false; + + /** The string buffer for content of unit element */ + private StringBuffer unitBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of color element */ + private StringBuffer colorBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of font element */ + private StringBuffer fontBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** + * Initializes a newly created empty TypeXmlHandler. + */ + public TypeXmlHandler() { + unitList = new ArrayList(); + fontList = new LinkedHashMap(); + colorList = new LinkedHashMap(); + } + + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { + TypeTags enumTag = TagDefinition.TypeTags.getValue(qName); + switch (enumTag) { + case COLOR: + insideColorElement = true; + colorBuffer.setLength(0); + key = atts.getValue(0); + break; + case UNIT: + insideUnitElement = true; + unitBuffer.setLength(0); + break; + case FONT: + insideFontElement = true; + fontBuffer.setLength(0); + break; + } + } + + @Override + public void endElement(String namespaceURI, String localName, String qName) { + TypeTags enumTag = TagDefinition.TypeTags.getValue(qName); + switch (enumTag) { + case COLOR: + insideColorElement = false; + colorList.put(key, colorBuffer.toString()); + break; + case UNIT: + insideUnitElement = false; + unitList.add(unitBuffer.toString()); + break; + case FONT: + insideFontElement = false; + fontList.put(fontBuffer.toString(), fontBuffer.toString()); + break; + } + } + + @Override + public void characters(char[] ch, int start, int length) { + if (insideColorElement) { + colorBuffer.append(ch, start, length); + } else if (insideUnitElement) { + unitBuffer.append(ch, start, length); + } else if (insideFontElement) { + fontBuffer.append(ch, start, length); + } + } + + public Map getColorList() { + return colorList; + } + + public Map getFontList() { + return fontList; + } + + public List getUnitList() { + return unitList; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MainController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MainController.java new file mode 100644 index 000000000..790a76059 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MainController.java @@ -0,0 +1,50 @@ +package cz.zcu.fav.kiv.editor.controller; + +import javax.swing.UIManager; +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; +import cz.zcu.fav.kiv.editor.graphics.intro.IntroException; +import cz.zcu.fav.kiv.editor.graphics.intro.IntroFrame; +import cz.zcu.fav.kiv.editor.graphics.intro.ProgressBar; +import cz.zcu.fav.kiv.editor.utils.ErrorDialog; + +/** + * The MainController class is the main control class of the application. Controls + * loading of configurations files and creating of the application GUI. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class MainController { + + /** + * Main class that controls loading of configurations files and creating of the application GUI. + * + * @param args + * main application arguments. + * @throws Exception + * if an fatal error occurs in the application. + */ + public static void main(String args[]) throws Exception { + + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + + OptionController.readOptions(); + + IntroFrame introFrame = new IntroFrame(); + ConfigData data = ProgressBar.getData(); + introFrame.hideFrame(); + + MainFrame.createFrame(data).go(); + } catch (IntroException introEx) { + } catch (Exception ex) { + Log.fatal(ex); + ErrorDialog.showDialog(ex); + System.exit(1); + } + + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MenuController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MenuController.java new file mode 100644 index 000000000..47a339978 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MenuController.java @@ -0,0 +1,195 @@ +package cz.zcu.fav.kiv.editor.controller; + +import java.io.File; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.OpenFile; +import cz.zcu.fav.kiv.editor.controller.errors.OpenFileException; +import cz.zcu.fav.kiv.editor.controller.errors.SaveFileException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionController; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.stylesheet.XslParser; +import cz.zcu.fav.kiv.editor.template.TemplateConst; +import cz.zcu.fav.kiv.editor.template.TemplateController; +import cz.zcu.fav.kiv.editor.utils.RunBatch; + +/** + * The MenuController class contains method that are called for every item from the + * application GUI. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class MenuController { + + /** + * Creates a new empty stylesheet file, sets default values to the GUI editor element. + * + * @param configData + * the data containing editor data structure. + * @param openFile + * the structure containing information about actually opened file. + */ + public static void newFileEmptyItem(ConfigData configData, OpenFile openFile) { + MessageWriter.writeTitle(ResourceController.getMessage("new_file.title")); + configData.clearValues(); + openFile.setOpenFilePath(null); + openFile.setWholeFile(XslParser.createXsltFile()); + MessageWriter.writeInfo(ResourceController.getMessage("new_file.empty.info")); + } + + /** + * Creates a new stylesheet file and sets values to the GUI editor element according to the + * default template. + * + * @param configData + * the data containing editor data structure. + * @param openFile + * the structure containing information about actually opened file. + */ + public static void newFileDefaultItem(ConfigData configData, OpenFile openFile) { + MessageWriter.writeTitle(ResourceController.getMessage("new_file.title")); + configData.clearValues(); + // load default template + try { + TemplateController.getInstance().readTemplate(configData, + TemplateConst.CONF_FILE_TEMPLATE); + MessageWriter.writeInfo(ResourceController.getMessage("new_file.default.info")); + } catch (Throwable ex) { + MessageWriter.writeError(ex.getMessage()); + } + openFile.setOpenFilePath(null); + openFile.setWholeFile(XslParser.createXsltFile()); + } + + /** + * Creates a new stylesheet file and sets values to the GUI editor element according to the user + * template. + * + * @param configData + * the data containing editor data structure. + * @param openFile + * the structure containing information about actually opened file. + * @param templateFile + * the file containing user template. + */ + public static void newFileStylesheetItem(ConfigData configData, OpenFile openFile, + String templateFile) { + MessageWriter.writeTitle(ResourceController.getMessage("new_file.title")); + configData.clearValues(); + // load user template + try { + TemplateController.getInstance().readTemplate(configData, templateFile); + MessageWriter.writeInfo(ResourceController.getMessage("new_file.stylesheet.info", + templateFile)); + } catch (Throwable ex) { + MessageWriter.writeError(ex.getMessage()); + } + openFile.setOpenFilePath(null); + openFile.setWholeFile(XslParser.createXsltFile()); + } + + /** + * Opens specified XSL stylesheet file. + * + * @param configData + * the data containing editor data structure. + * @param file + * the XSL stylesheet file for opening. + * @param openFile + * the structure containing information about actually opened file. + */ + public static void openFileItem(ConfigData configData, String file, OpenFile openFile) { + try { + MessageWriter.writeTitle(ResourceController.getMessage("open_file.title")); + + configData.clearValues(); + openFile.setOpenFilePath(file); + openFile.setWholeFile(XslParser.readXsltFile(file, configData)); + + MessageWriter.writeInfo(ResourceController.getMessage("open_file.success_info", file)); + } catch (OpenFileException ex) { + MessageWriter.writeError(ex.getMessage()); + } + } + + /** + * Saves actually opened XSL stylesheet in the file with specified name. + * + * @param configData + * the data containing editor data structure. + * @param saveFile + * the name of the file where the XSL stylesheet will be saved. + * @param openFile + * the structure containing information about actually opened file. + */ + public static void saveAsFileItem(ConfigData configData, String saveFile, OpenFile openFile) { + openFile.setOpenFilePath(saveFile); + saveFileItem(configData, openFile); + } + + /** + * Saves changes of the actually opened XSL stylesheet file. + * + * @param configData + * the data containing editor data structure. + * @param openFile + * the structure containing information about actually opened file. + */ + public static void saveFileItem(ConfigData configData, OpenFile openFile) { + try { + MessageWriter.writeTitle(ResourceController.getMessage("save_file.title")); + // remove comments + if (OptionItems.REARRANGE_SAVE) + XslParser.removeComments(openFile.getWholeFile()); + + XslParser.saveXsltFile(openFile.getOpenFilePath(), openFile.getWholeFile(), configData); + openFile.setFileChanged(false); + MessageWriter.writeInfo(ResourceController.getMessage("save_file.success_info", + openFile.getOpenFilePath())); + } catch (SaveFileException ex) { + MessageWriter.writeError(ResourceController.getMessage("error.save_file", openFile + .getWholeFile()) + + ex.getMessage()); + } + } + + /** + * Stores editor options in the application cofiguration file. + */ + public static void exitItem() { + OptionController.storeOptionItems(); + } + + /** + * Launches a selected batch file. + * + * @param openFile + * the structure containing information about actually opened file. + */ + public static void runBatchFile(OpenFile openFile) { + MessageWriter.writeTitle(ResourceController.getMessage("run_batch_file.title")); + if (openFile.getOpenFilePath() == null) { + MessageWriter.writeError(ResourceController.getMessage("run_batch_file.not_saved")); + return; + } + // exists batch file? + if (!(new File(OptionItems.BATCH_FILE)).exists()) { + MessageWriter.writeError(ResourceController + .getMessage("run_batch_file.file_not_exists")); + return; + } + try { + MessageWriter.writeInfo(ResourceController.getMessage("run_batch_file.running", + OptionItems.BATCH_FILE)); + RunBatch.replaceXslName(OptionItems.BATCH_FILE, openFile.getOpenFilePath()); + RunBatch.execBatch(); + } catch (Throwable ex) { + Log.error(ex); + MessageWriter.writeError(ResourceController.getMessage("run_batch_file.error_running", + OptionItems.BATCH_FILE)); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MessageWriter.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MessageWriter.java new file mode 100644 index 000000000..e7582a63c --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/MessageWriter.java @@ -0,0 +1,82 @@ +package cz.zcu.fav.kiv.editor.controller; + +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.graphics.console.MessageConsole; + +/** + * The MessageWriter class provides methods for writting down information and errors + * to the editor console. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class MessageWriter { + /** + * Writes a normal information to the editor console. + * + * @param message + * the normal text message. + */ + public static void write(String message) { + MessageConsole.logMessage(message); + } + + /** + * Writes an emphasis information to the editor console. + * + * @param message + * the normal text message. + */ + public static void writeEmphasis(String message) { + MessageConsole.logMessageEmphasis(message); + } + + /** + * Writes a title to the editor console. + * + * @param message + * the message containing title. + */ + public static void writeTitle(String message) { + if (OptionItems.ERASE_CONSOLE) + MessageWriter.eraseConsole(); + MessageConsole.logTitle(message); + } + + /** + * Writes a warning message to the editor console. + * + * @param message + * the message containing warning. + */ + public static void writeWarning(String message) { + MessageConsole.logWarning(message); + } + + /** + * Writes an error message to the editor console. + * + * @param message + * the message containing error. + */ + public static void writeError(String message) { + MessageConsole.logError(message); + } + + /** + * Writes an information message to the editor console. + * + * @param message + * the message containing information. + */ + public static void writeInfo(String message) { + MessageConsole.logInfo(message); + } + + /** + * Erases the editor console. + */ + public static void eraseConsole() { + MessageConsole.eraseConsole(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/ProgressControl.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/ProgressControl.java new file mode 100644 index 000000000..2d4961469 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/ProgressControl.java @@ -0,0 +1,168 @@ +package cz.zcu.fav.kiv.editor.controller; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.config.ConfigController; +import cz.zcu.fav.kiv.editor.config.ParamController; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The ProgressControl class controls the progress of configuration files loading. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ProgressControl { + /** The numerical representation of the loading progress */ + private int current = 0; + + /** The flag indicating if the loading progress has already finished */ + private boolean done = false; + + /** The flag indicating if the loading progress is canceled */ + private boolean canceled = false; + + /** The message containing information about the loading progress */ + private static String statMessage; + + /** The message containing error rised during the loading progress */ + private String errorMessage; + + /** The char representing a new line */ + private final static String NEWLINE = "\n"; + + /** The controll class containing methods for loading configuration files */ + private ConfigController config; + + /** + * Returns editor data structure loaded from configuration files. + * + * @return the editor data structure loaded from configuration files. + */ + public ConfigData getData() { + return config.getData(); + } + + /** + * Initializes a newly created empty ProgressControl. + */ + public ProgressControl() { + } + + /** + * Launches the thread which loads configuration files. + */ + public void go() { + ConfigThread con = new ConfigThread(); + con.setPriority(1); + con.start(); + try { + con.join(); + } catch (InterruptedException ex) { + Log.warn(ex); + } + } + + /** + * Called from ProgressBar to find out how much has been done. + * + * @return the number indicating the loading progress. + */ + public int getCurrent() { + return current; + } + + /** + * Called from ProgressBar to find out if the task has completed. + * + * @return true if the task is done. + */ + public boolean isDone() { + return done; + } + + /** + * Called from ProgressBar to find out if the task is canceled. + * + * @return true if the task is camceled. + */ + public boolean isCanceled() { + return canceled; + } + + /** + * Returns the most recent status message. + * + * @return the most recent status message. + */ + public String getMessage() { + return statMessage; + } + + /** + * The ConfigThread class is a thread used for controling the progress of + * configuration files loading. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class ConfigThread extends Thread { + public void run() { + try { + statMessage = ""; + config = new ConfigController(); + + config.readTypes(); + current = 10; + statMessage += ResourceController.getMessage("frame.intro.progress.read_file", FileConst.CONF_FILE_TYPE) + NEWLINE; + Thread.yield(); + + config.readAttributes(); + current = 20; + statMessage += ResourceController.getMessage("frame.intro.progress.read_file", FileConst.CONF_FILE_ATTRIBUTES) + NEWLINE; + Thread.yield(); + + config.readConfig(); + current = 30; + statMessage += ResourceController.getMessage("frame.intro.progress.read_file", FileConst.CONF_FILE_CONFIG) + NEWLINE; + Thread.yield(); + + ParamController configXml = new ParamController(config.getData(), config.getCommonTypes()); + configXml.readParameters(); + current = 75; + + config.readFigures(configXml.getParsedParameterList()); + current = 80; + statMessage += ResourceController.getMessage("frame.intro.progress.read_file", FileConst.CONF_FILE_FIGURES) + NEWLINE; + Thread.yield(); + + configXml.readProperties(); + current = 100; + configXml.removeInvalidParam(config.getFigureList()); + + statMessage += ResourceController.getMessage("frame.intro.progress.read_ok") + NEWLINE; + done = true; + } catch (Throwable ex) { + canceled = true; + errorMessage = ex.getMessage() + NEWLINE + NEWLINE; + errorMessage += ResourceController.getMessage("frame.intro.progress.correct_error"); + Log.errorText(ex.getMessage(), ex); + return; + } + } + } + + /** + * Returns the error message. + * + * @return the error message. + */ + public String getErrorMessage() { + return errorMessage; + } + + public static void addStatMessage(String statMessage) { + ProgressControl.statMessage += statMessage + NEWLINE; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/ConfigException.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/ConfigException.java new file mode 100644 index 000000000..2b0f8997b --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/ConfigException.java @@ -0,0 +1,35 @@ +package cz.zcu.fav.kiv.editor.controller.errors; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The ConfigException class is used for reporting errors generated during loading configuration + * files and templates. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ConfigException extends Throwable implements java.io.Serializable { + + private static final long serialVersionUID = 7020184336946762911L; + + /** + * Initializes a newly created empty ConfigException. + */ + public ConfigException() { + super(); + } + + /** + * Initializes a newly created ConfigException with specified error messages and + * error source file. + * + * @param fileName + * the name of file where the error was generated. + * @param message + * the error message. + */ + public ConfigException(String fileName, String message) { + super(ResourceController.getMessage("error.config_error", fileName) + "\n" + message); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/FileNotFoundException.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/FileNotFoundException.java new file mode 100644 index 000000000..33e32a7c1 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/FileNotFoundException.java @@ -0,0 +1,42 @@ +package cz.zcu.fav.kiv.editor.controller.errors; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The FileNotFoundException class is used when a configuration file, templates or + * their XML schema is missing. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class FileNotFoundException extends Throwable implements java.io.Serializable { + + private static final long serialVersionUID = -4128798341326945960L; + + /** + * Initializes a newly created FileNotFoundException with missing file. + * + * @param fileName + * the name of the missing file. + */ + public FileNotFoundException(String fileName) { + super(ResourceController.getMessage("error.file_not_found.file", fileName)); + } + + /** + * Initializes a newly created empty FileNotFoundException. + */ + public FileNotFoundException() { + super(ResourceController.getMessage("error.file_not_found.dir")); + } + + /** + * Initializes a newly created empty FileNotFoundException with the rised error. + * + * @param t + * the rised error. + */ + public FileNotFoundException(Throwable t) { + super(t.getMessage(), t); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/OpenFileException.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/OpenFileException.java new file mode 100644 index 000000000..e68708303 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/OpenFileException.java @@ -0,0 +1,32 @@ +package cz.zcu.fav.kiv.editor.controller.errors; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The OpenFileException class is used for reporting errors rised during opening XSL + * stylesheet files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OpenFileException extends Throwable implements java.io.Serializable { + + private static final long serialVersionUID = 7020184336946762911L; + + /** + * Initializes a newly created empty OpenFileException. + */ + public OpenFileException() { + super(ResourceController.getMessage("error.open_file.wrong_form")); + } + + /** + * Initializes a newly created empty OpenFileException with specified message. + * + * @param message + * the message decribing the rised error. + */ + public OpenFileException(String message) { + super(ResourceController.getMessage("error.open_file.wrong_form") + message); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/ParserException.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/ParserException.java new file mode 100644 index 000000000..12203a8a4 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/ParserException.java @@ -0,0 +1,32 @@ +package cz.zcu.fav.kiv.editor.controller.errors; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The ParserException class is used for reporting errors rised during parsing values + * from input files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParserException extends Throwable { + + private static final long serialVersionUID = 7020184336946762911L; + + /** + * Initializes a newly created empty ParserException. + */ + public ParserException() { + super(); + } + + /** + * Initializes a newly created empty ParserException with specified message. + * + * @param message + * the message decribing the rised error. + */ + public ParserException(String message) { + super(ResourceController.getMessage("error.parser_error", message)); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/SaveFileException.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/SaveFileException.java new file mode 100644 index 000000000..bcb1833d0 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/SaveFileException.java @@ -0,0 +1,23 @@ +package cz.zcu.fav.kiv.editor.controller.errors; + +/** + * The SaveFileException class is used for reporting errors rised during saving XSL + * stylesheet files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class SaveFileException extends Throwable implements java.io.Serializable { + + private static final long serialVersionUID = 7020184336946762911L; + + /** + * Initializes a newly created empty SaveFileException with the rised error. + * + * @param t + * the rised error. + */ + public SaveFileException(Throwable t) { + super(t); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/XslParserException.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/XslParserException.java new file mode 100644 index 000000000..ced570369 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/errors/XslParserException.java @@ -0,0 +1,63 @@ +package cz.zcu.fav.kiv.editor.controller.errors; + +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The XslParserException class is used for reporting errors rised during parsing + * input XML and XSL files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class XslParserException implements ErrorHandler { + /** + * Creates text containing a message with the error. + * + * @param exception + * the rised error. + * @return a message with the error. + */ + private String errorText(SAXParseException exception) { + return ResourceController.getMessage("error.xslt_parser", exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage()); + } + + /** + * Handles the warning messages rised during file parsing. + * + * @param exception + * the rised warning. + * @throws SAXException + * with the content of the rised warning. + */ + public void warning(SAXParseException exception) throws SAXException { + throw new SAXException(ResourceController.getMessage("error.xslt_parser.warning") + errorText(exception)); + } + + /** + * Handles the error messages rised during file parsing. + * + * @param exception + * the rised error. + * @throws SAXException + * with the content of the rised error. + */ + public void error(SAXParseException exception) throws SAXException { + throw new SAXException(errorText(exception)); + } + + /** + * Handles the fatal error messages rised during file parsing. + * + * @param exception + * the rised fatal error. + * @throws SAXException + * with the content of the rised fatal error. + */ + public void fatalError(SAXParseException exception) throws SAXException { + throw new SAXException(ResourceController.getMessage("error.xslt_parser.fatal") + errorText(exception)); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/logger/Log.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/logger/Log.java new file mode 100644 index 000000000..8730a5101 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/logger/Log.java @@ -0,0 +1,121 @@ +package cz.zcu.fav.kiv.editor.controller.logger; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + +import cz.zcu.fav.kiv.editor.controller.resource.ErrorResourceController; + +/** + * The Log class is used for logging all errors and debug messages in the editor. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class Log { + /** + * Logs the error with its error tracing and description obtained by + * ErrorResourceController. + * + * @param resource + * the resource key of the error description. + * @param ex + * the rised error. + */ + public static void error(String resource, Throwable ex) { + Logger.getRootLogger().log(Level.ERROR, ErrorResourceController.getMessage(resource) + "\n" + getStackTrace(ex)); + } + + /** + * Logs the error with its error tracing and description. + * + * @param text + * the error description. + * @param ex + * the rised error. + */ + public static void errorText(String text, Throwable ex) { + Logger.getRootLogger().log(Level.ERROR, text +"\n"+ getStackTrace(ex)); + } + + /** + * Logs the error with its error tracing. + * + * @param ex + * the rised error. + */ + public static void error(Throwable ex) { + Logger.getRootLogger().log(Level.ERROR, getStackTrace(ex)); + } + + /** + * Logs the information with its description obtained by ErrorResourceController + * with arguments. + * + * @param resource + * the resource key of the error description. + * @param args + * the arguments of the description. + */ + public static void info(String resource, Object... args) { + Logger.getRootLogger().info(ErrorResourceController.getMessage(resource, args)); + } + + /** + * Logs the warning with its error tracing and description obtained by + * ErrorResourceController. + * + * @param resource + * the resource key of the error description. + * @param ex + * the rised error. + */ + public static void warn(String resource, Throwable ex) { + Logger.getRootLogger().log(Level.WARN, ErrorResourceController.getMessage(resource) +"\n"+ getStackTrace(ex)); + } + + /** + * Logs the warning with its error tracing and description obtained by + * ErrorResourceController with arguments. + * + * @param resource + * the resource key of the warning description. + * @param ex + * the rised warning. + * @param args + * the arguments of the description. + */ + public static void warn(String resource, Throwable ex, Object... args) { + Logger.getRootLogger().log(Level.WARN, ErrorResourceController.getMessage(resource, args) +"\n"+ getStackTrace(ex)); + } + + /** + * Logs the warning with its error tracing. + * + * @param ex + * the rised warning. + */ + public static void warn(Throwable ex) { + Logger.getRootLogger().log(Level.WARN, getStackTrace(ex)); + } + + /** + * Logs the fatal error with its error tracing. + * + * @param ex + * the rised fatal error. + */ + public static void fatal(Throwable ex) { + Logger.getRootLogger().log(Level.FATAL, getStackTrace(ex)); + } + + public static String getStackTrace(Throwable t) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + pw.flush(); + return sw.toString(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/EncodingEnum.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/EncodingEnum.java new file mode 100644 index 000000000..ee70d84d9 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/EncodingEnum.java @@ -0,0 +1,61 @@ +package cz.zcu.fav.kiv.editor.controller.options; + +/** + * The EncodingEnum class is the enumerated list of document encodings. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public enum EncodingEnum { + UTF8("UTF-8"), UTF16BE("UTF-16BE"), UTF16LE("UTF-16LE"), ASCII("US-ASCII"), WIN1250( + "WINDOWS-1250"), ISO88591("ISO-8859-1"), ISO88592("ISO-8859-2"); + /** The key specifying every type of encoding */ + private String key; + + /** + * Initializes a newly created EncodingEnum with defined key. + * + * @param key + * the key of the encoding. + */ + private EncodingEnum(String key) { + this.key = key; + } + + public String getKey() { + return key; + } + + public String toString() { + return key; + } + + /** + * Returns EncodingEnum object for corresponding key. + * + * @param encodKey + * the key of the encoding. + * @return the encoding for the input key. + */ + public static EncodingEnum getEncoding(String encodKey) { + for (int i = 0; i < EncodingEnum.values().length; i++) + if (EncodingEnum.values()[i].key.equals(encodKey)) + return EncodingEnum.values()[i]; + return null; + } + + /** + * Specifies if the input encoding is among predefined encodings EncodingEnum. + * + * @param encodKey + * the key of the encoding. + * @return true if the input encoding is present in the predefined encodings + * EncodingEnum. + */ + public static boolean containsEncoding(String encodKey) { + for (int i = 0; i < EncodingEnum.values().length; i++) + if (EncodingEnum.values()[i].key.equals(encodKey)) + return true; + return false; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/NewlineEnum.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/NewlineEnum.java new file mode 100644 index 000000000..94adb50dd --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/NewlineEnum.java @@ -0,0 +1,74 @@ +package cz.zcu.fav.kiv.editor.controller.options; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The NewlineEnum class is the enumerated list of chars defining ends of line in the + * output XSL stylesheet. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public enum NewlineEnum { + CRLF("cr+lf", "encoding.crlf"), LF("lf", "encoding.lf"), CR("cr", "encoding.cr"); + /** The resource message specifying every end of line */ + private String message; + + /** The key specifying every end of line */ + private String key; + + /** + * Initializes a newly created NewlineEnum with defined key and resource message. + * + * @param key + * the key of the encoding. + * @param mes + * the resource message of encoding. + */ + private NewlineEnum(String key, String mes) { + this.message = mes; + this.key = key; + } + + public String getMessage() { + return message; + } + + public String toString() { + return ResourceController.getMessage(message); + } + + /** + * Returns NewlineEnum object for the corresponding key. + * + * @param newLineKey + * the key of the end of line. + * @return the end of line for the input key. + */ + public static NewlineEnum getNewline(String newLineKey) { + for (int i = 0; i < NewlineEnum.values().length; i++) + if (NewlineEnum.values()[i].key.equals(newLineKey)) + return NewlineEnum.values()[i]; + return null; + } + + /** + * Specifies if the input end of line is among predefined ends of line NewlineEnum. + * + * @param encodKey + * the key of the end of line. + * @return true if the input end of line is present in the predefined ends of line + * NewlineEnum. + */ + public static boolean containsNewline(String encodKey) { + for (int i = 0; i < NewlineEnum.values().length; i++) + if (NewlineEnum.values()[i].key.equals(encodKey)) + return true; + return false; + } + + public String getKey() { + return key; + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/OptionController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/OptionController.java new file mode 100644 index 000000000..ec91e9912 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/OptionController.java @@ -0,0 +1,179 @@ +package cz.zcu.fav.kiv.editor.controller.options; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Locale; +import java.util.Properties; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.resource.LanguageEnum; + +/** + * The OptionController class is used for loading and saving editor options. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OptionController { + /** The properties storing options of the application */ + private static Properties property; + + /** + * Fills application properties property firstly by default option values and + * then by the option values loaded from the editor configuration file. The option values loaded + * from the configuration file rewrites the corresponding default option values. + * + * Then maps values from application properties property to the corresponding + * variables defined in OptionItems. + */ + public static void readOptions() { + property = new Properties(); + + loadDefaultOptions(); + readOptionFile(); + + mapEditorOptionItems(); + mapStylesheetOptionItems(); + mapBatchOptionItems(); + Log.info("info.progress_control.load_file", OptionItems.OPTION_PATH); + } + + /** + * Rewrites application properties property by default option values specifying + * stylesheet options. Then maps values from system properties property (only + * those specifying stylesheet options) to the corresponding variables defined in + * OptionItems. + */ + public static void setDefaultStylesheetOptions() { + OptionItems.getDefaultStylesheetSettings(property); + mapStylesheetOptionItems(); + } + + /** + * Rewrites application properties property by default option values specifying + * editor options. Then maps values from system properties property (only those + * specifying editor options) to the corresponding variables defined in OptionItems. + */ + public static void setDefaultEditorOptions() { + OptionItems.getDefaultEditorSettings(property); + mapEditorOptionItems(); + } + + /** + * Loads editor configuration files and saves its content to the system properties + * property. + */ + private static void readOptionFile() { + try { + property.loadFromXML(new FileInputStream(System.getProperty("user.dir") + + File.separator + OptionItems.OPTION_PATH)); + Log.info("info.option_controller.load_file"); + } catch (Exception ex) { + Log.warn("error.option_controller.file_not_found", ex, OptionItems.OPTION_PATH); + } + } + + /** + * Sets all default option values to the system properties property. + */ + private static void loadDefaultOptions() { + OptionItems.getDefaultEditorSettings(property); + OptionItems.getDefaultStylesheetSettings(property); + OptionItems.getDefaultBatchSettings(property); + Log.info("info.option_controller.load_default_option"); + } + + /** + * Maps values from system properties property to the corresponding variables + * defined in OptionItems. Maps only variables specifying editor options (LANGUAGE, + * XML_DEFINITION_PATH, ERASE_CONSOLE). + */ + private static void mapEditorOptionItems() { + OptionItems.LANGUAGE = LanguageEnum.parseLocale(property + .getProperty(OptionItems.KEY_LANGUAGE)); + Locale.setDefault(OptionItems.LANGUAGE); + + OptionItems.XML_DEFINITION_PATH = property.getProperty(OptionItems.KEY_XML_DEFINITION_PATH); + OptionItems.ERASE_CONSOLE = Boolean.parseBoolean(property + .getProperty(OptionItems.KEY_ERASE_CONSOLE)); + } + + /** + * Maps values from system properties property to the corresponding variables + * defined in OptionItems. Maps only variables specifying stylesheet options (ADD_FO_NAMESPACE, + * REARRANGE_SAVE, GENERATE_COMMENTS, + * USE_PARAM_SELECT, ENCODING, NEWLINE, + * STYLESHEET_VERSION, IMPORT_FILE). + */ + private static void mapStylesheetOptionItems() { + OptionItems.ADD_FO_NAMESPACE = Boolean.parseBoolean(property + .getProperty(OptionItems.KEY_ADD_FO_NAMESPACE)); + OptionItems.REARRANGE_SAVE = Boolean.parseBoolean(property + .getProperty(OptionItems.KEY_REARRANGE_SAVE)); + OptionItems.GENERATE_COMMENTS = Boolean.parseBoolean(property + .getProperty(OptionItems.KEY_GENERATE_COMMENTS)); + OptionItems.USE_PARAM_SELECT = Boolean.parseBoolean(property + .getProperty(OptionItems.KEY_USE_PARAM_SELECT)); + if (EncodingEnum.containsEncoding(property.getProperty(OptionItems.KEY_ENCODING))) + OptionItems.ENCODING = property.getProperty(OptionItems.KEY_ENCODING); + if (NewlineEnum.containsNewline(property.getProperty(OptionItems.KEY_NEWLINE))) + OptionItems.NEWLINE = NewlineEnum.getNewline(property + .getProperty(OptionItems.KEY_NEWLINE)); + OptionItems.STYLESHEET_VERSION = property.getProperty(OptionItems.KEY_STYLESHEET_VERSION); + OptionItems.IMPORT_FILE = property.getProperty(OptionItems.KEY_IMPORT_FILE); + + } + + /** + * Maps values from system properties property to the corresponding variables + * defined in OptionItems. Maps only variables specifying batch options (BATCH_FILE, + * SAVE_BEFORE_RUN). + */ + private static void mapBatchOptionItems() { + OptionItems.BATCH_FILE = property.getProperty(OptionItems.KEY_BATCH_FILE); + OptionItems.SAVE_BEFORE_RUN = Boolean.parseBoolean(property + .getProperty(OptionItems.KEY_SAVE_BEFORE_RUN)); + } + + /** + * Maps all variables defined in OptionItems to the corresponding values in the + * system properties property. + */ + private static void saveOptionItems() { + // editor options + property.put(OptionItems.KEY_LANGUAGE, OptionItems.LANGUAGE.toString()); + property.put(OptionItems.KEY_XML_DEFINITION_PATH, OptionItems.XML_DEFINITION_PATH); + property.put(OptionItems.KEY_ERASE_CONSOLE, OptionItems.ERASE_CONSOLE.toString()); + + // stylesheet options + property.put(OptionItems.KEY_ADD_FO_NAMESPACE, OptionItems.ADD_FO_NAMESPACE.toString()); + property.put(OptionItems.KEY_REARRANGE_SAVE, OptionItems.REARRANGE_SAVE.toString()); + property.put(OptionItems.KEY_GENERATE_COMMENTS, OptionItems.GENERATE_COMMENTS.toString()); + property.put(OptionItems.KEY_USE_PARAM_SELECT, OptionItems.USE_PARAM_SELECT.toString()); + property.put(OptionItems.KEY_ENCODING, OptionItems.ENCODING); + property.put(OptionItems.KEY_NEWLINE, OptionItems.NEWLINE.getKey()); + property.put(OptionItems.KEY_IMPORT_FILE, OptionItems.IMPORT_FILE); + property.put(OptionItems.KEY_STYLESHEET_VERSION, OptionItems.STYLESHEET_VERSION); + + // batch options + property.put(OptionItems.KEY_BATCH_FILE, OptionItems.BATCH_FILE); + property.put(OptionItems.KEY_SAVE_BEFORE_RUN, OptionItems.SAVE_BEFORE_RUN.toString()); + } + + /** + * Saves values in the system properties property to the editor configuration + * file. + */ + public static void storeOptionItems() { + saveOptionItems(); + try { + property.storeToXML(new FileOutputStream(OptionItems.OPTION_PATH), + OptionItems.OPTION_PATH); + Log.info("info.option_controller.save_file", OptionItems.OPTION_PATH); + } catch (Exception ex) { + Log.error("error.option_controller.store", ex); + } + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/OptionItems.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/OptionItems.java new file mode 100644 index 000000000..fc2ca2b70 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/options/OptionItems.java @@ -0,0 +1,200 @@ +package cz.zcu.fav.kiv.editor.controller.options; + +import java.util.Locale; +import java.util.Properties; + +import cz.zcu.fav.kiv.editor.controller.resource.LanguageEnum; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.TopMenu; + +/** + * The OptionItems class contains variables defining all options used in the + * application. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OptionItems { + /** The configuration file where options of the application are stored */ + public static final String OPTION_PATH = "options.xml"; + + /** The version of the application */ + public static final String APPLICATION_VERSION = "1.0"; + + /** The stylesheet XSL namespace */ + public static final String XSL_NAMESPACE = "http://www.w3.org/1999/XSL/Transform"; + + /** The stylesheet FO namespace */ + public static final String FO_NAMESPACE = "http://www.w3.org/1999/XSL/Format"; + + // ------------- editor options ------------------------ + + /** The property key of the language used in the editor */ + public static final String KEY_LANGUAGE = "fo_parameter_editor.language"; + + /** The language used in the editor */ + public static Locale LANGUAGE = LanguageEnum.getDefaultLocale(); + + /** + * Changes language used in the editor by the input language locale, if the language locale is + * supported by the editor. Updates all text expression in the application according to the new + * language. + * + * @param language + * the locale of the language that will be set as current editor language. + */ + public static void changeLanguage(Locale language) { + OptionItems.LANGUAGE = language; + ResourceController.changeInstance(); + TopMenu.changeLanguage(); + Locale.setDefault(language); + } + + /** The property key of the path where files with XML descriptions of FO parameters are stored */ + public static final String KEY_XML_DEFINITION_PATH = "fo_parameter_editor.xml_definition_path"; + + /** The path where files with XML descriptions of FO parameters are stored */ + public static String XML_DEFINITION_PATH; + + /** The property key of the flag specifying if the editor console is erased before every action */ + public static final String KEY_ERASE_CONSOLE = "fo_parameter_editor.erase_console"; + + /** The flag specifying if the editor console is erased before every action */ + public static Boolean ERASE_CONSOLE; + + // ------------------- stylesheet options --------------------- + + /** + * The property key of the flag specifying if the FO namespace definition is added to every new + * stylesheet file + */ + public static final String KEY_ADD_FO_NAMESPACE = "fo_parameter_editor.add_fo_namespace"; + + /** The flag specifying if the FO namespace definition is added to every new stylesheet file */ + public static Boolean ADD_FO_NAMESPACE; + + /** The property key of the flag specifying if the rearrange stylesheet saving is used */ + public static final String KEY_REARRANGE_SAVE = "fo_parameter_editor.rearrange_save"; + + /** The flag specifying if the rearrange stylesheet saving is used */ + public static Boolean REARRANGE_SAVE; + + /** The property key of the flag specifying if the comments in stylesheets are generated */ + public static final String KEY_GENERATE_COMMENTS = "fo_parameter_editor.generate_comments"; + + /** The flag specifying if the comments in stylesheets are generated */ + public static Boolean GENERATE_COMMENTS; + + /** + * The property key of the flag specifying if attribute select is used in the stylesheet + * parameter element + */ + public static final String KEY_USE_PARAM_SELECT = "fo_parameter_editor.use_param_select"; + + /** The flag specifying if attribute select is used in the stylesheet parameter element */ + public static Boolean USE_PARAM_SELECT; + + /** The property key of the actual editor encoding */ + public static final String KEY_ENCODING = "fo_parameter_editor.encoding"; + + /** The actual editor encoding */ + public static String ENCODING; + + /** The property key of the actual stylesheet end of line */ + public static final String KEY_NEWLINE = "fo_parameter_editor.newline"; + + /** The actual stylesheet end of line */ + public static NewlineEnum NEWLINE; + + // ----------------- xsl options ------------------------ + + /** + * The property key of the list specifying XSL stylesheet files imported to a new stylesheet + * file + */ + public static final String KEY_IMPORT_FILE = "fo_parameter_editor.xsl_import_file"; + + /** The list specifying XSL stylesheet files imported to a new stylesheet file */ + public static String IMPORT_FILE; + + /** The property key of stylesheet version */ + public static final String KEY_STYLESHEET_VERSION = "fo_parameter_editor.stylesheet_version"; + + /** The stylesheet version */ + public static String STYLESHEET_VERSION; + + // ----------------- batch options ------------------------ + + /** The property key of batch file path */ + public static final String KEY_BATCH_FILE = "fo_parameter_editor.batch_file"; + + /** The batch file path */ + public static String BATCH_FILE; + + /** + * The property key of flag specifying if the opened stylesheet is automatically saved before + * launching batch file + */ + public static final String KEY_SAVE_BEFORE_RUN = "fo_parameter_editor.save_before_run"; + + /** + * The flag specifying if the opened stylesheet is automatically saved before launching batch + * file + */ + public static Boolean SAVE_BEFORE_RUN; + + /** + * Fills application properties property by default option values. Maps only + * variables specifying editor options (LANGUAGE, + * XML_DEFINITION_PATH, ERASE_CONSOLE). + * + * @param defaultSettings + * the properties storing options of the application. + * @return the properties storing options of the application containing default editor options. + */ + public static Properties getDefaultEditorSettings(Properties defaultSettings) { + defaultSettings.put(KEY_LANGUAGE, LanguageEnum.getDefaultLocale()); + defaultSettings.put(KEY_XML_DEFINITION_PATH, "docbook-params"); + defaultSettings.put(KEY_ERASE_CONSOLE, "false"); + return defaultSettings; + } + + /** + * Fills application properties property by default option values. Maps only + * variables specifying stylesheet options (ADD_FO_NAMESPACE, + * REARRANGE_SAVE, GENERATE_COMMENTS, + * USE_PARAM_SELECT, ENCODING, NEWLINE, + * STYLESHEET_VERSION, IMPORT_FILE). + * + * @param defaultSettings + * the properties storing options of the application. + * @return the properties storing options of the application containing default stylesheet + * options. + */ + public static Properties getDefaultStylesheetSettings(Properties defaultSettings) { + defaultSettings.put(KEY_ADD_FO_NAMESPACE, "false"); + defaultSettings.put(KEY_REARRANGE_SAVE, "false"); + defaultSettings.put(KEY_GENERATE_COMMENTS, "true"); + defaultSettings.put(KEY_USE_PARAM_SELECT, "false"); + defaultSettings.put(KEY_ENCODING, EncodingEnum.UTF8.getKey()); + defaultSettings.put(KEY_NEWLINE, NewlineEnum.CRLF.getKey()); + defaultSettings.put(KEY_STYLESHEET_VERSION, "1.0"); + defaultSettings.put(KEY_IMPORT_FILE, + "http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl;"); + return defaultSettings; + } + + /** + * Fills application properties property by default other values. Maps only + * variables specifying batch options (BATCH_FILE, SAVE_BEFORE_RUN). + * + * @param defaultSettings + * the properties storing options of the application. + * @return the properties storing options of the application containing default batch options. + */ + public static Properties getDefaultBatchSettings(Properties defaultSettings) { + defaultSettings.put(KEY_BATCH_FILE, ""); + defaultSettings.put(KEY_SAVE_BEFORE_RUN, "true"); + return defaultSettings; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ErrorResourceController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ErrorResourceController.java new file mode 100644 index 000000000..28fc22af9 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ErrorResourceController.java @@ -0,0 +1,88 @@ +package cz.zcu.fav.kiv.editor.controller.resource; + +import java.text.MessageFormat; +import java.util.ResourceBundle; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The ErrorResourceController class contains methods for loading error text + * resources. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ErrorResourceController { + + /** The bundle of text resources */ + private ResourceBundle resource; + + /** The instance of the ErrorResourceController class */ + private static ErrorResourceController instance; + + /** + * Singleton constructor - gets the single instance of the ErrorResourceController class. + * + * @return the instance of the ErrorResourceController class. + */ + private static ErrorResourceController getInstance() { + if (instance == null) + instance = new ErrorResourceController(); + return instance; + } + + /** + * Initializes a newly created ErrorResourceController with error resource + * bundle. + */ + public ErrorResourceController() { + this.resource = ResourceBundle.getBundle(ResourceConst.ERROR_RESOURCE_PATH); + } + + /** + * Gets the error text resource for the input key. + * + * @param key + * the key of the error text resource. + * @return the error text resource for the input key. + */ + private String getString(String key) { + return resource.getString(key); + } + + /** + * Gets the error text resource for the input key. + * + * @param key + * the key of the error text resource. + * @return the error text resource for the input key. + */ + public static String getMessage(String key) { + try { + return ErrorResourceController.getInstance().getString(key); + } catch (Exception ex) { + Log.warn(ex); + return key; + } + } + + /** + * Gets the error text resource for the input key and arguments. + * + * @param key + * the key of the error text resource. + * @param args + * the arguments of the error text resource. + * @return the error text resource for the input key and arguments. + */ + public static String getMessage(String key, Object... args) { + try { + MessageFormat format = new MessageFormat(ErrorResourceController.getInstance() + .getString(key).replaceAll("'", "''")); + return format.format(args); + } catch (Exception ex) { + Log.warn(ex); + return key; + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/LanguageEnum.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/LanguageEnum.java new file mode 100644 index 000000000..0206584da --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/LanguageEnum.java @@ -0,0 +1,79 @@ +package cz.zcu.fav.kiv.editor.controller.resource; + +import java.util.Locale; + +/** + * The EncodingEnum class is the enumerated list of languages used in the + * application. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public enum LanguageEnum { + EN(Locale.ENGLISH), CS(new Locale("cs")); + + /** The locale specifying the language */ + private Locale locale; + + /** + * Initializes a newly created LanguageEnum with defined locale language. + * + * @param locale + * the locale of the language. + */ + private LanguageEnum(Locale locale) { + this.locale = locale; + } + + /** + * Returns title of the language loaded from resources ResourceController. + * + * @return the language title loaded from ResourceController. + */ + public String toString() { + return ResourceController.getMessage("language." + locale.toString()); + } + + /** + * Returns LanguageEnum language for corresponding locale. + * + * @param loc + * the locale of the language. + * @return the language for the input locale. + */ + public static LanguageEnum getLanguage(Locale loc) { + if (CS.locale.equals(loc)) + return CS; + return EN; + } + + /** + * Parses input string containing language and returns corresponding locale + * language. + * + * @param language + * the input text constant containing language. + * @return the locale corresponding to the input text constant. + */ + public static Locale parseLocale(String language) { + if ((language != null) && (language.equals(CS.getLocale().getLanguage()))) + return CS.getLocale(); + return EN.getLocale(); + } + + public Locale getLocale() { + return locale; + } + + /** + * Gets the current value of the default locale for this instance of the Java Virtual Machine. + * Returns only supported value - CS or EN. + * + * @return the locale of this instance of JVM. + */ + public static Locale getDefaultLocale() { + if (Locale.getDefault().getLanguage().equals(LanguageEnum.CS.getLocale().getLanguage())) + return LanguageEnum.CS.getLocale(); + return LanguageEnum.EN.getLocale(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ResourceConst.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ResourceConst.java new file mode 100644 index 000000000..92bf1e7f3 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ResourceConst.java @@ -0,0 +1,18 @@ +package cz.zcu.fav.kiv.editor.controller.resource; + +/** + * The ResourceConst class contains paths of the editor text resources. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ResourceConst { + /** The editor containing text resources */ + private final static String RESOURCE_DIR = "resources/"; + + /** The file containing the error text resources */ + public final static String ERROR_RESOURCE_PATH = RESOURCE_DIR + "ErrorResource"; + + /** The file containing the application text resources */ + public final static String TEXT_RESOURCE_PATH = RESOURCE_DIR + "TextResource"; +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ResourceController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ResourceController.java new file mode 100644 index 000000000..1638c3579 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/controller/resource/ResourceController.java @@ -0,0 +1,153 @@ +package cz.zcu.fav.kiv.editor.controller.resource; + +import java.io.UnsupportedEncodingException; +import java.text.MessageFormat; +import java.util.Enumeration; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; + +/** + * The ResourceController class contains methods for loading text resources. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ResourceController { + + /** The bundle of text resources */ + private static ResourceBundle resource; + + /** The instance of the ResourceController class */ + private static ResourceController instance; + + /** + * Singleton constructor - gets the instance of the ResourceController class. + * + * @return the instance of the ResourceController class. + */ + private static ResourceController getInstance() { + if (instance == null) + instance = new ResourceController(); + return instance; + } + + /** + * Changes the loaded resource bundle to the new bundle for actully chosen editor language. + */ + public static void changeInstance() { + instance = new ResourceController(); + } + + /** + * Initializes a newly created ResourceController with resource bundle for actual + * editor language. + */ + private ResourceController() { + ResourceController.resource = ResourceBundle.getBundle(ResourceConst.TEXT_RESOURCE_PATH, + OptionItems.LANGUAGE); + ResourceController.resource = createUtf8PropertyResourceBundle(ResourceController.resource); + } + + /** + * Gets the text resource of the actual language for the input key. + * + * @param key + * the key of the text resource. + * @return the text resource for the input key. + */ + private String getString(String key) { + return resource.getString(key); + } + + /** + * Gets the text resource of the actual language for the input key. + * + * @param key + * the key of the text resource. + * @return the text resource for the input key. + */ + public static String getMessage(String key) { + try { + return ResourceController.getInstance().getString(key); + } catch (Exception ex) { + Log.warn("error.resource_controller.missing_key", ex, key); + return key; + } + } + + /** + * Gets the text resource of the actual language for the input key and arguments. + * + * @param key + * the key of the text resource. + * @param args + * the arguments of the text resource. + * @return the text resource for the input key and arguments. + */ + public static String getMessage(String key, Object... args) { + try { + MessageFormat format = new MessageFormat(ResourceController.getInstance() + .getString(key).replaceAll("'", "''"), OptionItems.LANGUAGE); + return format.format(args); + } catch (Exception ex) { + Log.warn("error.resource_controller.missing_key", ex, key); + return key; + } + } + + /** + * Convert the input resource bundle to the UTF-8 resource bundle. + * + * @param bundle + * the resource bundle. + * @return the UTF-8 resource bundle converted from the input resource bundle. + */ + private static ResourceBundle createUtf8PropertyResourceBundle(ResourceBundle bundle) { + if (!(bundle instanceof PropertyResourceBundle)) + return bundle; + + return new Utf8PropertyResourceBundle((PropertyResourceBundle) bundle); + } + + /** + * The Utf8PropertyResourceBundle class define resource bundle that converts text + * resources from ISO-8859-1 to UTF-8 encoding. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + private static class Utf8PropertyResourceBundle extends ResourceBundle { + /** The property resource bundle */ + PropertyResourceBundle bundle; + + /** + * Initializes a newly created Utf8PropertyResourceBundle with define + * property resource bundle. + * + * @param bundle + * the property resource bundle. + */ + private Utf8PropertyResourceBundle(PropertyResourceBundle bundle) { + this.bundle = bundle; + } + + @Override + public Enumeration getKeys() { + return bundle.getKeys(); + } + + @Override + protected Object handleGetObject(String key) { + String value = (String) bundle.handleGetObject(key); + try { + return new String(value.getBytes("ISO-8859-1"), "UTF-8"); + } catch (UnsupportedEncodingException ex) { + Log.warn(ex); + return null; + } + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/displays/GraphicsFigure.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/displays/GraphicsFigure.java new file mode 100644 index 000000000..7085112fb --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/displays/GraphicsFigure.java @@ -0,0 +1,23 @@ +package cz.zcu.fav.kiv.editor.displays; + +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; + +/** + * The GraphicsFigure class represents a parent for all graphics figures. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public abstract class GraphicsFigure extends JPanel { + + private static final long serialVersionUID = -6123711841424326935L; + + /** + * Sets the list of parameter that are an input data source for the graphics figure. + * + * @param parameterList + */ + public abstract void setInputs(Parameter[] parameterList); +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/displays/PageFigure.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/displays/PageFigure.java new file mode 100644 index 000000000..4848bfc16 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/displays/PageFigure.java @@ -0,0 +1,90 @@ +package cz.zcu.fav.kiv.editor.displays; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import java.util.Observable; +import java.util.Observer; + +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; + +/** + * The PageFigure class represents a graphics figure illustrating dimesions of the + * paper. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class PageFigure extends GraphicsFigure implements Observer { + + private static final long serialVersionUID = 7211322657832007934L; + + /** The reference to the parameter representing paper width */ + private Parameter pageWidthParameter; + + /** The reference to the parameter representing paper height */ + private Parameter pageHeightParameter; + + /** The total size of graphics figure */ + private static final int SIZE = 140; + + /** The maximum size of the paper */ + private static final int PAPER_SIZE = 100; + + /** The actual width of the graphics figure illustrating paper */ + private int widthSize; + + /** The actual height of the graphics figure illustrating paper */ + private int heightSize; + + /** The color of the graphics figure illustrating paper */ + private static final Color PAPER_COLOR = new Color(0, 64, 128); + + public PageFigure() { + this.setPreferredSize(new Dimension(SIZE, SIZE)); + } + + /** + * Repaints the graphics figure according to actual parameter values. + */ + public void paintComponent(Graphics graphics) { + Graphics2D graphics2 = (Graphics2D) graphics; + super.paintComponent(graphics); + countSizes(); + + graphics2.setColor(PAPER_COLOR); + graphics2.fill(new Rectangle2D.Double((SIZE - PAPER_SIZE) / 2, (SIZE - PAPER_SIZE) / 2, + widthSize, heightSize)); + } + + @Override + public void setInputs(Parameter[] parameterList) { + this.pageWidthParameter = parameterList[0]; + this.pageWidthParameter.addObserver(this); + this.pageHeightParameter = parameterList[1]; + this.pageHeightParameter.addObserver(this); + } + + /** + * Method is called when some dependent parameter changes his value. Then the graphics figure + * values are updated according to parameter values. + */ + public void update(Observable arg0, Object arg1) { + this.repaint(); + } + + /** + * Counts new sizes of the graphics figure illustrating paper. New sizes are counted on the + * basis of parameter actual values. + */ + private void countSizes() { + Double pageWidth = Double.valueOf(pageWidthParameter.getType().getValue().replace(",", ".")); + double pageHeight = Double.valueOf(pageHeightParameter.getType().getValue().replace(",", ".")); + Double max = Math.max(pageWidth, pageHeight); + max /= PAPER_SIZE; + widthSize = (int) (pageWidth / max); + heightSize = (int) (pageHeight / max); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/MainFrame.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/MainFrame.java new file mode 100644 index 000000000..77a0129bc --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/MainFrame.java @@ -0,0 +1,192 @@ +package cz.zcu.fav.kiv.editor.graphics; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Image; + +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.ToolTipManager; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.OpenFile; +import cz.zcu.fav.kiv.editor.controller.MenuController; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.components.editor.EditorBody; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; +import cz.zcu.fav.kiv.editor.graphics.utils.FrameShower; + +/** + * The MainFrame class represents the main frame of the application. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public final class MainFrame extends JFrame { + + private static final long serialVersionUID = 2955560489556252043L; + + /** The instance of the MainFrame class */ + private static MainFrame instance; + + /** The main menu of the application */ + private static TopMenu menuBar; + + /** The data containing editor data structure */ + private ConfigData configData; + + /** The structure containing information about actually opened file */ + private OpenFile openFile; + + /** + * Initializes a newly created MainFrame. + */ + private MainFrame() { + } + + /** + * Initializes a newly created MainFrame with specified data. + * + * @param data + * the data containing editor data structure. + */ + private MainFrame(ConfigData data) { + this.configData = data; + this.openFile = new OpenFile(); + } + + /** + * Singleton constructor - gets the single instance of the MainFrame class. + * + * @return the single instance of MainFrame. + */ + public static MainFrame getInstance() { + if (instance == null) { + instance = new MainFrame(); + return instance; + } + return instance; + + } + + /** + * Creates the main application frame MainFrame with specified data. + * + * @param data + * the data containing editor data structure. + * @return newly created main application frame. + */ + public static MainFrame createFrame(ConfigData data) { + instance = new MainFrame(data); + return instance; + } + + /** + * This method is called from within the constructor to initialize the form. + */ + private void initComponents() { + + setTitle(ResourceController.getMessage("editor.title")); + + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + exitForm(evt); + } + + public void windowOpened(java.awt.event.WindowEvent evt) { + formWindowOpened(evt); + } + }); + + menuBar = new TopMenu(this); + setJMenuBar(menuBar); + + JComponent newContentPane = new EditorBody(configData.getSectionList()); + newContentPane.setOpaque(true); + this.getContentPane().add(newContentPane, BorderLayout.CENTER); + + ToolTipManager.sharedInstance().setInitialDelay(0); + + Dimension dim = getToolkit().getScreenSize(); + Dimension abounds = getPreferredSize(); + setLocation((dim.width - abounds.width) / 2, (dim.height - abounds.height) / 2); + + // Threadsafe startup of main frame + Runnable runner = new FrameShower(this); + EventQueue.invokeLater(runner); + } + + /** + * Reaction on frame window opening. + * + * @param evt + * the opened window. + */ + private void formWindowOpened(java.awt.event.WindowEvent evt) { + Image frameImage = EditorIcon.createEditorIcon(); + if (frameImage != null) { + setIconImage(frameImage); + } + } + + /** + * Reaction on frame window closing. + * + * @param evt + * the actually closing window. + */ + private void exitForm(java.awt.event.WindowEvent evt) { + MenuController.exitItem(); + shutDown(); + } + + /** + * Shuts down the main application frame - terminates the whole application. + * + */ + public void shutDown() { + System.exit(0); + } + + /** + * Initializes the form and launched it. + * + * @throws Exception + * if an error during initialization occurs. + */ + public void go() throws Exception { + initComponents(); + } + + public ConfigData getConfigData() { + return configData; + } + + public OpenFile getOpenFile() { + return openFile; + } + + /** + * Changes the title of the main frame. Sets the name of the actually opened file to the title. + * If the actually opened file has been modified then the title is changed. + * + */ + public void changeTitle() { + String title = ResourceController.getMessage("editor.title") + " - "; + if (openFile.isFileChanged()) + title += "*"; + if (openFile.getOpenFilePath() != null) + title += openFile.getOpenFilePath(); + setTitle(title); + } + + /** + * Specifies that the actually opened file OpenFile has been modified. + */ + public void setFileChanged() { + if (!openFile.isFileChanged()) + this.getOpenFile().setFileChanged(true); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/TopMenu.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/TopMenu.java new file mode 100644 index 000000000..9c58eb127 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/TopMenu.java @@ -0,0 +1,653 @@ +package cz.zcu.fav.kiv.editor.graphics; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.io.File; + +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JFileChooser; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; + +import cz.zcu.fav.kiv.editor.controller.MenuController; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.frames.AboutForm; +import cz.zcu.fav.kiv.editor.graphics.frames.ConfigInfoForm; +import cz.zcu.fav.kiv.editor.graphics.frames.HelpFrame; +import cz.zcu.fav.kiv.editor.graphics.options.OptionEditorDialog; +import cz.zcu.fav.kiv.editor.graphics.options.OptionStylesheetDialog; +import cz.zcu.fav.kiv.editor.graphics.utils.OverwriteFileDialog; +import cz.zcu.fav.kiv.editor.graphics.utils.SaveFileDialog; +import cz.zcu.fav.kiv.editor.graphics.utils.XmlFilter; +import cz.zcu.fav.kiv.editor.graphics.utils.XslFilter; +import cz.zcu.fav.kiv.editor.template.TemplateConst; + +/** + * The TopMenu class represents the main menu of the application. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TopMenu extends JMenuBar { + + private static final long serialVersionUID = 6053686624644714331L; + + /** The reference to the main frame MainFrame */ + private MainFrame frame; + + /* ---------------------- file menu ---------------------------- */ + + /** The file menu */ + private static JMenu fileMenu = new JMenu(); + + /** The item 'exit' from the file menu */ + private static JMenuItem exitFileMenuItem = new JMenuItem(); + + /** The submenu item of the item 'new' from the file menu */ + private static JMenu submenuNewFile = new JMenu(); + + /** The item 'new empty stylesheet' of the file submenu 'new' */ + private static JMenuItem newFileMenuEmptyItem = new JMenuItem(); + + /** The item 'new default stylesheet' of the file submenu 'new' */ + private static JMenuItem newFileMenuDefaultItem = new JMenuItem(); + + /** The item 'new user stylesheet' of the file submenu 'new' */ + private static JMenuItem newFileMenuStylesheetItem = new JMenuItem(); + + /** The item 'open' of the file menu */ + private static JMenuItem openFileMenuItem = new JMenuItem(); + + /** The item 'close' of the file menu */ + private static JMenuItem closeFileMenuItem = new JMenuItem(); + + /** The item 'save' of the file menu */ + private static JMenuItem saveFileMenuItem = new JMenuItem(); + + /** The item 'save as' of the file menu */ + private static JMenuItem saveAsFileMenuItem = new JMenuItem(); + + /* ---------------------- run menu ---------------------------- */ + /** The run menu */ + private static JMenu runMenu = new JMenu(); + + /** The item 'run batch' from the run menu */ + private static JMenuItem runBatchMenuItem = new JMenuItem(); + + /** The item 'select batch' from the run menu */ + private static JMenuItem selectBatchMenuItem = new JMenuItem(); + + /** The item 'save batch before' from the run menu */ + private static JCheckBoxMenuItem batchSaveBeforeMenuItem = new JCheckBoxMenuItem(); + + /* ---------------------- option menu ---------------------------- */ + /** The option menu */ + private static JMenu optionMenu = new JMenu(); + + /** The item 'stylesheet option' from the option menu */ + private static JMenuItem optionStylesheetMenuItem = new JMenuItem(); + + /** The item 'editor option' from the option menu */ + private static JMenuItem optionEditorMenuItem = new JMenuItem(); + + /* ---------------------- help menu ---------------------------- */ + /** The help menu */ + private static JMenu helpMenu = new JMenu(); + + /** The item 'help contents' from the help menu */ + private static JMenuItem helpWindowMenuItem = new JMenuItem(); + + /** The item 'about' from the help menu */ + private static JMenuItem aboutHelpMenuItem = new JMenuItem(); + + /** The item 'config info' from the help menu */ + private static JMenuItem configInfoMenuItem = new JMenuItem(); + + /** The file chooser */ + private JFileChooser fileChooser = new JFileChooser(); + + /** The batch file chooser */ + private JFileChooser batchFileChooser = new JFileChooser(); + + /** + * Initializes a newly created TopMenu of the main frame MainFrame. + * Creates all items of the menu. + * + * @param frame + * the main application frame. + */ + public TopMenu(MainFrame frame) { + this.frame = frame; + + /* ---------------------- file ---------------------------- */ + setMenuItem(fileMenu, "menu.file"); + + // new + submenuNewFile.setToolTipText(ResourceController.getMessage("menu_item.new.tooltip")); + setMenuItem(submenuNewFile, "menu_item.new"); + fileMenu.add(submenuNewFile); + + // new file - empty stylesheet + setMenuItem(newFileMenuEmptyItem, "menu_item.new_empty"); + newFileMenuEmptyItem.setToolTipText(ResourceController + .getMessage("menu_item.new_empty.tooltip")); + newFileMenuEmptyItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + newFileEmptyMenuItemActionPerformed(); + } + }); + submenuNewFile.add(newFileMenuEmptyItem); + + // new file - default stylesheet + setMenuItem(newFileMenuDefaultItem, "menu_item.new_default"); + newFileMenuDefaultItem.setToolTipText(ResourceController + .getMessage("menu_item.new_default.tooltip")); + newFileMenuDefaultItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + newFileDefaultMenuItemActionPerformed(); + } + }); + submenuNewFile.add(newFileMenuDefaultItem); + + // new file - user stylesheet + setMenuItem(newFileMenuStylesheetItem, "menu_item.new_stylesheet"); + newFileMenuStylesheetItem.setToolTipText(ResourceController + .getMessage("menu_item.new_stylesheet.tooltip")); + newFileMenuStylesheetItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + newFileStylesheetMenuItemActionPerformed(); + } + }); + submenuNewFile.add(newFileMenuStylesheetItem); + + // open + setMenuItem(openFileMenuItem, "menu_item.open"); + openFileMenuItem.setToolTipText(ResourceController.getMessage("menu_item.open.tooltip")); + openFileMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + openFileMenuItemActionPerformed(); + } + }); + fileMenu.add(openFileMenuItem); + + fileMenu.addSeparator(); + + // close + setMenuItem(closeFileMenuItem, "menu_item.close"); + closeFileMenuItem.setToolTipText(ResourceController.getMessage("menu_item.close.tooltip")); + closeFileMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + newFileEmptyMenuItemActionPerformed(); + } + }); + fileMenu.add(closeFileMenuItem); + + fileMenu.addSeparator(); + + // save + setMenuItem(saveFileMenuItem, "menu_item.save"); + saveFileMenuItem.setToolTipText(ResourceController.getMessage("menu_item.save.tooltip")); + saveFileMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + saveFileMenuItemActionPerformed(); + } + }); + saveFileMenuItem.setAccelerator(KeyStroke + .getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); + fileMenu.add(saveFileMenuItem); + + // save as + setMenuItem(saveAsFileMenuItem, "menu_item.save_as"); + saveAsFileMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.save_as.tooltip")); + saveAsFileMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + saveAsFileMenuItemActionPerformed(); + } + }); + fileMenu.add(saveAsFileMenuItem); + + fileMenu.addSeparator(); + + // exit + setMenuItem(exitFileMenuItem, "menu_item.exit"); + exitFileMenuItem.setToolTipText(ResourceController.getMessage("menu_item.exit.tooltip")); + exitFileMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + exitFileMenuItemActionPerformed(); + } + }); + fileMenu.add(exitFileMenuItem); + + this.add(fileMenu); + + /* ---------------------- run ---------------------------- */ + setMenuItem(runMenu, "menu_item.run"); + + setMenuItem(runBatchMenuItem, "menu_item.run_batch"); + runBatchMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.run_batch.tooltip")); + runBatchMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + runBatchMenuItemActionPerformed(); + } + }); + runBatchMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0)); + runMenu.add(runBatchMenuItem); + + setMenuItem(selectBatchMenuItem, "menu_item.run_edit_batch"); + selectBatchMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.run_edit_batch.tooltip")); + selectBatchMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + selectBatchMenuItemActionPerformed(); + } + }); + runMenu.add(selectBatchMenuItem); + + setMenuItem(batchSaveBeforeMenuItem, "menu_item.run_batch_save"); + batchSaveBeforeMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.run_batch_save.tooltip")); + batchSaveBeforeMenuItem.setSelected(OptionItems.SAVE_BEFORE_RUN); + batchSaveBeforeMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + batchSaveBeforeMenuItemActionPerformed(); + } + }); + runMenu.add(batchSaveBeforeMenuItem); + + this.add(runMenu); + + /* ---------------------- options ---------------------------- */ + setMenuItem(optionMenu, "menu_item.option"); + + setMenuItem(optionStylesheetMenuItem, "menu_item.option_save"); + optionStylesheetMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.option_save.tooltip")); + optionStylesheetMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + optionStylesheetMenuItemActionPerformed(); + } + }); + optionMenu.add(optionStylesheetMenuItem); + + setMenuItem(optionEditorMenuItem, "menu_item.option_editor"); + optionEditorMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.option_editor.tooltip")); + optionEditorMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + optionEditorMenuItemActionPerformed(); + } + }); + optionMenu.add(optionEditorMenuItem); + + this.add(optionMenu); + + /* ---------------------- help ---------------------------- */ + setMenuItem(helpMenu, "menu_item.help"); + + setMenuItem(helpWindowMenuItem, "menu_item.help_window"); + helpWindowMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.help_window.tooltip")); + helpWindowMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + helpWindowMenuItemActionPerformed(); + } + }); + helpMenu.add(helpWindowMenuItem); + + setMenuItem(configInfoMenuItem, "menu_item.config"); + configInfoMenuItem + .setToolTipText(ResourceController.getMessage("menu_item.config.tooltip")); + configInfoMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + configInfoMenuItemActionPerformed(); + } + }); + helpMenu.add(configInfoMenuItem); + + setMenuItem(aboutHelpMenuItem, "menu_item.about"); + aboutHelpMenuItem.setToolTipText(ResourceController.getMessage("menu_item.about.tooltip")); + aboutHelpMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + aboutHelpMenuItemActionPerformed(); + } + }); + helpMenu.add(aboutHelpMenuItem); + + this.add(helpMenu); + } + + /** + * Stores application options and terminates the application. + */ + private void exitFileMenuItemActionPerformed() { + MenuController.exitItem(); + frame.shutDown(); + } + + /** + * Shows the dialog with information about the application. + */ + private void aboutHelpMenuItemActionPerformed() { + AboutForm.showDialog(); + } + + /** + * Shows the dialog asking if the actually opened stylesheet should be saved. If the user choses + * to save the stylesheet then the method saveFileMenuItemActionPerformed() is + * called and the stylesheet is saved. + * + * @return if the actual stylesheet was saved. + */ + private boolean saveOpenedStylesheet() { + if (frame.getOpenFile().getOpenFilePath() == null && frame.getOpenFile().isFileChanged()) { + SaveFileDialog questionDial = SaveFileDialog.showDialog(frame); + if (questionDial.getAnswer() == null) + return false; + if (questionDial.getAnswer()) + return saveFileMenuItemActionPerformed(); + } + return true; + } + + /** + * Saves the actully opened stylesheet (if it is required). Then creates a new empty stylesheet. + */ + private void newFileEmptyMenuItemActionPerformed() { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (saveOpenedStylesheet()) + MenuController.newFileEmptyItem(frame.getConfigData(), frame.getOpenFile()); + } + }); + } + + /** + * Saves the actully opened stylesheet (if it is required). Then creates a new stylesheet + * according to the default stylesheet template. + */ + private void newFileDefaultMenuItemActionPerformed() { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (saveOpenedStylesheet()) + MenuController.newFileDefaultItem(frame.getConfigData(), frame.getOpenFile()); + } + }); + } + + /** + * Saves the actully opened stylesheet (if it is required). Then shows the open file dialog and + * user is asked to choose a user stylesheet template. Afterwards creates a new stylesheet + * according to the chosen user template. + */ + private void newFileStylesheetMenuItemActionPerformed() { + if (saveOpenedStylesheet()) { + fileChooser.setFileFilter(new XmlFilter()); + fileChooser.setSelectedFile(null); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir") + + File.separator + TemplateConst.CONF_FILE_TEMPLATE_DIR)); + int returnVal = fileChooser.showOpenDialog(frame); + if (returnVal == JFileChooser.APPROVE_OPTION) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + MenuController.newFileStylesheetItem(frame.getConfigData(), frame + .getOpenFile(), fileChooser.getSelectedFile().getPath().toString()); + } + }); + } + } + } + + /** + * Saves the actully opened stylesheet (if it is required). Afterwards shows the open file + * dialog and user is asked to choose the stylesheet file to open. Then opens the choosen + * stylesheet file. + */ + private void openFileMenuItemActionPerformed() { + if (saveOpenedStylesheet()) { + fileChooser.setFileFilter(new XslFilter()); + fileChooser.setSelectedFile(null); + int returnVal = fileChooser.showOpenDialog(frame); + if (returnVal == JFileChooser.APPROVE_OPTION) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + MenuController.openFileItem(frame.getConfigData(), fileChooser + .getSelectedFile().getPath().toString(), frame.getOpenFile()); + } + }); + } + } + } + + /** + * Saves the actually opened stylesheet file. If the stylesheet has not defined its name then + * the method saveAsFileMenuItemActionPerformed() is called. + * + * @return true if the stylesheet was saved. + */ + private boolean saveFileMenuItemActionPerformed() { + if (this.frame.getOpenFile().getOpenFilePath() == null) + return saveAsFileMenuItemActionPerformed(); + else + MenuController.saveFileItem(frame.getConfigData(), frame.getOpenFile()); + return true; + } + + /** + * Saves the actually opened stylesheet file under the chosen name. Firstly shows the save file + * dialog and user is asked to choose a new file name or an existing file. If user chooses the + * existing file, then he must approve that he really wants to rewrite the existing file. + * Finally the stylesheet is saved under the chosen name. + * + * @return true if the stylesheet was saved. + */ + private boolean saveAsFileMenuItemActionPerformed() { + fileChooser.setFileFilter(new XslFilter()); + fileChooser.setSelectedFile(null); + int returnVal = fileChooser.showSaveDialog(frame); + if (returnVal == JFileChooser.APPROVE_OPTION) { + if (fileChooser.getSelectedFile().exists()) { + OverwriteFileDialog questionDial = OverwriteFileDialog.showDialog(frame); + if (!questionDial.getAnswer()) + return false; + } + MenuController.saveAsFileItem(frame.getConfigData(), fileChooser.getSelectedFile() + .getPath().toString(), frame.getOpenFile()); + return true; + + } + return false; + } + + /** + * Shows the dialog with stylesheet options. + */ + private void optionStylesheetMenuItemActionPerformed() { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + OptionStylesheetDialog.showDialog(); + } + }); + } + + /** + * Shows the dialog with editor options. + */ + private void optionEditorMenuItemActionPerformed() { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + OptionEditorDialog.showDialog(); + } + }); + } + + /** + * Shows the dialog with information about configuration files. + */ + private void configInfoMenuItemActionPerformed() { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + ConfigInfoForm.showDialog(); + } + }); + } + + /** + * Launches the batch file for the actually opened XSL stylesheet. + */ + private void runBatchMenuItemActionPerformed() { + if (OptionItems.SAVE_BEFORE_RUN) { + if (!saveFileMenuItemActionPerformed()) + return; + } else { + if (!saveOpenedStylesheet()) + return; + } + MenuController.runBatchFile(frame.getOpenFile()); + } + + /** + * Shows the open file dialog and user is asked to choose a batch file. Then the chosen path to + * the batch file is stored. + */ + private void selectBatchMenuItemActionPerformed() { + batchFileChooser.setFileFilter(null); + batchFileChooser.setSelectedFile(null); + if (OptionItems.BATCH_FILE.compareTo("") != 0) + batchFileChooser.setSelectedFile(new File(OptionItems.BATCH_FILE)); + int returnVal = batchFileChooser.showOpenDialog(frame); + if (returnVal == JFileChooser.APPROVE_OPTION) { + OptionItems.BATCH_FILE = batchFileChooser.getSelectedFile().getAbsolutePath(); + } + } + + /** + * Changes if the actually opened XSL stylesheet should be automatically saved before launching + * of the batch file. If the item is selected, then the XSL stylesheet is automatically saved. + */ + private void batchSaveBeforeMenuItemActionPerformed() { + OptionItems.SAVE_BEFORE_RUN = batchSaveBeforeMenuItem.isSelected(); + } + + /** + * Shows the dialog with help content. + * + */ + private void helpWindowMenuItemActionPerformed() { + HelpFrame.getInstance().createHelp(); + } + + /** + * Changes the text titles of all menu items according to the actual application language. + */ + public static void changeLanguage() { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + setMenuItem(fileMenu, "menu.file"); + + //new + setMenuItem(submenuNewFile, "menu_item.new"); + submenuNewFile.setToolTipText(ResourceController.getMessage("menu_item.new.tooltip")); + + setMenuItem(newFileMenuEmptyItem, "menu_item.new_empty"); + newFileMenuEmptyItem.setToolTipText(ResourceController + .getMessage("menu_item.new_empty.tooltip")); + + setMenuItem(newFileMenuDefaultItem, "menu_item.new_default"); + newFileMenuDefaultItem.setToolTipText(ResourceController + .getMessage("menu_item.new_default.tooltip")); + + setMenuItem(newFileMenuStylesheetItem, "menu_item.new_stylesheet"); + newFileMenuStylesheetItem.setToolTipText(ResourceController + .getMessage("menu_item.new_stylesheet.tooltip")); + + //open + setMenuItem(openFileMenuItem, "menu_item.open"); + openFileMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.open.tooltip")); + //close + setMenuItem(closeFileMenuItem, "menu_item.close"); + closeFileMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.close.tooltip")); + + //save + setMenuItem(saveAsFileMenuItem, "menu_item.save_as"); + saveAsFileMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.save_as.tooltip")); + + setMenuItem(saveFileMenuItem, "menu_item.save"); + saveFileMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.save.tooltip")); + + //exit + setMenuItem(exitFileMenuItem, "menu_item.exit"); + exitFileMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.exit.tooltip")); + + //run + setMenuItem(runMenu, "menu_item.run"); + + setMenuItem(runBatchMenuItem, "menu_item.run_batch"); + runBatchMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.run_batch.tooltip")); + + setMenuItem(selectBatchMenuItem, "menu_item.run_edit_batch"); + selectBatchMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.run_edit_batch.tooltip")); + + setMenuItem(batchSaveBeforeMenuItem, "menu_item.run_batch_save"); + batchSaveBeforeMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.run_batch_save.tooltip")); + + //options + setMenuItem(optionMenu, "menu_item.option"); + + setMenuItem(optionStylesheetMenuItem, "menu_item.option_save"); + optionStylesheetMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.option_save.tooltip")); + + setMenuItem(optionEditorMenuItem, "menu_item.option_editor"); + optionEditorMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.option_editor.tooltip")); + + //help + setMenuItem(helpMenu, "menu_item.help"); + + setMenuItem(helpWindowMenuItem, "menu_item.help_window"); + helpWindowMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.help_window.tooltip")); + + setMenuItem(configInfoMenuItem, "menu_item.config"); + configInfoMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.config.tooltip")); + setMenuItem(aboutHelpMenuItem, "menu_item.about"); + aboutHelpMenuItem.setToolTipText(ResourceController + .getMessage("menu_item.about.tooltip")); + } + }); + } + + /** + * Sets the name of the menu item. Assignes the item title from the resource bundle + * ResourceController according to the resource key. + * + * @param item + * the item of the menu. + * @param key + * the resource key specifying the item title. + */ + private static void setMenuItem(JMenuItem item, String key) { + String message = ResourceController.getMessage(key); + int pos = message.indexOf("&"); + if ((pos >= 0) && ((pos + 1) < message.length())) { + item.setMnemonic(message.charAt(pos + 1)); + message = message.replaceAll("&", ""); + } + item.setText(message); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/CheckBox.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/CheckBox.java new file mode 100644 index 000000000..465899b50 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/CheckBox.java @@ -0,0 +1,88 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JCheckBox; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; +import cz.zcu.fav.kiv.editor.utils.TagParser; + +/** + * The CheckBox class is the component check-box used for displaying + * parameter with boolean values - false (no) and true (yes). + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class CheckBox extends JCheckBox implements Observer, ItemListener { + + private static final long serialVersionUID = -6605204557074361719L; + + /** The parameter type which values the component displays */ + private Type type; + + /** + * Initializes a newly created CheckBox with the parameter type. + * + * @param type + * the parameter type. + */ + public CheckBox(Type type) { + setSelected(type.getValue()); + + this.type = type; + type.addObserver(this); + this.addItemListener(this); + } + + /** + * Selects or deselects the check-box according to the input value. If the input value is not + * valid boolean value, the check-box keeps its previous value. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + if (!setSelected(value.toString())) { + type.changeValue(TagParser.convertBoolean(this.isSelected())); + MessageWriter.writeWarning(ResourceController.getMessage( + "error.component.update_value", type.getOwnerName(), value)); + } + } + + /** + * Action performed when the check-box is selected or deselected. Assignes a new estate to the + * parameter type. + * + * @param event + * the item event. + */ + public void itemStateChanged(ItemEvent event) { + type.changeValue(TagParser.convertBoolean(this.isSelected())); + MainFrame.getInstance().setFileChanged(); + } + + /** + * Selects or deselects the check-box according to the input value. + * + * @param newValue + * the new boolean input value. + * @return true if the input value is valid boolean value. + */ + private boolean setSelected(String newValue) { + Boolean value = TagParser.parseBoolean(newValue); + if (value != null) { + this.setSelected(value); + return true; + } else + return false; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ColorChooser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ColorChooser.java new file mode 100644 index 000000000..f5a7fccbd --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ColorChooser.java @@ -0,0 +1,251 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JColorChooser; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; +import cz.zcu.fav.kiv.editor.utils.TagParser; + +/** + * The ColorChooser class is the component used for choosing colors from the list of + * colors or from the color palette. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ColorChooser extends JPanel implements ActionListener, ItemListener, Observer { + + private static final long serialVersionUID = -2515399651281284846L; + + /** The width of the rectangle displaying the actually chosen color */ + public static final int COLOR_RECT_WIDTH = 25; + + /** The height of the rectangle displaying the actually chosen color */ + public static final int COLOR_RECT_HEIGHT = 23; + + /** The size of the button displaying the dialog with color palette */ + public static final int BUTTON_SIZE = 20; + + /** The width of the empty gap components */ + private static final int EMPTY_GAP_WIDTH = 10; + + /** The height of the empty gap components */ + private static final int EMPTY_GAP_HEIGHT = 0; + + /** The list of predefined colors */ + private JComboBox colorBox; + + /** The button displaying the dialog with color palette */ + private JButton colorButton; + + /** The color palette enabling choosing of colors */ + private JColorChooser colorChooser; + + /** The rectangle displaying the actually chosen color */ + private ColorRect colorRect; + + /** The dialog displaying the color palette */ + private JDialog dialog; + + /** The parameter type which values the component displays */ + private Type type; + + /** The actually choosen color */ + private Color color; + + /** + * Initializes a newly created ColorChooser with the parameter type. + * + * @param type + * the parameter type. + */ + public ColorChooser(Type type) { + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + this.type = type; + type.addObserver(this); + + // color combo-box + colorBox = new JComboBox(type.getValueList().keySet().toArray()); + this.color = getColor(type.getValue()); + setSelectedColor(type.getValue()); + colorBox.setEditable(true); + colorBox.addItemListener(this); + this.add(colorBox); + + this.add(Box.createRigidArea(new Dimension(EMPTY_GAP_WIDTH, EMPTY_GAP_HEIGHT))); + + // button displaying the color palette + colorButton = new JButton(EditorIcon.createColorIcon()); + colorButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); + colorButton.addActionListener(this); + this.add(colorButton); + + this.add(Box.createRigidArea(new Dimension(EMPTY_GAP_WIDTH, EMPTY_GAP_HEIGHT))); + + // color rectangle + colorRect = new ColorRect(); + this.add(colorRect); + } + + /** + * Sets a new color according to the input value. If the input value is not valid color value, + * then the previous color is kept. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + Color newColor = getColor(value.toString()); + if (newColor != null) { + setSelectedColor(value); + this.color = newColor; + } else { + type.changeValue(TagParser.createColor(color)); + MessageWriter.writeWarning(ResourceController.getMessage( + "error.component.update_value", type.getOwnerName(), value)); + } + } + + /** + * Action performed when the button is pressed, it displays the dialog with color palette. + * + * @param event + * the item event. + */ + public void actionPerformed(ActionEvent event) { + colorChooser = new JColorChooser(color); + colorChooser.setPreviewPanel(new JPanel()); + + dialog = JColorChooser.createDialog(this, ResourceController + .getMessage("component.color_editor.title"), true, colorChooser, new ActionColor(), + null); + dialog.setVisible(true); + } + + /** + * Action performed when a color from the combo-box list has been selected or a new one is + * inserted. Assignes a new value to the parameter type. If the inserted color is + * invalid, then the previous color is kept. + * + * @param event + * the item event. + */ + public void itemStateChanged(ItemEvent event) { + if ((event.getStateChange() & ItemEvent.ITEM_STATE_CHANGED) != 0) { + Color col = getColor(colorBox.getSelectedItem().toString()); + if (col != null) { + type.changeValue((String) colorBox.getSelectedItem()); + this.color = col; + colorRect.repaint(); + MainFrame.getInstance().setFileChanged(); + } else { + setSelectedColor(type.getValue()); + } + } + } + + /** + * Selects the input color in the list if the list contains it or adds the new color to the + * list. + * + * @param newColor + * the actually selected color. + */ + private void setSelectedColor(Object newColor) { + for (int i = 0; i < colorBox.getItemCount(); i++) { + if (colorBox.getItemAt(i).equals(type.getKeyFromValue(newColor.toString())) + || colorBox.getItemAt(i).equals(newColor.toString())) { + colorBox.setSelectedIndex(i); + return; + } + } + if (colorBox.getItemCount() > type.getValueList().size()) + colorBox.removeItemAt(0); + colorBox.insertItemAt(newColor, 0); + colorBox.setSelectedIndex(0); + } + + /** + * The ActionColor inner class represents the action performed when a color is + * choosen in the color palette. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class ActionColor implements ActionListener { + public void actionPerformed(ActionEvent event) { + color = colorChooser.getColor(); + + String colStr = TagParser.createColor(color); + dialog.dispose(); + type.changeValue(colStr); + setSelectedColor(colStr); + MainFrame.getInstance().setFileChanged(); + } + } + + /** + * Creates Color from the string containing a color in the hexadecimal format #rrggbb + * or containing a color name. + * + * @param color + * the string containing a color in the hexadecimal format #rrggbb or containing a + * color name. + * @return the color parsed from the string. + */ + private Color getColor(String color) { + if (type.getValueList().get(color) != null) + return TagParser.parseColor(type.getValueList().get(color)); + else + return TagParser.parseColor(color); + } + + /** + * The ColorRect inner class represents the rectangle displaying actually choosen + * color. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class ColorRect extends JPanel { + + private static final long serialVersionUID = 5631478801104148565L; + + /** + * Initializes a newly created ColorRectclass. + */ + public ColorRect() { + this.setPreferredSize(new Dimension(COLOR_RECT_WIDTH, COLOR_RECT_HEIGHT)); + } + + /** + * Changes the color of the rectangle according to the actually chosen color. + */ + public void paintComponent(Graphics graphics) { + super.paintComponent(graphics); + graphics.setColor(color); + graphics.fillRect(0, 0, COLOR_RECT_WIDTH, COLOR_RECT_HEIGHT); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBox.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBox.java new file mode 100644 index 000000000..07dd0c535 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBox.java @@ -0,0 +1,77 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JComboBox; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The ComboBox class is the component combo-box used for displaying a + * list of predefined values of a parameter. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ComboBox extends JComboBox implements Observer, ActionListener { + + private static final long serialVersionUID = -151909741397111994L; + + /** The parameter type which values the component displays */ + private Type type; + + /** + * Initializes a newly created ComboBox with the parameter type. + * + * @param type + * the parameter type. + */ + public ComboBox(Type type) { + super(type.getValueList().values().toArray()); + + this.setSelectedItem(type.getValueList().get(type.getValue())); + + this.type = type; + type.addObserver(this); + this.addActionListener(this); + } + + /** + * Selects the input value in the list if the list contains it. If the input value is not in the + * list then the previously selected item is left as selected. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + String newValue = type.getValueList().get(value.toString()); + if (newValue != null) + this.setSelectedItem(newValue); + else { + type.changeValue((String) type.getValueList().get(this.getSelectedItem())); + MessageWriter.writeWarning(ResourceController.getMessage( + "error.component.update_value", type.getOwnerName(), value)); + } + } + + /** + * Action performed when an item of the combo-box list has been selected. Assignes a new value + * to the parameter type. + * + * @param event + * the action event. + */ + public void actionPerformed(ActionEvent event) { + type.changeValue((String) type.getKeyFromValue(this.getSelectedItem().toString())); + MainFrame.getInstance().setFileChanged(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBoxEdit.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBoxEdit.java new file mode 100644 index 000000000..e3f6fb1f0 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBoxEdit.java @@ -0,0 +1,93 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JComboBox; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The ComboBoxEdit class is the component combo-box used for displaying a + * list of predefined values of a parameter. It enables to insert a new value to the list. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ComboBoxEdit extends JComboBox implements Observer, ItemListener { + + private static final long serialVersionUID = -5008301149696067333L; + + /** The parameter type which values the component displays */ + private Type type; + + /** + * Initializes a newly created ComboBoxEdit with the parameter type. + * + * @param type + * the parameter type. + */ + public ComboBoxEdit(Type type) { + super(type.getValueList().values().toArray()); + + this.type = type; + // selected value + setSelectedIndex(type.getValue()); + + type.addObserver(this); + this.setEditable(true); + this.addItemListener(this); + } + + /** + * Selects the input parameter value in the list if the list contains it. If the input value is + * not in the list then inserts it to the list. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + setSelectedIndex(value); + } + + /** + * Action performed when an item in the combo-box list has been selected or a new one has been + * inserted. Assignes a new value to the parameter type. + * + * @param event + * the item event. + */ + public void itemStateChanged(ItemEvent event) { + if ((event.getStateChange() & ItemEvent.ITEM_STATE_CHANGED) != 0) { + String newValue = type.getDefaultValue().getKeyFromValue(this.getSelectedItem().toString()); + if (newValue != null) + type.changeValue(newValue); + else + type.changeValue(this.getSelectedItem().toString()); + MainFrame.getInstance().setFileChanged(); + } + } + + /** + * Selects the input value in the list if the list contains it. If the input value is not in the + * list then inserts it to the list. + * + * @param obj + * the input parameter value. + */ + private void setSelectedIndex(Object obj) { + for (int i = 0; i < this.getItemCount(); i++) { + if (this.getItemAt(i).equals(type.getValueList().get(obj))) { + this.setSelectedIndex(i); + return; + } + } + this.addItem(obj); + this.setSelectedIndex(this.getItemCount() - 1); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBoxUnit.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBoxUnit.java new file mode 100644 index 000000000..7cb450438 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/ComboBoxUnit.java @@ -0,0 +1,68 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JComboBox; + +import cz.zcu.fav.kiv.editor.beans.types.Unit; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The ComboBoxUnit class is the component combo-box used for displaying a + * list of predefined units of a parameter. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ComboBoxUnit extends JComboBox implements Observer, ActionListener { + + private static final long serialVersionUID = -5900614666148972102L; + + /** The parameter unit which values the component displays */ + private Unit unit; + + /** + * Initializes a newly created ComboBoxUnit with the parameter unit. + * + * @param unit + * the parameter unit. + */ + public ComboBoxUnit(Unit unit) { + super(unit.getValueList().toArray()); + int selected = unit.getValueList().indexOf(unit.getValue()); + if (selected >= 0) + this.setSelectedIndex(selected); + this.unit = unit; + unit.addObserver(this); + this.addActionListener(this); + } + + /** + * Selects the input value in the list. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + int selected = unit.getValueList().indexOf(value.toString()); + if (selected >= 0) + this.setSelectedIndex(selected); + } + + /** + * Action performed when an item in the combo-box list has been selected. Assignes a new value + * to the parameter unit. + * + * @param event + * the item event. + */ + public void actionPerformed(ActionEvent event) { + unit.changeValue((String) this.getSelectedItem()); + MainFrame.getInstance().setFileChanged(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/FileChooser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/FileChooser.java new file mode 100644 index 000000000..a9ef78e95 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/FileChooser.java @@ -0,0 +1,108 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The FileChooser class is the component text-field and button + * used for choosing a directory path with the file-chooser. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class FileChooser extends JPanel implements Observer, ActionListener { + + private static final long serialVersionUID = -151909741397111994L; + + /** The width of the text-field */ + private static final int WIDTH = 180; + + /** The width of the empty gap between the text-field and the button */ + private static final int EMPTY_GAP_WIDTH = 10; + + /** The height of the empty gap between the text-field and the button */ + private static final int EMPTY_GAP_HEIGHT = 0; + + /** The parameter type which values the component displays */ + private Type type; + + /** The text-field displaying directory path */ + private JTextField textField; + + /** The file-chooser used for choosing a directory path */ + JFileChooser fileChooser = new JFileChooser(); + + /** + * Initializes a newly created FileChooser with the parameter type. + * + * @param type + * the parameter type. + */ + public FileChooser(Type type) { + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + + // text-field + textField = new JTextField(type.getValue()); + textField.setPreferredSize(new Dimension(WIDTH, textField.getPreferredSize().height)); + this.add(textField); + + this.add(Box.createRigidArea(new Dimension(EMPTY_GAP_WIDTH, EMPTY_GAP_HEIGHT))); + + // chooser button + JButton chooseButton = new JButton(ResourceController + .getMessage("option_editor.xml_definition_path.button")); + chooseButton.addActionListener(this); + this.add(chooseButton); + + this.type = type; + type.addObserver(this); + } + + /** + * Sets a new parameter value to the text-field. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + textField.setText(value.toString()); + } + + /** + * Action performed when the button is pressed, it displays the file-chooser enabling to choose + * a direcotory path. Assignes a new value to the parameter type. + * + * @param event + * the item event. + */ + public void actionPerformed(ActionEvent event) { + File directory = new File(textField.getText()); + if (directory.exists()) + fileChooser.setCurrentDirectory(directory); + + int returnVal = fileChooser.showOpenDialog(MainFrame.getInstance()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + textField.setText(fileChooser.getSelectedFile().getPath()); + type.changeValue(fileChooser.getSelectedFile().getPath()); + MainFrame.getInstance().setFileChanged(); + } + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/RadioButton.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/RadioButton.java new file mode 100644 index 000000000..09ae35fcf --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/RadioButton.java @@ -0,0 +1,103 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Iterator; +import java.util.Map; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.ButtonGroup; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The RadioButton class is the component containing a group of radio-buttons + * used for choosing one of predefined values. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class RadioButton extends JPanel implements Observer, ActionListener { + + private static final long serialVersionUID = 7530690462466562523L; + + /** The parameter type which values the component displays */ + private Type type; + + /** The list of radio-buttons */ + private JRadioButton[] radioList; + + /** + * Initializes a newly created RadioButton with the parameter type. + * + * @param type + * the parameter type. + */ + public RadioButton(Type type) { + this.setLayout(new GridLayout(0, 3)); + this.type = type; + ButtonGroup group = new ButtonGroup(); + radioList = new JRadioButton[type.getValueList().size()]; + + int i = 0; + for (Iterator it = type.getValueList().entrySet().iterator(); it.hasNext();) { + Map.Entry e = (Map.Entry) it.next(); + radioList[i] = new JRadioButton(e.getKey().toString()); + radioList[i].setName(e.getValue().toString()); + radioList[i].addActionListener(this); + if (e.getValue().equals(type.getValue())) + radioList[i].setSelected(true); + group.add(radioList[i]); + this.add(radioList[i]); + i++; + } + type.addObserver(this); + } + + /** + * Selects one radio-button representing the input value. If the input value is not among the + * values of radio-buttons, then the previous selection of a radio-button is kept. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + boolean selected = false; + for (int i = 0; i < radioList.length; i++) { + if (radioList[i].getName().equals(value.toString())) { + radioList[i].setSelected(true); + selected = true; + break; + } + } + if (!selected) { + for (int i = 0; i < radioList.length; i++) { + if (radioList[i].isSelected()) + type.changeValue(radioList[i].getName()); + } + MessageWriter.writeWarning(ResourceController.getMessage( + "error.component.update_value", type.getOwnerName(), value)); + } + } + + /** + * Action performed when one of radio-buttons is selected. Assignes a new value to the parameter + * type. + * + * @param event + * the item event. + */ + public void actionPerformed(ActionEvent event) { + type.changeValue(((JRadioButton) event.getSource()).getName()); + MainFrame.getInstance().setFileChanged(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/SpinnerFloat.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/SpinnerFloat.java new file mode 100644 index 000000000..9fc6f5cc8 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/SpinnerFloat.java @@ -0,0 +1,113 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.text.DecimalFormat; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The SpinnerFloat class is the component spinner used for displaying and + * changing decimal numbers. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class SpinnerFloat extends JSpinner implements Observer, ChangeListener { + + private static final long serialVersionUID = 3179056596219532766L; + + /** The step of the spinner */ + private static final double STEP = 0.1; + + /** The number of columns in the spinner */ + private static final int SPINNER_SIZE = 4; + + /** The number format used for converting a decimal value to the string */ + private static final DecimalFormat formatDouble = new DecimalFormat("0.##"); + + /** The parameter type which values the component displays */ + private Type type; + + /** + * Creates the spinner used for displaying and changing decimal numbers. + * + * @param type + * the parameter type. + * @return the newly created spinner used form decimal numbers. + */ + public static SpinnerFloat createSpinnerFloat(Type type) { + SpinnerNumberModel spinnerModel = new SpinnerNumberModel(); + spinnerModel.setValue(convertDouble(type.getValue())); + spinnerModel.setStepSize(STEP); + return new SpinnerFloat(spinnerModel, type); + } + + /** + * Initializes a newly created SpinnerFloat with the parameter type and spinner + * model. + * + * @param spinnerModel + * the spinner model. + * @param type + * the parameter type. + */ + private SpinnerFloat(SpinnerNumberModel spinnerModel, Type type) { + super(spinnerModel); + this.type = type; + type.addObserver(this); + this.addChangeListener(this); + ((JSpinner.DefaultEditor) this.getEditor()).getTextField().setColumns(SPINNER_SIZE); + } + + /** + * Updates the spinner number value according to the input value. If the input value is not a + * valid decimal number, then the previous spinner value is kept. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + try { + ((SpinnerNumberModel) this.getModel()).setValue(convertDouble(value.toString())); + } catch (NumberFormatException ex) { + type.changeValue(formatDouble.format(convertDouble(this.getModel().getValue() + .toString()))); + MessageWriter.writeWarning(ResourceController.getMessage( + "error.component.update_value", type.getOwnerName(), value)); + } + } + + /** + * Action performed when the spinner value is changed. Assignes a new value to the parameter + * type. + * + * @param event + * the item event. + */ + public void stateChanged(ChangeEvent event) { + type.changeValue(formatDouble.format(convertDouble(this.getModel().getValue().toString()))); + MainFrame.getInstance().setFileChanged(); + } + + /** + * Converts the input text containing a decimal number to a double number. + * + * @param number + * the input text containing a decimal number. + * @return converted double number. + */ + private static Double convertDouble(String number) { + return Double.parseDouble(number.replace(",", ".")); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/SpinnerInt.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/SpinnerInt.java new file mode 100644 index 000000000..a3873f6bb --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/SpinnerInt.java @@ -0,0 +1,100 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import static java.lang.Integer.parseInt; + +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JSpinner; +import javax.swing.SpinnerModel; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The SpinnerInt class is the component spinner used for displaying and + * changing integer numbers. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class SpinnerInt extends JSpinner implements Observer, ChangeListener { + + private static final long serialVersionUID = 6920036545501669043L; + + /** The number of columns in the spinner */ + private static final int SPINNER_SIZE = 4; + + /** The step of the spinner */ + private final static int STEP = 1; + + /** The parameter type which values the component displays */ + private Type type; + + /** + * Creates the spinner used for displaying and changing integer numbers. + * + * @param type + * the parameter type. + * @return the newly created spinner used form integer numbers. + */ + public static SpinnerInt createSpinnerInt(Type type) { + SpinnerNumberModel spinnerModel = new SpinnerNumberModel(); + spinnerModel.setValue(parseInt(type.getValue())); + spinnerModel.setStepSize(STEP); + return new SpinnerInt(spinnerModel, type); + } + + /** + * Initializes a newly created SpinnerInt with the parameter type and spinner + * model. + * + * @param spinnerModel + * the spinner model. + * @param type + * the parameter type. + */ + private SpinnerInt(SpinnerModel spinnerModel, Type type) { + super(spinnerModel); + this.type = type; + type.addObserver(this); + this.addChangeListener(this); + ((JSpinner.DefaultEditor) this.getEditor()).getTextField().setColumns(SPINNER_SIZE); + } + + /** + * Updates the spinner number value according to the input value. If the input value is not a + * valid integer number, then the previous spinner value is kept. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + try { + ((SpinnerNumberModel) this.getModel()).setValue(Integer.valueOf(value.toString())); + } catch (NumberFormatException ex) { + type.changeValue(this.getModel().getValue().toString()); + MessageWriter.writeWarning(ResourceController.getMessage( + "error.component.update_value", type.getOwnerName(), value)); + } + } + + /** + * Action performed when the spinner value is changed. Assignes a new value to the parameter + * type. + * + * @param event + * the item event. + */ + public void stateChanged(ChangeEvent event) { + type.changeValue(this.getModel().getValue().toString()); + MainFrame.getInstance().setFileChanged(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/TextArea.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/TextArea.java new file mode 100644 index 000000000..b237d3b80 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/TextArea.java @@ -0,0 +1,76 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JTextArea; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The TextArea class is the component text-area used for displaying + * longer texts. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TextArea extends JTextArea implements Observer, FocusListener { + + private static final long serialVersionUID = -2338840101614677876L; + + /** The width of the text-area */ + private static final int TEXTAREA_WIDTH = 25; + + /** The height of the text-area */ + private static final int TEXTAREA_HEIGHT = 15; + + /** The parameter type which values the component displays */ + private Type type; + + /** + * Initializes a newly created TextArea with the parameter type. + * + * @param type + * the parameter type. + */ + public TextArea(Type type) { + super(TEXTAREA_HEIGHT, TEXTAREA_WIDTH); + this.setText(type.getValue()); + this.addFocusListener(this); + this.type = type; + type.addObserver(this); + } + + /** + * Action performed when the text-area losts focus. Assignes a new value to the + * parameter type. + * + * @param event + * the focus event. + */ + public void focusLost(FocusEvent event) { + type.changeValue(this.getText()); + MainFrame.getInstance().setFileChanged(); + } + + /** + * Action performed when the text-area gains focus - does nothing. + */ + public void focusGained(FocusEvent event) { + } + + /** + * Sets the content of the text-area according to the input text. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + this.setText(value.toString()); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/TextField.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/TextField.java new file mode 100644 index 000000000..5c948d3d1 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/TextField.java @@ -0,0 +1,73 @@ +package cz.zcu.fav.kiv.editor.graphics.components; + +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JTextField; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The TextField class is the component text-field used for displaying + * shorter single-line texts. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TextField extends JTextField implements Observer, FocusListener { + + private static final long serialVersionUID = 4818192876380891610L; + + /** The size of the text-field */ + private static final int TEXTFIELD_SIZE = 25; + + /** The parameter type which values the component displays */ + private Type type; + + /** + * Initializes a newly created TextField with the parameter type. + * + * @param type + * the parameter type. + */ + public TextField(Type type) { + super(TEXTFIELD_SIZE); + this.setText(type.getValue()); + this.addFocusListener(this); + this.type = type; + type.addObserver(this); + } + + /** + * Action performed when the text-field losts focus. Assignes a new value to the + * parameter type. + * + * @param event + * the focus event. + */ + public void focusLost(FocusEvent event) { + type.changeValue(this.getText()); + MainFrame.getInstance().setFileChanged(); + } + + /** + * Action performed when the text-field gains focus - does nothing. + */ + public void focusGained(FocusEvent event) { + } + + /** + * Sets the content of the text-field according to the input text. + * + * @param observable + * the observable object. + * @param value + * the new parameter value. + */ + public void update(Observable observable, Object value) { + this.setText(value.toString()); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeButton.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeButton.java new file mode 100644 index 000000000..25af5142d --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeButton.java @@ -0,0 +1,63 @@ +package cz.zcu.fav.kiv.editor.graphics.components.attributes; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.beans.properties.Property; + +/** + * The AttributeButton class represents the button displaying the dialog + * with attributes AttributeDialog. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AttributeButton extends JPanel implements ActionListener { + + private static final long serialVersionUID = 6410143984336194601L; + + /** The size of horizontal empty gap */ + private static final int EMPTY_GAP_HORIZONTAL = 10; + + /** The size of vertical empty gap */ + private static final int EMPTY_GAP_VERTICAL = 0; + + /** The property which dialog dialog displays */ + private Property property; + + /** + * Initializes a newly created AttributeButton with the property. + * + * @param property + * the property with Attributes. + */ + public AttributeButton(Property property) { + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + + this.add(Box.createRigidArea(new Dimension(EMPTY_GAP_HORIZONTAL, EMPTY_GAP_VERTICAL))); + + JButton button = new JButton(property.getName()); + button.addActionListener(this); + this.add(button); + + this.property = property; + } + + /** + * Action performed when the button is pressed. It displays the dialog with attributes + * AttributeDialog. + */ + public void actionPerformed(ActionEvent event) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + AttributeDialog.showDialog(property); + } + }); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeCheckBox.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeCheckBox.java new file mode 100644 index 000000000..0c5560bbe --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeCheckBox.java @@ -0,0 +1,68 @@ +package cz.zcu.fav.kiv.editor.graphics.components.attributes; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JCheckBox; + +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The AttributeCheckBox class is the component check-box, that displays + * whether the corresponding Attribute of the Property is selected or + * not. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AttributeCheckBox extends JCheckBox implements Observer, ActionListener { + + private static final long serialVersionUID = -6845824213536903733L; + + /** The attribute which estate the component displays */ + private Attribute attribute; + + /** + * Initializes a newly created AttributeCheckBox with the Attribute. + * + * @param attribute + * the attribute of the Property. + */ + public AttributeCheckBox(Attribute attribute) { + super(); + + this.attribute = attribute; + setSelected(attribute.isChosen()); + + attribute.addObserver(this); + this.addActionListener(this); + } + + /** + * Selects or deselects the check-box according to the input value. + * + * @param observable + * the observable object. + * @param value + * the new check-box value. + */ + public void update(Observable observable, Object value) { + this.setSelected((Boolean) value); + } + + /** + * Action performed when the check-box is selected or deselected. Assignes a new estate to the + * Attribute. + * + * @param event + * the action event. + */ + public void actionPerformed(ActionEvent event) { + attribute.changeChosen(this.isSelected()); + MainFrame.getInstance().setFileChanged(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeComponent.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeComponent.java new file mode 100644 index 000000000..474481c94 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeComponent.java @@ -0,0 +1,60 @@ +package cz.zcu.fav.kiv.editor.graphics.components.attributes; + +import java.awt.BorderLayout; +import java.util.List; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SpringLayout; + +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.graphics.utils.SpringUtilities; + +/** + * The AttributeComponent class is the panel containing the Attributes + * belonging to one AttributeGroup. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AttributeComponent extends JPanel { + + private static final long serialVersionUID = -1735079147977227649L; + + /** The number of one component items in the panel */ + private static final int ITEMS = 3; + + /** The size of component margin */ + private static final int MARGIN = 3; + + /** + * Initializes a newly created AttributeComponent with the list of attributes. + * + * @param attributeList + * the list of attributes. + */ + public AttributeComponent(List attributeList) { + this.setLayout(new BorderLayout()); + + // parameters panel + JPanel paramPane = new JPanel(); + paramPane.setLayout(new SpringLayout()); + + for (Attribute attr : attributeList) { + // checkbox + paramPane.add(new AttributeCheckBox(attr)); + + // attribute name + paramPane.add(new JLabel(attr.getName())); + + // attribute types + paramPane.add(new AttributeTypeForm(attr)); + } + + SpringUtilities.makeCompactGrid(paramPane, attributeList.size(), ITEMS, MARGIN, MARGIN, + MARGIN, MARGIN); + + this.add(paramPane, BorderLayout.LINE_START); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeDialog.java new file mode 100644 index 000000000..5c42db099 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeDialog.java @@ -0,0 +1,118 @@ +package cz.zcu.fav.kiv.editor.graphics.components.attributes; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; + +import cz.zcu.fav.kiv.editor.beans.properties.AttributeGroup; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; + +/** + * The AttributeDialog class is the dialog with Attributes of one + * Property. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AttributeDialog extends JDialog implements ActionListener { + + private static final long serialVersionUID = -6526357047305363516L; + + /** The dialog representing the Property */ + private static AttributeDialog dialog; + + /** The property which Attributes the dialog displays */ + private static Property property; + + /** The save command */ + private static final String SAVE_COMMAND = "save"; + + /** The size of margin */ + private static final int MARGIN = 10; + + /** + * Displays the dialog with property attributes. + * + * @param prop + * the property with attributes. + */ + public static void showDialog(Property prop) { + property = prop; + dialog = new AttributeDialog(); + dialog.setVisible(true); + } + + /** + * Initializes a newly created AttributeDialog. + */ + private AttributeDialog() { + super(MainFrame.getInstance(), ResourceController.getMessage("frame.attribute.title") + + property.getName(), true); + + Container pan = new JPanel(new BorderLayout()); + + ImageIcon icon = EditorIcon.createTabIcon(); + + JTabbedPane tabPanel = new JTabbedPane(JTabbedPane.TOP); + for (AttributeGroup panel : property.getAttributeGroupList()) { + tabPanel.addTab(panel.getTitle(), icon, + new AttributeComponent(panel.getAttributeList())); + } + pan.add(tabPanel, BorderLayout.CENTER); + + // Create and initialize the buttons. + JButton cancelButton = new JButton(ResourceController.getMessage("button.cancel")); + cancelButton.addActionListener(this); + + JButton setButton = new JButton(ResourceController.getMessage("button.save")); + setButton.setActionCommand(SAVE_COMMAND); + setButton.addActionListener(this); + getRootPane().setDefaultButton(setButton); + + // Lay out the buttons from left to right. + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(setButton); + buttonPane.add(Box.createRigidArea(new Dimension(MARGIN, MARGIN))); + buttonPane.add(cancelButton); + + pan.add(buttonPane, BorderLayout.PAGE_END); + + this.getContentPane().add(pan, BorderLayout.CENTER); + + this.pack(); + this.setLocationRelativeTo(MainFrame.getInstance()); + } + + /** + * Action performed when a button of the dialog is pressed. If the Save button is + * pressed, then the changed attribute values are saved. + */ + public void actionPerformed(ActionEvent event) { + if (SAVE_COMMAND.equals(event.getActionCommand())) { + property.setValuesFromTemporary(); + property.setChosen(); + MainFrame.getInstance().setFileChanged(); + } + AttributeDialog.dialog.setVisible(false); + AttributeDialog.dialog.dispose(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeTypeForm.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeTypeForm.java new file mode 100644 index 000000000..7358c5e4b --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/attributes/AttributeTypeForm.java @@ -0,0 +1,93 @@ +package cz.zcu.fav.kiv.editor.graphics.components.attributes; + +import java.awt.Dimension; +import java.awt.FlowLayout; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.beans.properties.UnitAttr; +import cz.zcu.fav.kiv.editor.graphics.components.CheckBox; +import cz.zcu.fav.kiv.editor.graphics.components.ColorChooser; +import cz.zcu.fav.kiv.editor.graphics.components.ComboBox; +import cz.zcu.fav.kiv.editor.graphics.components.ComboBoxEdit; +import cz.zcu.fav.kiv.editor.graphics.components.ComboBoxUnit; +import cz.zcu.fav.kiv.editor.graphics.components.FileChooser; +import cz.zcu.fav.kiv.editor.graphics.components.SpinnerFloat; +import cz.zcu.fav.kiv.editor.graphics.components.SpinnerInt; +import cz.zcu.fav.kiv.editor.graphics.components.TextArea; +import cz.zcu.fav.kiv.editor.graphics.components.TextField; + +/** + * The AttributeTypeForm class is the panel containing the components used for + * editing Attribute value. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AttributeTypeForm extends JPanel { + + private static final long serialVersionUID = -2218273286123231184L; + + private static final int WIDTH = 200; + + /** + * Initializes a newly created AttributeTypeForm with the attribute. + * + * @param attribute + * the attribute. + */ + public AttributeTypeForm(Attribute attribute) { + this.setLayout(new FlowLayout(FlowLayout.LEFT)); + + attribute.getType().setAttr(attribute); + switch (attribute.getType().getName()) { + case BOOLEAN: + this.add(new CheckBox(attribute.getType())); + break; + case STRING: + case URI: + this.add(new TextField(attribute.getType())); + break; + case LIST: + this.add(new ComboBox(attribute.getType())); + break; + case LIST_OPEN: + case FONT: + this.add(new ComboBoxEdit(attribute.getType())); + break; + case FILENAME: + this.add(new FileChooser(attribute.getType())); + break; + case COLOR: + this.add(new ColorChooser(attribute.getType())); + break; + case LENGTH: + this.add(SpinnerFloat.createSpinnerFloat(attribute.getType())); + ((UnitAttr) attribute.getType().getUnit()).setAttribute(attribute); + this.add(new ComboBoxUnit(attribute.getType().getUnit())); + break; + case NUMBER: + case INTEGER: + this.add(SpinnerInt.createSpinnerInt(attribute.getType())); + break; + case RTF: + case TABLE: + TextArea area = new TextArea(attribute.getType()); + this.add(area); + JScrollPane scrollPane = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + this.add(scrollPane); + break; + case FLOAT: + this.add(SpinnerFloat.createSpinnerFloat(attribute.getType())); + break; + } + + this.setMaximumSize(new Dimension(this.getPreferredSize().width + WIDTH, + this.getPreferredSize().height)); + this.setPreferredSize(new Dimension(this.getPreferredSize().width + WIDTH, + this.getPreferredSize().height)); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/EditorBody.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/EditorBody.java new file mode 100644 index 000000000..5d2e09059 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/EditorBody.java @@ -0,0 +1,97 @@ +package cz.zcu.fav.kiv.editor.graphics.components.editor; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.plaf.basic.BasicSplitPaneUI; + +import cz.zcu.fav.kiv.editor.beans.sections.Section; +import cz.zcu.fav.kiv.editor.graphics.console.MessageConsole; + +/** + * The EditorBody class represents the body of the editor. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class EditorBody extends JPanel { + + private static final long serialVersionUID = 6221409996382853643L; + + /** The size of vertical panel margin */ + private static final int MARGIN_VERTICAL = 3; + + /** The size of horizontal panel margin */ + private static final int MARGIN_HORIZONTAL = 5; + + /** The height of the top part of the panel */ + private static final int PANEL_TOP_HEIGHT = 500; + + /** The width of the tree menu of the panel */ + private static final int PANEL_TREE_WIDTH = 200; + + /** The height of the panel */ + private static final int PANEL_HEIGHT = 600; + + /** The width of the panel */ + public static final int PANEL_WIDTH = 820; + + /** The split pane of the editor */ + private JSplitPane splitPaneTop; + + /** + * Initializes a newly created EditorBody with the list of Sections + * with parameters. + * + * @param sectionList + * the list of sections with parameters. + */ + public EditorBody(List
sectionList) { + this.setLayout(new BorderLayout(MARGIN_VERTICAL, MARGIN_HORIZONTAL)); + + // split tree menu x right panel + splitPaneTop = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + splitPaneTop.setDividerLocation(PANEL_TREE_WIDTH); + splitPaneTop.setBorder(null); + ((BasicSplitPaneUI) splitPaneTop.getUI()).getDivider().setBorder( + BorderFactory.createEmptyBorder()); + + // tree menu + TreeMenu treeMenu = TreeMenu.getInstance(this, sectionList); + JScrollPane treeView = new JScrollPane(treeMenu); + treeView.setPreferredSize(new Dimension(PANEL_TREE_WIDTH, PANEL_TOP_HEIGHT)); + treeView.setBorder(null); + splitPaneTop.setLeftComponent(treeView); + + // right panel + splitPaneTop.setRightComponent(treeMenu.getFirstSheet()); + + // split console x top panel + JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + splitPane.setBorder(null); + ((BasicSplitPaneUI) splitPane.getUI()).getDivider().setBorder( + BorderFactory.createEmptyBorder()); + splitPane.setTopComponent(splitPaneTop); + splitPane.setBottomComponent(MessageConsole.getInstance()); + splitPane.setDividerLocation(PANEL_TOP_HEIGHT); + + add(splitPane, BorderLayout.CENTER); + + this.setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT)); + } + + /** + * Changes the right panel of the editor body to the actually selected panel. + * + * @param panel + * the new selected panel. + */ + public void setEditorSheet(JPanel panel) { + splitPaneTop.setRightComponent(panel); + } +} \ No newline at end of file diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/GroupItemsPanel.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/GroupItemsPanel.java new file mode 100644 index 000000000..bbfea8ad9 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/GroupItemsPanel.java @@ -0,0 +1,76 @@ +package cz.zcu.fav.kiv.editor.graphics.components.editor; + +import java.util.List; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SpringLayout; + +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.graphics.components.attributes.AttributeButton; +import cz.zcu.fav.kiv.editor.graphics.components.parameters.HelpLabel; +import cz.zcu.fav.kiv.editor.graphics.components.parameters.ParameterCheckBox; +import cz.zcu.fav.kiv.editor.graphics.components.parameters.ParameterTypeForm; +import cz.zcu.fav.kiv.editor.graphics.components.parameters.UrlLabel; +import cz.zcu.fav.kiv.editor.graphics.utils.SpringUtilities; + +/** + * The GroupItemsPanel class is the panel containing the ParentParameters + * belonging to one Group. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class GroupItemsPanel extends JPanel { + + private static final long serialVersionUID = 6783434567893822418L; + + /** The number of one component items in the panel */ + private static final int ITEMS = 5; + + /** The size of component margin */ + private static final int MARGIN = 4; + + /** + * Initializes a newly created GroupItemsPanel with the list of parameters. + * + * @param elementList + * the list of parameters. + */ + public GroupItemsPanel(List elementList) { + int componentCount = 0; + + // parameters panel + this.setLayout(new SpringLayout()); + + for (ParentParameter element : elementList) { + // checkbox + this.add(new ParameterCheckBox(element)); + + // interrogation mark + this.add(new HelpLabel(element)); + + // url link + this.add(new UrlLabel(element.getName())); + + // parameter name + this.add( new JLabel(element.getName())); + + // parameter type + if (element instanceof Parameter) + this.add(new ParameterTypeForm(((Parameter) element).getType())); + + // property button + if (element instanceof Property) + this.add(new AttributeButton((Property) element)); + + componentCount++; + } + + SpringUtilities.makeCompactGrid(this, componentCount, ITEMS, MARGIN, MARGIN, MARGIN, + MARGIN); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/GroupPanel.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/GroupPanel.java new file mode 100644 index 000000000..d100879b7 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/GroupPanel.java @@ -0,0 +1,72 @@ +package cz.zcu.fav.kiv.editor.graphics.components.editor; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.SpringLayout; + +import cz.zcu.fav.kiv.editor.beans.sections.Group; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.displays.GraphicsFigure; +import cz.zcu.fav.kiv.editor.graphics.utils.SpringUtilities; + +/** + * The GroupPanel class is the panel containing the Group of parameters. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class GroupPanel extends JPanel { + + private static final long serialVersionUID = 6783432227893822418L; + + /** The size of vertical title margin */ + private static final int VERTICAL_MARGIN_TITLE = 0; + + /** The size of horizontal title margin */ + private static final int HORIZONTAL_MARGIN_TITLE = 10; + + /** The size of vertical margin of empty title */ + private static final int VERTICAL_MARGIN_EMPTY_TITLE = 5; + + /** The size of margin of components in the group panel */ + private static final int COMPONENT_MARGIN = 3; + + /** The number of rows in the group panel */ + private static final int ROW = 1; + + /** + * Initializes a newly created SubsectionSheet with the group. + * + * @param group + * the group with parameters. + */ + public GroupPanel(Group group) { + if (group.getTitle() != null) + this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder( + VERTICAL_MARGIN_TITLE, HORIZONTAL_MARGIN_TITLE, VERTICAL_MARGIN_TITLE, + HORIZONTAL_MARGIN_TITLE), BorderFactory.createTitledBorder(group.getTitle()))); + else + this.setBorder(BorderFactory.createEmptyBorder(VERTICAL_MARGIN_EMPTY_TITLE, + HORIZONTAL_MARGIN_TITLE, VERTICAL_MARGIN_EMPTY_TITLE, HORIZONTAL_MARGIN_TITLE)); + + int componentCount = 1; + + this.setLayout(new SpringLayout()); + + this.add(new GroupItemsPanel(group.getElementList())); + + if (group.getFigure() != null) + try { + GraphicsFigure graphicsFigure = (GraphicsFigure) Class.forName( + group.getFigure().getClassName()).newInstance(); + graphicsFigure.setInputs(group.getFigure().getParameterList()); + this.add(graphicsFigure); + componentCount++; + } catch (Exception ex) { + Log.error(ex); + } + + SpringUtilities.makeCompactGrid(this, ROW, componentCount, COMPONENT_MARGIN, + COMPONENT_MARGIN, COMPONENT_MARGIN, COMPONENT_MARGIN); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/SubsectionSheet.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/SubsectionSheet.java new file mode 100644 index 000000000..ae5b01c84 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/SubsectionSheet.java @@ -0,0 +1,88 @@ +package cz.zcu.fav.kiv.editor.graphics.components.editor; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Font; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSeparator; + +import cz.zcu.fav.kiv.editor.beans.sections.Group; +import cz.zcu.fav.kiv.editor.beans.sections.Subsection; +import cz.zcu.fav.kiv.editor.graphics.utils.GridLayoutUtilities; + +/** + * The SubsectionSheet class is the panel containing groups of parameters, that + * belongs to the Subsection. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class SubsectionSheet extends JPanel { + + private static final long serialVersionUID = -1940480099930144654L; + + /** The name of the sheet section */ + private String name; + + /** The number of sheet columns */ + private static int COLUMN = 1; + + /** The size of the sheet horizontal margin */ + private static final int MARGIN_HORIZONTAL = 0; + + /** The size of the sheet vertical margin */ + private static final int MARGIN_VERTICAL = 5; + + /** The size of the font used for sheet title */ + private static final int TITLE_FONT = 13; + + /** + * Initializes a newly created SubsectionSheet with the subsection. + * + * @param subsection + * the subsection with groups of parameters. + */ + public SubsectionSheet(Subsection subsection) { + this.name = subsection.getTitle(); + this.setLayout(new BorderLayout()); + + // top with title + JPanel topPanel = new JPanel(); + topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS)); + topPanel.add(Box.createRigidArea(new Dimension(MARGIN_HORIZONTAL, MARGIN_VERTICAL))); + + JLabel titleLabel = new JLabel(name, JLabel.LEFT); + titleLabel.setFont(new Font("Sans-Serif", Font.BOLD, TITLE_FONT)); + topPanel.add(titleLabel); + + topPanel.add(Box.createRigidArea(new Dimension(MARGIN_HORIZONTAL, MARGIN_VERTICAL))); + topPanel.add(new JSeparator(JSeparator.HORIZONTAL)); + topPanel.add(Box.createRigidArea(new Dimension(MARGIN_HORIZONTAL, 2 * MARGIN_VERTICAL))); + this.add(topPanel, BorderLayout.PAGE_START); + + // panel with parameters + JPanel groupPanel = new JPanel(); + groupPanel.setLayout(new GridLayoutUtilities(subsection.getGroupList().size(), COLUMN)); + + for (Group group : subsection.getGroupList()) { + groupPanel.add(new GroupPanel(group)); + } + JScrollPane sheetPanel = new JScrollPane(groupPanel, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + sheetPanel.setBorder(null); + this.add(sheetPanel, BorderLayout.CENTER); + } + + /** + * Returns the name of the sheet section. + */ + public String toString() { + return name; + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/TreeMenu.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/TreeMenu.java new file mode 100644 index 000000000..4ce71839e --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/TreeMenu.java @@ -0,0 +1,114 @@ +package cz.zcu.fav.kiv.editor.graphics.components.editor; + +import java.awt.Color; +import java.util.List; + +import javax.swing.ImageIcon; +import javax.swing.JPanel; +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; + +import cz.zcu.fav.kiv.editor.beans.sections.Section; +import cz.zcu.fav.kiv.editor.beans.sections.Subsection; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; + +/** + * The TreeMenu class is the panel containing the tree menu of the editor. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TreeMenu extends JPanel { + + private static final long serialVersionUID = 8347821460376344167L; + + /** The single instance of the panel with the tree menu */ + private static TreeMenu instance; + + /** The tree menu */ + private JTree tree; + + /** The list of tree nodes */ + private DefaultMutableTreeNode nodeList; + + /** + * Singleton constructor - gets the single instance of the TreeMenu class. + * + * @param editorBody + * the body of the editor. + * @param sectionList + * the list of sections. + * @return the single instance of the TreeMenu. + */ + public static TreeMenu getInstance(EditorBody editorBody, List
sectionList) { + if (instance == null) { + instance = new TreeMenu(editorBody, sectionList); + } + return instance; + } + + /** + * Initializes a newly created TreeMenu with the list of Sections with + * parameters and the editor body which part the TreeMenu creates. + * + * @param editorBody + * the body of the editor. + * @param sectionList + * the list of sections. + */ + public TreeMenu(EditorBody editorBody, List
sectionList) { + nodeList = createNodes(sectionList); + tree = new JTree(nodeList); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + + // Listen for when the selection changes. + tree.addTreeSelectionListener(new TreeSelectAction(editorBody)); + + // leaf icon + DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); + ImageIcon leafIcon = EditorIcon.createTabIcon(); + renderer.setLeafIcon(leafIcon); + + // select leaf + TreePath treePath = new TreePath(nodeList.getFirstLeaf().getPath()); + tree.setSelectionPath(treePath); + + tree.setRootVisible(false); + this.add(tree); + this.setBackground(Color.white); + } + + /** + * Creates the structure of tree nodes containing parameter sections. + * + * @param sectionList + * the list of sections. + * @return the root node of the tree menu. + */ + private DefaultMutableTreeNode createNodes(List
sectionList) { + DefaultMutableTreeNode top = new DefaultMutableTreeNode(); + DefaultMutableTreeNode sectionNode = null; + + for (Section section : sectionList) { + sectionNode = new DefaultMutableTreeNode(section.getTitle()); + top.add(sectionNode); + // subsections + for (Subsection subsection : section.getSubsectionList()) { + sectionNode.add(new DefaultMutableTreeNode(new SubsectionSheet(subsection))); + } + } + return top; + } + + /** + * Gets the section sheet belonging to the first tree node. + * + * @return the section sheet belonging to the first tree node. + */ + public SubsectionSheet getFirstSheet() { + return (SubsectionSheet) nodeList.getFirstLeaf().getUserObject(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/TreeSelectAction.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/TreeSelectAction.java new file mode 100644 index 000000000..ca8add94f --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/editor/TreeSelectAction.java @@ -0,0 +1,42 @@ +package cz.zcu.fav.kiv.editor.graphics.components.editor; + +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; + +/** + * The TreeSelectAction class represents the action performed when a leaf of tree + * menu is selected. Displays the SubsectionSheet belonging to the selected leaf. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TreeSelectAction implements TreeSelectionListener { + + /** The panel representing the editor body */ + private EditorBody editorBody; + + /** + * Initializes a newly created TreeSelectAction. + * + * @param editorBody + * the panel representing the editor body. + */ + public TreeSelectAction(EditorBody editorBody) { + this.editorBody = editorBody; + } + + /** + * Action performed when a tree node is selected. Displays the subsection sheet belonging to the + * selected node. + */ + public void valueChanged(TreeSelectionEvent selectEvent) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((JTree) selectEvent.getSource()) + .getLastSelectedPathComponent(); + if (node.isLeaf()) { + this.editorBody.setEditorSheet((SubsectionSheet) node.getUserObject()); + } + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/BrowserListener.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/BrowserListener.java new file mode 100644 index 000000000..ac2433d21 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/BrowserListener.java @@ -0,0 +1,128 @@ +package cz.zcu.fav.kiv.editor.graphics.components.parameters; + +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.ClipboardOwner; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; +import cz.zcu.fav.kiv.editor.graphics.utils.OpenBrowser; + +/** + * The BrowserListener class represents the action performed when the mouse is + * pressed above the UrlLabel. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class BrowserListener extends MouseAdapter implements ClipboardOwner { + + /** The popup menu displaying when the right mouse button is pressed */ + private JPopupMenu popup; + + /** + * The name of the parameter - is the same as the URL path of the web page with parameter + * description + */ + private String name; + + /** + * Creates the popup menu displaying when the right mouse button is pressed above + * UrlLabel. + * + * @return the popup menu of the UrlLabel. + */ + private JPopupMenu createPopupMenu() { + JPopupMenu popup = new JPopupMenu(); + // item opening the web browser + JMenuItem menuItem = new JMenuItem(ResourceController + .getMessage("editor.browser.menu.open_browser")); + menuItem.addActionListener(new OpenBrowserListener()); + popup.add(menuItem); + // item copying the URL path to the clippboard + menuItem = new JMenuItem(ResourceController.getMessage("editor.browser.menu.copy_location")); + menuItem.addActionListener(new CopyToClipboardListener()); + popup.add(menuItem); + return popup; + } + + /** + * Initializes a newly created BrowserListener with the parameter name. + * + * @param name + * the name of the parameter. + */ + public BrowserListener(String name) { + this.name = name; + popup = createPopupMenu(); + } + + /** + * Action performed when the mouse button is pressed. Shows the popup menu if the right mouse + * button has been pressed. + */ + public void mouseReleased(MouseEvent event) { + maybeShowPopup(event); + } + + /** + * Shows the popup menu if the right mouse button has been pressed. + * + * @param event + * the mouse event. + */ + private void maybeShowPopup(MouseEvent event) { + if (event.isPopupTrigger()) + popup.show(event.getComponent(), event.getX(), event.getY()); + else + OpenBrowser.openURL(ResourceController.getMessage("url.parameter_description", name)); + } + + /** + * The inner class BrowserListener represents the action performed when the left + * mouse button above the UrlLabel is pressed. It opens the web browser with the + * web page containg the parameter description. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class OpenBrowserListener implements ActionListener { + /** + * The action performed when the left mouse button above the UrlLabel is + * pressed. It opens the web browser with the web page containg the parameter description. + */ + public void actionPerformed(ActionEvent event) { + OpenBrowser.openURL(ResourceController.getMessage("url.parameter_description", name)); + } + } + + /** + * The inner class CopyToClipboardListener represents the action performed when + * the popup menu item Copy to clipboard is chosen. It copies the URL of the page + * with the parameter description to the clipboard. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class CopyToClipboardListener implements ActionListener { + + /** + * The action performed when the popup menu item Copy to clipboard is chosen. It + * copies the URL of the page with the parameter description to the clipboard. + */ + public void actionPerformed(ActionEvent event) { + Clipboard clipboard = MainFrame.getInstance().getToolkit().getSystemClipboard(); + clipboard.setContents(new StringSelection(name), BrowserListener.this); + } + } + + public void lostOwnership(Clipboard arg0, Transferable arg1) { + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/DescriptionForm.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/DescriptionForm.java new file mode 100644 index 000000000..9d8911203 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/DescriptionForm.java @@ -0,0 +1,111 @@ +package cz.zcu.fav.kiv.editor.graphics.components.parameters; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.JScrollPane; + +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The DescriptionForm class is the dialog displaying parameter description. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class DescriptionForm extends JDialog implements FocusListener { + + private static final long serialVersionUID = -4632340976081227454L; + + /** The width of the dialog */ + private static final int WIDTH = 300; + + /** The height width of the dialog */ + private static final int HEIGHT = 150; + + /** The color of the background dialog */ + private static final Color BACKGROUND_COLOR = new Color(255, 255, 225); + + /** The single instance of the dialog */ + private static DescriptionForm instance; + + /** The inner width of the dialog */ + private JEditorPane contentArea; + + /** + * Creates and shows the dialog with parameter description. + * + * @param content + * the description of parameter. + * @param label + * the label with parameter name. + */ + public static void showDialog(String content, JLabel label) { + instance = getInstance(); + instance.setContentArea(content); + instance.setLocationRelativeTo(label); + instance.setVisible(true); + } + + /** + * Gets the single instance of the dialog with parameter description. + * + * @return the single instance of the dialog with parameter description. + */ + private static DescriptionForm getInstance() { + if (instance == null) + instance = new DescriptionForm(); + return instance; + } + + /** + * Initializes a newly created DescriptionForm. + */ + private DescriptionForm() { + super(MainFrame.getInstance()); + + this.setLayout(new BorderLayout()); + + contentArea = new JEditorPane(); + contentArea.setEditable(false); + contentArea.setContentType("text/html"); + + contentArea.setBackground(BACKGROUND_COLOR); + + JScrollPane scrollBar = new JScrollPane(contentArea); + scrollBar.setPreferredSize(new Dimension(WIDTH, HEIGHT)); + this.add(scrollBar, BorderLayout.PAGE_START); + + contentArea.addFocusListener(this); + this.setUndecorated(true); + pack(); + } + + /** + * Action performed when the dialog gains focus - does nothing. + */ + public void focusGained(FocusEvent event) { + } + + /** + * Action performed when the dialog losts focus - hides the dialog. + */ + public void focusLost(FocusEvent event) { + this.setVisible(false); + } + + /** + * Sets a new parameter description to the content of the dialog. + * + * @param content + * the description of a parameter. + */ + public void setContentArea(String content) { + this.contentArea.setText(content); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/HelpLabel.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/HelpLabel.java new file mode 100644 index 000000000..b3032e20e --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/HelpLabel.java @@ -0,0 +1,101 @@ +package cz.zcu.fav.kiv.editor.graphics.components.parameters; + +import java.awt.Cursor; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.swing.JLabel; + +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; + +/** + * The HelpLabel class is the icon button displaying the tooltip with parameter purpose and + * the dialog with parameter description. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class HelpLabel extends JLabel { + + private static final long serialVersionUID = -2256167369619643267L; + + /** The parameter description */ + private String description = null; + + /** + * Initializes a newly created HelpLabel with the parameter. + * + * @param element + * the parameter. + */ + public HelpLabel(ParentParameter element) { + if (element.getDescription() != null) + description = insertStylesheet(element.getDescription(), element.getName()); + + this.setToolTipText(element.getPurpose()); + this.setIcon(EditorIcon.createHelpIcon()); + this.addMouseListener(new ShowHelpListener()); + this.setCursor(new Cursor(Cursor.HAND_CURSOR)); + } + + /** + * Inserts the parameter title to the HTML description of the parameter. + * + * @param text + * the description of the parameter. + * @param title + * the title of the parameter. + * @return the description of the parameter with the title. + */ + private String insertTitle(String text, String title) { + Pattern pattern = Pattern.compile(""); + Matcher matcher = pattern.matcher(text); + if (matcher.find()) { + return text.substring(0, matcher.end()) + "

" + title + "

" + + text.substring(matcher.end()); + } + return text; + } + + /** + * Inserts the CSS stylesheet to the HTML description of the parameter. + * + * @param text + * the description of the parameter. + * @param title + * the title of the parameter. + * @return the description of the parameter with the CSS stylesheet. + */ + private String insertStylesheet(String text, String title) { + text = text.replaceAll(".*", ""); + Pattern pattern = Pattern.compile(""); + Matcher matcher = pattern.matcher(text); + if (matcher.find()) { + text = matcher.group() + + "" + + text.substring(matcher.end()); + } + return insertTitle(text, title); + } + + /** + * The inner class ShowHelpListener represents action performed when the mouse is + * pressed above the help icon. Then the dialog with parameter description is displayed. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class ShowHelpListener extends MouseAdapter { + /** + * Action performed when the mouse is pressed above the help icon, it displays the dialog + * with parameter description. + */ + public void mousePressed(MouseEvent event) { + if (description != null) + DescriptionForm.showDialog(description, (JLabel) event.getSource()); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/ParameterCheckBox.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/ParameterCheckBox.java new file mode 100644 index 000000000..c434eff48 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/ParameterCheckBox.java @@ -0,0 +1,68 @@ +package cz.zcu.fav.kiv.editor.graphics.components.parameters; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JCheckBox; + +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The ParameterCheckBox class is the component check-box, that displays + * whether the corresponding Parameter is selected or not. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParameterCheckBox extends JCheckBox implements Observer, ActionListener { + + private static final long serialVersionUID = -6845824213536903733L; + + /** The parameter which estate the component displays */ + private ParentParameter parameter; + + /** + * Initializes a newly created ParameterCheckBox with the Parameter. + * + * @param parameter + * the parameter. + */ + public ParameterCheckBox(ParentParameter parameter) { + super(); + + this.parameter = parameter; + setSelected(parameter.isChosen()); + + parameter.addObserver(this); + this.addActionListener(this); + } + + /** + * Selects or deselects the check-box according to the input value. + * + * @param observable + * the observable object. + * @param value + * the new check-box value. + */ + public void update(Observable observable, Object value) { + if (value != null) + this.setSelected((Boolean) value); + } + + /** + * Action performed when the check-box is selected or deselected. Assignes a new estate to the + * Parameter. + * + * @param event + * the action event. + */ + public void actionPerformed(ActionEvent event) { + parameter.setChosen(this.isSelected()); + MainFrame.getInstance().setFileChanged(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/ParameterTypeForm.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/ParameterTypeForm.java new file mode 100644 index 000000000..28f1a5778 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/ParameterTypeForm.java @@ -0,0 +1,87 @@ +package cz.zcu.fav.kiv.editor.graphics.components.parameters; + +import java.awt.Dimension; +import java.awt.FlowLayout; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import cz.zcu.fav.kiv.editor.beans.parameters.TypeParam; +import cz.zcu.fav.kiv.editor.graphics.components.CheckBox; +import cz.zcu.fav.kiv.editor.graphics.components.ColorChooser; +import cz.zcu.fav.kiv.editor.graphics.components.ComboBox; +import cz.zcu.fav.kiv.editor.graphics.components.ComboBoxEdit; +import cz.zcu.fav.kiv.editor.graphics.components.ComboBoxUnit; +import cz.zcu.fav.kiv.editor.graphics.components.FileChooser; +import cz.zcu.fav.kiv.editor.graphics.components.SpinnerFloat; +import cz.zcu.fav.kiv.editor.graphics.components.SpinnerInt; +import cz.zcu.fav.kiv.editor.graphics.components.TextArea; +import cz.zcu.fav.kiv.editor.graphics.components.TextField; + +/** + * The ParameterTypeForm class is the panel containing the component used for editing + * Parameter value. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ParameterTypeForm extends JPanel { + + private static final long serialVersionUID = 6613158285413029141L; + + /** + * Initializes a newly created ParameterTypeForm with the parameter type. + * + * @param type + * the parameter type. + */ + public ParameterTypeForm(TypeParam type) { + this.setLayout(new FlowLayout(FlowLayout.LEADING)); + switch (type.getName()) { + case BOOLEAN: + this.add(new CheckBox(type)); + break; + case STRING: + case URI: + this.add(new TextField(type)); + break; + case LIST: + this.add(new ComboBox(type)); + break; + case LIST_OPEN: + case FONT: + this.add(new ComboBoxEdit(type)); + break; + case FILENAME: + this.add(new FileChooser(type)); + break; + case COLOR: + this.add(new ColorChooser(type)); + break; + case LENGTH: + this.add(SpinnerFloat.createSpinnerFloat(type)); + this.add(new ComboBoxUnit(type.getUnit())); + break; + case NUMBER: + case INTEGER: + this.add(SpinnerInt.createSpinnerInt(type)); + break; + case RTF: + case TABLE: + TextArea area = new TextArea(type); + this.add(area); + JScrollPane scrollPane = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + this.add(scrollPane); + break; + case FLOAT: + this.add(SpinnerFloat.createSpinnerFloat(type)); + break; + } + + this.setMaximumSize(new Dimension(this.getPreferredSize().width, + this.getPreferredSize().height)); + this.setPreferredSize(new Dimension(this.getPreferredSize().width, + this.getPreferredSize().height)); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/UrlLabel.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/UrlLabel.java new file mode 100644 index 000000000..12bd43d26 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/components/parameters/UrlLabel.java @@ -0,0 +1,35 @@ +package cz.zcu.fav.kiv.editor.graphics.components.parameters; + +import java.awt.Cursor; + +import javax.swing.JLabel; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; + +/** + * The UrlLabel class is the icon button opening the web browser with the parameter + * description. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class UrlLabel extends JLabel { + + private static final long serialVersionUID = 2760298589328490225L; + + /** + * Initializes a newly created UrlLabel with the parameter name. + * + * @param elementName + * the name of the parameter. + */ + public UrlLabel(String elementName) { + this.setToolTipText(ResourceController.getMessage("editor.browser.description", + ResourceController.getMessage("url.parameter_description", elementName))); + this.setIcon(EditorIcon.createBrowserIcon()); + this.addMouseListener(new BrowserListener(elementName)); + this.setCursor(new Cursor(Cursor.HAND_CURSOR)); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/console/MessageConsole.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/console/MessageConsole.java new file mode 100644 index 000000000..649f5f908 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/console/MessageConsole.java @@ -0,0 +1,227 @@ +package cz.zcu.fav.kiv.editor.graphics.console; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridLayout; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextPane; +import javax.swing.text.BadLocationException; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.components.editor.EditorBody; + +/** + * The MessageConsoleclass represents the output console that displays messages, + * errors and warnings to user. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class MessageConsole extends JPanel { + + private static final long serialVersionUID = 5544740912147120927L; + + /** The size of the console height */ + private static final int FRAME_CONSOLE_HEIGHT = 70; + + /** The char specifying the end of line used in the console */ + private static final String NEWLINE = "\n"; + + /** The size of font used in the console */ + private static final int FONT_SIZE = 12; + + /** The single instance of the console */ + private static MessageConsole instance; + + /** The mutable attribute set of the JTextPane */ + private MutableAttributeSet mutAttr; + + /** The styled document of the JTextPane */ + private StyledDocument styledDoc; + + /** The text pane creating the content of the console */ + private JTextPane editor; + + /** + * Singleton constructor - gets the single instance of the MessageConsole class. + * + * @return the single instance of MessageConsole. + */ + public static MessageConsole getInstance() { + if (instance == null) + instance = new MessageConsole(); + return instance; + } + + /** + * Initializes a newly created MessageConsole. + */ + private MessageConsole() { + this.setLayout(new GridLayout(1, 1)); + + editor = new JTextPane(); + editor.setEditable(false); + editor.setFont(new Font("DialogInput", Font.PLAIN, FONT_SIZE)); + mutAttr = new SimpleAttributeSet(); + styledDoc = editor.getStyledDocument(); + StyleConstants.setForeground(mutAttr, Color.black); + + JScrollPane scrollBar = new JScrollPane(editor); + scrollBar.setPreferredSize(new Dimension(EditorBody.PANEL_WIDTH, FRAME_CONSOLE_HEIGHT)); + + add(scrollBar, BorderLayout.CENTER); + } + + /** + * Appends the input text to the console. + * + * @param message + * the text that will be appended to the console. + */ + private void appendText(String message) { + try { + styledDoc.insertString(styledDoc.getLength(), message, mutAttr); + editor.setCaretPosition(styledDoc.getLength()); + } catch (BadLocationException ex) { + Log.error(ex); + } + } + + /** + * Erases the content of the whole console. + */ + private void erase() { + try { + styledDoc.remove(0, styledDoc.getLength()); + } catch (BadLocationException ex) { + Log.error(ex); + } + } + + /** + * Appends to the console a new line. + * + * @param message + * the text that will be appended to the console as a new line. + */ + private void appendLine(String message) { + appendText(message + NEWLINE); + } + + /** + * Appends to the console a new word. + * + * @param message + * the text that will be appended to the console as a new word. + */ + private void appendWord(String message) { + appendText(message); + } + + /** + * Writes a normal information to the console. + * + * @param message + * the normal text message. + */ + public static void logMessage(String message) { + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), Color.black); + MessageConsole.getInstance().appendLine(message); + } + + /** + * Writes a emphasis information to the console. + * + * @param message + * the normal text message. + */ + public static void logMessageEmphasis(String message) { + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), Color.black); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), true); + MessageConsole.getInstance().appendLine(message); + } + + /** + * Writes a warning message to the console. + * + * @param message + * the message containing warning. + */ + public static void logWarning(String message) { + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), new Color(0, 64, + 128)); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), true); + MessageConsole.getInstance().appendWord( + ResourceController.getMessage("message_writer.warning")); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), false); + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), Color.black); + MessageConsole.getInstance().appendLine(message); + } + + /** + * Writes an error message to the console. + * + * @param message + * the message containing error. + */ + public static void logError(String message) { + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), new Color(208, 9, + 32)); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), true); + MessageConsole.getInstance().appendWord( + ResourceController.getMessage("message_writer.error")); + MessageConsole.getInstance().appendLine(message); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), false); + } + + /** + * Writes an information message to the console. + * + * @param message + * the message containing information. + */ + public static void logInfo(String message) { + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), new Color(217, 121, + 36)); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), true); + MessageConsole.getInstance().appendWord( + ResourceController.getMessage("message_writer.info")); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), false); + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), Color.black); + MessageConsole.getInstance().appendLine(message); + } + + /** + * Writes a title to the console. + * + * @param message + * the message containing title. + */ + public static void logTitle(String message) { + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), true); + StyleConstants.setForeground(MessageConsole.getInstance().getMutAttr(), + new Color(128, 0, 0)); + MessageConsole.getInstance().appendLine(" * * * " + message.toUpperCase() + " * * *"); + StyleConstants.setBold(MessageConsole.getInstance().getMutAttr(), false); + } + + /** + * Erases the content of the console. + */ + public static void eraseConsole() { + MessageConsole.getInstance().erase(); + } + + public MutableAttributeSet getMutAttr() { + return mutAttr; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/AboutForm.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/AboutForm.java new file mode 100644 index 000000000..63b65bd22 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/AboutForm.java @@ -0,0 +1,75 @@ +package cz.zcu.fav.kiv.editor.graphics.frames; + +import java.awt.BorderLayout; +import java.awt.Font; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; + +/** + * The AboutForm class is the dialog displaying information about application. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class AboutForm extends InfoDialog { + + private static final long serialVersionUID = -4631230976081227814L; + + /** The size of the title font */ + private static final int TITLE_FONT = 12; + + /** The single instance of the dialog */ + private static AboutForm instance; + + /** + * Initializes a newly created AboutForm with its title. + */ + public AboutForm() { + super("frame.about.title"); + } + + /** + * Creates and shows the dialog with information about application. + */ + public static void showDialog() { + instance = new AboutForm(); + instance.setVisible(true); + } + + @Override + protected JPanel createContent() { + JPanel content = new JPanel(); + JPanel panelImage = new JPanel(); + JLabel logoLabel = new JLabel(); + + logoLabel.setIcon(EditorIcon.createLargeEditorIcon()); + panelImage.add(logoLabel); + + JPanel panelText = new JPanel(); + panelText.setLayout(new BoxLayout(panelText, BoxLayout.Y_AXIS)); + panelText.setBorder(BorderFactory.createEmptyBorder(HORIZONTAL_MARGIN, VERTICAL_MARGIN, + HORIZONTAL_MARGIN, VERTICAL_MARGIN)); + + JLabel titleLabel = new JLabel(ResourceController.getMessage("editor.title")); + titleLabel.setFont(new Font("SansSerif", Font.BOLD, TITLE_FONT)); + titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 30)); + + panelText.add(titleLabel); + panelText.add(Box.createHorizontalGlue()); + panelText.add(new JLabel(ResourceController.getMessage("frame.about.version", + OptionItems.APPLICATION_VERSION))); + panelText.add(new JLabel(ResourceController.getMessage("frame.about.author"))); + + content.add(panelImage, BorderLayout.WEST); + content.add(panelText, BorderLayout.EAST); + return content; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/ConfigInfoForm.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/ConfigInfoForm.java new file mode 100644 index 000000000..36fe64427 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/ConfigInfoForm.java @@ -0,0 +1,211 @@ +package cz.zcu.fav.kiv.editor.graphics.frames; + +import java.awt.Dimension; +import java.awt.Font; +import java.io.File; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SpringLayout; + +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; +import cz.zcu.fav.kiv.editor.graphics.utils.SpringUtilities; +import cz.zcu.fav.kiv.editor.template.TemplateConst; + +/** + * The ConfigInfoForm class is the dialog displaying information about configuratio + * files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ConfigInfoForm extends InfoDialog { + + private static final long serialVersionUID = -4631230976081227814L; + + /** The width of the line */ + private static final int LINE_WIDTH = 80; + + /** The number of rows in the dialog */ + private static final int ROW_COUNT = 4; + + /** The number of columns in the dialog */ + private static final int COLUMN_COUNT = 3; + + /** The size of the font */ + private static final int FONT_SIZE = 11; + + /** The size of the margin */ + private static final int MARGIN = 3; + + /** The size of the right margin */ + private static final int MARGIN_RIGHT = 10; + + /** The inner width of the dialog */ + private static final int DIALOG_INNER_WIDTH = 490; + + /** The outer width of the dialog */ + private static final int DIALOG_OUTER_WIDTH = 500; + + /** The single instance of the dialog */ + private static ConfigInfoForm instance; + + /** + * Initializes a newly created ConfigInfoForm with its title. + */ + public ConfigInfoForm() { + super("frame.config_info.title"); + } + + /** + * Creates and shows the dialog with information about application. + */ + public static void showDialog() { + instance = new ConfigInfoForm(); + instance.setVisible(true); + } + + @Override + protected JPanel createContent() { + JPanel content = new JPanel(); + + JPanel dirPanel = new JPanel(); + dirPanel.setBorder(BorderFactory.createTitledBorder(ResourceController + .getMessage("frame.config_info.directory"))); + String labelText = System.getProperty("user.dir") + File.separator + + OptionItems.XML_DEFINITION_PATH; + labelText = wrapLabel(labelText); + JLabel dirLabel = new JLabel("" + labelText + ""); + dirLabel.setFont(new Font("Sans-Serif", Font.BOLD, FONT_SIZE)); + dirPanel.add(dirLabel); + dirPanel.setPreferredSize(new Dimension(DIALOG_INNER_WIDTH, + dirPanel.getPreferredSize().height)); + + content.add(dirPanel); + JPanel filePanel = filePanel(); + content.add(filePanel()); + JPanel templatePanel = templatePanel(); + content.add(templatePanel); + + content.setPreferredSize(new Dimension(DIALOG_OUTER_WIDTH, + dirPanel.getPreferredSize().height + filePanel.getPreferredSize().height + + templatePanel.getPreferredSize().height + 20)); + + return content; + } + + /** + * Creates the panel contenting the information about stylesheet template. + * + * @return the panel contenting the information about stylesheet template. + */ + private JPanel templatePanel() { + JPanel templatePanel = new JPanel(); + templatePanel.setBorder(BorderFactory.createTitledBorder(ResourceController + .getMessage("frame.config_info.template.title"))); + + String labelText = System.getProperty("user.dir") + File.separator + + TemplateConst.CONF_FILE_TEMPLATE; + labelText = wrapLabel(labelText); + JLabel dirLabel = new JLabel("" + labelText + ""); + dirLabel.setFont(new Font("Sans-Serif", Font.BOLD, FONT_SIZE)); + templatePanel.add(dirLabel); + + templatePanel.setPreferredSize(new Dimension(DIALOG_INNER_WIDTH, templatePanel + .getPreferredSize().height)); + return templatePanel; + } + + /** + * Creates the panel contenting the information about configuration files. + * + * @return the panel contenting the information about configuration files. + */ + private JPanel filePanel() { + ImageIcon img = EditorIcon.createHelpIcon(); + + JPanel configPanel = new JPanel(); + configPanel.setBorder(BorderFactory.createTitledBorder(ResourceController + .getMessage("frame.config_info.files.title"))); + configPanel.setLayout(new SpringLayout()); + + // config.xml + JLabel iconLabel = new JLabel(); + iconLabel.setIcon(img); + iconLabel.setToolTipText(ResourceController + .getMessage("frame.config_info.files.config.description")); + configPanel.add(iconLabel); + configPanel.add(new JLabel(FileConst.CONF_FILE_CONFIG.substring(FileConst.CONF_FILE_CONFIG + .indexOf(File.separator) + 1))); + JTextField valueField = new JTextField(System.getProperty("user.dir") + File.separator + + FileConst.CONF_FILE_CONFIG); + valueField.setEditable(false); + configPanel.add(valueField); + + // attributes.xml + iconLabel = new JLabel(); + iconLabel.setIcon(img); + iconLabel.setToolTipText(ResourceController + .getMessage("frame.config_info.files.attributes.description")); + configPanel.add(iconLabel); + configPanel.add(new JLabel(FileConst.CONF_FILE_ATTRIBUTES + .substring(FileConst.CONF_FILE_ATTRIBUTES.indexOf(File.separator) + 1))); + valueField = new JTextField(System.getProperty("user.dir") + File.separator + + FileConst.CONF_FILE_ATTRIBUTES); + valueField.setEditable(false); + configPanel.add(valueField); + + // types.xml + iconLabel = new JLabel(); + iconLabel.setIcon(img); + iconLabel.setToolTipText(ResourceController + .getMessage("frame.config_info.files.types.description")); + configPanel.add(iconLabel); + configPanel.add(new JLabel(FileConst.CONF_FILE_TYPE.substring(FileConst.CONF_FILE_TYPE + .indexOf(File.separator) + 1))); + valueField = new JTextField(System.getProperty("user.dir") + File.separator + + FileConst.CONF_FILE_TYPE); + valueField.setEditable(false); + configPanel.add(valueField); + + // graphics + iconLabel = new JLabel(); + iconLabel.setIcon(img); + iconLabel.setToolTipText(ResourceController + .getMessage("frame.config_info.files.graphics.description")); + configPanel.add(iconLabel); + configPanel.add(new JLabel(FileConst.CONF_FILE_FIGURES + .substring(FileConst.CONF_FILE_FIGURES.indexOf(File.separator) + 1))); + valueField = new JTextField(System.getProperty("user.dir") + File.separator + + FileConst.CONF_FILE_FIGURES); + valueField.setEditable(false); + configPanel.add(valueField); + + SpringUtilities.makeCompactGrid(configPanel, ROW_COUNT, COLUMN_COUNT, MARGIN, MARGIN, + MARGIN_RIGHT, MARGIN); + configPanel.setPreferredSize(new Dimension(DIALOG_INNER_WIDTH, configPanel + .getPreferredSize().height)); + return configPanel; + } + + /** + * Wraps string line - adds
+ * if the line is longer than LINE_WIDTH. + * + * @param text + * not wrapped text. + * @return the wrapped text. + */ + private String wrapLabel(String text) { + if (text.length() > LINE_WIDTH) + text = text.substring(0, LINE_WIDTH) + "
" + + text.substring(LINE_WIDTH, text.length()); + return text; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/HelpFrame.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/HelpFrame.java new file mode 100644 index 000000000..ce4250519 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/HelpFrame.java @@ -0,0 +1,72 @@ +package cz.zcu.fav.kiv.editor.graphics.frames; + +import java.net.URL; + +import javax.help.HelpBroker; +import javax.help.HelpSet; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; + +/** + * The HelpFrame class is the frame displaying application help. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class HelpFrame { + private static final String HELPSET = "jhelpset.hs"; + + /** The help set */ + private HelpSet helpSet; + + /** The help broker */ + private HelpBroker helpBroker; + + /** The single instance of the frame */ + private static HelpFrame instance; + + /** + * Returns the single instance of the help frame. + * + * @return single instance of the help frame. + */ + public static HelpFrame getInstance() { + if (instance == null) + instance = new HelpFrame(); + return instance; + } + + /** + * Initializes a newly created HelpFrame. + */ + public HelpFrame() { + } + + /** + * Creates the new help content according to the actual application language locale. + */ + public void createHelp() { + if ((helpSet != null) && (!helpSet.getLocale().equals(OptionItems.LANGUAGE))) + helpSet = null; + if (helpSet == null) { + createHelpSet(); + helpBroker = helpSet.createHelpBroker(); + } + helpBroker.setDisplayed(true); + } + + /** + * Initializes the help set according to the file jhelpset.hs. + */ + private void createHelpSet() { + ClassLoader loader = this.getClass().getClassLoader(); + try { + URL url = HelpSet.findHelpSet(loader, HELPSET); + helpSet = new HelpSet(null, url); + } catch (Exception ex) { + Log.error(ex); + } + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/InfoDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/InfoDialog.java new file mode 100644 index 000000000..0243c0973 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/frames/InfoDialog.java @@ -0,0 +1,80 @@ +package cz.zcu.fav.kiv.editor.graphics.frames; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The abstract class InfoDialog is the dialog used for displaying various information. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public abstract class InfoDialog extends JDialog implements ActionListener { + + private static final long serialVersionUID = -4632123976081227814L; + + /** The size of horizontal margin */ + protected static final int HORIZONTAL_MARGIN = 8; + + /** The size of vertical margin */ + protected static final int VERTICAL_MARGIN = 25; + + /** + * Initializes a newly created InfoDialog with specified title. + * + * @param title + * the title of the dialog. + */ + protected InfoDialog(String title) { + super(MainFrame.getInstance(), ResourceController.getMessage(title), true); + this.setLocationRelativeTo(MainFrame.getInstance()); + } + + /** + * Initializes the content of the dialog. + */ + public void dialogInit() { + JPanel buttonPane = new JPanel(); + buttonPane.setBorder(BorderFactory.createEmptyBorder(HORIZONTAL_MARGIN, VERTICAL_MARGIN, + HORIZONTAL_MARGIN, VERTICAL_MARGIN)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + + JButton button = new JButton(ResourceController.getMessage("button.ok")); + button.addActionListener(this); + buttonPane.add(button); + + super.dialogInit(); + Container content = this.getContentPane(); + content.add(createContent(), BorderLayout.PAGE_START); + content.add(buttonPane, BorderLayout.PAGE_END); + + pack(); + } + + /** + * Creates the panel forming the content of the dialog. + * + * @return the panel forming the content of the dialog. + */ + abstract protected JPanel createContent(); + + /** + * Action performed when a button of dialog is pressed - then the dialog closes. + */ + public void actionPerformed(ActionEvent e) { + this.setVisible(false); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/EditorIcon.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/EditorIcon.java new file mode 100644 index 000000000..f2100b995 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/EditorIcon.java @@ -0,0 +1,106 @@ +package cz.zcu.fav.kiv.editor.graphics.images; + +import java.awt.Image; + +import javax.swing.ImageIcon; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The EditorIconclass is used for loading images used in the editor. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class EditorIcon { + /** The path to the directory where images are stored */ + private static final String ICON_PATH = '\u002f' + + EditorIcon.class.getPackage().getName().replace('.', '\u002f') + '\u002f' + + "resources" + '\u002f'; + + /** The name of the image file representing main editor icon */ + private static final String EDITOR_ICON_PATH = ICON_PATH + "icon.png"; + + /** The name of the image file representing tab */ + private static final String TAB_ICON_PATH = ICON_PATH + "tab.png"; + + /** The name of the image file representing help */ + private static final String HELP_ICON_PATH = ICON_PATH + "help.png"; + + /** The name of the image file representing browser */ + private static final String BROWSER_ICON_PATH = ICON_PATH + "browser.png"; + + /** The name of the image file representing colors chooser */ + private static final String COLOR_ICON_PATH = ICON_PATH + "colors.png"; + + /** + * Loads the main editor icon. + * + * @return the main editor icon. + */ + public static Image createEditorIcon() { + final ImageIcon imageIcon = createIcon(EDITOR_ICON_PATH); + return imageIcon != null ? imageIcon.getImage() : null; + } + + /** + * Loads the icon from the input file. + * + * @param image + * the name of the file where the icon is stored. + * @return the icon loaded from the input file. + */ + private static ImageIcon createIcon(String image) { + try { + return new ImageIcon(EditorIcon.class.getResource(image)); + } catch (Exception ex) { + Log.error("error.editor_icon", ex); + } + return null; + } + + /** + * Loads the large editor icon. + * + * @return the large editor icon. + */ + public static ImageIcon createLargeEditorIcon() { + return createIcon(EDITOR_ICON_PATH); + } + + /** + * Loads the tab icon. + * + * @return the tab icon. + */ + public static ImageIcon createTabIcon() { + return createIcon(TAB_ICON_PATH); + } + + /** + * Loads the help icon. + * + * @return the help icon. + */ + public static ImageIcon createHelpIcon() { + return createIcon(HELP_ICON_PATH); + } + + /** + * Loads the browser icon. + * + * @return the browser icon. + */ + public static ImageIcon createBrowserIcon() { + return createIcon(BROWSER_ICON_PATH); + } + + /** + * Loads the colors chooser icon. + * + * @return the colors chooser icon. + */ + public static ImageIcon createColorIcon() { + return createIcon(COLOR_ICON_PATH); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/browser.png b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/browser.png new file mode 100644 index 000000000..a97130f13 Binary files /dev/null and b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/browser.png differ diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/colors.png b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/colors.png new file mode 100644 index 000000000..59c64c19d Binary files /dev/null and b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/colors.png differ diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/help.png b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/help.png new file mode 100644 index 000000000..f25fc3fbf Binary files /dev/null and b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/help.png differ diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/icon.png b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/icon.png new file mode 100644 index 000000000..c4d5af81b Binary files /dev/null and b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/icon.png differ diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/tab.png b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/tab.png new file mode 100644 index 000000000..7f1299e9d Binary files /dev/null and b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/images/resources/tab.png differ diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/IntroException.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/IntroException.java new file mode 100644 index 000000000..a92362b6c --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/IntroException.java @@ -0,0 +1,21 @@ +package cz.zcu.fav.kiv.editor.graphics.intro; + + +/** + * The IntroException class is used for reporting errors generated in the intro frame during loading configuration + * files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class IntroException extends Exception { + + private static final long serialVersionUID = -5259345670724739417L; + + /** + * Initializes a newly created empty IntroException. + */ + public IntroException() { + super(); + } +} \ No newline at end of file diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/IntroFrame.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/IntroFrame.java new file mode 100644 index 000000000..d2f8f59fd --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/IntroFrame.java @@ -0,0 +1,67 @@ +package cz.zcu.fav.kiv.editor.graphics.intro; + +import java.awt.Dimension; +import java.awt.EventQueue; + +import javax.swing.JComponent; +import javax.swing.JFrame; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; +import cz.zcu.fav.kiv.editor.graphics.utils.FrameShower; + +/** + * The IntroFrame class represents the intro frame displaying the loading of configuration files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class IntroFrame extends JFrame { + + private static final long serialVersionUID = 1293269978761922832L; + + /** + * Initializes a newly created IntroFrame and launches loading of configuration files. + * @throws IntroException if an error occurs during loading of configuration files. + */ + public IntroFrame() throws IntroException { + super(ResourceController.getMessage("frame.intro.title")); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + setIconImage(EditorIcon.createEditorIcon()); + + // Create and set up the content pane. + JComponent newContentPane = new ProgressBar(); + newContentPane.setOpaque(true); + this.setContentPane(newContentPane); + + Dimension dim = getToolkit().getScreenSize(); + Dimension abounds = getPreferredSize(); + this.setLocation((dim.width - abounds.width) / 2, (dim.height - abounds.height) / 2); + this.setResizable(false); + + // Display the window. + Runnable runner = new FrameShower(this); + try { + EventQueue.invokeAndWait(runner); + } catch (Exception ex) { + Log.warn(ex); + } + + ProgressBar.getTimer().start(); + ProgressBar.getTask().go(); + + if (ProgressBar.getTask().isCanceled()) + throw new IntroException(); + } + + /** + * Hides and dispose the intro frame. + */ + public void hideFrame() { + this.setVisible(false); + this.dispose(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/ProgressBar.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/ProgressBar.java new file mode 100644 index 000000000..d70a995dd --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/intro/ProgressBar.java @@ -0,0 +1,139 @@ +package cz.zcu.fav.kiv.editor.graphics.intro; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.JTextPane; +import javax.swing.Timer; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.controller.ProgressControl; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The ProgressBar class is the progress bar used for displaying the progress of + * configuration files loading. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ProgressBar extends JPanel { + + private static final long serialVersionUID = 1982246205327449245L; + + /** The width of the progress bar */ + private static final int WIDTH = 400; + + /** The height of the progress bar */ + private static final int HEIGHT = 150; + + /** The size of margin of the progress bar */ + private static final int MARGIN = 10; + + /** The interval of timer launching */ + private final static int TIME_INTERVAL = 50; + + /** The progress bar */ + private static JProgressBar progressBar; + + /** The timer controlling the displaying of progress */ + private static Timer timer; + + /** The text pane displaying information about progress */ + private JTextPane editor; + + /** The mutable attribute set of the JTextPane */ + private MutableAttributeSet mutAttr; + + /** The styled document of the JTextPane */ + private StyledDocument styledDoc; + + /** The class controlling the loading the configuration files */ + private static ProgressControl task; + + /** + * Initializes a newly created ProgressBar. Starts the task that loads the + * configuration files and simultaneously starts the timer. + */ + public ProgressBar() { + super(new BorderLayout(MARGIN, MARGIN)); + + task = new ProgressControl(); + progressBar = new JProgressBar(); + progressBar.setValue(0); + progressBar.setStringPainted(true); + + JProgressBar progressBarIndetermin = new JProgressBar(); + progressBarIndetermin.setIndeterminate(true); + progressBarIndetermin.setStringPainted(true); + progressBarIndetermin.setString(ResourceController.getMessage("frame.intro.progress.loading_file")); + + editor = new JTextPane(); + mutAttr = new SimpleAttributeSet(); + styledDoc = editor.getStyledDocument(); + StyleConstants.setForeground(mutAttr, Color.black); + + add(progressBar, BorderLayout.PAGE_START); + add(progressBarIndetermin, BorderLayout.PAGE_END); + + JScrollPane scrollBar = new JScrollPane(editor); + scrollBar.setPreferredSize(new Dimension(WIDTH, HEIGHT)); + add(scrollBar, BorderLayout.CENTER); + this.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); + + // Create a timer. + timer = new Timer(TIME_INTERVAL, new ActionListener() { + public void actionPerformed(ActionEvent evt) { + progressBar.setValue(task.getCurrent()); + try { + if ((task.getMessage() != null) && (!task.isCanceled())) { + if (styledDoc.getLength() < task.getMessage().length()) { + styledDoc.remove(0, styledDoc.getLength()); + styledDoc.insertString(0, task.getMessage(), mutAttr); + } + } + if (task.isDone()) { + timer.stop(); + progressBar.setValue(progressBar.getMaximum()); + styledDoc.insertString(0, task.getMessage(), mutAttr); + } + if (task.isCanceled()) { + timer.stop(); + styledDoc.remove(0, styledDoc.getLength()); + styledDoc.insertString(0, task.getMessage(), mutAttr); + StyleConstants.setForeground(mutAttr, Color.red); + styledDoc.insertString(styledDoc.getLength(), task.getErrorMessage(), + mutAttr); + progressBar.setIndeterminate(false); + } + } catch (Exception ex) { + Log.error(ex); + } + } + }); + } + + public static ConfigData getData() { + return task.getData(); + } + + public static Timer getTimer() { + return timer; + } + + public static ProgressControl getTask() { + return task; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/EditorOptionForm.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/EditorOptionForm.java new file mode 100644 index 000000000..77c8eb19b --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/EditorOptionForm.java @@ -0,0 +1,202 @@ +package cz.zcu.fav.kiv.editor.graphics.options; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SpringLayout; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.LanguageEnum; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; +import cz.zcu.fav.kiv.editor.graphics.utils.SpringUtilities; + +/** + * The EditorOptionFormclass is the form with stylesheet options. It makes the content + * of the OptionEditorDialog dialog. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class EditorOptionForm extends JPanel { + + private static final long serialVersionUID = -1040245299541084094L; + + /** The number of rows in the form */ + private static final int ROW_COUNT = 3; + + /** The number of columns in the form */ + private static final int COLUMN_COUNT = 3; + + /** The width of the field with file path */ + private static final int FILE_FIELD_WIDTH = 200; + + /** The size of component margin */ + private static final int COMPONENT_MARGIN = 3; + + /** The label containing option name */ + private JLabel iconLabel; + + /** The icon image representing option item help */ + private ImageIcon image; + + /** + * The text-field specifying path of the directory with files containing XML definitions of + * parameters + */ + private JTextField xmlDefPathField; + + /** The combo-box specifying language of the editor */ + private JComboBox languageBox; + + /** The check-box specifying whether the editor console is erased before every action */ + private JCheckBox eraseConsoleCheck; + + /** + * Initializes a newly created EditorOptionForm. + */ + public EditorOptionForm() { + this.setLayout(new SpringLayout()); + + this.setBorder(BorderFactory.createEtchedBorder()); + + image = EditorIcon.createHelpIcon(); + + optionLanguage(); + optionXmlDefPath(); + optionEraseConsole(); + + SpringUtilities.makeCompactGrid(this, ROW_COUNT, COLUMN_COUNT, COMPONENT_MARGIN, + COMPONENT_MARGIN, COMPONENT_MARGIN, COMPONENT_MARGIN); + } + + /** + * Adds to the form the option item specifying language of the editor. + */ + private void optionLanguage() { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_editor.language.description")); + iconLabel.setIcon(image); + this.add(iconLabel); + // name + this.add(new JLabel(ResourceController.getMessage("option_editor.language"))); + // value + languageBox = new JComboBox(LanguageEnum.values()); + languageBox.setSelectedItem(LanguageEnum.getLanguage(OptionItems.LANGUAGE)); + this.add(languageBox); + } + + /** + * Adds to the form the option item specifying the path directory with files containing XML + * definitions of parameters. + */ + private void optionXmlDefPath() { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_editor.xml_definition_path.description")); + iconLabel.setIcon(image); + this.add(iconLabel); + // name + this.add(new JLabel(ResourceController.getMessage("option_editor.xml_definition_path"))); + // value + this.add(createFileChooser()); + } + + /** + * Creates the panel with a text-field and button that shows a file chooser dialog. The chosen + * file path is saved to the text-field. + * + * @return the panel used for choosing file paths. + */ + private JPanel createFileChooser() { + JPanel valuePanel = new JPanel(); + xmlDefPathField = new JTextField(OptionItems.XML_DEFINITION_PATH); + xmlDefPathField.setPreferredSize(new Dimension(FILE_FIELD_WIDTH, xmlDefPathField + .getPreferredSize().height)); + valuePanel.add(xmlDefPathField); + JButton chooseButton = new JButton(ResourceController + .getMessage("option_editor.xml_definition_path.button")); + chooseButton.addActionListener(new ChoosePath()); + valuePanel.add(chooseButton); + return valuePanel; + } + + /** + * Adds to the form the option item specifying whether the editor console is erased before every + * action. + */ + private void optionEraseConsole() { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_editor.erase_console.description")); + iconLabel.setIcon(image); + this.add(iconLabel); + // name + this.add(new JLabel(ResourceController.getMessage("option_editor.erase_console"))); + // value + eraseConsoleCheck = new JCheckBox(); + if (OptionItems.ERASE_CONSOLE) + eraseConsoleCheck.setSelected(true); + this.add(eraseConsoleCheck); + } + + /** + * Saves the changes of editor options made in the dialog by user. + */ + public void saveChanges() { + OptionItems.XML_DEFINITION_PATH = xmlDefPathField.getText(); + if (!((LanguageEnum) languageBox.getSelectedItem()).getLocale() + .equals(OptionItems.LANGUAGE)) + OptionItems.changeLanguage(((LanguageEnum) languageBox.getSelectedItem()).getLocale()); + OptionItems.ERASE_CONSOLE = eraseConsoleCheck.isSelected(); + Log.info("info.option_form.editor.save_values"); + } + + /** + * Sets default values to all editor options in the dialog. + */ + public void updateValues() { + languageBox.setSelectedItem(LanguageEnum.getLanguage(OptionItems.LANGUAGE)); + xmlDefPathField.setText(OptionItems.XML_DEFINITION_PATH); + eraseConsoleCheck.setSelected(OptionItems.ERASE_CONSOLE); + Log.info("info.option_form.editor.update_values"); + } + + /** + * The ChoosePath class shows the open file dialog that enables to choose a + * directory. Then the chosen directory path is saved to the xmlDefPathField. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class ChoosePath implements ActionListener { + public void actionPerformed(ActionEvent e) { + JFileChooser fc = new JFileChooser(); + File directory = new File(OptionItems.XML_DEFINITION_PATH); + if (directory.exists()) + fc.setCurrentDirectory(directory); + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int returnVal = fc.showOpenDialog(MainFrame.getInstance()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + xmlDefPathField.setText(fc.getSelectedFile().getPath()); + } + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionDialog.java new file mode 100644 index 000000000..898c2e8f2 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionDialog.java @@ -0,0 +1,142 @@ +package cz.zcu.fav.kiv.editor.graphics.options; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The abstract class OptionDialog is the dialog used for editing application + * options. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public abstract class OptionDialog extends JDialog implements ActionListener { + + private static final long serialVersionUID = -6526357047305363516L; + + /** The width of the dialog */ + private static final int DIALOG_WIDTH = 500; + + /** The size of margin */ + private static final int MARGIN = 10; + + /** The command SAVE */ + private static final String SAVE_COMMAND = "save"; + + /** The option dialog */ + protected static OptionDialog dialog; + + /** + * Initializes a newly created OptionDialog with specified title. + * + * @param title + * the title of the dialog. + */ + protected OptionDialog(String title) { + super(MainFrame.getInstance(), ResourceController.getMessage(title), true); + + Container pan = new JPanel(new BorderLayout()); + + JPanel contentPanel = new JPanel(); + contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); + + contentPanel.add(createForm()); + + pan.add(contentPanel, BorderLayout.PAGE_START); + pan.add(createButtonPane(), BorderLayout.PAGE_END); + + this.getContentPane().add(pan, BorderLayout.CENTER); + this.setResizable(false); + + this.pack(); + this.setSize(new Dimension(DIALOG_WIDTH, this.getHeight())); + this.setLocationRelativeTo(MainFrame.getInstance()); + } + + /** + * Creates the form that makes the content of the dialog. + * + * @return the form creating the dialog content. + */ + protected abstract JPanel createForm(); + + /** + * Saves the changes of options made in the dialog by user. + */ + protected abstract void saveChanges(); + + /** + * Sets default values to all options in the dialog. + */ + protected abstract void updateValues(); + + /** + * Action performed when a button of dialog is pressed. If the button is Save, then the changes + * of options are saved. + */ + public void actionPerformed(ActionEvent e) { + if (SAVE_COMMAND.equals(e.getActionCommand())) { + saveChanges(); + } + + OptionDialog.dialog.setVisible(false); + OptionDialog.dialog.dispose(); + } + + /** + * Creates the dialog panel with buttons. + * + * @return the panel with buttons. + */ + private JPanel createButtonPane() { + JButton defaultButton = new JButton(ResourceController.getMessage("button.default")); + defaultButton.addActionListener(new ChangeDefault()); + + JButton cancelButton = new JButton(ResourceController.getMessage("button.cancel")); + cancelButton.addActionListener(this); + + JButton setButton = new JButton(ResourceController.getMessage("button.save")); + setButton.setActionCommand(SAVE_COMMAND); + setButton.addActionListener(this); + getRootPane().setDefaultButton(setButton); + + // Lay out the buttons from left to right. + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(defaultButton); + buttonPane.add(Box.createRigidArea(new Dimension(3 * MARGIN, 0))); + buttonPane.add(setButton); + buttonPane.add(Box.createRigidArea(new Dimension(MARGIN, 0))); + buttonPane.add(cancelButton); + + return buttonPane; + } + + /** + * The inner class ChangeDefault class sets default values to options in the + * dialog when the button Restore Defaults is set. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ + class ChangeDefault implements ActionListener { + public void actionPerformed(ActionEvent e) { + updateValues(); + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionEditorDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionEditorDialog.java new file mode 100644 index 000000000..3c02b32b8 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionEditorDialog.java @@ -0,0 +1,52 @@ +package cz.zcu.fav.kiv.editor.graphics.options; + +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.controller.options.OptionController; + +/** + * The OptionEditorDialogclass is the dialog used for editing editor options. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OptionEditorDialog extends OptionDialog { + + private static final long serialVersionUID = 7118079845557600112L; + + /** The editor option dialog */ + private EditorOptionForm editorOptionForm; + + /** + * Creates and shows the dialog with editor options. + */ + public static void showDialog() { + dialog = new OptionEditorDialog(); + dialog.setVisible(true); + } + + /** + * Initializes a newly created OptionEditorDialog with its title. + */ + public OptionEditorDialog() { + super("frame.option.editor.title"); + } + + @Override + protected JPanel createForm() { + editorOptionForm = new EditorOptionForm(); + return editorOptionForm; + } + + @Override + protected void saveChanges() { + editorOptionForm.saveChanges(); + } + + @Override + protected void updateValues() { + OptionController.setDefaultEditorOptions(); + editorOptionForm.updateValues(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionStylesheetDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionStylesheetDialog.java new file mode 100644 index 000000000..2477f9f33 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/OptionStylesheetDialog.java @@ -0,0 +1,53 @@ +package cz.zcu.fav.kiv.editor.graphics.options; + +import javax.swing.JPanel; + +import cz.zcu.fav.kiv.editor.controller.options.OptionController; + +/** + * The OptionStylesheetDialogclass is the dialog used for editing stylesheet + * options. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OptionStylesheetDialog extends OptionDialog { + + private static final long serialVersionUID = 7118079159557600112L; + + /** The stylesheet option dialog */ + private StylesheetOptionForm stylesheetOptionForm; + + /** + * Shows the dialog with stylesheet options. + */ + public static void showDialog() { + dialog = new OptionStylesheetDialog(); + dialog.setVisible(true); + } + + /** + * Initializes a newly created OptionStylesheetDialog with its title. + */ + public OptionStylesheetDialog() { + super("frame.option.save.title"); + } + + @Override + protected JPanel createForm() { + stylesheetOptionForm = new StylesheetOptionForm(); + return stylesheetOptionForm; + } + + @Override + protected void saveChanges() { + stylesheetOptionForm.saveChanges(); + } + + @Override + protected void updateValues() { + OptionController.setDefaultStylesheetOptions(); + stylesheetOptionForm.updateValues(); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/StylesheetOptionForm.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/StylesheetOptionForm.java new file mode 100644 index 000000000..a1eb7ba56 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/options/StylesheetOptionForm.java @@ -0,0 +1,375 @@ +package cz.zcu.fav.kiv.editor.graphics.options; + +import java.awt.Dimension; +import java.awt.Font; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SpringLayout; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.EncodingEnum; +import cz.zcu.fav.kiv.editor.controller.options.NewlineEnum; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; +import cz.zcu.fav.kiv.editor.controller.resource.ErrorResourceController; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.images.EditorIcon; +import cz.zcu.fav.kiv.editor.graphics.utils.SpringUtilities; + +/** + * The StylesheetOptionFormclass is the form with editor options. It makes the + * content of the OptionStylesheetDialog dialog. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class StylesheetOptionForm extends JPanel { + + private static final long serialVersionUID = -1040245299541084094L; + + /** The number of columns in the form */ + private static final int COLUMN_COUNT = 3; + + /** The number of rows in the first panel of the form */ + private static final int ROW_1_COUNT = 3; + + /** The number of rows in the second panel of the form */ + private static final int ROW_2_COUNT = 3; + + /** The number of rows in the third panel of the form */ + private static final int ROW_3_COUNT = 2; + + /** The inner width of the form panel */ + private static final int PANEL_INNER_WIDTH = 490; + + /** The outer width of the form panel */ + private static final int PANEL_OUTER_WIDTH = 500; + + /** The size of component margin */ + private static final int COMPONENT_MARGIN = 3; + + /** The label containing option name */ + private JLabel iconLabel; + + /** The icon image representing option item help */ + private ImageIcon image; + + /** The check-box specifying whether FO namespace is appended to the stylesheet definiton */ + private JCheckBox addFoNamespaceCheck; + + /** The check-box specifying whether the rearrange saving is used */ + private JCheckBox changeSaveCheck; + + /** The check-box specifying whether comments are generated in the stylesheet */ + private JCheckBox generateCommentsCheck; + + /** The check-box specifying whether attribute select is used in parameter elements */ + private JCheckBox useParamSelectCheck; + + /** The combo-box specifying encoding of output files */ + private JComboBox encodingBox; + + /** The combo-box specifying char of ends of lines in output files */ + private JComboBox newlineBox; + + /** The text-field specifying stylesheet version */ + private JTextField stylesheetVersionField; + + /** The text-area specifying imported stylesheet files */ + private JTextArea importFileArea; + + /** + * Initializes a newly created StylesheetOptionForm. + */ + public StylesheetOptionForm() { + image = EditorIcon.createHelpIcon(); + + JPanel panelOne = createPanelOne(); + this.add(panelOne); + + JPanel panelTwo = createPanelTwo(); + this.add(panelTwo); + + JPanel panelThree = createPanelThree(); + this.add(panelThree); + this.setPreferredSize(new Dimension(PANEL_OUTER_WIDTH, panelOne.getPreferredSize().height + + panelTwo.getPreferredSize().height + panelThree.getPreferredSize().height + 20)); + } + + /** + * Creates the first form panel with options of new stylesheets. + * + * @return the panel with options of new stylesheets. + */ + private JPanel createPanelOne() { + JPanel panel = new JPanel(); + panel.setLayout(new SpringLayout()); + panel.setBorder(BorderFactory.createTitledBorder(ResourceController + .getMessage("option_save.new_file_template.title"))); + optionImportedFiles(panel); + optionStylesheetVersion(panel); + optionAddFoNamespace(panel); + SpringUtilities.makeCompactGrid(panel, ROW_1_COUNT, COLUMN_COUNT, COMPONENT_MARGIN, + COMPONENT_MARGIN, COMPONENT_MARGIN, COMPONENT_MARGIN); + panel.setPreferredSize(new Dimension(PANEL_INNER_WIDTH, panel.getPreferredSize().height)); + return panel; + } + + /** + * Creates the second form panel with options of all stylesheets. + * + * @return the panel with options of stylesheets. + */ + private JPanel createPanelTwo() { + JPanel panel = new JPanel(); + panel.setLayout(new SpringLayout()); + panel.setBorder(BorderFactory.createTitledBorder(ResourceController + .getMessage("option_save.stylesheet_format.title"))); + optionChangeSave(panel); + optionGenerateComments(panel); + optionUseParamSelect(panel); + SpringUtilities.makeCompactGrid(panel, ROW_2_COUNT, COLUMN_COUNT, COMPONENT_MARGIN, + COMPONENT_MARGIN, COMPONENT_MARGIN, COMPONENT_MARGIN); + panel.setPreferredSize(new Dimension(PANEL_INNER_WIDTH, panel.getPreferredSize().height)); + return panel; + } + + /** + * Creates the third form panel with options of output files. + * + * @return the panel with options of output files. + */ + private JPanel createPanelThree() { + JPanel panel = new JPanel(); + panel.setLayout(new SpringLayout()); + panel.setBorder(BorderFactory.createTitledBorder(ResourceController + .getMessage("option_save.output_file.title"))); + optionEncoding(panel); + optionNewline(panel); + SpringUtilities.makeCompactGrid(panel, ROW_3_COUNT, COLUMN_COUNT, COMPONENT_MARGIN, + COMPONENT_MARGIN, COMPONENT_MARGIN, COMPONENT_MARGIN); + panel.setPreferredSize(new Dimension(PANEL_INNER_WIDTH, panel.getPreferredSize().height)); + return panel; + } + + /** + * Adds to the panel the option item specifying whether FO namespace is appended to the + * stylesheet definiton. + * + * @param panel + * the parent panel. + */ + private void optionAddFoNamespace(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_save.add_fo_namespace.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.add_fo_namespace"))); + // value + addFoNamespaceCheck = new JCheckBox(); + if (OptionItems.ADD_FO_NAMESPACE) + addFoNamespaceCheck.setSelected(true); + panel.add(addFoNamespaceCheck); + } + + /** + * Adds to the panel the option item specifying whether the rearrange saving is used. + * + * @param panel + * the parent panel. + */ + private void optionChangeSave(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_save.change_save.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.change_save"))); + // value + JPanel valuePanel = new JPanel(); + valuePanel.setLayout(new BoxLayout(valuePanel, BoxLayout.LINE_AXIS)); + changeSaveCheck = new JCheckBox(); + if (OptionItems.REARRANGE_SAVE) + changeSaveCheck.setSelected(true); + valuePanel.add(changeSaveCheck); + valuePanel.add(Box.createRigidArea(new Dimension(10, 0))); + valuePanel + .add(new JLabel(ResourceController.getMessage("option_save.change_save.warning"))); + panel.add(valuePanel); + } + + /** + * Adds to the panel the option item specifying whether comments are generated in the + * stylesheet. + * + * @param panel + * the parent panel. + */ + private void optionGenerateComments(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_save.generate_com.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.generate_com"))); + // value + generateCommentsCheck = new JCheckBox(); + if (OptionItems.GENERATE_COMMENTS) + generateCommentsCheck.setSelected(true); + panel.add(generateCommentsCheck); + } + + /** + * Adds to the panel the option item specifying whether attribute select is used in + * parameter elements + * + * @param panel + * the parent panel. + */ + private void optionUseParamSelect(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_save.use_param_select.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.use_param_select"))); + // value + useParamSelectCheck = new JCheckBox(); + if (OptionItems.USE_PARAM_SELECT) + useParamSelectCheck.setSelected(true); + panel.add(useParamSelectCheck); + } + + /** + * Adds to the panel the option item specifying encoding of output files. + * + * @param panel + * the parent panel. + */ + private void optionEncoding(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController.getMessage("option_save.encoding.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.encoding"))); + // value + encodingBox = new JComboBox(EncodingEnum.values()); + encodingBox.setSelectedItem(EncodingEnum.getEncoding(OptionItems.ENCODING)); + panel.add(encodingBox); + } + + /** + * Adds to the panel the option item specifying char of ends of lines in output files. + * + * @param panel + * the parent panel. + */ + private void optionNewline(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController.getMessage("option_save.newline.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.newline"))); + // value + newlineBox = new JComboBox(NewlineEnum.values()); + newlineBox.setSelectedItem(OptionItems.NEWLINE); + panel.add(newlineBox); + } + + /** + * Adds to the panel the option item specifying stylesheet version. + * + * @param panel + * the parent panel. + */ + private void optionStylesheetVersion(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_save.stylesheet_version.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.stylesheet_version"))); + // value + stylesheetVersionField = new JTextField(OptionItems.STYLESHEET_VERSION); + panel.add(stylesheetVersionField); + } + + /** + * Adds to the panel the option item specifying imported stylesheet files. + * + * @param panel + * the parent panel. + */ + private void optionImportedFiles(JPanel panel) { + // interrogation mark + iconLabel = new JLabel(); + iconLabel.setToolTipText(ResourceController + .getMessage("option_save.import_file.description")); + iconLabel.setIcon(image); + panel.add(iconLabel); + // name + panel.add(new JLabel(ResourceController.getMessage("option_save.import_file"))); + // textarea + importFileArea = new JTextArea(3, 5); + importFileArea.setText(OptionItems.IMPORT_FILE); + importFileArea.setLineWrap(true); + importFileArea.setFont(new Font("SansSerif", Font.PLAIN, 12)); + JScrollPane scrollBar = new JScrollPane(importFileArea, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + panel.add(scrollBar); + } + + /** + * Saves the changes of stylesheet options made in the dialog by user. + */ + public void saveChanges() { + OptionItems.IMPORT_FILE = importFileArea.getText(); + OptionItems.ADD_FO_NAMESPACE = addFoNamespaceCheck.isSelected(); + OptionItems.REARRANGE_SAVE = changeSaveCheck.isSelected(); + OptionItems.GENERATE_COMMENTS = generateCommentsCheck.isSelected(); + OptionItems.USE_PARAM_SELECT = useParamSelectCheck.isSelected(); + OptionItems.ENCODING = ((EncodingEnum) encodingBox.getSelectedItem()).getKey(); + OptionItems.NEWLINE = (NewlineEnum) newlineBox.getSelectedItem(); + OptionItems.STYLESHEET_VERSION = stylesheetVersionField.getText(); + Log.info("info.option_form.save.save_values"); + } + + /** + * Sets default values to all stylesheet options in the dialog. + */ + public void updateValues() { + importFileArea.setText(OptionItems.IMPORT_FILE); + addFoNamespaceCheck.setSelected(OptionItems.ADD_FO_NAMESPACE); + changeSaveCheck.setSelected(OptionItems.REARRANGE_SAVE); + generateCommentsCheck.setSelected(OptionItems.GENERATE_COMMENTS); + useParamSelectCheck.setSelected(OptionItems.USE_PARAM_SELECT); + encodingBox.setSelectedItem(EncodingEnum.getEncoding(OptionItems.ENCODING)); + newlineBox.setSelectedItem(OptionItems.NEWLINE); + stylesheetVersionField.setText(OptionItems.STYLESHEET_VERSION); + Log.info(ErrorResourceController.getMessage("info.option_form.save.update_values")); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/FrameShower.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/FrameShower.java new file mode 100644 index 000000000..d6775bbbb --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/FrameShower.java @@ -0,0 +1,32 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import javax.swing.JFrame; + +/** + * The FrameShower class is used for displaying the frame in the thread safe mode. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class FrameShower implements Runnable { + /** The frame */ + private final JFrame frame; + + /** + * Initializes a newly created FrameShower with the specified frame. + * + * @param frame + * the frame. + */ + public FrameShower(JFrame frame) { + this.frame = frame; + } + + /** + * Launches the frame in the thread safe mode. + */ + public void run() { + frame.pack(); + frame.setVisible(true); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/GridLayoutUtilities.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/GridLayoutUtilities.java new file mode 100644 index 000000000..cbeb71894 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/GridLayoutUtilities.java @@ -0,0 +1,171 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.Insets; + +/** + * The GridLayoutUtilities class is used for laying out components within a + * container in the grid. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class GridLayoutUtilities extends GridLayout { + + private static final long serialVersionUID = -659668560032059816L; + + /** + * Initializes a newly created GridLayoutUtilities with specified number of rows + * and columns. + * + * @param rows + * the number of rows. + * @param cols + * the number of columns. + */ + public GridLayoutUtilities(int rows, int cols) { + this(rows, cols, 0, 0); + } + + /** + * Initializes a newly created GridLayoutUtilities with specified number of rows + * and columns and size of gaps. + * + * @param rows + * the number of rows. + * @param cols + * the number of columns. + * @param hgap + * the size of horizontal gap. + * @param vgap + * the size of vertical gap. + */ + public GridLayoutUtilities(int rows, int cols, int hgap, int vgap) { + super(rows, cols, hgap, vgap); + } + + @Override + public Dimension preferredLayoutSize(Container parent) { + synchronized (parent.getTreeLock()) { + Insets insets = parent.getInsets(); + int ncomponents = parent.getComponentCount(); + int nrows = getRows(); + int ncols = getColumns(); + if (nrows > 0) { + ncols = (ncomponents + nrows - 1) / nrows; + } else { + nrows = (ncomponents + ncols - 1) / ncols; + } + int[] w = new int[ncols]; + int[] h = new int[nrows]; + for (int i = 0; i < ncomponents; i++) { + int r = i / ncols; + int c = i % ncols; + Component comp = parent.getComponent(i); + Dimension d = comp.getPreferredSize(); + if (w[c] < d.width) { + w[c] = d.width; + } + if (h[r] < d.height) { + h[r] = d.height; + } + } + int nw = 0; + for (int j = 0; j < ncols; j++) { + nw += w[j]; + } + int nh = 0; + for (int i = 0; i < nrows; i++) { + nh += h[i]; + } + return new Dimension(insets.left + insets.right + nw + (ncols - 1) * getHgap(), + insets.top + insets.bottom + nh + (nrows - 1) * getVgap()); + } + } + + @Override + public Dimension minimumLayoutSize(Container parent) { + synchronized (parent.getTreeLock()) { + Insets insets = parent.getInsets(); + int ncomponents = parent.getComponentCount(); + int nrows = getRows(); + int ncols = getColumns(); + if (nrows > 0) { + ncols = (ncomponents + nrows - 1) / nrows; + } else { + nrows = (ncomponents + ncols - 1) / ncols; + } + int[] w = new int[ncols]; + int[] h = new int[nrows]; + for (int i = 0; i < ncomponents; i++) { + int r = i / ncols; + int c = i % ncols; + Component comp = parent.getComponent(i); + Dimension d = comp.getMinimumSize(); + if (w[c] < d.width) { + w[c] = d.width; + } + if (h[r] < d.height) { + h[r] = d.height; + } + } + int nw = 0; + for (int j = 0; j < ncols; j++) { + nw += w[j]; + } + int nh = 0; + for (int i = 0; i < nrows; i++) { + nh += h[i]; + } + return new Dimension(insets.left + insets.right + nw + (ncols - 1) * getHgap(), + insets.top + insets.bottom + nh + (nrows - 1) * getVgap()); + } + } + + @Override + public void layoutContainer(Container parent) { + synchronized (parent.getTreeLock()) { + Insets insets = parent.getInsets(); + int ncomponents = parent.getComponentCount(); + int nrows = getRows(); + int ncols = getColumns(); + if (ncomponents == 0) { + return; + } + if (nrows > 0) { + ncols = (ncomponents + nrows - 1) / nrows; + } else { + nrows = (ncomponents + ncols - 1) / ncols; + } + int hgap = getHgap(); + int vgap = getVgap(); + + int[] w = new int[ncols]; + int[] h = new int[nrows]; + for (int i = 0; i < ncomponents; i++) { + int r = i / ncols; + int c = i % ncols; + Component comp = parent.getComponent(i); + Dimension d = comp.getPreferredSize(); + w[c] = parent.getWidth(); + + if (h[r] < d.height) { + h[r] = d.height; + } + } + for (int c = 0, x = insets.left; c < ncols; c++) { + for (int r = 0, y = insets.top; r < nrows; r++) { + int i = r * ncols + c; + if (i < ncomponents) { + parent.getComponent(i).setBounds(x, y, w[c], h[r]); + } + y += h[r] + vgap; + } + x += w[c] + hgap; + } + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/OpenBrowser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/OpenBrowser.java new file mode 100644 index 000000000..e0a7802cd --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/OpenBrowser.java @@ -0,0 +1,55 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import java.lang.reflect.Method; + +import javax.swing.JOptionPane; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The OpenBrowser class is used for launching the main web browser of the operating + * system. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OpenBrowser { + + /** + * Launches the main web browser of any operating system (Mac, Windows or Unix). + * + * @param url + * the url of the page that will be opened in the web browser. + */ + public static void openURL(String url) { + String osName = System.getProperty("os.name"); + try { + if (osName.startsWith("Mac OS")) { + Class fileMgr = Class.forName("com.apple.eio.FileManager"); + Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class }); + openURL.invoke(null, new Object[] { url }); + } else if (osName.startsWith("Windows")) { + Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); + } else { // assume Unix or Linux + String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", + "netscape" }; + String browser = null; + for (int count = 0; count < browsers.length && browser == null; count++) + if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }) + .waitFor() == 0) + browser = browsers[count]; + if (browser == null) + throw new Exception("Could not find web browser"); + else + Runtime.getRuntime().exec(new String[] { browser, url }); + } + } catch (Exception ex) { + Log.error(ex); + JOptionPane.showMessageDialog(null, ResourceController.getMessage("error.open_browser") + + ":\n" + ex.getLocalizedMessage(), ResourceController + .getMessage("error.open_browser.title"), JOptionPane.WARNING_MESSAGE); + } + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/OverwriteFileDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/OverwriteFileDialog.java new file mode 100644 index 000000000..8c32de5f5 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/OverwriteFileDialog.java @@ -0,0 +1,84 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The OverwriteFileDialog class is the dialog used for asking the user if the chosen + * file should be overwritten or not. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OverwriteFileDialog { + /** The dialog panel with options */ + private final JOptionPane optionPane; + + /** The single instance of the dialog */ + private static OverwriteFileDialog instance; + + /** + * Shows the OverwriteFileDialog dialog with three options : yes, no and cancel. + * + * @param frame + * the parent frame of the option dialog. + * @return the single instance of the dialog. + */ + public static OverwriteFileDialog showDialog(final JFrame frame) { + instance = new OverwriteFileDialog(frame); + return instance; + } + + /** + * Initializes and shows a newly created OverwriteFileDialog dialog with three + * options : yes, no and cancel. + * + * @param frame + * the parent frame of the option dialog. + */ + private OverwriteFileDialog(JFrame frame) { + optionPane = new JOptionPane(ResourceController + .getMessage("save_file.dialog_file_exist.text"), JOptionPane.QUESTION_MESSAGE, + JOptionPane.YES_NO_OPTION, null, new Object[] { + ResourceController.getMessage("button.yes"), + ResourceController.getMessage("button.cancel") }, ResourceController + .getMessage("button.yes")); + final JDialog dialog = new JDialog(frame, ResourceController + .getMessage("save_file.dialog_file_exist.title"), true); + dialog.setContentPane(optionPane); + dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + + optionPane.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent e) { + String prop = e.getPropertyName(); + + if (dialog.isVisible() && (e.getSource() == optionPane) + && (prop.equals(JOptionPane.VALUE_PROPERTY))) { + dialog.setVisible(false); + } + } + }); + dialog.pack(); + dialog.setLocationRelativeTo(frame); + dialog.setVisible(true); + } + + /** + * Gets the user answer chosen in the option dialog. + * + * @return true if the user has chosen the option yes. + */ + public boolean getAnswer() { + String value = optionPane.getValue().toString(); + if (value.equals(ResourceController.getMessage("button.yes"))) + return true; + else + return false; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/SaveFileDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/SaveFileDialog.java new file mode 100644 index 000000000..dfc88affc --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/SaveFileDialog.java @@ -0,0 +1,88 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The OverwriteFileDialog class is the dialog used for asking the user if the actual + * file should be saved or not. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class SaveFileDialog { + /** The dialog panel with options */ + private JOptionPane optionPane; + + /** The single instance of the dialog */ + private static SaveFileDialog instance; + + /** + * Shows the SaveFileDialog dialog with three options : yes, no and cancel. + * + * @param frame + * the parent frame of the save dialog. + * @return the single instance of the dialog. + */ + public static SaveFileDialog showDialog(final JFrame frame) { + instance = new SaveFileDialog(frame); + return instance; + } + + /** + * Initializes and shows a newly created SaveFileDialog dialog with three options : + * yes, no and cancel. + * + * @param frame + * the parent frame of the save dialog. + */ + private SaveFileDialog(final JFrame frame) { + optionPane = new JOptionPane(ResourceController + .getMessage("save_file.dialog_save_changes.text"), JOptionPane.QUESTION_MESSAGE, + JOptionPane.YES_NO_CANCEL_OPTION, null, new Object[] { + ResourceController.getMessage("button.yes"), + ResourceController.getMessage("button.no"), + ResourceController.getMessage("button.cancel") }, ResourceController + .getMessage("button.yes")); + final JDialog dialog = new JDialog(frame, ResourceController + .getMessage("save_file.dialog_save_changes.title"), true); + dialog.setContentPane(optionPane); + dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + + optionPane.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent e) { + String prop = e.getPropertyName(); + + if (dialog.isVisible() && (e.getSource() == optionPane) + && (prop.equals(JOptionPane.VALUE_PROPERTY))) { + dialog.setVisible(false); + } + } + }); + + dialog.pack(); + dialog.setLocationRelativeTo(frame); + dialog.setVisible(true); + } + + /** + * Gets the user answer chosen in the save dialog. + * + * @return true if the user has chosen the option yes. + */ + public Boolean getAnswer() { + String value = optionPane.getValue().toString(); + if (value.equals(ResourceController.getMessage("button.yes"))) + return true; + else if (value.equals(ResourceController.getMessage("button.no"))) + return false; + else + return null; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/SpringUtilities.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/SpringUtilities.java new file mode 100644 index 000000000..20b332bc3 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/SpringUtilities.java @@ -0,0 +1,106 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import java.awt.Component; +import java.awt.Container; + +import javax.swing.Spring; +import javax.swing.SpringLayout; + +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The SpringUtilities class is used for laying out components within a container in + * the compact grid. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class SpringUtilities { + + /** + * Gets the constraints for the specified cell. + * + * @param row + * row where the cell is placed. + * @param col + * column where the cell is placed. + * @param parent + * the parent container of the cell. + * @param cols + * number of columns. + * @return the constraints for the cell. + */ + private static SpringLayout.Constraints getConstraintsForCell(int row, int col, + Container parent, int cols) { + SpringLayout layout = (SpringLayout) parent.getLayout(); + Component c = parent.getComponent(row * cols + col); + + return layout.getConstraints(c); + } + + /** + * Aligns the first rows * cols components of parent + * in a grid. Each component in a column is as wide as the maximum preferred width of the + * components in that column; height is similarly determined for each row. The parent is made + * just big enough to fit them all. + * + * @param rows + * number of rows. + * @param cols + * number of columns. + * @param initialX + * x location to start the grid at. + * @param initialY + * y location to start the grid at. + * @param xPad + * x padding between cells. + * @param yPad + * y padding between cells. + */ + public static void makeCompactGrid(Container parent, int rows, int cols, int initialX, + int initialY, int xPad, int yPad) { + SpringLayout layout; + try { + layout = (SpringLayout) parent.getLayout(); + } catch (ClassCastException exc) { + Log.error(exc); + return; + } + + // Align all cells in each column and make them the same width. + Spring x = Spring.constant(initialX); + for (int c = 0; c < cols; c++) { + Spring width = Spring.constant(0); + for (int r = 0; r < rows; r++) { + width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth()); + } + for (int r = 0; r < rows; r++) { + SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols); + constraints.setX(x); + constraints.setWidth(width); + } + x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad))); + } + + // Align all cells in each row and make them the same height. + Spring y = Spring.constant(initialY); + for (int r = 0; r < rows; r++) { + Spring height = Spring.constant(0); + for (int c = 0; c < cols; c++) { + height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight()); + } + + for (int c = 0; c < cols; c++) { + SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols); + constraints.setY(y); + constraints.setHeight(height); + } + y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad))); + } + + // Set the parent's size. + SpringLayout.Constraints pCons = layout.getConstraints(parent); + pCons.setConstraint(SpringLayout.SOUTH, y); + pCons.setConstraint(SpringLayout.EAST, x); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/XmlFilter.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/XmlFilter.java new file mode 100644 index 000000000..e64a2e923 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/XmlFilter.java @@ -0,0 +1,51 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import java.io.File; + +import javax.swing.filechooser.FileFilter; + +/** + * The XmlFilter class is used for showing only XML files in the directory listing of + * a JFileChooser. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class XmlFilter extends FileFilter { + /** The xml extension */ + public final static String xml = "xml"; + + @Override + public boolean accept(File f) { + if (f.isDirectory()) + return true; + + String extension = getExtension(f); + if ((extension != null) && (extension.equals(xml))) + return true; + + return false; + } + + @Override + public String getDescription() { + return "XML files (*.xml)"; + } + + /** + * Parses the file extension of the input file (part of the file name situated behind '.'). + * + * @param file + * the name of the file. + * @return the extension of the file. + */ + private String getExtension(File file) { + String ext = null; + int i = file.getName().lastIndexOf('.'); + + if (i > 0 && i < file.getName().length() - 1) { + ext = file.getName().substring(i + 1).toLowerCase(); + } + return ext; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/XslFilter.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/XslFilter.java new file mode 100644 index 000000000..c2e691cb2 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/graphics/utils/XslFilter.java @@ -0,0 +1,51 @@ +package cz.zcu.fav.kiv.editor.graphics.utils; + +import java.io.File; + +import javax.swing.filechooser.FileFilter; + +/** + * The XmlFilter class is used for showing only XSL files in the directory listing of + * a JFileChooser. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class XslFilter extends FileFilter { + /** The xsl extension */ + public final static String xsl = "xsl"; + + @Override + public boolean accept(File f) { + if (f.isDirectory()) + return true; + + String extension = getExtension(f); + if ((extension != null) && (extension.equals(xsl))) + return true; + + return false; + } + + @Override + public String getDescription() { + return "XSL files (*.xsl)"; + } + + /** + * Parses the file extension of the input file (part of the file name situated behind '.'). + * + * @param file + * the name of the file. + * @return the extension of the file. + */ + private String getExtension(File file) { + String ext = null; + int i = file.getName().lastIndexOf('.'); + + if (i > 0 && i < file.getName().length() - 1) { + ext = file.getName().substring(i + 1).toLowerCase(); + } + return ext; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/FileStreamOutput.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/FileStreamOutput.java new file mode 100644 index 000000000..7ddf20518 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/FileStreamOutput.java @@ -0,0 +1,102 @@ +package cz.zcu.fav.kiv.editor.stylesheet; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; + +/** + * The FileStreamOutput class is used for changing chars of ends of line (CR+LF, CR, + * LF) in the output XSL stylesheet file stream. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class FileStreamOutput extends OutputStream { + /** The output XSL file stream */ + private final FileOutputStream file; + + /** The char defining CR (carriage return) */ + private static final int CR = 13; + + /** The char defining CR (line feed) */ + private static final int LF = 10; + + /** + * Initializes a newly created FileStreamOutput with defined file output stream. + * + * @param outputStream + * the output file stream. + */ + public FileStreamOutput(final FileOutputStream outputStream) { + super(); + this.file = outputStream; + } + + @Override + public void write(int b) throws IOException { + file.write(b); + } + + @Override + public void close() throws IOException { + file.close(); + super.close(); + } + + @Override + public void flush() throws IOException { + file.flush(); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + replaceNewline(b, off, len); + } + + @Override + public void write(byte[] b) throws IOException { + replaceNewline(b, 0, b.length); + } + + /** + * Replaces chars at ends of lines. There are defined 3 types of chars: CR, LF, or CR+LF. + * + * @param byteArrray + * the array of byte representing a text. + * @param begin + * the begin of the actually processing part of the byte array. + * @param length + * the length of the actually processing part of the byte array. + * @throws IOException + */ + private void replaceNewline(byte[] byteArrray, int begin, int length) throws IOException { + for (int i = begin; i < length; i++) { + switch (OptionItems.NEWLINE) { + case CRLF: + if ((byteArrray[i] == CR) && (byteArrray[i + 1] != LF)) { + file.write(byteArrray[i]); + file.write(LF); + } else if ((byteArrray[i] != CR) && (byteArrray.length > (i + 1)) + && (byteArrray[i + 1] == LF)) { + file.write(byteArrray[i]); + file.write(CR); + } else { + file.write(byteArrray[i]); + } + break; + case CR: + if (byteArrray[i] != LF) + file.write(byteArrray[i]); + break; + case LF: + if (byteArrray[i] != CR) + file.write(byteArrray[i]); + break; + default: + file.write(byteArrray[i]); + } + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/OpenFileHadler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/OpenFileHadler.java new file mode 100644 index 000000000..3b73dd344 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/OpenFileHadler.java @@ -0,0 +1,146 @@ +package cz.zcu.fav.kiv.editor.stylesheet; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The OpenFileHadler class contains methods for processing elements of loading XSL + * stylesheet files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class OpenFileHadler { + + /** + * Parses node 'parameter' and its value in the input XSL file. + * + * @param node + * the node 'parameter' in the input XSL file. + * @param line + * the number of line where is the node 'parameter' in the input XSL file. + * @param data + * the data containing editor data structure. + */ + public static void parserParameterTag(Element node, int line, ConfigData data) { + String paramName = null; + String paramValue = null; + try { + paramName = node.getAttributeNode(XslTagConst.NAME).getNodeValue(); + // param has both - select and text value + if (node.hasAttribute(XslTagConst.SELECT) && (node.hasChildNodes())) + throw new ParserException(); + + if (node.hasAttribute(XslTagConst.SELECT)) + paramValue = node.getAttribute(XslTagConst.SELECT); + else { + Node text = node.getFirstChild(); // Text + paramValue = text.getNodeValue().toString(); + } + + Parameter param = data.searchParameter(paramName); + if (param != null) { + parserValue(param.getType(), paramValue); + param.setNode(node); + param.setChosen(); + } else { + MessageWriter.writeWarning(ResourceController.getMessage( + "open_file.parameter_exist", line, paramName)); + } + } catch (Throwable ex) { + MessageWriter.writeWarning(ResourceController.getMessage("open_file.parameter_invalid", + line, paramName)); + } + } + + /** + * Parses node 'attribute-set' and its value in the input XSL file. + * + * @param node + * the node 'attribute-set' in the input XSL file. + * @param line + * the number of line where is the node 'attribute-set' in the input XSL file. + * @param data + * the data containing editor data structure. + * @return the editor property corresponding to the node 'attribute-set' + */ + public static Property parserPropertyTag(Element node, int line, ConfigData data) { + String propName = null; + Property prop = null; + try { + propName = node.getAttributeNode(XslTagConst.NAME).getNodeValue(); + + prop = data.searchProperty(propName); + if (prop != null) { + prop.setNode(node); + prop.setChosen(); + } else + MessageWriter.writeWarning(ResourceController.getMessage( + "open_file.attribute_set_exist", line, propName)); + + } catch (Throwable ex) { + MessageWriter.writeWarning(ResourceController.getMessage( + "open_file.attribute_set_invalid", line, propName)); + } + return prop; + } + + /** + * Parses node 'attribute' of the node 'attribute-set' and its value in the input XSL file. + * + * @param node + * the node 'attribute' in the input XSL file. + * @param line + * the number of line where is the node 'attribute' in the input XSL file. + * @param propery + * the parent property of attribute. + */ + public static void parserPropertyAttribute(Element node, int line, Property propery) { + String attrName = null; + String attrValue = null; + try { + attrName = node.getAttributeNode(XslTagConst.NAME).getNodeValue(); + Node text = node.getFirstChild(); // Text + attrValue = text.getNodeValue().toString(); + + Attribute attr = propery.searchAttribute(attrName); + if (attr != null) { + parserValue(attr.getType(), attrValue); + attr.setChosen(true); + attr.setNode(node); + } else + MessageWriter.writeWarning(ResourceController.getMessage( + "open_file.attribute_exist", line, attrName)); + + } catch (Throwable ex) { + MessageWriter.writeWarning(ResourceController.getMessage("open_file.attribute_invalid", + line, attrName)); + } + } + + /** + * Parses the value of node 'parameter' and assignes it to the corresponding parameter. + * Type. + * + * @param type + * the type of parameter. + * @param typeValue + * the new value of the type. + * @throws ParserException + * if the new value is not valid. + */ + private static void parserValue(Type type, String typeValue) throws ParserException { + typeValue = typeValue.trim().replaceAll("'", ""); + type.setLoadedValue(typeValue); + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/SaveFileHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/SaveFileHandler.java new file mode 100644 index 000000000..6967b65c0 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/SaveFileHandler.java @@ -0,0 +1,334 @@ +package cz.zcu.fav.kiv.editor.stylesheet; + +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.Text; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.common.ParentParameter; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.parameters.TypeParam; +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.beans.properties.AttributeGroup; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.beans.properties.TypeAttr; +import cz.zcu.fav.kiv.editor.beans.sections.Group; +import cz.zcu.fav.kiv.editor.beans.sections.Section; +import cz.zcu.fav.kiv.editor.beans.sections.Subsection; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; + +/** + * The SaveFileHandler class contains methods for saving changes of actually opened + * XSL stylesheet file. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class SaveFileHandler { + + /** + * Saves changes of actually opened XSL stylesheet file. + * + * @param doc + * DOM structure of the opened XSL document. + * @param data + * the data containing editor data structure. + */ + public static void saveStylesheet(Document doc, ConfigData data) { + Node stylesheet = doc.getElementsByTagName(XslTagConst.STYLESHEET).item(0); + Node firstNode = null; + boolean newInSection; + boolean isInserted = false; + for (Section section : data.getSectionList()) { + for (Subsection subsection : section.getSubsectionList()) { + if ((OptionItems.REARRANGE_SAVE)&&(subsection.getComment() != null)) + subsection.setComment(null); + firstNode = null; + newInSection = false; + for (Group gr : subsection.getGroupList()) { + for (ParentParameter elem : gr.getElementList()) { + if (elem instanceof Parameter) { + if (OptionItems.REARRANGE_SAVE) + isInserted = rearrangeParameter((Parameter) elem, doc, stylesheet); + else { + isInserted = changeParameter((Parameter) elem, doc, stylesheet, subsection.getComment()); + } + } + if (elem instanceof Property) { + isInserted = changeProperty((Property) elem, doc, stylesheet, subsection.getComment()); + } + if (elem.getNode() != null) { + //first node inserted in section -> insert comment + if ((isInserted)&&(!newInSection)) { + newInSection = true; + firstNode = elem.getNode(); + } + } + } + } + //has comment? + if ((OptionItems.GENERATE_COMMENTS) && (firstNode != null) + && (subsection.getComment() == null) + && (newInSection)) { + Comment comment = doc.createComment(" " + section.getTitle() + " :: " + + subsection.getTitle() + " "); + subsection.setComment(comment); + stylesheet.insertBefore(comment, firstNode); + } + //remove comment - no parameters + if ((subsection.getComment() != null) + && (subsection.getComment().getNextSibling() instanceof Comment)) { + XslParser.removeNode(subsection.getComment()); + subsection.setComment(null); + } + } + } + } + + /** + * Changes the parameter value and places the parameter at the end of stylesheet file. + * + * @param param + * the changing parameter. + * @param doc + * DOM structure of the opened XSL document. + * @param stylesheet + * the node of 'stylesheet' element. + * @return true if the parameter was inserted at the end of stylesheet. + */ + private static boolean rearrangeParameter(Parameter param, Document doc, Node stylesheet) { + if (param.getNode() != null) { + XslParser.removeNode(param.getNode()); + param.setNode(null); + } + // add node at the end + return addNewParameter(param, doc, stylesheet, null); + } + + /** + * Change parameter value in the opened stylesheet file. If the parameter is yet in the opened + * stylesheet then it is inserted at the end of stylesheet. + * + * @param param + * the changing parameter. + * @param doc + * DOM structure of the opened XSL document. + * @param stylesheet + * the node of 'stylesheet' element. + * @param lastNode + * the last node of the same subsection. + * @return true if the parameter was inserted at the end of stylesheet. + */ + private static boolean changeParameter(Parameter param, Document doc, Node stylesheet, Node lastNode) { + if (param.getNode() != null) { + if (!param.isChosen()) { + XslParser.removeNode(param.getNode()); + param.setNode(null); + } else { + Node newNode = createParamElement(param, doc); + param.getNode().getParentNode().replaceChild(newNode, param.getNode()); + param.setNode(newNode); + } + return false; + } + return addNewParameter(param, doc, stylesheet, lastNode); + } + + /** + * Inserts a new parameter at the end of stylesheet file + * or after the 'lastNode' it it is not null. + * + * @param param + * the changing parameter. + * @param doc + * DOM structure of the opened XSL document. + * @param stylesheet + * the node of 'stylesheet' element. + * @param lastNode + * the last node of the same subsection. + * @return true if the parameter was inserted at the end of stylesheet file. + */ + private static boolean addNewParameter(Parameter param, Document doc, Node stylesheet, Node lastNode) { + if (param.isChosen()) { + Node node = createParamElement(param, doc); + if (lastNode != null) + stylesheet.insertBefore(node, lastNode.getNextSibling()); + else + stylesheet.appendChild(node); + param.setNode(node); + return true; + } + return false; + } + + /** + * Changes or inserts property in the stylesheet file. + * + * @param prop + * the changing property. + * @param doc + * DOM structure of the opened XSL document. + * @param stylesheet + * the node of 'stylesheet' element. + * @return true if the property was inserted at the end of stylesheet file. + */ + private static boolean changeProperty(Property prop, Document doc, Node stylesheet, Node lastNode) { + if ((prop.getNode() == null) && (prop.isChosen())) { + Element attrSetElem = doc.createElement(XslTagConst.ATTRIBUTE_SET); + attrSetElem.setAttribute(XslTagConst.NAME, prop.getName()); + changeAttributes(prop.getAttributeGroupList(), attrSetElem, doc); + // add new property + if (attrSetElem.getChildNodes().getLength() > 0) { + if (lastNode != null) + stylesheet.insertBefore(attrSetElem, lastNode.getNextSibling()); + else + stylesheet.appendChild(attrSetElem); + prop.setNode(attrSetElem); + return true; + } + return false; + } + // property is not chosen and was in the opened stylesheet file + if ((prop.getNode() != null) && (!prop.isChosen())) { + XslParser.removeNode(prop.getNode()); + return false; + } + + if ((prop.getNode() != null) && (prop.isChosen())) { + changeAttributes(prop.getAttributeGroupList(), prop.getNode(), doc); + // move property to the end + if (OptionItems.REARRANGE_SAVE) { + stylesheet.appendChild(prop.getNode()); + return true; + } + return false; + } + return false; + } + + /** + * Changes property attributes and their values. + * + * @param attributeGroups + * the groups of attributes of the parent property. + * @param parent + * the node of parent property. + * @param doc + * DOM structure of the opened XSL document. + */ + private static void changeAttributes(AttributeGroup[] attributeGroups, Node parent, Document doc) { + Node node; + for (AttributeGroup panel : attributeGroups) + for (Attribute attr : panel.getAttributeList()) { + if (attr.isChosen()) { + if (attr.getNode() != null) { + attr.getNode().setTextContent(createNewValueAttr(attr.getType())); + } else { + node = createAttributeElement(attr, doc); + parent.appendChild(node); + attr.setNode(node); + } + } else { + if (attr.getNode() != null) { + XslParser.removeNode(attr.getNode()); + attr.setNode(null); + } + } + } + } + + /** + * Creates a new node from parameter. + * + * @param param + * the parameter used for creating the node. + * @param doc + * DOM structure of the opened XSL document. + * @return the new parameter node. + */ + private static Element createParamElement(Parameter param, Document doc) { + Element paramElem = doc.createElement(XslTagConst.PARAM); + // name + paramElem.setAttribute(XslTagConst.NAME, param.getName()); + + String paramValue = createNewValueParam(param.getType()); + + if (OptionItems.USE_PARAM_SELECT) { + paramElem.setAttribute(XslTagConst.SELECT, addApostrophe(paramValue)); + } else { + Text text = doc.createTextNode(paramValue); + paramElem.appendChild(text); + } + + return paramElem; + } + + /** + * Creates a new node from attribute. + * + * @param attr + * the attribute used for creating the node. + * @param doc + * DOM structure of the opened XSL document. + * @return the new attribute node. + */ + private static Element createAttributeElement(Attribute attr, Document doc) { + Element element = doc.createElement(XslTagConst.ATTRIBUTE); + + Text text = doc.createTextNode(createNewValueAttr(attr.getType())); + element.appendChild(text); + + // name + element.setAttribute(XslTagConst.NAME, attr.getName()); + return element; + } + + /** + * Creates a new value content of the parameter node. + * + * @param type + * the parameter type with value. + * @return the new value content of the parameter node. + */ + private static String createNewValueParam(TypeParam type) { + StringBuilder value = new StringBuilder(type.getValue()); + if (type.getUnit() != null) + value.append(type.getUnit().getValue()); + return value.toString(); + } + + /** + * Creates a new value content of the attribute node. + * + * @param types + * the attribute type with value. + * @return the new value content of the attribute node. + */ + private static String createNewValueAttr(TypeAttr type) { + StringBuilder attrValue = new StringBuilder(); + attrValue.append(type.getValue().toString()); + if (type.getUnit() != null) + attrValue.append(type.getUnit().getValue()); + + return attrValue.toString().trim(); + } + + /** + * Adds apostrophes around the value if the value isnt't a number. + * + * @param value + * the changing value. + * @return value with apostrophes if the value isn't a number. + */ + private static String addApostrophe(String value) { + try { + Float.parseFloat(value); + } catch (NumberFormatException e) { + value = "'" + value.trim() + "'"; + } + return value; + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XslParser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XslParser.java new file mode 100644 index 000000000..624a32146 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XslParser.java @@ -0,0 +1,214 @@ +package cz.zcu.fav.kiv.editor.stylesheet; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.traversal.DocumentTraversal; +import org.w3c.dom.traversal.NodeFilter; +import org.w3c.dom.traversal.NodeIterator; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.controller.errors.OpenFileException; +import cz.zcu.fav.kiv.editor.controller.errors.SaveFileException; +import cz.zcu.fav.kiv.editor.controller.errors.XslParserException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.options.OptionItems; + +/** + * The XslParser class contains methods for reading and saving XSL stylesheet files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class XslParser { + + /** The size of indent used in output XSL files */ + public static final int INDENT = 2; + + /** + * Opens and reads the input XSL file. Creates a DOM structure of the opened XSL document. + * + * @param file + * the name of the XSL file that will be opened. + * @param configData + * the data containing editor data structure. + * @return DOM structure of the opened XSL document. + * @throws OpenFileException + * if the file cannot be opened. + */ + public static Document readXsltFile(String file, ConfigData configData) + throws OpenFileException { + Document doc = null; + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(false); + spf.setNamespaceAware(true); + + SAXParser sp = spf.newSAXParser(); + XMLReader parser = sp.getXMLReader(); + parser.setErrorHandler(new XslParserException()); + + XsltFileHandler handler = new XsltFileHandler(configData); + parser.setContentHandler(handler); + parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); + parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler); + + parser.parse(file); + + doc = handler.getDocument(); + } catch (SAXException ex) { + Log.error(ex); + throw new OpenFileException(ex.getMessage()); + } catch (Exception ex) { + Log.error(ex); + throw new OpenFileException(); + } + return doc; + } + + /** + * Saves changes of actually opened XSL stylesheet file and saves the DOM structure to the XSL file. + * + * @param file + * the name of the XSL file that will be saved. + * @param document + * the DOM structure of the file that will be saved. + * @throws SaveFileException + * if the file cannot be saved. + */ + public static void saveXsltFile(String file, Document document, ConfigData configData) throws SaveFileException { + SaveFileHandler.saveStylesheet(document, configData); + try { + TransformerFactory tf = TransformerFactory.newInstance(); + tf.setAttribute("indent-number", INDENT); + Transformer writer = tf.newTransformer(); + writer.setOutputProperty(OutputKeys.INDENT, "yes"); + writer.setOutputProperty("encoding", OptionItems.ENCODING); + + writer.setOutputProperty(OutputKeys.METHOD, "xml"); + + OutputStreamWriter osw = new OutputStreamWriter(new FileStreamOutput( + new FileOutputStream(new File(file))), Charset.forName(OptionItems.ENCODING)); + + writer.transform(new DOMSource(document), new StreamResult(osw)); + } catch (Exception ex) { + Log.error(ex); + throw new SaveFileException(ex); + } + } + + /** + * Creates a new DOM structure of an empty XSL stylesheet. + * + * @return a DOM structure of an empty XSL stylesheet. + */ + public static Document createXsltFile() { + Document doc = null; + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = dbf.newDocumentBuilder(); + DOMImplementation impl = builder.getDOMImplementation(); + doc = impl.createDocument(OptionItems.XSL_NAMESPACE, "xsl:stylesheet", null); + // XSL namespace + Element element = doc.getDocumentElement(); + element.setAttribute("xmlns:xsl", OptionItems.XSL_NAMESPACE); + // FO namespace + if (OptionItems.ADD_FO_NAMESPACE) + element.setAttribute("xmlns:fo", OptionItems.FO_NAMESPACE); + element.setAttribute("version", OptionItems.STYLESHEET_VERSION); + + // add imports + addImportFiles(doc); + } catch (ParserConfigurationException ex) { + Log.error(ex); + } + return doc; + } + + /** + * Adds to the DOM structure elements defining import of other XSL stylesheets. + * + * @param document + * the DOM structure of the XSL stylesheet. + */ + private static void addImportFiles(Document document) { + Element importElem; + int lastChar = 0; + Pattern pattern = Pattern.compile(";"); + Matcher matcher = pattern.matcher(OptionItems.IMPORT_FILE); + while (matcher.find()) { + importElem = document.createElement("xsl:import"); + importElem.setAttribute("href", OptionItems.IMPORT_FILE.substring(lastChar, + matcher.start()).trim()); + lastChar = matcher.end(); + document.getDocumentElement().appendChild(importElem); + } + if (lastChar < OptionItems.IMPORT_FILE.trim().length()) { + importElem = document.createElement("xsl:import"); + importElem.setAttribute("href", OptionItems.IMPORT_FILE.substring(lastChar, + OptionItems.IMPORT_FILE.trim().length())); + document.getDocumentElement().appendChild(importElem); + } + } + + /** + * Removes all comments in DOM structure of the XSL stylesheet. + * + * @param document + * the DOM structure of the XSL stylesheet. + */ + public static void removeComments(Document document) { + NodeIterator nodeList = ((DocumentTraversal) document).createNodeIterator(document + .getDocumentElement(), NodeFilter.SHOW_COMMENT, null, false); + Node comment; + List commentList = new ArrayList(); + while ((comment = nodeList.nextNode()) != null) + commentList.add(comment); + removeNodes(commentList); + } + + /** + * Removes all nodes from the list. + * + * @param nodeList + * the list of nodes that will be removed. + */ + public static void removeNodes(List nodeList) { + for (Node node : nodeList) { + removeNode(node); + } + } + + /** + * Remove the input node. + * + * @param node + * the node that will be removed. + */ + public static void removeNode(Node node) { + node.getParentNode().removeChild(node); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XslTagConst.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XslTagConst.java new file mode 100644 index 000000000..7d7d6920a --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XslTagConst.java @@ -0,0 +1,25 @@ +package cz.zcu.fav.kiv.editor.stylesheet; + +/** + * The XslTagConst class contains elements used in XSL stylesheet files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class XslTagConst { + public static final String STYLESHEET = "xsl:stylesheet"; + + public static final String IMPORT = "xsl:import"; + + public static final String HREF = "href"; + + public static final String PARAM = "xsl:param"; + + public static final String NAME = "name"; + + public static final String SELECT = "select"; + + public static final String ATTRIBUTE_SET = "xsl:attribute-set"; + + public static final String ATTRIBUTE = "xsl:attribute"; +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XsltFileHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XsltFileHandler.java new file mode 100644 index 000000000..2c06a0a54 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/stylesheet/XsltFileHandler.java @@ -0,0 +1,237 @@ +package cz.zcu.fav.kiv.editor.stylesheet; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Stack; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Text; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.DTDHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.ext.DeclHandler; + +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The XsltFileHandler class reads the input XSL stylesheet file element by element and creates from them a DOM structure. + * Simultaneously reports all errros in the input XSL file. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class XsltFileHandler extends DefaultHandler implements ContentHandler, LexicalHandler, + DeclHandler, DTDHandler { + private ConfigData data; + + // locator + private Locator locator; + + private Document document; + + private Element element = null; + + private Element stylesheet; + + private Comment comment; + + private Stack stack; + + private int parameterBeginLine; + + private int attributeBeginLine; + + private Property property; + + private Map namespaces; + + private boolean insideCDATA; + + // string buffers + private StringBuffer commentBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + private StringBuffer elementBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + private StringBuffer cdataBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + public XsltFileHandler(ConfigData data) { + super(); + this.data = data; + } + + public void startDocument() { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = dbf.newDocumentBuilder(); + + document = builder.newDocument(); + stylesheet = document.createElement(XslTagConst.STYLESHEET); + } catch (Exception ex) { + + } + stack = new Stack(); + namespaces = new HashMap(); + } + + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) + throws SAXException { + if (qName.equals(XslTagConst.STYLESHEET)) { + //attributes + if (atts.getLength() > 0) + appendAttributes(stylesheet, atts); + + // namespaces + if (namespaces.size() > 0) { + appendNamespaces(stylesheet); + } + + document.appendChild(stylesheet); + stack.push(stylesheet); + } else { + if (stack.empty()) + throw new SAXException(ResourceController + .getMessage("open_file.stylesheet_invalid")); + element = document.createElement(qName); + //attributes + if (atts.getLength() > 0) + appendAttributes(element, atts); + + // namespaces + if (namespaces.size() > 0) + appendNamespaces(element); + + stack.peek().appendChild(element); + stack.push(element); + } + + if (qName.equals(XslTagConst.PARAM)) { + parameterBeginLine = locator.getLineNumber(); + } else if (qName.equals(XslTagConst.ATTRIBUTE)) { + attributeBeginLine = locator.getLineNumber(); + } else if ((qName.equals(XslTagConst.ATTRIBUTE_SET)) + && (stack.peek().getParentNode().getNodeName().equals(XslTagConst.STYLESHEET))) { + property = OpenFileHadler + .parserPropertyTag(stack.peek(), locator.getLineNumber(), data); + } + + elementBuffer.setLength(0); + } + + private void appendNamespaces(Element node) { + for (Iterator it = namespaces.entrySet().iterator(); it.hasNext();) { + Map.Entry entry = (Map.Entry) it.next(); + if (entry.getKey().toString().length() > 0) + node.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + + entry.getKey().toString(), entry.getValue().toString()); + else + node.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", entry.getValue() + .toString()); + } + namespaces = new HashMap(); + } + + private void appendAttributes(Element node, Attributes atts) { + for (int i = 0; i < atts.getLength(); i++) { + node.setAttribute(atts.getQName(i), atts.getValue(i)); + } + } + + public void endElement(String namespaceURI, String localName, String qName) { + if (elementBuffer.length() > 0) { + if (elementBuffer.toString().trim().length() > 0) { + Text text = document.createTextNode(elementBuffer.toString().trim()); + stack.peek().appendChild(text); + } + elementBuffer.setLength(0); + } + + if (qName.equals(XslTagConst.PARAM) + && (stack.peek().getParentNode().getNodeName().equals(XslTagConst.STYLESHEET))) { + OpenFileHadler.parserParameterTag(stack.peek(), parameterBeginLine, data); + } else if (qName.equals(XslTagConst.ATTRIBUTE_SET)) { + property = null; + } else if ((qName.equals(XslTagConst.ATTRIBUTE)) && (property != null)) { + OpenFileHadler.parserPropertyAttribute(stack.peek(), attributeBeginLine, property); + } + + stack.pop(); + } + + public void characters(char[] ch, int start, int length) { + if (insideCDATA) + cdataBuffer.append(ch, start, length); + else + elementBuffer.append(ch, start, length); + } + + public void startPrefixMapping(String prefix, String uri) throws SAXException { + namespaces.put(prefix, uri); + } + + public void setDocumentLocator(Locator locator) { + this.locator = locator; + } + + public void comment(char[] ch, int start, int length) throws SAXException { + commentBuffer.append(ch, start, length); + comment = document.createComment(commentBuffer.toString()); + if (!stack.empty()) + stack.peek().appendChild(comment); + else + document.appendChild(comment); + commentBuffer.setLength(0); + } + + public void endCDATA() throws SAXException { + insideCDATA = false; + stack.peek().appendChild(document.createCDATASection(cdataBuffer.toString())); + cdataBuffer.setLength(0); + } + + public void endDTD() throws SAXException { + } + + public void endEntity(String name) throws SAXException { + } + + public void startCDATA() throws SAXException { + insideCDATA = true; + } + + public void startDTD(String name, String publicId, String systemId) throws SAXException { + } + + public void startEntity(String name) throws SAXException { + } + + public Document getDocument() { + return document; + } + + public void attributeDecl(String arg0, String arg1, String arg2, String arg3, String arg4) + throws SAXException { + } + + public void elementDecl(String arg0, String arg1) throws SAXException { + } + + public void externalEntityDecl(String arg0, String arg1, String arg2) throws SAXException { + } + + public void internalEntityDecl(String arg0, String arg1) throws SAXException { + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateConst.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateConst.java new file mode 100644 index 000000000..89d87d08a --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateConst.java @@ -0,0 +1,55 @@ +package cz.zcu.fav.kiv.editor.template; + +import java.io.File; + +import cz.zcu.fav.kiv.editor.config.constants.FileConst; + +/** + * The TemplateConst class contains enumarated lists of elements used in XML template + * and XML schema of the template and path and name of the default template. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TemplateConst { + /** The size of buffer used for reading element contents */ + public static int BUFFER_SIZE = 300; + + /** The directory where default template is stored */ + public static final String CONF_FILE_TEMPLATE_DIR = "templates" + File.separator; + + /** The file with default template */ + public static final String CONF_FILE_TEMPLATE = CONF_FILE_TEMPLATE_DIR + "template.xml"; + + /** The XML schema of the file with default template */ + public static final String CONF_FILE_TEMPLATE_XSD = FileConst.CONF_FILE_XSD_DIR + + "template.xsd"; + + /** + * The enumerated list of elements used in templates. + */ + public static enum TemplateTags { + ATTRIBUTE_SET("attribute-set"), ATTRIBUTE("attribute"), PARAMETER("parameter"); + + String value; + + TemplateTags(String value) { + this.value = value; + } + + /** + * Returns predefined constant of element according to the element name. + * + * @param key + * the name of element. + * @return a constant of element with defined name. + */ + public static TemplateTags getValue(String key) { + for (TemplateTags type : values()) { + if (type.value.equals(key)) + return type; + } + return null; + } + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateController.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateController.java new file mode 100644 index 000000000..c9afc1d5f --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateController.java @@ -0,0 +1,63 @@ +package cz.zcu.fav.kiv.editor.template; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ConfigException; +import cz.zcu.fav.kiv.editor.controller.errors.FileNotFoundException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; + +/** + * The TemplateController class contains method for reading templates. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TemplateController { + + /** The instance of TemplateController */ + private static TemplateController instance; + + /** + * Static methods return instance of TemplateController. If the + * instance is null, initializes a new one. + * + * @return the instance of TemplateController. + */ + public static TemplateController getInstance() { + if (instance != null) + return instance; + return new TemplateController(); + } + + /** The parser of XML templates */ + private TemplateParser parser; + + /** + * Initializes a newly created TemplateController. Simultaneously initializes + * new TemplateParser. + */ + private TemplateController() { + parser = new TemplateParser(); + } + + /** + * Reads a template defined by its path templateFile. + * + * @param configData + * the data containing editor data structure. + * @param templateFile + * the path to the file with template. + * @throws ConfigException + * if the template or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the template or its XML schema doesn't exist. + */ + public void readTemplate(ConfigData configData, String templateFile) throws ConfigException, + FileNotFoundException { + MessageWriter.writeInfo(ResourceController.getMessage( + "new_file_template.load_template.title", TemplateConst.CONF_FILE_TEMPLATE)); + parser.readTemplate(configData, templateFile); + Log.info("info.template_control.load_template", TemplateConst.CONF_FILE_TEMPLATE); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateParser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateParser.java new file mode 100644 index 000000000..bb8bb4919 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateParser.java @@ -0,0 +1,86 @@ +package cz.zcu.fav.kiv.editor.template; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.controller.errors.ConfigException; +import cz.zcu.fav.kiv.editor.controller.errors.FileNotFoundException; +import cz.zcu.fav.kiv.editor.controller.errors.XslParserException; +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The TemplateParser class contains method for parsing template files. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TemplateParser { + /** The parser key defining XML schema language */ + private static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; + + /** The constants defining XML schema language */ + private static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; + + /** The key defining XML schema */ + private static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; + + /** The XML parser used for reading template files */ + private XMLReader parser; + + /** + * Initializes a newly created TemplateParser. Sets up the SAX parser used for + * parsing. + */ + public TemplateParser() { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(true); + spf.setNamespaceAware(true); + + try { + SAXParser sp = spf.newSAXParser(); + sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); + parser = sp.getXMLReader(); + parser.setErrorHandler(new XslParserException()); + } catch (Exception ex) { + Log.error(ex); + } + } + + /** + * Parses the file with template. + * + * @param configData + * the data containing editor data structure. + * @param templateFile + * the path to the file with template. + * @throws ConfigException + * if the template or its XML schema isn't well-formed. + * @throws FileNotFoundException + * if the template or its XML schema doesn't exist. + */ + public void readTemplate(ConfigData configData, String templateFile) throws ConfigException, + FileNotFoundException { + InputStream xsdFile = TemplateParser.class.getResourceAsStream(TemplateConst.CONF_FILE_TEMPLATE_XSD); + if (xsdFile == null) + throw new FileNotFoundException(TemplateConst.CONF_FILE_TEMPLATE_XSD); + + TemplateXmlHandler handler = new TemplateXmlHandler(configData, templateFile); + parser.setContentHandler(handler); + try { + parser.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); + parser.parse(templateFile); + } catch (IOException ex) { + throw new FileNotFoundException(templateFile); + } catch (SAXException ex) { + throw new ConfigException(templateFile, ex.getMessage()); + } + } + +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateXmlHandler.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateXmlHandler.java new file mode 100644 index 000000000..8637b047c --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/template/TemplateXmlHandler.java @@ -0,0 +1,172 @@ +package cz.zcu.fav.kiv.editor.template; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.helpers.DefaultHandler; + +import cz.zcu.fav.kiv.editor.beans.ConfigData; +import cz.zcu.fav.kiv.editor.beans.parameters.Parameter; +import cz.zcu.fav.kiv.editor.beans.properties.Attribute; +import cz.zcu.fav.kiv.editor.beans.properties.Property; +import cz.zcu.fav.kiv.editor.config.constants.FileConst; +import cz.zcu.fav.kiv.editor.config.constants.TagDefinition; +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.template.TemplateConst.TemplateTags; + +/** + * The TemplateXmlHandler class is used for parsing file with template. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TemplateXmlHandler extends DefaultHandler { + /** The locator specifying actual line number */ + private Locator locator; + + /** The data containing editor data structure */ + private ConfigData configData; + + /** The name of the file with template */ + private String templateFile; + + /** The number of the line with property element */ + private int propertyLine; + + /** The property with attribute */ + private Property property; + + /** The list of attribute values */ + private String attributeValue; + + /** The name of parameter */ + private String parameterValue; + + /** The flag specifying whether the parser is inside attribute element */ + private boolean insideAttributeElement = false; + + /** The flag specifying whether the parser is inside parameter element */ + private boolean insideParameterElement = false; + + /** The string buffer for content of attribute element */ + private StringBuffer attributeBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** The string buffer for content of parameter element */ + private StringBuffer parameterBuffer = new StringBuffer(TagDefinition.BUFFER_SIZE); + + /** + * Initializes a newly created TemplateXmlHandler with ConfigData + * and template name templateFile. + * + * @param configData + * the data containing editor data structure. + * @param template + * the name of the file with template. + */ + public TemplateXmlHandler(ConfigData configData, String template) { + this.configData = configData; + this.templateFile = template; + } + + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { + TemplateTags enumTag = TemplateConst.TemplateTags.getValue(qName); + if (enumTag != null) + switch (enumTag) { + case ATTRIBUTE_SET: + property = configData.searchProperty(atts.getValue(0)); + if (property == null) + MessageWriter.writeWarning(ResourceController.getMessage("parser.template.find_property", FileConst.CONF_FILE_CONFIG, atts.getValue(0), templateFile, locator.getLineNumber())); + else + property.setChosen(); + + this.propertyLine = locator.getLineNumber(); + break; + case ATTRIBUTE: + insideAttributeElement = true; + attributeBuffer.setLength(0); + attributeValue = atts.getValue(0); + break; + case PARAMETER: + insideParameterElement = true; + parameterBuffer.setLength(0); + parameterValue = atts.getValue(0); + break; + } + } + + @Override + public void endElement(String namespaceURI, String localName, String qName) { + TemplateTags enumTag = TemplateConst.TemplateTags.getValue(qName); + if (enumTag != null) + switch (enumTag) { + case ATTRIBUTE: + insideAttributeElement = false; + try { + if (property != null) + changeAttribute(attributeBuffer.toString()); + } catch (ParserException ce) { + MessageWriter.writeWarning(ResourceController.getMessage("parser.template.parse_attribute_value", templateFile, attributeBuffer.toString(), this.propertyLine)); + } + break; + case PARAMETER: + insideParameterElement = false; + try { + changeParameter(); + } catch (ParserException ce) { + MessageWriter.writeWarning(ResourceController.getMessage("parser.template.parse_parameter_value", templateFile, attributeBuffer.toString(), this.propertyLine)); + } + break; + } + } + + @Override + public void characters(char[] ch, int start, int length) { + if (insideAttributeElement) { + attributeBuffer.append(ch, start, length); + } else if (insideParameterElement) { + parameterBuffer.append(ch, start, length); + } + } + + /** + * Change type value of the actual parsed parameter. + * + * @throws ParserException + * if the parameter value is not valid. + */ + private void changeParameter() throws ParserException { + Parameter parameter = configData.searchParameter(parameterBuffer.toString()); + if (parameter == null) + MessageWriter.writeWarning(ResourceController.getMessage("parser.template.find_parameter", FileConst.CONF_FILE_CONFIG, parameterBuffer.toString(), templateFile, locator.getLineNumber())); + else { + // set new parameter value + parameter.getType().setLoadedValue(parameterValue); + parameter.setChosen(); + } + + } + + /** + * Change type values of the actual parsed attribute specified by name. + * + * @param attrName + * an attribute name. + * @throws ParserException + * if the attribute values are not valid. + */ + private void changeAttribute(String attrName) throws ParserException { + Attribute searchAttr = property.searchAttribute(attrName); + if (searchAttr != null) { + if (attributeValue != null) + searchAttr.getType().setLoadedValue(attributeValue); + searchAttr.setChosen(true); + } else + MessageWriter.writeWarning(ResourceController.getMessage("parser.template.find_attribute", FileConst.CONF_FILE_ATTRIBUTES, attributeBuffer.toString(), templateFile, this.propertyLine)); + } + + public void setDocumentLocator(Locator locator) { + this.locator = locator; + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/ErrorDialog.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/ErrorDialog.java new file mode 100644 index 000000000..9665df66a --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/ErrorDialog.java @@ -0,0 +1,27 @@ +package cz.zcu.fav.kiv.editor.utils; + +import javax.swing.JOptionPane; + +import cz.zcu.fav.kiv.editor.controller.resource.ResourceController; +import cz.zcu.fav.kiv.editor.graphics.MainFrame; + +/** + * The ErrorDialog class displays the error dialog containing the description of the + * application error. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class ErrorDialog { + + /** + * Shows the error dialog with the description of the input error. + * + * @param error + * the error to display in the error dialog. + */ + public static void showDialog(Exception error) { + JOptionPane.showMessageDialog(MainFrame.getInstance(), error.getStackTrace(), + ResourceController.getMessage("error_dialog.title"), JOptionPane.ERROR_MESSAGE); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/RunBatch.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/RunBatch.java new file mode 100644 index 000000000..a08eb16a6 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/RunBatch.java @@ -0,0 +1,143 @@ +package cz.zcu.fav.kiv.editor.utils; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import cz.zcu.fav.kiv.editor.controller.MessageWriter; +import cz.zcu.fav.kiv.editor.controller.logger.Log; + +/** + * The StreamWriter class is used for reporting messages and errors generated during + * lauch of the batch file. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +class StreamWriter extends Thread { + /** The constant defining error message */ + public static final String ERROR = "error"; + + /** The constant defining output message */ + public static final String OUTPUT = "output"; + + /** The input message stream */ + private InputStream inputStream; + + /** The type of output message */ + private String type; + + /** + * Initializes a newly created StreamWriter with defined InputStream + * and message type. + * + * @param is + * the input stream. + * @param type + * the type of message. + */ + public StreamWriter(InputStream is, String type) { + this.inputStream = is; + this.type = type; + } + + /** + * Launches the message writer. + */ + public void run() { + try { + InputStreamReader input = new InputStreamReader(inputStream); + BufferedReader reader = new BufferedReader(input); + String line = null; + while ((line = reader.readLine()) != null) { + if (type.equals(ERROR)) + MessageWriter.writeEmphasis(line); + else + MessageWriter.write(line); + } + } catch (IOException ioe) { + Log.error(ioe); + } + } +} + +/** + * The RunBatch class launches a batch file defined by user. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class RunBatch { + /** The constant defining file separator */ + private static final String FILE_SEPARATOR = "\\" + File.separator; + + /** The in the batch file that determine place where the actual XSL stylesheet is placed */ + private static final String XSL = "\\[XSL\\]"; + + /** The constant defining quote */ + private static final String QUOTE = "\""; + + /** The name of the auxiliary batch file */ + public static final String RUN_BAT = "transformation.bat"; + + /** + * Executes the batch file. + * + * @throws Throwable + * if the batch file cannot be executed. + */ + public static void execBatch() throws Throwable { + String osName = System.getProperty("os.name"); + String[] cmd = new String[3]; + if (osName.startsWith("Windows")) { + cmd[0] = "cmd.exe"; + cmd[1] = "/C"; + cmd[2] = RUN_BAT; + } + + Runtime rt = Runtime.getRuntime(); + Process proc = rt.exec(cmd); + // any error message? + StreamWriter errorGobbler = new StreamWriter(proc.getErrorStream(), StreamWriter.ERROR); + + // any output? + StreamWriter outputGobbler = new StreamWriter(proc.getInputStream(), StreamWriter.OUTPUT); + + // kick them off + errorGobbler.start(); + outputGobbler.start(); + } + + /** + * Replace the mark [XSL] in the batch file by the actual opened XSL stylesheet file. + * + * @param batchName + * the name of the batch file. + * @param xslName + * the name of the actually opened XSL stylesheet file. + * @throws Throwable + * if the batch file is invalid. + */ + public static void replaceXslName(String batchName, String xslName) throws Throwable { + FileReader fileRead = new FileReader(batchName); + BufferedReader in = new BufferedReader(fileRead); + FileWriter fw = new FileWriter(RUN_BAT); + BufferedWriter out = new BufferedWriter(fw); + + String line; + while ((line = in.readLine()) != null) { + line = line.replaceAll(XSL, QUOTE + + xslName.replaceAll(FILE_SEPARATOR, FILE_SEPARATOR + FILE_SEPARATOR) + QUOTE); + + out.write(line); + out.newLine(); + } + fileRead.close(); + out.close(); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/TagControl.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/TagControl.java new file mode 100644 index 000000000..7adb15a78 --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/TagControl.java @@ -0,0 +1,156 @@ +package cz.zcu.fav.kiv.editor.utils; + +import cz.zcu.fav.kiv.editor.beans.types.Type; +import cz.zcu.fav.kiv.editor.beans.types.Unit; +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; + +/** + * The TagControl class controls the components and values of parameters and + * attributes. + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TagControl { + + /** + * Controls if the input value corresponds to the Type component. + * + * @param type + * the type with the component. + * @param value + * the new value for controlling. + */ + public static void controlSetTypeValue(Type type, String value) throws ParserException { + switch (type.getName()) { + case LIST: + controlList(type, value); + break; + case INTEGER: + controlInteger(type, value); + break; + case NUMBER: + controlInteger(type, value); + break; + case FLOAT: + controlFloat(type, value); + break; + case COLOR: + controlColor(type, value); + break; + case BOOLEAN: + controlBoolean(type, value); + break; + case LENGTH: + controlLength(type, value); + break; + default: + type.setValue(value); + } + } + + + /** + * Controls if the list of predefined units in Unit contains the input unit name. + * + * @param unit + * the unit with the list of predefined units. + * @param unitName + * the name of input unit. + * @return true if the Unit contains the input unit name. + */ + private static void controlTypeUnit(Unit unit, String unitName) throws ParserException { + if (unit.getValueList().contains(unitName)) + unit.setValue(unitName); + else + throw new ParserException(); + } + + /** + * Controls if the input value is a valid value for component combo-box. + * + * @param type + * the type with component combo-box. + * @param value + * the input value for controlling. + * @return true if the input value is valid for the component combo-box. + */ + private static void controlList(Type type, String value) throws ParserException{ + if ((type.getValueList() != null) + &&(type.getValueList().containsKey(value))) + type.setValue(value); + else + throw new ParserException(); + } + + /** + * Controls if the input value is a valid value for component spinner-int. + * + * @param value + * the input value for controlling. + * @return true if the input value is valid for the component spinner-int. + */ + private static void controlInteger(Type type, String value) throws ParserException { + try { + Integer.parseInt(value); + type.setValue(value); + } catch (Exception pe) { + throw new ParserException(); + } + } + + /** + * Controls if the input value is a valid value for component spinner-float. + * + * @param value + * the input value for controlling. + * @return true if the input value is valid for the component spinner-float. + */ + private static void controlFloat(Type type, String value) throws ParserException { + try { + Double.parseDouble(value); + type.setValue(value); + } catch (NumberFormatException pe) { + throw new ParserException(); + } + } + + /** + * Controls if the input value is a valid value for component color-chooser. + * + * @param type + * the type with component color-chooser. + * @param value + * the input value for controlling. + * @return true if the input value is valid for the component color-chooser. + */ + private static void controlColor(Type type, String value) throws ParserException { + if ((type.getValueList() != null) + &&(type.getValueList().get(value) == null) + &&(TagParser.parseColor(value) == null)) + throw new ParserException(); + else + type.setValue(value); + } + + /** + * Controls if the input value is a valid value for component check-box. + * + * @param value + * the input value for controlling. + * @return true if the input value is valid for the component check-box. + */ + private static void controlBoolean(Type type, String value) throws ParserException { + if (value.equals("0") || value.equals("1")) + type.setValue(value); + else + throw new ParserException(); + } + + private static void controlLength(Type type,String value) throws ParserException { + String number = TagParser.parserNumber(value); + String unit = TagParser.parserUnit(value); + controlTypeUnit(type.getUnit(), unit); + type.setValue(number); + } +} diff --git a/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/TagParser.java b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/TagParser.java new file mode 100644 index 000000000..e3f80ddee --- /dev/null +++ b/contrib/tools/fo-editor/src/cz/zcu/fav/kiv/editor/utils/TagParser.java @@ -0,0 +1,123 @@ +package cz.zcu.fav.kiv.editor.utils; + +import java.awt.Color; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import cz.zcu.fav.kiv.editor.controller.errors.ParserException; + +/** + * The TagParser class parses values of parameters, properties and attributes loaded + * from input files (configuration and XSL stylesheet). + * + * @author Marta Vaclavikova + * @version 1.0, 05/2007 + */ +public class TagParser { + + /** + * Parses the number from the string containing number with unit e.g. parses 12.4 from 12.4em. + * + * @param text + * the input text containing number and unit. + * @throws ParserException + * if the input text doesn't contain a number. + * @return a number parsed from the input text. + */ + public static String parserNumber(String text) throws ParserException { + text = text.trim().replaceAll("'", ""); + Pattern pattern = Pattern.compile("\\+?\\-?\\d+\\.?\\d*"); + Matcher matcher = pattern.matcher(text); + if (matcher.find()) + return matcher.group(); + else + throw new ParserException(text); + } + + /** + * Parses the unit from the string containing number with unit e.g. parses em from 12.4em. + * + * @param text + * the input text containing number and unit. + * @return a unit parsed from the input text. + */ + public static String parserUnit(String text) { + Pattern pattern = Pattern.compile("[a-z]+"); + Matcher matcher = pattern.matcher(text); + if (matcher.find()) + return matcher.group(); + else + return ""; + } + + /** + * Transformes a string containing color in hexadecimal format (#rrggbb) to Color. + * + * @param color + * the input color Color. + * @return transformed input color to a string containg the color in hexadecimal format + * (#rrggbb). + */ + public static String createColor(Color color) { + String red = Integer.toHexString(color.getRed()).toUpperCase(); + String green = Integer.toHexString(color.getGreen()).toUpperCase(); + String blue = Integer.toHexString(color.getBlue()).toUpperCase(); + + if (red.length() == 1) + red = "0" + red; + if (green.length() == 1) + green = "0" + green; + if (blue.length() == 1) + blue = "0" + blue; + + return "#" + red + green + blue; + } + + /** + * Parses the string containing color in hexadecimal format (#rrggbb) and converts it to the + * Color. + * + * @param hexCol + * the string containing a color in in hexadecimal format (#rrggbb). + * @return a color parsed from the input string. If the input color is invalid, then + * null is returned. + */ + public static Color parseColor(String hexCol) { + if (hexCol.length() != 7) + return null; + try { + return new Color(Integer.parseInt(hexCol.substring(1, 3), 16), Integer.parseInt(hexCol + .substring(3, 5), 16), Integer.parseInt(hexCol.substring(5, 7), 16)); + } catch (Throwable e) { + return null; + } + } + + /** + * Parses boolean value from the input string containig 1/0 or true/false. + * + * @param boolValue + * the string containing 1/0 or true/false. + * @return a parsed boolean value - true or false. + */ + public static Boolean parseBoolean(String boolValue) { + try { + return (Integer.valueOf(boolValue) == 0) ? false : true; + } catch (NumberFormatException ex) { + if (boolValue.equals("true") || boolValue.equals("false")) + return Boolean.valueOf(boolValue); + } + return null; + } + + /** + * Converts the boolean value to the string value "1" or "0". + * + * @param boolValue + * the input boolean value. + * @return a string "1" if the input was true, "0" if the input was false. + */ + public static String convertBoolean(boolean boolValue) { + return boolValue ? "1" : "0"; + } +} diff --git a/contrib/tools/fo-editor/src/log4j.xml b/contrib/tools/fo-editor/src/log4j.xml new file mode 100644 index 000000000..96cb5cd3d --- /dev/null +++ b/contrib/tools/fo-editor/src/log4j.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/contrib/tools/fo-editor/src/resources/ErrorResource.properties b/contrib/tools/fo-editor/src/resources/ErrorResource.properties new file mode 100644 index 000000000..78b748b7f --- /dev/null +++ b/contrib/tools/fo-editor/src/resources/ErrorResource.properties @@ -0,0 +1,35 @@ + +#OptionController +error.option_controller.file_not_found=File {0} not found. +error.option_controller.store=Couldn't store {0}. +info.option_controller.load_default_option=Default option loaded. +info.option_controller.load_file=Option file loaded. +info.option_controller.load_option_items=Option items loaded. +info.option_controller.save_file=Option file saved. + +#ProgressControl +info.progress_control.load_file=File {0} successfully loaded. +info.progress_control.load_parameter_description=Files with parameter descriptions successfully loaded. +info.progress_control.load_property_description=Files with property descriptions successfully loaded. + +#TemplateControl +info.template_control.load_template=File {0} succesfully loaded. + +#ResourceController +error.resource_controller.missing_key=Missing string key {0}. + +#ParamXmlParser +error.param_parser.transformation_error=Cannot transform description. +error.param_parser.parser_error=Cannot parser .xml definition file. + +#EditorIcon +error.editor_icon=File image not found. + +#TypeParam - relations +error.update_value=Cannot update component value. + +#OptionForm +info.option_form.editor.update_values=Restored default editor option values. +info.option_form.editor.save_values=Saved editor option values. +info.option_form.save.update_values=Restored default stylesheet option values. +info.option_form.save.save_values=Saved stylesheet option values. diff --git a/contrib/tools/fo-editor/src/resources/TextResource_cs.properties b/contrib/tools/fo-editor/src/resources/TextResource_cs.properties new file mode 100644 index 000000000..5de8b9b67 --- /dev/null +++ b/contrib/tools/fo-editor/src/resources/TextResource_cs.properties @@ -0,0 +1,205 @@ +#main frame +editor.title=Editor FO parametrů + +editor.browser.description=Otevře stránku s popisem {0} ve webovém prohlížeči. +editor.browser.menu.open_browser=Otevřít webový prohlížeč +editor.browser.menu.copy_location=Kopírovat umístění + +#attribute frame +frame.attribute.title=Atributy - + +#intro frame +frame.intro.title=Editor FO parametrů - načítání... + +frame.intro.progress.loading_file=Načítání konfiguračních souborů... +frame.intro.progress.read_file=Soubor {0} úspěšně načten. +frame.intro.progress.read_ok=OK +frame.intro.progress.correct_error=Prosím opravte výše uvedenou chybu a spusťte editor znovu. + +parser.config_file.title=Načítání konfiguračních souborů +parser.config.duplicate_parameter={0} - {1} (řádka {2}) se vyskytuje vícekrát. +parser.attributes.invalid_attribute_value={0} - (řádka {1}) má nepodporované hodnoty hodnotu. +parser.attributes.invalid_attribute_default_value={0} - (řádka {1}) nepodporovanou hodnotu . +parser.attributes.invalid_attribute_type={0} - (řádka {1}) má nepodporovaný typ. +parser.figures.invalid_parameter_value={0} -
"{1}" (řádka {2}) má nepodporovaný parametr "{3}". +parser.figures.invalid_class={0} -
"{1}" (řádka {2}) odkazuje na nepodporovanou třídu {3}. +parser.xml_definition_file.invalid_directory=Cesta k adresáři s XML specifikacemi FO parametrů není správně nastavena (Nastavení/Vlastnosti editoru.../Specifikace FO parametrů). +parser.xml_definition_file.missing_file=Chybí soubor "{0}.xml" v adresáři "{1}". +parser.parameters.invalid_type={0} - "{1}" (řádka {2}) má nepodporovaný "data-type" ({1}.xml). +parser.parameters.invalid_value={0} - "{1}" (řádka {2}) má nepodporovanou hodnotu ({1}.xml). +parser.parameters.dependency_cycle={0} - cyklicky závislé parametry: {1}. +parser.property.invalid_value={0} - "{1}" (řádka {2}) má nepodporovanou hodnotu atributu {3} ({1}.xml). +parser.property.invalid_type={0} - {1} (řádka {2}) má nepodporovaný "data-type" ({1}.xml). +parser.property.unsupported_attribute={0} - {1} (řádka {2}) má nepodporovaný atribut {3} ({1}.xml). + +#template +parser.template.find_property={0} - nelze najít "{1}" definovaný v {2} (řádka {3}). +parser.template.find_attribute={0} - nelze najít "{1}" definovaný v {2} (řádka {3}). +parser.template.find_parameter={0} - nelze najít "{1}" definovaný v {2} (řádka {3}). +parser.template.parse_attribute_value={0} - nelze přečíst hodnotu "{1}" (řádka {2}). +parser.template.parse_parameter_value={0} - nelze přečíst hodnotu "{1}" (řádka {2}). + +#frame about +frame.about.title=O programu Editor FO parametrů +frame.about.version=Verze: {0} +frame.about.author=Autor: Marta Vaclavikova + +#frame info +frame.config_info.title=Informace o konfiguračních souborech +frame.config_info.directory=Adresář s XML specifikacemi FO parametrů +frame.config_info.files.title=Konfigurační soubory +frame.config_info.files.config.description=Definuje rozmístění parametrů a sad atributů v editoru. +frame.config_info.files.attributes.description=Definuje vlastnosti a rozmístění atributů. +frame.config_info.files.types.description=Definuje typy parametrů a atributů. +frame.config_info.files.graphics.description=Definuje grafické prvky. +frame.config_info.template.title=Standardní šablona + +#frame option +frame.option.save.title=Vlastnosti stylu +frame.option.editor.title=Vlastnosti editoru + +option_editor.language=Jazyk editoru +option_editor.language.description=Změnit jazykovou verzi prohlížeče. +option_editor.xml_definition_path=XML specifikace FO parametrů +option_editor.xml_definition_path.description=Cesta k adresáři, kde jsou uloženy XML specifikace FO parametrů. +option_editor.xml_definition_path.button=Projít... +option_editor.erase_console=Smazat konzoli +option_editor.erase_console.description=Smazat konzoli pred každou akcí editoru. + +option_save.new_file_template.title=Nový XSL styl +option_save.stylesheet_format.title=XSL styl +option_save.output_file.title=Výstupní soubor +option_save.add_fo_namespace=Přidat jmenný prostor FO +option_save.add_fo_namespace.description=Přidat jmenný prostor FP do definice elementu xsl:stylesheet. +option_save.change_save=Uložení s přeuspořádáním +option_save.change_save.description=Přeuspořádat všechny známé parametry při ukládání XSL stylu. +option_save.change_save.warning=Všechny komentáře v otevřeném souboru se odstraní! +option_save.generate_com=Generovat komentáře +option_save.generate_com.description=Generovat komentáře k parametrům v XSL stylu. +option_save.use_param_select=Použít 'select' v parametrech +option_save.use_param_select.description=Použít atribut 'select' v definicích parametrů, např. . +option_save.encoding=Kódování +option_save.encoding.description=Kódování výstupního XSL souboru, např. . +option_save.newline=Konec řádky +option_save.newline.description=Znak konce řádky používaný ve výstupních XSL souborech. +option_save.stylesheet_version=Verze XSL stylu +option_save.stylesheet_version.description=Verze XSL stylu, např. . +option_save.import_file=Importovaný styl +option_save.import_file.description=Standardní XSL styl importovaný editovaným XSL stylem, např. . Write down path separated by ';'. + +# open file +open_file.title=Otevírání souboru +open_file.success_info=Soubor {0} úspěšně načten. +open_file.stylesheet_invalid=Element typu je na nesprávné pozici. +open_file.parameter_exist=Řádka {0} - "{1}" není dosud podporovaný editorem. +open_file.parameter_invalid=Řádka {0} - "{1}" má nepodporovaný formát. +open_file.attribute_set_exist=Řádka {0} - "{1}" není dosud podporovaný editorem. +open_file.attribute_set_invalid=Řádka {0} - "{1}" má nepodporovaný formát. +open_file.attribute_exist=Řádka {0} - "{1}" není dosud podporovaný editorem. +open_file.attribute_invalid=Řádka {0} - "{1}" má nepodporovaný formát. + +#save file +save_file.dialog_file_exist.title=Přepsat soubor +save_file.dialog_file_exist.text=Přepsat existující soubor? +save_file.dialog_save_changes.title=Uložit změny +save_file.dialog_save_changes.text=Soubor s XSL stylem byl změněn.\nChcete uložit změny? +save_file.title=Ukládání souboru +save_file.success_info=Soubor {0} úspěšně uložen. + +#new file +new_file.title=Vytváření nového souboru +new_file.empty.info=Nový prázdný soubor úspěšně vytvořen. +new_file.default.info=Nový soubor podle standardní šablony úspěšně vytvořen. +new_file.stylesheet.info=Nový soubor podle šablony {0} úspěšně vytvořen. +new_file_template.load_template.title=Načítání souboru se šablonou {0}. + +#run batch +run_batch_file.title=Spuštění dávkového souboru +run_batch_file.running=Spuštění dávkového souboru {0}. +run_batch_file.not_saved=Nelze spustit dávkový soubor - soubor se stylem není uložen. +run_batch_file.file_not_exists=Nelze spustit dávkový soubor - dávkový soubor neexistuje. Prosím vyberte dávkový soubor. +run_batch_file.error_running=Chyba při běhu dávkového souboru {0}. + +#errors +error.config_error=Chyba v souboru {0}. +error.xslt_parser=Řádka {0}, sloupec {1} \n {2} +error.xslt_parser.fatal=Závažná chyba: +error.xslt_parser.warning=Varování: +error.file_not_found.file=Nelze najít soubor {0}. +error.file_not_found.dir=Cesta k adresáři s XML specifikacemi parametrů není správně nastavena. +error.parser_error=Nelze přečíst {0}. +error.open_file.wrong_form=Soubor není validní\n +error.save_file=Chyba při ukládání souboru {0}: +error.component.update_value=Nelze změnit hodnotu komponenty {0} na novou hodnotu {1}. +error_dialog.title=Chyba v aplikaci +error.open_browser=Chyba při spouštění webového prohlížeče. +error.open_browser.title=Chyba spouštění webového prohlížeče + +#menu +menu.file=&Soubor +menu_item.new=&Nový +menu_item.new.tooltip=Vytvořit nový XSL styl +menu_item.new_empty=&Prázdný +menu_item.new_empty.tooltip=Vytvořit nový prázdný XSL styl +menu_item.new_default=&Standardní šablona +menu_item.new_default.tooltip=Vytvořit nový styl podle standardní šablony +menu_item.new_stylesheet=&Vybrat šablonu... +menu_item.new_stylesheet.tooltip=Vytvořit nový styl podle uživatelovy šablony +menu_item.open=&Otevřít... +menu_item.open.tooltip=Otevřít XSL soubor se stylem +menu_item.close=&Zavřít +menu_item.close.tooltip=Zavřít XSL soubor se stylem +menu_item.save_as=&Uložit jako... +menu_item.save_as.tooltip=Uložit XSL soubor se stylem +menu_item.save=&Uložit +menu_item.save.tooltip=Uložit XSL soubor se stylem +menu_item.exit=&Konec +menu_item.exit.tooltip=Zavřít editor +menu_item.option=&Nastavení +menu_item.option_save=Vlastnosti &stylu... +menu_item.option_save.tooltip=Změnit vlastnosti stylu +menu_item.option_editor=Vlastnosti &editoru... +menu_item.option_editor.tooltip=Změnit vlastnosti editoru +menu_item.run=&Spustit +menu_item.run_batch=&Spustit dávku +menu_item.run_batch.tooltip=Spustit vybraný dávkový soubor +menu_item.run_edit_batch=&Změnit dávkový soubor.. +menu_item.run_edit_batch.tooltip=Vybrat dávkový soubor +menu_item.run_batch_save=&Uložit před spuštěním +menu_item.run_batch_save.tooltip=Uložit aktuální soubor se stylem před spuštěním dávky +menu_item.help=&Nápověda +menu_item.help_window=&Obsah +menu_item.help_window.tooltip=Zobrazit obsah nápovědy +menu_item.config=&Konfigurace... +menu_item.config.tooltip=Zobrazit informace o konfiguračních souborech +menu_item.about=&O programu... +menu_item.about.tooltip=Zobrazit dialog O programu + +#language +language.en=Anglicky +language.cs=Česky + +#newline +encoding.crlf=WIN (CR+LF) +encoding.lf=UNIX (LF) +encoding.cr=MAC (CR) + +#button +button.cancel=Zrušit +button.save=Uložit +button.default=Obnovit původní +button.yes=Ano +button.no=Ne +button.ok=OK + +#url +url.parameter_description=http://docbook.sourceforge.net/release/xsl/current/doc/fo/{0}.html + +#color editor +component.color_editor.title=Editor barev +component.color_editor.error_parsing_color=Nelze přečíst barvu {0}. Nastavena standardní barva. + +# message writer +message_writer.warning=VAROVÁNÍ: +message_writer.error=CHYBA: +message_writer.info=INFO: diff --git a/contrib/tools/fo-editor/src/resources/TextResource_en.properties b/contrib/tools/fo-editor/src/resources/TextResource_en.properties new file mode 100644 index 000000000..ca62f04f7 --- /dev/null +++ b/contrib/tools/fo-editor/src/resources/TextResource_en.properties @@ -0,0 +1,205 @@ +#main frame +editor.title=FO Parameter Editor + +editor.browser.description=Open description page {0} in web browser. +editor.browser.menu.open_browser=Open web browser +editor.browser.menu.copy_location=Copy location + +#attribute frame +frame.attribute.title=Attributes - + +#intro frame +frame.intro.title=FO Parameter Editor - loading... + +frame.intro.progress.loading_file=Loading configuration files... +frame.intro.progress.read_file=File {0} successfully loaded. +frame.intro.progress.read_ok=OK +frame.intro.progress.correct_error=Please correct last mentioned error and launch the editor again. + +parser.config_file.title=Loading configuration files +parser.config.duplicate_parameter={0} - {1} (line {2}) is duplicated. +parser.attributes.invalid_attribute_value={0} - (line {1}) has unsupported values. +parser.attributes.invalid_attribute_default_value={0} - (line {1}) has unsupported value. +parser.attributes.invalid_attribute_type={0} - (line {1}) has unsupported type. +parser.figures.invalid_parameter_value={0} -
"{1}" (line {2}) has unsupported parameter "{3}". +parser.figures.invalid_class={0} -
"{1}" (line {2}) has reference to unsupported class {3}. +parser.xml_definition_file.invalid_directory=Path to the directory containing XML specifications of FO parameters is not properly set (Options/Editor options.../FO parameter specification). +parser.xml_definition_file.missing_file=Missing file "{0}.xml" in "{1}" directory. +parser.parameters.invalid_type={0} - "{1}" (line {2}) has unsupported "data-type" ({1}.xml). +parser.parameters.invalid_value={0} - "{1}" (line {2}) has unsupported value ({1}.xml). +parser.parameters.dependency_cycle={0} - cycle dependent parameters: {1}. +parser.property.invalid_value={0} - "{1}" (line {2}) has unsupported value of the attribute {3} ({1}.xml). +parser.property.invalid_type={0} - {1} (line {2}) has unsupported "data-type" ({1}.xml). +parser.property.unsupported_attribute={0} - {1} (line {2}) has unsupported attribute {3} ({1}.xml). + +#template +parser.template.find_property={0} - can’t find "{1}" defined in {2} (line {3}). +parser.template.find_attribute={0} - can’t find "{1}" defined in {2} (line {3}). +parser.template.find_parameter={0} - can’t find "{1}" defined in {2} (line {3}). +parser.template.parse_attribute_value={0} - can’t parse value of "{1}" (line {2}). +parser.template.parse_parameter_value={0} - can’t parse value of "{1}" (line {2}). + +#frame about +frame.about.title=About FO Parameters Editor +frame.about.version=Version: {0} +frame.about.author=Author: Marta Vaclavikova + +#frame info +frame.config_info.title=Configuration Files Info +frame.config_info.directory=Directory with FO parameter XML specification +frame.config_info.files.title=Configuration files +frame.config_info.files.config.description=Defines layout of parameters and attribute-sets in the editor. +frame.config_info.files.attributes.description=Defines features and layout of attributes in the attribute-sets. +frame.config_info.files.types.description=Defines parameter and attribute types. +frame.config_info.files.graphics.description=Defines graphics figures. +frame.config_info.template.title=Default template + +#frame option +frame.option.save.title=Stylesheet Options +frame.option.editor.title=Editor Options + +option_editor.language=Editor language +option_editor.language.description=Change language used in the editor. +option_editor.xml_definition_path=FO parameter XML specification +option_editor.xml_definition_path.description=Path to the directory where files with XML specifications of FO parameters are stored. +option_editor.xml_definition_path.button=Browse... +option_editor.erase_console=Erase console +option_editor.erase_console.description=Erase error console before every editor action. + +option_save.new_file_template.title=New XSL stylesheet +option_save.stylesheet_format.title=XSL stylesheet +option_save.output_file.title=Output file +option_save.add_fo_namespace=Add FO namespace +option_save.add_fo_namespace.description=Add FO namespace to the xsl:stylesheet definition. +option_save.change_save=Rearrange save +option_save.change_save.description=Rearrange all known parameters by saving XSL stylesheet. +option_save.change_save.warning=All comments in the opened file will be erased! +option_save.generate_com=Generate comments +option_save.generate_com.description=Generate parameter comments in the XSL stylesheet. +option_save.use_param_select=Use 'select' in parameters +option_save.use_param_select.description=Use attribute 'select' in parameter definitions, e.g. . +option_save.encoding=Output encoding +option_save.encoding.description=Output XSL file encoding, e.g. . +option_save.newline=End of line +option_save.newline.description=End of line character used in output XSL files. +option_save.stylesheet_version=Stylesheet version +option_save.stylesheet_version.description=Stylesheet version, e.g. . +option_save.import_file=Imported stylesheet +option_save.import_file.description=Standard stylesheet file imported by edited stylesheet, e.g. . Write down path separated by ';'. + +# open file +open_file.title=Opening file +open_file.success_info=File {0} succesfully opened. +open_file.stylesheet_invalid=The element isn’t well placed. +open_file.parameter_exist=Line {0} - "{1}" isn’t supported by the editor yet. +open_file.parameter_invalid=Line {0} - "{1}" hasn’t supported format. +open_file.attribute_set_exist=Line {0} - "{1}" isn’t supported by the editor yet. +open_file.attribute_set_invalid=Line {0} - "{1}" hasn’t supported format. +open_file.attribute_exist=Line {0} - "{1}" isn’t supported by the editor yet. +open_file.attribute_invalid=Line {0} - "{1}" hasn’t supported format. + +#save file +save_file.dialog_file_exist.title=Overwrite file +save_file.dialog_file_exist.text=Overwrite existing file? +save_file.dialog_save_changes.title=Save changes +save_file.dialog_save_changes.text=Stylesheet file has changed.\nDo you want to save the changes? +save_file.title=Saving file +save_file.success_info=File {0} succesfully saved. + +#new file +new_file.title=Creating new file +new_file.empty.info=New empty file succesfully created. +new_file.default.info=New file according to the default template succesfully created. +new_file.stylesheet.info=New file according to the stylesheet {0} succesfully created. +new_file_template.load_template.title=Loading template file {0}. + +#run batch +run_batch_file.title=Running batch file +run_batch_file.running=Running batch file {0}. +run_batch_file.not_saved=Cannot run batch file - stylesheet file is not saved. +run_batch_file.file_not_exists=Cannot run batch file - batch file doesn't exist. Please choose a batch file. +run_batch_file.error_running=Error running batch file {0}. + +#errors +error.config_error=Error in the file {0}. +error.xslt_parser=Line {0}, column {1} \n {2} +error.xslt_parser.fatal=Fatal error: +error.xslt_parser.warning=Warning: +error.file_not_found.file=Could not find file {0}. +error.file_not_found.dir=Path to the directory with XML parameter specifications is not properly set. +error.parser_error=Cannot parse {0}. +error.open_file.wrong_form=File is not well-formed\n +error.save_file=Error saving file {0}: +error.component.update_value=Cannot update value of the parameter/attribute {0} by new value {1}. +error_dialog.title=Application Error +error.open_browser=Error attempting to launch web browser. +error.open_browser.title=Error launching web browser + +#menu +menu.file=&File +menu_item.new=&New +menu_item.new.tooltip=Create new XSL file +menu_item.new_empty=&Empty +menu_item.new_empty.tooltip=Create a new empty stylesheet +menu_item.new_default=&Default Template +menu_item.new_default.tooltip=Create a new stylesheet according the default template +menu_item.new_stylesheet=&Choose Template... +menu_item.new_stylesheet.tooltip=Create a new stylesheet according the user template +menu_item.open=&Open... +menu_item.open.tooltip=Open XSL stylesheet file +menu_item.close=&Close +menu_item.close.tooltip=Close XSL stylesheet file +menu_item.save_as=S&ave As... +menu_item.save_as.tooltip=Save XSL stylesheet file +menu_item.save=&Save +menu_item.save.tooltip=Save XSL stylesheet file +menu_item.exit=&Exit +menu_item.exit.tooltip=Close editor +menu_item.option=&Options +menu_item.option_save=&Stylesheet Options... +menu_item.option_save.tooltip=Change stylesheet options +menu_item.option_editor=&Editor Options... +menu_item.option_editor.tooltip=Change editor options +menu_item.run=&Run +menu_item.run_batch=&Run Batch +menu_item.run_batch.tooltip=Run selected batch file +menu_item.run_edit_batch=&Change Batch File.. +menu_item.run_edit_batch.tooltip=Select batch file +menu_item.run_batch_save=&Save Before Run +menu_item.run_batch_save.tooltip=Save actual stylesheet file before running batch file +menu_item.help=&Help +menu_item.help_window=&Help Contents +menu_item.help_window.tooltip=Show help contents +menu_item.config=&Config Info... +menu_item.config.tooltip=Show information about configuration files +menu_item.about=&About... +menu_item.about.tooltip=Show about dialog + +#language +language.en=English +language.cs=Czech + +#newline +encoding.crlf=WIN (CR+LF) +encoding.lf=UNIX (LF) +encoding.cr=MAC (CR) + +#button +button.cancel=Cancel +button.save=Save +button.default=Restore Defaults +button.yes=Yes +button.no=No +button.ok=OK + +#url +url.parameter_description=http://docbook.sourceforge.net/release/xsl/current/doc/fo/{0}.html + +#color editor +component.color_editor.title=Color Editor +component.color_editor.error_parsing_color=Cannot parse color {0}. Set default color. + +# message writer +message_writer.warning=WARNING: +message_writer.error=ERROR: +message_writer.info=INFO: diff --git a/contrib/tools/fo-editor/src/schemas/attributes.xsd b/contrib/tools/fo-editor/src/schemas/attributes.xsd new file mode 100644 index 000000000..47dab7992 --- /dev/null +++ b/contrib/tools/fo-editor/src/schemas/attributes.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/tools/fo-editor/src/schemas/config.xsd b/contrib/tools/fo-editor/src/schemas/config.xsd new file mode 100644 index 000000000..aaac93460 --- /dev/null +++ b/contrib/tools/fo-editor/src/schemas/config.xsd @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/tools/fo-editor/src/schemas/convert.xsl b/contrib/tools/fo-editor/src/schemas/convert.xsl new file mode 100644 index 000000000..91b013ca0 --- /dev/null +++ b/contrib/tools/fo-editor/src/schemas/convert.xsl @@ -0,0 +1,45 @@ + +&amp;"> +]> + + + + + + + + + + + + +

+
+ + + + + + + + + + + + + + +
+
+ + +
    + +
  • -
  • +
    +
+
+ +
diff --git a/contrib/tools/fo-editor/src/schemas/graphics.xsd b/contrib/tools/fo-editor/src/schemas/graphics.xsd new file mode 100644 index 000000000..4e572081d --- /dev/null +++ b/contrib/tools/fo-editor/src/schemas/graphics.xsd @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/tools/fo-editor/src/schemas/template.xsd b/contrib/tools/fo-editor/src/schemas/template.xsd new file mode 100644 index 000000000..6190d86e0 --- /dev/null +++ b/contrib/tools/fo-editor/src/schemas/template.xsd @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/tools/fo-editor/src/schemas/types.xsd b/contrib/tools/fo-editor/src/schemas/types.xsd new file mode 100644 index 000000000..3275e352d --- /dev/null +++ b/contrib/tools/fo-editor/src/schemas/types.xsd @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/tools/fo-editor/templates/template.xml b/contrib/tools/fo-editor/templates/template.xml new file mode 100644 index 000000000..4db7ed858 --- /dev/null +++ b/contrib/tools/fo-editor/templates/template.xml @@ -0,0 +1,36 @@ + +