Skip to content

Commit

Permalink
Initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-hoffman committed Feb 23, 2015
1 parent ec90c3e commit aaca0c0
Show file tree
Hide file tree
Showing 68 changed files with 6,359 additions and 7 deletions.
17 changes: 10 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
*.class
#ant specific
*/build/
*/dist/

# Mobile Tools for Java (J2ME)
.mtj.tmp/
#NetBeans specific
#ignore entire folder but make exceptions
*/nbproject/*
*/manifest.mf

# Package Files #
*.jar
*.war
*.ear
#Project specific
/ResearchManagementSystem/files/
*/*.rms

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
71 changes: 71 additions & 0 deletions ResearchManagementSystem/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="ResearchManagementSystem" default="default" basedir=".">
<description>Builds, tests, and runs the project ResearchManagementSystem.</description>
<import file="nbproject/build-impl.xml"/>

<tstamp/>

<target name="update-version-minor">
<propertyfile file="build_info.properties">
<entry pattern="00" value="1" operation="+" type="int" key="build.minor.number"/>
</propertyfile>

</target>

<target name="update-version-major">
<propertyfile file="build_info.properties">
<entry pattern="00" value="1" operation="+" type="int" key="build.major.number"/>
<entry pattern="00" value="0" type="int" key="build.minor.number"/>
</propertyfile>
</target>

<target name="deploy-one-jar" depends="update-version-minor,jar">
<!-- Build version properties -->
<local name="build.major.number"/>
<local name="build.minor.number"/>
<property file="build_info.properties"/>
<property name="build.version" value="${build.major.number}_${build.minor.number}"/>

<!-- Directory and jar file name -->
<property name="store.dir" value="deploy/${build.version}"/>
<property name="store.jar" value="${store.dir}/${ant.project.name}_${build.version}.jar"/>


<!-- Create directory if not exists -->
<mkdir dir="${store.dir}"/>

<!-- Backup sources for the new version -->
<property name="store.src" value="${store.dir}/src_${build.version}.zip"/>
<echo message="Backup sources to ${store.src}"/>
<zip destfile="${store.src}" basedir="${src.dir}"/>

<!-- Deploy new version: create the jar -->
<echo message="Deploying ${application.title} to ${store.jar}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Built-Date" value="${TODAY}"/>
<attribute name="Specification-Title" value="${application.title}"/>
<attribute name="Specification-Vendor" value="${application.vendor}"/>
<attribute name="Specification-Version" value="${build.version}"/>
<attribute name="Implementation-Version" value="${TODAY}"/>
</manifest>
</jar>

<zip destfile="${store.jar}">
<zipfileset excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA" src="${store.dir}/temp_final.jar"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
</project>
4 changes: 4 additions & 0 deletions ResearchManagementSystem/build_info.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Mon, 23 Feb 2015 14:16:13 -0600

build.major.number=02
build.minor.number=01
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions ResearchManagementSystem/lib/nblibraries.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
libs.beans-binding.classpath=\
${base}/beans-binding/beansbinding-1.2.1.jar
libs.beans-binding.displayName=Beans Binding
libs.beans-binding.javadoc=\
${base}/beans-binding/beansbinding-1.2.1-doc.zip
libs.beans-binding.prop-maven-dependencies=org.jdesktop:beansbinding:1.2.1:jar
libs.CopyLibs.classpath=\
${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
libs.CopyLibs.prop-version=2.0
Binary file not shown.
89 changes: 89 additions & 0 deletions ResearchManagementSystem/src/rms/control/Loader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package rms.control;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import rms.model.State;
import rms.util.Helpers;

/**
* Facilities to load the State from file and store it to file
*
* @author Timothy
*/
public class Loader {

private static final boolean DUBUG_LOADING = false;
private static final Logger thisLog = Logger.getLogger(Loader.class.getName());
private static final String STATE_FILE_NAME = String.format("index_%s.rms", Loader.class.getPackage().getSpecificationVersion());

private static String getRootDir(){
return System.getProperty("user.dir");
}

/**
* Attempts to deserialize the stored {@code State} from file
*
* @return the {@code State} object stored in file or null if unable to deserialize
*
* @see rms.model.State
*/
public static synchronized State loadFromFile(){
if(DUBUG_LOADING)System.out.println("Loader.loadFromFile()");

String baseDir = getRootDir();
if(baseDir == null) {
thisLog.log(Level.SEVERE, "Unable to determine user directory.");
return null;
}

State retVal;
ObjectInputStream in = null;
try {
in = new ObjectInputStream(new FileInputStream(baseDir.concat("/").concat(STATE_FILE_NAME)));
retVal = (State) in.readObject();
} catch (IOException | ClassNotFoundException ex) {
thisLog.log(Level.INFO, "Unable to load state. Creating new.", ex);
retVal = new State();
} finally {
Helpers.closeResource(in);
}

return retVal;
}

/**
* Attempts to serialize the given {@code State} object to file
*
* @param state {@code State} object to serialize
*
* @return true iff serialization was successful
*
* @see rms.model.State
*/
public static synchronized boolean storeToFile(State state){
if(DUBUG_LOADING)System.out.println("Loader.storeToFile()");
String baseDir = getRootDir();
if(baseDir == null) {
thisLog.log(Level.SEVERE, "Unable to determine user directory.");
return false;
}

ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(new FileOutputStream(baseDir.concat("/").concat(STATE_FILE_NAME)));
out.writeObject(state);
} catch (IOException ex) {
thisLog.log(Level.SEVERE, "Unable to store state.", ex);
return false;
} finally {
Helpers.closeResource(out);
}

return true;
}
}
127 changes: 127 additions & 0 deletions ResearchManagementSystem/src/rms/control/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package rms.control;

