Commit 853e1058 authored by Andrew McKinney's avatar Andrew McKinney Committed by Gerrit Review System

Added AIMerger Tool to appinventor code base and created and modified appropriate build.xml files

Change-Id: I51dabf18eb9feff48bebd3b00111a9c006a6fb22
parent 74e821fc
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="AIMergerApp" name="AIMergerApp">
<description> App Inventor build AIMerger Tool </description>
<!-- =====================================================================
Import common directory, task, and target definitions.
===================================================================== -->
<import file="../build-common.xml" />
<!-- =====================================================================
AIMerger Tool: builds ../build/AIMerger/AIMerger.jar
===================================================================== -->
<property name="AIMergerApp.pkg" value="edu/mills/feeney/thesis/aimerger" />
<property name="AIMergerApp-class.dir" location="${class.dir}/AIMergerApp" />
<target name="AIMergerApp">
<mkdir dir="${AIMergerApp-class.dir}" />
<copy todir="${AIMergerApp-class.dir}/${AIMergerApp.pkg}/img">
<fileset dir="${src.dir}/${AIMergerApp.pkg}/img" includes="*" />
</copy>
<ai.javac destdir="${AIMergerApp-class.dir}">
<include name="${AIMergerApp.pkg}/**/*.java" />
</ai.javac>
<jar destfile="${local.build.dir}/AIMergerApp.jar"
filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class"
value="edu.mills.feeney.thesis.aimerger.AIMerger" />
<attribute name="Class-Path" value="." />
</manifest>
<fileset dir="${AIMergerApp-class.dir}" />
</jar>
</target>
</project>
package edu.mills.feeney.thesis.aimerger;
/**
* A representation of an App Inventor asset (media file).
*
* @author feeney.kate@gmail.com (Kate Feeney)
*/
public class AIAsset {
// Backing for the asset's directory path from project file
private String assetPath;
/**
* Creates a new AIAsset.
*
* @param assetPath the path to the asset within the project file
*/
public AIAsset(String assetPath) {
this.assetPath = assetPath;
}
/**
* Returns an AIAsset's directory path within the project file.
*
* @return AIAsset's directory path within the project file
*/
public String getPath() {
return assetPath;
}
/**
* Returns the AIAsset's name.
*
* @return AIAsset's name
*/
public String getName() {
// The assetName is the name of the asset's file.
return assetPath.substring(assetPath.lastIndexOf('/') + 1, assetPath.lastIndexOf('.'));
}
}
package edu.mills.feeney.thesis.aimerger;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import javax.swing.JOptionPane;
/**
* A representation of an App Inventor project. This includes its path, name,
* list of assets, list of screens and project properties file.
*
* @author feeney.kate@gmail.com (Kate Feeney)
*/
public class AIProject {
// Backing for the project's directory path from home
private String projectPath;
// Backing for the list of AIScreens
private List<AIScreen> screensList;
// Backing for the list of AIAssets
private List<AIAsset> assetsList;
// Backing for the path to the projects properties file
private String propertiesFilePath;
// Backing for if the project is a valid source file
private boolean valid;
/**
* Creates a new AIProject.
*
* @param projectPath the path to the project from the home directory
*/
public AIProject(String projectPath) {
try {
this.projectPath = projectPath;
// Create screens list.
this.screensList = new LinkedList<AIScreen>();
// Create assets list.
this.assetsList = new LinkedList<AIAsset>();
// Go through each file in the project and create the appropriate classes.
Enumeration<? extends ZipEntry> e = new ZipFile(new File(projectPath)).entries();
while (e.hasMoreElements()) {
// fileName is the path of the file in the project file.
String fileName = (new ZipEntry(e.nextElement())).getName();
// Create an AIScreen from any screen file in the project's src folder.
if (fileName.startsWith("src") && fileName.endsWith(".scm")) {
AIScreen screen = new AIScreen(fileName);
screensList.add(screen);
// Create an AIAsset from any file in the project's assets folder.
} else if (fileName.startsWith("assets")) {
AIAsset asset = new AIAsset(fileName);
assetsList.add(asset);
} else if (fileName.endsWith("project.properties")) {
this.setPropertiesFilePath(fileName);
}
}
// Check if valid project, if not show error.
valid = screensList != null && propertiesFilePath != null;
if (!valid) {
JOptionPane.showMessageDialog(AIMerger.getInstance().myCP, "The selected project is not a"
+ " project source file! Project source files are zip files.", "File error",
JOptionPane.ERROR_MESSAGE);
}
} catch (ZipException e) {
JOptionPane.showMessageDialog(AIMerger.getInstance().myCP,
"The selected project is not a project source file! Project source files are zip files.",
"File error", JOptionPane.ERROR_MESSAGE);
valid = false;
} catch (IOException e) {
JOptionPane.showMessageDialog(AIMerger.getInstance().myCP,
"The selected project is not a project source file! Project source files are zip files.",
"File error", JOptionPane.ERROR_MESSAGE);
valid = false;
}
}
/**
* Returns the AIProject's name.
*
* @return AIProject's name
*/
public String getProjectName() {
// The projectName is the name of the zip file.
if (projectPath.contains(File.separator)) {
return projectPath.substring(projectPath.lastIndexOf(File.separator) + 1,
projectPath.lastIndexOf("."));
} else {
return projectPath;
}
}
/**
* Returns the AIProject's path from home directory.
*
* @return AIProject's path from home directory
*/
public String getProjectPath() {
return projectPath;
}
/**
* Returns the AIProject's list of AIScreens.
*
* @return list of project's AIScreens
*/
public List<AIScreen> getScreensList() {
return screensList;
}
/**
* Returns the AIProject's list of AIAssets.
*
* @return list of project's AIAssets
*/
public List<AIAsset> getAssetsList() {
return assetsList;
}
/**
* Returns the path to the projects properties file from project file.
*
* @return path to project's properties file within the project file
*/
public String getPropertiesFilePath() {
return propertiesFilePath;
}
/**
* Sets the projects properties file
*
* @param propertiesFilePath the path to the project's properties file within the project
*/
public void setPropertiesFilePath(String propertiesFilePath) {
this.propertiesFilePath = propertiesFilePath;
}
/**
* Returns if the project is valid and can be used for a merge.
*
* @return if project is valid
*/
public boolean isValid() {
return this.valid;
}
}
\ No newline at end of file
package edu.mills.feeney.thesis.aimerger;
/**
* A representation of an App Inventor screen.
*
* @author feeney.kate@gmail.com (Kate Feeney)
*/
public class AIScreen {
// Backing for the screen's directory path from project file
private String screenPath;
/**
* Creates a new AIScreen.
*
* @param screenPath the path to the screen within the project file
*/
public AIScreen(String screenPath) {
this.screenPath = screenPath;
}
/**
* Returns an AIScreen's directory path within the project file.
*
* @return AIScreen's directory path within the project file
*/
public String getPath() {
return screenPath;
}
/**
* Returns the AIScreen's name.
*
* @return AIScreen's name
*/
public String getName() {
// The screenName is the name of the screen's file.
return screenPath.substring(screenPath.lastIndexOf('/') + 1, screenPath.lastIndexOf('.'));
}
}
package edu.mills.feeney.thesis.aimerger;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.LinkedList;
/**
* Displays the list of checkboxes.
*
* Informed by code at www.devx.com/tips/Tip/5342 by Trevor Harmon, Febuary 10, 1999.
*
* @author feeney.kate@gmail.com (Kate Feeney)
*
*/
public class CheckBoxList extends JList {
private LinkedList<String> checked = new LinkedList<String>();
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
public CheckBoxList() {
setCellRenderer(new CellRenderer());
// A mouse listener for when the mouse clicks a checkbox
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
// Get index of box clicked.
int index = locationToIndex(e.getPoint());
if (index != -1) {
JCheckBox checkbox = (JCheckBox) getModel().getElementAt(index);
// For all checkboxes other than Screen1 toggle. Screen1 is not selectable since
// Screen1 from the main project is automatically merged.
if (!checkbox.getText().equals("Screen1")) {
checkbox.setSelected(!checkbox.isSelected());
if (checkbox.isEnabled() && !checked.contains(checkbox.getText())) {
checked.add(checkbox.getText());
} else if (checked.contains(checkbox.getText())) {
checked.remove(checkbox.getText());
}
}
repaint();
}
}
});
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
public LinkedList<String> getChecked() {
return checked;
}
/**
* Clears the list of checked items.
*/
public void clearChecked() {
checked.clear();
}
protected class CellRenderer implements ListCellRenderer {
public Component getListCellRendererComponent(JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
JCheckBox checkbox = (JCheckBox) value;
checkbox.setBackground(isSelected ? getSelectionBackground() : getBackground());
checkbox.setForeground(isSelected ? getSelectionForeground() : getForeground());
checkbox.setEnabled(isEnabled());
checkbox.setFont(getFont());
checkbox.setFocusPainted(false);
checkbox.setBorderPainted(true);
checkbox.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder")
: noFocusBorder);
if (checkbox.getText().equals("Screen1")) {
checkbox.setForeground(Color.gray);
}
return checkbox;
}
}
}
\ No newline at end of file
......@@ -29,6 +29,10 @@
<ant inheritAll="false" useNativeBasedir="true" dir="buildserver" target="PlayApp"/>
</target>
<target name="AIMergerApp">
<ant inheritAll="false" useNativeBasedir="true" dir="aimerger" target="AIMergerApp"/>
</target>
<target name="tests">
<ant inheritAll="false" useNativeBasedir="true" dir="appengine" target="tests"/>
<ant inheritAll="false" useNativeBasedir="true" dir="blockseditor" target="tests"/>
......@@ -124,6 +128,7 @@
<target name="clean">
<ant inheritAll="false" useNativeBasedir="true" dir="appengine" target="clean"/>
<ant inheritAll="false" useNativeBasedir="true" dir="aimerger" target="clean"/>
<ant inheritAll="false" useNativeBasedir="true" dir="blockseditor" target="clean"/>
<ant inheritAll="false" useNativeBasedir="true" dir="blockslib" target="clean"/>
<ant inheritAll="false" useNativeBasedir="true" dir="buildserver" target="clean"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment