diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..c1dd12f Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..22f219d --- /dev/null +++ b/.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 diff --git a/Images/FondoApp.png b/Images/FondoApp.png new file mode 100644 index 0000000..34547a5 Binary files /dev/null and b/Images/FondoApp.png differ diff --git a/Images/elrondIcon.jpg b/Images/elrondIcon.jpg new file mode 100644 index 0000000..3977938 Binary files /dev/null and b/Images/elrondIcon.jpg differ diff --git a/Images/maiarIcon.jpg b/Images/maiarIcon.jpg new file mode 100644 index 0000000..f380af2 Binary files /dev/null and b/Images/maiarIcon.jpg differ diff --git a/Images/nonenft.jpg b/Images/nonenft.jpg new file mode 100644 index 0000000..734a690 Binary files /dev/null and b/Images/nonenft.jpg differ diff --git a/Images/question.png b/Images/question.png new file mode 100644 index 0000000..8648195 Binary files /dev/null and b/Images/question.png differ diff --git a/Video/nftVideo0.mp4 b/Video/nftVideo0.mp4 new file mode 100644 index 0000000..210d885 Binary files /dev/null and b/Video/nftVideo0.mp4 differ diff --git a/Video/nftVideo1.mp4 b/Video/nftVideo1.mp4 new file mode 100644 index 0000000..210d885 Binary files /dev/null and b/Video/nftVideo1.mp4 differ diff --git a/Video/nftVideo2.mp4 b/Video/nftVideo2.mp4 new file mode 100644 index 0000000..6fc6b2a Binary files /dev/null and b/Video/nftVideo2.mp4 differ diff --git a/Video/nftVideo3.mp4 b/Video/nftVideo3.mp4 new file mode 100644 index 0000000..28dd184 Binary files /dev/null and b/Video/nftVideo3.mp4 differ diff --git a/Video/nftVideo4.mp4 b/Video/nftVideo4.mp4 new file mode 100644 index 0000000..28dd184 Binary files /dev/null and b/Video/nftVideo4.mp4 differ diff --git a/Video/nftVideo5.mp4 b/Video/nftVideo5.mp4 new file mode 100644 index 0000000..6e52cde Binary files /dev/null and b/Video/nftVideo5.mp4 differ diff --git a/Video/nftVideo6.mp4 b/Video/nftVideo6.mp4 new file mode 100644 index 0000000..ce0a7b8 Binary files /dev/null and b/Video/nftVideo6.mp4 differ diff --git a/application.properties b/application.properties new file mode 100644 index 0000000..ce48a7c --- /dev/null +++ b/application.properties @@ -0,0 +1,11 @@ + +java.awt.headless=false +spring.main.web-application-type=NONE +spring.datasource.url=jdbc:mysql://localhost:3306/zpectrumbbdd +spring.datasource.username=zpectrumuser +spring.datasource.password=password +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect +spring.jpa.hibernate.ddl-auto=create-drop +server.port=8093 +spring.jpa.show-sql=true + diff --git a/lib/mysql-connector-java-8.0.22.jar b/lib/mysql-connector-java-8.0.22.jar new file mode 100644 index 0000000..412d81f Binary files /dev/null and b/lib/mysql-connector-java-8.0.22.jar differ diff --git a/miglayout-src.zip b/miglayout-src.zip new file mode 100644 index 0000000..9c51c32 Binary files /dev/null and b/miglayout-src.zip differ diff --git a/miglayout15-swing.jar b/miglayout15-swing.jar new file mode 100644 index 0000000..a6e93fb Binary files /dev/null and b/miglayout15-swing.jar differ diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..8a8fb22 --- /dev/null +++ b/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/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..1d8ab01 --- /dev/null +++ b/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/pom.xml b/pom.xml new file mode 100644 index 0000000..1700e5b --- /dev/null +++ b/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.1 + + + com.example + Zpectrum + 0.0.1-SNAPSHOT + Zpectrum + End-Degree project for Spring Boot + + 17 + + + + org.jcodec + jcodec + 0.2.3 + + + org.jcodec + jcodec-javase + 0.2.3 + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + mysql + mysql-connector-java + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + org.json + json + 20180130 + jar + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/main/java/ZpectrumApp/DTO/CryptoDTO.java b/src/main/java/ZpectrumApp/DTO/CryptoDTO.java new file mode 100644 index 0000000..a212b75 --- /dev/null +++ b/src/main/java/ZpectrumApp/DTO/CryptoDTO.java @@ -0,0 +1,114 @@ +package ZpectrumApp.DTO; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CryptoDTO { + + private long id; + @JsonProperty(value = "name") + private String cryptoName; + @JsonProperty(value = "price") + private double price; + @JsonProperty(value = "balance") + private String balance; + @JsonProperty(value = "marketCap") + private double marketcap; + @JsonProperty(value = "valueUsd") + private double valueUsd; + @JsonProperty (value ="decimals") + private int decimals; + + public double getValueUsd() { + return valueUsd; + } + + public void setValueUsd(double valueUsd) { + this.valueUsd = valueUsd; + } + + public int getDecimals() { + return decimals; + } + + public void setDecimals(int decimals) { + this.decimals = decimals; + } + + public long getId() { + return id; + } + + public String getBalance() { + return balance; + } + + public void setBalance(String balance) { + this.balance = balance; + } + + public double getMarketcap() { + return marketcap; + } + + public void setMarketcap(double marketcap) { + this.marketcap = marketcap; + } + + public double getValueUSD() { + return valueUsd; + } + + public void setValueUSD(double valueUSD) { + this.valueUsd = valueUSD; + } + + public String getCryptoName() { + return cryptoName; + } + + public void setCryptoName(String cryptoName) { + this.cryptoName = cryptoName; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public CryptoDTO(String cryptoName, double price, String balance, double marketcap, double valueUSD) { + super(); + this.cryptoName = cryptoName; + this.price = price; + this.balance = balance; + this.marketcap = marketcap; + this.valueUsd = valueUSD; + } + + public CryptoDTO(String cryptoName, double price, String balance, double marketcap, double valueUsd, int decimals) { + super(); + this.cryptoName = cryptoName; + this.price = price; + this.balance = balance; + this.marketcap = marketcap; + this.valueUsd = valueUsd; + this.decimals = decimals; + } + + public CryptoDTO() { + super(); + } + + @Override + public String toString() { + return "CryptoDTO [id=" + id + ", cryptoName=" + cryptoName + ", price=" + price + ", balance=" + balance + + ", marketcap=" + marketcap + ", valueUsd=" + valueUsd + ", decimals=" + decimals + "]"; + } + + + +} diff --git a/src/main/java/ZpectrumApp/DTO/NftDTO.java b/src/main/java/ZpectrumApp/DTO/NftDTO.java new file mode 100644 index 0000000..d7c9e83 --- /dev/null +++ b/src/main/java/ZpectrumApp/DTO/NftDTO.java @@ -0,0 +1,74 @@ +package ZpectrumApp.DTO; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class NftDTO { + + private long nftId; + @JsonProperty(value = "name") + private String nftName; + @JsonProperty(value = "collection") + private String colletionName; + @JsonProperty(value = "royalties") + private int royalties; + @JsonProperty(value = "url") + private String nftUrl; + + public long getNftId() { + return nftId; + } + + public String getNftName() { + return nftName; + } + + public void setNftName(String nftName) { + this.nftName = nftName; + } + + public String getColletionName() { + return colletionName; + } + + public void setColletionName(String colletionName) { + this.colletionName = colletionName; + } + + public int getRoyalties() { + return royalties; + } + + public void setRoyalties(int royalties) { + this.royalties = royalties; + } + + public String getNftUrl() { + return nftUrl; + } + + public void setNftUrl(String nftUrl) { + this.nftUrl = nftUrl; + } + + public NftDTO(long nftId, String nftName, String colletionName, int royalties, String nftUrl) { + super(); + this.nftId = nftId; + this.nftName = nftName; + this.colletionName = colletionName; + this.royalties = royalties; + this.nftUrl = nftUrl; + } + + public NftDTO() { + super(); + } + + @Override + public String toString() { + return "NftDTO [nftId=" + nftId + ", nftName=" + nftName + ", colletionName=" + colletionName + ", royalties=" + + royalties + ", nftUrl=" + nftUrl + "]"; + } + +} diff --git a/src/main/java/ZpectrumApp/DTO/UsuarioDTO.java b/src/main/java/ZpectrumApp/DTO/UsuarioDTO.java new file mode 100644 index 0000000..787a8fc --- /dev/null +++ b/src/main/java/ZpectrumApp/DTO/UsuarioDTO.java @@ -0,0 +1,66 @@ +package ZpectrumApp.DTO; + +public class UsuarioDTO { + + private long userId; + private String userName; + private String erd; + private double balance; + private int shard; + + public long getUserId() { + return userId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getErd() { + return erd; + } + + public void setErd(String erd) { + this.erd = erd; + } + + public double getBalance() { + return balance; + } + + public void setBalance(double balance) { + this.balance = balance; + } + + public int getShard() { + return shard; + } + + public void setShard(int shard) { + this.shard = shard; + } + + public UsuarioDTO(long userId, String userName, String erd, double balance, int shard) { + super(); + this.userId = userId; + this.userName = userName; + this.erd = erd; + this.balance = balance; + this.shard = shard; + } + + public UsuarioDTO() { + super(); + } + + @Override + public String toString() { + return "UsuarioDTO [userId=" + userId + ", userName=" + userName + ", erd=" + erd + ", balance=" + balance + + ", shard=" + shard + "]"; + } + +} diff --git a/src/main/java/ZpectrumApp/EventHandler/EventsHandlerMainWindow.java b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerMainWindow.java new file mode 100644 index 0000000..da5fc2a --- /dev/null +++ b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerMainWindow.java @@ -0,0 +1,144 @@ +package ZpectrumApp.EventHandler; + +import java.awt.CardLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import javax.swing.JMenu; +import javax.swing.JOptionPane; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; +import ZpectrumApp.Peticiones.Peticiones; +import ZpectrumApp.Vista.MainWindow; + +public class EventsHandlerMainWindow extends ComponentAdapter implements ActionListener, MenuListener { + + private Peticiones peticiones; + private MainWindow mainWindow; + private CardLayout cardLayout; + + public EventsHandlerMainWindow(MainWindow mainWindow, Peticiones peticiones) { + super(); + this.peticiones = peticiones; + this.mainWindow = mainWindow; + } + + public MainWindow getMainWindow() { + return mainWindow; + } + + public void MouseClicked(MouseEvent e) { + + } + + @Override + public void actionPerformed(ActionEvent e) { + /* + * if(e.getSource() == mainWindow.getItemHome()) { System.out.println("anña"); + * JOptionPane.showMessageDialog(mainWindow, + * "Eggs are not supposed to be green."); } + */ + if (e.getSource() == mainWindow.getHome()) { + // JOptionPane.showMessageDialog(mainWindow, "Need to login before enter"); + mainWindow.getCardLayout().show(mainWindow.getMainWindowContainer(), "Main panel container"); + mainWindow.getMaiarExchangeLabel().setText("

Maiar Exchange

"); + } + if (e.getSource() == mainWindow.getItemPortfolio()) { + if (!mainWindow.isLoggedUser()) { + JOptionPane.showMessageDialog(mainWindow, "Need to login before enter"); + } else { + cardLayout = (CardLayout) (mainWindow.getCapas().getLayout()); + mainWindow.getMaiarExchangeLabel().setText("

Portfolio

"); + cardLayout.show(mainWindow.getCapas(), "PortfolioPanel"); + System.out.println("ventana portfolio"); + } + + } + if (e.getSource() == mainWindow.getItemWatchlist()) { + if (!mainWindow.isLoggedUser()) { + JOptionPane.showMessageDialog(mainWindow, "Need to login before enter"); + } else { + cardLayout = (CardLayout) (mainWindow.getCapas().getLayout()); + mainWindow.getMaiarExchangeLabel().setText("