import java.io.File;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import rms.model.State;
import rms.model.item.ItemFactory;
import rms.model.item.ItemThread;
import rms.view.MainFrame;

/**
*
* @author Timothy
*/
public class Main {

private static final Logger thisLog = Logger.getLogger(Main.class.getName());

private static MainFrame gui;
private static State state;

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code ">
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
thisLog.log(java.util.logging.Level.SEVERE, "Error setting L&F", ex);
}
//</editor-fold>

//create the view
gui = MainFrame.instance();

// display the UI
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
gui.setVisible(true);
gui.loadStateAndPopulate();
}
});
}

/**
* Load the data from file to State
* @return true iff loading was successful
*/
public static boolean loadStateFromFile(){
state = Loader.loadFromFile();
return state != null;
}

/**
* Store the current state to file
* @return
*/
public static boolean storeStateToFile(){
return Loader.storeToFile(state);
}

public static void deleteThread(){
state.getThreads().remove(gui.getSelectedThread());
gui.refreshThreadListAndDisplay();
gui.clearSelectedThread();
}

/**
* Create a new task on the current thread. If there is no current thread,
* create one.
*/
public static void newTask() {
ItemThread td = getSelectedThreadOrCreate();
ItemFactory.newTaskItem(td);
gui.refreshSelectedThread();
}

/**
* Create a new file on the current thread. If there is no current thread,
* create one.
*/
public static void newFile() {
ItemThread td = getSelectedThreadOrCreate();
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
if(chooser.showOpenDialog(gui) == JFileChooser.APPROVE_OPTION) {
for(File f : chooser.getSelectedFiles()){
ItemFactory.newFileItem(td, f);
}
}
gui.refreshSelectedThread();
}

/**
* Create a new note on the current thread. If there is no current thread,
* create one.
*/
public static void newNote() {
ItemThread td = getSelectedThreadOrCreate();
ItemFactory.newNoteItem(td);
gui.refreshSelectedThread();
}

public static State getState(){
return state;
}

/**
* Gets the currently selected thread. If none is selected, then creates new.
* @return
*/
private static ItemThread getSelectedThreadOrCreate(){
ItemThread td = gui.getSelectedThread();
if(td == null){
td = gui.createAndShowNewThread();
}
return td;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package rms.control.search;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import rms.model.item.Item;
import rms.model.item.ItemThread;

/**
* An AbstractFinder takes a Collection of {@link ItemThread} and returns the
* subset which matches the criteria defined for the specific implementation.
*
* @author Timothy
*/
public abstract class AbstractFinder {

/**
* Searches the {@code input} Collection for {@link ItemThread}s which match
* the criteria of the subclass implementation.
*
* @param input
* @return Set of {@link ItemThread}s which match the criteria
*/
public Set<ItemThread> find(Collection<ItemThread> input){
HashSet<ItemThread> retVal = new HashSet<>();
for(ItemThread t : input){
if(accept(t)){
retVal.add(t);
continue; //continue with the next thread
}

for(Item i : t){
if(accept(i)){
retVal.add(t);
break; //skip remaining items in thread
}
}
}
return retVal;
}

/**
*
* @param item
* @return {@code true} iff the given {@link Item} should be returned by this AbstractFinder
*/
protected abstract boolean accept(Item item);

/**
*
* @param thread
* @return {@code true} iff the given {@link ItemThread} should be returned by this AbstractFinder
*/
protected abstract boolean accept(ItemThread thread);

}
Loading

0 comments on commit aaca0c0

Please sign in to comment.