Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the project-chooser part of the EditorWindow, made the MainL…
…auncher launch the EditorWindow, and added a ProjectChooserModel and a SourceFileFilter.
- Loading branch information
raceimaztion
committed
May 7, 2011
1 parent
260bdda
commit 529a1a5
Showing
5 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |