Commit 1678503d577fa8efd91021a98e8d4a7728f42f4e
1 parent
94f296fa
dodane GUI w Javie
Autorem GUI jest Piotr Rychlik Uwzględnione tworzenie pakietu .deb i „dysku” dla MacOS
Showing
60 changed files
with
3509 additions
and
3 deletions
CMakeLists.txt
| ... | ... | @@ -4,7 +4,7 @@ project (Morfeusz) |
| 4 | 4 | |
| 5 | 5 | set (Morfeusz_VERSION_MAJOR 1) |
| 6 | 6 | set (Morfeusz_VERSION_MINOR 9) |
| 7 | -set (Morfeusz_VERSION_PATCH 11) | |
| 7 | +set (Morfeusz_VERSION_PATCH 12) | |
| 8 | 8 | set (Morfeusz_VERSION "${Morfeusz_VERSION_MAJOR}.${Morfeusz_VERSION_MINOR}.${Morfeusz_VERSION_PATCH}") |
| 9 | 9 | set (Morfeusz_LIB_VERSION "${Morfeusz_VERSION}") |
| 10 | 10 | if (BUILT_ON) |
| ... | ... | @@ -202,6 +202,7 @@ file (COPY fsabuilder doTest.sh testJavaWrapper.sh testPythonWrapper.sh morfeusz |
| 202 | 202 | |
| 203 | 203 | add_subdirectory (morfeusz) |
| 204 | 204 | add_subdirectory (fsabuilder) |
| 205 | +add_subdirectory (gui) | |
| 205 | 206 | |
| 206 | 207 | ########## add tests ########## |
| 207 | 208 | |
| ... | ... |
createGUIDeb.sh
0 → 100755
| 1 | +#!/bin/bash | |
| 2 | + | |
| 3 | +SRC_DIR="$1" | |
| 4 | +BIN_DIR="$2" | |
| 5 | +LIB_VERSION="$3" | |
| 6 | +ARCH="$4" | |
| 7 | +TARGET_DIR="$5" | |
| 8 | + | |
| 9 | +PKG_NAME="morfeusz2-gui" | |
| 10 | + | |
| 11 | +PKG_DIR="$BIN_DIR/CMakeFiles/gui-deb.dir/${PKG_NAME}_${LIB_VERSION}" | |
| 12 | +echo Building GUI deb in $PKG_DIR | |
| 13 | + | |
| 14 | +mkdir -p "$PKG_DIR" | |
| 15 | +install -D "$SRC_DIR/gui/morfeusz.desktop" "$PKG_DIR/usr/share/applications/morfeusz.desktop" | |
| 16 | +install -D "$BIN_DIR/morfeusz.jar" "$PKG_DIR/usr/share/java/morfeusz.jar" | |
| 17 | +install -D "$SRC_DIR/gui/morfeusz.svg" "$PKG_DIR/usr/share/morfeusz2/morfeusz.svg" | |
| 18 | +install -D "$SRC_DIR/gui/morfeusz2-gui.menu" "$PKG_DIR/usr/share/menu/morfeusz2-gui" | |
| 19 | +install -D "$SRC_DIR/gui/morfeusz2-gui" "$PKG_DIR/usr/bin/morfeusz2-gui" | |
| 20 | + | |
| 21 | + | |
| 22 | +#SRC_DIR="$( cd "$( dirname "$0" )" && pwd )" | |
| 23 | + | |
| 24 | +"$SRC_DIR/createDeb.sh" "$PKG_NAME" \ | |
| 25 | + "GUI for morphological analyzer Morfeusz 2" \ | |
| 26 | + "Graphical user inferface for the morphological analyzer and generator Morfeusz 2 (used mainly for Polish)" \ | |
| 27 | + "java-runtime, libjmorfeusz-java" "morfeusz2-gui" "$LIB_VERSION" "$ARCH" misc "$PKG_DIR" "$TARGET_DIR" | |
| ... | ... |
gui/CMakeLists.txt
0 → 100644
| 1 | +include(UseJava) | |
| 2 | +find_package(Java REQUIRED) | |
| 3 | + | |
| 4 | +# include_directories (${JAVA_INCLUDE_PATH}) | |
| 5 | +# include_directories (${JAVA_INCLUDE_PATH2}) | |
| 6 | +# include_directories (${CMAKE_SOURCE_DIR}/morfeusz) | |
| 7 | + | |
| 8 | +set(GUI_SOURCES | |
| 9 | + morfeusz/AboutDialog.java | |
| 10 | + morfeusz/Agent.java | |
| 11 | + morfeusz/DictSearchPathsDialog.java | |
| 12 | + morfeusz/Morfeusz.java | |
| 13 | + morfeusz/OptionsDialog.java | |
| 14 | + morfeusz/PlaceHolder.java | |
| 15 | + morfeusz/Preferences.java | |
| 16 | + morfeusz/RecentFileAction.java | |
| 17 | + morfeusz/ResultsPane.java | |
| 18 | + morfeusz/SelectFileDialog.java | |
| 19 | + morfeusz/ToolBarButton.java | |
| 20 | + ) | |
| 21 | + | |
| 22 | +# set(GUI_IMAGES | |
| 23 | +# images/book_open_disabled.png images/book_open.png | |
| 24 | +# images/book_open_pressed.png images/book_open_roll_over.png | |
| 25 | +# images/conf.png images/conf_pressed.png images/conf_roll_over.png | |
| 26 | +# images/down.gif images/end_node.gif images/font_decrease.png | |
| 27 | +# images/font_decrease_pressed.png images/font_decrease_roll_over.png | |
| 28 | +# images/font_increase.png images/font_increase_pressed.png | |
| 29 | +# images/font_increase_roll_over.png images/info.png | |
| 30 | +# images/info_pressed.png images/info_roll_over.png images/open.png | |
| 31 | +# images/open_pressed.png images/open_roll_over.png images/return.png | |
| 32 | +# images/return_pressed.png images/return_roll_over.png | |
| 33 | +# images/save_disabled.png images/save.png images/save_pressed.png | |
| 34 | +# images/save_roll_over.png images/start_node.gif | |
| 35 | +# ) | |
| 36 | + | |
| 37 | +# kopiujemy, żeby zip poniżej mógł je dodać bez ścieżki: | |
| 38 | +file(GLOB IMAGE_FILES "images/*") | |
| 39 | +file(COPY ${IMAGE_FILES} DESTINATION .) | |
| 40 | +file(COPY quitaboutpreferenceshandler/ DESTINATION quitaboutpreferenceshandler/) | |
| 41 | + | |
| 42 | +# to jest w zasadzie niepotrzebne, chyba że chcemy odpalić skompilowanego morfeusz.jar bez instalacji: | |
| 43 | +#file(COPY QuitAboutPreferencesHandler.jar DESTINATION .) | |
| 44 | + | |
| 45 | +add_jar (gui-proto-jar | |
| 46 | + SOURCES "${GUI_SOURCES}" | |
| 47 | + #"${GUI_IMAGES}" | |
| 48 | +# INCLUDE_JARS jmorfeusz.jar QuitAboutPreferencesHandler.jar images.jar | |
| 49 | +# INCLUDE_JARS ${CMAKE_CURRENT_BINARY_DIR}/../morfeusz/wrappers/java/jmorfeusz.jar QuitAboutPreferencesHandler.jar Images/*.png | |
| 50 | + INCLUDE_JARS jmorfeusz QuitAboutPreferencesHandler.jar | |
| 51 | + # ENTRY_POINT morfeusz/Morfeusz | |
| 52 | + MANIFEST MANIFEST.MF | |
| 53 | + OUTPUT_NAME morfeusz | |
| 54 | + ) | |
| 55 | + | |
| 56 | +add_dependencies(gui-proto-jar jmorfeusz) | |
| 57 | + | |
| 58 | +add_custom_target(gui-jar | |
| 59 | + COMMAND zip -q morfeusz.jar "*.png" | |
| 60 | + COMMAND zip -q morfeusz.jar "*.gif" | |
| 61 | + COMMAND zip -q morfeusz.jar "quitaboutpreferenceshandler/*" | |
| 62 | + DEPENDS gui-proto-jar | |
| 63 | + ) | |
| 64 | + | |
| 65 | + | |
| 66 | +add_custom_target (gui-deb | |
| 67 | + COMMAND "${PROJECT_SOURCE_DIR}/createGUIDeb.sh" "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${Morfeusz_DEB_VERSION}" "${ARCHITECTURE}" "${TARGET_DIR}" | |
| 68 | + DEPENDS gui-jar | |
| 69 | + ) | |
| 70 | + | |
| 71 | +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |
| 72 | + set(MAC_APP_DIR "dmg/Morfeusz.app") | |
| 73 | + file(COPY Morfeusz.app/ DESTINATION "${MAC_APP_DIR}") | |
| 74 | + add_custom_target(gui-dmg | |
| 75 | + COMMAND install -D "${CMAKE_CURRENT_BINARY_DIR}/../morfeusz/libmorfeusz2.dylib" "${MAC_APP_DIR}/Contents/MacOS/libmorfeusz2.dylib" | |
| 76 | + COMMAND install -D "${CMAKE_CURRENT_BINARY_DIR}/../morfeusz/wrappers/java/libjmorfeusz.jnilib" "${MAC_APP_DIR}/Contents/MacOS/libjmorfeusz.jnilib" | |
| 77 | + COMMAND install -D "${CMAKE_CURRENT_BINARY_DIR}/morfeusz.jar" "${MAC_APP_DIR}/Contents/Java/morfeusz.jar" | |
| 78 | + COMMAND install -D "${CMAKE_CURRENT_BINARY_DIR}/../morfeusz/wrappers/java/jmorfeusz.jar" "${MAC_APP_DIR}/Contents/Java/jmorfeusz.jar" | |
| 79 | + COMMAND genisoimage -V Morfeusz2 -D -R -apple -no-pad -o "$TARGET_DIR/morfeusz2-gui_${Morfeusz_LIB_VERSION}.${DICT_VERSION}-${CMAKE_SYSTEM_NAME}-${ARCHITECTURE}.dmg" "dmg/" | |
| 80 | + ) | |
| 81 | +endif () | |
| ... | ... |
gui/MANIFEST.MF
0 → 100644
gui/Morfeusz.app/Contents/Info.plist
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| 3 | +<plist version="1.0"> | |
| 4 | +<dict> | |
| 5 | + <key>CFBundleDevelopmentRegion</key> | |
| 6 | + <string>English</string> | |
| 7 | + <key>CFBundleExecutable</key> | |
| 8 | + <string>JavaAppLauncher</string> | |
| 9 | + <key>CFBundleIdentifier</key> | |
| 10 | + <string>morfeusz.Morfeusz</string> | |
| 11 | + <key>CFBundleDisplayName</key> | |
| 12 | + <string>Morfeusz</string> | |
| 13 | + <key>CFBundleInfoDictionaryVersion</key> | |
| 14 | + <string>6.0</string> | |
| 15 | + <key>CFBundleName</key> | |
| 16 | + <string>Morfeusz</string> | |
| 17 | + <key>CFBundlePackageType</key> | |
| 18 | + <string>APPL</string> | |
| 19 | + <key>CFBundleShortVersionString</key> | |
| 20 | + <string>2.0</string> | |
| 21 | + <key>CFBundleSignature</key> | |
| 22 | + <string>????</string> | |
| 23 | + <key>CFBundleVersion</key> | |
| 24 | + <string>2</string> | |
| 25 | + <key>NSHumanReadableCopyright</key> | |
| 26 | + <string>Instytut Podstaw Informatyki PAN</string> | |
| 27 | + <key>JVMMainClassName</key> | |
| 28 | + <string>morfeusz.Morfeusz</string> | |
| 29 | + <key>JVMOptions</key> | |
| 30 | + <array> | |
| 31 | + </array> | |
| 32 | + <key>JVMArguments</key> | |
| 33 | + <array> | |
| 34 | + </array> | |
| 35 | +</dict> | |
| 36 | +</plist> | |
| ... | ... |
gui/Morfeusz.app/Contents/Java/.exists
0 → 100644
gui/Morfeusz.app/Contents/MacOS/JavaAppLauncher
0 → 100755
No preview for this file type
gui/Morfeusz.app/Contents/Resources/.exists
0 → 100644
gui/QuitAboutPreferencesHandler.jar
0 → 100644
No preview for this file type
gui/images/book_open.png
0 → 100644
2.87 KB
gui/images/book_open_disabled.png
0 → 100644
2.9 KB
gui/images/book_open_pressed.png
0 → 100644
2.86 KB
gui/images/book_open_roll_over.png
0 → 100644
2.86 KB
gui/images/conf.png
0 → 100644
4.86 KB
gui/images/conf_pressed.png
0 → 100644
4.84 KB
gui/images/conf_roll_over.png
0 → 100644
4.87 KB
gui/images/down.gif
0 → 100644
114 Bytes
gui/images/end_node.gif
0 → 100644
91 Bytes
gui/images/font_decrease.png
0 → 100644
3.36 KB
gui/images/font_decrease_pressed.png
0 → 100644
3.27 KB
gui/images/font_decrease_roll_over.png
0 → 100644
3.32 KB
gui/images/font_increase.png
0 → 100644
3.56 KB
gui/images/font_increase_pressed.png
0 → 100644
3.42 KB
gui/images/font_increase_roll_over.png
0 → 100644
3.48 KB
gui/images/info.png
0 → 100644
4.89 KB
gui/images/info_pressed.png
0 → 100644
4.77 KB
gui/images/info_roll_over.png
0 → 100644
4.88 KB
gui/images/open.png
0 → 100644
2.86 KB
gui/images/open_pressed.png
0 → 100644
2.87 KB
gui/images/open_roll_over.png
0 → 100644
2.87 KB
gui/images/return.png
0 → 100644
2.83 KB
gui/images/return_pressed.png
0 → 100644
2.82 KB
gui/images/return_roll_over.png
0 → 100644
2.83 KB
gui/images/save.png
0 → 100644
3.14 KB
gui/images/save_disabled.png
0 → 100644
3.03 KB
gui/images/save_pressed.png
0 → 100644
3.14 KB
gui/images/save_roll_over.png
0 → 100644
3.15 KB
gui/images/start_node.gif
0 → 100644
92 Bytes
gui/morfeusz.desktop
0 → 100644
| 1 | +[Desktop Entry] | |
| 2 | +Encoding=UTF-8 | |
| 3 | +Type=Application | |
| 4 | +Name=Morfeusz | |
| 5 | +Comment=Morphological analyzer and generator Morfeusz 2 | |
| 6 | +Comment[pl]=Analizator i generator fleksyjny Morfeusz 2 | |
| 7 | +Icon=/usr/share/morfeusz2/morfeusz.svg | |
| 8 | +Exec=/usr/bin/morfeusz2-gui | |
| 9 | +Terminal=false | |
| 10 | +Categories=Office;Dictionary;GTK; | |
| ... | ... |
gui/morfeusz.svg
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 2 | +<!-- Created with Inkscape (http://www.inkscape.org/) --> | |
| 3 | + | |
| 4 | +<svg | |
| 5 | + xmlns:dc="http://purl.org/dc/elements/1.1/" | |
| 6 | + xmlns:cc="http://creativecommons.org/ns#" | |
| 7 | + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
| 8 | + xmlns:svg="http://www.w3.org/2000/svg" | |
| 9 | + xmlns="http://www.w3.org/2000/svg" | |
| 10 | + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
| 11 | + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
| 12 | + version="1.0" | |
| 13 | + width="113.38583" | |
| 14 | + height="113.38583" | |
| 15 | + id="svg2" | |
| 16 | + inkscape:version="0.48.4 r9939" | |
| 17 | + sodipodi:docname="morfeusz2.svg"> | |
| 18 | + <metadata | |
| 19 | + id="metadata16"> | |
| 20 | + <rdf:RDF> | |
| 21 | + <cc:Work | |
| 22 | + rdf:about=""> | |
| 23 | + <dc:format>image/svg+xml</dc:format> | |
| 24 | + <dc:type | |
| 25 | + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | |
| 26 | + <dc:title /> | |
| 27 | + </cc:Work> | |
| 28 | + </rdf:RDF> | |
| 29 | + </metadata> | |
| 30 | + <sodipodi:namedview | |
| 31 | + pagecolor="#ffffff" | |
| 32 | + bordercolor="#666666" | |
| 33 | + borderopacity="1" | |
| 34 | + objecttolerance="10" | |
| 35 | + gridtolerance="10" | |
| 36 | + guidetolerance="10" | |
| 37 | + inkscape:pageopacity="0" | |
| 38 | + inkscape:pageshadow="2" | |
| 39 | + inkscape:window-width="1366" | |
| 40 | + inkscape:window-height="692" | |
| 41 | + id="namedview14" | |
| 42 | + showgrid="false" | |
| 43 | + inkscape:zoom="2.0813888" | |
| 44 | + inkscape:cx="54.940755" | |
| 45 | + inkscape:cy="56.248551" | |
| 46 | + inkscape:window-x="0" | |
| 47 | + inkscape:window-y="24" | |
| 48 | + inkscape:window-maximized="1" | |
| 49 | + inkscape:current-layer="svg2" /> | |
| 50 | + <defs | |
| 51 | + id="defs4" /> | |
| 52 | + <path | |
| 53 | + style="fill:#a05a2c;fill-opacity:1;fill-rule:nonzero;stroke:none" | |
| 54 | + d="M 17.75 0 C 7.9124097 0 0 7.9124101 0 17.75 L 0 56.6875 L 0 95.625 C 0 105.4626 7.9124097 113.375 17.75 113.375 L 56.6875 113.375 L 95.625 113.375 C 105.46259 113.375 113.375 105.4626 113.375 95.625 L 113.375 56.6875 L 113.375 17.75 C 113.375 7.9124092 105.46258 0 95.625 0 L 56.6875 0 L 17.75 0 z " | |
| 55 | + id="rect1307" /> | |
| 56 | + <g | |
| 57 | + id="g3860" | |
| 58 | + transform="translate(0.07142581,0.95918088)"> | |
| 59 | + <path | |
| 60 | + inkscape:connector-curvature="0" | |
| 61 | + id="path3058" | |
| 62 | + d="m 49.48619,49.304254 c 3.854793,-2.652072 9.732679,-2.779341 13.524988,-10e-7" | |
| 63 | + style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" | |
| 64 | + sodipodi:nodetypes="cc" /> | |
| 65 | + <g | |
| 66 | + transform="translate(4.5642603,-1.2011211)" | |
| 67 | + id="g3832"> | |
| 68 | + <path | |
| 69 | + sodipodi:type="arc" | |
| 70 | + style="fill:#000000;fill-opacity:1" | |
| 71 | + id="path3056" | |
| 72 | + sodipodi:cx="-26.064329" | |
| 73 | + sodipodi:cy="51.768322" | |
| 74 | + sodipodi:rx="18.377153" | |
| 75 | + sodipodi:ry="15.254238" | |
| 76 | + d="m -7.6871758,51.768322 c 0,8.424683 -8.2277322,15.254238 -18.3771532,15.254238 -10.149422,0 -18.377154,-6.829555 -18.377154,-15.254238 0,-8.424683 8.227732,-15.254238 18.377154,-15.254238 10.149421,0 18.3771532,6.829555 18.3771532,15.254238 z" | |
| 77 | + transform="matrix(1.1633987,0,0,1,55.786973,-2.6424662)" /> | |
| 78 | + <path | |
| 79 | + sodipodi:type="arc" | |
| 80 | + style="fill:#ffffff;fill-opacity:1;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none" | |
| 81 | + id="path3828" | |
| 82 | + sodipodi:cx="-23.782198" | |
| 83 | + sodipodi:cy="53.329777" | |
| 84 | + sodipodi:rx="10.81009" | |
| 85 | + sodipodi:ry="8.8882961" | |
| 86 | + d="m -12.972108,53.329777 c 0,4.90887 -4.839842,8.888296 -10.81009,8.888296 -5.970248,0 -10.81009,-3.979426 -10.81009,-8.888296 0,-4.908871 4.839842,-8.888296 10.81009,-8.888296 5.970248,0 10.81009,3.979425 10.81009,8.888296 z" | |
| 87 | + transform="matrix(0.66666667,0,0,0.64864864,49.005741,11.770987)" /> | |
| 88 | + </g> | |
| 89 | + <g | |
| 90 | + id="g3832-4" | |
| 91 | + transform="translate(56.933142,-0.84078676)"> | |
| 92 | + <path | |
| 93 | + sodipodi:type="arc" | |
| 94 | + style="fill:#000000;fill-opacity:1" | |
| 95 | + id="path3056-3" | |
| 96 | + sodipodi:cx="-26.064329" | |
| 97 | + sodipodi:cy="51.768322" | |
| 98 | + sodipodi:rx="18.377153" | |
| 99 | + sodipodi:ry="15.254238" | |
| 100 | + d="m -7.6871758,51.768322 c 0,8.424683 -8.2277322,15.254238 -18.3771532,15.254238 -10.149422,0 -18.377154,-6.829555 -18.377154,-15.254238 0,-8.424683 8.227732,-15.254238 18.377154,-15.254238 10.149421,0 18.3771532,6.829555 18.3771532,15.254238 z" | |
| 101 | + transform="matrix(1.1633987,0,0,1,55.786973,-2.6424662)" /> | |
| 102 | + <path | |
| 103 | + sodipodi:type="arc" | |
| 104 | + style="fill:#ffffff;fill-opacity:1;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none" | |
| 105 | + id="path3828-3" | |
| 106 | + sodipodi:cx="-23.782198" | |
| 107 | + sodipodi:cy="53.329777" | |
| 108 | + sodipodi:rx="10.81009" | |
| 109 | + sodipodi:ry="8.8882961" | |
| 110 | + d="m -12.972108,53.329777 c 0,4.90887 -4.839842,8.888296 -10.81009,8.888296 -5.970248,0 -10.81009,-3.979426 -10.81009,-8.888296 0,-4.908871 4.839842,-8.888296 10.81009,-8.888296 5.970248,0 10.81009,3.979425 10.81009,8.888296 z" | |
| 111 | + transform="matrix(0.66666667,0,0,0.64864864,49.005741,11.770987)" /> | |
| 112 | + </g> | |
| 113 | + </g> | |
| 114 | +</svg> | |
| ... | ... |
gui/morfeusz/AboutDialog.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.event.*; | |
| 5 | + | |
| 6 | +import javax.swing.*; | |
| 7 | + | |
| 8 | +@SuppressWarnings("serial") | |
| 9 | +public class AboutDialog extends JPanel | |
| 10 | +{ | |
| 11 | + | |
| 12 | + private static final String INFO = "<html><center><h3>Morfeusz</h3></center><br/>" + | |
| 13 | + "<center>Analizator morfologiczny dla j\u0119zyka polskiego.<br/><br/>" + | |
| 14 | + "Wersja: " + pl.sgjp.morfeusz.Morfeusz.getVersion() + "</center></html>"; | |
| 15 | + private JDialog dialog; | |
| 16 | + private JCheckBox pr = new JCheckBox("Program"); | |
| 17 | + private JCheckBox dict = new JCheckBox("S\u0142ownik"); | |
| 18 | + private JTextArea ta = new JTextArea(4, 58); | |
| 19 | + private Rectangle rect = new Rectangle(0, 0, 0, 0); | |
| 20 | + private String copyrights; | |
| 21 | + private String dictCopyrights; | |
| 22 | + | |
| 23 | + public AboutDialog(pl.sgjp.morfeusz.Morfeusz morfeusz) | |
| 24 | + { | |
| 25 | + super(new BorderLayout()); | |
| 26 | + | |
| 27 | + JLabel label = new JLabel(INFO); | |
| 28 | + JPanel panel = new JPanel(); | |
| 29 | + JScrollPane sp = new JScrollPane(ta); | |
| 30 | + ButtonGroup group = new ButtonGroup(); | |
| 31 | + Box vbox = Box.createVerticalBox(); | |
| 32 | + Box hbox = Box.createHorizontalBox(); | |
| 33 | + | |
| 34 | + setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); | |
| 35 | + vbox.setBorder(BorderFactory.createEmptyBorder(16, 0, 0, 0)); | |
| 36 | + ta.setMargin(new Insets(4, 4, 4, 4)); | |
| 37 | + ta.setEditable(false); | |
| 38 | + ta.setFont(Morfeusz.plainFont); | |
| 39 | + panel.add(label); | |
| 40 | + add(panel, BorderLayout.CENTER); | |
| 41 | + label = new JLabel("Prawa autorskie: "); | |
| 42 | + hbox.add(label); | |
| 43 | + hbox.add(pr); | |
| 44 | + hbox.add(dict); | |
| 45 | + hbox.add(Box.createHorizontalGlue()); | |
| 46 | + group.add(pr);; | |
| 47 | + group.add(dict); | |
| 48 | + pr.setSelected(true); | |
| 49 | + vbox.add(hbox); | |
| 50 | + vbox.add(sp); | |
| 51 | + add(vbox, BorderLayout.SOUTH); | |
| 52 | + pr.addActionListener(new ActionListener() { | |
| 53 | + public void actionPerformed(ActionEvent e) | |
| 54 | + { | |
| 55 | + setText(); | |
| 56 | + } | |
| 57 | + }); | |
| 58 | + dict.addActionListener(new ActionListener() { | |
| 59 | + public void actionPerformed(ActionEvent e) | |
| 60 | + { | |
| 61 | + setText(); | |
| 62 | + } | |
| 63 | + }); | |
| 64 | + copyrights = pl.sgjp.morfeusz.Morfeusz.getCopyright(); | |
| 65 | + copyrights = copyrights.replaceFirst("Science\n", "Sciences\n"); | |
| 66 | + copyrights = copyrights.replaceFirst("\n$", ""); | |
| 67 | + dictCopyrights = morfeusz.getDictCopyright(); | |
| 68 | + dictCopyrights = dictCopyrights.replaceFirst("\n$", ""); | |
| 69 | + setText(); | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void setText() | |
| 73 | + { | |
| 74 | + if (pr.isSelected()) ta.setText(copyrights); | |
| 75 | + else ta.setText(dictCopyrights); | |
| 76 | + EventQueue.invokeLater(new Runnable() { | |
| 77 | + public void run() | |
| 78 | + { | |
| 79 | + ta.scrollRectToVisible(rect); | |
| 80 | + } | |
| 81 | + }); | |
| 82 | + } | |
| 83 | + | |
| 84 | + public void doDialog() | |
| 85 | + { | |
| 86 | + dialog = new JDialog(); | |
| 87 | + dialog.setModal(true); | |
| 88 | + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); | |
| 89 | + dialog.setTitle("Informacje o programie"); | |
| 90 | + dialog.setResizable(false); | |
| 91 | + dialog.getContentPane().add(this); | |
| 92 | + dialog.pack(); | |
| 93 | + dialog.setLocationRelativeTo(null); | |
| 94 | + dialog.setVisible(true); | |
| 95 | + } | |
| 96 | + | |
| 97 | +} | |
| ... | ... |
gui/morfeusz/Agent.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.io.*; | |
| 4 | +import java.util.*; | |
| 5 | + | |
| 6 | +import pl.sgjp.morfeusz.*; | |
| 7 | + | |
| 8 | +public class Agent | |
| 9 | +{ | |
| 10 | + | |
| 11 | + private Morfeusz controller; | |
| 12 | + private String textToAnalyze; | |
| 13 | + private String lemma; | |
| 14 | + private String dictionary; | |
| 15 | + private HashSet<Integer> interpBoundaries; | |
| 16 | + private List<MorphInterpretation> analyzeResults; | |
| 17 | + private List<MorphInterpretation> generateResults; | |
| 18 | + private pl.sgjp.morfeusz.Morfeusz morfeusz; | |
| 19 | + | |
| 20 | + public static Agent createAgent(Morfeusz controller) | |
| 21 | + { | |
| 22 | + Agent agent = new Agent(controller); | |
| 23 | + | |
| 24 | + if (agent.morfeusz == null) return null; | |
| 25 | + return agent; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public Agent(Morfeusz controller) | |
| 29 | + { | |
| 30 | + this.controller = controller; | |
| 31 | + textToAnalyze = null; | |
| 32 | + lemma = null; | |
| 33 | + dictionary = null; | |
| 34 | + interpBoundaries = null; | |
| 35 | + analyzeResults = null; | |
| 36 | + generateResults = null; | |
| 37 | + initializeWithDictionaryName(); | |
| 38 | + } | |
| 39 | + | |
| 40 | + public void initialize() | |
| 41 | + { | |
| 42 | + Preferences prefs = controller.getPreferences(); | |
| 43 | + | |
| 44 | + morfeusz.setAggl(prefs.aggl); | |
| 45 | + morfeusz.setPraet(prefs.praet); | |
| 46 | + morfeusz.setCaseHandling(prefs.caseHandling); | |
| 47 | + morfeusz.setWhitespaceHandling(prefs.whitespaceHandling); | |
| 48 | + morfeusz.setTokenNumbering(prefs.tokenNumbering); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void initializeWithDictionaryName() | |
| 52 | + { | |
| 53 | + Preferences prefs = controller.getPreferences(); | |
| 54 | + | |
| 55 | + morfeusz = null; | |
| 56 | + if (prefs.dictionary != null) { | |
| 57 | + try { | |
| 58 | + morfeusz = pl.sgjp.morfeusz.Morfeusz.createInstance(prefs.dictionary, MorfeuszUsage.BOTH_ANALYSE_AND_GENERATE); | |
| 59 | + } | |
| 60 | + catch (Exception exception) { | |
| 61 | + morfeusz = null; | |
| 62 | + prefs.dictionary = null; | |
| 63 | + } | |
| 64 | + } | |
| 65 | + if (morfeusz == null) { | |
| 66 | + try { | |
| 67 | + morfeusz = pl.sgjp.morfeusz.Morfeusz.createInstance(MorfeuszUsage.BOTH_ANALYSE_AND_GENERATE); | |
| 68 | + } | |
| 69 | + catch (Exception exception) { | |
| 70 | + morfeusz = null; | |
| 71 | + } | |
| 72 | + } | |
| 73 | + if (morfeusz != null) initialize(); | |
| 74 | + else prefs.dictionary = null; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public void setTextToAnalyze(String text) | |
| 78 | + { | |
| 79 | + textToAnalyze = text; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public void setLemma(String text) | |
| 83 | + { | |
| 84 | + lemma = text; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public void clearAnalyzeResults() | |
| 88 | + { | |
| 89 | + analyzeResults.clear(); | |
| 90 | + analyzeResults = null; | |
| 91 | + interpBoundaries = null; | |
| 92 | + textToAnalyze = null; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public void clearGenerateResults() | |
| 96 | + { | |
| 97 | + generateResults.clear(); | |
| 98 | + generateResults = null; | |
| 99 | + lemma = null; | |
| 100 | + } | |
| 101 | + | |
| 102 | + public HashSet<Integer> getInterpBoundaries() | |
| 103 | + { | |
| 104 | + return interpBoundaries; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public List<MorphInterpretation> getAnalyzeResults() | |
| 108 | + { | |
| 109 | + return analyzeResults; | |
| 110 | + } | |
| 111 | + | |
| 112 | + public List<MorphInterpretation> getGenerateResults() | |
| 113 | + { | |
| 114 | + return generateResults; | |
| 115 | + } | |
| 116 | + | |
| 117 | + public boolean hasAnalyzeResults() | |
| 118 | + { | |
| 119 | + if (analyzeResults == null) return false; | |
| 120 | + return !analyzeResults.isEmpty(); | |
| 121 | + } | |
| 122 | + | |
| 123 | + public boolean hasGenerateResults() | |
| 124 | + { | |
| 125 | + if (generateResults == null) return false; | |
| 126 | + return !generateResults.isEmpty(); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public boolean analyze() | |
| 130 | + { | |
| 131 | + analyzeResults = null; | |
| 132 | + interpBoundaries = null; | |
| 133 | + try { | |
| 134 | + analyze(textToAnalyze); | |
| 135 | + } | |
| 136 | + catch (Exception exception) { | |
| 137 | + analyzeResults = null; | |
| 138 | + interpBoundaries = null; | |
| 139 | + return false; | |
| 140 | + } | |
| 141 | + return true; | |
| 142 | + } | |
| 143 | + | |
| 144 | + public void analyze(String text) | |
| 145 | + { | |
| 146 | + StringTokenizer tokenizer = new StringTokenizer(text, "\n"); | |
| 147 | + | |
| 148 | + while (tokenizer.hasMoreTokens()) { | |
| 149 | + String line = tokenizer.nextToken(); | |
| 150 | + List<MorphInterpretation> res = morfeusz.analyseAsList(line); | |
| 151 | + | |
| 152 | + if (analyzeResults == null) { | |
| 153 | + analyzeResults = res; | |
| 154 | + interpBoundaries = new HashSet<Integer>(); | |
| 155 | + } | |
| 156 | + else analyzeResults.addAll(res); | |
| 157 | + interpBoundaries.add(analyzeResults.size()); | |
| 158 | + } | |
| 159 | + } | |
| 160 | + | |
| 161 | + public boolean generate() | |
| 162 | + { | |
| 163 | + generateResults = null; | |
| 164 | + try { | |
| 165 | + generateResults = morfeusz.generate(lemma); | |
| 166 | + } | |
| 167 | + catch (Exception exception) { | |
| 168 | + generateResults = null; | |
| 169 | + return false; | |
| 170 | + } | |
| 171 | + return true; | |
| 172 | + } | |
| 173 | + | |
| 174 | + public boolean setDictionary(String name) | |
| 175 | + { | |
| 176 | + pl.sgjp.morfeusz.Morfeusz oldMorfeusz = morfeusz; | |
| 177 | + | |
| 178 | + try { | |
| 179 | + if (name == null) { | |
| 180 | + if (dictionary != null) { | |
| 181 | + morfeusz = pl.sgjp.morfeusz.Morfeusz.createInstance(MorfeuszUsage.BOTH_ANALYSE_AND_GENERATE); | |
| 182 | + initialize(); | |
| 183 | + } | |
| 184 | + } | |
| 185 | + else { | |
| 186 | + morfeusz = pl.sgjp.morfeusz.Morfeusz.createInstance(name, MorfeuszUsage.BOTH_ANALYSE_AND_GENERATE); | |
| 187 | + initialize(); | |
| 188 | + } | |
| 189 | + dictionary = name; | |
| 190 | + } | |
| 191 | + catch (Exception exception) { | |
| 192 | + morfeusz = oldMorfeusz; | |
| 193 | + return false; | |
| 194 | + } | |
| 195 | + return true; | |
| 196 | + } | |
| 197 | + | |
| 198 | + public void saveAnalyzeResults(PrintWriter pw) | |
| 199 | + { | |
| 200 | + if (hasAnalyzeResults()) { | |
| 201 | + for (int i = 0; i < analyzeResults.size(); i++) { | |
| 202 | + MorphInterpretation interp = analyzeResults.get(i); | |
| 203 | + | |
| 204 | + pw.print("["); | |
| 205 | + pw.print(Integer.toString(interp.getStartNode())); | |
| 206 | + pw.print(", "); | |
| 207 | + pw.print(Integer.toString(interp.getEndNode())); | |
| 208 | + pw.print(", "); | |
| 209 | + pw.print(interp.getOrth()); | |
| 210 | + pw.print(", "); | |
| 211 | + pw.print(interp.getLemma()); | |
| 212 | + pw.print(", "); | |
| 213 | + pw.print(interp.getTag(morfeusz)); | |
| 214 | + pw.print(", "); | |
| 215 | + pw.print(interp.getName(morfeusz)); | |
| 216 | + pw.print(", "); | |
| 217 | + | |
| 218 | + Collection<String> labels = interp.getLabels(controller.getMorfeusz()); | |
| 219 | + String str = null; | |
| 220 | + boolean append = false; | |
| 221 | + | |
| 222 | + if (labels.size() > 0) { | |
| 223 | + str = ""; | |
| 224 | + for (String s : labels) { | |
| 225 | + if (append) str += "; "; | |
| 226 | + str += s; | |
| 227 | + append = true; | |
| 228 | + } | |
| 229 | + } | |
| 230 | + | |
| 231 | + pw.print(str); | |
| 232 | + pw.println("]"); | |
| 233 | + } | |
| 234 | + } | |
| 235 | + } | |
| 236 | + | |
| 237 | + public void saveGenerateResults(PrintWriter pw) | |
| 238 | + { | |
| 239 | + if (hasAnalyzeResults()) { | |
| 240 | + for (int i = 0; i < generateResults.size(); i++) { | |
| 241 | + MorphInterpretation interp = generateResults.get(i); | |
| 242 | + | |
| 243 | + pw.print("["); | |
| 244 | + pw.print(interp.getOrth()); | |
| 245 | + pw.print(", "); | |
| 246 | + pw.print(interp.getLemma()); | |
| 247 | + pw.print(", "); | |
| 248 | + pw.print(interp.getTag(morfeusz)); | |
| 249 | + pw.print(", "); | |
| 250 | + pw.print(interp.getName(morfeusz)); | |
| 251 | + pw.print(", "); | |
| 252 | + pw.print(interp.getName(morfeusz)); | |
| 253 | + pw.print(", "); | |
| 254 | + | |
| 255 | + Collection<String> labels = interp.getLabels(controller.getMorfeusz()); | |
| 256 | + String str = null; | |
| 257 | + boolean append = false; | |
| 258 | + | |
| 259 | + if (labels.size() > 0) { | |
| 260 | + str = ""; | |
| 261 | + for (String s : labels) { | |
| 262 | + if (append) str += "; "; | |
| 263 | + str += s; | |
| 264 | + append = true; | |
| 265 | + } | |
| 266 | + } | |
| 267 | + | |
| 268 | + pw.print(str); | |
| 269 | + pw.println("]"); | |
| 270 | + } | |
| 271 | + } | |
| 272 | + } | |
| 273 | + | |
| 274 | + public pl.sgjp.morfeusz.Morfeusz getMorfeusz() | |
| 275 | + { | |
| 276 | + return morfeusz; | |
| 277 | + } | |
| 278 | + | |
| 279 | +} | |
| ... | ... |
gui/morfeusz/DictSearchPathsDialog.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.BorderLayout; | |
| 4 | +import java.awt.Color; | |
| 5 | +import java.awt.Dimension; | |
| 6 | +import java.awt.datatransfer.*; | |
| 7 | +import java.awt.event.*; | |
| 8 | +import java.io.*; | |
| 9 | +import java.util.*; | |
| 10 | + | |
| 11 | +import javax.swing.*; | |
| 12 | +import javax.swing.event.ListSelectionEvent; | |
| 13 | +import javax.swing.event.ListSelectionListener; | |
| 14 | +import javax.swing.table.*; | |
| 15 | + | |
| 16 | +@SuppressWarnings("serial") | |
| 17 | +public class DictSearchPathsDialog extends JPanel | |
| 18 | +{ | |
| 19 | + | |
| 20 | + private JDialog dialog; | |
| 21 | + private PathList pathList; | |
| 22 | + private JButton acceptButton; | |
| 23 | + private JButton cancelButton; | |
| 24 | + private JButton addButton; | |
| 25 | + private JButton removeButton; | |
| 26 | + private JButton defaultsButton; | |
| 27 | + private List<String> searchPaths; | |
| 28 | + private List<String> defaultSearchPaths; | |
| 29 | + private int ret; | |
| 30 | + | |
| 31 | + public DictSearchPathsDialog(List<String> searchPaths, List<String> defaultSearchPaths) | |
| 32 | + { | |
| 33 | + super(new BorderLayout()); | |
| 34 | + setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16)); | |
| 35 | + setPreferredSize(new Dimension(600, 200)); | |
| 36 | + this.searchPaths = searchPaths; | |
| 37 | + this.defaultSearchPaths = defaultSearchPaths; | |
| 38 | + arrangeComponents(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + public void arrangeComponents() | |
| 42 | + { | |
| 43 | + JLabel label = new JLabel("\u015Acie\u017Cka wyszukiwania s\u0142ownik\u00F3w:"); | |
| 44 | + Box hbox = Box.createHorizontalBox(); | |
| 45 | + JScrollPane sp; | |
| 46 | + Dimension dim; | |
| 47 | + | |
| 48 | + label.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); | |
| 49 | + add(label, BorderLayout.NORTH); | |
| 50 | + pathList = new PathList(); | |
| 51 | + sp = new JScrollPane(pathList); | |
| 52 | + sp.setBorder(BorderFactory.createEtchedBorder()); | |
| 53 | + sp.getViewport().setBackground(Color.white); | |
| 54 | + add(sp, BorderLayout.CENTER); | |
| 55 | + addButton = new JButton("Dodaj"); | |
| 56 | + removeButton = new JButton("Usu\u0144"); | |
| 57 | + defaultsButton = new JButton("Domy\u015Blna"); | |
| 58 | + cancelButton = new JButton("Anuluj"); | |
| 59 | + acceptButton = new JButton("Akceptuj"); | |
| 60 | + dim = defaultsButton.getPreferredSize(); | |
| 61 | + addButton.setPreferredSize(dim); | |
| 62 | + removeButton.setPreferredSize(dim); | |
| 63 | + cancelButton.setPreferredSize(dim); | |
| 64 | + acceptButton.setPreferredSize(dim); | |
| 65 | + hbox.setBorder(BorderFactory.createEmptyBorder(16, 0, 0, 0)); | |
| 66 | + hbox.add(addButton); | |
| 67 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 68 | + hbox.add(removeButton); | |
| 69 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 70 | + hbox.add(Box.createHorizontalGlue()); | |
| 71 | + hbox.add(defaultsButton); | |
| 72 | + hbox.add(Box.createHorizontalGlue()); | |
| 73 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 74 | + hbox.add(cancelButton); | |
| 75 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 76 | + hbox.add(acceptButton); | |
| 77 | + add(hbox, BorderLayout.SOUTH); | |
| 78 | + removeButton.setEnabled(false); | |
| 79 | + addButton.addActionListener(new ActionListener() { | |
| 80 | + public void actionPerformed(ActionEvent event) | |
| 81 | + { | |
| 82 | + addPath(); | |
| 83 | + } | |
| 84 | + }); | |
| 85 | + removeButton.addActionListener(new ActionListener() { | |
| 86 | + public void actionPerformed(ActionEvent event) | |
| 87 | + { | |
| 88 | + removePath(); | |
| 89 | + } | |
| 90 | + }); | |
| 91 | + defaultsButton.addActionListener(new ActionListener() { | |
| 92 | + public void actionPerformed(ActionEvent event) | |
| 93 | + { | |
| 94 | + defaults(); | |
| 95 | + } | |
| 96 | + }); | |
| 97 | + cancelButton.addActionListener(new ActionListener() { | |
| 98 | + public void actionPerformed(ActionEvent event) | |
| 99 | + { | |
| 100 | + dialog.setVisible(false); | |
| 101 | + } | |
| 102 | + }); | |
| 103 | + acceptButton.addActionListener(new ActionListener() { | |
| 104 | + public void actionPerformed(ActionEvent event) | |
| 105 | + { | |
| 106 | + modifySearchPaths(); | |
| 107 | + ret = 1; | |
| 108 | + dialog.setVisible(false); | |
| 109 | + } | |
| 110 | + }); | |
| 111 | + } | |
| 112 | + | |
| 113 | + public void addPath() | |
| 114 | + { | |
| 115 | + JFileChooser chooser = new JFileChooser(); | |
| 116 | + | |
| 117 | + chooser.setDialogTitle("Select Files"); | |
| 118 | + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | |
| 119 | + chooser.setMultiSelectionEnabled(true); | |
| 120 | + | |
| 121 | + int state = chooser.showOpenDialog(this); | |
| 122 | + if (state == JFileChooser.APPROVE_OPTION) { | |
| 123 | + File[] files = chooser.getSelectedFiles(); | |
| 124 | + DefaultTableModel model = (DefaultTableModel)pathList.getModel(); | |
| 125 | + Object[] row = new Object[1]; | |
| 126 | + | |
| 127 | + for (int i = 0; i < files.length; i++) { | |
| 128 | + row[0] = files[i].getPath(); | |
| 129 | + model.addRow(row); | |
| 130 | + } | |
| 131 | + } | |
| 132 | + } | |
| 133 | + | |
| 134 | + public void removePath() | |
| 135 | + { | |
| 136 | + int[] rows = pathList.getSelectedRows(); | |
| 137 | + DefaultTableModel model = (DefaultTableModel)pathList.getModel(); | |
| 138 | + | |
| 139 | + for (int i = 0; i < rows.length; i++) { | |
| 140 | + model.removeRow(rows[i] - i); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + public void defaults() | |
| 145 | + { | |
| 146 | + DefaultTableModel model = (DefaultTableModel)pathList.getModel(); | |
| 147 | + int count = model.getRowCount(); | |
| 148 | + | |
| 149 | + for (int i = 0; i < count; i++) { | |
| 150 | + model.removeRow(0); | |
| 151 | + } | |
| 152 | + if (defaultSearchPaths != null && !defaultSearchPaths.isEmpty()) { | |
| 153 | + Object[] row = new Object[1]; | |
| 154 | + | |
| 155 | + for (String path : defaultSearchPaths) { | |
| 156 | + row[0] = path; | |
| 157 | + model.addRow(row); | |
| 158 | + } | |
| 159 | + } | |
| 160 | + } | |
| 161 | + | |
| 162 | + public void modifySearchPaths() | |
| 163 | + { | |
| 164 | + DefaultTableModel model = (DefaultTableModel)pathList.getModel(); | |
| 165 | + int count = model.getRowCount(); | |
| 166 | + | |
| 167 | + searchPaths.clear(); | |
| 168 | + for (int i = 0; i < count; i++) { | |
| 169 | + String path = (String)model.getValueAt(i, 0); | |
| 170 | + | |
| 171 | + searchPaths.add(path); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + | |
| 175 | + public int doDialog() | |
| 176 | + { | |
| 177 | + ret = 0; | |
| 178 | + dialog = new JDialog(); | |
| 179 | + dialog.setModal(true); | |
| 180 | + dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); | |
| 181 | + dialog.setTitle("Ustawianie \u015Bcie\u017Cki wyszukiwania s\u0142ownik\u00F3w"); | |
| 182 | + dialog.setResizable(true); | |
| 183 | + dialog.getContentPane().add(this); | |
| 184 | + dialog.pack(); | |
| 185 | + dialog.setLocationRelativeTo(null); | |
| 186 | + dialog.setVisible(true); | |
| 187 | + return ret; | |
| 188 | + } | |
| 189 | + | |
| 190 | + public void dispose() | |
| 191 | + { | |
| 192 | + if (dialog != null) { | |
| 193 | + dialog.dispose(); | |
| 194 | + dialog = null; | |
| 195 | + } | |
| 196 | + } | |
| 197 | + | |
| 198 | + private class PathList extends JTable | |
| 199 | + { | |
| 200 | + | |
| 201 | + public PathList() | |
| 202 | + { | |
| 203 | + super(new PathListModel()); | |
| 204 | + | |
| 205 | + setBorder(BorderFactory.createEmptyBorder()); | |
| 206 | + setBackground(Color.white); | |
| 207 | + setTableHeader(null); | |
| 208 | + setRowSelectionAllowed(true); | |
| 209 | + setDragEnabled(true); | |
| 210 | + setShowHorizontalLines(false); | |
| 211 | + setShowVerticalLines(false); | |
| 212 | + setTransferHandler(new PathListTransferHandler()); | |
| 213 | + getSelectionModel().addListSelectionListener(new ListSelectionListener() { | |
| 214 | + public void valueChanged(ListSelectionEvent event) | |
| 215 | + { | |
| 216 | + removeButton.setEnabled(getSelectedRowCount() > 0); | |
| 217 | + } | |
| 218 | + }); | |
| 219 | + | |
| 220 | + DefaultTableModel model = (DefaultTableModel)getModel(); | |
| 221 | + Object[] row = new Object[1]; | |
| 222 | + | |
| 223 | + for (String path : searchPaths) { | |
| 224 | + row[0] = path; | |
| 225 | + model.addRow(row); | |
| 226 | + } | |
| 227 | + } | |
| 228 | + | |
| 229 | + } | |
| 230 | + | |
| 231 | + private class PathListModel extends DefaultTableModel | |
| 232 | + { | |
| 233 | + | |
| 234 | + public PathListModel() | |
| 235 | + { | |
| 236 | + super(0, 1); | |
| 237 | + } | |
| 238 | + | |
| 239 | + public Class<? extends Object> getColumnClass(int col) | |
| 240 | + { | |
| 241 | + Vector<?> v = (Vector<?>)getDataVector().elementAt(0); | |
| 242 | + return v.elementAt(col).getClass(); | |
| 243 | + } | |
| 244 | + | |
| 245 | + public boolean isCellEditable(int row, int column) | |
| 246 | + { | |
| 247 | + return false; | |
| 248 | + } | |
| 249 | + | |
| 250 | + } | |
| 251 | + | |
| 252 | + private class PathListTransferHandler extends TransferHandler | |
| 253 | + { | |
| 254 | + | |
| 255 | + private boolean canImport; | |
| 256 | + private boolean accept; | |
| 257 | + private int[] rows; | |
| 258 | + private int addIndex; | |
| 259 | + private int addCount; | |
| 260 | + | |
| 261 | + public PathListTransferHandler() | |
| 262 | + { | |
| 263 | + canImport = false; | |
| 264 | + accept = false; | |
| 265 | + rows = null; | |
| 266 | + addIndex = -1; | |
| 267 | + addCount = 0; | |
| 268 | + } | |
| 269 | + | |
| 270 | + protected Transferable createTransferable(JComponent c) | |
| 271 | + { | |
| 272 | + accept = true; | |
| 273 | + return new StringSelection(exportString(c)); | |
| 274 | + } | |
| 275 | + | |
| 276 | + protected String exportString(JComponent c) | |
| 277 | + { | |
| 278 | + JTable table = (JTable)c; | |
| 279 | + StringBuffer buff = new StringBuffer(); | |
| 280 | + | |
| 281 | + rows = table.getSelectedRows(); | |
| 282 | + for (int i = 0; i < rows.length; i++) { | |
| 283 | + String s = (String)table.getValueAt(rows[i], 0); | |
| 284 | + buff.append(s); | |
| 285 | + if (i != rows.length - 1) buff.append("\n"); | |
| 286 | + } | |
| 287 | + return buff.toString(); | |
| 288 | + } | |
| 289 | + | |
| 290 | + protected void importString(JComponent c, String str) | |
| 291 | + { | |
| 292 | + JTable target = (JTable)c; | |
| 293 | + DefaultTableModel model = (DefaultTableModel)target.getModel(); | |
| 294 | + int index = target.getSelectedRow(); | |
| 295 | + | |
| 296 | + if (rows != null && index >= rows[0] - 1 && | |
| 297 | + index <= rows[rows.length - 1]) | |
| 298 | + { | |
| 299 | + rows = null; | |
| 300 | + return; | |
| 301 | + } | |
| 302 | + | |
| 303 | + int max = model.getRowCount(); | |
| 304 | + | |
| 305 | + if (index < 0) index = max; | |
| 306 | + else { | |
| 307 | + index++; | |
| 308 | + if (index > max) index = max; | |
| 309 | + } | |
| 310 | + | |
| 311 | + addIndex = index; | |
| 312 | + String[] rvalues = str.split("\n"); | |
| 313 | + addCount = rvalues.length; | |
| 314 | + | |
| 315 | + for (int i = 0; i < rvalues.length; i++) { | |
| 316 | + Object[] row = new Object[1]; | |
| 317 | + | |
| 318 | + row[0] = rvalues[i]; | |
| 319 | + model.insertRow(index++, row); | |
| 320 | + } | |
| 321 | + } | |
| 322 | + | |
| 323 | + public int getSourceActions(JComponent c) | |
| 324 | + { | |
| 325 | + return COPY_OR_MOVE; | |
| 326 | + } | |
| 327 | + | |
| 328 | + public boolean importData(JComponent c, Transferable t) | |
| 329 | + { | |
| 330 | + if (canImport(c, t.getTransferDataFlavors())) { | |
| 331 | + canImport = true; | |
| 332 | + try { | |
| 333 | + String str = (String)t.getTransferData(DataFlavor.stringFlavor); | |
| 334 | + importString(c, str); | |
| 335 | + return true; | |
| 336 | + } | |
| 337 | + catch (UnsupportedFlavorException ufe) { | |
| 338 | + } | |
| 339 | + catch (IOException ioe) { | |
| 340 | + } | |
| 341 | + } | |
| 342 | + return false; | |
| 343 | + } | |
| 344 | + | |
| 345 | + protected void exportDone(JComponent c, Transferable data, int action) | |
| 346 | + { | |
| 347 | + if (canImport) { | |
| 348 | + JTable source = (JTable)c; | |
| 349 | + | |
| 350 | + if (rows != null) { | |
| 351 | + DefaultTableModel model = (DefaultTableModel)source.getModel(); | |
| 352 | + | |
| 353 | + if (addCount > 0) { | |
| 354 | + for (int i = 0; i < rows.length; i++) { | |
| 355 | + if (rows[i] > addIndex) rows[i] += addCount; | |
| 356 | + } | |
| 357 | + } | |
| 358 | + for (int i = rows.length - 1; i >= 0; i--) model.removeRow(rows[i]); | |
| 359 | + } | |
| 360 | + rows = null; | |
| 361 | + addCount = 0; | |
| 362 | + addIndex = -1; | |
| 363 | + canImport = false; | |
| 364 | + } | |
| 365 | + accept = false; | |
| 366 | + } | |
| 367 | + | |
| 368 | + public boolean canImport(JComponent c, DataFlavor[] flavors) | |
| 369 | + { | |
| 370 | + if (accept) { | |
| 371 | + for (int i = 0; i < flavors.length; i++) { | |
| 372 | + if (DataFlavor.stringFlavor.equals(flavors[i])) return true; | |
| 373 | + } | |
| 374 | + } | |
| 375 | + return false; | |
| 376 | + } | |
| 377 | + | |
| 378 | + } | |
| 379 | + | |
| 380 | +} | |
| ... | ... |
gui/morfeusz/Morfeusz.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.event.*; | |
| 5 | +import java.io.*; | |
| 6 | +import java.text.*; | |
| 7 | +import java.util.*; | |
| 8 | + | |
| 9 | +import javax.swing.*; | |
| 10 | +import javax.swing.event.*; | |
| 11 | + | |
| 12 | +import quitaboutpreferenceshandler.*; | |
| 13 | + | |
| 14 | +@SuppressWarnings("serial") | |
| 15 | +public class Morfeusz extends JFrame | |
| 16 | +{ | |
| 17 | + | |
| 18 | + public static final String WINDOW_TITLE = "Analizator Morfologiczny Morfeusz"; | |
| 19 | + public static final String STANDARD = "Standardowy (" + pl.sgjp.morfeusz.Morfeusz.getDefaultDictName() + ")"; | |
| 20 | + public static final String DICT_MESSAGE = "<html>Wyst\u0105pi\u0142 b\u0142\u0105d przy pr\u00F3bie zamiany s\u0142ownika.<br/>" + | |
| 21 | + "S\u0142ownik nie zosta\u0142 zmieniony.</html>"; | |
| 22 | + public static final String NATIVE_ERROR_MESSAGE = "Wyst\u0105pi\u0142 nieznany b\u0142\u0105d"; | |
| 23 | + public static final Color LIGHT_GRAY = new Color(240, 240, 240); | |
| 24 | + public static final Color VLIGHT_BLUE = new Color(237, 243, 254); | |
| 25 | + public static final Font FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 10); | |
| 26 | + public static final int NUM_OF_FONT_SIZES = 10; | |
| 27 | + | |
| 28 | + private static boolean isMacOS; | |
| 29 | + | |
| 30 | + public static Font plainFont; | |
| 31 | + public static Font boldFont; | |
| 32 | + public static Font italicFont; | |
| 33 | + private java.util.List<String> defaultSearchPaths; | |
| 34 | + private java.util.List<String> dictSearchPaths; | |
| 35 | + private java.util.List<String> dictionaries; | |
| 36 | + private Agent agent; | |
| 37 | + private Preferences preferences; | |
| 38 | + private JTabbedPane tabbedPane; | |
| 39 | + private AnalyzeView analyzeView; | |
| 40 | + private GenerateView generateView; | |
| 41 | + private JTextArea textPane; | |
| 42 | + private JTextField lemmaField; | |
| 43 | + private ResultsPane analyzePane; | |
| 44 | + private ResultsPane generatePane; | |
| 45 | + private Action exitAction; | |
| 46 | + private Action aboutAction; | |
| 47 | + private Action optionsAction; | |
| 48 | + private Action resetAction; | |
| 49 | + private Action analyzeAction; | |
| 50 | + private Action generateAction; | |
| 51 | + private Action openAction; | |
| 52 | + private Action saveActionA; | |
| 53 | + private Action saveActionG; | |
| 54 | + private Action changeAction; | |
| 55 | + private Action changeToStandardAction; | |
| 56 | + private Action editAction; | |
| 57 | + private Action increaseFontAction; | |
| 58 | + private Action decreaseFontAction; | |
| 59 | + private Action insertNewLineAction; | |
| 60 | + private JButton exitButton; | |
| 61 | + private JButton resetButton; | |
| 62 | + private JButton actionButton; | |
| 63 | + private ToolBarButton returnButton; | |
| 64 | + private ToolBarButton openButton; | |
| 65 | + private ToolBarButton saveButtonA; | |
| 66 | + private ToolBarButton saveButtonG; | |
| 67 | + private ToolBarButton changeButtonA; | |
| 68 | + private ToolBarButton changeButtonG; | |
| 69 | + private ToolBarButton aboutButton; | |
| 70 | + private ToolBarButton optionsButton; | |
| 71 | + private ToolBarButton increaseFontButton; | |
| 72 | + private ToolBarButton decreaseFontButton; | |
| 73 | + private JCheckBox appendCheckBoxA; | |
| 74 | + private JCheckBox appendCheckBoxG; | |
| 75 | + private JPopupMenu changePopup; | |
| 76 | + private JLabel analyzeDictionaryName; | |
| 77 | + private JLabel generateDictionaryName; | |
| 78 | + private File inputFile; | |
| 79 | + private File outputFile; | |
| 80 | + private DictFilter filter; | |
| 81 | + private String dictionary; | |
| 82 | + private boolean analyze; | |
| 83 | + private Rectangle topLeft = new Rectangle(0, 0, 0, 0); | |
| 84 | + | |
| 85 | + public Morfeusz() | |
| 86 | + { | |
| 87 | + String str = System.getProperty("os.name"); | |
| 88 | + | |
| 89 | + if (str != null && str.contains("Mac OS X")) { | |
| 90 | + new QuitAboutPreferencesHandler() { | |
| 91 | + public void handleQuitRequest() | |
| 92 | + { | |
| 93 | + exit(); | |
| 94 | + } | |
| 95 | + | |
| 96 | + public void handleAboutRequest() | |
| 97 | + { | |
| 98 | + about(); | |
| 99 | + } | |
| 100 | + | |
| 101 | + public void handlePreferencesRequest() | |
| 102 | + { | |
| 103 | + options(); | |
| 104 | + } | |
| 105 | + }; | |
| 106 | + System.setProperty("apple.laf.useScreenMenuBar", "true"); | |
| 107 | + isMacOS = true; | |
| 108 | + } | |
| 109 | + else isMacOS = false; | |
| 110 | + | |
| 111 | + readPreferences(); | |
| 112 | + plainFont = FONT.deriveFont(Font.PLAIN, preferences.fontSize + 10); | |
| 113 | + boldFont = FONT.deriveFont(Font.BOLD, preferences.fontSize + 10); | |
| 114 | + italicFont = FONT.deriveFont(Font.ITALIC, preferences.fontSize + 10); | |
| 115 | + initialize(); | |
| 116 | + agent = Agent.createAgent(this); | |
| 117 | + if (agent == null) { | |
| 118 | + JOptionPane.showMessageDialog(null, NATIVE_ERROR_MESSAGE, "Uwaga", JOptionPane.ERROR_MESSAGE); | |
| 119 | + exit(); | |
| 120 | + } | |
| 121 | + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); | |
| 122 | + setTitle(WINDOW_TITLE); | |
| 123 | + setSizeAndPosition(); | |
| 124 | + arrangeComponents(); | |
| 125 | + getRootPane().setDefaultButton(actionButton); | |
| 126 | + checkComponents(); | |
| 127 | + addWindowListener(new WindowAdapter() | |
| 128 | + { | |
| 129 | + public void windowClosing(WindowEvent event) | |
| 130 | + { | |
| 131 | + exit(); | |
| 132 | + } | |
| 133 | + }); | |
| 134 | + } | |
| 135 | + | |
| 136 | + public void initialize() | |
| 137 | + { | |
| 138 | + openAction = new AbstractAction("Czytaj z pliku") { | |
| 139 | + public void actionPerformed(ActionEvent e) | |
| 140 | + { | |
| 141 | + open(); | |
| 142 | + } | |
| 143 | + }; | |
| 144 | + | |
| 145 | + optionsAction = new AbstractAction("Opcje programu") { | |
| 146 | + public void actionPerformed(ActionEvent e) | |
| 147 | + { | |
| 148 | + options(); | |
| 149 | + } | |
| 150 | + }; | |
| 151 | + | |
| 152 | + saveActionA = new AbstractAction("Zapisz Wyniki Analizy") { | |
| 153 | + public void actionPerformed(ActionEvent e) | |
| 154 | + { | |
| 155 | + save(); | |
| 156 | + } | |
| 157 | + }; | |
| 158 | + | |
| 159 | + saveActionG = new AbstractAction("Zapisz Wygenerowane Formy") { | |
| 160 | + public void actionPerformed(ActionEvent e) | |
| 161 | + { | |
| 162 | + save(); | |
| 163 | + } | |
| 164 | + }; | |
| 165 | + | |
| 166 | + changeToStandardAction = new AbstractAction("S\u0142ownik Standardowy") { | |
| 167 | + public void actionPerformed(ActionEvent e) | |
| 168 | + { | |
| 169 | + changeToStandardDictionary(); | |
| 170 | + } | |
| 171 | + }; | |
| 172 | + | |
| 173 | + changeAction = new AbstractAction() { | |
| 174 | + public void actionPerformed(ActionEvent e) | |
| 175 | + { | |
| 176 | + changeDictionary(); | |
| 177 | + } | |
| 178 | + }; | |
| 179 | + | |
| 180 | + editAction = new AbstractAction("Ustaw \u015Acie\u017Ck\u0119 Wyszukiwania S\u0142ownik\u00F3w...") { | |
| 181 | + public void actionPerformed(ActionEvent e) | |
| 182 | + { | |
| 183 | + editDictSearchPaths(); | |
| 184 | + } | |
| 185 | + }; | |
| 186 | + | |
| 187 | + exitAction = new AbstractAction("Zako\u0144cz") { | |
| 188 | + public void actionPerformed(ActionEvent e) | |
| 189 | + { | |
| 190 | + exit(); | |
| 191 | + } | |
| 192 | + }; | |
| 193 | + | |
| 194 | + aboutAction = new AbstractAction("About") { | |
| 195 | + public void actionPerformed(ActionEvent e) | |
| 196 | + { | |
| 197 | + about(); | |
| 198 | + } | |
| 199 | + }; | |
| 200 | + | |
| 201 | + increaseFontAction = new AbstractAction("Powi\u0119ksz czcionk\u0119") { | |
| 202 | + public void actionPerformed(ActionEvent e) | |
| 203 | + { | |
| 204 | + changeFontSize(true); | |
| 205 | + } | |
| 206 | + }; | |
| 207 | + | |
| 208 | + decreaseFontAction = new AbstractAction("Zmniejsz czcionk\u0119") { | |
| 209 | + public void actionPerformed(ActionEvent e) | |
| 210 | + { | |
| 211 | + changeFontSize(false); | |
| 212 | + } | |
| 213 | + }; | |
| 214 | + | |
| 215 | + resetAction = new AbstractAction("Wyczy\u015B\u0107") { | |
| 216 | + public void actionPerformed(ActionEvent e) | |
| 217 | + { | |
| 218 | + reset(); | |
| 219 | + } | |
| 220 | + }; | |
| 221 | + | |
| 222 | + analyzeAction = new AbstractAction("Analizuj") { | |
| 223 | + public void actionPerformed(ActionEvent e) | |
| 224 | + { | |
| 225 | + analyze(); | |
| 226 | + } | |
| 227 | + }; | |
| 228 | + | |
| 229 | + generateAction = new AbstractAction("Generuj") { | |
| 230 | + public void actionPerformed(ActionEvent e) | |
| 231 | + { | |
| 232 | + generate(); | |
| 233 | + } | |
| 234 | + }; | |
| 235 | + | |
| 236 | + insertNewLineAction = new AbstractAction() { | |
| 237 | + public void actionPerformed(ActionEvent e) | |
| 238 | + { | |
| 239 | + insertNewLine(); | |
| 240 | + } | |
| 241 | + }; | |
| 242 | + | |
| 243 | + filter = new DictFilter(); | |
| 244 | + dictSearchPaths = pl.sgjp.morfeusz.Morfeusz.getDictionarySearchPaths(); | |
| 245 | + defaultSearchPaths = new LinkedList<String>(); | |
| 246 | + for (String path : dictSearchPaths) defaultSearchPaths.add(path); | |
| 247 | + | |
| 248 | + if (preferences.dictPaths != null) { | |
| 249 | + dictSearchPaths.clear(); | |
| 250 | + for (String path : preferences.dictPaths) { | |
| 251 | + dictSearchPaths.add(path); | |
| 252 | + } | |
| 253 | + } | |
| 254 | + else if (dictSearchPaths.size() > 0) { | |
| 255 | + int i = 0; | |
| 256 | + | |
| 257 | + preferences.dictPaths = new String[dictSearchPaths.size()]; | |
| 258 | + for (String path : dictSearchPaths) { | |
| 259 | + preferences.dictPaths[i++] = path; | |
| 260 | + } | |
| 261 | + } | |
| 262 | + getDictionaries(); | |
| 263 | + if (preferences.dictionary == null) dictionary = STANDARD; | |
| 264 | + else dictionary = preferences.dictionary; | |
| 265 | + if (!dictionaries.contains(dictionary)) dictionary = STANDARD; | |
| 266 | + analyze = true; | |
| 267 | + } | |
| 268 | + | |
| 269 | + public void getDictionaries() | |
| 270 | + { | |
| 271 | + ListIterator<String> it; | |
| 272 | + | |
| 273 | + dictionaries = new LinkedList<String>(); | |
| 274 | + if (dictSearchPaths.size() > 0) { | |
| 275 | + it = dictSearchPaths.listIterator(); | |
| 276 | + while (it.hasNext()) { | |
| 277 | + String path = it.next(); | |
| 278 | + File dir = new File(path); | |
| 279 | + | |
| 280 | + if (dir.exists()) addDictionaries(dir); | |
| 281 | + } | |
| 282 | + } | |
| 283 | + else { | |
| 284 | + File currentDir = new File(System.getProperty("user.dir")); | |
| 285 | + | |
| 286 | + addDictionaries(currentDir); | |
| 287 | + } | |
| 288 | + changePopup = new JPopupMenu(); | |
| 289 | + changePopup.add(changeToStandardAction); | |
| 290 | + changePopup.addSeparator(); | |
| 291 | + if (!dictionaries.isEmpty()) { | |
| 292 | + for (String d : dictionaries) { | |
| 293 | + changePopup.add(new RecentFileAction(d, this)); | |
| 294 | + } | |
| 295 | + changePopup.addSeparator(); | |
| 296 | + } | |
| 297 | + changePopup.add(editAction); | |
| 298 | + } | |
| 299 | + | |
| 300 | + public void addDictionaries(File dir) | |
| 301 | + { | |
| 302 | + String[] d = dir.list(filter); | |
| 303 | + | |
| 304 | + for (String str : d) { | |
| 305 | + int index = str.lastIndexOf("-"); | |
| 306 | + | |
| 307 | + str = str.substring(0, index); | |
| 308 | + if (!dictionaries.contains(str)) dictionaries.add(str); | |
| 309 | + } | |
| 310 | + } | |
| 311 | + | |
| 312 | + public void setSizeAndPosition() | |
| 313 | + { | |
| 314 | + Toolkit toolkit = Toolkit.getDefaultToolkit(); | |
| 315 | + Dimension dim = toolkit.getScreenSize(); | |
| 316 | + GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); | |
| 317 | + GraphicsConfiguration conf = dev.getDefaultConfiguration(); | |
| 318 | + Insets insets = toolkit.getScreenInsets(conf); | |
| 319 | + Rectangle rect = new Rectangle(); | |
| 320 | + | |
| 321 | + rect.x = (dim.width - insets.left - insets.right) / 4; | |
| 322 | + rect.y = (dim.height - insets.top - insets.bottom) / 8; | |
| 323 | + rect.width = 2 * rect.x; | |
| 324 | + rect.height = 6 * rect.y; | |
| 325 | + | |
| 326 | + setBounds(rect); | |
| 327 | + } | |
| 328 | + | |
| 329 | + public void arrangeComponents() | |
| 330 | + { | |
| 331 | + JPanel mainView = new JPanel(new BorderLayout()); | |
| 332 | + Box hbox, vbox; | |
| 333 | + | |
| 334 | + mainView.setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16)); | |
| 335 | + tabbedPane = new JTabbedPane(); | |
| 336 | + analyzeView = new AnalyzeView(); | |
| 337 | + generateView = new GenerateView(); | |
| 338 | + tabbedPane.setFocusable(false); | |
| 339 | + tabbedPane.addTab("Analizator", analyzeView); | |
| 340 | + tabbedPane.addTab("Generator", generateView); | |
| 341 | + mainView.add(tabbedPane, BorderLayout.CENTER); | |
| 342 | + | |
| 343 | + exitButton = new JButton(exitAction); | |
| 344 | + resetButton = new JButton(resetAction); | |
| 345 | + actionButton = new JButton(analyzeAction); | |
| 346 | + aboutButton = new ToolBarButton(aboutAction, "info"); | |
| 347 | + aboutButton.setToolTipText("Informacje o programie."); | |
| 348 | + optionsButton = new ToolBarButton(optionsAction, "conf"); | |
| 349 | + optionsButton.setToolTipText("Parametry programu."); | |
| 350 | + increaseFontButton = new ToolBarButton(increaseFontAction, "font_increase"); | |
| 351 | + increaseFontButton.setToolTipText("Powi\u0119ksz czcionk\u0119."); | |
| 352 | + decreaseFontButton = new ToolBarButton(decreaseFontAction, "font_decrease"); | |
| 353 | + decreaseFontButton.setToolTipText("Zmniejsz czcionk\u0119."); | |
| 354 | + increaseFontButton.setEnabled(preferences.fontSize < NUM_OF_FONT_SIZES - 1); | |
| 355 | + decreaseFontButton.setEnabled(preferences.fontSize > 0); | |
| 356 | + | |
| 357 | + vbox = Box.createVerticalBox(); | |
| 358 | + if (!isMacOS) vbox.add(Box.createVerticalStrut(16)); | |
| 359 | + hbox = Box.createHorizontalBox(); | |
| 360 | + hbox.add(aboutButton); | |
| 361 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 362 | + hbox.add(optionsButton); | |
| 363 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 364 | + hbox.add(increaseFontButton); | |
| 365 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 366 | + hbox.add(decreaseFontButton); | |
| 367 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 368 | + hbox.add(exitButton); | |
| 369 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 370 | + hbox.add(resetButton); | |
| 371 | + hbox.add(Box.createHorizontalGlue()); | |
| 372 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 373 | + hbox.add(actionButton); | |
| 374 | + vbox.add(hbox); | |
| 375 | + mainView.add(vbox, BorderLayout.SOUTH); | |
| 376 | + getContentPane().add(mainView); | |
| 377 | + | |
| 378 | + tabbedPane.addChangeListener(new ChangeListener() { | |
| 379 | + public void stateChanged(ChangeEvent e) | |
| 380 | + { | |
| 381 | + int i = tabbedPane.getSelectedIndex(); | |
| 382 | + | |
| 383 | + if (i == 0) { | |
| 384 | + actionButton.setAction(analyzeAction); | |
| 385 | + analyze = true; | |
| 386 | + } | |
| 387 | + else { | |
| 388 | + actionButton.setAction(generateAction); | |
| 389 | + analyze = false; | |
| 390 | + } | |
| 391 | + checkComponents(); | |
| 392 | + } | |
| 393 | + }); | |
| 394 | + } | |
| 395 | + | |
| 396 | + public void open() | |
| 397 | + { | |
| 398 | + SelectFileDialog dialog = new SelectFileDialog(this, SelectFileDialog.LOAD); | |
| 399 | + | |
| 400 | + dialog.setVisible(true); | |
| 401 | + if (dialog.accept()) { | |
| 402 | + inputFile = dialog.getSelectedFile(); | |
| 403 | + readText(inputFile, dialog.getEncoding()); | |
| 404 | + } | |
| 405 | + dialog.dispose(); | |
| 406 | + } | |
| 407 | + | |
| 408 | + public void readText(File file, String encoding) | |
| 409 | + { | |
| 410 | + try { | |
| 411 | + BufferedReader reader = | |
| 412 | + new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding)); | |
| 413 | + String line; | |
| 414 | + boolean addNewLine = false; | |
| 415 | + | |
| 416 | + textPane.setText(""); | |
| 417 | + while ((line = reader.readLine()) != null) { | |
| 418 | + if (addNewLine) textPane.append("\n"); | |
| 419 | + textPane.append(Normalizer.normalize(line, Normalizer.Form.NFC)); | |
| 420 | + addNewLine = true; | |
| 421 | + } | |
| 422 | + reader.close(); | |
| 423 | + EventQueue.invokeLater(new Runnable() { | |
| 424 | + public void run() | |
| 425 | + { | |
| 426 | + textPane.scrollRectToVisible(topLeft); | |
| 427 | + } | |
| 428 | + }); | |
| 429 | + } | |
| 430 | + catch (Exception exception) { | |
| 431 | + exception.getStackTrace(); | |
| 432 | + } | |
| 433 | + } | |
| 434 | + | |
| 435 | + public void save() | |
| 436 | + { | |
| 437 | + boolean select = true; | |
| 438 | + boolean append = (analyze ? appendCheckBoxA.isSelected() : appendCheckBoxG.isSelected()); | |
| 439 | + | |
| 440 | + if (append) { | |
| 441 | + if (outputFile != null && outputFile.exists()) select = false; | |
| 442 | + } | |
| 443 | + if (select) { | |
| 444 | + SelectFileDialog dialog = new SelectFileDialog(this, SelectFileDialog.SAVE); | |
| 445 | + | |
| 446 | + dialog.setSelectedFile(new File("Results.txt")); | |
| 447 | + dialog.setVisible(true); | |
| 448 | + if (dialog.accept()) { | |
| 449 | + outputFile = dialog.getSelectedFile(); | |
| 450 | + save(outputFile, append); | |
| 451 | + appendCheckBoxA.setSelected(true); | |
| 452 | + } | |
| 453 | + } | |
| 454 | + else { | |
| 455 | + save(outputFile, append); | |
| 456 | + } | |
| 457 | + } | |
| 458 | + | |
| 459 | + public void save(File file, boolean append) | |
| 460 | + { | |
| 461 | + try { | |
| 462 | + OutputStreamWriter writer = new OutputStreamWriter( | |
| 463 | + new FileOutputStream(file, append), "UTF8"); | |
| 464 | + BufferedWriter bw = new BufferedWriter(writer); | |
| 465 | + PrintWriter pw = new PrintWriter(bw); | |
| 466 | + | |
| 467 | + if (append) pw.println(); | |
| 468 | + if (analyze) agent.saveAnalyzeResults(pw); | |
| 469 | + else agent.saveGenerateResults(pw); | |
| 470 | + pw.flush(); | |
| 471 | + pw.close(); | |
| 472 | + } | |
| 473 | + catch (Exception exception) { | |
| 474 | + exception.getStackTrace(); | |
| 475 | + } | |
| 476 | + } | |
| 477 | + | |
| 478 | + public void changeDictionaryName(String name) | |
| 479 | + { | |
| 480 | + dictionary = name; | |
| 481 | + if (name.equals(STANDARD)) { | |
| 482 | + analyzeDictionaryName.setText(name); | |
| 483 | + analyzeDictionaryName.setForeground(Color.gray); | |
| 484 | + generateDictionaryName.setText(name); | |
| 485 | + generateDictionaryName.setForeground(Color.gray); | |
| 486 | + } | |
| 487 | + else { | |
| 488 | + analyzeDictionaryName.setText(name); | |
| 489 | + analyzeDictionaryName.setForeground(Color.black); | |
| 490 | + generateDictionaryName.setText(name); | |
| 491 | + generateDictionaryName.setForeground(Color.black); | |
| 492 | + } | |
| 493 | + } | |
| 494 | + | |
| 495 | + public void changeToStandardDictionary() | |
| 496 | + { | |
| 497 | + preferences.dictionary = null; | |
| 498 | + agent.setDictionary(null); | |
| 499 | + refreshAnalyzeResults(); | |
| 500 | + refreshGenerateResults(); | |
| 501 | + changeDictionaryName(STANDARD); | |
| 502 | + } | |
| 503 | + | |
| 504 | + public void changeDictionary() | |
| 505 | + { | |
| 506 | + if (analyze) changePopup.show(changeButtonA, 0, 0); | |
| 507 | + else changePopup.show(changeButtonG, 0, 0); | |
| 508 | + } | |
| 509 | + | |
| 510 | + public void changeDictionary(String name) | |
| 511 | + { | |
| 512 | + if (agent.setDictionary(name)) { | |
| 513 | + preferences.dictionary = name; | |
| 514 | + changeDictionaryName(name); | |
| 515 | + refreshAnalyzeResults(); | |
| 516 | + refreshGenerateResults(); | |
| 517 | + } | |
| 518 | + else { | |
| 519 | + JOptionPane.showMessageDialog(null, DICT_MESSAGE, "Uwaga", JOptionPane.ERROR_MESSAGE); | |
| 520 | + removeFromChangePopup(name); | |
| 521 | + } | |
| 522 | + } | |
| 523 | + | |
| 524 | + public void removeFromChangePopup(String name) | |
| 525 | + { | |
| 526 | + JMenuItem item = null; | |
| 527 | + int count = changePopup.getComponentCount() - 2; | |
| 528 | + | |
| 529 | + for (int i = 2; i < count; i++) { | |
| 530 | + JMenuItem menuItem = (JMenuItem)changePopup.getComponent(i); | |
| 531 | + RecentFileAction action = (RecentFileAction)menuItem.getAction(); | |
| 532 | + | |
| 533 | + if (action.getName().equals(name)) { | |
| 534 | + item = menuItem; | |
| 535 | + break; | |
| 536 | + } | |
| 537 | + } | |
| 538 | + if (item != null) { | |
| 539 | + changePopup.remove(item); | |
| 540 | + if (count == 3) changePopup.remove(2); | |
| 541 | + } | |
| 542 | + } | |
| 543 | + | |
| 544 | + public void exit() | |
| 545 | + { | |
| 546 | + savePreferences(); | |
| 547 | + System.exit(0); | |
| 548 | + } | |
| 549 | + | |
| 550 | + public void insertNewLine() | |
| 551 | + { | |
| 552 | + textPane.insert("\n", textPane.getCaretPosition()); | |
| 553 | + } | |
| 554 | + | |
| 555 | + public void options() | |
| 556 | + { | |
| 557 | + OptionsDialog dialog = new OptionsDialog(this); | |
| 558 | + | |
| 559 | + if (dialog.doDialog() != 0) { | |
| 560 | + dialog.transfer(preferences); | |
| 561 | + agent.initialize(); | |
| 562 | + refreshAnalyzeResults(); | |
| 563 | + refreshGenerateResults(); | |
| 564 | + } | |
| 565 | + dialog.dispose(); | |
| 566 | + } | |
| 567 | + | |
| 568 | + public void editDictSearchPaths() | |
| 569 | + { | |
| 570 | + DictSearchPathsDialog dialog = new DictSearchPathsDialog(dictSearchPaths, defaultSearchPaths); | |
| 571 | + | |
| 572 | + if (dialog.doDialog() != 0) { | |
| 573 | + getDictionaries(); | |
| 574 | + preferences.dictPaths = null; | |
| 575 | + if (dictSearchPaths.size() > 0) { | |
| 576 | + int i = 0; | |
| 577 | + | |
| 578 | + preferences.dictPaths = new String[dictSearchPaths.size()]; | |
| 579 | + for (String path : dictSearchPaths) { | |
| 580 | + preferences.dictPaths[i++] = path; | |
| 581 | + } | |
| 582 | + } | |
| 583 | + } | |
| 584 | + dialog.dispose(); | |
| 585 | + } | |
| 586 | + | |
| 587 | + public void readPreferences() | |
| 588 | + { | |
| 589 | + String path = System.getProperty("user.home") + File.separator + ".morfeuszGUI"; | |
| 590 | + File file = new File(path); | |
| 591 | + ObjectInputStream input; | |
| 592 | + | |
| 593 | + try { | |
| 594 | + input = new ObjectInputStream(new FileInputStream(file)); | |
| 595 | + preferences = (Preferences)input.readObject(); | |
| 596 | + input.close(); | |
| 597 | + } | |
| 598 | + catch (Exception exception) { | |
| 599 | + preferences = new Preferences(); | |
| 600 | + preferences.setDefaults(); | |
| 601 | + } | |
| 602 | + } | |
| 603 | + | |
| 604 | + public void savePreferences() | |
| 605 | + { | |
| 606 | + String path = System.getProperty("user.home") + File.separator + ".morfeuszGUI"; | |
| 607 | + File file = new File(path); | |
| 608 | + ObjectOutputStream output; | |
| 609 | + | |
| 610 | + try { | |
| 611 | + output = new ObjectOutputStream(new FileOutputStream(file)); | |
| 612 | + output.writeObject(preferences); | |
| 613 | + output.close(); | |
| 614 | + } | |
| 615 | + catch (Exception exception) { | |
| 616 | + } | |
| 617 | + } | |
| 618 | + | |
| 619 | + public Preferences getPreferences() | |
| 620 | + { | |
| 621 | + return preferences; | |
| 622 | + } | |
| 623 | + | |
| 624 | + public void about() | |
| 625 | + { | |
| 626 | + AboutDialog dialog = new AboutDialog(agent.getMorfeusz()); | |
| 627 | + | |
| 628 | + dialog.doDialog(); | |
| 629 | + } | |
| 630 | + | |
| 631 | + public void changeFontSize(boolean increase) | |
| 632 | + { | |
| 633 | + if (increase) preferences.fontSize++; | |
| 634 | + else preferences.fontSize--; | |
| 635 | + increaseFontButton.setEnabled(preferences.fontSize < NUM_OF_FONT_SIZES - 1); | |
| 636 | + decreaseFontButton.setEnabled(preferences.fontSize > 0); | |
| 637 | + plainFont = new Font(plainFont.getFontName(), plainFont.getStyle(), preferences.fontSize + 10); | |
| 638 | + boldFont = new Font(boldFont.getFontName(), boldFont.getStyle(), preferences.fontSize + 10); | |
| 639 | + italicFont = new Font(italicFont.getFontName(), italicFont.getStyle(), preferences.fontSize + 10); | |
| 640 | + textPane.setFont(plainFont); | |
| 641 | + analyzeView.changeFont(); | |
| 642 | + generateView.changeFont(); | |
| 643 | + } | |
| 644 | + | |
| 645 | + public pl.sgjp.morfeusz.Morfeusz getMorfeusz() | |
| 646 | + { | |
| 647 | + if (agent != null) return agent.getMorfeusz(); | |
| 648 | + return null; | |
| 649 | + } | |
| 650 | + | |
| 651 | + public void reset() | |
| 652 | + { | |
| 653 | + if (analyze) { | |
| 654 | + textPane.setText(null); | |
| 655 | + textPane.requestFocusInWindow(); | |
| 656 | + analyzePane.showColumns(false); | |
| 657 | + agent.clearAnalyzeResults(); | |
| 658 | + } | |
| 659 | + else { | |
| 660 | + lemmaField.setText(null); | |
| 661 | + lemmaField.requestFocusInWindow(); | |
| 662 | + generatePane.showColumns(false); | |
| 663 | + agent.clearGenerateResults(); | |
| 664 | + } | |
| 665 | + checkComponents(); | |
| 666 | + System.gc(); | |
| 667 | + } | |
| 668 | + | |
| 669 | + public void analyze() | |
| 670 | + { | |
| 671 | + agent.setTextToAnalyze(textPane.getText()); | |
| 672 | + if (agent.analyze()) { | |
| 673 | + if (agent.hasAnalyzeResults()) { | |
| 674 | + analyzePane.setResults(agent.getAnalyzeResults(), agent.getInterpBoundaries()); | |
| 675 | + analyzePane.scrollRectToVisible(topLeft); | |
| 676 | + } | |
| 677 | + else analyzePane.setResults(null, null); | |
| 678 | + checkComponents(); | |
| 679 | + } | |
| 680 | + else { | |
| 681 | + JOptionPane.showMessageDialog(null, NATIVE_ERROR_MESSAGE, "Uwaga", JOptionPane.ERROR_MESSAGE); | |
| 682 | + analyzePane.showColumns(false); | |
| 683 | + agent.clearAnalyzeResults(); | |
| 684 | + } | |
| 685 | + System.gc(); | |
| 686 | + } | |
| 687 | + | |
| 688 | + public void refreshAnalyzeResults() | |
| 689 | + { | |
| 690 | + if (agent.hasAnalyzeResults()) { | |
| 691 | + if (agent.analyze()) { | |
| 692 | + if (agent.hasAnalyzeResults()) { | |
| 693 | + analyzePane.setResults(agent.getAnalyzeResults(), agent.getInterpBoundaries()); | |
| 694 | + analyzePane.scrollRectToVisible(topLeft); | |
| 695 | + } | |
| 696 | + else analyzePane.setResults(null, null); | |
| 697 | + checkComponents(); | |
| 698 | + } | |
| 699 | + else { | |
| 700 | + JOptionPane.showMessageDialog(null, NATIVE_ERROR_MESSAGE, "Uwaga", JOptionPane.ERROR_MESSAGE); | |
| 701 | + analyzePane.showColumns(false); | |
| 702 | + agent.clearAnalyzeResults(); | |
| 703 | + } | |
| 704 | + System.gc(); | |
| 705 | + } | |
| 706 | + } | |
| 707 | + | |
| 708 | + public void generate() | |
| 709 | + { | |
| 710 | + String text = lemmaField.getText(); | |
| 711 | + String[] t; | |
| 712 | + | |
| 713 | + text = text.trim(); | |
| 714 | + t = text.split(" "); | |
| 715 | + text = t[0]; | |
| 716 | + lemmaField.setText(text); | |
| 717 | + agent.setLemma(lemmaField.getText()); | |
| 718 | + if (agent.generate()) { | |
| 719 | + if (agent.hasGenerateResults()) { | |
| 720 | + generatePane.setResults(agent.getGenerateResults(), null); | |
| 721 | + generatePane.scrollRectToVisible(topLeft); | |
| 722 | + } | |
| 723 | + else generatePane.setResults(null, null); | |
| 724 | + checkComponents(); | |
| 725 | + } | |
| 726 | + else { | |
| 727 | + JOptionPane.showMessageDialog(null, NATIVE_ERROR_MESSAGE, "Uwaga", JOptionPane.ERROR_MESSAGE); | |
| 728 | + generatePane.showColumns(false); | |
| 729 | + agent.clearGenerateResults(); | |
| 730 | + } | |
| 731 | + System.gc(); | |
| 732 | + } | |
| 733 | + | |
| 734 | + public void refreshGenerateResults() | |
| 735 | + { | |
| 736 | + if (agent.hasGenerateResults()) { | |
| 737 | + if (agent.generate()) { | |
| 738 | + if (agent.hasGenerateResults()) { | |
| 739 | + generatePane.setResults(agent.getGenerateResults(), null); | |
| 740 | + generatePane.scrollRectToVisible(topLeft); | |
| 741 | + } | |
| 742 | + else generatePane.setResults(null, null); | |
| 743 | + checkComponents(); | |
| 744 | + } | |
| 745 | + else { | |
| 746 | + JOptionPane.showMessageDialog(null, NATIVE_ERROR_MESSAGE, "Uwaga", JOptionPane.ERROR_MESSAGE); | |
| 747 | + generatePane.showColumns(false); | |
| 748 | + agent.clearGenerateResults(); | |
| 749 | + } | |
| 750 | + System.gc(); | |
| 751 | + } | |
| 752 | + } | |
| 753 | + | |
| 754 | + public void checkComponents() | |
| 755 | + { | |
| 756 | + boolean f1 = (analyze && textPane.getDocument().getLength() > 0), | |
| 757 | + f2 = (!analyze && lemmaField.getDocument().getLength() > 0), | |
| 758 | + f3 = (analyze && agent.hasAnalyzeResults()), | |
| 759 | + f4 = (!analyze && agent.hasGenerateResults()); | |
| 760 | + | |
| 761 | + analyzeAction.setEnabled(f1); | |
| 762 | + generateAction.setEnabled(f2); | |
| 763 | + saveActionA.setEnabled(f3); | |
| 764 | + saveActionG.setEnabled(f4); | |
| 765 | + resetAction.setEnabled(f1 || f2 || f3 || f4); | |
| 766 | + } | |
| 767 | + | |
| 768 | + public static boolean isMacOS() | |
| 769 | + { | |
| 770 | + return isMacOS; | |
| 771 | + } | |
| 772 | + | |
| 773 | + public static void main(String[] args) | |
| 774 | + { | |
| 775 | + Morfeusz morfeuszWnd = new Morfeusz(); | |
| 776 | + | |
| 777 | + morfeuszWnd.setVisible(true); | |
| 778 | + } | |
| 779 | + | |
| 780 | + private class AnalyzeView extends JPanel | |
| 781 | + { | |
| 782 | + | |
| 783 | + public AnalyzeView() | |
| 784 | + { | |
| 785 | + super(new BorderLayout()); | |
| 786 | + arrangeComponents(); | |
| 787 | + } | |
| 788 | + | |
| 789 | + public void arrangeComponents() | |
| 790 | + { | |
| 791 | + Box hbox, vbox; | |
| 792 | + JLabel label; | |
| 793 | + JScrollPane sp; | |
| 794 | + PlaceHolder placeHolder; | |
| 795 | + KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); | |
| 796 | + InputMap im; | |
| 797 | + int x = (isMacOS() ? -4 : -2); | |
| 798 | + | |
| 799 | + vbox = Box.createVerticalBox(); | |
| 800 | + vbox.setBorder(BorderFactory.createEmptyBorder(16, 16, 8, 16)); | |
| 801 | + hbox = Box.createHorizontalBox(); | |
| 802 | + hbox.setBorder(BorderFactory.createCompoundBorder( | |
| 803 | + BorderFactory.createTitledBorder("S\u0142ownik:"), | |
| 804 | + BorderFactory.createEmptyBorder(4, 4, 8, 4))); | |
| 805 | + analyzeDictionaryName = new JLabel(dictionary); | |
| 806 | + if (dictionary.equals(STANDARD)) analyzeDictionaryName.setForeground(Color.gray); | |
| 807 | + hbox.add(analyzeDictionaryName); | |
| 808 | + hbox.add(Box.createHorizontalGlue()); | |
| 809 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 810 | + changeButtonA = new ToolBarButton(changeAction, "book_open"); | |
| 811 | + changeButtonA.setFocusable(false); | |
| 812 | + changeButtonA.setToolTipText("Zmie\u0144 s\u0142ownik."); | |
| 813 | + hbox.add(changeButtonA); | |
| 814 | + vbox.add(hbox); | |
| 815 | + vbox.add(Box.createVerticalStrut(16)); | |
| 816 | + hbox = Box.createHorizontalBox(); | |
| 817 | + hbox.setBorder(BorderFactory.createEmptyBorder(0, 0, x, 0)); | |
| 818 | + label = new JLabel("Tekst:"); | |
| 819 | + hbox.add(label); | |
| 820 | + hbox.add(Box.createHorizontalGlue()); | |
| 821 | + hbox.add(Box.createHorizontalStrut(32)); | |
| 822 | + returnButton = new ToolBarButton(insertNewLineAction, "return"); | |
| 823 | + returnButton.setFocusable(false); | |
| 824 | + returnButton.setToolTipText("Nowa linia."); | |
| 825 | + hbox.add(returnButton); | |
| 826 | + hbox.add(Box.createHorizontalGlue()); | |
| 827 | + hbox.add(Box.createHorizontalStrut(32)); | |
| 828 | + openButton = new ToolBarButton(openAction, "open"); | |
| 829 | + openButton.setFocusable(false); | |
| 830 | + openButton.setToolTipText("Czytaj tekst z pliku."); | |
| 831 | + hbox.add(openButton); | |
| 832 | + vbox.add(hbox); | |
| 833 | + | |
| 834 | + textPane = new JTextArea(); | |
| 835 | + textPane.setFont(plainFont); | |
| 836 | + textPane.setLineWrap(true); | |
| 837 | + textPane.setWrapStyleWord(true); | |
| 838 | + textPane.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4)); | |
| 839 | + im = textPane.getInputMap(); | |
| 840 | + textPane.getActionMap().put(im.get(enterStroke), analyzeAction); | |
| 841 | + sp = new JScrollPane(textPane); | |
| 842 | + sp.setPreferredSize(new Dimension(0, 100)); | |
| 843 | + add(sp); | |
| 844 | + vbox.add(sp); | |
| 845 | + add(vbox, BorderLayout.NORTH); | |
| 846 | + | |
| 847 | + vbox = Box.createVerticalBox(); | |
| 848 | + vbox.setBorder(BorderFactory.createEmptyBorder(8, 16, 16, 16)); | |
| 849 | + hbox = Box.createHorizontalBox(); | |
| 850 | + hbox.setBorder(BorderFactory.createEmptyBorder(0, 0, x, 0)); | |
| 851 | + label = new JLabel("Analiza morfologiczna:"); | |
| 852 | + hbox.add(label); | |
| 853 | + hbox.add(Box.createHorizontalGlue()); | |
| 854 | + appendCheckBoxA = new JCheckBox("Dopisz "); | |
| 855 | + appendCheckBoxA.setFocusable(false); | |
| 856 | + hbox.add(appendCheckBoxA); | |
| 857 | + saveButtonA = new ToolBarButton(saveActionA, "save"); | |
| 858 | + saveButtonA.setFocusable(false); | |
| 859 | + saveButtonA.setToolTipText("Zapisz wynik analizy do pliku."); | |
| 860 | + hbox.add(saveButtonA); | |
| 861 | + vbox.add(hbox); | |
| 862 | + | |
| 863 | + placeHolder = new PlaceHolder(); | |
| 864 | + analyzePane = new ResultsPane(true, Morfeusz.this, placeHolder); | |
| 865 | + sp = new JScrollPane(analyzePane); | |
| 866 | + sp.getViewport().setBackground(LIGHT_GRAY); | |
| 867 | + sp.setCorner(JScrollPane.UPPER_RIGHT_CORNER, placeHolder); | |
| 868 | + vbox.add(sp); | |
| 869 | + add(vbox, BorderLayout.CENTER); | |
| 870 | + | |
| 871 | + textPane.getDocument().addDocumentListener(new DocumentListener() { | |
| 872 | + public void changedUpdate(DocumentEvent event) | |
| 873 | + { | |
| 874 | + } | |
| 875 | + | |
| 876 | + public void insertUpdate(DocumentEvent event) | |
| 877 | + { | |
| 878 | + checkComponents(); | |
| 879 | + } | |
| 880 | + | |
| 881 | + public void removeUpdate(DocumentEvent event) | |
| 882 | + { | |
| 883 | + checkComponents(); | |
| 884 | + } | |
| 885 | + }); | |
| 886 | + | |
| 887 | + appendCheckBoxA.addActionListener(new ActionListener() { | |
| 888 | + public void actionPerformed(ActionEvent event) | |
| 889 | + { | |
| 890 | + appendCheckBoxG.setSelected(appendCheckBoxA.isSelected()); | |
| 891 | + } | |
| 892 | + }); | |
| 893 | + } | |
| 894 | + | |
| 895 | + public void changeFont() | |
| 896 | + { | |
| 897 | + analyzePane.changeFont(); | |
| 898 | + } | |
| 899 | + | |
| 900 | + } | |
| 901 | + | |
| 902 | + private class GenerateView extends JPanel | |
| 903 | + { | |
| 904 | + | |
| 905 | + public GenerateView() | |
| 906 | + { | |
| 907 | + super(new BorderLayout()); | |
| 908 | + arrangeComponents(); | |
| 909 | + } | |
| 910 | + | |
| 911 | + public void arrangeComponents() | |
| 912 | + { | |
| 913 | + Box hbox, vbox; | |
| 914 | + JLabel label; | |
| 915 | + JScrollPane sp; | |
| 916 | + PlaceHolder placeHolder; | |
| 917 | + Dimension dim; | |
| 918 | + int x = (isMacOS() ? -4 : -2); | |
| 919 | + | |
| 920 | + vbox = Box.createVerticalBox(); | |
| 921 | + hbox = Box.createHorizontalBox(); | |
| 922 | + hbox.setBorder(BorderFactory.createCompoundBorder( | |
| 923 | + BorderFactory.createTitledBorder("S\u0142ownik:"), | |
| 924 | + BorderFactory.createEmptyBorder(4, 4, 8, 4))); | |
| 925 | + generateDictionaryName = new JLabel(dictionary); | |
| 926 | + if (dictionary.equals(STANDARD)) generateDictionaryName.setForeground(Color.gray); | |
| 927 | + hbox.add(generateDictionaryName); | |
| 928 | + hbox.add(Box.createHorizontalGlue()); | |
| 929 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 930 | + changeButtonG = new ToolBarButton(changeAction, "book_open"); | |
| 931 | + changeButtonG.setFocusable(false); | |
| 932 | + changeButtonG.setToolTipText("Zmie\u0144 s\u0142ownik."); | |
| 933 | + hbox.add(changeButtonG); | |
| 934 | + vbox.add(hbox); | |
| 935 | + vbox.add(Box.createVerticalStrut(20)); | |
| 936 | + hbox = Box.createHorizontalBox(); | |
| 937 | + vbox.setBorder(BorderFactory.createEmptyBorder(16, 16, 8, 16)); | |
| 938 | + label = new JLabel("Lemat:"); | |
| 939 | + hbox.add(label); | |
| 940 | + hbox.add(Box.createHorizontalStrut(8)); | |
| 941 | + lemmaField = new JTextField(30); | |
| 942 | + hbox.add(lemmaField); | |
| 943 | + dim = lemmaField.getPreferredSize(); | |
| 944 | + lemmaField.setMaximumSize(dim); | |
| 945 | + hbox.add(Box.createHorizontalGlue()); | |
| 946 | + vbox.add(hbox); | |
| 947 | + add(vbox, BorderLayout.NORTH); | |
| 948 | + | |
| 949 | + vbox = Box.createVerticalBox(); | |
| 950 | + vbox.setBorder(BorderFactory.createEmptyBorder(8, 16, 16, 16)); | |
| 951 | + hbox = Box.createHorizontalBox(); | |
| 952 | + hbox.setBorder(BorderFactory.createEmptyBorder(0, 0, x, 0)); | |
| 953 | + label = new JLabel("Wygenerowane formy:"); | |
| 954 | + hbox.add(label); | |
| 955 | + hbox.add(Box.createHorizontalGlue()); | |
| 956 | + appendCheckBoxG = new JCheckBox("Dopisz "); | |
| 957 | + appendCheckBoxG.setFocusable(false); | |
| 958 | + hbox.add(appendCheckBoxG); | |
| 959 | + saveButtonG = new ToolBarButton(saveActionG, "save"); | |
| 960 | + saveButtonG.setFocusable(false); | |
| 961 | + saveButtonG.setToolTipText("Zapisz wygenerowane formy wyrazowe do pliku."); | |
| 962 | + hbox.add(saveButtonG); | |
| 963 | + vbox.add(hbox); | |
| 964 | + | |
| 965 | + placeHolder = new PlaceHolder(); | |
| 966 | + generatePane = new ResultsPane(false, Morfeusz.this, placeHolder); | |
| 967 | + sp = new JScrollPane(generatePane); | |
| 968 | + sp.getViewport().setBackground(LIGHT_GRAY); | |
| 969 | + sp.setCorner(JScrollPane.UPPER_RIGHT_CORNER, placeHolder); | |
| 970 | + vbox.add(sp); | |
| 971 | + add(vbox, BorderLayout.CENTER); | |
| 972 | + | |
| 973 | + lemmaField.getDocument().addDocumentListener(new DocumentListener() { | |
| 974 | + public void changedUpdate(DocumentEvent event) | |
| 975 | + { | |
| 976 | + } | |
| 977 | + | |
| 978 | + public void insertUpdate(DocumentEvent event) | |
| 979 | + { | |
| 980 | + checkComponents(); | |
| 981 | + } | |
| 982 | + | |
| 983 | + public void removeUpdate(DocumentEvent event) | |
| 984 | + { | |
| 985 | + checkComponents(); | |
| 986 | + } | |
| 987 | + }); | |
| 988 | + | |
| 989 | + appendCheckBoxG.addActionListener(new ActionListener() { | |
| 990 | + public void actionPerformed(ActionEvent event) | |
| 991 | + { | |
| 992 | + appendCheckBoxA.setSelected(appendCheckBoxG.isSelected()); | |
| 993 | + } | |
| 994 | + }); | |
| 995 | + } | |
| 996 | + | |
| 997 | + public void changeFont() | |
| 998 | + { | |
| 999 | + generatePane.changeFont(); | |
| 1000 | + } | |
| 1001 | + | |
| 1002 | + } | |
| 1003 | + | |
| 1004 | + public class DictFilter implements FilenameFilter | |
| 1005 | + { | |
| 1006 | + | |
| 1007 | + public boolean accept(File dir, String name) | |
| 1008 | + { | |
| 1009 | + return (name.endsWith("-a.dict") || name.endsWith("-s.dict")); | |
| 1010 | + } | |
| 1011 | + | |
| 1012 | + } | |
| 1013 | + | |
| 1014 | +} | |
| ... | ... |
gui/morfeusz/OptionsDialog.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.event.*; | |
| 5 | + | |
| 6 | +import javax.swing.*; | |
| 7 | +import javax.swing.GroupLayout.*; | |
| 8 | + | |
| 9 | +import pl.sgjp.morfeusz.*; | |
| 10 | + | |
| 11 | +@SuppressWarnings("serial") | |
| 12 | +public class OptionsDialog extends JPanel | |
| 13 | +{ | |
| 14 | + | |
| 15 | + private JDialog dialog; | |
| 16 | + private JButton acceptButton; | |
| 17 | + private JButton cancelButton; | |
| 18 | + private JButton defaultsButton; | |
| 19 | + private JComboBox<String> agglCombo; | |
| 20 | + private JComboBox<String> praetCombo; | |
| 21 | + private JComboBox<String> caseCombo; | |
| 22 | + private JComboBox<String> spaceCombo; | |
| 23 | + private JComboBox<String> tokenCombo; | |
| 24 | + private Morfeusz controller; | |
| 25 | + private int ret; | |
| 26 | + | |
| 27 | + public OptionsDialog(Morfeusz controller) | |
| 28 | + { | |
| 29 | + super(new BorderLayout()); | |
| 30 | + this.controller = controller; | |
| 31 | + arrangeComponents(); | |
| 32 | + initiateValues(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public void arrangeComponents() | |
| 36 | + { | |
| 37 | + JLabel label1, label2, label3, label4, label5; | |
| 38 | + JPanel paramPanel = new JPanel(); | |
| 39 | + Box bottomPanel = Box.createHorizontalBox(); | |
| 40 | + GroupLayout gl = new GroupLayout(paramPanel); | |
| 41 | + GroupLayout.SequentialGroup hGroup = gl.createSequentialGroup(); | |
| 42 | + GroupLayout.SequentialGroup vGroup = gl.createSequentialGroup(); | |
| 43 | + Dimension dim; | |
| 44 | + | |
| 45 | + acceptButton = new JButton("Akceptuj"); | |
| 46 | + cancelButton = new JButton("Anuluj"); | |
| 47 | + defaultsButton = new JButton("Warto\u015Bci domy\u015Blne"); | |
| 48 | + label1 = new JLabel("aggl: "); | |
| 49 | + label2 = new JLabel("praet: "); | |
| 50 | + label3 = new JLabel("case-handling: "); | |
| 51 | + label4 = new JLabel("whitespace-handling: "); | |
| 52 | + label5 = new JLabel("token-numbering: "); | |
| 53 | + agglCombo = new JComboBox<String>(); | |
| 54 | + for (String str : controller.getMorfeusz().getAvailableAgglOptions()) agglCombo.addItem(str); | |
| 55 | + praetCombo = new JComboBox<String>(); | |
| 56 | + for (String str : controller.getMorfeusz().getAvailablePraetOptions()) praetCombo.addItem(str); | |
| 57 | + caseCombo = new JComboBox<String>(); | |
| 58 | + for (CaseHandling ch : CaseHandling.values()) caseCombo.addItem(ch.name()); | |
| 59 | + spaceCombo = new JComboBox<String>(); | |
| 60 | + for (WhitespaceHandling wh : WhitespaceHandling.values()) spaceCombo.addItem(wh.name()); | |
| 61 | + tokenCombo = new JComboBox<String>(); | |
| 62 | + for (TokenNumbering tn : TokenNumbering.values()) tokenCombo.addItem(tn.name()); | |
| 63 | + if (!Morfeusz.isMacOS()) { | |
| 64 | + gl.setAutoCreateGaps(true); | |
| 65 | + gl.setAutoCreateContainerGaps(true); | |
| 66 | + } | |
| 67 | + paramPanel.setLayout(gl); | |
| 68 | + hGroup.addGroup(gl.createParallelGroup().addComponent(label1). | |
| 69 | + addComponent(label2).addComponent(label3). | |
| 70 | + addComponent(label4).addComponent(label5)); | |
| 71 | + hGroup.addGroup(gl.createParallelGroup().addComponent(agglCombo). | |
| 72 | + addComponent(praetCombo).addComponent(caseCombo). | |
| 73 | + addComponent(spaceCombo).addComponent(tokenCombo)); | |
| 74 | + gl.setHorizontalGroup(hGroup); | |
| 75 | + vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE). | |
| 76 | + addComponent(label1).addComponent(agglCombo)); | |
| 77 | + vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE). | |
| 78 | + addComponent(label2).addComponent(praetCombo)); | |
| 79 | + vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE). | |
| 80 | + addComponent(label3).addComponent(caseCombo)); | |
| 81 | + vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE). | |
| 82 | + addComponent(label4).addComponent(spaceCombo)); | |
| 83 | + vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE). | |
| 84 | + addComponent(label5).addComponent(tokenCombo)); | |
| 85 | + gl.setVerticalGroup(vGroup); | |
| 86 | + bottomPanel.setBorder(BorderFactory.createEmptyBorder(16, 0, 0, 0)); | |
| 87 | + bottomPanel.add(defaultsButton); | |
| 88 | + bottomPanel.add(Box.createHorizontalStrut(8)); | |
| 89 | + bottomPanel.add(Box.createHorizontalGlue()); | |
| 90 | + bottomPanel.add(cancelButton); | |
| 91 | + bottomPanel.add(Box.createHorizontalStrut(8)); | |
| 92 | + bottomPanel.add(acceptButton); | |
| 93 | + dim = acceptButton.getPreferredSize(); | |
| 94 | + cancelButton.setPreferredSize(dim); | |
| 95 | + setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16)); | |
| 96 | + add(paramPanel, BorderLayout.CENTER); | |
| 97 | + add(bottomPanel, BorderLayout.SOUTH); | |
| 98 | + defaultsButton.addActionListener(new ActionListener() { | |
| 99 | + public void actionPerformed(ActionEvent event) | |
| 100 | + { | |
| 101 | + setDefaults(); | |
| 102 | + } | |
| 103 | + }); | |
| 104 | + cancelButton.addActionListener(new ActionListener() { | |
| 105 | + public void actionPerformed(ActionEvent event) | |
| 106 | + { | |
| 107 | + dialog.setVisible(false); | |
| 108 | + } | |
| 109 | + }); | |
| 110 | + acceptButton.addActionListener(new ActionListener() { | |
| 111 | + public void actionPerformed(ActionEvent event) | |
| 112 | + { | |
| 113 | + ret = 1; | |
| 114 | + dialog.setVisible(false); | |
| 115 | + } | |
| 116 | + }); | |
| 117 | + } | |
| 118 | + | |
| 119 | + public void setDefaults() | |
| 120 | + { | |
| 121 | + Preferences prefs = new Preferences(); | |
| 122 | + | |
| 123 | + prefs.setMorfeuszDefaults(); | |
| 124 | + initiateValues(prefs); | |
| 125 | + } | |
| 126 | + | |
| 127 | + public void initiateValues() | |
| 128 | + { | |
| 129 | + initiateValues(controller.getPreferences()); | |
| 130 | + } | |
| 131 | + | |
| 132 | + public void initiateValues(Preferences prefs) | |
| 133 | + { | |
| 134 | + agglCombo.setSelectedItem(prefs.aggl); | |
| 135 | + praetCombo.setSelectedItem(prefs.praet); | |
| 136 | + caseCombo.setSelectedItem(prefs.caseHandling.name()); | |
| 137 | + spaceCombo.setSelectedItem(prefs.whitespaceHandling.name()); | |
| 138 | + tokenCombo.setSelectedItem(prefs.tokenNumbering.name()); | |
| 139 | + } | |
| 140 | + | |
| 141 | + public void transfer(Preferences prefs) | |
| 142 | + { | |
| 143 | + prefs.aggl = (String) agglCombo.getSelectedItem(); | |
| 144 | + prefs.praet = (String) praetCombo.getSelectedItem(); | |
| 145 | + prefs.caseHandling = CaseHandling.values()[caseCombo.getSelectedIndex()]; | |
| 146 | + prefs.whitespaceHandling = WhitespaceHandling.values()[spaceCombo.getSelectedIndex()]; | |
| 147 | + prefs.tokenNumbering = TokenNumbering.values()[tokenCombo.getSelectedIndex()]; | |
| 148 | + } | |
| 149 | + | |
| 150 | + public int doDialog() | |
| 151 | + { | |
| 152 | + ret = 0; | |
| 153 | + dialog = new JDialog(); | |
| 154 | + dialog.setModal(true); | |
| 155 | + dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); | |
| 156 | + dialog.setTitle("Opcje programu"); | |
| 157 | + dialog.setResizable(false); | |
| 158 | + dialog.getContentPane().add(this); | |
| 159 | + dialog.pack(); | |
| 160 | + dialog.setLocationRelativeTo(null); | |
| 161 | + dialog.setVisible(true); | |
| 162 | + return ret; | |
| 163 | + } | |
| 164 | + | |
| 165 | + public void dispose() | |
| 166 | + { | |
| 167 | + if (dialog != null) { | |
| 168 | + dialog.dispose(); | |
| 169 | + dialog = null; | |
| 170 | + } | |
| 171 | + } | |
| 172 | + | |
| 173 | +} | |
| ... | ... |
gui/morfeusz/PlaceHolder.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | + | |
| 5 | +import javax.swing.*; | |
| 6 | + | |
| 7 | +@SuppressWarnings("serial") | |
| 8 | +public class PlaceHolder extends JPanel | |
| 9 | +{ | |
| 10 | + private boolean show; | |
| 11 | + | |
| 12 | + public PlaceHolder() | |
| 13 | + { | |
| 14 | + super(); | |
| 15 | + show = false; | |
| 16 | + setBackground(Morfeusz.LIGHT_GRAY); | |
| 17 | + } | |
| 18 | + | |
| 19 | + public void showBottomLine(boolean f) | |
| 20 | + { | |
| 21 | + if (show != f) { | |
| 22 | + show = f; | |
| 23 | + repaint(); | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void paintComponent(Graphics graphics) | |
| 28 | + { | |
| 29 | + super.paintComponent(graphics); | |
| 30 | + if (show) { | |
| 31 | + graphics.setColor(Color.lightGray); | |
| 32 | + if (Morfeusz.isMacOS()) { | |
| 33 | + graphics.drawLine(0, getHeight() - 2, getWidth(), getHeight() - 2); | |
| 34 | + graphics.setColor(Color.white); | |
| 35 | + graphics.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1); | |
| 36 | + } | |
| 37 | + else graphics.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1); | |
| 38 | + } | |
| 39 | + } | |
| 40 | + | |
| 41 | +} | |
| ... | ... |
gui/morfeusz/Preferences.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.io.Serializable; | |
| 4 | + | |
| 5 | +import pl.sgjp.morfeusz.*; | |
| 6 | + | |
| 7 | +@SuppressWarnings("serial") | |
| 8 | +public class Preferences implements Serializable | |
| 9 | +{ | |
| 10 | + | |
| 11 | + public String aggl; | |
| 12 | + public String praet; | |
| 13 | + public CaseHandling caseHandling; | |
| 14 | + public WhitespaceHandling whitespaceHandling; | |
| 15 | + public TokenNumbering tokenNumbering; | |
| 16 | + public int fontSize; | |
| 17 | + public int sortedColumn; | |
| 18 | + public String dictionary; | |
| 19 | + public String[] dictPaths; | |
| 20 | + | |
| 21 | + public Preferences() | |
| 22 | + { | |
| 23 | + } | |
| 24 | + | |
| 25 | + public void setDefaults() | |
| 26 | + { | |
| 27 | + setMorfeuszDefaults(); | |
| 28 | + fontSize = 2; | |
| 29 | + sortedColumn = 0; | |
| 30 | + dictionary = null; | |
| 31 | + dictPaths = null; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public void setMorfeuszDefaults() | |
| 35 | + { | |
| 36 | + aggl = "strict"; | |
| 37 | + praet = "split"; | |
| 38 | + caseHandling = CaseHandling.CONDITIONALLY_CASE_SENSITIVE; | |
| 39 | + whitespaceHandling = WhitespaceHandling.SKIP_WHITESPACES; | |
| 40 | + tokenNumbering = TokenNumbering.SEPARATE_NUMBERING; | |
| 41 | + } | |
| 42 | + | |
| 43 | +} | |
| ... | ... |
gui/morfeusz/RecentFileAction.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.event.ActionEvent; | |
| 4 | +import javax.swing.AbstractAction; | |
| 5 | +import javax.swing.Action; | |
| 6 | + | |
| 7 | +@SuppressWarnings("serial") | |
| 8 | +public class RecentFileAction extends AbstractAction | |
| 9 | +{ | |
| 10 | + | |
| 11 | + private Morfeusz controller; | |
| 12 | + private String name; | |
| 13 | + | |
| 14 | + public RecentFileAction(String name, Morfeusz controller) | |
| 15 | + { | |
| 16 | + super(); | |
| 17 | + this.name = name; | |
| 18 | + this.controller = controller; | |
| 19 | + | |
| 20 | + putValue(Action.NAME, name); | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void actionPerformed(ActionEvent e) | |
| 24 | + { | |
| 25 | + controller.changeDictionary(name); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public String getName() | |
| 29 | + { | |
| 30 | + return name; | |
| 31 | + } | |
| 32 | + | |
| 33 | +} | |
| ... | ... |
gui/morfeusz/ResultsPane.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.event.*; | |
| 5 | +import java.net.*; | |
| 6 | +import java.text.*; | |
| 7 | +import java.util.*; | |
| 8 | + | |
| 9 | +import javax.swing.*; | |
| 10 | +import javax.swing.border.*; | |
| 11 | +import javax.swing.table.*; | |
| 12 | + | |
| 13 | +import pl.sgjp.morfeusz.*; | |
| 14 | + | |
| 15 | +@SuppressWarnings("serial") | |
| 16 | +public class ResultsPane extends JTable | |
| 17 | +{ | |
| 18 | + | |
| 19 | + public static final String[] HEADERS1 = { "", "", "Forma", "Lemat", "Tag", "Nazwa", "Kwalifikatory" }; | |
| 20 | + public static final String[] HEADERS2 = { "Forma", "Lemat", "Tag", "Nazwa", "Kwalifikatory" }; | |
| 21 | + public static final Border emptyBorder = BorderFactory.createEmptyBorder(0, 2, 0, 2); | |
| 22 | + public static final Border lineBorder = BorderFactory.createCompoundBorder( | |
| 23 | + BorderFactory.createCompoundBorder( | |
| 24 | + BorderFactory.createEmptyBorder(0, -1, -1, -1), | |
| 25 | + BorderFactory.createLineBorder(Color.lightGray)), | |
| 26 | + BorderFactory.createEmptyBorder(0, 2, 0, 2)); | |
| 27 | + | |
| 28 | + private Morfeusz controller; | |
| 29 | + private JTable resultsTable; | |
| 30 | + private ColumnSorter columnSorter; | |
| 31 | + private java.util.List<MorphInterpretation> results; | |
| 32 | + private HashSet<Integer> interpBoundaries; | |
| 33 | + private PlaceHolder placeHolder; | |
| 34 | + private String[] headers; | |
| 35 | + private TableColumn[] tableColumns; | |
| 36 | + private boolean analyze; | |
| 37 | + private boolean columnsAreVisible; | |
| 38 | + | |
| 39 | + public ResultsPane(boolean analyze, Morfeusz controller, PlaceHolder placeHolder) | |
| 40 | + { | |
| 41 | + super(); | |
| 42 | + this.controller = controller; | |
| 43 | + this.analyze = analyze; | |
| 44 | + this.placeHolder = placeHolder; | |
| 45 | + resultsTable = this; | |
| 46 | + initTable(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + public void initTable() | |
| 50 | + { | |
| 51 | + | |
| 52 | + if (analyze) headers = HEADERS1; | |
| 53 | + else headers = HEADERS2; | |
| 54 | + | |
| 55 | + TableViewModel model = new TableViewModel(); | |
| 56 | + FontMetrics fm = getFontMetrics(Morfeusz.boldFont); | |
| 57 | + | |
| 58 | + columnSorter = new ColumnSorter(); | |
| 59 | + setModel(model); | |
| 60 | + setBorder(BorderFactory.createCompoundBorder( | |
| 61 | + BorderFactory.createEmptyBorder(-1, -1 , 0, -1), | |
| 62 | + BorderFactory.createLineBorder(Color.lightGray))); | |
| 63 | + setBackground(Morfeusz.LIGHT_GRAY); | |
| 64 | + setGridColor(Color.lightGray); | |
| 65 | + setShowHorizontalLines(false); | |
| 66 | + setAutoResizeMode(AUTO_RESIZE_OFF); | |
| 67 | + setRowSelectionAllowed(false); | |
| 68 | + setRowHeight(fm.getHeight() + 4); | |
| 69 | + | |
| 70 | + TableColumnModel columnModel = getColumnModel(); | |
| 71 | + TableCellRenderer cellRenderer = new RowRenderer(); | |
| 72 | + TableHeader tableHeader = new TableHeader(columnModel); | |
| 73 | + setTableHeader(tableHeader); | |
| 74 | + tableColumns = new TableColumn[headers.length]; | |
| 75 | + | |
| 76 | + for (int i = 0; i < columnModel.getColumnCount(); i++) { | |
| 77 | + TableColumn column = columnModel.getColumn(i); | |
| 78 | + | |
| 79 | + tableColumns[i] = column; | |
| 80 | + column.setHeaderValue(headers[i]); | |
| 81 | + column.setCellRenderer(cellRenderer); | |
| 82 | + column.setHeaderRenderer(tableHeader.getDefaultRenderer()); | |
| 83 | + } | |
| 84 | + | |
| 85 | + getTableHeader().setReorderingAllowed(false); | |
| 86 | + columnsAreVisible = true; | |
| 87 | + showColumns(false); | |
| 88 | + } | |
| 89 | + | |
| 90 | + public void sortTable(int sortedColumn) | |
| 91 | + { | |
| 92 | + if (controller.getPreferences().sortedColumn != sortedColumn) { | |
| 93 | + controller.getPreferences().sortedColumn = sortedColumn; | |
| 94 | + columnSorter.setSortedColumn(sortedColumn); | |
| 95 | + resetResults(); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + public void showColumns(boolean show) | |
| 100 | + { | |
| 101 | + if (columnsAreVisible != show) { | |
| 102 | + columnsAreVisible = show; | |
| 103 | + for (int i = 0; i < tableColumns.length; i++) { | |
| 104 | + if (show) addColumn(tableColumns[i]); | |
| 105 | + else removeColumn(tableColumns[i]); | |
| 106 | + } | |
| 107 | + if (show) { | |
| 108 | + TableColumnModel columnModel = getColumnModel(); | |
| 109 | + | |
| 110 | + for (int i = 0; i < columnModel.getColumnCount(); i++) { | |
| 111 | + TableColumn column = columnModel.getColumn(i); | |
| 112 | + | |
| 113 | + column.setHeaderRenderer(tableHeader.getDefaultRenderer()); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + } | |
| 117 | + placeHolder.showBottomLine(show); | |
| 118 | + } | |
| 119 | + | |
| 120 | + public void calculateSizes() | |
| 121 | + { | |
| 122 | + TableColumnModel columnModel = getColumnModel(); | |
| 123 | + TableColumn tableColumn; | |
| 124 | + TableCellRenderer renderer; | |
| 125 | + Component component; | |
| 126 | + Object value; | |
| 127 | + int w; | |
| 128 | + | |
| 129 | + for (int column = 0; column < columnModel.getColumnCount(); column++) { | |
| 130 | + w = 0; | |
| 131 | + tableColumn = columnModel.getColumn(column); | |
| 132 | + for (int row = 0; row < getRowCount(); row++) { | |
| 133 | + renderer = getCellRenderer(row, column); | |
| 134 | + value = getValueAt(row, column); | |
| 135 | + component = renderer.getTableCellRendererComponent(this, | |
| 136 | + value, false, false, row, column); | |
| 137 | + w = Math.max (component.getPreferredSize().width, w); | |
| 138 | + } | |
| 139 | + renderer = tableColumn.getHeaderRenderer(); | |
| 140 | + value = tableColumn.getHeaderValue(); | |
| 141 | + component = renderer.getTableCellRendererComponent(this, | |
| 142 | + value, false, false, 0, column); | |
| 143 | + w = Math.max (component.getPreferredSize().width, w); | |
| 144 | + columnModel.getColumn(column).setPreferredWidth(w + 4); | |
| 145 | + } | |
| 146 | + } | |
| 147 | + | |
| 148 | + public void changeFont() | |
| 149 | + { | |
| 150 | + FontMetrics fm = getFontMetrics(Morfeusz.boldFont); | |
| 151 | + TableHeader tableHeader = new TableHeader(columnModel); | |
| 152 | + TableColumnModel columnModel = getColumnModel(); | |
| 153 | + | |
| 154 | + setRowHeight(fm.getHeight() + 4); | |
| 155 | + for (int i = 0; i < columnModel.getColumnCount(); i++) { | |
| 156 | + TableColumn column = columnModel.getColumn(i); | |
| 157 | + | |
| 158 | + column.setHeaderRenderer(tableHeader.getDefaultRenderer()); | |
| 159 | + } | |
| 160 | + calculateSizes(); | |
| 161 | + revalidate(); | |
| 162 | + repaint(); | |
| 163 | + getTableHeader().repaint(); | |
| 164 | + } | |
| 165 | + | |
| 166 | + public boolean isCellEditable(int row, int column) | |
| 167 | + { | |
| 168 | + return false; | |
| 169 | + } | |
| 170 | + | |
| 171 | + public void setResults(java.util.List<MorphInterpretation> results, | |
| 172 | + HashSet<Integer> interpBoundaries) | |
| 173 | + { | |
| 174 | + this.results = results; | |
| 175 | + this.interpBoundaries = interpBoundaries; | |
| 176 | + resetResults(); | |
| 177 | + } | |
| 178 | + | |
| 179 | + public void resetResults() | |
| 180 | + { | |
| 181 | + if (results == null) showColumns(false); | |
| 182 | + else { | |
| 183 | + if (!analyze) Collections.sort(results, columnSorter); | |
| 184 | + showColumns(true); | |
| 185 | + calculateSizes(); | |
| 186 | + revalidate(); | |
| 187 | + repaint(); | |
| 188 | + } | |
| 189 | + getTableHeader().repaint(); | |
| 190 | + } | |
| 191 | + | |
| 192 | + public boolean newNode(int row) | |
| 193 | + { | |
| 194 | + boolean f = true; | |
| 195 | + | |
| 196 | + if (row > 0) { | |
| 197 | + MorphInterpretation i1 = results.get(row); | |
| 198 | + MorphInterpretation i2 = results.get(row - 1); | |
| 199 | + int sn1 = i1.getStartNode(), en1 = i1.getEndNode(), | |
| 200 | + sn2 = i2.getStartNode(), en2 = i2.getEndNode(); | |
| 201 | + | |
| 202 | + if (sn1 == sn2 && en1 == en2 && !interpBoundaries.contains(row)) f = false; | |
| 203 | + } | |
| 204 | + return f; | |
| 205 | + } | |
| 206 | + | |
| 207 | + private class TableViewModel extends AbstractTableModel | |
| 208 | + { | |
| 209 | + | |
| 210 | + public TableViewModel() | |
| 211 | + { | |
| 212 | + super(); | |
| 213 | + } | |
| 214 | + | |
| 215 | + public int getRowCount() | |
| 216 | + { | |
| 217 | + if (results == null) return 0; | |
| 218 | + return (int)results.size(); | |
| 219 | + } | |
| 220 | + | |
| 221 | + public int getColumnCount() | |
| 222 | + { | |
| 223 | + return headers.length; | |
| 224 | + } | |
| 225 | + | |
| 226 | + public Object getValueAt(int row, int column) | |
| 227 | + { | |
| 228 | + MorphInterpretation interp = results.get(row); | |
| 229 | + boolean f; | |
| 230 | + | |
| 231 | + if (analyze) f = newNode(row); | |
| 232 | + else { | |
| 233 | + f = true; | |
| 234 | + column += 2; | |
| 235 | + } | |
| 236 | + | |
| 237 | + switch (column) { | |
| 238 | + case 0 : if (f) return(Integer.toString(interp.getStartNode())); | |
| 239 | + return null; | |
| 240 | + case 1 : if (f) return(Integer.toString(interp.getEndNode())); | |
| 241 | + return null; | |
| 242 | + case 2 : if (f) { | |
| 243 | + String str = interp.getOrth(); | |
| 244 | + | |
| 245 | + if (str.contains(" ")) str = str.replace(' ', '\u23B5'); | |
| 246 | + return(str); | |
| 247 | + } | |
| 248 | + return null; | |
| 249 | + case 3 : return(interp.getLemma()); | |
| 250 | + case 4 : return(interp.getTag(controller.getMorfeusz())); | |
| 251 | + case 5 : return(interp.getName(controller.getMorfeusz())); | |
| 252 | + case 6 : | |
| 253 | + Collection<String> labels = interp.getLabels(controller.getMorfeusz()); | |
| 254 | + String str = null; | |
| 255 | + boolean append = false; | |
| 256 | + | |
| 257 | + if (labels.size() > 0) { | |
| 258 | + str = "["; | |
| 259 | + for (String s : labels) { | |
| 260 | + if (append) str += "; "; | |
| 261 | + str += s; | |
| 262 | + append = true; | |
| 263 | + } | |
| 264 | + str += "]"; | |
| 265 | + } | |
| 266 | + return str; | |
| 267 | + default : return null; | |
| 268 | + } | |
| 269 | + } | |
| 270 | + | |
| 271 | + } | |
| 272 | + | |
| 273 | + private class RowRenderer extends DefaultTableCellRenderer | |
| 274 | + { | |
| 275 | + | |
| 276 | + public Component getTableCellRendererComponent(JTable table, Object value, | |
| 277 | + boolean isSelected, boolean hasFocus, int row, int column) | |
| 278 | + { | |
| 279 | + JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); | |
| 280 | + | |
| 281 | + if (analyze) { | |
| 282 | + boolean f = newNode(row) && row > 0; | |
| 283 | + | |
| 284 | + if (column <= 1) label.setHorizontalAlignment(JLabel.CENTER); | |
| 285 | + else label.setHorizontalAlignment(JLabel.LEFT); | |
| 286 | + if (column == 2) setFont(Morfeusz.boldFont); | |
| 287 | + else if (column == 5 || column == 6) setFont(Morfeusz.italicFont); | |
| 288 | + else setFont(Morfeusz.plainFont); | |
| 289 | + if (f) setBorder(lineBorder); | |
| 290 | + else setBorder(emptyBorder); | |
| 291 | + } | |
| 292 | + else { | |
| 293 | + if (column == 0) setFont(Morfeusz.boldFont); | |
| 294 | + else if (column == 1) setFont(Morfeusz.plainFont); | |
| 295 | + else setFont(Morfeusz.italicFont); | |
| 296 | + setBorder(emptyBorder); | |
| 297 | + } | |
| 298 | + if (row % 2 == 0) setBackground(Morfeusz.VLIGHT_BLUE); | |
| 299 | + else setBackground(Color.white); | |
| 300 | + setForeground(Color.black); | |
| 301 | + setValue(value); | |
| 302 | + return this; | |
| 303 | + } | |
| 304 | + | |
| 305 | + } | |
| 306 | + | |
| 307 | + private class TableHeader extends JTableHeader | |
| 308 | + { | |
| 309 | + | |
| 310 | + private PlaceHolder corner = new PlaceHolder(); | |
| 311 | + private boolean initialized = false; | |
| 312 | + private int cursorPos = -1; | |
| 313 | + private int column = -1; | |
| 314 | + | |
| 315 | + public TableHeader(TableColumnModel model) | |
| 316 | + { | |
| 317 | + super(model); | |
| 318 | + setDefaultRenderer(new HeaderRenderer()); | |
| 319 | + setResizingAllowed(true); | |
| 320 | + corner.setLocation(0, 0); | |
| 321 | + corner.showBottomLine(columnsAreVisible); | |
| 322 | + add(corner); | |
| 323 | + if (!analyze) { | |
| 324 | + addMouseListener(new MouseAdapter() | |
| 325 | + { | |
| 326 | + public void mouseClicked(MouseEvent event) | |
| 327 | + { | |
| 328 | + cursorPos = event.getX(); | |
| 329 | + | |
| 330 | + TableColumnModel tcm = getColumnModel(); | |
| 331 | + | |
| 332 | + column = tcm.getColumnIndexAtX(event.getX()); | |
| 333 | + | |
| 334 | + if (column >= 0 && column <= 2) sortTable(column); | |
| 335 | + } | |
| 336 | + | |
| 337 | + public void mouseReleased(MouseEvent event) | |
| 338 | + { | |
| 339 | + cursorPos = event.getX(); | |
| 340 | + | |
| 341 | + TableColumnModel tcm = getColumnModel(); | |
| 342 | + | |
| 343 | + column = tcm.getColumnIndexAtX(cursorPos); | |
| 344 | + adjustCursor(); | |
| 345 | + } | |
| 346 | + }); | |
| 347 | + addMouseMotionListener(new MouseMotionAdapter() { | |
| 348 | + public void mouseMoved(MouseEvent event) | |
| 349 | + { | |
| 350 | + cursorPos = event.getX(); | |
| 351 | + | |
| 352 | + TableColumnModel model = resultsTable.getColumnModel(); | |
| 353 | + int c = model.getColumnIndexAtX(cursorPos); | |
| 354 | + | |
| 355 | + TableColumn col = null; | |
| 356 | + if (c >= 0 && c <= 2) col = model.getColumn(c); | |
| 357 | + if (col != null) { | |
| 358 | + if (c != column) { | |
| 359 | + switch (c) { | |
| 360 | + case 0 : setToolTipText("Sortuj formy."); break; | |
| 361 | + case 1 : setToolTipText("Sortuj lematy."); break; | |
| 362 | + case 2 : setToolTipText("Sortuj tagi."); break; | |
| 363 | + default : setToolTipText(null); | |
| 364 | + } | |
| 365 | + } | |
| 366 | + } | |
| 367 | + else setToolTipText(null); | |
| 368 | + if (c != column) column = c; | |
| 369 | + adjustCursor(); | |
| 370 | + } | |
| 371 | + }); | |
| 372 | + } | |
| 373 | + } | |
| 374 | + | |
| 375 | + public void adjustCursor() | |
| 376 | + { | |
| 377 | + if (column >= 0 && column <= 2) { | |
| 378 | + if (isResizeSpot(column, cursorPos)) | |
| 379 | + setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); | |
| 380 | + else setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); | |
| 381 | + } | |
| 382 | + else { | |
| 383 | + if (isResizeSpot(column, cursorPos)) | |
| 384 | + setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); | |
| 385 | + else setCursor(Cursor.getDefaultCursor()); | |
| 386 | + } | |
| 387 | + } | |
| 388 | + | |
| 389 | + public boolean isResizeSpot(int column, int x) | |
| 390 | + { | |
| 391 | + TableColumnModel model = resultsTable.getColumnModel(); | |
| 392 | + Rectangle rect = getHeaderRect(column); | |
| 393 | + int left, right, count = model.getColumnCount(); | |
| 394 | + | |
| 395 | + if (column < 0 || column >= count) return false; | |
| 396 | + else if (column == 0) { | |
| 397 | + left = rect.x; | |
| 398 | + right = left + rect.width - 3; | |
| 399 | + } | |
| 400 | + else { | |
| 401 | + left = rect.x += 3; | |
| 402 | + right = left + rect.width - 6; | |
| 403 | + } | |
| 404 | + if (x >= left && x < right) return false; | |
| 405 | + return true; | |
| 406 | + } | |
| 407 | + | |
| 408 | + public Dimension getPreferredSize() | |
| 409 | + { | |
| 410 | + Dimension dim = super.getPreferredSize(); | |
| 411 | + FontMetrics fm = getFontMetrics(Morfeusz.boldFont); | |
| 412 | + | |
| 413 | + dim.height = fm.getHeight() + 4; | |
| 414 | + return dim; | |
| 415 | + } | |
| 416 | + | |
| 417 | + public void setBounds(int x, int y, int width, int height) | |
| 418 | + { | |
| 419 | + super.setBounds(x, y, width, height); | |
| 420 | + moveCorner(); | |
| 421 | + initialized = true; | |
| 422 | + } | |
| 423 | + | |
| 424 | + public void moveCorner() | |
| 425 | + { | |
| 426 | + TableColumnModel tcm = getColumnModel(); | |
| 427 | + Rectangle rect; | |
| 428 | + | |
| 429 | + rect = getHeaderRect(tcm.getColumnCount() - 1); | |
| 430 | + corner.setLocation(rect.x + rect.width, 0); | |
| 431 | + corner.setSize(getWidth() - rect.x - rect.width, getHeight()); | |
| 432 | + } | |
| 433 | + | |
| 434 | + public void resizeAndRepaint() | |
| 435 | + { | |
| 436 | + super.resizeAndRepaint(); | |
| 437 | + if (initialized) { | |
| 438 | + moveCorner(); | |
| 439 | + corner.showBottomLine(columnsAreVisible); | |
| 440 | + } | |
| 441 | + } | |
| 442 | + } | |
| 443 | + | |
| 444 | + private class HeaderRenderer implements TableCellRenderer | |
| 445 | + { | |
| 446 | + | |
| 447 | + private JLabel renderer; | |
| 448 | + private Icon startNode, endNode, downArrow; | |
| 449 | + | |
| 450 | + public HeaderRenderer() | |
| 451 | + { | |
| 452 | + Border headerBorder = UIManager.getBorder("TableHeader.cellBorder"); | |
| 453 | + URL url; | |
| 454 | + | |
| 455 | + renderer = new JLabel(); | |
| 456 | + renderer.setFont(Morfeusz.boldFont); | |
| 457 | + renderer.setBorder(headerBorder); | |
| 458 | + renderer.setBackground(UIManager.getColor("TableHeader.background")); | |
| 459 | + renderer.setForeground(UIManager.getColor("TableHeader.foreground")); | |
| 460 | + if (analyze) { | |
| 461 | + url = ClassLoader.getSystemClassLoader().getResource("start_node.gif"); | |
| 462 | + startNode = new ImageIcon(url); | |
| 463 | + url = ClassLoader.getSystemClassLoader().getResource("end_node.gif"); | |
| 464 | + endNode = new ImageIcon(url); | |
| 465 | + } | |
| 466 | + else { | |
| 467 | + url = ClassLoader.getSystemClassLoader().getResource("down.gif"); | |
| 468 | + downArrow = new ImageIcon(url); | |
| 469 | + } | |
| 470 | + } | |
| 471 | + | |
| 472 | + public Component getTableCellRendererComponent(JTable table, | |
| 473 | + Object value, boolean isSelected, boolean hasFocus, int row, int column) | |
| 474 | + { | |
| 475 | + renderer.setText((String)value); | |
| 476 | + if (analyze) { | |
| 477 | + if (column == 0) { | |
| 478 | + renderer.setIcon(startNode); | |
| 479 | + renderer.setHorizontalAlignment(JLabel.CENTER); | |
| 480 | + } | |
| 481 | + else if (column == 1) { | |
| 482 | + renderer.setIcon(endNode); | |
| 483 | + renderer.setHorizontalAlignment(JLabel.CENTER); | |
| 484 | + } | |
| 485 | + else { | |
| 486 | + renderer.setIcon(null); | |
| 487 | + renderer.setHorizontalAlignment(JLabel.LEFT); | |
| 488 | + } | |
| 489 | + } | |
| 490 | + else { | |
| 491 | + int sortedColumn = controller.getPreferences().sortedColumn; | |
| 492 | + | |
| 493 | + if (column == sortedColumn) renderer.setIcon(downArrow); | |
| 494 | + else renderer.setIcon(null); | |
| 495 | + renderer.setHorizontalAlignment(JLabel.LEFT); | |
| 496 | + } | |
| 497 | + return renderer; | |
| 498 | + } | |
| 499 | + | |
| 500 | + } | |
| 501 | + | |
| 502 | + private class ColumnSorter implements Comparator<MorphInterpretation> | |
| 503 | + { | |
| 504 | + | |
| 505 | + private Collator collator = Collator.getInstance(new Locale("pl", "PL")); | |
| 506 | + private int sortedColumn; | |
| 507 | + | |
| 508 | + public ColumnSorter() | |
| 509 | + { | |
| 510 | + sortedColumn = controller.getPreferences().sortedColumn; | |
| 511 | + } | |
| 512 | + | |
| 513 | + public void setSortedColumn(int sortedColumn) | |
| 514 | + { | |
| 515 | + this.sortedColumn = sortedColumn; | |
| 516 | + } | |
| 517 | + | |
| 518 | + public int compare(MorphInterpretation mi1, MorphInterpretation mi2) | |
| 519 | + { | |
| 520 | + if (sortedColumn == 0) return compareForms(mi1, mi2); | |
| 521 | + else if (sortedColumn == 1) return compareLemmas(mi1, mi2); | |
| 522 | + return compareTags(mi1, mi2); | |
| 523 | + } | |
| 524 | + | |
| 525 | + public int compareForms(MorphInterpretation mi1, MorphInterpretation mi2) | |
| 526 | + { | |
| 527 | + String s1 = mi1.getOrth(), s2 = mi2.getOrth(); | |
| 528 | + int res = collator.compare(s1, s2); | |
| 529 | + | |
| 530 | + if (res == 0) { | |
| 531 | + s1 = mi1.getLemma(); | |
| 532 | + s2 = mi2.getLemma(); | |
| 533 | + res = collator.compare(s1, s2); | |
| 534 | + } | |
| 535 | + return res; | |
| 536 | + } | |
| 537 | + | |
| 538 | + public int compareLemmas(MorphInterpretation mi1, MorphInterpretation mi2) | |
| 539 | + { | |
| 540 | + String s1 = mi1.getLemma(), s2 = mi2.getLemma(); | |
| 541 | + int res = collator.compare(s1, s2); | |
| 542 | + | |
| 543 | + if (res == 0) { | |
| 544 | + s1 = mi1.getOrth(); | |
| 545 | + s2 = mi2.getOrth(); | |
| 546 | + res = collator.compare(s1, s2); | |
| 547 | + } | |
| 548 | + return res; | |
| 549 | + } | |
| 550 | + | |
| 551 | + public int compareTags(MorphInterpretation mi1, MorphInterpretation mi2) | |
| 552 | + { | |
| 553 | + String s1 = mi1.getTag(controller.getMorfeusz()), s2 = mi2.getTag(controller.getMorfeusz()); | |
| 554 | + | |
| 555 | + return collator.compare(s1, s2); | |
| 556 | + } | |
| 557 | + | |
| 558 | + } | |
| 559 | + | |
| 560 | +} | |
| ... | ... |
gui/morfeusz/SelectFileDialog.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.event.*; | |
| 5 | +import java.io.*; | |
| 6 | +import javax.swing.*; | |
| 7 | +import javax.swing.filechooser.*; | |
| 8 | + | |
| 9 | +@SuppressWarnings("serial") | |
| 10 | +public class SelectFileDialog extends JDialog | |
| 11 | +{ | |
| 12 | + | |
| 13 | + public static final int LOAD = 0; | |
| 14 | + public static final int SAVE = 1; | |
| 15 | + | |
| 16 | + private int mode; | |
| 17 | + private boolean accepted; | |
| 18 | + private JFileChooser fileChooser; | |
| 19 | + private JComboBox<String> encodingsCombo; | |
| 20 | + | |
| 21 | + public SelectFileDialog(Frame owner, int mode) | |
| 22 | + { | |
| 23 | + super(owner, true); | |
| 24 | + this.mode = mode; | |
| 25 | + initDialog(); | |
| 26 | + pack(); | |
| 27 | + setLocationRelativeTo(owner); | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void initDialog() | |
| 31 | + { | |
| 32 | + accepted = false; | |
| 33 | + setPreferredSize(new Dimension(640, 480)); | |
| 34 | + fileChooser = new JFileChooser(); | |
| 35 | + fileChooser.addActionListener(new ActionListener() | |
| 36 | + { | |
| 37 | + public void actionPerformed(ActionEvent e) | |
| 38 | + { | |
| 39 | + approveSelection((String)e.getActionCommand()); | |
| 40 | + } | |
| 41 | + }); | |
| 42 | + if (mode == LOAD) { | |
| 43 | + JPanel panel = new JPanel(new BorderLayout()); | |
| 44 | + JPanel accessoryContainer = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); | |
| 45 | + JPanel accessory = new JPanel(); | |
| 46 | + JLabel label; | |
| 47 | + | |
| 48 | + setTitle("Select File"); | |
| 49 | + fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); | |
| 50 | + fileChooser.setApproveButtonText("Select"); | |
| 51 | + fileChooser.setApproveButtonMnemonic('S'); | |
| 52 | + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); | |
| 53 | + fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Plain Text Files (*.txt)", "txt")); | |
| 54 | + | |
| 55 | + encodingsCombo = new JComboBox<String>(); | |
| 56 | + encodingsCombo.addItem("UTF8 (Eight-bit Unicode Transformation Format)"); | |
| 57 | + encodingsCombo.addItem("Cp1250 (Windows Eastern European)"); | |
| 58 | + encodingsCombo.addItem("Cp852 (MS-DOS Latin-2)"); | |
| 59 | + encodingsCombo.addItem("Cp870 (IBM Multilingual Latin-2)"); | |
| 60 | + encodingsCombo.addItem("ISO-8859-2 (ISO 8859-2, Latin Alphabet No. 2)"); | |
| 61 | + encodingsCombo.addItem("MacCentralEurope (Macintosh Latin-2)"); | |
| 62 | + | |
| 63 | + accessoryContainer.setBorder(BorderFactory.createEmptyBorder(0, 0, 12, 0)); | |
| 64 | + label = new JLabel("Encoding: "); | |
| 65 | + accessory.add(label); | |
| 66 | + accessory.add(encodingsCombo); | |
| 67 | + accessoryContainer.add(accessory); | |
| 68 | + panel.add(fileChooser, BorderLayout.CENTER); | |
| 69 | + panel.add(accessoryContainer, BorderLayout.SOUTH); | |
| 70 | + getContentPane().add(panel); | |
| 71 | + } | |
| 72 | + else { | |
| 73 | + setTitle("Save Results"); | |
| 74 | + fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); | |
| 75 | + fileChooser.setApproveButtonText("Save"); | |
| 76 | + fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Plain Text Files (*.txt)", "txt")); | |
| 77 | + getContentPane().add(fileChooser); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void approveSelection(String action) | |
| 82 | + { | |
| 83 | + File file; | |
| 84 | + | |
| 85 | + if (action.equals(JFileChooser.APPROVE_SELECTION)) { | |
| 86 | + if (mode == SAVE) { | |
| 87 | + file = fileChooser.getSelectedFile(); | |
| 88 | + if (file.exists()) { | |
| 89 | + Object[] existMsg = new Object[] { | |
| 90 | + "Plik \"" + file.getName() + "\" ju\u017C istnieje.", | |
| 91 | + "Czy chcesz go zamieni\u0107?" | |
| 92 | + }; | |
| 93 | + int answer = JOptionPane.showConfirmDialog(this, existMsg, "File Exists", | |
| 94 | + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); | |
| 95 | + if (answer == JOptionPane.YES_OPTION) { | |
| 96 | + accepted = true; | |
| 97 | + setVisible(false); | |
| 98 | + } | |
| 99 | + else if (answer == JOptionPane.NO_OPTION) { | |
| 100 | + accepted = false; | |
| 101 | + setVisible(false); | |
| 102 | + } | |
| 103 | + else accepted = false; | |
| 104 | + } | |
| 105 | + else { | |
| 106 | + accepted = true; | |
| 107 | + setVisible(false); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + else { | |
| 111 | + accepted = true; | |
| 112 | + setVisible(false); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + else { | |
| 116 | + accepted = false; | |
| 117 | + setVisible(false); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + | |
| 121 | + public void setSelectedFile(File file) | |
| 122 | + { | |
| 123 | + fileChooser.setSelectedFile(file); | |
| 124 | + } | |
| 125 | + | |
| 126 | + public File getSelectedFile() | |
| 127 | + { | |
| 128 | + return fileChooser.getSelectedFile(); | |
| 129 | + } | |
| 130 | + | |
| 131 | + public void setCurrentDirectory(File dir) | |
| 132 | + { | |
| 133 | + fileChooser.setCurrentDirectory(dir); | |
| 134 | + } | |
| 135 | + | |
| 136 | + public File getCurrentDirectory() | |
| 137 | + { | |
| 138 | + return fileChooser.getCurrentDirectory(); | |
| 139 | + } | |
| 140 | + | |
| 141 | + public String getEncoding() | |
| 142 | + { | |
| 143 | + String[] encoding = ((String)encodingsCombo.getSelectedItem()).split(" "); | |
| 144 | + | |
| 145 | + return encoding[0].trim(); | |
| 146 | + } | |
| 147 | + | |
| 148 | + public boolean accept() | |
| 149 | + { | |
| 150 | + return accepted; | |
| 151 | + } | |
| 152 | + | |
| 153 | +} | |
| ... | ... |
gui/morfeusz/ToolBarButton.java
0 → 100755
| 1 | +package morfeusz; | |
| 2 | + | |
| 3 | +import java.awt.Insets; | |
| 4 | +import java.net.URL; | |
| 5 | + | |
| 6 | +import javax.swing.Action; | |
| 7 | +import javax.swing.Icon; | |
| 8 | +import javax.swing.ImageIcon; | |
| 9 | +import javax.swing.JButton; | |
| 10 | + | |
| 11 | +@SuppressWarnings("serial") | |
| 12 | +public class ToolBarButton extends JButton | |
| 13 | +{ | |
| 14 | + | |
| 15 | + private String iconName; | |
| 16 | + | |
| 17 | + public ToolBarButton(Action action, String iconName) | |
| 18 | + { | |
| 19 | + super(action); | |
| 20 | + setText(null); | |
| 21 | + this.iconName = iconName; | |
| 22 | + initButton(); | |
| 23 | + } | |
| 24 | + | |
| 25 | + private void initButton() | |
| 26 | + { | |
| 27 | + URL url; | |
| 28 | + Icon icon; | |
| 29 | + | |
| 30 | + setRolloverEnabled(true); | |
| 31 | + setRequestFocusEnabled(false); | |
| 32 | + setMargin(new Insets(0, 0, 0, 0)); | |
| 33 | + putClientProperty("JToolBar.isRollover", Boolean.TRUE); | |
| 34 | + setBorderPainted(false); | |
| 35 | + setContentAreaFilled(false); | |
| 36 | + url = ClassLoader.getSystemClassLoader().getResource(iconName + ".png"); | |
| 37 | + if (url != null) { | |
| 38 | + icon = new ImageIcon(url); | |
| 39 | + setIcon(icon); | |
| 40 | + } | |
| 41 | + url = ClassLoader.getSystemClassLoader().getResource(iconName + "_disabled.png"); | |
| 42 | + if (url != null) { | |
| 43 | + icon = new ImageIcon(url); | |
| 44 | + setDisabledIcon(icon); | |
| 45 | + } | |
| 46 | + url = ClassLoader.getSystemClassLoader().getResource(iconName + "_roll_over.png"); | |
| 47 | + if (url != null) { | |
| 48 | + icon = new ImageIcon(url); | |
| 49 | + setRolloverIcon(icon); | |
| 50 | + } | |
| 51 | + url = ClassLoader.getSystemClassLoader().getResource(iconName + "_pressed.png"); | |
| 52 | + if (url != null) { | |
| 53 | + icon = new ImageIcon(url); | |
| 54 | + setPressedIcon(icon); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + public boolean isFocusTraversable() | |
| 59 | + { | |
| 60 | + return isRequestFocusEnabled(); | |
| 61 | + } | |
| 62 | + | |
| 63 | +} | |
| ... | ... |
gui/morfeusz2-gui
0 → 100755
gui/morfeusz2-gui.menu
0 → 100644
| 1 | +?package(morfeusz2-gui):needs="X11" section="Applications/Education" title="morfeusz2" command="/usr/bin/morfeusz-gui" | |
| ... | ... |
gui/morfeusz32.nsi
0 → 100644
| 1 | +############################################################################################ | |
| 2 | +# NSIS Installation Script created by NSIS Quick Setup Script Generator v1.09.18 | |
| 3 | +# Entirely Edited with NullSoft Scriptable Installation System | |
| 4 | +# by Vlasis K. Barkas aka Red Wine red_wine@freemail.gr Sep 2006 | |
| 5 | +############################################################################################ | |
| 6 | + | |
| 7 | +!define APP_NAME "Morfeusz 2.0" | |
| 8 | +!define COMP_NAME "Institute of Computer Science, Polish Academy of Sciences" | |
| 9 | +!define WEB_SITE "sgjp.pl/morfeusz" | |
| 10 | +!define VERSION "02.00.00.00" | |
| 11 | +!define COPYRIGHT "Institute of Computer Science, Polish Academy of Sciences" | |
| 12 | +!define DESCRIPTION "Morfological analyzer for Polish" | |
| 13 | +!define INSTALLER_NAME "Morfeusz_Setup.exe" | |
| 14 | +!define MAIN_APP_EXE "morfeusz32.exe" | |
| 15 | +!define INSTALL_TYPE "SetShellVarContext all" | |
| 16 | +!define REG_ROOT "HKLM" | |
| 17 | +!define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${MAIN_APP_EXE}" | |
| 18 | +!define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" | |
| 19 | + | |
| 20 | +!define REG_START_MENU "Start Menu Folder" | |
| 21 | + | |
| 22 | +var SM_Folder | |
| 23 | + | |
| 24 | +###################################################################### | |
| 25 | + | |
| 26 | +VIProductVersion "${VERSION}" | |
| 27 | +VIAddVersionKey "ProductName" "${APP_NAME}" | |
| 28 | +VIAddVersionKey "CompanyName" "${COMP_NAME}" | |
| 29 | +VIAddVersionKey "LegalCopyright" "${COPYRIGHT}" | |
| 30 | +VIAddVersionKey "FileDescription" "${DESCRIPTION}" | |
| 31 | +VIAddVersionKey "FileVersion" "${VERSION}" | |
| 32 | + | |
| 33 | +###################################################################### | |
| 34 | + | |
| 35 | +SetCompressor ZLIB | |
| 36 | +Name "${APP_NAME}" | |
| 37 | +Caption "${APP_NAME}" | |
| 38 | +OutFile "${INSTALLER_NAME}" | |
| 39 | +BrandingText "${APP_NAME}" | |
| 40 | +XPStyle on | |
| 41 | +InstallDirRegKey "${REG_ROOT}" "${REG_APP_PATH}" "" | |
| 42 | +InstallDir "$PROGRAMFILES\Morfeusz 2.0" | |
| 43 | + | |
| 44 | +###################################################################### | |
| 45 | + | |
| 46 | +!include "MUI.nsh" | |
| 47 | + | |
| 48 | +!define MUI_ABORTWARNING | |
| 49 | +!define MUI_UNABORTWARNING | |
| 50 | + | |
| 51 | +!define MUI_LANGDLL_REGISTRY_ROOT "${REG_ROOT}" | |
| 52 | +!define MUI_LANGDLL_REGISTRY_KEY "${UNINSTALL_PATH}" | |
| 53 | +!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language" | |
| 54 | + | |
| 55 | +!insertmacro MUI_PAGE_WELCOME | |
| 56 | + | |
| 57 | +!ifdef LICENSE_TXT | |
| 58 | +!insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}" | |
| 59 | +!endif | |
| 60 | + | |
| 61 | +!insertmacro MUI_PAGE_DIRECTORY | |
| 62 | + | |
| 63 | +!ifdef REG_START_MENU | |
| 64 | +!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Morfeusz 2.0" | |
| 65 | +!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${REG_ROOT}" | |
| 66 | +!define MUI_STARTMENUPAGE_REGISTRY_KEY "${UNINSTALL_PATH}" | |
| 67 | +!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${REG_START_MENU}" | |
| 68 | +!insertmacro MUI_PAGE_STARTMENU Application $SM_Folder | |
| 69 | +!endif | |
| 70 | + | |
| 71 | +!insertmacro MUI_PAGE_INSTFILES | |
| 72 | + | |
| 73 | +!define MUI_FINISHPAGE_RUN "$INSTDIR\${MAIN_APP_EXE}" | |
| 74 | +!insertmacro MUI_PAGE_FINISH | |
| 75 | + | |
| 76 | +!insertmacro MUI_UNPAGE_CONFIRM | |
| 77 | + | |
| 78 | +!insertmacro MUI_UNPAGE_INSTFILES | |
| 79 | + | |
| 80 | +!insertmacro MUI_UNPAGE_FINISH | |
| 81 | + | |
| 82 | +!insertmacro MUI_LANGUAGE "English" | |
| 83 | +!insertmacro MUI_LANGUAGE "Polish" | |
| 84 | + | |
| 85 | +!insertmacro MUI_RESERVEFILE_LANGDLL | |
| 86 | + | |
| 87 | +###################################################################### | |
| 88 | + | |
| 89 | +Function .onInit | |
| 90 | +!insertmacro MUI_LANGDLL_DISPLAY | |
| 91 | +FunctionEnd | |
| 92 | + | |
| 93 | +###################################################################### | |
| 94 | + | |
| 95 | +Section -MainProgram | |
| 96 | +${INSTALL_TYPE} | |
| 97 | +SetOverwrite ifnewer | |
| 98 | +SetOutPath "$INSTDIR" | |
| 99 | +File "morfeusz32.exe" | |
| 100 | +File "jmorfeusz.dll" | |
| 101 | +File "morfeusz2.dll" | |
| 102 | +File "libwinpthread-1.dll" | |
| 103 | +SectionEnd | |
| 104 | + | |
| 105 | +###################################################################### | |
| 106 | + | |
| 107 | +Section -Icons_Reg | |
| 108 | +SetOutPath "$INSTDIR" | |
| 109 | +WriteUninstaller "$INSTDIR\uninstall.exe" | |
| 110 | + | |
| 111 | +!ifdef REG_START_MENU | |
| 112 | +!insertmacro MUI_STARTMENU_WRITE_BEGIN Application | |
| 113 | +CreateDirectory "$SMPROGRAMS\$SM_Folder" | |
| 114 | +CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 115 | +CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 116 | +CreateShortCut "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe" | |
| 117 | + | |
| 118 | +!ifdef WEB_SITE | |
| 119 | +WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "URL" "${WEB_SITE}" | |
| 120 | +CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk" "$INSTDIR\${APP_NAME} website.url" | |
| 121 | +!endif | |
| 122 | +!insertmacro MUI_STARTMENU_WRITE_END | |
| 123 | +!endif | |
| 124 | + | |
| 125 | +!ifndef REG_START_MENU | |
| 126 | +CreateDirectory "$SMPROGRAMS\Morfeusz 2.0" | |
| 127 | +CreateShortCut "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 128 | +CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 129 | +CreateShortCut "$SMPROGRAMS\Morfeusz 2.0\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe" | |
| 130 | + | |
| 131 | +!ifdef WEB_SITE | |
| 132 | +WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "URL" "${WEB_SITE}" | |
| 133 | +CreateShortCut "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME} Website.lnk" "$INSTDIR\${APP_NAME} website.url" | |
| 134 | +!endif | |
| 135 | +!endif | |
| 136 | + | |
| 137 | +WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE}" | |
| 138 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}" | |
| 139 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe" | |
| 140 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${MAIN_APP_EXE}" | |
| 141 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}" | |
| 142 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}" | |
| 143 | + | |
| 144 | +!ifdef WEB_SITE | |
| 145 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "URLInfoAbout" "${WEB_SITE}" | |
| 146 | +!endif | |
| 147 | +SectionEnd | |
| 148 | + | |
| 149 | +###################################################################### | |
| 150 | + | |
| 151 | +Section Uninstall | |
| 152 | +${INSTALL_TYPE} | |
| 153 | +Delete "$INSTDIR\${MAIN_APP_EXE}" | |
| 154 | +Delete "$INSTDIR\jmorfeusz.dll" | |
| 155 | +Delete "$INSTDIR\morfeusz2.dll" | |
| 156 | +Delete "$INSTDIR\libwinpthread-1.dll" | |
| 157 | +Delete "$INSTDIR\uninstall.exe" | |
| 158 | +!ifdef WEB_SITE | |
| 159 | +Delete "$INSTDIR\${APP_NAME} website.url" | |
| 160 | +!endif | |
| 161 | + | |
| 162 | +RmDir "$INSTDIR" | |
| 163 | + | |
| 164 | +!ifdef REG_START_MENU | |
| 165 | +!insertmacro MUI_STARTMENU_GETFOLDER "Application" $SM_Folder | |
| 166 | +Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" | |
| 167 | +Delete "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" | |
| 168 | +!ifdef WEB_SITE | |
| 169 | +Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk" | |
| 170 | +!endif | |
| 171 | +Delete "$DESKTOP\${APP_NAME}.lnk" | |
| 172 | + | |
| 173 | +RmDir "$SMPROGRAMS\$SM_Folder" | |
| 174 | +!endif | |
| 175 | + | |
| 176 | +!ifndef REG_START_MENU | |
| 177 | +Delete "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME}.lnk" | |
| 178 | +Delete "$SMPROGRAMS\Morfeusz 2.0\Uninstall ${APP_NAME}.lnk" | |
| 179 | +!ifdef WEB_SITE | |
| 180 | +Delete "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME} Website.lnk" | |
| 181 | +!endif | |
| 182 | +Delete "$DESKTOP\${APP_NAME}.lnk" | |
| 183 | + | |
| 184 | +RmDir "$SMPROGRAMS\Morfeusz 2.0" | |
| 185 | +!endif | |
| 186 | + | |
| 187 | +DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}" | |
| 188 | +DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}" | |
| 189 | +SectionEnd | |
| 190 | + | |
| 191 | +###################################################################### | |
| 192 | + | |
| 193 | +Function un.onInit | |
| 194 | +!insertmacro MUI_UNGETLANGUAGE | |
| 195 | +FunctionEnd | |
| 196 | + | |
| 197 | +###################################################################### | |
| ... | ... |
gui/morfeusz64.nsi
0 → 100644
| 1 | +############################################################################################ | |
| 2 | +# NSIS Installation Script created by NSIS Quick Setup Script Generator v1.09.18 | |
| 3 | +# Entirely Edited with NullSoft Scriptable Installation System | |
| 4 | +# by Vlasis K. Barkas aka Red Wine red_wine@freemail.gr Sep 2006 | |
| 5 | +############################################################################################ | |
| 6 | + | |
| 7 | +!define APP_NAME "Morfeusz 2.0" | |
| 8 | +!define COMP_NAME "Institute of Computer Science, Polish Academy of Sciences" | |
| 9 | +!define WEB_SITE "sgjp.pl/morfeusz" | |
| 10 | +!define VERSION "02.00.00.00" | |
| 11 | +!define COPYRIGHT "Institute of Computer Science, Polish Academy of Sciences" | |
| 12 | +!define DESCRIPTION "Morfological analyzer for Polish" | |
| 13 | +!define INSTALLER_NAME "Morfeusz_Setup.exe" | |
| 14 | +!define MAIN_APP_EXE "morfeusz64.exe" | |
| 15 | +!define INSTALL_TYPE "SetShellVarContext all" | |
| 16 | +!define REG_ROOT "HKLM" | |
| 17 | +!define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${MAIN_APP_EXE}" | |
| 18 | +!define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" | |
| 19 | + | |
| 20 | +!define REG_START_MENU "Start Menu Folder" | |
| 21 | + | |
| 22 | +var SM_Folder | |
| 23 | + | |
| 24 | +###################################################################### | |
| 25 | + | |
| 26 | +VIProductVersion "${VERSION}" | |
| 27 | +VIAddVersionKey "ProductName" "${APP_NAME}" | |
| 28 | +VIAddVersionKey "CompanyName" "${COMP_NAME}" | |
| 29 | +VIAddVersionKey "LegalCopyright" "${COPYRIGHT}" | |
| 30 | +VIAddVersionKey "FileDescription" "${DESCRIPTION}" | |
| 31 | +VIAddVersionKey "FileVersion" "${VERSION}" | |
| 32 | + | |
| 33 | +###################################################################### | |
| 34 | + | |
| 35 | +SetCompressor ZLIB | |
| 36 | +Name "${APP_NAME}" | |
| 37 | +Caption "${APP_NAME}" | |
| 38 | +OutFile "${INSTALLER_NAME}" | |
| 39 | +BrandingText "${APP_NAME}" | |
| 40 | +XPStyle on | |
| 41 | +InstallDirRegKey "${REG_ROOT}" "${REG_APP_PATH}" "" | |
| 42 | +InstallDir "$PROGRAMFILES\Morfeusz 2.0" | |
| 43 | + | |
| 44 | +###################################################################### | |
| 45 | + | |
| 46 | +!include "MUI.nsh" | |
| 47 | + | |
| 48 | +!define MUI_ABORTWARNING | |
| 49 | +!define MUI_UNABORTWARNING | |
| 50 | + | |
| 51 | +!define MUI_LANGDLL_REGISTRY_ROOT "${REG_ROOT}" | |
| 52 | +!define MUI_LANGDLL_REGISTRY_KEY "${UNINSTALL_PATH}" | |
| 53 | +!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language" | |
| 54 | + | |
| 55 | +!insertmacro MUI_PAGE_WELCOME | |
| 56 | + | |
| 57 | +!ifdef LICENSE_TXT | |
| 58 | +!insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}" | |
| 59 | +!endif | |
| 60 | + | |
| 61 | +!insertmacro MUI_PAGE_DIRECTORY | |
| 62 | + | |
| 63 | +!ifdef REG_START_MENU | |
| 64 | +!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Morfeusz 2.0" | |
| 65 | +!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${REG_ROOT}" | |
| 66 | +!define MUI_STARTMENUPAGE_REGISTRY_KEY "${UNINSTALL_PATH}" | |
| 67 | +!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${REG_START_MENU}" | |
| 68 | +!insertmacro MUI_PAGE_STARTMENU Application $SM_Folder | |
| 69 | +!endif | |
| 70 | + | |
| 71 | +!insertmacro MUI_PAGE_INSTFILES | |
| 72 | + | |
| 73 | +!define MUI_FINISHPAGE_RUN "$INSTDIR\${MAIN_APP_EXE}" | |
| 74 | +!insertmacro MUI_PAGE_FINISH | |
| 75 | + | |
| 76 | +!insertmacro MUI_UNPAGE_CONFIRM | |
| 77 | + | |
| 78 | +!insertmacro MUI_UNPAGE_INSTFILES | |
| 79 | + | |
| 80 | +!insertmacro MUI_UNPAGE_FINISH | |
| 81 | + | |
| 82 | +!insertmacro MUI_LANGUAGE "English" | |
| 83 | +!insertmacro MUI_LANGUAGE "Polish" | |
| 84 | + | |
| 85 | +!insertmacro MUI_RESERVEFILE_LANGDLL | |
| 86 | + | |
| 87 | +###################################################################### | |
| 88 | + | |
| 89 | +Function .onInit | |
| 90 | +!insertmacro MUI_LANGDLL_DISPLAY | |
| 91 | +FunctionEnd | |
| 92 | + | |
| 93 | +###################################################################### | |
| 94 | + | |
| 95 | +Section -MainProgram | |
| 96 | +${INSTALL_TYPE} | |
| 97 | +SetOverwrite ifnewer | |
| 98 | +SetOutPath "$INSTDIR" | |
| 99 | +File "morfeusz64.exe" | |
| 100 | +File "jmorfeusz.dll" | |
| 101 | +File "morfeusz2.dll" | |
| 102 | +File "libwinpthread-1.dll" | |
| 103 | +SectionEnd | |
| 104 | + | |
| 105 | +###################################################################### | |
| 106 | + | |
| 107 | +Section -Icons_Reg | |
| 108 | +SetOutPath "$INSTDIR" | |
| 109 | +WriteUninstaller "$INSTDIR\uninstall.exe" | |
| 110 | + | |
| 111 | +!ifdef REG_START_MENU | |
| 112 | +!insertmacro MUI_STARTMENU_WRITE_BEGIN Application | |
| 113 | +CreateDirectory "$SMPROGRAMS\$SM_Folder" | |
| 114 | +CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 115 | +CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 116 | +CreateShortCut "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe" | |
| 117 | + | |
| 118 | +!ifdef WEB_SITE | |
| 119 | +WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "URL" "${WEB_SITE}" | |
| 120 | +CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk" "$INSTDIR\${APP_NAME} website.url" | |
| 121 | +!endif | |
| 122 | +!insertmacro MUI_STARTMENU_WRITE_END | |
| 123 | +!endif | |
| 124 | + | |
| 125 | +!ifndef REG_START_MENU | |
| 126 | +CreateDirectory "$SMPROGRAMS\Morfeusz 2.0" | |
| 127 | +CreateShortCut "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 128 | +CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}" | |
| 129 | +CreateShortCut "$SMPROGRAMS\Morfeusz 2.0\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe" | |
| 130 | + | |
| 131 | +!ifdef WEB_SITE | |
| 132 | +WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "URL" "${WEB_SITE}" | |
| 133 | +CreateShortCut "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME} Website.lnk" "$INSTDIR\${APP_NAME} website.url" | |
| 134 | +!endif | |
| 135 | +!endif | |
| 136 | + | |
| 137 | +WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE}" | |
| 138 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}" | |
| 139 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe" | |
| 140 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${MAIN_APP_EXE}" | |
| 141 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}" | |
| 142 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}" | |
| 143 | + | |
| 144 | +!ifdef WEB_SITE | |
| 145 | +WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "URLInfoAbout" "${WEB_SITE}" | |
| 146 | +!endif | |
| 147 | +SectionEnd | |
| 148 | + | |
| 149 | +###################################################################### | |
| 150 | + | |
| 151 | +Section Uninstall | |
| 152 | +${INSTALL_TYPE} | |
| 153 | +Delete "$INSTDIR\${MAIN_APP_EXE}" | |
| 154 | +Delete "$INSTDIR\jmorfeusz.dll" | |
| 155 | +Delete "$INSTDIR\morfeusz2.dll" | |
| 156 | +Delete "$INSTDIR\libwinpthread-1.dll" | |
| 157 | +Delete "$INSTDIR\uninstall.exe" | |
| 158 | +!ifdef WEB_SITE | |
| 159 | +Delete "$INSTDIR\${APP_NAME} website.url" | |
| 160 | +!endif | |
| 161 | + | |
| 162 | +RmDir "$INSTDIR" | |
| 163 | + | |
| 164 | +!ifdef REG_START_MENU | |
| 165 | +!insertmacro MUI_STARTMENU_GETFOLDER "Application" $SM_Folder | |
| 166 | +Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" | |
| 167 | +Delete "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" | |
| 168 | +!ifdef WEB_SITE | |
| 169 | +Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk" | |
| 170 | +!endif | |
| 171 | +Delete "$DESKTOP\${APP_NAME}.lnk" | |
| 172 | + | |
| 173 | +RmDir "$SMPROGRAMS\$SM_Folder" | |
| 174 | +!endif | |
| 175 | + | |
| 176 | +!ifndef REG_START_MENU | |
| 177 | +Delete "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME}.lnk" | |
| 178 | +Delete "$SMPROGRAMS\Morfeusz 2.0\Uninstall ${APP_NAME}.lnk" | |
| 179 | +!ifdef WEB_SITE | |
| 180 | +Delete "$SMPROGRAMS\Morfeusz 2.0\${APP_NAME} Website.lnk" | |
| 181 | +!endif | |
| 182 | +Delete "$DESKTOP\${APP_NAME}.lnk" | |
| 183 | + | |
| 184 | +RmDir "$SMPROGRAMS\Morfeusz 2.0" | |
| 185 | +!endif | |
| 186 | + | |
| 187 | +DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}" | |
| 188 | +DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}" | |
| 189 | +SectionEnd | |
| 190 | + | |
| 191 | +###################################################################### | |
| 192 | + | |
| 193 | +Function un.onInit | |
| 194 | +!insertmacro MUI_UNGETLANGUAGE | |
| 195 | +FunctionEnd | |
| 196 | + | |
| 197 | +###################################################################### | |
| ... | ... |
gui/quitaboutpreferenceshandler/QuitAboutPreferencesHandler$1.class
0 → 100644
No preview for this file type
gui/quitaboutpreferenceshandler/QuitAboutPreferencesHandler$2.class
0 → 100644
No preview for this file type
gui/quitaboutpreferenceshandler/QuitAboutPreferencesHandler$3.class
0 → 100644
No preview for this file type
gui/quitaboutpreferenceshandler/QuitAboutPreferencesHandler.class
0 → 100644
No preview for this file type
morfeusz/wrappers/CMakeLists.txt
| 1 | 1 | add_subdirectory (java) |
| 2 | -add_subdirectory (perl) | |
| 2 | +#add_subdirectory (perl) | |
| 3 | 3 | |
| 4 | 4 | if (${PY}) |
| 5 | 5 | if("${PY}" MATCHES "2.*") |
| ... | ... | @@ -7,4 +7,4 @@ if (${PY}) |
| 7 | 7 | elseif("${PY}" MATCHES "3.*") |
| 8 | 8 | add_subdirectory (python3) |
| 9 | 9 | endif() |
| 10 | -endif() | |
| 11 | 10 | \ No newline at end of file |
| 11 | +endif() | |
| ... | ... |