mission planning system - technical university of denmarketd.dtu.dk/thesis/221869/bac08_25.pdf ·...

380
Mission Planning System Michael Sørensen, s052683 Mathias Holm Andersen, s052761 Kongens Lyngby 2008 IMM-BSC-2008-25

Upload: vuongliem

Post on 15-Feb-2018

222 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Mission Planning System

Michael Sørensen, s052683Mathias Holm Andersen, s052761

Kongens Lyngby 2008IMM-BSC-2008-25

Page 2: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Technical University of DenmarkInformatics and Mathematical ModellingBuilding 321, DK-2800 Kongens Lyngby, DenmarkPhone +45 45253351, Fax +45 [email protected]

Page 3: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Abstract

The project described in this report has developed a system called MissionPlanning System, capable of planning the mission of a satellite. The system isdeveloped for a project called DTUsat2.

Page 4: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

ii

Page 5: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Preface

This thesis was prepared at DTU Informatics, at the Technical University ofDenmark, in partial fulfillment of the requirements for acquiring the B.Sc. de-gree in Software Engineering.

The thesis has been made in the period from February 1st to June 27th.

During the project several people have been helpful. First a thanks should goout to Hans Henrik Løvengreen for all the research and help he have contributedwith to the project.Second a thanks to DTUsat2 project manager, Rene Fleron, for given us a warmwelcome to the project and helping us usability test our system.Thanks also to Kenneth Agerskov Jensen and Andreas Andersen Kjær, for usingtime on telling us about the Mission Control Center, and their work on theDTUsat2 project, even though they are long gone from the project.Also a big thanks to Anders Friis and Jesper Skytte, who has worked more orless as a hot line service when their ground station gave us problems.Finally a big thanks to Steen Eiler Jørgensen from Terma Herlev, for showingus how the Ørsted satellite is controlled from a ground segment, and to StigRasmussen from Rovsing A/S, for showing us the Columbus Lab commandingsystem.

Lyngby, 27th of June 2008

Michael Sørensen, s052683 Mathias Holm Andersen, s052761

Page 6: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

iv

Page 7: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Contents

Abstract i

Preface iii

1 Introduction 1

1.1 Report Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.2 Readers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.3 Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 System overview 5

2.1 Key Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.2 Mission Planning System in a context . . . . . . . . . . . . . . . 7

3 Project Requirements Analysis 13

3.1 Product Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.2 Other Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Page 8: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

vi CONTENTS

3.3 Supplementary Goals . . . . . . . . . . . . . . . . . . . . . . . . . 20

4 Requirements Specification 23

4.1 Annotation conventions . . . . . . . . . . . . . . . . . . . . . . . 23

4.2 Commanding the Satellite . . . . . . . . . . . . . . . . . . . . . . 24

4.3 Controlling the Mission . . . . . . . . . . . . . . . . . . . . . . . 27

4.4 Man-Machine Interface . . . . . . . . . . . . . . . . . . . . . . . . 29

4.5 Non-functional requirements . . . . . . . . . . . . . . . . . . . . . 31

5 System Design 35

5.1 Design Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

5.2 New Command Structure . . . . . . . . . . . . . . . . . . . . . . 36

5.3 Overall design of MPS . . . . . . . . . . . . . . . . . . . . . . . . 39

6 Implementation 51

6.1 Singleton Implementations . . . . . . . . . . . . . . . . . . . . . . 51

6.2 Saving and loading files - XML framework . . . . . . . . . . . . . 51

6.3 Command Type Editor . . . . . . . . . . . . . . . . . . . . . . . 52

6.4 Command Type Map . . . . . . . . . . . . . . . . . . . . . . . . . 52

6.5 Client - user access . . . . . . . . . . . . . . . . . . . . . . . . . . 54

6.6 Generic building of view for command setup . . . . . . . . . . . . 54

6.7 Command Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

6.8 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

6.9 User input of time - DateTimeSpinnersPanel . . . . . . . . . . . 55

Page 9: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

CONTENTS vii

6.10 Time Synchronization . . . . . . . . . . . . . . . . . . . . . . . . 56

6.11 Program Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

6.12 MCC Workarounds . . . . . . . . . . . . . . . . . . . . . . . . . . 57

6.13 MCC Alterations . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

7 Testing 59

7.1 Test Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

7.2 Regression Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

7.3 Test Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

8 Project Conclusion 61

8.1 Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Appendix A - Use Cases 67

Appendix B - Usability Test 79

Appendix C - Source Code 81

.1 MPS Source Sode . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

.2 Common Source Code . . . . . . . . . . . . . . . . . . . . . . . . 327

.3 MCC Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . 366

Page 10: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

viii CONTENTS

Page 11: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 1

Introduction

In 2005 a project called DTUsat2 were founded. The purpose of this projectwas to build a satellite and make it accomplish a mission in space. The missionof the satellite were decided to be tracking the migration of Cuckoo birds fromEurope to Africa.To accomplish this goal several hardware and software subsystems had to be de-veloped. Among these were the software for the ground segment, which consistsof a Mission Control module and a Ground Station module. After the groundstation software were developed, a Mission Control Center were developed inthe spring of 2007, to act as a server for the mission control. The only thingmissing now was a client to use this server. This client were to be called theMission Planning System, which is the system that this report concerns.The objective of this bachelor thesis is to develop and document the MissionPlanning System for the ground segment of the DTUsat2 project. The systemmust be able to plan the mission of the DTUsat2 by using the existing featuresof the Mission Control Center. In this context planning the mission of a satel-lite, is a term for sending commands to the satellite while the satellite orbitsearth.To specify the requirements of the Mission Planning System, initially the projectleaders of the DTUsat2 project were interviewed to find out which features wereneeded and wanted. Furthermore the two Danish companies Rovising A/S andTherma agreed to do a presentation of their solutions to similar tasks, as theone which Mission Planning System is to accomplish.

Page 12: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

2 Introduction

This helped in the process of defining the requirement for the Mission PlanningSystem.

1.1 Report Structure

This report consists of 8 chapters. The rest of this chapter contains some guide-lines how to read the report. All chapters can individually be read out ofcontext, but for better understanding of the report it is recommended to followthe guidelines for reading in the following section.

Chapter 2 System Overview, shows in what context the Mission PlanningSystem is, and further more contains a description of the components surround-ing the Mission Planning System.

Chapter 3 Requirements Analysis, is an analysis of the main purposes of theproject. Through the chapter these purposes are broken down into sub pur-poses, and these sub purposes will be analyzed to define the goals the project isto achieve.

Chapter 4 Requirements Specification, states the requirements to the projectand the software system, and indicates the priority of how crucial it is for projectsuccess to fulfill these requirements.

Chapter 5 System Design, contains the information on how the software sys-tem is designed, and why the design was chosen over others.

Chapter 6 Implementation, describes how the system has been implementedin means of non-trivial implementation.

Chapter 7 Testing, deals with test strategy used regarding the requirementsfor the project, and how the software has been tested.

Chapter 8 Project Conclusion, finalizes the reports main matter concludingon the project. It describes what goals have been accomplished and what goalshaven’t been accomplished. The chapter also contains the perspective of the

Page 13: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

1.2 Readers 3

project and the system developed.

1.2 Readers

This report targets people with interest in development of software systemsdeveloped for mission controlling, especially mission control of satellites. Thereport is also directed at developers that wants to implement features to theMission Planning System, or develop a system with an interface to the MissionPlanning System.Developers of new features will find the chapters 5 and 6 most useful. Develop-ers of systems interfacing with the Mission Planning System should read chapter2 as well as it gives the overview that will give an understanding of the systemin a context.In any case it is recommended to read this chapter and chapter 2 as it conveysoverall information about the report and the system it describes.

1.3 Conventions

To make this report easier to read and understand, a number of conventionshave been made for the report.

1.3.1 Typographic Conventions

Following typographic conventions have been made for this report:

• When referring to Java classes and object, the italic typesetting will beused

• When referring to Java methods, the typewriter typesetting will be used

• In the analysis of the system, requirement priority will be indicated withthe bold typesetting

Page 14: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

4 Introduction

1.3.2 Name conventions

The following conventions have been made:

• The system Mission Planning System will in this report be referred to asMPS.

• The system Mission Control Center will in this report be referred to asMCC.

• The MPS together with the MCC will in this report be known as theMission Control.

• A satellite Ground Station, will in this report be referred to as GS.

• The GS has an Operation Client abbreviated GSop.

• The GS, GSop and Mission Control altogether will be known as the GroundSegment.

Note that names and titles that would be abbreviated, like in the above, will bementioned by full name the first time they occur in a chapter.

Page 15: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 2

System overview

This chapter concerns the context of the Mission Planning System (MPS), de-scribing the DTUsat2 project in further detail. As mentioned in the introduc-tion, the DTUsat2 contains many subsystems. The most important subsystems,seen from MPS’ point of view, are the software systems. These will be intro-duced in this chapter.

2.1 Key Concepts

To understand what task the MPS is to accomplish, it is important to under-stand the key concepts of DTUsat2. This section will introduce these concepts.

2.1.1 Satellite Mission

A satellite’s mission is a definition of what the purpose of the satellite is. Themission for DTUsat2 is to ”Solve the Mystery of Bird Migration: TrackingSmall Birds from Space”, i.e. finding positions for birds migrating from Europeto Africa [2].

Page 16: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

6 System overview

2.1.2 Time Line

A key concept in the DTUsat2 mission is the Time Line. A time line representsa span of time. In that time span an amount of passes and commands arepresent. It is said that the time line contains passes and commands. Boththe ground segment and the satellite has a time line, and these two time lineshould be synchronized so the satellite and the ground segment have the sameunderstanding of the time line. The concept of the time line can be seen infigure 2.1.

Figure 2.1: The time line containing passes and commands

2.1.2.1 Passes

A Pass is a span of time where the satellite is within radio contact of a groundsegment associated with the satellites mission. Within the span of a pass com-munication can be established between the ground segment and the satellite.To know when a pass should occur satellite, a Two Line Element (TLE) file hasto be known, as well as the position of the radio tower, that communicates withthe satellite. A TLE file contains information about position vectors for objectsorbiting the Earth i.e. describing its orbit path, and are produced analyzingthe satellites tracking data i.e. the signal the satellite sends out with a giveninterval. However these position vectors will change over time, and TLE filesare therefore subject to change. Updating TLE files are therefore necessary tospecify when passes occur. Normally TLE files are downloaded from the Inter-net, where different web sites are publishing the newest TLE files.

Page 17: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

2.2 Mission Planning System in a context 7

2.1.2.2 Commands

Commands are packets of data that are transmitted from the ground segment tothe satellite. When a command is created at the ground segments, it becomespart of the time line of the Mission Control. When the command is received atthe satellite’s on-board computer it becomes a part of the satellites time line.The set of commands in the system is called the command stack, and shouldbe seen as the commands, in the system, that are sorted after their time ofexecution on the satellite. The command with the lowest time of executionis naturally executed first, if things go as they should, and therefore the termcommand stack is used. This term can get a bit confusing, as the MissionControl Center (MCC) supports that commands can have a time of executionthat is as soon as possible, and the command stack can only estimate when theexecution takes place.Commands can either have normal or high priority.

2.1.2.3 Command Blocks

Commands can be gathered in Command Blocks. Having several commands ina block indicates that the commands have some task in common.

2.1.3 Commanding

Commanding is a term for creating and sending commands to a satellite. Com-manding is used to make the satellite do tasks on the fly. Normally the satellitehave some basic functionality that it will do, like gathering data and transmit-ting them to a ground segment, but in the case that a user of the satellite wantsit to do other tasks he has to command it.

2.2 Mission Planning System in a context

The MPS is meant as a client to the Mission Control Center. Figure 2.2 givesan overview of all the components in the ground segment of the DTUsat2.

As seen in the figure the DTUsat2 project consists of three major softwaremodules

Page 18: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

8 System overview

Figure 2.2: Overview of the DTUsat2 system

Page 19: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

2.2 Mission Planning System in a context 9

• The software on the Ground Station (GS) module, seen on the right handside

• The software on the Mission Control module, seen on the left side.

• The software on the Satellites on board computer, seen at the top.

These three systems must be seen as three distributed systems, synchronizingsome data, and sending data to each other, when in contact with each other.

2.2.1 Mission Control

The Mission Control is responsible for controlling a satellites mission from theground. This component creates, stores and sends commands to the GS so thatGS can transmit these commands to the satellite. The Mission Control alsoreceives all data from the satellite and stores it in a database. It consists of theMPS and the MCC.

2.2.1.1 Mission Planning System

The MPS offers a graphical user interface (GUI), so that functionality at theMCC can be accessed. As seen in chapter 4, the MPS has other functionalitythan being an interface between the user and the MCC.

2.2.1.2 Mission Control Center

The MCC is meant to be the administrator of the time line and the database,that functions as the data storage for the Mission Control. The MCC is respon-sible for keeping commands in the right states and keeping the time line up todate. The MCC’s database also contains satellite passes and book sessions atthe GS according to these passes, so that the GS is dedicated to the satellite’smission when the satellite passes the ground station. This booking is done byan update session. Update sessions synchronizes MCC’s passes with the sessionsat the ground station, so that changes at the MCC will be done at the GS too.

Figure 2.3 shows the connection type and direction, for the MCC. Arrows aredirected at the component offering the interface.

Page 20: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

10 System overview

Figure 2.3: Interfaces in the ground software

Page 21: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

2.2 Mission Planning System in a context 11

2.2.2 Ground Station

The GS software is responsible for tracking satellites and offer a line of com-munication between MCC and the satellite. The ground station has the controlof a radio tower that can receive and send signals to the satellite. When MCCruns an update session all newly added passes in MCC’s database will be givena session ID at the GS. A session must be seen as a time interval where theradio tower is booked by a system, in this case MCC. GS has two interfaceswith MCC: A RMI-interface and a TCP-interface. The RMI is used for updatesessions, and the TCP-connection is used when MCC connects to the groundstation when the satellite of the mission comes within communication reach ofthe radio tower GS . The TCP connection is used to transfer data packagesbetween MCC and GS.

2.2.2.1 Ground Station Operation Client

The GSop is a client for the GS and is the Man-machine interface (MMI) formanually operating the GS. It controls the functionalities of the GS, and is usedto manually track satellites by starting a tracking session at the GS via theMMI.

2.2.2.2 On Board Computer

The on board computer (OBC) of the satellite, manages the data flow, betweensubsystems, at the satellite, and is responsible for the satellites time line. TheOBC executes commands transmitted to the satellite, and passes on the request,of the command, to the subsystem the command was meant for.

2.2.3 Data Packets

Data packets are packets going between the ground segment and the satellite.There are three types of packets:

• Commands (as introduced in section 2.1.2)

• Confirmations

• Telemetric Data

Page 22: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

12 System overview

For every command sent to the on board computer, the OBC creates a con-firmation packet that confirms the execution of the command. This executioncan either be successful or not, and can have a result set dependent on whatcommand that got executed. A command asking for certain data, would havea confirmation packet that contained that data.

To survey the satellites status as it passes through space, a great deal of data isproduced on board the satellite. For satellites with a mission, like the DTUsat2,some mission specific data will be produced. The data for DTUsat2 is birdpositions with timestamps, so it can be analyzed how birds are migrating. Allthis data that are produced on board should be transmitted to earth. Telemetricdata packets are used for this purpose. All data produced on board, commandedor not, should be transmitted to earth with the telemetric data packets.

Page 23: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 3

Project Requirements Analysis

The DTUsat2 is an ongoing project, and many issues have not been consideredthoroughly, and solutions are yet undefined.To realize the requirements that should be stated to the software system, ananalysis is required of the projects purpose. It is important to have differentfactors of a project in mind when analyzing the projects purpose. A softwareproject is not only meant to develop a software system. It is also meant to con-tribute with something to the base organization and the project members[REFto GDPM]. The base organization for the project is the DTUsat2 project.This chapter will show how the main purpose of the project is broken down intosub purposes, and how sub purposes are broken down into goals. In the nextchapter the goals will be split up into requirements and stated with a priority,to specify what specific features that is to implement in the software, and whatnon-functional requirements applies to the project.The project is successful if the main purpose is accomplished. The main pur-pose is accomplished when all sub purposes are accomplished. sub purposes areaccomplished when all goals for the purpose is accomplished. A goal is accom-plished when all requirements of highest priority, for the goal, is accomplished.

The purpose of this project is to plan the mission of the satellite . This pur-pose have been broken down into sub purposes and goals by using a missionbreakdown structure [1]. Figure 3.1 shows the purposes and goals for the project.

Page 24: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

14 Project Requirements Analysis

Figure 3.1: The Mission Brakedown Structure of the project

This breakdown and the analysis found in this chapter, is founded on the usecases found in appendix 8.1.2, as well as the fact that DTUsat2 is an ongoingproject, and not every aspects are defined.Boxes accentuated in the figure are the purposes and goals that are the mainfocus of the project, and should be prioritized higher. The rest must be seen asgoals and purposes a larger project could have accomplished, and these goalsare only implemented if all goals of high priority is accomplished. Purposes arewritten using the bold text format.The mission breakdown structure shows that there are three goal lines in thesoftware development part:

Page 25: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

3.1 Product Goals 15

• Commanding the Satellite

• Controlling the Mission

• Man-Machine Interface

Goals stated below these three must be seen as sub goals in accomplishing themain goals, and the three main goals has to be accomplished for the productpurpose to be fulfilled.

3.1 Product Goals

Product goals are described in the following subsections, and other goals aredescribed in the section 3.2 Other Goals.

3.1.1 Commanding the Satellite

Commanding the satellite is to create and send commands to the satellite. Thesatellite’s on-board software will then handle the command and construct aconfirmation for the ground software. To get a better understanding of thisconstruct, see section 2.2.3.A satellite could survive and accomplish its mission with no commanding. Intheory, a well constructed satellite with well constructed on-board software couldhave the functionality to keep the satellite alive and able to send its data to theground, and thereby fulfill its mission. Many unknown factors are present inspace, and programming the on-board software so it is intelligent enough tosolve this can be quite a task. Per Lundahl Thomsen from the DTUsat2 projecthave stated that it is impossible to foresee all scenarios, especially when work-ing with elements in space. Commanding must therefore be seen as a way ofaltering things on board of the satellite, a way of changing the tasks that thesatellite is doing and saving the satellite if it enters a scenario that has not beenforeseen while implementing the on-board software.For commanding to be possible, the commanding system must have an under-standing of the time line, and elements in the time line. The concept of the timeline is described in section 2.1.2.

Page 26: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

16 Project Requirements Analysis

3.1.1.1 Creating Elements

Commands As a command should have information about what to com-mand and when, it is important that the system can create commands withsome attributes. It is important that commands have a well defined dynami-cally structure, so that it can be possible to create commands as dynamicallyas possible. This will also solve some problems when implementing the Man-Machine Interface (MMI), as feeding the system with data is a main task increating commands.

Command Blocks A feature for creating, editing and saving a commandblock for later use is wanted by the end users of MPS. Saving the time of execu-tion of each command in the block will not make much sense when reused later.However saving the offsets between the time of executions will be much morerelevant. Then a start time of execution can be set and the time of executionof all commands in the block will be relative to this.

Passes To generate passes the user needs to specify a start and end time ofthe pass as well as ground station, and a session will automatically be createdat this ground station.

Ground Stations To be able to work with passes, commands and satellites,the system needs one or more ground stations. Before being able to add passesto the system a ground station must be specified.

MCC As MCC already has the functionality to create, store and modify thesethree elements, the MPS should concentrate on how the user can access thefunctionality, and how the functionality should be presented to the user i.e.giving the user a usable interface to work with. The MMI should also hinderthe user in giving illegal data when creating elements.

3.1.2 Controlling the Mission

Controlling the mission means to monitor events regarding the satellite andits mission, analyze the given event, and finally, to act on it. To obtain the

Page 27: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

3.1 Product Goals 17

needed information about events of the mission, the user needs to have somevisual overview of commands in the command stack as well as the passes, andthe connections between these. One could argue that creating and sendingcommands to the satellite is enough for the system to fulfill its purpose. It mustbe emphasized that every time a command is sent to the satellite there is achance of something unexpected happening. Therefore it is important that theuser can monitor commands in the system. It is equally important that the enduser can get confirmation that a command has been executed on the satellite,and whether the execution was successful or not. Thereby the user knows whathas happened at the satellite. This controlling can be seen as a human filteragainst mistakes. Through interviewing end users of the system it got obviousthat the users expect this controlling to be present in the system.

3.1.2.1 The Time Line

To get a good overview of the time line and the command stack, it is desirable tohave tables for both commands and passes, and some graphics so the user quicklycan get an overview of the time line. As satellite commanding is not a matterof fast commanding, the graphics should be prioritized lower than the tables,as tables can show more information about commands and passes. Graphicscan be used to give information about the relationship between commands andpasses, and the power of graphics should therefore not be neglected.

3.1.2.2 Suggestions over auto-handling

Since end users want full control of the mission planning the system should neverdo any task changing the time line automatically. Instead the system shouldmake suggestions to the user.

3.1.2.3 Satellite Health Status

On board the DTU Satellite 2 there is a set of sensors embedded. Data fromthese sensors are called house keeping and are acquired in the database, at theMCC, as data packages. Surveying the house keeping data have two purposes:

• An indication if the satellite is in danger and user action is needed

• Analysis of the data to know more about how a satellite is, in an environ-ment like space

Page 28: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

18 Project Requirements Analysis

Therefore it could be a usable feature if the MPS could show these data - boththe newest data and the whole set of data in a given period.

3.1.2.4 Emergency and Pass mode

The MCC introduces these two terms. Emergency mode is when the satellite isin danger and sending commands instantly and with higher priority should bepossible. Pass mode is when the system gets close to a pass on the time line. Inpass mode certain restrictions apply.These features and restrictions should be implemented at the MPS.

3.1.3 Man-Machine Interface

The Man-Machine Interface, also known as the user interface, is the interfacebetween the end user and the system. To make access to the system easier forthe user through this interface, and to realize some of the features suggestedabove, a GUI should be used.

3.1.3.1 Graphical User Interface

A GUI has several advantages and disadvantages. First of all it is more intuitivefor a user to use a graphical interface, and it will make the controlling of themission a much easier task. Second of all it makes input feeding to the systemfaster as some graphical elements can ease the task of inputting data e.g. abutton is faster to press than typing ”Create and Send” in a terminal window.This also lessens the amount of type errors.The disadvantage of using graphic is that it is harder to test, and statementcoverage will be lower for the system overall.

3.1.3.2 Usable

As requirements to a system must be measurable there must be some kind ofmeasurement of how usable the GUI is. A test should be developed with basetasks and see if end users of the system can complete the task with no criticalerrors. A critical error must be defined, together with the test.

Page 29: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

3.2 Other Goals 19

3.1.3.3 Interface Access

It is not desired that everyone can access the MMI. Therefore it is necessaryto implement interface access control, that validates the user of the system.Besides validating the user of the system it is also necessary to validate thecomputer that the MPS is running on. Computers without the prober key andtrust stores [3] should not be able to access the MCC and therefore not the MPS.

3.2 Other Goals

As seen in the mission break down structure other goals than software goals ap-ply to the project. These goals are to provide something to the base organizationand to the project members.

3.2.1 Base Organization

As the ground software is not tested fully as one component, the software issubject to changes. Therefore it is important, that future work on the MPS canbe done without using heaps of resources, understanding how MPS is designedand implemented. MPS should therefore be documented in a well written reportso future developers fast can get the understanding of MPS. It is also importantthat the source code is well documented with in-line comments, so developerscan understand the implementation.

3.2.2 Project Members

In the future project members will develop other software systems, maybe forthe DTUsat2. It is therefore important that the project members benefit fromthe project, by developing competences in software development.

3.2.3 Testing

Testing a GUI is quite difficult using unit testing. Furthermore it is very difficultto make test cases that does not rely fully on the functionality of the MCC. It

Page 30: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

20 Project Requirements Analysis

is therefore decided that the testing of the MPS should be entirely use casetesting. This is decision based on hours of work trying to implement meaningfultest cases. Testing should also happen while developing the software, to finderrors in an early stage.

3.3 Supplementary Goals

All the above stated analysis is based on knowledge known from the start of theproject. As the project progressed, new requirements for the project was found.These was either requirements given by supervisor Hans Henrik Løvengreen orrequirements necessary to fulfill important goals.

3.3.1 New Command Structure

A command structure was designed by the developers of the MCC. It was de-signed so all commands had to have a separate class. It was also designed sothat all commands had to have a type ID. This was found inconvenient for thedevelopment of MPS, and in consultation with Hans Henrik Løvengreen it wasdecided to change the command structure.

3.3.2 Scheduling

The MCC is responsible for scheduling the time line when asked by a client.After several testing by the project members it was realized that the schedulerwas faulty. It was decided to change the scheduler at MCC so it would schedulecorrectly.

3.3.3 Command Type Creator

As the command types of the satellite has not yet been defined, some tool shouldbe made for easy generation of command types. Commands generated shouldbe well formed so the mission control can interpret the commands and use themfor commanding. To ensure well formed commands and easy generation, a Com-mand Type Generator should be developed.These command types must be accessible for the mission control so the system

Page 31: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

3.3 Supplementary Goals 21

always will be able to interpret the commands. It has been chosen to store thecommand types in a file, and it seems a natural choice to choose the XML-fileformat. This seems like a good choice because heaps of editors exist for thisfile format, and is a great markup language to define structures and share thisstructure across different systems.Even though other editors could be used to generate the XML file with com-mand types whenever the structure is known, the need for a Command TypeGenerator is still existing since this tool is specialized in easy and fast generationof command types.

Page 32: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

22 Project Requirements Analysis

Page 33: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 4

Requirements Specification

In the last chapter the purposes and goals of the project got analyzed. Thischapter will state, with foundation in the analysis, what requirements are statedto the project, and how important these requirements are for the project to suc-ceed. From the mission break down structure, in figure 3.1, there are threemain goals for the software development. Each main goal has a section in thischapter that describes what features should be implemented for this goal to beaccomplished. Other requirements to the project are listed in section 4.5 Non-functional Requirements.

4.1 Annotation conventions

To get an understanding of how important a requirement is, all requirementsmust be prioritized. The priority of the requirements specified in this chapterwill be indicated, with inspiration from the MoSCoW method1, by the keywords:must, should, could and won’t.

• Must — Requirements that must be implemented as a minimum for the1http://en.wikipedia.org/wiki/Moscow Method

Page 34: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

24 Requirements Specification

goals to be accomplished. Resources must be allocated to these require-ments.

• Should — Requirements that adds to the software systems functionalitybut not required for it to work. If possible resource should be allocated.

• Could — Requirements that is of least importance but should be imple-mented if resources are available. Alternatively they could be done in laterversions of the software.

• Won’t — Requirements which are considered ideas for future versions,and should not be implemented.

These words will be emphasized using bold format. It is only when this formatis used that the keywords have the meanings indicated above.Where requirements state that the user should be able to, it is implicit that theuser has to use the system to do the task.

4.2 Commanding the Satellite

As described in the analysis the system must have an understanding of com-mands, passes and ground stations, and be able to communicate and synchronizesome data with the MCC. This is reflected in the following.

4.2.1 Functional Requirements

The functional requirements for Commanding the Satellite are:

4.2.1.1 Creation of Commands

a The MPS must offer the user to create commands, by letting the useraccess the functionality to do so at MCC.

b The user must have the opportunity to feed the system the following datafor commands at the MPS’s interface:

• A time of execution

• A destination for the command e.g. a subsystem on the satellite

• Arguments for the command

Page 35: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

4.2 Commanding the Satellite 25

• Whether the user wants to schedule the command himself or let mis-sion control schedule the command

• Whether the command is high priority or normal priority

c The MPS must offer the user to choose that a command shall be executedas soon as possible i.e. letting the command be executed as soon as thecommand is received by the satellite.

d The MPS must make sure that the input data for commands is valid forthe command to be created.

e The MPS should let the user duplicate a selected command, so a copy ofthe command is created.

f The MPS could only let users choose arguments that are valid i.e. let thegraphical elements function as an interface so the user can’t give invalidinputs.

g The MPS could under creation of a command offer to let the command beduplicated in a way, so that a command can be repeated a given amount oftimes with a given interval between the commands, e.g. repeat a commandevery week for the next 4 months, or every time the satellite passes aground station.

h The MPS could under creation of a command offer to add the commandin to an already existing command block.

i The MPS could be able to add a comment for the command describingthe commands purpose.

j The MPS won’t let the user choose the time of execution by giving MPSa latitude or longitude as input, and then set the time of execution for thecommand before submitting the command to the MCC.

4.2.1.2 Command Blocks

a The MPS must offer the user to create command blocks, by letting theuser access the functionality to do so at MCC.

b The user should have the opportunity to feed the system the followingdata for command blocks at the MPS’s interface:

• A base time of execution

• The priority of the command

• The commands that should belong to the command block

Page 36: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

26 Requirements Specification

• An offset time for every command to specify how long after the basetime of execution the command should be executed

c The user should be able to save and load command blocks, so it can beused at a later time.

4.2.1.3 Creation of Passes

a The MPS must offer the user to create passes, by letting the user accessthe functionality to do so at MCC.

b The user must have the opportunity to feed the system the following datafor passes at the MPS’s interface:

• Ground station used for this pass• Start time for the pass• End time for the pass

c The user should be able to create passes at the MPS, by letting the systemcalculate future passes start and end time, based on a TLE-file.

4.2.1.4 Creation of a Ground Station

a The MPS must offer the user to create ground stations, by letting theuser access the functionality to do so at MCC.

b The user must have the opportunity to feed the system the following datafor a ground station at the MPS’s interface:

• Name of the ground station• Longitude of the ground station’s position• Latitude of the ground station’s position• Altitude of the ground station’s position• The host that runs the ground stations software• The RMI port on which MCC should connect to the ground station• The TCP port on which MCC should connect to the ground station• The login object of the MCC• The user name for accessing the ground station with the correct pass-

word

c The MPS should only let valid ground stations be created, by checkingthe user given input.

Page 37: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

4.3 Controlling the Mission 27

4.2.1.5 Submitting created elements to Mission Control Center

a All data flow between the MPS and the MCC must go through the RMI-interface given by the MCC.

b No data, which is a part of the time line, must at any time be created atthe MPS without being submitted to the MCC.

4.2.1.6 Handling Emergency and Pass mode

a While the Mission Control is in emergency mode the user must be ableto create emergency commands, in the MMI.

b While the Mission Control is in pass mode and emergency mode the usermust be able to create emergency LIVE commands, in the MMI.

4.3 Controlling the Mission

As described in the analysis controlling consists of three elements:

• Monitoring events

• Analyzing the events

• Acting on the analysis

The following reflects these three elements.

4.3.1 Functional Requirements

The functional requirements for Controlling the Mission are:

4.3.1.1 Show time line of the mission

a The system must show commands in the system to the user.

b The system must show passes in the system to the user.

Page 38: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

28 Requirements Specification

c The system should let the user monitor a specific part of the time line,giving it a start and end time.

d The system should let the user do monitoring in a graphical way, so abetter overview of the time line can be obtained.

e The system should let the user navigate in the time line in a graphicalway, i.e. to zoom and drag on the graphical time line.

f The system should update the GUI from the data base when the userwants it.

g The system should update the GUI from the data base with a certaintime interval.

h The system could update the GUI from the data base with a certain timeinterval, given by the user.

4.3.1.2 Editing functionality for the time line

Editing in the time line has certain restrictions given by the MCC. These re-quirements must therefore apply to the MPS as well. Editing in the followingcontext is meant as modifying or deleting of an element.

a To edit a command in the system, the command must be in a state thatsupports editing, i.e. not being transmitted, have been transmitted orexecuted.

b To edit a pass in the system, the pass must be in the future i.e. have astart time after the current time.

c To edit a command block in the system, the command block’s commandsmust be in a state that supports editing, i.e. not being transmitted, havebeen transmitted or executed.

d The system must let the user edit commands in the time line, with therestrictions stated above.

e The system must let the user edit pass in the time line, with the restric-tions stated above.

f The system must let the user edit command blocks in the time line, withthe restrictions stated above.

g The system must let the user modify the state of commands in two way:

Page 39: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

4.4 Man-Machine Interface 29

• Verifying a command, changing the state to have been verified.

• Scheduling the time line, changing the state of commands, in thefuture, to have a pass.

h The system should be able to calculate a number of future passes specifiedby the user and match these with the passes already in the system, andthereby generate suggestions for modifying, deleting or creating passes inthe time line.

i The user should be able to specify a minimum horizontal degree, whichpasses should be above to be suggested by the above feature.

j The user should be able to specify from where to download the TLE file,and where it should be saved on the local computer.

4.4 Man-Machine Interface

The Man-Machine Interface is the the interface that is offered to the user.The interface offers a range of functionality. The functionality is stated in theabove sections. This section will describe the functional requirements to theinterface e.g. when the user can access the features of the MPS, or how thegraphical interface architecture is setup. Furthermore this section will describewhat requirements that apply for the usability.

4.4.1 Functional Requirements

The functional requirements for the Man-Machine Interface are:

4.4.1.1 Graphical User Interface

a The Man-Machine Interface must be a graphical interface.

b The interface should have a similar look as the operative system i.e.implement a look and feel feature that gives the look of the GUI the sameas the operative system.

c By double clicking a command in the table, the system could show infor-mation about the command as well as command history.

Page 40: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

30 Requirements Specification

d The user should have the option to view the time line by a predefinedsetting, such as today or this month.

e THe user should have the option of choosing the date format for the wholesystem e.g. setting the date format to showing the date as 2008-04-05 or5/4-08.

f The interface could allow the user to select colors for different states ofcommands, which will be enforced allover the interface. These settingsshould be remember next time the interface is loaded.

g The graphics in the interface won’t be dynamic i.e. follow the windowssize.

4.4.1.2 Usable

a The test, developed as a non-functional requirement, should be passed.Pass requirements is that no critical errors are made during the test.

4.4.1.3 Interface access

a The Man-Machine Interface must only be accessed if the user have cre-dentials at the MCC.

b The Man-Machine Interface must only be accessed if the user has accessto MPS’s key- and trust store.

c The user should specify where MPS’s key- and trust store is located onthe users computer.

d The user must feed the system with the pass words for the key- and truststore, to access the MPS.

e The system could save the location of the key- and trust store, and theirpasswords, in the registry, so the user will be given the path to the key-and trust store, and their passwords, if logged in successfully before.

f The interface must not be accessed if MCC is not running.

g The user could be informed why the user cannot access the interface, ifthe access fails.

h All access to the system won’t be logged, logging which users have ac-cessed the system.

Page 41: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

4.5 Non-functional requirements 31

4.5 Non-functional requirements

To clarify requirements not related to the actual features of the software system,a number of requirement to the project are identified in the following sections.

4.5.1 Project constrains

4.5.1.1 Platform

The software must be implemented so that it is platform independent. Javahas been chosen as implementation language.

4.5.1.2 Technology Constrains

The DTUsat2 project are using big monitors with high resolution, so the systemsgraphical user interface should not worry about the monitor of the computer itis running on.The computer running the system will be dedicated to the system, so resizingand small windows for the graphics should not be weighted high when develop-ing.

4.5.1.3 Time

The software must be implemented, tested and documented within the timescope of the project. The time scope is set to be 400 working hours per projectmember i.e. 800 man hours in total. The project starts at 1st of February andends the 27th of June.

4.5.1.4 Budget

The software have no financial backing, thus no budget exist for the project.

Page 42: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

32 Requirements Specification

4.5.2 Quality

The quality insurance procedures of this project will be limited to three mainareas:

• The insurance of quality of documentation

• The insurance of quality of implementation

• The insurance of quality of testing

4.5.2.1 Documentation

To ensure the quality of the documentation the following requirements apply tothe project:

a Every document produced for project delivery must be approved by bothteam members.

b The commenting of all implemented Java code should use the javadocstandard.2

c The software must be documented in such a way that both end users ofthe system, and developers adding to the system, can obtain the neededinformation from the report documenting the system.

4.5.2.2 Implementation

To ensure the quality of the implementation the following requirements applyto the project:

a The system developed must be extensible, so future features to the systemeasily can be implemented i.e. no major changes to the system architectureshould be made.

b The system developed should be extensible at runtime, so that the sys-tems behavior can be modified at runtime.

2http://java.sun.com/j2se/javadoc/

Page 43: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

4.5 Non-functional requirements 33

c The system developed should be maintainable, so that system defectseasily can be corrected, and the system easily can be modified to meetnew requirements for future versions.

d The system developed must be reusable so changes in the architectureonly occurs one place, and implementation time is reduced.

4.5.2.3 Testing

To ensure the quality of the testing the following requirements apply to theproject:All use cases, found in appendix 8.1.2 must be run successfully with alternativescenarios as well. Furthermore a usability test must be run on at least two endusers, and measure if any critical errors occur using the system. A critical erroris defined as an error where the user is stuck and cannot fulfill the task given inthe test.

Page 44: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

34 Requirements Specification

Page 45: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 5

System Design

To develop a good functional software system it is important make good designdecisions. This chapter includes the information on what thoughts was behindthe design of the software system, as well as why the decisions taken are bettersolutions to the problem than other solutions. It is important to keep in mindthat a good decision is not always the one that is most innovative or the one withbest performance. In projects some constrains makes decision making harder asother aspects like time, money and resources apply.

5.1 Design Guidelines

To obtain a high quality of software system design, it is essential that membersof the project group follows some guidelines regarding the design. To save timein the implementation part it is also important to use known design patterns andelements of reusable software. By reusing known patterns it is also more prob-able that the system is designed more generic, as these solutions are commonsolutions to problems in software designing, and it ensures that the solution isof higher quality as many developers have used this solution successfully before.

Page 46: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

36 System Design

5.1.1 Design Philosophy

The design philosophy must be seen as the guideline that the project membersopt to use to develop the software system. Project members should always keepthe following list in mind while designing the software system.

• There must be a clear relationship between elements in the system, andan interface that provides the access needed but nothing more.

• It is strived to have as few lines of communication between elements. Thiswill invoke a higher percentage of path coverage in the testing phase.

• Reuse of designs is strongly recommended when fitting to a certain prob-lem.

• It shall be easy to get an overview over the program, thus the system musthave a simple architecture, but still offer the functionality from section 4.

Some goals to the project have several design solutions. In the chapter 4 Re-quirements Specification, all the requirements to the system are stated. Thissection will discuss which decisions are possible for the design, so that imple-mentation of the features can be done smart and easily.

5.2 New Command Structure

As mentioned in the analysis the command structure defined by MCC did notoffer the wanted flexibility and therefor it should to be re-written.As designed by MCC a Command class should be a general representation ofa command holding data which should be used for commands in any mission.The MCC then proposed that each command type in a specific mission neededits own class inheriting from Command.Whenever a command instance of any type where to be created an implemen-tation of a class CommandFactory were used. It generated a command basedon the typeID and parameter string.The UML of this idea can be seen in figure 5.1. The design suffered the followingproblems:

• Command has a abstract method getCommandTypeID() which all inher-ited classes should implement with the purpose of returning the TypeID,

Page 47: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

5.2 New Command Structure 37

Figure 5.1: Old command structure

however it is mission specific if a command should contain this info andtherefor should not be part of Command.

• Arguments (called parameters in old MCC structure) are simply repre-sented by a single string. A method legalParameters() implemented ineach command should then return if the parameter string is legal. Thismeans that for every command type a algorithm needs to be implemented.

• To access the structure of the command type Java retrospection wasneeded.

To solve these issues the design seen in figure 5.2 has been made. In this designonly one class DTUsat2Command inherits from Command.

The Command class no longer contains a typeID or parameter, but instead itnow has a attribute called ”commandData” which describes the mission specificdata - this will be explained later.When a DTUsat2Command is created it contains a CommandType, a Mod-uleID, and some arguments. The CommandType represents the structure of thecommand, while the module ModuleID and arguments specifically tells the des-tination of the command and what the arguments are. The number and typeof arguments are defined by the CommandType.Command Type has a name, typeID, description, a list of legal destination (atleast one), and a list of required parameters (which might be empty).

Page 48: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

38 System Design

Figure 5.2: The new command structure

Page 49: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

5.3 Overall design of MPS 39

The paratemers are modelled in a Parameter class which has a name, descrip-tion, and type. The type of the parameter is modelled as an abstract Param-eterType. From this class for different parameter types inherit: IntParameter,DoubleParameter, BooleanParameter, or StringParameter. The first two typehas upper limit, lower limit , default value, and accuracy defined.

The DTUsat2CommandFactory builds DTUsat2Commands based on a ”com-mandData” string which hold information about the mission specific data: com-mand type, module destination, and arguments.The format of the commandData string is as follows:

type-destination-argument1-argument2-argument3...

The string is parsed and if it is well-formed the DTUsat2CommandFactory willcreate a DTUsat2Command with the instance data set correctly. The first objectcalled type defines the command type and thereby also the format for the restof the commandData string.The new command structure has the following advantages:

• It makes it easy to implement a very generic user interface for settingup (create or modify) commands. Whenever the wanted command typehas been chosen it is possible to present the user with with options forthe arguments, based on the ParameterType, and options for choosing aModuleID.

• Clear defined parameter types which has possibilities to include unit, up-per and lower limit, accuracy and default value.

• Command types has descriptions

• Parameters has descriptions

5.3 Overall design of MPS

A great amount of the work in this project deals with development of a well-designed GUI. It was decided to use the well-known Model-view-controller pat-tern. This is a good way to separate the business logic (Model) from the codecreating the graphical elements (Views) and the code responsible for dealingwith user actions (Controller) in the GUI.This classical Model-view-controller design is seen in figure 5.3.

Page 50: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

40 System Design

Figure 5.3: Classical design of Model-view-controller.

In MPS all views will have a corresponding controller, unless the case whereit is not possible to do any action in the view, but there has only been rarecases like this in the project. The GUI mainly involves around one windowTimeLineView. From this window much of the functionality is available andfurther more it has the graphical elements to open all other views, which isdone through the TimeLineController.Most of the views’ purposes is to show details about the timeline or provide pos-sibility to manipulate the timelime, which the controller handles through RMIcalls. There can only exist one timeline and access to this is needed allover thesystem, so it is a natural choice to implement it as a singleton. This is done inthe class TimeLineModel (see section 5.3.1.1) which then works as the centralmodel for all the views and controller.Similar it is needed to have one instance of a RMI Session interface to the MCCwhich can be access from everywhere. A singleton class Client holding this in-stance has been created. This class needs to be set up at login.Finally, for the same reasons, a singleton implementation of a class DTUsat2CommandMap,holding a map of all existing CommandType for the DTUsat2 project, wereneeded.The idea behind the overall design can be seen in figure 5.4. In the three follow-ing sections more details about the model, view and controllers are explained.

5.3.1 Model

As described in the above section the central model is the TimeLineModel,this class will be described in this section. Also the Client will be explained.Two additional models CommandBlockModel, used for creating/editing andsaving/loading of command blocks, and TLEUpdateModel, used to syncronizepassed with the latest from a TLE file, will be described.

Page 51: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

5.3 Overall design of MPS 41

Figure 5.4: The overall design concept.

Page 52: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

42 System Design

5.3.1.1 Time Line Model

As described above the TimeLineModel should be implemented as a singleton.At MCC the timeline has already been modelled in the class TimeLine whichholds the commands, command blocks, and passes in the timeline. An instanceof TimeLine can be retrieved through a RMI call for the MCC. It has beendecided to reuse this design, so the TimeLineModel in MPS contains a localcopy of the TimeLine object.The Time Line Model can be seen in figure 5.5.

Figure 5.5: The TimeLineModel.

Furthermore TimeLineModel should know which GroundStations exists andhold details about emergency mode and pass mode status. These informationcan also be retrieved through a RMI call for the MCC.One could argue that RMI calls could be used everytime information about thetimeline is needed, however information about the timeline is used extensivelyallover the program and therefor the GUI would get a severely slow-down ruingthe user experience - therefor a local copy of the timeline is needed.The TimeLineModel has a important method loadDataFromDB() which is calledto get the latest copy from MCC of all of the above described objects. Thismust be done right after a RMI call which manipulates the timeline, so that thechanges also will be reflected in the local model.Finally TimeLineModel has the information about which time span (start andend) of the timeline is currently being shown in the GUI. This is done becausethe time span of the table of commands and the graphical view of the timelineneeds to be syncronized and therefore a central place for storing the time spanis needed. TimeLineModel also has methods for setting the time span to somepredefined periods like today, tomorrow, or this week.

Page 53: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

5.3 Overall design of MPS 43

5.3.1.2 Client

A class ClientCreator is used to instantiate the Client class, which as previouslydescribed has been implemented as a Singleton, based on information aboutkeystore, truststore and MCC login. These information will then be containedby Client. The Client has a RMISessionMinimalTrust, which is the most generalRMI interface offered by MCC, and thereby also the one with the least rights.All other RMI interfaces to MCC (Medium, Full, and Admin) inherits from theRMISessionMinimalTrust.Client will contain a variable specifying which trust level the user has. Thiswill be used to know which RMI interface the user are allowed to cast the RMIinterface to. Methods for doing this is within Client.The Client structure can be seen in figure 5.6.

Figure 5.6: The Client structure

5.3.1.3 Command Block Model

As described in the analysis a feature for setting up command blocks using off-sets between their time of execution is needed, and further more it is importantto be able to save these.At MCC a command block has already been modelled in the class Command-Block, however this is a simple collection of commandIDs, which does not sup-

Page 54: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

44 System Design

port easily implementation of the feature described above. A CommandBlock-Model has been made at MPS. The CommandBlockModel inherits from a col-lection of Command. Furthermore it contains a start time of execution and amapping of the commands and their Offset from the start time of execution.An Offset is defined by a unit (miliseconds, seconds, minutes, or hours) and avalue.A PredefinedCommandBlock has been introduced as the object used for saving(serializing) a command block for later use. It has a name, description, and acollection of PredefinedCommand.The PredefinedCommand holds exactly the needed data about the commandneeded when loading a command block later on: the ”commandData” stringspecifying mission specific data, and a Offset or a indication that the commandshould be ASAP.The CommandBlockModel can easily be build from a PredefinedCommand asdescribed in the implementation.

5.3.1.4 TLEUpdateModel

The TLEUpdateModel contains one Satellite and a list of Predict (one foreach ground station in the system). Both these classes are borrowed from the”common-package” of the Ground Segment. The Predict class is responsiblefor doing advances calculations to get the next pass for a satellite after a giventime.TLEUpdateModel has methods for downloading the latest TLE file from theInternet. Furthermore it has methods to calculate a given number of futurepasses for the satellite from any number of ground station, where each pass hasto have a minimum horizontal elevation.A new class Suggestion is introduced to generate suggestions about recom-mended pass changes. A Suggestion has a type which can either be ”update”,”delete”, or ”modify”. It also contains old and a new pass - one of this mightnot be instantiated depending on the suggestion type.

5.3.2 View

When the program is launched the LoginView is opened and if the user enterslegal information he will gain access through to the TimeLineView. This is themost central place of the GUI since most of the monitoring of commands andpasses is done here, and it is also from here all other windows can be opended.The TimeLineView (as seen in figure 5.8 and 5.3.2) includes the following panels:

Page 55: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

5.3 Overall design of MPS 45

Figure 5.7: The TLEUpdateModel structure

• CommandTableView - To show data about all commands.

• PassesTableView - To show data about all upcomming passes.

• TimeLineGraphicView - To graphically represent the time line with com-mands and passes.

The time span of CommandTableView and TimeLineGraphicView are alwayssynchronized. This means if the user for examle zooms (by scrolling) in Time-LineGraphicView these changes must be reflected in CommandTableView andvice versa. The PassesTableView however always will show the upcoming passes.The three panels are all syncronized regarding selections. This means that if aselection of a command or pass is made in any of the panels it is reflected in theother ones.

5.3.2.1 Creation and editing - All-in-one

As the MMI has to offer both creation and editing for several different objects,the graphical elements should be reused and build in the same way for bothcreation and editing windows. The values of the graphical elements will then

Page 56: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

46 System Design

Figure 5.8: The TimeLineView and its components

Page 57: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

5.3 Overall design of MPS 47

vary depending on whether it is a creation or editing task, especially for inputfields, which will be empty at start of creation task but have predefined valuesat start of a editing tast.This approach has been used for the creation/editing windows for: Commands,Command Blocks, Passes, Ground Stations, and Users.

5.3.2.2 Generic building of view for command setup

As seen in the analysis, whenever creating or editing a command a large numberof options/settings can be specified.When creating a new single command all these options will apply, however inother situation it only makes sense to offer some of them.For example when creating a Emergency Command only CommandType, Pa-rameters, and Destination should be specified.Another example is when editing a command which is part of a block contain-ing more than one command it is not desirable to offer the option to specifyPriority, since the priority applies to the whole block, and therefor only shouldbe possible to set when using the ”Edit Block” function.It is realized that the graphical elements for creation and editing of commandsneeds to be build in a very generic way, so depending on the situation a withwith the appropriate options can be created. However the CommandType, Ar-gument(s), and Destination will always be needed.A class CommandSetupView has been responsible for creating a window forcommand creation/editing with optional panels. The implementation of this isdescribed in section 6.6.In figure 5.9 CommandSetupView has been used to buld a view SingleCom-mandSetupView for creation of new commands.

5.3.3 Controller

As described in the introduction to this section every view has a controller,however only the TimeLineController will be described here since it is the con-troller opening up for all other views. Figure 5.10 illustrates some of the actionshandles by TimeLineController.

Page 58: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

48 System Design

Figure 5.9: Example of CommandSetupView used to generetate the windowSingleCommandSetupView

Page 59: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

5.3 Overall design of MPS 49

Figure 5.10: Actions of TimeLineController

Page 60: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

50 System Design

5.3.4 UpdateThread

A class UpdateThread is designed to run a very naive thread, which updates thedata of TimeLineModel and the GUI at a given interval. This interval can beset as well as the thread can be stopped or started easily. When stopped thethread polls to access every 10 seconds.

Page 61: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 6

Implementation

This chapter will describe non-trivial implementations of components in MPS.

6.1 Singleton Implementations

Both TimeLineModel, Client, and DTUsat2CommandTypeMap have been im-plemented as Singletons using a Java 5 solution1. This implementation ensuresthat the object will not be manipulated from two sides at once. This could bea problem whenever the update-thread is running.

6.2 Saving and loading files - XML framework

It is wanted to save the different command types of the DTUsat2 project in aXML-file. This could be done by witting a parser but a better solution wouldbe to use a already existing and tested framework.For serializing and de-serializing a XML-file it was decided to use the ”Simple

1http://en.wikipedia.org/wiki/Singleton pattern#Java 5 solution

Page 62: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

52 Implementation

XML Serialization 1.7.2” 2 framework. This choice was made since it seemedrelatively easy to learn and had good recommendations.In short the framework works by putting different annotations on all instancedata of a class. The instance data which are objects should further more haveannotations in their class and so on. The classes can them be serialized withthe framework.It was also decided to use this framework to save PredefinedCommandBlocks.

6.3 Command Type Editor

A small tool DTUsat2CommandTypeEditor for creating XML files containingmaps of CommandType has been implemented. The tool can be seen in use infigure 6.1.

6.4 Command Type Map

As described in the design section 5.3 a DTUsat2CommandTypeMap has beenimplemented as a Singleton.The first time DTUsat2CommandMap is instantiated a file ”CommandTypeMap.xml”is loaded from the recource files. This file is de-serialized using the above de-scribed framework (see section 6.2) returning a DTUsat2CommandTypeXMLFile.In this class a HashMap with CommandType as values and their IDs as keyscan be found, and passed on to the Singleton DTUsat2CommandMap.Note about the serializeble class DTUsat2CommandTypeXMLFile: The classhas a ArrayList of CommandType which is serialized for a nice looking XML-file. However when the class is de-serialized a HashMap is wanted. A methodcreateHashMap is made for this convertion. This method has a ”@commit”annotation which means it will be called right after the de-serialization andthereby automatically generating a the wanted HashMap.

2http://simple.sourceforge.net/

Page 63: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

6.4 Command Type Map 53

Figure 6.1: The DTUsat2CommandTypeEdit in use.

Page 64: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

54 Implementation

6.5 Client - user access

6.5.1 Setting up acces

Before getting in to MPS the user is presented a login screen where informationabout keystore and truststore password and location needs to be specified. Fur-thermore login information to the MCC needs to be specified.The ClientCreator is responsible for checking the validity of the specified key-store and truststore. If these are valid the Client will be setup.When setting up the Client we need to find out which trust level the user hasat MCC. This is done by the method setupSessionType which tries to cast theRMI interface to a RMISessionAdminTrust, if this fails it will be tested if it canbe casted to a RMISessionFullTrust. It continuous this way down trying untila cast operation succeeds (and then user trust level is set) or a exception willbe thrown at the end.

6.5.2 Using RMI Interface

The trust level attribute in Client is used to test which functions should beallowed to the user. Whenever the RMI Interface is needed to do a operation onMCC, Client contains different methods to return a cast instance of the RMIInterface matching the wanted trust level. All these methods makes sure toping the RMISession since a timeout might have occurred - if this is this case are-login is made.

6.6 Generic building of view for command setup

The class SetupCommandView is capable of creating a JPanel with optionalTOE, Priority, User-given pass, and Block panels based on boolean values ofthe constructor. As with other views there also exists a second constructor forediting a command which takes an additional argument specifying which com-mand to edit - all graphical elements value is then set based on that command.

Page 65: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

6.7 Command Blocks 55

6.7 Command Blocks

The design of the CommandBlockModel has already been described in section5.3.1.3. The class has been implemented in such a way that it can be build inthree different ways:

• With a empty constructor for creation of a new command block

• With a constructor taking a CommandBlock (as specified by MCC) asargument. It is then needed to find the command in the block with thelowest time of execution. This will be the start time of execution. Therest of the commands offset unit and value can then be calculated fromthis with mathematics.

• By a method buildFromPredefinedCommandBlock() which takes a Pre-definedCommandBlock as a argument an the sets the data if the currentCommandBlockModel.

6.8 Tables

It was realized during the project that a good way of representing large amountsof data to a user is through tables. Therefor tables have been used at very centralplaces in the GUI: The command overview and passes overview.The tables are made as JTables. For these tables AbstractTableModel has beenused to specify the contents of the table, and DefaultTableCellRenderer hasbeen used to make different colors and fonts in side of the tables.Furthermore some of the tables use RowFilter.regexFilter to filter the contentsbased on a string typed by the user. The table in CommandTableView haveadditional two RowFilter.dateFilter which specifies that the commands in thetable must be between the start and end time defined in TimeLineModel.

6.9 User input of time - DateTimeSpinnersPanel

Several places in the program the user needs to input a time to the system. Itwas found that the most user friendly way of offering this feature where to useJSpinners, having a SpinnerDateModel to validate the input is of the correctform.With usability in mind it was decided to place two JSpinner right next to each

Page 66: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

56 Implementation

other: One to specify the date and one to specify the time on the given date.A class DateTimeSpinnersPanel is capable of creating the two spinners and itcontains methods to concatinate the date and time from these two spinners.In TimeLineView this object is used twice to make it possible for the userto specify the time span (start and end) of the currently viewed time line.A ChangeListener is implemented which updates the start and end in Time-LineModel on user action. However it is also possible to change time span byscrolling on the TimeLineGraphicView. Whenever this is done the value of thetwo spinner in TimeLineView must be set manually, but doing this invokes thelisteners which were found to produce so problems. To avoid this the Change-Listeners on these spinner are remove before the action and added again afterworth.

6.10 Time Synchronization

At the time of writing no time synchronization has been created at the GroundSegment. If this is done in the further more it can easily be implemented inMPS since the TimeLineModel contains a method getCurrentTimeInMillis()which is used allover MPS to get the current time. At the moment this methodsimply returns the computers current time.

6.11 Program Settings

The user should have the opportunity to change some program settings at run-time, like the coloring of commands or the date format used throughout theprogram. These settings needs to be remembered the next time the programis launched. As MPS does not have its own data base, MPS will need to storethese program settings somewhere else. It was decided that the program set-tings should be stored in the registry.

To do this it was decided to use the Java class Preferences. A class called MP-SPreferences is responsible for creating a instance of Preferences, and futuremore it contains methods for getting preferences from the registry and puttingpreferences in the registry. Whenever running the program a system variablecalled ”mpsPreferences” must must be defined.

Page 67: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

6.12 MCC Workarounds 57

6.12 MCC Workarounds

It was decided that it should be possible to let the user specify a pass to acommand at creation. However MCCs RMI interface does not offer the optionto do this, it only offers the possibility to set a user given pass for a alreadycreated command, so a small hack has been made.If a user given pass is specified at creation, then right after the command hasbeen added to the database, the command in the data base with the highestcommand id is found, and the pass of this command is edited using a RMI call.The option of adding a new command to an existing block is done in the sameway. The downside of doing this is that the command will exists in its own blockfor a very short time before it is moved, and therefor leaving an empty blockin the system. Some memory consumptions and higher IDs for future blocksare the side effect of this, but it was agreed that the significance of this wasirrelevant.

6.13 MCC Alterations

As problems were encountered working with the MCC it got decided to changecertain things in the MCC:

• The scheduler was proven faulty.

• The MCC introduces a CleanUp function for the time line. Testing showedthat the cleaner could get the system into a state where scheduling andmodifications of commands got impossible.

The scheduler and the cleaner is related as the scheduler calls the cleanUp()method. It has been impossible to pin point where the error occurs, but somealterations have been made, and the altered system has been tested.

6.13.1 Scheduler Alteration

The scheduler did wrong calculations, meaning that commands, more often thannot, got a pass, for transmitting the command, after the command was to beexecuted. A small change was made in the algorithm findPass() to help solvethe issue.The scheduler also tried to find passes for commands that was before the first

Page 68: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

58 Implementation

pass, which lead to errors. A variable called firstPassStartTime, that had thevalue of the first pass in the futures start time, was introduced, and commandshad to have a time of execution after this time to be part of the scheduling.To be able to schedule the scheduler have to un-schedule commands, so it couldgive them new passes. The un-scheduler algorithm was likewise faulty as it didnot un-schedule commands with the ASAP execution time, and it tried to un-scedule commands in the past.A new un-scheduler has been implemented in the method schedule(), to solvethis problem.Finally scheduling of commands in a far future make little sense, and the sched-uler should take an argument specifying how far in the future the schedulershould look for commands. This feature was implemented, so a user, in set-tings, can define how far in the future the user wants to schedule.

6.13.2 Cleaner

The cleaner was modifying commands in the past removing them from the timeline, but not from the database. First of all this was against the philosophy ofthe MPS, as even elements in the past should be shown in the time line. Secondof all it invoked errors so scheduling of the time line got impossible. After testingit got decided to remove cleaning function from the MCC. All tests so far showsthat the errors in scheduling now is gone, and that it does not invoke otherproblems, when cleaning of the time line is not done.

Page 69: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 7

Testing

To prove that the software developed is of high quality, the system needs to betested. Testing has two main reasons:

• To find errors in the software and correct them

• To prove that the software is running correctly

To test successfully a test strategy needs to be implemented.

7.1 Test Strategy

As stated in the analysis, testing of the MPS is complex. First of all most classesin the system is graphical components that cannot be easily tested. The otherproblem is that the whole modeling is done at MCC, and testing it again wouldnot make sense, as it would require major changes to MCC, as it is using theold command structure.After looking through all classes of the MPS, the project members discussedwhich ones should be tested and not. In the end only one class got tested usingunit testing: DTUsat2CommandFactory.java. All other classes made no sense

Page 70: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

60 Testing

to test as it would not test the MPS, but MCC. The GUI could likewise not betested.Testing is therefore done by running the use-cases made for the analysis, foundis appendix 8.1.2.A usability test have been made as well. The test was run on Hans HenrikLøvengreen and Rene Fleron. The test can be seen in appendix 8.1.2.

7.2 Regression Test

There exists no regression test for the MPS, other than re-running the use-cases.

7.3 Test Results

The unit test of the DTUsat2CommandFactory.java showed no errors.Use case test have all run successfully, and no errors were discovered.The usability test was run and no critical errors were made, and was thereforesuccessfull.

Page 71: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Chapter 8

Project Conclusion

The Mission Planning System has been developed and documented with all im-portant requirements accomplished. The system is able to plan the mission ofthe DTUsat2. Therefore the project has fulfilled its purpose.

The project members are both convinced, that this project have lead to increasedcompetences in developing software. The project have furthermore resulted inthe project members having developed skills in project management, and gainedknowledge of how a project works, where the product is actually going to beused in the real world.Both project members are likewise convinced that the DTUsat2 project willbenefit from the developed system.

8.1 Perspective

Looking at the project in a higher perspective, it is important to ask the follow-ing questions:

• At what state is the software system at the time being?

Page 72: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

62 Project Conclusion

• What can the Mission Control accomplish and what can it not?

• What consequences does this project have on the DTUsat2 project?

To answer the first question, it has been concluded that the software has ful-filled its goal, and is ready for release. As other requirements have not beenimplemented, the software can be developed further. If the DTUsat2 can findresources, the Mission Planning System could be developed further to includemore features, such as a status variable statistics module, for analyzing datasent from the satellite.

8.1.1 The State of Mission Control

The MPS can, at the time being, handle to access Mission Control Center’sfeatures. Some problems have been occurring under testing, where the MCCthrows exceptions when calling functions on the MCC. This situation have beendiscussed many times in the project, and with the supervisor, but only minorfixes of the MCC has been done, and errors still exists at the MCC. Furthermoresome plug-ins have to be developed for the MCC. The main plug-in missing atthe time being is the Verifier, for verifying commands that might be harmfulto the satellite. Before the satellite is to fly it is also important to define astructure for packets sent and received by the satellite and the ground segment.The conclusion is that Mission Control as a whole is not ready to control themission of the satellite yet, but will be when more testing is done on the com-ponent as a whole.

8.1.2 Experience

After the project end, the project members both had some ideas on how theywould do things different for the project if started up again. The MPS was a lotmore complex to develop because it had to communicate with a very complexsystem as the MCC. More time should have been put into interviewing thedevelopers of the MCC, even though they were not connected to the DTUsat2project any more.More time should also have been used on coming up with a better test solution.The MPS have only been tested using use cases. This form of testing can hardlybe seen as sufficient for a big piece of software as the MPS. The complexity of

Page 73: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

8.1 Perspective 63

testing the MPS can be seen in the analysis, and because of that it would takemany resources to test the MPS with other testing than use-cases.

Page 74: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

64 Project Conclusion

Page 75: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Bibliography

[1] Erling S. Andersen, Kristoffer V. Grude, Tor Haug, Goal Directed ProjectManagement, 2004

[2] Rene Fleron, http://www.dtusat.dtu.dk/fileadmin/docs/DTUsat MDD 1 21.pdf,2007

[3] Andreas Andersen Kjaer, Kenneth Agerskov Jensen, Mission Control Cen-ter, 2007

Page 76: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

66 BIBLIOGRAPHY

Page 77: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Appendix A - Use Cases

Page 78: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

68 Appendix A - Use Cases

Use case ID: 01 - Commanding

Purpose This use case describes how to create a command and submit it to Mission Control Center’s database

Actor A medium or higher trusted user

Pre-conditions None

Scenario

Action Action System

1. The user presses a button opening a dialog. A dialog is created and shown to the user.

2. The user selects a command type from a list of command types.

The dialog changes appearance to represent the information needed for this command type.

3. The user feeds the system the information required for this command type and presses a button to end his actions.

The system creates a command with all the information given by the user and submits it to the database via a RMI from the MCC.

Post-condition

MPS: A command is now added to the model. MCC: A command has been added to the database.

Alternative course of events

2. The user searches for the command type by using a search and sort features for the table, before selecting a command.

The system searches and sorts the table to fit the users input.

3. The user feeds the system data that does not comply with the command type, and presses a button to end his actions.

A dialog will appear telling the user that the data fed to the system is inconsistent with the command type. The command is not created.

3. After feeding the system data the user changes the command type.

The dialog changes appearance to represent the information needed for this command type. Old data fed the system is not stored.

2. The user closes the dialog by pressing a button or uses the OS’s button to dispose of the window.

The dialog is not shown anymore. No data is stored.

Page 79: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

69

Use case ID: 02 – Creating a Pass

Purpose This use case describes how to create a pass and submit it to Mission Control Center’s database

Actor A user with medium trust or more

Pre-conditions A ground station present in the database.

Scenario

Action Action System

1. The user presses a button opening a dialog A dialog is created and shown to the user.

2. The user selects a ground station, and feeds the system start and end time for the pass, and ends his actions by pressing a button to create the pass.

A pass is created, and via a RMI the pass is added to MCC’s database, with the given pass information. The dialog is disposed of.

Post-condition

MPS: A pass has been added to the model. MCC: A pass has been added to the database.

Alternative course of events

1a. The user presses an alternative button that opens an alternative dialog. This dialog will offer the user to add a number of passes, which have predefined start and end times, calculated from information regarding the satellite and the ground station.

A dialog is created and shown to the user.

1b. The user selects the passes that he wants to add to the system, and ends his actions pressing a button to add the passes.

The selected passes are added to the database, and the dialog is disposed of.

2. The user feeds the system invalid data for a pass.

The system shows a dialog that informs the user that the data fed to the system is inconsistent with passes.

2. The user closes the dialog. The dialog is disposed of and no data is stored.

Page 80: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

70 Appendix A - Use Cases

Use case ID: 03 – Creating a Command Block

Purpose This use case describes how to create a command block and submit it to Mission Control Center’s database

Actor A medium or higher trusted user

Pre-conditions None

Scenario

Action Action System

1. The user presses a button opening a dialog for creating a command block

A dialog is created and shown to the user.

2. The user presses a button opening another dialog to add a command to the block.

Another dialog is created and shown to the user.

3. The user selects a command type from a list of command types.

The latest dialog changes appearance to represent the information needed for this command type.

4. The user feeds the system the information required for this command type and presses a button to add the command to the block

The system creates a command with all the information given by the user and adds it to the block. The dialog is disposed of.

5. The user repeats action 3. and 4. until the block contains the commands needed

The system adds all the commands to the block

6. The user feeds the information needed for a block and ends his actions by clicking a button

The system creates a block containing the commands given and submits it to the database via a RMI from the MCC. The dialog is disposed of.

Post-condition

MPS: Commands created are now present in the model. MCC: Commands and their block is added to the database.

Alternative course of events

2. The user chooses to load a command block by pressing a button to load a command block

A dialog is created and shown to the user with predefined command blocks

3. The user chooses the command block and presses a button to load the command block

The dialog is disposed of and the first dialog is shown with the command block, showing commands in the block.

6. The user chooses to save the block the user is working on by pressing a button to save the block

A dialog is created and shown to the user

7. The user gives the block a name and presses a button to return working on the command

The command block is saved to a file and the view is disposed of

Page 81: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

71

Use case ID: 04 – Verifying Commands

Purpose This use case describes how to verify commands.

Actor A user with full trust or higher

Pre-conditions Commands in the system to be verified i.e. having a state of “awaiting verification” or “awaiting pass and verification”.

Scenario

Action Action System

1. The user selects one or more commands. The commands selected will be indicated. A button gets enabled to verify commands.

2. The user presses the now enabled button to end his actions.

The commands changes state so the no longer awaits verification, both in the MPS and in the database.

Post-condition

MPS: Commands selected while pressing the button have a state that is not awaiting verification. MCC: Commands selected while pressing the button have a state that is not awaiting verification.

Alternative course of events

2. The button to verify the command is not enabled, because the command/commands are not in a state that allows verifying.

When the user holds the mouse over the button a mouse over tip is shown to the user, why he cannot verify

Page 82: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

72 Appendix A - Use Cases

Use case ID: 05 – Scheduling Commands

Purpose This use case describes how to schedule commands.

Actor A user with full trust or more

Pre-conditions Commands in the system to be scheduled i.e. having a state of “awaiting pass” or “awaiting pass and verification”.

Scenario

Action Action System

1. The user presses a button that schedules commands in the system.

All commands in the system are given appropriate passes for transmission. Commands which have been given passes by the user are unchanged. The button indicates that scheduling is no longer necessary for the system.

Post-condition

MPS: Commands in the system, to be executed in the future, have a state that is not awaiting pass. MCC: Commands in the system, to be executed in the future, have a state that is not awaiting pass.

Page 83: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

73

Use case ID: 06 – Editing Commands

Purpose This use case shows how to edit a command already present in the system

Actor A user with full trust or higher

Pre-conditions One or more commands in the system

Scenario

Action Action System

1. The user selects a command in the system via the MMI interface

The command gets marked. A button gets enabled for editing command

2. The user clicks the now enabled button for editing commands

A dialog is created and shown to the user

3. The user modifies the command as wanted, and end his actions by pressing a button that invokes the modification of the command

The command is modified by the users newly fed options. The dialog is disposed of.

Post-condition

MPS: The command selected has been modified the way the user wished. MCC: The command in the database has changed data.

Alternative course of events

See Use Case 1 - Commanding

Page 84: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

74 Appendix A - Use Cases

Use case ID: 07 – Editing a Pass

Purpose This use case shows how to edit a pass in the system

Actor A user with full trust or higher

Pre-conditions One or more passes in the system

Scenario

Action Action System

1. The user selects a pass in the system via the MMI

The pass gets marked. A button gets enabled for editing pass

2. The user clicks the now enabled button A dialog is created and shown to the user

3. The user modifies the pass by changing its start time and/or end time, and end his actions by pressing a button that invokes the modification of the pass

The pass is modified by the users newly fed options. The dialog is disposed of.

Post-condition

MPS: The pass selected has been modified the way the user wished. MCC: The pass in the data base have changed data.

Alternative course of events

See Use Case 2 – Creating Pass

Page 85: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

75

Use case ID: 08 – Editing a Command Block

Purpose This use case shows how to edit a command block

Actor A user with full trust or higher

Pre-conditions Two or more commands in the same command block

Scenario

Action Action System

1. The user selects a command in a block in the system via the MMI

The command gets marked. A button gets enabled for editing command blocks

2. The user clicks the now enabled button A dialog is created and shown to the user

3. The user modifies the command block by altering settings for the block, and end his actions by pressing a button that invokes the modification of the pass

The command block is modified by the users newly fed options. The dialog is disposed of.

Post-condition

MPS: The command block altered now has altered information MCC: The commands in the block are changed in the database

Alternative course of events

See Use Case 3 – Creating Block

Page 86: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

76 Appendix A - Use Cases

Use case ID: 09 – Emergency

Purpose This use case shows how to enter and exit emergency mode

Actor A user with full trust level or higher

Pre-conditions The system is not in pass mode

Scenario

Action Action System

1. The user enters the Pass Window by clicking a button.

The pass window is created and shown to the user.

2. The user presses a button in the Pass Window making the system go into Emergency mode.

The system is now in Emergency mode, and the Emergency center is now available for adding emergency commands.

3. The user presses the same button as before to exit the emergency center and end his actions.

The system is no longer in Emergency mode, and the Emergency center is no longer available for adding emergency commands.

Post-condition

MPS: MCC:

Alternative course of events

3. The user chooses to add an Emergency command to the system by selecting a command and end his actions by pressing a button to add the emergency command.

The Emergency command is created and added to a table for emergency commands not yet transmitted to the satellite.

Page 87: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

77

Use case ID: 10 – Creation of Command Types

Purpose This use case shows how to create command types for the DTUsat2 mission

Actor A user of the “DTUsat2 Command Editor”

Pre-conditions None

Scenario

Action Action System

1. The user runs the application “DTUsat2CommandEditor”

A window is created and shown to the user

2. The user clicks on a button for creating new command types

A dialog is created and shown to the user

3. The user types in the information for the command and presses a button to add parameters.

A new dialog is created and shown to the user

4. The user types in the information for the parameter, and presses a button to add the parameter to the command type

The fed information is saved and shown to the user in a table. The dialog is disposed of

5. The user clicks a button to create the command type with all the information fed

The command type is shown to the user in the first window. The dialog is disposed of

6. The user clicks a button to save the command type just created

A dialog is created for file choosing and it is shown to the user

7. The user chooses a directory on his computer where he wants to save the command type XML-file, and clicks a button when done

An XML-file is created at the directory that the user chose. The dialog is disposed of

8. The user finishes his actions by closing the application

The application closes, and the window is disposed of

Post-condition

An XML-file at the given destination with information about one command type

Page 88: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

78 Appendix A - Use Cases

Use case ID: 11 – Creation of Ground Stations

Purpose This use case shows how to create a ground station

Actor A user with administrator trust

Pre-conditions No ground station in the system

Scenario

Action Action System

1. The user selects a button for creating ground stations

A dialog is created and shown to the user

2. The user feeds the system with ground station data via the dialog interface, and end his actions by clicking a button to accept the creation of the ground station

A ground station with the given data is created, and the dialog is disposed of

Post-condition

MPS: A ground station in the system MCC: A ground station in the database

Page 89: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Appendix B - Usability Test

Page 90: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

80 Appendix B - Usability Test

Test af brugbarheden af Mission Planning System

Forudsætninger Systemet er installeret og køre nu på computeren, som bruger operativsystemet Windows XP eller Windows Vista.

Et sted køre Mission Control Center og DTU Jordstation.

Der flyver en satellit rundt som kommer forbi en gang imellem. Satellitten hedder DTUsat.

Da der ikke er nogen brugermanual endnu, vil vi så behjælpelige som vi mener at brugermanualen kommer til at være.

Opgaver Log ind i systemet. Du er blevet tildelt brugernavnet XXX med kodeordet XXX. Din truststore og keystore finder du på følgende

sti: XXX. MCC kører på host med IP XXX.

Find ud af hvornår DTUsat kommer forbi næste gang, vha. systemet. Du ved at systemet har de nyeste TLE-filer liggende.

Sørg for at satellitten udfører en TC_Alive kommando på dens Pico-kamera 10 minutter efter den næste passage er færdigt.

Sørg for at Pico-kameraet får sat en ny RAM adresse vha. kommandoen TC_Set_Image_Start_Addr, så snart som muligt.

Du bliver klar over at den adresse ikke var den rigtige. Ændr den til 200 i stedet.

Du vil gerne oprette en kommandoblok med følgende kommandoer:

- TC_Alive

- TC_Gain_Scan

Kommandoerne skal eksekveres en time efter næste pass, og med 10 sekunders mellemrum.

Denne kommandoblok indser du at du ofte vil sende til satellitten. Kan MPS hjælpe dig med at huske den til næste gang du vil

sende den?

Der er kun 5 passager i fremtiden. Du vil gerne kunne se de næste 10 passager i systemet.

Bør du re-schedulere dine kommandoer nu?

Prøv at tilgå pass vinduet i højre hjørne. Fremgår det hvad de forskellige elementer i dette vindue gør?

Sæt systemet i emergency mode.

Prøv at oprette nogen kommandoer til satellitten via emergency centeret.

Det der bliver vist er ikke synkroniseret med databasen som vi arbejder med al tid. Der er derfor en updater der hjælper med at

dette sker. Prøv at finde og åbne muligheden for denne updater.

Log ud af systemet og ind som brugeren test, med pass word ”testtest”. Systemet har ændret sig. Hvordan?

Page 91: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

Appendix C - Source Code

.1 MPS Source Sode

.1.1 MPSPreferences.java

1 package mps ;23 import java . awt . Color ;4 import java . u t i l . p r e f s . P r e f e r ence s ;56 /∗∗7 ∗ R e s p o n s i b l e f o r h a v i n g a p r e f e r e n c e o b j e c t r e a d y f o r o t h e r8 ∗ s t a t i c c l a s s e s and i m p o r t i n g and e x p o r t i n g p r e f e r e n c e s .9 ∗ <br><br>

10 ∗ A s y s t em v a r i a b l e named m p s P r e f e r e n c e s mus t b e d e f i n e d .11 ∗ Th i s v a r i a b l e d e t e r m i n s i n w h i c h t r e e t h e p r e f e r e n c e s12 ∗ a r e t o b e s t o r e d i n and l o a d e d f r om .13 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 314 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 115 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 816 ∗ @see j a v a . u t i l . p r e f s . P r e f e r e n c e s . j a v a17 ∗/1819 public c lass MPSPreferences {202122 /∗∗23 ∗ S t a t i c v a r i a b l e f o r t h e p r e f e r e n c e o b j e c t24 ∗/25 public stat ic f ina l Pre f e r ence s p r e f s ;262728 /∗∗29 ∗ Th i s me t hod i s r u n s when t h e c l a s s i s l o a d e d30 ∗/31 stat ic{32 // Lo o k s up t h e p r e f e r e n c e o b j e c t33 St r ing prefName = System . getenv ( ) . get ( ” mpsPreferences ” ) ;34 i f ( prefName == null ){35 System . out . p r i n t l n ( ”The system va r i ab l e \” mpsPreferences \” i s undef ined ”

) ;36 System . out . p r i n t l n ( ” Exit ing ” ) ;37 System . ex i t (−1) ;38 }3940 p r e f s = Pre f e r ence s . userRoot ( ) . node ( prefName ) ;41 }

Page 92: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

82 Appendix C - Source Code

424344 // LOGIN4546 public stat ic void setLoginURL ( Str ing u r l ) {47 MPSPreferences . p r e f s . put ( ” l o g i n u r l ” , u r l ) ;48 }4950 public stat ic Str ing getLoginURL () {51 return MPSPreferences . p r e f s . get ( ” l o g i n u r l ” , ”” ) ;52 }5354 public stat ic void setLoginPort ( St r ing port ) {55 MPSPreferences . p r e f s . put ( ” l o g i n p o r t ” , port ) ;56 }5758 public stat ic Str ing getLoginPort ( ) {59 return MPSPreferences . p r e f s . get ( ” l o g i n p o r t ” , ”” ) ;60 }6162 public stat ic void setLoginUser ( St r ing user ) {63 MPSPreferences . p r e f s . put ( ” l o g i n u s e r ” , user ) ;64 }6566 public stat ic Str ing getLoginUser ( ) {67 return MPSPreferences . p r e f s . get ( ” l o g i n u s e r ” , ”” ) ;68 }6970 // LOGIN − k e y s t o r e and t r u s t s t o r e7172 public stat ic void setLoginKeyStore ( St r ing keys tore ) {73 MPSPreferences . p r e f s . put ( ” l o g i n k e y s t o r e ” , keys tore ) ;74 }7576 public stat ic Str ing getLoginKeyStore ( ) {77 return MPSPreferences . p r e f s . get ( ” l o g i n k e y s t o r e ” , ”” ) ;78 }7980 public stat ic void setLog inTrustStore ( St r ing t r u s t s t o r e ) {81 MPSPreferences . p r e f s . put ( ” l o g i n t r u s t s t o r e ” , t r u s t s t o r e ) ;82 }8384 public stat ic Str ing getLoginTrustStore ( ) {85 return MPSPreferences . p r e f s . get ( ” l o g i n t r u s t s t o r e ” , ”” ) ;86 }8788 public stat ic void setKeyStorePassword ( St r ing password ) {89 MPSPreferences . p r e f s . put ( ” keystore password ” , password ) ;90 }9192 public stat ic Str ing getKeyStorePassword ( ) {93 return MPSPreferences . p r e f s . get ( ” keystore password ” , ”” ) ;94 }9596 public stat ic void setTrustStorePassword ( St r ing password ) {97 MPSPreferences . p r e f s . put ( ” t ru s t s t o r e pa s sword ” , password ) ;98 }99

100 public stat ic Str ing getTrustStorePassword ( ) {101 return MPSPreferences . p r e f s . get ( ” t ru s t s t o r e pa s sword ” , ”” ) ;102 }103104105 //PRE−SCHEDULING106 public stat ic void s e tPre schedu l ing ( int days ) {107 MPSPreferences . p r e f s . putInt ( ” p r e s chedu l i ng ” , days ) ;108 }109110 public stat ic int getPreschedu l ing ( ) {111 return MPSPreferences . p r e f s . g e t In t ( ” p r e s chedu l i ng ” , 10) ;112 }113114 // UPDATE THREAD115116 public stat ic boolean isUpdatingOn ( ) {117 return MPSPreferences . p r e f s . getBoolean ( ” update gui ” , f a l s e ) ;118 }119120 public stat ic void setUpdatingOn (boolean updateOn ) {121 MPSPreferences . p r e f s . putBoolean ( ” update gui ” , updateOn ) ;122 }123124 public stat ic int getUpdate Inte rva l InMi l i s e conds ( ) {125 return MPSPreferences . p r e f s . g e t In t ( ” upda t e in t e rva l ” , 30000) ;126 }127128 public stat ic void s e tUpdate In te rva l InMi l i s e conds ( int i n t e r v a l ) {

Page 93: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 83

129 MPSPreferences . p r e f s . putInt ( ” upda t e in t e rva l ” , i n t e r v a l ) ;130 }131132 // TLE SETTINGS133134 public stat ic Str ing getSate l l i t eName ( ) {135 return MPSPreferences . p r e f s . get ( ” sat name” , ”” ) ;136 }137138 public stat ic void s e tSate l l i t eName ( St r ing name) {139 MPSPreferences . p r e f s . put ( ” sat name” , name) ;140 }141142 public stat ic Str ing getTLEurl ( ) {143 return MPSPreferences . p r e f s . get ( ” t l e u r l ” , ”” ) ;144 }145146 public stat ic void setTLEurl ( St r ing u r l ) {147 MPSPreferences . p r e f s . put ( ” t l e u r l ” , u r l ) ;148 }149150 public stat ic Str ing getTLEdir ( ) {151 return MPSPreferences . p r e f s . get ( ” t l e d i r ” , System . getProperty ( ” user . home” ) ) ;152 }153154 public stat ic void setTLEdir ( St r ing d i r ) {155 MPSPreferences . p r e f s . put ( ” t l e d i r ” , d i r ) ;156 }157158 public stat ic int getNumberOfFuturePasses ( ) {159 return MPSPreferences . p r e f s . g e t In t ( ” f u tu r e pa s s e s ” , 10) ;160 }161162 public stat ic void setNumberOfFuturePasses ( int passe s ) {163 MPSPreferences . p r e f s . putInt ( ” f u tu r e pa s s e s ” , pas se s ) ;164 }165166 public stat ic int getMinDegreesAboveHorizont ( ) {167 return MPSPreferences . p r e f s . g e t In t ( ” min degree above hor i zont ” , 15) ;168 }169170 public stat ic void setMinDegreesAboveHorizont ( int degrees ) {171 MPSPreferences . p r e f s . putInt ( ” min degree above hor i zont ” , degrees ) ;172 }173174 public stat ic Str ing getDateFormat ( ) {175 return MPSPreferences . p r e f s . get ( ” date format ” , ”dd/MM/yyyy” ) ;176 }177178 // DATE FORMAT179180 public stat ic void setDateFormat ( St r ing dateFormat ) {181 MPSPreferences . p r e f s . put ( ” date format ” , dateFormat ) ;182 }183184 public stat ic Str ing getTimeFormat ( ) {185 return MPSPreferences . p r e f s . get ( ” t ime format ” , ”HH:mm: s s ” ) ;186 }187188 public stat ic void setTimeFormat ( St r ing timeFormat ) {189 MPSPreferences . p r e f s . put ( ” t ime format ” , timeFormat ) ;190 }191192193 /∗∗ Ge t s t h e F u l l d a t e s t r i n g p a t t e r n w i t h b o t h d a t e and t im e194 ∗ @r e t u r n The s t r i n g p a t t e r n f o r d a t e and t im e s e p a r a t e d b y ” ” ( s p a c e )195 ∗ <br> The s t r i n g p a t t e r n f o l l o w s t h e s t a n d a r d o f S im p l eD a t e F o rma t :196 ∗ h t t p : / / j a v a . s un . com/ j 2 s e / 1 . 4 . 2 / d o c s / a p i / j a v a / t e x t / S im p l eD a t e F o rma t . h tm l197 ∗/198 public stat ic Str ing getFullDateTimeFormat ( ) {199 return getDateFormat ( ) + ” ” + getTimeFormat ( ) ;200 }201202 // PREDEFINED COMMAND BLOCKS203204 public stat ic Str ing getPredefinedCommandBlocksPath ( ) {205 return getPredefinedCommandBlocksLocation ( ) + ”\\” +

getPredefinedCommandBlocksFileName ( ) ;206 }207208 public stat ic Str ing getPredefinedCommandBlocksFileName ( ) {209 return ”CommandBlocks . xml” ;210 }211212 public stat ic Str ing getPredefinedCommandBlocksLocation ( ) {213 return MPSPreferences . p r e f s . get ( ” predef command blocks ” , System . getProperty (

” user . home” ) ) ;

Page 94: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

84 Appendix C - Source Code

214 }215216 public stat ic void setPredefinedCommandBlocksLocation ( St r ing path ) {217 MPSPreferences . p r e f s . put ( ” predef command blocks ” , path ) ;218 }219220 // STATE COLORING221222 public stat ic Color getStateCo lor ( int s t a t e ) {223 switch ( s t a t e ) {224 case 0 : return new Color ( p r e f s . g e t In t ( ”state0RGB” , 000000) ) ;

// INITIAL225 case 1 : return new Color ( p r e f s . g e t In t ( ”state1RGB” , 000000) ) ;

// AWAITING PASS AND VERIFICATION226 case 2 : return new Color ( p r e f s . g e t In t ( ”state2RGB” , 000000) ) ;

// AWAITING PASS227 case 3 : return new Color ( p r e f s . g e t In t ( ”state3RGB” , 000000) ) ;

// AWAITING VERIFICATION228 case 4 : return new Color ( p r e f s . g e t In t ( ”state4RGB” , 000000) ) ;

// SCHEDULED229 case 5 : return new Color ( p r e f s . g e t In t ( ”state5RGB” , 000000) ) ;

// AWAITING USER ACTION230 case 6 : return new Color ( p r e f s . g e t In t ( ”state6RGB” , 000000) ) ;

// BEING TRANSMITTED231 case 7 : return new Color ( p r e f s . g e t In t ( ”state7RGB” , 000000) ) ;

// TRANSMITTED232 case 8 : return new Color ( p r e f s . g e t In t ( ”state8RGB” , 000000) ) ;

// EXECUTED233 case 9 : return new Color ( p r e f s . g e t In t ( ”state9RGB” , 000000) ) ;

// DELETED234 default : throw new I l l ega lArgumentExcept ion ( ” Inva l i d s t a t e ” )

;235 }236237 }238239 public stat ic void s e tS ta teCo lo r ( int s tate , int rgb ) {240 MPSPreferences . p r e f s . putInt ( ” s t a t e ”+s ta t e+”RGB” , rgb ) ;241 }242243244 }

Page 95: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 85

.1.2 MPSRunner.java

1 package mps ;23 import mps . gui . LoginView ;45 /∗∗6 ∗ Th i s c l a s s ’ main me t hod i n v o k e s t h e l o g i n v i e w and i s u s e d7 ∗ t o s t a r t t h e MPS a p p l i c a t i o n8 ∗ <br><br>9 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3

10 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 111 ∗ @ v e r s i o n 1 . 012 ∗/13 public c lass MPSRunner {1415 /∗∗16 ∗ @param a r g s17 ∗ @th r ow s E x c e p t i o n18 ∗/19 public stat ic void main ( St r ing [ ] args ) throws Exception {2021 javax . swing . S w i n g U t i l i t i e s . invokeLater (new Runnable ( ) {22 public void run ( ) {23 try{24 new LoginView ( ) ;25 }catch ( Exception e ){26 e . pr intStackTrace ( ) ;27 }28 }29 }) ;303132 }3334 }

Page 96: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

86 Appendix C - Source Code

.1.3 AboutFrame.java

1 package mps . gui ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;6 import java . awt . event . ActionEvent ;7 import java . awt . event . Act ionL i s t ener ;89 import javax . swing . ImageIcon ;

10 import javax . swing . JButton ;11 import javax . swing . JFrame ;12 import javax . swing . JLabel ;13 import javax . swing . JPanel ;1415 import mps . gui . t ime l i n e . TimeLineView ;1617 /∗∗18 ∗ An a b o u t b o x f o r t h e MPS19 ∗20 ∗ @au t h o r And r e a s Ho l t , J e s p e r S k y t t e Hansen21 ∗ @ a l t e r e d b y M i c h a e l S o r e n s e n , s 0 5 2 6 8 322 ∗ @ a l t e r e d b y Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 123 ∗/24 public c lass AboutFrame extends JFrame {2526 private stat ic f ina l long se r ia lVers ionUID = 7628821280910460218L ;2728 public AboutFrame ( ) {29 super ( ”About” ) ;30 TimeLineView . s e t I con ( this ) ;3132 setLayout (new GridBagLayout ( ) ) ;3334 CenterPanel centerPane l = new CenterPanel ( ) ;3536 JButton c loseButton = new JButton ( ” Close ” ) ;37 c loseButton . addAct ionListener (38 new Act ionL i s t ener ( ) {39 public void act ionPerformed ( ActionEvent e ) {40 s e t V i s i b l e ( f a l s e ) ;41 }42 }43 ) ;4445 GridBagConstraints c = new GridBagConstraints ( ) ;46 c . i n s e t s = new I n s e t s (5 , 5 , 5 , 5 ) ;47 c . gr idy = 0 ;48 add ( centerPanel , c ) ;49 c . gr idy = 1 ;50 add ( closeButton , c ) ;5152 this . pack ( ) ;53 s e tRe s i z ab l e ( f a l s e ) ;54 this . s e tLocat ionRe lat iveTo ( null ) ;55 this . s e t V i s i b l e ( true ) ;565758 }5960 private c lass CenterPanel extends JPanel {6162 private stat ic f ina l long se r ia lVers ionUID = −3843372419071497866L ;6364 public CenterPanel ( ) {65 super (new GridBagLayout ( ) ) ;6667 JLabel logo = new JLabel (new ImageIcon ( getClas s ( ) .

getResource ( ”/ r e s ou r c e s / images / logo . jpg ” ) ) ) ;68 JLabel text = new JLabel ( ”<html>” +69 ”<h1>Mission Planning System</h1>” +70 ”<hr width=\”70%\”>” +71 ” Technica l Un ive r s i ty o f Denmark (DTU)<br>” +72 ”<h3>Version 1 .0 , Jun 2008</h3>” +73 ”Authors : ” +74 ”<ul>” +75 ”<l i >Mathias Holm Andsersen </ l i >” +76 ”<l i >Michael Sørensen </ l i >” +77 ”</ul>” +78 ”Developed as a part o f the DTUsat 2 p ro j e c t for<br>” +79 ” miss ion con t ro l . ” +80 ”</html>” ) ;8182 GridBagConstraints c = new GridBagConstraints ( ) ;83 c . f i l l = GridBagConstraints .NONE;

Page 97: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 87

84 c . i n s e t s = new I n s e t s (5 , 5 , 5 , 5 ) ;85 c . anchor = GridBagConstraints .NORTH;86 add ( logo , c ) ;87 add ( text , c ) ;88 }89 }90 }

Page 98: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

88 Appendix C - Source Code

.1.4 DateTimeSpinnersPanel.java

1 package mps . gui ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;6 import java . u t i l . Calendar ;7 import java . u t i l . Date ;89 import javax . swing . JPanel ;

10 import javax . swing . JSpinner ;11 import javax . swing . SpinnerDateModel ;1213 import mps . MPSPreferences ;1415 /∗∗16 ∗ Pan e l c o n t a i n i n g d a t e and t im e s p i n n e r s . I s im b e d d e d on17 ∗ a l l p a n e l s / f r am e s t h a t n e e d s t o d e f i n e a t im e o r18 ∗ t im e i n t e r v a l .19 ∗ <br><br>20 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 321 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 122 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 823 ∗/24 public c lass DateTimeSpinnersPanel extends JPanel {2526 /∗∗27 ∗ S e r i a l v e r s i o n number o f t h e c l a s s28 ∗/29 private stat ic f ina l long se r ia lVers ionUID = 1L ;30 /∗∗31 ∗ The d a t e s p i n n e r mod e l f o r t h e p a n e l32 ∗/33 private SpinnerDateModel dateSDM ;34 /∗∗35 ∗ The t im e s p i n n e r mod e l f o r t h e p a n e l36 ∗/37 private SpinnerDateModel timeSDM ;38 /∗∗39 ∗ The d a t e s p i n n e r f o r t h e p a n e l40 ∗/41 private JSpinner dateSpinner ;42 /∗∗43 ∗ The t im e s p i n n e r f o r t h e p a n e l44 ∗/45 private JSpinner t imeSpinner ;4647 /∗∗48 ∗ C o n s t r u c t s an i n s t a n c e o f t h e D a t e T im e S p i n n e r s P a n e l49 ∗/50 public DateTimeSpinnersPanel ( ) {5152 this . setLayout (new GridBagLayout ( ) ) ;53 GridBagConstraints c = new GridBagConstraints ( ) ;54 c . i n s e t s = new I n s e t s (1 , 1 , 1 , 1 ) ;5556 c . gr idx = 0 ;57 c . gr idy = 0 ;58 dateSDM = new SpinnerDateModel ( ) ;59 dateSDM . setCa lendarF ie ld ( Calendar .DAY OF YEAR) ;60 dateSpinner = new JSpinner (dateSDM) ;61 JSpinner . DateEditor dateSpinnerEditor = new JSpinner . DateEditor (

dateSpinner , MPSPreferences . getDateFormat ( ) ) ;62 dateSpinner . s e tEd i to r ( dateSpinnerEditor ) ;63 this . add ( dateSpinner , c ) ;6465 c . gr idx = 1 ;66 timeSDM = new SpinnerDateModel ( ) ;67 timeSDM . setCa lendarF ie ld ( Calendar .HOUR OF DAY) ;68 timeSpinner = new JSpinner (timeSDM) ;69 JSpinner . DateEditor t imeSpinnerEditor = new JSpinner . DateEditor (

timeSpinner , MPSPreferences . getTimeFormat ( ) ) ;70 timeSpinner . s e tEd i to r ( t imeSpinnerEditor ) ;71 this . add ( timeSpinner , c ) ;7273 //XXX : Maybe im p l em e n t s y n c b e t w e e n t h e two s p i n n e r s ? So when ” t im e ”

p a s s e s 24 h o u r ” d a t e ” i s i n c r e m e n t e d .7475 }7677 /∗∗78 ∗ Ge t s t h e t im e f r om t h e s p i n n e r mo d e l s79 ∗ @r e t u r n The u n i x t im e d e f i n e d a t t h e s p i n n e r mo d e l s80 ∗/81 @SuppressWarnings ( ” deprecat ion ” )

Page 99: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 89

82 public long getTime ( ) {83 java . u t i l . Date date = dateSDM . getDate ( ) ;84 java . u t i l . Date time = timeSDM . getDate ( ) ;85 java . u t i l . Date dateAndTime = new java . u t i l . Date ( date . getYear ( ) , date .

getMonth ( ) , date . getDate ( ) , time . getHours ( ) , time . getMinutes ( ) ,time . getSeconds ( ) ) ;

86 return dateAndTime . getTime ( ) ;87 }8889 /∗∗90 ∗ S e t s t h e t im e o f t h e s p i n n e r mo d e l s91 ∗ @param t im e The u n i x t im e t o b e s e t a t t h e s p i n n e r mo d e l s92 ∗/93 public void setTime ( long time ) {94 dateSDM . setValue (new Date ( time ) ) ;95 timeSDM . setValue (new Date ( time ) ) ;96 }9798 /∗∗99 ∗ Ge t s t h e d a t e s p i n n e r mode l

100 ∗ @r e t u r n The d a t e s p i n n e r mod e l101 ∗/102 public SpinnerDateModel getDateSDM () {103 return dateSDM ;104 }105106 /∗∗107 ∗ Ge t s t h e t im e s p i n n e r mod e l108 ∗ @r e t u r n The t im e s p i n n e r mod e l109 ∗/110 public SpinnerDateModel getTimeSDM () {111 return timeSDM ;112 }113114 /∗∗115 ∗ Ge t s t h e t im e s p i n n e r116 ∗ @r e t u r n The t im e s p i n n e r117 ∗/118 public JSpinner getTimeSpinner ( ) {119 return t imeSpinner ;120 }121122 /∗∗123 ∗ Ge t s t h e d a t e s p i n n e r124 ∗ @r e t u r n The d a t e s p i n n e r125 ∗/126 public JSpinner getDateSpinner ( ) {127 return dateSpinner ;128 }129130131 }

Page 100: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

90 Appendix C - Source Code

.1.5 GroundStationSetupController.java

1 package mps . gui ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;78 import javax . swing . JMenuItem ;9 import javax . swing . JOptionPane ;

1011 import mcc . s e rv e r . dataProcess ing . GroundStation ;12 import mps . rmi . C l i ent ;1314 import common . auth . S impleCredent ia l s ;1516 /∗∗17 ∗ C o n t r o l l e r f o r t h e v i e w f o r g r o u n d s t a t i o n s e t u p18 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 319 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 120 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 821 ∗/22 public c lass GroundStat ionSetupControl ler implements Act ionL i s t ener {2324 /∗∗25 ∗ The v i e w f o r t h e c o n t r o l l e r26 ∗/27 private GroundStationSetupView view ;2829 /∗∗30 ∗ C o n s t r u c t s31 ∗ @param g r o u n d S t a t i o n S e t u p V i e w32 ∗/33 public GroundStat ionSetupControl ler ( GroundStationSetupView

groundStationSetupView ) {3435 view = groundStationSetupView ;3637 }3839 @Override40 public void act ionPerformed ( ActionEvent ae ) {4142 i f ( ae . getSource ( ) . equa l s ( view . getSaveButton ( ) ) ) {43 //SAVE BUTTON CLICKED44 saveButtonClicked ( ) ;45 } else i f ( ae . getSource ( ) . equa l s ( view . getCloseButton ( ) ) ) {4647 view . d i spose ( ) ;4849 } else i f ( ae . getSource ( ) . equa l s ( view . getDeleteButton ( ) ) ) {50 // DELETE GS5152 Object [ ] opt ions = {”Yes” , ”No” , ”Cancel ” } ;5354 int n = JOptionPane . showOptionDialog ( view ,55 ”Would you l i k e to d e l e t e the s e s s i o n s

a s s o c i a t ed with t h i s Ground Stat ion ” , ”Delete Se s s i on s ?” ,

56 JOptionPane .YES NO CANCEL OPTION,57 JOptionPane .QUESTION MESSAGE, null ,

opt ions , opt ions [ 0 ] ) ;58 i f (n==0 | | n==1) {59 try {6061 i f (n==0) {62 Cl i ent . ge t In s tance ( ) .

getAdminInter face ( ) .de leteGroundStat ion ( view . getGs( ) . GetName ( ) , true ) ;

63 }64 i f (n==1) {65 Cl i ent . ge t In s tance ( ) .

getAdminInter face ( ) .de leteGroundStat ion ( view . getGs( ) . GetName ( ) , f a l s e ) ;

66 }6768 view . d i spose ( ) ;6970 for ( int i =0; i<=view . getTimeLineView ( ) .

getEditGsSubMenu ( ) . getItemCount ( )−1; i++) {

71 i f ( view . getTimeLineView ( ) .getEditGsSubMenu ( ) . getItem ( i ) .

Page 101: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 91

getText ( ) . equa l s ( view . getGs ( ) .GetName ( ) ) ) {

72 view . getTimeLineView ( ) .getEditGsSubMenu ( ) .remove ( i ) ;

73 }74 }7576 } catch ( RemoteException e ) {77 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

78 e . pr intStackTrace ( ) ;79 } catch ( NotBoundException e ) {80 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

81 e . pr intStackTrace ( ) ;82 }8384 }8586 }878889 }90919293 /∗∗94 ∗ Runs t h r o u g h t h e u s e r i n p u t o f t h e v i e w and a l t e r / g e n e r a t e a g r o u n d

s t a t i o n w i t h t h e g i v e n i n f o r m a t i o n95 ∗/96 @SuppressWarnings ( ” deprecat ion ” )97 public void saveButtonClicked ( ) {9899 St r ing errorMessege = ”” ;

100101 St r ing name = view . getGsNameTextField ( ) . getText ( ) ;102 double l ong i tude = −1;103 try {104 long i tude = Double . parseDouble ( view . getGsLongitudeTextField

( ) . getText ( ) ) ;105 } catch ( NumberFormatException e ) {106 errorMessege += ”\nLongitude must be a number . ” ;107 }108 double l a t i t u d e = −1;109 try {110 l a t i t u d e = Double . parseDouble ( view . getGsLat itudeTextFie ld ( ) .

getText ( ) ) ;111 } catch ( NumberFormatException e ) {112 errorMessege+=”\nLatitude must be a number . ” ;113 }114 double he ight = −1;115 try {116 he ight = Double . parseDouble ( view . getGsHeightTextField ( ) .

getText ( ) ) ;117 } catch ( NumberFormatException e ) {118 errorMessege+=”\nHeight must be a number . ” ;119 }120121 St r ing host = view . getGsHostTextField ( ) . getText ( ) ;122 int rmi = −1;123 try {124 rmi = Int ege r . pa r s e In t ( view . getGsRmiPortTextField ( ) . getText

( ) ) ;125 } catch ( NumberFormatException e ) {126 errorMessege+=”\nRMI port must be a number . ” ;127 }128 int tcp = −1;129 try {130 tcp = Int ege r . pa r s e In t ( view . getGsTcpPortTextField ( ) . getText

( ) ) ;131 } catch ( NumberFormatException e ) {132 errorMessege+=”\nTCP port must be a number . ” ;133 }134 St r ing log inObjec t = view . getGsLoginObjectTextField ( ) . getText ( ) ;135 St r ing user = view . getGsUsernameTextField ( ) . getText ( ) ;136 St r ing pass = view . getGsPasswordField ( ) . getText ( ) ;137 S impleCredent ia l s c r e d e n t i a l s = new SimpleCredent ia l s ( user , pass ) ;138139 i f ( ! errorMessege . equa l s ( ”” ) ) {140 // E r r o r i n i n p u t e x i s t s141 errorMessege = ”There were e r r o r s in the input : ” +

errorMessege + ”\n\nPlease c o r r e c t the e r r o r s ” ;142 JOptionPane . showMessageDialog ( view , errorMessege , ” Error in

input ” , JOptionPane .ERROR MESSAGE) ;

Page 102: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

92 Appendix C - Source Code

143 } else {144 // C o r r e c t i n p u t145 i f ( view . getGs ( )==null ) {146 // C r e a t e new GS147148 GroundStation gs = new GroundStation (name , long itude ,

l a t i tude , height , host , rmi , tcp , log inObject ,c r e d e n t i a l s . getUsername ( ) , c r e d e n t i a l s .getPassword ( ) . getBytes ( ) ) ;

149150 try {151 // add new Ground S t a t i o n t o MCC152 Cl i ent . g e t In s tance ( ) . getAdminInter face ( ) .

addGS( gs ) ;153154 view . getTimeLineView ( ) . updateTimeLineViews ( )

;155156 view . d i spose ( ) ;157158 JMenuItem menuItem = new JMenuItem( gs .

GetName ( ) ) ;159 view . getTimeLineView ( ) . getEditGsSubMenu ( ) .

add ( menuItem ) ;160 menuItem . addAct ionListener ( view .

getTimeLineView ( ) . g e tCont ro l l e r ( ) ) ;161162 } catch ( RemoteException e ) {163 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

164 e . pr intStackTrace ( ) ;165 } catch ( NotBoundException e ) {166 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

167 e . pr intStackTrace ( ) ;168 }169170171 } else {172 // Sa v e c h a n g e s t o GS173 St r ing gsName = view . getGs ( ) . GetName ( ) ;174175 try {176177 Cl i ent . g e t In s tance ( ) . getAdminInter face ( ) .

changeHost (gsName , host ) ;178 Cl i ent . g e t In s tance ( ) . getAdminInter face ( ) .

changeLoginInfo (gsName , c r e d e n t i a l s .getUsername ( ) , c r e d e n t i a l s . getPassword( ) ) ;

179 Cl i ent . g e t In s tance ( ) . getAdminInter face ( ) .changeLoginObject (gsName , log inObject ) ;

180 Cl i ent . g e t In s tance ( ) . getAdminInter face ( ) .changeRMIPort (gsName , rmi ) ;

181 Cl i ent . g e t In s tance ( ) . getAdminInter face ( ) .changeTCPPort (gsName , tcp ) ;

182 view . d i spose ( ) ;183184 } catch ( RemoteException e ) {185 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

186 e . pr intStackTrace ( ) ;187 } catch ( NotBoundException e ) {188 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

189 e . pr intStackTrace ( ) ;190 }191192193 }194 }195196 }197198 }

Page 103: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 93

.1.6 GroundStationSetupView.java

1 package mps . gui ;23 import java . awt . Dimension ;4 import java . awt . GridBagConstraints ;5 import java . awt . GridBagLayout ;6 import java . awt . I n s e t s ;7 import java . rmi . NotBoundException ;8 import java . rmi . RemoteException ;9

10 import javax . swing . BorderFactory ;11 import javax . swing . JButton ;12 import javax . swing . JFrame ;13 import javax . swing . JLabel ;14 import javax . swing . JPanel ;15 import javax . swing . JPasswordField ;16 import javax . swing . JTextField ;1718 import mcc . s e rv e r . dataProcess ing . GroundStation ;19 import mps . gui . t ime l i n e . TimeLineView ;2021 /∗∗22 ∗ The v i e w t h a t i s i n v o k e d when a u s e r w an t s t o c r e a t e o r e d i t a g r o u n d s t a t i o n23 ∗ <br><br>24 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 325 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 126 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 827 ∗/28 public c lass GroundStationSetupView extends JFrame{2930 /∗∗31 ∗ S e r i a l v e r s i o n number o f t h e c l a s s32 ∗/33 private stat ic f ina l long se r ia lVers ionUID = 1L ;34 /∗∗35 ∗ The g r o u n d s t a t i o n f o r t h e c r e a t i o n / e d i t i n g36 ∗/37 private GroundStation gs ;38 /∗∗39 ∗ The c o n t r o l l e r f o r t h e v i e w40 ∗/41 private GroundStat ionSetupControl ler c o n t r o l l e r ;42 /∗∗43 ∗ The t im e l i n e v i e w u s e d b y t h e c o n t r o l l e r44 ∗/45 private TimeLineView timeLineView ;4647 /∗∗48 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n name49 ∗/50 private JTextField gsNameTextField ;51 /∗∗52 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n l o n g i t u d e53 ∗/54 private JTextField gsLongitudeTextFie ld ;55 /∗∗56 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n l a t i t u d e57 ∗/58 private JTextField gsLat i tudeTextFie ld ;59 /∗∗60 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n h e i g h t61 ∗/62 private JTextField gsHeightTextFie ld ;63 /∗∗64 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n h o s t65 ∗/66 private JTextField gsHostTextFie ld ;67 /∗∗68 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n rmi p o r t69 ∗/70 private JTextField gsRmiPortTextField ;71 /∗∗72 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n t c p p o r t73 ∗/74 private JTextField gsTcpPortTextField ;75 /∗∗76 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n l o g i n o b j e c t77 ∗/78 private JTextField gsLoginObjectTextFie ld ;79 /∗∗80 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n u s e r name81 ∗/82 private JTextField gsUsernameTextField ;83 /∗∗84 ∗ I n p u t f i e l d f o r g r o u n d s t a t i o n u s e r p a s s word

Page 104: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

94 Appendix C - Source Code

85 ∗/86 private JPasswordField gsPasswordField ;8788 /∗∗89 ∗ Bu t t o n f o r s a v i n g t h e c h a n g e s / c r e a t i o n90 ∗/91 private JButton saveButton ;92 /∗∗93 ∗ Bu t t o n t o c l o s e t h e v i e w w/ o s a v i n g c h a n g e s94 ∗/95 private JButton c loseButton ;96 /∗∗97 ∗ Bu t t o n t o d e l e t e t h e g r o u n d s t a t i o n98 ∗/99 private JButton deleteButton ;

100101 /∗∗102 ∗ C o n s t r u c t s a G r o u n d S t a t i o n S e t u p V i e w w i t h t h e g i v e n g r o u n d s t a t i o n and

t im e l i n e v i e w .103 ∗ I f g r o u n d s t a t i o n i s n o t g i v e n ( n u l l ) The v i e w w i l l b e made t o c r e a t e a

new g r o u n d s t a t i o n104 ∗ @param t im e L i n eV i e w The v i e w u s e d b y t h e c o n t r o l l e r105 ∗ @param g s The g r o u n d s t a t i o n t o b e e d i t e d . I f n u l l t h e v i e w w i l l t r y t o

c r e a t e a g r o u n d s t a t i o n f r om t h e u s e r i n p u t106 ∗ @th r ow s R emo t e E x c e p t i o n107 ∗ @th r ow s N o tB o u n dE x c e p t i o n108 ∗/109 public GroundStationSetupView ( TimeLineView timeLineView , GroundStation gs )

throws RemoteException , NotBoundException {110111 this . timeLineView = timeLineView ;112 c o n t r o l l e r = new GroundStat ionSetupControl ler ( this ) ;113 this . gs = gs ;114115 // SETUP FRAME116 this . s e t S i z e (300 ,200) ;117 this . s e tRe s i z ab l e ( f a l s e ) ;118 this . s e tLocat ion (150 ,150) ;119 TimeLineView . s e t I con ( this ) ;120121 i f ( gs==null ) {122 this . s e t T i t l e ( ”Add new Ground Stat ion to MPS” ) ;123 } else {124 this . s e t T i t l e ( ” Edit \”” + gs . GetName ( ) + ”\”” ) ;125 }126127 JPanel panel = new JPanel ( ) ;128 panel . setLayout (new GridBagLayout ( ) ) ;129 GridBagConstraints c = new GridBagConstraints ( ) ;130131 c . gr idy = 0 ;132 c . gr idx = 0 ;133 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;134 c . gr idwidth = 3 ;135136 panel . add ( createGsSet t ingsPane l ( ) , c ) ;137138 i f ( gs==null ) {139 saveButton = new JButton ( ”Add Ground Stat ion ” ) ;140 } else {141 saveButton = new JButton ( ”Save changes ” ) ;142 }143 c . gr idwidth = 1 ;144 // c . a n c h o r = G r i d B a g C o n s t r a i n t s . LINE END ;145 c . gr idy = 1 ;146 panel . add ( saveButton , c ) ;147148 de leteButton = new JButton ( ” Delete ” ) ;149 c . gr idx = 2 ;150 panel . add ( deleteButton , c ) ;151 i f ( gs==null ) {152 deleteButton . s e t V i s i b l e ( f a l s e ) ;153 } else {154 deleteButton . s e t V i s i b l e ( true ) ;155 }156157 c loseButton = new JButton ( ” Close ” ) ;158 c . gr idx = 1 ;159 panel . add ( closeButton , c ) ;160161 this . add ( panel ) ;162163 this . s e t V i s i b l e ( true ) ;164165 this . pack ( ) ;166167 // LISTENERS

Page 105: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 95

168 saveButton . addAct ionListener ( c o n t r o l l e r ) ;169 c loseButton . addAct ionListener ( c o n t r o l l e r ) ;170 de leteButton . addAct ionListener ( c o n t r o l l e r ) ;171172 }173174 /∗∗175 ∗ C r e a t e s t h e p a n e l f o r t h e s e t t i n g s o f t h e g r o u n d s t a t i o n176 ∗ @r e t u r n a p a n e l w i t h a l l t h e i n p u t b o x e s f o r t h e u s e r177 ∗/178 private JPanel c reateGsSet t ingsPane l ( ) {179 JPanel panel = new JPanel ( ) ;180 panel . setBorder ( BorderFactory . c r ea teT i t l edBorder ( ”Ground s t a t i on

s e t t i n g s ” ) ) ;181 panel . setLayout (new GridBagLayout ( ) ) ;182 GridBagConstraints c = new GridBagConstraints ( ) ;183184 c . anchor = GridBagConstraints . LINE END;185 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;186 c . gr idwidth = 1 ;187 c . gr idy = 0 ;188 c . gr idx = 0 ;189 panel . add (new JLabel ( ”Name : ” ) , c ) ;190191 gsNameTextField = new JTextField ( ) ;192 gsNameTextField . s e t P r e f e r r e d S i z e (new Dimension (180 ,20) ) ;193 c . gr idx = 1 ;194 c . anchor = GridBagConstraints .LINE START;195 panel . add ( gsNameTextField , c ) ;196 i f ( gs !=null ) {197 gsNameTextField . setText ( gs . GetName ( ) ) ;198 gsNameTextField . setEnabled ( f a l s e ) ;199 }200201 c . gr idy = 1 ;202 c . gr idx = 0 ;203 c . anchor = GridBagConstraints . LINE END;204 panel . add (new JLabel ( ” Longitude ” ) , c ) ;205206 gsLongitudeTextFie ld = new JTextField ( ) ;207 gsLongitudeTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (100 ,20) ) ;208 c . gr idx = 1 ;209 c . anchor = GridBagConstraints .LINE START;210 panel . add ( gsLongitudeTextField , c ) ;211 i f ( gs !=null ) {212 gsLongitudeTextFie ld . setText ( ””+gs . GetLong ( ) ) ;213 gsLongitudeTextFie ld . setEnabled ( f a l s e ) ;214 }215216 c . gr idy = 2 ;217 c . gr idx = 0 ;218 c . anchor = GridBagConstraints . LINE END;219 panel . add (new JLabel ( ” Lat i tude ” ) , c ) ;220221 gsLat i tudeTextFie ld = new JTextField ( ) ;222 gsLat i tudeTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (100 ,20) ) ;223 c . gr idx = 1 ;224 c . anchor = GridBagConstraints .LINE START;225 panel . add ( gsLat i tudeTextFie ld , c ) ;226 i f ( gs !=null ) {227 gsLat i tudeTextFie ld . setText ( ””+gs . GetLat ( ) ) ;228 gsLat i tudeTextFie ld . setEnabled ( f a l s e ) ;229 }230231 c . gr idy = 3 ;232 c . gr idx = 0 ;233 c . anchor = GridBagConstraints . LINE END;234 panel . add (new JLabel ( ”Height ” ) , c ) ;235236 gsHeightTextFie ld = new JTextField ( ) ;237 gsHeightTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (100 ,20) ) ;238 c . gr idx = 1 ;239 c . anchor = GridBagConstraints .LINE START;240 panel . add ( gsHeightTextField , c ) ;241 i f ( gs !=null ) {242 gsHeightTextFie ld . setText ( ””+gs . GetHeight ( ) ) ;243 gsHeightTextFie ld . setEnabled ( f a l s e ) ;244 }245246 c . gr idy = 4 ;247 c . gr idx = 0 ;248 c . anchor = GridBagConstraints . LINE END;249 panel . add (new JLabel ( ”Host” ) , c ) ;250251 gsHostTextFie ld = new JTextField ( ) ;252 gsHostTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (150 ,20) ) ;253 c . gr idx = 1 ;

Page 106: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

96 Appendix C - Source Code

254 c . anchor = GridBagConstraints .LINE START;255 panel . add ( gsHostTextField , c ) ;256 i f ( gs !=null ) {257 gsHostTextFie ld . setText ( ””+gs . getHost ( ) ) ;258 }259260 c . gr idy = 5 ;261 c . gr idx = 0 ;262 c . anchor = GridBagConstraints . LINE END;263 panel . add (new JLabel ( ”RMI port ” ) , c ) ;264265 gsRmiPortTextField = new JTextField ( ) ;266 gsRmiPortTextField . s e t P r e f e r r e d S i z e ( (new Dimension (50 ,20) ) ) ;267 c . gr idx = 1 ;268 c . anchor = GridBagConstraints .LINE START;269 panel . add ( gsRmiPortTextField , c ) ;270 i f ( gs !=null ) {271 gsRmiPortTextField . setText ( ””+gs . getRMIPort ( ) ) ;272 }273274 c . gr idy = 6 ;275 c . gr idx = 0 ;276 c . anchor = GridBagConstraints . LINE END;277 panel . add (new JLabel ( ”TCP port ” ) , c ) ;278279 gsTcpPortTextField = new JTextField ( ) ;280 gsTcpPortTextField . s e t P r e f e r r e d S i z e ( (new Dimension (50 ,20) ) ) ;281 c . gr idx = 1 ;282 c . anchor = GridBagConstraints .LINE START;283 panel . add ( gsTcpPortTextField , c ) ;284 i f ( gs !=null ) {285 gsTcpPortTextField . setText ( ””+gs . getTCPPort ( ) ) ;286 }287288 c . gr idy = 7 ;289 c . gr idx = 0 ;290 c . anchor = GridBagConstraints . LINE END;291 panel . add (new JLabel ( ”Login ob j e c t ” ) , c ) ;292293 gsLoginObjectTextFie ld = new JTextField ( ) ;294 gsLoginObjectTextFie ld . s e t P r e f e r r e d S i z e ( (new Dimension (180 ,20) ) ) ;295 c . gr idx = 1 ;296 c . anchor = GridBagConstraints .LINE START;297 panel . add ( gsLoginObjectTextField , c ) ;298 i f ( gs !=null ) {299 gsLoginObjectTextFie ld . setText ( gs . getLoginObject ( ) ) ;300 }301302 c . gr idy = 8 ;303 c . gr idx = 0 ;304 c . anchor = GridBagConstraints . LINE END;305 panel . add (new JLabel ( ”Username” ) , c ) ;306307 gsUsernameTextField = new JTextField ( ) ;308 gsUsernameTextField . s e t P r e f e r r e d S i z e ( (new Dimension (180 ,20) ) ) ;309 c . gr idx = 1 ;310 c . anchor = GridBagConstraints .LINE START;311 panel . add ( gsUsernameTextField , c ) ;312 i f ( gs !=null ) {313 gsUsernameTextField . setText ( gs . getUsername ( ) ) ;314 }315316 c . gr idy = 9 ;317 c . gr idx = 0 ;318 c . anchor = GridBagConstraints . LINE END;319 panel . add (new JLabel ( ”Password” ) , c ) ;320321 gsPasswordField = new JPasswordField ( ) ;322 gsPasswordField . s e t P r e f e r r e d S i z e ( (new Dimension (180 ,20) ) ) ;323 c . gr idx = 1 ;324 c . anchor = GridBagConstraints .LINE START;325 panel . add ( gsPasswordField , c ) ;326 i f ( gs !=null ) {327 // g s P a s s w o r d F i e l d . s e t T e x t ( g s . g e t P a s s w o r d ( ) . t o S t r i n g ( ) ) ;328 }329330 return panel ;331 }332333 /∗334 ∗ GETTERS335 ∗/336337 /∗∗338 ∗ @r e t u r n s a v e B u t t o n339 ∗/340 public JButton getSaveButton ( ) {

Page 107: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 97

341 return saveButton ;342 }343344 /∗∗345 ∗ @r e t u r n c l o s e B u t t o n346 ∗/347 public JButton getCloseButton ( ) {348 return c loseButton ;349 }350351 /∗∗352 ∗ @r e t u r n g s353 ∗/354 public GroundStation getGs ( ) {355 return gs ;356 }357358 /∗∗359 ∗ @r e t u r n g sN am eT e x t F i e l d360 ∗/361 public JTextField getGsNameTextField ( ) {362 return gsNameTextField ;363 }364365 /∗∗366 ∗ @r e t u r n g s L o n g i t u d e T e x t F i e l d367 ∗/368 public JTextField getGsLongitudeTextField ( ) {369 return gsLongitudeTextFie ld ;370 }371372 /∗∗373 ∗ @r e t u r n g s L a t i t u d e T e x t F i e l d374 ∗/375 public JTextField getGsLat itudeTextFie ld ( ) {376 return gsLat i tudeTextFie ld ;377 }378379 /∗∗380 ∗ @r e t u r n g s H e i g h t T e x t F i e l d381 ∗/382 public JTextField getGsHeightTextField ( ) {383 return gsHeightTextFie ld ;384 }385386 /∗∗387 ∗ @r e t u r n g s H o s t T e x t F i e l d388 ∗/389 public JTextField getGsHostTextField ( ) {390 return gsHostTextFie ld ;391 }392393 /∗∗394 ∗ @r e t u r n g s R m i P o r t T e x t F i e l d395 ∗/396 public JTextField getGsRmiPortTextField ( ) {397 return gsRmiPortTextField ;398 }399400 /∗∗401 ∗ @r e t u r n g s T c p P o r t T e x t F i e l d402 ∗/403 public JTextField getGsTcpPortTextField ( ) {404 return gsTcpPortTextField ;405 }406407 /∗∗408 ∗ @r e t u r n g s L o g i n O b j e c t T e x t F i e l d409 ∗/410 public JTextField getGsLoginObjectTextField ( ) {411 return gsLoginObjectTextFie ld ;412 }413414 /∗∗415 ∗ @r e t u r n g s U s e r n a m e T e x t F i e l d416 ∗/417 public JTextField getGsUsernameTextField ( ) {418 return gsUsernameTextField ;419 }420421 /∗∗422 ∗ @r e t u r n423 ∗/424 public JPasswordField getGsPasswordField ( ) {425 return gsPasswordField ;426 }427

Page 108: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

98 Appendix C - Source Code

428 /∗∗429 ∗ @r e t u r n t im e L i n eV i e w430 ∗/431 public TimeLineView getTimeLineView ( ) {432 return timeLineView ;433 }434435 /∗∗436 ∗ @r e t u r n d e l e t e B u t t o n437 ∗/438 public JButton getDeleteButton ( ) {439 return deleteButton ;440 }441442443444445446 }

Page 109: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 99

.1.7 LoginController.java

1 package mps . gui ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . awt . event . KeyEvent ;6 import java . awt . event . KeyListener ;7 import java . i o . F i l e ;89 import javax . swing . JFi leChooser ;

10 import javax . swing . JOptionPane ;1112 import mps . MPSPreferences ;13 import mps . gui . t ime l i n e . TimeLineView ;14 import mps . rmi . C l i entCreator ;15161718 /∗∗19 ∗ The c o n t r o l l e r f o r t h e l o g i n v i e w . V e r i f i e s t h a t t h e u s e r can l o g i n t o t h e MCC

and k e y s t o r e s and t r u s t s t o r e s a r e v a l i d20 ∗ <br><br>21 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 322 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 123 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 824 ∗/25 public c lass Log inContro l l e r implements Act ionListener , KeyListener {2627 private LoginView view ;2829 /∗∗30 ∗ C o n s t r u c t s an i n s t a n c e o f t h e c o n t r o l l e r w i t h t h e g i v e n v i e w31 ∗ @param v i e w t h e v i e w f o r t h e c o n t r o l l e r32 ∗/33 public Log inContro l l e r ( LoginView view ) {34 this . view = view ;35 }3637 @Override38 public void act ionPerformed ( ActionEvent ae ) {394041 i f ( ae . getSource ( ) . equa l s ( view . getKeyStoreButton ( ) ) | | ae . getSource ( )

. equa l s ( view . getTrustStoreButton ( ) ) ) {42 // Us e r p r e s s e d Key S t o r e o r T r u s t S t o r e Browse b u t t o n43 int returnVal = view . g e tF i l e choo s e r ( ) . showOpenDialog ( view ) ;44 i f ( returnVal == JFi leChooser .APPROVE OPTION) {45 F i l e f i l e = view . g e tF i l e choo s e r ( ) . g e t S e l e c t e d F i l e ( )

;46 i f ( ae . getSource ( ) . equa l s ( view . getKeyStoreButton ( ) )

) view . getKeyStoreTextFie ld ( ) . setText ( f i l e .getPath ( ) ) ;

47 else i f ( ae . getSource ( ) . equa l s ( view .getTrustStoreButton ( ) ) ) view .getTrustStoreTextFie ld ( ) . setText ( f i l e . getPath( ) ) ;

48 }4950 } else i f ( ae . getSource ( ) . equa l s ( view . getLoginButton ( ) ) ) {51 // Us e r p r e s s e d L o g i n b u t t o n52 log inButtonPressed ( ) ;535455 } else i f ( ae . getSource ( ) . equa l s ( view . getClearButton ( ) ) ) {5657 view . getKeyStoreTextFie ld ( ) . setText ( ”” ) ;58 view . getKeyStorePasswordField ( ) . setText ( ”” ) ;59 view . getTrustStoreTextFie ld ( ) . setText ( ”” ) ;60 view . getTrustStorePasswordFie ld ( ) . setText ( ”” ) ;61 view . getHostTextFie ld ( ) . setText ( ”” ) ;62 view . getPortTextFie ld ( ) . setText ( ”” ) ;63 view . getUsernameTextField ( ) . setText ( ”” ) ;64 view . getUserPasswordFie ld ( ) . setText ( ”” ) ;656667 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {68 view . d i spose ( ) ;6970 }7172 }7374 @Override75 public void keyPressed ( KeyEvent arg0 ) {76 i f ( arg0 . getKeyCode ( )==KeyEvent .VK ENTER) {

Page 110: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

100 Appendix C - Source Code

77 log inButtonPressed ( ) ;78 }79 else i f ( arg0 . getKeyCode ( )==KeyEvent .VK ESCAPE) {80 view . d i spose ( ) ;81 }82 }8384 @Override85 public void keyReleased ( KeyEvent arg0 ) { }8687 @Override88 public void keyTyped ( KeyEvent arg0 ) { }899091 /∗∗92 ∗ C r e a t e s a c l i e n t w i t h t h e t r u s t l e v e l f i t t i n g t o t h e u s e r i n p u t .93 ∗ C r e a t e s a t im e l i n e v i e w and d i s p o s e s o f t h e l o g i n v i e w .94 ∗ De t e rm i n e s t h e RMI s e s s i o n f o r t h e c l i e n t f r om t h e u s e r i n p u t95 ∗/96 @SuppressWarnings ( ” deprecat ion ” )97 private void log inButtonPressed ( ) {98 St r ing u r l = view . getHostTextFie ld ( ) . getText ( ) ;99 int port = Int ege r . pa r s e In t ( view . getPortTextFie ld ( ) . getText ( ) ) ;

100 St r ing username = view . getUsernameTextField ( ) . getText ( ) ;101 St r ing keys tore = view . getKeyStoreTextFie ld ( ) . getText ( ) ;102 St r ing t r u s t s t o r e = view . getTrustStoreTextFie ld ( ) . getText ( ) ;103104 try {105 Cl i entCreator . c r e a t eC l i en t ( ur l , port , ” l o g i n ” , username , view .

getUserPasswordFie ld ( ) . getText ( ) , keystore , view .getKeyStorePasswordField ( ) . getText ( ) , t r u s t s t o r e , view .getTrustStorePasswordFie ld ( ) . getText ( ) ) ;

106107 MPSPreferences . setKeyStorePassword ( view .

getKeyStorePasswordField ( ) . getText ( ) ) ;108 MPSPreferences . setTrustStorePassword ( view .

getTrustStorePasswordFie ld ( ) . getText ( ) ) ;109 MPSPreferences . setLoginURL ( ur l ) ;110 MPSPreferences . setLoginPort ( ””+port ) ;111 MPSPreferences . setLoginUser ( username ) ;112 MPSPreferences . setLoginKeyStore ( keys tore ) ;113 MPSPreferences . se tLog inTrustStore ( t r u s t s t o r e ) ;114115 view . d i spose ( ) ;116 javax . swing . S w i n g U t i l i t i e s . invokeLater (new Runnable ( ) {117 public void run ( ) {118 try{119 new TimeLineView ( ) ;120 }catch ( Exception e ){121 e . pr intStackTrace ( ) ;122 }123 }124 }) ;125126 } catch ( Exception e ) {127 e . pr intStackTrace ( ) ;128 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;129 }130131 }132133 }

Page 111: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 101

.1.8 LoginView.java

1 package mps . gui ;2 import java . awt . Dimension ;3 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;67 import javax . swing . BorderFactory ;8 import javax . swing . JButton ;9 import javax . swing . JFi leChooser ;

10 import javax . swing . JFrame ;11 import javax . swing . JLabel ;12 import javax . swing . JPanel ;13 import javax . swing . JPasswordField ;14 import javax . swing . JSeparator ;15 import javax . swing . JTextField ;16 import javax . swing . UIManager ;1718 import mps . MPSPreferences ;19 import mps . gui . t ime l i n e . TimeLineView ;2021 /∗∗22 ∗ Frame f o r l o g g i n g t h e u s e r o f t h e s y s t em i n t o t h e s y s t em .23 ∗ <br><br>24 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 325 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 126 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 827 ∗/28 public c lass LoginView extends JFrame{2930 /∗∗31 ∗ S e r i a l v e r s i o n number o f t h e c l a s s32 ∗/33 private stat ic f ina l long se r ia lVers ionUID = 1L ;34 /∗∗35 ∗ I n p u t f i e l d f o r u s e r name36 ∗/37 private JTextField usernameTextField ;38 /∗∗39 ∗ I n p u t f i e l d f o r p a s s w o r d40 ∗/41 private JPasswordField userPasswordFie ld ;42 /∗∗43 ∗ I n p u t f i e l d f o r h o s t44 ∗/45 private JTextField hostTextFie ld ;46 /∗∗47 ∗ I n p u t f i e l d f o r p o r t48 ∗/49 private JTextField portTextFie ld ;50 /∗∗51 ∗ I n p u t f i e l d f o r k e y s t o r e p a t h52 ∗/53 private JTextField keyStoreTextFie ld ;54 /∗∗55 ∗ I n p u t f i e l d f o r k e y s t o r e p a s s w o r d56 ∗/57 private JPasswordField keyStorePasswordFie ld ;58 /∗∗59 ∗ I n p u t f i e l d f o r t r u s t s t o r e p a t h60 ∗/61 private JTextField t rus tS to reTextF i e ld ;62 /∗∗63 ∗ I n p u t f i e l d f o r t r u s t s t o r e p a s s w o r d64 ∗/65 private JPasswordField t rustStorePasswordFie ld ;6667 /∗∗68 ∗ Bu t t o n f o r f i n d i n g k e y s t o r e p a t h69 ∗/70 private JButton keyStoreButton ;71 /∗∗72 ∗ Bu t t o n f o r f i n d i n g t r u s t s t o r e p a t h73 ∗/74 private JButton trustStoreButton ;75 /∗∗76 ∗ The f i l e c h o o s e r t o f i n d p a t h s f o r t r u s t and k e y s t o r e77 ∗/78 private JFi leChooser f i l e c h o o s e r ;7980 /∗∗81 ∗ Bu t t o n f o r l o g g i n g i n82 ∗/83 private JButton loginButton ;84 /∗∗

Page 112: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

102 Appendix C - Source Code

85 ∗ Bu t t o n f o r c a n c e l i n g l o g i n86 ∗/87 private JButton cancelButton ;88 /∗∗89 ∗ Bu t t o n f o r c l e a r i n g a l l i n p u t f i e l d s90 ∗/91 private JButton c learButton ;9293 /∗∗94 ∗ C o n t r o l l e r f o r t h i s v i e w95 ∗/96 private Log inContro l l e r c o n t r o l l e r ;9798 /∗∗99 ∗ C o n s t r u c t s an i n s t a n c e o f L o g i nV i ew

100 ∗/101 public LoginView ( ) {102103 // SETUP FRAME104 // I f w indow c l o s e d a p p l i c a t i o n mus t b e t e r m i n a t e d105 this . s e tDe fau l tCloseOperat ion ( JFrame .EXIT ON CLOSE) ;106 this . s e tRe s i z ab l e ( f a l s e ) ;107 TimeLineView . s e t I con ( this ) ;108 // LOOK AND FEEL109 try{110 UIManager . setLookAndFeel ( UIManager .

getSystemLookAndFeelClassName ( ) ) ;111 }catch ( Exception ex ) {112113 }114115 this . s e t T i t l e ( ”MPS Login” ) ;116117 this . s e t V i s i b l e ( true ) ;118119 c o n t r o l l e r = new Log inContro l l e r ( this ) ;120121 // CREATE COMPONENTS122 usernameTextField = new JTextField ( ) ;123 userPasswordFie ld = new JPasswordField ( ) ;124 hostTextFie ld = new JTextField ( ) ;125 portTextFie ld = new JTextField ( ) ;126127 keyStoreTextFie ld = new JTextField ( ) ;128 keyStorePasswordFie ld = new JPasswordField ( ) ;129 t rus tS to reTextF i e ld = new JTextField ( ) ;130 trustStorePasswordFie ld = new JPasswordField ( ) ;131 keyStoreButton = new JButton ( ” . . ” ) ;132 trustStoreButton = new JButton ( ” . . ” ) ;133 f i l e c h o o s e r = new JFi leChooser ( ) ;134135 loginButton = new JButton ( ”Login” ) ;136 cancelButton = new JButton ( ”Cancel ” ) ;137 c learButton = new JButton ( ” Clear ” ) ;138139140 // SETUP PANELS141 JPanel panel = new JPanel ( ) ;142 panel . setLayout (new GridBagLayout ( ) ) ;143 // p a n e l . s e t B o r d e r ( B o r d e r F a c t o r y . c r e a t e T i t l e d B o r d e r ( ” L o g i n i n f o ” ) ) ;144 GridBagConstraints c = new GridBagConstraints ( ) ;145146 c . gr idy = 0 ;147 c . gr idx = 0 ;148 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;149 c . gr idwidth = 3 ;150 panel . add ( createKeyStorePanel ( ) , c ) ;151152 c . gr idy = 1 ;153 panel . add ( createTrustStorePane l ( ) , c ) ;154155 c . gr idy = 2 ;156 panel . add (new JSeparator ( ) , c ) ;157158 c . gr idy = 3 ;159 panel . add ( createLoginPane l ( ) , c ) ;160161 c . gr idy = 4 ;162 c . gr idx = 0 ;163 c . gr idwidth = 1 ;164 c . anchor = GridBagConstraints . LINE END;165 panel . add ( loginButton , c ) ;166167 c . gr idx = 1 ;168 panel . add ( clearButton , c ) ;169170 c . gr idx = 2 ;

Page 113: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 103

171 panel . add ( cancelButton , c ) ;172173174 // LISTENERS175 keyStoreButton . addAct ionListener ( c o n t r o l l e r ) ;176 trustStoreButton . addAct ionListener ( c o n t r o l l e r ) ;177 loginButton . addAct ionListener ( c o n t r o l l e r ) ;178 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;179 c learButton . addAct ionListener ( c o n t r o l l e r ) ;180181 userPasswordFie ld . addKeyListener ( c o n t r o l l e r ) ;182183184 // Pack and show185 this . add ( panel ) ;186 this . s e t V i s i b l e ( true ) ;187 this . pack ( ) ;188 this . s e tLocat ionRe lat iveTo ( null ) ;189190 }191192 /∗∗193 ∗ C r e a t e s a p a n e l f o r c h o o s i n g t h e k e y s t o r e194 ∗ @r e t u r n A p a n e l f o r t h e k e y s t o r e s e l e c t i o n195 ∗/196 private JPanel createKeyStorePanel ( ) {197 JPanel panel = new JPanel ( ) ;198 panel . setBorder ( BorderFactory . c r ea teT i t l edBorder ( ”Key s t o r e ” ) ) ;199 panel . setLayout (new GridBagLayout ( ) ) ;200 GridBagConstraints c = new GridBagConstraints ( ) ;201202 c . anchor = GridBagConstraints . LINE END;203 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;204 c . gr idwidth = 1 ;205 c . gr idy = 0 ;206 c . gr idx = 0 ;207 panel . add (new JLabel ( ” Location : ” ) , c ) ;208209 keyStoreTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;210 keyStoreTextFie ld . s e tEd i t ab l e ( f a l s e ) ;211 keyStoreTextFie ld . setText ( MPSPreferences . getLoginKeyStore ( ) ) ;212 c . anchor = GridBagConstraints .LINE START;213 c . gr idx = 1 ;214 panel . add ( keyStoreTextFie ld , c ) ;215216 keyStoreButton . s e t P r e f e r r e d S i z e (new Dimension (20 ,20) ) ;217 c . gr idx = 2 ;218 panel . add ( keyStoreButton , c ) ;219220 c . anchor = GridBagConstraints .LINE START;221 c . gr idy = 1 ;222 c . gr idx = 0 ;223 panel . add (new JLabel ( ”Password : ” ) , c ) ;224225 keyStorePasswordFie ld . s e t P r e f e r r e d S i z e (new Dimension (150 ,20) ) ;226 keyStorePasswordFie ld . setText ( MPSPreferences . getKeyStorePassword ( )

) ;227 c . gr idx = 1 ;228 c . gr idwidth = 2 ;229 panel . add ( keyStorePasswordField , c ) ;230231 return panel ;232 }233234 /∗∗235 ∗ C r e a t e s a p a n e l f o r c h o o s i n g t h e t r u s t s t o r e236 ∗ @r e t u r n A p a n e l f o r t h e t r u s t s t o r e s e l e c t i o n237 ∗/238 private JPanel c reateTrustStorePane l ( ) {239 JPanel panel = new JPanel ( ) ;240 panel . setBorder ( BorderFactory . c r ea teT i t l edBorder ( ”Trust s t o r e ” ) ) ;241 panel . setLayout (new GridBagLayout ( ) ) ;242 GridBagConstraints c = new GridBagConstraints ( ) ;243244 c . anchor = GridBagConstraints . LINE END;245 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;246 c . gr idwidth = 1 ;247 c . gr idy = 0 ;248 c . gr idx = 0 ;249 panel . add (new JLabel ( ” Location : ” ) , c ) ;250251 t rus tSto r eTextF i e ld . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;252 t rus tS to reTextF i e ld . s e tEd i t ab l e ( f a l s e ) ;253 t rus tS to reTextF i e ld . setText ( MPSPreferences . getLoginTrustStore ( ) ) ;254 c . anchor = GridBagConstraints .LINE START;255 c . gr idx = 1 ;256 panel . add ( t rus tStoreTextFie ld , c ) ;

Page 114: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

104 Appendix C - Source Code

257258 trustStoreButton . s e t P r e f e r r e d S i z e (new Dimension (20 ,20) ) ;259 c . gr idx = 2 ;260 panel . add ( trustStoreButton , c ) ;261262 c . anchor = GridBagConstraints .LINE START;263 c . gr idy = 1 ;264 c . gr idx = 0 ;265 panel . add (new JLabel ( ”Password : ” ) , c ) ;266267 trustStorePasswordFie ld . s e t P r e f e r r e d S i z e (new Dimension (150 ,20) ) ;268 trustStorePasswordFie ld . setText ( MPSPreferences .

getTrustStorePassword ( ) ) ;269 c . gr idx = 1 ;270 c . gr idwidth = 2 ;271 panel . add ( trustStorePasswordFie ld , c ) ;272273 return panel ;274 }275276 /∗∗277 ∗ C r e a t e s a p a n e l f o r h o s t , p o r t , u s e r name and p a s s w o r d i n p u t f i e l d s278 ∗ @r e t u r n A p a n e l w i t h i n p u t f i e l d s f o r h o s t , p o r t , u s e r name and p a s s w o r d279 ∗/280 private JPanel createLog inPane l ( ) {281 JPanel panel = new JPanel ( ) ;282 panel . setBorder ( BorderFactory . c r ea teT i t l edBorder ( ”MCC Login i n f o ” ) ) ;283 panel . setLayout (new GridBagLayout ( ) ) ;284 GridBagConstraints c = new GridBagConstraints ( ) ;285286 c . anchor = GridBagConstraints . LINE END;287 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;288 c . gr idwidth = 1 ;289 c . gr idy = 0 ;290 c . gr idx = 0 ;291 panel . add (new JLabel ( ”Host : ” ) , c ) ;292293 hostTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (150 ,20) ) ;294 hostTextFie ld . setText ( MPSPreferences . getLoginURL () ) ;295 c . anchor = GridBagConstraints .LINE START;296 c . gr idx = 1 ;297 panel . add ( hostTextField , c ) ;298299 c . gr idx = 2 ;300 c . anchor = GridBagConstraints . LINE END;301 panel . add (new JLabel ( ”Port : ” ) , c ) ;302303 portTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (40 ,20) ) ;304 portTextFie ld . setText ( MPSPreferences . getLoginPort ( ) ) ;305 c . gr idx = 3 ;306 c . anchor = GridBagConstraints .LINE START;307 panel . add ( portTextFie ld , c ) ;308309310 c . anchor = GridBagConstraints . LINE END;311 c . gr idy = 1 ;312 c . gr idx = 0 ;313 panel . add (new JLabel ( ”Username : ” ) , c ) ;314315 c . gr idx = 1 ;316 c . gr idwidth = 3 ;317 c . anchor = GridBagConstraints .LINE START;318 usernameTextField . s e t P r e f e r r e d S i z e (new Dimension (150 ,20) ) ;319 usernameTextField . setText ( MPSPreferences . getLoginUser ( ) ) ;320 panel . add ( usernameTextField , c ) ;321322 c . anchor = GridBagConstraints . LINE END;323 c . gr idwidth = 1 ;324 c . gr idy = 2 ;325 c . gr idx = 0 ;326 panel . add (new JLabel ( ”Password : ” ) , c ) ;327328 c . gr idx = 1 ;329 c . gr idwidth = 3 ;330 c . anchor = GridBagConstraints .LINE START;331 userPasswordFie ld . s e t P r e f e r r e d S i z e (new Dimension (150 ,20) ) ;332 panel . add ( userPasswordField , c ) ;333334335 return panel ;336 }337338 /∗∗339 ∗ @r e t u r n u s e r n a m e T e x t F i e l d340 ∗/341 public JTextField getUsernameTextField ( ) {342 return usernameTextField ;

Page 115: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 105

343 }344345 /∗∗346 ∗ @r e t u r n u s e r P a s s w o r d F i e l d347 ∗/348 public JPasswordField getUserPasswordFie ld ( ) {349 return userPasswordFie ld ;350 }351352 /∗∗353 ∗ @r e t u r n h o s t T e x t F i e l d354 ∗/355 public JTextField getHostTextFie ld ( ) {356 return hostTextFie ld ;357 }358359 /∗∗360 ∗ @r e t u r n p o r t T e x t F i e l d361 ∗/362 public JTextField getPortTextFie ld ( ) {363 return portTextFie ld ;364 }365366 /∗∗367 ∗ @r e t u r n k e y S t o r e T e x t F i e l d368 ∗/369 public JTextField getKeyStoreTextFie ld ( ) {370 return keyStoreTextFie ld ;371 }372373 /∗∗374 ∗ @r e t u r n k e y S t o r e P a s s w o r d F i e l d375 ∗/376 public JPasswordField getKeyStorePasswordField ( ) {377 return keyStorePasswordFie ld ;378 }379380 /∗∗381 ∗ @r e t u r n t r u s t S t o r e T e x t F i e l d382 ∗/383 public JTextField getTrustStoreTextFie ld ( ) {384 return t ru s tS to reTextF i e ld ;385 }386387 /∗∗388 ∗ @r e t u r n t r u s t S t o r e P a s s w o r d F i e l d389 ∗/390 public JPasswordField getTrustStorePasswordFie ld ( ) {391 return t rustStorePasswordFie ld ;392 }393394 /∗∗395 ∗ @r e t u r n k e y S t o r e B u t t o n396 ∗/397 public JButton getKeyStoreButton ( ) {398 return keyStoreButton ;399 }400401 /∗∗402 ∗ @r e t u r n t r u s t S t o r e B u t t o n403 ∗/404 public JButton getTrustStoreButton ( ) {405 return t rustStoreButton ;406 }407408 /∗∗409 ∗ @r e t u r n f i l e c h o o s e r410 ∗/411 public JFi leChooser g e tF i l e choo s e r ( ) {412 return f i l e c h o o s e r ;413 }414415 /∗∗416 ∗ @r e t u r n l o g i n B u t t o n417 ∗/418 public JButton getLoginButton ( ) {419 return log inButton ;420 }421422 /∗∗423 ∗ @r e t u r n c a n c e l B u t t o n424 ∗/425 public JButton getCancelButton ( ) {426 return cancelButton ;427 }428429 /∗∗

Page 116: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

106 Appendix C - Source Code

430 ∗ @r e t u r n c l e a r B u t t o n431 ∗/432 public JButton getClearButton ( ) {433 return c learButton ;434 }435436437 }

Page 117: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 107

.1.9 Client.java

1 package mps . rmi ;23 import java . rmi . NotBoundException ;4 import java . rmi . RemoteException ;5 import java . rmi . r e g i s t r y . LocateReg is t ry ;6 import java . rmi . r e g i s t r y . Reg i s t ry ;78 import javax . rmi . s s l . Ss lRMIClientSocketFactory ;9

10 import mcc . s e rv e r . rmi . RMISessionAdminTrust ;11 import mcc . s e rv e r . rmi . RMISessionFullTrust ;12 import mcc . s e rv e r . rmi . RMISessionMediumTrust ;13 import mcc . s e rv e r . rmi . RMISessionMinimalTrust ;14 import mcc . s e rv e r . u s e r s . User ;1516 import common . auth . S impleCredent ia l s ;17 import common . command . DTUsat2CommandTypeXMLFile ;18 import common . rmi . s e cu r i t y . RMILogin ;19 import common . rmi . s e cu r i t y . RMISession ;2021 /∗∗22 ∗ Th i s c l a s s i s a s i n g l e t o n i m p l e m e n t a t i o n o f a C l i e n t . The o b j e c t s h o u l d b e s e t u p

u s i n g t h e C l i e n t C r e a t o r .23 ∗ Dep e n d i n g on t h e u s e r i n f o t h e mcc RMIS e s s i o n w i l l b e c a s t t o t h e c o r r e c t t r u s t

l e v e l .24 ∗ <br><br>25 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 326 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 127 ∗ @ v e r s i o n 1 . 028 ∗/29 public c lass Cl i ent {3031 /∗∗32 ∗ The h o s t o f MCC33 ∗/34 private Str ing host ;35 /∗∗36 ∗ The p o r t w h i c h MCC u s e s37 ∗/38 private int port ;39 /∗∗40 ∗ Remove o b j e c t u s e d t o l o g i n on MCC41 ∗/42 private Str ing remoteObject ;43 /∗∗44 ∗ C r e d e n t i a l s u s e d t o l o g i n on MCC45 ∗/46 private SimpleCredent ia l s c r e d e n t i a l s ;47 /∗∗48 ∗ Username o f t h e u s e r who i s l o g g e d i n49 ∗/50 private Str ing username ;51 /∗∗52 ∗ T r u s t l e v e l o f t h e u s e r who i s l o g g e d i n53 ∗/54 private int userTrustLeve l ;55 /∗∗56 ∗ The RMIS e s s i o n w h i c h i s u s e d t o do a l l t h e RMI c a l l s on MCC57 ∗/58 private RMISessionMinimalTrust mcc ;596061 /∗∗62 ∗ i n s t a n c e u s e d f o r t h e s i n g l e t o n i m p l e m e n t a t i o n63 ∗/64 private stat ic vo lat i l e Cl i ent in s tance = null ;6566 /∗∗67 ∗ Makes s u r e t h e r e i s n o t c r e a t e d a n o t h e r C l i e n t68 ∗/69 protected Cl i ent ( ) { }7071 /∗∗72 ∗ <b>S i n g l e t o n </b> i m p l e m e n t a t i o n − o n l y one C l i e n t can e x i s t s <br>73 ∗ Re t u r n s t h i s c l i e n t .74 ∗ C r e a t e s t h e c l i e n t t h e f i r s t t im e t h e me t hod i s c a l l e d .75 ∗ @r e t u r n C l i e n t76 ∗/77 public stat ic Cl i ent ge t In s tance ( ) {78 i f ( in s tance == null ) {79 synchronized (DTUsat2CommandTypeXMLFile . c lass ) {80 i f ( in s tance == null ) {81 in s tance = new Cl i ent ( ) ;82 }

Page 118: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

108 Appendix C - Source Code

83 }84 }85 return i n s tance ;86 }8788 /∗∗89 ∗90 ∗ @param h o s t The h o s t w h e r e MCC i s r u n n i n g91 ∗ @param p o r t The RMI p o r t92 ∗ @param r e m o t e O b j e c t The name o f t h e l o g i n o b j e c t93 ∗ @param c r e d e n t i a l s The c r e d e n t i a l s u s e d f o r l o g i n94 ∗ @th r ow s N o tB o u n dE x c e p t i o n95 ∗ @th r ow s R emo t e E x c e p t i o n96 ∗/97 public void s e t C l i e n t I n f o ( St r ing host , int port , S t r ing remoteObject ,

S impleCredent ia l s c r e d e n t i a l s ) throws RemoteException , NotBoundException{98 this . host = host ;99 this . port = port ;

100 this . remoteObject = remoteObject ;101 this . c r e d e n t i a l s = c r e d e n t i a l s ;102 username = c r e d e n t i a l s . getUsername ( ) ;103104 setupSess ionType ( ) ;105 }106107 /∗∗108 ∗ Log s i n and r e t u r n s an RMI s e s s i o n109 ∗ @r e t u r n The RMI s e s s i o n110 ∗ @th r ow s R emo t e E x c e p t i o n In c a s e o f any RMI s e s s i o n − i n c . n o t b e i n g a b l e t o

l o g i n111 ∗ @th r ow s N o tB o u n dE x c e p t i o n I f i t was i m p o s s i b l e t o l o c a t e t h e r emo t e o b j e c t112 ∗/113 private RMISession l o g i n ( ) throws RemoteException , NotBoundException{114 Reg i s t ry r e g i s t r y = LocateRegis t ry . ge tReg i s t ry ( host , port , new

SslRMIClientSocketFactory ( ) ) ;115 RMILogin l o g i n = (RMILogin ) r e g i s t r y . lookup ( remoteObject ) ;116117 return l o g i n . l o g i n ( c r e d e n t i a l s ) ;118 }119120 /∗∗121 ∗ P i n g s t h e s e r v e r . T r i e s t o l o g i n a g a i n i f t h e p i n g f a i l s .122 ∗ @th r ow s R emo t e E x c e p t i o n In c a s e o f an RMI e r r o r o r i f i t was i m p o s s i b l e t o

l o g i n123 ∗ @th r ow s N o tB o u n dE x c e p t i o n In c a s e o f an RMI e r r o r124 ∗/125 private void ping ( ) throws RemoteException , NotBoundException{126 try{127 mcc . ping ( ) ;128 }catch ( Exception e ){129 setupSess ionType ( ) ;130 }131 }132133 /∗∗ Use s t h e l o g i n me t hod t o s e t t h e MCC S e s s i o n t o t h e c o r r e c t t y p e a c c o r d i n g

t o c r e d e n t i a l s .134 ∗ F i r s t t r i e s i f Admin l e v e l i s p o s s i b l e , i f n o t i t c o n t i n u o u s t r y i n g w i t h

F u l l , Medium , o r M in ima l .135 ∗ The me thod i s u s e d a t l o g i n , o r when a p i n g f a i l s and t h e s e s s i o n n e e d s t o

b e re−e s t a b l i s h e d .136 ∗137 ∗ @th r ow s R emo t e E x c e p t i o n138 ∗ @th r ow s N o tB o u n dE x c e p t i o n139 ∗/140 private void setupSess ionType ( ) throws RemoteException , NotBoundException {141 try {142 mcc = ( RMISessionAdminTrust ) l o g i n ( ) ;143 userTrustLeve l = User .ADMINISTRATOR TRUST;144 } catch ( Exception adminException ) {145 try {146 mcc = ( RMISessionFullTrust ) l o g i n ( ) ;147 userTrustLeve l = User .FULL TRUST;148 } catch ( Exception fu l lExc ep t i on ) {149 try {150 mcc = ( RMISessionMediumTrust ) l o g i n ( ) ;151 userTrustLeve l = User .MEDIUM TRUST;152 } catch ( Exception mediumException ) {153 mcc = ( RMISessionMinimalTrust ) l o g i n ( ) ;154 userTrustLeve l = User .MINIMAL TRUST;155 }156 }157 }158159 }160161 /∗∗ Ge t s t h e RMIS e s s i o n a s a m i n ima l i n t e r f a c e162 ∗ @r e t u r n The r emo t e i n t e r f a c e

Page 119: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 109

163 ∗ @th r ow s N o tB o u n dE x c e p t i o n164 ∗ @th r ow s R emo t e E x c e p t i o n165 ∗/166 public RMISessionMinimalTrust getMin ima l Inte r face ( ) throws RemoteException ,

NotBoundException{167 ping ( ) ;168 return ( RMISessionMinimalTrust ) mcc ;169 }170171 /∗∗ Ge t s t h e RMIS e s s i o n a s a medium i n t e r f a c e172 ∗ @r e t u r n The r emo t e i n t e r f a c e173 ∗ @th r ow s N o tB o u n dE x c e p t i o n174 ∗ @th r ow s R emo t e E x c e p t i o n175 ∗/176 public RMISessionMediumTrust getMediumInterface ( ) throws RemoteException ,

NotBoundException {177 ping ( ) ;178 return ( RMISessionMediumTrust ) mcc ;179 }180181 /∗∗ Ge t s t h e RMIS e s s i o n a s a f u l l i n t e r f a c e182 ∗ @r e t u r n The r emo t e i n t e r f a c e183 ∗ @th r ow s N o tB o u n dE x c e p t i o n184 ∗ @th r ow s R emo t e E x c e p t i o n185 ∗/186 public RMISessionFullTrust g e t F u l l I n t e r f a c e ( ) throws RemoteException ,

NotBoundException {187 ping ( ) ;188 return ( RMISessionFullTrust ) mcc ;189 }190191 /∗∗ Ge t s t h e RMIS e s s i o n a s a admin i n t e r f a c e192 ∗ @r e t u r n The r emo t e i n t e r f a c e193 ∗ @th r ow s N o tB o u n dE x c e p t i o n194 ∗ @th r ow s R emo t e E x c e p t i o n195 ∗/196 public RMISessionAdminTrust getAdminInter face ( ) throws RemoteException ,

NotBoundException {197 ping ( ) ;198 return ( RMISessionAdminTrust ) mcc ;199 }200201202 /∗∗203 ∗ @r e t u r n r e m o t e O b j e c t204 ∗/205 public Str ing getRemoteObject ( ) {206 return remoteObject ;207 }208209 /∗∗210 ∗ @r e t u r n u s e r T r u s t L e v e l211 ∗/212 public int getUserTrustLeve l ( ) {213 return userTrustLeve l ;214 }215216 /∗∗217 ∗ @r e t u r n u s e r name218 ∗/219 public Str ing getUsername ( ) {220 return username ;221 }222 }

Page 120: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

110 Appendix C - Source Code

.1.10 ClientCreator.java

1 package mps . rmi ;23 import java . i o . F i l e ;4 import java . i o . Fi leInputStream ;5 import java . s e cu r i t y . KeyStore ;6 import java . s e cu r i t y . KeyStoreException ;7 import java . u t i l . Enumeration ;89 import common . auth . S impleCredent ia l s ;

10 import common . rmi . s e cu r i t y . SSLPropert ies ;111213 /∗∗14 ∗ Used t o s e t u p t h e C l i e n t o b j e c t .15 ∗ Method f o r c h e c k i n g k e y and t r u s t s t o r e im p l em e n t e d b y16 ∗ And r e a s and Kenne t h (MCC)17 ∗ <br><br>18 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 319 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 120 ∗ @see mps . rmi . C l i e n t . j a v a21 ∗ @ v e r s i o n 1 . 022 ∗/23 public c lass Cl ientCreator {242526 /∗∗27 ∗ C r e a t e s a c l i e n t b a s e d on i n f o f r om t h e a b o v e f i l e28 ∗ @r e t u r n29 ∗ @th r ow s E x c e p t i o n30 ∗/31 public stat ic void c r e a t eC l i en t ( St r ing url , int port , S t r ing log inObject , S t r ing

username , St r ing password , St r ing keystore , S t r ing keystorePassword ,St r ing t ru s t s t o r e , S t r ing trust s torePassword ) throws Exception{

3233 checkKeystores ( keystore , keystorePassword , t ru s t s t o r e , t rus t s torePassword ) ;34 Cl i ent . ge t In s tance ( ) . s e t C l i e n t I n f o ( ur l , port , log inObject , new

SimpleCredent ia l s ( username , password ) ) ;35 }3637 /∗∗38 ∗ Ch e c k s t h a t t h e u s e d k e y s t o r e s a r e ok39 ∗ Th i s me t hod i s a s l i g h t l y m o d i f i e d v e r s i o n o f t h e one f r om t h e c r e a t o r s o f

MCC40 ∗ @au t h o r And r e a s and Kenne t h41 ∗ @ a l t e r e d M i c h a e l and Ma t h i a s42 ∗ @th r ow s E x c e p t i o n43 ∗/44 private stat ic void checkKeystores ( St r ing keystore , S t r ing keystorePassword ,

St r ing t ru s t s t o r e , S t r ing trust s torePassword ) throws Exception{454647 F i l e k ey s t o r eF i l e = new F i l e ( keys tore ) ;48 i f ( ! k ey s t o r eF i l e . e x i s t s ( ) ){49 throw new Exception ( ”Unable to f i nd keys tore at ” + keystore ) ;50 }515253 KeyStore ks = null ;54 Enumeration<Str ing> keys = null ;555657 try{58 ks = KeyStore . ge t In s tance ( ” jk s ” ) ;59 ks . load (new FileInputStream ( key s t o r eF i l e ) , keystorePassword . toCharArray

( ) ) ;60 keys = ks . a l i a s e s ( ) ;61 }catch ( Exception e ){62 throw new Exception ( ”Unable to f i nd keys tore at ” + keystore + ”\

nThe password i s i n va l i d or the f i l e i s not a keys tore ” ) ;63 }6465 while ( keys . hasMoreElements ( ) ){66 St r ing a l i a s = keys . nextElement ( ) ;67 try {68 i f ( ks . isKeyEntry ( a l i a s ) ){69 try{70 St r ing algor i thm = ks . getKey ( a l i a s , keystorePassword .

toCharArray ( ) ) . getAlgorithm () ;71 i f ( ! a lgor i thm . toUpperCase ( ) . equa l s ( ”RSA” ) ){72 throw new Exception ( ”Key with a l i a s ” + a l i a s + ” i s

NOT a RSA key” ) ;73 }7475 }catch ( Exception e ){

Page 121: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 111

76 throw new Exception ( ”Unable to open the key with a l i a s ” +a l i a s + ”\nThe password i s wrong” ) ;

77 }7879 }80 } catch ( KeyStoreException e ) {81 // S h o u l d n e v e r h a p p en82 }83 }8485 F i l e t r u s t s t o r e F i l e = new F i l e ( t r u s t s t o r e ) ;86 i f ( ! t r u s t s t o r e F i l e . e x i s t s ( ) ){87 throw new Exception ( ”Unable to f i nd t r u s t s t o r e at ” + t r u s t s t o r e F i l e

. getAbsolutePath ( ) ) ;88 }8990919293 KeyStore t s = null ;94 Enumeration<Str ing> c e r t s = null ;9596 try{97 t s = KeyStore . ge t In s tance ( ” jk s ” ) ;98 t s . load (new FileInputStream ( t r u s t s t o r e F i l e ) , t rus t s torePassword .

toCharArray ( ) ) ;99 c e r t s = ts . a l i a s e s ( ) ;

100 }catch ( Exception e ){101 throw new Exception ( ”Unable to open t r u s t s t o r e at ” + t r u s t s t o r e F i l e

. getAbsolutePath ( ) + ”\nThe password i s i n va l i d or the f i l e i snot a keys tore ” ) ;

102 }103104 while ( c e r t s . hasMoreElements ( ) ){105 St r ing a l i a s = c e r t s . nextElement ( ) ;106 try {107 i f ( t s . i s C e r t i f i c a t e E n t r y ( a l i a s ) ){108 }109 } catch ( KeyStoreException e ) {110 // S h o u l d n e v e r h a p p en111 }112 }113114 SSLPropert ies s s lProp = new SSLPropert ies ( ) ;115 ss lProp . setKeyStore ( keystore , keystorePassword ) ;116 ss lProp . s e tTrus tStore ( t ru s t s t o r e , t rus t s torePassword ) ;117 }118 }

Page 122: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

112 Appendix C - Source Code

.1.11 DTUsat2CommandFactoryTest.java

1 package mps . t e s t ;23 import stat ic org . j un i t . Assert . a s s e r tEqua l s ;4 import stat ic org . j un i t . Assert . f a i l ;56 import org . j un i t . Test ;78 import common . command . DTUsat2Command ;9 import common . command . DTUsat2CommandFactory ;

10 import common . command . ModuleID ;11 import common . except ions . I l l ega lParamete rExcept ion ;12 import common . except ions . UnknownCommandTypeException ;1314 /∗∗15 ∗ <br><br>16 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 317 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 118 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 819 ∗/20 public c lass DTUsat2CommandFactoryTest {2122 /∗∗23 ∗ G e n e r a t e s a g o o d command and a s s e r t t y p e , d e s t i n a t i o n and a r g um e n t s a r e

c o r r e c t .24 ∗/25 @Test26 public void testGenerateCommandLegal ( ) {27 DTUsat2CommandFactory commandFactory = new DTUsat2CommandFactory ( ) ;28 DTUsat2Command command ;29 try {30 command = commandFactory . generateCommand ( ”2−CAM−10−150” ) ;3132 as s e r tEqua l s (2 , command . getCommandTypeID ( ) ) ;33 as s e r tEqua l s ( ModuleID .CAM, command . ge tDes t ina t i on ( ) ) ;34 as s e r tEqua l s (10 , command . getArguments ( ) [ 0 ] ) ;35 as s e r tEqua l s (150 , command . getArguments ( ) [ 1 ] ) ;3637 } catch (UnknownCommandTypeException e ) {38 e . pr intStackTrace ( ) ;39 f a i l ( ”Throw except ion − Unknown commandtype” ) ;40 } catch ( I l l ega lParamete rExcept ion e ) {41 e . pr intStackTrace ( ) ;42 f a i l ( ”Throw except ion − i l l e g a l parameter ” ) ;43 }4445 }4647 /∗∗ T r i e s t o g e n e r a t e a command w i t h i l l e g a l d e s t i n a t i o n48 ∗ @th r ow s UnknownCommandTypeExcep t i on49 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n50 ∗/51 @Test ( expected=Il lega lArgumentExcept ion . c lass )52 public void testGenerateCommandI l lega lDest inat ion ( ) throws

UnknownCommandTypeException , I l l ega lParamete rExcept ion {5354 DTUsat2CommandFactory commandFactory = new DTUsat2CommandFactory ( ) ;55 // COM i s i l l e g a l d e s t i n a t i o n f o r command t y p e 256 DTUsat2Command command = commandFactory . generateCommand ( ”2−COM

−10−150” ) ;5758 }5960 /∗∗ T r i e s t o g e n e r a t e a command i l l e g a l d o u b l e a r g umen t when e x p e c t i n g

i n t e g e r61 ∗ @th r ow s UnknownCommandTypeExcep t i on62 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n63 ∗/64 @Test ( expected=I l l ega lParamete rExcept ion . c lass )65 public void testGenerateCommandIllegalArgumentType ( ) throws

UnknownCommandTypeException , I l l ega lParamete rExcept ion {6667 DTUsat2CommandFactory commandFactory = new DTUsat2CommandFactory ( ) ;68 // COM i s i l l e g a l d e s t i n a t i o n f o r command t y p e 269 DTUsat2Command command = commandFactory . generateCommand ( ”2−CAM

−10−150.3” ) ;7071 }7273 /∗∗ T r i e s t o g e n e r a t e a command w i t h i l l e g a l d e s t i n a t i o n74 ∗ @th r ow s UnknownCommandTypeExcep t i on75 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n76 ∗/77 @Test ( expected=I l l ega lParamete rExcept ion . c lass )

Page 123: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 113

78 public void testGenerateCommandTooFewArguments ( ) throwsUnknownCommandTypeException , I l l ega lParamete rExcept ion {

7980 DTUsat2CommandFactory commandFactory = new DTUsat2CommandFactory ( ) ;8182 DTUsat2Command command = commandFactory . generateCommand ( ”2−CAM−10” ) ;8384 }8586 /∗∗ T r i e s t o g e n e r a t e a command w i t h i l l e g a l d e s t i n a t i o n87 ∗ @th r ow s UnknownCommandTypeExcep t i on88 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n89 ∗/90 @Test ( expected=I l l ega lParamete rExcept ion . c lass )91 public void testGenerateCommandTooManyArguments ( ) throws

UnknownCommandTypeException , I l l ega lParamete rExcept ion {9293 DTUsat2CommandFactory commandFactory = new DTUsat2CommandFactory ( ) ;9495 DTUsat2Command command = commandFactory . generateCommand ( ”2−CAM

−10−150−50” ) ;9697 }9899 /∗∗ T r i e s t o g e n e r a t e s a command w i t h unknown command t y p e

100 ∗ @th r ow s UnknownCommandTypeExcep t i on101 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n102 ∗/103 @Test ( expected=UnknownCommandTypeException . c lass )104 public void testGenerateCommandUnkownCommandType ( ) throws

UnknownCommandTypeException , I l l ega lParamete rExcept ion {105106 DTUsat2CommandFactory commandFactory = new DTUsat2CommandFactory ( ) ;107108 DTUsat2Command command = commandFactory . generateCommand ( ”50−CAM

−10−150” ) ;109110 }111112 }

Page 124: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

114 Appendix C - Source Code

.1.12 BlockController.java

1 package mps . gui . commanding ;23 import java . awt . event . ItemEvent ;4 import java . awt . event . I t emLis tener ;56 /∗∗7 ∗ C o n t r o l l e r f o r t h e b l o c k v i e w8 ∗ <br><br>9 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3

10 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 111 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 812 ∗/13 public c lass BlockContro l l e r implements I t emLis tener {1415 /∗∗16 ∗ The v i e w f o r t h e c o n t r o l l e r17 ∗/18 private BlockView view ;1920 /∗∗21 ∗ C o n s t r u c t s an i n s t a n c e o f t h e B l o c k C o n t r o l l e r w i t h t h e g i v e n B l o c kV i ew22 ∗ @param v i e w The v i e w f o r t h e c o n t r o l l e r23 ∗/24 public BlockContro l l e r ( BlockView view ) {25 this . view = view ;26 }2728 @Override29 public void itemStateChanged ( ItemEvent i e ) {303132 i f ( i e . getSource ( ) . equa l s ( view . getExistingBlockCheckBox ( ) ) ) {33 i f ( view . getExistingBlockCheckBox ( ) . i s S e l e c t e d ( ) ) {34 view . getBlocksCombo ( ) . setEnabled ( true ) ;35 } else {36 view . getBlocksCombo ( ) . setEnabled ( f a l s e ) ;37 }38 }394041 }4243 }

Page 125: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 115

.1.13 BlockView.java

1 package mps . gui . commanding ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . u t i l . ArrayList ;67 import javax . swing . JCheckBox ;8 import javax . swing . JComboBox ;9 import javax . swing . JPanel ;

1011 import mcc . s e rv e r . dataProcess ing . CommandBlock ;12 import mps . gui . t ime l i n e . TimeLineModel ;1314 import common . command .Command;1516 /∗∗17 ∗ A p a n e l f o r t h e command s e t u p v i e w wh e r e t h e u s e r can18 ∗ add t h e command t o an e x i s t i n g b l o c k19 ∗ <br><br>20 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 321 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 122 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 823 ∗ @see mps . g u i . commanding . CommandSetupView24 ∗/25 public c lass BlockView extends JPanel {2627 /∗∗28 ∗ The s e r i a l number o f t h e c l a s s29 ∗/30 private stat ic f ina l long se r ia lVers ionUID = 1L ;31 private Command commandToEdit ;32 private BlockContro l l e r c o n t r o l l e r ;3334 private JCheckBox exist ingBlockCheckBox ;35 private JComboBox blocksCombo ;3637 /∗∗38 ∗ C o n s t r u c t s an i n s t a n c e o f t h e B l o c kV i ew f o r a new command39 ∗/40 public BlockView ( ) {4142 bui ldBlockPanel ( ) ;43 }4445 /∗∗46 ∗ C o n s t r u c t s an i n s t a n c e o f t h e B l o c kV i ew f o r a g i v e n command f o r e d i t i n g47 ∗ @param commandToEdi t The command t h a t n e e d s e d i t i n g48 ∗/49 public BlockView (Command commandToEdit ) {50 this . commandToEdit = commandToEdit ;5152 bui ldBlockPanel ( ) ;5354 se tPrede f inedBlock ( ) ;5556 }5758 /∗∗59 ∗ B u i l d s t h e p a n e l f o r t h e u s e r i n p u t60 ∗/61 private void bui ldBlockPanel ( ) {6263 c o n t r o l l e r = new BlockContro l l e r ( this ) ;6465 JPanel panel = new JPanel ( ) ;6667 panel . setLayout (new GridBagLayout ( ) ) ;68 GridBagConstraints c = new GridBagConstraints ( ) ;69 c . anchor = GridBagConstraints .LINE START;7071 c . gr idy = 0 ;72 c . gr idx = 0 ;73 exist ingBlockCheckBox = new JCheckBox ( ”Add to e x i s t i n g block : ” ) ;7475 panel . add ( existingBlockCheckBox , c ) ;7677 blocksCombo = new JComboBox ( ) ;78 ArrayList<CommandBlock> blocks = TimeLineModel . g e t In s tance ( ) .

getUpcommingBlocks ( ) ;79 for (CommandBlock cb : b locks ) {80 blocksCombo . addItem ( cb . getCommandBlockID ( ) ) ;81 }8283 c . gr idx = 1 ;

Page 126: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

116 Appendix C - Source Code

84 panel . add ( blocksCombo , c ) ;8586 blocksCombo . setEnabled ( f a l s e ) ;8788 exist ingBlockCheckBox . addItemListener ( c o n t r o l l e r ) ;8990 this . add ( panel ) ;9192 }9394 /∗∗95 ∗ F i n d s t h e commands b l o c k . I f t h e b l o c k h a s two o r more commands i n t h e

b l o c k96 ∗ I t s e l e c t s t h e b l o c k i n t h i s p a n e l and s e l e c t t h e c h e c k b o x .97 ∗ I f t h e command i s i n i t s own b l o c k : Un−c h e c k t h e c h e c k b o x and s e l e c t de−

e n a b l e t h e l i s t o f commands98 ∗/99 private void se tPrede f inedBlock ( ) {

100101 boolean partOfBlock = ( TimeLineModel . g e t In s tance ( ) . getTimelineData ( )

. getCommandBlockMap ( ) . get ( commandToEdit . getBlockID ( ) ) . s i z e ( ) >1) ;

102103 // I f p a r t o f a b l o c k w i t h two o r more commands i n104 i f ( partOfBlock ) {105 exist ingBlockCheckBox . s e t S e l e c t ed ( true ) ;106 blocksCombo . setEnabled ( true ) ;107 blocksCombo . s e tSe l e c t ed I t em (commandToEdit . getBlockID ( ) ) ;108 } else {109 exist ingBlockCheckBox . s e t S e l e c t ed ( f a l s e ) ;110 blocksCombo . setEnabled ( f a l s e ) ;111 }112113 }114115 /∗∗116 ∗ @r e t u r n commandToEdi t117 ∗/118 public Command getCommandToEdit ( ) {119 return commandToEdit ;120 }121122 /∗∗123 ∗ @r e t u r n e x i s t i n g B l o c k C h e c k B o x124 ∗/125 public JCheckBox getExistingBlockCheckBox ( ) {126 return exist ingBlockCheckBox ;127 }128129 /∗∗130 ∗ @r e t u r n b l o c k sC omb o131 ∗/132 public JComboBox getBlocksCombo ( ) {133 return blocksCombo ;134 }135136 }

Page 127: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 117

.1.14 CommandSetupAbstractTableModel.java

1 package mps . gui . commanding ;23 import java . u t i l . ArrayList ;45 import javax . swing . tab l e . AbstractTableModel ;67 import common . command .CommandType ;8 import common . command . DTUsat2CommandTypeMap ;9

10 /∗∗11 ∗ An i m p l e m e n t a t i o n o f t h e A b s t r a c t T a b l e M o d e l .12 ∗ D e f i n e s wha t d a t a t o b e shown i n r ow s and c o l umn s13 ∗ <br><br>14 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 315 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 116 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 817 ∗ @see p a c k a g e j a v a x . s w i n g . t a b l e . A b s t r a c t T a b l e M o d e l . j a v a18 ∗/19 public c lass CommandSetupAbstractTableModel extends AbstractTableModel {2021 /∗∗22 ∗ The s e r i a l number o f t h e c l a s s23 ∗/24 private stat ic f ina l long se r ia lVers ionUID = 1L ;25 /∗∗26 ∗ The t y p e co l umn27 ∗/28 public stat ic f ina l int TYPE COLUMN = 0;29 /∗∗30 ∗ The name co l umn31 ∗/32 public stat ic f ina l int NAME COLUMN = 1;33 /∗∗34 ∗ The sub−s y s t em co l umn35 ∗/36 public stat ic f ina l int SUBSYSTEM COLUMN = 2;37 /∗∗38 ∗ The b y t e s c o l umn39 ∗/40 public stat ic f ina l int BYTES COLUMN = 3;4142 /∗∗43 ∗ An a r r a y c o n t a i n i n g a l l command t y p e s known t o t h e t a b l e44 ∗/45 private ArrayList<CommandType> commandTypeArray ;4647 /∗∗48 ∗ C o n s t r u c t s an i n s t a n c e o f C omman d S e t u pA b s t r a c t T a b l eMo d e l .49 ∗ Load s t h e commandType a r r a y a t c o n s t r u c t i o n , w i t h t h e known command t y p e s t o

t h e s y s t em50 ∗/51 public CommandSetupAbstractTableModel ( ) {52 // c o n v e r t HashMap t o A r r a y L i s t53 commandTypeArray = new ArrayList<CommandType>(DTUsat2CommandTypeMap .

ge t In s tance ( ) . getCommandTypeMap ( ) . va lues ( ) ) ;54 }5556 public int getColumnCount ( ) {57 return 4 ; // n e e d s s y n c h r o n i z a t i o n58 }5960 public int getRowCount ( ) {61 return commandTypeArray . s i z e ( ) ;62 }6364 public Str ing getColumnName( int co l ) {65 switch ( c o l ) {66 case TYPE COLUMN: return ”Type” ;67 case NAME COLUMN: return ”Name” ;68 case SUBSYSTEM COLUMN: return ”Subsystem” ;69 case BYTES COLUMN: return ”Bytes” ;70 default :71 return ”Unknown column” ;72 }73 }7475 public Object getValueAt ( int row , int co l ) {7677 CommandType commandType = commandTypeArray . get ( row ) ;78 i f (commandType == null ) return ”” ;7980 switch ( c o l ) {81 case TYPE COLUMN: return commandType . getTypeID ( ) ;82 case NAME COLUMN: return commandType . getName ( ) ;

Page 128: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

118 Appendix C - Source Code

83 case SUBSYSTEM COLUMN:84 St r ing subSystems = ”” ;85 subSystems += commandType .

ge tLega lDes t ina t i on s ( ) . get (0) ;86 for ( int i =1; i<= commandType .

ge tLega lDes t ina t i on s ( ) . s i z e ( )−1; i++) {

87 subSystems += ” , ” +commandType .ge tLega lDes t ina t i ons ( ) .get ( i ) . name ( ) ;

88 }89 return subSystems ;9091 case BYTES COLUMN: return commandType . getByteS ize ( ) ;92 default :93 return ”Unknown column” ;94 }9596 }9798 /∗∗99 ∗ JT a b l e u s e s t h i s me t hod t o d e t e r m i n e t h e d e f a u l t r e n d e r e r /

100 ∗ e d i t o r f o r e a c h c e l l . I f t h i s me t hod i s n o t imp l em en t e d ,101 ∗ t h e n t h e l a s t c o l umn wou l d c o n t a i n t e x t ( ” t r u e ”/” f a l s e ” ) ,102 ∗ r a t h e r t h a n a c h e c k b o x .103 ∗/104 @SuppressWarnings ( ”unchecked” )105 public Class getColumnClass ( int c ) {106 return getValueAt (0 , c ) . ge tClas s ( ) ;107 }108109110111 }

Page 129: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 119

.1.15 CommandSetupController.java

1 package mps . gui . commanding ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;56 import javax . swing . JOptionPane ;78 /∗∗9 ∗ C o n t r o l l e r f o r t h e command s e t u p

10 ∗ <br><br>11 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 312 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 113 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 814 ∗/15 public c lass CommandSetupController implements Act ionL i s t ener {1617 /∗∗18 ∗ The v i e w f o r t h e c o n t r o l l e r19 ∗/20 private CommandSetupView view ;2122 /∗∗23 ∗ C o n s t r u c t s an i n s t a n c e o f C omman d S e t u pC o n t r o l l e r w i t h t h e g i v e n v i e w24 ∗ @param v i e w A CommandSetupView f o r t h e c o n t r o l l e r25 ∗/26 public CommandSetupController (CommandSetupView view ) {27 this . view = view ;28 }2930 @Override31 public void act ionPerformed ( ActionEvent ae ) {32 i f ( ae . getSource ( ) . equa l s ( view . getCreateAndSendCommandButton ( ) ) ) {33 i f ( view . getSelectCommandPanelView ( ) . getDestinationComboBox ( )

. ge tSe l ec tedI tem () . equa l s ( view .getSelectCommandPanelView ( ) . getDefau l tDest inat ionTxt ( ) )) {

34 JOptionPane . showMessageDialog ( view , ” Please s e l e c t e da de s t i na t i on f o r the command” , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

3536 }37 }383940 }4142 }

Page 130: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

120 Appendix C - Source Code

.1.16 CommandSetupView.java

1 package mps . gui . commanding ;23 import java . awt . BorderLayout ;4 import java . awt . Font ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;78 import javax . swing . BorderFactory ;9 import javax . swing . JButton ;

10 import javax . swing . JPanel ;11 import javax . swing . border . EtchedBorder ;12 import javax . swing . border . Tit ledBorder ;1314 import common . command .Command;151617 /∗∗18 ∗ A g e n e r i c i m p l e m e n t a t i o n f o r command s e t u p . T h i s p a n e l i s c o n s t r u c t e d19 ∗ when t h e u s e r t r i e s t o c r e a t e o r e d i t a command . D e p e n d e n t on20 ∗ t h e c o r r e l a t i o n f o r t h e c r e a t i o n / e d i t i n g t h e p a n e l embed s p a n e l s21 ∗ f i t t i n g t o t h e t a s k .22 ∗ <br><br>23 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 324 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 125 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 826 ∗/27 public c lass CommandSetupView extends JPanel {282930 /∗∗31 ∗ The s e r i a l number o f t h e c l a s s32 ∗/33 private stat ic f ina l long se r ia lVers ionUID = 1L ;3435 /∗∗36 ∗ The command f e d t o t h e c l a s s i f t h e t a s k i s t o e d i t a command37 ∗/38 private Command commandToEdit ;3940 /∗∗41 ∗ Embed a t im e o f e x e c u t i o n p a n e l on t h i s p a n e l ?42 ∗/43 private boolean isTOE ;44 /∗∗45 ∗ Embed a p r i o r i t y p a n e l on t h i s p a n e l ?46 ∗/47 private boolean i s P r i o r i t y ;48 /∗∗49 ∗ Embed a p a s s p a n e l on t h i s p a n e l ?50 ∗/51 private boolean i sPas s ;52 /∗∗53 ∗ Embed a b l o c k p a n e l on t h i s p a n e l ?54 ∗/55 private boolean i sB lock ;5657 /∗∗58 ∗ The p a n e l c o n t a i n i n g a t a b l e f o r command s e l e c t i n g . T h i s p a n e l i s a l w a y s

embedd e d59 ∗/60 private SelectCommandPanelView selectCommandPanelView ;61 /∗∗62 ∗ A p a n e l f o r c h o o s i n g t im e o f e x e c u t i o n63 ∗/64 private ExecutionTimePanel executionTimePanel ;65 /∗∗66 ∗ A p a n e l f o r c h o o s i n g t h e p r i o r i t y o f t h e command ’ s b l o c k67 ∗/68 private Prior i tyView pr i o r i t yPane l ;69 /∗∗70 ∗ A p a n e l f o r c h o o s i n g t h e p a s s w h i c h t h e command h a s t o b e t r a n s m i t t e d w i t h71 ∗/72 private PassView passPanel ;73 /∗∗74 ∗ A p a n e l f o r c h o o s i n g t h e b l o c k t h e command can b e a d d e d t o75 ∗/76 private BlockView blockPanel ;7778 /∗∗79 ∗ The b u t t o n f o r a c c e p t i n g t h e i n p u t and c r e a t e / e d i t t h e command80 ∗/81 private JButton createAndSendCommandButton ;82 /∗∗83 ∗ The b u t t o n f o r c a n c e l i n g t h e t a s k and d i s p o s i n g o f t h e w indow

Page 131: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 121

84 ∗/85 private JButton cancelButton ;8687 /∗∗88 ∗ The c o n t r o l l e r o f t h i s p a n e l89 ∗/90 private CommandSetupController c o n t r o l l e r ;9192 /∗∗93 ∗ C o n s t r u c t s an i n s t a n c e o f CommandSetupView f o r c r e a t i n g commands94 ∗ @param isTOE Embed a t im e o f e x e c u t i o n p a n e l on t h i s p a n e l ?95 ∗ @param i s P r i o r i t y Embed a p r i o r i t y p a n e l on t h i s p a n e l ?96 ∗ @param i s P a s s Embed a p a s s p a n e l on t h i s p a n e l ?97 ∗ @param i s B l o c k Embed a b l o c k p a n e l on t h i s p a n e l ?98 ∗/99 public CommandSetupView(boolean isTOE , boolean i s P r i o r i t y , boolean i sPass ,

boolean i sB lock ) {100101 c o n t r o l l e r = new CommandSetupController ( this ) ;102103 this . isTOE = isTOE ;104 this . i s P r i o r i t y = i s P r i o r i t y ;105 this . i sPas s = i sPas s ;106 this . i sB lock = i sB lock ;107108 selectCommandPanelView = new SelectCommandPanelView ( ) ;109 i f ( isTOE) executionTimePanel = new ExecutionTimePanel ( ) ;110 i f ( i s P r i o r i t y ) p r i o r i t yPane l = new Prior i tyView ( ) ;111 i f ( i sPas s ) passPanel = new PassView ( ) ;112 i f ( i sB lock ) blockPanel = new BlockView ( ) ;113114 buildWindow () ;115116 }117118 /∗∗119 ∗ C o n s t r u c t s an i n s t a n c e o f CommandSetupView f o r e d i t i n g t h e g i v e n command120 ∗ @param isTOE Embed a t im e o f e x e c u t i o n p a n e l on t h i s p a n e l ?121 ∗ @param i s P r i o r i t y Embed a p r i o r i t y p a n e l on t h i s p a n e l ?122 ∗ @param i s P a s s Embed a p a s s p a n e l on t h i s p a n e l ?123 ∗ @param i s B l o c k Embed a b l o c k p a n e l on t h i s p a n e l ?124 ∗ @param commandToEdi t The command t o e d i t i n t h i s p a n e l125 ∗/126 public CommandSetupView(boolean isTOE , boolean i s P r i o r i t y , boolean i sPass ,

boolean i sBlock , Command commandToEdit ) {127128 this . isTOE = isTOE ;129 this . i s P r i o r i t y = i s P r i o r i t y ;130 this . i sPas s = i sPas s ;131 this . i sB lock = i sB lock ;132133 selectCommandPanelView = new SelectCommandPanelView (commandToEdit ) ;134 i f ( isTOE) executionTimePanel = new ExecutionTimePanel ( commandToEdit ) ;135 i f ( i s P r i o r i t y ) p r i o r i t yPane l = new Prior i tyView (commandToEdit ) ;136 i f ( i sPas s ) passPanel = new PassView (commandToEdit ) ;137 i f ( i sB lock ) blockPanel = new BlockView (commandToEdit ) ;138139 buildWindow () ;140141 }142143 /∗∗144 ∗ Ge t s t h e number o f c h o s e n p a n e l s embedd ed on t h i s p a n e l145 ∗ @r e t u r n The number o f p a n e l s c h o s e n t o embed on t h i s p a n e l146 ∗/147 private int getNoOfRightPanels ( ) {148 int r e s u l t = 0 ;149 i f ( isTOE) r e s u l t ++;150 i f ( i sPas s ) r e s u l t ++;151 i f ( i s P r i o r i t y ) r e s u l t ++;152 i f ( i sB lock ) r e s u l t ++;153154 return r e s u l t ;155 }156157 /∗∗158 ∗ B u i l d s t h e p a n e l w i t h t h e r i g h t hand s i d e p a n e l , t h a t c o n t a i n s t h e p a n e l s

s e t i n t h e c o n s t r u c t o r159 ∗/160 private void buildWindow () {161162 this . setLayout (new BorderLayout ( ) ) ;163164165 // B u i l d p a n e l s166 this . add ( buildMainPanels ( ) , BorderLayout .NORTH) ;167

Page 132: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

122 Appendix C - Source Code

168 JPanel buttonPanel = new JPanel ( ) ;169 cancelButton = new JButton ( ”Cancel ” ) ;170 buttonPanel . add ( cancelButton ) ;171 createAndSendCommandButton = new JButton ( ) ;172 buttonPanel . add ( createAndSendCommandButton ) ;173174 this . add ( buttonPanel , BorderLayout .SOUTH) ;175176177 // L i s t e n e r178 createAndSendCommandButton . addAct ionListener ( c o n t r o l l e r ) ;179 }180181182 /∗∗183 ∗ B u i l d s t h e r i g h t hand s i d e p a n e l , em b e d d i n g t h e p a n e l s t h a t i s n e e d e d f o r

t h e t a s k184 ∗ @r e t u r n A p a n e l embedd ed w i t h p a n e l s t h a t r e p r e s e n t t h e t a s k185 ∗/186 private JPanel buildMainPanels ( ) {187188 JPanel panel = new JPanel ( ) ;189190 panel . setLayout (new GridBagLayout ( ) ) ;191 GridBagConstraints c = new GridBagConstraints ( ) ;192193 c . f i l l = GridBagConstraints .HORIZONTAL;194 c . anchor = GridBagConstraints . FIRST LINE START ;195 c . g r i dhe i gh t = getNoOfRightPanels ( ) ;196 c . gr idx = 0 ;197 c . gr idy = 0 ;198 panel . add ( selectCommandPanelView , c ) ;199200 c . g r i dhe i gh t = 1 ;201 c . gr idx = 0 ;202 c . gr idx = 1 ;203 i f ( isTOE) {204 Tit ledBorder t i t l e = BorderFactory . c r ea teT i t l edBorder (

BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED) ,205 ” Execution Time” , Tit ledBorder .LEFT,

Tit ledBorder .CENTER ,new Font ( ”Tahoma”, Font .BOLD,11 ) ) ;

206 executionTimePanel . setBorder ( t i t l e ) ;207 panel . add ( executionTimePanel , c ) ;208 c . gr idy++;209 }210 i f ( i s P r i o r i t y ) {211 Tit ledBorder t i t l e = BorderFactory . c r ea teT i t l edBorder (

BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED) ,212 ” P r i o r i t y ” , Tit ledBorder .LEFT, Tit ledBorder .

CENTER ,new Font ( ”Tahoma” , Font .BOLD,11 )) ;

213 p r i o r i t yPane l . setBorder ( t i t l e ) ;214 panel . add ( pr i o r i tyPane l , c ) ;215 c . gr idy++;216 }217218 i f ( i sPas s ) {219 Tit ledBorder t i t l e = BorderFactory . c r ea teT i t l edBorder (

BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED) ,220 ”Pass” , Tit ledBorder .LEFT, Tit ledBorder .

CENTER ,new Font ( ”Tahoma” , Font .BOLD,11 ) ) ;

221 passPanel . setBorder ( t i t l e ) ;222 panel . add ( passPanel , c ) ;223 c . gr idy++;224 }225226 i f ( i sB lock ) {227 Tit ledBorder t i t l e = BorderFactory . c r ea teT i t l edBorder (

BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED) ,228 ”Block” , Tit ledBorder .LEFT, Tit ledBorder .

CENTER ,new Font ( ”Tahoma” , Font .BOLD,11 ) ) ;

229 blockPanel . setBorder ( t i t l e ) ;230 panel . add ( blockPanel , c ) ;231 c . gr idy++;232 }233234235 return panel ;236 }237238239 /∗∗240 ∗ @r e t u r n c r e a t eAndSendCommandBu t t on241 ∗/

Page 133: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 123

242 public JButton getCreateAndSendCommandButton ( ) {243 return createAndSendCommandButton ;244 }245246 /∗∗247 ∗ @r e t u r n commandToEdi t248 ∗/249 public Command getCommandToEdit ( ) {250 return commandToEdit ;251 }252253 /∗∗254 ∗ @r e t u r n c a n c e l B u t t o n255 ∗/256 public JButton getCancelButton ( ) {257 return cancelButton ;258 }259260 /∗∗261 ∗ @r e t u r n s e l e c tC ommandPan e lV i ew262 ∗/263 public SelectCommandPanelView getSelectCommandPanelView ( ) {264 return selectCommandPanelView ;265 }266267 /∗∗268 ∗ @r e t u r n p r i o r i t y P a n e l269 ∗/270 public Prior i tyView ge tPr i o r i t yPane l ( ) {271 return pr i o r i t yPane l ;272 }273274 /∗∗275 ∗ @r e t u r n p a s s P a n e l276 ∗/277 public PassView getPassPanel ( ) {278 return passPanel ;279 }280281 /∗∗282 ∗ @r e t u r n e x e c u t i o n T i m e P a n e l283 ∗/284 public ExecutionTimePanel getExecutionTimePanel ( ) {285 return executionTimePanel ;286 }287288 /∗∗289 ∗ @r e t u r n b l o c k P a n e l290 ∗/291 public BlockView getBlockPanel ( ) {292 return blockPanel ;293 }294295296 }

Page 134: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

124 Appendix C - Source Code

.1.17 ExecutionTimeController.java

1 package mps . gui . commanding ;23 import java . awt . event . ItemEvent ;4 import java . awt . event . I t emLis tener ;56 /∗∗7 ∗ C o n t r o l l e r f o r t h e t im e o f e x e c u t i o n p a n e l8 ∗ <br><br>9 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3

10 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 111 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 812 ∗/13 public c lass ExecutionTimeControl ler implements I t emLis tener {1415 /∗∗16 ∗ The v i e w f o r t h e c o n t r o l l e r17 ∗/18 private ExecutionTimePanel view ;1920 /∗∗21 ∗ C o n s t r u c t s an i n s t a n c e o f E x e c u t i o n T i m e C o n t r o l l e r w i t h t h e g i v e n v i e w22 ∗ @param v i e w23 ∗/24 public ExecutionTimeControl ler ( ExecutionTimePanel view ) {25 this . view = view ;2627 }2829 @Override30 public void itemStateChanged ( ItemEvent itemEvent ) {3132 i f ( itemEvent . getSource ( ) . equa l s ( view . getAsapCheckBox ( ) ) ) {3334 boolean asapChecked = view . getAsapCheckBox ( ) . i s S e l e c t e d ( ) ;3536 view . getDateAndTimeRadio ( ) . setEnabled ( ! asapChecked ) ;37 view . getDateTimeSpinnersPanel ( ) . getDateSpinner ( ) . setEnabled

( ! asapChecked ) ;38 view . getDateTimeSpinnersPanel ( ) . getTimeSpinner ( ) . setEnabled

( ! asapChecked ) ;3940 }414243 }4445 }

Page 135: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 125

.1.18 ExecutionTimePanel.java

1 package mps . gui . commanding ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;56 import javax . swing . ButtonGroup ;7 import javax . swing . JCheckBox ;8 import javax . swing . JPanel ;9 import javax . swing . JRadioButton ;

1011 import mps . gui . DateTimeSpinnersPanel ;1213 import common . command .Command;1415 /∗∗16 ∗ A p a n e l f o r h a n d l i n g t a s k a s s o c i a t e d w i t h t im e o f e x e c u t i o n f o r commands17 ∗ <br><br>18 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 319 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 120 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 821 ∗/22 public c lass ExecutionTimePanel extends JPanel {2324 /∗∗25 ∗ The s e r i a l number o f t h e c l a s s26 ∗/27 private stat ic f ina l long se r ia lVers ionUID = 1L ;28 /∗∗29 ∗ The c o n t r o l l e r f o r t h e v i e w30 ∗/31 private ExecutionTimeControl ler c o n t r o l l e r ;32 /∗∗33 ∗ A command f e d t o t h e p a n e l i f t h e t a s k o f t h e p a n e l i s t o e d i t a command34 ∗/35 private Command commandToEdit ;3637 /∗∗38 ∗ Check b o x f o r ma r k i n g t h e t im e o f e x e c u t i o n a s ASAP( a s s o on a s p o s s i b l e )39 ∗/40 private JCheckBox asapCheckBox = new JCheckBox ( ”As soon as p o s s i b l e ” ) ;41 /∗∗42 ∗ Rad i o b u t t o n t h a t mark s i f t h e command h a s a t im e o f e x e c u t i o n t h a t i s n o t

ASAP43 ∗/44 private JRadioButton dateAndTimeRadio ;4546 /∗∗47 ∗ Pan e l f o r s p i n n e r s s e t t i n g t h e t im e o f e x e c u t i o n48 ∗/49 private DateTimeSpinnersPanel dateTimeSpinnersPanel ;5051 /∗∗52 ∗ C o n s t r u c t s an i n s t a n c e o f E x e c u t i o nT im eP a n e l w i t h t h e t a s k o f c r e a t i n g a

command53 ∗/54 public ExecutionTimePanel ( ) {55 builtTOEPanel ( ) ;56 }5758 /∗∗59 ∗ C o n s t r u c t s an i n s t a n c e o f E x e c u t i o nT im eP a n e l w i t h t h e t a s k o f e d i t i n g a

command60 ∗ @param commandToEdi t The command t o e d i t61 ∗/62 public ExecutionTimePanel (Command commandToEdit ) {63 this . commandToEdit = commandToEdit ;64 builtTOEPanel ( ) ;65 setPredef inedExecutionTime ( ) ;66 }6768 /∗∗69 ∗ B u i l d s t h e p a n e l w i t h s p i n n e r s , c h e c k b o x and r a d i o b u t t o n , and a d d s t h e

c o n t r o l l e r70 ∗/71 private void builtTOEPanel ( ) {7273 c o n t r o l l e r = new ExecutionTimeControl ler ( this ) ;7475 JPanel panel = new JPanel ( ) ;76 // T i t l e d B o r d e r t i t l e = B o r d e r F a c t o r y . c r e a t e T i t l e d B o r d e r ( B o r d e r F a c t o r y .

c r e a t e E t c h e d B o r d e r ( E t c h e d B o r d e r .LOWERED) ,77 // ” E x e c u t i o n Time ” , T i t l e d B o r d e r . LEFT , T i t l e d B o r d e r .

CENTER , new Fon t ( ” Tahoma ” , Fon t . BOLD , 1 1 ) ) ;78 // p a n e l . s e t B o r d e r ( t i t l e ) ;

Page 136: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

126 Appendix C - Source Code

7980 panel . setLayout (new GridBagLayout ( ) ) ;81 GridBagConstraints c = new GridBagConstraints ( ) ;82 c . anchor = GridBagConstraints .LINE START;8384 c . gr idy = 0 ;85 c . gr idx = 0 ;86 panel . add ( asapCheckBox , c ) ;8788 dateAndTimeRadio = new JRadioButton ( ”Time” ) ;8990 dateAndTimeRadio . s e t S e l e c t ed ( true ) ;91 c . gr idy = 1 ;92 c . gr idx = 0 ;93 // c . g r i d w i d t h = 1 ;94 panel . add ( dateAndTimeRadio , c ) ;9596 dateTimeSpinnersPanel = new DateTimeSpinnersPanel ( ) ;97 c . gr idx = 1 ;98 panel . add ( dateTimeSpinnersPanel , c ) ;99

100101 ButtonGroup buttonGroup = new ButtonGroup ( ) ;102 buttonGroup . add ( dateAndTimeRadio ) ;103104105 asapCheckBox . addItemListener ( c o n t r o l l e r ) ;106107 this . add ( panel ) ;108 }109110 /∗∗111 ∗ I f t h e t a s k o f t h i s p a n e l i s t o e d i t a command t h e p a n e l mus t112 ∗ s e t t h e commands t im e o f e x e c u t i o n a s i t was d e f i n e d b y t h e g i v e n command113 ∗/114 private void setPredef inedExecutionTime ( ) {115116 i f ( commandToEdit . getTimeOfExecution ( )==−1) {117 asapCheckBox . doClick ( ) ;118 } else {119 dateTimeSpinnersPanel . setTime ( commandToEdit .

getTimeOfExecution ( ) ) ;120 }121122 }123124 /∗∗125 ∗ Ge t s t h e u n i x t im e f r om t h e s p i n n e r s126 ∗ @r e t u r n The u n i x t im e f r om t h e s p i n n e r s127 ∗/128 public long getTOEFromSpinners ( ) {129 return dateTimeSpinnersPanel . getTime ( ) ;130 }131132 /∗∗133 ∗ @r e t u r n a s a pCh e c kBo x134 ∗/135 public JCheckBox getAsapCheckBox ( ) {136 return asapCheckBox ;137 }138139 /∗∗140 ∗ @r e t u r n da t eAndT imeRad i o141 ∗/142 public JRadioButton getDateAndTimeRadio ( ) {143 return dateAndTimeRadio ;144 }145146 /∗∗147 ∗ @r e t u r n d a t e T i m e S p i n n e r s P a n e l148 ∗/149 public DateTimeSpinnersPanel getDateTimeSpinnersPanel ( ) {150 return dateTimeSpinnersPanel ;151 }152153 }

Page 137: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 127

.1.19 ParametersPanel.java

1 package mps . gui . commanding ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;6 import java . u t i l . ArrayList ;78 import javax . swing . JComboBox ;9 import javax . swing . JLabel ;

10 import javax . swing . JPanel ;11 import javax . swing . JSpinner ;12 import javax . swing . JTextField ;13 import javax . swing . SpinnerNumberModel ;1415 import common . command .Command;16 import common . command .CommandType ;17 import common . command . DTUsat2Command ;18 import common . command . DTUsat2CommandTypeMap ;19 import common . command . parameter . BooleanParameter ;20 import common . command . parameter . DoubleParameter ;21 import common . command . parameter . IntParameter ;22 import common . command . parameter . ParameterType ;23 import common . command . parameter . Str ingParameter ;2425 /∗∗26 ∗ A p a n e l f o r h a n d l i n g command p a r a m e t e r s .27 ∗ The p a n e l o f f e r s t h e u s e r t o s p e c i f y wha t a r g um e n t s28 ∗ t h e command s h o u l d h a v e . The p a n e l i s g e n e r a t e d f r om29 ∗ wha t command t y p e h a s b e e n g i v e n t o t h i s p a n e l .30 ∗ I f none i s g i v e n t h e p a n e l i s emp t y .31 ∗ Th i s p a n e l i s emb edd ed on S e l e c tCommandPan e lV i ew .32 ∗ <br><br>33 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 334 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 135 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 836 ∗/37 public c lass ParametersPanel extends JPanel{3839 /∗∗40 ∗ The s e r i a l number o f t h e c l a s s41 ∗/42 private stat ic f ina l long se r ia lVers ionUID = 1L ;43 /∗∗44 ∗ A l i s t o f g r a p h i c a l e l e m e n t s t h a t mus t b e shown t o t h e u s e r when

s e l e c t i n g a command .45 ∗ The e l e m e n t s i n t h i s l i s t a l s o c o n t a i n s t h e a r g um e n t s g i v e n b y t h e u s e r .46 ∗/47 private ArrayList<Object> argumentsChooser = new ArrayList<Object >() ;48 /∗∗49 ∗ The command t o e d i t i f t h e t a s k i s t o e d i t a command50 ∗/51 private Command commandToEdit ;52 /∗∗53 ∗ The command t y p e o f t h e command s e l e c t e d i n t h e t a b l e54 ∗/55 private CommandType commandType ;5657 /∗∗58 ∗ C o n s t r u c t s an i n s t a n c e o f P a r am e t e r s P a n e l . Used when c r e a t i n g a new

command59 ∗/60 public ParametersPanel ( ) {6162 bui ldPanel ( ) ;6364 this . s e t V i s i b l e ( true ) ;6566 }6768 /∗∗69 ∗ C o n s t r u c t s an i n s t a n c e o f P a r am e t e r s P a n e l w i t h t h e g i v e n command .70 ∗ Used when e d i t i n g commands71 ∗ @param commandToEdi t The command t o e d i t72 ∗/73 public ParametersPanel (Command commandToEdit ) {7475 this . commandToEdit = commandToEdit ;7677 int no = ((DTUsat2Command) commandToEdit ) . getCommandTypeID ( ) ;78 commandType = DTUsat2CommandTypeMap . ge t In s tance ( ) . getCommandType( no )

;7980 bui ldPanel ( ) ;81

Page 138: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

128 Appendix C - Source Code

82 this . s e t V i s i b l e ( true ) ;83 }8485 /∗∗86 ∗ B u i l d s t h e p a n e l . I f no command t y p e i s s p e c i f i e d f o r t h i s p a n e l t h e

p a n e l i s emp t y .87 ∗ I f a command t y p e i s s p e c i f i e d t h e command t y p e w i l l s p e c i f y wha t

e l e m e n t s88 ∗ s h o u l d b e g e n e r a t e d f o r t h i s p a n e l .89 ∗/90 public void bui ldPanel ( ) {91 // C l e a r s t h e p a n e l o f e l e m e n t s92 this . removeAll ( ) ;9394 JPanel panel = new JPanel ( ) ;9596 // I f a command t y p e i s s p e c i f i e d i . e . a command i s s e l e c t e d i n

S e l e c tCommandPan e lV i ew ’ s t a b l e97 i f (commandType!=null ) {9899 panel . setLayout (new GridBagLayout ( ) ) ;

100101 GridBagConstraints c = new GridBagConstraints ( ) ;102 c . f i l l = GridBagConstraints .HORIZONTAL;103104 c . gr idx = 0 ;105 c . gr idy = 0 ;106 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;107 c . anchor = GridBagConstraints .LINE START;108109 argumentsChooser . c l e a r ( ) ;110111 i f (commandType . getParameters ( ) . s i z e ( )==0) {112 panel . add (new JLabel ( ”No arguments needed f o r ” +

commandType . getName ( ) ) ) ;113 } else {114115 for ( int i =0; i<=commandType . getParameters ( ) . s i z e ( )

−1; i++) {116117 panel . add (new JLabel (commandType .

getParameters ( ) . get ( i ) . getName ( ) + ” : ”) , c ) ;

118119 ParameterType parameterType = commandType .

getParameters ( ) . get ( i ) . getParameterType( ) ;

120 i f ( parameterType instanceof IntParameter ) {121 IntParameter param = ( IntParameter )

parameterType ;122123 SpinnerNumberModel

spinnerNumberModel = newSpinnerNumberModel (param .getDefaultValue ( ) , param .getLowerLimit ( ) , param .getUpperLimit ( ) , param .getAccuracy ( ) ) ;

124 JSpinner j s p i nne r = new JSpinner (spinnerNumberModel ) ;

125 c . gr idx++;126 c . anchor = GridBagConstraints .

LINE START;127 panel . add ( j sp inner , c ) ;128 St r ing unit = param . getUnit ( )==null

? ”” : param . getUnit ( ) ;129 JLabel unitLabe l = new JLabel ( ”<html

><i> ”+unit+”</i>” ) ;130 c . gr idx++;131 panel . add ( unitLabel , c ) ;132133 argumentsChooser . add (

spinnerNumberModel ) ;134135 i f ( commandToEdit!=null ) {136 // S e t c u r r e n t v a l u e137 Object [ ] args = ( (

DTUsat2Command)commandToEdit ) .getArguments ( ) ;

138 spinnerNumberModel . setValue (args [ i ] ) ;

139 }140141 } else i f ( parameterType instanceof DoubleParameter )

{

Page 139: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 129

142 DoubleParameter param = ( DoubleParameter )parameterType ;

143 // TODO: DEFUALT VALUES OFPARAMETERS

144 SpinnerNumberModelspinnerNumberModel = newSpinnerNumberModel (param .getDefaultValue ( ) , param .getLowerLimit ( ) , param .getUpperLimit ( ) , param .getAccuracy ( ) ) ;

145 JSpinner j s p i nne r = new JSpinner (spinnerNumberModel ) ;

146 c . gr idx++;147 c . anchor = GridBagConstraints .

LINE START;148 panel . add ( j sp inner , c ) ;149150 St r ing unit = param . getUnit ( )==null

? ”” : param . getUnit ( ) ;151 JLabel unitLabe l = new JLabel ( ”<html

><i> ”+unit+”</i>” ) ;152 c . gr idx++;153 panel . add ( unitLabel , c ) ;154155 argumentsChooser . add (

spinnerNumberModel ) ;156157 i f ( commandToEdit!=null ) {158 // S e t c u r r e n t v a l u e159 Object [ ] args = ( (

DTUsat2Command)commandToEdit )

. getArguments ( );

160 spinnerNumberModel .setValue ( args [i ] ) ;

161 }162163 } else i f ( parameterType instanceof BooleanParameter )

{164 // TODO: S u p p o r t b o o l i s o t h e r t y p e t h a t

0/1?165 St r ing [ ] comboOptions = {” true ” , ” f a l s e ” } ;166 JComboBox boolComboBox = new JComboBox(

comboOptions ) ;167 c . gr idx++;168 c . anchor = GridBagConstraints .LINE START;169 panel . add (boolComboBox , c ) ;170171 JLabel unitLabe l = new JLabel ( ” ” ) ;

// emp t y ( no u n i t f o r b o o l e a nv a l u e s

172 c . gr idx++;173 panel . add ( unitLabe l ) ;174175 argumentsChooser . add (boolComboBox ) ;176177 i f ( commandToEdit!=null ) {178 // S e t c u r r e n t v a l u e179 Object [ ] args = ( (

DTUsat2Command)commandToEdit )

. getArguments ( );

180 i f ( ( In t ege r ) args [ i ]== 1)boolComboBox .s e tSe l e c t ed I t em( ” true ” ) ;

181 else boolComboBox .s e tSe l e c t ed I t em( ” f a l s e ” ) ;

182 }183184 } else i f ( parameterType instanceof StringParameter )

{185 JTextField s t r ingTextF i e ld = new JTextField

( ) ;186 c . gr idx++;187 c . anchor = GridBagConstraints .LINE START;188 panel . add ( s t r ingTextFie ld , c ) ;189190 JLabel unitLabe l = new JLabel ( ” ” ) ; // emp t y

( no u n i t f o r s t r i n g v a l u e s191 c . gr idx++;

Page 140: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

130 Appendix C - Source Code

192 panel . add ( unitLabe l ) ;193194 argumentsChooser . add ( s t r ingTextF i e ld ) ;195196 i f ( commandToEdit!=null ) {197 // S e t c u r r e n t v a l u e198 Object [ ] args = ( (

DTUsat2Command)commandToEdit )

. getArguments ( );

199 s t r ingTextF i e ld .setText ( args [ i] . t oS t r ing ( ) ) ;

200 }201202 } else {203 throw new I l l ega lArgumentExcept ion ( ”

Parameter type not contained in f a c to ry” ) ;

204 }205206207 // c . g r i d x ++;208 //TODO: F i x u n i t209 // p a n e l . add ( new J L a b e l ( commandType .

g e t P a r a m e t e r s ( ) . g e t ( i ) . g e t P a r am e t e r T y p e( ) . g e t U n i t ( ) ) , c ) ;

210211212 JLabel de s c r i p t i onLabe l = new JLabel (

commandType . getParameters ( ) . get ( i ) .g e tDesc r ip t i on ( ) ) ;

213 c . gr idx++;214 panel . add ( desc r ip t i onLabe l , c ) ;215216 c . gr idy++;217 c . gr idx = 0 ;218219 }220221 }222223 }224225226 this . r epa in t ( ) ;227228 panel . s e t V i s i b l e ( true ) ;229230 this . add ( panel ) ;231 }232233 /∗∗234 ∗ S e t s t h e command t y p e t o s p e c i f y how t h e p a n e l s h o u l d b e b u i l d .235 ∗ I s c a l l e d b y S e l e c tCommandPan e lV i ew t o draw e l e m e n t s n e e d e d f o r t h e

command s e l e c t e d236 ∗ @param commandType237 ∗/238 public void setCommandTypeNo(CommandType commandType) {239 this . commandType = commandType ;240 }241242 /∗∗243 ∗ @r e t u r n a r g um e n t s C h o o s e r244 ∗/245 public ArrayList<Object> getArgumentsChooser ( ) {246 return argumentsChooser ;247 }248249 }

Page 141: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 131

.1.20 PassComboBox.java

1 package mps . gui . commanding ;23 import java . text . SimpleDateFormat ;4 import java . u t i l . ArrayList ;56 import javax . swing . JComboBox ;78 import mcc . s e rv e r . dataProcess ing . Pass ;9 import mps . MPSPreferences ;

10 import mps . gui . t ime l i n e . TimeLineModel ;1112 /∗∗13 ∗ A combo b o x ( d r o p down menu ) w i t h f u t u r e op en p a s s e s .14 ∗ I s embedd e d i n two d i f f e r e n t p a n e l s :15 ∗ <u l >16 ∗ < l i >I n t h e p a n e l f o r s e l e c t i n g u s e r g i v e n p a s s17 ∗ < l i >I n t h e t a b l e o f commands a d d e d t o a command b l o c k18 ∗ </u l >19 ∗ <br><br>20 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 321 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 122 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 823 ∗/24 public c lass PassComboBox extends JComboBox{252627 /∗∗28 ∗ The s e r i a l number f o r t h e c l a s s29 ∗/30 private stat ic f ina l long se r ia lVers ionUID = 1L ;3132 /∗∗33 ∗ L i s t o f u p c om in g open p a s s e s34 ∗/35 private ArrayList<Pass> upcomingPasses ;3637 /∗∗38 ∗ S h a l l t h e combo b o x i n c l u d e a u t o m a t i c s c h e d u l i n g a s an o p t i o n ?39 ∗/40 private boolean autoOptionOn ;4142 /∗∗43 ∗ C o n s t r u c t s an i n s t a n c e o f PassComboBox . F i l l s t h e u p c om i n g P a s s e s w i t h

p a s s e s .44 ∗ Th i s c o n s t r u c t o r i s u s e d f o r t h e p a n e l f o r s e l e c t i n g u s e r g i v e n p a s s .45 ∗/46 public PassComboBox ( ) {47 autoOptionOn = f a l s e ;48 upcomingPasses = TimeLineModel . g e t In s tance ( ) . getUpcomingOpenPasses ( )

;4950 addPassesToCombo ( ) ;51 }5253 /∗∗54 ∗ C o n s t r u c t s an i n s t a n c e o f PassComboBox . F i l l s t h e u p c om i n g P a s s e s w i t h

p a s s e s .55 ∗ Th i s c o n s t r u c t o r i s u s e d i n t h e t a b l e o f commands , a d d e d t o a command

b l o c k .56 ∗/57 public PassComboBox(boolean autoOptionOn ) {58 upcomingPasses = TimeLineModel . g e t In s tance ( ) . getUpcomingOpenPasses ( )

;59 this . addItem ( ” AUTO” ) ;60 this . addItem ( ”−−−−−−−−−−−−” ) ;6162 addPassesToCombo ( ) ;63 }6465 /∗∗66 ∗ Adds a l l t h e p a s s e s i n u p c om i n g P a s s e s t o t h e combo b o x67 ∗/68 private void addPassesToCombo ( ) {6970 for ( Pass pass : upcomingPasses ) {71 St r ing startTime = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( pass . getStartTime ( ) ) ;72 St r ing endTime = new SimpleDateFormat ( MPSPreferences . getTimeFormat ( )

) . format ( pass . getEndTime ( ) ) ;73 this . addItem ( ”ID : ”+pass . getPassID ( )+ ” , Time : ” + startTime + ” − ”

+ endTime ) ;74 }7576 }

Page 142: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

132 Appendix C - Source Code

7778 /∗∗79 ∗ Ge t s t h e p a s s ID o f t h e p a s s s e l e c t e d i n t h e combo b o x .80 ∗ I f t h e a u t o o p t i o n i s on and f i r s t o r s e c o n d e l e m e n t i s s e l e c t e d i t

r e t u r n s −1.81 ∗ @r e t u r n The p a s s ID o f t h e s e l e c t e d p a s s . −1 i f a u t o o p t i o n i s on and

f i r s t o r s e c o n d e l e m e n t i s s e l e c t e d82 ∗/83 public long getSe lectedPass ID ( ) {8485 int s e l e c t ed Index = this . g e tSe l e c t ed Index ( ) ;8687 i f ( autoOptionOn ) {88 // move 2 f o r w a r d i n a r r a y b e c a u s e o f t h e ” Auto ” and ”−−−”

i t em89 i f ( s e l e c t ed Index==0) return −1;90 i f ( s e l e c t ed Index==1) return −1;91 return upcomingPasses . get ( s e l e c t ed Index +2) . getPassID ( ) ;9293 } else {94 return upcomingPasses . get ( s e l e c t ed Index ) . getPassID ( ) ;95 }9697 }9899 /∗∗

100 ∗ S e t s t h e s e l e c t i o n o f t h e combo b o x t o t h e p a s s w i t h t h e g i v e n p a s s ID101 ∗ @param i d The p a s s ID o f t h e p a s s t o b e s e l e c t e d102 ∗/103 public void setSelec ionFromPassID ( long id ) {104105 // i f combo b o x h a s a u t o o p t i o n and t h e p a s s i s a u t o106 i f ( autoOptionOn && id==−1) this . s e tSe l e c t ed Index (0) ;107108 for ( int i =0; i<=upcomingPasses . s i z e ( )−1; i++) {109 i f ( upcomingPasses . get ( i ) . getPassID ( )==id ) {110 i f ( autoOptionOn ) {111 // s e l e c t i o n +2112 this . s e tSe l e c t ed Index ( i +2) ;113 } else {114 this . s e tSe l e c t ed Index ( i ) ;115 }116117118 }119 }120 }121122123124 }

Page 143: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 133

.1.21 PassController.java

1 package mps . gui . commanding ;23 import java . awt . event . ItemEvent ;4 import java . awt . event . I t emLis tener ;56 /∗∗7 ∗ Th i s c l a s s i s t h e c o n t r o l l e r o f t h e Pa s s View8 ∗ <br><br>9 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3

10 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 111 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 812 ∗/13 public c lass PassContro l l e r implements I t emLis tener {1415 /∗∗16 ∗ The v i e w c o n t r o l l e d b y t h i s c o n t r o l l e r17 ∗/18 private PassView view ;1920 /∗∗21 ∗ C o n s t r u c t s an i n s t a n c e o f P a s s C o n t r o l l e r w i t h t h e g i v e n v i e w22 ∗ @param v i e w23 ∗/24 public PassContro l l e r ( PassView view ) {25 this . view = view ;26 }2728 @Override29 public void itemStateChanged ( ItemEvent i e ) {3031 i f ( i e . getSource ( ) . equa l s ( view . getAutomaticPassCheckBox ( ) ) ) {32 i f ( view . getAutomaticPassCheckBox ( ) . i s S e l e c t e d ( ) ) {33 view . getUserGivenPassCombo ( ) . setEnabled ( f a l s e ) ;34 } else {35 view . getUserGivenPassCombo ( ) . setEnabled ( true ) ;36 }37 }383940 }4142 }

Page 144: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

134 Appendix C - Source Code

.1.22 PassView.java

1 package mps . gui . commanding ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;56 import javax . swing . JCheckBox ;7 import javax . swing . JComboBox ;8 import javax . swing . JLabel ;9 import javax . swing . JPanel ;

1011 import common . command .Command;121314 /∗∗15 ∗ The p a n e l w i t h i n f o r m a t i o n a b o u t t h e p a s s t h a t a command s h o u l d b e t r a n s m i t t e d

w i t h .16 ∗ Can b e g i v e n a command i f t h e t a s k i s t o e d i t an e x i s t i n g command17 ∗ <br><br>18 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 319 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 120 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 821 ∗/22 public c lass PassView extends JPanel{2324 /∗∗25 ∗ The s e r i a l number o f t h e c l a s s26 ∗/27 private stat ic f ina l long se r ia lVers ionUID = 1L ;28 /∗∗29 ∗ The c o n t r o l l e r f o r t h e v i e w30 ∗/31 private PassContro l l e r c o n t r o l l e r ;32 /∗∗33 ∗ The command g i v e n t o t h e v i e w i f t h e t a s k i s t o e d i t a command34 ∗/35 private Command commandToEdit ;3637 /∗∗38 ∗ Check b o x t o i n d i c a t e i f t h e p a s s i s u s e r g i v e n o r n o t39 ∗/40 private JCheckBox automaticPassCheckBox ;41 /∗∗42 ∗ Combo b o x f o r c h o o s i n g a p a s s43 ∗/44 private PassComboBox userGivenPassCombo ;4546 /∗∗47 ∗ C o n s t r u c t s an i n s t a n c e o f Pas sV iew , w i t h t h e t a s k o f a new command48 ∗/49 public PassView ( ) {5051 bui ldPassPanel ( ) ;52 }5354 /∗∗55 ∗ C o n s t r u c t s an i n s t a n c e o f Pas sV iew , w i t h t h e t a s k t o e d i t a command56 ∗ @param commandToEdi t The command t h a t s h o u l d b e e d i t e d57 ∗/58 public PassView (Command commandToEdit ) {59 this . commandToEdit = commandToEdit ;6061 bui ldPassPanel ( ) ;62 se tPrede f inedPass ( ) ;63 }6465 private void bui ldPassPanel ( ) {6667 c o n t r o l l e r = new PassContro l l e r ( this ) ;6869 JPanel panel = new JPanel ( ) ;70 // T i t l e d B o r d e r t i t l e = B o r d e r F a c t o r y . c r e a t e T i t l e d B o r d e r ( B o r d e r F a c t o r y .

c r e a t e E t c h e d B o r d e r ( E t c h e d B o r d e r .LOWERED) ,71 // ” Pa s s ” , T i t l e d B o r d e r . LEFT , T i t l e d B o r d e r . CENTER , new

Fon t ( ” Tahoma ” , Fon t . BOLD , 1 1 ) ) ;72 // p a n e l . s e t B o r d e r ( t i t l e ) ;737475 panel . setLayout (new GridBagLayout ( ) ) ;76 GridBagConstraints c = new GridBagConstraints ( ) ;77 c . anchor = GridBagConstraints .LINE START;7879 c . gr idy = 0 ;80 c . gr idx = 0 ;81 c . gr idwidth= 2 ;

Page 145: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 135

82 automaticPassCheckBox = new JCheckBox ( ”Automatic pass schedu l ing . ” ) ;8384 panel . add ( automaticPassCheckBox , c ) ;8586 c . gr idwidth = 1 ;87 c . gr idy = 1 ;88 panel . add (new JLabel ( ”User given pass : ” ) , c ) ;89 c . gr idx = 2 ;9091 userGivenPassCombo = new PassComboBox ( ) ;929394 c . gr idx = 1 ;95 panel . add ( userGivenPassCombo , c ) ;9697 automaticPassCheckBox . s e t S e l e c t ed ( true ) ;98 userGivenPassCombo . setEnabled ( f a l s e ) ;99

100101 automaticPassCheckBox . addItemListener ( c o n t r o l l e r ) ;102103104 this . add ( panel ) ;105106 }107108 /∗∗109 ∗ S e t s t h e c h e c k b o x and t h e combo b o x f o r t h e p a n e l .110 ∗ I s s e t d e p e n d i n g on w h e t h e r t h e t a s k i s t o c r e a t e o r e d i t a command111 ∗/112 private void s e tPrede f inedPass ( ) {113114 i f ( ! commandToEdit . getUserGivenPass ( ) ) {115 automaticPassCheckBox . s e t S e l e c t ed ( true ) ;116 userGivenPassCombo . setEnabled ( f a l s e ) ;117 } else {118 automaticPassCheckBox . s e t S e l e c t ed ( f a l s e ) ;119 userGivenPassCombo . setEnabled ( true ) ;120 // s e l e c t c o r r e c t p a s s i n combo :121 userGivenPassCombo . setSelec ionFromPassID (commandToEdit . getPassID ( ) ) ;122 }123124 }125126 /∗∗127 ∗ @r e t u r n The p a s s ID o f t h e s e l e c t e d i t em i n t h e combo b o x128 ∗/129 public long getSelectedUserGivenPassID ( ) {130 return userGivenPassCombo . getSe lectedPass ID ( ) ;131 }132133 /∗∗134 ∗ @r e t u r n a u t om a t i c P a s s C h e c k B o x135 ∗/136 public JCheckBox getAutomaticPassCheckBox ( ) {137 return automaticPassCheckBox ;138 }139140 /∗∗141 ∗ @r e t u r n u s e rG i v e nPa s sCombo142 ∗/143 public JComboBox getUserGivenPassCombo ( ) {144 return userGivenPassCombo ;145 }146147148 }

Page 146: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

136 Appendix C - Source Code

.1.23 PriorityView.java

1 package mps . gui . commanding ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;6 import java . rmi . NotBoundException ;7 import java . rmi . RemoteException ;8 import java . u t i l . HashMap ;9

10 import javax . swing . ButtonGroup ;11 import javax . swing . JLabel ;12 import javax . swing . JOptionPane ;13 import javax . swing . JPanel ;14 import javax . swing . JRadioButton ;1516 import mcc . s e rv e r . dataProcess ing . CommandBlock ;17 import mps . rmi . C l i ent ;1819 import common . command .Command;2021 /∗∗22 ∗ A p a n e l f o r d e f i n i n g w h e t h e r a command / command b l o c k i s h i g h o r n o rma l p r i o r i t y23 ∗ <br><br>24 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 325 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 126 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 827 ∗/28 public c lass Prior i tyView extends JPanel {2930 /∗∗31 ∗ The s e r i a l number o f t h e c l a s s32 ∗/33 private stat ic f ina l long se r ia lVers ionUID = 1L ;3435 /∗∗36 ∗ The command g i v e n i f t h e t a s k i s t o e d i t a command37 ∗/38 private Command commandToEdit ;3940 /∗∗41 ∗ Rad i o b u t t o n t h a t i n d i c a t e s n o rma l p r i o r i t y i f s e l e c t e d42 ∗/43 private JRadioButton normalPr ior i tyRadio ;44 /∗∗45 ∗ Rad i o b u t t o n t h a t i n d i c a t e s h i g h p r i o r i t y i f s e l e c t e d46 ∗/47 private JRadioButton h ighPr ior i tyRad io ;4849 /∗∗50 ∗ C o n s t r u c t s an i n s t a n c e o f P r i o r i t y V i e w , w i t h t h e t a s k o f e d i t i n g t h e

g i v e n command51 ∗ @param commandToEdi t52 ∗/53 public Prior i tyView (Command commandToEdit ) {54 this . commandToEdit = commandToEdit ;55 bu i l tP r i o r i t yPane l ( ) ;56 s e tP r ed e f i n edPr i o r i t y ( ) ;57 }5859 /∗∗60 ∗ C o n s t r u c t s an i n s t a n c e o f P r i o r i t y V i e w , w i t h t h e t a s k o f c r e a t i n g a

command61 ∗/62 public Prior i tyView ( ) {63 bu i l tP r i o r i t yPane l ( ) ;64 }6566 /∗∗67 ∗ B u i l d s t h e p a n e l68 ∗/69 private void bu i l tP r i o r i t yPane l ( ) {70 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;71 GridBagConstraints c = new GridBagConstraints ( ) ;72 c . i n s e t s = new I n s e t s (1 , 1 , 1 , 1 ) ;7374 // T i t l e d B o r d e r t i t l e = B o r d e r F a c t o r y . c r e a t e T i t l e d B o r d e r ( B o r d e r F a c t o r y .

c r e a t e E t c h e d B o r d e r ( E t c h e d B o r d e r .LOWERED) ,75 // ” P r i o r i t y ” , T i t l e d B o r d e r . LEFT , T i t l e d B o r d e r . CENTER ,

new Fon t ( ” Tahoma ” , Fon t . BOLD , 1 1 ) ) ;76 // p a n e l . s e t B o r d e r ( B o r d e r F a c t o r y . c r e a t e T i t l e d B o r d e r ( t i t l e ) ) ;7778 normalPr ior i tyRadio = new JRadioButton ( ”Normal” ) ;79 h ighPr ior i tyRad io = new JRadioButton ( ”High” ) ;80

Page 147: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 137

81 normalPr ior i tyRadio . s e t S e l e c t ed ( true ) ;8283 ButtonGroup buttonGroup = new ButtonGroup ( ) ;84 buttonGroup . add ( normalPr ior i tyRadio ) ;85 buttonGroup . add ( h ighPr ior i tyRad io ) ;8687 c . gr idx = 0 ;88 c . gr idy = 0 ;89 panel . add (new JLabel ( ” Set the p r i o r i t y l e v e l : ” ) , c ) ;90 c . gr idx = 1 ;91 panel . add ( normalPrior ityRadio , c ) ;92 c . gr idx = 2 ;93 panel . add ( highPr ior i tyRadio , c ) ;94959697 this . add ( panel ) ;98 }99

100101 /∗∗102 ∗ S e t s t h e r a d i o b u t t o n s f o r t h i s p a n e l , d e p e n d i n g on t h e t a s k103 ∗/104 private void s e tP r ed e f i n edPr i o r i t y ( ) {105106 HashMap<Long , CommandBlock> commandBlocks ;107 try {108 commandBlocks = Cl i ent . ge t In s tance ( ) . ge tMin ima l Inte r face ( ) .

getCommandBlocks ( null ) ;109 CommandBlock block = commandBlocks . get ( commandToEdit .

getBlockID ( ) ) ;110 i f ( block . g e t P r i o r i t y ( )==CommandBlock .NORMAL PRIORITY)

normalPr ior i tyRadio . s e t S e l e c t ed ( true ) ;111 else i f ( block . g e t P r i o r i t y ( )==CommandBlock .URGENT PRIORITY)

h ighPr ior i tyRadio . s e t S e l e c t ed ( true ) ;112 } catch ( RemoteException e ) {113 JOptionPane . showMessageDialog ( this , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;114 e . pr intStackTrace ( ) ;115 } catch ( NotBoundException e ) {116 JOptionPane . showMessageDialog ( this , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;117 e . pr intStackTrace ( ) ;118 }119120 }121122 /∗∗123 ∗ @r e t u r n n o r m a l P r i o r i t y R a d i o124 ∗/125 public JRadioButton getNormalPrior ityRadio ( ) {126 return normalPr ior i tyRadio ;127 }128129130 /∗∗131 ∗ @r e t u r n h i g h P r i o r i t y R a d i o132 ∗/133 public JRadioButton getHighPr ior i tyRadio ( ) {134 return highPr ior i tyRad io ;135 }136137 }

Page 148: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

138 Appendix C - Source Code

.1.24 SelectCommandPanelController.java

1 package mps . gui . commanding ;23 import javax . swing . event . L i s tSe l e c t i onEvent ;4 import javax . swing . event . L i s t S e l e c t i o n L i s t e n e r ;56 /∗∗7 ∗ C o n t r o l l e r f o r t h e command p a n e l8 ∗ <br><br>9 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3

10 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 111 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 812 ∗/13 public c lass SelectCommandPanelController implements L i s t S e l e c t i o n L i s t e n e r {1415 /∗∗16 ∗ The t a b l e t o b e c o n t r o l l e d b y t h i s c l a s s17 ∗/18 private SelectCommandPanelView view ;1920 /∗∗21 ∗ C o n s t r u c t s an i n s t a n c e o f S e l e c t C o m m a n d P a n e l C o n t r o l l e r w i t h t h e g i v e n

v i e w22 ∗ @param s e l e c tC ommandPan e lV i ew The command p a n e l t o b e l i s t e n e d t o23 ∗/24 public SelectCommandPanelController ( SelectCommandPanelView

selectCommandPanelView ) {25 view = selectCommandPanelView ;26 }2728 @Override29 public void valueChanged ( L i s tSe l e c t i onEvent l s e ) {3031 int selectedRow = view . getTable ( ) . getSelectedRow () ;3233 view . updateLowerPanel ( selectedRow ) ;343536 }3738 }

Page 149: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 139

.1.25 SelectCommandPanelView.java

1 package mps . gui . commanding ;23 import java . awt . Dimension ;4 import java . awt . FlowLayout ;5 import java . awt . Font ;6 import java . awt . GridBagConstraints ;7 import java . awt . GridBagLayout ;8 import java . awt . I n s e t s ;9 import java . u t i l . ArrayList ;

1011 import javax . swing . BorderFactory ;12 import javax . swing . JComboBox ;13 import javax . swing . JLabel ;14 import javax . swing . JPanel ;15 import javax . swing . JScro l lPane ;16 import javax . swing . JTable ;17 import javax . swing . JTextField ;18 import javax . swing . L i s tSe l e c t i onMode l ;19 import javax . swing . RowFilter ;20 import javax . swing . SpinnerNumberModel ;21 import javax . swing . border . EtchedBorder ;22 import javax . swing . border . Tit ledBorder ;23 import javax . swing . event . DocumentEvent ;24 import javax . swing . event . DocumentListener ;25 import javax . swing . tab l e . TableRowSorter ;2627 import common . command .Command;28 import common . command .CommandType ;29 import common . command . DTUsat2Command ;30 import common . command . DTUsat2CommandTypeMap ;31 import common . command . ModuleID ;32 import common . command . parameter . BooleanParameter ;33 import common . command . parameter . DoubleParameter ;34 import common . command . parameter . IntParameter ;35 import common . command . parameter . Parameter ;36 import common . command . parameter . Str ingParameter ;3738 /∗∗39 ∗ The p a n e l f o r s e l e c t i n g commands i n t h e command t a b l e ,40 ∗ and g i v e i n t e r f a c e t o i n p u t command i n f o r m a t i o n b a s e d on t h e command s e l e c t e d41 ∗ <br><br>42 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 343 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 144 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 845 ∗/46 public c lass SelectCommandPanelView extends JPanel{4748 /∗∗49 ∗ The s e r i a l number o f t h e c l a s s50 ∗/51 private stat ic f ina l long se r ia lVers ionUID = 1L ;5253 /∗∗54 ∗ The command g i v e n i f t h e t a s k i s t o e d i t a command55 ∗/56 private Command commandToEdit ;5758 /∗∗59 ∗ The c o n t r o l l e r f o r t h i s p a n e l60 ∗/61 private SelectCommandPanelController c o n t r o l l e r ;62 /∗∗63 ∗ The t a b l e c o n t a i n i n g commands64 ∗/65 private JTable tab l e ;66 /∗∗67 ∗ The t e x t f i e l d f o r g i v i n g a f i l t e r t e x t t o s e a r c h commands68 ∗/69 private JTextField f i l t e r T e x t ;70 /∗∗71 ∗ The a b s t r a c t t a b l e mod e l f o r t h e t a b l e72 ∗/73 private CommandSetupAbstractTableModel commandSetupAbstractTableModel ;74 /∗∗75 ∗ The l a b e l d e s c r i b i n g t h e command76 ∗/77 private JLabel commandDesriptionLabel ;78 /∗∗79 ∗ The l a b e l d e s c r i b i n g t h e d e s t i n a t i o n o f t h e command80 ∗/81 private JLabel de s t ina t i onLabe l ;82 /∗∗83 ∗ The combo b o x f o r s e l e c t i n g t h e d e s t i n a t i o n f o r t h e command84 ∗/

Page 150: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

140 Appendix C - Source Code

85 private JComboBox destinationComboBox ;86 /∗∗87 ∗ Te x t i f more t h a n one d e s t i n a t i o n can b e c h o s e n88 ∗/89 private Str ing de fau l tDest inat ionTxt = ”−−Se lec t−−” ;90 /∗∗91 ∗ The l a b e l f o r a r g um e n t s92 ∗/93 private JLabel argumentsLabel ;94 /∗∗95 ∗ Pan e l f o r p a r a m e t e r s96 ∗/97 private ParametersPanel parametersPanel ;98 /∗∗99 ∗ The row s o r t e r f o r t h e t a b l e

100 ∗/101 private TableRowSorter<CommandSetupAbstractTableModel> s o r t e r ;102103 /∗∗104 ∗ C o n s t r u c t s an i n s t a n c e o f S e l e c tCommandPane lV i ew , w i t h t h e t a s k o f c r e a t i n g a

t a s k105 ∗/106 public SelectCommandPanelView ( ) {107 c o n t r o l l e r = new SelectCommandPanelController ( this ) ;108109 parametersPanel = new ParametersPanel ( ) ;110 buildSelectCommandPanel ( ) ;111 }112113 /∗∗114 ∗ C o n s t r u c t s an i n s t a n c e o f S e l e c tCommandPane lV i ew , w i t h t h e t a s k o f

e d i t i n g a command115 ∗ @param commandToEdi t116 ∗/117 public SelectCommandPanelView (Command commandToEdit ) {118 this . commandToEdit = commandToEdit ;119 c o n t r o l l e r = new SelectCommandPanelController ( this ) ;120121 parametersPanel = new ParametersPanel ( commandToEdit ) ;122 buildSelectCommandPanel ( ) ;123124 setPredefinedCommandSelection ( ) ;125 s e tPrede f i n edDes t ina t i on ( ) ;126127 }128129130 /∗∗131 ∗ B u i l d s t h e s e l e c t i o n p a n e l132 ∗/133 private void buildSelectCommandPanel ( ) {134 JPanel panel = new JPanel ( ) ;135 Tit ledBorder t i t l e = BorderFactory . c r ea teTi t l edBorder ( BorderFactory .

createEtchedBorder ( EtchedBorder .LOWERED) ,136 ” Se l e c t command” , Tit ledBorder .LEFT, Tit ledBorder .

CENTER ,new Font ( ”Tahoma” , Font .BOLD,11 ) ) ;137 panel . setBorder ( t i t l e ) ;138 panel . setLayout (new GridBagLayout ( ) ) ;139 GridBagConstraints c = new GridBagConstraints ( ) ;140141 c . gr idx = 0 ;142 c . gr idy = 0 ;143 c . i n s e t s = new I n s e t s (1 , 1 , 1 , 1 ) ;144145 c . anchor = GridBagConstraints . FIRST LINE END ;146 panel . add ( bu i l dF i l t e rPane l ( ) , c ) ;147148 c . anchor = GridBagConstraints .LINE START;149 c . gr idx = 0 ;150 c . gr idy = 1 ;151 panel . add ( buildCommandTablePanel ( ) , c ) ;152153 c . gr idx = 0 ;154 c . gr idy = 2 ;155 c . f i l l = GridBagConstraints .HORIZONTAL;156 panel . add ( buildLowerPanel ( ) , c ) ;157158 this . add ( panel ) ;159 }160161162 /∗∗163 ∗ B u i l d s t h e f i l t e r p a n e l164 ∗ @r e t u r n The p a n e l f o r t h e f i l t e r t e x t165 ∗/166 private JPanel bu i l dF i l t e rPane l ( ) {167 JPanel panel = new JPanel ( ) ;

Page 151: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 141

168169 panel . setLayout (new FlowLayout ( ( FlowLayout .TRAILING) ) ) ;170171 JLabel l 1 = new JLabel ( ” F i l t e r Text : ” ) ;172 l 1 . setFont (new Font ( ” Ar ia l ” , Font .BOLD, 9 ) ) ;173 l 1 . s e t P r e f e r r e d S i z e (new Dimension (65 ,25) ) ;174175 panel . add ( l 1 ) ;176177 f i l t e r T e x t = new JTextField ( ) ;178 f i l t e r T e x t . getDocument ( ) . addDocumentListener (179 new DocumentListener ( ) {180 public void changedUpdate ( DocumentEvent e ) {181 newFi l ter ( ) ;182 }183 public void insertUpdate ( DocumentEvent e ) {184 newFi l ter ( ) ;185 }186 public void removeUpdate ( DocumentEvent e ) {187 newFi l ter ( ) ;188 }189 }) ;190 f i l t e r T e x t . s e t P r e f e r r e d S i z e (new Dimension (100 ,20) ) ;191 f i l t e r T e x t . setFont (new Font ( ” Ar ia l ” , Font .PLAIN, 9 ) ) ;192 l 1 . setLabelFor ( f i l t e r T e x t ) ;193194 panel . add ( f i l t e r T e x t ) ;195196197 return panel ;198 }199200 /∗∗201 ∗ B u i l d s t h e command t a b l e202 ∗ @r e t u r n The p a n e l w i t h t h e command t a b l e203 ∗/204 private JPanel buildCommandTablePanel ( ) {205206 JPanel panel = new JPanel ( ) ;207208 commandSetupAbstractTableModel = new CommandSetupAbstractTableModel

( ) ;209 s o r t e r = new TableRowSorter<CommandSetupAbstractTableModel>(

commandSetupAbstractTableModel ) ;210 tab l e = new JTable ( commandSetupAbstractTableModel ) ;211 tab l e . setRowSorter ( s o r t e r ) ;212 tab l e . s e tP r e f e r r edSc r o l l ab l eV i ewpo r tS i z e (new Dimension (400 , 100) ) ;213 tab l e . s e tF i l l sV i ewpor tHe ight ( true ) ;214215 // D i s a b l e a u t o r e s i z i n g216 tab l e . setAutoResizeMode ( JTable .AUTO RESIZE OFF) ;217218 tab l e . getColumnModel ( ) . getColumn ( CommandSetupAbstractTableModel .TYPE COLUMN)

. setPreferredWidth (35) ;219 tab l e . getColumnModel ( ) . getColumn ( CommandSetupAbstractTableModel .NAME COLUMN)

. setPreferredWidth (200) ;220 tab l e . getColumnModel ( ) . getColumn ( CommandSetupAbstractTableModel .BYTES COLUMN

) . setPreferredWidth (40) ;221 tab l e . getColumnModel ( ) . getColumn ( CommandSetupAbstractTableModel .

SUBSYSTEM COLUMN) . setPreferredWidth (120) ;222223224 tab l e . setSe lect ionMode ( L i s tSe l e c t i onMode l . SINGLE SELECTION) ;225226227 JScro l lPane s c ro l lPane = new JScro l lPane ( tab l e ) ;228229 panel . add ( s c ro l lPane ) ;230231 tab l e . getSe l ect ionMode l ( ) . addL i s t S e l e c t i onL i s t en e r ( c o n t r o l l e r ) ;232233 return panel ;234 }235236 /∗∗237 ∗ B u i l d s a l l l o w e r p a n e l s i n t h e s e l e c t i o n v i e w238 ∗ @r e t u r n A s c r o l l p ane r e p r e s e n t i n g t h e l o w e r p a n e l s o f t h e v i e w239 ∗/240 private JScro l lPane buildLowerPanel ( ) {241242 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;243 GridBagConstraints c = new GridBagConstraints ( ) ;244245 c . gr idx = 0 ;246 c . gr idy = 0 ;247 c . gr idwidth = 1 ;248 c . anchor = GridBagConstraints .LINE START;

Page 152: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

142 Appendix C - Source Code

249 commandDesriptionLabel = new JLabel ( ) ;250 panel . add ( commandDesriptionLabel , c ) ;251252 JPanel de s t ina t i onPane l = bui ldDest inat ionPane l ( ) ;253 c . gr idx = 1 ;254 c . gr idy = 0 ;255 panel . add ( dest inat ionPane l , c ) ;256257 c . gr idx = 0 ;258 c . gr idy = 1 ;259 c . gr idwidth = 2 ;260 c . anchor = GridBagConstraints .LINE START;261 argumentsLabel = new JLabel ( ) ;262 panel . add ( argumentsLabel , c ) ;263264 c . gr idy = 2 ;265 c . gr idx = 0 ;266 panel . add ( parametersPanel , c ) ;267268269 JPanel dummyPanel = new JPanel (new FlowLayout ( FlowLayout .LEADING) ) ;270 dummyPanel . add ( panel ) ;271272 JScro l lPane s c ro l lPane = new JScro l lPane (dummyPanel ) ;273 s c ro l lPane . s e t P r e f e r r e d S i z e (new Dimension (400 , 250) ) ;274275 updateLowerPanel ( tab l e . getSelectedRow () ) ;276277278279 return s c ro l lPane ;280 }281282 /∗∗283 ∗ B u i l d s t h e p a n e l f o r c h o o s i n g t h e d e s t i n a t i o n o f t h e command284 ∗ @r e t u r n The p a n e l f o r c h o o s i n g t h e d e s t i n a t i o n o f t h e command285 ∗/286 private JPanel bu i ldDest inat ionPane l ( ) {287 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;288 GridBagConstraints c = new GridBagConstraints ( ) ;289 c . anchor = GridBagConstraints .LINE START;290 c . gr idx = 0 ;291 c . gr idy = 0 ;292 de s t ina t i onLabe l = new JLabel ( ) ;293 panel . add ( des t inat ionLabe l , c ) ;294295 c . gr idx = 0 ;296 c . gr idy = 1 ;297 destinationComboBox = new JComboBox ( ) ;298 destinationComboBox . s e t P r e f e r r e d S i z e (new Dimension (85 ,20) ) ;299 panel . add ( destinationComboBox , c ) ;300301 return panel ;302 }303304 /∗∗305 ∗ S e t s t h e command f o r e d i t i n g i f one i s g i v e n and s e l e c t s i t i n t h e t a b l e306 ∗/307 private void setPredef inedCommandSelection ( ) {308309 // F ind command t o s e l e c t310 for ( int i =0; i<=tab l e . getRowCount ( )−1; i++) {311 int commandType = ((DTUsat2Command)commandToEdit ) .

getCommandTypeID ( ) ;312 int columnType = Intege r . pa r s e In t ( tab l e . getValueAt ( i ,

CommandSetupAbstractTableModel .TYPE COLUMN) . toSt r ing ( ) );

313 i f ( commandType == columnType ) {314 tab l e . s e tRowSe l e c t i on In t e rva l ( i , i ) ;315 }316 }317318 }319320 /∗∗321 ∗ S e t s t h e d e s t i n a t i o n o f t h e command t o e d i t t o t h e one t h a t i t had

a l r e a d y322 ∗/323 private void s e tPrede f i n edDes t ina t i on ( ) {324325 // s e l e c t p r e v i o u s d e s t i n a t i o n326 St r ing dest =((DTUsat2Command)commandToEdit ) . g e tDes t ina t i on ( ) . name ( )

;327 destinationComboBox . s e tSe l e c t ed I t em ( dest ) ;328 }329330 /∗∗

Page 153: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 143

331 ∗ Up d a t e s t h e l o w e r p a n e l s , a s t h e y c h a n g e a c c o r d i n g t o wha t command i ss e l e c t e d

332 ∗ @param s e l e c t e d R o w The row number o f t h e command s e l e c t e d333 ∗/334 public void updateLowerPanel ( int selectedRow ) {335336 i f ( selectedRow==−1) {337 commandDesriptionLabel . setText ( ”” ) ;338 argumentsLabel . setText ( ”” ) ;339 de s t ina t i onLabe l . setText ( ”” ) ;340 destinationComboBox . s e t V i s i b l e ( f a l s e ) ;341 } else {342 setCommandDescriptionLabel ( selectedRow ) ;343 argumentsLabel . setText ( ”<html><b>Arguments:</b></html>” ) ;344 de s t ina t i onLabe l . setText ( ”<html><b>ModuleID : </b></html>” ) ;345 setPoss ib leDest inat ionCombo ( selectedRow ) ;346 }347 repaintParametersPanel ( selectedRow ) ;348349 }350351 /∗∗352 ∗ S e t s t h e d e s c r i p t i o n o f t h e command s e l e c t e d353 ∗ @param s e l e c t e d R o w The row o f t h e s e l e c t e d command354 ∗/355 private void setCommandDescriptionLabel ( int selectedRow ) {356357 St r ing txt = ”” ;358359 i f ( selectedRow !=−1) {360 int commandType = ( In t ege r ) tab l e . getValueAt ( selectedRow ,

CommandSetupAbstractTableModel .TYPE COLUMN) ;361 txt += ”<html><b>Command desc r ip t i on </b><br> <tab l e width

=290><tr><td>” +362 DTUsat2CommandTypeMap . ge t In s tance ( ) . getCommandType(

commandType) . g e tDesc r ip t i on ( ) +363 ”</td></tr ></table ></html>” ;364 }365366 commandDesriptionLabel . setText ( txt ) ;367 commandDesriptionLabel . r epa in t ( ) ;368 }369370371 /∗∗372 ∗ S e t s t h e combo b o x s o t h a t i t m a t c h e s t h e command s e l e c t e d i n t h e t a b l e373 ∗ @param s e l e c t e d R o w The row number o f t h e s e l e c t e d command374 ∗/375 private void setPoss ib leDest inat ionCombo ( int selectedRow ) {376377 destinationComboBox . removeAllItems ( ) ;378 i f ( selectedRow !=−1) {379 // a row i s s e l e c t e d380 int commandType = ( In t ege r ) tab l e . getValueAt ( selectedRow ,

CommandSetupAbstractTableModel .TYPE COLUMN) ;381 CommandType c = DTUsat2CommandTypeMap . ge t In s tance ( ) .

getCommandType(commandType) ;382383 i f ( c . g e tLega lDes t ina t i ons ( ) . s i z e ( )==1) {384 // o n l y one l e g a l d e s t i n a t i o n e x i s t s385 destinationComboBox . addItem ( c . g e tLega lDes t ina t i ons ( )

. get (0) ) ;386 } else i f ( c . g e tLega lDes t ina t i ons ( ) . s i z e ( ) > 1) {387 // more t h a n one l e g a l d e s t i n a t i o n388 destinationComboBox . addItem ( de fau l tDes t inat ionTxt ) ;389 for ( ModuleID d : c . g e tLega lDes t ina t i ons ( ) ) {390 destinationComboBox . addItem (d . name ( ) ) ;391 }392 }393394 destinationComboBox . s e t V i s i b l e ( true ) ;395 } else {396 // no row i s s e l e c t e d397 destinationComboBox . s e t V i s i b l e ( f a l s e ) ;398 }399 }400401 /∗∗402 ∗ R e p a i n t s t h e p a r a m e t e r s p a n e l when c h a n g e s h a p p en403 ∗ @param s e l e c t e d R o w404 ∗/405 private void repaintParametersPanel ( int selectedRow ) {406407 i f ( selectedRow == −1) {408 parametersPanel . setCommandTypeNo( null ) ;409 } else {

Page 154: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

144 Appendix C - Source Code

410 int no = ( In t ege r ) tab l e . getValueAt ( selectedRow ,CommandSetupAbstractTableModel .TYPE COLUMN) ;

411 CommandType commandType = DTUsat2CommandTypeMap . ge t In s tance( ) . getCommandType( no ) ;

412 parametersPanel . setCommandTypeNo(commandType) ;413 }414 parametersPanel . bui ldPanel ( ) ;415 this . r epa in t ( ) ;416417 }418419420 /∗∗421 ∗ Upda t e t h e row f i l t e r r e g u l a r e x p r e s s i o n f r om t h e e x p r e s s i o n i n422 ∗ t h e t e x t b o x .423 ∗/424 private void newFi l ter ( ) {425 RowFilter<CommandSetupAbstractTableModel , Object> r f = null ;426 // I f c u r r e n t e x p r e s s i o n d o e s n ’ t p a r s e , don ’ t u p d a t e .427 try {428 r f = RowFilter . r e g e x F i l t e r ( ” (? i ) ”+f i l t e r T e x t . getText ( ) ) ; // ( ? i )

g i v e s c a s e i n s e n s i t i v e m a t c h i n g429 } catch ( java . u t i l . regex . PatternSyntaxException e ) {430 return ;431 }432 s o r t e r . setRowFi l ter ( r f ) ;433 }434435436 /∗∗437 ∗ G e n e r a t e s t h e i n f o r m a t i o n o f t h e command s e l e c t e d438 ∗ @r e t u r n S t r i n g c o n t a i n i n g command i n f o r m a t i o n439 ∗/440 public Str ing generateCommandInfo ( ) {441 int selectedRowNo = tab l e . getSelectedRow () ;442 // FIND COMMAND TYPE443 int selectedCommandNo = Intege r . pa r s e In t ( (

commandSetupAbstractTableModel . getValueAt ( selectedRowNo ,CommandSetupAbstractTableModel .TYPE COLUMN) . toSt r ing ( ) ) ) ;

444445 // FIND ARGUMENTS446 ArrayList<Object> argumentsChooser = parametersPanel .

getArgumentsChooser ( ) ;447448 CommandType commandType = DTUsat2CommandTypeMap . ge t In s tance ( ) .

getCommandType( selectedCommandNo ) ;449450 ArrayList<Parameter> parameters = commandType . getParameters ( ) ;451 ArrayList<Str ing> arguments = new ArrayList<Str ing >() ;452 for ( int i =0; i<= parameters . s i z e ( )−1; i++) {453454 Parameter p = parameters . get ( i ) ;455 St r ing paramValue = ”” ;456457 i f (p . getParameterType ( ) instanceof IntParameter ) {458 SpinnerNumberModel snm = ( SpinnerNumberModel )

argumentsChooser . get ( i ) ;459 paramValue = snm . getValue ( ) . t oS t r ing ( ) ;460 } else i f (p . getParameterType ( ) instanceof DoubleParameter ) {461 SpinnerNumberModel snm = ( SpinnerNumberModel )

argumentsChooser . get ( i ) ;462 paramValue = snm . getValue ( ) . t oS t r ing ( ) ;463 } else i f (p . getParameterType ( ) instanceof BooleanParameter )

{464 JComboBox combo = (JComboBox) argumentsChooser . get ( i

) ;465 i f ( combo . getSe l ec tedI tem () . t oSt r ing ( ) .

equa l s IgnoreCase ( ” true ” ) ) {466 paramValue = ””+1;467 } else i f ( combo . getSe l ec tedI tem () . t oSt r ing ( ) .

equa l s IgnoreCase ( ” f a l s e ” ) ) {468 paramValue = ””+0;469 }470471 } else i f (p . getParameterType ( ) instanceof StringParameter ) {472 JTextField t ex tF i e l d = ( JTextField ) argumentsChooser

. get ( i ) ;473 paramValue = tex tF i e l d . getText ( ) ;474 } else {475 // TODO: FEJL476 }477 arguments . add ( paramValue ) ;478 }479480 St r ing dest = destinationComboBox . getSe l ec tedI tem () . t oSt r ing ( ) ;481 St r ing commandData = selectedCommandNo + ”−” + dest ;482 for ( St r ing s : arguments ) {

Page 155: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 145

483 commandData += ”−” + s ;484 }485486 return commandData ;487 }488489490491 /∗∗492 ∗ @r e t u r n t a b l e493 ∗/494 public JTable getTable ( ) {495 return tab l e ;496 }497498499 /∗∗500 ∗ @r e t u r n d e f a u l t D e s t i n a t i o n T x t501 ∗/502 public Str ing getDefau l tDest inat ionTxt ( ) {503 return de fau l tDes t inat ionTxt ;504 }505506 /∗∗507 ∗ @r e t u r n d e s t i n a t i o n C o m b o B o x508 ∗/509 public JComboBox getDestinationComboBox ( ) {510 return destinationComboBox ;511 }512513514 }

Page 156: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

146 Appendix C - Source Code

.1.26 SingleCommandSetupController.java

1 package mps . gui . commanding ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;7 import java . u t i l . ArrayList ;89 import javax . swing . JOptionPane ;

1011 import mcc . s e rv e r . dataProcess ing . CommandBlock ;12 import mcc . s e rv e r . dataProcess ing . T i m e l i n e U t i l i t i e s ;13 import mps . gui . t ime l i n e . TimeLineModel ;14 import mps . rmi . C l i ent ;1516 import common . command .Command;17 import common . command . DTUsat2CommandFactory ;18 import common . except ions . I l l ega lParamete rExcept ion ;19 import common . except ions . UnknownCommandTypeException ;20212223 /∗∗24 ∗ A c o n t r o l l e r f o r t h e S i n g l eCommandS e t u pV i ew25 ∗ <br><br>26 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 327 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 128 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 829 ∗/30 public c lass SingleCommandSetupController implements Act ionL i s t ener {3132 private SingleCommandSetupView view ;3334 private DTUsat2CommandFactory t c f = new DTUsat2CommandFactory ( ) ;3536 public SingleCommandSetupController ( SingleCommandSetupView view ) {3738 this . view = view ;3940 }414243 @Override44 public void act ionPerformed ( ActionEvent ae ) {4546 i f ( ae . getSource ( ) . equa l s ( view . getCommandSetupView ( ) .

getCreateAndSendCommandButton ( ) ) ) {4748 try {4950 i f ( view . getCommandToEdit ( )==null ) {51 createNewClicked ( ) ;52 } else {53 editCommandClicked ( ) ;54 }55 // Upda t e g r a p h i c s56 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;5758 view . getTimeLineView ( ) . newFi l te r ( ) ;59 // D i s p o s e w indow60 view . d i spose ( ) ;6162 } catch ( RemoteException e ) {63 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;64 e . pr intStackTrace ( ) ;65 } catch ( NotBoundException e ) {66 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;67 e . pr intStackTrace ( ) ;68 } catch (UnknownCommandTypeException e ) {69 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;70 e . pr intStackTrace ( ) ;71 } catch ( I l l ega lParamete rExcept ion e ) {72 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;73 e . pr intStackTrace ( ) ;74 }757677 } else i f ( ae . getSource ( ) . equa l s ( view . getCommandSetupView ( ) .

getCancelButton ( ) ) ) {78

Page 157: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 147

79 // CANCEL BUTTON CLICKED8081 view . d i spose ( ) ;82 }8384 }8586 /∗∗87 ∗ C r e a t e s t h e command w i t h t h e u s e r g i v e n i n p u t88 ∗ @th r ow s UnknownCommandTypeExcep t i on89 ∗ @th r ow s R emo t e E x c e p t i o n90 ∗ @th r ow s N o tB o u n dE x c e p t i o n91 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n92 ∗/93 private void createNewClicked ( ) throws UnknownCommandTypeException ,

RemoteException , NotBoundException , I l l ega lParamete rExcept ion {94 // NEW Command r e a d y t o b e s e n d9596 Command command = null ;9798 command = t c f . generateCommand ( view . getCommandSetupView ( ) .

getSelectCommandPanelView ( ) . generateCommandInfo ( ) ) ;99

100 // S e t t im e o f e x e c u t i o n101 i f ( view . getCommandSetupView ( ) . getExecutionTimePanel ( ) .

getAsapCheckBox ( ) . i s S e l e c t e d ( ) ) {102 // S e t e x e c u t i o n t im e t o −1 = ASAP103 command . setTimeOfExecution (−1) ;104 } else {105 long executionEpoch = view . getCommandSetupView ( ) .

getExecutionTimePanel ( ) . getTOEFromSpinners ( ) ;106 command . setTimeOfExecution ( executionEpoch ) ;107 }108109 int p r i o r i t y = view . getCommandSetupView ( ) . g e tPr i o r i t yPane l ( ) .

getNormalPrior ityRadio ( ) . i s S e l e c t e d ( ) ? CommandBlock .NORMAL PRIORITY : CommandBlock .URGENT PRIORITY;

110111 ArrayList<Command> commands = new ArrayList<Command>() ;112 commands . add (command) ;113 Cl i ent . g e t In s tance ( ) . getMediumInterface ( ) . addBlock (commands , p r i o r i t y

) ;114115116 // S e t p a s s i f Manua l p a s s a s s i g n m e n t117 i f ( ! view . getCommandSetupView ( ) . getPassPanel ( ) .

getAutomaticPassCheckBox ( ) . i s S e l e c t e d ( ) ) {118 /∗119 ∗ Sma l l h a c k c r e a t e d t o a l l o w u s e r t o s e t s p e c i f i c p a s s a t

c r e a t i n g o f command .120 ∗ Pa s s a s s i g n m e n t n e e d s t o b e done t h r o u g h t h e

modi fyCommand RMI c a l l , s o r i g h t a f t e r121 ∗ t h e c r e a t i o n o f t h e command , t h e DB i s c h e c k e d f o r t h e

h i g h e s t e x i s t i n g command ID − t h i s122 ∗ s h o u l d b e t h e command we j u s t c r e a t e d .123 ∗124 ∗/125126 long highestCommandID = getLatestAddedCommandID ( ) ;127128 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand(

highestCommandID , true ) ;129 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand(

highestCommandID , T i m e l i n e U t i l i t i e s . PASSID , view .getCommandSetupView ( ) . getPassPanel ( ) .getSelectedUserGivenPassID ( ) ) ;

130 }131132133 i f ( view . getCommandSetupView ( ) . getBlockPanel ( ) .

getExistingBlockCheckBox ( ) . i s S e l e c t e d ( ) ) {134 // HACK a l s o n e e d e d t o p u t i n e x i s t i n g b l o c k a t c r e a t i o n135 // The command w i l l b e c r e a t e d i n i t s own b l o c k and t h e n

i m m e d i a t e l y moved t o t h e s p e c i f i e d .136137 long highestCommandID = getLatestAddedCommandID ( ) ;138 long newBlockID = ( Long ) view . getCommandSetupView ( ) .

getBlockPanel ( ) . getBlocksCombo ( ) . ge tSe l ec tedI tem () ;139 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand(

highestCommandID , T i m e l i n e U t i l i t i e s .BLOCKID, newBlockID) ;

140141 }142143144145

Page 158: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

148 Appendix C - Source Code

146 view . getTimeLineView ( ) . setScheduleRecommendation ( true ) ;147148149 }150151 /∗∗152 ∗ Hack me t hod t o f i n d t h e l a t e s a d d e d command t o t h e d a t a b a s e153 ∗ @r e t u r n154 ∗ @th r ow s R emo t e E x c e p t i o n155 ∗ @th r ow s N o tB o u n dE x c e p t i o n156 ∗/157 private long getLatestAddedCommandID ( ) throws RemoteException ,

NotBoundException {158159 ArrayList<Command> allCommands= Cl i ent . ge t In s tance ( ) .

ge tMin ima l Inte r face ( ) . getCommands ( null ) ;160161 long highestCommandID = 0 ; // l a s t a d d e d command t o t h e d a t a b a s e162 for (Command c : allCommands ) {163 i f ( c . getCommandID ()> highestCommandID ) {164 highestCommandID = c . getCommandID () ;165 }166 }167168 return highestCommandID ;169170 }171172 /∗∗173 ∗ E d i t s t h e command e d i t e d i n t h e v i e w174 ∗ @th r ow s R emo t e E x c e p t i o n175 ∗ @th r ow s N o tB o u n dE x c e p t i o n176 ∗/177 private void editCommandClicked ( ) throws RemoteException , NotBoundException

{178 // EDIT EXISTING COMMAND179180181 St r ing commandData = view . getCommandSetupView ( ) .

getSelectCommandPanelView ( ) . generateCommandInfo ( ) ;182 boolean changes = f a l s e ;183184 i f ( ! view . getCommandToEdit ( ) . getParameters ( ) . equa l s (commandData) ) {185 // PARAMETERS186187 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , commandData) ;188 changes = true ;189 }190191 // PASS192 i f ( view . getCommandSetupView ( ) . getPassPanel ( ) .

getAutomaticPassCheckBox ( ) . i s S e l e c t e d ( ) && view .getCommandToEdit ( ) . getUserGivenPass ( ) ) {

193 // Was s c h e d u l e d b y u s e r and s h o u l d NOW be au t o−s c h e d u l e d194 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , f a l s e ) ;195 changes = true ;196197 } else i f ( ! view . getCommandToEdit ( ) . getUserGivenPass ( ) && ! view .

getCommandSetupView ( ) . getPassPanel ( ) . getAutomaticPassCheckBox ( ). i s S e l e c t e d ( ) ) {

198 // Was au t o−s c h e d u l e d and s h o u l d now g e t UGP199 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , true ) ;200 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , T i m e l i n e U t i l i t i e s .PASSID , view . getCommandSetupView ( ) . getPassPanel ( ) .getSelectedUserGivenPassID ( ) ) ;

201 changes = true ;202203 } else i f ( ! view . getCommandSetupView ( ) . getPassPanel ( ) .

getAutomaticPassCheckBox ( ) . i s S e l e c t e d ( ) && view .getCommandSetupView ( ) . getPassPanel ( ) . getSelectedUserGivenPassID( ) !=view . getCommandToEdit ( ) . getPassID ( ) ){

204 // O ld UGP d i f f e r e n t f r om new UGP205 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , T i m e l i n e U t i l i t i e s .PASSID , view . getCommandSetupView ( ) . getPassPanel ( ) .getSelectedUserGivenPassID ( ) ) ;

206 changes = true ;207 }208209 // TOE210 long executionEpoch = view . getCommandSetupView ( ) .

getExecutionTimePanel ( ) . getTOEFromSpinners ( ) ;211

Page 159: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 149

212 i f ( view . getCommandToEdit ( ) . getTimeOfExecution ( ) !=−1 && view .getCommandSetupView ( ) . getExecutionTimePanel ( ) . getAsapCheckBox ( ). i s S e l e c t e d ( ) ) {

213 // Had s p e c i f i c TOE b u t s h o u l d now b e a s a p214 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , T i m e l i n e U t i l i t i e s .TOE, −1) ;

215 changes = true ;216 } else i f ( view . getCommandToEdit ( ) . getTimeOfExecution ( )==−1 && ! view

. getCommandSetupView ( ) . getExecutionTimePanel ( ) . getAsapCheckBox( ) . i s S e l e c t e d ( ) ) {

217 // Was a s a p and s h o u l d now h a v e s p e c i f i c TOE218 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , T i m e l i n e U t i l i t i e s .TOE, executionEpoch ) ;

219 changes = true ;220 } else i f ( ! view . getCommandSetupView ( ) . getExecutionTimePanel ( ) .

getAsapCheckBox ( ) . i s S e l e c t e d ( ) && view . getCommandToEdit ( ) .getTimeOfExecution ( ) != executionEpoch ) {

221 // O ld TOE d i f f e r e n t f r om new TOE222 Cl i ent . ge t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyCommand( view .

getCommandToEdit ( ) . getCommandID () , T i m e l i n e U t i l i t i e s .TOE, executionEpoch ) ;

223 changes = true ;224 }225226227 long blockID = view . getCommandToEdit ( ) . getBlockID ( ) ;228 // PRIORITY229 i f ( view . getCommandSetupView ( ) . g e tPr i o r i t yPane l ( ) !=null ) {230 // I f P r i o r i t y p a n e l e x i s t s ( i t o n l y d o e s s o i f e d i t i n g a command

wh i c h i s p a r t o f a b l o c k w i t h s i z e >1)231232 CommandBlock block = TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . lookupCommandBlock ( blockID ) ;233234 i f ( ( block . g e t P r i o r i t y ( )==CommandBlock .URGENT PRIORITY) &&

view . getCommandSetupView ( ) . g e tPr i o r i t yPane l ( ) .getNormalPrior ityRadio ( ) . i s S e l e c t e d ( ) ) {

235 // was u r g e n t and s h o u l d b e n o rma l236 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyBlock (

blockID , CommandBlock .NORMAL PRIORITY) ;237 changes = true ;238 } else i f ( ( block . g e t P r i o r i t y ( )==CommandBlock .

NORMAL PRIORITY) && view . getCommandSetupView ( ) .g e tPr i o r i t yPane l ( ) . getHighPr ior i tyRadio ( ) . i s S e l e c t e d ( ) ){

239 // was no rma l and s h o u l d b e u r g e n t240 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyBlock (

blockID , CommandBlock .URGENT PRIORITY) ;241 changes = true ;242 }243 }244245246247 // BLOCK248 i f ( view . getCommandSetupView ( ) . getBlockPanel ( ) .

getExistingBlockCheckBox ( ) . i s S e l e c t e d ( ) ) {249 long newBlockID = ( Long ) view . getCommandSetupView ( ) .

getBlockPanel ( ) . getBlocksCombo ( ) . ge tSe l ec tedI tem () ;250 i f ( blockID != newBlockID ) {251 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

modifyCommand( view . getCommandToEdit ( ) .getCommandID () , T i m e l i n e U t i l i t i e s .BLOCKID,newBlockID ) ;

252 }253254 }255256257258 i f ( changes ) {259 view . getTimeLineView ( ) . setScheduleRecommendation ( true ) ;260 }261262263 }264265266 }

Page 160: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

150 Appendix C - Source Code

.1.27 SingleCommandSetupView.java

1 package mps . gui . commanding ;23 import java . awt . FlowLayout ;45 import javax . swing . JFrame ;67 import mps . gui . t ime l i n e . TimeLineModel ;8 import mps . gui . t ime l i n e . TimeLineView ;9

10 import common . command .Command;111213 /∗∗14 ∗ A f r ame t h a t c o n t a i n s t h e p a n e l s f o r c r e a t i n g and e d i t i n g commands15 ∗ <br><br>16 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 317 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 118 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 819 ∗/20 public c lass SingleCommandSetupView extends JFrame{212223 /∗∗24 ∗ The s e r i a l number f o r t h e c l a s s25 ∗/26 private stat ic f ina l long se r ia lVers ionUID = 1L ;27 /∗∗28 ∗ The t im e l i n e v i e w g i v e n t o t h i s f r ame29 ∗/30 private TimeLineView timeLineView ;31 /∗∗32 ∗ Command f o r e d i t i n g g i v e n t o t h i s f r ame i f t h e t a s k i s t o e d i t a command33 ∗/34 private Command commandToEdit ;35 /∗∗36 ∗ The p a n e l t h a t h a s a l l t h e p a n e l s f o r g i v i n g u s e r i n p u t f o r a command37 ∗/38 private CommandSetupView commandSetupView ;39 /∗∗40 ∗ S t r i n g f o r t h e l a b e l f o r t h e c r e a t i o n b u t t o n41 ∗/42 private Str ing createButtonLabel = ”<html><b>Create and send new command</b

></html>” ;4344 /∗∗45 ∗ C o n t r o l l e r o f t h i s v i e w46 ∗/47 private SingleCommandSetupController c o n t r o l l e r ;4849 /∗∗ B u i l d s a S i n g l eCommandS e t u pV i ew f o r C r e a t i o n o f a new command50 ∗ @param t im e L i n eV i e w51 ∗/52 public SingleCommandSetupView ( TimeLineView timeLineView ) {53 this . timeLineView = timeLineView ;5455 this . s e t T i t l e ( ” Create new command” ) ;5657 commandSetupView = new CommandSetupView( true , true , true , true ) ;58 commandSetupView . getCreateAndSendCommandButton ( ) . setText (

createButtonLabel ) ;5960 bu i ld ( ) ;61 }626364 /∗∗ B u i l d s a S i n g l eCommandS e t u pV i ew f r ame w i t h a l r e a d y s e t v a l u e s f r om <b>

commandToEdi t </b >.65 ∗ The v a l u e o f <b>copy </b> i n d i c a t e s e d i t i n g o r c o p y mode66 ∗ @param t im e L i n eV i e w67 ∗ @param commandToEdi t The command w h i c h s h o u l d b e e d i t e d68 ∗ @param co p y <br> I f t r u e : C r e a t i o n o f new command ( c o p y ) .69 ∗ <br> I f f a l s e : M o d i f i c a t i o n o f t h e e x i s t i n g

commandToEdi t70 ∗/71 public SingleCommandSetupView ( TimeLineView timeLineView , Command

commandToEdit , boolean copy ) {72 this . timeLineView = timeLineView ;7374 i f ( copy ) {75 // B u i l d w indow f o r c r e a t i o n o f New Command b a s e d on

commandToEdi t7677 this . s e t T i t l e ( ” Create new command” ) ;78

Page 161: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 151

79 // t h i s . commandToEdi t s h o u l d n o t b e s e t , b e c a u s e we a r ec r e a t i n g a new command

80 commandToEdit . setPassID (−1) ; // i f u s e r g i v e n p a s s was g i v e n, r emo v e s i t

81 commandToEdit . setTimeOfExecution ( TimeLineModel .getCurrentTimeInMi l l i s ( ) ) ; // makes s u r e s p i n n e r s s t a r t

a t c u r r e n t t im e82 commandSetupView = new CommandSetupView( true , true , true ,

true , commandToEdit ) ;83 commandSetupView . getCreateAndSendCommandButton ( ) . setText (

createButtonLabel ) ;8485 } else {86 // B u i l d w indow f o r e d i t i n g commandToEdi t8788 this . commandToEdit = commandToEdit ; // i n d i c a t e s e d i t i n g8990 boolean partOfBlock = ( TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . getCommandBlockMap ( ) . get (commandToEdit . getBlockID ( ) ) . s i z e ( ) > 1) ;

91 St r ing extraTxt = ”” ;92 i f ( partOfBlock ) extraTxt = ” − part o f block \”” +

commandToEdit . getBlockID ( ) + ”\”” ;93 this . s e t T i t l e ( ” Edit command \”” +commandToEdit . getCommandID

() +”\”” + extraTxt ) ;9495 commandSetupView = new CommandSetupView( true , ! partOfBlock ,

true , true , commandToEdit ) ;96 commandSetupView . getCreateAndSendCommandButton ( ) . setText ( ”<

html><b>Modify command!</b></html>” ) ;97 }9899

100 bu i ld ( ) ;101102 }103104 /∗∗105 ∗ B u i l d s t h e f r ame106 ∗/107 private void bui ld ( ) {108 TimeLineView . s e t I con ( this ) ;109 c o n t r o l l e r = new SingleCommandSetupController ( this ) ;110111 this . setLayout (new FlowLayout ( FlowLayout .LEADING) ) ;112 this . add ( commandSetupView) ;113114 // LISTENERS115 commandSetupView . getCreateAndSendCommandButton ( ) . addAct ionListener (

c o n t r o l l e r ) ;116 commandSetupView . getCancelButton ( ) . addAct ionListener ( c o n t r o l l e r ) ;117118 this . pack ( ) ;119 this . s e tLocat ionRe lat iveTo ( null ) ;120 this . s e t V i s i b l e ( true ) ;121 }122123 /∗∗124 ∗ @r e t u r n commandSe tupView125 ∗/126 public CommandSetupView getCommandSetupView ( ) {127 return commandSetupView ;128 }129130 /∗∗131 ∗ @r e t u r n commandToEdi t132 ∗/133 public Command getCommandToEdit ( ) {134 return commandToEdit ;135 }136137 /∗∗138 ∗ @r e t u r n t im e L i n eV i e w139 ∗/140 public TimeLineView getTimeLineView ( ) {141 return timeLineView ;142 }143144 }

Page 162: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

152 Appendix C - Source Code

.1.28 AddCommandToBlockController.java

1 package mps . gui . commanding . block ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;56 import javax . swing . JOptionPane ;78 import common . command .Command;9 import common . command . DTUsat2CommandFactory ;

10 import common . except ions . I l l ega lParamete rExcept ion ;11 import common . except ions . UnknownCommandTypeException ;121314 /∗∗15 ∗ C o n t r o l l e r f o r t h e AddCommandToBlockView16 ∗ <br><br>17 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 318 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 119 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 820 ∗/21 public c lass AddCommandToBlockController implements Act ionL i s t ener {2223 /∗∗24 ∗ The v i e w t o c o n t r o l25 ∗/26 private AddCommandToBlockView view ;2728 /∗∗29 ∗ C r e a t e s an i n s t a n c e o f Ad dCommandToB l o c kCon t r o l l e r w i t h t h e g i v e n v i e w30 ∗ @param v i e w31 ∗/32 public AddCommandToBlockController (AddCommandToBlockView view ) {33 this . view = view ;34 }3536 @Override37 public void act ionPerformed ( ActionEvent ae ) {3839 i f ( ae . getSource ( ) . equa l s ( view . getAddCommandPanel ( ) .

getCreateAndSendCommandButton ( ) ) ) {4041 St r ing commandData = view . getAddCommandPanel ( ) .

getSelectCommandPanelView ( ) . generateCommandInfo ( ) ;4243 i f ( view . getCommandToEdit ( )==null ) {44 // ADD New command t o b l o c k4546 DTUsat2CommandFactory t c f = new

DTUsat2CommandFactory ( ) ;4748 try {49 Command command = t c f . generateCommand (

commandData) ;50 command . setTimeOfExecution (−1) ;51 view . getCreateCommandBlockView ( ) .

getCommandBlockModel ( ) . addCommand(command) ;

5253 } catch (UnknownCommandTypeException e ) {54 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

55 e . pr intStackTrace ( ) ;56 } catch ( I l l ega lParamete rExcept ion e ) {57 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

58 e . pr intStackTrace ( ) ;59 }6061 } else {62 // MODIFY e x i s t i n g command i n b l o c k63 view . getCommandToEdit ( ) . setParameters (commandData) ;64 }6566 view . getCreateCommandBlockView ( ) . getTable ( ) . r epa in t ( ) ;67 view . d i spose ( ) ;6869 } else i f ( ae . getSource ( ) . equa l s ( view . getAddCommandPanel ( ) .

getCancelButton ( ) ) ) {70 view . d i spose ( ) ;71 }7273 }

Page 163: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 153

7475 }

Page 164: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

154 Appendix C - Source Code

.1.29 AddCommandToBlockView.java

1 package mps . gui . commanding . block ;23 import javax . swing . JFrame ;45 import mps . gui . commanding . CommandSetupView ;6 import mps . gui . t ime l i n e . TimeLineView ;78 import common . command .Command;9

1011 /∗∗12 ∗ The f r ame f o r a d d i n g a command t o t h e a b l o c k13 ∗ <br><br>14 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 315 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 116 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 817 ∗/18 public c lass AddCommandToBlockView extends JFrame {1920 /∗∗21 ∗ The s e r i a l number o f t h e c l a s s22 ∗/23 private stat ic f ina l long se r ia lVers ionUID = 1L ;24 /∗∗25 ∗26 ∗/27 private CommandBlockSetupView commandBlockSetupView ;28 /∗∗29 ∗30 ∗/31 private Command commandToEdit ;32 /∗∗33 ∗34 ∗/35 private CommandSetupView addCommandPanel ;3637 /∗∗38 ∗39 ∗/40 private AddCommandToBlockController c o n t r o l l e r ;4142 /∗∗43 ∗ @param commandB l o c k S e t u pV i ew44 ∗/45 public AddCommandToBlockView( CommandBlockSetupView commandBlockSetupView ) {46 this . commandBlockSetupView = commandBlockSetupView ;4748 TimeLineView . s e t I con ( this ) ;49 this . s e t T i t l e ( ”Add new command to block ” ) ;50 addCommandPanel = new CommandSetupView( fa lse , fa lse , fa lse , f a l s e ) ;51 addCommandPanel . getCreateAndSendCommandButton ( ) . setText ( ”<html><b>

Add command to block </b></html>” ) ;5253 b u i l t ( ) ;54 }5556 /∗∗57 ∗ @param commandB l o c k S e t u pV i ew58 ∗ @param commandToEdi t59 ∗/60 public AddCommandToBlockView( CommandBlockSetupView commandBlockSetupView ,

Command commandToEdit ) {61 this . commandBlockSetupView = commandBlockSetupView ;62 this . commandToEdit = commandToEdit ;6364 TimeLineView . s e t I con ( this ) ;65 this . s e t T i t l e ( ” Edit command \”” + commandToEdit . getCommandID () + ”\”

” ) ;6667 addCommandPanel = new CommandSetupView( fa lse , fa lse , fa lse , fa lse ,

commandToEdit ) ;68 addCommandPanel . getCreateAndSendCommandButton ( ) . setText ( ”<html><b>

Modify command in block </b></html>” ) ;6970 b u i l t ( ) ;71 }7273 /∗∗74 ∗75 ∗/76 private void b u i l t ( ) {7778 this . add (addCommandPanel ) ;79

Page 165: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 155

80 c o n t r o l l e r = new AddCommandToBlockController ( this ) ;8182 addCommandPanel . getCreateAndSendCommandButton ( ) . addAct ionListener (

c o n t r o l l e r ) ;8384 this . pack ( ) ;85 this . s e t V i s i b l e ( true ) ;86 this . s e tLocat ionRe lat iveTo ( null ) ;8788 }8990 /∗∗91 ∗ @r e t u r n92 ∗/93 public CommandSetupView getAddCommandPanel ( ) {94 return addCommandPanel ;95 }9697 /∗∗98 ∗ @r e t u r n99 ∗/

100 public CommandBlockSetupView getCreateCommandBlockView ( ) {101 return commandBlockSetupView ;102 }103104 /∗∗105 ∗ @r e t u r n106 ∗/107 public Command getCommandToEdit ( ) {108 return commandToEdit ;109 }110111112113114 }

Page 166: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

156 Appendix C - Source Code

.1.30 CommandBlockModel.java

1 package mps . gui . commanding . block ;23 import java . rmi . NotBoundException ;4 import java . rmi . RemoteException ;5 import java . u t i l . ArrayList ;6 import java . u t i l . HashMap ;78 import mcc . s e rv e r . dataProcess ing . CommandBlock ;9 import mps . gui . commanding . block . save load . PredefinedCommand ;

10 import mps . gui . commanding . block . save load . PredefinedCommandBlock ;11 import mps . gui . t ime l i n e . TimeLineModel ;1213 import common . command .Command;14 import common . command . DTUsat2Command ;15 import common . command . DTUsat2CommandFactory ;16 import common . except ions . I l l ega lParamete rExcept ion ;17 import common . except ions . UnknownCommandTypeException ;1819 /∗∗20 ∗ <br><br>21 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 322 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 123 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 824 ∗/25 public c lass CommandBlockModel extends ArrayList<Command> {2627 /∗∗28 ∗29 ∗/30 private stat ic f ina l long se r ia lVers ionUID = 1L ;3132 /∗∗33 ∗34 ∗/35 private long blockStartTOE = TimeLineModel . getCurrentTimeInMi l l i s ( ) ;3637 /∗∗38 ∗39 ∗/40 private HashMap<Command, Of f set > offSetMap ;414243 /∗∗44 ∗ G e n e r a t e s a CommandBlockMode l u s e d f o r t h e Cr ea t e dCommandB l o c kV i ew .45 ∗/46 public CommandBlockModel ( ) {47 offSetMap = new HashMap<Command, Of f set >() ;48 }4950 /∗∗ G e n e r a t e s a CommandBlockMode l , u s e d f o r t h e Crea t edCommandB loc kV i ew ,

f r om a Command B l o c k w i t h i n t h e T i m e l i n e .51 ∗ @param t im e l i n eC omman dB l o c k52 ∗ @th r ow s UnknownCommandTypeExcep t i on53 ∗ @th r ow s R emo t e E x c e p t i o n54 ∗ @th r ow s N o tB o u n dE x c e p t i o n55 ∗ @th r ow s UnknownCommandTypeExcep t i on56 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n57 ∗/58 public CommandBlockModel (CommandBlock timelineCommandBlock ) throws

UnknownCommandTypeException , I l l ega lParamete rExcept ion {59 offSetMap = new HashMap<Command, Of f set >() ;6061 // Add c l o n e s o f t h e commands t o t h e mod e l62 for ( int i =0; i<=timelineCommandBlock . s i z e ( )−1; i++) {63 long id = timelineCommandBlock . getCommand( i ) ;64 DTUsat2Command c = (DTUsat2Command) TimeLineModel .

g e t In s tance ( ) . getTimelineData ( ) . getCommandMap( ) . get ( id );

65 this . addCommand( c . cloneCommand(new DTUsat2CommandFactory ( ) )) ;

66 }67 // F ind and s t o r e l o w e s t TOE o f a command i n t h e b l o c k ( e x c e p t −1

b e c a u s e i t i s ASAP)68 long lowestTOE = Long .MAX VALUE;69 for (Command c : this ) {70 i f ( c . getTimeOfExecution ( ) < lowestTOE && c .

getTimeOfExecution ( ) !=−1) lowestTOE = c .getTimeOfExecution ( ) ;

71 }72 i f ( lowestTOE==Long .MAX VALUE) this . setBlockStartTOE ( TimeLineModel .

getCurrentTimeInMi l l i s ( ) ) ;73 else this . setBlockStartTOE ( lowestTOE ) ;7475 for (Command c : this ) {

Page 167: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 157

76 i f ( c . getTimeOfExecution ( ) !=−1) {77 long o f f s e t = c . getTimeOfExecution ( ) − lowestTOE ;7879 i f ( o f f s e t ==0) {80 this . getOffSetMap ( ) . get ( c ) . se tUnit ( O f f s e t .

SECONDS) ;81 this . getOffSetMap ( ) . get ( c ) . s e t O f f s e t (0) ;82 } else i f ( o f f s e t % (1000∗60∗60)==0) {83 // HOURS84 this . getOffSetMap ( ) . get ( c ) . se tUnit ( O f f s e t .

HOURS) ;85 this . getOffSetMap ( ) . get ( c ) . s e t O f f s e t ( o f f s e t

/(1000∗60∗60) ) ;86 } else i f ( o f f s e t % (1000∗60)==0) {87 // MINUTES88 this . getOffSetMap ( ) . get ( c ) . se tUnit ( O f f s e t .

MINUTES) ;89 this . getOffSetMap ( ) . get ( c ) . s e t O f f s e t ( o f f s e t

/(1000∗60) ) ;90 } else i f ( o f f s e t % (1000)==0) {91 // SECONDS92 this . getOffSetMap ( ) . get ( c ) . se tUnit ( O f f s e t .

SECONDS) ;93 this . getOffSetMap ( ) . get ( c ) . s e t O f f s e t ( o f f s e t

/1000) ;94 } else {95 // MILISECONDS96 this . getOffSetMap ( ) . get ( c ) . se tUnit ( O f f s e t .

MILISECONDS) ;97 this . getOffSetMap ( ) . get ( c ) . s e t O f f s e t ( o f f s e t )

;98 }99 }

100 }101102 }103104 /∗∗ Th i s me t hod c l e a r s t h e c u r r e n t CommandBlockMode l and r e b u i l d s i t f r om a

s p e c i f i e d P r e d e f i n e dCommandB l o c k105 ∗ @param p r e d e f i n e dC omman dB l o c k106 ∗ @th r ow s UnknownCommandTypeExcep t i on107 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n108 ∗/109 public void buildFromPredefinedCommandBlock ( PredefinedCommandBlock

predefinedCommandBlock ) throws UnknownCommandTypeException ,I l l ega lParamete rExcept ion {

110 // c l e a r a l l commands i n t h e b l o c k111 this . c l e a r ( ) ;112 offSetMap . c l e a r ( ) ;113114 DTUsat2CommandFactory t c f = new DTUsat2CommandFactory ( ) ;115 for ( PredefinedCommand pc : predefinedCommandBlock . getCommands ( ) ) {116117 DTUsat2Command c = t c f . generateCommand ( pc . getCommandInfo ( ) ) ;118 this . add ( c ) ;119 offSetMap . put ( c , pc . g e tO f f s e t ( ) ) ;120121 i f ( pc . isAsapTOE () ) {122 c . setTimeOfExecution (−1) ;123 } else {124 updateTOE( c ) ; // i f t h e command i s n o t ASAP t h e TOE

s h o u l d b e u p d a t e d125 }126 }127128 }129130 /∗∗131 ∗ @r e t u r n132 ∗/133 public PredefinedCommandBlock createPredefinedCommandBlock ( ) {134 PredefinedCommandBlock r e s u l t = new PredefinedCommandBlock ( ) ;135136 St r ing commandData ;137 for (Command c : this ) {138 commandData = ((DTUsat2Command) c ) . generateCommandDataString

( ) ;139 i f ( c . getTimeOfExecution ( )==−1) {140 r e s u l t . getCommands ( ) . add ( new PredefinedCommand (

commandData) ) ;141 } else {142 r e s u l t . getCommands ( ) . add ( new PredefinedCommand (

commandData , getOf fSet ( c ) ) ) ;143 }144 }145146 return r e s u l t ;

Page 168: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

158 Appendix C - Source Code

147 }148149150 /∗∗ Adds a command t o t h e CommandBlockMode l and c r e a t e s a mapp in g t o an

emp t y o f f s e t151 ∗ @param c152 ∗/153 public void addCommand(Command c ) {154 add ( c ) ;155 offSetMap . put ( c , new Of f s e t ( ) ) ;156157 }158159 /∗∗ Ge t s t h e o f f s e t o f a command f r om Base TOE i n t h e s p e c i f i e d u n i t160 ∗ @param command command t o g e t o f f s e t o f161 ∗ @r e t u r n t h e o f f s e t o f t h e command i n t h e s p e c i f i e d u n i t162 ∗/163 public Of f s e t getOf fSet (Command command) {164 return offSetMap . get (command) ;165 }166167 /∗∗168 ∗ @param command169 ∗/170 public void updateTOE(Command command) {171172 command . setTimeOfExecution ( blockStartTOE + offSetMap . get (command) .

ge tOf fSe t InMi l i s e conds ( ) ) ;173 }174175 /∗∗176 ∗177 ∗/178 public void updateAllTOE () {179180 for (Command c : this ) {181 i f ( c . getTimeOfExecution ( ) !=−1) updateTOE( c ) ;182 }183 }184185 /∗∗186 ∗ @r e t u r n187 ∗/188 public long getBlockStartTOE () {189 return blockStartTOE ;190 }191192 /∗∗193 ∗ @param b l o c k S t a r t TOE194 ∗/195 public void setBlockStartTOE ( long blockStartTOE ) {196 this . blockStartTOE = blockStartTOE ;197 }198199 /∗∗200 ∗ @r e t u r n201 ∗/202 public HashMap<Command, Of f set > getOffSetMap ( ) {203 return offSetMap ;204 }205206207 }

Page 169: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 159

.1.31 CommandBlockSetupAbstractTableModel.java

1 package mps . gui . commanding . block ;23 import java . text . SimpleDateFormat ;45 import javax . swing . tab l e . AbstractTableModel ;67 import mps . MPSPreferences ;89 import common . command .Command;

10 import common . command . DTUsat2Command ;11 import common . command . DTUsat2CommandTypeMap ;1213 /∗∗14 ∗ <br><br>15 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 316 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 117 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 818 ∗/19 public c lass CommandBlockSetupAbstractTableModel extends AbstractTableModel {202122 /∗∗23 ∗24 ∗/25 private stat ic f ina l long se r ia lVers ionUID = 1L ;2627 public stat ic f ina l int ID COLUMN =

0;28 public stat ic f ina l int NO COLUMN =

1;29 public stat ic f ina l int NAME COLUMN = 2;30 public stat ic f ina l int SUBSYSTEM COLUMN = 3;31 public stat ic f ina l int PARAMETERS COLUMN = 4;32 public stat ic f ina l int TOE IS ASAP = 5;33 public stat ic f ina l int TOE OFFSET = 6;34 public stat ic f ina l int TOE OFFSET UNIT = 7 ;35 public stat ic f ina l int TOE COLUMN = 8;36 public stat ic f ina l int PASS COLUMN = 9;37 public stat ic f ina l int STATE COLUMN = 10;3839 /∗∗40 ∗41 ∗/42 private CommandBlockSetupView commandBlockView ;4344 /∗∗45 ∗ @param commandB lockV iew46 ∗/47 public CommandBlockSetupAbstractTableModel ( CommandBlockSetupView

commandBlockView ) {48 this . commandBlockView = commandBlockView ;49 }5051 /∗∗52 ∗ @param baseTOE53 ∗/54 public void setBaseTOE ( long baseTOE) {55 commandBlockView . getCommandBlockModel ( ) . setBlockStartTOE (baseTOE) ;56 }5758 public int getColumnCount ( ) {59 return 11 ; // n e e d s s y n c h r o n i z a t i o n60 }6162 public int getRowCount ( ) {63 i f ( commandBlockView . getCommandBlockModel ( )==null ) return 0 ;64 else return commandBlockView . getCommandBlockModel ( ) . s i z e ( ) ;65 }6667 public Str ing getColumnName( int co l ) {6869 switch ( c o l ) {70 case ID COLUMN: return ” Id . ” ;71 case NO COLUMN: return ”No . ” ;72 case NAME COLUMN: return ”Name” ;73 case SUBSYSTEM COLUMN: return ”Subsystem” ;74 case PARAMETERS COLUMN: return ”Paramters ” ;75 case TOE IS ASAP : return ”ASAP” ;76 case TOE OFFSET: return ” Of f s e t ” ;77 case TOE OFFSET UNIT: return ”Unit” ;78 case TOE COLUMN : return ”Time o f execut ion ” ;79 case PASS COLUMN : return ”Pass” ;80 case STATE COLUMN : return ” State ” ;81 default :

Page 170: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

160 Appendix C - Source Code

82 return ”Unknown column” ;83 }84 }8586 @Override87 public boolean i s C e l l E d i t a b l e ( int rowIndex , int columnIndex ) {88 // i f ( c o l umn I n d e x==TOE COLUMN) r e t u r n t r u e ;8990 i f ( commandBlockView . getCommandBlockModel ( ) . get ( rowIndex ) . ge tState ( )>=Command

.BEING TRANSMITTED) {91 return fa l se ;92 }9394 i f ( columnIndex==TOE IS ASAP) return true ;95 else i f ( columnIndex==TOE OFFSET | | columnIndex==TOE OFFSET UNIT) {96 i f ( ( Boolean ) getValueAt ( rowIndex , TOE IS ASAP) == true ) return fa l se ;97 else return true ;98 }99 else i f ( columnIndex==PASS COLUMN) return true ;

100 else return fa l se ;101 }102103 /∗104 ∗ Don ’ t n e e d t o im p l em e n t t h i s me t hod u n l e s s y o u r t a b l e ’ s105 ∗ d a t a can c h a n g e .106 ∗/107 public void setValueAt ( Object value , int row , int co l ) {108109 DTUsat2Command command = (DTUsat2Command) commandBlockView .

getCommandBlockModel ( ) . get ( row ) ;110111 i f ( c o l==TOE IS ASAP) {112 i f ( ( Boolean ) value==true ) {113 command . setTimeOfExecution (−1) ;114 } else i f ( ( Boolean ) value==f a l s e ) {115 commandBlockView . getCommandBlockModel ( ) . updateTOE(command) ;116117 }118 } else i f ( c o l==TOE OFFSET) {119120 long o f f s e t = Long . parseLong ( value . t oS t r ing ( ) ) ;121122 commandBlockView . getCommandBlockModel ( ) . ge tOf fSet (command) . s e t O f f s e t

( o f f s e t ) ;123 commandBlockView . getCommandBlockModel ( ) . updateTOE(command) ;124125126 } else i f ( c o l == TOE OFFSET UNIT) {127 commandBlockView . getCommandBlockModel ( ) . ge tOf fSet (command) . se tUnit (

value . t oSt r ing ( ) ) ;128129 commandBlockView . getCommandBlockModel ( ) . updateTOE(command) ;130131 } else i f ( c o l == PASS COLUMN) {132133 i f ( value . equa l s ( ”AUTO” ) | | value . equa l s ( ”−−−−−” ) ) {134 command . setPassID (−1) ;135 } else {136 long passID = Long . parseLong ( value . t oS t r ing ( ) ) ;137 command . setUserGivenPass ( true ) ;138 command . setPassID ( passID ) ;139 }140141 }142 fireTableDataChanged ( ) ;143144 }145146 public Object getValueAt ( int row , int co l ) {147148 //FIXME : What t o do i f no commands i n b l o c k149 i f ( commandBlockView . getCommandBlockModel ( ) . get ( row )==null ) return ”” ;150151 DTUsat2Command command = (DTUsat2Command) commandBlockView .

getCommandBlockModel ( ) . get ( row ) ;152153 switch ( c o l ) {154 case ID COLUMN:155 i f (command . getCommandID ()==−1) return ”NEW” ;156 else return ””+command . getCommandID () ;157 case NO COLUMN:158 return ””+command . getCommandTypeID ( ) ;159 case NAME COLUMN:160 return DTUsat2CommandTypeMap . ge t In s tance ( ) . getCommandType(

command . getCommandTypeID ( ) ) . getName ( ) ;161 case SUBSYSTEM COLUMN:162 return command . ge tDes t ina t i on ( ) . name ( ) ;

Page 171: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 161

163 case PARAMETERS COLUMN:164 return command . getParameters ( ) ;165 case TOE IS ASAP :166 i f (command . getTimeOfExecution ( )==−1) return new Boolean ( true

) ;167 else return new Boolean ( f a l s e ) ;168 case TOE OFFSET:169 i f (command . getTimeOfExecution ( )==−1) return ”N/A” ;170 else {171 return commandBlockView . getCommandBlockModel ( ) .

ge tOf fSet (command) . getValue ( ) ;172 }173 case TOE OFFSET UNIT:174 i f (command . getTimeOfExecution ( )==−1) return ”N/A” ;175 else return commandBlockView . getCommandBlockModel ( ) .

ge tOf fSet (command) . getUnit ( ) ;176 case TOE COLUMN:177 i f (command . getTimeOfExecution ( )==−1) return ”ASAP” ;178 else return new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format (command .getTimeOfExecution ( ) ) ;

179 case PASS COLUMN:180 i f ( ! command . getUserGivenPass ( ) ) return ”AUTO” ;181 else return command . getPassID ( ) ;182 case STATE COLUMN:183 i f (command . ge tState ( )==−1) return ”NEW” ;184 else return command . ge tS ta t eDes c r ip t i on ( ) ;185 default :186 return ”Unknown column” ;187 }188189 }190191 /∗192 ∗ JT a b l e u s e s t h i s me t hod t o d e t e r m i n e t h e d e f a u l t r e n d e r e r /193 ∗ e d i t o r f o r e a c h c e l l . I f we d i d n ’ t im p l em e n t t h i s method ,194 ∗ t h e n t h e l a s t c o l umn wou l d c o n t a i n t e x t ( ” t r u e ”/” f a l s e ” ) ,195 ∗ r a t h e r t h a n a c h e c k b o x .196 ∗/197 public Class getColumnClass ( int c ) {198 return getValueAt (0 , c ) . ge tClas s ( ) ;199 }200201202203 }

Page 172: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

162 Appendix C - Source Code

.1.32 CommandBlockSetupController.java

1 package mps . gui . commanding . block ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;7 import java . u t i l . ArrayList ;89 import javax . swing . JOptionPane ;

10 import javax . swing . event . ChangeEvent ;11 import javax . swing . event . ChangeListener ;12 import javax . swing . event . L i s tSe l e c t i onEvent ;13 import javax . swing . event . L i s t S e l e c t i o n L i s t e n e r ;1415 import mcc . s e rv e r . dataProcess ing . CommandBlock ;16 import mcc . s e rv e r . dataProcess ing . T i m e l i n e U t i l i t i e s ;17 import mps . gui . commanding . block . save load . LoadCommandBlockView ;18 import mps . gui . commanding . block . save load . PredefinedCommandBlocksSaveObject ;19 import mps . gui . commanding . block . save load . SaveCommandBlockView ;20 import mps . gui . t ime l i n e . TimeLineModel ;21 import mps . rmi . C l i ent ;2223 import common . command .Command;2425 /∗∗26 ∗ <br><br>27 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 328 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 129 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 830 ∗/31 public c lass CommandBlockSetupController implements Act ionListener , ChangeListener ,

L i s t S e l e c t i o n L i s t e n e r {3233 /∗∗34 ∗35 ∗/36 private CommandBlockSetupView view ;3738 /∗∗39 ∗ @param v i e w40 ∗/41 public CommandBlockSetupController ( CommandBlockSetupView view ) {42 this . view = view ;434445 }4647 @Override48 public void act ionPerformed ( ActionEvent ae ) {4950 i f ( ae . getSource ( ) . equa l s ( view . getLoadButton ( ) ) ) {51 // LOAD BUTTON5253 PredefinedCommandBlocksSaveObject saveObject = TimeLineModel

. g e t In s tance ( ) . getPredefinedCommandBlocksSaveObject ( ) ;5455 i f ( saveObject . s i z e ( )==0) {56 JOptionPane . showMessageDialog ( view , ”No command

blocks saved” , ”No command blocks ” , JOptionPane .INFORMATION MESSAGE) ;

57 } else {58 new LoadCommandBlockView( view ) ;5960 }616263 } else i f ( ae . getSource ( ) . equa l s ( view . getSaveButton ( ) ) ) {64 // SAVE65 i f ( view . getCommandBlockModel ( ) . s i z e ( )==0){66 JOptionPane . showMessageDialog ( view , ”You must add

commands to the block be fo r e you can save i t ” ,”No command in block ” , JOptionPane .INFORMATION MESSAGE) ;

67 } else {68 new SaveCommandBlockView( view , view .

getCommandBlockModel ( ) .createPredefinedCommandBlock ( ) ) ;

69 }7071727374 } else i f ( ae . getSource ( ) . equa l s ( view . getAddCommandButton ( ) ) ) {75 // ADD COMMAND TO BLOCK

Page 173: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 163

76 new AddCommandToBlockView( view ) ;7778 } else i f ( ae . getSource ( ) . equa l s ( view . getEditCommandButton ( ) ) ) {79 // EDIT COMMAND80 Command command = view . getCommandBlockModel ( ) . get ( view .

getTable ( ) . getSelectedRow () ) ;81 new AddCommandToBlockView( view , command) ;8283 } else i f ( ae . getSource ( ) . equa l s ( view . getDeleteCommandButton ( ) ) ) {84 // DELETE COMMAND8586 Command c = view . getCommandBlockModel ( ) . get ( view . getTable ( ) .

getSelectedRow () ) ;87 view . getCommandBlockModel ( ) . remove ( c ) ;88 view . getTable ( ) . r epa in t ( ) ;8990 } else i f ( ae . getSource ( ) . equa l s ( view . getSendButton ( ) ) ) {91 // SEND/MODIFY BLOCK92 i f ( view . isEditMode ( ) ) editCommandBlock ( ) ;93 else createNewCommandBlock ( ) ;949596 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {979899 }

100101102 }103104 /∗∗105 ∗106 ∗/107 private void createNewCommandBlock ( ) {108109 try {110111 // CommandBlockMode l mus t b e c o n v e r t e d t o an A r r a y L i s t <

Command> t o s e n d i t t h r o u g h RMI112 ArrayList<Command> newBlock = new ArrayList<Command>() ;113 for (Command c : view . getCommandBlockModel ( ) ) {114 newBlock . add ( c ) ;115 }116117 int p r i o r i t y = view . ge tPr i o r i t yPane l ( ) .

getNormalPrior ityRadio ( ) . i s S e l e c t e d ( ) ? CommandBlock .NORMAL PRIORITY : CommandBlock .URGENT PRIORITY;

118119 Cl i ent . ge t In s tance ( ) . getMediumInterface ( ) . addBlock ( newBlock ,

p r i o r i t y ) ;120121 ArrayList<Command> allCommands= Cl i ent . ge t In s tance ( ) .

ge tMin ima l Inte r face ( ) . getCommands ( null ) ;122123 // SET PASS124 long highestCommandID = getHighestCommandID () ;125126 int numberOfCommandsInBlock = view . getCommandBlockModel ( ) .

s i z e ( ) ;127 long f irstCommandIdInBlock = highestCommandID −

numberOfCommandsInBlock + 1 ; // e x amp l e : h i g h e s t =7 ,numberOfcommands =3 , f i r s t C omman d I d = 7−3+1 = 5 ( n e x t i s

6 , 7 )128129 for ( int i= 0 ; i <= numberOfCommandsInBlock−1; i++) {130131 long currentCommandID = firstCommandIdInBlock+i ;132 long passIdForCurrentCommand = view .

getCommandBlockModel ( ) . get ( i ) . getPassID ( ) ;133 i f ( passIdForCurrentCommand!=−1) {134 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

modifyCommand( currentCommandID , true ) ;135 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

modifyCommand( currentCommandID ,T i m e l i n e U t i l i t i e s . PASSID ,passIdForCurrentCommand ) ;

136 }137138 }139140141 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;142 view . getTimeLineView ( ) . setScheduleRecommendation ( true ) ;143 view . d i spose ( ) ;144145 } catch ( RemoteException e ) {

Page 174: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

164 Appendix C - Source Code

146 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

147 e . pr intStackTrace ( ) ;148 } catch ( NotBoundException e ) {149 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;150 e . pr intStackTrace ( ) ;151 }152153 }154155 /∗∗156 ∗157 ∗/158 private void editCommandBlock ( ) {159160 long commandBlockIDToEdit = view . getCommandBlockIDToEdit ( ) ;161 CommandBlock cb = TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

getCommandBlockMap ( ) . get ( commandBlockIDToEdit ) ;162163 try {164165 ArrayList<Command> newCommands = new ArrayList<Command>() ;

// l i s t w i l l c o n t a i n new commands t h a t s h o u l d b e a d d e dt o b l o c k

166167 for (Command command : view . getCommandBlockModel ( ) ) {168169 i f (command . getCommandID () == −1) {170 // TODO: New command wh i c h s h o u l d b e a d d e d

t o t h e b l o c k . . Hack n e e d e d ?171 newCommands . add (command) ;172173 } else {174175 Command originalCommand = TimeLineModel .

g e t In s tance ( ) . getTimelineData ( ) .getCommandMap( ) . get (command .getCommandID () ) ;

176177178 i f ( ! command . getParameters ( ) . equa l s (

originalCommand . getParameters ( ) ) ) {179 // PARAMETER180 Cl i ent . ge t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) .modifyCommand(command .getCommandID () , command .getParameters ( ) ) ;

181 }182183 i f (command . getPassID ( ) != originalCommand .

getPassID ( ) ) {184 // PASS185 i f (command . getPassID ( )==−1) {186 Cl i ent . ge t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) .modifyCommand(command .getCommandID () , f a l s e ) ;

187 // C l i e n t . g e t I n s t a n c e ( ) .g e t A d m i n I n t e r f a c e ( ) .modi fyCommand ( command .getCommandID ( ) ,T i m e l i n e U t i l i t i e s .PASSID , −1) ;

188 } else {189 Cl i ent . ge t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) .modifyCommand(command .getCommandID () , true ) ;

190 Cl i ent . ge t In s tance ( ) .g e t F u l l I n t e r f a c e ( ) .modifyCommand(command .getCommandID () ,T i m e l i n e U t i l i t i e s .PASSID , command .getPassID ( ) ) ;

191 }192 }193194 //TOE195 i f (command . getTimeOfExecution ( ) !=

originalCommand . getTimeOfExecution ( ) ) {196 Cl i ent . ge t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) .modifyCommand(command .getCommandID () ,

Page 175: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 165

T i m e l i n e U t i l i t i e s .TOE, command .getTimeOfExecution ( ) ) ;

197 }198199 }200201 }202203 // ADD NEW COMMANDS TO CURRENT BLOCK204 // HACK t o i n c l u d e new commands i n t h i s b l o c k . They w i l l g e t

t h e r e own b l o c k f i r s t , and t h e n b e moved :205 Cl i ent . ge t In s tance ( ) . getMediumInterface ( ) . addBlock (

newCommands) ;206207 long highestCommandID = getHighestCommandID () ;208209 long numberOfCommandsInBlock = newCommands . s i z e ( ) ;210 long f irstCommandIdInBlock = highestCommandID −

numberOfCommandsInBlock +1; // e x amp l e : h i g h e s t =7 ,numberOfcommands =3 , f i r s t C omman d I d = 7−3+1 = 5 ( n e x t i s

6 , 7 )211 for ( int i= 0 ; i <= numberOfCommandsInBlock−1; i++) {212213 long currentCommandID = firstCommandIdInBlock+i ;214215 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

modifyCommand( currentCommandID ,T i m e l i n e U t i l i t i e s .BLOCKID, commandBlockIDToEdit) ;

216217 }218219220221 // Chec k i f any commands h a s b e e n d e l e t e d222 for ( int i =0; i<=cb . s i z e ( )−1; i++) {223 // run t h r o u g h a l l commands i n o r i g i n a l command b l o c k224 long commandID = cb . getCommand( i ) ; // Command f r om

t h e o r i g i n a l b l o c k . We h a v e t o s e e i f t h i ss t i l l e x i s t s .

225 boolean e x i s t s = f a l s e ; // Th i s w i l l b e s e t t o t r u ei f t h e command i s f o u n d i n t h e c u r r e n t b l o c k

226 for (Command c : view . getCommandBlockModel ( ) ) {227 i f ( c . getCommandID ()==commandID) {228 e x i s t s = true ;229 break ;230 }231 }232 i f ( ! e x i s t s ) {233 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

removeCommand(commandID) ;234 }235 }236237238 // PRIORITY ( s e t f o r a l l b l o c k )239 i f ( view . ge tPr i o r i t yPane l ( ) . getHighPr ior i tyRadio ( ) . i s S e l e c t e d

( ) && cb . g e t P r i o r i t y ( )== CommandBlock .NORMAL PRIORITY){

240 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyBlock (view . getCommandBlockIDToEdit ( ) , CommandBlock .URGENT PRIORITY) ;

241242 } else i f ( view . ge tPr i o r i t yPane l ( ) . getNormalPrior ityRadio ( ) .

i s S e l e c t e d ( ) && cb . g e t P r i o r i t y ( )== CommandBlock .URGENT PRIORITY) {

243 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . modifyBlock (view . getCommandBlockIDToEdit ( ) , CommandBlock .NORMAL PRIORITY) ;

244 }245246247248 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;249 view . getTimeLineView ( ) . setScheduleRecommendation ( true ) ;250 view . d i spose ( ) ;251252 } catch ( RemoteException e ) {253 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;254 e . pr intStackTrace ( ) ;255 } catch ( NotBoundException e ) {256 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;257 e . pr intStackTrace ( ) ;258 }259

Page 176: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

166 Appendix C - Source Code

260261262 }263264265 /∗∗266 ∗ @r e t u r n The h i g h e s t ID o f a command i n t h e DB ( t h e l a t e s t a d d e d command )267 ∗ @th r ow s R emo t e E x c e p t i o n268 ∗ @th r ow s N o tB o u n dE x c e p t i o n269 ∗/270 private long getHighestCommandID () throws RemoteException , NotBoundException

{271 ArrayList<Command> allCommands= Cl i ent . ge t In s tance ( ) .

ge tMin ima l Inte r face ( ) . getCommands ( null ) ;272 long highestCommandID = 0 ; // l a s t a d d e d command t o t h e d a t a b a s e273 for (Command c : allCommands ) {274 i f ( c . getCommandID ()> highestCommandID ) {275 highestCommandID = c . getCommandID () ;276 }277 }278 return highestCommandID ;279 }280281 @Override282 public void stateChanged ( ChangeEvent ce ) {283 i f ( ce . getSource ( ) . equa l s ( view . getBlockStartTimeSpinnersPanel ( ) .

getDateSDM () ) | | ce . getSource ( ) . equa l s ( view .getBlockStartTimeSpinnersPanel ( ) . getTimeSDM () ) ) {

284 long time = view . getBlockStartTimeSpinnersPanel ( ) . getTime ( ) ;285 view . getCommandBlockModel ( ) . setBlockStartTOE ( time ) ;286 view . getCommandBlockModel ( ) . updateAllTOE () ;287 view . getTable ( ) . r epa in t ( ) ;288 }289290291 }292293 @Override294 public void valueChanged ( L i s tSe l e c t i onEvent l s e ) {295296297 // Upda t e d e l e t e and e d i t b u t t o n s c l i c k a b i l i t y298 i f ( view . getTable ( ) . getSelectedRow () == −1){299 view . getEditCommandButton ( ) . setEnabled ( f a l s e ) ;300 view . getDeleteCommandButton ( ) . setEnabled ( f a l s e ) ;301 } else {302 // TODO: p o s s i b l e t o e d i t / d e l e t e a c c o r d i n g t o s t a t e303 view . getEditCommandButton ( ) . setEnabled ( true ) ;304 view . getDeleteCommandButton ( ) . setEnabled ( true ) ;305 }306307308 }309310311 }

Page 177: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 167

.1.33 CommandBlockSetupView.java

1 package mps . gui . commanding . block ;23 import java . awt . Color ;4 import java . awt . Component ;5 import java . awt . Dimension ;6 import java . awt . FlowLayout ;7 import java . awt . Font ;8 import java . awt . GridBagConstraints ;9 import java . awt . GridBagLayout ;

10 import java . rmi . NotBoundException ;11 import java . rmi . RemoteException ;12 import java . u t i l . ArrayList ;1314 import javax . swing . BorderFactory ;15 import javax . swing . De fau l tCe l lEd i to r ;16 import javax . swing . JButton ;17 import javax . swing . JComboBox ;18 import javax . swing . JFrame ;19 import javax . swing . JLabel ;20 import javax . swing . JPanel ;21 import javax . swing . JScro l lPane ;22 import javax . swing . JTable ;23 import javax . swing . L i s tSe l e c t i onMode l ;24 import javax . swing . border . EtchedBorder ;25 import javax . swing . border . Tit ledBorder ;26 import javax . swing . tab l e . DefaultTableCel lRenderer ;27 import javax . swing . tab l e . TableRowSorter ;2829 import mcc . s e rv e r . dataProcess ing . CommandBlock ;30 import mcc . s e rv e r . dataProcess ing . Pass ;31 import mps . gui . DateTimeSpinnersPanel ;32 import mps . gui . commanding . Pr ior i tyView ;33 import mps . gui . t ime l i n e . TimeLineModel ;34 import mps . gui . t ime l i n e . TimeLineView ;3536 import common . except ions . I l l ega lParamete rExcept ion ;37 import common . except ions . UnknownCommandTypeException ;3839 /∗∗40 ∗ <br><br>41 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 342 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 143 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 844 ∗/45 /∗∗46 ∗ @au t h o r Ma l a e u s47 ∗48 ∗/49 public c lass CommandBlockSetupView extends JFrame {5051 /∗∗52 ∗53 ∗/54 private stat ic f ina l long se r ia lVers ionUID = 1L ;5556 /∗∗57 ∗58 ∗/59 private CommandBlockSetupController c o n t r o l l e r ;6061 /∗∗62 ∗63 ∗/64 private long commandBlockIDToEdit ;65 /∗∗66 ∗67 ∗/68 private boolean isEditMode = f a l s e ;6970 /∗∗71 ∗72 ∗/73 private TimeLineView timeLineView ;7475 /∗∗76 ∗77 ∗/78 private DateTimeSpinnersPanel blockStartTimeSpinnersPanel ;7980 /∗∗81 ∗82 ∗/83 private JButton loadButton ;84 /∗∗

Page 178: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

168 Appendix C - Source Code

85 ∗86 ∗/87 private JButton saveButton ;88 /∗∗89 ∗90 ∗/91 private JButton addCommandButton ;92 /∗∗93 ∗94 ∗/95 private JButton editCommandButton ;96 /∗∗97 ∗98 ∗/99 private JButton deleteCommandButton ;

100 /∗∗101 ∗102 ∗/103 private Prior i tyView pr i o r i t yPane l ;104 /∗∗105 ∗106 ∗/107 private JButton sendButton ;108 /∗∗109 ∗110 ∗/111 private JButton cancelButton ;112113 /∗∗114 ∗115 ∗/116 private JTable tab l e ;117 /∗∗118 ∗119 ∗/120 private CommandBlockSetupAbstractTableModel

commandBlockSetupAbstractTableModel ;121 /∗∗122 ∗123 ∗/124 private TableRowSorter<CommandBlockSetupAbstractTableModel> s o r t e r ;125126127 /∗∗128 ∗129 ∗/130 private CommandBlockModel commandBlockModel ;131132 /∗∗ Used t o c o n s t r u c t a Command B l o c k v i e w f o r c r e a t i n g a new command b l o c k133 ∗ @param t im e L i n eV i e w134 ∗/135 public CommandBlockSetupView ( TimeLineView timeLineView ) {136 this . timeLineView = timeLineView ;137138 this . setLayout (new FlowLayout ( FlowLayout .LEADING) ) ;139 this . s e t T i t l e ( ” Create new command block ” ) ;140141 // c r e a t e Command B l o c k Mode l .142 commandBlockModel = new CommandBlockModel ( ) ;143 commandBlockModel . setBlockStartTOE ( System . currentTimeMi l l i s ( ) ) ;144 buildWindow () ;145146 sendButton . setText ( ”<html><b>Create and send new Command Block !</b

></html>” ) ;147 }148149 /∗∗ Used t o c o n s t r u c t a Command B l o c k v i e w f o r e d i t i n g a command b l o c k w h i c h

a l r e a d y e x i s t i n t h e MCC150 ∗ @param t im e L i n eV i e w151 ∗ @param commandB l o c k IDToEd i t The u n i q u e i d o f t h e command b l o c k w h i c h

s h o u l d b e e d i t e d .152 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n153 ∗ @th r ow s UnknownCommandTypeExcep t i on154 ∗ @th r ow s UnknownCommandTypeExcep t i on155 ∗ @th r ow s UnknownCommandTypeExcep t i on156 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n157 ∗ @th r ow s N o tB o u n dE x c e p t i o n158 ∗ @th r ow s R emo t e E x c e p t i o n159 ∗/160 public CommandBlockSetupView ( TimeLineView timeLineView , long

commandBlockIDToEdit ) throws UnknownCommandTypeException ,I l l ega lParamete rExcept ion {

161 this . timeLineView = timeLineView ;162 this . commandBlockIDToEdit = commandBlockIDToEdit ;163 isEditMode = true ;164

Page 179: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 169

165 this . s e t T i t l e ( ” Edit command block \”” + commandBlockIDToEdit + ”\”” );

166167 CommandBlock cbTimeline = TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . getCommandBlockMap ( ) . get ( commandBlockIDToEdit) ;

168 // c r e a t e Command B l o c k Mode l .169 commandBlockModel = new CommandBlockModel ( TimeLineModel . g e t In s tance

( ) . getTimelineData ( ) . getCommandBlockMap ( ) . get (commandBlockIDToEdit ) ) ;

170171172 buildWindow () ;173174 i f ( cbTimeline . g e t P r i o r i t y ( )==CommandBlock .NORMAL PRIORITY)

p r i o r i t yPane l . getNormalPrior ityRadio ( ) . s e t S e l e c t ed ( true ) ;175 else pr i o r i t yPane l . getHighPr ior i tyRadio ( ) . s e t S e l e c t ed ( true ) ;176177 sendButton . setText ( ”<html><b>Modify and send CommandBlock!</b></html

>” ) ;178 }179180 /∗∗181 ∗182 ∗/183 private void buildWindow () {184185186 TimeLineView . s e t I con ( this ) ;187188 c o n t r o l l e r = new CommandBlockSetupController ( this ) ;189190 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;191 GridBagConstraints c = new GridBagConstraints ( ) ;192193 JPanel loadSavePanel = new JPanel ( ) ;194 loadButton = new JButton ( ”Load” ) ;195 saveButton = new JButton ( ”Save” ) ;196 loadSavePanel . add ( loadButton ) ;197 loadSavePanel . add ( saveButton ) ;198 i f ( isEditMode ) {199 loadButton . s e t V i s i b l e ( f a l s e ) ;200 loadButton . setEnabled ( f a l s e ) ;201 }202203 c . gr idwidth = 1 ;204 c . gr idx = 1 ;205 c . gr idy = 0 ;206 c . anchor = GridBagConstraints . LINE END;207 panel . add ( loadSavePanel , c ) ;208209 loadButton . addAct ionListener ( c o n t r o l l e r ) ;210 saveButton . addAct ionListener ( c o n t r o l l e r ) ;211212213 c . gr idx = 0 ;214 c . gr idy = 1 ;215 c . gr idwidth = 2 ;216 c . anchor = GridBagConstraints .CENTER;217 panel . add ( buildCommandsPanel ( ) , c ) ;218219220 p r i o r i t yPane l = new Prior i tyView ( ) ;221 c . gr idx = 0 ;222 c . gr idy = 2 ;223 c . gr idwidth = 2 ;224 c . f i l l = GridBagConstraints .HORIZONTAL;225 c . anchor = GridBagConstraints . FIRST LINE START ;226 panel . add ( pr i o r i tyPane l , c ) ;227228 JPanel sendCancelPanel = new JPanel ( ) ;229 cancelButton = new JButton ( ”Cancel ” ) ;230 sendCancelPanel . add ( cancelButton ) ;231 sendButton = new JButton ( ) ;232 sendCancelPanel . add ( sendButton ) ;233 c . gr idx = 0 ;234 c . gr idwidth = 2 ;235 c . gr idy = 3 ;236 c . anchor = GridBagConstraints . LAST LINE END ;237 panel . add ( sendCancelPanel , c ) ;238239 this . add ( panel ) ;240241242 // LISTENERS243 tab l e . getSe l ect ionMode l ( ) . addL i s t S e l e c t i onL i s t en e r ( c o n t r o l l e r ) ;244

Page 180: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

170 Appendix C - Source Code

245 addCommandButton . addAct ionListener ( c o n t r o l l e r ) ;246 editCommandButton . addAct ionListener ( c o n t r o l l e r ) ;247 deleteCommandButton . addAct ionListener ( c o n t r o l l e r ) ;248 sendButton . addAct ionListener ( c o n t r o l l e r ) ;249 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;250251 blockStartTimeSpinnersPanel . getTimeSDM () . addChangeListener ( c o n t r o l l e r ) ;252 blockStartTimeSpinnersPanel . getDateSDM () . addChangeListener ( c o n t r o l l e r ) ;253254255 this . pack ( ) ;256 this . s e tLocat ionRe lat iveTo ( null ) ;257 this . s e t V i s i b l e ( true ) ;258259 }260261 /∗∗262 ∗ @r e t u r n263 ∗/264 private JPanel buildCommandsPanel ( ) {265 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;266267 Tit ledBorder t i t l e = BorderFactory . c r ea teTi t l edBorder ( BorderFactory .

createEtchedBorder ( EtchedBorder .LOWERED) ,268 ”Commands in block ” , Tit ledBorder .LEFT, Tit ledBorder

.CENTER ,new Font ( ”Tahoma” , Font .BOLD,11 ) ) ;269 panel . setBorder ( BorderFactory . c r ea teT i t l edBorder ( t i t l e ) ) ;270271 panel . setBorder ( t i t l e ) ;272273 GridBagConstraints c = new GridBagConstraints ( ) ;274275 JPanel blockStartTimePanel = new JPanel ( ) ;276 blockStartTimePanel . add (new JLabel ( ”Block s t a r t time : ” ) ) ;277 blockStartTimeSpinnersPanel = new DateTimeSpinnersPanel ( ) ;278 blockStartTimeSpinnersPanel . setTime ( commandBlockModel .

getBlockStartTOE () ) ;279 blockStartTimePanel . add ( blockStartTimeSpinnersPanel ) ;280281 c . gr idwidth = 2 ;282 c . anchor = GridBagConstraints . LAST LINE END ;283 c . gr idx = 0 ;284 c . gr idy = 0 ;285286 panel . add ( blockStartTimePanel , c ) ;287288289 commandBlockSetupAbstractTableModel = new

CommandBlockSetupAbstractTableModel ( this ) ;290 s o r t e r = new TableRowSorter<CommandBlockSetupAbstractTableModel >(

commandBlockSetupAbstractTableModel ) ;291 tab l e = new JTable ( commandBlockSetupAbstractTableModel ) ;292 tab l e . setRowSorter ( s o r t e r ) ;293294 tab l e . s e tP r e f e r r edSc r o l l ab l eV i ewpo r tS i z e (new Dimension (795 , 100) ) ;295 tab l e . s e tF i l l sV i ewpor tHe ight ( true ) ;296 tab l e . se tDefau l tRenderer ( Object . class , new MyTableCellRenderer ( ) ) ;297 // D i s a b l e a u t o r e s i z i n g298 tab l e . setAutoResizeMode ( JTable .AUTO RESIZE OFF) ;299300 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

. ID COLUMN) . setPre ferredWidth (30) ;301 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.NO COLUMN) . setPre ferredWidth (30) ;302 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.NAME COLUMN) . setPreferredWidth (150) ;303 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.SUBSYSTEM COLUMN) . setPreferredWidth (60) ;304 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.PARAMETERS COLUMN) . setPre ferredWidth (145) ;305 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

. TOE IS ASAP) . setPreferredWidth (50) ;306 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.TOE OFFSET) . setPre ferredWidth (65) ;307 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.TOE OFFSET UNIT) . setPre ferredWidth (40) ;308 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.TOE COLUMN) . setPreferredWidth (120) ;309 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.PASS COLUMN) . setPreferredWidth (50) ;310 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.STATE COLUMN) . setPreferredWidth (50) ;311312 tab l e . setSe lect ionMode ( L i s tSe l e c t i onMode l . SINGLE SELECTION) ;313314 // C r e a t e s p e c i a l e d i t o r f o r Un i t c o l umn315 JComboBox unitComboBox = new JComboBox ( ) ;

Page 181: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 171

316 unitComboBox . addItem ( Of f s e t .MILISECONDS) ;317 unitComboBox . addItem ( Of f s e t .SECONDS) ;318 unitComboBox . addItem ( Of f s e t .MINUTES) ;319 unitComboBox . addItem ( Of f s e t .HOURS) ;320 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.TOE OFFSET UNIT) . s e tCe l lEd i t o r (new Defau l tCe l lEd i to r (unitComboBox ) ) ;

321322 // C r e a t e s p e c i a l e d i t o r f o r Pa s s co l umn323 ArrayList<Pass> passe s = TimeLineModel . g e t In s tance ( ) .

getUpcomingOpenPasses ( ) ;324 JComboBox passComboBox = new JComboBox ( ) ;325 passComboBox . addItem ( ”AUTO” ) ;326 passComboBox . addItem ( ”−−−−−” ) ;327328 for ( Pass p : passe s ) {329 passComboBox . addItem (p . getPassID ( ) ) ;330 }331 tab l e . getColumnModel ( ) . getColumn ( CommandBlockSetupAbstractTableModel

.PASS COLUMN) . s e tCe l lEd i t o r (new Defau l tCe l lEd i to r ( passComboBox )) ;

332333334335 JScro l lPane s c ro l lPane = new JScro l lPane ( tab l e ) ;336 s c ro l lPane . setMinimumSize (new Dimension (795 ,100) ) ;337 s c ro l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .VERTICAL SCROLLBAR ALWAYS)

;338 s c ro l lPane . s e tHo r i z on ta l S c r o l lBa rPo l i c y ( JScro l lPane .

HORIZONTAL SCROLLBAR AS NEEDED) ;339 c . anchor = GridBagConstraints .CENTER;340 c . gr idwidth = 2 ;341 c . gr idx = 0 ;342 c . gr idy = 1 ;343 panel . add ( scro l lPane , c ) ;344345 addCommandButton = new JButton ( ”Add Command . . ” ) ;346 c . gr idwidth = 1 ;347 c . anchor = GridBagConstraints .LINE START;348 c . gr idx = 0 ;349 c . gr idy = 2 ;350 panel . add (addCommandButton , c ) ;351352 JPanel ed i tDe l e t ePane l = new JPanel ( ) ;353 ed i tDe l e t ePane l . add (new JLabel ( ” S e l e c t i on ” ) ) ;354 editCommandButton = new JButton ( ” Edit ” ) ;355 editCommandButton . setEnabled ( f a l s e ) ;356 ed i tDe l e t ePane l . add ( editCommandButton ) ;357 deleteCommandButton = new JButton ( ” Delete ” ) ;358 deleteCommandButton . setEnabled ( f a l s e ) ;359 ed i tDe l e t ePane l . add ( deleteCommandButton ) ;360 c . gr idx = 1 ;361 c . anchor = GridBagConstraints . LINE END;362 panel . add ( ed i tDe letePane l , c ) ;363364 return panel ;365 }366367368 /∗∗369 ∗ @r e t u r n370 ∗/371 public CommandBlockSetupController g e tCont r o l l e r ( ) {372 return c o n t r o l l e r ;373 }374375 /∗∗376 ∗ @r e t u r n377 ∗/378 public TimeLineView getTimeLineView ( ) {379 return timeLineView ;380 }381382 /∗∗383 ∗ @r e t u r n384 ∗/385 public JButton getLoadButton ( ) {386 return loadButton ;387 }388389 /∗∗390 ∗ @r e t u r n391 ∗/392 public JButton getSaveButton ( ) {393 return saveButton ;394 }395

Page 182: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

172 Appendix C - Source Code

396 /∗∗397 ∗ @r e t u r n398 ∗/399 public JButton getAddCommandButton ( ) {400 return addCommandButton ;401 }402403 /∗∗404 ∗ @r e t u r n405 ∗/406 public JButton getEditCommandButton ( ) {407 return editCommandButton ;408 }409410 /∗∗411 ∗ @r e t u r n412 ∗/413 public JButton getDeleteCommandButton ( ) {414 return deleteCommandButton ;415 }416417 /∗∗418 ∗ @r e t u r n419 ∗/420 public Prior i tyView ge tPr i o r i t yPane l ( ) {421 return pr i o r i t yPane l ;422 }423424 /∗∗425 ∗ @r e t u r n426 ∗/427 public JButton getSendButton ( ) {428 return sendButton ;429 }430431 /∗∗432 ∗ @r e t u r n433 ∗/434 public JButton getCancelButton ( ) {435 return cancelButton ;436 }437438 /∗∗439 ∗ @r e t u r n440 ∗/441 public JTable getTable ( ) {442 return tab l e ;443 }444445 /∗∗446 ∗ @r e t u r n447 ∗/448 public CommandBlockSetupAbstractTableModel getCreateCommandBlockTableModel ( )

{449 return commandBlockSetupAbstractTableModel ;450 }451452 /∗∗453 ∗ @r e t u r n454 ∗/455 public boolean isEditMode ( ) {456 return isEditMode ;457 }458459 /∗∗460 ∗ @r e t u r n461 ∗/462 public CommandBlockModel getCommandBlockModel ( ) {463 return commandBlockModel ;464 }465466 /∗∗467 ∗ @r e t u r n468 ∗/469 public DateTimeSpinnersPanel getBlockStartTimeSpinnersPanel ( ) {470 return blockStartTimeSpinnersPanel ;471 }472473 /∗∗474 ∗ @r e t u r n475 ∗/476 public long getCommandBlockIDToEdit ( ) {477 return commandBlockIDToEdit ;478 }479480 }481

Page 183: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 173

482483 /∗∗484 ∗ <br><br>485 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3486 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 1487 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 8488 ∗/489 c lass MyTableCellRenderer extends DefaultTableCel lRenderer {490491 public Component getTableCellRendererComponent ( JTable table , Object value ,

boolean i s S e l e c t ed , boolean hasFocus , int row , int column ) {492493 Component c = super . getTableCellRendererComponent ( table , value ,

i s S e l e c t ed , hasFocus , row , column ) ;494 i f ( column == CommandBlockSetupAbstractTableModel . ID COLUMN | |

column == CommandBlockSetupAbstractTableModel .NO COLUMN495 | | column == CommandBlockSetupAbstractTableModel .

NAME COLUMN | | column ==CommandBlockSetupAbstractTableModel .PARAMETERS COLUMN

496 | | column == CommandBlockSetupAbstractTableModel .TOE COLUMN | | column ==CommandBlockSetupAbstractTableModel .STATE COLUMN

497 | | column == CommandBlockSetupAbstractTableModel .SUBSYSTEM COLUMN) {

498499 c . setForeground ( Color .GRAY) ;500 c . setFont (new Font ( ”Tahoma” , Font . ITALIC ,11 ) ) ;501502 } else {503 c . setForeground ( Color . b lack ) ;504 c . setFont (new Font ( ”Tahoma” , Font .PLAIN,11 ) ) ;505 }506507 return c ;508 }509510 }

Page 184: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

174 Appendix C - Source Code

.1.34 Offset.java

1 package mps . gui . commanding . block ;23 import org . simpleframework . xml . Attr ibute ;45 /∗∗6 ∗ <br><br>7 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 38 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 19 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 8

10 ∗/11 public c lass Of f s e t {121314 public stat ic f ina l Str ing MILISECONDS = ”ms” ;15 public stat ic f ina l Str ing SECONDS = ” s ” ;16 public stat ic f ina l Str ing MINUTES = ”m” ;17 public stat ic f ina l Str ing HOURS = ”h” ;1819 @Attribute20 private long value ;2122 @Attribute23 private Str ing unit ;2425 public Of f s e t ( ) {26 value = 0 ;27 unit = SECONDS;28 }2930 /∗∗31 ∗ @param o f f s e t32 ∗ @param u n i t33 ∗/34 public Of f s e t ( long o f f s e t , S t r ing unit ) {35 this . va lue = o f f s e t ;36 this . un i t = unit ;37 }3839 /∗∗40 ∗ @r e t u r n41 ∗/42 public long ge tOf fSe t InMi l i s e conds ( ) {4344 i f ( uni t . equa l s (MILISECONDS) ) return value ;45 else i f ( uni t . equa l s (SECONDS) ) return value ∗1000;46 else i f ( uni t . equa l s (MINUTES) ) return value ∗1000∗60;47 else i f ( uni t . equa l s (HOURS) ) return value ∗1000∗60∗60;4849 throw new I l l ega lArgumentExcept ion ( ” I l l e g a l uni t ” ) ;50 }515253 /∗∗54 ∗ @r e t u r n55 ∗/56 public long getValue ( ) {57 return value ;58 }596061 /∗∗62 ∗ @r e t u r n63 ∗/64 public Str ing getUnit ( ) {65 return unit ;66 }6768 /∗∗69 ∗ @param u n i t70 ∗/71 public void setUnit ( St r ing unit ) {72 this . un i t = unit ;73 }7475 /∗∗76 ∗ @param o f f s e t77 ∗/78 public void s e t O f f s e t ( long o f f s e t ) {79 this . va lue = o f f s e t ;80 }8182 }

Page 185: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 175

.1.35 LoadCommandBlockController.java

1 package mps . gui . commanding . block . save load ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;56 import javax . swing . JOptionPane ;7 import javax . swing . event . L i s tSe l e c t i onEvent ;8 import javax . swing . event . L i s t S e l e c t i o n L i s t e n e r ;9

10 import mps . gui . t ime l i n e . TimeLineModel ;1112 import common . except ions . I l l ega lParamete rExcept ion ;13 import common . except ions . UnknownCommandTypeException ;1415 /∗∗16 ∗ <br><br>17 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 318 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 119 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 820 ∗/21 public c lass LoadCommandBlockController implements Act ionListener ,

L i s t S e l e c t i o n L i s t e n e r {2223 /∗∗24 ∗25 ∗/26 private LoadCommandBlockView view ;2728 /∗∗29 ∗ @param v i e w30 ∗/31 public LoadCommandBlockController (LoadCommandBlockView view ) {32 this . view = view ;33 }3435 @Override36 public void act ionPerformed ( ActionEvent ae ) {3738 i f ( ae . getSource ( ) . equa l s ( view . getLoadButton ( ) ) ) {39 // LOAD4041 // f i n d command b l o c k42 for ( PredefinedCommandBlock pcb : TimeLineModel . g e t In s tance ( )

. getPredefinedCommandBlocksSaveObject ( ) .getPreDefinedCommandBlocks ( ) ) {

4344 i f ( pcb . getName ( ) . equa l s ( view . getCommandBlockList ( ) .

ge tSe l ec tedValue ( ) . t oS t r ing ( ) ) ) {4546 // i f P r e d e f i n e d command b l o c k s name ma t c h e s

t h e s e l e c t e d t e x t47 try {48 view . getCreateCommandBlockView ( ) .

getCommandBlockModel ( ) .buildFromPredefinedCommandBlock( pcb ) ;

49 view . getCreateCommandBlockView ( ) .getTable ( ) . r epa in t ( ) ;

50 view . d i spose ( ) ;5152 } catch (UnknownCommandTypeException e ) {53 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

54 e . pr intStackTrace ( ) ;55 } catch ( I l l ega lParamete rExcept ion e ) {56 JOptionPane . showMessageDialog ( view , e

. getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

57 e . pr intStackTrace ( ) ;58 }59 break ;60 }61 }626364 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {6566 view . d i spose ( ) ;67 }6869 }7071 @Override

Page 186: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

176 Appendix C - Source Code

72 public void valueChanged ( L i s tSe l e c t i onEvent l s e ) {73 view . updateDescr ipt ionLabe l ( ) ;74 }7576 }

Page 187: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 177

.1.36 LoadCommandBlockView.java

1 package mps . gui . commanding . block . save load ;23 import java . awt . Dimension ;4 import java . awt . Font ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;7 import java . awt . I n s e t s ;89 import javax . swing . BorderFactory ;

10 import javax . swing . JButton ;11 import javax . swing . JDialog ;12 import javax . swing . JLabel ;13 import javax . swing . JL i s t ;14 import javax . swing . JPanel ;15 import javax . swing . JScro l lPane ;16 import javax . swing . L i s tSe l e c t i onMode l ;17 import javax . swing . border . EtchedBorder ;18 import javax . swing . border . Tit ledBorder ;1920 import mps . gui . commanding . block . CommandBlockSetupView ;21 import mps . gui . t ime l i n e . TimeLineModel ;2223 /∗∗24 ∗ <br><br>25 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 326 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 127 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 828 ∗/29 public c lass LoadCommandBlockView extends JDialog {3031 /∗∗32 ∗33 ∗/34 private stat ic f ina l long se r ia lVers ionUID = 1L ;3536 /∗∗37 ∗38 ∗/39 private JL i s t commandBlockList ;40 /∗∗41 ∗42 ∗/43 private JLabel de s c r i p t i onLabe l ;4445 /∗∗46 ∗47 ∗/48 private JButton loadButton ;49 /∗∗50 ∗51 ∗/52 private JButton cancelButton ;5354 /∗∗55 ∗56 ∗/57 private CommandBlockSetupView commandBlockSetupView ;5859 /∗∗60 ∗61 ∗/62 private PredefinedCommandBlocksSaveObject saveObject ;6364 /∗∗65 ∗66 ∗/67 private LoadCommandBlockController c o n t r o l l e r ;6869 /∗∗70 ∗ @param commandB l o c k S e t u pV i ew71 ∗/72 public LoadCommandBlockView( CommandBlockSetupView commandBlockSetupView ) {7374 super ( commandBlockSetupView , true ) ;7576 this . commandBlockSetupView = commandBlockSetupView ;77 saveObject = TimeLineModel . g e t In s tance ( ) .

getPredefinedCommandBlocksSaveObject ( ) ;7879 // t h i s . s e t M o d a l ( t r u e ) ;8081 c o n t r o l l e r = new LoadCommandBlockController ( this ) ;8283 this . s e t T i t l e ( ”Load Command Block” ) ;

Page 188: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

178 Appendix C - Source Code

8485 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;8687 GridBagConstraints c = new GridBagConstraints ( ) ;8889 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;90 c . gr idwidth = 1 ;91 c . anchor = GridBagConstraints .LINE START;929394 commandBlockList = new JL i s t ( saveObject . getPreDefinedCommandBlocks ( )

. toArray ( ) ) ; // d a t a h a s t y p e O b j e c t [ ]95 commandBlockList . setSe lect ionMode ( L i s tSe l e c t i onMode l .

SINGLE INTERVAL SELECTION) ;96 commandBlockList . se tLayoutOr ientat ion ( JL i s t .HORIZONTAL WRAP) ;97 commandBlockList . setVisibleRowCount (−1) ;9899 JScro l lPane l i s t S c r o l l e r = new JScro l lPane ( commandBlockList ) ;

100 l i s t S c r o l l e r . s e t P r e f e r r e d S i z e (new Dimension (250 , 80) ) ;101102 c . gr idy = 0 ;103 c . gr idx = 0 ;104 panel . add ( l i s t S c r o l l e r , c ) ;105106 de s c r i p t i onLabe l = new JLabel ( ”” ) ;107 de s c r i p t i onLabe l . s e tVe r t i c a lTex tPo s i t i on ( JLabel .TOP) ;108 Tit ledBorder t i t l e = BorderFactory . c r ea teTi t l edBorder ( BorderFactory .

createEtchedBorder ( EtchedBorder .LOWERED) ,109 ” Desc r ip t i on ” , Tit ledBorder .LEFT, Tit ledBorder .

CENTER ,new Font ( ”Tahoma” , Font .BOLD,11 ) ) ;110 de s c r i p t i onLabe l . setBorder ( BorderFactory . c r ea teT i t l edBorder ( t i t l e ) ) ;111 de s c r i p t i onLabe l . s e t P r e f e r r e d S i z e (new Dimension (250 ,80) ) ;112 c . gr idy = 1 ;113 c . gr idx = 0 ;114 panel . add ( desc r ip t i onLabe l , c ) ;115116117 JPanel loadCancelPanel = new JPanel ( ) ;118 loadButton = new JButton ( ”Load” ) ;119 cancelButton = new JButton ( ”Cancel ” ) ;120 loadCancelPanel . add ( cancelButton ) ;121 loadCancelPanel . add ( loadButton ) ;122 c . gr idy = 2 ;123 c . gr idx = 0 ;124 c . anchor = GridBagConstraints . LINE END;125 panel . add ( loadCancelPanel , c ) ;126127128 loadButton . addAct ionListener ( c o n t r o l l e r ) ;129 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;130 commandBlockList . addL i s t S e l e c t i onL i s t en e r ( c o n t r o l l e r ) ;131132 this . add ( panel ) ;133 this . pack ( ) ;134135 this . s e tLocat ionRe lat iveTo ( null ) ;136 this . s e t V i s i b l e ( true ) ;137 }138139140 /∗∗141 ∗142 ∗/143 public void updateDescr ipt ionLabe l ( ) {144145 for ( PredefinedCommandBlock pcb : saveObject .

getPreDefinedCommandBlocks ( ) ) {146 i f ( pcb . getName ( ) . equa l s ( commandBlockList .

ge tSe l ec tedValue ( ) . t oSt r ing ( ) ) ) {147 de s c r i p t i onLabe l . setText ( pcb . ge tDesc r ip t i on ( ) ) ;148 break ;149 }150 }151 de s c r i p t i onLabe l . s e tVe r t i c a lTex tPo s i t i on ( JLabel .TOP) ;152 }153154155 /∗∗156 ∗ @r e t u r n157 ∗/158 public JButton getLoadButton ( ) {159 return loadButton ;160 }161162163 /∗∗164 ∗ @r e t u r n

Page 189: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 179

165 ∗/166 public JButton getCancelButton ( ) {167 return cancelButton ;168 }169170 /∗∗171 ∗ @r e t u r n172 ∗/173 public JL i s t getCommandBlockList ( ) {174 return commandBlockList ;175 }176177178 /∗∗179 ∗ @r e t u r n180 ∗/181 public CommandBlockSetupView getCreateCommandBlockView ( ) {182 return commandBlockSetupView ;183 }184185186187 }

Page 190: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

180 Appendix C - Source Code

.1.37 PredefinedCommand.java

1 package mps . gui . commanding . block . save load ;23 import mps . gui . commanding . block . O f f s e t ;45 import org . simpleframework . xml . Element ;678 /∗∗9 ∗ <br><br>

10 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 311 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 112 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 813 ∗/14 public c lass PredefinedCommand {1516 @Element17 private Str ing commandData ;1819 @Element20 private Of f s e t o f f s e t ;2122 @Element23 private boolean asapTOE ;2425 /∗∗ C r e a t e s a Pr ed e f i n e dCommand w i t h TOE a s ASAP26 ∗ @param commandData27 ∗/28 public PredefinedCommand ( St r ing commandData) {29 this . commandData = commandData ;30 asapTOE = true ;31 this . o f f s e t = new Of f s e t ( ) ;32 }3334 /∗∗ C r e a t e s a Pr ed e f i n e dCommand w i t h a O f f s e t on TOE35 ∗ @param commandData36 ∗ @param o f f s e t37 ∗/38 public PredefinedCommand ( St r ing commandData , O f f s e t o f f s e t ) {39 this . commandData = commandData ;40 this . o f f s e t = o f f s e t ;41 asapTOE = f a l s e ;42 }4344 /∗∗45 ∗ Empty c o n s t r u c t o r . T h i s i s n e e d e d b y t h e S im p l e XML f r amewo r k46 ∗/47 public PredefinedCommand ( ) {4849 }5051 /∗∗52 ∗ @r e t u r n53 ∗/54 public Str ing getCommandInfo ( ) {55 return commandData ;56 }5758 /∗∗59 ∗ @r e t u r n60 ∗/61 public Of f s e t g e tO f f s e t ( ) {62 return o f f s e t ;63 }6465 /∗∗66 ∗ @r e t u r n67 ∗/68 public boolean isAsapTOE () {69 return asapTOE ;70 }7172 }

Page 191: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 181

.1.38 PredefinedCommandBlock.java

1 package mps . gui . commanding . block . save load ;23 import java . u t i l . ArrayList ;45 import org . simpleframework . xml . Attr ibute ;6 import org . simpleframework . xml . Element ;7 import org . simpleframework . xml . ElementList ;89

10 /∗∗11 ∗ <br><br>12 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 313 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 114 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 815 ∗/16 public c lass PredefinedCommandBlock {1718 @Attribute19 private Str ing name ;2021 @Element22 private Str ing d e s c r i p t i on ;2324 @ElementList25 private ArrayList<PredefinedCommand> commands ;2627 /∗∗28 ∗ @param name29 ∗ @param d e s c r i p t i o n30 ∗/31 public PredefinedCommandBlock ( St r ing name , St r ing d e s c r i p t i on ) {32 this . name = name ;33 this . d e s c r i p t i on = de s c r i p t i on ;34 commands = new ArrayList<PredefinedCommand >() ;35 }3637 /∗∗38 ∗39 ∗/40 public PredefinedCommandBlock ( ) {41 commands = new ArrayList<PredefinedCommand >() ;42 }434445 /∗∗46 ∗ @r e t u r n47 ∗/48 public Str ing getName ( ) {49 return name ;50 }5152 /∗∗53 ∗ @param name54 ∗/55 public void setName ( St r ing name) {56 this . name = name ;57 }5859 /∗∗60 ∗ @r e t u r n61 ∗/62 public Str ing ge tDesc r ip t i on ( ) {63 return de s c r i p t i on ;64 }6566 /∗∗67 ∗ @param d e s c r i p t i o n68 ∗/69 public void s e tDe s c r i p t i on ( St r ing d e s c r i p t i on ) {70 this . d e s c r i p t i on = de s c r i p t i on ;71 }7273 /∗∗74 ∗ @r e t u r n75 ∗/76 public ArrayList<PredefinedCommand> getCommands ( ) {77 return commands ;78 }7980 public Str ing toSt r ing ( ) {81 return name ;82 }8384

Page 192: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

182 Appendix C - Source Code

85 }

Page 193: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 183

.1.39 PredefinedCommandBlocksSaveObject.java

1 package mps . gui . commanding . block . save load ;23 import java . u t i l . ArrayList ;45 import org . simpleframework . xml . ElementList ;6 import org . simpleframework . xml . Root ;78 /∗∗9 ∗ <br><br>

10 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 311 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 112 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 813 ∗/14 @Root15 public c lass PredefinedCommandBlocksSaveObject {1617 /∗∗18 ∗19 ∗/20 @ElementList21 private ArrayList<PredefinedCommandBlock> preDefinedCommandBlocks ;2223 /∗∗24 ∗25 ∗/26 public PredefinedCommandBlocksSaveObject ( ) {27 preDefinedCommandBlocks = new ArrayList<PredefinedCommandBlock >() ;28 }293031 /∗∗32 ∗ @r e t u r n33 ∗/34 public ArrayList<PredefinedCommandBlock> getPreDefinedCommandBlocks ( ) {35 return preDefinedCommandBlocks ;36 }3738 /∗∗39 ∗ @param b l o c k40 ∗/41 public void add ( PredefinedCommandBlock block ) {42 preDefinedCommandBlocks . add ( block ) ;43 }4445 /∗∗46 ∗ @r e t u r n47 ∗/48 public int s i z e ( ) {49 return preDefinedCommandBlocks . s i z e ( ) ;50 }51525354 }

Page 194: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

184 Appendix C - Source Code

.1.40 SaveCommandBlockController.java

1 package mps . gui . commanding . block . save load ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;56 import javax . swing . JOptionPane ;78 import mps . gui . t ime l i n e . TimeLineModel ;9

10 /∗∗11 ∗ <br><br>12 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 313 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 114 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 815 ∗/16 public c lass SaveCommandBlockController implements Act ionL i s t ener {1718 /∗∗19 ∗20 ∗/21 private SaveCommandBlockView view ;2223 /∗∗24 ∗ @param v i e w25 ∗/26 public SaveCommandBlockController ( SaveCommandBlockView view ) {27 this . view = view ;28 }2930 @Override31 public void act ionPerformed ( ActionEvent ae ) {323334 i f ( ae . getSource ( ) . equa l s ( view . getSaveButton ( ) ) ) {3536 St r ing name = view . getNameTextField ( ) . getText ( ) ;37 St r ing d e s c r i p t i on = view . getDescr ipt ionEditorPane ( ) . getText

( ) ;3839 PredefinedCommandBlock pcb = view . getPreDefinedCommandBlock

( ) ;40 pcb . setName (name) ;41 pcb . s e tDe s c r i p t i on ( d e s c r i p t i on ) ;4243 // Get t h e s a v e o b j e c t44 PredefinedCommandBlocksSaveObject saveObject = TimeLineModel

. g e t In s tance ( ) . getPredefinedCommandBlocksSaveObject ( ) ;4546 // T e s t i f name i s a l r e a d y u s e d i n a n o t h e r p r e d e f i n e d

command b l o c k47 boolean sameName = f a l s e ;48 for ( PredefinedCommandBlock p : saveObject .

getPreDefinedCommandBlocks ( ) ) {49 i f (p . getName ( ) . equa l s IgnoreCase ( ( name) ) ) {50 sameName = true ;51 break ;52 }53 }54 i f (sameName) {55 JOptionPane . showMessageDialog ( view , ”<html>There

a l ready e x i s t a Command Block with the name ”56 + name + ”<br>Please s p e c i f y another

one .</html>” , ”Name al readyused” , JOptionPane .INFORMATION MESSAGE) ;

57 } else {5859 // add new command b l o c k60 saveObject . add ( pcb ) ;61 try {62 // S e r i a l i z e o b j e c t a g a i n and s a v e63 TimeLineModel . g e t In s tance ( ) .

savePredefinedCommandBlocksFile (saveObject ) ;

64 } catch ( Exception e ) {65 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

66 e . pr intStackTrace ( ) ;67 }6869 view . d i spose ( ) ;70 }71

Page 195: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 185

72737475 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {76 view . d i spose ( ) ;77 }7879 }808182838485 }

Page 196: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

186 Appendix C - Source Code

.1.41 SaveCommandBlockView.java

1 package mps . gui . commanding . block . save load ;23 import java . awt . Dimension ;4 import java . awt . GridBagConstraints ;5 import java . awt . GridBagLayout ;6 import java . awt . I n s e t s ;78 import javax . swing . JButton ;9 import javax . swing . JDialog ;

10 import javax . swing . JEditorPane ;11 import javax . swing . JLabel ;12 import javax . swing . JPanel ;13 import javax . swing . JScro l lPane ;14 import javax . swing . JTextField ;1516 import mps . gui . commanding . block . CommandBlockSetupView ;1718 /∗∗19 ∗ <br><br>20 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 321 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 122 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 823 ∗/24 public c lass SaveCommandBlockView extends JDialog {252627 /∗∗28 ∗29 ∗/30 private stat ic f ina l long se r ia lVers ionUID = 1L ;3132 /∗∗33 ∗34 ∗/35 private JTextField nameTextField ;36 /∗∗37 ∗38 ∗/39 private JEditorPane descr ipt ionEdi torPane ;40 /∗∗41 ∗42 ∗/43 private JButton saveButton ;44 /∗∗45 ∗46 ∗/47 private JButton cancelButton ;4849 /∗∗50 ∗51 ∗/52 private SaveCommandBlockController c o n t r o l l e r ;53 /∗∗54 ∗55 ∗/56 private PredefinedCommandBlock preDefinedCommandBlock ;5758 /∗∗59 ∗ @param commandB l o c k S e t u pV i ew60 ∗ @param p r eDe f i n e dCommandB l o c k61 ∗/62 public SaveCommandBlockView( CommandBlockSetupView commandBlockSetupView ,

PredefinedCommandBlock preDefinedCommandBlock ) {63 super ( commandBlockSetupView , true ) ;6465 c o n t r o l l e r = new SaveCommandBlockController ( this ) ;66 this . preDefinedCommandBlock = preDefinedCommandBlock ;6768 // T imeL in eV i ew . s e t I c o n ( t h i s ) ;69 this . s e t T i t l e ( ”Save Command Block” ) ;70 this . setModal ( true ) ;7172 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;7374 GridBagConstraints c = new GridBagConstraints ( ) ;7576 c . gr idy = 0 ;77 c . gr idx = 0 ;78 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;79 c . gr idwidth = 1 ;80 c . anchor = GridBagConstraints .LINE START;8182 panel . add (new JLabel ( ”Name : ” ) , c ) ;83

Page 197: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 187

84 nameTextField = new JTextField ( ) ;85 nameTextField . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;86 c . anchor = GridBagConstraints .LINE START;87 c . gr idx = 1 ;88 panel . add ( nameTextField , c ) ;8990 c . gr idy = 1 ;91 c . gr idx = 0 ;9293 panel . add (new JLabel ( ” Desc r ip t i on : ” ) , c ) ;9495 desc r ipt ionEdi torPane = new JEditorPane ( ) ;96 JScro l lPane de s c r i p t i onSc ro l lPane = new JScro l lPane (

desc r ipt ionEdi torPane ) ;97 de s c r i p t i onSc r o l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .

VERTICAL SCROLLBAR ALWAYS) ;98 de s c r i p t i onSc r o l lPane . s e t P r e f e r r e d S i z e (new Dimension (220 , 100) ) ;99 de s c r i p t i onSc r o l lPane . setMinimumSize (new Dimension (10 , 10) ) ;

100 c . anchor = GridBagConstraints .LINE START;101 c . gr idx = 1 ;102 panel . add ( de s c r ip t i onSc ro l lPane , c ) ;103104105 JPanel saveCancelPanel = new JPanel ( ) ;106 saveButton = new JButton ( ”Save” ) ;107 cancelButton = new JButton ( ”Cancel ” ) ;108 saveCancelPanel . add ( cancelButton ) ;109 saveCancelPanel . add ( saveButton ) ;110 c . gr idy = 2 ;111 c . gr idx = 0 ;112 c . anchor = GridBagConstraints . LINE END;113 panel . add ( saveCancelPanel , c ) ;114115116117 saveButton . addAct ionListener ( c o n t r o l l e r ) ;118 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;119120 this . add ( panel ) ;121122 this . pack ( ) ;123 this . s e tLocat ionRe lat iveTo ( null ) ;124 this . s e t V i s i b l e ( true ) ;125 }126127 /∗∗128 ∗ @r e t u r n129 ∗/130 public JTextField getNameTextField ( ) {131 return nameTextField ;132 }133134 /∗∗135 ∗ @r e t u r n136 ∗/137 public JEditorPane getDescr ipt ionEditorPane ( ) {138 return descr ipt ionEdi torPane ;139 }140141 /∗∗142 ∗ @r e t u r n143 ∗/144 public JButton getSaveButton ( ) {145 return saveButton ;146 }147148 /∗∗149 ∗ @r e t u r n150 ∗/151 public JButton getCancelButton ( ) {152 return cancelButton ;153 }154155 /∗∗156 ∗ @r e t u r n157 ∗/158 public PredefinedCommandBlock getPreDefinedCommandBlock ( ) {159 return preDefinedCommandBlock ;160 }161162 }

Page 198: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

188 Appendix C - Source Code

.1.42 CountDownLabel.java

1 package mps . gui . passwindow ;23 import java . awt . Color ;4 import java . awt . event . ActionEvent ;5 import java . awt . event . Act ionL i s t ener ;6 import java . text . DateFormat ;7 import java . u t i l . Calendar ;89 import javax . swing . JLabel ;

10 import javax . swing . Timer ;1112 import mcc . s e rv e r . dataProcess ing . Pass ;13 import mps . gui . t ime l i n e . TimeLineModel ;1415 /∗∗16 ∗ Time p a n e l . T h i s w i l l s how t h e c u r r e n t t im e .17 ∗ A t i m e r t o u p d a t e t h e t im e i s s t a r t e d when t h e c omponen t18 ∗ i s a d d e d t o i t s p a r e n t and s t o p p e d when r emov e d f r om i t s p a r e n t .19 ∗20 ∗ @au t h o r <A HREF=” m a i l t o : v i n o d . s i g h @ a g i l e o b j e c t s i n c . com”>Vinod Kumar S i n g h </A>21 ∗/22 public c lass CountDownLabel extends JLabel implements Act ionL i s t ener23 {24 /∗∗25 ∗26 ∗/27 private stat ic f ina l long se r ia lVers ionUID = 1L ;2829 /∗∗ Timer t h a t u p d a t e s t im e . ∗/30 private Timer timer ;3132 /∗∗ Used t o f o rm a t t h e d i s p l a y e d d a t e . ∗/33 private DateFormat dateFormat = DateFormat . getTimeInstance ( DateFormat .MEDIUM

) ;3435 private Pass nextPass ;36 private Str ing txt ;3738 /∗∗39 ∗ D e f a u l t c o n s t r u c t o r .40 ∗ @param p a s sw i n d owV i ew41 ∗/42 public CountDownLabel ( )43 {44 super ( ”” , JLabel .CENTER) ;4546 nextPass = TimeLineModel . g e t In s tance ( ) . getNextOpenPass ( ) ;47 }4849 /∗∗50 ∗ Add componen t t o i t s p a r e n t . S t a r t t h e t i m e r f o r au t o−u p d a t e .51 ∗/52 public void addNotify ( )53 {54 super . addNotify ( ) ;55 timer = new Timer (1000 , this ) ;56 timer . s t a r t ( ) ;57 }5859 /∗∗60 ∗ Remove c omponen t f r om i t s p a r e n t . S t o p t h e t i m e r .61 ∗/62 public void removeNotify ( )63 {64 super . removeNotify ( ) ;65 i f ( t imer != null )66 {67 timer . stop ( ) ;68 timer = null ;69 }70 }7172 /∗∗73 ∗ Upda t e c omponen t w i t h t h e c u r r e n t t im e .74 ∗75 ∗ @param e v t The c u r r e n t e v e n t .76 ∗/77 public void act ionPerformed ( ActionEvent evt )78 {7980 i f ( ! TimeLineModel . g e t In s tance ( ) . i sWithinPass ( ) ) {81 nextPass = TimeLineModel . g e t In s tance ( ) . getNextOpenPass ( ) ;82 }83

Page 199: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 189

8485 i f ( nextPass !=null ) {868788 long timeToNextPass = nextPass . getStartTime ( )− Calendar .

ge t In s tance ( ) . ge tTimeInMi l l i s ( ) ; // HACK8990 txt = ”” ;9192 i f ( timeToNextPass<=−1) {93 // On g o i n g p a s s !94 this . setForeground ( Color .RED) ;95 // B l i n k e v e r y o t h e r s e c o n d96 i f ( ( int ) ( Calendar . ge t In s tance ( ) . ge tTimeInMi l l i s ( )

/1000) % 2 == 0) {97 txt += ”ONGOING PASS ! ” ;98 } else {99 txt += ”” ;

100 }101102 // i f ( C a l e n d a r . g e t I n s t a n c e ( ) . g e t T i m e I n M i l l i s ( ) >

n e x t P a s s . g e tEndT ime ( ) ) {103 // // i f p a s s e n d e d104 // n e x t P a s s = t im e L i n eMo d e l . g e t N e x t O p e nP a s s ( ) ;105 // }106 } else {107 this . setForeground ( Color .BLACK) ;108 txt += dateFormat . format ( timeToNextPass−3600000) ;109 }110111 setText ( txt ) ;112 } else {113114 setText ( ”None in system” ) ;115 }116117 }118119120 }

Page 200: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

190 Appendix C - Source Code

.1.43 LogView.java

1 package mps . gui . passwindow ;23 import javax . swing . JLabel ;45 /∗∗6 ∗ <br><br>7 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 38 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 19 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 8

10 ∗/11 public c lass LogView extends JLabel{121314 /∗∗15 ∗16 ∗/17 private stat ic f ina l long se r ia lVers ionUID = 1L ;1819 /∗∗20 ∗21 ∗/22 public LogView ( ) {23 updateLog ( ) ;24 }2526 /∗∗27 ∗28 ∗/29 public void updateLog ( ) {30 // TODO: Imp l emen t t h i s me t hod31 }32 }

Page 201: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 191

.1.44 PassInformationPanel.java

1 package mps . gui . passwindow ;23 import java . text . SimpleDateFormat ;45 import javax . swing . JLabel ;6 import javax . swing . JPanel ;78 import mcc . s e rv e r . dataProcess ing . Pass ;9 import mps . MPSPreferences ;

1011 /∗∗12 ∗ <br><br>13 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 314 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 115 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 816 ∗/17 public c lass PassInformationPanel extends JPanel {1819 /∗∗20 ∗21 ∗/22 private stat ic f ina l long se r ia lVers ionUID = 1L ;2324 private Pass pass ;2526 /∗∗27 ∗28 ∗/29 private JLabel in foLabe l ;3031 /∗∗32 ∗ @param p a s s33 ∗/34 public PassInformationPanel ( Pass pass ) {35 this . pass = pass ;363738 in foLabe l = new JLabel ( ) ;39 updateInfoLabel ( ) ;4041 this . add ( in foLabe l ) ;4243 }4445 /∗∗46 ∗47 ∗/48 public void updateInfoLabel ( ) {49 St r ing s t a r t ;50 St r ing end ;51 St r ing durat ion ;52 St r ing gs ;53 long upl ink ;54 long s e s s i o n ;55 i f ( pass !=null ) {56 s t a r t = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( pass . getStartTime ( ) ) ;57 end = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( pass . getEndTime ( ) ) ;58 durat ion = new SimpleDateFormat ( MPSPreferences . getTimeFormat

( ) ) . format ( pass . getEndTime ( )−pass . getStartTime ( ) ) ;59 gs = pass . getGroundStationName ( ) ;60 upl ink = pass . getUpl inkBytesAvai lab le ( ) ;61 s e s s i o n = pass . getSess ionID ( ) ;62 } else {63 s t a r t = ”N/A” ;64 end = ”N/A” ;65 durat ion = ”N/A” ;66 gs = ”N/A” ;67 upl ink = 0 ;68 s e s s i o n = 0 ;69 }707172 St r ing i n f o = ”<html><table>” +73 ”<tr><td a l i gn=r ight ><b>Start time : ” + ”</td><td>” + s t a r t + ”</td>

” +74 ”<td a l i gn=r ight ><b>Duration :</td><td>” + durat ion +

”</td><td a l i gn=r ight ><b>Ground s t a t i on :</td><td> ” + gs +”</td></tr>” +

75 ”<tr><td a l i gn=r ight ><b>End time :</td><td>” + end +”</td><td a l i gn=r ight ><b>Uplink a v a i l a b l e :</td><td>” + upl ink +

76 ” b</td><td a l i gn=r ight ><b>Ses s i on :</td><td>” + s e s s i o n + ”</td></tr>” +

Page 202: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

192 Appendix C - Source Code

77 ”</table ></html>” ;7879 in foLabe l . setText ( i n f o ) ;8081 }828384 }

Page 203: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 193

.1.45 PasswindowView.java

1 package2 mps . gui . passwindow ;34 import java . awt . Dimension ;5 import java . awt . Font ;6 import java . awt . GridBagConstraints ;7 import java . awt . GridBagLayout ;8 import java . awt . I n s e t s ;9 import java . rmi . NotBoundException ;

10 import java . rmi . RemoteException ;11 import java . text . SimpleDateFormat ;12 import java . u t i l . HashMap ;1314 import javax . swing . BorderFactory ;15 import javax . swing . JFrame ;16 import javax . swing . JLabel ;17 import javax . swing . JPanel ;18 import javax . swing . JSpl itPane ;19 import javax . swing . border . EtchedBorder ;20 import javax . swing . border . Tit ledBorder ;2122 import mcc . s e rv e r . dataProcess ing . Pass ;23 import mps . MPSPreferences ;24 import mps . gui . passwindow . emergency . EmergencyView ;25 import mps . gui . t ime l i n e . TimeLineModel ;26 import mps . gui . t ime l i n e . TimeLineView ;2728 import common . command .Command;29 import common . command .CommandType ;30 import common . command . DTUsat2Command ;31 import common . command . DTUsat2CommandTypeMap ;3233 /∗∗34 ∗ <br><br>35 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 336 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 137 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 838 ∗/39 public c lass PasswindowView extends JFrame{4041 /∗∗42 ∗43 ∗/44 private stat ic f ina l long se r ia lVers ionUID = 1L ;45 /∗∗46 ∗47 ∗/48 private Pass pass ;49 /∗∗50 ∗51 ∗/52 private EmergencyView emergencyView ;53 /∗∗54 ∗55 ∗/56 private JLabel commandTable ;5758 /∗∗59 ∗ @param t im e L i n eV i e w60 ∗ @th r ow s R emo t e E x c e p t i o n61 ∗/62 public PasswindowView ( TimeLineView timeLineView ) throws RemoteException{6364 pass = TimeLineModel . g e t In s tance ( ) . getNextOpenPass ( ) ;6566 // SET−UP FRAME67 this . s e t T i t l e ( ”Pass Window” ) ;68 TimeLineView . s e t I con ( this ) ;6970 // MAIN PANEL71 JPanel mainPanel = new JPanel (new GridBagLayout ( ) ) ;72 GridBagConstraints c = new GridBagConstraints ( ) ;73 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;7475 // ADDING COMPONENENTS7677 c . gr idy = 0 ;78 c . gr idx = 0 ;79 c . gr idwidth = 1 ;80 c . anchor = GridBagConstraints . FIRST LINE END ;81 JLabel pass IdLabe l ;82 i f ( pass !=null ) {83 passIdLabe l = new JLabel ( ”Next Pass ID=”+pass . getPassID ( ) +

” | Count down : ” ) ;

Page 204: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

194 Appendix C - Source Code

84 } else {85 passIdLabe l = new JLabel ( ”No upcomming passe s in system” ) ;86 }8788 passIdLabe l . setFont (new Font ( ”Tahoma” , Font .BOLD,16 ) ) ;89 mainPanel . add ( passIdLabel , c ) ;9091 CountDownLabel cd l = new CountDownLabel ( ) ;92 cd l . setFont (new Font ( ” Courier New” , Font .BOLD,16 ) ) ;93 c . anchor = GridBagConstraints . FIRST LINE START ;94 c . gr idx = 1 ;95 mainPanel . add ( cdl , c ) ;9697 c . gr idy = 1 ;98 c . gr idx = 0 ;99 c . gr idwidth = 2 ;

100 c . anchor = GridBagConstraints .PAGE START;101 mainPanel . add (new PassInformationPanel ( pass ) , c ) ;102103 c . gr idy = 2 ;104 c . gr idx = 0 ;105 c . gr idwidth = 1 ;106 c . f i l l = GridBagConstraints .BOTH;107 c . anchor = GridBagConstraints . FIRST LINE START ;108 commandTable = new JLabel ( ) ;109 commandTable . s e tVer t i ca lA l ignment ( JLabel .TOP) ;110 St r ing baseTxt = ”Commands to be transmitted ” ;111 St r ing borderTxt = pass != null ? baseTxt + ” ( ” + pass . s i z e ( ) + ” ) ”

: baseTxt ;112 Tit ledBorder t i t l e = BorderFactory . c r ea teTi t l edBorder ( BorderFactory .

createEtchedBorder ( EtchedBorder .LOWERED) ,113 borderTxt , Tit ledBorder .LEFT, Tit ledBorder .TOP ,new

Font ( ”Tahoma” , Font .BOLD,12 ) ) ;114 commandTable . setBorder ( t i t l e ) ;115116 updateCommandTable ( ) ;117 mainPanel . add ( commandTable , c ) ;118119 c . gr idx = 1 ;120 c . f i l l = GridBagConstraints .NONE;121 c . anchor = GridBagConstraints . FIRST LINE END ;122 StatusVar iablesView statusVar iab leView = new StatusVar iablesView ( ) ;123 mainPanel . add ( statusVariableView , c ) ;124125 emergencyView = new EmergencyView ( timeLineView ) ;126 emergencyView . setMinimumSize (new Dimension (300 ,300) ) ;127 // ma i nPan e l . add ( eme r g en c yV i ew , c ) ;128129 JSpl itPane sp l i tPane = new JSpl itPane ( JSpl i tPane . VERTICAL SPLIT , mainPanel ,

emergencyView ) ;130 sp l i tPane . setOneTouchExpandable ( true ) ;131 sp l i tPane . setContinuousLayout ( true ) ;132 sp l i tPane . s e tD iv i d e rS i z e (15) ;133 sp l i tPane . setName ( ”Test” ) ;134 // s p l i t P a n e . s e t D i v i d e r L o c a t i o n ( 1 5 0 ) ;135 // s p l i t P a n e . s e t L a y o u t ( new F l owL a y o u t ( F l owL a y o u t . LEADING) ) ;136137138 // EMBEDDING SPLIT PANEL139 this . add ( sp l i tPane ) ;140141 this . pack ( ) ;142 this . s e tLocat ionRe lat iveTo ( null ) ;143 this . s e t V i s i b l e ( true ) ;144 }145146 /∗∗147 ∗ @th r ow s R emo t e E x c e p t i o n148 ∗ @th r ow s N o tB o u n dE x c e p t i o n149 ∗/150 public void repaintPassWindow () throws RemoteException , NotBoundException {151152 emergencyView . updateView ( ) ;153154 updateCommandTable ( ) ;155156 }157158 /∗∗159 ∗160 ∗/161 private void updateCommandTable ( ) {162 St r ing t ab l eS t r i ng = ”<html><tab l e border=0>” ;163 t ab l eS t r i ng += ”<tr><td>ID</td><td>No</td><td><b>Name</b></td><td>

ModuleID</td><td>Parameters </td>” +164 ”<td>Time of execution </td><td>Bytes</td><td><b>

State </b></td></tr>” ;

Page 205: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 195

165166 HashMap<Long , Command> commandMap = TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . getCommandMap( ) ;167168 i f ( pass !=null ) {169 for ( int i =0; i <= pass . s i z e ( )−1; i++ ) {170 // f i n d a l l t h e commands w i t h i n t h i s p a s s171 long commandID = pass . getCommand( i ) ;172 Command c = commandMap . get (commandID) ;173174 int typeID = ((DTUsat2Command) c ) .

getCommandTypeID ( ) ;175 CommandType type = DTUsat2CommandTypeMap .

ge t In s tance ( ) . getCommandType( typeID ) ;176177 t ab l eS t r i ng += ”<tr><td>” + c . getCommandID

() + ”</td><td>” + c . getCommandTypeID ( )+ ”</td><td><b>” +

178 type . getName ( ) + ”</b></td><td>” + ((DTUsat2Command) c ) . ge tDes t ina t i on ( ) +”</td><td>” + c .getParameters ( ) + ”</td><td>” +

179 new SimpleDateFormat (MPSPreferences .getFullDateTimeFormat ( )) . format ( c .getTimeOfExecution ( ) ) +

”</td><td>” +180 c . getByteS ize ( ) + ”</td><td

><b>” + Command.de s c r i p eS ta t e ( c .ge tState ( ) ) + ”</b></td></tr>” ;

181182 }183 }184185186 t ab l eS t r i ng += ”</table ></html>” ;187188 commandTable . setText ( t ab l eS t r i ng ) ;189190 }191192 /∗∗193 ∗ @r e t u r n194 ∗/195 public Pass getPass ( ) {196 return pass ;197 }198 }

Page 206: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

196 Appendix C - Source Code

.1.46 StatusVariablesView.java

1 package mps . gui . passwindow ;23 import java . awt . Dimension ;4 import java . awt . Font ;56 import javax . swing . BorderFactory ;7 import javax . swing . JLabel ;8 import javax . swing . border . EtchedBorder ;9 import javax . swing . border . Tit ledBorder ;

1011 /∗∗12 ∗ <br><br>13 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 314 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 115 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 816 ∗/17 public c lass StatusVar iablesView extends JLabel{1819 /∗∗20 ∗21 ∗/22 private stat ic f ina l long se r ia lVers ionUID = 1L ;23 private Str ing va r i a b l e s ;2425 /∗∗26 ∗27 ∗/28 public StatusVar iablesView ( ) {2930 Tit ledBorder t i t l e = BorderFactory . c r ea teTi t l edBorder ( BorderFactory .

createEtchedBorder ( EtchedBorder .LOWERED) ,31 ” Status Var iab l e s ” , Tit ledBorder .LEFT, Tit ledBorder .

TOP ,new Font ( ”Tahoma” , Font .BOLD,12 ) ) ;3233 this . setBorder ( t i t l e ) ;3435 this . s e t P r e f e r r e d S i z e (new Dimension (250 ,200) ) ;3637 updateVar iables ( ) ;38 }3940 /∗∗41 ∗42 ∗/43 public void updateVar iables ( ) {44 St r ing va r i ab l e = ”XX” ;4546 va r i a b l e s = ”<html><table><tr><td>Var iab le A: </td><td><b>”+

va r i ab l e + ”</td></tr>” +47 ”<tr><td>Var iab le B: </td><td><b>” + va r i ab l e + ”</td></tr>” +48 ”<tr><td>Var iab le C: </td><td><b>” + va r i ab l e + ”</td></tr>” +49 ”<tr><td>Var iab le D: </td><td><b>” + va r i ab l e + ”</td></tr>” +50 ”<tr><td>Var iab le E: </td><td><b>” + va r i ab l e + ”</td></tr>” +51 ”<tr><td>Var iab le F : </td><td><b>” + va r i ab l e + ”</td></tr ></table>”

;52 this . setText ( v a r i a b l e s ) ;53 }5455 }

Page 207: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 197

.1.47 UpdateThread.java

1 package mps . gui . passwindow ;23 import java . rmi . NotBoundException ;4 import java . rmi . RemoteException ;56 import javax . swing . JOptionPane ;78 import mps . MPSPreferences ;9 import mps . gui . t ime l i n e . TimeLineControl ler ;

1011 /∗∗12 ∗ <br><br>13 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 314 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 115 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 816 ∗/17 public c lass UpdateThread extends Thread{1819 private boolean running = true ;20 private long i n t e r v a l ;21 private TimeLineControl ler t imeL ineContro l l e r ;2223 public UpdateThread ( TimeLineControl ler t imeL ineContro l l e r ) {24 this . t imeL ineContro l l e r = t imeLineContro l l e r ;25 }2627 public void run ( ) {2829 while ( true ) {30 while ( running ){31 // Method c a l l h e r e32 try {3334 i n t e r v a l = MPSPreferences .

ge tUpdate Inte rva l InMi l i s e conds ( ) ;35 running = MPSPreferences . isUpdatingOn ( ) ;3637 s l e ep ( i n t e r v a l ) ;3839 t imeL ineContro l l e r . getView ( ) .

updateTimeLineViews ( ) ;4041 } catch ( InterruptedExcept ion e ) {42 JOptionPane . showMessageDialog (

t imeLineContro l l e r . getView ( ) , e .getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

43 e . pr intStackTrace ( ) ;44 } catch ( RemoteException e ) {45 JOptionPane . showMessageDialog (

t imeLineContro l l e r . getView ( ) , e .getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

46 e . pr intStackTrace ( ) ;47 } catch ( NotBoundException e ) {48 JOptionPane . showMessageDialog (

t imeLineContro l l e r . getView ( ) , e .getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

49 e . pr intStackTrace ( ) ;50 }51 } try {52 s l e ep (10000) ;53 } catch ( InterruptedExcept ion e ) {54 // TODO Auto−g e n e r a t e d c a t c h b l o c k55 e . pr intStackTrace ( ) ;56 }5758 }5960 }6162 /∗∗63 ∗ @param r u n n i n g64 ∗/65 public void setRunning (boolean running ) {66 this . running = running ;67 }6869 /∗∗70 ∗ @r e t u r n71 ∗/72 public long g e t I n t e r v a l ( ) {73 return i n t e r v a l ;

Page 208: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

198 Appendix C - Source Code

74 }7576 /∗∗77 ∗ @param i n t e r v a l78 ∗/79 public void s e t I n t e r v a l ( int i n t e r v a l ) {80 this . i n t e r v a l = i n t e r v a l ;81 }8283 }

Page 209: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 199

.1.48 EmergencyCommandSetupView.java

1 package mps . gui . passwindow . emergency ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;67 import javax . swing . JFrame ;8 import javax . swing . JPanel ;9

10 import mps . gui . commanding . CommandSetupView ;11 import mps . gui . t ime l i n e . TimeLineModel ;12 import mps . gui . t ime l i n e . TimeLineView ;1314 /∗∗15 ∗ <br><br>16 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 317 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 118 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 819 ∗/20 public c lass EmergencyCommandSetupView extends JFrame {2122 /∗∗23 ∗24 ∗/25 private stat ic f ina l long se r ia lVers ionUID = 1L ;2627 private CommandSetupView commandSetupView ;2829 private EmergencyCommandSetupController c o n t r o l l e r ;30 private EmergencyView emergencyView ;3132 private boolean isPassModeOnFrameLoad ;3334 public EmergencyCommandSetupView( EmergencyView emergencyView ) {35 TimeLineView . s e t I con ( this ) ;3637 this . emergencyView = emergencyView ;38 c o n t r o l l e r = new EmergencyCommandSetupController ( this ) ;39 isPassModeOnFrameLoad = TimeLineModel . g e t In s tance ( ) . isPassMode ( ) ;4041 // T i t l e42 i f ( TimeLineModel . g e t In s tance ( ) . isPassMode ( ) ) this . s e t T i t l e ( ”Send

LIVE Emergency Command” ) ;43 else this . s e t T i t l e ( ”Add Emergency Command” ) ;444546 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;47 GridBagConstraints c = new GridBagConstraints ( ) ;48 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;4950 c . gr idy = 0 ;51 c . gr idx = 0 ;52 c . anchor = GridBagConstraints .LINE START;53 commandSetupView = new CommandSetupView( fa lse , fa lse , fa lse , f a l s e ) ;54 panel . add ( commandSetupView , c ) ;5556 commandSetupView . getCreateAndSendCommandButton ( ) . setText ( ”Send” ) ;57 commandSetupView . getCreateAndSendCommandButton ( ) . addAct ionListener (

c o n t r o l l e r ) ;5859 this . add ( panel ) ;6061 this . pack ( ) ;62 this . s e tLocat ionRe lat iveTo ( null ) ;63 this . s e t V i s i b l e ( true ) ;6465 }6667 public EmergencyView getEmergencyView ( ) {68 return emergencyView ;69 }7071 public boolean isPassModeOnFrameLoad ( ) {72 return isPassModeOnFrameLoad ;73 }7475 public CommandSetupView getCommandSetupView ( ) {76 return commandSetupView ;77 }7879 }

Page 210: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

200 Appendix C - Source Code

.1.49 EmergencyController.java

1 package mps . gui . passwindow . emergency ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;78 import javax . swing . JOptionPane ;9 import javax . swing . event . L i s tSe l e c t i onEvent ;

10 import javax . swing . event . L i s t S e l e c t i o n L i s t e n e r ;1112 import mcc . s e rv e r . u s e r s . User ;13 import mps . gui . t ime l i n e . TimeLineModel ;14 import mps . rmi . C l i ent ;1516 /∗∗17 ∗ <br><br>18 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 319 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 120 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 821 ∗/22 public c lass EmergencyControl ler implements Act ionListener , L i s t S e l e c t i o n L i s t e n e r {232425 /∗∗26 ∗27 ∗/28 private EmergencyView view ;2930 /∗∗31 ∗ @param eme r g e n c yV i ew32 ∗/33 public EmergencyControl ler ( EmergencyView emergencyView ) {34 view = emergencyView ;35 }3637 @Override38 public void act ionPerformed ( ActionEvent ae ) {394041 i f ( ae . getSource ( ) . equa l s ( view . getSetEmergencyButton ( ) ) ) {42 // Emerg ency C e n t e r On/ O f f43 int n ;44 i f ( TimeLineModel . g e t In s tance ( ) . isEmergencyMode ( ) ) {45 n = JOptionPane . showConfirmDialog ( view , ”Are you

sure you wish to turn Emergency Center OFF?” , ”Emergency Center OFF?” ,

46 JOptionPane .YES NO OPTION) ;47 } else {48 n = JOptionPane . showConfirmDialog ( view , ”Are you

sure you wish to turn Emergency Center ON?” , ”Emergency Center ON?” ,

49 JOptionPane .YES NO OPTION) ;50 }5152 i f (n== JOptionPane .YES OPTION) {5354 try {55 // T o g g l e em e r g e n c y mode s t a t u s56 i f ( TimeLineModel . g e t In s tance ( ) .

isEmergencyMode ( ) ) {57 Cl i ent . ge t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) .stopEmergencyMode ( ) ;

58 } else {59 Cl i ent . g e t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) .startEmergencyMode ( ) ;

60 }61 view . getTimeLineView ( ) . updateTimeLineViews ( )

;6263 view . updateView ( ) ;64 } catch ( RemoteException e ) {65 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

66 e . pr intStackTrace ( ) ;67 } catch ( NotBoundException e ) {68 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

69 e . pr intStackTrace ( ) ;70 }

Page 211: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 201

71727374 }7576 } else i f ( ae . getSource ( ) . equa l s ( view . getAddCommandButton ( ) ) ) {77 i f ( TimeLineModel . g e t In s tance ( ) . isEmergencyMode ( ) ) new

EmergencyCommandSetupView( view ) ;787980 } else i f ( ae . getSource ( ) . equa l s ( view . getDeleteCommandButton ( ) ) ) {8182 int selectedRow = view . getTable ( ) . getSelectedRow () ;83 long commandID = ( Long ) view . getTable ( ) . getValueAt (

selectedRow , EmergencyAbstractTableModel . ID COLUMN) ;8485 try {86 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

deleteEmergencyCommand (commandID) ;87 view . updateView ( ) ;88 } catch ( RemoteException e ) {89 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;90 e . pr intStackTrace ( ) ;91 } catch ( NotBoundException e ) {92 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;93 e . pr intStackTrace ( ) ;94 }9596 }979899 }

100101 @Override102 public void valueChanged ( L i s tSe l e c t i onEvent l s e ) {103104 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( )>=User .FULL TRUST) {105 i f ( view . getTable ( ) . getSelectedRow ()==−1) {106 view . getDeleteCommandButton ( ) . setEnabled ( f a l s e ) ;107 } else {108 view . getDeleteCommandButton ( ) . setEnabled ( true ) ;109 }110 }111112113 }114115 }

Page 212: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

202 Appendix C - Source Code

.1.50 EmergencyView.java

1 package mps . gui . passwindow . emergency ;23 import java . awt . Color ;4 import java . awt . Dimension ;5 import java . awt . Font ;6 import java . awt . GridBagConstraints ;7 import java . awt . GridBagLayout ;8 import java . awt . I n s e t s ;9 import java . rmi . NotBoundException ;

10 import java . rmi . RemoteException ;1112 import javax . swing . BorderFactory ;13 import javax . swing . ImageIcon ;14 import javax . swing . JButton ;15 import javax . swing . JLabel ;16 import javax . swing . JPanel ;17 import javax . swing . JScro l lPane ;18 import javax . swing . JTable ;19 import javax . swing . L i s tSe l e c t i onMode l ;20 import javax . swing . border . EtchedBorder ;21 import javax . swing . border . Tit ledBorder ;2223 import mcc . s e rv e r . u s e r s . User ;24 import mps . gui . t ime l i n e . TimeLineModel ;25 import mps . gui . t ime l i n e . TimeLineView ;26 import mps . rmi . C l i ent ;2728 /∗∗29 ∗ <br><br>30 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 331 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 132 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 833 ∗/34 public c lass EmergencyView extends JPanel{3536 /∗∗37 ∗38 ∗/39 private stat ic f ina l long se r ia lVers ionUID = 1L ;40 /∗∗41 ∗42 ∗/43 private TimeLineView timeLineView ;44 /∗∗45 ∗46 ∗/47 private EmergencyControl ler c o n t r o l l e r ;4849 /∗∗50 ∗51 ∗/52 private JTable tab l e ;53 /∗∗54 ∗55 ∗/56 private JScro l lPane s c ro l lPane ;57 /∗∗58 ∗59 ∗/60 private EmergencyAbstractTableModel tableModel ;61 /∗∗62 ∗63 ∗/64 private JButton addCommandButton ;65 /∗∗66 ∗67 ∗/68 private JButton deleteCommandButton ;69 /∗∗70 ∗71 ∗/72 private JButton setEmergencyButton ;73 /∗∗74 ∗75 ∗/76 private JLabel emergencyIcon ;7778 /∗∗79 ∗ @param t im e L i n eV i e w80 ∗/81 public EmergencyView ( TimeLineView timeLineView ){8283 this . timeLineView = timeLineView ;84

Page 213: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 203

85 c o n t r o l l e r = new EmergencyControl ler ( this ) ;8687 this . setLayout (new GridBagLayout ( ) ) ;88 GridBagConstraints c = new GridBagConstraints ( ) ;89 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;9091 c . anchor = GridBagConstraints .CENTER;92 c . gr idy = 0 ;93 c . gr idx = 0 ;94 this . add ( c reateStatusPane l ( ) , c ) ;9596 c . gr idx = 1 ;97 this . add ( createTablePanel ( ) , c ) ;9899 c . gr idx = 2 ;

100101 addCommandButton = new JButton ( ) ;102 addCommandButton . s e t P r e f e r r e d S i z e (new Dimension (100 ,100) ) ;103 this . add (addCommandButton , c ) ;104105 try {106 updateView ( ) ;107 } catch ( RemoteException e ) {108 // TODO Auto−g e n e r a t e d c a t c h b l o c k109 e . pr intStackTrace ( ) ;110 } catch ( NotBoundException e ) {111 // TODO Auto−g e n e r a t e d c a t c h b l o c k112 e . pr intStackTrace ( ) ;113 }114115 // L i s t e n e r s116 tab l e . getSe lec t ionMode l ( ) . addL i s t S e l e c t i onL i s t en e r ( c o n t r o l l e r ) ;117 addCommandButton . addAct ionListener ( c o n t r o l l e r ) ;118 setEmergencyButton . addAct ionListener ( c o n t r o l l e r ) ;119 deleteCommandButton . addAct ionListener ( c o n t r o l l e r ) ;120121 }122123 /∗∗124 ∗ @r e t u r n125 ∗/126 public JPanel c reateStatusPane l ( ) {127 JPanel panel = new JPanel ( ) ;128 panel . setLayout (new GridBagLayout ( ) ) ;129 GridBagConstraints c = new GridBagConstraints ( ) ;130 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;131132 c . gr idy = 0 ;133 c . gr idx = 0 ;134 c . anchor = GridBagConstraints .CENTER;135 emergencyIcon = new JLabel ( ) ;136 emergencyIcon . s e t P r e f e r r e d S i z e (new Dimension (80 ,80) ) ;137 panel . add ( emergencyIcon , c ) ;138139 c . gr idy = 1 ;140 c . anchor = GridBagConstraints .PAGE START;141 setEmergencyButton = new JButton ( ) ;142 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( )<=User .MEDIUM TRUST) {143 setEmergencyButton . setEnabled ( f a l s e ) ;144 }145146 panel . add ( setEmergencyButton , c ) ;147148 return panel ;149 }150151 /∗∗152 ∗ @r e t u r n153 ∗/154 public JPanel createTablePanel ( ) {155 JPanel panel = new JPanel ( ) ;156 panel . setLayout (new GridBagLayout ( ) ) ;157 GridBagConstraints c = new GridBagConstraints ( ) ;158 c . i n s e t s = new I n s e t s (1 , 1 , 1 , 1 ) ;159160 tableModel = new EmergencyAbstractTableModel ( ) ;161 try {162 tableModel . loadCommandsFromMCC() ;163 } catch ( RemoteException e ) {164 // TODO Auto−g e n e r a t e d c a t c h b l o c k165 e . pr intStackTrace ( ) ;166 } catch ( NotBoundException e ) {167 // TODO Auto−g e n e r a t e d c a t c h b l o c k168 e . pr intStackTrace ( ) ;169 }170 tab l e = new JTable ( tableModel ) ;171 tab l e . setColumnSelect ionAllowed ( f a l s e ) ;

Page 214: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

204 Appendix C - Source Code

172 tab l e . setRowSelect ionAllowed ( true ) ;173 tab l e . setSe lect ionMode ( L i s tSe l e c t i onMode l . SINGLE SELECTION) ;174 tab l e . s e tP r e f e r r edSc r o l l ab l eV i ewpo r tS i z e (new Dimension (600 ,100) ) ;175 tab l e . s e tF i l l sV i ewpor tHe ight ( true ) ;176 tab l e . setAutoResizeMode ( JTable .AUTO RESIZE OFF) ;177178 s c ro l lPane = new JScro l lPane ( tab l e ) ;179 s c ro l lPane . setMinimumSize (new Dimension (595 ,150) ) ;180 s c ro l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .VERTICAL SCROLLBAR ALWAYS)

;181 s c ro l lPane . s e tHo r i z on ta l S c r o l lBa rPo l i c y ( JScro l lPane .

HORIZONTAL SCROLLBAR AS NEEDED) ;182183 c . gr idy = 0 ;184 c . gr idx = 0 ;185 c . anchor = GridBagConstraints .LINE START;186 panel . add ( scro l lPane , c ) ;187188 deleteCommandButton = new JButton ( ” Delete ” ) ;189 deleteCommandButton . setEnabled ( f a l s e ) ;190 JLabel s e l e c t i o nLabe l = new JLabel ( ” S e l e c t i on : ” ) ;191 JPanel dummyPanel = new JPanel ( ) ;192 dummyPanel . add ( s e l e c t i o nLabe l ) ;193 dummyPanel . add ( deleteCommandButton ) ;194 c . gr idy = 1 ;195 c . anchor = GridBagConstraints . LINE END;196 panel . add (dummyPanel , c ) ;197198 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( )<=User .MEDIUM TRUST) {199 deleteCommandButton . setEnabled ( f a l s e ) ;200 }201202203 return panel ;204 }205206 /∗∗207 ∗ @th r ow s R emo t e E x c e p t i o n208 ∗ @th r ow s N o tB o u n dE x c e p t i o n209 ∗/210 public void updateView ( ) throws RemoteException , NotBoundException{211212 tableModel . loadCommandsFromMCC() ;213214 tab l e . r epa in t ( ) ;215216 i f ( TimeLineModel . g e t In s tance ( ) . isEmergencyMode ( ) ){217 // Emerg ency Mode218219 Tit ledBorder ma in t i t l e = BorderFactory . c r ea teT i t l edBorder (

BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED,Color .RED, Color .RED) ,

220 ” Emergency Center ON ” , Tit ledBorder .CENTER, Tit ledBorder .TOP ,new Font ( ”Tahoma” ,Font .BOLD,14 ) , Color .BLACK) ;

221 this . setBorder ( ma in t i t l e ) ;222223224 setEmergencyButton . setText ( ”<html><center><f ont c o l o r=green

><b>Exit </b><br>Emergency Center</font ></center ></html>” ) ;

225 emergencyIcon . s e t I con ( createImageIcon ( ” graphic /emergency . png” ) ) ;

226 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( )>=User .FULL TRUST) {

227 addCommandButton . setEnabled ( true ) ;228 }229230 i f ( TimeLineModel . g e t In s tance ( ) . isPassMode ( ) ) {231 addCommandButton . setText ( ”<html><center><b>Send <i>

LIVE</i><br>Emergency Command</b></center ></html>” ) ;

232 } else {233 addCommandButton . setText ( ”<html><center><b>Add<br>

Emergency Command</b></center ></html>” ) ;234 }235236 Tit ledBorder commandTitle = BorderFactory . c r ea teTi t l edBorder

( BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED),

237 ” Commands ” , Tit ledBorder .LEFT,Tit ledBorder .TOP ,new Font ( ”Tahoma” ,Font .BOLD,14 ) , Color .BLACK) ;

238 s c ro l lPane . setBorder ( commandTitle ) ;239240 tab l e . setForeground ( Color .RED) ;241 tab l e . getTableHeader ( ) . setForeground ( Color .BLACK) ;

Page 215: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 205

242 tab l e . getTableHeader ( ) . setReorder ingAl lowed ( true ) ;243 tab l e . setEnabled ( true ) ;244245 } else {246 // Not eme r g e n c y mode247248 Tit ledBorder ma in t i t l e = BorderFactory . c r ea teT i t l edBorder (

BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED) ,249 ” Emergency Center OFF ” , Tit ledBorder .

CENTER, Tit ledBorder .TOP ,new Font ( ”Tahoma” , Font .BOLD,14 ) , Color .GRAY) ;

250 this . setBorder ( ma in t i t l e ) ;251252 setEmergencyButton . setText ( ”<html><center><f ont c o l o r=red><b

>Start </b><br>Emergency Center</font ></center ></html>” );

253 emergencyIcon . s e t I con ( createImageIcon ( ” graphic /normal . jpg ” ) );

254 addCommandButton . setEnabled ( f a l s e ) ;255 i f ( TimeLineModel . g e t In s tance ( ) . isPassMode ( ) ) {256 addCommandButton . setText ( ”<html><center><b><f ont

c o l o r=gray>Send <i>LIVE</i><br>EmergencyCommand</font ></b></center ></html>” ) ;

257 } else {258 addCommandButton . setText ( ”<html><center><f ont c o l o r=

gray><b>Add<br>Emergency Command</b></font ></center ></html>” ) ;

259 }260261 Tit ledBorder commandTitle = BorderFactory . c r ea teTi t l edBorder

( BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED),

262 ” Commands ” , Tit ledBorder .LEFT,Tit ledBorder .TOP ,new Font ( ”Tahoma” ,Font .BOLD,14 ) , Color .GRAY) ;

263 s c ro l lPane . setBorder ( commandTitle ) ;264 tab l e . setForeground ( Color .GRAY) ;265 tab l e . getTableHeader ( ) . setForeground ( Color .GRAY) ;266 tab l e . getTableHeader ( ) . setReorder ingAl lowed ( f a l s e ) ;267 tab l e . setEnabled ( f a l s e ) ;268 }269270 setTableColumnWidths ( ) ;271272 }273274 /∗∗275 ∗ @param p a t h276 ∗ @r e t u r n277 ∗/278 private ImageIcon createImageIcon ( St r ing path ) {279 java . net .URL imgURL = EmergencyView . c lass . getResource ( path ) ;280 i f (imgURL != null ) {281 return new ImageIcon (imgURL) ;282 } else {283 System . e r r . p r i n t l n ( ”Couldn ’ t f i nd f i l e : ” + path ) ;284 return null ;285 }286 }287288 /∗∗289 ∗290 ∗/291 public void setTableColumnWidths ( ) {292293 tab l e . getColumnModel ( ) . getColumn ( EmergencyAbstractTableModel . ID COLUMN) .

setPreferredWidth (30) ;294 tab l e . getColumnModel ( ) . getColumn ( EmergencyAbstractTableModel .NO COLUMN) .

setPreferredWidth (30) ;295 tab l e . getColumnModel ( ) . getColumn ( EmergencyAbstractTableModel .NAME COLUMN) .

setPreferredWidth (190) ;296 tab l e . getColumnModel ( ) . getColumn ( EmergencyAbstractTableModel .

DESTINATION COLUMN) . setPre ferredWidth (70) ;297 tab l e . getColumnModel ( ) . getColumn ( EmergencyAbstractTableModel .

PARAMETERS COLUMN) . setPre ferredWidth (145) ;298 tab l e . getColumnModel ( ) . getColumn ( EmergencyAbstractTableModel .STATE COLUMN) .

setPreferredWidth (130) ;299 }300301 /∗∗302 ∗ @r e t u r n303 ∗/304 public JButton getAddCommandButton ( ) {305 return addCommandButton ;306 }307308 /∗∗

Page 216: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

206 Appendix C - Source Code

309 ∗ @r e t u r n310 ∗/311 public JButton getSetEmergencyButton ( ) {312 return setEmergencyButton ;313 }314315316 /∗∗317 ∗ @r e t u r n318 ∗/319 public EmergencyAbstractTableModel getTableModel ( ) {320 return tableModel ;321 }322323 /∗∗324 ∗ @r e t u r n325 ∗/326 public JTable getTable ( ) {327 return tab l e ;328 }329330 /∗∗331 ∗ @r e t u r n332 ∗/333 public JButton getDeleteCommandButton ( ) {334 return deleteCommandButton ;335 }336337 /∗∗338 ∗ @r e t u r n339 ∗/340 public TimeLineView getTimeLineView ( ) {341 return timeLineView ;342 }343344345 }

Page 217: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 207

.1.51 EmergencyCommandSetupController.java

1 package mps . gui . passwindow . emergency ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;78 import javax . swing . JOptionPane ;9

10 import mps . rmi . C l i ent ;1112 import common . command .Command;13 import common . command . DTUsat2CommandFactory ;14 import common . except ions . I l l ega lParamete rExcept ion ;15 import common . except ions . UnknownCommandTypeException ;1617 /∗∗18 ∗ <br><br>19 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 320 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 121 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 822 ∗/23 public c lass EmergencyCommandSetupController implements Act ionL i s t ener {2425 /∗∗26 ∗27 ∗/28 EmergencyCommandSetupView view ;2930 public EmergencyCommandSetupController (EmergencyCommandSetupView view ) {31 this . view = view ;3233 }3435 @Override36 public void act ionPerformed ( ActionEvent ae ) {3738 i f ( ae . getSource ( ) . equa l s ( view . getCommandSetupView ( ) .

getCreateAndSendCommandButton ( ) ) ) {3940 St r ing commandData = view . getCommandSetupView ( ) .

getSelectCommandPanelView ( ) . generateCommandInfo ( ) ;4142 DTUsat2CommandFactory t c f = new DTUsat2CommandFactory ( ) ;4344 Command command = null ;45 try {46 command = t c f . generateCommand (commandData) ;47 } catch (UnknownCommandTypeException e ) {48 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;49 e . pr intStackTrace ( ) ;50 } catch ( I l l ega lParamete rExcept ion e ) {51 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;52 e . pr intStackTrace ( ) ;53 }5455 try {56 i f ( view . isPassModeOnFrameLoad ( ) ) { // TODO: Chec k i f

s t i l l p a s s mode57 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

addEmergencyCommandLive (command) ;58 } else { // TODO: Chec k i f s t i l l NOT p a s s mode59 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

addEmergencyCommand(command) ;60 }6162 view . getEmergencyView ( ) . updateView ( ) ;63 view . d i spose ( ) ;646566 } catch ( RemoteException e ) {67 // TODO Auto−g e n e r a t e d c a t c h b l o c k68 e . pr intStackTrace ( ) ;69 } catch ( NotBoundException e ) {70 // TODO Auto−g e n e r a t e d c a t c h b l o c k71 e . pr intStackTrace ( ) ;72 }737475 }7677 }

Page 218: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

208 Appendix C - Source Code

7879 }

Page 219: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 209

.1.52 EmergencyAbstractTableModel.java

1 package mps . gui . passwindow . emergency ;23 import java . rmi . NotBoundException ;4 import java . rmi . RemoteException ;5 import java . u t i l . ArrayList ;67 import javax . swing . tab l e . AbstractTableModel ;89 import mps . rmi . C l i ent ;

1011 import common . command .Command;12 import common . command . DTUsat2Command ;13 import common . command . DTUsat2CommandTypeMap ;1415 /∗∗16 ∗ <br><br>17 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 318 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 119 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 820 ∗/21 public c lass EmergencyAbstractTableModel extends AbstractTableModel{2223 /∗∗24 ∗25 ∗/26 private stat ic f ina l long se r ia lVers ionUID = 1L ;2728 public stat ic f ina l int ID COLUMN =

0;29 public stat ic f ina l int NO COLUMN =

1;30 public stat ic f ina l int NAME COLUMN = 2;31 public stat ic f ina l int DESTINATION COLUMN = 3;32 public stat ic f ina l int PARAMETERS COLUMN = 4;33 public stat ic f ina l int STATE COLUMN = 5;3435 /∗∗36 ∗37 ∗/38 private ArrayList<Command> emergencyCommands ;3940 /∗∗41 ∗ @th r ow s R emo t e E x c e p t i o n42 ∗ @th r ow s N o tB o u n dE x c e p t i o n43 ∗/44 public void loadCommandsFromMCC() throws RemoteException , NotBoundException

{45 // emergencyCommands = C l i e n t . g e t I n s t a n c e ( ) . g e t M i n i m a l I n t e r f a c e ( ) .

g e tN o tT r a n sm i t t e dEme r g e n c yCommand s ( ) ;46 emergencyCommands = Cl i ent . ge t In s tance ( ) . ge tMin ima l Inte r face ( ) .

getEmergencyCommands ( ” state <”+Command.DELETED) ;47 }4849 public int getColumnCount ( ) {50 return 6 ; // co lumnNames . l e n g t h ;51 }5253 public int getRowCount ( ) {54 return emergencyCommands . s i z e ( ) ;55 }5657 public Str ing getColumnName( int co l ) {5859 switch ( c o l ) {60 case ID COLUMN: return ” Id” ;61 case NO COLUMN: return ”No” ;62 case NAME COLUMN: return ”Name” ;63 case DESTINATION COLUMN: return ”ModuleID” ;64 case PARAMETERS COLUMN: return ”Parameters ” ;65 case STATE COLUMN: return ” State ” ;66 default :67 return ”Unknown column” ;68 }69 }7071 public Object getValueAt ( int row , int co l ) {7273 Command command =emergencyCommands . get ( row ) ;74 i f (command==null ) return ”” ;7576 // i f ( command == n u l l ) r e t u r n ” ” ;7778 switch ( c o l ) {79 case ID COLUMN:

Page 220: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

210 Appendix C - Source Code

80 return command . getCommandID ( ) ;81 case NO COLUMN:82 return command . getCommandTypeID ( ) ;83 case NAME COLUMN:84 return DTUsat2CommandTypeMap . ge t In s tance ( ) . getCommandType(

command . getCommandTypeID ( ) ) . getName ( ) ;85 case DESTINATION COLUMN:86 return ( (DTUsat2Command) command) . ge tDes t ina t i on ( ) ;87 case PARAMETERS COLUMN:88 return ( (DTUsat2Command) command) . getParameters ( ) ;89 case STATE COLUMN:90 return command . ge tS ta t eDes c r ip t i on ( ) ;91 default :92 return null ;93 }94 }9596 /∗97 ∗ JT a b l e u s e s t h i s me t hod t o d e t e r m i n e t h e d e f a u l t r e n d e r e r /98 ∗ e d i t o r f o r e a c h c e l l . I f we d i d n ’ t im p l em e n t t h i s method ,99 ∗ t h e n t h e l a s t c o l umn wou l d c o n t a i n t e x t ( ” t r u e ”/” f a l s e ” ) ,

100 ∗ r a t h e r t h a n a c h e c k b o x .101 ∗/102 public Class getColumnClass ( int c ) {103 // i f ( c ==5) {104 // r e t u r n Da t e . c l a s s ;105 // }106 return getValueAt (0 , c ) . ge tClas s ( ) ;107 }108109110 }

Page 221: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 211

.1.53 PassManuelSetupView.java

1 package mps . gui . planning . pas se s ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;6 import java . rmi . NotBoundException ;7 import java . rmi . RemoteException ;8 import java . u t i l . ArrayList ;9

10 import javax . swing . JButton ;11 import javax . swing . JComboBox ;12 import javax . swing . JFrame ;13 import javax . swing . JLabel ;14 import javax . swing . JPanel ;1516 import mcc . s e rv e r . dataProcess ing . GroundStation ;17 import mcc . s e rv e r . dataProcess ing . Pass ;18 import mps . gui . DateTimeSpinnersPanel ;19 import mps . gui . t ime l i n e . TimeLineView ;20 import mps . rmi . C l i ent ;2122 /∗∗23 ∗ <br><br>24 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 325 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 126 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 827 ∗/28 public c lass PassManuelSetupView extends JFrame {2930 /∗∗31 ∗32 ∗/33 private stat ic f ina l long se r ia lVers ionUID = 1L ;34 private Pass passToEdit ;35 private TimeLineView timeLineView ;36 private PassManuelSetupControl ler c o n t r o l l e r ;3738 private JComboBox gsComboBox ;3940 private DateTimeSpinnersPanel s ta r tSp inner sPane l ;41 private DateTimeSpinnersPanel endSpinnersPanel ;4243 private JButton addButton ;44 private JButton cancelButton ;4546 public PassManuelSetupView ( Pass passToEdit , TimeLineView timeLineView )

throws RemoteException , NotBoundException {4748 this . passToEdit = passToEdit ;49 this . timeLineView = timeLineView ;50 c o n t r o l l e r = new PassManuelSetupControl ler ( this ) ;5152 // Frame s e t−up53 this . s e tRe s i z ab l e ( f a l s e ) ;54 this . s e tLocat ion (100 ,100) ;55 TimeLineView . s e t I con ( this ) ;5657 i f ( passToEdit==null ) {58 this . s e t T i t l e ( ”Add pass ” ) ;59 } else {60 this . s e t T i t l e ( ” Edit pass ” + passToEdit . getPassID ( ) ) ;61 }626364 this . s e t S i z e (380 ,395) ;65 this . s e t V i s i b l e ( true ) ;66676869 JPanel panel = new JPanel ( ) ;70 panel . setLayout (new GridBagLayout ( ) ) ;71 GridBagConstraints c = new GridBagConstraints ( ) ;72 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;7374 c . gr idy = 0 ;75 c . gr idx = 0 ;76 c . anchor = GridBagConstraints . LINE END;77 panel . add (new JLabel ( ”Ground Stat ion : ” ) , c ) ;7879 ArrayList<GroundStation> s t a t i o n s = Cl i ent . g e t In s tance ( ) .

ge tMin ima l Inte r face ( ) . getGroundStations ( ) ;80 gsComboBox = new JComboBox ( ) ;81 for ( GroundStation gs : s t a t i o n s ) {82 gsComboBox . addItem ( gs . GetName ( ) ) ;

Page 222: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

212 Appendix C - Source Code

83 }84 i f ( passToEdit !=null ) {8586 gsComboBox . s e tSe l e c t ed I t em ( passToEdit . getGroundStationName ( )

) ;87 gsComboBox . setEnabled ( f a l s e ) ;88 }899091 c . gr idx = 1 ;92 c . anchor = GridBagConstraints .LINE START;93 panel . add (gsComboBox , c ) ;949596 c . gr idy = 1 ;97 c . gr idx = 0 ;98 c . anchor = GridBagConstraints . LINE END;99 panel . add (new JLabel ( ” Star t time : ” ) , c ) ;

100101 s ta r tSp inner sPane l = new DateTimeSpinnersPanel ( ) ;102103 c . gr idx = 1 ;104 c . anchor = GridBagConstraints .LINE START;105 panel . add ( s tar tSp innersPane l , c ) ;106107108 c . gr idy = 2 ;109 c . gr idx = 0 ;110 c . anchor = GridBagConstraints . LINE END;111 panel . add (new JLabel ( ”End time : ” ) , c ) ;112113 endSpinnersPanel = new DateTimeSpinnersPanel ( ) ;114115 c . gr idx = 1 ;116 c . anchor = GridBagConstraints .LINE START;117 panel . add ( endSpinnersPanel , c ) ;118119 i f ( passToEdit !=null ) {120 s ta r tSp inner sPane l . setTime ( passToEdit . getStartTime ( ) ) ;121 endSpinnersPanel . setTime ( passToEdit . getEndTime ( ) ) ;122 }123124 addButton = new JButton ( ) ;125 St r ing txt = passToEdit==null ? ”Add” : ”Modify” ;126 addButton . setText ( txt ) ;127 c . gr idy= 3 ;128 panel . add ( addButton , c ) ;129130131 // L i s t e n e r s132 addButton . addAct ionListener ( c o n t r o l l e r ) ;133134135 this . add ( panel ) ;136 this . pack ( ) ;137 this . s e tLocat ionRe lat iveTo ( null ) ;138 this . s e t V i s i b l e ( true ) ;139 }140141142 public JButton getAddButton ( ) {143 return addButton ;144 }145146 public JComboBox getGsComboBox ( ) {147 return gsComboBox ;148 }149150 public TimeLineView getTimeLineView ( ) {151 return timeLineView ;152 }153154 public Pass getPassToEdit ( ) {155 return passToEdit ;156 }157158159 public DateTimeSpinnersPanel ge tStar tSp inner sPane l ( ) {160 return s ta r tSp inner sPane l ;161 }162163164 public DateTimeSpinnersPanel getEndSpinnersPanel ( ) {165 return endSpinnersPanel ;166 }167168 }

Page 223: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 213

.1.54 Suggestion.java

1 package mps . gui . planning . pas se s ;23 import mcc . s e rv e r . dataProcess ing . Pass ;45 /∗∗6 ∗ <br><br>7 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 38 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 19 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 8

10 ∗/11 public c lass Suggest ion {1213 private int type ; // 1 i s u p d a t e s u g g e s t i o n ; 2 i s new p a s s s u g g e s t i o n ; 3 i s

d e l e t e p a s s s u g g e s t i o n14 private Pass oldPass ;15 private Pass newPass ;1617 public stat ic f ina l int UPDATE = 0;18 public stat ic f ina l int NEW = 1;19 public stat ic f ina l int DELETE = 2;2021 /∗∗22 ∗ @param t y p e23 ∗ @param p a s s24 ∗/25 public Suggest ion ( int type , Pass pass ){2627 i f ( ! ( type==NEW | | type==DELETE) ) {28 throw new I l l ega lArgumentExcept ion ( ” I l l e g a l Type” ) ;29 }3031 setType ( type ) ;3233 i f ( type == NEW){34 newPass = pass ;35 } else i f ( type ==DELETE){36 oldPass = pass ;37 }38 }3940 /∗∗41 ∗ @param t y p e42 ∗ @param newPas s43 ∗ @param o l d P a s s44 ∗/45 public Suggest ion ( int type , Pass newPass , Pass oldPass ) {46 setType ( type ) ;47 this . newPass = newPass ;48 this . o ldPass = oldPass ;49 }5051 /∗∗52 ∗ @param t y p e53 ∗/54 private void setType ( int type ) {55 switch ( type ){56 case UPDATE:57 case NEW:58 case DELETE:59 this . type = type ;60 break ;61 default :62 throw new I l l ega lArgumentExcept ion ( ” I l l e g a l Type” ) ;63 }64 }6566 /∗∗67 ∗ @r e t u r n68 ∗/69 public int getType ( ) {70 return type ;71 }7273 /∗∗74 ∗ @r e t u r n75 ∗/76 public Pass getOldPass ( ) {77 return oldPass ;78 }7980 /∗∗81 ∗ @r e t u r n82 ∗/83 public Pass getNewPass ( ) {

Page 224: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

214 Appendix C - Source Code

84 return newPass ;85 }86878889 }

Page 225: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 215

.1.55 TLEUpdateController.java

1 package mps . gui . planning . pas se s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;7 import java . u t i l . HashMap ;89 import javax . swing . JCheckBox ;

10 import javax . swing . JOptionPane ;1112 import mcc . s e rv e r . dataProcess ing . Pass ;13 import mcc . s e rv e r . dataProcess ing . T i m e l i n e U t i l i t i e s ;14 import mps . rmi . C l i ent ;1516 /∗∗17 ∗ <br><br>18 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 319 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 120 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 821 ∗/22 public c lass TLEUpdateController implements Act ionL i s t ener {2324 /∗∗25 ∗26 ∗/27 private TLEUpdateView view ;2829 /∗∗30 ∗ @param u p d a t eV i e w31 ∗/32 public TLEUpdateController (TLEUpdateView updateView ) {33 view = updateView ;34 }3536 @Override37 public void act ionPerformed ( ActionEvent ae ) {3839 i f ( ae . getSource ( ) . equa l s ( view . getAcceptButton ( ) ) ) {40 // ACCEPT Bu t t o n p r e s s e d4142 boolean changes = f a l s e ;4344 HashMap<Suggest ion , JCheckBox> h = view . getAcceptChangeMap ( )

;45 for ( Suggest ion s : h . keySet ( ) ) {46 // run t h r o u g h a l l s u g g e s t i o n s47 i f (h . get ( s ) . i s S e l e c t e d ( ) ) {48 // i f c o r r e s p o n d i n g c h e c k b o x i s s e l c e d49 try {5051 i f ( s . getType ( )==Suggest ion .NEW) {52 Cl i ent . ge t In s tance ( ) .

getMediumInterface ( ) .addPass ( s . getNewPass ( ) );

53 changes = true ;5455 } else i f ( s . getType ( )==Suggest ion .UPDATE) {56 long s t a r t = s . getNewPass ( ) . getStartTime ( ) ;57 long end = s . getNewPass ( ) . getEndTime ( ) ;58 long passID = s . getOldPass ( ) . getPassID ( ) ;59 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

modifyPass ( passID , T i m e l i n e U t i l i t i e s .STARTTIME, s t a r t ) ;

60 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .modifyPass ( passID , T i m e l i n e U t i l i t i e s .ENDTIME, end ) ;

61 changes = true ;6263 } else i f ( s . getType ( )==Suggest ion .DELETE) {64 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

removePass ( s . getOldPass ( ) . getPassID ( ) ,Pass .DELETED USER) ;

65 changes = true ;66 }6768 } catch ( RemoteException e ) {69 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;70 e . pr intStackTrace ( ) ;71 } catch ( NotBoundException e ) {72 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,

Page 226: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

216 Appendix C - Source Code

JOptionPane .ERROR MESSAGE) ;73 e . pr intStackTrace ( ) ;74 }75 }7677 }7879 i f ( changes ) view . getTimeLineView ( ) .

setScheduleRecommendation ( true ) ;8081 // u p d a t e t a b l e s82 try {83 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;8485 view . d i spose ( ) ;86 } catch ( RemoteException e ) {87 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;88 e . pr intStackTrace ( ) ;89 } catch ( NotBoundException e ) {90 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;91 e . pr intStackTrace ( ) ;92 }9394959697 }9899 }

100101 }

Page 227: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 217

.1.56 TLEUpdateModel.java

1 package mps . gui . planning . pas se s ;23 import java . i o . BufferedReader ;4 import java . i o . Buf feredWriter ;5 import java . i o . F i l e ;6 import java . i o . Fi leReader ;7 import java . i o . F i l eWr i te r ;8 import java . i o . IOException ;9 import java . net . HttpURLConnection ;

10 import java . net . MalformedURLException ;11 import java . net .URL;12 import java . rmi . NotBoundException ;13 import java . rmi . RemoteException ;14 import java . u t i l . ArrayList ;15 import java . u t i l . Calendar ;16 import java . u t i l . Co l l e c t i o n s ;17 import java . u t i l . GregorianCalendar ;1819 import mcc . s e rv e r . dataProcess ing . GroundStation ;20 import mcc . s e rv e r . dataProcess ing . Pass ;21 import mps . MPSPreferences ;22 import mps . gui . t ime l i n e . TimeLineModel ;2324 import common . U t i l s ;25 import common . s a t e l l i t e . Pred ic t ;26 import common . s a t e l l i t e . PredictExcept ion ;27 import common . s a t e l l i t e . S a t e l l i t e ;28 import common . s a t e l l i t e .TLE;2930 /∗∗31 ∗ <br><br>32 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 333 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 134 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 835 ∗/36 public c lass TLEUpdateModel {373839 /∗∗40 ∗41 ∗/42 private S a t e l l i t e s a t e l l i t e ;4344 /∗∗45 ∗46 ∗/47 private ArrayList<Predict> p r ed i c t s = new ArrayList<Predict >() ;4849 /∗∗50 ∗51 ∗/52 public TLEUpdateModel ( ) { }5354 /∗∗55 ∗ @param no Number o f u p c om in g p a s s e s t o f i n d f r om TLE f i l e .56 ∗ @r e t u r n A l i s t o f t h e no up c om in g p a s s e s .57 ∗ @th r ow s P r e d i c t E x c e p t i o n58 ∗ @th r ow s R emo t e E x c e p t i o n59 ∗ @th r ow s N o tB o u n dE x c e p t i o n60 ∗/61 private ArrayList<Pass> findUpcomingPassesByTLE ( int no ) throws

PredictException , RemoteException , NotBoundException {6263 St r ing u r l = MPSPreferences . getTLEurl ( ) ; // u r l , w h e r e t o d own l o a d

t h e TLE f i l e64 St r ing d i r = MPSPreferences . getTLEdir ( ) ; // D i r e c t o r y o f t h e l o c a l

TLE f i l e6566 // Down l oad t h e TLE f i l e f r om t h e c h o s e n u r l67 downloadFile ( ur l , d i r + ”\\” ) ;6869 St r ing f i l e L o c a t i o n = d i r + ”\\” + extractFi lename ( u r l ) ; // l o c a l

f i l e l o c a t i o n = l o c a l f i l e d i r e c t o r y + f i l e n a m e7071 // im p o r t TLE − Gen e a t e a S a t e l i t t e o b j e c t .72 importTLEFile ( f i l e L o c a t i o n ) ;7374 // G e n e r a t e P r e d i c t o b j e c t s .75 updatePredicts ( ) ;7677 // C r e a t e an emp t y l i s t f o r t h e upcomming p a s s e s :78 ArrayList<Pass> upcomingPasses = new ArrayList<Pass >() ;7980 // I n i t i t i a l z e C a l e n d a r o b j e c t t o c u r r e n t t im e

Page 228: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

218 Appendix C - Source Code

81 Calendar time = new GregorianCalendar ( ) ;82 time . s e tT imeInMi l l i s ( TimeLineModel . getCurrentTimeInMi l l i s ( ) ) ;8384 // For t h e ” no ” n e x t p a s s e s85 for ( int i = 0 ; i<no ; i++) {86 Pass nextPass = getNextPass ( time ) ; // n e x t p a s s a f t e r ” t im e

” :8788 upcomingPasses . add ( nextPass ) ; // add t h e p a s s t o t h e l i s t8990 // s e t ” t im e ” t o one s e c o n d a f t e r t h e j u s t f o u n d p a s s :91 time . s e tT imeInMi l l i s ( nextPass . getEndTime ( ) ) ;92 time . add ( GregorianCalendar .SECOND, 1) ;93 }9495 return upcomingPasses ;96 }9798 /∗∗99 ∗ @param Ca l e n d a r t h e t im e w h i c h t h e p a s s s h o u l d b e a f t e r

100 ∗ @r e t u r n Pa s s : t h e n e x t p a s s a f t e r t h e t im e f o r any o f t h e p r e d i c t s i n t h eTLEUpda teMode l .

101 ∗ @th r ow s P r e d i c t E x c e p t i o n102 ∗/103 private Pass getNextPass ( Calendar time ) throws PredictExcept ion{104105 // A l i s t c o n t a i n g t h e n e x t p a s s f o r e a c h o f t h e P r e d i c t s106 ArrayList<Pass> passe s = new ArrayList<Pass >() ;107108 Calendar currentTime = time ;109110 // A l g o r i t h m n e e d s t o run u n t i l a t l e a s t one u s e f u l p a s s i s f o u n d a t

one o f t h e p r e d i c t s (GS ) .111 while ( passe s . s i z e ( )==0) {112113 // For a l l t h e P r e d i c t o b j e c t s (GS ) f i n d t h e n e x t Pa s s a f t e r

” t im e ”114 for ( Pred ic t p r ed i c t : p r ed i c t s ) {115 St r ing name = pred i c t . g e tS ta t i on ( ) . GetName ( ) ;116 Calendar s t a r t = pred i c t . getNextPass ( currentTime ) ;117 Calendar end = pred i c t . getPassEnd ( currentTime ) ;118119 Calendar mid = new GregorianCalendar ( ) ;120 mid . s e tT imeInMi l l i s ( ( end . getTimeInMi l l i s ( )+s t a r t .

ge tTimeInMi l l i s ( ) ) /2 ) ;121122 // Chec k i f p a s s i s u s e f u l ( h o r i z o n t a l e l e v a t i o n i s

l a r g e r t h a n u s e r s p e c i f i e d v a l u e )123 i f ( p r ed i c t . g e tHor i z on ta lPo s i t i on (mid ) . El >

MPSPreferences . getMinDegreesAboveHorizont ( ) ) {124 passe s . add (new Pass (name , s t a r t .

ge tTimeInMi l l i s ( ) , end . getTimeInMi l l i s ( )) ) ;

125 } else {126 i f ( end . getTimeInMi l l i s ( ) > currentTime .

getTimeInMi l l i s ( ) ) currentTime = end ;127 currentTime . add ( Calendar .SECOND, 1) ;128 }129130 }131132 }133134135136 // F ind t h e p a s s w i t h t h e l o w e s t s t a r t t im e i n t h e l i s t137 Pass nextPass = passe s . get (0) ;138 for ( Pass pass : pas se s ) {139 i f ( pass . getStartTime ( )<nextPass . getStartTime ( ) ) {140 nextPass = pass ;141 }142 }143 // s o r t p a s s e s144 Co l l e c t i on s . s o r t ( passe s ) ;145146 return nextPass ;147148 }149150151 /∗∗152 ∗ Down l o a d s t h e f i l e s p e c i f i e d b y u r i i n t o d e s t F o l d e r .153 ∗ I f t h e f i l e e x i s t s i n d e s t F o l d e r , t h e d own l o a d b e c ome s c o n d i t i o n a l154 ∗ t o c o n s e r v e b a n d w i d t h o t h e r w i s e t h e f i l e i s c r e a t e d .155 ∗ @param p a t h − L i n k t o t h e f i l e156 ∗ @param d e s t F o l d e r − F i l e d e s t i n a t i o n f o l d e r157 ∗/

Page 229: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 219

158 private stat ic void downloadFile ( St r ing path , St r ing destFo lder ) {159 F i l e f = new F i l e ( des tFo lder+extractFi lename ( path ) ) ;160161 URL ur l ;162 try {163 u r l = new URL( path ) ;164 } catch ( MalformedURLException e1 ) { return ; }165166 HttpURLConnection conn = null ;167 try {168 conn = ( HttpURLConnection ) u r l . openConnection ( ) ;169 i f ( f . e x i s t s ( ) && conn . getLastModi f i ed ( ) < f . l a s tMod i f i ed ( ) )

{170 // t h i s f i l e h a s n o t c h a n g e d171 return ;172 }173174 St r ing content = U t i l s . readToEnd ( conn . getInputStream () ) ;175 // l o g g e r . i n f o ( ” S a v i n g f i l e ”+ f . g e tName ( ) + ” t o ”+ d e s t F o l d e r

) ;176177 saveContentToFile ( content , f ) ;178179 } catch ( IOException e ) {180 // l o g g e r . w a r n i n g ( ” F a i l e d t o d own l o a d f i l e ”+ p a t h ) ;181 }182 f i na l ly {183 i f ( conn != null )184 conn . d i s connect ( ) ;185 }186 }187188 /∗∗ E x t r a c t s t h e f i l e name f r om a p a t h189 ∗ @param p a t h190 ∗ @r e t u r n f i l e name191 ∗/192 private stat ic Str ing extractFi lename ( St r ing path ){193 return (new F i l e ( path ) ) . getName ( ) ;194 }195196 /∗∗197 ∗ @param c o n t e n t The c o n t e n t o f t h e f i l e t o w r i t e198 ∗ @param d e s t F i l e The d e s t i n a t i o n o f t h e f i l e199 ∗/200 private stat ic void saveContentToFile ( St r ing content , F i l e d e s tF i l e ) {201 Buf feredWriter out = null ;202 try {203 out = new BufferedWriter (new Fi l eWr i te r ( d e s tF i l e ) ) ;204 out . wr i t e ( content ) ;205 }206 catch ( Exception e ) {207 // l o g g e r . l o g ( L e v e l .WARNING,208 // ” F a i l e d t o s a v e c o n t e n t t o ”+ d e s t F i l e .

g e t A b s o l u t e P a t h ( ) , e ) ;209 }210 f i na l ly {211 Ut i l s . c l o s e I fNo tNu l l ( out ) ;212 }213 }214215 /∗∗216 ∗ Tak e s a S t r i n g a s a r g umen t .217 ∗ @param f i l e n a m e − t h e f i l e name o f a TLE f i l e .218 ∗/219 private void importTLEFile ( St r ing f i l ename ) {220 BufferedReader br = null ;221222 try {223 br = new BufferedReader (new Fi leReader ( f i l ename ) ) ;224 St r ing commonName ;225226 while ( br . ready ( ) ) {227 commonName = br . readLine ( ) . trim ( ) ;228 i f (commonName . equa l s ( MPSPreferences . getSate l l i t eName

( ) ) ) {229230 s a t e l l i t e = new S a t e l l i t e (commonName , new

TLE( br . readLine ( ) , br . readLine ( ) ) ,f i l ename ) ;

231 } else {232 br . readLine ( ) ;233 br . readLine ( ) ;234 }235236 }237 }238 catch ( Exception e ) {

Page 230: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

220 Appendix C - Source Code

239 System . e r r . p r i n t l n ( ” Sa t e l l i t eReade r f a i l e d to load TLEs from”+(new F i l e ( f i l ename ) ) . getName ( ) ) ;

240 // TODO: DOWNLOAD FILE241 }242 f i na l ly {243 Ut i l s . c l o s e I fNo tNu l l ( br ) ;244 }245 }246247 /∗∗248 ∗ @r e t u r n An a r r a y l i s t o f s u g g e s t i o n s f o r c h a n g e s f o r t h e p a s s e s i n t h e

t im e l i n e249 ∗ @th r ow s P r e d i c t E x c e p t i o n250 ∗ @th r ow s N o tB o u n dE x c e p t i o n251 ∗ @th r ow s R emo t e E x c e p t i o n252 ∗/253 public ArrayList<Suggest ion> makeSuggestionsForPassListChanges ( ) throws

PredictException , RemoteException , NotBoundException{254255 // A emp ty l i s t , w h i c h i s g o i n g t o t o h o l d a l l t h e s u g g e s t i o n s :256 ArrayList<Suggest ion> sugge s t i on s = new ArrayList<Suggest ion >() ;257 // The upcomming p a s s e s c a l c u l a t e d f r om t h e TLE f i l e s :258 ArrayList<Pass> t l ePa s s e s = findUpcomingPassesByTLE ( MPSPreferences .

getNumberOfFuturePasses ( ) ) ;259 // The p a s s e s w h i c h e x i s t s i n t h e T imeL ine /DB r i g h t now :260 ArrayList<Pass> o ldPasses = TimeLineModel . g e t In s tance ( ) .

getUpcomingOpenPasses ( ) ;261262 // For a l l p a s s e s t h e TLE f i l e s u g g e s t s263 for ( Pass t l e p a s s : t l ePa s s e s ){264 boolean match = f a l s e ;265 // For a l l p a s s e s t h a t a r e u p c om in g i n t h e c u r r e n t t im e l i n e266 for ( Pass o ldpass : o ldPasses ){267 // I f t h e two p a s s e s a r e e x a c t l y t h e same , l e t no

s u g g e s t i o n b e made268 i f ( t l e p a s s . getStartTime ( ) == oldpass . getStartTime ( )

&& t l e p a s s . getEndTime ( ) == oldpass . getEndTime ( )){

269 match = true ;270 o ldPasses . remove ( o ldpass ) ;271 break ;272 } else i f ( comparePasses ( t l epas s , o ldpass ) ){ // I f

t h e two p a s s e s a r e o v e r l a p p i n g c r e a t e newu p d a t e s u g g e s t i o n f o r t h e l i s t

273 match = true ;274 sugge s t i on s . add (new Suggest ion ( Suggest ion .

UPDATE, t l epas s , o ldpass ) ) ;275 o ldPasses . remove ( o ldpass ) ; // Removes t h e

o l d p a s s f r om t h e l i s t t o b e c h e c k e d276 break ;277 }278 }279 i f ( match==f a l s e ) sugge s t i on s . add (new Suggest ion ( Suggest ion .

NEW, t l e p a s s ) ) ;280 }281 // For a l l o l d p a s s e s r e m a i n i n g i n t h e l i s t282 for ( Pass pass : o ldPasses ){283 sugge s t i on s . add (new Suggest ion ( Suggest ion .DELETE, pass ) ) ;284 }285286 return sugge s t i on s ;287 }288289 /∗∗290 ∗ @param p a s s 1291 ∗ @param p a s s 2292 ∗ @r e t u r n t r u e i f t h e p a s s e s a r e w i t h i n e a c h o t h e r s s p an o f t im e and h a v e

same g r o u n d s t a t i o n ; E l s e f a l s e293 ∗/294 private boolean comparePasses ( Pass pass1 , Pass pass2 ){295296 // I f t h e p a s s e s a r e o v e r l a p p i n g297 i f ( pass1 . getStartTime ( )>=pass2 . getStartTime ( ) && pass1 . getStartTime

( )<=pass2 . getEndTime ( )298 | | pass2 . getStartTime ( )>=pass1 . getStartTime ( ) && pass2 .

getStartTime ( )<=pass1 . getEndTime ( ) ){299 // I f t h e p a s s e s h a v e same g r o u n d s t a t i o n300 i f ( pass1 . getGroundStationName ( ) . equa l s ( pass2 .

getGroundStationName ( ) ) ){301 return true ;302 }303 }304305 return fa l se ;306 }307308

Page 231: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 221

309 /∗∗310 ∗ C r e a t e s a P r e d i c t o b j e c t a s s o c i a t e d t o e a c h Ground S t a t i o n i n t h e

s y s t em311 ∗/312 private void updatePredicts ( ) {313 i f ( s a t e l l i t e !=null ) {314 p r ed i c t s . c l e a r ( ) ;315 for ( GroundStation gs : TimeLineModel . g e t In s tance ( ) .

getGroundStations ( ) ) {316 p r ed i c t s . add (new Pred ic t ( s a t e l l i t e . getTLE () , gs ) ) ;317 }318 }319 }320321322323 }

Page 232: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

222 Appendix C - Source Code

.1.57 TLEUpdateView.java

1 package mps . gui . planning . pas se s ;23 import java . awt . BorderLayout ;4 import java . awt . Font ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;7 import java . rmi . NotBoundException ;8 import java . rmi . RemoteException ;9 import java . text . SimpleDateFormat ;

10 import java . u t i l . ArrayList ;11 import java . u t i l . HashMap ;1213 import javax . swing . BorderFactory ;14 import javax . swing . JButton ;15 import javax . swing . JCheckBox ;16 import javax . swing . JFrame ;17 import javax . swing . JLabel ;18 import javax . swing . JOptionPane ;19 import javax . swing . JPanel ;20 import javax . swing . border . EtchedBorder ;2122 import mps . MPSPreferences ;23 import mps . gui . t ime l i n e . TimeLineView ;2425 import common . s a t e l l i t e . PredictExcept ion ;2627 /∗∗28 ∗ <br><br>29 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 330 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 131 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 832 ∗/33 public c lass TLEUpdateView extends JFrame{343536 /∗∗37 ∗38 ∗/39 private stat ic f ina l long se r ia lVers ionUID = 1L ;40 /∗∗41 ∗42 ∗/43 private HashMap<Suggest ion , JCheckBox> acceptChangeMap ;44 /∗∗45 ∗46 ∗/47 private JButton acceptButton ;48 /∗∗49 ∗50 ∗/51 private ArrayList<Suggest ion> sugge s t i on s ;5253 /∗∗54 ∗55 ∗/56 private TimeLineView timeLineView ;57 /∗∗58 ∗59 ∗/60 private TLEUpdateController c o n t r o l l e r ;6162 private int tableFirstRowWidth = 80 ;63 private int tableStartTimeWidth = 200;64 private int tableEndTimeWidth = 200;65 private int tableGSWidth = 130;66 private int tablePassIDWidth = 40 ;6768 /∗∗69 ∗ @param t im e L i n eV i e w70 ∗ @th r ow s R emo t e E x c e p t i o n71 ∗ @th r ow s P r e d i c t E x c e p t i o n72 ∗ @th r ow s N o tB o u n dE x c e p t i o n73 ∗/74 public TLEUpdateView( TimeLineView timeLineView ) throws RemoteException ,

PredictException , NotBoundException {7576 this . timeLineView = timeLineView ;77 c o n t r o l l e r = new TLEUpdateController ( this ) ;78 TLEUpdateModel tleUpdateModel = new TLEUpdateModel ( ) ;79 sugge s t i on s = tleUpdateModel . makeSuggestionsForPassListChanges ( ) ;8081 i f ( sugge s t i on s . s i z e ( )==0) {82 JOptionPane . showMessageDialog ( this , ” Al l pas se s are

synchronized ” , ”No updates ” , JOptionPane .

Page 233: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 223

INFORMATION MESSAGE) ;83 } else {8485 acceptChangeMap = new HashMap<Suggest ion , JCheckBox >() ;868788 this . s e t T i t l e ( ”Update passe s from TLE” ) ;89 TimeLineView . s e t I con ( this ) ;9091 JPanel panel = new JPanel ( ) ;92 panel . setLayout (new GridBagLayout ( ) ) ;9394 GridBagConstraints c = new GridBagConstraints ( ) ;95 c . anchor = GridBagConstraints .LINE START;96 c . gr idx = 0 ;97 c . gr idy = 0 ;98 panel . add ( tableHeaderPanel ( ) , c ) ;99

100101102 boolean f i r s tUpdateSugge s t i on = true ;103 for ( Suggest ion sug : sugge s t i on s ) {104 i f ( sug . getType ( )==Suggest ion .UPDATE) {105 i f ( f i r s tUpdateSugge s t i on ) {106 c . gr idy++;107 JLabel updateLabel = new JLabel ( ”

Update passe s ” ) ;108 updateLabel . setFont (new Font ( ”Tahoma

” , Font .BOLD,12 ) ) ;109 panel . add ( updateLabel , c ) ;110 f i r s tUpdateSugge s t i on = f a l s e ; // no

l o n g e r t h e f i r s t u p d a t e , don ’ tp a i n t h e a d e r

111 }112 c . gr idy++;113 panel . add ( suggest ionUpdatePanel ( sug ) , c ) ;114 }115 }116117 boolean f i r s tNewSugges t ion = true ;118 for ( Suggest ion sug : sugge s t i on s ) {119 i f ( sug . getType ( )==Suggest ion .NEW) {120 i f ( f i r s tNewSugges t ion ) {121 c . gr idy++;122 JLabel newLabel = new JLabel ( ”New

passe s ” ) ;123 newLabel . setFont (new Font ( ”Tahoma” ,

Font .BOLD,12 ) ) ;124 panel . add ( newLabel , c ) ;125 f i r s tNewSugges t ion = f a l s e ; // no

l o n g e r t h e f i r s t new s u g g e s t i o n, don ’ t p a i n t h e a d e r

126 }127 c . gr idy++;128 panel . add ( suggestionNewPanel ( sug ) , c ) ;129 }130 }131132 boolean f i r s t D e l e t e S u g g e s t i o n = true ;133 for ( Suggest ion sug : sugge s t i on s ) {134 i f ( sug . getType ( )==Suggest ion .DELETE) {135 i f ( f i r s t D e l e t e S u g g e s t i o n ) {136 c . gr idy++;137 JLabel de l e t eLabe l = new JLabel ( ”

Delete passe s ” ) ;138 de l e t eLabe l . setFont (new Font ( ”Tahoma

” , Font .BOLD,12 ) ) ;139 panel . add ( de le teLabe l , c ) ;140 f i r s t D e l e t e S u g g e s t i o n = f a l s e ; // no

l o n g e r t h e f i r s t news u g g e s t i o n , don ’ t p a i n t h e a d e r

141 }142 c . gr idy++;143 panel . add ( sugges t i onDe le tePane l ( sug ) , c ) ;144 }145 }146147 c . gr idy++;148 c . anchor = GridBagConstraints . LINE END;149 acceptButton = new JButton ( ”Accept” ) ;150 panel . add ( acceptButton , c ) ;151152153 this . add ( panel ) ;154155 acceptButton . addAct ionListener ( c o n t r o l l e r ) ;156 this . pack ( ) ;

Page 234: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

224 Appendix C - Source Code

157 this . s e tLocat ionRe lat iveTo ( null ) ;158 this . s e t V i s i b l e ( true ) ;159160 }161162163 }164165 /∗∗166 ∗ @r e t u r n167 ∗/168 private JPanel tableHeaderPanel ( ) {169 St r ing htmlTable = createHtmlTable ( ” ” , ”<b>Start time</b>” , ”<b>End

time</b>” , ”<b>Pass ID</b>” , ”<b>Ground Stat ion </b>” ) ;170171 JPanel panel = new JPanel ( ) ;172 panel . add (new JLabel ( htmlTable ) ) ;173174 return panel ;175 }176177 /∗∗178 ∗ @param s u g179 ∗ @r e t u r n180 ∗/181 public JPanel suggest ionUpdatePanel ( Suggest ion sug ) {182 JPanel panel = new JPanel ( ) ;183 panel . setLayout (new BorderLayout ( ) ) ;184 panel . setBorder ( BorderFactory . createEtchedBorder ( EtchedBorder .RAISED

) ) ;185186 St r ing o ldSta r t = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( sug . getOldPass ( ) . getStartTime ( )) ;

187 St r ing newStart = new SimpleDateFormat ( MPSPreferences .getFullDateTimeFormat ( ) ) . format ( sug . getNewPass ( ) . getStartTime ( )) ;

188 St r ing oldEnd = new SimpleDateFormat ( MPSPreferences .getFullDateTimeFormat ( ) ) . format ( sug . getOldPass ( ) . getEndTime ( ) ) ;

189 St r ing newEnd = new SimpleDateFormat ( MPSPreferences .getFullDateTimeFormat ( ) ) . format ( sug . getNewPass ( ) . getEndTime ( ) ) ;

190 St r ing passID = ””+sug . getOldPass ( ) . getPassID ( ) ;191 St r ing gs = ””+sug . getOldPass ( ) . getGroundStationName ( ) ;192193 St r ing htmlTable = createHtmlTable ( ”Current :<br>Updated : ” , o ldSta r t

+ ”<br>” + newStart , oldEnd + ”<br>” + newEnd , passID , gs ) ;194195 panel . add (new JLabel ( htmlTable ) , BorderLayout .CENTER) ;196197 JCheckBox checkBox = new JCheckBox ( ) ;198 checkBox . s e t S e l e c t ed ( true ) ;199 panel . add ( checkBox , BorderLayout . LINE END) ;200201 acceptChangeMap . put ( sug , checkBox ) ;202203 return panel ;204 }205206 /∗∗207 ∗ @param s u g208 ∗ @r e t u r n209 ∗/210 public JPanel suggestionNewPanel ( Suggest ion sug ) {211 JPanel panel = new JPanel ( ) ;212 panel . setLayout (new GridBagLayout ( ) ) ;213 panel . setBorder ( BorderFactory . createEtchedBorder ( EtchedBorder .RAISED

) ) ;214215 GridBagConstraints c = new GridBagConstraints ( ) ;216 c . anchor = GridBagConstraints .LINE START;217 c . gr idx = 0 ;218 c . gr idy = 0 ;219220 St r ing s t a r t = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( sug . getNewPass ( ) . getStartTime ( )) ;

221 St r ing end = new SimpleDateFormat ( MPSPreferences .getFullDateTimeFormat ( ) ) . format ( sug . getNewPass ( ) . getEndTime ( ) ) ;

222 St r ing gs = sug . getNewPass ( ) . getGroundStationName ( ) ;223224 St r ing htmlTable = createHtmlTable ( ”New: ” , s ta r t , end , ” . . . ” , gs ) ;225226 panel . add (new JLabel ( htmlTable ) , c ) ;227228 JCheckBox checkBox = new JCheckBox ( ) ;229 checkBox . s e t S e l e c t ed ( true ) ;230

Page 235: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 225

231 c . gr idx++;232 c . anchor = GridBagConstraints . LINE END;233 c . f i l l = GridBagConstraints .HORIZONTAL;234 panel . add ( checkBox , c ) ;235236 acceptChangeMap . put ( sug , checkBox ) ;237238 return panel ;239 }240241 /∗∗242 ∗ @param s u g243 ∗ @r e t u r n244 ∗/245 public JPanel sugges t ionDe le tePane l ( Suggest ion sug ) {246 JPanel panel = new JPanel ( ) ;247 panel . setLayout (new GridBagLayout ( ) ) ;248 panel . setBorder ( BorderFactory . createEtchedBorder ( EtchedBorder .RAISED

) ) ;249250 GridBagConstraints c = new GridBagConstraints ( ) ;251 c . anchor = GridBagConstraints .LINE START;252 c . gr idx = 0 ;253 c . gr idy = 0 ;254255 St r ing s t a r t = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( sug . getOldPass ( ) . getStartTime ( )) ;

256 St r ing end = new SimpleDateFormat ( MPSPreferences .getFullDateTimeFormat ( ) ) . format ( sug . getOldPass ( ) . getEndTime ( ) ) ;

257 St r ing passID = ”” +sug . getOldPass ( ) . getPassID ( ) ;258 St r ing gs = sug . getOldPass ( ) . getGroundStationName ( ) ;259260 St r ing htmlTable = createHtmlTable ( ” De le t ion : ” , s ta r t , end , passID ,

gs ) ;261262 panel . add (new JLabel ( htmlTable ) , c ) ;263264 JCheckBox checkBox = new JCheckBox ( ) ;265 checkBox . s e t S e l e c t ed ( true ) ;266267 c . gr idx++;268 c . anchor = GridBagConstraints . LINE END;269 c . f i l l = GridBagConstraints .HORIZONTAL;270 panel . add ( checkBox , c ) ;271272 acceptChangeMap . put ( sug , checkBox ) ;273274 return panel ;275 }276277278 /∗∗279 ∗ @param f i r s t280 ∗ @param s t a r t281 ∗ @param end282 ∗ @param p a s s ID283 ∗ @param g s284 ∗ @r e t u r n285 ∗/286 private Str ing createHtmlTable ( St r ing f i r s t , S t r ing s ta r t , S t r ing end ,

St r ing passID , St r ing gs ) {287 St r ing htmlTable = ”<html><body><tab l e border=0>” +288 ”<tr>” +289 ”<td width=”+ tableFirstRowWidth +”><i>”+ f i r s t + ”</i ></td>” +290 ”<td width=”+ tableStartTimeWidth +”>” + s t a r t+ ”</td>” +291 ”<td width=”+ tableEndTimeWidth +”>” + end+ ”</td>” +292 ”<td width=”+ tablePassIDWidth +”>” + passID + ”</td>” +293 ”<td width=”+ tableGSWidth +”>” + gs+ ”</td>” +294 ”</tr>” +295 ”</table ></body></html>” ;296297 return htmlTable ;298 }299300 /∗∗301 ∗ @r e t u r n302 ∗/303 public HashMap<Suggest ion , JCheckBox> getAcceptChangeMap ( ) {304 return acceptChangeMap ;305 }306307308 /∗∗309 ∗ @r e t u r n310 ∗/311 public ArrayList<Suggest ion> getSugges t i ons ( ) {

Page 236: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

226 Appendix C - Source Code

312 return sugge s t i on s ;313 }314315316 /∗∗317 ∗ @r e t u r n318 ∗/319 public TimeLineView getTimeLineView ( ) {320 return timeLineView ;321 }322323324 /∗∗325 ∗ @r e t u r n326 ∗/327 public JButton getAcceptButton ( ) {328 return acceptButton ;329 }330331332 }

Page 237: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 227

.1.58 PassManuelSetupController.java

1 package mps . gui . planning . pas se s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;78 import javax . swing . JOptionPane ;9

10 import mcc . s e rv e r . dataProcess ing . Pass ;11 import mcc . s e rv e r . dataProcess ing . T i m e l i n e U t i l i t i e s ;12 import mps . rmi . C l i ent ;1314 /∗∗15 ∗ <br><br>16 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 317 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 118 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 819 ∗/20 public c lass PassManuelSetupControl ler implements Act ionL i s t ener {2122 /∗∗23 ∗24 ∗/25 private PassManuelSetupView view ;2627 /∗∗28 ∗ @param p a s sMa n u e l S e t u pV i e w29 ∗/30 public PassManuelSetupControl ler ( PassManuelSetupView passManuelSetupView ) {31 view = passManuelSetupView ;32 }3334 @Override35 public void act ionPerformed ( ActionEvent ae ) {363738 i f ( ae . getSource ( ) . equa l s ( view . getAddButton ( ) ) ) {3940 long s t a r t = view . getStar tSp inner sPane l ( ) . getTime ( ) ;41 long end = view . getEndSpinnersPanel ( ) . getTime ( ) ;424344 i f ( view . getPassToEdit ( )==null ) {45 // NEW PASS46 St r ing gsName = view . getGsComboBox ( ) . ge tSe l ec tedI tem

() . t oSt r ing ( ) ;47 Pass pass = new Pass (gsName , s ta r t , end ) ;4849 try {50 Cl i ent . g e t In s tance ( ) . getMediumInterface ( ) .

addPass ( pass ) ;51 view . getTimeLineView ( ) .

setScheduleRecommendation ( true ) ;52 } catch ( RemoteException e ) {53 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

54 e . pr intStackTrace ( ) ;55 } catch ( NotBoundException e ) {56 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

57 e . pr intStackTrace ( ) ;58 }59 } else {60 // EDITING PASS61 long passID = view . getPassToEdit ( ) . getPassID ( ) ;6263 i f ( s t a r t !=view . getPassToEdit ( ) . getStartTime ( ) ) {6465 try {66 Cl i ent . ge t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) . modifyPass (passID , T i m e l i n e U t i l i t i e s .STARTTIME, s t a r t ) ;

67 view . getTimeLineView ( ) .setScheduleRecommendation ( true );

68 } catch ( RemoteException e ) {69 JOptionPane . showMessageDialog ( view , e

. getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

70 e . pr intStackTrace ( ) ;

Page 238: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

228 Appendix C - Source Code

71 } catch ( NotBoundException e ) {72 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

73 e . pr intStackTrace ( ) ;74 }75 }76 i f ( end!=view . getPassToEdit ( ) . getEndTime ( ) ) {77 try {78 Cl i ent . g e t In s tance ( ) .

g e t F u l l I n t e r f a c e ( ) . modifyPass (passID , T i m e l i n e U t i l i t i e s .ENDTIME, end ) ;

79 view . getTimeLineView ( ) .setScheduleRecommendation ( true );

80 } catch ( RemoteException e ) {81 JOptionPane . showMessageDialog ( view , e

. getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

82 e . pr intStackTrace ( ) ;83 } catch ( NotBoundException e ) {84 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

85 e . pr intStackTrace ( ) ;86 }87 }8889 }90919293 try {94 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;95 } catch ( RemoteException e ) {96 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;97 e . pr intStackTrace ( ) ;98 } catch ( NotBoundException e ) {99 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;100 e . pr intStackTrace ( ) ;101 }102103104 view . d i spose ( ) ;105106107 }108109 }110111 }

Page 239: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 229

.1.59 DateFormatController.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;7 import java . text . SimpleDateFormat ;89 import javax . swing . JOptionPane ;

1011 import mps . MPSPreferences ;1213 /∗∗14 ∗ <br><br>15 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 316 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 117 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 818 ∗/19 public c lass DateFormatControl ler implements Act ionL i s t ener {2021 /∗∗22 ∗23 ∗/24 private DateFormatView view ;2526 /∗∗27 ∗ @param da t eF o rma tV i ew28 ∗/29 public DateFormatControl ler ( DateFormatView dateFormatView ) {3031 view = dateFormatView ;323334 }3536 @Override37 public void act ionPerformed ( ActionEvent ae ) {383940 i f ( ae . getSource ( ) . equa l s ( view . getOkButton ( ) ) ) {41 // OK BUTTON4243 St r ing time = view . getTimeTextField ( ) . getText ( ) ;44 St r ing date = view . getDateTextField ( ) . getText ( ) ;4546 St r ing errorMsg = ”” ;4748 try {49 SimpleDateFormat timeSDF = new SimpleDateFormat ( time

) ;505152 } catch ( I l l ega lArgumentExcept ion e ) {53 errorMsg += ”<br>− I l l e g a l time s t r i n g pattern ” ;54 }5556 try {57 SimpleDateFormat dateSDF = new SimpleDateFormat ( date

) ;58 } catch ( I l l ega lArgumentExcept ion e ) {59 errorMsg = ”<br>− I l l e g a l date s t r i n g pattern ” ;60 }616263 i f ( errorMsg . equa l s ( ”” ) ) {64 // No e r r o r s i n s t r i n g p a t t e r n s65 MPSPreferences . setDateFormat ( date ) ;66 MPSPreferences . setTimeFormat ( time ) ;6768 try {69 view . getTimeLineView ( ) . updateTimeLineViews ( )

;70 } catch ( RemoteException e ) {71 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

72 e . pr intStackTrace ( ) ;73 } catch ( NotBoundException e ) {74 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

75 e . pr intStackTrace ( ) ;76 }77

Page 240: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

230 Appendix C - Source Code

7879 view . d i spose ( ) ;808182 } else {83 // E r r o r i n s t r i n g p a t t e r n84 St r ing txt = ”The act ion could not be performed f o r

the f o l l ow ing reason ”85 + errorMsg86 + ”<br>Please c o r r e c t the pattern accord ing

to the SimpleDateFormat . ” ;87 JOptionPane . showMessageDialog ( view , txt , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;8889 }909192 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ){93 // CANCEL BUTTON9495 view . d i spose ( ) ;96979899 }

100101102 }103104 }

Page 241: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 231

.1.60 DateFormatView.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . Dimension ;4 import java . awt . GridBagConstraints ;5 import java . awt . GridBagLayout ;6 import java . awt . I n s e t s ;78 import javax . swing . JButton ;9 import javax . swing . JFrame ;

10 import javax . swing . JLabel ;11 import javax . swing . JPanel ;12 import javax . swing . JTextField ;1314 import mps . MPSPreferences ;15 import mps . gui . t ime l i n e . TimeLineView ;1617 /∗∗18 ∗ <br><br>19 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 320 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 121 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 822 ∗/23 public c lass DateFormatView extends JFrame {2425 /∗∗26 ∗27 ∗/28 private stat ic f ina l long se r ia lVers ionUID = 1L ;29 /∗∗30 ∗31 ∗/32 private DateFormatControl ler c o n t r o l l e r ;33 /∗∗34 ∗35 ∗/36 private TimeLineView timeLineView ;3738 /∗∗39 ∗40 ∗/41 private JTextField dateTextFie ld ;42 /∗∗43 ∗44 ∗/45 private JTextField t imeTextFie ld ;46 /∗∗47 ∗48 ∗/49 private JButton okButton ;50 /∗∗51 ∗52 ∗/53 private JButton cancelButton ;5455 /∗∗56 ∗ @param t im e L i n eV i e w57 ∗/58 public DateFormatView ( TimeLineView timeLineView ) {5960 this . timeLineView = timeLineView ;61 c o n t r o l l e r = new DateFormatControl ler ( this ) ;6263 TimeLineView . s e t I con ( this ) ;64 this . s e t T i t l e ( ”Date Format s e t t i n g s ” ) ;656667 JPanel panel = new JPanel ( ) ;68 panel . setLayout (new GridBagLayout ( ) ) ;69 GridBagConstraints c = new GridBagConstraints ( ) ;70 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;717273 JLabel in t roLabe l = new JLabel ( ”<html>Please s p e c i f y how you would l i k e to

have dates r epre sented in MPS. ” +74 ”<br>The <i >\”date and time pattern\”</i> s t r i n g should

f o l l ow the s t y l e o f a java SimpleDateFormat . ” +75 ”<br>For more in format ion on the pattern : http :// java . sun .

com/ j 2 s e /1 . 4 . 2/ docs / api / java / text /SimpleDateFormat . html</html>” ) ;

7677 c . gr idy = 0 ;78 c . gr idx = 0 ;79 c . gr idwidth = 2 ;80 c . anchor = GridBagConstraints .LINE START;

Page 242: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

232 Appendix C - Source Code

8182 panel . add ( introLabe l , c ) ;8384 c . gr idy = 1 ;85 c . gr idwidth = 1 ;86 c . anchor = GridBagConstraints . LINE END;87 panel . add (new JLabel ( ”Date pattern s t r i n g : ” ) , c ) ;8889 dateTextFie ld = new JTextField ( ) ;90 dateTextFie ld . setText ( MPSPreferences . getDateFormat ( ) ) ;91 dateTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (180 ,20) ) ;92 c . gr idx = 1 ;93 c . anchor = GridBagConstraints .LINE START;94 panel . add ( dateTextField , c ) ;9596 c . gr idy = 2 ;97 c . gr idx = 0 ;98 c . anchor = GridBagConstraints . LINE END;99 panel . add (new JLabel ( ”Time pattern s t r i n g : ” ) , c ) ;

100101 timeTextFie ld = new JTextField ( ) ;102 t imeTextFie ld . setText ( MPSPreferences . getTimeFormat ( ) ) ;103 t imeTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (180 ,20) ) ;104 c . gr idx = 1 ;105 c . anchor = GridBagConstraints .LINE START;106 panel . add ( timeTextField , c ) ;107108109 okButton = new JButton ( ”OK” ) ;110 c . gr idy = 3 ;111 c . gr idx = 0 ;112 c . anchor = GridBagConstraints . LINE END;113 panel . add ( okButton , c ) ;114115 cancelButton = new JButton ( ”Cancel ” ) ;116 c . gr idx = 1 ;117 panel . add ( cancelButton , c ) ;118119120 okButton . addAct ionListener ( c o n t r o l l e r ) ;121 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;122123124125 this . add ( panel ) ;126 this . pack ( ) ;127 this . s e tLocat ionRe lat iveTo ( null ) ;128 this . s e t V i s i b l e ( true ) ;129 }130131 /∗∗132 ∗ @r e t u r n133 ∗/134 public JTextField getDateTextField ( ) {135 return dateTextFie ld ;136 }137138 /∗∗139 ∗ @r e t u r n140 ∗/141 public JButton getCancelButton ( ) {142 return cancelButton ;143 }144145 /∗∗146 ∗ @r e t u r n147 ∗/148 public JTextField getTimeTextField ( ) {149 return t imeTextFie ld ;150 }151152 /∗∗153 ∗ @r e t u r n154 ∗/155 public JButton getOkButton ( ) {156 return okButton ;157 }158159 /∗∗160 ∗ @r e t u r n161 ∗/162 public TimeLineView getTimeLineView ( ) {163 return timeLineView ;164 }165166 }

Page 243: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 233

.1.61 PredefinedBlocksPathController.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . i o . F i l e ;67 import javax . swing . JFi leChooser ;8 import javax . swing . JOptionPane ;9

10 import mps . MPSPreferences ;11 import mps . gui . t ime l i n e . TimeLineModel ;1213 /∗∗14 ∗ <br><br>15 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 316 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 117 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 818 ∗/19 public c lass Prede f inedBlocksPathContro l l e r implements Act ionL i s t ener {202122 /∗∗23 ∗24 ∗/25 private PredefinedBlocksPathView view ;2627 /∗∗28 ∗ @param v i e w29 ∗/30 public Prede f inedBlocksPathContro l l e r ( PredefinedBlocksPathView view ) {3132 this . view = view ;3334 }3536 @Override37 public void act ionPerformed ( ActionEvent ae ) {383940 i f ( ae . getSource ( ) . equa l s ( view . getDirButton ( ) ) ) {4142 int returnVal = view . getDirChooser ( ) . showOpenDialog ( view ) ;4344 i f ( returnVal == JFi leChooser .APPROVE OPTION) {45 F i l e f i l e = view . getDirChooser ( ) . g e t S e l e c t e d F i l e ( ) ;46 view . getDirTextFie ld ( ) . setText ( f i l e . getPath ( ) ) ;47 }4849 } else i f ( ae . getSource ( ) . equa l s ( view . getApplyButton ( ) ) ) {5051 // g e t o l d s a v e l o c a t i o n52 St r ing oldPath = MPSPreferences .

getPredefinedCommandBlocksPath ( ) ;53 St r ing newPath = view . getDirTextFie ld ( ) . getText ( ) ;5455 try {56 // s e t new l o c a t i o n i p r e f s57 MPSPreferences . setPredefinedCommandBlocksLocation (

newPath ) ;5859 // s a v e o b j e c t a t new l o c a t i o n60 TimeLineModel . g e t In s tance ( ) .

savePredefinedCommandBlocksFile ( TimeLineModel .g e t In s tance ( ) .getPredefinedCommandBlocksSaveObject ( ) ) ;

6162 // d e l e t e o l d f i l e63 F i l e o l dF i l e = new F i l e ( oldPath ) ;64 i f ( o l dF i l e . e x i s t s ( ) ) o l dF i l e . d e l e t e ( ) ;6566 view . d i spose ( ) ;6768 } catch ( Exception e ) {69 // s e t l o c a t i o n i n p r e f s t o o l d l o c a t i o n a g a i n70 MPSPreferences . setPredefinedCommandBlocksLocation (

oldPath ) ;71 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;72 e . pr intStackTrace ( ) ;73 }747576 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {77 view . d i spose ( ) ;

Page 244: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

234 Appendix C - Source Code

78 }7980 }8182 }

Page 245: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 235

.1.62 PredefinedBlocksPathView.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . Dimension ;4 import java . awt . GridBagConstraints ;5 import java . awt . GridBagLayout ;6 import java . awt . I n s e t s ;78 import javax . swing . JButton ;9 import javax . swing . JDialog ;

10 import javax . swing . JFi leChooser ;11 import javax . swing . JLabel ;12 import javax . swing . JPanel ;13 import javax . swing . JTextField ;1415 import mps . MPSPreferences ;1617 /∗∗18 ∗ <br><br>19 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 320 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 121 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 822 ∗/23 public c lass PredefinedBlocksPathView extends JDialog {2425 /∗∗26 ∗27 ∗/28 private stat ic f ina l long se r ia lVers ionUID = 1L ;29 /∗∗30 ∗31 ∗/32 private JTextField d i rTextF ie ld ;33 /∗∗34 ∗35 ∗/36 private JFi leChooser dirChooser ;37 /∗∗38 ∗39 ∗/40 private JButton dirButton ;41 /∗∗42 ∗43 ∗/44 private JButton applyButton ;45 /∗∗46 ∗47 ∗/48 private JButton cancelButton ;4950 /∗∗51 ∗52 ∗/53 private Prede f inedBlocksPathContro l l e r c o n t r o l l e r ;5455 /∗∗56 ∗57 ∗/58 public PredefinedBlocksPathView ( ) {59 super ( ) ;60 c o n t r o l l e r = new Prede f inedBlocksPathContro l l e r ( this ) ;6162 this . s e t T i t l e ( ”Path to Prede f ined Command Blocks f i l e ” ) ;6364 JPanel panel = new JPanel ( ) ;65 panel . setLayout (new GridBagLayout ( ) ) ;66 GridBagConstraints c = new GridBagConstraints ( ) ;67 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;6869 c . gr idwidth = 3 ;70 c . anchor = GridBagConstraints .LINE START;71 c . gr idx = 0 ;72 c . gr idy = 0 ;73 JLabel in t roLabe l = new JLabel ( ”<html><table><tr><td width=280>To

use the funct i on Load/Save Predef ined Command Block a f i l ec a l l e d \”” + MPSPreferences . getPredefinedCommandBlocksFileName( )

74 + ”\” i s c reated . Please s p e c i f y at which l o c a t i onyou wish to save t h i s f i l e :</td></tr ></table>” );

75 panel . add ( introLabe l , c ) ;7677 c . anchor = GridBagConstraints . LINE END;78 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;79 c . gr idwidth = 1 ;

Page 246: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

236 Appendix C - Source Code

80 c . gr idy = 1 ;81 c . gr idx = 0 ;82 panel . add (new JLabel ( ” Directory : ” ) , c ) ;8384 d i rTextF ie ld = new JTextField ( ) ;85 d i rTextF ie ld . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;86 d i rTextF ie ld . s e tEd i t ab l e ( f a l s e ) ;87 d i rTextF ie ld . setText ( MPSPreferences . getPredefinedCommandBlocksLocation ( )

) ;88 c . anchor = GridBagConstraints .LINE START;89 c . gr idx = 1 ;90 panel . add ( dirTextFie ld , c ) ;9192 dirButton = new JButton ( ” . . . ” ) ;93 dirButton . s e t P r e f e r r e d S i z e (new Dimension (20 ,20) ) ;94 c . gr idx = 2 ;95 panel . add ( dirButton , c ) ;9697 dirChooser = new JFi leChooser ( ) ;98 dirChooser . s e tF i l eSe l e c t i onMode ( JFi leChooser .DIRECTORIES ONLY) ;99

100101 JPanel applyCancelPanel = new JPanel ( ) ;102 applyButton = new JButton ( ”Apply” ) ;103 cancelButton = new JButton ( ”Cancel ” ) ;104 applyCancelPanel . add ( applyButton ) ;105 applyCancelPanel . add ( cancelButton ) ;106107 c . gr idy = 2 ;108 c . gr idx = 0 ;109 c . gr idwidth = 3 ;110 c . anchor = GridBagConstraints .CENTER;111 panel . add ( applyCancelPanel , c ) ;112113 // L i s t e n e r s114 dirButton . addAct ionListener ( c o n t r o l l e r ) ;115 applyButton . addAct ionListener ( c o n t r o l l e r ) ;116 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;117118119 this . add ( panel ) ;120 this . pack ( ) ;121 this . s e tLocat ionRe lat iveTo ( null ) ;122 this . s e t V i s i b l e ( true ) ;123124 }125126 /∗∗127 ∗ @r e t u r n128 ∗/129 public JTextField getDirTextFie ld ( ) {130 return d i rTextF ie ld ;131 }132133 /∗∗134 ∗ @r e t u r n135 ∗/136 public JButton getDirButton ( ) {137 return dirButton ;138 }139140 /∗∗141 ∗ @r e t u r n142 ∗/143 public JButton getApplyButton ( ) {144 return applyButton ;145 }146147 /∗∗148 ∗ @r e t u r n149 ∗/150 public JButton getCancelButton ( ) {151 return cancelButton ;152 }153154 /∗∗155 ∗ @r e t u r n156 ∗/157 public JFi leChooser getDirChooser ( ) {158 return dirChooser ;159 }160161 }

Page 247: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 237

.1.63 StateColoringController.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . Color ;4 import java . awt . event . ActionEvent ;5 import java . awt . event . Act ionL i s t ener ;6 import java . rmi . NotBoundException ;7 import java . rmi . RemoteException ;8 import java . u t i l . HashMap ;9

10 import javax . swing . JButton ;11 import javax . swing . JColorChooser ;12 import javax . swing . JOptionPane ;1314 import mps . MPSPreferences ;1516 import common . command .Command;1718 /∗∗19 ∗ @au t h o r Ma l a e u s20 ∗21 ∗/22 public c lass Sta t eCo lo r ingCont ro l l e r implements Act ionL i s t ener {2324 /∗∗25 ∗26 ∗/27 private StateColor ingView view ;2829 /∗∗30 ∗ @param v i e w31 ∗/32 public Sta t eCo lo r ingCont ro l l e r ( StateColor ingView view ) {33 this . view = view ;34 }3536 @Override37 public void act ionPerformed ( ActionEvent ae ) {383940 i f ( ae . getSource ( ) . equa l s ( view . getOkButton ( ) ) ) {41 // OK b u t t o n c l i c k e d42 view . d i spose ( ) ;43 try {44 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;45 } catch ( RemoteException e ) {46 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;47 e . pr intStackTrace ( ) ;48 } catch ( NotBoundException e ) {49 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;50 e . pr intStackTrace ( ) ;51 }5253 } else {54 // one o f t h e c o l o r c h o s i n g b u t t o n s c l i c k e d55 HashMap<Integer , JButton> buttonMap = view . getButtonMap ( ) ;5657 for ( int id : buttonMap . keySet ( ) ) {5859 i f ( ae . getSource ( ) . equa l s ( buttonMap . get ( id ) ) ) {6061 Color newColor = JColorChooser . showDialog (

view , ”Choose s t a t e c o l o r f o r \”” +Command. de s c r i p eS ta t e ( id ) +”\”” ,MPSPreferences . getStateCo lor ( id ) ) ;

6263 i f ( newColor !=null ) {64 MPSPreferences . s e tS ta teCo lo r ( id ,

newColor . getRGB () ) ;65 view . getColorBoxMap ( ) . get ( id ) .

setBackground ( newColor ) ;66 }6768 }69 }70 }717273 }7475 }

Page 248: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

238 Appendix C - Source Code

.1.64 StateColoringView.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . Dimension ;4 import java . awt . GridBagConstraints ;5 import java . awt . GridBagLayout ;6 import java . awt . I n s e t s ;7 import java . u t i l . HashMap ;89 import javax . swing . JButton ;

10 import javax . swing . JFrame ;11 import javax . swing . JLabel ;12 import javax . swing . JPanel ;1314 import mps . MPSPreferences ;15 import mps . gui . t ime l i n e . TimeLineView ;1617 import common . command .Command;181920 /∗∗21 ∗ <br><br>22 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 323 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 124 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 825 ∗/26 public c lass StateColor ingView extends JFrame {272829 /∗∗30 ∗31 ∗/32 private stat ic f ina l long se r ia lVers ionUID = 1L ;33 /∗∗34 ∗35 ∗/36 private Sta t eCo lo r ingCont ro l l e r c o n t r o l l e r ;37 /∗∗38 ∗39 ∗/40 private TimeLineView timeLineView ;4142 /∗∗43 ∗44 ∗/45 private HashMap<Integer , JButton> buttonMap ;46 /∗∗47 ∗48 ∗/49 private HashMap<Integer , JLabel> colorBoxMap ;50 /∗∗51 ∗52 ∗/53 private JButton okButton ;545556 /∗∗57 ∗ @param t im e L i n eV i e w58 ∗/59 public StateColor ingView ( TimeLineView timeLineView ) {6061 c o n t r o l l e r = new Sta t eCo lo r ingCont ro l l e r ( this ) ;62 this . timeLineView = timeLineView ;6364 this . s e t T i t l e ( ” State Color ing ” ) ;65 TimeLineView . s e t I con ( this ) ;666768 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;6970 GridBagConstraints c = new GridBagConstraints ( ) ;7172 c . gr idy = 0 ;73 c . i n s e t s = new I n s e t s (1 , 2 , 1 , 2 ) ;74 c . anchor = GridBagConstraints .LINE START;7576 buttonMap = new HashMap<Integer , JButton >() ;77 colorBoxMap = new HashMap<Integer , JLabel >() ;7879 for ( int i =0; i <=9; i++) {8081 c . gr idx = 0 ;82 panel . add (new JLabel (Command. de s c r i p eS ta t e ( i )+” : ” ) , c ) ;8384 JLabel colorBox = new JLabel ( ”” ) ;

Page 249: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 239

85 colorBox . setOpaque ( true ) ;86 colorBox . s e t P r e f e r r e d S i z e (new Dimension (30 ,20) ) ;87 colorBox . setBackground ( MPSPreferences . getStateCo lor ( i ) ) ;88 c . gr idx = 1 ;89 panel . add ( colorBox , c ) ;90 colorBoxMap . put ( i , colorBox ) ;9192 JButton button = new JButton ( ” . . ” ) ;93 c . gr idx = 2 ;94 panel . add ( button , c ) ;9596 buttonMap . put ( i , button ) ;97 button . addAct ionListener ( c o n t r o l l e r ) ;9899 c . gr idy++;

100 }101102 c . gr idx = 0 ;103 c . gr idwidth = 3 ;104 c . anchor = GridBagConstraints .CENTER;105 okButton = new JButton ( ”OK” ) ;106 panel . add ( okButton , c ) ;107 okButton . addAct ionListener ( c o n t r o l l e r ) ;108109110111 this . add ( panel ) ;112 this . s e tRe s i z ab l e ( f a l s e ) ;113 this . pack ( ) ;114 this . s e tLocat ionRe lat iveTo ( null ) ;115 this . s e t V i s i b l e ( true ) ;116 ;117118 }119120 /∗∗121 ∗ @r e t u r n122 ∗/123 public HashMap<Integer , JButton> getButtonMap ( ) {124 return buttonMap ;125 }126127 /∗∗128 ∗ @r e t u r n129 ∗/130 public JButton getOkButton ( ) {131 return okButton ;132 }133134 /∗∗135 ∗ @r e t u r n136 ∗/137 public HashMap<Integer , JLabel> getColorBoxMap ( ) {138 return colorBoxMap ;139 }140141 /∗∗142 ∗ @r e t u r n143 ∗/144 public TimeLineView getTimeLineView ( ) {145 return timeLineView ;146 }147148149 }

Page 250: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

240 Appendix C - Source Code

.1.65 TleSettingsController.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . i o . F i l e ;67 import javax . swing . JFi leChooser ;89 import mps . MPSPreferences ;

1011 /∗∗12 ∗ <br><br>13 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 314 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 115 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 816 ∗/17 public c lass TleSe t t i ng sCon t r o l l e r implements Act ionL i s t ener {1819 /∗∗20 ∗21 ∗/22 private TleSett ingsView view ;2324 /∗∗25 ∗ @param t l e S e t t i n g s V i e w26 ∗/27 public TleSe t t i ng sCont r o l l e r ( TleSett ingsView t l eSe t t ing sV i ew ) {28 view = t l eSe t t ing sV i ew ;2930 }3132 @Override33 public void act ionPerformed ( ActionEvent ae ) {3435 i f ( ae . getSource ( ) . equa l s ( view . getDirButton ( ) ) ) {3637 int returnVal = view . getDirChooser ( ) . showOpenDialog ( view ) ;3839 i f ( returnVal == JFi leChooser .APPROVE OPTION) {40 F i l e f i l e = view . getDirChooser ( ) . getCurrentDirectory

( ) ;41 view . getDirTextFie ld ( ) . setText ( f i l e . getPath ( ) ) ;42 }434445 } else i f ( ae . getSource ( ) . equa l s ( view . getApplyButton ( ) ) ) {4647 MPSPreferences . setTLEurl ( view . getUr lTextFie ld ( ) . getText ( ) ) ;48 MPSPreferences . setTLEdir ( view . getDirTextFie ld ( ) . getText ( ) ) ;49 MPSPreferences . s e tSate l l i t eName ( view . getSatNameTextField ( ) .

getText ( ) ) ;50 MPSPreferences . setNumberOfFuturePasses ( ( In t ege r ) view .

getFuturePassesSpinnerNumberModel ( ) . getValue ( ) ) ;51 MPSPreferences . setMinDegreesAboveHorizont ( ( In t ege r ) view .

getDegreesSpinnerNumberModel ( ) . getValue ( ) ) ;5253 view . d i spose ( ) ;54 }5556 }5758 }

Page 251: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 241

.1.66 TleSettingsView.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . Dimension ;4 import java . awt . GridBagConstraints ;5 import java . awt . GridBagLayout ;6 import java . awt . I n s e t s ;78 import javax . swing . JButton ;9 import javax . swing . JDialog ;

10 import javax . swing . JFi leChooser ;11 import javax . swing . JLabel ;12 import javax . swing . JPanel ;13 import javax . swing . JSpinner ;14 import javax . swing . JTextField ;15 import javax . swing . SpinnerModel ;16 import javax . swing . SpinnerNumberModel ;1718 import mps . MPSPreferences ;1920 /∗∗21 ∗ <br><br>22 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 323 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 124 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 825 ∗/26 public c lass TleSett ingsView extends JDialog {2728 /∗∗29 ∗30 ∗/31 private stat ic f ina l long se r ia lVers ionUID = 1L ;3233 /∗∗34 ∗35 ∗/36 private TleSe t t i ng sCont r o l l e r c o n t r o l l e r ;3738 /∗∗39 ∗40 ∗/41 private JTextField ur lTextF ie ld ;42 /∗∗43 ∗44 ∗/45 private JTextField satNameTextField ;46 /∗∗47 ∗48 ∗/49 private JTextField d i rTextF ie ld ;50 /∗∗51 ∗52 ∗/53 private JButton dirButton ;54 /∗∗55 ∗56 ∗/57 private JButton applyButton ;5859 /∗∗60 ∗61 ∗/62 private SpinnerModel futurePassesSpinnerNumberModel ;63 /∗∗64 ∗65 ∗/66 private SpinnerModel degreesSpinnerNumberModel ;6768 /∗∗69 ∗70 ∗/71 private JFi leChooser dirChooser ;7273 /∗∗74 ∗75 ∗/76 public TleSett ingsView ( ) {7778 c o n t r o l l e r = new TleSe t t i ng sCont r o l l e r ( this ) ;7980 this . s e t T i t l e ( ” Se t t i ng s f o r TLE Update” ) ;8182 JPanel panel = new JPanel ( ) ;83 panel . setLayout (new GridBagLayout ( ) ) ;84 GridBagConstraints c = new GridBagConstraints ( ) ;

Page 252: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

242 Appendix C - Source Code

85 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;8687 c . gr idwidth = 1 ;88 c . gr idy = 0 ;89 c . gr idx = 0 ;90 c . anchor = GridBagConstraints . LINE END;91 panel . add (new JLabel ( ”Download URL of TLE: ” ) , c ) ;929394 ur lTextF ie ld = new JTextField ( ) ;95 ur lTextF ie ld . setText ( MPSPreferences . getTLEurl ( ) ) ;96 ur lTextF ie ld . s e t P r e f e r r e d S i z e (new Dimension (250 ,20) ) ;97 c . gr idx = 1 ;98 c . gr idwidth = 2 ;99 c . anchor = GridBagConstraints .LINE START;

100 panel . add ( ur lTextFie ld , c ) ;101102103 c . anchor = GridBagConstraints . LINE END;104 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;105 c . gr idwidth = 1 ;106 c . gr idy = 1 ;107 c . gr idx = 0 ;108 panel . add (new JLabel ( ”Save d i r e c t o r y : ” ) , c ) ;109110 d i rTextF ie ld = new JTextField ( ) ;111 d i rTextF ie ld . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;112 d i rTextF ie ld . s e tEd i t ab l e ( f a l s e ) ;113 d i rTextF ie ld . setText ( MPSPreferences . getTLEdir ( ) ) ;114 c . anchor = GridBagConstraints .LINE START;115 c . gr idx = 1 ;116 panel . add ( dirTextFie ld , c ) ;117118 dirButton = new JButton ( ” . . . ” ) ;119 dirButton . s e t P r e f e r r e d S i z e (new Dimension (20 ,20) ) ;120 dirButton . addAct ionListener ( c o n t r o l l e r ) ;121 c . gr idx = 2 ;122 panel . add ( dirButton , c ) ;123124 dirChooser = new JFi leChooser ( ) ;125 dirChooser . s e tF i l eSe l e c t i onMode ( JFi leChooser .DIRECTORIES ONLY) ;126127128 c . gr idy = 2 ;129 c . gr idx = 0 ;130 c . gr idwidth = 1 ;131 c . anchor = GridBagConstraints . LINE END;132 panel . add (new JLabel ( ” S a t e l l i t e name : ” ) , c ) ;133134135 satNameTextField = new JTextField ( ) ;136 satNameTextField . setText ( MPSPreferences . ge tSate l l i t eName ( ) ) ;137 satNameTextField . s e t P r e f e r r e d S i z e (new Dimension (100 ,20) ) ;138 c . gr idx = 1 ;139 c . gr idwidth = 2 ;140 c . anchor = GridBagConstraints .LINE START;141 panel . add ( satNameTextField , c ) ;142143 c . gr idy = 3 ;144 c . gr idx = 0 ;145 c . gr idwidth = 1 ;146 c . anchor = GridBagConstraints . LINE END;147 panel . add (new JLabel ( ”Future passe s : ” ) , c ) ;148149 futurePassesSpinnerNumberModel = new SpinnerNumberModel (

MPSPreferences . getNumberOfFuturePasses ( ) , 0 , 100 , 1) ;150 JSpinner futurePasse sSp inner = new JSpinner (

futurePassesSpinnerNumberModel ) ;151 c . gr idx = 1 ;152 c . anchor = GridBagConstraints .LINE START;153 panel . add ( futurePassesSpinner , c ) ;154155 c . gr idy = 4 ;156 c . gr idx = 0 ;157 c . gr idwidth = 1 ;158 c . anchor = GridBagConstraints . LINE END;159 panel . add (new JLabel ( ”Min . degree ” ) , c ) ;160161 degreesSpinnerNumberModel = new SpinnerNumberModel ( MPSPreferences .

getMinDegreesAboveHorizont ( ) , 0 , 90 , 1) ;162 JSpinner minDegreeSpinner = new JSpinner ( degreesSpinnerNumberModel ) ;163 JLabel degreeLabel = new JLabel ( ” ( S a t e l l i t e s ho r i z on ta l e l e va t i on at

i t s top must be l a r g e r than t h i s ) ” ) ;164 JPanel degreePanel = new JPanel ( ) ;165 degreePanel . add ( minDegreeSpinner ) ;166 degreePanel . add ( degreeLabel ) ;167 c . gr idx = 1 ;

Page 253: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 243

168 c . anchor = GridBagConstraints .LINE START;169 panel . add ( degreePanel , c ) ;170171172 applyButton = new JButton ( ”Apply” ) ;173 c . gr idy = 5 ;174 c . gr idx = 0 ;175 c . gr idwidth = 3 ;176 c . anchor = GridBagConstraints .CENTER;177 panel . add ( applyButton , c ) ;178179180 applyButton . addAct ionListener ( c o n t r o l l e r ) ;181182183 this . add ( panel ) ;184 this . pack ( ) ;185 this . s e tLocat ionRe lat iveTo ( null ) ;186 this . s e t V i s i b l e ( true ) ;187 }188189 /∗∗190 ∗ @r e t u r n191 ∗/192 public JTextField getUr lTextFie ld ( ) {193 return ur lTextF ie ld ;194 }195196 /∗∗197 ∗ @r e t u r n198 ∗/199 public JTextField getSatNameTextField ( ) {200 return satNameTextField ;201 }202203 /∗∗204 ∗ @r e t u r n205 ∗/206 public JButton getApplyButton ( ) {207 return applyButton ;208 }209210 /∗∗211 ∗ @r e t u r n212 ∗/213 public JTextField getDirTextFie ld ( ) {214 return d i rTextF ie ld ;215 }216217 /∗∗218 ∗ @r e t u r n219 ∗/220 public JButton getDirButton ( ) {221 return dirButton ;222 }223224 /∗∗225 ∗ @r e t u r n226 ∗/227 public JFi leChooser getDirChooser ( ) {228 return dirChooser ;229 }230231 /∗∗232 ∗ @r e t u r n233 ∗/234 public SpinnerModel getFuturePassesSpinnerNumberModel ( ) {235 return futurePassesSpinnerNumberModel ;236 }237238 /∗∗239 ∗ @r e t u r n240 ∗/241 public SpinnerModel getDegreesSpinnerNumberModel ( ) {242 return degreesSpinnerNumberModel ;243 }244245246 }

Page 254: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

244 Appendix C - Source Code

.1.67 UpdateIntervalController.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;56 import mps . MPSPreferences ;78 /∗∗9 ∗ <br><br>

10 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 311 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 112 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 813 ∗/14 public c lass Update Inte rva lCont ro l l e r implements Act ionL i s t ener {1516 /∗∗17 ∗18 ∗/19 private UpdateIntervalView view ;2021 /∗∗22 ∗ @param v i e w23 ∗/24 public Update Inte rva lCont ro l l e r ( UpdateIntervalView view ) {25 this . view = view ;2627 }2829 @Override30 public void act ionPerformed ( ActionEvent ae ) {3132 i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {3334 view . d i spose ( ) ;3536 } else i f ( ae . getSource ( ) . equa l s ( view . getApplyButton ( ) ) ) {37 MPSPreferences . s e tUpdate In te rva l InMi l i s e conds ( ( In t ege r ) view .

getUpdateIntervalSpinnerNumberModel ( ) . getValue ( ) ∗1000) ;38 view . d i spose ( ) ;3940 }4142 }4344 }

Page 255: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 245

.1.68 UpdateIntervalView.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;56 import javax . swing . JButton ;7 import javax . swing . JDialog ;8 import javax . swing . JLabel ;9 import javax . swing . JPanel ;

10 import javax . swing . JSpinner ;11 import javax . swing . SpinnerNumberModel ;1213 import mps . MPSPreferences ;1415 /∗∗16 ∗ <br><br>17 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 318 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 119 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 820 ∗/21 public c lass UpdateIntervalView extends JDialog {222324 /∗∗25 ∗26 ∗/27 private stat ic f ina l long se r ia lVers ionUID = 1L ;28 /∗∗29 ∗30 ∗/31 private SpinnerNumberModel updateIntervalSpinnerNumberModel ;32 /∗∗33 ∗34 ∗/35 private JSpinner update Inte rva lSp inner ;3637 /∗∗38 ∗39 ∗/40 private JButton applyButton ;41 /∗∗42 ∗43 ∗/44 private JButton cancelButton ;4546 /∗∗47 ∗48 ∗/49 private Update Inte rva lCont ro l l e r c o n t r o l l e r ;5051 /∗∗52 ∗53 ∗/54 public UpdateIntervalView ( ) {5556 this . s e t T i t l e ( ”GUI Update i n t e r v a l ” ) ;5758 c o n t r o l l e r = new Update Inte rva lCont ro l l e r ( this ) ;5960 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;61 GridBagConstraints c = new GridBagConstraints ( ) ;62 St r ing d e s c r i p t i on = ” Set the i n t e r v a l with which the new data i s

r e t r i e v d from the database and the GUI i s updated” ;63 JLabel in t roLabe l = new JLabel ( ”<html><table><tr><td width=280>” +

de s c r i p t i on +”</td></tr ></table>” ) ;64 c . gr idx = 0 ;65 c . gr idy = 0 ;66 c . gr idwidth = 2 ;67 panel . add ( introLabe l , c ) ;686970 c . gr idwidth = 1 ;71 c . gr idx = 0 ;72 c . gr idy = 1 ;73 panel . add (new JLabel ( ” In t eva l in seconds : ” ) , c ) ;74 int s t a r t = MPSPreferences . ge tUpdate Inte rva l InMi l i s e conds ( ) /1000;75 updateIntervalSpinnerNumberModel = new SpinnerNumberModel ( s ta r t , 2 ,

180 , 1) ;76 update Inte rva lSp inner = new JSpinner (

updateIntervalSpinnerNumberModel ) ;77 update Inte rva lSp inner . setToolTipText ( d e s c r i p t i on ) ;78 c . gr idx = 1 ;79 c . gr idwidth = 2 ;80 panel . add ( updateInterva lSpinner , c ) ;

Page 256: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

246 Appendix C - Source Code

818283 applyButton = new JButton ( ”Apply” ) ;84 c . gr idwidth = 1 ;85 c . gr idx = 0 ;86 c . gr idy =2;87 panel . add ( applyButton , c ) ;8889 cancelButton = new JButton ( ”Cancel ” ) ;90 c . gr idx = 1 ;91 panel . add ( cancelButton , c ) ;929394 // L i s t e n e r s95 applyButton . addAct ionListener ( c o n t r o l l e r ) ;96 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;979899 this . add ( panel ) ;

100 this . pack ( ) ;101 this . s e tLocat ionRe lat iveTo ( null ) ;102 this . s e t V i s i b l e ( true ) ;103104 }105106 /∗∗107 ∗ @r e t u r n108 ∗/109 public JButton getApplyButton ( ) {110 return applyButton ;111 }112113 /∗∗114 ∗ @r e t u r n115 ∗/116 public JButton getCancelButton ( ) {117 return cancelButton ;118 }119120 /∗∗121 ∗ @r e t u r n122 ∗/123 public SpinnerNumberModel getUpdateIntervalSpinnerNumberModel ( ) {124 return updateIntervalSpinnerNumberModel ;125 }126127 }

Page 257: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 247

.1.69 UserChooserController.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;56 import mcc . s e rv e r . u s e r s . User ;78 /∗∗9 ∗ <br><br>

10 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 311 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 112 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 813 ∗/14 public c lass UserChooserContro l l e r implements Act ionL i s t ener {151617 /∗∗18 ∗19 ∗/20 private UserChooserView view ;2122 /∗∗23 ∗ @param v i e w24 ∗/25 public UserChooserContro l l e r ( UserChooserView view ) {26 this . view = view ;27 }2829 @Override30 public void act ionPerformed ( ActionEvent ae ) {3132 i f ( ae . getSource ( ) . equa l s ( view . getEditButton ( ) ) ) {33 int s e l e c t ed Index = view . ge tUse rL i s t ( ) . ge tSe l e c t ed Index ( ) ;34 User user = view . getUsers ( ) . get ( s e l e c t ed Index ) ;3536 new UserSetupView ( user ) ;3738 view . d i spose ( ) ;3940 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {4142 view . d i spose ( ) ;4344 }4546 }4748 }

Page 258: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

248 Appendix C - Source Code

.1.70 UserChooserView.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . GridBagConstraints ;4 import java . awt . GridBagLayout ;5 import java . awt . I n s e t s ;6 import java . rmi . NotBoundException ;7 import java . rmi . RemoteException ;8 import java . u t i l . ArrayList ;9

10 import javax . swing . JButton ;11 import javax . swing . JFrame ;12 import javax . swing . JL i s t ;13 import javax . swing . JOptionPane ;14 import javax . swing . JPanel ;1516 import mcc . s e rv e r . u s e r s . User ;17 import mps . gui . t ime l i n e . TimeLineView ;18 import mps . rmi . C l i ent ;1920 /∗∗21 ∗ <br><br>22 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 323 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 124 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 825 ∗/26 public c lass UserChooserView extends JFrame{2728 /∗∗29 ∗30 ∗/31 private stat ic f ina l long se r ia lVers ionUID = 1L ;32 /∗∗33 ∗34 ∗/35 private JButton editButton ;36 /∗∗37 ∗38 ∗/39 private JButton cancelButton ;4041 /∗∗42 ∗43 ∗/44 private JL i s t u s e rL i s t ;4546 /∗∗47 ∗48 ∗/49 private ArrayList<User> use r s ;5051 /∗∗52 ∗53 ∗/54 private UserChooserContro l l e r c o n t r o l l e r ;5556 /∗∗57 ∗58 ∗/59 public UserChooserView ( ) {6061 TimeLineView . s e t I con ( this ) ;62 this . s e t T i t l e ( ” Edit user ” ) ;6364 c o n t r o l l e r = new UserChooserContro l l e r ( this ) ;656667 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;6869 try {70717273 GridBagConstraints c = new GridBagConstraints ( ) ;74 c . i n s e t s = new I n s e t s (1 , 1 , 1 , 1 ) ;7576 use r s = Cl i ent . ge t In s tance ( ) . getAdminInter face ( ) . getUsers ( ) ;7778 Object [ ] l i s t = new Object [ u s e r s . s i z e ( ) ] ;79 for ( int i =0; i<=use r s . s i z e ( )−1; i++) {80 l i s t [ i ] = use r s . get ( i ) . getUsername ( ) + ” − ” + User

. ge tTrustDesc r ip t ion ( use r s . get ( i ) . getTrustLeve l( ) ) ;

81 }82

Page 259: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 249

83 u s e rL i s t = new JL i s t ( l i s t ) ;84 c . gr idx = 0 ;85 c . gr idy = 0 ;86 panel . add ( use rL i s t , c ) ;8788 editButton = new JButton ( ” Edit ” ) ;89 cancelButton = new JButton ( ”Cancel ” ) ;90 JPanel buttonPanel = new JPanel ( ) ;91 buttonPanel . add ( editButton ) ;92 buttonPanel . add ( cancelButton ) ;9394 c . gr idy = 1 ;95 c . anchor = GridBagConstraints .CENTER;96 panel . add ( buttonPanel , c ) ;979899 // L i s t e n e r s :

100 editButton . addAct ionListener ( c o n t r o l l e r ) ;101 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;102103104 } catch ( RemoteException e ) {105 JOptionPane . showMessageDialog ( this , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;106 e . pr intStackTrace ( ) ;107 } catch ( NotBoundException e ) {108 JOptionPane . showMessageDialog ( this , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;109 e . pr intStackTrace ( ) ;110 }111112113 this . add ( panel ) ;114 this . pack ( ) ;115 this . s e tLocat ionRe lat iveTo ( null ) ;116 this . s e t V i s i b l e ( true ) ;117118 }119120 /∗∗121 ∗ @r e t u r n122 ∗/123 public JButton getEditButton ( ) {124 return editButton ;125 }126127 /∗∗128 ∗ @r e t u r n129 ∗/130 public JButton getCancelButton ( ) {131 return cancelButton ;132 }133134 /∗∗135 ∗ @r e t u r n136 ∗/137 public JL i s t ge tUse rL i s t ( ) {138 return u s e rL i s t ;139 }140141 /∗∗142 ∗ @r e t u r n143 ∗/144 public ArrayList<User> getUsers ( ) {145 return use r s ;146 }147148 }

Page 260: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

250 Appendix C - Source Code

.1.71 UserSetupController.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . rmi . NotBoundException ;6 import java . rmi . RemoteException ;78 import javax . swing . JOptionPane ;9

10 import mcc . s e rv e r . u s e r s . User ;11 import mps . rmi . C l i ent ;1213 /∗∗14 ∗ <br><br>15 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 316 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 117 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 818 ∗/19 public c lass UserSetupContro l l e r implements Act ionL i s t ener {2021 /∗∗22 ∗23 ∗/24 private UserSetupView view ;2526 /∗∗27 ∗ @param v i e w28 ∗/29 public UserSetupContro l l e r ( UserSetupView view ) {3031 this . view = view ;3233 }3435 @Override36 public void act ionPerformed ( ActionEvent ae ) {373839 i f ( ae . getSource ( ) . equa l s ( view . getSaveButton ( ) ) ) {40 // C r e a t e / S a v e b u t t o n4142 St r ing username = view . getUsernameTextField ( ) . getText ( ) ;4344 i f ( ! view . getPasswordTextField ( ) . getText ( ) . equa l s ( view .

getConfirmPasswordTextField ( ) . getText ( ) ) ) {45 // P a s s w o r d s d o e s NOT match46 JOptionPane . showMessageDialog ( view , ”The two

passwords does not match . ” , ”Password e r r o r ” ,JOptionPane .INFORMATION MESSAGE) ;

47 view . getPasswordTextField ( ) . setText ( ”” ) ;48 view . getConfirmPasswordTextField ( ) . setText ( ”” ) ;49 } else {50 // Pa s swo r d ma t c h e s5152 byte [ ] pass = view . getPasswordTextField ( ) . getText ( ) .

getBytes ( ) ;5354 int t ru s t = User .MINIMAL TRUST;5556 St r ing t r u s t S t r i n g = view . getTrustlevelComboBox ( ) .

ge tSe l ec tedI tem () . t oSt r ing ( ) ;5758 i f ( t r u s t S t r i n g . equa l s ( User .MINIMAL TRUST DESCRIPTION

) ) t ru s t = User .MINIMAL TRUST;59 else i f ( t r u s t S t r i n g . equa l s ( User .

MEDIUM TRUST DESCRIPTION) ) t ru s t = User .MEDIUM TRUST;

60 else i f ( t r u s t S t r i n g . equa l s ( User .FULL TRUST DESCRIPTION) ) t ru s t = User .FULL TRUST;

61 else i f ( t r u s t S t r i n g . equa l s ( User .ADMINISTRATOR TRUST DESCRIPTION) ) t ru s t = User .ADMINISTRATOR TRUST;

6263 boolean ac t i v e = view . getActiveRadioButton ( ) .

i s S e l e c t e d ( ) ;646566 i f ( view . getUser ( )==null ) {67 // NEW USER68 User user = new User ( username , pass , t rust ,

a c t i v e ) ;69 try {

Page 261: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 251

70 Cl i ent . ge t In s tance ( ) .getAdminInter face ( ) . addUser (user ) ;

71 view . d i spose ( ) ;72 } catch ( RemoteException e ) {73 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

74 e . pr intStackTrace ( ) ;75 } catch ( NotBoundException e ) {76 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

77 e . pr intStackTrace ( ) ;78 }79 } else {80 // EDIT USER8182 try {8384 i f ( view . getUser ( ) . getPassword ( ) !=

pass ) {85 Cl i ent . ge t In s tance ( ) .

getAdminInter face ( ) .changeUserPassword ( view. getUser ( ) . getUsername( ) , view .getPasswordTextField ( ) .getText ( ) ) ;

86 }8788 i f ( view . getUser ( ) . getTrustLeve l ( ) !=

t ru s t ) {89 Cl i ent . ge t In s tance ( ) .

getAdminInter face ( ) .se tUserTrustLeve l ( view .getUser ( ) . getUsername ( ), t r u s t ) ;

90 }9192 i f ( view . getUser ( ) . i sAc t i v e ( ) != ac t i v e

) {93 Cl i ent . ge t In s tance ( ) .

getAdminInter face ( ) .s e tUse rAct ivat i on ( view .getUser ( ) . getUsername ( ), a c t i v e ) ;

94 }9596 view . d i spose ( ) ;9798 } catch ( RemoteException e ) {99 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

100 e . pr intStackTrace ( ) ;101 } catch ( NotBoundException e ) {102 JOptionPane . showMessageDialog ( view ,

e . getMessage ( ) , ” Error ” ,JOptionPane .ERROR MESSAGE) ;

103 e . pr intStackTrace ( ) ;104 }105106 }107108 }109110 } else i f ( ae . getSource ( ) . equa l s ( view . getCancelButton ( ) ) ) {111 // C a n c e l112 view . d i spose ( ) ;113 }114115116 }117118 }

Page 262: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

252 Appendix C - Source Code

.1.72 UserSetupView.java

1 package mps . gui . s e t t i n g s ;23 import java . awt . Dimension ;4 import java . awt . FlowLayout ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;7 import java . awt . I n s e t s ;89 import javax . swing . ButtonGroup ;

10 import javax . swing . JButton ;11 import javax . swing . JComboBox ;12 import javax . swing . JFrame ;13 import javax . swing . JLabel ;14 import javax . swing . JPanel ;15 import javax . swing . JPasswordField ;16 import javax . swing . JRadioButton ;17 import javax . swing . JTextField ;1819 import mcc . s e rv e r . u s e r s . User ;20 import mps . gui . t ime l i n e . TimeLineView ;2122 /∗∗23 ∗ <br><br>24 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 325 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 126 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 827 ∗/28 public c lass UserSetupView extends JFrame {2930 /∗∗31 ∗32 ∗/33 private stat ic f ina l long se r ia lVers ionUID = 1L ;34 /∗∗35 ∗36 ∗/37 private JTextField usernameTextField ;38 /∗∗39 ∗40 ∗/41 private JPasswordField passwordTextField ;42 /∗∗43 ∗44 ∗/45 private JPasswordField confirmPasswordTextField ;46 /∗∗47 ∗48 ∗/49 private JComboBox trustlevelComboBox ;50 /∗∗51 ∗52 ∗/53 private JRadioButton activeRadioButton ;54 /∗∗55 ∗56 ∗/57 private JRadioButton inActiveRadioButton ;5859 /∗∗60 ∗61 ∗/62 private JButton saveButton ;63 /∗∗64 ∗65 ∗/66 private JButton cancelButton ;6768 /∗∗69 ∗70 ∗/71 private User user ;72 /∗∗73 ∗74 ∗/75 private UserSetupContro l l e r c o n t r o l l e r ;767778 /∗∗79 ∗ @param a r g s80 ∗/81 public stat ic void main ( St r ing [ ] args ) {82 new UserSetupView ( ) ;83 }84

Page 263: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 253

8586 /∗∗87 ∗ B u i l d s a f r ame wh e r e an admin can c r e a t e a new u s e r88 ∗/89 public UserSetupView ( ) {90 this . s e t T i t l e ( ” Create user ” ) ;91 bu i ld ( ) ;92 activeRadioButton . s e t S e l e c t ed ( true ) ;93 saveButton . setText ( ” Create user ” ) ;9495 }9697 /∗∗ B u i l d s a f r ame wh e r e an admin can e d i t an e x i s t i n g u s e r98 ∗ @param u s e r t h e u s e r t o e d i t99 ∗/

100 public UserSetupView ( User user ) {101102 this . user = user ;103104 this . s e t T i t l e ( ” Edit user ” ) ;105106 bu i ld ( ) ;107108 usernameTextField . setText ( user . getUsername ( ) ) ;109 usernameTextField . setEnabled ( f a l s e ) ;110111 trustlevelComboBox . s e tSe l e c t ed I t em ( User . ge tTrustDesc r ip t ion ( user .

getTrustLeve l ( ) ) ) ;112113 i f ( user . i sAc t i v e ( ) ) activeRadioButton . s e t S e l e c t ed ( true ) ;114 else inActiveRadioButton . s e t S e l e c t ed ( true ) ;115116 saveButton . setText ( ”Save changes ” ) ;117 }118119120 /∗∗121 ∗ Adds a l l t h e c ompon e n t s o f t h i s f r ame a t t h e r i g h t p l a c e s122 ∗/123 private void bui ld ( ) {124125 TimeLineView . s e t I con ( this ) ;126127 c o n t r o l l e r = new UserSetupContro l l e r ( this ) ;128129 this . setLayout (new FlowLayout ( FlowLayout .LEADING) ) ;130131 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;132133 GridBagConstraints c = new GridBagConstraints ( ) ;134135 c . i n s e t s = new I n s e t s (1 , 1 , 1 , 1 ) ;136137 c . gr idx = 0 ;138 c . gr idy = 0 ;139 c . anchor = GridBagConstraints . LINE END;140 panel . add (new JLabel ( ”Name : ” ) , c ) ;141142 usernameTextField = new JTextField ( ) ;143 usernameTextField . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;144 c . gr idx++;145 c . anchor = GridBagConstraints .LINE START;146 panel . add ( usernameTextField , c ) ;147148 c . gr idx = 0 ;149 c . gr idy++;150 c . anchor = GridBagConstraints . LINE END;151 panel . add (new JLabel ( ”New password : ” ) , c ) ;152153 passwordTextField = new JPasswordField ( ) ;154 passwordTextField . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;155 c . gr idx++;156 c . anchor = GridBagConstraints .LINE START;157 panel . add ( passwordTextField , c ) ;158159 c . gr idx = 0 ;160 c . gr idy++;161 c . anchor = GridBagConstraints . LINE END;162 panel . add (new JLabel ( ”Confirm password : ” ) , c ) ;163164 confirmPasswordTextField = new JPasswordField ( ) ;165 confirmPasswordTextField . s e t P r e f e r r e d S i z e (new Dimension (200 ,20) ) ;166 c . gr idx++;167 c . anchor = GridBagConstraints .LINE START;168 panel . add ( confirmPasswordTextField , c ) ;169170 c . gr idx = 0 ;

Page 264: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

254 Appendix C - Source Code

171 c . gr idy++;172 c . anchor = GridBagConstraints . LINE END;173 panel . add (new JLabel ( ”Trust l e v e l : ” ) , c ) ;174175 trustlevelComboBox = new JComboBox ( ) ;176 trustlevelComboBox . addItem ( User .MINIMAL TRUST DESCRIPTION) ;177 trustlevelComboBox . addItem ( User .MEDIUM TRUST DESCRIPTION) ;178 trustlevelComboBox . addItem ( User .FULL TRUST DESCRIPTION) ;179 trustlevelComboBox . addItem ( User .ADMINISTRATOR TRUST DESCRIPTION) ;180 c . gr idx++;181 c . anchor = GridBagConstraints .LINE START;182 panel . add ( trustlevelComboBox , c ) ;183184 c . gr idx = 0 ;185 c . gr idy++;186 c . anchor = GridBagConstraints . LINE END;187 panel . add (new JLabel ( ” Active : ” ) , c ) ;188189 activeRadioButton = new JRadioButton ( ”True” ) ;190 inActiveRadioButton = new JRadioButton ( ” False ” ) ;191 ButtonGroup buttonGroup = new ButtonGroup ( ) ;192 buttonGroup . add ( activeRadioButton ) ;193 buttonGroup . add ( inActiveRadioButton ) ;194 JPanel i sAct ivePane l = new JPanel ( ) ;195 i sAct ivePane l . add ( activeRadioButton ) ;196 i sAct ivePane l . add ( inActiveRadioButton ) ;197 c . gr idx++;198 c . anchor = GridBagConstraints .LINE START;199 panel . add ( i sAct ivePane l , c ) ;200201202 saveButton = new JButton ( ) ;203 cancelButton = new JButton ( ”Cancel ” ) ;204205 JPanel buttonPanel = new JPanel ( ) ;206 buttonPanel . add ( saveButton ) ;207 buttonPanel . add ( cancelButton ) ;208 c . gr idx = 0 ;209 c . gr idy++;210 c . gr idwidth = 2 ;211 c . anchor = GridBagConstraints .CENTER;212 panel . add ( buttonPanel , c ) ;213214215 // L i s t e n e r s216 saveButton . addAct ionListener ( c o n t r o l l e r ) ;217 cancelButton . addAct ionListener ( c o n t r o l l e r ) ;218219 this . add ( panel ) ;220 this . pack ( ) ;221 this . s e tLocat ionRe lat iveTo ( null ) ;222 this . s e t V i s i b l e ( true ) ;223 }224225226 // GETTERS AND SETTERS :227228 /∗∗229 ∗ @r e t u r n230 ∗/231 public JTextField getUsernameTextField ( ) {232 return usernameTextField ;233 }234235 /∗∗236 ∗ @r e t u r n237 ∗/238 public JPasswordField getPasswordTextField ( ) {239 return passwordTextField ;240 }241242 /∗∗243 ∗ @r e t u r n244 ∗/245 public JComboBox getTrustlevelComboBox ( ) {246 return trustlevelComboBox ;247 }248249 /∗∗250 ∗ @r e t u r n251 ∗/252 public JButton getSaveButton ( ) {253 return saveButton ;254 }255256 /∗∗257 ∗ @r e t u r n

Page 265: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 255

258 ∗/259 public JButton getCancelButton ( ) {260 return cancelButton ;261 }262263 /∗∗264 ∗ @r e t u r n265 ∗/266 public User getUser ( ) {267 return user ;268 }269270271 /∗∗272 ∗ @r e t u r n273 ∗/274 public JRadioButton getActiveRadioButton ( ) {275 return activeRadioButton ;276 }277278279 /∗∗280 ∗ @r e t u r n281 ∗/282 public JRadioButton getInActiveRadioButton ( ) {283 return inActiveRadioButton ;284 }285286287 /∗∗288 ∗ @r e t u r n289 ∗/290 public JPasswordField getConfirmPasswordTextField ( ) {291 return confirmPasswordTextField ;292 }293294295 }

Page 266: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

256 Appendix C - Source Code

.1.73 CommandAbstractTableModel.java

1 package mps . gui . t ime l i n e ;23 import java . u t i l . ArrayList ;4 import java . u t i l . Co l l e c t i o n s ;5 import java . u t i l . Date ;67 import javax . swing . tab l e . AbstractTableModel ;89 import mcc . s e rv e r . dataProcess ing . Pass ;

1011 import common . command .Command;12 import common . command . DTUsat2Command ;13 import common . command . DTUsat2CommandTypeMap ;1415 /∗∗16 ∗ <br><br>17 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 318 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 119 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 820 ∗/21 public c lass CommandAbstractTableModel extends AbstractTableModel{2223 /∗∗24 ∗25 ∗/26 private stat ic f ina l long se r ia lVers ionUID = 1L ;2728 public stat ic f ina l int ID COLUMN =

0;29 public stat ic f ina l int TYPE COLUMN =

1;30 public stat ic f ina l int BLOCK COLUMN = 2;31 public stat ic f ina l int NAME COLUMN = 3;32 public stat ic f ina l int DESTINATION COLUMN = 4;33 public stat ic f ina l int PARAMETERS COLUMN = 5;34 public stat ic f ina l int PASS COLUMN = 6;35 public stat ic f ina l int TIME OF EXECUTION COLUMN = 7;36 public stat ic f ina l int BYTES COLUMN = 8;37 public stat ic f ina l int STATE COLUMN = 9;3839 /∗∗40 ∗41 ∗/42 private TimeLineModel timeLineModel = TimeLineModel . g e t In s tance ( ) ;434445 /∗∗46 ∗47 ∗/48 public CommandAbstractTableModel ( ) {49 }5051 public int getColumnCount ( ) {52 return 10 ; // co lumnNames . l e n g t h ;53 }5455 public int getRowCount ( ) {56 return timeLineModel . getTimelineData ( ) . numberOfCommands ( ) ;57 }5859 public Str ing getColumnName( int co l ) {6061 switch ( c o l ) {62 case ID COLUMN: return ” Id” ;63 case TYPE COLUMN: return ”Type” ;64 case BLOCK COLUMN: return ”Block” ;65 case NAME COLUMN: return ”Name” ;66 case DESTINATION COLUMN: return ”ModuleID” ;67 case PARAMETERS COLUMN: return ”Parameters ” ;68 case PASS COLUMN: return ”Pass” ;69 case TIME OF EXECUTION COLUMN: return ”Time o f execut ion ” ;70 case BYTES COLUMN: return ”Bytes” ;71 case STATE COLUMN: return ” State ” ;72 default :73 return ”Unknown column” ;74 }75 }7677 public Object getValueAt ( int row , int co l ) {7879 // c o n v e r t HashMap t o A r r a y L i s t80 ArrayList<Command> array = new ArrayList<Command>(timeLineModel .

getTimelineData ( ) . getCommandMap( ) . va lues ( ) ) ;81

Page 267: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 257

82 Co l l e c t i on s . s o r t ( array ) ;8384 i f ( array . s i z e ( )==0 | | row>array . s i z e ( )−1) return ”” ;85 Command command = array . get ( row ) ;86 // i f ( command == n u l l ) r e t u r n ” ” ;8788 switch ( c o l ) {89 case ID COLUMN:90 return command . getCommandID ( ) ;91 case TYPE COLUMN:92 return command . getCommandTypeID ( ) ;93 case BLOCK COLUMN:94 return command . getBlockID ( ) ;95 case NAME COLUMN:96 return DTUsat2CommandTypeMap . ge t In s tance ( ) . getCommandType(

command . getCommandTypeID ( ) ) . getName ( ) ;97 case DESTINATION COLUMN:98 return ( (DTUsat2Command) command) . ge tDes t ina t i on ( ) ;99 case PARAMETERS COLUMN:

100 return command . getParameters ( ) ;101 case PASS COLUMN:102 return command . getPassID ( ) == −1 ? ”NA” : command . getPassID

( ) ;103 case TIME OF EXECUTION COLUMN:104 // r e t u r n new j a v a . t e x t . S im p l eD a t e F o rma t ( ” dd /MM−y y y y HH :mm: s s

” ) . f o rm a t ( new j a v a . u t i l . Da t e ( command .g e t T i m e O f E x e c u t i o n ( ) ) ) ;

105106 // I f command i s / was ASAP107 i f (command . getTimeOfExecution ( )==−1) {108 // i f command a l r e a d y h a s a p a s s a s s i g n e d109 i f (command . getPassID ( ) !=−1) {110 // show s t a r t t im e o f t h e commands p a s s (

t h i s i s an a p p r o x i m a t i o n111 Pass pass = timeLineModel . getTimelineData ( ) .

lookupPass (command . getPassID ( ) ) ;112 return new Date ( pass . getStartTime ( ) ) ;113114 } else {115 i f ( timeLineModel . getNextOpenPass ( ) !=null ) {116 return new Date ( timeLineModel .

getNextOpenPass ( ) . getStartTime( ) ) ;

117 } else {118 // TODO: I f no p a s s i n t h e f u t u r e

e x i s t s119 }120 }121122 } else { // no rma l command123 return new Date (command . getTimeOfExecution ( ) ) ;124 }125 // r e t u r n command . g e t T i m e O f E x e c u t i o n ( )==−1 ? ”ASAP” : new

Da t e ( command . g e t T i m e O f E x e c u t i o n ( ) ) ;126 // r e t u r n new Da t e ( command . g e t T i m e O f E x e c u t i o n ( ) ) ;127 case BYTES COLUMN:128 return command . getByteS ize ( ) ;129 case STATE COLUMN:130 return command . ge tS ta t eDes c r ip t i on ( ) ;131 default :132 return null ;133 }134 }135136 /∗∗137 ∗ @param c138 ∗ @r e t u r n139 ∗/140 public Str ing getClassNameWithoutPackage ( Class c ) {141 St r ing FQClassName = c . getName ( ) ;142 int f i r s tCha r ;143 f i r s tCha r = FQClassName . las t IndexOf ( ’ . ’ ) + 1 ;144 i f ( f i r s tCha r > 0) {145 FQClassName = FQClassName . subs t r ing ( f i r s tCha r ) ;146 }147 return FQClassName ;148 }149150 /∗151 ∗ JT a b l e u s e s t h i s me t hod t o d e t e r m i n e t h e d e f a u l t r e n d e r e r /152 ∗ e d i t o r f o r e a c h c e l l . I f we d i d n ’ t im p l em e n t t h i s method ,153 ∗ t h e n t h e l a s t c o l umn wou l d c o n t a i n t e x t ( ” t r u e ”/” f a l s e ” ) ,154 ∗ r a t h e r t h a n a c h e c k b o x .155 ∗/156 public Class getColumnClass ( int c ) {157 // i f ( c ==5) {158 // r e t u r n Da t e . c l a s s ;

Page 268: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

258 Appendix C - Source Code

159 // }160 return getValueAt (0 , c ) . ge tClas s ( ) ;161 }162163164 }

Page 269: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 259

.1.74 CommandInfoView.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Dimension ;4 import java . awt . FlowLayout ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;7 import java . awt . I n s e t s ;8 import java . rmi . NotBoundException ;9 import java . rmi . RemoteException ;

10 import java . text . SimpleDateFormat ;11 import java . u t i l . ArrayList ;1213 import javax . swing . JDialog ;14 import javax . swing . JLabel ;15 import javax . swing . JOptionPane ;16 import javax . swing . JPanel ;17 import javax . swing . JScro l lPane ;1819 import mcc . s e rv e r . dataProcess ing . CommandHistory ;20 import mps . MPSPreferences ;21 import mps . rmi . C l i ent ;2223 import common . command .Command;24 import common . command . DTUsat2Command ;2526 /∗∗27 ∗ <br><br>28 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 329 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 130 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 831 ∗/32 public c lass CommandInfoView extends JDialog {333435 /∗∗36 ∗37 ∗/38 private stat ic f ina l long se r ia lVers ionUID = 1L ;3940 /∗∗41 ∗ @param commandID42 ∗/43 public CommandInfoView( long commandID) {4445 DTUsat2Command command = (DTUsat2Command) TimeLineModel . g e t In s tance

( ) . getTimelineData ( ) . lookupCommand(commandID) ;4647 this . s e t T i t l e ( ”Command In fo f o r \”” + commandID + ”\”” ) ;48 this . setLayout (new FlowLayout ( FlowLayout .LEADING) ) ;4950 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;51 GridBagConstraints c = new GridBagConstraints ( ) ;5253 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;5455 c . gr idx = 0 ;56 c . gr idy = 0 ;57 c . anchor = GridBagConstraints .LINE START;5859 panel . add (new JLabel ( TimeLineModel . g e t In s tance ( ) . getHtmlPrettyPrint (

commandID) ) , c ) ;606162 ArrayList<CommandHistory> commandHistories = null ;63 try {6465 commandHistories = Cl i ent . ge t In s tance ( ) . ge tMin ima l Inte r face

( ) . getCommandHistory ( null ) ;66 } catch ( RemoteException e ) {67 JOptionPane . showMessageDialog ( this , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;68 e . pr intStackTrace ( ) ;69 } catch ( NotBoundException e ) {70 JOptionPane . showMessageDialog ( this , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;71 e . pr intStackTrace ( ) ;72 }73 CommandHistory commandHistory = null ; // commands h i s t o r y f o r t h i s

command74 for ( CommandHistory ch : commandHistories ) {75 i f ( ch . getCommandID ( )==commandID) {76 commandHistory = ch ;77 break ;78 }

Page 270: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

260 Appendix C - Source Code

79 }8081 St r ing commandHistoryText = ”<html><b>History f o r command with ID ”

+ commandID + ”:<b><br>” + ”<tab l e width=400>” ;82 // G e n e r a t i n g t h e h i s t o r y t e x t83 for ( int i = 0 ; i<=commandHistory . s i z e ( )−1; i++){84 long unixtime = commandHistory . getCommandHistoryPart ( i ) .

getTime ( ) ;85 St r ing time = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( unixtime ) ;86 St r ing username= commandHistory . getCommandHistoryPart ( i ) .

getUsername ( ) ;87 St r ing s t a t e = Command. de s c r i p eS ta t e ( commandHistory .

getCommandHistoryPart ( i ) . getCommandState ( ) ) ;88 commandHistoryText += ”<tr><td>” + time + ”</td><td>” +

username + ”</td><td>” + s ta t e + ”</td></tr>” ;8990 }91 commandHistoryText += ”</table ></html>” ;9293 JLabel label = new JLabel ( commandHistoryText ) ;94 label . s e tVert i ca lA l ignment ( JLabel .TOP) ;9596 JScro l lPane h i s t o rySc ro l lPane = new JScro l lPane ( label ) ;97 h i s t o rySc ro l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .

VERTICAL SCROLLBAR ALWAYS) ;98 h i s t o rySc ro l lPane . s e t P r e f e r r e d S i z e (new Dimension (420 , 300) ) ;99 h i s t o rySc ro l lPane . setMinimumSize (new Dimension (10 , 10) ) ;

100101 c . gr idx = 0 ;102 c . gr idy = 1 ;103 panel . add ( h i s to ryScro l lPane , c ) ;104105 this . add ( panel ) ;106 this . pack ( ) ;107 this . s e tLocat ionRe lat iveTo ( null ) ;108 this . s e t V i s i b l e ( true ) ;109 }110111 }

Page 271: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 261

.1.75 CommandTableController.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Point ;4 import java . awt . event . ActionEvent ;5 import java . awt . event . Act ionL i s t ener ;6 import java . awt . event . MouseEvent ;7 import java . awt . event . MouseListener ;8 import java . rmi . NotBoundException ;9 import java . rmi . RemoteException ;

1011 import javax . swing . JOptionPane ;12 import javax . swing . event . L i s tSe l e c t i onEvent ;13 import javax . swing . event . L i s t S e l e c t i o n L i s t e n e r ;1415 import mcc . s e rv e r . u s e r s . User ;16 import mps . gui . commanding . SingleCommandSetupView ;17 import mps . gui . commanding . block . CommandBlockSetupView ;18 import mps . rmi . C l i ent ;1920 import common . command .Command;21 import common . except ions . I l l ega lParamete rExcept ion ;22 import common . except ions . UnknownCommandTypeException ;2324 /∗∗25 ∗ <br><br>26 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 327 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 128 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 829 ∗/30 public c lass CommandTableController implements L i s t S e l e c t i o nL i s t e n e r , Act ionListener

, MouseListener {3132 /∗∗33 ∗34 ∗/35 private CommandTableView view ;3637 /∗∗38 ∗ @param v i e w39 ∗/40 public CommandTableController (CommandTableView view ) {41 this . view = view ;4243 }4445 @Override46 public void valueChanged ( L i s tSe l e c t i onEvent arg0 ) {4748 // r e p a i n t g r a p h i c t i m e l i n e t o make t h e s e l e c t i n g v i s i b l e49 view . getTimeLineView ( ) . getGraphicView ( ) . r epa in t ( ) ;5051 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( ) >= User .FULL TRUST) {52 view . updateButtonEnabi l i ty ( ) ;53 }545556 }5758 @Override59 public void act ionPerformed ( ActionEvent ae ) {606162 // BUTTON PRESSED6364 i f ( ae . getSource ( ) . equa l s ( view . getNewCommandButton ( ) ) ) {65 // NEW COMMAND BUTTON6667 new SingleCommandSetupView ( view . getTimeLineView ( ) ) ;686970 } else i f ( ae . getSource ( ) . equa l s ( view . getNewCommandBlockButton ( ) ) ) {71 // NEW COMMAND BLOCK72 new CommandBlockSetupView ( view . getTimeLineView ( ) ) ;737475 } else i f ( ae . getSource ( ) . equa l s ( view . getDeleteButton ( ) ) | | ae .

getSource ( ) . equa l s ( view . getDeleteMenuItem () ) ) {76 // DELETE BUTTON7778 int [ ] se lectedRows = view . getTable ( ) . getSelectedRows ( ) ;79 for ( int i =0; i<=selectedRows . length −1; i++) {80 long commandID = ( Long ) view . getTable ( ) . getValueAt (

se lectedRows [ i ] , CommandAbstractTableModel .ID COLUMN) ;

Page 272: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

262 Appendix C - Source Code

81 try {82 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

removeCommand(commandID) ;83 view . getTimeLineView ( ) .

setScheduleRecommendation ( true ) ;8485 } catch ( RemoteException e ) {86 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

87 e . pr intStackTrace ( ) ;88 } catch ( NotBoundException e ) {89 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

90 e . pr intStackTrace ( ) ;91 }92 }9394 update ( ) ;9596 } else i f ( ae . getSource ( ) . equa l s ( view . getVer i fyButton ( ) ) | | ae .

getSource ( ) . equa l s ( view . getVerifyMenuItem () ) ) {97 // VERIFY BUTTON9899 int [ ] se lectedRows = view . getTable ( ) . getSelectedRows ( ) ;

100 for ( int i =0; i<=selectedRows . length −1; i++) {101 long commandID = ( Long ) view . getTable ( ) . getValueAt (

se lectedRows [ i ] , CommandAbstractTableModel .ID COLUMN) ;

102 try {103 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

verifyCommand (commandID , true ) ;104105 } catch ( RemoteException e ) {106 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

107 e . pr intStackTrace ( ) ;108 } catch ( NotBoundException e ) {109 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

110 e . pr intStackTrace ( ) ;111 }112 }113114 update ( ) ;115116117 } else i f ( ae . getSource ( ) . equa l s ( view . getEditButton ( ) ) | | ae .

getSource ( ) . equa l s ( view . getEditMenuItem () ) ) {118 // EDIT COMMAND119120 int row = view . getTable ( ) . getSelectedRow () ;121 long commandID = ( Long ) view . getTable ( ) . getValueAt ( row ,

CommandAbstractTableModel . ID COLUMN) ;122 Command command = TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . lookupCommand(commandID) ;123124 new SingleCommandSetupView ( view . getTimeLineView ( ) ,command ,

f a l s e ) ;125126127128 } else i f ( ae . getSource ( ) . equa l s ( view . getEditBlockButton ( ) ) | | ae .

getSource ( ) . equa l s ( view . getEditBlockMenuItem () ) ) {129 // EDIT BLOCK130131 int row = view . getTable ( ) . getSelectedRow () ;132 long blockID = ( Long ) view . getTable ( ) . getValueAt ( row ,

CommandAbstractTableModel .BLOCK COLUMN) ;133134 try {135 new CommandBlockSetupView ( view . getTimeLineView ( ) ,

blockID ) ;136 } catch (UnknownCommandTypeException e ) {137 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;138 e . pr intStackTrace ( ) ;139 } catch ( I l l ega lParamete rExcept ion e ) {140 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;141 e . pr intStackTrace ( ) ;142 }143

Page 273: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 263

144 } else i f ( ae . getSource ( ) . equa l s ( view . getCopyButton ( ) ) | | ae .getSource ( ) . equa l s ( view . getCopyMenuItem () ) ) {

145 // COPY BUTTON146 int row = view . getTable ( ) . getSelectedRow () ;147 long commandID = ( Long ) view . getTable ( ) . getValueAt ( row ,

CommandAbstractTableModel . ID COLUMN) ;148 Command command = TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . lookupCommand(commandID) ;149150 new SingleCommandSetupView ( view . getTimeLineView ( ) ,command ,

true ) ;151 }152153 }154155 /∗∗156 ∗157 ∗/158 private void update ( ) {159 try {160 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;161 view . getTimeLineView ( ) . newFi l ter ( ) ;162 } catch ( RemoteException e ) {163 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;164 e . pr intStackTrace ( ) ;165 } catch ( NotBoundException e ) {166 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;167 e . pr intStackTrace ( ) ;168 }169 }170171 @Override172 public void mouseClicked ( MouseEvent e ) {173174 i f ( e . getClickCount ( ) == 2 && e . getButton ( )== MouseEvent .BUTTON1){175 int row = view . getTable ( ) . getSelectedRow () ;176 long commandID = ( Long ) view . getTable ( ) . getValueAt ( row ,

CommandAbstractTableModel . ID COLUMN) ;177 new CommandInfoView(commandID) ;178 }179 }180181 @Override182 public void mouseEntered ( MouseEvent e ) {183 // TODO Auto−g e n e r a t e d me t hod s t u b184185 }186187 @Override188 public void mouseExited ( MouseEvent e ) {189 // TODO Auto−g e n e r a t e d me t hod s t u b190191 }192193 @Override194 public void mousePressed ( MouseEvent e ) {195 // TODO Auto−g e n e r a t e d me t hod s t u b196197 }198199 @Override200 public void mouseReleased ( MouseEvent e ) {201202 maybeShowPopup( e ) ;203204 }205206 /∗∗207 ∗ @param e208 ∗/209 private void maybeShowPopup( MouseEvent e ) {210 i f ( e . isPopupTrigger ( ) ) {211212 int row = view . getTable ( ) . rowAtPoint (new Point ( e . getX ( ) , e . getY ( ) ) ) ;213214 i f ( row!=−1) {215 view . getTable ( ) . s e tRowSe l e c t i on In te rva l ( row , row ) ;216217 view . getRightClickPopupMenu ( ) . show ( e . getComponent ( ) , e . getX ( ) , e .

getY ( ) ) ;218 }219220 }221 }222

Page 274: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

264 Appendix C - Source Code

223224 }

Page 275: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 265

.1.76 CommandTableView.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Color ;4 import java . awt . Component ;5 import java . awt . Dimension ;6 import java . awt . Font ;7 import java . awt . GridBagConstraints ;8 import java . awt . GridBagLayout ;9 import java . rmi . RemoteException ;

10 import java . text . SimpleDateFormat ;11 import java . u t i l . ArrayList ;12 import java . u t i l . Date ;1314 import javax . swing . JButton ;15 import javax . swing . JLabel ;16 import javax . swing . JMenuItem ;17 import javax . swing . JPanel ;18 import javax . swing . JPopupMenu ;19 import javax . swing . JScro l lPane ;20 import javax . swing . JTable ;21 import javax . swing . L i s tSe l e c t i onMode l ;22 import javax . swing . tab l e . DefaultTableCel lRenderer ;23 import javax . swing . tab l e . TableRowSorter ;2425 import mcc . s e rv e r . dataProcess ing . CommandBlock ;26 import mcc . s e rv e r . u s e r s . User ;27 import mps . MPSPreferences ;28 import mps . rmi . C l i ent ;2930 import common . command .Command;3132 /∗∗33 ∗ <br><br>34 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 335 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 136 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 837 ∗/38 public c lass CommandTableView extends JPanel{3940 /∗∗41 ∗42 ∗/43 private stat ic f ina l long se r ia lVers ionUID = 1L ;44 /∗∗45 ∗46 ∗/47 private TimeLineView timeLineView ;48 /∗∗49 ∗50 ∗/51 private TimeLineModel timeLineModel = TimeLineModel . g e t In s tance ( ) ;5253 /∗∗54 ∗55 ∗/56 private CommandAbstractTableModel commandAbstractTableModel ;57 /∗∗58 ∗59 ∗/60 private JTable tab l e ;61 /∗∗62 ∗63 ∗/64 private TableRowSorter<CommandAbstractTableModel> s o r t e r ;65 /∗∗66 ∗67 ∗/68 private CommandTableController c o n t r o l l e r ;6970 /∗∗71 ∗72 ∗/73 private JLabel s e l e c t i o nLabe l ;74 /∗∗75 ∗76 ∗/77 private JButton newCommandButton ;78 /∗∗79 ∗80 ∗/81 private JButton newCommandBlockButton ;82 /∗∗83 ∗84 ∗/

Page 276: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

266 Appendix C - Source Code

85 private JButton deleteButton ;86 /∗∗87 ∗88 ∗/89 private JButton editButton ;90 /∗∗91 ∗92 ∗/93 private JButton copyButton ;94 /∗∗95 ∗96 ∗/97 private JButton editBlockButton ;98 /∗∗99 ∗

100 ∗/101 private JButton ver i fyButton ;102103 /∗∗104 ∗105 ∗/106 private JPopupMenu rightClickPopupMenu ;107 /∗∗108 ∗109 ∗/110 private JMenuItem deleteMenuItem ;111 /∗∗112 ∗113 ∗/114 private JMenuItem editMenuItem ;115 /∗∗116 ∗117 ∗/118 private JMenuItem copyMenuItem ;119 /∗∗120 ∗121 ∗/122 private JMenuItem editBlockMenuItem ;123 /∗∗124 ∗125 ∗/126 private JMenuItem verifyMenuItem ;127128 public stat ic f ina l int ID COLUMN WIDTH =

30;129 public stat ic f ina l int TYPE COLUMN WIDTH =

35;130 public stat ic f ina l int BLOCK COLUMN WIDTH =

40;131 public stat ic f ina l int NAME COLUMN WIDTH =

190;132 public stat ic f ina l int DESTINATION COLUMN WIDTH = 70;133 public stat ic f ina l int PARAMETERS COLUMN WIDTH = 145;134 public stat ic f ina l int PASS COLUMN WIDTH =

40;135 public stat ic f ina l int TIME OF EXECUTION COLUMN WIDTH = 120;136 public stat ic f ina l int BYTES COLUMN WIDTH = 40;137 public stat ic f ina l int STATES COLUMN WIDTH = 130;138139140 /∗∗141 ∗ @param t im e L i n eV i e w142 ∗ @th r ow s R emo t e E x c e p t i o n143 ∗/144 public CommandTableView( TimeLineView timeLineView ) throws RemoteException{145146 c o n t r o l l e r = new CommandTableController ( this ) ;147 this . timeLineView = timeLineView ;148149 this . setLayout (new GridBagLayout ( ) ) ;150 GridBagConstraints c = new GridBagConstraints ( ) ;151 c . anchor = GridBagConstraints .LINE START;152 c . gr idx = 0 ;153 c . gr idy = 0 ;154 c . gr idwidth = 6 ;155156 commandAbstractTableModel = new CommandAbstractTableModel ( ) ;157 // c omman dA b s t r a c t T a b l eMo d e l . u p d a t eDa t aF r omMod e l ( ) ;158159 tab l e = new JTable ( commandAbstractTableModel ) ;160161 s o r t e r = new TableRowSorter<CommandAbstractTableModel>(

commandAbstractTableModel ) ;162 tab l e . setRowSorter ( s o r t e r ) ;163164 tab l e . setColumnSelect ionAllowed ( f a l s e ) ;165 tab l e . setRowSelect ionAllowed ( true ) ;

Page 277: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 267

166167 setTableColumnWidths ( ) ;168169 tab l e . s e tP r e f e r r edSc r o l l ab l eV i ewpo r tS i z e (new Dimension ( getTableWidth ( )

+10 ,350) ) ;170 tab l e . s e tF i l l sV i ewpor tHe ight ( true ) ;171 // S e t d e f a u l t r e n d e r t o c o l o r t h e c e l l s c o r r e c t172 tab l e . se tDefau l tRenderer ( Object . class , new MyTableCellRenderer ( ) ) ;173 tab l e . se tDefau l tRenderer ( Long . class , new MyTableCellRenderer ( ) ) ;174 // For co l umn 5 i s n e e d e d a s p e c i a l175 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .

TIME OF EXECUTION COLUMN) . se tCe l lRendere r (new DateRenderer ( ) ) ;176 // D i s a b l e a u t o r e s i z i n g177 tab l e . setAutoResizeMode ( JTable .AUTO RESIZE OFF) ;178179180 tab l e . setSe lect ionMode ( L i s tSe l e c t i onMode l .MULTIPLE INTERVAL SELECTION) ;181182 JScro l lPane s c ro l lPane = new JScro l lPane ( tab l e ) ;183 s c ro l lPane . setMinimumSize (new Dimension ( getTableWidth ( ) ,350) ) ;184 s c ro l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .VERTICAL SCROLLBAR ALWAYS)

;185 s c ro l lPane . s e tHo r i z on ta l S c r o l lBa rPo l i c y ( JScro l lPane .

HORIZONTAL SCROLLBAR AS NEEDED) ;186187 this . add ( scro l lPane , c ) ;188189190 JPanel newCommandButtonPanel = new JPanel ( ) ;191 newCommandButton = new JButton ( ”New Command” ) ;192 newCommandBlockButton = new JButton ( ”New Command Block” ) ;193 newCommandButtonPanel . add (newCommandButton) ;194 newCommandButtonPanel . add (newCommandBlockButton ) ;195 c . gr idy = 1 ;196 c . gr idx = 0 ;197 this . add (newCommandButtonPanel , c ) ;198199 JPanel ed i t ingPane l = new JPanel ( ) ;200 s e l e c t i o nLabe l = new JLabel ( ” S e l e c t i on act i on : ” ) ;201 ed i t ingPane l . add ( s e l e c t i o nLabe l ) ;202 editButton = new JButton ( ” Edit ” ) ;203 copyButton = new JButton ( ”Copy” ) ;204 editBlockButton = new JButton ( ” Edit Block” ) ;205 de leteButton = new JButton ( ” Delete ” ) ;206 ver i fyButton = new JButton ( ” Ver i fy ” ) ;207208 ed i t ingPane l . add ( copyButton ) ;209 ed i t ingPane l . add ( editButton ) ;210 ed i t ingPane l . add ( editBlockButton ) ;211 ed i t ingPane l . add ( de leteButton ) ;212 ed i t ingPane l . add ( ver i fyButton ) ;213214 c . gr idx = 1 ;215 c . anchor = GridBagConstraints . LINE END;216 this . add ( ed i t ingPane l , c ) ;217218 // C r e a t e RIGHT CLICK popupmenu219 createRightClickMenu ( ) ;220221222 setButtonStatusFromTrustLevel ( ) ;223 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( )>=User .FULL TRUST) {224 updateButtonEnabi l i ty ( ) ;225 }226227 // LISTENERS228 // h t t p : / / www . e x a m p l e d e p o t . com/ e g s / j a v a x . s w i n g . t a b l e / S e l E v e n t . h tm l229 tab l e . getSe l ect ionMode l ( ) . addL i s t S e l e c t i onL i s t en e r ( c o n t r o l l e r ) ;230 tab l e . addMouseListener ( c o n t r o l l e r ) ;231 de leteButton . addAct ionListener ( c o n t r o l l e r ) ;232 newCommandButton . addAct ionListener ( c o n t r o l l e r ) ;233 newCommandBlockButton . addAct ionListener ( c o n t r o l l e r ) ;234 ver i fyButton . addAct ionListener ( c o n t r o l l e r ) ;235 editButton . addAct ionListener ( c o n t r o l l e r ) ;236 copyButton . addAct ionListener ( c o n t r o l l e r ) ;237 editBlockButton . addAct ionListener ( c o n t r o l l e r ) ;238239 }240241 /∗∗242 ∗243 ∗/244 private void setButtonStatusFromTrustLevel ( ) {245 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( ) <= User .MEDIUM TRUST) {246247 St r ing ed i t = ”To ed i t commands \” Ful l Trust\” or h igher i s

r equ i r ed . ” ;

Page 278: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

268 Appendix C - Source Code

248 editButton . setEnabled ( f a l s e ) ;249 editButton . setToolTipText ( ed i t ) ;250 editMenuItem . setEnabled ( f a l s e ) ;251 editMenuItem . setToolTipText ( ed i t ) ;252253 St r ing block =”To ed i t command blocks \” Ful l Trust\” or

h igher i s r equ i r ed . ” ;254 editBlockButton . setEnabled ( f a l s e ) ;255 editBlockButton . setToolTipText ( block ) ;256 editBlockMenuItem . setEnabled ( f a l s e ) ;257 editBlockMenuItem . setToolTipText ( block ) ;258259 St r ing de l e t e = ”To de l e t e commands \” Ful l Trust\” or h igher

i s r equ i r ed . ” ;260 de leteButton . setEnabled ( f a l s e ) ;261 de leteButton . setToolTipText ( d e l e t e ) ;262 deleteMenuItem . setEnabled ( f a l s e ) ;263 deleteMenuItem . setToolTipText ( d e l e t e ) ;264265 St r ing v e r i f y = ”To v e r i f y commands \” Ful l Trust\” or h igher

i s r equ i r ed . ” ;266 ver i fyButton . setEnabled ( f a l s e ) ;267 ver i fyButton . setToolTipText ( v e r i f y ) ;268 verifyMenuItem . setEnabled ( f a l s e ) ;269 verifyMenuItem . setToolTipText ( v e r i f y ) ;270 }271 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( ) <= User .MINIMAL TRUST) {272273 St r ing copy = ”To copy a command \”Medium Trust\” or h igher i s r equ i r ed . ” ;274 copyButton . setEnabled ( f a l s e ) ;275 copyButton . setToolTipText ( copy ) ;276 copyMenuItem . setEnabled ( f a l s e ) ;277 copyMenuItem . setToolTipText ( copy ) ;278279 newCommandButton . setEnabled ( f a l s e ) ;280 newCommandButton . setToolTipText ( ”To c r ea t e new command \”Medium Trust\” or

h igher i s r equ i r ed . ” ) ;281282 newCommandBlockButton . setEnabled ( f a l s e ) ;283 newCommandBlockButton . setToolTipText ( ”To c r ea t e new command block \”Medium

Trust\” or h igher i s r equ i r ed . ” ) ;284285 }286287 }288289 /∗∗290 ∗291 ∗/292 public void setTableColumnWidths ( ) {293294 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel . ID COLUMN

) . setPreferredWidth (ID COLUMN WIDTH) ;295 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .

TYPE COLUMN) . setPreferredWidth (TYPE COLUMN WIDTH) ;296 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .

BLOCK COLUMN) . setPreferredWidth (BLOCK COLUMN WIDTH) ;297 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .

NAME COLUMN) . setPreferredWidth (NAME COLUMN WIDTH) ;298 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .

DESTINATION COLUMN) . setPreferredWidth (DESTINATION COLUMN WIDTH);

299 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .PARAMETERS COLUMN) . setPre ferredWidth (PARAMETERS COLUMN WIDTH) ;

300 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .PASS COLUMN) . setPreferredWidth (PASS COLUMN WIDTH) ;

301 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .TIME OF EXECUTION COLUMN) . setPreferredWidth (TIME OF EXECUTION COLUMN WIDTH) ;

302 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .BYTES COLUMN) . setPreferredWidth (BYTES COLUMN WIDTH) ;

303 tab l e . getColumnModel ( ) . getColumn ( CommandAbstractTableModel .STATE COLUMN) . setPreferredWidth (STATES COLUMN WIDTH) ;

304305 }306307 /∗∗308 ∗ @r e t u r n309 ∗/310 private int getTableWidth ( ) {311312 return ID COLUMN WIDTH +313 TYPE COLUMN WIDTH +314 BLOCK COLUMN WIDTH +315 NAME COLUMN WIDTH +316 DESTINATION COLUMN WIDTH +317 PARAMETERS COLUMN WIDTH +

Page 279: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 269

318 PASS COLUMN WIDTH +319 TIME OF EXECUTION COLUMN WIDTH +320 BYTES COLUMN WIDTH +321 STATES COLUMN WIDTH;322 }323324325 /∗∗326 ∗327 ∗/328 public void createRightClickMenu ( ) {329 rightClickPopupMenu = new JPopupMenu ( ) ;330331 deleteMenuItem = new JMenuItem( ” Delete ” ) ;332 copyMenuItem = new JMenuItem( ”Copy” ) ;333 copyMenuItem . setToolTipText ( ” Create a new command as a copy o f the

s e l e c t e d command . ” ) ;334 // Copy Menu I t em w i l l a l w a y s b e p o s s i b l e i n r i g h t c l i c k menu s i n c e

o t h e r commands a r e d e s e l e c t e d on r i g h t c l i c k .335336 editMenuItem = new JMenuItem( ” Edit ” ) ;337 editBlockMenuItem = new JMenuItem( ” Edit block ” ) ;338 verifyMenuItem = new JMenuItem( ” Ver i fy ” ) ;339340 rightClickPopupMenu . add ( copyMenuItem ) ;341 rightClickPopupMenu . add ( editMenuItem ) ;342 rightClickPopupMenu . add ( editBlockMenuItem ) ;343 rightClickPopupMenu . add ( deleteMenuItem ) ;344 rightClickPopupMenu . add ( verifyMenuItem ) ;345346347 // L i s t e n e r s348 copyMenuItem . addAct ionListener ( c o n t r o l l e r ) ;349 deleteMenuItem . addAct ionListener ( c o n t r o l l e r ) ;350 editBlockMenuItem . addAct ionListener ( c o n t r o l l e r ) ;351 editMenuItem . addAct ionListener ( c o n t r o l l e r ) ;352 verifyMenuItem . addAct ionListener ( c o n t r o l l e r ) ;353354 }355356357 /∗∗358 ∗ Th i s me t hod i s u s e d t o u p d a t e t h e e n a b i l i t y o f t h e e d i t , d e l e t e and

v e r i f y b u t t o n s359 ∗ d e p e n d i n g on how many t h e r e i s s e l e c t e d and t h e s t a t u s o f t h e s e l e c t e d

commands .360 ∗/361 public void updateButtonEnabi l i ty ( ) {362 int [ ] se lectedRows = tab l e . getSelectedRows ( ) ;363364 i f ( se lectedRows . l ength==0) {365 // No command s e l e c t e d − n o t a b l e t o e d i t , d e l e t e o r v e r i f y366 editButton . setEnabled ( f a l s e ) ;367 copyButton . setEnabled ( f a l s e ) ;368 editBlockButton . setEnabled ( f a l s e ) ;369 de leteButton . setEnabled ( f a l s e ) ;370 ver i fyButton . setEnabled ( f a l s e ) ;371 editButton . setToolTipText ( ” S e l e c t a command to ed i t . ” ) ;372 copyButton . setToolTipText ( ” S e l e c t a command to c r ea t e a new

copy o f i t . ” ) ;373 de leteButton . setToolTipText ( ” S e l e c t one or more commands to

d e l e t e . ” ) ;374 ver i fyButton . setToolTipText ( ” S e l e c t one or more commands to

v e r i f y . ” ) ;375 editBlockButton . setToolTipText ( ” S e l e c t a command to ed i t i t s

block ” ) ;376377 } else i f ( se lectedRows . l ength==1) {378 // E x c a s t l y one row s e l e c t e d379 // Th i s a l s o h a n d l e s t h e r i g h t c l i c k menu , s i n c e t h e y n e e d t o b e

s y n c r o n i z e d w h e n e v e r o n l y one command i s s e l e t e d ( p o s s i b l er i g h t c l i c k )

380381 copyButton . setEnabled ( true ) ;382 copyButton . setToolTipText ( ” Create a new command as a copy o f

the s e l e c t e d command . ” ) ;383384 long blockID = ( Long ) tab l e . getValueAt ( se lectedRows [ 0 ] ,

CommandAbstractTableModel .BLOCK COLUMN) ;385 i f ( timeLineModel . getTimelineData ( ) . getCommandBlockMap ( ) . get (

blockID ) . s i z e ( ) > 1) {386 // i f t h e command ’ s b l o c k c o n s i s t s o f more t h a n one command387 i f ( i sB lockEd i tab l e ( blockID ) ) {388 St r ing editBlockToolTip = ” Edit Block with

id ” + blockID ;389 // B u t t o n s390 editBlockButton . setEnabled ( true ) ;

Page 280: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

270 Appendix C - Source Code

391 editBlockButton . setToolTipText (editBlockToolTip ) ;

392 // R i g h t c l i c k menu393 editBlockMenuItem . setEnabled ( true ) ;394 editBlockMenuItem . setToolTipText (

editBlockToolTip ) ;395 } else {396 St r ing editBlockToolTip = ” State o f the

command does not a l low v e r i f i c a t i o n ” ;397 // B u t t o n s398 editBlockButton . setEnabled ( f a l s e ) ;399 editBlockButton . setToolTipText (

editBlockToolTip ) ;400 // R i g h t c l i c k menu401 editBlockMenuItem . setEnabled ( f a l s e ) ;402 editBlockMenuItem . setToolTipText (

editBlockToolTip ) ;403 }404 } else {405 // o n l y one command i n b l o c k = s h o u l d n o t b e e d i t e d a s a

b l o c k406 St r ing editBlockToolTip = ”Command with id \”” + (

Long ) tab l e . getValueAt ( se lectedRows [ 0 ] ,CommandAbstractTableModel . ID COLUMN) + ”\” i snot within a block c on s i t i n g o f 2 or morecommands” ;

407 // Bu t t o n408 editBlockButton . setEnabled ( f a l s e ) ;409 editBlockButton . setToolTipText ( editBlockToolTip ) ;410 // R i g h t c l i c k menu411 editBlockMenuItem . setEnabled ( f a l s e ) ;412 editBlockMenuItem . setToolTipText ( editBlockToolTip ) ;413 }414415 // i f o n l y one i s s e l e c t e d e d i t b u t t o n may b e e n a b l e d i f

s t a t e o f t h a t command a l l o w s i t416 int stateNo = getState ( se lectedRows [ 0 ] ) ;417 i f ( stateNo<=Command.AWAITING USER ACTION) {418 St r ing editTxt = ” Edit s e l e c t e d command” ;419 St r ing de leteTxt = ” Delete s e l e c t e d command” ;420 // B u t t o n s421 editButton . setEnabled ( true ) ;422 de leteButton . setEnabled ( true ) ;423 editButton . setToolTipText ( editTxt ) ;424 deleteButton . setToolTipText ( de leteTxt ) ;425 // R i g h t c l i c k menu426 editMenuItem . setEnabled ( true ) ;427 deleteMenuItem . setEnabled ( true ) ;428 editMenuItem . setToolTipText ( editTxt ) ;429 deleteMenuItem . setToolTipText ( de leteTxt ) ;430431 i f ( stateNo==Command.INITIAL COMMAND | | stateNo==

Command.AWAITING VERIFICATION | | stateNo==Command.AWAITING PASS AND VERIFICATION) {

432 St r ing ver i fyTxt = ” Ver i fy s e l e c t e d command”;

433 // Bu t t o n434 ver i fyButton . setEnabled ( true ) ;435 ver i fyButton . setToolTipText ( ver i fyTxt ) ;436 // r i g h t c l i c k menu437 verifyMenuItem . setEnabled ( true ) ;438 verifyMenuItem . setToolTipText ( ver i fyTxt ) ;439 } else {440 St r ing ver i fyTxt = ” State o f the command

does not a l low v e r i f i c a t i o n ” ;441 // Bu t t o n442 ver i fyButton . setEnabled ( f a l s e ) ;443 ver i fyButton . setToolTipText ( ver i fyTxt ) ;444 // R i g h t c l i c k menu445 verifyMenuItem . setEnabled ( f a l s e ) ;446 verifyMenuItem . setToolTipText ( ver i fyTxt ) ;447 }448 } else {449 // S t a t e h i g h e r t h a n A w a i t i n g u s e r a c t i o n . . . T h i s means

b e i n g t r a n s m i t t e d , t r a n s m i t t e d , e x e c u t e d o r d e l e t e d .450 // Bu t t o n451 St r ing ed i t = ” State o f the command does not a l low

ed i t i n g ” ;452 St r ing de l e t e = ” State o f the command does not a l low

de l e t i on ” ;453 St r ing v e r i f y = ” State o f the command does not a l low

v e r i f i c a t i o n ” ;454 editButton . setEnabled ( f a l s e ) ;455 de leteButton . setEnabled ( f a l s e ) ;456 ver i fyButton . setEnabled ( f a l s e ) ;457 editButton . setToolTipText ( ed i t ) ;458 de leteButton . setToolTipText ( d e l e t e ) ;

Page 281: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 271

459 ver i fyButton . setToolTipText ( v e r i f y ) ;460 // R i g h t c l i c k Menu461 editBlockMenuItem . setEnabled ( f a l s e ) ;462 deleteMenuItem . setEnabled ( f a l s e ) ;463 verifyMenuItem . setEnabled ( f a l s e ) ;464 editBlockMenuItem . setToolTipText ( ed i t ) ;465 deleteMenuItem . setToolTipText ( d e l e t e ) ;466 verifyMenuItem . setToolTipText ( v e r i f y ) ;467 }468469 } else {470 // More t h a n one command s e l e c t e d471 editButton . setEnabled ( f a l s e ) ; // e d i t o f m u l t i p l e commands

a t s ame t ime n o t p o s s i b l e472 editButton . setToolTipText ( ” Edit ing i s not p o s s i b l e f o r

s e v e r a l commands at the same time” ) ;473 copyButton . setEnabled ( f a l s e ) ;474 copyButton . setToolTipText ( ” S e l e c t a s i n g l e command to c r ea t e

a copy from” ) ;475476 boolean i sD e l e t e ab l e = true ;477 boolean i s V e r i f y a b l e = true ;478 boolean isAllCommandsInSameBlock = true ; // a l l s e l e c t e d

commands mus t b e o f same command b l o c k479 boolean isAllCommandsEditable = true ;480481 long f i r s t S e l e c t edB l o ck ID = ( Long ) tab l e . getValueAt (

se lectedRows [ 0 ] , CommandAbstractTableModel .BLOCK COLUMN) ; // b l o c k i d o f t h e f i r s t s e l e c t e d command − a l lo t h e r s s h o u l d b e t h e same

482 for ( int i =0; i<=selectedRows . length −1; i++) {483484 int stateNo = getState ( se lectedRows [ i ] ) ;485486 i f ( stateNo >5) i s D e l e t e a b l e = f a l s e ;487 i f ( ! ( stateNo==0 | | stateNo==1 | | stateNo==3))

i s V e r i f y a b l e = f a l s e ;488 long blockID = ( Long ) tab l e . getValueAt ( se lectedRows [ i

] , CommandAbstractTableModel .BLOCK COLUMN) ;489 i f ( f i r s t S e l e c t edB l o ck ID != blockID )

isAllCommandsInSameBlock = f a l s e ;490 i f ( ! i sB lockEd i tab l e ( blockID ) ) isAllCommandsEditable

= f a l s e ;491 }492493 i f ( i s De l e t e a b l e ) {494 deleteButton . setEnabled ( true ) ;495 de leteButton . setToolTipText ( ” Delete a l l s e l e c t e d

commands” ) ;496 } else {497 deleteButton . setEnabled ( f a l s e ) ;498 de leteButton . setToolTipText ( ”The s t a t e o f one or

more commands does not a l low de l e t i on ” ) ;499 }500 i f ( i s V e r i f y a b l e ) {501 ver i fyButton . setEnabled ( true ) ;502 ver i fyButton . setToolTipText ( ” Ver i fy a l l s e l e c t e d

commands” ) ;503 } else {504 ver i fyButton . setEnabled ( f a l s e ) ;505 ver i fyButton . setToolTipText ( ”The s t a t e o f one or

more commands does not a l low v e r i f i c a t i o n ” ) ;506 }507508 i f ( isAllCommandsInSameBlock && isAllCommandsEditable ) {509 editBlockButton . setEnabled ( true ) ;510 editBlockButton . setToolTipText ( ” Edit Block with id ”

+ f i r s t S e l e c t edB l o ck ID ) ;511 } else {512 editBlockButton . setEnabled ( f a l s e ) ;513 i f ( ! isAllCommandsInSameBlock ) editBlockButton .

setToolTipText ( ”To \” Edit Block\” a l l thes e l e c t e d commands must be within the same block. ” ) ;

514 i f ( ! isAllCommandsEditable ) editBlockButton .setToolTipText ( ”One or more o f the b lockscommands i s in a s t a t e which not a l low ed i t i n g ”) ;

515 }516517 }518519 }520521 /∗∗522 ∗ @param rowNo523 ∗ @r e t u r n

Page 282: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

272 Appendix C - Source Code

524 ∗/525 private int getState ( int rowNo) {526 long commandID = ( Long ) tab l e . getValueAt (rowNo ,

CommandAbstractTableModel . ID COLUMN) ;527 Command c = TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

lookupCommand(commandID) ;528529 return c . ge tState ( ) ;530531 }532533 /∗∗534 ∗ @param i d535 ∗ @r e t u r n536 ∗/537 private boolean i sB lockEd i tab l e ( long id ) {538 CommandBlock cb = timeLineModel . getTimelineData ( ) . getCommandBlockMap

( ) . get ( id ) ;539540 for ( int i =0; i<=cb . s i z e ( )−1; i++) {541 Command c = timeLineModel . getTimelineData ( ) . getCommandMap( ) .

get ( cb . getCommand( i ) ) ;542 i f ( c . ge tState ( )>Command.BEING TRANSMITTED) return fa l se ;543 }544545 return true ;546 }547548549 /∗∗550 ∗ @param commandID551 ∗ @r e t u r n552 ∗/553 public boolean isCommandSelected ( long commandID) {554 int [ ] se lectedRows = tab l e . getSelectedRows ( ) ;555 for ( int i =0; i<=selectedRows . length −1; i++) {556 long selectedCommandID = ( Long ) tab l e . getValueAt (

se lectedRows [ i ] , CommandAbstractTableModel . ID COLUMN) ;557 i f ( selectedCommandID == commandID) return true ;558 }559 return fa l se ; // n o t f o u n d560 }561562 /∗∗563 ∗ Re t u r n s an a r r a y o f a l l s e l e c t e d commands i n t h e command t a b l e564 ∗ @r e t u r n An a r r a y l i s t o f a l l commands s e l e c t e d i n t h e command t a b l e565 ∗/566 public ArrayList<Command> getSelectedCommands ( ) {567568 int [ ] se lectedRows = tab l e . getSelectedRows ( ) ;569 i f ( se lectedRows . l ength == 0){570 return null ;571 } else{572 ArrayList<Command> r e s u l t = new ArrayList<Command>() ;573 for ( int index : se lectedRows ){574 long selectedCommandId = ( Long ) tab l e . getValueAt (

index , CommandAbstractTableModel . ID COLUMN) ;575 r e s u l t . add ( timeLineModel . getTimelineData ( ) .

getCommandMap( ) . get ( selectedCommandId ) ) ;576 }577 return r e s u l t ;578 }579580581 }582583 /∗∗584 ∗ @r e t u r n585 ∗/586 public TimeLineView getTimeLineView ( ) {587 return timeLineView ;588 }589590 /∗∗591 ∗ @r e t u r n592 ∗/593 public JTable getTable ( ) {594 return tab l e ;595 }596597 /∗∗598 ∗ @r e t u r n599 ∗/600 public TableRowSorter<CommandAbstractTableModel> ge tSo r t e r ( ) {601 return s o r t e r ;602 }603

Page 283: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 273

604 /∗∗605 ∗ @r e t u r n606 ∗/607 public CommandAbstractTableModel getCommandTableModel ( ) {608 return commandAbstractTableModel ;609 }610611 /∗∗612 ∗ @r e t u r n613 ∗/614 public JButton getNewCommandButton ( ) {615 return newCommandButton ;616 }617618 /∗∗619 ∗ @r e t u r n620 ∗/621 public JButton getNewCommandBlockButton ( ) {622 return newCommandBlockButton ;623 }624625 /∗∗626 ∗ @r e t u r n627 ∗/628 public JButton getDeleteButton ( ) {629 return deleteButton ;630 }631632 /∗∗633 ∗ @r e t u r n634 ∗/635 public JButton getEditButton ( ) {636 return editButton ;637 }638639 /∗∗640 ∗ @r e t u r n641 ∗/642 public JButton getVer i fyButton ( ) {643 return ver i fyButton ;644 }645646 /∗∗647 ∗ @r e t u r n648 ∗/649 public JButton getEditBlockButton ( ) {650 return editBlockButton ;651 }652653 /∗∗654 ∗ @r e t u r n655 ∗/656 public JPopupMenu getRightClickPopupMenu ( ) {657 return rightClickPopupMenu ;658 }659660 /∗∗661 ∗ @r e t u r n662 ∗/663 public JMenuItem getDeleteMenuItem () {664 return deleteMenuItem ;665 }666667 /∗∗668 ∗ @r e t u r n669 ∗/670 public JMenuItem getEditMenuItem () {671 return editMenuItem ;672 }673674 /∗∗675 ∗ @r e t u r n676 ∗/677 public JMenuItem getEditBlockMenuItem () {678 return editBlockMenuItem ;679 }680681 /∗∗682 ∗ @r e t u r n683 ∗/684 public JMenuItem getVerifyMenuItem () {685 return verifyMenuItem ;686 }687688 /∗∗689 ∗ @r e t u r n690 ∗/

Page 284: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

274 Appendix C - Source Code

691 public JButton getCopyButton ( ) {692 return copyButton ;693 }694695 /∗∗696 ∗ @r e t u r n697 ∗/698 public JMenuItem getCopyMenuItem () {699 return copyMenuItem ;700 }701702 }703704 /∗∗705 ∗ <br><br>706 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3707 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 1708 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 8709 ∗/710 c lass MyTableCellRenderer extends DefaultTableCel lRenderer {711712 public MyTableCellRenderer ( ) { super ( ) ; }713714 public Component getTableCellRendererComponent ( JTable table , Object

value , boolean i s S e l e c t ed , boolean hasFocus , int row , intcolumn ) {

715716 Component c = super . getTableCellRendererComponent ( table ,

value , i s S e l e c t ed , hasFocus , row , column ) ;717718 long commandID = Long . parseLong ( tab l e . getValueAt ( row ,

CommandAbstractTableModel . ID COLUMN) . toSt r ing ( ) ) ;719 Command com = TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

lookupCommand(commandID) ;720721 setToolTipText ( ”<html><b>”+TimeLineModel . g e t In s tance ( ) .

getHtmlPrettyPrint (commandID) ) ;722723724 i f ( column == CommandAbstractTableModel .NAME COLUMN) { //

Command name co l umn725726 c . setForeground ( Color . black ) ;727 c . setFont (new Font ( ”Tahoma” , Font .BOLD,12 ) ) ;728729 } else i f ( column == CommandAbstractTableModel .PASS COLUMN) {730731 i f (com . getUserGivenPass ( ) ) {732 c . setForeground ( Color . b lack ) ;733 c . setFont (new Font ( ”Tahoma” , Font .BOLD,11 ) ) ;734 }735736737738739 } else i f ( column == CommandAbstractTableModel .

TIME OF EXECUTION COLUMN) { // E x e c u t i o n t im e co l umn740741 i f (com . getTimeOfExecution ( )==−1) {742 c . setFont (new Font ( ”Tahoma” , Font . ITALIC ,10 ) )

;743 }744745746 } else i f ( column == CommandAbstractTableModel .STATE COLUMN)

{ // co l umn 7 i s t h e s t a t e c o l umn747748 Command command = TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . lookupCommand(commandID) ;749750 c . setForeground ( MPSPreferences . getStateCo lor (command

. ge tState ( ) ) ) ;751 } else {752 c . setForeground ( Color . black ) ;753 c . setFont (new Font ( ”Tahoma” , Font .PLAIN,11 ) ) ;754 }755756 return c ;757 }758759 }760761 /∗∗762 ∗ <br><br>763 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 3764 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 1765 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 8

Page 285: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 275

766 ∗/767 c lass DateRenderer extends DefaultTableCel lRenderer {768 // Da t eFo rma t f o r m a t t e r ;769770771 public DateRenderer ( ) { super ( ) ; }772773 public Component getTableCellRendererComponent ( JTable table , Object

value , boolean i s S e l e c t ed , boolean hasFocus , int row , intcolumn ) {

774775 Component c = super . getTableCellRendererComponent ( table ,

value , i s S e l e c t ed , hasFocus , row , column ) ;776777778779 long commandID = Long . parseLong ( tab l e . getValueAt ( row ,

CommandAbstractTableModel . ID COLUMN) . toSt r ing ( ) ) ;780 Command com = TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

lookupCommand(commandID) ;781 i f (com . getTimeOfExecution ( )==−1) {782 c . setFont (new Font ( ”Tahoma” , Font . ITALIC ,11 ) ) ;783 } else {784 c . setFont (new Font ( ”Tahoma” , Font .PLAIN,11 ) ) ;785 }786787788 return c ;789 }790791 public void setValue ( Object value ) {792793 // i f ( f o r m a t t e r== n u l l ) {794 // f o r m a t t e r = Da t eFo rma t . g e t D a t e I n s t a n c e ( Da t eFo rma t . FULL ) ;795 // }796797 Date date = ( Date ) value ;798 St r ing r e s u l t = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( date ) ;799 setText ( ( value == null ) ? ”” : r e s u l t ) ;800 }801 }

Page 286: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

276 Appendix C - Source Code

.1.77 PassesAbstractTableModel.java

1 package mps . gui . t ime l i n e ;23 import java . text . SimpleDateFormat ;45 import javax . swing . tab l e . AbstractTableModel ;67 import mcc . s e rv e r . dataProcess ing . Pass ;8 import mps . MPSPreferences ;9

10 /∗∗11 ∗ <br><br>12 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 313 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 114 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 815 ∗/16 public c lass PassesAbstractTableModel extends AbstractTableModel{171819 /∗∗20 ∗21 ∗/22 private stat ic f ina l long se r ia lVers ionUID = 1L ;23 public stat ic f ina l int ID COLUMN =

0;24 public stat ic f ina l int START COLUMN = 1;25 // p u b l i c s t a t i c f i n a l i n t END COLUMN =

2 ;26 public stat ic f ina l int SESSION COLUMN = 2;2728 @Override29 public int getColumnCount ( ) {30 return 3 ;31 }3233 public Str ing getColumnName( int co l ) {34 switch ( c o l ) {35 case ID COLUMN: return ” Id” ;36 case START COLUMN: return ” Star t ” ;37 // c a s e END COLUMN : r e t u r n ”End ” ;38 case SESSION COLUMN: return ” Ses s i on ” ;39 default :40 return ”Unknown column” ;41 }42 }4344 @Override45 public int getRowCount ( ) {46 return TimeLineModel . g e t In s tance ( ) . getUpcomingOpenPasses ( ) . s i z e ( ) ;47 }4849 @Override50 public Object getValueAt ( int row , int co l ) {5152 i f ( TimeLineModel . g e t In s tance ( ) . getUpcomingOpenPasses ( ) . s i z e ( )==0)

return ”” ;5354 Pass pass = TimeLineModel . g e t In s tance ( ) . getUpcomingOpenPasses ( ) . get (

row ) ;5556 switch ( c o l ) {57 case ID COLUMN:58 return pass . getPassID ( ) ;59 case START COLUMN:60 return new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( pass . getStartTime ( ) ) ;61 // c a s e END COLUMN :62 // r e t u r n new S imp l eD a t e F o rma t ( MPSP r e f e r e n c e s .

g e t F u l l D a t e T im e F o rm a t ( ) ) . f o rm a t ( p a s s . g e tEndT ime ( ) ) ;63 // c a s e 3 :64 // r e t u r n p a s s . g e t U p l i n k B y t e s A v a i l a b l e ( ) ;65 // c a s e 4 :66 // r e t u r n p a s s . g e t S t a t u s D e s c r i p t i o n ( ) ;67 // c a s e 5 :68 // r e t u r n p a s s . g e tG r o u n d S t a t i o nN am e ( ) ;69 case SESSION COLUMN:70 return pass . getSess ionID ( ) ;71 default :72 return null ;7374 }7576 }7778 }

Page 287: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 277

.1.78 PassesTableController.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Point ;4 import java . awt . event . ActionEvent ;5 import java . awt . event . Act ionL i s t ener ;6 import java . awt . event . MouseEvent ;7 import java . awt . event . MouseListener ;8 import java . rmi . NotBoundException ;9 import java . rmi . RemoteException ;

1011 import javax . swing . JOptionPane ;12 import javax . swing . event . L i s tSe l e c t i onEvent ;13 import javax . swing . event . L i s t S e l e c t i o n L i s t e n e r ;1415 import mcc . s e rv e r . dataProcess ing . Pass ;16 import mcc . s e rv e r . u s e r s . User ;17 import mps . gui . planning . pas se s . PassManuelSetupView ;18 import mps . gui . planning . pas se s . TLEUpdateView ;19 import mps . rmi . C l i ent ;2021 import common . s a t e l l i t e . PredictExcept ion ;2223 /∗∗24 ∗ <br><br>25 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 326 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 127 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 828 ∗/29 public c lass PassesTab leContro l l e r implements Act ionListener , L i s t S e l e c t i o nL i s t e n e r ,

MouseListener {3031 /∗∗32 ∗33 ∗/34 private PassesTableView view ;3536 /∗∗37 ∗ @param p a s s e s V i e w38 ∗/39 public PassesTab leContro l l e r ( PassesTableView passesView ) {4041 view = passesView ;4243 }4445 @Override46 public void act ionPerformed ( ActionEvent ae ) {474849 i f ( ae . getSource ( ) . equa l s ( view . getNewPassButton ( ) ) ) {50 // NEW BUTTON51 try {52 new PassManuelSetupView ( null , view . getTimeLineView ( ) )

;53 } catch ( RemoteException e ) {54 // TODO Auto−g e n e r a t e d c a t c h b l o c k55 e . pr intStackTrace ( ) ;56 } catch ( NotBoundException e ) {57 // TODO Auto−g e n e r a t e d c a t c h b l o c k58 e . pr intStackTrace ( ) ;59 }60 } else i f ( ae . getSource ( ) . equa l s ( view . getDeleteButton ( ) ) | | ae .

getSource ( ) . equa l s ( view . getDeleteMenuItem () ) ) {61 // DELETE BUTTON OR DELETE RIGHT CLICK6263 int selectedRow = view . getTable ( ) . getSelectedRow () ;64 long passID = ( Long ) view . getTable ( ) . getValueAt ( selectedRow ,

CommandAbstractTableModel . ID COLUMN) ;6566 int n = JOptionPane . showConfirmDialog ( view , ”Are you sure

you wish to de l e t e pass ”+ passID+”?” , ” Delete pass ?” ,67 JOptionPane .YES NO OPTION) ;6869 i f (n== JOptionPane .YES OPTION) {70 try {71 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) .

removePass ( passID , Pass .DELETED USER) ;72 view . getTimeLineView ( ) .

setScheduleRecommendation ( true ) ;73 update ( ) ;74 } catch ( RemoteException e ) {7576 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .

Page 288: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

278 Appendix C - Source Code

ERROR MESSAGE) ;77 e . pr intStackTrace ( ) ;78 } catch ( NotBoundException e ) {79 JOptionPane . showMessageDialog ( view , e .

getMessage ( ) , ” Error ” , JOptionPane .ERROR MESSAGE) ;

80 e . pr intStackTrace ( ) ;81 }8283 }8485 } else i f ( ae . getSource ( ) . equa l s ( view . getEditButton ( ) ) | | ae .

getSource ( ) . equa l s ( view . getEditMenuItem () ) ) {86 // EDIT BUTTON OR EDIT RIGHT CLICK87 int row = view . getTable ( ) . getSelectedRow () ;88 long passID = ( Long ) view . getTable ( ) . getValueAt ( row ,

PassesAbstractTableModel . ID COLUMN) ;89 TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) . getPassMap ( ) .

get ( passID ) ;90 Pass pass = TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

getPassMap ( ) . get ( passID ) ;91 try {92 new PassManuelSetupView ( pass , view . getTimeLineView ( ) )

;93 } catch ( RemoteException e ) {94 // TODO Auto−g e n e r a t e d c a t c h b l o c k95 e . pr intStackTrace ( ) ;96 } catch ( NotBoundException e ) {97 // TODO Auto−g e n e r a t e d c a t c h b l o c k98 e . pr intStackTrace ( ) ;99 }

100101 } else i f ( ae . getSource ( ) . equa l s ( view . getUpdateButton ( ) ) ) {102 // UPDATE BYTTON103104 try {105 i f ( TimeLineModel . g e t In s tance ( ) . getGroundStations ( ) .

s i z e ( )==0) {106 JOptionPane . showMessageDialog ( view , ”You

need to add a ground s t a t i on be fo r e TLEupdate can be performed . ” , ”No Ground

Stat ion ” , JOptionPane .WARNING MESSAGE) ;107 } else {108 new TLEUpdateView( view . getTimeLineView ( ) ) ;109 }110111 } catch ( RemoteException e ) {112 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;113 e . pr intStackTrace ( ) ;114 } catch ( PredictExcept ion e ) {115 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;116 e . pr intStackTrace ( ) ;117 } catch ( NotBoundException e ) {118 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;119 e . pr intStackTrace ( ) ;120 }121122 }123124 }125126 private void update ( ) {127 try {128 view . getTimeLineView ( ) . updateTimeLineViews ( ) ;129 view . getTimeLineView ( ) . newFi l ter ( ) ;130 } catch ( RemoteException e ) {131 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;132 e . pr intStackTrace ( ) ;133 } catch ( NotBoundException e ) {134 JOptionPane . showMessageDialog ( view , e . getMessage ( ) , ” Error ” ,

JOptionPane .ERROR MESSAGE) ;135 e . pr intStackTrace ( ) ;136 }137 }138139 @Override140 public void valueChanged ( L i s tSe l e c t i onEvent l s e ) {141142 // r e p a i n t g r a p h i c t i m e l i n e t o make t h e s e l e c t i n g v i s i b l e143 int selectedRow = view . getTable ( ) . getSelectedRow () ;144 i f ( selectedRow==−1) {145 view . getTimeLineView ( ) . getGraphicView ( ) . s e tSe l ec tedPass ID

(−1) ;

Page 289: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 279

146 } else{147 long se l ec tedPass ID = ( Long ) view . getTable ( ) . getValueAt (

selectedRow , PassesAbstractTableModel . ID COLUMN ) ;148 view . getTimeLineView ( ) . getGraphicView ( ) . s e tSe l ec tedPass ID (

se l ec tedPass ID ) ;149 }150151 view . getTimeLineView ( ) . getGraphicView ( ) . r epa in t ( ) ;152153 // u p d a t e s e l e c t e d p a s s i n f o l a b e l154 view . updateSe lec tedPass In foLabe l ( ) ;155156 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( ) >=User .FULL TRUST) {157 // u p d a t e E d i t / D e l e t e b u t t o n s s t a t u s158 i f ( view . getTable ( ) . getSelectedRow ()==−1) {159 // B u t t o n s160 view . getEditButton ( ) . setEnabled ( f a l s e ) ;161 view . getDeleteButton ( ) . setEnabled ( f a l s e ) ;162 view . getEditButton ( ) . setToolTipText ( ” S e l e c t a pass

to ed i t ” ) ;163 view . getDeleteButton ( ) . setToolTipText ( ” S e l e c t a pass

to d e l t e ” ) ;164 } else {165 // B u t t o n s166 view . getEditButton ( ) . setEnabled ( true ) ;167 view . getDeleteButton ( ) . setEnabled ( true ) ;168 view . getEditButton ( ) . setToolTipText ( ” Cl ick to ed i t

pass ” ) ;169 view . getDeleteButton ( ) . setToolTipText ( ” Cl ick to

d e l e t e pass ” ) ;170 }171 }172173174 }175176 @Override177 public void mouseClicked ( MouseEvent arg0 ) {178 // TODO Auto−g e n e r a t e d me t hod s t u b179180 }181182 @Override183 public void mouseEntered ( MouseEvent arg0 ) {184 // TODO Auto−g e n e r a t e d me t hod s t u b185186 }187188 @Override189 public void mouseExited ( MouseEvent arg0 ) {190 // TODO Auto−g e n e r a t e d me t hod s t u b191192 }193194 @Override195 public void mousePressed ( MouseEvent arg0 ) {196 // TODO Auto−g e n e r a t e d me t hod s t u b197198 }199200 @Override201 public void mouseReleased ( MouseEvent e ) {202203 maybeShowPopup( e ) ;204205 }206207 /∗∗208 ∗ @param e209 ∗/210 private void maybeShowPopup( MouseEvent e ) {211 i f ( e . isPopupTrigger ( ) ) {212213 int row = view . getTable ( ) . rowAtPoint (new Point ( e . getX ( ) , e . getY ( ) ) ) ;214215 i f ( row!=−1) {216 view . getTable ( ) . s e tRowSe l e c t i on In te rva l ( row , row ) ;217218 view . getRightClickPopupMenu ( ) . show ( e . getComponent ( ) , e . getX ( ) , e .

getY ( ) ) ;219 }220221 }222 }223224225 }

Page 290: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

280 Appendix C - Source Code

.1.79 PassesTableView.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Dimension ;4 import java . awt . Font ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;7 import java . rmi . RemoteException ;8 import java . text . SimpleDateFormat ;9

10 import javax . swing . BorderFactory ;11 import javax . swing . JButton ;12 import javax . swing . JLabel ;13 import javax . swing . JMenuItem ;14 import javax . swing . JPanel ;15 import javax . swing . JPopupMenu ;16 import javax . swing . JScro l lPane ;17 import javax . swing . JTable ;18 import javax . swing . L i s tSe l e c t i onMode l ;19 import javax . swing . border . EtchedBorder ;20 import javax . swing . border . Tit ledBorder ;21 import javax . swing . tab l e . TableRowSorter ;2223 import mcc . s e rv e r . dataProcess ing . Pass ;24 import mcc . s e rv e r . u s e r s . User ;25 import mps . MPSPreferences ;26 import mps . rmi . C l i ent ;2728 /∗∗29 ∗ <br><br>30 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 331 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 132 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 833 ∗/34 public c lass PassesTableView extends JPanel {3536 /∗∗37 ∗38 ∗/39 private stat ic f ina l long se r ia lVers ionUID = 1L ;40 /∗∗41 ∗42 ∗/43 private TimeLineView timeLineView ;44 /∗∗45 ∗46 ∗/47 private PassesAbstractTableModel passesAbstractTableModel ;48 /∗∗49 ∗50 ∗/51 private TableRowSorter<PassesAbstractTableModel> s o r t e r ;52 /∗∗53 ∗54 ∗/55 private PassesTab leContro l l e r c o n t r o l l e r ;56 /∗∗57 ∗58 ∗/59 private JTable tab l e ;6061 /∗∗62 ∗63 ∗/64 private JLabel s e l e c t i o nLabe l ;65 /∗∗66 ∗67 ∗/68 private JButton newPassButton ;69 /∗∗70 ∗71 ∗/72 private JButton updateButton ;73 /∗∗74 ∗75 ∗/76 private JButton editButton ;77 /∗∗78 ∗79 ∗/80 private JButton deleteButton ;8182 /∗∗83 ∗84 ∗/

Page 291: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 281

85 private JPopupMenu rightClickPopupMenu ;86 /∗∗87 ∗88 ∗/89 private JMenuItem deleteMenuItem ;90 /∗∗91 ∗92 ∗/93 private JMenuItem editMenuItem ;9495 /∗∗96 ∗97 ∗/98 private JLabel s e l e c t edPas s In f oPane l ;99

100101 /∗∗102 ∗ @param t im e L i n eV i e w103 ∗ @th r ow s R emo t e E x c e p t i o n104 ∗/105 public PassesTableView ( TimeLineView timeLineView ) throws RemoteException {106 this . timeLineView = timeLineView ;107 c o n t r o l l e r = new PassesTab leContro l l e r ( this ) ;108109 this . setLayout (new GridBagLayout ( ) ) ;110 GridBagConstraints c = new GridBagConstraints ( ) ;111112113 // TABLE SET−UP114 passesAbstractTableModel = new PassesAbstractTableModel ( ) ;115 tab l e = new JTable ( passesAbstractTableModel ) ;116117 s o r t e r = new TableRowSorter<PassesAbstractTableModel >(

passesAbstractTableModel ) ;118 tab l e . setRowSorter ( s o r t e r ) ;119 tab l e . setColumnSelect ionAllowed ( f a l s e ) ;120 tab l e . setRowSelect ionAllowed ( true ) ;121122 tab l e . s e tP r e f e r r edSc r o l l ab l eV i ewpo r tS i z e (new Dimension (370 ,170) ) ;123 tab l e . s e tF i l l sV i ewpor tHe ight ( true ) ;124 // t a b l e . s e t A u t o R e s i z e M o d e ( JT a b l e . AUTO RESIZE OFF ) ;125 setTableColumnWidths ( ) ;126127 tab l e . setSe lect ionMode ( L i s tSe l e c t i onMode l . SINGLE SELECTION) ;128129 JScro l lPane s c ro l lPane = new JScro l lPane ( tab l e ) ;130 s c ro l lPane . setMinimumSize (new Dimension (380 ,170) ) ;131 s c ro l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .VERTICAL SCROLLBAR ALWAYS)

;132 s c ro l lPane . s e tHo r i z on ta l S c r o l lBa rPo l i c y ( JScro l lPane .

HORIZONTAL SCROLLBAR AS NEEDED) ;133134 c . anchor = GridBagConstraints .LINE START;135 c . gr idx = 0 ;136 c . gr idy = 0 ;137 c . gr idwidth = 2 ;138 this . add ( scro l lPane , c ) ;139140141 JPanel l e f tButtonPane l = new JPanel ( ) ;142 newPassButton = new JButton ( ”New” ) ;143 updateButton = new JButton ( ”Update from TLE” ) ;144 le f tButtonPane l . add ( newPassButton ) ;145 le f tButtonPane l . add ( updateButton ) ;146 c . gr idy = 1 ;147 this . add ( le f tButtonPanel , c ) ;148149 JPanel r ightButtonPanel = new JPanel ( ) ;150 editButton = new JButton ( ” Edit ” ) ;151 de leteButton = new JButton ( ” Delete ” ) ;152 editButton . setEnabled ( f a l s e ) ;153 de leteButton . setEnabled ( f a l s e ) ;154 s e l e c t i o nLabe l = new JLabel ( ” S e l e c t i on act ion : ” ) ;155 r ightButtonPanel . add ( s e l e c t i onLabe l ) ;156 r ightButtonPanel . add ( editButton ) ;157 r ightButtonPanel . add ( de leteButton ) ;158 c . gr idx = 1 ;159 c . anchor = GridBagConstraints . LINE END;160 this . add ( rightButtonPanel , c ) ;161162 setButtonStatusFromTrustLevel ( ) ;163164 c . gr idx = 0 ;165 c . gr idy = 2 ;166 c . gr idwidth = 2 ;167 c . anchor = GridBagConstraints .LINE START;168 c . f i l l = GridBagConstraints .HORIZONTAL;

Page 292: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

282 Appendix C - Source Code

169170 s e l e c t edPas s In f oPane l = new JLabel ( ) ;171 this . add ( se l e c t edPass In foPane l , c ) ;172173 // C r e a t e R i g h t C l i c k menu174 createRightClickMenu ( ) ;175176 // L i s t e n e r s177 tab l e . getSe l ect ionMode l ( ) . addL i s t S e l e c t i onL i s t en e r ( c o n t r o l l e r ) ;178 tab l e . addMouseListener ( c o n t r o l l e r ) ; // f o r r i g h t c l i c k menu179 newPassButton . addAct ionListener ( c o n t r o l l e r ) ;180 de leteButton . addAct ionListener ( c o n t r o l l e r ) ;181 editButton . addAct ionListener ( c o n t r o l l e r ) ;182 updateButton . addAct ionListener ( c o n t r o l l e r ) ;183184 }185186 public void createRightClickMenu ( ) {187 rightClickPopupMenu = new JPopupMenu ( ) ;188189 deleteMenuItem = new JMenuItem( ” Delete ” ) ;190 editMenuItem = new JMenuItem( ” Edit ” ) ;191192 rightClickPopupMenu . add ( editMenuItem ) ;193 rightClickPopupMenu . add ( deleteMenuItem ) ;194195 // L i s t e n e r s196 deleteMenuItem . addAct ionListener ( c o n t r o l l e r ) ;197 editMenuItem . addAct ionListener ( c o n t r o l l e r ) ;198199 }200201 /∗∗202 ∗203 ∗/204 private void setButtonStatusFromTrustLevel ( ) {205 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( ) <= User .MEDIUM TRUST) {206 // e d i t B u t t o n . s e t V i s i b l e ( f a l s e ) ;207 // d e l e t e B u t t o n . s e t V i s i b l e ( f a l s e ) ;208 // u p d a t e B u t t o n . s e t V i s i b l e ( f a l s e ) ;209 editButton . setEnabled ( f a l s e ) ;210 de leteButton . setEnabled ( f a l s e ) ;211 updateButton . setEnabled ( f a l s e ) ;212 editButton . setToolTipText ( ”To ed i t pass \” Ful l Trust\” or

h igher i s r equ i r ed . ” ) ;213 de leteButton . setToolTipText ( ”To de l e t e pass \” Ful l Trust\”

or h igher i s r equ i r ed . ” ) ;214 updateButton . setToolTipText ( ”To update pass from TLE \” Ful l

Trust\” or h igher i s r equ i r ed . ” ) ;215 }216 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( ) <= User .MINIMAL TRUST) {217 // n ewPa s sBu t t o n . s e t V i s i b l e ( f a l s e ) ;218 newPassButton . setEnabled ( f a l s e ) ;219 newPassButton . setToolTipText ( ”To c r ea t e new pass \”Medium

Trust\” or h igher i s r equ i r ed . ” ) ;220221 }222223 }224225 /∗∗226 ∗227 ∗/228 public void updateSe lec tedPass In foLabe l ( ) {229230 i f ( tab l e . getSelectedRow ()==−1) {231 // No s e l e c t i o n232 s e l e c t edPas s In f oPane l . setBorder ( null ) ;233 s e l e c t edPas s In f oPane l . setText ( ”” ) ;234 s e l e c t edPas s In f oPane l . s e t V i s i b l e ( f a l s e ) ;235 } else {236 // A s e l e c t i o n237238 long passID = ( Long ) tab l e . getValueAt ( tab l e . getSelectedRow ()

, PassesAbstractTableModel . ID COLUMN) ;239 Pass pass = TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

lookupPass ( passID ) ;240241 Tit ledBorder t i t l e = BorderFactory . c r ea teT i t l edBorder (

BorderFactory . createEtchedBorder ( EtchedBorder .LOWERED) ,242 ”Pass In fo ” , Tit ledBorder .LEFT, Tit ledBorder

.CENTER ,new Font ( ”Tahoma” , Font .BOLD,11 ) ) ;

243 s e l e c t edPas s In f oPane l . setBorder ( t i t l e ) ;244245 St r ing s t a r t = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( pass . getStartTime ( ) ) ;

Page 293: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 283

246 St r ing end = new SimpleDateFormat ( MPSPreferences .getFullDateTimeFormat ( ) ) . format ( pass . getEndTime ( ) ) ;

247 St r ing durat ion = new SimpleDateFormat ( MPSPreferences .getTimeFormat ( ) ) . format ( ( pass . getEndTime ( )−pass .getStartTime ( ) ) − 3600000 ) ;

248 St r ing gs = pass . getGroundStationName ( ) ;249 long upl ink = pass . getUpl inkBytesAvai lab le ( ) ;250 long s e s s i o n = pass . getSess ionID ( ) ;251252 St r ing txt = ”<html><table>” +253 ”<tr><td>ID:</td><td><b>”+ pass . getPassID ( )

+”</b></td><td>Ground Stat ion </td><td><b>” + gs + ”</b></td></tr>” +

254 ”<tr><td>Start :</td><td><b>”+ s t a r t +”</b></td><td>Duration </td><td><b>” + durat ion+ ”</b></td></tr>” +

255 ”<tr><td>End:</td><td><b>”+ end +”</b></td><td>Bytes f r e e </b></td><td><b>” + upl ink+ ”</b></td></tr>” +

256 ”<tr><td>Commands:</td><td><b>”+ pass . s i z e ( )+”</b></td><td>Sess ion </td><td><b>” +

s e s s i o n + ”</b></td></tr>” ;257258 s e l e c t edPas s In f oPane l . setText ( txt ) ;259 s e l e c t edPas s In f oPane l . s e t V i s i b l e ( true ) ;260261 }262263 }264265266 /∗∗267 ∗268 ∗/269 public void setTableColumnWidths ( ) {270271 tab l e . getColumnModel ( ) . getColumn ( PassesAbstractTableModel . ID COLUMN)

. setPreferredWidth (30) ;272 tab l e . getColumnModel ( ) . getColumn ( PassesAbstractTableModel .

START COLUMN) . setPreferredWidth (120) ;273 tab l e . getColumnModel ( ) . getColumn ( PassesAbstractTableModel .

SESSION COLUMN) . setPreferredWidth (100) ;274 // t a b l e . g e tC o l umnMod e l ( ) . g e tCo l umn ( 2 ) . s e t P r e f e r r e d W i d t h ( 1 2 0 ) ;275 // t a b l e . g e tC o l umnMod e l ( ) . g e tCo l umn ( 3 ) . s e t P r e f e r r e d W i d t h ( 5 0 ) ;276 // t a b l e . g e tC o l umnMod e l ( ) . g e tCo l umn ( 4 ) . s e t P r e f e r r e d W i d t h ( 1 0 0 ) ;277 // t a b l e . g e tC o l umnMod e l ( ) . g e tCo l umn ( 5 ) . s e t P r e f e r r e d W i d t h ( 1 0 0 ) ;278 // t a b l e . g e tC o l umnMod e l ( ) . g e tCo l umn ( 6 ) . s e t P r e f e r r e d W i d t h ( 1 5 0 ) ;279280 }281282 /∗∗283 ∗ Re t u r n s t h e p a s s s e l e c t e d i n t h e p a s s t a b l e284 ∗ @r e t u r n The p a s s s e l e c t e d i n t h e p a s s t a b l e , o r n u l l i f no p a s s i s

s e l e c t e d285 ∗/286 public Pass ge tSe l e c t edPass ( ) {287 int selectedRow = tab l e . getSelectedRow () ;288 i f ( selectedRow==−1){289 return null ;290 } else {291 long se l ec tedPass ID = ( Long ) tab l e . getValueAt ( selectedRow ,

PassesAbstractTableModel . ID COLUMN) ;292 return TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

getPassMap ( ) . get ( se l ec tedPass ID ) ;293 }294295 }296297 /∗∗298 ∗ @r e t u r n299 ∗/300 public JButton getNewPassButton ( ) {301 return newPassButton ;302 }303304305 /∗∗306 ∗ @r e t u r n307 ∗/308 public JButton getUpdateButton ( ) {309 return updateButton ;310 }311312313 /∗∗314 ∗ @r e t u r n315 ∗/

Page 294: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

284 Appendix C - Source Code

316 public JButton getEditButton ( ) {317 return editButton ;318 }319320321 /∗∗322 ∗ @r e t u r n323 ∗/324 public JButton getDeleteButton ( ) {325 return deleteButton ;326 }327328329 /∗∗330 ∗ @r e t u r n331 ∗/332 public TimeLineView getTimeLineView ( ) {333 return timeLineView ;334 }335336337 /∗∗338 ∗ @r e t u r n339 ∗/340 public JTable getTable ( ) {341 return tab l e ;342 }343344345 /∗∗346 ∗ @r e t u r n347 ∗/348 public PassesAbstractTableModel getPassesTableModel ( ) {349 return passesAbstractTableModel ;350 }351352 /∗∗353 ∗ @r e t u r n354 ∗/355 public JPopupMenu getRightClickPopupMenu ( ) {356 return rightClickPopupMenu ;357 }358359 /∗∗360 ∗ @r e t u r n361 ∗/362 public JMenuItem getDeleteMenuItem () {363 return deleteMenuItem ;364 }365366 /∗∗367 ∗ @r e t u r n368 ∗/369 public JMenuItem getEditMenuItem () {370 return editMenuItem ;371 }372373 }

Page 295: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 285

.1.80 TimeLineController.java

1 package mps . gui . t ime l i n e ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . awt . event . ItemEvent ;6 import java . awt . event . I t emLis tener ;7 import java . rmi . NotBoundException ;8 import java . rmi . RemoteException ;9 import java . u t i l . ArrayList ;

1011 import javax . swing . JOptionPane ;12 import javax . swing . event . ChangeEvent ;13 import javax . swing . event . ChangeListener ;14 import javax . swing . event . DocumentEvent ;15 import javax . swing . event . DocumentListener ;1617 import mcc . s e rv e r . dataProcess ing . GroundStation ;18 import mps . MPSPreferences ;19 import mps . gui . AboutFrame ;20 import mps . gui . GroundStationSetupView ;21 import mps . gui . LoginView ;22 import mps . gui . passwindow . PasswindowView ;23 import mps . gui . passwindow . UpdateThread ;24 import mps . gui . s e t t i n g s . DateFormatView ;25 import mps . gui . s e t t i n g s . PreSchedulingView ;26 import mps . gui . s e t t i n g s . PredefinedBlocksPathView ;27 import mps . gui . s e t t i n g s . StateColor ingView ;28 import mps . gui . s e t t i n g s . TleSett ingsView ;29 import mps . gui . s e t t i n g s . UpdateIntervalView ;30 import mps . gui . s e t t i n g s . UserChooserView ;31 import mps . gui . s e t t i n g s . UserSetupView ;32 import mps . rmi . C l i ent ;3334 import common . auth . S impleCredent ia l s ;3536 /∗∗37 ∗ <br><br>38 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 339 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 140 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 841 ∗/42 public c lass TimeLineControl ler implements ChangeListener , I temListener ,

DocumentListener , Act ionL i s t ener {4344 /∗∗45 ∗46 ∗/47 private TimeLineView view ;48 /∗∗49 ∗50 ∗/51 private TimeLineModel model ;5253 /∗∗54 ∗55 ∗/56 private UpdateThread updateThread ;5758 /∗∗59 ∗ @param t im e L i n eV i e w60 ∗ @param mode l61 ∗/62 public TimeLineControl ler ( TimeLineView timeLineView , TimeLineModel model ) {63 this . view = timeLineView ;64 this . model = model ;6566 updateThread = new UpdateThread ( this ) ;67 }686970 @Override71 public void act ionPerformed ( ActionEvent ae ) {727374 i f ( ae . getSource ( ) . equa l s ( view . getLogoutMenuItem () ) ) {7576 try {77 Cl i ent . g e t In s tance ( ) . s e t C l i e n t I n f o ( ”” , 0 , ”” , new

SimpleCredent ia l s ( ”” , ”” ) ) ;78 } catch ( RemoteException e ) {79 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;80 e . pr intStackTrace ( ) ;81 } catch ( NotBoundException e ) {

Page 296: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

286 Appendix C - Source Code

82 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,” Error ” , JOptionPane .ERROR MESSAGE) ;

83 e . pr intStackTrace ( ) ;84 } // k i l l c l i e n t85 view . d i spose ( ) ;86 new LoginView ( ) ;878889 } else i f ( ae . getSource ( ) . equa l s ( view . getExitMenuItem () ) ) {9091 System . ex i t (0) ;9293 } else i f ( ae . getSource ( ) . equa l s ( view . getNewGsMenuItem () ) ) {94 // NEW GS9596 try {97 new GroundStationSetupView ( view , null ) ;98 } catch ( RemoteException e ) {99 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;100 e . pr intStackTrace ( ) ;101 } catch ( NotBoundException e ) {102 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;103 e . pr intStackTrace ( ) ;104 }105106 } else i f ( ae . getSource ( ) . equa l s ( view . getCreateUserMenuItem () ) ) {107108 new UserSetupView ( ) ;109110 } else i f ( ae . getSource ( ) . equa l s ( view . getEditUserMenuItem () ) ) {111 new UserChooserView ( ) ;112113 } else i f ( ae . getSource ( ) . equa l s ( view . getTleMenuItem () ) ) {114 // SETTINGS > TLE F i l e115 new TleSett ingsView ( ) ;116117 } else i f ( ae . getSource ( ) . equa l s ( view . getPreschedulingMenuItem () ) ) {118 // PRE−SCHEDULING119 new PreSchedulingView ( ) ;120121122 } else i f ( ae . getSource ( ) . equa l s ( view . getPreDefinedBlocksMenuItem () ) )

{123 // SETTINGS > PREDEFINED BLOCK PATH124 new PredefinedBlocksPathView ( ) ;125126 } else i f ( ae . getSource ( ) . equa l s ( view . getDateFormatMenuItem () ) ) {127 // SETTINGS > DATE FORMAT128 new DateFormatView ( view ) ;129130 } else i f ( ae . getSource ( ) . equa l s ( view . getStateColoringMenuItem () ) ) {131 // SETTINGS > S t a t e c o l o r132 new StateColor ingView ( view ) ;133134135 } else i f ( ae . getSource ( ) . equa l s ( view .

getGuiUpdateOnRadioButtonMenuItem () ) ) {136 // Upda t e Th r ead ON Rad i o b u t t o n137 MPSPreferences . setUpdatingOn ( true ) ;138 updateThread . setRunning ( true ) ;139 view . getGuiUpdateIntervalMenuItem () . setEnabled ( true ) ;140 view . getGuiUpdateIntervalMenuItem () . setText ( ” I n t e r v a l ( ” +

MPSPreferences . ge tUpdate Inte rva l InMi l i s e conds ( ) /1000 +” s ) ” ) ;

141142 } else i f ( ae . getSource ( ) . equa l s ( view .

getGuiUpdateOffRadioButtonMenuItem () ) ) {143 // Upda t e Th r ead OFF Rad i o b u t t o n144 MPSPreferences . setUpdatingOn ( f a l s e ) ;145 updateThread . setRunning ( f a l s e ) ;146 view . getGuiUpdateIntervalMenuItem () . setEnabled ( f a l s e ) ;147 view . getGuiUpdateIntervalMenuItem () . setText ( ” I n t e r v a l ” ) ;148149 } else i f ( ae . getSource ( ) . equa l s ( view . getGuiUpdateIntervalMenuItem () )

) {150 new UpdateIntervalView ( ) ;151152 } else i f ( ae . getSource ( ) . equa l s ( view . getScheduleButton ( ) ) ) {153 // SCHEDULE BUTTON154 try {155 // FIXME : S e t t h i s v e r y l a r g e number t o t h e u s e r

i n p u t156 long preSchedu l ingMi l i s econds = MPSPreferences .

ge tPreschedu l ing ( ) ∗1000∗60∗60∗24;

Page 297: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 287

157 Cl i ent . g e t In s tance ( ) . g e t F u l l I n t e r f a c e ( ) . schedule (preSchedu l ingMi l i s econds ) ;

158159 view . setScheduleRecommendation ( f a l s e ) ;160161 view . updateTimeLineViews ( ) ;162 view . newFi l te r ( ) ;163 JOptionPane . showMessageDialog ( view , ”The commands

has been scheduled ” , ” Schedul ing done” ,JOptionPane .INFORMATION MESSAGE) ;

164165 } catch ( RemoteException e1 ) {166 JOptionPane . showMessageDialog ( view , e1 . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;167 e1 . pr intStackTrace ( ) ;168 } catch ( NotBoundException e ) {169 JOptionPane . showMessageDialog ( view , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;170 e . pr intStackTrace ( ) ;171 }172173 } else i f ( ae . getSource ( ) . equa l s ( view . getAllConnectionsCheckBox ( ) ) ) {174175 boolean a l l S e l e c t e d = view . getAllConnectionsCheckBox ( ) .

i s S e l e c t e d ( ) ;176 view . getPassToCommandsCheckBox ( ) . setEnabled ( ! a l l S e l e c t e d ) ;177 view . getCommandsToPassCheckBox ( ) . setEnabled ( ! a l l S e l e c t e d ) ;178179 view . getGraphicView ( ) . r epa in t ( ) ;180181 } else i f ( ae . getSource ( ) . equa l s ( view . getCommandsToPassCheckBox ( ) )

| | ae . getSource ( ) . equa l s ( view . getPassToCommandsCheckBox ( ) ) ) {182 view . getGraphicView ( ) . r epa in t ( ) ;183184 } else i f ( ae . getSource ( ) . equa l s ( view . getPassWindowButton ( ) ) ) {185 // PASS WINDOW186 try {187 new PasswindowView ( view ) ;188 } catch ( RemoteException e ) {189 // TODO Auto−g e n e r a t e d c a t c h b l o c k190 e . pr intStackTrace ( ) ;191 }192 } else i f ( ae . getSource ( ) . equa l s ( view . getAboutMenuItem () ) ) {193194 new AboutFrame ( ) ;195196197 } else {198 // T e s t i f e d i t o f a GS h a s b e e n p r e s s e d199 ArrayList<GroundStation> groundStat ions = null ;200 try {201 groundStat ions = Cl i ent . g e t In s tance ( ) .

ge tMin ima l Inte r face ( ) . getGroundStations ( ) ;202 } catch ( RemoteException e ) {203 // TODO Auto−g e n e r a t e d c a t c h b l o c k204 e . pr intStackTrace ( ) ;205 } catch ( NotBoundException e ) {206 // TODO Auto−g e n e r a t e d c a t c h b l o c k207 e . pr intStackTrace ( ) ;208 }209 for ( GroundStation gs : groundStat ions ) {210 i f ( ae . getActionCommand ( ) . equa l s ( gs . GetName ( ) ) ) {211 // EDIT GS212 try {213 new GroundStationSetupView ( view , gs ) ;214 } catch ( RemoteException e ) {215 // TODO Auto−g e n e r a t e d c a t c h b l o c k216 e . pr intStackTrace ( ) ;217 } catch ( NotBoundException e ) {218 // TODO Auto−g e n e r a t e d c a t c h b l o c k219 e . pr intStackTrace ( ) ;220 }221 }222 }223224 }225226 }227228 @Override // FILTER TEXT229 public void changedUpdate ( DocumentEvent arg0 ) {230 view . newFi l te r ( ) ;231 }232233 @Override // FILTER TEXT234 public void insertUpdate ( DocumentEvent arg0 ) {235 view . newFi l te r ( ) ;

Page 298: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

288 Appendix C - Source Code

236 }237238 @Override // FILTER TEXT239 public void removeUpdate ( DocumentEvent arg0 ) {240 view . newFi l te r ( ) ;241 }242243 @Override244 public void stateChanged ( ChangeEvent ce ) {245246 i f ( ce . getSource ( ) . equa l s ( view . getStartDateTimeSpinnersPanel ( ) .

getDateSDM () ) | | ce . getSource ( ) . equa l s ( view .getStartDateTimeSpinnersPanel ( ) . getTimeSDM () )

247 | | ce . getSource ( ) . equa l s ( view .getEndDateTimeSpinnersPanel ( ) . getDateSDM () ) | |ce . getSource ( ) . equa l s ( view .getEndDateTimeSpinnersPanel ( ) . getTimeSDM () ) ) {

248 // SPINNER CHANGED ( ma n u a l l y )249250 model . s e t S t a r t ( view . getStartEpochFromSpinners ( ) ) ;251 model . setEnd ( view . getEndEpochFromSpinners ( ) ) ;252253 // u p d a t e f i l t e r254 view . newFi l ter ( ) ;255256 // u p d a t e g r a p h i c v i e w257 view . getGraphicView ( ) . r epa in t ( ) ;258259 // r e s e t c ombo bo x260 view . resetToComboHeader ( ) ;261262 }263264 }265266 @Override267 public void itemStateChanged ( ItemEvent i e ) {268269 i f ( i e . getSource ( ) . equa l s ( view . getTimelineOptionsComboBox ( ) ) ) {270271 view . removeListenersFromSpinners ( ) ;272273 switch ( view . getTimelineOptionsComboBox ( ) . ge tSe l e c t ed Index ( )

) {274 case 0 : break ; // do n o t h i n g − t h i s i s t h e h e a d e r275 case 1 : model . setTimeLineToDefaultTimes ( ) ; break ;276 case 2 : model . setTimeLineToAll ( ) ; break ;277 case 3 : model . setTimeLineToToday ( ) ; break ;278 case 4 : model . setTimeLineToNext24Hours ( ) ; break ;279 case 5 : model . setTimeLineToTomorrow ( ) ; break ;280 case 6 : model . setTimeLineToThisWeek ( ) ; break ;281 case 7 : model . setTimeLineToNextWeek ( ) ; break ;282 case 8 : model . setTimeLineToThisMonth ( ) ; break ;283 case 9 : model . setTimeLineToNextMonth ( ) ; break ;284 default :285 break ;286 }287288 view . updateTimeLineEndAndStart ( model . g e tS ta r t ( ) , model .

getEnd ( ) ) ;289290 view . addListenersToSpinners ( ) ;291 }292293 }294295 /∗∗296 ∗ @r e t u r n297 ∗/298 public TimeLineView getView ( ) {299 return view ;300 }301302303 /∗∗304 ∗ @r e t u r n305 ∗/306 public UpdateThread getUpdateThread ( ) {307 return updateThread ;308 }309310311312313 }

Page 299: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 289

.1.81 TimeLineGraphicController.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Cursor ;4 import java . awt . Point ;5 import java . awt . event . ActionEvent ;6 import java . awt . event . Act ionL i s t ener ;7 import java . awt . event . InputEvent ;8 import java . awt . event . MouseEvent ;9 import java . awt . event . MouseListener ;

10 import java . awt . event . MouseMotionListener ;11 import java . awt . event . MouseWheelEvent ;12 import java . awt . event . MouseWheelListener ;13 import java . u t i l . HashMap ;1415 import mcc . s e rv e r . dataProcess ing . Pass ;1617 import common . command .Command;18192021 /∗∗22 ∗ <br><br>23 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 324 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 125 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 826 ∗/27 public c lass TimeLineGraphicControl ler implements MouseWheelListener , MouseListener ,

MouseMotionListener , Act ionL i s t ener{2829 /∗∗30 ∗31 ∗/32 private TimeLineGraphicView view ;33 /∗∗34 ∗35 ∗/36 private TimeLineModel timeLineModel = TimeLineModel . g e t In s tance ( ) ;3738 /∗∗39 ∗40 ∗/41 private long lastX ;4243 /∗∗44 ∗ @param v i e w45 ∗/46 public TimeLineGraphicControl ler ( TimeLineGraphicView view ){47 this . view = view ;4849 }5051 @Override52 public void mouseWheelMoved ( MouseWheelEvent e ) {5354 long s t a r t = view . getLineStartTime ( ) ;55 long end = view . getLineEndTime ( ) ;5657 long l ineLength = end−s t a r t ;5859 double zoomFactor = 10∗( e . getWheelRotation ( ) ∗e . getWheelRotation ( ) ) ;6061 f loat f a c t o r = ( f loat ) e . getX ( ) /( f loat ) TimeLineGraphicView .LINELENGTH

;62 long mouseTime = ( long ) ( f a c t o r ∗( l ineLength ) + s t a r t ) ; // At wha t

t im e t h e mouse i s p o s i t i o n e d63 long distanceFromStartToMouse = mouseTime−s t a r t ;64 long distanceFromEndToMouse = end−mouseTime ;656667 // Remove l i s t e n e r s f r om s p i n n e r s w h i l e z o om i n g t o a v i o d c o n f u s i n g

i n u p d a t e68 view . getTimeLineView ( ) . removeListenersFromSpinners ( ) ;6970 long newStart , newEnd ;7172 i f ( e . getWheelRotation ( ) <0){ // I f t h e w h e e l r o t a t i o n i s n e g a t i v e i . e

. ZOOM IN73 newStart = ( long ) ( s t a r t +(distanceFromStartToMouse/zoomFactor

) ) ;74 newEnd = ( long ) ( end−(distanceFromEndToMouse/zoomFactor ) ) ;75 timeLineModel . s e t S t a r t ( newStart ) ;76 timeLineModel . setEnd (newEnd) ;77 view . getTimeLineView ( ) . updateTimeLineEndAndStart ( newStart ,

newEnd) ;

Page 300: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

290 Appendix C - Source Code

7879 } else { // I f t h e w h e e l r o t a t i o n i s p o s i t i v e o r 0 i . e .

ZOOM OUT80 newStart = ( long ) ( s ta r t −(distanceFromStartToMouse/zoomFactor

) ) ;81 newEnd = ( long ) ( end+(distanceFromEndToMouse/zoomFactor ) ) ;82 timeLineModel . s e t S t a r t ( newStart ) ;83 timeLineModel . setEnd (newEnd) ;84 view . getTimeLineView ( ) . updateTimeLineEndAndStart ( newStart ,

newEnd) ;85 }868788 // add t h e l i s t e n e r s t o t h e s p i n n e r a g a i n89 view . getTimeLineView ( ) . addListenersToSpinners ( ) ;9091 view . getTimeLineView ( ) . resetToComboHeader ( ) ;929394 }9596 @Override97 public void mouseClicked ( MouseEvent e ) {9899 // c h e c k t h a t t h e l e f t mouse b u t t o n i s c l i c k e d

100 i f ( e . getButton ( )==MouseEvent .BUTTON1) {101102 // c h e c k i f C t r l w e r e p r e s s e d w h i l e c l i c k i n g on t h e command103 boolean ctrlDown = ( MouseEvent . getMouseModif iersText ( e .

g e tMod i f i e r s ( ) ) . indexOf ( ” Ctr l ” )>=0) ? true : f a l s e ;104105 // g e t commandID o f t h e command wh e r e t h e u s e r c l i c k e d106 long commandID = getCommanID( e . getPoint ( ) ) ;107108 // COMMAND CLICKED109 i f (commandID != −1){110111 // run t h r o u g h a l l t h e commands i n t h e t a b l e112 for ( int i = 0 ; i<=view . getTimeLineView ( ) .

getCommandTableView ( ) . getTable ( ) . getRowCount ( )−1; i++){

113114 // g e t command i d o f c u r r e n t row i n t a b l e115 long rowCommandID = Long . parseLong ( view .

getTimeLineView ( ) . getCommandTableView ( ). getTable ( ) . getValueAt ( i ,CommandAbstractTableModel . ID COLUMN) .toSt r ing ( ) ) ;

116 // c h e c k i f c u r r e n t command i d i s t h e samea s t h e c l i c k e d one

117 i f (commandID == rowCommandID){118119 // Chec k i f C t r l i s p r e s s e d w h i l e

t h e u s e r c l i c k s on t h e command120 i f ( ctrlDown ) {121 // C t r l p r e s s e d122123 // c h e c k i f command a l r e a d y

i s s e l e c t e d124 i f ( view . getTimeLineView ( ) .

getCommandTableView ( ) .getTable ( ) .i s C e l l S e l e c t e d ( i , 0) ) {

125 // a l r e a d y c h e c k e d126 view . getTimeLineView

( ) .getCommandTableView( ) . getTable ( ) .removeRowSelect ionInterval( i , i ) ;

127 } else {128 // NOT c h e c k e d

a l r e a d y129 view . getTimeLineView

( ) .getCommandTableView( ) . getTable ( ) .addRowSelect ionInterva l( i , i ) ;

130 }131 } else {132 // C t r l NOT p r e s s e d133 view . getTimeLineView ( ) .

getCommandTableView ( ) .getTable ( ) .s e tRowSe l e c t i on In te rva l( i , i ) ;

Page 301: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 291

134 }135 break ; // command f o u n d136 }137 }138139140 }141142 long c l i ckedPass ID = getPassID ( e . getPoint ( ) ) ;143 i f ( c l i ckedPass ID != −1 ) {144 // PASS CLICKED145146 i f ( ctrlDown && view . getSe lectedPass ID ( ) ==

cl i ckedPass ID ) {147 // C t r l down and a l r e a d y s e l e c t e d = d e s e l e c t148 view . se tSe l ec tedPass ID (−1) ;149150 } else {151 view . se tSe l ec tedPass ID ( c l i ckedPass ID ) ;152 }153154 boolean foundPass = f a l s e ;155 // run t h r o u g h a l l t h e p a s s e s i n t h e t a b l e t o f i n d

new one t o s e l e c t156 for ( int i = 0 ; i<=view . getTimeLineView ( ) .

getPassesTableView ( ) . getTable ( ) . getRowCount ( )−1; i++){

157 // g e t p a s s o f c u r r e n t row i n t a b l e158 long currentPassID = ( Long ) view .

getTimeLineView ( ) . getPassesTableView ( ) .getTable ( ) . getValueAt ( i ,PassesAbstractTableModel . ID COLUMN) ;

159 i f ( currentPassID == view . getSe lectedPass ID ( )) {

160 view . getTimeLineView ( ) .getPassesTableView ( ) . getTable ( ). s e tRowSe l e c t i on In t e rva l ( i , i ) ;

161 foundPass = true ;162 break ; // p a s s f o u n d163 }164165 }166167 i f ( ! foundPass ) { // i f new s e l e c t i o n n o t f o u n d i n

t a b l e , d e s e l e c t o l d s e l e c t i o n168 int selectedRow = view . getTimeLineView ( ) .

getPassesTableView ( ) . getTable ( ) .getSelectedRow () ;

169 i f ( selectedRow !=−1) {170 // s a v e s o l d v a l u e a s P a s s e s T a b l e

l i s t e n e r s w i l l s e ts e l e c t e d P a s s I D t o −1 whenr e m o v e R o w S e l e c t i o n I n t e r v a l i sc a l l e d .

171 long old = view . getSe lectedPass ID ( ) ;172 view . getTimeLineView ( ) .

getPassesTableView ( ) . getTable ( ). removeRowSelect ionInterval (selectedRow , selectedRow ) ;

173 view . se tSe l ec tedPass ID ( old ) ;174 }175 }176177 }178179 view . r epa in t ( ) ;180181 }182183 }184185 @Override186 public void mouseEntered ( MouseEvent e ) {187 // s e t c u r s o r t o hand when e n t e r i n g t i m e l i n e g r a p h i c s188 // v i e w . s e t C u r s o r ( new Cu r s o r ( Cu r s o r . CROSSHAIR CURSOR ) ) ;189 }190191 @Override192 public void mouseExited ( MouseEvent e ) {193 // r e s e t c u r s o r t o d e f a u l t194 view . setCursor (new Cursor ( Cursor .DEFAULT CURSOR) ) ;195 }196197 @Override198 public void mousePressed ( MouseEvent e ) {199 lastX = e . getX ( ) ;200

Page 302: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

292 Appendix C - Source Code

201 }202203 @Override204 public void mouseReleased ( MouseEvent e ) {205 maybeShowPopup( e ) ;206207 }208209 // Mo t i on210211 @Override212 public void mouseDragged ( MouseEvent e ) {213214215 i f ( ( e . g e tMod i f i e r s ( ) & InputEvent .BUTTON1 MASK)==InputEvent .

BUTTON1 MASK){216217 long s t a r t = view . getLineStartTime ( ) ;218 long end = view . getLineEndTime ( ) ;219220 long mousePos = e . getX ( ) ;221 long moveFactor = Math . abs ( mousePos−lastX ) ∗70000;222223 // Remove l i s t e n e r s f r om s p i n n e r s w h i l e d r a g g i n g t o a v o i d

c o n f u s i n g i n u p d a t e224 view . getTimeLineView ( ) . removeListenersFromSpinners ( ) ;225226227 // When t h e mouse i s d r a g g e d t h e t im e l i n e w i l l b e s h i f t e d228 i f ( lastX < e . getX ( ) ){229 view . setCursor (new Cursor ( Cursor .E RESIZE CURSOR) ) ;230 timeLineModel . s e t S t a r t ( s ta r t−moveFactor ) ;231 timeLineModel . setEnd ( end−moveFactor ) ;232 view . getTimeLineView ( ) . updateTimeLineEndAndStart (

s ta r t−moveFactor , end−moveFactor ) ;233 } else {234 view . setCursor (new Cursor ( Cursor .W RESIZE CURSOR) ) ;235 timeLineModel . s e t S t a r t ( s t a r t+moveFactor ) ;236 timeLineModel . setEnd ( end+moveFactor ) ;237 view . getTimeLineView ( ) . updateTimeLineEndAndStart (

s t a r t+moveFactor , end+moveFactor ) ;238 }239240 lastX = e . getX ( ) ;241242 view . r epa in t ( ) ;243244 // s e t t h e f i l t e r a g a i n245 view . getTimeLineView ( ) . newFi l ter ( ) ;246247 // add t h e l i s t e n e r s t o t h e s p i n n e r a g a i n248 view . getTimeLineView ( ) . addListenersToSpinners ( ) ;249250 view . getTimeLineView ( ) . resetToComboHeader ( ) ;251 }252 }253254 @Override255 public void mouseMoved( MouseEvent e ) {256257 // Cu r s o r c h a n g e s t o hand c u r s o r when c u r s o r i s o v e r a command

g r a p h i c a l l y258 long commandID = getCommanID( e . getPoint ( ) ) ;259 i f (commandID > −1) {260 view . setCursor (new Cursor ( Cursor .HAND CURSOR) ) ;261 } else i f ( getPassID ( e . getPoint ( ) ) != −1) {262 view . setCursor (new Cursor ( Cursor .HAND CURSOR) ) ;263 } else {264265 // T o o l k i t t o o l k i t = T o o l k i t . g e t D e f a u l t T o o l k i t ( ) ;266 // Image c u r s o r I m a g e = t o o l k i t . g e t I m a g e ( T imeL i n eG r a p h i cV i ew . c l a s s .

g e t R e s o u r c e ( ” g r a b . g i f ” ) ) ;267 // P o i n t c u r s o r H o t S p o t = new P o i n t ( 0 , 0 ) ;268 // Cu r s o r c u s t omCu r s o r = t o o l k i t . c r e a t e C u s t o m C u r s o r ( c u r s o r Im a g e ,

c u r s o r H o t S p o t , ” Cu r s o r ” ) ;269 // v i e w . s e t C u r s o r ( c u s t omCu r s o r ) ;270271272 view . setCursor (new Cursor ( Cursor .CROSSHAIR CURSOR) ) ;273274 }275276 }277278 /∗∗279 ∗ @param p o i n t o f t h e c u r s o r280 ∗ @r e t u r n −1 i f n o t o v e r a command , e l s e t h e command ID

Page 303: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 293

281 ∗/282 private long getCommanID( Point point ){283284 TimeLineModel timeLineModel= TimeLineModel . g e t In s tance ( ) ;285286 HashMap<Long , Command> commandMap = timeLineModel . getTimelineData ( ) .

getCommandMap( ) ;287 Command command ;288289 double commandPositionX ;290 double commandPositionY ;291292 // A dummy t im e o f e x e c u t i o n f o r commands w i t h ASAP e x e c u t i o n293 long dummyToE;294295 for ( Long id : commandMap . keySet ( ) ){296 command = commandMap . get ( id ) ;297 // Command i s ASAP298 i f ( view . getLineStartTime ( ) < command . getTimeOfExecution ( ) &&

view . getLineEndTime ( ) > command . getTimeOfExecution ( )| | command . getTimeOfExecution ( ) == −1){

299 i f (command . getTimeOfExecution ( ) == −1){300 // Command h a s no p a s s301 i f (command . getPassID ( ) == −1){302 dummyToE = timeLineModel .

getNextOpenPass ( ) . getStartTime( ) ;

303 } else { // Command h a s a p a s s304 dummyToE = timeLineModel .

getTimelineData ( ) . getPassMap ( ) .get (command . getPassID ( ) ) .getStartTime ( ) ;

305 }306 commandPositionX = view .

unixTimeToPixelOnTimeLine (dummyToE) ;307 commandPositionY = TimeLineGraphicView .

COMMAND ELEVATION;308 } else {309 commandPositionX = view .

unixTimeToPixelOnTimeLine (command .getTimeOfExecution ( ) ) ;

310 commandPositionY = TimeLineGraphicView .COMMAND ELEVATION;

311 }312313 double distanceX = commandPositionX−point . getX ( ) ;314 double distanceY = commandPositionY−point . getY ( ) ;315 double d i s tance = Math . sq r t ( distanceX∗distanceX +

distanceY∗distanceY ) ;316317 i f ( d i s tance <= TimeLineGraphicView .COMMAND SIZE/2){318319 long commandID = commandMap . get ( id ) .

getCommandID () ;320 return commandID ;321 }322 }323324325326 }327 return −1;328 }329330 /∗∗331 ∗ @param p o i n t o f t h e c u r s o r332 ∗ @r e t u r n −1 i f n o t o v e r a p a s s , e l s e t h e p a s s ID333 ∗/334 private long getPassID ( Point point ){335336 HashMap<Long , Pass> passMap = timeLineModel . getTimelineData ( ) .

getPassMap ( ) ;337 for ( Long id : passMap . keySet ( ) ){338 double passStartPos i t ionX = view . unixTimeToPixelOnTimeLine (

passMap . get ( id ) . getStartTime ( ) ) ;339 double passEndPositionX = view . unixTimeToPixelOnTimeLine (

passMap . get ( id ) . getEndTime ( ) ) ;340 double passPos it ionY = TimeLineGraphicView .LINEHIGHT−

TimeLineGraphicView .PASS ELEVATION;341342 i f ( po int . getX ( ) >= passStartPos i t ionX && point . getX ( ) <=

passEndPositionX ) {343 // i f b e t w e e n s t a r t and end on x−a x e s344 i f ( po int . getY ( ) >= passPosit ionY−(

TimeLineGraphicView .PASS THICKNESS/2)345 && point . getY ( ) <= passPos it ionY+(

TimeLineGraphicView .

Page 304: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

294 Appendix C - Source Code

PASS THICKNESS/2) ) {346 return id ;347 }348 }349 }350351 return −1;352 }353354 @Override355 public void act ionPerformed ( ActionEvent ae ) {356357 view . getTimeLineView ( ) . removeListenersFromSpinners ( ) ;358359 i f ( ae . getSource ( ) . equa l s ( view . getAllCommandsMenuItem () ) ) {360 timeLineModel . setTimeLineToAll ( ) ;361362 } else i f ( ae . getSource ( ) . equa l s ( view . getNowUntillLastMenuItem () ) ) {363 timeLineModel . setTimeLineToDefaultTimes ( ) ;364365 } else i f ( ae . getSource ( ) . equa l s ( view . getTodayMenuItem () ) ) {366 timeLineModel . setTimeLineToToday ( ) ;367368 } else i f ( ae . getSource ( ) . equa l s ( view . getTomorrowMenuItem () ) ) {369 timeLineModel . setTimeLineToTomorrow ( ) ;370371 } else i f ( ae . getSource ( ) . equa l s ( view . getNext24MenuItem () ) ) {372 timeLineModel . setTimeLineToNext24Hours ( ) ;373374 } else i f ( ae . getSource ( ) . equa l s ( view . getThisWeekMenuItem () ) ) {375 timeLineModel . setTimeLineToThisWeek ( ) ;376377 } else i f ( ae . getSource ( ) . equa l s ( view . getNextWeekMenuItem () ) ) {378 timeLineModel . setTimeLineToNextWeek ( ) ;379380 } else i f ( ae . getSource ( ) . equa l s ( view . getThisMonthMenuItem () ) ) {381 timeLineModel . setTimeLineToThisMonth ( ) ;382383 } else i f ( ae . getSource ( ) . equa l s ( view . getNextMonthMenuItem () ) ) {384 timeLineModel . setTimeLineToNextMonth ( ) ;385 }386 // u p d a t e t i m e l i n e v i e w s387388 view . getTimeLineView ( ) . updateTimeLineEndAndStart ( timeLineModel .

g e tS ta r t ( ) , timeLineModel . getEnd ( ) ) ;389 view . getTimeLineView ( ) . addListenersToSpinners ( ) ;390391392 }393394 /∗∗395 ∗ @param e396 ∗/397 private void maybeShowPopup( MouseEvent e ) {398 i f ( e . isPopupTrigger ( ) ) {399 view . getRightClickMenu ( ) . show ( e . getComponent ( ) ,400 e . getX ( ) , e . getY ( ) ) ;401 }402 }403404 }

Page 305: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 295

.1.82 TimeLineGraphicView.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Bas icStroke ;4 import java . awt . Color ;5 import java . awt . Dimension ;6 import java . awt . Graphics ;7 import java . awt . Graphics2D ;8 import java . awt . Point ;9 import java . awt . Shape ;

10 import java . awt . geom . El l ipse2D ;11 import java . awt . geom . Line2D ;12 import java . rmi . NotBoundException ;13 import java . rmi . RemoteException ;14 import java . text . SimpleDateFormat ;15 import java . u t i l . ArrayList ;16 import java . u t i l . Calendar ;17 import java . u t i l . GregorianCalendar ;18 import java . u t i l . HashMap ;1920 import javax . swing . BorderFactory ;21 import javax . swing . JMenuItem ;22 import javax . swing . JPanel ;23 import javax . swing . JPopupMenu ;24 import javax . swing . border . EtchedBorder ;2526 import mcc . s e rv e r . dataProcess ing . Pass ;27 import mps . MPSPreferences ;2829 import common . command .Command;3031 /∗∗32 ∗ <br><br>33 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 334 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 135 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 836 ∗/37 public c lass TimeLineGraphicView extends JPanel{3839 /∗∗40 ∗41 ∗/42 private stat ic f ina l long se r ia lVers ionUID = 1L ;43 public f ina l s tat ic int LINEHIGHT = 70;44 public f ina l s tat ic int LINELENGTH = 1200;45 private f ina l s tat ic double drawInterva l sFactor = 2 . 0 ;46 private f ina l s tat ic int LINESTART = 0;4748 /∗∗49 ∗50 ∗/51 private TimeLineView timeLineView ;52 /∗∗53 ∗54 ∗/55 private TimeLineModel timeLineModel = TimeLineModel . g e t In s tance ( ) ;5657 /∗∗58 ∗59 ∗/60 private TimeLineGraphicControl ler c o n t r o l l e r ;6162 /∗∗63 ∗64 ∗/65 private long l ineStartTime ;66 /∗∗67 ∗68 ∗/69 private long lineEndTime ;707172 /∗∗73 ∗74 ∗/75 private Point l i n e S t a r t = new Point (LINESTART, LINEHIGHT) ;76 /∗∗77 ∗78 ∗/79 private Point l ineEnd = new Point ( ( int ) l i n e S t a r t . getX ( ) +( int )LINELENGTH,

LINEHIGHT) ;8081 public f ina l s tat ic int COMMAND ELEVATION = (LINEHIGHT/2)−15;82 public f ina l s tat ic double COMMAND SIZE = 1 0 . 0 ;

Page 306: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

296 Appendix C - Source Code

83 public f ina l s tat ic int PASS ELEVATION = 10; // how many p i x e l s a b o v e t h et i m e l i n e t h a t t h e p a s s e s s h o u l d b e drawn

84 public f ina l s tat ic int PASS THICKNESS = 4 ; // how t h i c k t h e p a s s e s s h o u l db e drawn

8586 // Menu i t em f o r r i g h t c l i c k menu87 /∗∗88 ∗89 ∗/90 private JMenuItem allCommandsMenuItem ;91 /∗∗92 ∗93 ∗/94 private JMenuItem nowUntillLastMenuItem ;95 /∗∗96 ∗97 ∗/98 private JMenuItem todayMenuItem ;99 /∗∗

100 ∗101 ∗/102 private JMenuItem tomorrowMenuItem ;103 /∗∗104 ∗105 ∗/106 private JMenuItem next24MenuItem ;107 /∗∗108 ∗109 ∗/110 private JMenuItem thisWeekMenuItem ;111 /∗∗112 ∗113 ∗/114 private JMenuItem nextWeekMenuItem ;115 /∗∗116 ∗117 ∗/118 private JMenuItem thisMonthMenuItem ;119 /∗∗120 ∗121 ∗/122 private JMenuItem nextMonthMenuItem ;123 /∗∗124 ∗125 ∗/126 private JPopupMenu rightClickPopupMenu ;127128 /∗∗129 ∗130 ∗/131 private Graphics2D g2d ;132133 /∗∗134 ∗135 ∗/136 private long se l ec tedPass ID ;137138139 /∗∗140 ∗ @param t im e L i n eV i e w141 ∗/142 public TimeLineGraphicView ( TimeLineView timeLineView ) {143144 // VIEW − CONTROLLER145 this . timeLineView = timeLineView ;146 c o n t r o l l e r = new TimeLineGraphicControl ler ( this ) ;147148 // DATA149 l ineStartTime = timeLineModel . g e tS ta r t ( ) ;150 lineEndTime = timeLineModel . getEnd ( ) ;151152 this . setBorder ( BorderFactory . createEtchedBorder ( EtchedBorder .RAISED)

) ;153 this . setBackground ( Color . white ) ;154 this . s e t P r e f e r r e d S i z e (new Dimension (LINELENGTH,100) ) ;155156157 createRightClickMenu ( ) ;158159 // LISTENERS160 this . addMouseWheelListener ( c o n t r o l l e r ) ;161 this . addMouseListener ( c o n t r o l l e r ) ;162 this . addMouseMotionListener ( c o n t r o l l e r ) ;163164 }165166

Page 307: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 297

167168 /∗ ( non−J a v a d o c )169 ∗ @see j a v a x . s w i n g . JComponent#p a i n tC ompon e n t ( j a v a . aw t . G r a p h i c s )170 ∗/171 public void paintComponent ( Graphics g ){172173 super . paintComponent ( g ) ;174175 l ineStartTime = timeLineModel . g e tS ta r t ( ) ;176 lineEndTime = timeLineModel . getEnd ( ) ;177178 // Ca s t d r a w i n g t o o l t o 2D f o r e x t r a f u n c t i o n a l i t y179 g2d = ( Graphics2D ) g ;180181 // Main l i n e i n t im e182 Line2D l i n e = new Line2D . Double ( l i n eS ta r t , l ineEnd ) ;183 Line2D arrow1 = new Line2D . Double ( l ineEnd , new Point ( ( int ) l ineEnd . getX

( )−5, ( int ) l ineEnd . getY ( )−5)) ;184 Line2D arrow2 = new Line2D . Double ( l ineEnd , new Point ( ( int ) l ineEnd . getX

( )−5, ( int ) l ineEnd . getY ( ) +5) ) ;185 g2d . se tCo lor ( Color . b lack ) ;186 g2d . draw ( l i n e ) ;187 g2d . draw ( arrow1 ) ;188 g2d . draw ( arrow2 ) ;189190 // Draw l i n e s f r om commands t o p a s s e s191 i f ( timeLineView . getAllConnectionsCheckBox ( ) . i s S e l e c t e d ( ) ){192 drawAllLinesFromCommandsToPasses ( ) ;193 } else {194 i f ( timeLineView . getCommandsToPassCheckBox ( ) . i s S e l e c t e d ( ) ){195 drawLineFromSelectedCommandsToPasses ( ) ;196 }197 i f ( timeLineView . getPassToCommandsCheckBox ( ) . i s S e l e c t e d ( ) ){198 drawLineFromSelectedPassToCommands ( ) ;199 }200 }201202 // Draw o t h e r c ompon e n t s i n t h e c a n v a s203 drawCommands ( ) ;204 drawPasses ( ) ;205 drawTimeIntervals ( ) ;206 drawCurrentTime ( ) ;207208 }209210 /∗∗211 ∗ Re t u r n s t h e p i x e l number on t h e t im e l i n e , t h a t t h e g i v e n u n i x t im e

c omp l y t o212 ∗ @param un i xT ime i n m i l l i s e c o n d s213 ∗ @r e t u r n t h e p i x e l number on t h e t im e l i n e t h e u n i x t im e c omp l y t o214 ∗/215 public int unixTimeToPixelOnTimeLine ( long unixTime ){216 f loat mil iSecondsPerPixe l = ( f loat ) ( ( lineEndTime−l ineStartTime ) /

LINELENGTH) ; // i n m i l i s e c / p i x217 f loat mil iSecondsFromLineStart = ( f loat ) ( unixTime−l ineStartTime ) ; // i n

m i l i s e c218 f loat po s i t i on = mil iSecondsFromLineStart / mi l iSecondsPerPixe l ; // i n

p i x e l s219 int r e s u l t = Math . round ( po s i t i on ) ; // Round i n g t o g e t t h e p i x e l number

on t h e t im e l i n e220 // Adds t h e l i n e s s t a r t p o i n t t o p o s i t i o n t h e p i x e l c o r r e c t221 return r e s u l t + LINESTART;222 }223224 /∗225 ∗ Draw in g f e a t u r e s226 ∗/227228 /∗∗229 ∗ @th r ow s R emo t e E x c e p t i o n230 ∗ @th r ow s N o tB o u n dE x c e p t i o n231 ∗/232 public void drawCommands ( ) {233234 HashMap<Long , Command> commandMap = timeLineModel . getTimelineData ( ) .

getCommandMap( ) ;235 Command command ;236237 for ( Long id : commandMap . keySet ( ) ){238 command = commandMap . get ( id ) ;239 i f (command . getTimeOfExecution ( )>=lineStartTime && command .

getTimeOfExecution ( ) <= lineEndTime | | command .getTimeOfExecution ( )==−1){

240 drawCommand(command) ;241 }242 }243 }

Page 308: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

298 Appendix C - Source Code

244245246 /∗∗247 ∗ @param command248 ∗/249 private void drawCommand(Command command){250251 long drawToE ;252 // Command i s ASAP253 i f (command . getTimeOfExecution ( ) == −1){254 // Command h a s no p a s s a s s i g n e d255 i f (command . getPassID ( ) == −1){256 drawToE = timeLineModel . getNextOpenPass ( ) .

getStartTime ( ) ;257 } else { // Command h a s a p a s s a s s i g n e d258 Pass pass = timeLineModel . getTimelineData ( ) .

lookupPass (command . getPassID ( ) ) ;259 drawToE = pass . getStartTime ( ) ;260 }261262 } else { // Command i s NOT ASAP263 drawToE = command . getTimeOfExecution ( ) ;264 }265266 El l ipse2D c i r c l e = new El l ipse2D . Double (267 l i n e S t a r t . getX ( )+unixTimeToPixelOnTimeLine (drawToE

)−(COMMAND SIZE/2) // x−c o o r d i n a t e ( t o p )268 , COMMAND ELEVATION−(COMMAND SIZE/2) // y−c o o r d i n a t e

( t o p )269 , COMMAND SIZE // E l l i p s e h e i g h t270 , COMMAND SIZE) ; // E l l i p s e w i d t h271272 g2d . se tCo lo r ( Color .BLACK) ;273 g2d . draw ( c i r c l e ) ;274 i f ( timeLineView . getCommandTableView ( ) . isCommandSelected (command .

getCommandID () ) ) {275 g2d . s e tCo lor ( Color .BLUE) ;276 } else {277 g2d . s e tCo lor ( MPSPreferences . getStateCo lor (command . ge tState ( )

) ) ;278 }279280281 g2d . f i l l ( c i r c l e ) ;282 }283284 /∗∗285 ∗286 ∗/287 public void drawPasses ( ) {288 ArrayList<Pass> passe s ;289290 passe s = TimeLineModel . getOpenPasses ( ) ;291 // Draw e v e r y op en p a s s292 for ( Pass pass : pas se s ){293 // On l y p a s s e s t h a t a r e w i t h i n t h e c u r r e n t t im e s p an s h o u l d

b e drawn294 i f ( pass . getEndTime ( )>=lineStartTime && pass . getStartTime ( )<=

lineEndTime ){295 // i f p a s s i s s e l e c t e d i n t h e t a b l e i t s h o u l d b e b l u e ,

e l s e b l a c k296297 i f ( se l ec tedPass ID==pass . getPassID ( ) ) {298 g2d . se tCo lo r ( Color .BLUE) ;299 } else {300 g2d . se tCo lor ( Color .BLACK) ;301 }302303 Point s t a r tPo in t = new Point ( ( int ) l i n e S t a r t . getX ( )+

unixTimeToPixelOnTimeLine ( pass . getStartTime ( ) ) ,LINEHIGHT−PASS ELEVATION) ;

304 Point endPoint = new Point ( ( int ) l i n e S t a r t . getX ( )+unixTimeToPixelOnTimeLine ( pass . getEndTime ( ) ) ,LINEHIGHT−PASS ELEVATION) ;

305 Line2D . Double passGraphic = new Line2D . Double (s tar tPo int , endPoint ) ;

306 g2d . s e tS t roke (new Bas icStroke (PASS THICKNESS) ) ;307 g2d . draw ( passGraphic ) ; // draw308 g2d . s e tS t roke (new Bas icStroke (1) ) ;309 }310 }311 }312313 /∗∗314 ∗315 ∗/316 public void drawCurrentTime ( ) {

Page 309: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 299

317318 int x =( int ) unixTimeToPixelOnTimeLine ( TimeLineModel .

getCurrentTimeInMi l l i s ( ) ) ;319320 Point s t a r tPo in t = new Point (x ,LINEHIGHT−10) ;321 Point endPoint = new Point (x ,LINEHIGHT+10) ;322323 Line2D currentTime = new Line2D . Double ( s tar tPo int , endPoint ) ;324325 g2d . se tCo lo r ( Color .RED) ;326 g2d . s e tS t roke (new Bas icStroke (2) ) ;327 g2d . draw ( currentTime ) ;328 g2d . s e tS t roke (new Bas icStroke (1) ) ;329 }330331 /∗332 ∗ Draw t h e t im e i n t e r v a l s333 ∗/334335336 /∗∗337 ∗338 ∗/339 public void drawTimeIntervals ( ) {340 g2d . se tCo lo r ( Color .BLACK) ;341 long timeLength = ( lineEndTime−l ineStartTime ) ;342343 // D i f f e r e n t l e n g t h o f t h e t im e l i n e i n v o k e s d i f f e r e n t p a i n t i n g o f t h e

t im e344 i f ( timeLength < (60∗1000∗ drawInterva l sFactor ) ){345 drawSeconds ( f a l s e ) ;346 drawMinutes ( true ) ;347 } else i f ( timeLength < (60∗60∗1000∗ drawInterva l sFactor ) ){348 drawMinutes ( f a l s e ) ;349 drawHours ( true ) ;350 } else i f ( timeLength < (60∗60∗24∗1000∗ drawInterva l sFactor ) ){351 drawHours ( f a l s e ) ;352 drawDays ( true ) ;353 } else i f ( timeLength < 2678400000L∗drawInterva l sFactor ){ //

( 6 0∗ 6 0∗ 2 4∗ 3 1∗ 1 0 0 0 )354 drawDays ( f a l s e ) ;355 drawMonths ( true ) ;356 } else i f ( timeLength < 31536000000L∗drawInterva l sFactor ){ //

( 6 0∗ 6 0∗ 2 4∗ 3 6 5∗ 1 0 0 0 )357 drawMonths ( f a l s e ) ;358 drawYears ( true ) ;359 } else {360 drawYears ( f a l s e ) ;361 }362363 }364365366 /∗∗367 ∗ @param i s B i g L i n e s368 ∗/369 private void drawSeconds (boolean i sB i gL ine s ) {370371 GregorianCalendar ca l = timeLineModel . getStartAsCalendar ( ) ;372 ca l . s e t ( Calendar .MILLISECOND, 0) ;373 long o f f s e t = ca l . ge tTimeInMi l l i s ( ) ;374375 for ( long i = o f f s e t ; i<lineEndTime ; i = ( i +(1∗1000) ) ){376 drawInterva l s ( i , i sB i gL ine s ) ;377 }378 }379380381 /∗∗382 ∗ @param i s B i g L i n e s383 ∗/384 private void drawMinutes (boolean i sB i gL ine s ) {385386 GregorianCalendar ca l = timeLineModel . getStartAsCalendar ( ) ;387 ca l . s e t ( Calendar .MILLISECOND, 0) ;388 ca l . s e t ( Calendar .SECOND, 0) ;389 long o f f s e t = ca l . ge tTimeInMi l l i s ( ) ;390391 int pushdown ;392 pushdown = ( i sB igL ine s ) ? −20 : 25 ;393 int pushr ight ;394 pushr ight = ( i sB igL ine s ) ? −12 : −7;395396 for ( long i = o f f s e t ; i<lineEndTime ; i= ( i +(60∗1000) ) ){397 drawInterva l s ( i , i sB i gL ine s ) ;398 char [ ] time ;399 i f ( i sB igL ine s ){

Page 310: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

300 Appendix C - Source Code

400 time = new SimpleDateFormat ( ”mm: s s ” ) . format ( i ) .toCharArray ( ) ;

401 } else {402 time = new SimpleDateFormat ( ”mm” ) . format ( i ) .

toCharArray ( ) ;403 }404 g2d . drawChars ( time , 0 , time . length ,

unixTimeToPixelOnTimeLine ( i )−pushright , LINEHIGHT+pushdown ) ;

405 }406 }407408409 /∗∗410 ∗ @param i s B i g L i n e s411 ∗/412 private void drawHours (boolean i sB i gL ine s ) {413414 GregorianCalendar ca l = timeLineModel . getStartAsCalendar ( ) ;415 ca l . s e t ( Calendar .MILLISECOND, 0) ;416 ca l . s e t ( Calendar .SECOND, 0) ;417 ca l . s e t ( Calendar .MINUTE, 0) ;418 long o f f s e t = ca l . ge tTimeInMi l l i s ( ) ;419420 int pushdown ;421 pushdown = ( i sB igL ine s ) ? −20 : 25 ;422 int pushr ight ;423 pushr ight = ( i sB igL ine s ) ? −12 : −7;424425 for ( long i = o f f s e t ; i<lineEndTime ; i= ( i +(3600∗1000) ) ){426 drawInterva l s ( i , i sB i gL ine s ) ;427 char [ ] time ;428 i f ( i sB igL ine s ){429 time = new SimpleDateFormat ( ”HH:mm” ) . format ( i ) .

toCharArray ( ) ;430 } else {431 time = new SimpleDateFormat ( ”HH” ) . format ( i ) .

toCharArray ( ) ;432 }433 g2d . drawChars ( time , 0 , time . length ,

unixTimeToPixelOnTimeLine ( i )+pushright , LINEHIGHT+pushdown ) ;

434 }435 }436437 /∗∗438 ∗ @param i s B i g L i n e s439 ∗/440 private void drawDays (boolean i sB i gL ine s ) {441442 GregorianCalendar ca l = timeLineModel . getStartAsCalendar ( ) ;443 ca l . s e t ( Calendar .MILLISECOND, 0) ;444 ca l . s e t ( Calendar .SECOND, 0) ;445 ca l . s e t ( Calendar .MINUTE, 0) ;446 ca l . s e t ( Calendar .HOUR OF DAY, 0) ;447 long o f f s e t = ca l . ge tTimeInMi l l i s ( ) ;448449 int pushdown ;450 pushdown = ( i sB igL ine s ) ? −20 : 25 ;451 int pushr ight ;452 pushr ight = ( i sB igL ine s ) ? −12 : −7;453454455 for ( long i = o f f s e t ; i<lineEndTime ; i= ( i +(3600∗24∗1000) ) ){456 drawInterva l s ( i , i sB i gL ine s ) ;457 char [ ] time ;458 i f ( i sB igL ine s ){459 time = new SimpleDateFormat ( ”dd/MM” ) . format ( i ) .

toCharArray ( ) ;460 } else {461 time = new SimpleDateFormat ( ”dd” ) . format ( i ) .

toCharArray ( ) ;462 }463 g2d . drawChars ( time , 0 , time . length ,

unixTimeToPixelOnTimeLine ( i )+pushright , LINEHIGHT+pushdown ) ;

464 }465 }466467468 /∗∗469 ∗ @param i s B i g L i n e s470 ∗/471 private void drawMonths (boolean i sB i gL ine s ) {472473 GregorianCalendar ca l = timeLineModel . getStartAsCalendar ( ) ;474 ca l . s e t ( Calendar .MILLISECOND, 0) ;

Page 311: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 301

475 ca l . s e t ( Calendar .SECOND, 0) ;476 ca l . s e t ( Calendar .MINUTE, 0) ;477 ca l . s e t ( Calendar .HOUR OF DAY, 0) ;478 ca l . s e t ( Calendar .DATE, 1) ;479 long o f f s e t = ca l . ge tTimeInMi l l i s ( ) ;480481 int monthNumber = ca l . get ( Calendar .MONTH) +1;482 long mil l iSecondsInMonth = getMil l iSecondsInMonth (monthNumber) ;483484 int pushdown ;485 pushdown = ( i sB igL ine s ) ? −20 : 25 ;486 int pushr ight ;487 pushr ight = ( i sB igL ine s ) ? −12 : −7;488489 for ( long i = o f f s e t ; i<lineEndTime ; i= ( i +(mil l iSecondsInMonth ) ) ){

// I n t e r v a l i s d i f f e r e n t f o r d i f f e r e n t mon t h s490 drawInterva l s ( i , i sB i gL ine s ) ;491 char [ ] time ;492 i f ( i sB igL ine s ){493 time = new SimpleDateFormat ( ”MM/yyyy” ) . format ( i ) .

toCharArray ( ) ;494 } else {495 time = new SimpleDateFormat ( ”MM” ) . format ( i ) .

toCharArray ( ) ;496 }497 g2d . drawChars ( time , 0 , time . length ,

unixTimeToPixelOnTimeLine ( i )+pushright , LINEHIGHT+pushdown ) ;

498 }499 }500501502 /∗∗503 ∗ @param i s B i g L i n e s504 ∗/505 private void drawYears (boolean i sB i gL ine s ) {506507 GregorianCalendar ca l = timeLineModel . getStartAsCalendar ( ) ;508 ca l . s e t ( Calendar .MILLISECOND, 0) ;509 ca l . s e t ( Calendar .SECOND, 0) ;510 ca l . s e t ( Calendar .MINUTE, 0) ;511 ca l . s e t ( Calendar .HOUR OF DAY, 0) ;512 ca l . s e t ( Calendar .DATE, 1) ;513 ca l . s e t ( Calendar .MONTH, 0) ;514 long o f f s e t = ca l . ge tTimeInMi l l i s ( ) ;515516 long mil l iSeconds InYear ;517 i f ( c a l . isLeapYear ( ca l . get ( Calendar .YEAR) ) ){518 mi l l iSeconds InYear = 31622400000L ; // 366 d a y s i n y e a r

( 3 6 6∗ 2 4∗ 6 0∗ 6 0∗ 1 0 0 0 )519 } else mil l iSeconds InYear = 31536000000L ; // 365 d a y s i n y e a r

( 3 6 5∗ 2 4∗ 6 0∗ 6 0∗ 1 0 0 0 )520521 int pushdown ;522 pushdown = ( i sB igL ine s ) ? −20 : 25 ;523 int pushr ight ;524 pushr ight = ( i sB igL ine s ) ? −12 : −7;525526 for ( long i = o f f s e t ; i<lineEndTime ; i= ( i +(mi l l iSeconds InYear ) ) ){

// I n t e r v a l i s d i f f e r e n t f o r d i f f e r e n t y e a r s527 drawInterva l s ( i , i sB i gL ine s ) ;528 char [ ] time ;529 i f ( i sB igL ine s ){530 time = new SimpleDateFormat ( ”yyyy” ) . format ( i ) .

toCharArray ( ) ;531 } else {532 time = new SimpleDateFormat ( ”yyyy” ) . format ( i ) .

toCharArray ( ) ;533 }534 g2d . drawChars ( time , 0 , time . length ,

unixTimeToPixelOnTimeLine ( i )+pushright , LINEHIGHT+pushdown ) ;

535 }536 }537538 /∗∗539 ∗ @param monthNumber540 ∗ @r e t u r n t h e m i l l i s e c o n d s i n t h e g i v e n month541 ∗/542 private long getMil l iSecondsInMonth ( int monthNumber) {543544 long mil l iSecondsInFebruary ;545 GregorianCalendar ca l = timeLineModel . getStartAsCalendar ( ) ;546 i f ( c a l . isLeapYear ( ca l . get ( Calendar .YEAR) ) ){547 mi l l iSecondsInFebruary = 2505600000L ; // 29 d a y s i n month

( 2 9∗ 2 4∗ 6 0∗ 6 0∗ 1 0 0 0 )

Page 312: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

302 Appendix C - Source Code

548 } else mil l iSecondsInFebruary = 2419200000L ; // 28 d a y s i n month( 2 8∗ 2 4∗ 6 0∗ 6 0∗ 1 0 0 0 )

549550 switch (monthNumber) {551 case 1 : return 2678400000L ; // 31 d a y s i n month

( 3 1∗ 2 4∗ 6 0∗ 6 0∗ 1 0 0 0 )552 case 2 : return mil l iSecondsInFebruary ;553 case 3 : return 2678400000L ;554 case 4 : return 2592000000L ; // 30 d a y s i n month

( 3 0∗ 2 4∗ 6 0∗ 6 0∗ 1 0 0 0 )555 case 5 : return 2678400000L ;556 case 6 : return 2592000000L ;557 case 7 : return 2678400000L ;558 case 8 : return 2678400000L ;559 case 9 : return 2592000000L ;560 case 10 : return 2678400000L ;561 case 11 : return 2592000000L ;562 case 12 : return 2678400000L ;563564 default : throw new I l l ega lArgumentExcept ion ( ) ;565566 }567568 }569570 /∗∗571 ∗ @param i572 ∗ @param i s B i g L i n e s573 ∗/574 private void drawInterva l s ( long i , boolean i sB i gL ine s ){575576 i f ( i<lineEndTime ){577 int po s i t i on = ( int ) l i n e S t a r t . getX ( ) +

unixTimeToPixelOnTimeLine ( i ) ;578579 Point s ta r tPo in t = new Point ( pos i t i on ,LINEHIGHT−5) ;580 Point endPoint = new Point ( pos i t i on ,LINEHIGHT+5) ;581582 i f ( i sB igL ine s ){583 s ta r tPo in t = new Point ( pos i t i on ,LINEHIGHT−15) ;584 endPoint = new Point ( pos i t i on ,LINEHIGHT+15) ;585 }586587 Shape t ime In t e rva l = new Line2D . Double ( s tar tPo int , endPoint )

;588589 g2d . draw ( t ime In t e rva l ) ;590 }591592 }593594 /∗595 ∗ LINES FROM COMMANDS TO PASSES METHODS596 ∗/597598599 /∗∗600 ∗ Draws a l i n e f r om e v e r y command b e i n g t r a n s m i t t e d w i t h a p a s s i n t h e

f u t u r e601 ∗/602 public void drawAllLinesFromCommandsToPasses ( ) {603 HashMap<Long , Pass> passMap = timeLineModel . getTimelineData ( ) .

getPassMap ( ) ;604 for ( Long id : passMap . keySet ( ) ){605 Pass pass = passMap . get ( id ) ;606 i f ( pass . s i z e ( ) >0){607 for ( int i = 0 ; i<pass . s i z e ( ) ; i++){608 Command command = timeLineModel .

getTimelineData ( ) . getCommandMap( ) . get (pass . getCommand( i ) ) ;

609 drawLineFromCommandToPass (command , pass ) ;610 }611 }612 }613 }614615 /∗∗616 ∗ Draw l i n e s f r om a l l s e l e c t e d commands i n t h e command t a b l e t o t h e p a s s

t r a n s m i t t i n g i t617 ∗/618 public void drawLineFromSelectedCommandsToPasses ( ) {619 ArrayList<Command> commands = timeLineView . getCommandTableView ( ) .

getSelectedCommands ( ) ;620 i f ( commands != null ){621 for (Command command : commands){622 i f (command . getPassID ( ) !=−1){

Page 313: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 303

623 Pass pass = TimeLineModel . g e t In s tance ( ) .getTimelineData ( ) . getPassMap ( ) . get (command . getPassID ( ) ) ;

624 drawLineFromCommandToPass (command , pass ) ;625 }626627 }628 }629 }630631 /∗∗632 ∗ Draw l i n e s f r om t h e s e l e c t e d p a s s t o commands t r a n s m i t t e d w i t h t h i s p a s s633 ∗/634 public void drawLineFromSelectedPassToCommands ( ) {635 i f ( se l ec tedPass ID != −1){636 Pass pass = TimeLineModel . g e t In s tance ( ) . getTimelineData ( ) .

lookupPass ( se l ec tedPass ID ) ;637 for ( int i = 0 ; i<pass . s i z e ( ) ; i++){638 Command command = TimeLineModel . g e t In s tance ( ) .

getTimelineData ( ) . getCommandMap( ) . get ( pass .getCommand( i ) ) ;

639 drawLineFromCommandToPass (command , pass ) ;640 }641 }642 }643644 /∗∗645 ∗ Draws a l i n e f r om t h e g i v e n command t o t h e g i v e n p a s s646 ∗ @param command The command t o b e drawn f r om647 ∗ @param p a s s The p a s s t o b e drawn t o648 ∗/649 public void drawLineFromCommandToPass (Command command , Pass pass ){650 Point commandPoint ;651 Point passPoint ;652653 long passMiddle = ( pass . getEndTime ( )+pass . getStartTime ( ) ) /2 ;654655 // Command i s f l o a t i n g656 i f (command . getTimeOfExecution ( ) == −1){657 // The command p o i n t i s s e t t o i t s p a s s s t a r t t im e658 commandPoint = new Point ( unixTimeToPixelOnTimeLine (659 timeLineModel . getTimelineData ( ) . lookupPass (

command . getPassID ( ) ) . getStartTime ( ) ) ,COMMAND ELEVATION) ;

660 } else { // Command h a s a ToE661 commandPoint = new Point ( unixTimeToPixelOnTimeLine (command .

getTimeOfExecution ( ) ) , COMMAND ELEVATION) ;662 }663664 passPoint = new Point ( unixTimeToPixelOnTimeLine ( passMiddle ) ,

LINEHIGHT − PASS ELEVATION) ;665666 Line2D l i n e = new Line2D . Double ( commandPoint , passPoint ) ;667 g2d . se tCo lo r ( Color .BLACK) ;668 i f ( pass . getPassID ( ) == se lec tedPass ID ){669 g2d . s e tCo lor ( Color .BLUE) ;670 }671 i f ( timeLineView . getCommandTableView ( ) . getSelectedCommands ( ) != null )

{672 i f ( timeLineView . getCommandTableView ( ) . getSelectedCommands ( ) .

conta ins (command) ){673 g2d . se tCo lo r ( Color .BLUE) ;674 }675 }676677678 g2d . draw ( l i n e ) ;679 }680681682 /∗∗683 ∗684 ∗/685 private void createRightClickMenu ( ) {686 rightClickPopupMenu = new JPopupMenu ( ) ;687688 nowUntillLastMenuItem = new JMenuItem( ”Now u n t i l l a s t command” ) ;689 nowUntillLastMenuItem . addAct ionListener ( c o n t r o l l e r ) ;690 rightClickPopupMenu . add ( nowUntillLastMenuItem ) ;691692 allCommandsMenuItem = new JMenuItem( ” F i r s t u n t i l l a s t command” ) ;693 allCommandsMenuItem . addAct ionListener ( c o n t r o l l e r ) ;694 rightClickPopupMenu . add ( allCommandsMenuItem ) ;695696 todayMenuItem = new JMenuItem( ”Today” ) ;697 todayMenuItem . addAct ionListener ( c o n t r o l l e r ) ;698 rightClickPopupMenu . add ( todayMenuItem ) ;

Page 314: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

304 Appendix C - Source Code

699700 tomorrowMenuItem = new JMenuItem( ”Tomorrow” ) ;701 tomorrowMenuItem . addAct ionListener ( c o n t r o l l e r ) ;702 rightClickPopupMenu . add ( tomorrowMenuItem ) ;703704 next24MenuItem = new JMenuItem( ”Next 24 hours ” ) ;705 next24MenuItem . addAct ionListener ( c o n t r o l l e r ) ;706 rightClickPopupMenu . add ( next24MenuItem ) ;707708 thisWeekMenuItem = new JMenuItem( ”This week” ) ;709 thisWeekMenuItem . addAct ionListener ( c o n t r o l l e r ) ;710 rightClickPopupMenu . add ( thisWeekMenuItem ) ;711712 nextWeekMenuItem = new JMenuItem( ”Next week” ) ;713 nextWeekMenuItem . addAct ionListener ( c o n t r o l l e r ) ;714 rightClickPopupMenu . add ( nextWeekMenuItem ) ;715716 thisMonthMenuItem = new JMenuItem( ”This month” ) ;717 thisMonthMenuItem . addAct ionListener ( c o n t r o l l e r ) ;718 rightClickPopupMenu . add ( thisMonthMenuItem ) ;719720 nextMonthMenuItem = new JMenuItem( ”Next month” ) ;721 nextMonthMenuItem . addAct ionListener ( c o n t r o l l e r ) ;722 rightClickPopupMenu . add ( nextMonthMenuItem ) ;723724 }725726 /∗∗727 ∗ @r e t u r n728 ∗/729 public JPopupMenu getRightClickMenu ( ) {730731 return rightClickPopupMenu ;732 }733734735 /∗736 ∗ G e t t e r s737 ∗/738739 /∗∗740 ∗ @r e t u r n741 ∗/742 public TimeLineView getTimeLineView ( ) {743 return timeLineView ;744 }745746747 /∗∗748 ∗ @r e t u r n749 ∗/750 public long getLineStartTime ( ) {751 return l ineStartTime ;752 }753754755 /∗∗756 ∗ @r e t u r n757 ∗/758 public long getLineEndTime ( ) {759 return lineEndTime ;760 }761762 /∗∗763 ∗ @r e t u r n764 ∗/765 public JMenuItem getAllCommandsMenuItem () {766 return allCommandsMenuItem ;767 }768769770 /∗∗771 ∗ @r e t u r n772 ∗/773 public JMenuItem getNowUntillLastMenuItem () {774 return nowUntillLastMenuItem ;775 }776777778 /∗∗779 ∗ @r e t u r n780 ∗/781 public JMenuItem getTodayMenuItem () {782 return todayMenuItem ;783 }784785

Page 315: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 305

786 /∗∗787 ∗ @r e t u r n788 ∗/789 public JMenuItem getTomorrowMenuItem () {790 return tomorrowMenuItem ;791 }792793794 /∗∗795 ∗ @r e t u r n796 ∗/797 public JMenuItem getNext24MenuItem () {798 return next24MenuItem ;799 }800801802 /∗∗803 ∗ @r e t u r n804 ∗/805 public JMenuItem getThisWeekMenuItem () {806 return thisWeekMenuItem ;807 }808809810 /∗∗811 ∗ @r e t u r n812 ∗/813 public JMenuItem getNextWeekMenuItem () {814 return nextWeekMenuItem ;815 }816817818 /∗∗819 ∗ @r e t u r n820 ∗/821 public JMenuItem getThisMonthMenuItem () {822 return thisMonthMenuItem ;823 }824825826 /∗∗827 ∗ @r e t u r n828 ∗/829 public JMenuItem getNextMonthMenuItem () {830 return nextMonthMenuItem ;831 }832833834835 /∗∗836 ∗ @param s e l e c t e d P a s s I D837 ∗/838 public void se tSe l ec tedPass ID ( long se l ec tedPass ID ) {839 this . s e l ec tedPass ID = se lec tedPass ID ;840 }841842843844 /∗∗845 ∗ @r e t u r n846 ∗/847 public long getSe lectedPass ID ( ) {848 return se l ec tedPass ID ;849 }850851852 }

Page 316: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

306 Appendix C - Source Code

.1.83 TimeLineModel.java

1 package mps . gui . t ime l i n e ;23 import java . i o . F i l e ;4 import java . rmi . NotBoundException ;5 import java . rmi . RemoteException ;6 import java . text . SimpleDateFormat ;7 import java . u t i l . ArrayList ;8 import java . u t i l . Calendar ;9 import java . u t i l . Co l l e c t i o n s ;

10 import java . u t i l . GregorianCalendar ;11 import java . u t i l . HashMap ;1213 import mcc . s e rv e r . dataProcess ing . CommandBlock ;14 import mcc . s e rv e r . dataProcess ing . GroundStation ;15 import mcc . s e rv e r . dataProcess ing . Pass ;16 import mcc . s e rv e r . dataProcess ing . Timeline ;17 import mps . MPSPreferences ;18 import mps . gui . commanding . block . save load . PredefinedCommandBlocksSaveObject ;19 import mps . rmi . C l i ent ;2021 import org . simpleframework . xml . S e r i a l i z e r ;22 import org . simpleframework . xml . load . P e r s i s t e r ;2324 import common . command .Command;25 import common . command .CommandType ;26 import common . command . DTUsat2Command ;27 import common . command . DTUsat2CommandTypeMap ;28 import common . command . parameter . DoubleParameter ;29 import common . command . parameter . IntParameter ;30 import common . command . parameter . Parameter ;3132 /∗∗33 ∗ Th i s mod e l c l a s s c o n t a i n s d a t a and me t h o d s c o n c e r n i n g t h e t i m e l i n e : commands and

p a s s e s .34 ∗ <br><br>35 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 336 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 137 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 838 ∗/39 /∗∗40 ∗ @au t h o r Ma l a e u s41 ∗42 ∗/43 public c lass TimeLineModel {444546 /∗∗47 ∗48 ∗/49 private long s t a r t = 100;50 /∗∗51 ∗52 ∗/53 private long end = 500;54 /∗∗55 ∗56 ∗/57 private stat ic boolean passMode ;58 /∗∗59 ∗60 ∗/61 private stat ic boolean emergencyMode ;6263 /∗∗64 ∗65 ∗/66 private stat ic Timeline t imel ineData ;67 /∗∗68 ∗69 ∗/70 private ArrayList<GroundStation> groundStat ions ;7172 /∗∗73 ∗74 ∗/75 private PredefinedCommandBlocksSaveObject predefinedCommandBlocksSaveObject ;767778 /∗∗79 ∗80 ∗/81 private stat ic vo lat i l e TimeLineModel INSTANCE;8283 /∗∗

Page 317: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 307

84 ∗85 ∗/86 protected TimeLineModel ( ) {87 try {88 loadPredefinedCommandBlocksSaveObject ( ) ;89 } catch ( Exception e ) {90 // TODO Auto−g e n e r a t e d c a t c h b l o c k91 e . pr intStackTrace ( ) ;92 }93 }9495 /∗∗96 ∗ @r e t u r n97 ∗/98 public stat ic TimeLineModel ge t In s tance ( ) {99 i f (INSTANCE == null ) {

100 synchronized ( TimeLineModel . c lass ) {101 i f (INSTANCE == null ) {102 INSTANCE = new TimeLineModel ( ) ;103 }104 }105 }106 return INSTANCE;107 }108109 /∗∗110 ∗ @th r ow s E x c e p t i o n111 ∗/112 private void loadPredefinedCommandBlocksSaveObject ( ) throws Exception {113114 F i l e f i l e = new F i l e ( MPSPreferences . getPredefinedCommandBlocksPath ( ) ) ;115116 i f ( ! f i l e . e x i s t s ( ) ) {117 // f i l e d o e s n ’ t e x i s t , c r e a t e new118 predefinedCommandBlocksSaveObject = new

PredefinedCommandBlocksSaveObject ( ) ;119 } else {120 S e r i a l i z e r s e r i a l i z e r = new P e r s i s t e r ( ) ;121 predefinedCommandBlocksSaveObject = s e r i a l i z e r . read (

PredefinedCommandBlocksSaveObject . class , f i l e ) ;122 // p r e d e f i n e d C o m m a n d B l o c k s S a v e O b j e c t = l o a d e d O b j e c t .

g e t P r eD e f i n e dC omman dB l o c k s ( ) ;123124 }125126127 }128129 /∗∗130 ∗ @param s a v e O b j e c t131 ∗ @th r ow s E x c e p t i o n132 ∗/133 public void savePredefinedCommandBlocksFile ( PredefinedCommandBlocksSaveObject

saveObject ) throws Exception {134135 F i l e f i l e = new F i l e ( MPSPreferences . getPredefinedCommandBlocksPath ( ) ) ;136 i f ( f i l e . e x i s t s ( ) ) f i l e . d e l e t e ( ) ; // o v e r w r i t e137 S e r i a l i z e r s e r i a l i z e r = new P e r s i s t e r ( ) ;138 s e r i a l i z e r . wr i te ( saveObject , f i l e ) ;139 }140141 /∗∗142 ∗ @th r ow s R emo t e E x c e p t i o n143 ∗ @th r ow s N o tB o u n dE x c e p t i o n144 ∗/145 public void loadDataFromDB () throws RemoteException , NotBoundException {146 t imel ineData = Cl i ent . g e t In s tance ( ) . ge tMin ima l Inte r face ( ) .

getTimel ine (−2, Long .MAX VALUE, true ) ;147 // t i m e l i n e D a t a = C l i e n t . g e t I n s t a n c e ( ) . g e t M i n i m a l I n t e r f a c e ( ) .

g e t C u r r e n t T i m e l i n e ( ) ;148 groundStat ions = Cl i ent . g e t In s tance ( ) . ge tMin ima l Inte r face ( ) .

getGroundStations ( ) ;149 passMode = Cl i ent . ge t In s tance ( ) . ge tMin ima l Inte r face ( ) . getPassMode ( ) ;150 emergencyMode = Cl i ent . ge t In s tance ( ) . ge tMin ima l Inte r face ( ) .

getEmergencyMode ( ) ;151152 }153154 /∗∗155 ∗ Ge t s t h e c u r r e n t t im e i n m i l l i s e c o n d s .156 ∗ @r e t u r n The c u r r e n t t im e i n m i l l i s e c o n d s .157 ∗158 ∗/159 public stat ic long getCurrentTimeInMi l l i s ( ) {160 return System . currentTimeMi l l i s ( ) ;161 }162

Page 318: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

308 Appendix C - Source Code

163 public Str ing getHtmlPrettyPrint ( long commandID) {164 DTUsat2Command command = (DTUsat2Command) t imel ineData . lookupCommand(

commandID) ;165 CommandType type = DTUsat2CommandTypeMap . ge t In s tance ( ) .

getCommandType(command . getCommandTypeID ( ) ) ;166167 St r ing txt = ”<html><table>” +168 ”<tr><td>ID:</td><td><b>” + commandID + ”</b></td></tr>” +169 ”<tr><td>Type:</td><td>” + type . getTypeID ( ) + ”</td></tr>” +170 ”<tr><td va l i gn=top>Name:</td><td width=350><b>” + type .

getName ( ) + ”</b><br>” + type . g e tDesc r ip t i on ( ) + ”</td></tr>” +

171 ”<tr><td>ModuleID:</td><td><b>” + command . getModuleID ( ) + ”<b></td></tr>” +

172 ”<tr><td va l i gn=top>Parameters :</td><td width=350>” ;173174 for ( int i = 0 ; i<=type . getParameters ( ) . s i z e ( )−1; i++) {175 Parameter p = type . getParameters ( ) . get ( i ) ;176 txt+= p . getName ( ) + ” : <b>” + command . getArguments ( ) [ i ] ;177 i f (p . getParameterType ( ) instanceof IntParameter ) {178 txt += ” ”+ (( IntParameter )p . getParameterType ( ) ) .

getUnit ( ) + ”” ;179 } else i f ( type . getParameters ( ) . get ( i ) . getParameterType ( )

instanceof DoubleParameter ) {180 txt += ” ”+ (( DoubleParameter )p . getParameterType ( ) ) .

getUnit ( ) + ”” ;181 }182 txt += ”</b><br>” + p . ge tDesc r ip t i on ( ) + ”<br>” ;183 }184 i f ( type . getParameters ( ) . s i z e ( )==0) txt += ”None” ;185 txt+=”</td></tr>” ;186 Pass pass = timel ineData . lookupPass (command . getPassID ( ) ) ;187 St r ing passTxt = ”” ;188 i f ( pass !=null ) {189 St r ing s t a r t = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format ( pass . getStartTime ( ) ) ;190 // S t r i n g end = new S imp l eD a t e F o rma t ( MPSP r e f e r e n c e s .

g e t F u l l D a t e T im e F o rm a t ( ) ) . f o rm a t ( p a s s . g e tEndT ime ( ) ) ;191 passTxt = ”<b>” + command . getPassID ( ) +”</b>” ;192 i f (command . getUserGivenPass ( ) ) passTxt += ” ( User given ) ” ;193 else passTxt += ” (Auto−scheduled ) ” ;194 passTxt += ” ( Pass s t a r t : ” + s t a r t + ” ) ” ;195 } else {196 passTxt = ”Not scheduled ” ;197 }198 St r ing toe = ”” ;199 i f (command . getTimeOfExecution ( )==−1) {200 toe = ”As soon as p o s s i b l e ” ;201 } else {202 toe = new SimpleDateFormat ( MPSPreferences .

getFullDateTimeFormat ( ) ) . format (command .getTimeOfExecution ( ) ) ;

203 }204205 txt += ”<tr><td va l i gn=top>Time of execut ion :</td><td><b>” + toe +”

</b></td></tr>” ;206 txt += ”<tr><td va l i gn=top>Pass :</td><td> ” + passTxt +”</td></tr>” ;207208 txt+= ”</table ></html>” ;209 return txt ;210211 }212213214 /∗∗ Ge t s t h e n e x t upcomming open p a s s . I f a p a s s i s g o i n g on r i g h t now , t h e n

i t i s r e t u r n e d .215 ∗ @r e t u r n Ne x t p a s s216 ∗/217 public Pass getNextOpenPass ( ) {218219 i f ( getUpcomingOpenPasses ( ) . s i z e ( )==0) return null ;220 else {221 Pass nextPass = getUpcomingOpenPasses ( ) . get (0) ;222223 for ( Pass pass : getUpcomingOpenPasses ( ) ) {224 i f ( pass . getStartTime ( )>TimeLineModel .

getCurrentTimeInMi l l i s ( ) && pass . getStartTime ( )<nextPass . getStartTime ( ) && pass . getStatus ( ) ==

Pass .OPEN) {225 nextPass = pass ;226 }227 }228 return nextPass ;229 }230 }231232 /∗∗

Page 319: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 309

233 ∗ @r e t u r n234 ∗/235 public ArrayList<Pass> getUpcomingOpenPasses ( ) {236 ArrayList<Pass> r e s u l t = new ArrayList<Pass >() ;237238 HashMap<Long , Pass> passMap = timel ineData . getPassMap ( ) ;239240 for ( Long id : passMap . keySet ( ) ) {241 i f ( passMap . get ( id ) . getEndTime ( ) > TimeLineModel .

getCurrentTimeInMi l l i s ( ) && passMap . get ( id ) . getStatus ( )== Pass .OPEN) {

242 r e s u l t . add ( passMap . get ( id ) ) ;243 }244 }245 Co l l e c t i on s . s o r t ( r e s u l t ) ;246 return r e s u l t ;247 }248249 /∗∗250 ∗ @r e t u r n251 ∗/252 public stat ic ArrayList<Pass> getOpenPasses ( ) {253 ArrayList<Pass> r e s u l t = new ArrayList<Pass >() ;254255 HashMap<Long , Pass> passMap = timel ineData . getPassMap ( ) ;256257 for ( Long id : passMap . keySet ( ) ) {258 i f ( passMap . get ( id ) . getStatus ( ) == Pass .OPEN) {259 r e s u l t . add ( passMap . get ( id ) ) ;260 }261 }262 return r e s u l t ;263 }264265 /∗∗266 ∗ @r e t u r n267 ∗/268 public boolean i sWithinPass ( ) {269270 HashMap<Long , Pass> passMap = timel ineData . getPassMap ( ) ;271272 for ( Long id : passMap . keySet ( ) ) {273 i f ( TimeLineModel . getCurrentTimeInMi l l i s ( ) > passMap . get ( id ) .

getStartTime ( ) && TimeLineModel . getCurrentTimeInMi l l i s( ) < passMap . get ( id ) . getEndTime ( ) ) {

274 return true ;275 }276 }277278 return fa l se ;279 }280281282 /∗∗283 ∗ @r e t u r n284 ∗/285 public ArrayList<CommandBlock> getUpcommingBlocks ( ) {286 ArrayList<CommandBlock> r e s u l t = new ArrayList<CommandBlock>() ;287288 HashMap<Long , CommandBlock> commandBlockMap = timel ineData .

getCommandBlockMap ( ) ;289 for ( Long id : commandBlockMap . keySet ( ) ) {290 i f ( commandBlockMap . get ( id ) . s i z e ( ) > 1 && isBlockOpen (

commandBlockMap . get ( id ) ) ) {291 r e s u l t . add (commandBlockMap . get ( id ) ) ;292 }293 }294295 return r e s u l t ;296 }297298 /∗∗299 ∗ @param commandBlock300 ∗ @r e t u r n301 ∗/302 private boolean isBlockOpen (CommandBlock commandBlock ) {303304 for ( int i =0; i<=commandBlock . s i z e ( )−1; i++) {305 long commandID = commandBlock . getCommand( i ) ;306 i f ( t imel ineData . getCommandMap( ) . get (commandID) . ge tState ( ) <

Command.BEING TRANSMITTED) return true ;307 }308309 return fa l se ;310311 }312

Page 320: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

310 Appendix C - Source Code

313314315 /∗∗316 ∗317 ∗/318 public void setTimeLineToDefaultTimes ( ) {319320 long s t a r t = TimeLineModel . getCurrentTimeInMi l l i s ( ) ;321322 // l o n g l owe s tTOE ;323 long highestTOE = 0;324325 HashMap<Long , Command> commandMap = timel ineData . getCommandMap( ) ;326 for ( Long id : commandMap . keySet ( ) ) {327 i f (commandMap . get ( id ) . getTimeOfExecution ( )>highestTOE ) {328 highestTOE = commandMap . get ( id ) . getTimeOfExecution ( )

;329 }330 }331332 this . s t a r t = s t a r t ;333 end = highestTOE ;334 }335336 /∗∗337 ∗338 ∗/339 public void setTimeLineToAll ( ) {340341 HashMap<Long , Command> commandMap = timel ineData . getCommandMap( ) ;342343 i f (commandMap . s i z e ( ) >0) {344 // TODO: s e t l o w e s t c o r r e c t345 long lowestTOE = 0 ;346 long highestTOE = 0;347348 for ( Long id : commandMap . keySet ( ) ) {349 i f (commandMap . get ( id ) . getTimeOfExecution ( )>

highestTOE ) {350 highestTOE = commandMap . get ( id ) .

getTimeOfExecution ( ) ;351 }352 i f (commandMap . get ( id ) . getTimeOfExecution ( )<lowestTOE

) {353 lowestTOE = commandMap . get ( id ) .

getTimeOfExecution ( ) ;354 }355 }356357 s t a r t = lowestTOE ;358 end = highestTOE ;359360 }361362 }363364 /∗∗365 ∗366 ∗/367 public void setTimeLineToToday ( ) {368 GregorianCalendar ca l = new GregorianCalendar ( ) ;369 ca l . s e tT imeInMi l l i s ( System . cur rentTimeMi l l i s ( ) ) ;370 ca l . s e t ( Calendar .HOUR OF DAY, 0 ) ;371 ca l . s e t ( Calendar .MINUTE, 0) ;372 ca l . s e t ( Calendar .SECOND, 0) ;373 long s t a r t = ca l . ge tTimeInMi l l i s ( ) ; // s e t s t a r t374 ca l . add ( Calendar .DATE, 1 ) ; // add one day375 long end = ca l . ge tTimeInMi l l i s ( ) ; // s e t end376377 this . s t a r t = s t a r t ;378 this . end = end ;379 }380381 /∗∗382 ∗383 ∗/384 public void setTimeLineToTomorrow ( ) {385 GregorianCalendar ca l = new GregorianCalendar ( ) ;386 ca l . s e tT imeInMi l l i s ( TimeLineModel . getCurrentTimeInMi l l i s ( ) ) ;387 ca l . s e t ( Calendar .HOUR OF DAY, 0 ) ;388 ca l . s e t ( Calendar .MINUTE, 0) ;389 ca l . s e t ( Calendar .SECOND, 0) ;390 ca l . add ( Calendar .DATE, 1 ) ; // add one day391 long s t a r t = ca l . ge tTimeInMi l l i s ( ) ; // s e t s t a r t392 ca l . add ( Calendar .DATE, 1 ) ; // add one day393 long end = ca l . ge tTimeInMi l l i s ( ) ; // s e t end394

Page 321: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 311

395 this . s t a r t = s t a r t ;396 this . end = end ;397398 }399400 /∗∗401 ∗402 ∗/403 public void setTimeLineToNext24Hours ( ) {404 GregorianCalendar ca l = new GregorianCalendar ( ) ;405 ca l . s e tT imeInMi l l i s ( System . cur rentTimeMi l l i s ( ) ) ;406 long s t a r t = ca l . ge tTimeInMi l l i s ( ) ; // s e t s t a r t407 ca l . add ( Calendar .DATE, 1 ) ;408 long end = ca l . ge tTimeInMi l l i s ( ) ; // s e t end409410 this . s t a r t = s t a r t ;411 this . end = end ;412413 }414415 /∗∗416 ∗417 ∗/418 public void setTimeLineToThisWeek ( ) {419 GregorianCalendar ca l = new GregorianCalendar ( ) ;420 ca l . s e tT imeInMi l l i s ( TimeLineModel . getCurrentTimeInMi l l i s ( ) ) ;421 ca l . s e t ( Calendar .HOUR OF DAY, 0 ) ;422 ca l . s e t ( Calendar .MINUTE, 0) ;423 ca l . s e t ( Calendar .SECOND, 0) ;424 ca l . s e t ( Calendar .DAY OF WEEK, Calendar .MONDAY) ;425 long s t a r t = ca l . ge tTimeInMi l l i s ( ) ; // s e t s t a r t426 ca l . s e t ( Calendar .DAY OF WEEK, Calendar .SUNDAY) ;427 long end = ca l . ge tTimeInMi l l i s ( ) ; // s e t end428429 this . s t a r t = s t a r t ;430 this . end = end ;431 }432433 /∗∗434 ∗435 ∗/436 public void setTimeLineToNextWeek ( ) {437 GregorianCalendar ca l = new GregorianCalendar ( ) ;438 ca l . s e tT imeInMi l l i s ( System . cur rentTimeMi l l i s ( ) ) ;439 ca l . s e t ( Calendar .HOUR OF DAY, 0 ) ;440 ca l . s e t ( Calendar .MINUTE, 0) ;441 ca l . s e t ( Calendar .SECOND, 0) ;442 ca l . s e t ( Calendar .DAY OF WEEK, Calendar .SUNDAY) ; // s e t t o s u n d a y443 ca l . add ( Calendar .DATE, 1 ) ; // add one day . . n o t i t i s monday t h e

n e x t we e k444 long s t a r t = ca l . ge tTimeInMi l l i s ( ) ; // s e t s t a r t445 ca l . s e t ( Calendar .DAY OF WEEK, Calendar .SUNDAY) ; // s e t s u n d a y t h i s

we e k446 long end = ca l . ge tTimeInMi l l i s ( ) ; // s e t end447448 this . s t a r t = s t a r t ;449 this . end = end ;450451 }452453 /∗∗454 ∗455 ∗/456 public void setTimeLineToThisMonth ( ) {457 GregorianCalendar ca l = new GregorianCalendar ( ) ;458 ca l . s e tT imeInMi l l i s ( TimeLineModel . getCurrentTimeInMi l l i s ( ) ) ;459 ca l . s e t ( Calendar .HOUR OF DAY, 0 ) ;460 ca l . s e t ( Calendar .MINUTE, 0) ;461 ca l . s e t ( Calendar .SECOND, 0) ;462 ca l . s e t ( Calendar .DAY OF MONTH, 1 ) ;463 long s t a r t = ca l . ge tTimeInMi l l i s ( ) ; // s e t s t a r t464 ca l . s e t ( Calendar .DAY OF MONTH, ca l . getActualMaximum ( Calendar .

DAY OF MONTH) ) ;465 long end = ca l . ge tTimeInMi l l i s ( ) ; // s e t end466467 this . s t a r t = s t a r t ;468 this . end = end ;469470 }471472 /∗∗473 ∗474 ∗/475 public void setTimeLineToNextMonth ( ) {476 GregorianCalendar ca l = new GregorianCalendar ( ) ;477 ca l . s e tT imeInMi l l i s ( TimeLineModel . getCurrentTimeInMi l l i s ( ) ) ;478 ca l . s e t ( Calendar .HOUR OF DAY, 0 ) ;

Page 322: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

312 Appendix C - Source Code

479 ca l . s e t ( Calendar .MINUTE, 0) ;480 ca l . s e t ( Calendar .SECOND, 0) ;481 ca l . add ( Calendar .MONTH, 1) ;482 ca l . s e t ( Calendar .DAY OF MONTH, 1 ) ;483 long s t a r t = ca l . ge tTimeInMi l l i s ( ) ; // s e t s t a r t484 ca l . s e t ( Calendar .DAY OF MONTH, ca l . getActualMaximum ( Calendar .

DAY OF MONTH) ) ;485 long end = ca l . ge tTimeInMi l l i s ( ) ; // s e t end486487 this . s t a r t = s t a r t ;488 this . end = end ;489490 }491492 /∗∗493 ∗ @param c494 ∗ @r e t u r n495 ∗/496 public stat ic Str ing getClassNameWithoutPackage ( Class c ) {497 St r ing FQClassName = c . getName ( ) ;498 int f i r s tCha r ;499 f i r s tCha r = FQClassName . las t IndexOf ( ’ . ’ ) + 1 ;500 i f ( f i r s tCha r > 0) {501 FQClassName = FQClassName . subs t r ing ( f i r s tCha r ) ;502 }503 return FQClassName ;504 }505506507 /∗∗508 ∗ @r e t u r n The s t a r t t im e o f t h e t i m e l i n e w h i c h i s b e i n g shown i n t h e

p l a n n i n g v i e w509 ∗/510 public long ge tS ta r t ( ) {511 return s t a r t ;512 }513514 /∗∗515 ∗ @r e t u r n The end t im e o f t h e t i m e l i n e w h i c h i s b e i n g shown i n t h e p l a n n i n g

v i e w516 ∗/517 public long getEnd ( ) {518 return end ;519 }520521 /∗∗ S e t s t h e s t a r t t im e o f t h e t i m e l i n e w h i c h i s b e i n g shown i n t h e p l a n n i n g

v i e w .522 ∗ @param s t a r t The s t a r t t im e o f t h e t i m e l i n e .523 ∗/524 public void s e t S t a r t ( long s t a r t ) {525 this . s t a r t = s t a r t ;526 }527528 /∗∗ S e t s t h e end t im e o f t h e t i m e l i n e w h i c h i s b e i n g shown i n t h e p l a n n i n g

v i e w .529 ∗ @param end The end t im e o f t h e t i m e l i n e .530 ∗/531 public void setEnd ( long end ) {532 this . end = end ;533 }534535 /∗∗536 ∗ @r e t u r n537 ∗/538 public GregorianCalendar getStartAsCalendar ( ) {539 GregorianCalendar ca l = new GregorianCalendar ( ) ;540 ca l . s e tT imeInMi l l i s ( s t a r t ) ;541 return ca l ;542 }543544 /∗∗545 ∗ @r e t u r n546 ∗/547 public GregorianCalendar getEndAsCalendar ( ) {548 GregorianCalendar ca l = new GregorianCalendar ( ) ;549 ca l . s e tT imeInMi l l i s ( end ) ;550 return ca l ;551 }552553 /∗∗554 ∗ @r e t u r n555 ∗/556 public Timeline getTimelineData ( ) {557 return t imel ineData ;558 }559560 /∗∗

Page 323: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 313

561 ∗ @r e t u r n562 ∗/563 public boolean isPassMode ( ) {564 return passMode ;565 }566567 /∗∗568 ∗ @r e t u r n569 ∗/570 public boolean isEmergencyMode ( ) {571 return emergencyMode ;572 }573574 /∗∗575 ∗ @r e t u r n576 ∗/577 public ArrayList<GroundStation> getGroundStations ( ) {578 return groundStat ions ;579 }580581 /∗∗582 ∗ @r e t u r n583 ∗/584 public PredefinedCommandBlocksSaveObject

getPredefinedCommandBlocksSaveObject ( ) {585586 return predefinedCommandBlocksSaveObject ;587588 }589590 }

Page 324: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

314 Appendix C - Source Code

.1.84 TimeLineView.java

1 package mps . gui . t ime l i n e ;23 import java . awt . Color ;4 import java . awt . Dimension ;5 import java . awt . FlowLayout ;6 import java . awt . Font ;7 import java . awt . GridBagConstraints ;8 import java . awt . GridBagLayout ;9 import java . awt . I n s e t s ;

10 import java . awt . Too lk i t ;11 import java . awt . event . ActionEvent ;12 import java . awt . event . KeyEvent ;13 import java . net .URL;14 import java . rmi . NotBoundException ;15 import java . rmi . RemoteException ;16 import java . u t i l . ArrayList ;17 import java . u t i l . Date ;1819 import javax . swing . BorderFactory ;20 import javax . swing . ButtonGroup ;21 import javax . swing . JButton ;22 import javax . swing . JCheckBox ;23 import javax . swing . JComboBox ;24 import javax . swing . JFrame ;25 import javax . swing . JLabel ;26 import javax . swing . JMenu ;27 import javax . swing . JMenuBar ;28 import javax . swing . JMenuItem ;29 import javax . swing . JOptionPane ;30 import javax . swing . JPanel ;31 import javax . swing . JRadioButtonMenuItem ;32 import javax . swing . JSeparator ;33 import javax . swing . JTextField ;34 import javax . swing . KeyStroke ;35 import javax . swing . RowFilter ;36 import javax . swing . RowFilter . ComparisonType ;3738 import mcc . s e rv e r . dataProcess ing . GroundStation ;39 import mcc . s e rv e r . u s e r s . User ;40 import mps . MPSPreferences ;41 import mps . gui . DateTimeSpinnersPanel ;42 import mps . gui . passwindow . CountDownLabel ;43 import mps . rmi . C l i ent ;4445 /∗∗46 ∗ <br><br>47 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 348 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 149 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 850 ∗/51 public c lass TimeLineView extends JFrame {5253 /∗54 ∗ I n s t a n c e d a t a55 ∗/5657 /∗∗58 ∗59 ∗/60 private stat ic f ina l long se r ia lVers ionUID = 1L ;61 /∗∗62 ∗63 ∗/64 private TimeLineControl ler c o n t r o l l e r ;65 /∗∗66 ∗67 ∗/68 private TimeLineModel model = TimeLineModel . g e t In s tance ( ) ;6970 /∗∗71 ∗72 ∗/73 private JMenuBar menuBar ;74 /∗∗75 ∗76 ∗/77 private JMenu f i leMenu ;78 /∗∗79 ∗80 ∗/81 private JMenuItem logoutMenuItem ;82 /∗∗83 ∗84 ∗/

Page 325: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 315

85 private JMenuItem exitMenuItem ;86 /∗∗87 ∗88 ∗/89 private JMenu settingsMenu ;90 /∗∗91 ∗92 ∗/93 private JMenuItem tleMenuItem ;94 /∗∗95 ∗96 ∗/97 private JMenuItem preschedulingMenuItem ;98 /∗∗99 ∗

100 ∗/101 private JMenuItem preDefinedBlocksMenuItem ;102 /∗∗103 ∗104 ∗/105 private JMenuItem dateFormatMenuItem ;106 /∗∗107 ∗108 ∗/109 private JMenuItem stateColoringMenuItem ;110 /∗∗111 ∗112 ∗/113 private JMenu guiUpdateSubMenu ;114 /∗∗115 ∗116 ∗/117 private JRadioButtonMenuItem guiUpdateOnRadioButtonMenuItem ;118 /∗∗119 ∗120 ∗/121 private JRadioButtonMenuItem guiUpdateOffRadioButtonMenuItem ;122 /∗∗123 ∗124 ∗/125 private JMenuItem guiUpdateIntervalMenuItem ;126 /∗∗127 ∗128 ∗/129 private JMenu adminMenu ;130 /∗∗131 ∗132 ∗/133 private JMenuItem createUserMenuItem ;134 /∗∗135 ∗136 ∗/137 private JMenuItem editUserMenuItem ;138 /∗∗139 ∗140 ∗/141 private JMenuItem newGsMenuItem ;142 /∗∗143 ∗144 ∗/145 private JMenu editGsSubMenu ; // submenu146 /∗∗147 ∗148 ∗/149 private JMenu helpMenu ;150 /∗∗151 ∗152 ∗/153 private JMenuItem aboutMenuItem ;154155 /∗∗156 ∗157 ∗/158 private DateTimeSpinnersPanel startDateTimeSpinnersPanel ; // s t a r t d a t e and

t im e on c u r r e n t t i m e l i n e159 /∗∗160 ∗161 ∗/162 private DateTimeSpinnersPanel endDateTimeSpinnersPanel ; // end d a t e and t im e

on c u r r e n t t i m e l i n e163 /∗∗164 ∗165 ∗/166 private JComboBox timelineOptionsComboBox ;167168 /∗∗169 ∗

Page 326: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

316 Appendix C - Source Code

170 ∗/171 private TimeLineGraphicView graphicView ;172 /∗∗173 ∗174 ∗/175 private CommandTableView commandTableView ;176 /∗∗177 ∗178 ∗/179 private PassesTableView passesTableView ;180181 /∗∗182 ∗183 ∗/184 private JTextField f i l t e r T e x t ;185186 /∗∗187 ∗188 ∗/189 private JButton scheduleButton ;190191 /∗∗192 ∗193 ∗/194 private CountDownLabel countDownClockLabel ;195 /∗∗196 ∗197 ∗/198 private JLabel emergencyLabel ;199 /∗∗200 ∗201 ∗/202 private JButton passWindowButton ;203 /∗∗204 ∗205 ∗/206 private JPanel passCountDownPanel ;207208 /∗∗209 ∗210 ∗/211 private JCheckBox allConnectionsCheckBox ;212 /∗∗213 ∗214 ∗/215 private JCheckBox commandsToPassCheckBox ;216 /∗∗217 ∗218 ∗/219 private JCheckBox passToCommandsCheckBox ;220221222 /∗∗223 ∗ C o n s t r u c t o r224 ∗ @th r ow s E x c e p t i o n225 ∗/226 public TimeLineView ( ) throws Exception{227228 // MVC229 model . loadDataFromDB () ;230231 c o n t r o l l e r = new TimeLineControl ler ( this , model ) ;232233 // SET−UP FRAME234 this . s e tDe fau l tCloseOperat ion ( JFrame .EXIT ON CLOSE) ;235 this . s e t T i t l e ( ” Miss ion Planning System fo r DTUsat2” ) ;236 this . s e t S i z e (1024 ,768) ;237 this . setExtendedState ( JFrame .MAXIMIZED BOTH) ;238239 this . setLayout (new FlowLayout ( FlowLayout .LEADING) ) ;240241 // CREATE MENU BAR242 createMenuBar ( ) ;243244 JPanel panel = new JPanel ( ) ;245 panel . setLayout (new GridBagLayout ( ) ) ;246247 // ADD PANELS248 GridBagConstraints c = new GridBagConstraints ( ) ;249 c . anchor = GridBagConstraints .LINE START;250 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;251 c . gr idwidth = 1 ;252253 St r ing t ru s t = User . ge tTrustDesc r ip t ion ( Cl i ent . ge t In s tance ( ) .

getUserTrustLeve l ( ) ) ;254

Page 327: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 317

255 JLabel l o g i n I n f o = new JLabel ( ”<html>Login : <b>” + Cl i ent .ge t In s tance ( ) . getUsername ( ) + ”</b> ( ” + t ru s t + ” )</html>” ) ;

256 c . gr idx = 0 ;257 c . gr idy = 0 ;258 c . g r i dhe i gh t = 1 ;259 panel . add ( l og in In f o , c ) ;260261 c . gr idx = 0 ;262 c . gr idy = 1 ;263 panel . add ( c r e a t eF i l t e r i n gPane l ( ) , c ) ;264265 c . gr idx = 0 ;266 c . gr idy = 2 ;267 c . g r i dhe i gh t = 1 ;268 c . anchor = GridBagConstraints .CENTER;269 JLabel commandHeadlineLabel = new JLabel ( ”Commands” ) ;270 commandHeadlineLabel . setFont (new Font ( ”Verdana” , Font .BOLD,16 ) ) ;271 panel . add ( commandHeadlineLabel , c ) ;272273 commandTableView = new CommandTableView( this ) ;274 c . gr idx = 0 ;275 c . gr idy = 3 ;276 c . g r i dhe i gh t = 1 ;277 c . anchor = GridBagConstraints . FIRST LINE START ;278 panel . add ( commandTableView , c ) ;279280 c . gr idx = 1 ;281 c . gr idy = 0 ;282 c . g r i dhe i gh t = 2 ;283 c . anchor = GridBagConstraints .LINE START;284 passCountDownPanel = createPassCountDownPanel ( ) ;285 panel . add ( passCountDownPanel , c ) ;286287 c . gr idx = 2 ;288 c . gr idy = 0 ;289 c . g r i dhe i gh t = 2 ;290 c . anchor = GridBagConstraints .CENTER;291 passWindowButton = new JButton ( ”<html><b><center>Pass<br>Window</center ></b

></html>” ) ;292 // p a s sW in d owBu t t o n . s e t P r e f e r r e d S i z e ( new D imen s i o n ( 1 3 0 , 2 5 ) ) ;293 // p a s sW in d owBu t t o n . s e t F o n t ( new Fon t ( ” Tahoma ” , Fon t . BOLD , 1 2 ) ) ;294 passWindowButton . addAct ionListener ( c o n t r o l l e r ) ;295 panel . add ( passWindowButton , c ) ;296297 c . gr idx = 1 ;298 c . gr idy = 2 ;299 c . g r i dhe i gh t = 1 ;300 c . gr idwidth = 2 ;301 c . anchor = GridBagConstraints .CENTER;302 JLabel passesHeadl ineLabe l = new JLabel ( ”Upcomming Passes ” ) ;303 passesHeadl ineLabe l . setFont (new Font ( ”Verdana” , Font .BOLD,16 ) ) ;304 panel . add ( passesHeadl ineLabel , c ) ;305306 passesTableView = new PassesTableView ( this ) ;307 c . gr idx = 1 ;308 c . gr idy = 3 ;309 c . gr idwidth = 2 ;310 c . anchor = GridBagConstraints . FIRST LINE START ;311 panel . add ( passesTableView , c ) ;312313314 scheduleButton = new JButton ( ” Schedule t ime l i n e ” ) ;315 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( )<=User .MEDIUM TRUST) {316 scheduleButton . setEnabled ( f a l s e ) ;317 scheduleButton . setToolTipText ( ”To schedule commands \” Ful l Trust\”

or h igher i s r equ i r ed . ” ) ;318 }319 scheduleButton . s e t P r e f e r r e d S i z e (new Dimension (200 ,40) ) ;320 scheduleButton . setFont (new Font ( ”Tahoma” , Font .BOLD,12 ) ) ;321322 c . gr idy = 4 ;323 c . gr idx = 0 ;324 c . gr idwidth = 4 ;325 c . anchor = GridBagConstraints .CENTER;326 // c . f i l l = G r i d B a g C o n s t r a i n t s . HORIZONTAL ;327 panel . add ( scheduleButton , c ) ;328329 graphicView = new TimeLineGraphicView ( this ) ;330 c . gr idy = 5 ;331 panel . add ( graphicView , c ) ;332333 c . gr idy = 6 ;334 c . anchor = GridBagConstraints .LINE START;335 panel . add ( createConnect ionsPane l ( ) , c ) ;336337338 // s e t b o t h t a b l e and g r a p h i c t i m e l i n e s

Page 328: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

318 Appendix C - Source Code

339 model . setTimeLineToToday ( ) ;340 updateTimeLineEndAndStart ( model . g e tS ta r t ( ) , model . getEnd ( ) ) ;341342 this . add ( panel ) ;343344 s e t I con ( this ) ;345346 // LISTENERS347 addListenersToSpinners ( ) ;348 timelineOptionsComboBox . addItemListener ( c o n t r o l l e r ) ;349 f i l t e r T e x t . getDocument ( ) . addDocumentListener ( c o n t r o l l e r ) ;350 scheduleButton . addAct ionListener ( c o n t r o l l e r ) ;351 allConnectionsCheckBox . addAct ionListener ( c o n t r o l l e r ) ;352 commandsToPassCheckBox . addAct ionListener ( c o n t r o l l e r ) ;353 passToCommandsCheckBox . addAct ionListener ( c o n t r o l l e r ) ;354355 this . s e t V i s i b l e ( true ) ;356357 // run t h e u p d a t e t h r e a d o f t h e GUI358 c o n t r o l l e r . getUpdateThread ( ) . s t a r t ( ) ;359 }360361 /∗∗362 ∗363 ∗/364 private stat ic f ina l URL iconUr l =365 TimeLineView . c lass . getResource ( ”/ r e s ou r c e s / images /DTUsatIcon .PNG” ) ;366367 /∗∗368 ∗ @param f r ame369 ∗/370 public stat ic void s e t I con ( JFrame frame ) {371 frame . setIconImage ( Too lk i t . g e tDe fau l tToo lk i t ( ) . getImage ( i conUr l ) ) ;372 }373374 /∗∗375 ∗ @r e t u r n376 ∗/377 private JPanel createConnect ionsPane l ( ) {378379 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;380 GridBagConstraints c = new GridBagConstraints ( ) ;381 c . anchor = GridBagConstraints .LINE START;382 // c . i n s e t s = new I n s e t s ( 1 , 1 , 1 , 1 ) ;383384385 JLabel connect ionsLabe l = new JLabel ( ”Show command/ pass connect ions : ” ) ;386 c . gr idx = 0 ;387 c . gr idy = 0 ;388 c . gr idwidth = 3 ;389 panel . add ( connect ionsLabel , c ) ;390391 allConnectionsCheckBox = new JCheckBox ( ” Al l ” ) ;392 c . gr idwidth = 1 ;393 c . gr idy++;394 panel . add ( allConnectionsCheckBox , c ) ;395396 commandsToPassCheckBox = new JCheckBox ( ” Se l e c t ed command( s ) ” ) ;397 c . gr idx++;398 panel . add ( commandsToPassCheckBox , c ) ;399400 passToCommandsCheckBox = new JCheckBox ( ” Se l e c t ed pass ” ) ;401 c . gr idx++;402 panel . add (passToCommandsCheckBox , c ) ;403404405 return panel ;406 }407408 /∗∗409 ∗ @r e t u r n410 ∗/411 private JPanel createPassCountDownPanel ( ) {412413 JPanel panel = new JPanel (new GridBagLayout ( ) ) ;414 // p a n e l . s e tM i n imumS i z e ( new D imen s i o n ( 3 0 0 , 1 0 0 ) ) ;415416 GridBagConstraints c = new GridBagConstraints ( ) ;417 c . anchor = GridBagConstraints .LINE START;418 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 5 ) ;419420 c . gr idx = 0 ;421 c . gr idy = 0 ;422 JLabel label = new JLabel ( ”Count down : ” ) ;423 panel . add ( label , c ) ;424425 countDownClockLabel = new CountDownLabel ( ) ;

Page 329: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 319

426 countDownClockLabel . setFont (new Font ( ”Tahoma” , Font .BOLD,13 ) ) ;427 c . gr idx = 1 ;428 panel . add ( countDownClockLabel , c ) ;429430 c . gr idx = 0 ;431 c . gr idy = 1 ;432 c . gr idwidth = 2 ;433 emergencyLabel = new JLabel ( ) ;434 setEmergencyLabel ( ) ;435 panel . add ( emergencyLabel , c ) ;436437 return panel ;438 }439440441 /∗∗442 ∗ @th r ow s R emo t e E x c e p t i o n443 ∗/444 private void createMenuBar ( ) throws RemoteException {445 menuBar = new JMenuBar ( ) ;446447 // F i l e Menu448 f i leMenu = new JMenu( ” F i l e ” ) ;449 f i leMenu . setMnemonic ( KeyEvent .VK F) ;450 f i leMenu . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on (451 ”The F i l e menu” ) ;452 menuBar . add ( f i leMenu ) ;453454 logoutMenuItem = new JMenuItem( ”Log out” ) ;455 // l o g o u tM e n u I t em . s e t A c c e l e r a t o r ( K e y S t r o k e . g e t K e y S t r o k e ( KeyEv en t .

VK F4 , A c t i o n E v e n t . ALT MASK) ) ;456 logoutMenuItem . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on ( ”Log

out o f Miss ion Planning Sytem” ) ;457 f i leMenu . add ( logoutMenuItem ) ;458459 exitMenuItem = new JMenuItem( ” Exit ” ) ;460 exitMenuItem . s e tAcc e l e r a t o r ( KeyStroke . getKeyStroke ( KeyEvent . VK F4 ,

ActionEvent .ALT MASK) ) ;461 exitMenuItem . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on ( ” Exit

Miss ion Planning Sytem” ) ;462 f i leMenu . add ( exitMenuItem ) ;463464465 // S e t t i n g s Menu466 settingsMenu = new JMenu( ” Se t t i ng s ” ) ;467 settingsMenu . setMnemonic ( KeyEvent . VK S) ;468 settingsMenu . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on (469 ”The Se t t i ng s menu” ) ;470 menuBar . add ( sett ingsMenu ) ;471472 tleMenuItem = new JMenuItem( ”TLE f i l e ” , KeyEvent .VK T) ;473 tleMenuItem . s e tAcc e l e r a t o r ( KeyStroke . getKeyStroke ( KeyEvent .VK T,

ActionEvent .ALT MASK) ) ;474 tleMenuItem . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on ( ” Edit

URL of TLE and name of s a t e l l i t e in TLE” ) ;475 settingsMenu . add ( tleMenuItem ) ;476477 preschedulingMenuItem = new JMenuItem( ”Pre−s chedu l ing ” ) ;478 preschedulingMenuItem . getAcces s ib l eContext ( ) .

s e tAc c e s s i b l eDe s c r i p t i on ( ”Pre−s chedu l ing ” ) ;479 settingsMenu . add ( preschedulingMenuItem ) ;480481 preDefinedBlocksMenuItem = new JMenuItem( ” Predef ined Blocks ” ,

KeyEvent .VK P) ;482 preDefinedBlocksMenuItem . s e tAcc e l e r a t o r ( KeyStroke . getKeyStroke (

KeyEvent .VK P, ActionEvent .ALT MASK) ) ;483 preDefinedBlocksMenuItem . getAcces s ib l eContext ( ) .

s e tAc c e s s i b l eDe s c r i p t i on ( ” Edit the path to save and loadPrede f ined Command Blocks from . ” ) ;

484 settingsMenu . add ( preDefinedBlocksMenuItem ) ;485486 dateFormatMenuItem = new JMenuItem( ”Date format” , KeyEvent .VK D) ;487 dateFormatMenuItem . s e tAcc e l e r a t o r ( KeyStroke . getKeyStroke ( KeyEvent .

VK D, ActionEvent .ALT MASK) ) ;488 dateFormatMenuItem . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on ( ”

Edit the date format used a l l over MPS” ) ;489 settingsMenu . add ( dateFormatMenuItem ) ;490491 stateColoringMenuItem = new JMenuItem( ” State c o l o r i n g ” , KeyEvent .

VK S) ;492 stateColoringMenuItem . s e tAcc e l e r a t o r ( KeyStroke . getKeyStroke ( KeyEvent

. VK S , ActionEvent .ALT MASK) ) ;493 stateColoringMenuItem . getAcces s ib l eContext ( ) .

s e tAc c e s s i b l eDe s c r i p t i on ( ” Edit s t a t e c o l o r i n g o f commands” ) ;494 settingsMenu . add ( stateColoringMenuItem ) ;495496

Page 330: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

320 Appendix C - Source Code

497 guiUpdateSubMenu = new JMenu( ”GUI Update / DB Pool ing ” ) ;498 settingsMenu . add ( guiUpdateSubMenu ) ;499500 guiUpdateOnRadioButtonMenuItem = new JRadioButtonMenuItem ( ”ON” ) ;501502 guiUpdateSubMenu . add ( guiUpdateOnRadioButtonMenuItem ) ;503 guiUpdateOffRadioButtonMenuItem = new JRadioButtonMenuItem ( ”OFF” ) ;504 guiUpdateSubMenu . add ( guiUpdateOffRadioButtonMenuItem ) ;505 ButtonGroup group = new ButtonGroup ( ) ;506 group . add ( guiUpdateOffRadioButtonMenuItem ) ;507 group . add ( guiUpdateOnRadioButtonMenuItem ) ;508 boolean updateOn = MPSPreferences . isUpdatingOn ( ) ;509 guiUpdateOnRadioButtonMenuItem . s e t S e l e c t ed ( updateOn ) ;510 guiUpdateOffRadioButtonMenuItem . s e t S e l e c t ed ( ! updateOn ) ;511512 guiUpdateSubMenu . add (new JSeparator ( ) ) ;513 guiUpdateIntervalMenuItem = new JMenuItem( ” In t e r v a l ” ) ;514 guiUpdateSubMenu . add ( guiUpdateIntervalMenuItem ) ;515516517 // ADMIN Menu518 i f ( C l i ent . ge t In s tance ( ) . getUserTrustLeve l ( )>=User .

ADMINISTRATOR TRUST) {519 adminMenu = new JMenu( ”Admin” ) ;520 adminMenu . setMnemonic ( KeyEvent .VK A) ;521 adminMenu . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on ( ”

The Admin Menu” ) ;522 menuBar . add (adminMenu) ;523524 // Us e r mangement525 createUserMenuItem = new JMenuItem( ” Create user ” ) ;526 createUserMenuItem . getAcces s ib l eContext ( ) .

s e tAc c e s s i b l eDe s c r i p t i on ( ”Add a new User to the MPS” ) ;527 adminMenu . add ( createUserMenuItem ) ;528 createUserMenuItem . addAct ionListener ( c o n t r o l l e r ) ;529530 editUserMenuItem = new JMenuItem( ” Edit User” ) ;531 editUserMenuItem . getAcces s ib l eContext ( ) .

s e tAc c e s s i b l eDe s c r i p t i on ( ” Edit an e x i s t i n g user ” ) ;532 adminMenu . add ( editUserMenuItem ) ;533 editUserMenuItem . addAct ionListener ( c o n t r o l l e r ) ;534535 adminMenu . add (new JSeparator ( ) ) ;536537 // GS Menu i t e m s538 newGsMenuItem = new JMenuItem( ”Add Ground Stat ion ” , KeyEvent

.VK N) ;539 newGsMenuItem . s e tAcc e l e r a t o r ( KeyStroke . getKeyStroke ( KeyEvent

.VK N, ActionEvent .ALT MASK) ) ;540 newGsMenuItem . getAcces s ib l eContext ( ) .

s e tAc c e s s i b l eDe s c r i p t i on ( ”Add a new Ground Stat ion tothe MPS” ) ;

541 adminMenu . add (newGsMenuItem) ;542 newGsMenuItem . addAct ionListener ( c o n t r o l l e r ) ;543544 editGsSubMenu = new JMenu( ” Edit GS” ) ;545 editGsSubMenu . setMnemonic ( KeyEvent .VK E) ;546 editGsSubMenu . getAcces s ib l eContext ( ) .

s e tAc c e s s i b l eDe s c r i p t i on ( ” Edit Ground Sta t i ons ” ) ;547 adminMenu . add ( editGsSubMenu ) ;548549 try {550 for ( GroundStation gs : C l i ent . ge t In s tance ( ) .

ge tMin ima l Inte r face ( ) . getGroundStations ( ) ) {551 JMenuItem editGSMenuItem = new JMenuItem( gs .

GetName ( ) ) ;552 editGsSubMenu . add ( editGSMenuItem ) ;553 editGSMenuItem . addAct ionListener ( c o n t r o l l e r )

;554 }555 } catch ( NotBoundException e ) {556 JOptionPane . showMessageDialog ( this , e . getMessage ( ) ,

” Error ” , JOptionPane .ERROR MESSAGE) ;557 e . pr intStackTrace ( ) ;558 }559 }560561 helpMenu = new JMenu( ”Help” ) ;562 helpMenu . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on ( ”The Help

Menu” ) ;563 aboutMenuItem = new JMenuItem( ”About Miss ion Planning System” ) ;564 aboutMenuItem . getAcces s ib l eContext ( ) . s e tAc c e s s i b l eDe s c r i p t i on ( ”View

in format ion about the Miss ion Planning System” ) ;565 helpMenu . add ( aboutMenuItem ) ;566567 menuBar . add ( helpMenu ) ;568

Page 331: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 321

569 this . setJMenuBar (menuBar ) ;570571 // LISTENERS572573 exitMenuItem . addAct ionListener ( c o n t r o l l e r ) ;574 logoutMenuItem . addAct ionListener ( c o n t r o l l e r ) ;575 tleMenuItem . addAct ionListener ( c o n t r o l l e r ) ;576 preschedulingMenuItem . addAct ionListener ( c o n t r o l l e r ) ;577 preDefinedBlocksMenuItem . addAct ionListener ( c o n t r o l l e r ) ;578 stateColoringMenuItem . addAct ionListener ( c o n t r o l l e r ) ;579 guiUpdateIntervalMenuItem . addAct ionListener ( c o n t r o l l e r ) ;580 guiUpdateOffRadioButtonMenuItem . addAct ionListener ( c o n t r o l l e r ) ;581 guiUpdateOnRadioButtonMenuItem . addAct ionListener ( c o n t r o l l e r ) ;582 dateFormatMenuItem . addAct ionListener ( c o n t r o l l e r ) ;583 aboutMenuItem . addAct ionListener ( c o n t r o l l e r ) ;584585 }586587588 /∗∗589 ∗ @r e t u r n590 ∗/591 public JPanel c r e a t eF i l t e r i n gPane l ( ) {592 JPanel panel = new JPanel ( ) ;593 panel . setBorder ( BorderFactory . c r ea teT i t l edBorder ( ” F i l t e r i n g s e t t i n g s

” ) ) ;594 panel . setLayout (new GridBagLayout ( ) ) ;595 GridBagConstraints c = new GridBagConstraints ( ) ;596597 c . anchor = GridBagConstraints .LINE START;598 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;599 c . gr idwidth = 1 ;600601 c . gr idy = 0 ;602 c . gr idx = 0 ;603 panel . add (new JLabel ( ”From” ) , c ) ;604605 startDateTimeSpinnersPanel = new DateTimeSpinnersPanel ( ) ;606 c . gr idx = 1 ;607 panel . add ( startDateTimeSpinnersPanel , c ) ;608609 c . gr idx = 2 ;610 panel . add (new JLabel ( ” u n t i l ” ) , c ) ;611612 endDateTimeSpinnersPanel = new DateTimeSpinnersPanel ( ) ;613 c . gr idx = 3 ;614 panel . add ( endDateTimeSpinnersPanel , c ) ;615616 St r ing [ ] op t i on sS t r i ng s = {” −− Quick s e t −−” , ”Now u n t i l l a s t

command” , ” F i r s t u n t i l l a s t command” , ”Today” , ”Next 24 hours ”, ”Tomrrow” , ”This week” , ”Next week” , ”This month” , ”Nextmonth” } ;

617 timelineOptionsComboBox = new JComboBox( op t i on sS t r i ng s ) ;618 c . gr idx = 4 ;619 panel . add ( timelineOptionsComboBox , c ) ;620621 c . gr idx = 5 ;622 c . anchor = GridBagConstraints . LINE END;623 panel . add (new JLabel ( ” F i l t e r text ” ) , c ) ;624625 f i l t e r T e x t = new JTextField ( ) ;626 f i l t e r T e x t . s e t P r e f e r r e d S i z e (new Dimension (100 ,20) ) ;627 c . gr idx = 6 ;628 c . anchor = GridBagConstraints .LINE START;629 panel . add ( f i l t e rTex t , c ) ;630631 return panel ;632 }633634 /∗∗635 ∗ @th r ow s R emo t e E x c e p t i o n636 ∗ @th r ow s N o tB o u n dE x c e p t i o n637 ∗/638 public void updateTimeLineViews ( ) throws RemoteException , NotBoundException

{639 model . loadDataFromDB () ;640641 commandTableView . setTableColumnWidths ( ) ;642 commandTableView . r epa in t ( ) ;643644 graphicView . r epa in t ( ) ;645646 passesTableView . setTableColumnWidths ( ) ;647 passesTableView . r epa in t ( ) ;648649 setEmergencyLabel ( ) ;650

Page 332: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

322 Appendix C - Source Code

651 newFi l te r ( ) ;652653 this . r epa in t ( ) ;654 }655656 /∗∗657 ∗ @param n e w S t a r t658 ∗ @param newEnd659 ∗/660 public void updateTimeLineEndAndStart ( long newStart , long newEnd) {661662 // s e t s p i n n e r s d a t e c o r r e s p o n d i n g t o t h e d r a g g i n g o f t h e g r a p h i c663 startDateTimeSpinnersPanel . setTime ( newStart ) ;664 endDateTimeSpinnersPanel . setTime (newEnd) ;665666 graphicView . r epa in t ( ) ;667668 // s e t t h e f i l t e r a g a i n669 newFi l te r ( ) ;670671 }672673 /∗∗674 ∗675 ∗/676 private void setEmergencyLabel ( ) {677 i f ( model . isEmergencyMode ( ) ){678 emergencyLabel . setText ( ”Emergency Mode : ON” ) ;679 emergencyLabel . setForeground ( Color .RED) ;680 } else {681 emergencyLabel . setText ( ”Emergency Mode : OFF” ) ;682 emergencyLabel . setForeground ( Color .BLACK) ;683 }684 }685686 /∗∗687 ∗ @param s h o u l d U p d a t e688 ∗/689 public void setScheduleRecommendation (boolean shouldUpdate ) {690 i f ( shouldUpdate ) {691 scheduleButton . setForeground ( Color .RED) ;692 scheduleButton . setToolTipText ( ”Changes has been made to the

t ime l i n e and i t i s recommended to re−schedule ” ) ;693 } else {694 scheduleButton . setForeground (new Color (0 ,150 ,0) ) ;695 scheduleButton . setToolTipText ( null ) ;696 }697698 }699700 /∗∗701 ∗702 ∗/703 public void newFi l ter ( ) {704705 ArrayList<RowFilter<CommandAbstractTableModel , Object>> f i l t e r s = new

ArrayList<RowFilter<CommandAbstractTableModel , Object >>(2) ;706707 // C r e a t e f i l t e r b a s e d on i n p u t t e s t708 int [ ] i n d i c i e s = {CommandAbstractTableModel .NAME COLUMN,

CommandAbstractTableModel .DESTINATION COLUMN,CommandAbstractTableModel .STATE COLUMN} ;

709 RowFilter<CommandAbstractTableModel , Object> r f 1 = RowFilter .r e g e x F i l t e r ( ” (? i ) ”+f i l t e r T e x t . getText ( ) , i n d i c i e s ) ;

710 // C a l c u l a t e s t a r t and end t im e f r om s p i n n e r s711 long s t a r t = model . g e tS ta r t ( ) ;712 long end = model . getEnd ( ) ;713714 // c r e a t e f i l t e r s b a s e d on s t a r t and end t im e715 RowFilter<CommandAbstractTableModel , Object> r f 2 = RowFilter .

d a t e F i l t e r ( ComparisonType .AFTER, new Date ( s ta r t −1) ) ; // +1 t omake i t a f t e r o r e q u a l s

716 RowFilter<CommandAbstractTableModel , Object> r f 3 = RowFilter .d a t e F i l t e r ( ComparisonType .BEFORE, new Date ( end+1) ) ; // −1 t omake i t b e f o r e o r e q u a l s

717 f i l t e r s . add ( r f 1 ) ;718 f i l t e r s . add ( r f 2 ) ;719 f i l t e r s . add ( r f 3 ) ;720721 RowFilter<CommandAbstractTableModel , Object> f i l t e r = RowFilter .

andF i l t e r ( f i l t e r s ) ;722723 commandTableView . ge tSo r t e r ( ) . setRowFi l ter ( f i l t e r ) ;724725726 /∗727 ∗

Page 333: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 323

728 ∗ D a t e F i l t e r OR (ASAP AND ( p a s s I D i n T i m e l i n e OR ( i n i t i a l s t a t e AND )) )

729 ∗730 ∗731 ∗732 ∗/733734735 }736737738 /∗∗739 ∗740 ∗/741 public void removeListenersFromSpinners ( ) {742 endDateTimeSpinnersPanel . getDateSDM () . removeChangeListener (

c o n t r o l l e r ) ;743 endDateTimeSpinnersPanel . getTimeSDM () . removeChangeListener ( c o n t r o l l e r ) ;744 startDateTimeSpinnersPanel . getDateSDM () . removeChangeListener ( c o n t r o l l e r ) ;745 startDateTimeSpinnersPanel . getTimeSDM () . removeChangeListener ( c o n t r o l l e r ) ;746 }747748 /∗∗749 ∗750 ∗/751 public void addListenersToSpinners ( ) {752 endDateTimeSpinnersPanel . getDateSDM () . addChangeListener ( c o n t r o l l e r ) ;753 endDateTimeSpinnersPanel . getTimeSDM () . addChangeListener ( c o n t r o l l e r ) ;754 startDateTimeSpinnersPanel . getDateSDM () . addChangeListener ( c o n t r o l l e r ) ;755 startDateTimeSpinnersPanel . getTimeSDM () . addChangeListener ( c o n t r o l l e r ) ;756 }757758 /∗∗759 ∗760 ∗/761 public void resetToComboHeader ( ) {762 i f ( timelineOptionsComboBox . ge tSe l e c t ed Index ( ) !=0) {763 // s o m e t h i n g d i f f e r e n t f r om t h e h e a d e r i s s e l e c t e d i n t h e

combo , b u t now t h e u s e r m a n u a l l y c h a n g e t h e v i e w .764 timelineOptionsComboBox . s e tSe l e c t ed Index (0) ;765 }766 }767768 /∗∗769 ∗ @r e t u r n770 ∗/771 public long getStartEpochFromSpinners ( ) {772 return startDateTimeSpinnersPanel . getTime ( ) ;773 }774775 /∗∗776 ∗ @r e t u r n777 ∗/778 public long getEndEpochFromSpinners ( ) {779 return endDateTimeSpinnersPanel . getTime ( ) ;780 }781782 /∗∗783 ∗ @r e t u r n784 ∗/785 public JComboBox getTimelineOptionsComboBox ( ) {786 return timelineOptionsComboBox ;787 }788789 /∗∗790 ∗ @r e t u r n791 ∗/792 public JTextField ge tF i l t e rText ( ) {793 return f i l t e r T e x t ;794 }795796 /∗∗797 ∗ @r e t u r n798 ∗/799 public CommandTableView getCommandTableView ( ) {800 return commandTableView ;801 }802803 /∗∗804 ∗ @r e t u r n805 ∗/806 public TimeLineGraphicView getGraphicView ( ) {807 return graphicView ;808 }809810811 /∗∗

Page 334: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

324 Appendix C - Source Code

812 ∗ @r e t u r n813 ∗/814 public JButton getScheduleButton ( ) {815 return scheduleButton ;816 }817818819 /∗∗820 ∗ @r e t u r n821 ∗/822 public JMenuItem getNewGsMenuItem () {823 return newGsMenuItem ;824 }825826827 /∗∗828 ∗ @r e t u r n829 ∗/830 public JButton getPassWindowButton ( ) {831 return passWindowButton ;832 }833834835 /∗∗836 ∗ @r e t u r n837 ∗/838 public PassesTableView getPassesTableView ( ) {839 return passesTableView ;840 }841842843 /∗∗844 ∗ @r e t u r n845 ∗/846 public JMenu getEditGsSubMenu ( ) {847 return editGsSubMenu ;848 }849850 /∗∗851 ∗ @r e t u r n852 ∗/853 public JMenuItem getTleMenuItem () {854 return tleMenuItem ;855 }856857858 /∗∗859 ∗ @r e t u r n860 ∗/861 public JMenuItem getDateFormatMenuItem () {862 return dateFormatMenuItem ;863 }864865866 /∗∗867 ∗ @r e t u r n868 ∗/869 public TimeLineControl ler g e tCont r o l l e r ( ) {870 return c o n t r o l l e r ;871 }872873874 /∗∗875 ∗ @r e t u r n876 ∗/877 public JMenuItem getExitMenuItem () {878 return exitMenuItem ;879 }880881882 /∗∗883 ∗ @r e t u r n884 ∗/885 public JMenuItem getLogoutMenuItem () {886 return logoutMenuItem ;887 }888889 /∗∗890 ∗ @r e t u r n891 ∗/892 public JMenuItem getStateColoringMenuItem () {893 return stateColoringMenuItem ;894 }895896897 /∗∗898 ∗ @r e t u r n

Page 335: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.1 MPS Source Sode 325

899 ∗/900 public DateTimeSpinnersPanel getStartDateTimeSpinnersPanel ( ) {901 return startDateTimeSpinnersPanel ;902 }903904905 /∗∗906 ∗ @r e t u r n907 ∗/908 public DateTimeSpinnersPanel getEndDateTimeSpinnersPanel ( ) {909 return endDateTimeSpinnersPanel ;910 }911912913 /∗∗914 ∗ @r e t u r n915 ∗/916 public JMenuItem getPreDefinedBlocksMenuItem () {917 return preDefinedBlocksMenuItem ;918 }919920921 /∗∗922 ∗ @r e t u r n923 ∗/924 public JRadioButtonMenuItem getGuiUpdateOnRadioButtonMenuItem () {925 return guiUpdateOnRadioButtonMenuItem ;926 }927928929 /∗∗930 ∗ @r e t u r n931 ∗/932 public JRadioButtonMenuItem getGuiUpdateOffRadioButtonMenuItem () {933 return guiUpdateOffRadioButtonMenuItem ;934 }935936937 /∗∗938 ∗ @r e t u r n939 ∗/940 public JMenuItem getGuiUpdateIntervalMenuItem () {941 return guiUpdateIntervalMenuItem ;942 }943944945 /∗∗946 ∗ @r e t u r n947 ∗/948 public JMenuItem getCreateUserMenuItem () {949 return createUserMenuItem ;950 }951952953 /∗∗954 ∗ @r e t u r n955 ∗/956 public JMenuItem getEditUserMenuItem () {957 return editUserMenuItem ;958 }959960 /∗∗961 ∗ @r e t u r n962 ∗/963 public JCheckBox getAllConnectionsCheckBox ( ) {964 return allConnectionsCheckBox ;965 }966967 /∗∗968 ∗ @r e t u r n969 ∗/970 public JCheckBox getCommandsToPassCheckBox ( ) {971 return commandsToPassCheckBox ;972 }973974 /∗∗975 ∗ @r e t u r n976 ∗/977 public JCheckBox getPassToCommandsCheckBox ( ) {978 return passToCommandsCheckBox ;979 }980981 /∗∗982 ∗ @r e t u r n983 ∗/984 public JMenuItem getAboutMenuItem () {985 return aboutMenuItem ;

Page 336: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

326 Appendix C - Source Code

986 }987988 public JMenuItem getPreschedulingMenuItem () {989 return preschedulingMenuItem ;990 }991992 }

Page 337: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 327

.2 Common Source Code

.2.1 CommandType.java

1 package common . command ;23 import java . i o . S e r i a l i z a b l e ;4 import java . u t i l . ArrayList ;56 import org . simpleframework . xml . Attr ibute ;7 import org . simpleframework . xml . Element ;8 import org . simpleframework . xml . ElementList ;9

10 import common . command . con f i rmat ion . ConfirmationType ;11 import common . command . parameter . Parameter ;1213 public c lass CommandType implements S e r i a l i z a b l e {1415 @Attribute16 private Str ing name ;1718 @Attribute19 private int typeID ;2021 @Element22 private Str ing d e s c r i p t i on ;2324 @ElementList25 private ArrayList<ModuleID> l e g a l D e s t i n a t i o n s ;2627 @ElementList ( r equ i r ed=f a l s e )28 private ArrayList<Parameter> parameters ;2930 private ArrayList<ConfirmationType> l e g a l R e p l i e s ;3132 public CommandType( ) {3334 }3536 public CommandType( St r ing name , int typeID , St r ing de s c r ip t i on , ArrayList<

ModuleID> l e ga lDe s t i na t i on s , ArrayList<Parameter> parameters ){37 this . name = name ;38 this . typeID = typeID ;39 this . d e s c r i p t i on = de s c r i p t i on ;40 this . l e g a l D e s t i n a t i o n s = l e g a l D e s t i n a t i o n s ;41 this . parameters = parameters ;4243 }4445 public int getTypeID ( ) {46 return typeID ;47 }4849 public ArrayList<Parameter> getParameters ( ) {50 return parameters ;51 }5253 public ArrayList<ModuleID> ge tLega lDes t ina t i on s ( ) {54 return l e g a l D e s t i n a t i o n s ;55 }5657 public int getByteS ize ( ) {58 // C a l c u l a t e b y t e s i z e5960 return 0 ;61 }626364 public Str ing ge tDesc r ip t i on ( ) {65 return de s c r i p t i on ;66 }6768 public void s e tDe s c r i p t i on ( St r ing d e s c r i p t i on ) {69 this . d e s c r i p t i on = de s c r i p t i on ;70 }7172 public Str ing getName ( ) {73 return name ;74 }75 }

Page 338: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

328 Appendix C - Source Code

.2.2 Command.java

1 package common . command ;23 import java . i o . S e r i a l i z a b l e ;45 import common . except ions . I l l ega lParamete rExcept ion ;6 import common . except ions . UnknownCommandTypeException ;789 /∗∗

10 ∗ R e p r e s e n t s a Command i n an a b s t r a c t way . A m i s s i o n i s s u p p o s e d t o g e n e r a t e11 ∗ e x t e n t i o n s o f t h i s c l a s s t o p r o v i d e m i s s i o n s p e c i f i c commands .12 ∗13 ∗ @au t h o r Kenne t h A g e r s k o v J en s en , s 0 3 1 7 5 014 ∗ @au t h o r And r e a s And e r s e n Kjae r , s 0 3 2 1 0 315 ∗ @ v e r s i o n 1 . 016 ∗/1718 public abstract c lass Command implements S e r i a l i z a b l e , Comparable<Command> {192021 // The a v a i l a b l e s t a t e s o f a Command22 public stat ic f ina l int INITIAL COMMAND = 0;23 public stat ic f ina l int AWAITING PASS AND VERIFICATION = 1;24 public stat ic f ina l int AWAITING PASS = 2 ;25 public stat ic f ina l int AWAITING VERIFICATION = 3;26 public stat ic f ina l int SCHEDULED = 4;27 public stat ic f ina l int AWAITING USER ACTION = 5;28 public stat ic f ina l int BEING TRANSMITTED = 6;29 public stat ic f ina l int TRANSMITTED = 7;30 public stat ic f ina l int EXECUTED = 8;31 public stat ic f ina l int DELETED = 9;323334 // The ID o f t h e command35 private long commandID = −1L ;3637 // The b l o c k ID o f t h e command38 private long blockID = −1L ;3940 // The p a s s ID o f t h e command41 private long passID = −1L ;4243 // The c u r r e n t s t a t e o f t h e command44 private int s t a t e = −1;4546 // The t im e o f e x e c u t i o n − u s e −1 f o r a s s o on a s p o s s i b l e47 // O t h e r w i s e u s e a number i n m i l l i s e c o n d s48 private long timeOfExecution = −2L ;4950 // The p a r a m e t e r s o f t h e command51 private Str ing parameters ;5253 // True i f t h e u s e r h a s a s s i g n e d t h e command t o a p a s s54 private boolean userGivenPass ;555657 /∗∗58 ∗ Must b e c a l l e d b y any c l a s s t h a t e x t e n d s t h i s c l a s s59 ∗ @param p a r a m e t e r s The p a r a m t e r s o f t h e command60 ∗/61 public Command( ) {62 setPassID (−1) ;63 setCommandID(−1) ;64 }6566 /∗∗67 ∗ Used by MMC t o d e f i n e an u n i q u e command i d e n t i f i e r . <br>68 ∗ MCC w i l l o v e r r i d e any u s e r−d e f i n e d ID .69 ∗ @param commandID The u n i q u e command i d e n t i f i e r .70 ∗/71 public void setCommandID( long commandID){72 this . commandID = commandID ;73 }7475 /∗∗76 ∗ @r e t u r n The u n i q u e command i d e n f i f i e r .77 ∗/78 public long getCommandID () {79 return commandID ;80 }8182 /∗∗83 ∗ D e f i n e s t h e b l o c k ID o f a Command .84 ∗ @param b l o c k I D The command ’ s b l o c k I D

Page 339: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 329

85 ∗/86 public void setBlockID ( long blockID ){87 this . blockID = blockID ;88 }8990 /∗∗91 ∗ @r e t u r n The command ’ s b l o c k92 ∗/93 public long getBlockID ( ) {94 return blockID ;95 }9697 /∗∗98 ∗ D e f i n e s t h e command ’ s t im e o f e x e c u t i o n a t t h e s a t e l l i t e .99 ∗ @param t i m e O f E x e c u t i o n The t im e o f e x e c u t i o n i n m i l i s e c o n d s . <br>

100 ∗ −1 <=> i m m e d i a t e l y e x e c u t i o n when t h e command i s t r a n s m i t t e d .101 ∗/102 public void setTimeOfExecution ( long timeOfExecution ){103 this . t imeOfExecution = timeOfExecution ;104 }105106 /∗∗107 ∗ @r e t u r n The t im e o f e x e c u t i o n i n m i l i s e c o n d s .108 ∗/109 public long getTimeOfExecution ( ) {110 return timeOfExecution ;111 }112113 /∗∗114 ∗ D e f i n e s t h e p a r a m e t e r s o f t h e command .115 ∗ @param p a r a m e t e r s The p a r a m e t e r s o f t h e command . n u l l i f no p a r a m e t e r s .116 ∗/117 public void setParameters ( St r ing parameters ){118 this . parameters = parameters ;119 }120121 /∗∗122 ∗ @r e t u r n The p a r a m e t e r s o f t h e command .123 ∗/124 public Str ing getParameters ( ) {125 return parameters ;126 }127128 /∗∗129 ∗ Used by MCC t o d e f i n e t h e s t a t e o f a command .130 ∗ @param s t a t e Must b e one o f t h e s t a t i c s t a t e s f r om t h e Command c l a s s .131 ∗ @th r ow s I l l e g a l A r g u m e n t E x c e p t i o n i n c a s e o f an i l l e g a l s t a t e132 ∗/133 public void s e tS ta t e ( int s t a t e ){134 switch ( s t a t e ){135 case INITIAL COMMAND:136 case AWAITING PASS AND VERIFICATION:137 case AWAITING PASS:138 case AWAITING VERIFICATION:139 case SCHEDULED:140 case BEING TRANSMITTED:141 case TRANSMITTED:142 case EXECUTED:143 case AWAITING USER ACTION:144 case DELETED:145 break ;146 default :147 throw new I l l ega lArgumentExcept ion ( ” Inva l i d s t a t e ” ) ;148149 }150151 this . s t a t e = s ta t e ;152 }153154 /∗∗155 ∗ @r e t u r n The s t a t e o f t h e command156 ∗/157 public int getState ( ) {158 return s t a t e ;159 }160161 /∗∗162 ∗ D e f i n e s t h e p a s s o f a Command . −1 => no p a s s163 ∗ <br><br>164 ∗ MCC w i l l o v e r w r i d e t h i s v a l u e w i t h −1 when t h e Command i s i n s e r t e d .165 ∗ @param p a s s ID The p a s s i d o f t h e command166 ∗ @th r ow s I l l e g a l A r g u m e n t E x c e p t i o n I f p a s s i d < −1167 ∗/168 public void setPassID ( long passID ){169 i f ( passID < −1){170 throw new I l l ega lArgumentExcept ion ( ”Pass id < −1” ) ;171 }

Page 340: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

330 Appendix C - Source Code

172 this . passID = passID ;173 }174175 /∗∗176 ∗ @r e t u r n The p a s s o f t h e command . −1 i f no p a s s177 ∗/178 public long getPassID ( ) {179 return passID ;180 }181182 /∗∗183 ∗ D e f i n e s w h e t h e r a u s e r h a s a s s i g n e d a p a s s o r n o t184 ∗ <br><br>185 ∗ MCC w i l l o v e r w r i d e t h i s v a l u e w i t h f a l s e , when t h e Command i s i n s e r t e d .186 ∗ @param u s e r G i v e n P a s s True i f t h e u s e r h a s a s s i g n e d a p a s s187 ∗/188 public void setUserGivenPass (boolean userGivenPass ){189 this . userGivenPass = userGivenPass ;190 }191192 /∗∗193 ∗ @r e t u r n I f a p a s s i s u s e r g i v e n o r n o t .194 ∗/195 public boolean getUserGivenPass ( ) {196 return userGivenPass ;197 }198199 /∗∗200 ∗ @r e t u r n True i f two commands h a v e same i d201 ∗/202 public boolean equa l s ( Object command){203204 i f (command == null | | ! ( command instanceof Command) ){205 return fa l se ;206 }207208 return ( (Command) command) . commandID == commandID ;209 }210211212 /∗∗213 ∗ From t h e Compa r a b l e i n t e r f a c e214 ∗ <br><br>215 ∗ Makes i t p o s s i b l e t o s o r t commands b y t i m eO f E x e c u t i o n , i d216 ∗/217 public int compareTo (Command command){218219 i f (command == null ){220 throw new Nul lPointerExcept ion ( ) ;221 }222223 i f (command . equa l s (commandID) ){224 return 0 ;225 }226227 i f (command . timeOfExecution == timeOfExecution ){228 i f (commandID < command . commandID ){229 return −1;230 }231 else{232 return 1 ;233 }234 }235 else i f ( timeOfExecution < command . timeOfExecution ){236 return −1;237 }238 else{239 return 1 ;240 }241 }242243 /∗∗244 ∗ @r e t u r n True i f i t i s o k t o i n s e r t t h e command t o t h e d a t a b a s e − o t h e r w i s e

f a l s e245 ∗/246 public boolean readyForDatabase ( ) {247 i f (commandID == −1L | | s t a t e < 0 | | timeOfExecution < −1L){248 return fa l se ;249 }250251 return true ;252 }253254 /∗∗255 ∗ C l o n e s a command256 ∗ @param f a c t o r y A CommandFactory u s e d f o r c l o n i n g t h e command .257 ∗ @r e t u r n The ClonedCommand

Page 341: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 331

258 ∗ @th r ow s UnknownCommandTypeExcep t i on S h o u l d n e v e r h a p p en . Thrown i f t h eCommandFactory d o e s n o t know

259 ∗ t h e command t y p e .260 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n261 ∗/262 public Command cloneCommand(CommandFactory f a c to ry ) throws

UnknownCommandTypeException , I l l ega lParameterExcept ion{263 Command command = fac to ry . generateCommand ( parameters ) ;264 command . commandID = commandID ;265 command . blockID = blockID ;266 command . passID = passID ;267 command . s t a t e = s ta t e ;268 command . timeOfExecution = timeOfExecution ;269 command . parameters = new Str ing ( parameters ) ;270 command . userGivenPass = userGivenPass ;271 return command ;272 }273274 /∗∗275 ∗ Made f o r t e s t i n g − c om p a i r s a l l f i e l d s o f 2 Commands276 ∗ @param command The command t o b e c omp a i r e d w i t h277 ∗ @r e t u r n True i f a l l f i e l d s e q u a l s e a c h o t h e r − o t h e r w i s e f a l s e278 ∗/279 public boolean a l lF i e l d sEqua l s (Command command){280 i f (commandID != command . commandID | |281 blockID != command . blockID | |282 passID != command . passID | |283 s t a t e != command . s t a t e | |284 ! parameters . equa l s (command . parameters ) | |285 userGivenPass != command . userGivenPass286 ){287 return fa l se ;288 }289290 return true ;291 }292293 /∗∗294 ∗ Use r t o g e n e r a t e d e s c r i p t i o n s o f t h e Command s t a t e295 ∗ @param s t a t e t h e s t a t e t o b e d e s c r i p e d296 ∗ @r e t u r n A s t r i n g t h a t d e s c r i p e s t h e s t a t e297 ∗/298 public stat ic Str ing de s c r i p eS ta t e ( int s t a t e ){299 switch ( s t a t e ){300 case INITIAL COMMAND:301 return ” I n i t i a l command” ;302 case AWAITING PASS AND VERIFICATION:303 return ”Awaiting pass and v e r i f i c a t i o n ” ;304 case AWAITING PASS:305 return ”Awaiting pass ” ;306 case AWAITING VERIFICATION:307 return ”Awaiting v e r i f i c a t i o n ” ;308 case SCHEDULED:309 return ” Scheduled ” ;310 case AWAITING USER ACTION:311 return ”Awaiting user ac t i on ” ;312 case BEING TRANSMITTED:313 return ”Being transmitted ” ;314 case TRANSMITTED:315 return ”Transmitted” ;316 case EXECUTED:317 return ”Executed” ;318 case DELETED:319 return ” Deleted ” ;320 default :321 return ” Inva l i d s t a t e ” ;322 }323 }324325 /∗∗326 ∗ D e s r i p e s t h e s t a t e o f t h i s Command i n s t a n c e327 ∗ @r e t u r n328 ∗/329 public Str ing ge tS ta t eDesc r ip t i on ( ) {330 return de s c r i p eS ta t e ( s t a t e ) ;331 }332333334 /∗∗335 ∗ @r e t u r n The number o f b y t e s t o b e s e n t when t h e command i s t r a n s m i t t e d .336 ∗/337 public abstract int getByteS ize ( ) ;338339 /∗∗340 ∗ @r e t u r n The b y t e s t o b e t r a n s m i t t e d t o t h e s a t e l l i t e .341 ∗/342 public abstract byte [ ] toByteArray ( ) ;

Page 342: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

332 Appendix C - Source Code

343344 /∗∗345 ∗ @r e t u r n An u n i q u e i d e n t i f i e r f o r t h e command t y p e . <br>346 ∗ Must b e t h e same f o r e v e r y i n s t a n c e o f a g i v e n e x t e n s i o n o f t h e c l a s s .347 ∗/348 public abstract int getCommandTypeID ( ) ;349 }

Page 343: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 333

.2.3 DTUsat2Command.java

1 package common . command ;234 public c lass DTUsat2Command extends Command{56 private CommandType type ;7 private ModuleID moduleID ;8 private Object [ ] arguments ;9

10 public DTUsat2Command(CommandType type , ModuleID moduleID , Object [ ]arguments ) {

11 super ( ) ;1213 this . type = type ;14 this . moduleID = moduleID ;15 this . arguments = arguments ;1617 this . setParameters ( generateCommandDataString ( ) ) ;18 }1920 public Str ing generateCommandDataString ( ) {21 St r ing r e s u l t = type . getTypeID ( ) + ”−” + moduleID . name ( ) ;22 for ( Object a : arguments ) {23 r e s u l t += ”−” + a . toSt r ing ( ) ;24 }25 return r e s u l t ;26 }2728 @Override29 public int getByteS ize ( ) {30 return type . getByteS ize ( ) ;31 }3233 @Override34 public int getCommandTypeID ( ) {35 // TODO Auto−g e n e r a t e d me t hod s t u b36 return type . getTypeID ( ) ;37 }3839 @Override40 public byte [ ] toByteArray ( ) {41 // TODO Auto−g e n e r a t e d me t hod s t u b42 return null ;43 }4445 public Object [ ] getArguments ( ) {46 return arguments ;47 }4849 public ModuleID getDes t ina t i on ( ) {50 return moduleID ;51 }5253 public ModuleID getModuleID ( ) {54 return moduleID ;55 }5657 }

Page 344: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

334 Appendix C - Source Code

.2.4 DTUsat2CommandFactory.java

1 package common . command ;23 import java . u t i l . St r ingToken izer ;456 import common . command . parameter . BooleanParameter ;7 import common . command . parameter . DoubleParameter ;8 import common . command . parameter . IntParameter ;9 import common . command . parameter . ParameterType ;

10 import common . command . parameter . Str ingParameter ;11 import common . except ions . I l l ega lParamete rExcept ion ;12 import common . except ions . UnknownCommandTypeException ;1314 /∗∗15 ∗ Th i s i m p l e m e n t a t i o n o f a CommandFactory g e n e r a t e s commands f o r t h e DTUsat2

m i s s i o n16 ∗ f r om a s t r i n g g i v e n t o t h e o b j e c t . The s t r i n g c o n t a i n s m i s s i o n s p e c i f i c

i n f o r m a t i o n :17 ∗ <u l >18 ∗ < l i > The d e s t i n a t i o n o f t h e command t o b e c r e a t e d19 ∗ < l i > The command t y p e o f t h e command d e f i n i n g i t s s t r u c t u r e20 ∗ < l i > The a r g um e n t s o f t h e command t o b e c r e a t e d21 ∗ </u l >22 ∗ <br>23 ∗ @au t h o r M i c h a e l S o r e n s e n , s 0 5 2 6 8 324 ∗ @au t h o r Ma t h i a s Holm Ande r s en , s 0 5 2 7 6 125 ∗ @see mcc . s e r v e r . d a t a P r o c e s s i n g . CommandFactory . j a v a26 ∗ @see common . command . CommandType . j a v a27 ∗ @ v e r s i o n 1 . 0 , 0 6 / 2 7 / 0 828 ∗/29 public c lass DTUsat2CommandFactory implements CommandFactory{303132 /∗ ( non−J a v a d o c )33 ∗ @see mcc . s e r v e r . d a t a P r o c e s s i n g . CommandFactory#gene ra t eCommand ( j a v a . l a n g .

S t r i n g )34 ∗/35 public DTUsat2Command generateCommand ( St r ing commandData) throws

UnknownCommandTypeException , I l l ega lParamete rExcept ion {3637 // The t o k e n i z e r w i l l t o k e n i z e t o e l e m e n t s s e p e r a t e d b y ”−”38 Str ingToken izer t oken i z e r = new Str ingToken izer (commandData , ”−” ) ;3940 // Ge t s t h e command t y p e .41 int type = Int ege r . pa r s e In t ( t oken i z e r . nextToken ( ) ) ;42 // Lo o k s up t h e command t y p e i n t h e t im e l i n e mode l43 CommandType commandType = DTUsat2CommandTypeMap . ge t In s tance ( ) . getCommandType

( type ) ;44 i f (commandType == null ) throw new UnknownCommandTypeException ( ”Unknown

commandtype id : ” + type ) ;4546 // Ge t s t h e d e s t i n a t i o n o f t h e command , and c h e c k s w h e t h e r i t i s a l e g a l

d e s t i n a t i o n a c c o r d i n g t o t h e command t y p e .47 St r ing d = token i z e r . nextToken ( ) ;48 ModuleID moduleID = getDes t ina t i on (commandType , d) ;49 // I f no l e g a l modu l e i d was f o u n d f o r t h e p a r s e d d e s t i n a t i o n , t h r ow

e x c e p t i o n50 i f ( moduleID == null ) throw new I l l ega lArgumentExcept ion ( ” I l l e g a l

d e s t i na t i on o f CommandType ” + type ) ;5152 // Argumen t p a r s i n g53 int i = 0 ;54 int expectedNoOfArguments = commandType . getParameters ( ) . s i z e ( ) ;55 Object [ ] args = new Object [ expectedNoOfArguments ] ;5657 while ( t oken i z e r . hasMoreElements ( ) ){5859 i f ( i > expectedNoOfArguments−1) throw new I l l ega lParamete rExcept ion (

”Too many arguments f o r the given type” ) ;6061 // Get t h e e x p e c t e d p a r am e t e r t y p e f r om t h e s t r u c t u r e o f t h e command

t y p e .62 ParameterType parameterType = commandType . getParameters ( ) . get ( i ) .

getParameterType ( ) ;6364 St r ing tok =”” ;6566 i f ( parameterType instanceof IntParameter ) {67 try {68 tok = token i z e r . nextToken ( ) ;6970 args [ i ] = In t ege r . pa r s e In t ( tok ) ;71

Page 345: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 335

72 int lower = ( ( IntParameter ) parameterType ) .getLowerLimit ( ) ;

73 int upper = (( IntParameter ) parameterType ) .getUpperLimit ( ) ;

74 i f ( In t ege r . pa r s e In t ( tok ) < lower | | In t ege r . pa r s e In t( tok ) > upper )

75 throw new I l l ega lParamete rExcept ion ( ”I l l e g e a l parameter \” ”+ tok + ”\” −Must be between ” + lower + ” and ” +upper ) ;

767778 } catch ( NumberFormatException e ) {79 throw new I l l ega lParamete rExcept ion ( ”

I l l e g e a l parameter \” ”+ tok + ”\” −In t ege r parameter expected . ” ) ;

80 }8182 } else i f ( parameterType instanceof DoubleParameter ) {8384 try {85 tok = token i z e r . nextToken ( ) ;8687 args [ i ] = Double . parseDouble ( tok ) ;8889 double lower = ( ( DoubleParameter ) parameterType ) .

getLowerLimit ( ) ;90 double upper = (( DoubleParameter ) parameterType ) .

getUpperLimit ( ) ;91 i f ( Double . parseDouble ( tok ) < lower | | Double .

parseDouble ( tok ) > upper )92 throw new I l l ega lParamete rExcept ion ( ”

I l l e g e a l parameter \” ”+ tok + ”\” −Must be between ” + lower + ” and ” +upper ) ;

9394 } catch ( NumberFormatException e ) {95 throw new I l l ega lParamete rExcept ion ( ”

I l l e g e a l parameter \” ”+ tok + ”\” −Double parameter expected . ” ) ;

96 }9798 } else i f ( parameterType instanceof BooleanParameter ) {99 try {

100 tok = token i z e r . nextToken ( ) ;101 args [ i ] = In t ege r . pa r s e In t ( tok ) ;102 // Bo o l e a n i s d e f i n e d b y 0 o r 1103 i f ( ! ( In t ege r . pa r s e In t ( tok )==0 | | In t ege r . pa r s e In t

( tok )==1) )104 throw new I l l ega lParamete rExcept ion ( ”

I l l e g e a l boolean parameter \” ”+ tok +”\” − expected 0 or 1 . ” ) ;

105106 } catch ( NumberFormatException e ) {107 throw new I l l ega lParamete rExcept ion ( ”

I l l e g e a l parameter \” ”+ tok + ”\” −i n t e g e r parameter expected . ” ) ;

108 }109110 } else i f ( parameterType instanceof StringParameter ) {111 args [ i ] = token i z e r . nextToken ( ) ;112 } else {113 throw new I l l ega lArgumentExcept ion ( ”Parameter type not

contained in f a c t o ry ” ) ;114 }115116 i ++;117 }118119 i f ( i !=expectedNoOfArguments ) throw new I l l ega lParamete rExcept ion ( ”Too few

arguments . Expected number : ” + expectedNoOfArguments ) ;120121122 return new DTUsat2Command(commandType , moduleID , args ) ;123 }124125 /∗∗126 ∗ Ma t c h e s t h e l e g a l d e s t i n a t i o n s f o r t h e command t y p e w i t h t h e d e s t i n a t i o n

g i v e n .127 ∗ Re t u r n s t h e modu l e i d o f t h e l e g a l d e s t i n a t i o n t h e command i s g o i n g t o .128 ∗ @param commandType The command t y p e o f t h e command129 ∗ @param d e s t i n a t i o n The d e s t i n a t i o n b e i n g p a r s e d t o a modu l e i d130 ∗ @r e t u r n The l e g a l modu l e i d o f t h e l e g a l d e s t i n a t i o n131 ∗/132 private ModuleID getDes t ina t i on (CommandType commandType , St r ing de s t i na t i on ) {133 for ( ModuleID d : commandType . ge tLega lDes t ina t i on s ( ) ) {134 i f (d . name ( ) . equa l s ( d e s t i na t i on ) ) return d ;

Page 346: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

336 Appendix C - Source Code

135136 }137 return null ;138 }139140 }

Page 347: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 337

.2.5 DTUsat2CommandTypeMap.java

1 package common . command ;23 import java . i o . F i l e ;4 import java . u t i l . HashMap ;56 import org . simpleframework . xml . S e r i a l i z e r ;7 import org . simpleframework . xml . load . P e r s i s t e r ;89 public c lass DTUsat2CommandTypeMap {

1011 private HashMap<Integer , CommandType> commandTypeMap ;1213 private stat ic vo lat i l e DTUsat2CommandTypeMap INSTANCE;1415 // P r o t e c t e d c o n s t r u c t o r i s s u f f i c i e n t t o s u p p r e s s u n a u t h o r i z e d c a l l s t o t h e

c o n s t r u c t o r16 protected DTUsat2CommandTypeMap( ) {1718 try {19 loadCommandTypesFromXML () ;20 } catch ( Exception e ) {21 // TODO Auto−g e n e r a t e d c a t c h b l o c k22 e . pr intStackTrace ( ) ;23 }2425 }2627 public stat ic DTUsat2CommandTypeMap get In s tance ( ) {28 synchronized (DTUsat2CommandTypeMap . c lass ) {29 i f (INSTANCE == null )30 INSTANCE = new DTUsat2CommandTypeMap( ) ;31 }32 return INSTANCE;3334 }3536 private void loadCommandTypesFromXML () throws Exception {3738 S e r i a l i z e r s e r i a l i z e r = new P e r s i s t e r ( ) ;39 F i l e f i l e = new F i l e ( getClas s ( ) . getResource ( ”/ r e s ou r c e s /commandtypes/

CommandTypeMap . xml” ) . toURI ( ) ) ;40 DTUsat2CommandTypeXMLFile loadedMap = s e r i a l i z e r . read (

DTUsat2CommandTypeXMLFile . class , f i l e ) ;41 commandTypeMap = loadedMap . getMap ( ) ;42 }4344 public CommandType getCommandType( int typeno ) {45 return commandTypeMap . get ( typeno ) ;46 }4748 public HashMap<Integer , CommandType> getCommandTypeMap ( ) {49 return commandTypeMap ;50 }515253 }

Page 348: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

338 Appendix C - Source Code

.2.6 DTUsat2CommandTypeXMLFile.java

1 package common . command ;23 import java . u t i l . ArrayList ;4 import java . u t i l . HashMap ;56 import org . simpleframework . xml . ElementList ;7 import org . simpleframework . xml . Root ;8 import org . simpleframework . xml . load . Commit ;9

10 @Root11 public c lass DTUsat2CommandTypeXMLFile {1213 private stat ic HashMap<Integer , CommandType> map = new HashMap<Integer ,

CommandType>() ;1415 @ElementList16 private ArrayList<CommandType> commandTypes ;1718 public DTUsat2CommandTypeXMLFile ( ) {19 commandTypes = new ArrayList<CommandType>() ;20 }2122 @Commit23 private void createHashMap ( ) {24 for (CommandType ct : commandTypes ) {25 map . put ( ct . getTypeID ( ) , ct ) ;26 }27 }2829 public int s i z e ( ) {30 return commandTypes . s i z e ( ) ;31 }3233 public HashMap<Integer , CommandType> getMap ( ) {34 return map ;35 }363738 public ArrayList<CommandType> getCommandTypes ( ) {39 return commandTypes ;40 }414243 }

Page 349: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 339

.2.7 Argument.java

1 package common . command ;23 public c lass Argument {45 private Object value ;67 public Argument ( Object value ){8 this . va lue = value ;9 }

1011 public boolean i s I n t ( ) {12 return ( value instanceof In t ege r ) ? true : f a l s e ;13 }1415 public boolean i sBoo lean ( ) {16 return ( value instanceof Boolean ) ? true : f a l s e ;17 }1819 public boolean i s S t r i n g ( ) {20 return ( value instanceof Str ing ) ? true : f a l s e ;21 }22 }

Page 350: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

340 Appendix C - Source Code

.2.8 ModuleID.java

1 package common . command ;23 import java . i o . S e r i a l i z a b l e ;45 public enum ModuleID implements S e r i a l i z a b l e {67 GND, // Ground Se gmen t8 PLM, // P l a t f o r m Manager9 HOC, // H o u s e k e e p i n g C e n t e r

10 RAD, // Rad i o ( i n c l u d i n g s c h e d u l e r )11 FLA, // F l a s h C o n t r o l12 OBC, // Onboard Compu t e r S y s t em13 EPS, // E l e c t r i c a l Power S y s t em14 COM, // Commun i c a t i on S y s t em15 ACS, // A t t i t u d e C o n t r o l S y s t em16 PPL, // Pr ima r y P a y l o a d S y s t em17 CAM; // P i c o Camera S y s t em1819 public Str ing toSt r ing ( ) {20 return name ( ) ;21 }22 }

Page 351: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 341

.2.9 CommandFactory.java

1 package common . command ;23456 import common . except ions . I l l ega lParamete rExcept ion ;7 import common . except ions . UnknownCommandTypeException ;89 /∗∗

10 ∗ I n t e r f a c e f o r a p l u g i n t h a t g e n e r a t e s Commands . A l l o w s MCC t o g e n e r a t e i n s t a n c e s11 ∗ o f t h e sub−i m p l e m e n t a t i o n s o f t h e Command c l a s s w i t h o u t k n ow i n g wh e r e t h e c o d e12 ∗ i s l o c a t e d .13 ∗ <br><br>14 ∗ Must b e im p l em e n t e d b y e a c h m i s s i o n15 ∗16 ∗ @au t h o r Kenne t h A g e r s k o v J en s en , s 0 3 1 7 5 017 ∗ @au t h o r And r e a s And e r s e n Kjae r , s 0 3 2 1 0 318 ∗ @ v e r s i o n 1 . 019 ∗/20 public interface CommandFactory {2122 /∗∗23 ∗ G e n e r a t e s a Command b a s e d on i t s t y p e and p a r a m e t e r s24 ∗ @param commandType The t y p e o f t h e Command − e a c h command i m p l e m e n t a t i o n

s h o u l d h a v e i t s own t y p e25 ∗ @param p a r a m e t e r s The p a r a m e t e r s o f t h e Command26 ∗ @r e t u r n The g e n e r a t e d command27 ∗ @th r ow s UnknownCommandTypeExcep t i on I f t h e Command t y p e i s unknown , o r i n any

o t h e r c a s e s wh e r e28 ∗ i t i s i m p o s s i b l e t o g e n e r a t e t h e Command .29 ∗ @th r ow s I l l e g a l P a r a m e t e r E x c e p t i o n30 ∗/31 public Command generateCommand ( St r ing parameters ) throws

UnknownCommandTypeException , I l l ega lParamete rExcept ion ;3233 // /∗∗34 // ∗ Th i s me t hod i s n o t d i r e c t l y u s e d b y MCC. I t g i v e s a p o s s i b i l i t y o f

e x p l a n i n g t h e m i s s i o n s p e c i f i c p a r am e t e r s y n t a x .35 // ∗ @param commandType The p a r a m e t e r s o f t h i s command t y p e i s t o b e d e s c r i p e d36 // ∗ @r e t u r n A t e x t d e s c r i p t i o n f o r human r e a d e r s .37 // ∗ @th r ow s UnknownCommandTypeExcep t i on I f t h e command t y p e i s unknown38 // ∗/39 // p u b l i c S t r i n g g e t P a r a m a t e r I n f o ( i n t commandType ) t h r o w s

UnknownCommandTypeExcep t i on ;40 //41 // /∗∗42 // ∗ Th i s me t hod i s n o t d i r e c t l y u s e d b y MCC. I t g i v e s a p o s s i b i l i t y o f g i v e i n g

i n f o a b o u t t h e command t y p e .43 // ∗ @param commandType The t y p e t o b e d e s c r i p e d44 // ∗ @r e t u r n A t e x t d e s c r i p t i o n f o r human r e a d e r s .45 // ∗ @th r ow s UnknownCommandTypeExcep t i on I f t h e command t y p e i s unknown46 // ∗/47 // p u b l i c S t r i n g g e t T y p e I n f o ( i n t commandType ) t h r o w s UnknownCommandTypeExcep t i on ;48 }

Page 352: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

342 Appendix C - Source Code

.2.10 ConfirmationCode.java

1 package common . command . con f i rmat ion ;23 import java . i o . S e r i a l i z a b l e ;45 public c lass ConfirmationCode implements S e r i a l i z a b l e {67 public stat ic f ina l int EXECUTION CORRECT = 101;8 public stat ic f ina l int EXECUTION FAIL = 201;9 public stat ic f ina l int COMMANDCORRUPTED = 202;

10 public stat ic f ina l int REPLY CORRUPTED = 301;111213 }

Page 353: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 343

.2.11 ConfirmationType.java

1 package common . command . con f i rmat ion ;23 import java . i o . S e r i a l i z a b l e ;4 import java . u t i l . ArrayList ;56 import common . command . parameter . Parameter ;789 public c lass ConfirmationType implements S e r i a l i z a b l e {

1011 private Str ing name ;12 private int typeID ;13 private ArrayList<Parameter> parameters ;141516 public ConfirmationType ( ) {1718 }1920 }

Page 354: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

344 Appendix C - Source Code

.2.12 Confirmation.java

1 package common . command . con f i rmat ion ;23 import java . i o . S e r i a l i z a b l e ;45 public c lass Confirmation implements S e r i a l i z a b l e {67 private long timeStamp ;8 private ConfirmationType type ;9 private long commandID ;

10 private Object [ ] r e s u l t s ;111213 public Confirmation ( ConfirmationType type , long timeStamp ){14 this . timeStamp = timeStamp ;15 this . type = type ;16 }1718 }

Page 355: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 345

.2.13 CommandTypeSetupController.java

1 package common . command . generat ion ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . u t i l . ArrayList ;6 import java . u t i l . Arrays ;78 import common . command .CommandType ;9 import common . command . ModuleID ;

10 import common . command . parameter . Parameter ;1112 public c lass CommandTypeSetupController implements Act ionL i s t ener {1314 private CommandTypeSetup view ;1516 public CommandTypeSetupController (CommandTypeSetup view ) {17 this . view = view ;1819 }2021 @Override22 public void act ionPerformed ( ActionEvent ae ) {232425 i f ( ae . getSource ( ) . equa l s ( view . getAddParameterButton ( ) ) ) {2627 new ParameterGeneratorPanel ( view ) ;2829 } else i f ( ae . getSource ( ) . equa l s ( view . getCreateCommandTypeButton ( ) ) )

{3031 St r ing name = view . getNameTextField ( ) . getText ( ) ;32 St r ing d e s c r i p t i on = view . getDescr ipt ionEditorPane ( ) . getText

( ) ;33 Object [ ] d e s t i n a t i on s = view . g e tLega lDe s t i na t i on sL i s t ( ) .

ge tSe l e c t edVa lues ( ) ;34 // n e e d s t o b e c o n v e r t e d t o an A r r a y L i s t :35 ArrayList<ModuleID> destArrayLi s t = new ArrayList<ModuleID

>() ;36 for ( int i = 0 ; i<=de s t i n a t i on s . length −1; i++) {37 destArrayLi s t . add ( ( ModuleID ) d e s t i n a t i on s [ i ] ) ;38 }3940 CommandType ct = new CommandType(name , view . get Id ( ) ,

de s c r ip t i on , destArrayList , view . getParamters ( ) ) ;414243 view . getDtuSat2CommandEditor ( ) . getCommandTypes ( ) . add ( ct ) ;44 view . getDtuSat2CommandEditor ( ) . updateLabel ( ) ;45 view . d i spose ( ) ;464748 }4950 }5152 }

Page 356: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

346 Appendix C - Source Code

.2.14 DTUsat2CommandTypeEditor.java

1 package common . command . generat ion ;23 import java . awt . BorderLayout ;4 import java . awt . Dimension ;5 import java . u t i l . ArrayList ;67 import javax . swing . JButton ;8 import javax . swing . JFrame ;9 import javax . swing . JLabel ;

10 import javax . swing . JScro l lPane ;11 import javax . swing . JToolBar ;12 import javax . swing . UIManager ;1314 import common . command .CommandType ;15 import common . command . DTUsat2CommandTypeXMLFile ;16 import common . command . ModuleID ;17 import common . command . parameter . Parameter ;1819 public c lass DTUsat2CommandTypeEditor extends JFrame {202122 public stat ic void main ( St r ing [ ] args ) {23 new DTUsat2CommandTypeEditor ( ) ;24 }252627 private JButton newButton ;28 private JButton openButton ;29 private JButton saveButton ;30 private JButton createButton ;3132 private JLabel commandTypeLabel ;3334 private DTUsat2CommandTypeXMLFile commandTypeMap = new

DTUsat2CommandTypeXMLFile ( ) ;35 private Str ing f i l e L o c a t i o n ;3637 private DTUsat2CommandTypeEditorController c o n t r o l l e r ;3839 public DTUsat2CommandTypeEditor ( ) {4041 c o n t r o l l e r = new DTUsat2CommandTypeEditorController ( this ) ;42 commandTypeMap = new DTUsat2CommandTypeXMLFile ( ) ;4344 // LOOK AND FEEL45 try{46 UIManager . setLookAndFeel ( UIManager .

getSystemLookAndFeelClassName ( ) ) ;47 }catch ( Exception ex ) {4849 }5051 this . s e t T i t l e ( ”DTUsat2 Command Type Editor ” ) ;52 this . s e tDe fau l tCloseOperat ion ( JFrame .EXIT ON CLOSE) ;5354 JToolBar toolBar = new JToolBar ( ”Toolbar ” ) ;5556 newButton = new JButton ( ”New” ) ;57 toolBar . add ( newButton ) ;58 openButton = new JButton ( ”Open” ) ;59 toolBar . add ( openButton ) ;60 saveButton = new JButton ( ”Save” ) ;61 toolBar . add ( saveButton ) ;62 createButton = new JButton ( ” Create new Command Type” ) ;63 toolBar . add ( createButton ) ;6465 this . add ( toolBar , BorderLayout .PAGE START) ;6667 commandTypeLabel = new JLabel ( ) ;68 commandTypeLabel . s e tVer t i ca lA l ignment ( JLabel .TOP) ;6970 JScro l lPane s c ro l lPane = new JScro l lPane ( commandTypeLabel ) ;71 s c ro l lPane . s e t P r e f e r r e d S i z e (new Dimension (510 ,300) ) ;72 this . add ( scro l lPane , BorderLayout .CENTER) ;737475 // L i s t e n e r e s76 newButton . addAct ionListener ( c o n t r o l l e r ) ;77 openButton . addAct ionListener ( c o n t r o l l e r ) ;78 saveButton . addAct ionListener ( c o n t r o l l e r ) ;79 createButton . addAct ionListener ( c o n t r o l l e r ) ;808182

Page 357: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 347

83 this . pack ( ) ;84 this . s e t V i s i b l e ( true ) ;858687 }888990 public void updateLabel ( ) {91 St r ing r e s u l t = ”” ;92 i f (commandTypeMap . s i z e ( ) !=0) {93 r e s u l t = ”<html><table><tr><td>Type</td><td>Name</td><td>

Descr ipt ion </td><td>Dest inat ions </td><td>Paramteres </td></tr>” ;

9495 for (CommandType ct : commandTypeMap . getCommandTypes ( ) ) {96 r e s u l t += ”<tr><td va l i gn=top width=30>” + ct .

getTypeID ( ) + ”</td><td va l i gn=top width=120>”+ ct . getName ( ) + ”</td><td va l i gn=top width=170>” + ct . g e tDesc r ip t i on ( ) + ”</td><tdva l i gn=top width=90>” ;

9798 for ( ModuleID d : ct . g e tLega lDes t ina t i ons ( ) ) {99 r e s u l t += d + ” ” ;

100 }101 r e s u l t += ”</td><td va l i gn=top width=90>” ;102 for ( Parameter p : ct . getParameters ( ) ) {103 r e s u l t+= p . getName ( ) + ” ” ;104 }105 r e s u l t+= ”</td></tr>” ;106 }107108 r e s u l t += ”</table ></html>” ;109110 }111 commandTypeLabel . setText ( r e s u l t ) ;112 commandTypeLabel . r epa in t ( ) ;113 this . r epa in t ( ) ;114 }115116117 public JButton getOpenButton ( ) {118 return openButton ;119 }120121122 public JButton getSaveButton ( ) {123 return saveButton ;124 }125126127 public JButton getCreateButton ( ) {128 return createButton ;129 }130131132 public ArrayList<CommandType> getCommandTypes ( ) {133 return commandTypeMap . getCommandTypes ( ) ;134 }135136137 public void setCommandTypeMap(DTUsat2CommandTypeXMLFile commandTypeMap) {138 this . commandTypeMap = commandTypeMap ;139 }140141142 public Str ing ge tF i l eLoca t i on ( ) {143 return f i l e L o c a t i o n ;144 }145146147 public void s e tF i l eLoca t i on ( St r ing f i l e L o c a t i o n ) {148 this . f i l e L o c a t i o n = f i l e L o c a t i o n ;149 }150151152 public DTUsat2CommandTypeXMLFile getCommandTypeMap ( ) {153 return commandTypeMap ;154 }155156157 public JButton getNewButton ( ) {158 return newButton ;159 }160161162163

Page 358: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

348 Appendix C - Source Code

164 }

Page 359: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 349

.2.15 DTUsat2CommandTypeEditorController.java

1 package common . command . generat ion ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;5 import java . i o . F i l e ;6 import java . u t i l . ArrayList ;78 import javax . swing . ∗ ;9 import javax . swing . f i l e c h o o s e r . ∗ ;

10111213 import javax . swing . JFi leChooser ;14 import javax . swing . f i l e c h o o s e r . F i l e F i l t e r ;1516 import org . simpleframework . xml . S e r i a l i z e r ;17 import org . simpleframework . xml . load . P e r s i s t e r ;1819 import common . command .CommandType ;20 import common . command . DTUsat2CommandTypeXMLFile ;21 import common . command . ModuleID ;22 import common . command . parameter . Parameter ;2324 public c lass DTUsat2CommandTypeEditorController implements Act ionL i s t ener {252627 private DTUsat2CommandTypeEditor view ;2829 public DTUsat2CommandTypeEditorController (DTUsat2CommandTypeEditor view ) {3031 this . view = view ;3233 }3435 @Override36 public void act ionPerformed ( ActionEvent ae ) {3738 i f ( ae . getSource ( ) . equa l s ( view . getNewButton ( ) ) ) {39 view . setCommandTypeMap(new DTUsat2CommandTypeXMLFile ( ) ) ;40 view . updateLabel ( ) ;4142 } i f ( ae . getSource ( ) . equa l s ( view . getOpenButton ( ) ) ) {4344 JFi leChooser f i l e c h o o s e r = new JFi leChooser ( ) ;45 f i l e c h o o s e r . addChoosab l eF i l eF i l t e r (new XMLfilter ( ) ) ;46 f i l e c h o o s e r . s e tAccep tA l lF i l eF i l t e rUsed ( f a l s e ) ;47 int returnVal = f i l e c h o o s e r . showOpenDialog ( view ) ;48 i f ( returnVal == JFi leChooser .APPROVE OPTION) {49 F i l e f i l e = f i l e c h o o s e r . g e t S e l e c t e d F i l e ( ) ;5051 S e r i a l i z e r s e r i a l i z e r = new P e r s i s t e r ( ) ;52 try {53 DTUsat2CommandTypeXMLFile loadedMap =

s e r i a l i z e r . read (DTUsat2CommandTypeXMLFile . class , f i l e ) ;

5455 view . setCommandTypeMap( loadedMap ) ;56 view . updateLabel ( ) ;5758 } catch ( Exception e ) {59 // TODO Auto−g e n e r a t e d c a t c h b l o c k60 e . pr intStackTrace ( ) ;61 }6263 }64656667 } else i f ( ae . getSource ( ) . equa l s ( view . getSaveButton ( ) ) ) {686970 JFi leChooser f i l e c h o o s e r = new JFi leChooser ( ) ;71 f i l e c h o o s e r . addChoosab l eF i l eF i l t e r (new XMLfilter ( ) ) ;72 f i l e c h o o s e r . s e tAccep tA l lF i l eF i l t e rUsed ( f a l s e ) ;73 int returnVal = f i l e c h o o s e r . showSaveDialog ( view ) ;74 i f ( returnVal == JFi leChooser .APPROVE OPTION) {75 F i l e f i l e = f i l e c h o o s e r . g e t S e l e c t e d F i l e ( ) ;76 S e r i a l i z e r s e r i a l i z e r = new P e r s i s t e r ( ) ;77 // makes s u r e t o h a v e f i l e e x t e n s i o n78 i f ( f i l e . getName ( ) . l ength ( )<=4 | | ! f i l e . getName ( ) .

subs t r ing ( f i l e . getName ( ) . l ength ( )−4, f i l e .getName ( ) . l ength ( ) ) . equa l s ( ” . xml” ) ) f i l e=newF i l e ( f i l e . getAbsolutePath ( )+” . xml” ) ;

79 try {

Page 360: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

350 Appendix C - Source Code

8081 s e r i a l i z e r . wr i te ( view . getCommandTypeMap ( ) ,

f i l e ) ;8283 } catch ( Exception e ) {84 // TODO Auto−g e n e r a t e d c a t c h b l o c k85 e . pr intStackTrace ( ) ;86 }8788 }89909192 } else i f ( ae . getSource ( ) . equa l s ( view . getCreateButton ( ) ) ) {93 new CommandTypeSetup( view ) ;94 }9596 }9798 }99

100 c lass XMLfilter extends F i l e F i l t e r {101102 @Override103 public boolean accept ( F i l e f ) {104105 i f ( f . i sD i r e c t o r y ( ) ) {106 return true ;107 }108109110 St r ing extens ion = getExtens ion ( f ) ;111 i f ( extens ion != null ) {112 i f ( extens ion . equa l s ( ”xml” ) ) return true ;113 else return fa l se ;114 }115116 return fa l se ;117118119 }120121 public stat ic Str ing getExtens ion ( F i l e f ) {122 St r ing ext = null ;123 St r ing s = f . getName ( ) ;124 int i = s . la s t IndexOf ( ’ . ’ ) ;125126 i f ( i > 0 && i < s . l ength ( ) − 1) {127 ext = s . subs t r ing ( i +1) . toLowerCase ( ) ;128 }129 return ext ;130 }131132133 @Override134 public Str ing ge tDesc r ip t i on ( ) {135 return ”DTUsat2Command Map XML− f i l e ” ;136 }137138139140141 }

Page 361: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 351

.2.16 ParameterGeneratorController.java

1 package common . command . generat ion ;23 import java . awt . event . ActionEvent ;4 import java . awt . event . Act ionL i s t ener ;56 import common . command . parameter . BooleanParameter ;7 import common . command . parameter . DoubleParameter ;8 import common . command . parameter . IntParameter ;9 import common . command . parameter . Parameter ;

10 import common . command . parameter . Str ingParameter ;1112 public c lass ParameterGeneratorContro l ler implements Act ionL i s t ener {131415 private ParameterGeneratorPanel view ;1617 public ParameterGeneratorContro l ler ( ParameterGeneratorPanel view ) {1819 this . view = view ;2021 }2223 @Override24 public void act ionPerformed ( ActionEvent ae ) {2526 i f ( ae . getSource ( ) . equa l s ( view . getTypeComboBox ( ) ) ) {2728 St r ing se lectedType = ( Str ing ) view . getTypeComboBox ( ) .

ge tSe l ec tedI tem () ;2930 i f ( se lectedType . equa l s ( ” In t ege r ” ) | | se lectedType . equa l s ( ”

Double” ) ) {31 view . getTypeOptionsPanel ( ) . s e t V i s i b l e ( true ) ;3233 } else i f ( se lectedType . equa l s ( ” St r ing ” ) | | se lectedType .

equa l s ( ”Boolean” ) ) {34 view . getTypeOptionsPanel ( ) . s e t V i s i b l e ( f a l s e ) ;35 }363738 } else i f ( ae . getSource ( ) . equa l s ( view . getAddButton ( ) ) ) {3940 St r ing se lectedType = ( Str ing ) view . getTypeComboBox ( ) .

ge tSe l ec tedI tem () ;4142 St r ing name = view . getNameTextField ( ) . getText ( ) ;43 St r ing d e s c r i p t i on = view . getDescr ipt ionEditorPane ( ) . getText

( ) ;44 St r ing unit = view . getUnitTextFie ld ( ) . getText ( ) ;454647 i f ( se lectedType . equa l s ( ” In t ege r ” ) ) {48 int upper = Intege r . pa r s e In t ( view .

getUpperLimitTextField ( ) . getText ( ) ) ;49 int lower = Int ege r . pa r s e In t ( view .

getLowerLimitTextField ( ) . getText ( ) ) ;50 int de fau l tVa l = Int ege r . pa r s e In t ( view .

getDefau l tTextFie ld ( ) . getText ( ) ) ;51 int accuracy = Intege r . pa r s e In t ( view .

getAccuracyTextFie ld ( ) . getText ( ) ) ;5253 IntParameter intParam = new IntParameter ( unit , lower

, upper , de faultVal , accuracy ) ;5455 Parameter p = new Parameter (name , de s c r ip t i on ,

intParam ) ;5657 view . getCommandTypeGeneratorView ( ) . getParamters ( ) .

add (p) ;5859 } else i f ( se lectedType . equa l s ( ”Double” ) ) {60 double upper = Double . parseDouble ( view .

getUpperLimitTextField ( ) . getText ( ) ) ;61 double lower = Double . parseDouble ( view .

getLowerLimitTextField ( ) . getText ( ) ) ;62 double de fau l tVa l = Double . parseDouble ( view .

getDefau l tTextFie ld ( ) . getText ( ) ) ;63 double accuracy = Double . parseDouble ( view .

getAccuracyTextFie ld ( ) . getText ( ) ) ;6465 DoubleParameter doubleParam = new DoubleParameter (

unit , lower , upper , de faultVal , accuracy ) ;66

Page 362: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

352 Appendix C - Source Code

67 Parameter p = new Parameter (name , de s c r ip t i on ,doubleParam ) ;

68 view . getCommandTypeGeneratorView ( ) . getParamters ( ) .add (p) ;

6970 } else i f ( se lectedType . equa l s ( ”Boolean” ) ) {7172 Parameter p = new Parameter (name , de s c r ip t i on , new

BooleanParameter ( ) ) ;73 view . getCommandTypeGeneratorView ( ) . getParamters ( ) .

add (p) ;74 } else i f ( se lectedType . equa l s ( ” St r ing ” ) ) {7576 Parameter p = new Parameter (name , de s c r ip t i on , new

StringParameter ( ) ) ;77 view . getCommandTypeGeneratorView ( ) . getParamters ( ) .

add (p) ;78 }7980 view . getCommandTypeGeneratorView ( ) . getParamtersTable ( ) .

r epa in t ( ) ;81 view . d i spose ( ) ;8283 }8485 }8687 }

Page 363: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 353

.2.17 ParameterGeneratorPanel.java

1 package common . command . generat ion ;23 import java . awt . Dimension ;4 import java . awt . FlowLayout ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;7 import java . awt . I n s e t s ;89 import javax . swing . JButton ;

10 import javax . swing . JComboBox ;11 import javax . swing . JDialog ;12 import javax . swing . JEditorPane ;13 import javax . swing . JLabel ;14 import javax . swing . JPanel ;15 import javax . swing . JScro l lPane ;16 import javax . swing . JTextArea ;17 import javax . swing . JTextField ;1819 public c lass ParameterGeneratorPanel extends JDialog {2021 private JTextField nameTextField ;22 private JEditorPane descr ipt ionEdi torPane ;23 private JComboBox typeComboBox ;24 private JPanel typeOptionsPanel ;2526 // i n t / d o u b l e t y p e o p t i o n s :27 private JTextField uni tTextFie ld ;28 private JTextField lowerLimitTextFie ld ;29 private JTextField upperLimitTextField ;30 private JTextField de fau l tTextF i e ld ;31 private JTextField accuracyTextFie ld ;3233 private JButton addButton ;3435 private ParameterGeneratorContro l ler c o n t r o l l e r ;3637 private CommandTypeSetup commandTypeGeneratorView ;3839 public ParameterGeneratorPanel (CommandTypeSetup view ) {4041 this . setLayout (new FlowLayout ( FlowLayout .LEADING) ) ;42 this . s e t T i t l e ( ”Add parameter ” ) ;4344 commandTypeGeneratorView = view ;4546 c o n t r o l l e r = new ParameterGeneratorContro l ler ( this ) ;4748 JPanel panel = new JPanel ( ) ;49 panel . setLayout (new GridBagLayout ( ) ) ;50 GridBagConstraints c = new GridBagConstraints ( ) ;51 c . anchor = GridBagConstraints .LINE START;5253 c . i n s e t s = new I n s e t s (5 , 2 , 5 , 2 ) ;54 c . gr idwidth = 1 ;5556 c . gr idx = 0 ;57 c . gr idy = 0 ;58 panel . add (new JLabel ( ”Name : ” ) , c ) ;5960 nameTextField = new JTextField ( ) ;61 nameTextField . s e t P r e f e r r e d S i z e (new Dimension (100 ,20) ) ;62 c . gr idx++;63 panel . add ( nameTextField , c ) ;6465 c . gr idx = 0 ;66 c . gr idy++;67 panel . add (new JLabel ( ” Desc r ip t i on : ” ) , c ) ;6869 desc r ipt ionEdi torPane = new JEditorPane ( ) ;70 JScro l lPane de s c r i p t i onSc ro l lPane = new JScro l lPane (

desc r ipt ionEdi torPane ) ;71 de s c r i p t i onSc r o l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .

VERTICAL SCROLLBAR ALWAYS) ;72 de s c r i p t i onSc r o l lPane . s e t P r e f e r r e d S i z e (new Dimension (220 , 100) ) ;73 de s c r i p t i onSc r o l lPane . setMinimumSize (new Dimension (10 , 10) ) ;74 c . gr idx++;75 panel . add ( de s c r ip t i onSc ro l lPane , c ) ;7677 c . gr idx = 0 ;78 c . gr idy++;79 panel . add (new JLabel ( ”Type : ” ) , c ) ;8081 typeComboBox = new JComboBox ( ) ;82 typeComboBox . addItem ( ” In t ege r ” ) ;

Page 364: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

354 Appendix C - Source Code

83 typeComboBox . addItem ( ”Double” ) ;84 typeComboBox . addItem ( ”Boolean” ) ;85 typeComboBox . addItem ( ” St r ing ” ) ;86 c . gr idx++;87 panel . add ( typeComboBox , c ) ;8889 typeOptionsPanel = createTypeOptionsPanel ( ) ;90 c . gr idx = 0 ;91 c . gr idy++;92 c . gr idwidth = 2 ;93 panel . add ( typeOptionsPanel , c ) ;9495 c . gr idx = 0 ;96 c . gr idy++;97 c . anchor = GridBagConstraints .CENTER;98 addButton = new JButton ( ”Add” ) ;99 panel . add ( addButton , c ) ;

100101102 this . add ( panel ) ;103104 // L i s t e n e r s105 typeComboBox . addAct ionListener ( c o n t r o l l e r ) ;106 addButton . addAct ionListener ( c o n t r o l l e r ) ;107108 this . pack ( ) ;109 this . s e t V i s i b l e ( true ) ;110 }111112 private JPanel createTypeOptionsPanel ( ) {113 JPanel panel = new JPanel ( ) ;114 panel . setLayout (new GridBagLayout ( ) ) ;115 GridBagConstraints c = new GridBagConstraints ( ) ;116117 c . i n s e t s = new I n s e t s (2 , 2 , 2 , 2 ) ;118119 c . gr idx = 0 ;120 c . gr idy = 0 ;121 c . anchor = GridBagConstraints . LINE END;122 panel . add (new JLabel ( ”Unit : ” ) , c ) ;123124 unitTextFie ld = new JTextField ( ) ;125 unitTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (30 ,20) ) ;126 unitTextFie ld . setText ( ”” ) ;127 c . gr idx++;128 c . anchor = GridBagConstraints .LINE START;129 panel . add ( unitTextFie ld , c ) ;130131 c . gr idx = 0 ;132 c . gr idy++;133 c . anchor = GridBagConstraints . LINE END;134 panel . add (new JLabel ( ”Lower l i m i t : ” ) , c ) ;135136 lowerLimitTextFie ld = new JTextField ( ) ;137 lowerLimitTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (30 ,20) ) ;138 c . gr idx++;139 c . anchor = GridBagConstraints .LINE START;140 panel . add ( lowerLimitTextFie ld , c ) ;141142 c . gr idx++;143 c . anchor = GridBagConstraints . LINE END;144 panel . add (new JLabel ( ”Upper l i m i t : ” ) , c ) ;145146 upperLimitTextFie ld = new JTextField ( ) ;147 upperLimitTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (30 ,20) ) ;148 c . gr idx++;149 c . anchor = GridBagConstraints .LINE START;150 panel . add ( upperLimitTextField , c ) ;151152 c . gr idx = 0 ;153 c . gr idy++;154 c . anchor = GridBagConstraints . LINE END;155 panel . add (new JLabel ( ”Accuracy : ” ) , c ) ;156157 accuracyTextFie ld = new JTextField ( ) ;158 accuracyTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (30 ,20) ) ;159 c . gr idx++;160 c . anchor = GridBagConstraints .LINE START;161 panel . add ( accuracyTextField , c ) ;162163 c . anchor = GridBagConstraints . LINE END;164 c . gr idx++;165 panel . add (new JLabel ( ” Default value : ” ) , c ) ;166167 de fau l tTextF i e ld = new JTextField ( ) ;168 de fau l tTextF i e ld . s e t P r e f e r r e d S i z e (new Dimension (30 ,20) ) ;169 c . gr idx++;

Page 365: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 355

170 c . anchor = GridBagConstraints .LINE START;171 panel . add ( de fau l tTextFie ld , c ) ;172173 return panel ;174 }175176 public JTextField getNameTextField ( ) {177 return nameTextField ;178 }179180 public JEditorPane getDescr ipt ionEditorPane ( ) {181 return descr ipt ionEdi torPane ;182 }183184 public JComboBox getTypeComboBox ( ) {185 return typeComboBox ;186 }187188 public JPanel getTypeOptionsPanel ( ) {189 return typeOptionsPanel ;190 }191192 public JTextField getUnitTextFie ld ( ) {193 return unitTextFie ld ;194 }195196 public JTextField getLowerLimitTextField ( ) {197 return lowerLimitTextFie ld ;198 }199200 public JTextField getUpperLimitTextField ( ) {201 return upperLimitTextField ;202 }203204 public JTextField getDefau l tTextFie ld ( ) {205 return de fau l tTextF i e ld ;206 }207208 public JTextField getAccuracyTextFie ld ( ) {209 return accuracyTextFie ld ;210 }211212 public CommandTypeSetup getCommandTypeGeneratorView ( ) {213 return commandTypeGeneratorView ;214 }215216 public JButton getAddButton ( ) {217 return addButton ;218 }219220221 }

Page 366: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

356 Appendix C - Source Code

.2.18 CommandTypeSetup.java

1 package common . command . generat ion ;23 import java . awt . Dimension ;4 import java . awt . FlowLayout ;5 import java . awt . GridBagConstraints ;6 import java . awt . GridBagLayout ;7 import java . awt . I n s e t s ;8 import java . u t i l . ArrayList ;9

10 import javax . swing . JButton ;11 import javax . swing . JEditorPane ;12 import javax . swing . JFrame ;13 import javax . swing . JLabel ;14 import javax . swing . JL i s t ;15 import javax . swing . JPanel ;16 import javax . swing . JScro l lPane ;17 import javax . swing . JTable ;18 import javax . swing . JTextField ;19 import javax . swing . tab l e . AbstractTableModel ;20 import javax . swing . tab l e . TableRowSorter ;212223 import common . command . ModuleID ;24 import common . command . parameter . Parameter ;2526 public c lass CommandTypeSetup extends JFrame {2728 private JTextField idTextFie ld ;29 private JTextField nameTextField ;30 private JEditorPane descr ipt ionEdi torPane ;31 private JL i s t l e g a l D e s t i n a t i o n s L i s t ;3233 private ParameterTableModel parameterTableModel ;34 private JTable paramtersTable ;3536 private JButton addParameterButton ;37 private JButton createCommandTypeButton ;3839 private ArrayList<Parameter> paramters ;4041 private CommandTypeSetupController c o n t r o l l e r ;42 private DTUsat2CommandTypeEditor dtuSat2CommandEditor ;43 private int id ;4445 public CommandTypeSetup(DTUsat2CommandTypeEditor dtuSat2CommandEditor ) {4647 i f ( dtuSat2CommandEditor . getCommandTypes ( ) . s i z e ( )==0) {48 id = 0 ;49 } else {50 int s i z e = dtuSat2CommandEditor . getCommandTypes ( ) . s i z e ( ) ;51 id = dtuSat2CommandEditor . getCommandTypes ( ) . get ( s i z e −1) .

getTypeID ( ) +1;52 }5354 this . dtuSat2CommandEditor = dtuSat2CommandEditor ;5556 c o n t r o l l e r = new CommandTypeSetupController ( this ) ;5758 this . s e t T i t l e ( ”Add Command Type” ) ;59 this . setLayout (new FlowLayout ( FlowLayout .LEADING) ) ;6061 paramters = new ArrayList<Parameter >() ;6263 JPanel panel = new JPanel ( ) ;64 panel . setLayout (new GridBagLayout ( ) ) ;65 GridBagConstraints c = new GridBagConstraints ( ) ;6667 c . i n s e t s = new I n s e t s (3 , 2 , 3 , 2 ) ;68 c . gr idwidth = 1 ;69 c . anchor = GridBagConstraints . FIRST LINE START ;7071 c . gr idx = 0 ;72 c . gr idy = 0 ;73 panel . add (new JLabel ( ”ID : ” ) , c ) ;7475 idTextFie ld = new JTextField ( ) ;76 idTextFie ld . setText ( ””+id ) ;77 idTextFie ld . s e t P r e f e r r e d S i z e (new Dimension (30 ,20) ) ;78 idTextFie ld . setEnabled ( f a l s e ) ;79 c . gr idx++;80 panel . add ( idTextFie ld , c ) ;8182 c . gr idx = 0 ;83 c . gr idy++;

Page 367: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 357

84 panel . add (new JLabel ( ”Name : ” ) , c ) ;8586 nameTextField = new JTextField ( ) ;87 nameTextField . s e t P r e f e r r e d S i z e (new Dimension (180 ,20) ) ;88 c . gr idx++;89 panel . add ( nameTextField , c ) ;9091 c . gr idx = 0 ;92 c . gr idy++;93 panel . add (new JLabel ( ” Desc r ip t i on : ” ) , c ) ;9495 desc r ipt ionEdi torPane = new JEditorPane ( ) ;96 // d e s c r i p t i o n E d i t o r P a n e . s e t P r e f e r r e d S i z e ( new D ime s i o n ( 1 4 0 , 7 0 ) ) ;97 JScro l lPane de s c r i p t i onSc ro l lPane = new JScro l lPane (

desc r ipt ionEdi torPane ) ;98 de s c r i p t i onSc r o l lPane . s e t V e r t i c a l S c r o l l B a r P o l i c y ( JScro l lPane .

VERTICAL SCROLLBAR ALWAYS) ;99 de s c r i p t i onSc r o l lPane . s e t P r e f e r r e d S i z e (new Dimension (220 , 100) ) ;

100 de s c r i p t i onSc r o l lPane . setMinimumSize (new Dimension (10 , 10) ) ;101102 c . gr idx++;103 panel . add ( de s c r ip t i onSc ro l lPane , c ) ;104105 c . gr idx = 0 ;106 c . gr idy++;107 panel . add (new JLabel ( ”<html>Legal<br>ModuleID ( s ) :</html>” ) , c ) ;108 ModuleID [ ] d e s t i n a t i on s = ModuleID . va lues ( ) ;109 l e g a l D e s t i n a t i o n s L i s t = new JL i s t ( d e s t i n a t i on s ) ;110 l e g a l D e s t i n a t i o n s L i s t . se tLayoutOr ientat ion ( JL i s t .HORIZONTAL WRAP) ;111 l e g a l D e s t i n a t i o n s L i s t . setVisibleRowCount (3) ;112 // s l e g a l D e s t i n a t i o n s L i s t . s e t P r e f e r r e d S i z e ( new D imen s i o n ( 6 0 , 8 0 ) ) ;113 c . gr idx++;114 panel . add ( l e g a lDe s t i n a t i on sL i s t , c ) ;115116117 c . gr idx = 0 ;118 c . gr idy++;119 panel . add (new JLabel ( ”Paramters : ” ) , c ) ;120121 addParameterButton = new JButton ( ”Add parameter ” ) ;122 c . gr idx++;123 panel . add ( addParameterButton , c ) ;124125 parameterTableModel = new ParameterTableModel ( paramters ) ;126 paramtersTable = new JTable ( parameterTableModel ) ;127 paramtersTable . getColumnModel ( ) . getColumn (0) . setPreferredWidth (150) ;128 paramtersTable . getColumnModel ( ) . getColumn (1) . setPreferredWidth (50) ;129130131 TableRowSorter<ParameterTableModel> s o r t e r = new TableRowSorter<

ParameterTableModel >(parameterTableModel ) ;132 paramtersTable . setRowSorter ( s o r t e r ) ;133134 paramtersTable . setColumnSelect ionAllowed ( f a l s e ) ;135 paramtersTable . setRowSelect ionAl lowed ( true ) ;136 paramtersTable . s e tF i l l sV i ewpor tHe ight ( true ) ;137 paramtersTable . setAutoResizeMode ( JTable .AUTO RESIZE OFF) ; // D i s a b l e a u t o

r e s i z i n g138139140 JScro l lPane s c ro l lPane = new JScro l lPane ( paramtersTable ) ;141 s c ro l lPane . s e t P r e f e r r e d S i z e (new Dimension (200 ,100) ) ;142 c . gr idx = 0 ;143 c . gr idy++;144 c . gr idwidth = 2 ;145 panel . add ( scro l lPane , c ) ;146147 createCommandTypeButton = new JButton ( ” Create Command Type” ) ;148 c . gr idx = 0 ;149 c . gr idy++;150 c . anchor = GridBagConstraints .CENTER;151 panel . add ( createCommandTypeButton , c ) ;152153154 // L i s t e n e r s155 addParameterButton . addAct ionListener ( c o n t r o l l e r ) ;156 createCommandTypeButton . addAct ionListener ( c o n t r o l l e r ) ;157158159 this . add ( panel ) ;160 this . pack ( ) ;161 this . s e t V i s i b l e ( true ) ;162163 }164165 public JTextField get IdTextFie ld ( ) {166 return idTextFie ld ;

Page 368: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

358 Appendix C - Source Code

167 }168169 public JTextField getNameTextField ( ) {170 return nameTextField ;171 }172173 public JEditorPane getDescr ipt ionEditorPane ( ) {174 return descr ipt ionEdi torPane ;175 }176177 public JL i s t g e tLega lDe s t i na t i on sL i s t ( ) {178 return l e g a l D e s t i n a t i o n s L i s t ;179 }180181 public JTable getParamtersTable ( ) {182 return paramtersTable ;183 }184185 public JButton getAddParameterButton ( ) {186 return addParameterButton ;187 }188189 public JButton getCreateCommandTypeButton ( ) {190 return createCommandTypeButton ;191 }192193 public ArrayList<Parameter> getParamters ( ) {194 return paramters ;195 }196197 public DTUsat2CommandTypeEditor getDtuSat2CommandEditor ( ) {198 return dtuSat2CommandEditor ;199 }200201 public int get Id ( ) {202 return id ;203 }204205206 }207208209 c lass ParameterTableModel extends AbstractTableModel {210211 private ArrayList<Parameter> paramters ;212213 public ParameterTableModel ( ArrayList<Parameter> paramters ) {214 this . paramters = paramters ;215 }216217 @Override218 public int getColumnCount ( ) {219 return 2 ;220 }221222 @Override223 public int getRowCount ( ) {224 return paramters . s i z e ( ) ;225 }226227 public Str ing getColumnName( int co l ) {228 switch ( c o l ) {229 case 0 : return ”Name” ;230 case 1 : return ”Type” ;231 default : return null ;232 }233 }234235 @Override236 public Object getValueAt ( int row , int co l ) {237 Parameter p = paramters . get ( row ) ;238239 switch ( c o l ) {240 case 0 :241 return p . getName ( ) ;242 case 1 :243 return p . getParameterType ( ) ;244 default :245 return null ;246 }247248 }249250251252253

Page 369: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 359

254 }

Page 370: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

360 Appendix C - Source Code

.2.19 DoubleParameter.java

1 package common . command . parameter ;23 import java . i o . S e r i a l i z a b l e ;45 import org . simpleframework . xml . Element ;67 public c lass DoubleParameter extends ParameterType implements S e r i a l i z a b l e {89 @Element ( r equ i r ed=f a l s e )

10 private Str ing unit ;1112 @Element13 private double lowerLimit ;1415 @Element16 private double upperLimit ;1718 @Element19 private double de fau l tVa lue ;2021 @Element22 private double accuracy ;2324 public DoubleParameter ( ) {2526 }2728 public DoubleParameter ( St r ing unit , double lowerLimit , double upperLimit ,

double defaultValue , double accuracy ) {29 this . un i t = unit ;30 this . lowerLimit = lowerLimit ;31 this . upperLimit = upperLimit ;32 i f ( defaultValue>=lowerLimit && defaultValue<=upperLimit ) {33 this . de fau l tVa lue = defau l tVa lue ;34 } else {35 throw new I l l ega lArgumentExcept ion ( ” Default value must be

between upper and lower l i m i t ” ) ;36 }37 this . accuracy = accuracy ;3839 }4041 public double getLowerLimit ( ) {42 return lowerLimit ;43 }4445 public double getUpperLimit ( ) {46 return upperLimit ;47 }4849 public double getDefaultValue ( ) {50 return de fau l tVa lue ;51 }5253 public double getAccuracy ( ) {54 return accuracy ;55 }5657 public Str ing getUnit ( ) {58 return unit ;59 }6061 }

Page 371: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 361

.2.20 IntParameter.java

1 package common . command . parameter ;23 import java . i o . S e r i a l i z a b l e ;4 import org . simpleframework . xml . Element ;567 public c lass IntParameter extends ParameterType implements S e r i a l i z a b l e {89 @Element ( r equ i r ed=f a l s e )

10 private Str ing unit ;1112 @Element13 private int lowerLimit ;1415 @Element16 private int upperLimit ;1718 @Element19 private int de fau l tVa lue ;2021 @Element22 private int accuracy ;2324 public IntParameter ( ) {2526 }2728 public IntParameter ( St r ing unit , int lowerLimit , int upperLimit , int

defaultValue , int accuracy ) {29 this . un i t = unit ;30 this . lowerLimit = lowerLimit ;31 this . upperLimit = upperLimit ;32 i f ( defaultValue>=lowerLimit && defaultValue<=upperLimit ) {33 this . de fau l tVa lue = defau l tVa lue ;34 } else {35 throw new I l l ega lArgumentExcept ion ( ” Default value must be

between upper and lower l i m i t ” ) ;36 }37 this . accuracy = accuracy ;3839 }4041 public int getLowerLimit ( ) {42 return lowerLimit ;43 }4445 public int getUpperLimit ( ) {46 return upperLimit ;47 }4849 public int getDefaultValue ( ) {50 return de fau l tVa lue ;51 }5253 public int getAccuracy ( ) {54 return accuracy ;55 }5657 public Str ing getUnit ( ) {58 return unit ;59 }6061 }

Page 372: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

362 Appendix C - Source Code

.2.21 Parameter.java

1 package common . command . parameter ;23 import java . i o . S e r i a l i z a b l e ;45 import org . simpleframework . xml . Attr ibute ;6 import org . simpleframework . xml . Element ;789 public c lass Parameter implements S e r i a l i z a b l e {

1011 @Attribute12 private Str ing name ;1314 @Element15 private Str ing d e s c r i p t i on ;1617 @Element18 private ParameterType parameterType ;1920 public Parameter ( ) {2122 }2324 public Parameter ( St r ing name , St r ing de s c r ip t i on , ParameterType

parameterType ) {2526 //FIXME : Un i t h v i s t y p e e r b o o l e l l e r s t r i n g ? ? ? ? ? ?27 this . name = name ;28 this . d e s c r i p t i on = de s c r i p t i on ;29 this . parameterType = parameterType ;30 }313233 public ParameterType getParameterType ( ) {34 return parameterType ;35 }363738 public Str ing getName ( ) {39 return name ;40 }414243 public Str ing ge tDesc r ip t i on ( ) {44 return de s c r i p t i on ;45 }4647 }

Page 373: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 363

.2.22 ParameterType.java

1 package common . command . parameter ;23 import java . i o . S e r i a l i z a b l e ;45 import org . simpleframework . xml . Root ;67 public abstract c lass ParameterType implements S e r i a l i z a b l e {89

10 }

Page 374: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

364 Appendix C - Source Code

.2.23 StringParameter.java

1 package common . command . parameter ;23 import java . i o . S e r i a l i z a b l e ;45 public c lass StringParameter extends ParameterType implements S e r i a l i z a b l e {67 public StringParameter ( ) {89 }

1011 }

Page 375: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.2 Common Source Code 365

.2.24 BooleanParameter.java

1 package common . command . parameter ;23 import java . i o . S e r i a l i z a b l e ;45 public c lass BooleanParameter extends ParameterType implements S e r i a l i z a b l e {67 public BooleanParameter ( ) {89

10 }1112 }

Page 376: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

366 Appendix C - Source Code

.3 MCC Source Code

.3.1 Scheduler.java

1 package mcc . s e rv e r . dataProcess ing ;23 import java . u t i l . ArrayList ;4 import java . u t i l . Co l l e c t i o n s ;56 import common . command .Command;78 import mcc . s e rv e r . database . c l i e n t . DBClient ;9

10 /∗∗11 ∗ The S c h e d u l e r , l o o k s a t t h e c u r r e n t t i m e l i n e and t r i e s t o s c h e d u l e a l l commands

a c c o r d i n g t o t h e d e f i n i t i o n s e t up .12 ∗ @au t h o r Kenne t h A g e r s k o v J en s en , s 0 3 1 7 5 013 ∗ @au t h o r And r e a s And e r s e n Kjae r , s 0 3 2 1 0 314 ∗ @ v e r s i o n 1 . 015 ∗∗/16 public c lass Scheduler {17 private Timeline t l ;18 private T i m e l i n e U t i l i t i e s t l u ;19 private Str ing user = ”mcc” ;20 private int currentPass ;21 // The amount o f commands t o s c h e d u l e22 private int commSize ;23 // The amount o f p a s s ’ s a v a i l a b l e24 private int pas sS i z e ;25 private int preSchedul ing ;26 private int l a s tPo s s i b l ePa s s ;27 // The command t h e t i m e l i n e i s c u r r e n t l y w o r k i n g on28 private Command command ;29 // The p a s s t h e t i m e l i n e i s c u r r e n t l y w o r k i n g on30 private Pass pass ;31 // A l i s t o f u s e a b l e p a s s e s32 private ArrayList<Pass> pas sL i s t ;33 private Cleaner c l e ane r ;34 private DBClient dbc ;35 private long f i r s tPas sSta r tT ime ;3637 /∗∗38 ∗ S e t s t h e s c h e d u l e r up i n s u c h a way t h a t i t i s r e a d y t o s c h e d u l e39 ∗ @param t l u The t i m e l i n e U t i l i t i e s o b j e c t t h e s c h e d u l e r u s e s t o s c h e d u l e40 ∗ @param t l The t i m e l i n e t h e s c h e d u l e r s h o u l d s c h e d u l e41 ∗ @param c l e a n e r A c l e a n e r t h e s c h e d u l e r can c a l l t o make s u r e i t d o s n t

s c h e d u l e u s e l e s s commands42 ∗ @param p r e S c h e d u l i n g An i n t v a l u e d e f i n i n g how much b e f o r e a p a s s e s

e x e c u t i o n t im e i t s h o u l d b e s c h e d u l e d43 ∗/44 public Scheduler ( T i m e l i n e U t i l i t i e s t lu , Timeline t l , Cleaner c l eaner , int

preSchedul ing ){45 this . c l e ane r = c l eane r ;46 this . t l u = t lu ;47 this . t l = t l ;48 this . preSchedul ing = preSchedul ing ;49 dbc = DBClient . ge t In s tance ( ) ;50 }5152 /∗∗53 ∗ S c h e d u l e s a l l commands n o t y e t l o c k e d , a l s o r e s c h e d u l e s a l l p r e v i o u s l y

s c h e d u l e d commands54 ∗ @param f u t u r e P l a n n i n g How many m i l l i s e c o n d s s h o u l d t h e s c h e d u l e r p l a n f o r

i n t h e f u t u r e55 ∗ @th r ow s E x c e p t i o n56 ∗/57 public void schedule ( long futurePlanning ) throws Exception{58 // XXX : Removed c l e a n i n g f r om MCC59 // c l e a n e r . c l e a nUp ( ) ;60 boolean ass igned = f a l s e ;61 CommandBlock block ;62 commSize = t l . numberOfCommands ( ) ;63 pas sS i z e = t l . numberOfPasses ( ) ;64 pa s sL i s t = new ArrayList<Pass >() ;65 long maxScheduleTime = futurePlanning+System . currentTimeMi l l i s ( ) ;6667 // C r e a t e s a l i s t o f u s e a b l e p a s s e s68 for ( int i = 0 ; i < pas sS i z e ; i++){69 i f ( t l . getPass ( i ) . ge tStatus ( ) == Pass .OPEN && t l . getPass ( i ) .

getStartTime ( ) > System . currentTimeMi l l i s ( ) ){70 pa s sL i s t . add ( t l . getPass ( i ) ) ;71 }

Page 377: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.3 MCC Source Code 367

72 }7374 // S o r t s t h e l i s t o f u s a b l e p a s s e s75 Co l l e c t i on s . s o r t ( pa s sL i s t ) ;7677 // On l y l e t commands a f t e r t h e f i r s t p a s s ’ s t a r t t im e b e s c h e d u l e d78 i f ( pa s sL i s t !=null ){79 f i r s tPas sSta r tT ime = pas sL i s t . get (0) . getStartTime ( ) ;80 }8182 // U n s c h e d u l e s a l l s c h e d u l e d commands u n l e s s t h e y h a v e a u s e r g i v e n

p a s s8384 // For a l l commands i n t h e t im e l i n e85 for ( Long id : t l . getCommandMap( ) . keySet ( ) ){86 Command command = t l . lookupCommand( id ) ;87 // I f p a s s i s a f t e r f i r s t p a s s and n o t g i v e n a u s e r g i v e n

p a s s88 i f ( ! ( command . getTimeOfExecution ( )<=f i r s tPas sSta r tT ime | |

command . getUserGivenPass ( ) ) ){89 // On l y commands t h a t a r e n o t t r a n s m i t t e d mus t b e

u n s c h e d u l e d90 i f (command . ge tState ( )<Command.TRANSMITTED){91 t l u . modifyCommand( id , T i m e l i n e U t i l i t i e s .

PASSID , −1, user ) ;92 dbc . commit ( ) ;93 }94 // Command i s f l o a t i n g95 } else i f (command . getTimeOfExecution ( ) == −1 && ! ( command .

getUserGivenPass ( ) ) ){96 i f (command . ge tState ( )<Command.TRANSMITTED){97 t l u . modifyCommand( id , T i m e l i n e U t i l i t i e s .

PASSID , −1, user ) ;98 dbc . commit ( ) ;99 }

100 }101 }102103 /∗104 ∗ OLD u n s c h e d u l e r105 ∗/106 // f o r ( i n t i = 0 ; i < p a s s S i z e ; i ++){107 // p a s s = t l . g e t P a s s ( i ) ;108 // i f ( p a s s . g e t S t a r t T i m e ( ) > Sy s t em . c u r r e n t T i m e M i l l i s ( ) ){109 // i n t s i z e O f P a s s = p a s s . s i z e ( ) ;110 // f o r ( i n t j = s i z e O f P a s s −1; j >= 0 ; j−−){111 // i f ( ! t l . l ookupCommand ( p a s s . getCommand ( j ) ) .

g e t U s e r G i v e n P a s s ( ) ){112 // t l u . modi fyCommand ( p a s s . getCommand ( j )

, T i m e l i n e U t i l i t i e s . PASSID , −1, u s e r ) ;113 // }114 // d b c . commi t ( ) ;115 // }116 // }117 // }118119 // S c h e d u l e s u r g e n t f l o a t i n g commands120 for ( int i = 0 ; i < commSize ; i++){121 command = t l . getCommand( i ) ;122 block = t l . lookupCommandBlock (command . getBlockID ( ) ) ;123 i f (command . ge tState ( ) <= Command.AWAITING PASS && block .

g e t P r i o r i t y ( ) == CommandBlock .URGENT PRIORITY124 && command . getTimeOfExecution ( ) == −1 &&

block . passCanBeAssigned ( ) ){125 pass = pas sL i s t . get (0) ;126 // I f f i r s t p o s s i b l e p a s s d o s n t h a v e e n o u g h room

moves on u n t i l t h e r e i s room127 i f ( ! addCommand( ) ){128 ass igned = f a l s e ;129 int k = 1 ;130 while (k < pas sL i s t . s i z e ( ) && ! as s igned ){131 pass = pas sL i s t . get (k ) ;132 as s igned = addCommand( ) ;133 k++;134 }135 i f ( ! a s s i gned ){136 t l u . internalModifyCommand (command .

getCommandID () , Command.AWAITING USER ACTION, user ) ;

137 }138 }139 }140 }141142 // S c h e d u l e s a l l u r g e n t commands143 for ( int i = 0 ; i < commSize ; i++){144 command = t l . getCommand( i ) ;

Page 378: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

368 Appendix C - Source Code

145 block = t l . lookupCommandBlock (command . getBlockID ( ) ) ;146 i f (command . ge tState ( ) <= Command.AWAITING PASS && block .

g e t P r i o r i t y ( ) == CommandBlock .URGENT PRIORITY147 && block . passCanBeAssigned ( ) && command .

getTimeOfExecution ( ) >=f i r s tPas sSta r tT ime

148 && command . getTimeOfExecution ( ) <=maxScheduleTime ){

149 f indPass ( ) ;150 i f ( ! addCommand( ) ){151 ass igned = f a l s e ;152 int k = 1 ;153 // c h e c k s i f t h e r e i s room i n a l a t e r p a s s154 while (k < l a s tPo s s i b l ePa s s && k <=

preSchedul ing && ! ass igned ){155 pass = pas sL i s t . get ( currentPass+k) ;156 as s igned = addCommand( ) ;157 k++;158 }159 i f ( ! a s s i gned ){160 i f ( ! pushBack ( ) ){161 t l u . internalModifyCommand (

command . getCommandID ( ) ,Command.

AWAITING USER ACTION,user ) ;

162 }163 }164 }165 }166 }167168 // S c h e d u l e s n o rma l f l o a t i n g commands169 for ( int i = 0 ; i < commSize ; i++){170 command = t l . getCommand( i ) ;171 block = t l . lookupCommandBlock (command . getBlockID ( ) ) ;172 i f (command . ge tState ( ) <= Command.AWAITING PASS && block .

g e t P r i o r i t y ( ) == CommandBlock .NORMAL PRIORITY173 && command . getTimeOfExecution ( ) == −1 &&

block . passCanBeAssigned ( ) ){174 pass = pas sL i s t . get (0) ;175 // I f f i r s t p o s s i b l e p a s s d o s n t h a v e e n o u g h room

moves on u n t i l t h e r e i s room176 i f ( ! addCommand( ) ){177 ass igned = f a l s e ;178 int k = 1 ;179 while (k < pas sL i s t . s i z e ( ) && ! as s igned ){180 pass = pas sL i s t . get (k ) ;181 as s igned = addCommand( ) ;182 k++;183 }184 i f ( ! a s s i gned ){185 t l u . internalModifyCommand (command .

getCommandID () , Command.AWAITING USER ACTION, user ) ;

186 }187 }188 }189 }190191 // S c h e d u l e s a l l n o rma l commands192 for ( int i = 0 ; i < commSize ; i++){193 command = t l . getCommand( i ) ;194195 block = t l . lookupCommandBlock (command . getBlockID ( ) ) ;196 i f (command . ge tState ( ) <= Command.AWAITING PASS && block .

g e t P r i o r i t y ( ) == CommandBlock .NORMAL PRIORITY197 && block . passCanBeAssigned ( ) && command .

getTimeOfExecution ( ) >=f i r s tPas sSta r tT ime

198 && command . getTimeOfExecution ( ) <=maxScheduleTime ){

199 f indPass ( ) ;200 i f ( ! addCommand( ) ){201 ass igned = f a l s e ;202 int k = 1 ;203 // c h e c k s i f t h e r e i s room i n a l a t e r p a s s204 while ( ( currentPass + k) < l a s tPo s s i b l ePa s s

&& k <= preSchedul ing && ! ass igned ){205 pass = pas sL i s t . get ( currentPass+k) ;206 as s igned = addCommand( ) ;207 k++;208 }209 i f ( ! a s s i gned ){210 i f ( ! pushBack ( ) ){211 t l u . internalModifyCommand (

command . getCommandID ( ) ,

Page 379: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

.3 MCC Source Code 369

Command.AWAITING USER ACTION,user ) ;

212 }213 }214 }215216 }217 }218 dbc . commit ( ) ;219 }220221 /∗∗222 ∗ F i n d s t h e l a t e s t p a s s w h i c h s t i l l h a s an end t im e b e f o r e t h e t o e o f t h e

command223 ∗/224 public void f indPass ( ) {225 long toe = command . getTimeOfExecution ( ) ;226 long passEndTime = toe−1;227 currentPass = 0 ;228229 // r u n s u n t i l i t g e t s t h e p a s s j u s t t o l a t e t o b e u s e f u l , o r t h e r e

i s no more p a s s e s230 while ( toe > passEndTime && currentPass < pas sL i s t . s i z e ( ) ){231 pass = pas sL i s t . get ( currentPass ) ;232 passEndTime = pass . getEndTime ( ) ;233 currentPass++;234 }235236 // I f t h e w h i l e l o o p was t e r m i n a t e d b e c a u s e t h e p a s s was t o o l a t e :

Go one p a s s b a c k237 i f ( toe < passEndTime ){238 currentPass −−;239 }240 // In any c a s e t h e w h i l e l o o p t o o k c u r r e n t P a s s t o one t o h i g h241 currentPass−−;242243 // Th i s p a s s mus t b e t h e l a s t p o s s i b l e p a s s244 l a s tPo s s i b l ePa s s = currentPass ;245246 // P r e s c h e d u l i n g w i l l p u s h t h e p a s s t h e g i v e n amount o f p a s s e s b a c k247 for ( int i = 0 ; i<preSchedul ing ; i++){248 i f ( currentPass >0) currentPass−−;249 }250251 // The p a s s i s s u b m i t t e d t o t h e s c h e d u l e r252 pass = pas sL i s t . get ( currentPass ) ;253 }254255 /∗∗256 ∗ a d d s t h e c u r r e n t command t o t h e c u r r e n t l y s e l e c t e d Pa s s i f t h e r e i s room257 ∗ @r e t u r n b o o l e a n v a l u e o f w e t h e r t h e command g e t s i n s e r t e d o r n o t258 ∗ @th r ow s E x c e p t i o n259 ∗/260 public boolean addCommand( ) throws Exception{261 i f ( pass . getUpl inkBytesAvai lab le ( ) >= command . getByteS ize ( ) ){262 t l u . modifyCommand(command . getCommandID () , T i m e l i n e U t i l i t i e s .

PASSID , pass . getPassID ( ) , user ) ;263 return true ;264 }265 else{266 return fa l se ;267 }268 }269270 /∗∗271 ∗ T r i e s t o move commands b a c k w a r d s i n t h e t i m e l i n e i n o r d e r t o make room

f o r t h e c u r r e n t command i n t h e c u r r e n t p a s s272 ∗ @r e t u r n b o o l e a n v a l u e o f w e t h e r t h e p u s h b a c k was s u c c e s f u l o r n o t273 ∗ @th r ow s E x c e p t i o n274 ∗/275 public boolean pushBack ( ) throws Exception{276 pass = t l . getPass ( currentPass ) ;277 int i = 1 ; // t h e d i s t a n c e f r om c u r r e n t P a s s278 int j ; // u s e d f o r s w i t c h i n g279 boolean swi tch ing = true ;280 Pass currPass = pass ;281 Pass prevPass = pas sL i s t . get ( currentPass−i ) ;282 // w h i l e t h e r e i s no room f o r t h e command i n t h e p a s s , o r t h e r e a r e

no more p a s s e s t o t r y283 while ( pass . getUpl inkBytesAvai lab le ( ) < command . getByteS ize ( ) && i <=

currentPass ){284 // i f t h e r e i s room i n t h e p r e v i o u s p a s s f o r t h e e a r l i e s t

command i n t h e c u r r e n t p a s s285286 i f ( currPass . s i z e ( ) > 0 && prevPass . getUpl inkBytesAvai lab le ( )

> t l . lookupCommand( currPass . getCommand (0) ) . getByteS ize

Page 380: Mission Planning System - Technical University of Denmarketd.dtu.dk/thesis/221869/bac08_25.pdf · The objective of this bachelor thesis is to develop and document the Mission

370 Appendix C - Source Code

( ) ){287 t l u . modifyCommand( currPass . getCommand (0) ,

T i m e l i n e U t i l i t i e s . PASSID , prevPass . getPassID ( ) ,user ) ;

288 int k = 1 ;289 // c h e c k s i f t h e r e i s room f o r more t h a n t h e one

command i n t h e p r e v i o u s p a s s290 while (k < currPass . s i z e ( ) && prevPass .

getUpl inkBytesAvai lab le ( ) > t l . lookupCommand(currPass . getCommand(k ) ) . getByteS ize ( ) ){

291 t l u . modifyCommand( currPass . getCommand(k ) ,T i m e l i n e U t i l i t i e s . PASSID , prevPass .getPassID ( ) , user ) ;

292 k++;293 }294 j = i ;295296 // t r i e s t o move a command i n t h e r e m a i n i n g p a s s e s

w i t h t h e n e w l y a q u i r e d room297 while ( j >= 1 && switch ing ){298 j−−;299 i f ( pa s sL i s t . get ( currentPass−j ) .

getUpl inkBytesAvai lab le ( ) > t l .lookupCommand( pa s sL i s t . get ( currentPass−( j +1) ) . getCommand (0) ) . getByteS ize ( ) ){

300 t l u . modifyCommand( t l . getPass (currentPass−( j +1) ) . getCommand(0) , T i m e l i n e U t i l i t i e s . PASSID ,pa s sL i s t . get ( currentPass−j ) .getPassID ( ) , user ) ;

301 }302 else{303 // i f one s w i t c h i n g f a i l e s t h e r e w i l l

b e no c h a n g e i n t h e l a t e rp a s s e s and s o t h e r e i s nor e a s o n t o c o n t i n u e

304 switch ing = f a l s e ;305 }306 }307 }308 i ++;309310 i f ( i <= currentPass ){311 currPass = prevPass ;312 prevPass = pas sL i s t . get ( currentPass−i ) ;313 }314 }315 // Ch e c k s i f i t s p o s s i b l e t o i n s e r t t h e command now316317 i f (addCommand( ) ){318319 return true ;320 }321 else{322 return fa l se ;323 }324 }325 }