Skip to content

Commit

Permalink
Improved the project-chooser part of the EditorWindow, made the MainL…
Browse files Browse the repository at this point in the history
…auncher launch the EditorWindow, and added a ProjectChooserModel and a SourceFileFilter.
  • Loading branch information
raceimaztion committed May 7, 2011
1 parent 260bdda commit 529a1a5
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 16 deletions.
38 changes: 38 additions & 0 deletions create/simulator/utils/SourceFileFilter.java
@@ -0,0 +1,38 @@
package create.simulator.utils;

import java.io.File;
import java.io.FilenameFilter;

import javax.swing.filechooser.FileFilter;

public class SourceFileFilter extends FileFilter implements FilenameFilter
{
private static SourceFileFilter singleton = null;

public static SourceFileFilter getSingleton()
{
if (singleton == null)
singleton = new SourceFileFilter();

return singleton;
}

public boolean accept(File f)
{
// TODO Auto-generated method stub
return false;
}

public String getDescription()
{
// TODO Auto-generated method stub
return null;
}

public boolean accept(File dir, String name)
{
// TODO Auto-generated method stub
return false;
}

}
7 changes: 4 additions & 3 deletions create/simulator/window/CreateProject.java
Expand Up @@ -19,7 +19,7 @@ public class CreateProject
/**
* These represent all the modules that make up this CreateProject.
*/
protected Vector<String> modules;
protected Vector<String> moduleNames;

protected CreateProject(File projectFolder)
{
Expand All @@ -34,22 +34,23 @@ protected CreateProject(File projectFolder)
embeddedBinFolder.mkdirs();

// Load information about each module
moduleNames = new Vector<String>();
}

/**
* Compiles the current code for execution on this computer.
*/
public void buildSimulatorProject()
{

// TODO: Build the project for local simulation
}

/**
* Compiles the current code for execution on the Command Module.
*/
public void buildEmbeddedProject()
{

// TODO: Build the project for embedded operation.
}

/**
Expand Down
13 changes: 10 additions & 3 deletions create/simulator/window/EditorWindow.java
Expand Up @@ -44,6 +44,9 @@ public class EditorWindow implements ActionListener

protected JScrollPane chooserScroller;

protected JList chooserList;
protected ProjectChooserModel chooserModel;

/**
* Contains all the widgets necessary for the development and testing of projects.
*/
Expand Down Expand Up @@ -154,9 +157,14 @@ private void setup()
window.setJMenuBar(menubar);

// The Chooser card:
chooserPanel = new JPanel(new BorderLayout());
chooserPanel = new JPanel(new BorderLayout(3, 3));

updateProjectList();
chooserModel = new ProjectChooserModel();
chooserList = new JList(chooserModel);
chooserList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

chooserPanel.add(new JLabel("Choose a project to load:"), BorderLayout.NORTH);
chooserPanel.add(chooserList, BorderLayout.CENTER);

mainContainer.add(chooserPanel, CHOOSER_PANEL);

Expand Down Expand Up @@ -204,7 +212,6 @@ protected void closeProject()
*/
protected void updateProjectList()
{

}

/**
Expand Down
13 changes: 3 additions & 10 deletions create/simulator/window/MainLauncher.java
Expand Up @@ -85,16 +85,9 @@ else if (RUNTIME_PLATFORM == Platform.LINUX)
if (!SKETCHBOOK_FOLDER.exists())
SKETCHBOOK_FOLDER.mkdirs();

// TODO: Replace this with the launcher for the EditorWindow:
System.out.printf("Sketchbook folder is: %s\n", SKETCHBOOK_FOLDER.toString());

System.out.println("All current projects:");
String projects[] = getSketchNames();
if (projects != null)
for (String project: projects)
System.out.println(project);
else
System.out.println("No projects!");
// Launch the EditorWindow:
EditorWindow window = new EditorWindow();
window.show();
}

/**
Expand Down
58 changes: 58 additions & 0 deletions create/simulator/window/ProjectChooserModel.java
@@ -0,0 +1,58 @@
package create.simulator.window;

import java.util.Arrays;

import javax.swing.DefaultComboBoxModel;

public class ProjectChooserModel extends DefaultComboBoxModel
{
private static final long serialVersionUID = 9287598745L;

private String[] projectList;

public ProjectChooserModel()
{
projectList = MainLauncher.getSketchNames();

Arrays.sort(projectList);

for (String project : projectList)
addElement(project);
}

public void updateProjectList()
{
int index = getIndexOf(getSelectedItem());
String selected = projectList[index];

String[] newProjectList = MainLauncher.getSketchNames();
Arrays.sort(newProjectList);

// If the arrays are the same, do nothing.
boolean equal = true;
if (projectList.length == newProjectList.length)
{
for (int i=projectList.length-1; i >= 0 && equal; i--)
if (!projectList[i].equals(newProjectList[i]))
equal = false;
}
if (equal)
return;

removeAllElements();

for (String project : newProjectList)
addElement(project);

projectList = newProjectList;

// Find the previously-selected element and select it
int newIndex = Arrays.binarySearch(newProjectList, selected);
if (newIndex >= 0)
setSelectedItem(selected);
else if (projectList.length > 0)
setSelectedItem(projectList[Math.min(index, projectList.length-1)]);
else
setSelectedItem(null);
} // end updateProjectList()
}

0 comments on commit 529a1a5

Please sign in to comment.