<file_sep><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>simuladorAmbiente</groupId>
    <artifactId>simuladorAmbiente</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.plugin.version>3.6.1</maven.compiler.plugin.version>
        <maven.assembly.plugin.version>3.0.0</maven.assembly.plugin.version>
        <jsk.version>2.2.2</jsk.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <OpenJms.lib.path>${project.basedir}/lib/</OpenJms.lib.path>
    </properties>

    <build>
        <finalName>simuladorAmbiente</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${maven.assembly.plugin.version}</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
                <executions>
                    <execution>
                        <id>install-external</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/jms-1.1.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>javax.jms</groupId>
                            <artifactId>jms</artifactId>
                            <version>1.1</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>install-external1</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/openjms-0.7.7-beta-1.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>openjms</groupId>
                            <artifactId>openjms</artifactId>
                            <version>0.7.7-beta-1</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>install-external2</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/openjms-common-0.7.7-beta-1.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>openjms</groupId>
                            <artifactId>openjms-common</artifactId>
                            <version>0.7.7-beta-1</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>install-external3</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/openjms-net-0.7.7-beta-1.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>openjms</groupId>
                            <artifactId>openjms-net</artifactId>
                            <version>0.7.7-beta-1</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>install-external4</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/openjms-tools-0.7.7-beta-1.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>openjms</groupId>
                            <artifactId>openjms-tools</artifactId>
                            <version>0.7.7-beta-1</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>install-external5</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/jndi-1.2.1.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>javax.naming</groupId>
                            <artifactId>jndi</artifactId>
                            <version>1.2.1</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>net.jini</groupId>
            <artifactId>jsk-platform</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>net.jini</groupId>
            <artifactId>jsk-dl</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>net.jini</groupId>
            <artifactId>jsk-lib</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>net.jini</groupId>
            <artifactId>jsk-resources</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>net.jini</groupId>
            <artifactId>jsk-policy</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.river</groupId>
            <artifactId>reggie</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.river</groupId>
            <artifactId>reggie-dl</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.river</groupId>
            <artifactId>outrigger-dl</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.river</groupId>
            <artifactId>start</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.river</groupId>
            <artifactId>tools</artifactId>
            <version>${jsk.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>openjms</groupId>
            <artifactId>openjms</artifactId>
            <version>0.7.7-beta-1</version>
        </dependency>

        <dependency>
            <groupId>openjms</groupId>
            <artifactId>openjms-common</artifactId>
            <version>0.7.7-beta-1</version>
        </dependency>

        <dependency>
            <groupId>openjms</groupId>
            <artifactId>openjms-net</artifactId>
            <version>0.7.7-beta-1</version>
        </dependency>

        <dependency>
            <groupId>openjms</groupId>
            <artifactId>openjms-tools</artifactId>
            <version>0.7.7-beta-1</version>
        </dependency>

        <dependency>
            <groupId>javax.naming</groupId>
            <artifactId>jndi</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>spice</groupId>
            <artifactId>spice-jndikit</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>

        <dependency>
            <groupId>concurrent</groupId>
            <artifactId>concurrent</artifactId>
            <version>1.3.4</version>
        </dependency>
    </dependencies>
</project>
<file_sep>package utilitarios;

import java.util.List;
import java.util.Optional;

import javafx.scene.control.ChoiceDialog;

public class EscolherAmbienteDialogo {

    //inicia o dialogo com opcoes para escolha
    public static String iniciarDialogo(String titulo, String cabecalho, String conteudo, List<String> opcoes) {
        ChoiceDialog<String> dialogo = new ChoiceDialog<>(null, opcoes);
        dialogo.setTitle(titulo);
        dialogo.setHeaderText(cabecalho);
        dialogo.setContentText(conteudo);

        Optional<String> resultado = dialogo.showAndWait();
        return resultado.orElse(null);
    }
}<file_sep>package controladores;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;

import servicos.javaspaces.AmbienteServico;
import servicos.jms.CoordenadorJMSServico;
import servicos.jms.MensagemServico;


public class MainControlador implements Initializable {

    @FXML
    private TreeView<String> ambientes;

    @FXML
    private ListView<String> mensagens;

    private AmbienteServico ambienteServico;

    private MensagemServico mensagemServico;

    private CoordenadorJMSServico coordenadorJmsServico;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        //inicializa a arvore de ambientes
        TreeItem<String> item = new TreeItem<>("Todos");
        item.setExpanded(true);
        ambientes.setRoot(item);

        //inicia a conexao com o jms
        coordenadorJmsServico = new CoordenadorJMSServico();
        coordenadorJmsServico.iniciarConexao();

        //carrega as acoes de ambiente
        ambienteServico = new AmbienteServico(ambientes, coordenadorJmsServico);

        //carrega as acoes de mensagens
        mensagemServico = new MensagemServico(mensagens, coordenadorJmsServico);
    }

    //o usuario ao clicar no botao adiciona um ambiente na arvore
    @FXML
    private void adicionarAmbiente() {
        ambienteServico.adicionarAmbiente();
    }

    //o usuario ao clicar no botao remove um ambiente na arvore
    @FXML
    private void removerAmbiente() {
        ambienteServico.removerAmbiente();
    }

    //o usuario ao clicar no botao reseta os ambientes na arvore
    @FXML
    private void resetarAmbientes() {
        ambienteServico.resetar();
        mensagemServico.resetar();
    }

    //o usuario ao clicar no botao adiciona um dispositivo em um ambiente na arvore
    @FXML
    private void adicionarDispositivo() {
        ambienteServico.adicionarDispositivo();
    }

    //o usuario ao clicar no botao remove um dispositivo em um ambiente na arvore
    @FXML
    private void removerDispositivo() {
        ambienteServico.removerDispositivo();
    }

    //o usuario ao clicar no botao move um dispositivo de um ambiente para outro ambiente na arvore
    @FXML
    private void moverDispositivo() {
        ambienteServico.moverDispositivo();
    }

    //acao quando sai do programa
    public void sair() {
        ambienteServico.sair();
    }
}
<file_sep>package servicos.javaspaces;

