diff --git a/.gitignore b/.gitignore index 234aced12a100c17a9db54eb0f55e3a0a13047a5..9124a2007286f5570f707dc768cfc6b1be9a02ce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ tp/.idea tp/target tp/src/test tp/src/main/resouces +tp/save.csv +tp/contact_save.csv diff --git a/tp/.gitignore b/tp/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5ff6309b7199129c1afe4f4ec1906e640bec48c6 --- /dev/null +++ b/tp/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/tp/.mvn/wrapper/maven-wrapper.jar b/tp/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..c1dd12f17644411d6e840bd5a10c6ecda0175f18 Binary files /dev/null and b/tp/.mvn/wrapper/maven-wrapper.jar differ diff --git a/tp/.mvn/wrapper/maven-wrapper.properties b/tp/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..40ca0155f714d58a8b51693db47b5d80821bad4c --- /dev/null +++ b/tp/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar \ No newline at end of file diff --git a/tp/mvnw b/tp/mvnw new file mode 100644 index 0000000000000000000000000000000000000000..8a8fb2282df5b8f7263470a5a2dc0e196f35f35f --- /dev/null +++ b/tp/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/tp/mvnw.cmd b/tp/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..1d8ab018eaf11d9b3a4a90e7818ace373dfbb380 --- /dev/null +++ b/tp/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/tp/pom.xml b/tp/pom.xml index 7f3c7bedd0c42d722e06de85e00953a235ee9174..093bf9c3e1c23de2993faf34424ebf7aebdeb31a 100644 --- a/tp/pom.xml +++ b/tp/pom.xml @@ -1,65 +1,76 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>org.example</groupId> - <artifactId>tp</artifactId> + <groupId>com.example</groupId> + <artifactId>TPFx</artifactId> <version>1.0-SNAPSHOT</version> - -<!-- <dependencies>--> -<!-- <dependency>--> -<!-- <groupId>org.jetbrains</groupId>--> -<!-- <artifactId>annotations</artifactId>--> -<!-- <version>RELEASE</version>--> -<!-- <scope>compile</scope>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>org.junit.jupiter</groupId>--> -<!-- <artifactId>junit-jupiter</artifactId>--> -<!-- <version>5.9.0</version>--> -<!-- <scope>test</scope>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>org.apache.commons</groupId>--> -<!-- <artifactId>commons-lang3</artifactId>--> -<!-- <version>3.1</version>--> -<!-- </dependency>--> -<!-- </dependencies>--> - - <build> - <pluginManagement> - <plugins> -<!-- <plugin>--> -<!-- <groupId>org.apache.maven.plugins</groupId>--> -<!-- <artifactId>maven-surefire-plugin</artifactId>--> -<!-- <version>2.22.0</version>--> -<!-- </plugin>--> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>3.1.0</version> - <executions> - <execution> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>org.example.Main</mainClass> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> + <name>TPFx</name> <properties> - <maven.compiler.source>18</maven.compiler.source> - <maven.compiler.target>18</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <junit.version>5.9.1</junit.version> </properties> + <dependencies> + <dependency> + <groupId>org.openjfx</groupId> + <artifactId>javafx-controls</artifactId> + <version>18.0.2</version> + </dependency> + <dependency> + <groupId>org.openjfx</groupId> + <artifactId>javafx-fxml</artifactId> + <version>18.0.2</version> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.10.1</version> + <configuration> + <source>18</source> + <target>18</target> + </configuration> + </plugin> + <plugin> + <groupId>org.openjfx</groupId> + <artifactId>javafx-maven-plugin</artifactId> + <version>0.0.8</version> + <executions> + <execution> + <!-- Default configuration for running with: mvn clean javafx:run --> + <id>default-cli</id> + <configuration> + <mainClass>com.example.tpfx/com.example.tpfx.HelloApplication</mainClass> + <launcher>app</launcher> + <jlinkZipName>app</jlinkZipName> + <jlinkImageName>app</jlinkImageName> + <noManPages>true</noManPages> + <stripDebug>true</stripDebug> + <noHeaderFiles>true</noHeaderFiles> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> \ No newline at end of file diff --git a/tp/src/main/java/org/example/Contact.java b/tp/src/main/java/com/example/tpfx/Contact.java similarity index 92% rename from tp/src/main/java/org/example/Contact.java rename to tp/src/main/java/com/example/tpfx/Contact.java index 02eefd759d6aa10297a6740c82510d12368f946b..577c0429c97739c873c8aac194ec7490a1ff37cf 100644 --- a/tp/src/main/java/org/example/Contact.java +++ b/tp/src/main/java/com/example/tpfx/Contact.java @@ -1,7 +1,6 @@ -package org.example; +package com.example.tpfx; import java.util.*; - -public abstract class Contact implements Comparable<Contact>{ +public class Contact implements Comparable<Contact>{ protected String type; //Fields protected List<String> first_name; @@ -118,8 +117,8 @@ public abstract class Contact implements Comparable<Contact>{ w_social += elem + " "; } - return w_names + "\n" + this.last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n" - + w_social + "\n" + this.job; + return w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + + w_social + " - " + this.job; } @Override public int compareTo(Contact c){ diff --git a/tp/src/main/java/org/example/Family.java b/tp/src/main/java/com/example/tpfx/Family.java similarity index 76% rename from tp/src/main/java/org/example/Family.java rename to tp/src/main/java/com/example/tpfx/Family.java index b8581d1f0d4a42a46a0ed548f1d1a44b863a72bf..cf862ba1b31bd668a9b594228a0cb75303397b3c 100644 --- a/tp/src/main/java/org/example/Family.java +++ b/tp/src/main/java/com/example/tpfx/Family.java @@ -1,8 +1,5 @@ -package org.example; - -import java.util.ArrayList; +package com.example.tpfx; import java.util.List; - public class Family extends Contact{ private String relation; public Family(List<String> first_name, String last_name, String addr, List<String> phone, List<String> email, @@ -15,6 +12,10 @@ public class Family extends Contact{ return relation; } + public void EditRelation(String newRelation){ + this.relation = newRelation; + } + @Override public String toString(){ String w_names = ""; @@ -35,7 +36,7 @@ public class Family extends Contact{ w_social += elem + " "; } - return w_names + "\n" + this.last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n" - + w_social + "\n" + this.job + "\n" + this.relation; + return w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + + w_social + " - " + this.job + " - " + this.relation; } } diff --git a/tp/src/main/java/org/example/Friend.java b/tp/src/main/java/com/example/tpfx/Friend.java similarity index 85% rename from tp/src/main/java/org/example/Friend.java rename to tp/src/main/java/com/example/tpfx/Friend.java index ae75ea235ccac2bbe7b8057f48f6bcee08e27c7f..7165cd1484b80c30e73befda976400371a2eeeb8 100644 --- a/tp/src/main/java/org/example/Friend.java +++ b/tp/src/main/java/com/example/tpfx/Friend.java @@ -1,10 +1,6 @@ -package org.example; - -import java.util.ArrayList; +package com.example.tpfx; import java.util.List; - public class Friend extends Contact{ - public Friend(List<String> first_name, String last_name, String addr, List<String> phone, List<String> email, List<String> social, String job){ super("Friend", first_name, last_name, addr, phone, email, social, job); diff --git a/tp/src/main/java/com/example/tpfx/HelloApplication.java b/tp/src/main/java/com/example/tpfx/HelloApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..c07eaef5229b353da504d3069b18d81c5a788bca --- /dev/null +++ b/tp/src/main/java/com/example/tpfx/HelloApplication.java @@ -0,0 +1,23 @@ +package com.example.tpfx; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.io.IOException; + +public class HelloApplication extends Application { + @Override + public void start(Stage stage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 900, 630); + stage.setTitle("Contact List"); + stage.setScene(scene); + stage.show(); + } + + public static void main(String[] args) { + launch(); + } +} \ No newline at end of file diff --git a/tp/src/main/java/com/example/tpfx/HelloController.java b/tp/src/main/java/com/example/tpfx/HelloController.java new file mode 100644 index 0000000000000000000000000000000000000000..26a1001ee3982ba08087d810c971bc58641640c0 --- /dev/null +++ b/tp/src/main/java/com/example/tpfx/HelloController.java @@ -0,0 +1,373 @@ +package com.example.tpfx; + +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.*; + +import java.io.*; +import java.util.*; + +public class HelloController { + static ArrayList<Contact> contactArray = new ArrayList<Contact>(); + int selectedID = 0; + ObservableList<String> ctType = FXCollections.observableArrayList("Friend", "Family", "Professional"); + @FXML + private TextField txtFirst; + @FXML + private TextField txtSearch; + @FXML + private TextField txtLast; + @FXML + private TextField txtAdd; + @FXML + private TextField txtPhone; + @FXML + private TextField txtEmail; + @FXML + private TextField txtSocial; + @FXML + private TextField txtJob; + @FXML + private TextField txtOther; + @FXML + private Label lblOther; + @FXML + private Button btnAdd; + @FXML + private Button btnSave; + @FXML + private Button btnLoad; + @FXML + private Button btnSearch; + @FXML + private Button btnDelete; + @FXML + private Button btnEdit; + @FXML + private Button btnALl; + @FXML + private ListView LstCt; + @FXML + private ComboBox cbxType; + @FXML + protected void initialize() { + cbxType.setValue("Friend"); + cbxType.setItems(ctType); + lblOther.setVisible(false); + txtOther.setVisible(false); + btnEdit.setDisable(true); + btnDelete.setDisable(true); + } + @FXML + protected void AddCt() { + switch (cbxType.getValue().toString()){ + case "Friend": + AddPal(); + break; + case "Family": + AddFam(); + break; + case "Professional": + AddPro(); + break; + } + } + @FXML + protected void ChangeType(){ + switch (cbxType.getValue().toString()){ + case "Friend": + lblOther.setVisible(false); + txtOther.setVisible(false); + break; + case "Family": + lblOther.setVisible(true); + lblOther.setText("Relation"); + txtOther.setVisible(true); + break; + case "Professional": + lblOther.setVisible(true); + lblOther.setText("Job"); + txtOther.setVisible(true); + break; + } + } + @FXML + protected void ImportCt() { + LstCt.getItems().clear(); + contactArray.clear(); + try{ + BufferedReader reader = new BufferedReader(new FileReader("contact_save.csv")); + String line; + int checker = 0; + while((line = reader.readLine()) != null){ + switch (line){ + case "Friend": + checker = 1; + break; + case "Family": + checker = 2; + break; + case "Professional": + checker = 3; + break; + default: + List<String> str_array = SplitLine(line, "/"); + AddContactToList(str_array, checker); + checker = 0; + break; + } + } + reader.close(); + } catch (IOException e){ + e.printStackTrace(); + } + } + @FXML + protected void ExportCt() { + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter("contact_save.csv")); + for (Contact c: contactArray){ + List<String> str_array = SplitLine(c.toString(), " - "); + writer.write(c.get_type() + "\n"); + writer.write(str_array.get(0) + "/"); + writer.write(str_array.get(1) + "/"); + writer.write(str_array.get(2) + "/"); + writer.write(str_array.get(3) + "/"); + writer.write(str_array.get(4) + "/"); + writer.write(str_array.get(5) + "/"); + writer.write(str_array.get(6)); + if(c.get_type().equals("Family") || c.get_type().equals("Professional")){ + writer.write("/" + str_array.get(7) + "\n"); + } else{ + writer.write("/" + "\n"); + } + } + writer.close(); + } catch (IOException e){ + e.printStackTrace(); + } + } + @FXML + protected void Search() { + LstCt.getItems().clear(); + for(Contact c: contactArray){ + for(String n: c.getFirst_name()){ + if(n.equals(txtSearch.getText())){ + LstCt.getItems().add(c); + } + } + } + } + @FXML + protected void Selected() { + selectedID = LstCt.getSelectionModel().getSelectedIndex(); + lblOther.setVisible(true); + lblOther.setText(String.valueOf(selectedID) + " - " + String.valueOf(LstCt.getSelectionModel().getSelectedIndex())); + btnDelete.setDisable(false); + btnEdit.setDisable(false); + List<String> data = SplitLine(LstCt.getSelectionModel().getSelectedItem().toString(), " - "); + + txtFirst.setText(data.get(0)); + txtLast.setText(data.get(1)); + txtAdd.setText(data.get(2)); + txtPhone.setText(data.get(3)); + txtEmail.setText(data.get(4)); + txtSocial.setText(data.get(5)); + txtJob.setText(data.get(6)); + if(data.size() > 7){ + txtOther.setVisible(true); + lblOther.setVisible(true); + txtOther.setText(data.get(7)); + } else { + txtOther.setVisible(false); + lblOther.setVisible(false); + } + } + @FXML + protected void Delete() { + lblOther.setText(String.valueOf(selectedID)); + contactArray.remove(selectedID); + ShowAll(); + } + @FXML + protected void Edit() { + List<String> firstName = SplitLine(txtFirst.getText(), " "); + String lastName = txtLast.getText(); + String address = txtAdd.getText(); + List<String> phone = SplitLine(txtPhone.getText(), " "); + List<String> emails = SplitLine(txtEmail.getText(), " "); + List<String> social = SplitLine(txtSocial.getText(), " "); + String job = txtJob.getText(); + String other = txtOther.getText(); + + contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditFirstName(firstName); + contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditLastName(lastName); + contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditAddress(address); + contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditPhone(phone); + contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditEmail(emails); + contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditSocial(social); + contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditJob(job); + if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).get_type().equals("Family")){ + //contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditRelation(other); + } + if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).get_type().equals("Professional")){ + + } + ShowAll(); + } + @FXML + protected void ShowAll() { + LstCt.getItems().clear(); + for(Contact c: contactArray){ + LstCt.getItems().add(c.toString()); + } + } + public void AddPal(){ + String firstName = txtFirst.getText(); + String lastName = txtLast.getText(); + String address = txtAdd.getText(); + String phone = txtPhone.getText(); + String emails = txtEmail.getText(); + String social = txtSocial.getText(); + String job = txtJob.getText(); + + List<String> first_name_list = Arrays.asList(firstName.split(",")); + List<String> phoneList = Arrays.asList(phone.split(",")); + List<String> emailList = Arrays.asList(emails.split(",")); + List<String> socialList = Arrays.asList(social.split(",")); + + Friend pal = new Friend(first_name_list, lastName, address, phoneList, emailList, socialList, job); + Add(pal); + } + public void AddFam(){ + String firstName = txtFirst.getText(); + String lastName = txtLast.getText(); + String address = txtAdd.getText(); + String phone = txtPhone.getText(); + String emails = txtEmail.getText(); + String social = txtSocial.getText(); + String job = txtJob.getText(); + String relation = txtOther.getText(); + + List<String> first_name_list = Arrays.asList(firstName.split(" ")); + List<String> phoneList = Arrays.asList(phone.split(" ")); + List<String> emailList = Arrays.asList(emails.split(" ")); + List<String> socialList = Arrays.asList(social.split(" ")); + + Family fam = new Family(first_name_list, lastName, address, phoneList, emailList, socialList, job, relation); + Add(fam); + } + public void AddPro(){ + String firstName = txtFirst.getText(); + String lastName = txtLast.getText(); + String address = txtAdd.getText(); + String phone = txtPhone.getText(); + String emails = txtEmail.getText(); + String social = txtSocial.getText(); + String job = txtJob.getText(); + String wp = txtOther.getText(); + + List<String> first_name_list = Arrays.asList(firstName.split(" ")); + List<String> phoneList = Arrays.asList(phone.split("/")); + List<String> emailList = Arrays.asList(emails.split("/")); + List<String> socialList = Arrays.asList(social.split("/")); + + Professional pro = new Professional(first_name_list, lastName, address, phoneList, emailList, socialList, job, wp); + Add(pro); + } + public void Add(Contact c){ + contactArray.add(c); + Collections.sort(contactArray); + ShowAll(); + txtFirst.setText(""); + txtLast.setText(""); + txtAdd.setText(""); + txtPhone.setText(""); + txtEmail.setText(""); + txtSocial.setText(""); + txtJob.setText(""); + txtOther.setText(""); + } + public void ImportFriend(List<String> str_array){ + Friend f = new Friend( + SplitArray(str_array.get(0)), + str_array.get(1), + str_array.get(2), + SplitArray(str_array.get(3)), + SplitArray(str_array.get(4)), + SplitArray(str_array.get(5)), + str_array.get(6) + ); + Add(f); + } + public void ImportFamily(List<String> str_array){ + Family f = new Family( + SplitArray(str_array.get(0)), + str_array.get(1), + str_array.get(2), + SplitArray(str_array.get(3)), + SplitArray(str_array.get(4)), + SplitArray(str_array.get(5)), + str_array.get(6), + str_array.get(7) + ); + Add(f); + } + public void ImportProfessional(List<String> str_array){ + Professional f = new Professional( + SplitArray(str_array.get(0)), + str_array.get(1), + str_array.get(2), + SplitArray(str_array.get(3)), + SplitArray(str_array.get(4)), + SplitArray(str_array.get(5)), + str_array.get(6), + str_array.get(7) + ); + Add(f); + } + public void AddContactToList(List<String> str_array, int checker){ + switch (checker){ + case 1: + ImportFriend(str_array); + break; + case 2: + ImportFamily(str_array); + break; + case 3: + ImportProfessional(str_array); + break; + default: + System.out.println("Error contact type"); + break; + } + } + public List<String> SplitLine(String str, String splitter){ + List<String> data = Arrays.asList(str.split(splitter)); + return data; + } + public List<String> SplitArray(String str){ + //str = str.substring(1, str.length() - 1); + String new_str = ""; + for(char c: str.toCharArray()){ + if(c !='[' && c !=']'){ + new_str += c; + } + } + List<String> names = Arrays.asList(new_str.split(",")); + return names; + } + + + //TODO + /* + Edit family/pro + Delete/Edit with search + Better toString in export + Add type for real + List first names & co + */ + +} \ No newline at end of file diff --git a/tp/src/main/java/org/example/Professional.java b/tp/src/main/java/com/example/tpfx/Professional.java similarity index 77% rename from tp/src/main/java/org/example/Professional.java rename to tp/src/main/java/com/example/tpfx/Professional.java index 2fa74c60e659f804d84f028b5dba1fccd6479243..2bd675e50acd5cdf3efe90723a14f1e983de5e3f 100644 --- a/tp/src/main/java/org/example/Professional.java +++ b/tp/src/main/java/com/example/tpfx/Professional.java @@ -1,8 +1,5 @@ -package org.example; - -import java.util.ArrayList; +package com.example.tpfx; import java.util.List; - public class Professional extends Contact{ private String work_place; public Professional(List<String> first_name, String last_name, String addr, List<String> phone, List<String> email, @@ -13,6 +10,10 @@ public class Professional extends Contact{ public String getWork_place() { return work_place; } + + public void EditWork(String newWork){ + this.work_place = newWork; + } @Override public String toString(){ String w_names = ""; @@ -33,7 +34,7 @@ public class Professional extends Contact{ w_social += elem + " "; } - return w_names + "\n" + last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n" - + w_social + "\n" + this.job + "\n" + this.work_place; + return w_names + " - " + last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + + w_social + " - " + this.job + " - " + this.work_place; } } diff --git a/tp/src/main/java/module-info.java b/tp/src/main/java/module-info.java new file mode 100644 index 0000000000000000000000000000000000000000..b6ff8a11667680bdd582543d46b7a75f6cba040d --- /dev/null +++ b/tp/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module com.example.tpfx { + requires javafx.controls; + requires javafx.fxml; + + + opens com.example.tpfx to javafx.fxml; + exports com.example.tpfx; +} \ No newline at end of file diff --git a/tp/src/main/java/org/example/Main.java b/tp/src/main/java/org/example/Main.java deleted file mode 100644 index 35d7b3649fc82861c3650186fdcd2418951bf9e8..0000000000000000000000000000000000000000 --- a/tp/src/main/java/org/example/Main.java +++ /dev/null @@ -1,417 +0,0 @@ -package org.example; -import java.io.*; -import java.util.*; -public class Main { - static ArrayList<Contact> contactArray = new ArrayList<Contact>(); - public static void main(String[] args) { - while(true){ - System.out.println(""); - System.out.println("[0] Add new Contact"); - System.out.println("[1] Edit Contact"); - System.out.println("[2] Delete Contact"); - System.out.println("[3] Show Contact"); - System.out.println("[4] Search Contact"); - System.out.println("[5] Export Contact"); - System.out.println("[6] Import Contact"); - - Scanner myObj = new Scanner(System.in); - String usrInput = myObj.nextLine(); - - switch (usrInput){ - case "0": - Pick(); - break; - case "1": - Edit(); - break; - case "2": - Delete(); - break; - case "3": - Show(); - break; - case "4": - Search(); - break; - case "5": - Export(contactArray); - break; - case "6": - Import(contactArray); - break; - default: - System.out.println("Please enter valid input"); - break; - } - } - } - /* - * Pick which type contact the user wants to add - */ - public static void Pick(){ - int size_array = contactArray.size(); - - System.out.println(""); - System.out.println("[0] Friend"); - System.out.println("[1] Family"); - System.out.println("[2] Professional"); - - Scanner myObj = new Scanner(System.in); - String usrInput = myObj.nextLine(); - - switch (usrInput){ - case "0": - AddPal(); - break; - case "1": - AddFam(); - break; - case "2": - AddPro(); - break; - default: - System.out.println("Please enter valid input"); - break; - } - } - /* - * Adds a friend contact - */ - public static void AddPal(){ - System.out.println("Enter first names"); - Scanner myObj = new Scanner(System.in); - String firstName = myObj.nextLine(); - System.out.println("Enter last names"); - String lastName = myObj.nextLine(); - - System.out.println("Enter Address"); - String address = myObj.nextLine(); - System.out.println("Enter Phone"); - String phone = myObj.nextLine(); - System.out.println("Enter Emails"); - String emails = myObj.nextLine(); - System.out.println("Enter Socials"); - String social = myObj.nextLine(); - System.out.println("Enter Job"); - String job = myObj.nextLine(); - - List<String> first_name_list = Arrays.asList(firstName.split(" ")); - List<String> phoneList = Arrays.asList(phone.split(" ")); - List<String> emailList = Arrays.asList(emails.split(" ")); - List<String> socialList = Arrays.asList(social.split(" ")); - - Friend pal = new Friend(first_name_list, lastName, address, phoneList, emailList, socialList, job); - Add(pal); - } - /* - * Adds a family contact - */ - public static void AddFam(){ - System.out.println("Enter first names"); - Scanner myObj = new Scanner(System.in); - String firstName = myObj.nextLine(); - System.out.println("Enter last names"); - String lastName = myObj.nextLine(); - - System.out.println("Enter Address"); - String address = myObj.nextLine(); - System.out.println("Enter Phone"); - String phone = myObj.nextLine(); - System.out.println("Enter Emails"); - String emails = myObj.nextLine(); - System.out.println("Enter Socials"); - String social = myObj.nextLine(); - System.out.println("Enter Job"); - String job = myObj.nextLine(); - System.out.println("Enter relation"); - String relation = myObj.nextLine(); - - List<String> first_name_list = Arrays.asList(firstName.split(" ")); - List<String> phoneList = Arrays.asList(phone.split(" ")); - List<String> emailList = Arrays.asList(emails.split(" ")); - List<String> socialList = Arrays.asList(social.split(" ")); - - Family fam = new Family(first_name_list, lastName, address, phoneList, emailList, socialList, job, relation); - Add(fam); - } - /* - * Adds a professional contact (obviously) - */ - public static void AddPro(){ - System.out.println("Enter first name(s)"); - Scanner myObj = new Scanner(System.in); - String firstName = myObj.nextLine(); - System.out.println("Enter last name"); - String lastName = myObj.nextLine(); - - System.out.println("Enter Address"); - String address = myObj.nextLine(); - System.out.println("Enter Phone (use / as separator)"); - String phone = myObj.nextLine(); - System.out.println("Enter Emails (use / as separator)"); - String emails = myObj.nextLine(); - System.out.println("Enter Socials (use / as separator)"); - String social = myObj.nextLine(); - System.out.println("Enter Job"); - String job = myObj.nextLine(); - System.out.println("Enter Work Place"); - String wp = myObj.nextLine(); - - List<String> first_name_list = Arrays.asList(firstName.split(" ")); - List<String> phoneList = Arrays.asList(phone.split("/")); - List<String> emailList = Arrays.asList(emails.split("/")); - List<String> socialList = Arrays.asList(social.split("/")); - - Professional pro = new Professional(first_name_list, lastName, address, phoneList, emailList, socialList, job, wp); - Add(pro); - } - public static void Add(Contact c){ - contactArray.add(c); - Collections.sort(contactArray); - } - public static void Edit(){ - int size_array = contactArray.size(); - if(size_array == 0){ - System.out.println("List is empty"); - } else{ - System.out.println("Which contact?"); - Scanner myObj = new Scanner(System.in); - String contactNb = myObj.nextLine(); - if(TryNumber(contactNb)){ - System.out.println("[0] Edit First names"); - System.out.println("[1] Edit Last names"); - System.out.println("[2] Edit Address"); - System.out.println("[3] Edit Phones"); - System.out.println("[4] Edit Emails"); - System.out.println("[5] Edit Social"); - System.out.println("[6] Edit Job"); - String usrInput = myObj.nextLine(); - - switch (usrInput){ - case "0": - System.out.println("Enter new first names"); - String editFirst = myObj.nextLine(); - List<String> new_first = Arrays.asList(editFirst.split(" ")); - contactArray.get(Integer.parseInt(contactNb)).EditFirstName(new_first); - break; - case "1": - System.out.println("Enter new last names"); - String editLast = myObj.nextLine(); - contactArray.get(Integer.parseInt(contactNb)).EditLastName(editLast); - break; - case "2": - System.out.println("Enter new first address"); - String editAddr = myObj.nextLine(); - contactArray.get(Integer.parseInt(contactNb)).EditAddress(editAddr); - break; - case "3": - System.out.println("Enter new phone numbers (use / as separator)"); - String editPhone = myObj.nextLine(); - List<String> editPhoneList = Arrays.asList(editPhone.split("/")); - contactArray.get(Integer.parseInt(contactNb)).EditPhone(editPhoneList); - break; - case "4": - System.out.println("Enter new Emails (use / as separator)"); - String editEmail = myObj.nextLine(); - List<String> editEmailList = Arrays.asList(editEmail.split("/")); - contactArray.get(Integer.parseInt(contactNb)).EditEmail(editEmailList); - break; - case "5": - System.out.println("Enter new Socials (use / as separator)"); - String editSocial = myObj.nextLine(); - List<String> editSocialList = Arrays.asList(editSocial.split("/")); - contactArray.get(Integer.parseInt(contactNb)).EditEmail(editSocialList); - break; - case "6": - System.out.println("Enter new Job"); - String editJob = myObj.nextLine(); - contactArray.get(Integer.parseInt(contactNb)).EditLastName(editJob); - break; - default: - System.out.println("Please enter correct value"); - break; - } - } else { - System.out.println("Please enter valid input"); - System.out.println("It must be a number between 0 and " + (size_array -1)); - } - } - } - public static void Delete(){ - int size_array = contactArray.size(); - if(size_array == 0){ - System.out.println("List is empty"); - } else{ - System.out.println("Which Contact?"); - Scanner myObj = new Scanner(System.in); - String usrInput = myObj.nextLine(); - if(TryNumber(usrInput)){ - contactArray.remove(usrInput); - } else{ - System.out.println("Please enter valid input"); - System.out.println("It must be a number between 0 and " + (size_array -1)); - } - } - } - public static void Show(){ - for(Contact ct: contactArray){ - System.out.println(ct.toString()); - System.out.println(); - } - } - public static void Search(){ - System.out.println("Enter Contact first name"); - Scanner myObj = new Scanner(System.in); - String ctName = myObj.nextLine(); - for(Contact c: contactArray){ - if(c.getFirst_name().equals(ctName)){ - System.out.println(c.toString()); - } - } - } - /* - * Export list of contact - */ - public static void Export(ArrayList<Contact> ca){ - System.out.println("Enter save file name"); - Scanner myObj = new Scanner(System.in); - String fileName = myObj.nextLine(); - - try{ - BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); - for (Contact c: ca){ - List<String> str_array = SplitLine(c.toString(), "\n"); - writer.write(c.get_type() + "\n"); - writer.write(str_array.get(0) + "/"); - writer.write(str_array.get(1) + "/"); - writer.write(str_array.get(2) + "/"); - writer.write(str_array.get(3) + "/"); - writer.write(str_array.get(4) + "/"); - writer.write(str_array.get(5) + "/"); - writer.write(str_array.get(6)); - if(c.get_type().equals("Family") || c.get_type().equals("Professional")){ - writer.write("/" + str_array.get(7) + "\n"); - } - } - writer.close(); - } catch (IOException e){ - e.printStackTrace(); - } - } - //TODO find good way to save - //Warning list - //Type of contact - public static void Import(ArrayList<Contact> ca){ - System.out.println("Enter save file name"); - Scanner myObj = new Scanner(System.in); - String fileName = myObj.nextLine(); - try{ - BufferedReader reader = new BufferedReader(new FileReader(fileName)); - String line; - int checker = 0; - while((line = reader.readLine()) != null){ - switch (line){ - case "Friend": - checker = 1; - break; - case "Family": - checker = 2; - break; - case "Professional": - checker = 3; - break; - default: - List<String> str_array = SplitLine(line, "/"); - AddContactToList(str_array, checker); - checker = 0; - break; - } - } - reader.close(); - } catch (IOException e){ - e.printStackTrace(); - } - } - //Test if the value is a number or not and if it's withing the range of the list - public static boolean TryNumber(String nb){ - int size_array = contactArray.size(); - int nbInt = 0; - try{ - nbInt = Integer.parseInt(nb); - } - catch (NumberFormatException e){ - - } - return (nbInt < size_array); - } - - public static void AddContactToList(List<String> str_array, int checker){ - switch (checker){ - case 1: - ImportFriend(str_array); - break; - case 2: - ImportFamily(str_array); - break; - case 3: - ImportProfessional(str_array); - break; - default: - System.out.println("Error contact type"); - break; - } - } - public static void ImportFriend(List<String> str_array){ - Friend f = new Friend( - SplitArray(str_array.get(0)), - str_array.get(1), - str_array.get(2), - SplitArray(str_array.get(3)), - SplitArray(str_array.get(4)), - SplitArray(str_array.get(5)), - str_array.get(6) - ); - Add(f); - } - public static void ImportFamily(List<String> str_array){ - Family f = new Family( - SplitArray(str_array.get(0)), - str_array.get(1), - str_array.get(2), - SplitArray(str_array.get(3)), - SplitArray(str_array.get(4)), - SplitArray(str_array.get(5)), - str_array.get(6), - str_array.get(7) - ); - Add(f); - } - public static void ImportProfessional(List<String> str_array){ - Professional f = new Professional( - SplitArray(str_array.get(0)), - str_array.get(1), - str_array.get(2), - SplitArray(str_array.get(3)), - SplitArray(str_array.get(4)), - SplitArray(str_array.get(5)), - str_array.get(6), - str_array.get(7) - ); - Add(f); - } - public static List<String> SplitLine(String str, String splitter){ - List<String> data = Arrays.asList(str.split(splitter)); - return data; - } - public static List<String> SplitArray(String str){ - //str = str.substring(1, str.length() - 1); - String new_str = ""; - for(char c: str.toCharArray()){ - if(c !='[' && c !=']'){ - new_str += c; - } - } - List<String> names = Arrays.asList(new_str.split(",")); - return names; - } -} \ No newline at end of file diff --git a/tp/src/main/resources/com/example/tpfx/hello-view.fxml b/tp/src/main/resources/com/example/tpfx/hello-view.fxml new file mode 100644 index 0000000000000000000000000000000000000000..682a327e1c4dce96a0114ed849888b3b79fd3433 --- /dev/null +++ b/tp/src/main/resources/com/example/tpfx/hello-view.fxml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + Copyright (c) 2015, 2019, Gluon and/or its affiliates. + All rights reserved. Use is subject to license terms. + + This file is available and licensed under the following license: + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + - Neither the name of Oracle Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> + +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.ComboBox?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.ListView?> +<?import javafx.scene.control.TextField?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.VBox?> + +<VBox prefHeight="624.0" prefWidth="905.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.tpfx.HelloController"> + <children> + <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="532.0" prefWidth="817.0" VBox.vgrow="ALWAYS"> + <children> + <ListView fx:id="LstCt" layoutX="427.0" layoutY="38.0" onMouseClicked="#Selected" prefHeight="489.0" prefWidth="384.0" /> + <Button fx:id="btnAdd" layoutX="229.0" layoutY="51.0" mnemonicParsing="false" onAction="#AddCt" prefHeight="24.0" prefWidth="62.0" text="Add" /> + <TextField fx:id="txtFirst" layoutX="32.0" layoutY="52.0" /> + <Label layoutX="230.0" layoutY="300.0" text="First Name" /> + <TextField fx:id="txtLast" layoutX="32.0" layoutY="107.0" /> + <Label layoutX="32.0" layoutY="85.0" text="Last Name" /> + <TextField fx:id="txtAdd" layoutX="32.0" layoutY="162.0" /> + <Label layoutX="32.0" layoutY="140.0" text="Address" /> + <TextField fx:id="txtPhone" layoutX="32.0" layoutY="216.0" /> + <Label layoutX="32.0" layoutY="194.0" text="Phones" /> + <TextField fx:id="txtEmail" layoutX="32.0" layoutY="270.0" /> + <Label layoutX="32.0" layoutY="248.0" text="Emails" /> + <TextField fx:id="txtSocial" layoutX="32.0" layoutY="322.0" /> + <Label layoutX="32.0" layoutY="300.0" text="Socials" /> + <TextField fx:id="txtJob" layoutX="32.0" layoutY="374.0" /> + <Label layoutX="32.0" layoutY="352.0" text="Job" /> + <TextField fx:id="txtOther" layoutX="32.0" layoutY="491.0" /> + <Label fx:id="lblOther" layoutX="32.0" layoutY="467.0" prefHeight="16.0" prefWidth="78.0" text="Depends" /> + <Label layoutX="37.0" layoutY="412.0" text="Type" /> + <Button fx:id="btnSave" layoutX="229.0" layoutY="88.0" mnemonicParsing="false" onAction="#ExportCt" prefHeight="24.0" prefWidth="62.0" text="Save" /> + <Button fx:id="btnLoad" layoutX="229.0" layoutY="127.0" mnemonicParsing="false" onAction="#ImportCt" prefHeight="24.0" prefWidth="62.0" text="Load" /> + <ComboBox fx:id="cbxType" layoutX="35.0" layoutY="437.0" onAction="#ChangeType" prefHeight="24.0" prefWidth="171.0" /> + <TextField fx:id="txtSearch" layoutX="229.0" layoutY="322.0" /> + <Label layoutX="36.0" layoutY="32.0" text="First Names" /> + <Button fx:id="btnSearch" layoutX="230.0" layoutY="359.0" mnemonicParsing="false" onAction="#Search" prefHeight="24.0" prefWidth="70.0" text="Search" /> + <Button fx:id="btnDelete" layoutX="230.0" layoutY="198.0" mnemonicParsing="false" onAction="#Delete" prefHeight="24.0" prefWidth="62.0" text="Delete" /> + <Button fx:id="btnEdit" layoutX="230.0" layoutY="162.0" mnemonicParsing="false" onAction="#Edit" prefHeight="24.0" prefWidth="62.0" text="Edit" /> + <Button fx:id="btnALl" layoutX="230.0" layoutY="236.0" mnemonicParsing="false" onAction="#ShowAll" prefHeight="24.0" prefWidth="62.0" text="All" /> + </children> + </AnchorPane> + </children> +</VBox>