WatchList

"); + cardLayout.show(mainWindow.getCapas(), "WatchlistPanel"); + System.out.println("ventana watchlist"); + } + + } + + if (e.getSource() == mainWindow.getLoginButton()) { + cardLayout = (CardLayout) (mainWindow.getCapas().getLayout()); + cardLayout.show(mainWindow.getCapas(), "UserPanel"); + mainWindow.getMaiarExchangeLabel().setText("

Login Page

"); + System.out.println("ventana login"); + } + + } + + @Override + public void menuSelected(MenuEvent e) { + + if (e.getSource() == mainWindow.getHome()) { + + cardLayout = (CardLayout) (mainWindow.getCapas().getLayout()); + cardLayout.show(mainWindow.getCapas(), "MainWindowPanel"); + mainWindow.getMaiarExchangeLabel().setText("

Maiar Exchange

"); + printEcentInfo("Selected", e); + } + + if (e.getSource() == mainWindow.getLogin()) { + + cardLayout = (CardLayout) (mainWindow.getCapas().getLayout()); + cardLayout.show(mainWindow.getCapas(), "UserPanel"); + mainWindow.getMaiarExchangeLabel().setText("

Login Page

"); + System.out.println("ventana login"); + + } + if (e.getSource() == mainWindow.getLogout()) { + int reply = JOptionPane.showConfirmDialog(null, "Do you want to close session?", "Close session", + JOptionPane.YES_NO_OPTION); + if (reply == JOptionPane.YES_OPTION) { + mainWindow.setLoggedUser(false); + mainWindow.getLogout().setVisible(false); + cardLayout = (CardLayout) (mainWindow.getCapas().getLayout()); + cardLayout.show(mainWindow.getCapas(), "UserPanel"); + mainWindow.getMaiarExchangeLabel().setText("

Login Page