import net.jini.core.entry.Entry;
import net.jini.space.JavaSpace;
import net.jini.core.lease.Lease;

public class JavaSpaceServico {

    private LookupServico lookupServico;

    private JavaSpace espaco;

    //inicia o javaspace
    public void iniciarServico() {
        lookupServico = new LookupServico(JavaSpace.class);
        espaco = (JavaSpace) lookupServico.getService();
        if (espaco == null) {
            System.out.println("Serviço JavaSpace nao encontrado. Encerrando...");
            System.exit(-1);
        }
        System.out.println("O servico JavaSpace foi encontrado.");
    }

    //escreve uma tupla no javaspace
    public void escrever(Entry tupla) {
        try {
            espaco.write(tupla, null, Lease.FOREVER);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //ler uma tupla no javaspace
    public Entry ler(Entry tupla) {
        try {
            return espaco.read(tupla, null, 60 * 100);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //pega uma tupla no javaspace
    public Entry pegar(Entry tupla) {
        try {
            return espaco.take(tupla, null, 60 * 100);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
<file_sep>import javafx.application.Application;
import javafx.stage.Stage;

import utilitarios.CarregarView;

public class Main extends Application {

    private CarregarView carregarView;

    @Override
    public void start(Stage primaryStage) throws Exception {
        carregarView = new CarregarView("MainVisual"); //carrega o arquivo MainVisao.fxml
        carregarView.setEstagio(primaryStage);
        carregarView.setCena();
        carregarView.sairPartida(); //carrega acao quando o jogador sair do jogo
        carregarView.show();

    }

    //executa a aplicacao
    public static void main(String[] args) {
        launch(args);
    }
}