"); + } + } + + } + + @Override + public void menuDeselected(MenuEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void menuCanceled(MenuEvent e) { + // TODO Auto-generated method stub + + } + + private void printEcentInfo(String cadena, MenuEvent e) { + JMenu menu = (JMenu) e.getSource(); + System.out.println("La cadena es la siguiente: " + menu.getText()); + } + + @Override + public void componentResized(ComponentEvent e) { + if (mainWindow.getContentPane().getBounds().width > mainWindow.getContentPane().getMinimumSize().width + 1550) { + Border b = new EmptyBorder(130, 0, 0, 0); + mainWindow.getContainer().setBorder(b); + } + if (mainWindow.getContentPane().getBounds().width < mainWindow.getContentPane().getMinimumSize().width + 1550) { + Border b = new EmptyBorder(0, 0, 0, 0); + mainWindow.getContainer().setBorder(b); + } + } + +} diff --git a/src/main/java/ZpectrumApp/EventHandler/EventsHandlerPortfolio.java b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerPortfolio.java new file mode 100644 index 0000000..b017d48 --- /dev/null +++ b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerPortfolio.java @@ -0,0 +1,60 @@ +package ZpectrumApp.EventHandler; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.datatransfer.Clipboard; +import java.awt.*; + +import javax.swing.JOptionPane; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; +import java.awt.datatransfer.StringSelection; +import ZpectrumApp.Modelo.Usuario; +import ZpectrumApp.Peticiones.Peticiones; +import ZpectrumApp.Repositorio.UsuarioRepositorio; +import ZpectrumApp.Servicio.CryptoServicioIMPL; +import ZpectrumApp.Vista.MainWindow; + +public class EventsHandlerPortfolio implements ActionListener { + + private MainWindow mainWindow; + private UsuarioRepositorio userRepository; + private Peticiones peticiones; + private Usuario user; + + public EventsHandlerPortfolio(UsuarioRepositorio userRepository, CryptoServicioIMPL servicioIMPL, Peticiones peticiones, + MainWindow mainWindow) { + super(); + this.mainWindow = mainWindow; + this.userRepository = userRepository; + this.peticiones = peticiones; + } + + public MainWindow getMainWindow() { + return mainWindow; + } + + + @Override + public void actionPerformed(ActionEvent e) { + if(e.getSource() == mainWindow.getPortfolioPanel().getCopyBtn()) { + String str = mainWindow.getUser().getErd(); + Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringSelection strSel = new StringSelection(str); + cb.setContents(strSel, null); + JOptionPane.showMessageDialog(null, "Address copied"); + } + if(e.getSource() == mainWindow.getPortfolioPanel().getUpdateBtn()) { + + } + + + } + + + +} diff --git a/src/main/java/ZpectrumApp/EventHandler/EventsHandlerUser.java b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerUser.java new file mode 100644 index 0000000..3f1ded5 --- /dev/null +++ b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerUser.java @@ -0,0 +1,250 @@ +package ZpectrumApp.EventHandler; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.Desktop; +import java.awt.Font; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import javax.swing.JOptionPane; +import javax.swing.event.MouseInputListener; +import ZpectrumApp.DTO.CryptoDTO; +import ZpectrumApp.DTO.NftDTO; +import ZpectrumApp.Modelo.Crypto; +import ZpectrumApp.Modelo.Nft; +import ZpectrumApp.Modelo.Usuario; +import ZpectrumApp.Peticiones.Peticiones; +import ZpectrumApp.Repositorio.UsuarioRepositorio; +import ZpectrumApp.Servicio.CryptoServicioIMPL; +import ZpectrumApp.Vista.MainWindow; + +public class EventsHandlerUser implements ActionListener, MouseInputListener { + + private UsuarioRepositorio userRepository; + private CryptoServicioIMPL servicioIMPL; + private Peticiones peticiones; + private MainWindow mainWindow; + private Usuario user; + + public EventsHandlerUser(UsuarioRepositorio userRepository, CryptoServicioIMPL servicioIMPL, Peticiones peticiones, + MainWindow mainWindow) { + super(); + this.userRepository = userRepository; + this.servicioIMPL = servicioIMPL; + this.peticiones = peticiones; + this.mainWindow = mainWindow; + } + + public MainWindow getMainWindow() { + return mainWindow; + } + + @Override + public void actionPerformed(ActionEvent e) { + + if (e.getSource() == mainWindow.getUserPanel().getjBtnRegister()) { + + if (!mainWindow.getUserPanel().getUsersJList().isSelectionEmpty()) { + userLoggin(); + } else { + + if (mainWindow.getUserPanel().getjTextFUserName().getText().length() == 0 + || mainWindow.getUserPanel().getjTxtFERD().getText().length() != 62) { + JOptionPane.showMessageDialog(null, "The user name or erd is empty or not correct"); + } else { + + if (peticiones.connectionTest(mainWindow.getUserPanel().getjTxtFERD().getText())) { + + Usuario user = new Usuario(); + userParameters(user); + List lista = userRepository.findByerd(user.getErd()); + + if (!lista.isEmpty()) { + + JOptionPane.showMessageDialog(null, "Login Succesfull"); + mainWindow.getUserPanel().updateList(); + mainWindow.setLoggedUser(true); + mainWindow.setUser(user); + mainWindow.getLogout().setVisible(true); + mainWindow.makePanels(); + + } else { + try { + + userRepository.save(user); + JOptionPane.showMessageDialog(null, "User saved"); + mainWindow.getUserPanel().updateList(); + mainWindow.setLoggedUser(true); + mainWindow.getLogout().setVisible(true); + mainWindow.setUser(user); + mainWindow.makePanels(); + + } catch (Exception e2) { + System.out.println(e2.getMessage()); + e2.printStackTrace(); + } + } + + clearForm(); + + } else { + JOptionPane.showMessageDialog(null, "ERD addres is not correct"); + } + + } + } + + } + + if (e.getSource() == mainWindow.getUserPanel().getjBtnDelete()) { + if (mainWindow.getUserPanel().getUsersJList().isSelectionEmpty()) { + JOptionPane.showMessageDialog(null, "You must select an user before"); + } + if (mainWindow.getUserPanel().getUsersJList().getSelectedValue() == "No hay usuarios registrados") { + try { + JOptionPane.showMessageDialog(null, "You must select an user before"); + } catch (NullPointerException e2) { + System.out.println("No hay usuarios por lo que usuario es null"); + } + + } else { + if (!mainWindow.getUserPanel().getUsersJList().isSelectionEmpty()) { + deleteUser(); + } + } + + } + if (e.getSource() == mainWindow.getUserPanel().getjBtnCreate()) { + linkToBrowse("https://wallet.elrond.com/"); + } + + }// Action + + public void deleteUser() { + try { + user = null; + user = userRepository.findByuserName(mainWindow.getUserPanel().getUsersJList().getSelectedValue()); + userRepository.delete(user); + mainWindow.getUserPanel().updateList(); + JOptionPane.showMessageDialog(null, "User deleted"); + } catch (Exception e2) { + System.out.println(e2.getMessage()); + e2.printStackTrace(); + } + } + + public void userLoggin() { + try { + user = null; + user = userRepository.findByuserName(mainWindow.getUserPanel().getUsersJList().getSelectedValue()); + if (user == null) { + JOptionPane.showMessageDialog(null, "there is no users"); + } else { + mainWindow.setLoggedUser(true); + mainWindow.setUser(user); + mainWindow.getLogout().setVisible(true); + JOptionPane.showMessageDialog(null, "User logged"); + // TODO volver a pintar las ventanas de PORTFOLIO y WATCHLIST con el usuario + // registrado + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } + + public void linkToBrowse(String linkToEnter) { + Desktop enlace = Desktop.getDesktop(); + try { + enlace.browse(new URI(linkToEnter)); + } catch (IOException | URISyntaxException e) { + e.getMessage(); + } + } + + private void userParameters(Usuario user) { + + List cryptoList = peticiones.obtainTokensAccount(mainWindow.getUserPanel().getjTxtFERD().getText()); + List finalCryptoList = new ArrayList(); + List nftList = peticiones.obtainNftAccount(mainWindow.getUserPanel().getjTxtFERD().getText()); + List finalNftList = new ArrayList(); + + user.setUserName(mainWindow.getUserPanel().getjTextFUserName().getText()); + user.setErd(mainWindow.getUserPanel().getjTxtFERD().getText()); + user.setBalance(peticiones.obtainBalanceAccount(mainWindow.getUserPanel().getjTxtFERD().getText())); + user.setShard(peticiones.getShard(mainWindow.getUserPanel().getjTxtFERD().getText())); + for (CryptoDTO crypto : cryptoList) { + finalCryptoList.add(servicioIMPL.mapearEntidad(crypto)); + } + for (Crypto crypto : finalCryptoList) { + crypto.setOwner(user); + } + user.setCryptoList(finalCryptoList); + + for (NftDTO nft : nftList) { + finalNftList.add(servicioIMPL.mapearNft(nft)); + } + for (Nft nft : finalNftList) { + nft.setUserName(user); + } + user.setNftList(finalNftList); + + } + + private void clearForm() { + + mainWindow.getUserPanel().getjTextFUserName().setText(""); + mainWindow.getUserPanel().getjTxtFERD().setText(""); + + } + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + + mainWindow.getUserPanel().getjLblNewHelpText().setVisible(true); + + } + + @Override + public void mouseExited(MouseEvent e) { + + mainWindow.getUserPanel().getjLblNewHelpText().setVisible(false); + + } + + @Override + public void mouseDragged(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseMoved(MouseEvent e) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/ZpectrumApp/EventHandler/EventsHandlerWatchlist.java b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerWatchlist.java new file mode 100644 index 0000000..976ea26 --- /dev/null +++ b/src/main/java/ZpectrumApp/EventHandler/EventsHandlerWatchlist.java @@ -0,0 +1,73 @@ +package ZpectrumApp.EventHandler; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +import javax.swing.JOptionPane; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; +import ZpectrumApp.Vista.MainWindow; +import ZpectrumApp.Vista.PortfolioPanel; +import ZpectrumApp.Vista.UserPanel; +import ZpectrumApp.Vista.WatchlistPanel; + +public class EventsHandlerWatchlist extends ComponentAdapter implements ActionListener, MenuListener { + + private MainWindow mainWindow; + + public EventsHandlerWatchlist(MainWindow mainWindow) { + super(); + + this.mainWindow = mainWindow; + + } + + public MainWindow getMainWindow() { + return mainWindow; + } + + + @Override + public void menuSelected(MenuEvent e) { + + } + + @Override + public void menuDeselected(MenuEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void menuCanceled(MenuEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void actionPerformed(ActionEvent e) { + + + } + + @Override + public void componentResized(ComponentEvent e) { + /** + if (watchlistWindow.getContentPane().getBounds().width > watchlistWindow.getContentPane().getMinimumSize().width + + 1550) { + Border b = new EmptyBorder(130, 0, 0, 0); + //watchlistWindow.getContainerWatchlist().setBorder(b); + } + if (watchlistWindow.getContentPane().getBounds().width < watchlistWindow.getContentPane().getMinimumSize().width + + 1550) { + Border b = new EmptyBorder(0, 0, 0, 0); + //watchlistWindow.getContainerWatchlist().setBorder(b); + } + **/ + } + +} diff --git a/src/main/java/ZpectrumApp/JpaController/UsuariosDAO.java b/src/main/java/ZpectrumApp/JpaController/UsuariosDAO.java new file mode 100644 index 0000000..30dd106 --- /dev/null +++ b/src/main/java/ZpectrumApp/JpaController/UsuariosDAO.java @@ -0,0 +1,28 @@ +package ZpectrumApp.JpaController; + +import java.util.List; + +import ZpectrumApp.Modelo.Usuario; +import ZpectrumApp.Repositorio.UsuarioRepositorio; + +public class UsuariosDAO { + + private UsuarioRepositorio userRepository; + + public boolean login(String name, String erd) { + boolean valor = false; + List user = userRepository.findByerd(erd); + try { + if (user!=null) { + valor = true; + return valor; + } + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + return valor; + } + +} diff --git a/src/main/java/ZpectrumApp/Modelo/Crypto.java b/src/main/java/ZpectrumApp/Modelo/Crypto.java new file mode 100644 index 0000000..49de9ad --- /dev/null +++ b/src/main/java/ZpectrumApp/Modelo/Crypto.java @@ -0,0 +1,140 @@ +package ZpectrumApp.Modelo; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.springframework.stereotype.Component; + +@Component +@Entity +@Table(name = "crypto") +public class Crypto { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long cryptoId; + + @Column(name = "cryptoName") + private String cryptoName; + + @Column(name = "balance") + private String balance; + + @Column(name = "marketcap") + private double marketcap; + + @Column(name = "valueUSD") + private double valueUSD; + + @Column(name = "price") + private double price; + + @Column(name = "decimals") + private int decimals; + + @ManyToOne(cascade = CascadeType.PERSIST) + private Usuario owner; + + public int getDecimals() { + return decimals; + } + + public void setDecimals(int decimals) { + this.decimals = decimals; + } + + public long getCryptoId() { + return cryptoId; + } + + public String getCryptoName() { + return cryptoName; + } + + public void setCryptoName(String cryptoName) { + this.cryptoName = cryptoName; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public Usuario getOwner() { + return owner; + } + + public void setOwner(Usuario owner) { + this.owner = owner; + } + + public String getBalance() { + return balance; + } + + public void setBalance(String balance) { + this.balance = balance; + } + + public double getMarketcap() { + return marketcap; + } + + public void setMarketcap(double marketcap) { + this.marketcap = marketcap; + } + + public double getValueUSD() { + return valueUSD; + } + + public void setValueUSD(double valueUSD) { + this.valueUSD = valueUSD; + } + + public Crypto(long cryptoId, String cryptoName, String balance, double marketcap, double valueUSD, double price, + Usuario owner) { + super(); + this.cryptoId = cryptoId; + this.cryptoName = cryptoName; + this.balance = balance; + this.marketcap = marketcap; + this.valueUSD = valueUSD; + this.price = price; + this.owner = owner; + } + + + public Crypto(long cryptoId, String cryptoName, String balance, double marketcap, double valueUSD, double price, + int decimals, Usuario owner) { + super(); + this.cryptoId = cryptoId; + this.cryptoName = cryptoName; + this.balance = balance; + this.marketcap = marketcap; + this.valueUSD = valueUSD; + this.price = price; + this.decimals = decimals; + this.owner = owner; + } + + public Crypto() { + super(); + } + + @Override + public String toString() { + return "Crypto [cryptoId=" + cryptoId + ", cryptoName=" + cryptoName + ", balance=" + balance + ", marketcap=" + + marketcap + ", valueUSD=" + valueUSD + ", price=" + price + ", owner=" + owner + "]"; + } + +} diff --git a/src/main/java/ZpectrumApp/Modelo/Nft.java b/src/main/java/ZpectrumApp/Modelo/Nft.java new file mode 100644 index 0000000..ef3d782 --- /dev/null +++ b/src/main/java/ZpectrumApp/Modelo/Nft.java @@ -0,0 +1,115 @@ +package ZpectrumApp.Modelo; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.springframework.stereotype.Component; + +@Component +@Entity +@Table(name = "nft") +public class Nft { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long nftId; + + @Column(name = "nftName") + private String nftName; + + @Column(name = "colletionName") + private String colletionName; + + @Column(name = "royalties") + private int royalties; + + @Column(name = "nftUrl") + private String nftUrl; + + @Lob + @Column(name = "nftImage") + private byte[] nftImage; + + @ManyToOne(cascade = CascadeType.PERSIST) + private Usuario userName; + + public byte[] getNftImage() { + return nftImage; + } + + public void setNftImage(byte[] nftImage) { + this.nftImage = nftImage; + } + + public long getNftId() { + return nftId; + } + + public String getNftName() { + return nftName; + } + + public void setNftName(String nftName) { + this.nftName = nftName; + } + + public String getColletionName() { + return colletionName; + } + + public void setColletionName(String colletionName) { + this.colletionName = colletionName; + } + + public int getRoyalties() { + return royalties; + } + + public void setRoyalties(int royalties) { + this.royalties = royalties; + } + + public String getNftUrl() { + return nftUrl; + } + + public void setNftUrl(String nftUrl) { + this.nftUrl = nftUrl; + } + + public Usuario getUserName() { + return userName; + } + + public void setUserName(Usuario userName) { + this.userName = userName; + } + + public Nft(long nftId, String nftName, String colletionName, int royalties, String nftUrl, Usuario userName) { + super(); + this.nftId = nftId; + this.nftName = nftName; + this.colletionName = colletionName; + this.royalties = royalties; + this.nftUrl = nftUrl; + this.userName = userName; + } + + public Nft() { + super(); + } + + @Override + public String toString() { + return "Nft [nftId=" + nftId + ", nftName=" + nftName + ", colletionName=" + colletionName + ", royalties=" + + royalties + ", nftUrl=" + nftUrl + ", userName=" + userName + "]"; + } + +} diff --git a/src/main/java/ZpectrumApp/Modelo/TokensMaiar.java b/src/main/java/ZpectrumApp/Modelo/TokensMaiar.java new file mode 100644 index 0000000..3d7aa26 --- /dev/null +++ b/src/main/java/ZpectrumApp/Modelo/TokensMaiar.java @@ -0,0 +1,45 @@ +package ZpectrumApp.Modelo; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class TokensMaiar { + + @JsonProperty(value = "name") + private String name; + @JsonProperty(value = "price") + private double price; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public TokensMaiar(String name, double price) { + super(); + this.name = name; + this.price = price; + } + + public TokensMaiar() { + super(); + } + + @Override + public String toString() { + return "TokensMaiar [name=" + name + ", price=" + price + "]"; + } + +} diff --git a/src/main/java/ZpectrumApp/Modelo/Usuario.java b/src/main/java/ZpectrumApp/Modelo/Usuario.java new file mode 100644 index 0000000..dc158e7 --- /dev/null +++ b/src/main/java/ZpectrumApp/Modelo/Usuario.java @@ -0,0 +1,116 @@ +package ZpectrumApp.Modelo; + + +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import org.springframework.stereotype.Component; + +@Component +@Entity +@Table(name = "user", uniqueConstraints = { @UniqueConstraint(columnNames = { "erd" }) }) +public class Usuario { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long userId; + + @Column(name = "userName") + private String userName; + + @Column(name = "erd") + private String erd; + + @Column(name = "balance") + private double balance; + + @Column(name = "shard") + private int shard; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.LAZY) + private List cryptoList; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "userName", fetch = FetchType.LAZY) + private List nftList; + + public double getBalance() { + return balance; + } + + public void setBalance(double balance) { + this.balance = balance; + } + + public int getShard() { + return shard; + } + + public void setShard(int shard) { + this.shard = shard; + } + + public long getUserId() { + return userId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getErd() { + return erd; + } + + public void setErd(String erd) { + this.erd = erd; + } + + public List getCryptoList() { + return cryptoList; + } + + public void setCryptoList(List cryptoList) { + this.cryptoList = cryptoList; + } + + public List getNftList() { + return nftList; + } + + public void setNftList(List nftList) { + this.nftList = nftList; + } + + public Usuario(String userName, String erd, double balance, int shard, List cryptoList, List nftList) { + super(); + this.userName = userName; + this.erd = erd; + this.balance = balance; + this.shard = shard; + this.cryptoList = cryptoList; + this.nftList = nftList; + } + + public Usuario() { + super(); + } + + @Override + public String toString() { + return "Usuario [userId=" + userId + ", userName=" + userName + ", erd=" + erd + ", balance=" + balance + + ", shard=" + shard + ", cryptoList=" + cryptoList + ", nftList=" + nftList + "]"; + } + +} diff --git a/src/main/java/ZpectrumApp/Peticiones/Peticiones.java b/src/main/java/ZpectrumApp/Peticiones/Peticiones.java new file mode 100644 index 0000000..67ae080 --- /dev/null +++ b/src/main/java/ZpectrumApp/Peticiones/Peticiones.java @@ -0,0 +1,415 @@ +package ZpectrumApp.Peticiones; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import org.json.JSONObject; +import org.springframework.stereotype.Service; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import ZpectrumApp.DTO.CryptoDTO; +import ZpectrumApp.DTO.NftDTO; +import ZpectrumApp.Modelo.TokensMaiar; + +@Service +public class Peticiones { + + private static String accountApiElrond = "https://api.elrond.com/accounts/"; + private static String accountApiElrondMaiarExchange = "https://api.elrond.com/mex/tokens"; + private static String accountApiElrondBalance = "https://api.elrond.com/address/"; + private static ObjectMapper mapper = new ObjectMapper(); + + public boolean connectionTest(String erd) { + requestReset(); + String consulta = accountApiElrond; + consulta += erd + "/tokens"; + URL url; + try { + url = new URL(consulta); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + if (connection.getResponseCode() == 200) { + return true; + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return false; + } + + public List obtainTokensAccount(String erd) { + + requestReset(); + String consulta = accountApiElrond; + consulta += erd + "/tokens"; + StringBuilder constructor = new StringBuilder(); + List cryptoList = new ArrayList(); + String line = ""; + String process = ""; + + try { + + URL url = new URL(consulta); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + while ((line = rd.readLine()) != null) { + + constructor.append(line); + + } + + process = constructor.toString(); + rd.close(); + + try { + cryptoList = mapper.readValue(process, + mapper.getTypeFactory().constructCollectionType(List.class, CryptoDTO.class)); + } + + catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + for (CryptoDTO cryptoDTO : cryptoList) { + + String balance = cryptoDTO.getBalance(); + + if (balance.length() > cryptoDTO.getDecimals()) { + + String part1 = balance.substring(0, (balance.length() - cryptoDTO.getDecimals())); + String part2 = balance.substring(balance.length() - cryptoDTO.getDecimals(), balance.length()); + String finalString = part1 + "." + part2; + cryptoDTO.setBalance(finalString); + + } else { + // TODO cuando el balance es < 0 + if (cryptoDTO.getDecimals() - balance.length() == 0) { + + String finalString = "0." + cryptoDTO.getBalance(); + cryptoDTO.setBalance(finalString); + + } else { + String finalString = "0."; + String process2 = ""; + int firstPosition = cryptoDTO.getDecimals() - balance.length(); + int[] ceros = new int[firstPosition]; + for (int i = 0; i < ceros.length; i++) { + ceros[i] = 0; + process2 += ceros[i]; + } + finalString += process2 + cryptoDTO.getBalance(); + cryptoDTO.setBalance(finalString); + } + + } + } + + return cryptoList; + } + + public List obtainNftAccount(String erd) { + + requestReset(); + int numberOfNft = numberOfNft(erd); + String consulta = accountApiElrond; + consulta += erd + "/nfts?size=" + numberOfNft; + String line = ""; + String process = ""; + List nfts = null; + StringBuilder constructor = new StringBuilder(); + + try { + + URL url = new URL(consulta); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + while ((line = rd.readLine()) != null) { + + constructor.append(line); + + } + + process = constructor.toString(); + rd.close(); + + try { + + nfts = mapper.readValue(process, + mapper.getTypeFactory().constructCollectionType(List.class, NftDTO.class)); + + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + return nfts; + } + + public int obtainNumberOfNft(String erd) { + + requestReset(); + String consulta = accountApiElrond; + consulta += erd + "/nfts/count"; + String line = ""; + String process = ""; + int result = 0; + StringBuilder constructor = new StringBuilder(); + + try { + + URL url = new URL(consulta); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + while ((line = rd.readLine()) != null) { + + constructor.append(line); + + } + + process = constructor.toString(); + + try { + + result = mapper.readValue(process, + mapper.getTypeFactory().constructCollectionType(List.class, Integer.class)); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + return result; + + } + + public List tokensOnMaiar() { + + String line = ""; + String process = ""; + List tokens = null; + StringBuilder constructor = new StringBuilder(); + + try { + + URL url = new URL(accountApiElrondMaiarExchange); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + while ((line = rd.readLine()) != null) { + + constructor.append(line); + + } + + process = constructor.toString(); + + try { + + tokens = mapper.readValue(process, + mapper.getTypeFactory().constructCollectionType(List.class, TokensMaiar.class)); + + return tokens; + + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + return null; + } + + public double obtainBalanceAccount(String erd) { + + requestReset(); + String consulta = accountApiElrondBalance; + consulta += erd + "/balance"; + int contador = 19; + int contador2 = 0; + double response = 0.0; + String process3 = ""; + String decimals = ""; + String numbers = ""; + String line; + String holder; + String process1 = ""; + String process2 = "0."; + + try { + + URL url = new URL(consulta); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + + while ((line = rd.readLine()) != null) { + + process3 += line; + + } + + // la variable proceso es un String con formato Json + JSONObject json = new JSONObject(process3); + System.out.println(process3); + // Obtenemos la propiedad dentro de una rama del json + holder = json.getJSONObject("data").getString("balance"); + + if (holder.length() < 18) { + do { + process1 += "0"; + } while ((holder.length() + process1.length()) < 18); + process1 += holder; + + process2 += process1; + double respuesta = Double.parseDouble(process2); + + return respuesta; + } + + if (holder.length() >= 18) { + for (int i = holder.length(); i >= 0; i--) { + contador2++; + + // substring con la parte decimal + if (contador == contador2) { + decimals += holder.substring(i); + } + // substring con la parte entera + if (contador2 >= contador) { + numbers += holder.substring(0, i); + } + + } + + String devolucion = numbers + "." + decimals; + response = Double.parseDouble(devolucion); + + } + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + return response; + + } + + public int getShard(String erd) { + + requestReset(); + String consulta = accountApiElrond; + String proceso = ""; + String linea; + int response = 0; + consulta += erd; + + try { + + URL url = new URL(consulta); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + + while ((linea = rd.readLine()) != null) { + + proceso += linea; + + } + + // la variable proceso es un String con formato Json + JSONObject json = new JSONObject(proceso); + System.out.println(proceso); + // Obtenemos la propiedad dentro de una rama del json + response = json.getInt("shard"); + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + return response; + } + + private int numberOfNft(String erd) { + requestReset(); + String consulta = accountApiElrond; + String proceso = ""; + String linea; + int response = 0; + consulta += erd + "/nfts/count"; + + try { + + URL url = new URL(consulta); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + + while ((linea = rd.readLine()) != null) { + + proceso += linea; + + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + response = Integer.parseInt(proceso); + + return response; + } + + private static void requestReset() { + accountApiElrond = "https://api.elrond.com/accounts/"; + accountApiElrondBalance = "https://api.elrond.com/address/"; + } + +} diff --git a/src/main/java/ZpectrumApp/Repositorio/CryptoRepositorio.java b/src/main/java/ZpectrumApp/Repositorio/CryptoRepositorio.java new file mode 100644 index 0000000..ba7b2e2 --- /dev/null +++ b/src/main/java/ZpectrumApp/Repositorio/CryptoRepositorio.java @@ -0,0 +1,11 @@ +package ZpectrumApp.Repositorio; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import ZpectrumApp.Modelo.Crypto; + +@Repository +public interface CryptoRepositorio extends JpaRepository{ + +} diff --git a/src/main/java/ZpectrumApp/Repositorio/NftRepositorio.java b/src/main/java/ZpectrumApp/Repositorio/NftRepositorio.java new file mode 100644 index 0000000..c7fd40e --- /dev/null +++ b/src/main/java/ZpectrumApp/Repositorio/NftRepositorio.java @@ -0,0 +1,12 @@ +package ZpectrumApp.Repositorio; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import ZpectrumApp.Modelo.Nft; + +@Repository +public interface NftRepositorio extends JpaRepository{ + + public Nft findBynftName(String nftName); + +} diff --git a/src/main/java/ZpectrumApp/Repositorio/UsuarioRepositorio.java b/src/main/java/ZpectrumApp/Repositorio/UsuarioRepositorio.java new file mode 100644 index 0000000..838f7d9 --- /dev/null +++ b/src/main/java/ZpectrumApp/Repositorio/UsuarioRepositorio.java @@ -0,0 +1,17 @@ +package ZpectrumApp.Repositorio; + + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import ZpectrumApp.Modelo.Usuario; + +@Repository +public interface UsuarioRepositorio extends JpaRepository{ + +public Usuario findByuserName(String userName); +public List findByerd(String erd); + + +} diff --git a/src/main/java/ZpectrumApp/Servicio/CryptoServicio.java b/src/main/java/ZpectrumApp/Servicio/CryptoServicio.java new file mode 100644 index 0000000..eacc923 --- /dev/null +++ b/src/main/java/ZpectrumApp/Servicio/CryptoServicio.java @@ -0,0 +1,9 @@ +package ZpectrumApp.Servicio; + +import java.util.List; +import ZpectrumApp.DTO.UsuarioDTO; + +public interface CryptoServicio { + + public List obtainAllUsers(); +} diff --git a/src/main/java/ZpectrumApp/Servicio/CryptoServicioIMPL.java b/src/main/java/ZpectrumApp/Servicio/CryptoServicioIMPL.java new file mode 100644 index 0000000..fd40b34 --- /dev/null +++ b/src/main/java/ZpectrumApp/Servicio/CryptoServicioIMPL.java @@ -0,0 +1,57 @@ +package ZpectrumApp.Servicio; + + +import java.util.ArrayList; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import ZpectrumApp.DTO.CryptoDTO; +import ZpectrumApp.DTO.NftDTO; +import ZpectrumApp.DTO.UsuarioDTO; +import ZpectrumApp.Modelo.Crypto; +import ZpectrumApp.Modelo.Nft; +import ZpectrumApp.Modelo.Usuario; +import ZpectrumApp.Peticiones.Peticiones; +import ZpectrumApp.Repositorio.UsuarioRepositorio; + +@Service +public class CryptoServicioIMPL implements CryptoServicio{ + + @Autowired + private UsuarioRepositorio usuarioRepositorio; + + //convierte DTO a entidad + public Crypto mapearEntidad(CryptoDTO cryptoDTO) { + + Crypto crypto = new Crypto(); + + crypto.setCryptoName(cryptoDTO.getCryptoName()); + crypto.setPrice(cryptoDTO.getPrice()); + crypto.setBalance(cryptoDTO.getBalance()); + crypto.setMarketcap(cryptoDTO.getMarketcap()); + crypto.setValueUSD(cryptoDTO.getValueUSD()); + + return crypto; + } + + //convierte DTO a entidad + public Nft mapearNft(NftDTO nftDTO) { + Nft nft = new Nft(); + + nft.setNftName(nftDTO.getNftName()); + nft.setColletionName(nftDTO.getColletionName()); + nft.setRoyalties(nftDTO.getRoyalties()); + nft.setNftUrl(nftDTO.getNftUrl()); + + return nft; + } + + @Override + public List obtainAllUsers() { + List listaUsuarios = usuarioRepositorio.findAll(); + return null; + } + + + +} diff --git a/src/main/java/ZpectrumApp/Test2peticionTokens.java b/src/main/java/ZpectrumApp/Test2peticionTokens.java new file mode 100644 index 0000000..b9b7a0b --- /dev/null +++ b/src/main/java/ZpectrumApp/Test2peticionTokens.java @@ -0,0 +1,91 @@ +package ZpectrumApp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import ZpectrumApp.DTO.CryptoDTO; + +public class Test2peticionTokens { + static final String accountApiElrond = "https://api.elrond.com/accounts/erd18alaelkaha93wy88w67j4e8ehq9jkd7ydnqa2g6j3627nzukgsgsj6ap3j/tokens"; + + public static void main(String[] args) { + + StringBuilder resultado = new StringBuilder(); + String proceso = ""; + List cryptos3 = null; + ObjectMapper mapper = new ObjectMapper(); + + try { + + URL url = new URL(accountApiElrond); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + String linea = ""; + + while ((linea = rd.readLine()) != null) { + + resultado.append(linea); + + } + + proceso = resultado.toString(); + + try { + cryptos3 = mapper.readValue(proceso, + mapper.getTypeFactory().constructCollectionType(List.class, CryptoDTO.class)); + + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + for (CryptoDTO cryptoDTO : cryptos3) { + System.out.println(cryptoDTO.getCryptoName()); + System.out.println(cryptoDTO.getBalance()); + String balance = cryptoDTO.getBalance(); + + if (balance.length() > cryptoDTO.getDecimals()) { + String part1 = balance.substring(0, (balance.length() - cryptoDTO.getDecimals())); + String part2 = balance.substring(balance.length() - cryptoDTO.getDecimals(), balance.length()); + + String finalString = part1 + "." + part2; + cryptoDTO.setBalance(finalString); + System.out.println(finalString); + } else { + // TODO cuando el balance es < 0 + if (cryptoDTO.getDecimals() - balance.length() == 0) { + String finalString = "0." + cryptoDTO.getBalance(); + cryptoDTO.setBalance(finalString); + System.out.println(finalString); + } else { + String finalString = "0."; + String process = ""; + int primeraPosicion = cryptoDTO.getDecimals() - balance.length(); + int[] ceros = new int[primeraPosicion]; + for (int i = 0; i < ceros.length; i++) { + ceros[i] = 0; + process += ceros[i]; + } + finalString += process + cryptoDTO.getBalance(); + cryptoDTO.setBalance(finalString); + System.out.println(finalString); + } + + } + } + } +} diff --git a/src/main/java/ZpectrumApp/Test3PeticionTokens.java b/src/main/java/ZpectrumApp/Test3PeticionTokens.java new file mode 100644 index 0000000..34dc758 --- /dev/null +++ b/src/main/java/ZpectrumApp/Test3PeticionTokens.java @@ -0,0 +1,51 @@ +package ZpectrumApp; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Iterator; + +import org.apache.tomcat.util.json.JSONParser; +import org.json.JSONArray; +import org.json.JSONObject; + +import ZpectrumApp.DTO.CryptoDTO; + +public class Test3PeticionTokens { + + static final String accountApiElrond = "https://api.elrond.com/accounts/erd18alaelkaha93wy88w67j4e8ehq9jkd7ydnqa2g6j3627nzukgsgsj6ap3j/tokens"; + + public static void main(String[] args) { + + try { + + URL url = new URL(accountApiElrond); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String proceso = ""; + StringBuilder resultado = new StringBuilder(); + + while ((proceso = rd.readLine()) != null) { + + resultado.append(proceso); + + } + rd.close(); + + + + + + + System.out.println(resultado.toString()); + + } catch (Exception e) { + // TODO: handle exception + } + + } + +} diff --git a/src/main/java/ZpectrumApp/TestImage.java b/src/main/java/ZpectrumApp/TestImage.java new file mode 100644 index 0000000..e76713a --- /dev/null +++ b/src/main/java/ZpectrumApp/TestImage.java @@ -0,0 +1,17 @@ +package ZpectrumApp; + +import javax.swing.ImageIcon; + +public class TestImage { + static final String url = "https://media.elrond.com/nfts/asset/bafybeihqjuzjukrcd7lr37o7s52l3b4poni6xyiqp3yw43syt254v2rysa/7062.png"; + public static void main(String[] args) { + + + ImageIcon image = new ImageIcon(url); + + + + + } + +} diff --git a/src/main/java/ZpectrumApp/TestPeticionBalance.java b/src/main/java/ZpectrumApp/TestPeticionBalance.java new file mode 100644 index 0000000..bfd2db1 --- /dev/null +++ b/src/main/java/ZpectrumApp/TestPeticionBalance.java @@ -0,0 +1,86 @@ +package ZpectrumApp; + +import java.io.BufferedReader; + +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.json.JSONObject; + +public class TestPeticionBalance { + + static final String accountApiElrond = "https://api.elrond.com/address/erd18alaelkaha93wy88w67j4e8ehq9jkd7ydnqa2g6j3627nzukgsgsj6ap3j/balance"; + + public static void main(String[] args) { + + String proceso = ""; + String linea; + String devolucion = ""; + String holder; + String devolucion2 = ""; + String devolucion3 = "0."; + + try { + + URL url = new URL(accountApiElrond); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + + while ((linea = rd.readLine()) != null) { + + proceso += linea; + + } + + // la variable proceso es un String con formato Json + JSONObject json = new JSONObject(proceso); + System.out.println(proceso); + // Obtenemos la propiedad dentro de una rama del json + holder = json.getJSONObject("data").getString("balance"); + System.out.println(holder.length()); + if (holder.length() < 18) { + do { + devolucion2 += "0"; + } while ((holder.length() + devolucion2.length()) < 18); + devolucion2 += holder; + } + devolucion3 += devolucion2; + double respuesta = Double.parseDouble(devolucion3); + System.out.println(respuesta);// valor a devolver + + String decimals = ""; + String numbers = ""; + int contador = 19; + int contador2 = 0; + if (holder.length() >= 18) { + for (int i = holder.length(); i >= 0; i--) { + contador2++; + + // substring con la parte decimal + if (contador == contador2) { + System.out.println(holder.substring(i)); + decimals += holder.substring(i); + } + // substring con la parte entera + if (contador2 >= contador) { + numbers += holder.substring(0, i); + } + + } + System.out.println(numbers); + devolucion += numbers + "." + decimals; + System.out.println(devolucion); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/ZpectrumApp/TestPeticionNft.java b/src/main/java/ZpectrumApp/TestPeticionNft.java new file mode 100644 index 0000000..c235cf7 --- /dev/null +++ b/src/main/java/ZpectrumApp/TestPeticionNft.java @@ -0,0 +1,61 @@ +package ZpectrumApp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; + +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import ZpectrumApp.DTO.NftDTO; + +public class TestPeticionNft { + + static final String accountApiElrond = "https://api.elrond.com/accounts/erd18alaelkaha93wy88w67j4e8ehq9jkd7ydnqa2g6j3627nzukgsgsj6ap3j/nfts"; + + public static void main(String[] args) { + + StringBuilder resultado = new StringBuilder(); + String proceso = ""; + List nfts = null; + ObjectMapper mapper = new ObjectMapper(); + + try { + + URL url = new URL(accountApiElrond); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String linea = ""; + + while ((linea = rd.readLine()) != null) { + + resultado.append(linea); + + } + + proceso = resultado.toString(); + + try { + nfts = mapper.readValue(proceso, + mapper.getTypeFactory().constructCollectionType(List.class, NftDTO.class)); + + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + for (NftDTO nft : nfts) { + System.out.println(nft); + } + + } + +} diff --git a/src/main/java/ZpectrumApp/TestPeticionShard.java b/src/main/java/ZpectrumApp/TestPeticionShard.java new file mode 100644 index 0000000..c695233 --- /dev/null +++ b/src/main/java/ZpectrumApp/TestPeticionShard.java @@ -0,0 +1,59 @@ +package ZpectrumApp; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.json.JSONObject; + +public class TestPeticionShard { + + static final String accountApiElrond = "https://api.elrond.com/accounts/erd18alaelkaha93wy88w67j4e8ehq9jkd7ydnqa2g6j3627nzukgsgsj6ap3j"; + + public static void main(String[] args) { + + + + String proceso = ""; + String linea; + String devolucion = ""; + int holder; + + try { + + URL url = new URL(accountApiElrond); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + + while ((linea = rd.readLine()) != null) { + + proceso += linea; + + } + + //la variable proceso es un String con formato Json + JSONObject json = new JSONObject(proceso); + System.out.println(proceso); + //Obtenemos la propiedad dentro de una rama del json + holder = json.getInt("shard"); + //mostramos la propiedad del Json + System.out.println(holder); + + + + + + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/ZpectrumApp/TestPeticionTokensMaiar.java b/src/main/java/ZpectrumApp/TestPeticionTokensMaiar.java new file mode 100644 index 0000000..55c8e36 --- /dev/null +++ b/src/main/java/ZpectrumApp/TestPeticionTokensMaiar.java @@ -0,0 +1,91 @@ +package ZpectrumApp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import ZpectrumApp.Modelo.TokensMaiar; + +public class TestPeticionTokensMaiar { + + static final String accountApiElrond = "https://api.elrond.com/mex/tokens"; + + public static void main(String[] args) { + StringBuilder resultado = new StringBuilder(); + String proceso = ""; + List cryptos3 = null; + ObjectMapper mapper = new ObjectMapper(); + + try { + + URL url = new URL(accountApiElrond); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + String linea = ""; + + while ((linea = rd.readLine()) != null) { + + resultado.append(linea); + + } + + proceso = resultado.toString(); + + try { + cryptos3 = mapper.readValue(proceso, + mapper.getTypeFactory().constructCollectionType(List.class, TokensMaiar.class)); + + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println(cryptos3); + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + for (TokensMaiar crypto : cryptos3) { + + + + if (crypto.toString().contains("E-")) { + + String process1 = ""; + String lastC = String.valueOf(crypto.getPrice()) + .substring(String.valueOf(crypto.getPrice()).length() - 1); + int lastCN = Integer.parseInt(lastC); + int length = lastCN; + length = length - 1; + int[] ceros = new int[length]; + for (int i = 0; i < ceros.length; i++) { + ceros[i] = 0; + process1 += ceros[i]; + } + String precio = String.valueOf(crypto.getPrice()); + process1 += precio; + String aux = process1.substring(process1.length() - 3); + process1 = process1.replace(aux, ""); + process1 = process1.replace(".", ""); + String process2 = "0."; + process2 += process1; + System.out.println(process2); + + } + + + } + + } + +} diff --git a/src/main/java/ZpectrumApp/Vista/FondoApp.java b/src/main/java/ZpectrumApp/Vista/FondoApp.java new file mode 100644 index 0000000..39de653 --- /dev/null +++ b/src/main/java/ZpectrumApp/Vista/FondoApp.java @@ -0,0 +1,42 @@ +package ZpectrumApp.Vista; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.image.BufferedImage; +import javax.swing.border.Border; + +public class FondoApp implements Border{ + + private BufferedImage mImagen = null; + + /** + * Constructor, indicamos la imagen que queremos que se redimensione + * @param pImagen ImageIO.read(new File(ruta imagen)) + */ + + public FondoApp(BufferedImage mImagen) { + super(); + this.mImagen = mImagen; + } + + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + if (mImagen != null) { + g.drawImage(mImagen, 0, 0, width, height, null); + } + } + + @Override + public Insets getBorderInsets(Component c) { + return new Insets(0, 0, 0, 0); + } + + @Override + public boolean isBorderOpaque() { + return true; + } + + + +} diff --git a/src/main/java/ZpectrumApp/Vista/JListCellRenderer.java b/src/main/java/ZpectrumApp/Vista/JListCellRenderer.java new file mode 100644 index 0000000..c1413a2 --- /dev/null +++ b/src/main/java/ZpectrumApp/Vista/JListCellRenderer.java @@ -0,0 +1,31 @@ +package ZpectrumApp.Vista; + + +import java.awt.Component; +import java.awt.Font; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; + + +@SuppressWarnings("serial") +public class JListCellRenderer extends JLabel implements ListCellRenderer { + + public JListCellRenderer() { + setOpaque(true); + } + + @Override + public Component getListCellRendererComponent(JList list, String value, int index, + boolean isSelected, boolean cellHasFocus) { + + if (isSelected) { + list.setFont(new Font("Tahoma", Font.ITALIC, 15)); + } else { + list.setFont(new Font("Tahoma", Font.PLAIN, 14)); + } + + return this; + } + +} diff --git a/src/main/java/ZpectrumApp/Vista/MainWindow.java b/src/main/java/ZpectrumApp/Vista/MainWindow.java new file mode 100644 index 0000000..86e6382 --- /dev/null +++ b/src/main/java/ZpectrumApp/Vista/MainWindow.java @@ -0,0 +1,436 @@ +package ZpectrumApp.Vista; + +import java.awt.*; +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.event.TableModelListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import ZpectrumApp.EventHandler.EventsHandlerMainWindow; +import ZpectrumApp.EventHandler.EventsHandlerPortfolio; +import ZpectrumApp.EventHandler.EventsHandlerWatchlist; +import ZpectrumApp.Modelo.TokensMaiar; +import ZpectrumApp.Modelo.Usuario; +import ZpectrumApp.Peticiones.Peticiones; +import ZpectrumApp.Repositorio.NftRepositorio; +import ZpectrumApp.Repositorio.UsuarioRepositorio; +import ZpectrumApp.Servicio.CryptoServicioIMPL; + +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JTextField; +import javax.swing.JScrollBar; +import javax.swing.JScrollPane; +import net.miginfocom.swing.MigLayout; +import java.util.List; +import javax.swing.JTable; +import javax.swing.SwingConstants; + +public class MainWindow extends JFrame implements TableModel { + + /** + * + */ + private static final long serialVersionUID = -8312087735648019235L; + + private Peticiones peticiones; + private JPanel contentPane, mainWindowContainer, capas, mainPanel; + private CardLayout cardLayout = new CardLayout(); + private JMenuBar menuBar; + private JMenu home, tools, login, logout; + private JMenuItem itemPortfolio, itemWatchlist; + private JLabel presentationJLabel2, maiarExchangeLabel; + private JButton loginButton; + private FondoApp fondo; + private Font fuente1 = new Font("Tahoma", Font.PLAIN, 22), fuenteTable = new Font("Tahoma", Font.PLAIN, 15); + private JTable table; + private UsuarioRepositorio userRepository; + private UserPanel userPanel; + private PortfolioPanel portfolioPanel; + private WatchlistPanel watchListPanel; + private Usuario user; + private CryptoServicioIMPL servicioIMPL; + private EventsHandlerPortfolio portfolioWindowHandler; + private EventsHandlerWatchlist watchlistWindowHandler; + private boolean loggedUser; + private NftRepositorio nftRepository; + + public NftRepositorio getNftRepository() { + return nftRepository; + } + + public UsuarioRepositorio getUserRepository() { + return userRepository; + } + + public Peticiones getPeticiones() { + return peticiones; + } + + public boolean isLoggedUser() { + return loggedUser; + } + + public void setLoggedUser(boolean loggedUser) { + this.loggedUser = loggedUser; + } + + public EventsHandlerPortfolio getPortfolioWindowHandler() { + return portfolioWindowHandler; + } + + public void setPortfolioWindowHandler(EventsHandlerPortfolio portfolioWindowHandler) { + this.portfolioWindowHandler = portfolioWindowHandler; + } + + public EventsHandlerWatchlist getWatchlistWindowHandler() { + return watchlistWindowHandler; + } + + public void setWatchlistWindowHandler(EventsHandlerWatchlist watchlistWindowHandler) { + this.watchlistWindowHandler = watchlistWindowHandler; + } + + public Usuario getUser() { + return user; + } + + public void setUser(Usuario user) { + this.user = user; + } + + public JMenu getLogout() { + return logout; + } + + public JPanel getCapas() { + return capas; + } + + public CardLayout getCardLayout() { + return cardLayout; + } + + public PortfolioPanel getPortfolioPanel() { + return portfolioPanel; + } + + public WatchlistPanel getWatchListPanel() { + return watchListPanel; + } + + public UserPanel getUserPanel() { + return userPanel; + } + + public JPanel getMainWindowContainer() { + return mainWindowContainer; + } + + public JLabel getMaiarExchangeLabel() { + return maiarExchangeLabel; + } + + public JLabel getPresentationJLabel2() { + return presentationJLabel2; + } + + public JPanel getContainer() { + return mainWindowContainer; + } + + public JButton getLoginButton() { + return loginButton; + } + + public JMenuItem getItemPortfolio() { + return itemPortfolio; + } + + public JMenuItem getItemWatchlist() { + return itemWatchlist; + } + + public JPanel getContentPane() { + return contentPane; + } + + public JMenu getHome() { + return home; + } + + public JMenu getTools() { + return tools; + } + + public JMenu getLogin() { + return login; + } + + public MainWindow(FondoApp fondo, Peticiones peticiones, UsuarioRepositorio userRepository, + EventsHandlerWatchlist watchlistWindowHandler, EventsHandlerPortfolio portfolioWindowHandler, + boolean loggedUser, CryptoServicioIMPL servicioIMPL, NftRepositorio nftRepository) { + this.fondo = fondo; + this.peticiones = peticiones; + this.userRepository = userRepository; + this.userPanel = new UserPanel(userRepository, this); + this.watchlistWindowHandler = watchlistWindowHandler; + this.portfolioWindowHandler = portfolioWindowHandler; + this.loggedUser = loggedUser; + this.servicioIMPL = servicioIMPL; + this.nftRepository = nftRepository; + initMenu(); + setUI(); + this.getUserPanel().updateList(); + setVisible(true); + + } + + public void initMenu() { + + menuBar = new JMenuBar(); + menuBar.setBackground(SystemColor.activeCaptionBorder); + + home = new JMenu("Home"); + tools = new JMenu("Tools"); + login = new JMenu("Login"); + logout = new JMenu("Logout"); + logout.setVisible(false); + + itemPortfolio = new JMenuItem("Portfolio"); + itemWatchlist = new JMenuItem("Watchlist"); + + tools.add(itemPortfolio); + tools.add(itemWatchlist); + + menuBar.add(home); + menuBar.add(tools); + menuBar.add(Box.createHorizontalGlue()); + menuBar.add(logout); + menuBar.add(login); + + setJMenuBar(menuBar); + + } + + public void setUI() { + + contentPane = new JPanel(new BorderLayout(50, 50)); + contentPane.setFont(fuente1); + contentPane.setBorder(fondo); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 1400, 900); + setMinimumSize(new Dimension(1400, 900)); + setContentPane(contentPane); + + capas = new JPanel(cardLayout); + + mainWindowContainer = new JPanel(cardLayout); + userPanel.setLayout(cardLayout); + userPanel.add(userPanel.getContentPaneUser()); + + capas.add(mainWindowContainer, "MainWindowPanel"); + capas.add(userPanel, "UserPanel"); + + contentPane.add(capas, BorderLayout.CENTER); + + setIconImage(Toolkit.getDefaultToolkit().getImage("Images/elrondIcon.jpg")); + setTitle("Zpectrum - Home"); + mainWindowPresentation(); + + } + + private void mainWindowPresentation() { + + maiarExchangeLabel = new JLabel("

Maiar Exchange

"); + maiarExchangeLabel.setHorizontalAlignment(SwingConstants.CENTER); + maiarExchangeLabel.setFont(fuente1); + maiarExchangeLabel.setForeground(Color.WHITE); + maiarExchangeLabel.setBorder(new EmptyBorder(40, 0, 0, 0)); + contentPane.add(maiarExchangeLabel, BorderLayout.NORTH); + + String warningText = "

This space is dedicated to monitoring your actions, records, nft's and a lot more within elrond blockchain." + + " This app and his creator takes none responsibility for any loss may cost you. You are the only one responsible of " + + "any data you give.

"; + presentationJLabel2 = new JLabel(warningText); + presentationJLabel2.setFont(fuente1); + presentationJLabel2.setForeground(Color.WHITE); + Border margin2 = new EmptyBorder(10, 30, 80, 10); + presentationJLabel2.setBorder(margin2); + contentPane.add(presentationJLabel2, BorderLayout.SOUTH); + + loginButton = new JButton("Login"); + loginButton.setPreferredSize(new Dimension(120, 30)); + mainPanel = new JPanel(new MigLayout("fill", "[][grow]", "[grow][]")); + + mainWindowContainer.add(mainPanel); + mainPanel.add(new JScrollPane(tokensMaiar()), "cell 1 0, alignx center"); + mainPanel.add(loginButton, "cell 1 1, alignx center"); + + } + + @SuppressWarnings("serial") + private JTable tokensMaiar() { + + List tokens = peticiones.tokensOnMaiar(); + String[] columsName = new String[] { "Name", "Price" }; + DefaultTableModel modelo = new DefaultTableModel(2, columsName.length); + modelo.setColumnIdentifiers(columsName); + + for (TokensMaiar tokenMaiar : tokens) { + + modelo.addRow(new Object[] { tokenMaiar.getName(), priceStringValue(tokenMaiar) }); + } + modelo.removeRow(0); + table = new JTable(modelo) { + @Override + public boolean isCellEditable(int row, int column) { + // disable editing: + return false; + } + }; + table.setRowHeight(22); + table.setShowGrid(false); + table.setOpaque(false); + DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int column) { + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + setFont(fuenteTable); + if (hasFocus) { + table.setFont(new Font("Tahoma", Font.ITALIC, 16)); + } + return this; + } + + }; + + renderer.setHorizontalAlignment(JLabel.CENTER); + // table.setDefaultRenderer(getClass(), renderer); + table.getColumnModel().getColumn(0).setCellRenderer(renderer); + table.getColumnModel().getColumn(1).setCellRenderer(renderer); + + return table; + } + + private String priceStringValue(TokensMaiar crypto) { + String finalString = "0."; + if (crypto.toString().contains("E-")) { + + String process = ""; + String lastC = String.valueOf(crypto.getPrice()).substring(String.valueOf(crypto.getPrice()).length() - 1); + int lastCN = Integer.parseInt(lastC); + int length = lastCN; + length = length - 1; + int[] ceros = new int[length]; + for (int i = 0; i < ceros.length; i++) { + ceros[i] = 0; + process += ceros[i]; + } + String precio = String.valueOf(crypto.getPrice()); + process += precio; + String aux = process.substring(process.length() - 3); + process = process.replace(aux, ""); + process = process.replace(".", ""); + finalString += process; + return finalString; + } + String result = String.valueOf(crypto.getPrice()); + return result; + + } + + public void setHandler(EventsHandlerMainWindow handler) { + + itemPortfolio.addActionListener(handler); + itemWatchlist.addActionListener(handler); + login.addMenuListener(handler); + logout.addMenuListener(handler); + home.addMenuListener(handler); + contentPane.addComponentListener(handler); + loginButton.addActionListener(handler); + } + + public void makePanels() { + + portfolioPanel = new PortfolioPanel(this); + watchListPanel = new WatchlistPanel(this); + + portfolioWindowHandler = new EventsHandlerPortfolio(userRepository, servicioIMPL, peticiones, this); + watchlistWindowHandler = new EventsHandlerWatchlist(this); + + portfolioPanel.setLayout(cardLayout); + portfolioPanel.add(portfolioPanel.getContentPanePortfolio()); + + watchListPanel.setLayout(cardLayout); + watchListPanel.add(watchListPanel.getContentPaneWatchlist()); + + capas.add(portfolioPanel, "PortfolioPanel"); + capas.add(watchListPanel, "WatchlistPanel"); + + this.getPortfolioPanel().setPortfolioHandler(portfolioWindowHandler); + this.getWatchListPanel().setWatchlistHandler(watchlistWindowHandler); + } + + @Override + public int getRowCount() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getColumnCount() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getColumnName(int columnIndex) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Class getColumnClass(int columnIndex) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + // TODO Auto-generated method stub + + } + + @Override + public void addTableModelListener(TableModelListener l) { + // TODO Auto-generated method stub + + } + + @Override + public void removeTableModelListener(TableModelListener l) { + // TODO Auto-generated method stub + + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + // TODO Auto-generated method stub + return false; + } +} diff --git a/src/main/java/ZpectrumApp/Vista/MainWindowX.java b/src/main/java/ZpectrumApp/Vista/MainWindowX.java new file mode 100644 index 0000000..4717d87 --- /dev/null +++ b/src/main/java/ZpectrumApp/Vista/MainWindowX.java @@ -0,0 +1,30 @@ +package ZpectrumApp.Vista; + +import java.awt.BorderLayout; +import java.awt.EventQueue; +import java.awt.Font; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +public class MainWindowX extends JFrame { + + private JPanel contentPane; + + + + /** + * Create the frame. + */ + public MainWindowX() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 450, 300); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + contentPane.setLayout(new BorderLayout(0, 0)); + contentPane.setFont(new Font("Tahoma", Font.PLAIN, 15)); + setContentPane(contentPane); + } + +} diff --git a/src/main/java/ZpectrumApp/Vista/PortfolioPanel.java b/src/main/java/ZpectrumApp/Vista/PortfolioPanel.java new file mode 100644 index 0000000..5462043 --- /dev/null +++ b/src/main/java/ZpectrumApp/Vista/PortfolioPanel.java @@ -0,0 +1,385 @@ +package ZpectrumApp.Vista; + +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; +import javax.imageio.ImageIO; +import javax.swing.DefaultListModel; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +import org.jcodec.api.FrameGrab; +import org.jcodec.api.JCodecException; +import org.jcodec.common.model.Picture; +import org.jcodec.scale.AWTUtil; + +import ZpectrumApp.DTO.CryptoDTO; +import ZpectrumApp.DTO.NftDTO; +import ZpectrumApp.EventHandler.EventsHandlerPortfolio; +import ZpectrumApp.Modelo.Nft; +import ZpectrumApp.Modelo.Usuario; +import ZpectrumApp.Repositorio.UsuarioRepositorio; +import net.miginfocom.swing.MigLayout; + +public class PortfolioPanel extends JPanel { + + /** + * + */ + private static final long serialVersionUID = 9112234017946580041L; + + private JPanel contentPanePortfolio; + // private Usuario user; + private JLabel name, erd, balance, tokensList, totalValue, nftList; + private JList tokensFList; + private DefaultListModel listModel = new DefaultListModel<>(); + private JTable nftTable; + private Font fuente1 = new Font("Tahoma", Font.PLAIN, 22); + private MainWindow mainWindow; + private JButton updateBtn, copyBtn; + private int nftCount = 0; + private int videoCount = 0; + private DefaultTableModel nftModel; + private String nftVideoName = "Video/nftVideo" + videoCount + ".mp4"; + + public JButton getUpdateBtn() { + return updateBtn; + } + + public JButton getCopyBtn() { + return copyBtn; + } + + public JLabel getErd() { + return erd; + } + + public JLabel getBalance() { + return balance; + } + + public JLabel getTokensList() { + return tokensList; + } + + public JLabel getTotalValue() { + return totalValue; + } + + public JLabel getNftList() { + return nftList; + } + + public MainWindow getMainWindow() { + return mainWindow; + } + + public JPanel getContentPanePortfolio() { + return contentPanePortfolio; + } + + public PortfolioPanel(MainWindow mainWindow) { + + this.mainWindow = mainWindow; + setUI(); + + } + + private void setUI() { + + contentPanePortfolio = new JPanel(new MigLayout("fill", "[grow][grow]", "[][][][][][]")); + contentPanePortfolio.setFont(fuente1); + + name = new JLabel("Name: " + mainWindow.getUser().getUserName().toUpperCase()); + contentPanePortfolio.add(name, "cell 0 0"); + + erd = new JLabel("Erd: " + mainWindow.getUser().getErd()); + contentPanePortfolio.add(erd, "cell 0 1"); + + balance = new JLabel("Egld balance: " + mainWindow.getUser().getBalance()); + contentPanePortfolio.add(balance, " cell 0 2"); + + tokensList = new JLabel("Tokens : "); + contentPanePortfolio.add(tokensList, "cell 0 3"); + contentPanePortfolio.add(new JScrollPane(setTokensList()), "cell 0 3"); + + nftList = new JLabel("Nfts: "); + contentPanePortfolio.add(nftList, "cell 1 3"); + contentPanePortfolio.add(new JScrollPane(setNftTable()), "cell 1 3"); + + totalValue = new JLabel("Total tokens value: " + totalValue() + " $"); + contentPanePortfolio.add(totalValue, "cell 0 5"); + + updateBtn = new JButton("Update"); + contentPanePortfolio.add(updateBtn, "cell 1 1"); + + copyBtn = new JButton("Copy adress"); + contentPanePortfolio.add(copyBtn, "cell 0 1"); + + } + + private JList setTokensList() { + + tokensFList = new JList<>(listModel); + tokensFList.setPreferredSize(new Dimension(500, 800)); + List cryptoList = mainWindow.getPeticiones().obtainTokensAccount(mainWindow.getUser().getErd()); + if (cryptoList.isEmpty()) { + listModel.addElement("No hay tokens"); + } else { + for (CryptoDTO cryptoDTO : cryptoList) { + listModel.addElement(cryptoDTO.getCryptoName().toUpperCase() + ": " + cryptoDTO.getBalance() + + " Value: " + cryptoDTO.getValueUSD()); + } + } + + return tokensFList; + } + + private String totalValue() { + + double totalPrice = 0.0; + List cryptoList = mainWindow.getPeticiones().obtainTokensAccount(mainWindow.getUser().getErd()); + for (CryptoDTO cryptoDTO : cryptoList) { + totalPrice += cryptoDTO.getValueUsd(); + } + String response = String.valueOf(totalPrice); + return response; + } + + @SuppressWarnings("serial") + private JTable setNftTable() { + + List nfts = mainWindow.getPeticiones().obtainNftAccount(mainWindow.getUser().getErd()); + String[] columsName = new String[] { "Nu.", "Name", "Collection name", "royalties", "Image" }; + nftModel = new DefaultTableModel(5, columsName.length) { + @Override + public Class getColumnClass(int column) { + if (column == 4) { + return ImageIcon.class; + } + return Object.class; + + } + }; + nftModel.setColumnIdentifiers(columsName); + + for (NftDTO nft : nfts) { + // TODO añadir una imagen del nft como ultima columna + System.out.println(nft.getNftUrl()); + if (nft.getNftUrl() == null) { + nft.setNftUrl("There is no URL"); + } + nftModel.addRow(new Object[] { countNft(), nft.getNftName(), nft.getColletionName(), nft.getRoyalties(), + nftImage(nft.getNftUrl()) }); + } + nftModel.removeRow(0); + nftModel.removeRow(1); + + nftTable = new JTable(nftModel) { + @Override + public boolean isCellEditable(int row, int column) { + // disable editing: + return false; + } + }; + nftTable.getColumnModel().getColumn(0).setPreferredWidth(5); + nftTable.getColumnModel().getColumn(3).setPreferredWidth(5); + nftTable.setRowHeight(70); + nftModel.removeRow(0); + nftModel.removeRow(1); + nftModel.removeRow(2); + + return nftTable; + } + + private String countNft() { + nftCount++; + String resultNumber = String.valueOf(nftCount); + return resultNumber; + } + + private ImageIcon nftImage(String url2) { + if (url2.contains("There is no URL")) { + ImageIcon imageResult = new ImageIcon("Images/nonenft.jpg"); + return imageResult; + } else { + + HttpURLConnection urlConnection; + + try { + urlConnection = (HttpURLConnection) new URL(url2).openConnection(); + urlConnection.setInstanceFollowRedirects(true); + HttpURLConnection.setFollowRedirects(true); + + int status = urlConnection.getResponseCode(); + if (status >= 300 && status <= 307) { + url2 = urlConnection.getHeaderField("Location"); + urlConnection = (HttpURLConnection) new URL(url2).openConnection(); + System.out.println("Redirect to URL : " + url2); + } + String contentType = urlConnection.getHeaderField("Content-Type"); + + if (contentType.startsWith("image/")) { + + return processImage(urlConnection); + + } else if (contentType.contains("video/")) { + videoCount++; + // save video first + try (BufferedInputStream inputStream = new BufferedInputStream(urlConnection.getInputStream()); + FileOutputStream fileOS = new FileOutputStream(nftVideoName)) { + byte data[] = new byte[1024]; + int byteContent; + while ((byteContent = inputStream.read(data, 0, 1024)) != -1) { + fileOS.write(data, 0, byteContent); + } + } catch (IOException e) { + System.out.println(e.getMessage()); + } + // process video then + return processVideo(nftVideoName); + + } + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + ImageIcon imageResult = new ImageIcon("Images/nonenft.jpg"); + return imageResult; + } + + private ImageIcon processImage(HttpURLConnection urlConnection) { + BufferedImage processImage = null; + byte[] imageInByte = null; + try { + + processImage = ImageIO.read(urlConnection.getURL()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageIO.write(processImage, "jpg", baos); + imageInByte = baos.toByteArray(); + + + } catch (IOException e) { + e.printStackTrace(); + } + + ImageIcon image0 = new ImageIcon(processImage); + Image image = image0.getImage(); + Image image2 = image.getScaledInstance(70, 70, Image.SCALE_SMOOTH); + ImageIcon imageResult = new ImageIcon(image2); + System.out.println("imagen"); + + List nftList = mainWindow.getUser().getNftList(); + + for (Nft nft : nftList) { + nft.setNftImage(imageInByte); + mainWindow.getNftRepository().save(nft); + } + + return imageResult; + } + + private ImageIcon processVideo(String nftVideoName) { + + Picture frame = null; + ImageIcon imageResult; + byte[] imageInByte = null; + BufferedImage bufferedImage = null; + + try { + + frame = FrameGrab.getFrameAtSec(new File(nftVideoName), 1.0); + bufferedImage = AWTUtil.toBufferedImage(frame); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, "jpg", baos); + imageInByte = baos.toByteArray(); + + } catch (IOException e) { + e.printStackTrace(); + } catch (JCodecException e) { + e.printStackTrace(); + } + + List nftList = mainWindow.getUser().getNftList(); + + for (Nft nft : nftList) { + nft.setNftImage(imageInByte); + mainWindow.getNftRepository().save(nft); + } + + ImageIcon image0 = new ImageIcon(bufferedImage); + Image imageProcess = image0.getImage(); + Image image2 = imageProcess.getScaledInstance(70, 70, Image.SCALE_SMOOTH); + imageResult = new ImageIcon(image2); + System.out.println("video"); + + return imageResult; + } + + public void repaintComponents() { + videoCount = 0; + name.setText("Name: " + mainWindow.getUser().getUserName().toUpperCase()); + erd.setText("Erd: " + mainWindow.getUser().getErd()); + balance.setText("Egld balance: " + mainWindow.getUser().getBalance()); + repaintTokensList(); + repaintNftTable(); + totalValue.setText("Total tokens value: " + totalValue() + " $"); + + } + + private void repaintTokensList() { + listModel.removeAllElements(); + List cryptoList = mainWindow.getPeticiones().obtainTokensAccount(mainWindow.getUser().getErd()); + if (cryptoList.isEmpty()) { + listModel.addElement("No hay tokens"); + } else { + for (CryptoDTO cryptoDTO : cryptoList) { + listModel.addElement(cryptoDTO.getCryptoName().toUpperCase() + ": " + cryptoDTO.getBalance() + + " Value: " + cryptoDTO.getValueUSD()); + } + } + } + + private void repaintNftTable() { + nftModel.setRowCount(0); + nftCount = 0; + List nfts = mainWindow.getPeticiones().obtainNftAccount(mainWindow.getUser().getErd()); + + for (NftDTO nft : nfts) { + // TODO añadir una imagen del nft como ultima columna + System.out.println(nft.getNftUrl()); + if (nft.getNftUrl() == null) { + nft.setNftUrl("There is no URL"); + } + nftModel.addRow(new Object[] { countNft(), nft.getNftName(), nft.getColletionName(), nft.getRoyalties(), + nftImage(nft.getNftUrl()) }); + } + + } + + public void setPortfolioHandler(EventsHandlerPortfolio handler) { + + updateBtn.addActionListener(handler); + copyBtn.addActionListener(handler); + + } + +} diff --git a/src/main/java/ZpectrumApp/Vista/UserPanel.java b/src/main/java/ZpectrumApp/Vista/UserPanel.java new file mode 100644 index 0000000..d201c4e --- /dev/null +++ b/src/main/java/ZpectrumApp/Vista/UserPanel.java @@ -0,0 +1,214 @@ +package ZpectrumApp.Vista; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.util.ArrayList; +import java.util.List; +import javax.swing.DefaultListModel; +import javax.swing.ImageIcon; +import javax.swing.JPanel; +import ZpectrumApp.EventHandler.EventsHandlerUser; +import ZpectrumApp.Modelo.Usuario; +import ZpectrumApp.Repositorio.UsuarioRepositorio; +import net.miginfocom.swing.MigLayout; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.ListCellRenderer; +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.border.EmptyBorder; +import javax.swing.ListSelectionModel; + +public class UserPanel extends JPanel implements ListCellRenderer { + + /** + * + */ + private static final long serialVersionUID = 2131340037745280119L; + + private JPanel contentPaneUser; + private Font fuente1 = new Font("Tahoma", Font.PLAIN, 22), fuente2 = new Font("Tahoma", Font.PLAIN, 14); + private JLabel jLblERD, jLblUserName, jLblHelp, jLblNewHelpText, registeredUsers; + private JTextField jTxtFERD, jTextFUserName; + private JButton jBtnRegister, jBtnDelete, jBtnCreate; + private UsuarioRepositorio userRepository; + private JList usersJList; + private DefaultListModel model = new DefaultListModel<>(); + private List finalUserList = new ArrayList(); + private MainWindow mainWindow; + + public JList getUsersJList() { + return usersJList; + } + + public List getFinalUserList() { + return finalUserList; + } + + public JButton getjBtnCreate() { + return jBtnCreate; + } + + public MainWindow getMainWindow() { + return mainWindow; + } + + public JButton getjBtnDelete() { + return jBtnDelete; + } + + public JLabel getResgisteredUsers() { + return registeredUsers; + } + + public JList getList() { + return usersJList; + } + + public JLabel getjLblNewHelpText() { + return jLblNewHelpText; + } + + public JLabel getjLblHelp() { + return jLblHelp; + } + + public JTextField getjTxtFERD() { + return jTxtFERD; + } + + public JTextField getjTextFUserName() { + return jTextFUserName; + } + + public JButton getjBtnRegister() { + return jBtnRegister; + } + + public JPanel getContentPaneUser() { + return contentPaneUser; + } + + public UserPanel(UsuarioRepositorio userRepository, MainWindow mainwindow) { + + this.mainWindow = mainwindow; + this.userRepository = userRepository; + setUI(); + setVisible(true); + } + + private void setUI() { + + contentPaneUser = new JPanel(new MigLayout("fill", "[][grow][grow]", "[][][]")); + + jLblUserName = new JLabel("Name: "); + jLblUserName.setPreferredSize(new Dimension(80, 25)); + jLblUserName.setFont(fuente1); + contentPaneUser.add(jLblUserName, "cell 0 0"); + + jTextFUserName = new JTextField(); + jTextFUserName.setColumns(10); + contentPaneUser.add(jTextFUserName, "cell 0 0"); + + jLblERD = new JLabel("ERD: "); + jLblERD.setPreferredSize(new Dimension(80, 25)); + jLblERD.setFont(fuente1); + contentPaneUser.add(jLblERD, "cell 0 1"); + + jTxtFERD = new JTextField(); + jTxtFERD.setColumns(10); + contentPaneUser.add(jTxtFERD, "cell 0 1"); + + jLblHelp = new JLabel(); + jLblHelp.setIcon(new ImageIcon("Images/question.png")); + contentPaneUser.add(jLblHelp, "cell 0 1"); + + jLblNewHelpText = new JLabel( + "The ERD adress (elrond abbreviated) adress data it's required by the elrond blockchain to " + + "locate the adress and all info related"); + jLblNewHelpText.setFont(new Font("Tahoma", Font.PLAIN, 12)); + jLblNewHelpText.setVisible(false); + contentPaneUser.add(jLblNewHelpText, "cell 1 2, alignx center"); + + registeredUsers = new JLabel(" Usuarios registrados: "); + registeredUsers.setFont(fuente2); + contentPaneUser.add(registeredUsers, "cell 1 0, alignx center"); + + jBtnRegister = new JButton("Login"); + jBtnRegister.setPreferredSize(new Dimension(125,35)); + contentPaneUser.add(jBtnRegister, "cell 1 1, alignx center"); + + jBtnDelete = new JButton("Delete"); + jBtnDelete.setPreferredSize(new Dimension(125,35)); + contentPaneUser.add(jBtnDelete, "cell 1 1, alignx center"); + + jBtnCreate = new JButton("Create"); + jBtnCreate.setPreferredSize(new Dimension(125,35)); + contentPaneUser.add(jBtnCreate, "cell 1 1, alignx center"); + + setUserList(); + + } + + public void setUserHandler(EventsHandlerUser handler) { + + jBtnRegister.addActionListener(handler); + jBtnDelete.addActionListener(handler); + jBtnCreate.addActionListener(handler); + jLblHelp.addMouseListener(handler); + + } + + private void setUserList() { + + usersJList = new JList(model); + contentPaneUser.add(usersJList, "cell 2 0 0 3, grow, alignx left"); + usersJList.setFont(new Font("Tahoma", Font.PLAIN, 14)); + usersJList.setForeground(Color.GRAY); + usersJList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + usersJList.setLayoutOrientation(JList.HORIZONTAL_WRAP); + usersJList.setBorder(new EmptyBorder(5, 10, 5, 5)); + + List userList = userRepository.findAll(); + if (userList.size() == 0) { + model.addElement("No hay usuarios registrados"); + } else { + for (Usuario user : userList) { + finalUserList.add(user); + } + + for (Usuario user : finalUserList) { + model.addElement(user.getUserName()); + } + } + + } + + public void updateList() { + model.removeAllElements(); + List userList = userRepository.findAll(); + for (Usuario user : userList) { + finalUserList.add(user); + } + + for (Usuario user : userList) { + model.addElement(user.getUserName()); + } + for (Usuario usuario : userList) { + System.out.println(usuario.getUserName()); + } + if (userList.size() == 0) { + model.addElement("No hay usuarios registrados"); + } + + } + + @Override + public Component getListCellRendererComponent(JList list, String value, int index, + boolean isSelected, boolean cellHasFocus) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/main/java/ZpectrumApp/Vista/WatchlistPanel.java b/src/main/java/ZpectrumApp/Vista/WatchlistPanel.java new file mode 100644 index 0000000..81ac8ce --- /dev/null +++ b/src/main/java/ZpectrumApp/Vista/WatchlistPanel.java @@ -0,0 +1,62 @@ +package ZpectrumApp.Vista; + + +import java.awt.Dimension; +import java.awt.Font; +import javax.swing.JPanel; +import ZpectrumApp.EventHandler.EventsHandlerWatchlist; +import ZpectrumApp.Modelo.Usuario; + + +public class WatchlistPanel extends JPanel { + + /** + * + */ + private static final long serialVersionUID = -5295423397999336755L; + + private JPanel contentPaneWatchlist; + private Font fuente1 = new Font("Tahoma", Font.PLAIN, 22); + private MainWindow mainWindow; + private Usuario user; + + public Usuario getUser() { + return user; + } + + public void setUser(Usuario user) { + this.user = user; + } + + public MainWindow getMainWindow() { + return mainWindow; + } + + public JPanel getContentPaneWatchlist() { + return contentPaneWatchlist; + } + + public WatchlistPanel(MainWindow mainWindow) { + + this.mainWindow = mainWindow; + + setUI(); + setVisible(false); + } + + public void setUI() { + + setBounds(100, 100, 1400, 900); + contentPaneWatchlist = new JPanel(); + setMinimumSize(new Dimension(1400, 900)); + contentPaneWatchlist.setFont(fuente1); + + } + + public void setWatchlistHandler(EventsHandlerWatchlist handler) { + + //itemPortfolioWatchlist.addActionListener(handler); + + } + +} diff --git a/src/main/java/ZpectrumApp/ZpectrumApplication.java b/src/main/java/ZpectrumApp/ZpectrumApplication.java new file mode 100644 index 0000000..8cd8687 --- /dev/null +++ b/src/main/java/ZpectrumApp/ZpectrumApplication.java @@ -0,0 +1,108 @@ +package ZpectrumApp; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; +import javax.imageio.ImageIO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import ZpectrumApp.EventHandler.EventsHandlerMainWindow; +import ZpectrumApp.EventHandler.EventsHandlerPortfolio; +import ZpectrumApp.EventHandler.EventsHandlerUser; +import ZpectrumApp.EventHandler.EventsHandlerWatchlist; +import ZpectrumApp.Peticiones.Peticiones; +import ZpectrumApp.Repositorio.CryptoRepositorio; +import ZpectrumApp.Repositorio.NftRepositorio; +import ZpectrumApp.Repositorio.UsuarioRepositorio; +import ZpectrumApp.Servicio.CryptoServicioIMPL; +import ZpectrumApp.Vista.FondoApp; +import ZpectrumApp.Vista.MainWindow; + +@SpringBootApplication +public class ZpectrumApplication implements CommandLineRunner { + + @Autowired + private Peticiones peticiones; + + @Autowired + private CryptoServicioIMPL servicioIMPL; + + @Autowired + private UsuarioRepositorio userRepository; + + @Autowired + private CryptoRepositorio cryptoRepository; + + @Autowired + private NftRepositorio nftRepository; + + /** + * this method launches the main thread of the program, + * remember to start MySQL8 service before launching. + * + * @param args[] es un arreglo con los parámetros + * @return void + * @author Fran Gonzalez + */ + public static void main(String[] args) { + + // SpringApplication.run(ZpectrumApplication.class, args); + + // alternative mode to launch Springboot APP below: + Properties props = new Properties(); + props.put("spring.main.web-application-type", "NONE"); + props.put("spring.datasource.url", "jdbc:mysql://localhost:3306/zpectrumbbdd"); + props.put("spring.datasource.username", "zpectrumuser"); + props.put("spring.datasource.password", "password"); + props.put("server.port", "8093"); + props.put("spring.jpa.properties.hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect"); + props.put("spring.jpa.hibernate.ddl-auto", "create-drop"); + props.put("hibernate.physical_naming_strategy", + "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy"); + props.put("hibernate.implicit_naming_strategy", + "org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"); + props.put("spring.jpa.show-sql", "true"); + System.setProperty("java.awt.headless", "false"); + + new SpringApplicationBuilder(ZpectrumApplication.class).properties(props).run(args); + System.out.println("Contexto Spring cargado ¡"); + + } + + @Override + public void run(String... args) throws Exception { + + try { + + FondoApp fondo = null; + try { + fondo = new FondoApp(ImageIO.read(new File("Images/FondoApp.png"))); + } catch (IOException e) { + e.printStackTrace(); + } + + boolean loggedUser = false; + EventsHandlerPortfolio portfolioWindowHandler = null; + EventsHandlerWatchlist watchlistWindowHandler = null; + + MainWindow mainwindow = new MainWindow(fondo, peticiones, userRepository, watchlistWindowHandler, + portfolioWindowHandler, loggedUser, servicioIMPL, nftRepository); + + EventsHandlerMainWindow mainWindowHandler = new EventsHandlerMainWindow(mainwindow, peticiones); + EventsHandlerUser userWindowHandler = new EventsHandlerUser(userRepository, servicioIMPL, peticiones, + mainwindow); + + mainwindow.setHandler(mainWindowHandler); + mainwindow.getUserPanel().setUserHandler(userWindowHandler); + + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/ZpectrumApp/testPeticionNumeroNft.java b/src/main/java/ZpectrumApp/testPeticionNumeroNft.java new file mode 100644 index 0000000..a45a9d3 --- /dev/null +++ b/src/main/java/ZpectrumApp/testPeticionNumeroNft.java @@ -0,0 +1,44 @@ +package ZpectrumApp; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + + +public class testPeticionNumeroNft { + + static final String accountApiElrond = "https://api.elrond.com/accounts/erd18alaelkaha93wy88w67j4e8ehq9jkd7ydnqa2g6j3627nzukgsgsj6ap3j/nfts/count"; + + public static void main(String[] args) { + + String proceso = ""; + String linea; + + + try { + + URL url = new URL(accountApiElrond); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + System.out.println(connection.getResponseCode()); + System.out.println(connection.getResponseMessage()); + + while ((linea = rd.readLine()) != null) { + + proceso += linea; + + } + + //la variable proceso es un String de un numero entero con la cantidad de nft que pertenecen a esa cuenta ERD + System.out.println(proceso); + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..ce48a7c --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,11 @@ + +java.awt.headless=false +spring.main.web-application-type=NONE +spring.datasource.url=jdbc:mysql://localhost:3306/zpectrumbbdd +spring.datasource.username=zpectrumuser +spring.datasource.password=password +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect +spring.jpa.hibernate.ddl-auto=create-drop +server.port=8093 +spring.jpa.show-sql=true + diff --git a/src/test/java/com/example/demo/ZpectrumApplicationTests.java b/src/test/java/com/example/demo/ZpectrumApplicationTests.java new file mode 100644 index 0000000..c5357df --- /dev/null +++ b/src/test/java/com/example/demo/ZpectrumApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.demo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ZpectrumApplicationTests { + + @Test + void contextLoads() { + } + +}