updated to use new cooja project class

This commit is contained in:
fros4943 2010-12-02 15:28:06 +00:00
parent 7d26ad8426
commit 1d9ed108d4
2 changed files with 844 additions and 763 deletions

View file

@ -26,13 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ProjectConfig.java,v 1.4 2009/10/28 12:05:43 fros4943 Exp $ * $Id: ProjectConfig.java,v 1.5 2010/12/02 15:28:06 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
@ -293,6 +294,25 @@ public class ProjectConfig {
return true; return true;
} }
public boolean appendConfig(ProjectConfig config) {
Enumeration<String> propertyNames = config.getPropertyNames();
while (propertyNames.hasMoreElements()) {
String key = propertyNames.nextElement();
String property = config.getStringValue(key);
if (property.startsWith("+ ")) {
if (myConfig.getProperty(key) != null) {
myConfig.setProperty(key, myConfig.getProperty(key) + " "
+ property.substring(1).trim());
} else {
myConfig.setProperty(key, property.substring(1).trim());
}
} else {
myConfig.setProperty(key, property);
}
}
return true;
}
/** /**
* @return All property names in configuration * @return All property names in configuration
*/ */
@ -338,7 +358,8 @@ public class ProjectConfig {
*/ */
public String getStringValue(String name) { public String getStringValue(String name) {
if (!myConfig.containsKey(name)) { if (!myConfig.containsKey(name)) {
logger.debug("Could not find key named '" + name + "'"); /*logger.debug("Could not find key named '" + name + "'");*/
return null;
} }
return myConfig.getProperty(name); return myConfig.getProperty(name);

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ProjectDirectoriesDialog.java,v 1.16 2010/06/11 09:12:21 fros4943 Exp $ * $Id: ProjectDirectoriesDialog.java,v 1.17 2010/12/02 15:28:06 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -40,7 +40,6 @@ import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame; import java.awt.Frame;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -49,9 +48,9 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
@ -66,6 +65,7 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JSplitPane; import javax.swing.JSplitPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -84,6 +84,7 @@ import javax.swing.tree.TreePath;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.COOJAProject;
import se.sics.cooja.GUI; import se.sics.cooja.GUI;
import se.sics.cooja.ProjectConfig; import se.sics.cooja.ProjectConfig;
@ -100,10 +101,11 @@ public class ProjectDirectoriesDialog extends JDialog {
private GUI gui; private GUI gui;
private JTable table = null; private JTable table = null;
private JTextArea projectInfo = new JTextArea("Project information:");
private DirectoryTreePanel treePanel = null; private DirectoryTreePanel treePanel = null;
private ArrayList<File> currentProjects = new ArrayList<File>(); private ArrayList<COOJAProject> currentProjects = new ArrayList<COOJAProject>();
private File[] finalProjects = null; private COOJAProject[] returnedProjects = null;
/** /**
* Shows a blocking configuration dialog. * Shows a blocking configuration dialog.
@ -111,10 +113,10 @@ public class ProjectDirectoriesDialog extends JDialog {
* *
* @param parent Parent container * @param parent Parent container
* @param gui COOJA * @param gui COOJA
* @param currentProjects Current project configuration * @param currentProjects Current projects
* @return New COOJA projects, or null * @return New COOJA projects, or null
*/ */
public static File[] showDialog(Container parent, GUI gui, File[] currentProjects) { public static COOJAProject[] showDialog(Container parent, GUI gui, COOJAProject[] currentProjects) {
if (GUI.isVisualizedInApplet()) { if (GUI.isVisualizedInApplet()) {
return null; return null;
} }
@ -123,10 +125,10 @@ public class ProjectDirectoriesDialog extends JDialog {
dialog.gui = gui; dialog.gui = gui;
dialog.setLocationRelativeTo(parent); dialog.setLocationRelativeTo(parent);
dialog.setVisible(true); dialog.setVisible(true);
return dialog.finalProjects; return dialog.returnedProjects;
} }
private ProjectDirectoriesDialog(Container parent, File[] projects) { private ProjectDirectoriesDialog(Container parent, COOJAProject[] projects) {
super( super(
parent instanceof Dialog?(Dialog)parent: parent instanceof Dialog?(Dialog)parent:
parent instanceof Window?(Window)parent: parent instanceof Window?(Window)parent:
@ -145,16 +147,20 @@ public class ProjectDirectoriesDialog extends JDialog {
return rowIndex+1; return rowIndex+1;
} }
if (!currentProjects.get(rowIndex).exists()) { COOJAProject p = currentProjects.get(rowIndex);
return currentProjects.get(rowIndex) + " (directory not found)"; if (!p.directoryExists()) {
return p + " (not found)";
} }
if (!new File(currentProjects.get(rowIndex), GUI.PROJECT_CONFIG_FILENAME).exists()) { if (!p.configExists()) {
return currentProjects.get(rowIndex) + " (no " + GUI.PROJECT_CONFIG_FILENAME + " found)"; return p + " (no config)";
} }
if (!p.configRead()) {
return currentProjects.get(rowIndex); return p + " (config error)";
}
return p;
} }
}); });
table.setFillsViewportHeight(true);
table.setTableHeader(null); table.setTableHeader(null);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@ -163,6 +169,7 @@ public class ProjectDirectoriesDialog extends JDialog {
return; return;
} }
selectTreeProject(currentProjects.get(table.getSelectedRow())); selectTreeProject(currentProjects.get(table.getSelectedRow()));
showProjectInfo(currentProjects.get(table.getSelectedRow()));
} }
}); });
table.getColumnModel().getColumn(0).setPreferredWidth(30); table.getColumnModel().getColumn(0).setPreferredWidth(30);
@ -172,25 +179,24 @@ public class ProjectDirectoriesDialog extends JDialog {
public Component getTableCellRendererComponent(JTable table, public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row, Object value, boolean isSelected, boolean hasFocus, int row,
int column) { int column) {
if (!new File(currentProjects.get(row), GUI.PROJECT_CONFIG_FILENAME).exists()) { if (currentProjects.get(row).hasError()) {
setBackground(Color.RED); setBackground(Color.RED);
} else { } else {
setBackground(Color.WHITE); setBackground(table.getBackground());
} }
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, return super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
row, column); row, column);
} }
}); });
/* Add current projects */ /* Add current projects */
for (File projectDir : projects) { for (COOJAProject project : projects) {
addProjectDir(projectDir); addProjectDir(project);
} }
Box mainPane = Box.createVerticalBox(); Box mainPane = Box.createVerticalBox();
Box buttonPane = Box.createHorizontalBox(); Box buttonPane = Box.createHorizontalBox();
JPanel smallPane; JPanel sortPane;
JButton button; JButton button;
/* Lower buttons */ /* Lower buttons */
@ -201,28 +207,20 @@ public class ProjectDirectoriesDialog extends JDialog {
button = new JButton("View merged config"); button = new JButton("View merged config");
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ProjectConfig config;
try { try {
config = new ProjectConfig(true); /* Default config */
} catch (FileNotFoundException ex) { ProjectConfig config = new ProjectConfig(true);
logger.fatal("Could not find default project config file: " + GUI.PROJECT_DEFAULT_CONFIG_FILENAME);
return;
} catch (IOException ex) {
logger.fatal("Error when reading default project config file: " + GUI.PROJECT_DEFAULT_CONFIG_FILENAME);
return;
}
/* Merge configs */ /* Merge configs */
for (File project : getProjects()) { for (COOJAProject project : getProjects()) {
try { config.appendConfig(project.config);
config.appendProjectDir(project);
} catch (Exception ex) {
logger.fatal("Error when merging configurations: " + ex);
return;
}
} }
ConfigViewer.showDialog(ProjectDirectoriesDialog.this, config); ConfigViewer.showDialog(ProjectDirectoriesDialog.this, config);
} catch (Exception ex) {
logger.fatal("Error when merging config: " + ex.getMessage(), ex);
return;
}
} }
}); });
buttonPane.add(button); buttonPane.add(button);
@ -231,7 +229,7 @@ public class ProjectDirectoriesDialog extends JDialog {
button = new JButton("Cancel"); button = new JButton("Cancel");
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ProjectDirectoriesDialog.this.finalProjects = null; ProjectDirectoriesDialog.this.returnedProjects = null;
dispose(); dispose();
} }
}); });
@ -245,12 +243,12 @@ public class ProjectDirectoriesDialog extends JDialog {
Object[] options = { "Ok", "Cancel" }; Object[] options = { "Ok", "Cancel" };
String newDefaultProjectDirs = ""; String newDefaultProjectDirs = "";
for (File f: currentProjects) { for (COOJAProject p: currentProjects) {
if (newDefaultProjectDirs != "") { if (newDefaultProjectDirs != "") {
newDefaultProjectDirs += ";"; newDefaultProjectDirs += ";";
} }
newDefaultProjectDirs += gui.createPortablePath(f, false).getPath(); newDefaultProjectDirs += gui.createPortablePath(p.dir, false).getPath();
} }
newDefaultProjectDirs = newDefaultProjectDirs.replace('\\', '/'); newDefaultProjectDirs = newDefaultProjectDirs.replace('\\', '/');
@ -277,7 +275,7 @@ public class ProjectDirectoriesDialog extends JDialog {
button = new JButton("OK"); button = new JButton("OK");
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ProjectDirectoriesDialog.this.finalProjects = currentProjects.toArray(new File[0]); ProjectDirectoriesDialog.this.returnedProjects = currentProjects.toArray(new COOJAProject[0]);
dispose(); dispose();
} }
}); });
@ -287,16 +285,9 @@ public class ProjectDirectoriesDialog extends JDialog {
/* Center: Tree and list*/ /* Center: Tree and list*/
{ {
final JSplitPane listPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); treePanel = new DirectoryTreePanel(this);
listPane.setLeftComponent(treePanel = new DirectoryTreePanel(this));
listPane.setRightComponent(new JScrollPane(table));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
listPane.setDividerLocation(0.5);
}
});
smallPane = new JPanel(new BorderLayout()); sortPane = new JPanel(new BorderLayout());
Icon icon = UIManager.getLookAndFeelDefaults().getIcon("Table.ascendingSortIcon"); Icon icon = UIManager.getLookAndFeelDefaults().getIcon("Table.ascendingSortIcon");
if (icon == null) { if (icon == null) {
button = new JButton("Up"); button = new JButton("Up");
@ -309,13 +300,13 @@ public class ProjectDirectoriesDialog extends JDialog {
if (selectedIndex <= 0) { if (selectedIndex <= 0) {
return; return;
} }
File file = currentProjects.get(selectedIndex); COOJAProject project = currentProjects.get(selectedIndex);
removeProjectDir(file); removeProjectDir(project);
addProjectDir(file, selectedIndex - 1); addProjectDir(project, selectedIndex - 1);
table.getSelectionModel().setSelectionInterval(selectedIndex - 1, selectedIndex - 1); table.getSelectionModel().setSelectionInterval(selectedIndex - 1, selectedIndex - 1);
} }
}); });
smallPane.add(BorderLayout.NORTH, button); sortPane.add(BorderLayout.NORTH, button);
icon = UIManager.getLookAndFeelDefaults().getIcon("Table.descendingSortIcon"); icon = UIManager.getLookAndFeelDefaults().getIcon("Table.descendingSortIcon");
if (icon == null) { if (icon == null) {
button = new JButton("Down"); button = new JButton("Down");
@ -331,14 +322,15 @@ public class ProjectDirectoriesDialog extends JDialog {
if (selectedIndex >= currentProjects.size() - 1) { if (selectedIndex >= currentProjects.size() - 1) {
return; return;
} }
File file = currentProjects.get(selectedIndex); COOJAProject project = currentProjects.get(selectedIndex);
removeProjectDir(file); removeProjectDir(project);
addProjectDir(file, selectedIndex + 1); addProjectDir(project, selectedIndex + 1);
table.getSelectionModel().setSelectionInterval(selectedIndex + 1, selectedIndex + 1); table.getSelectionModel().setSelectionInterval(selectedIndex + 1, selectedIndex + 1);
} }
}); });
smallPane.add(BorderLayout.SOUTH, button); sortPane.add(BorderLayout.SOUTH, button);
{
button = new JButton("X"); button = new JButton("X");
button.setBackground(Color.RED); button.setBackground(Color.RED);
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
@ -350,28 +342,47 @@ public class ProjectDirectoriesDialog extends JDialog {
if (selectedIndex >= currentProjects.size()) { if (selectedIndex >= currentProjects.size()) {
return; return;
} }
File file = currentProjects.get(selectedIndex); COOJAProject project = currentProjects.get(selectedIndex);
String s1 = "Remove"; String s1 = "Remove";
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = { s1, s2 }; Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(), int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(),
"Remove COOJA project?\n" + file.getAbsolutePath(), "Remove COOJA project?\n" + project,
"Remove COOJA project?", JOptionPane.YES_NO_OPTION, "Remove COOJA project?", JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE, null, options, s1); JOptionPane.WARNING_MESSAGE, null, options, s1);
if (n != JOptionPane.YES_OPTION) { if (n != JOptionPane.YES_OPTION) {
return; return;
} }
removeProjectDir(file); removeProjectDir(project);
} }
}); });
smallPane.add(BorderLayout.CENTER, button); JPanel p = new JPanel(new BorderLayout());
p.add(BorderLayout.SOUTH, button);
sortPane.add(BorderLayout.CENTER, p);
}
mainPane.setBackground(Color.WHITE); JPanel tableAndSort = new JPanel(new BorderLayout());
JPanel listPanelWithSort = new JPanel(new BorderLayout()); JScrollPane scroll = new JScrollPane(table);
listPanelWithSort.add(BorderLayout.CENTER, listPane); tableAndSort.add(BorderLayout.CENTER, scroll);
listPanelWithSort.add(BorderLayout.EAST, smallPane); tableAndSort.add(BorderLayout.EAST, sortPane);
mainPane.add(listPanelWithSort);
final JSplitPane projectPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
projectPane.setTopComponent(tableAndSort);
projectInfo.setEditable(false);
projectPane.setBottomComponent(new JScrollPane(projectInfo));
final JSplitPane listPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
listPane.setLeftComponent(treePanel);
listPane.setRightComponent(projectPane);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
projectPane.setDividerLocation(0.6);
listPane.setDividerLocation(0.5);
}
});
mainPane.add(listPane);
} }
JPanel topPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout());
@ -383,15 +394,72 @@ public class ProjectDirectoriesDialog extends JDialog {
setSize(700, 500); setSize(700, 500);
} }
public File[] getProjects() { protected void showProjectInfo(COOJAProject project) {
return currentProjects.toArray(new File[0]); projectInfo.setText("");
if (project.getDescription() != null) {
projectInfo.append("-- " + project.getDescription() + " --\n\n");
} }
protected void addProjectDir(File projectDir) {
currentProjects.add(projectDir); projectInfo.append("Directory: " + project.dir.getAbsolutePath() +
(project.directoryExists()?"":": NOT FOUND") + "\n");
if (!project.directoryExists()) {
return;
}
projectInfo.append("Configuration: " + project.configFile.getAbsolutePath() +
(project.configExists()?"":": NOT FOUND") + "\n");
if (!project.configExists()) {
return;
}
projectInfo.append("Parsing: " +
(project.configRead()?"OK":"FAILED") + "\n\n");
if (!project.configRead()) {
return;
}
if (project.getConfigPlugins() != null) {
projectInfo.append("Plugins: " + Arrays.toString(project.getConfigPlugins()) + "\n");
}
if (project.getConfigJARs() != null) {
String[] jars = project.getConfigJARs();
projectInfo.append("JARs: " + Arrays.toString(jars) + "\n");
for (String jar: jars) {
File jarFile = GUI.findJarFile(project.dir, jar);
if (jarFile == null) {
projectInfo.append("\tERROR: " + jar + " could not be found!\n");
} else if (!jarFile.exists()) {
projectInfo.append("\tERROR: " + jarFile.getAbsolutePath() + " could not be found!\n");
} else {
projectInfo.append("\t" + jarFile.getAbsolutePath() + " found\n");
}
}
}
if (project.getConfigMoteTypes() != null) {
projectInfo.append("Mote types: " + Arrays.toString(project.getConfigMoteTypes()) + "\n");
}
if (project.getConfigRadioMediums() != null) {
projectInfo.append("Radio mediums: " + Arrays.toString(project.getConfigRadioMediums()) + "\n");
}
if (project.getConfigMoteInterfaces() != null) {
projectInfo.append("Contiki mote interfaces: " + Arrays.toString(project.getConfigMoteInterfaces()) + "\n");
}
if (project.getConfigCSources() != null) {
projectInfo.append("Contiki mote C sources: " + Arrays.toString(project.getConfigCSources()) + "\n");
}
}
public COOJAProject[] getProjects() {
return currentProjects.toArray(new COOJAProject[0]);
}
protected void addProjectDir(COOJAProject project) {
currentProjects.add(project);
((AbstractTableModel)table.getModel()).fireTableDataChanged(); ((AbstractTableModel)table.getModel()).fireTableDataChanged();
} }
protected void addProjectDir(File projectDir, int index) { protected void addProjectDir(File dir) {
currentProjects.add(index, projectDir); currentProjects.add(new COOJAProject(dir));
((AbstractTableModel)table.getModel()).fireTableDataChanged();
}
protected void addProjectDir(COOJAProject project, int index) {
currentProjects.add(index, project);
((AbstractTableModel)table.getModel()).fireTableDataChanged(); ((AbstractTableModel)table.getModel()).fireTableDataChanged();
} }
protected void removeProjectDir(int index) { protected void removeProjectDir(int index) {
@ -399,20 +467,36 @@ public class ProjectDirectoriesDialog extends JDialog {
((AbstractTableModel)table.getModel()).fireTableDataChanged(); ((AbstractTableModel)table.getModel()).fireTableDataChanged();
} }
protected void removeProjectDir(File dir) { protected void removeProjectDir(File dir) {
currentProjects.remove(dir); COOJAProject ps[] = getProjects();
((AbstractTableModel)table.getModel()).fireTableDataChanged(); for (COOJAProject p: ps) {
if (p.dir.equals(dir)) {
removeProjectDir(p);
} }
private int getProjectListIndex(File dir) { }
return currentProjects.indexOf(dir); }
protected void removeProjectDir(COOJAProject project) {
currentProjects.remove(project);
((AbstractTableModel)table.getModel()).fireTableDataChanged();
repaint();
}
private int getProjectListIndex(COOJAProject project) {
return currentProjects.indexOf(project);
} }
public void selectListProject(File dir) { public void selectListProject(File dir) {
int i = getProjectListIndex(dir); /* Check if project exists */
for (COOJAProject p: currentProjects) {
if (dir.equals(p.dir)) {
int i = getProjectListIndex(p);
if (i >= 0) { if (i >= 0) {
table.getSelectionModel().setSelectionInterval(i, i); table.getSelectionModel().setSelectionInterval(i, i);
} }
return;
} }
public void selectTreeProject(File dir) { }
treePanel.selectProject(dir);
}
public void selectTreeProject(COOJAProject project) {
treePanel.selectProject(project.dir);
} }
} }
@ -453,10 +537,10 @@ class DirectoryTreePanel extends JPanel {
if (value instanceof DefaultMutableTreeNode) { if (value instanceof DefaultMutableTreeNode) {
value = ((DefaultMutableTreeNode) value).getUserObject(); value = ((DefaultMutableTreeNode) value).getUserObject();
} }
if (!(value instanceof ProjectDirectory)) { if (!(value instanceof TreeDirectory)) {
return this; return this;
} }
ProjectDirectory td = (ProjectDirectory) value; TreeDirectory td = (TreeDirectory) value;
if (boldFont == null) { if (boldFont == null) {
normalFont = getFont(); normalFont = getFont();
@ -535,10 +619,10 @@ class DirectoryTreePanel extends JPanel {
if (!(o instanceof DefaultMutableTreeNode)) { if (!(o instanceof DefaultMutableTreeNode)) {
return; return;
} }
if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof ProjectDirectory)) { if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof TreeDirectory)) {
return; return;
} }
ProjectDirectory pd = (ProjectDirectory) ((DefaultMutableTreeNode) o).getUserObject(); TreeDirectory pd = (TreeDirectory) ((DefaultMutableTreeNode) o).getUserObject();
Rectangle r = tree.getPathBounds(selPath); Rectangle r = tree.getPathBounds(selPath);
int delta = e.getX() - r.x; int delta = e.getX() - r.x;
if (delta > 18 /* XXX Icon width */) { if (delta > 18 /* XXX Icon width */) {
@ -566,10 +650,10 @@ class DirectoryTreePanel extends JPanel {
if (!(o instanceof DefaultMutableTreeNode)) { if (!(o instanceof DefaultMutableTreeNode)) {
return; return;
} }
if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof ProjectDirectory)) { if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof TreeDirectory)) {
return; return;
} }
ProjectDirectory pd = (ProjectDirectory) ((DefaultMutableTreeNode) o).getUserObject(); TreeDirectory pd = (TreeDirectory) ((DefaultMutableTreeNode) o).getUserObject();
if (pd.isProject()) { if (pd.isProject()) {
DirectoryTreePanel.this.parent.selectListProject(pd.dir); DirectoryTreePanel.this.parent.selectListProject(pd.dir);
} }
@ -577,13 +661,13 @@ class DirectoryTreePanel extends JPanel {
}); });
/* Try expand current COOJA projects */ /* Try expand current COOJA projects */
for (File projectDir: parent.getProjects()) { for (COOJAProject project: parent.getProjects()) {
if (!projectDir.exists()) { if (!project.dir.exists()) {
logger.fatal("Project directory not found: " + projectDir); logger.fatal("Project directory not found: " + project.dir);
continue; continue;
} }
try { try {
String projectCanonical = projectDir.getCanonicalPath(); String projectCanonical = project.dir.getCanonicalPath();
TreePath tp = new TreePath(tree.getModel().getRoot()); TreePath tp = new TreePath(tree.getModel().getRoot());
tp = buildTreePath(projectCanonical, treeRoot, tp, tree); tp = buildTreePath(projectCanonical, treeRoot, tp, tree);
/*logger.info("Expanding: " + tp);*/ /*logger.info("Expanding: " + tp);*/
@ -621,11 +705,11 @@ class DirectoryTreePanel extends JPanel {
for (int i=0; i < tree.getModel().getChildCount(parent); i++) { for (int i=0; i < tree.getModel().getChildCount(parent); i++) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) tree.getModel().getChild(parent, i); DefaultMutableTreeNode child = (DefaultMutableTreeNode) tree.getModel().getChild(parent, i);
Object userObject = child.getUserObject(); Object userObject = child.getUserObject();
if (!(userObject instanceof ProjectDirectory)) { if (!(userObject instanceof TreeDirectory)) {
logger.fatal("Bad tree element: " + userObject.getClass()); logger.fatal("Bad tree element: " + userObject.getClass());
continue; continue;
} }
ProjectDirectory td = (ProjectDirectory) userObject; TreeDirectory td = (TreeDirectory) userObject;
String treeCanonical = td.dir.getCanonicalPath(); String treeCanonical = td.dir.getCanonicalPath();
projectCanonical = projectCanonical.replace('\\', '/'); projectCanonical = projectCanonical.replace('\\', '/');
@ -649,17 +733,17 @@ class DirectoryTreePanel extends JPanel {
return null; return null;
} }
private class ProjectDirectory { private class TreeDirectory {
File dir = null; File dir = null;
File[] subdirs = null; File[] subdirs = null;
public ProjectDirectory(File file) { public TreeDirectory(File file) {
this.dir = file; this.dir = file;
} }
boolean isProject() { boolean isProject() {
for (File project: parent.getProjects()) { for (COOJAProject project: parent.getProjects()) {
if (project.equals(dir)) { if (project.dir.equals(dir)) {
return true; return true;
} }
} }
@ -671,11 +755,11 @@ class DirectoryTreePanel extends JPanel {
boolean subtreeContainsProject() { boolean subtreeContainsProject() {
try { try {
String dirCanonical = dir.getCanonicalPath(); String dirCanonical = dir.getCanonicalPath();
for (File project: parent.getProjects()) { for (COOJAProject project: parent.getProjects()) {
if (!project.exists()) { if (!project.dir.exists()) {
continue; continue;
} }
String projectCanonical = project.getCanonicalPath(); String projectCanonical = project.dir.getCanonicalPath();
if (projectCanonical.startsWith(dirCanonical)) { if (projectCanonical.startsWith(dirCanonical)) {
return true; return true;
} }
@ -707,7 +791,7 @@ class DirectoryTreePanel extends JPanel {
return; return;
} }
for (File device: devices) { for (File device: devices) {
DefaultMutableTreeNode deviceNode = new DefaultMutableTreeNode(new ProjectDirectory(device)); DefaultMutableTreeNode deviceNode = new DefaultMutableTreeNode(new TreeDirectory(device));
computerNode.add(deviceNode); computerNode.add(deviceNode);
} }
} }
@ -718,11 +802,11 @@ class DirectoryTreePanel extends JPanel {
if ((node instanceof DefaultMutableTreeNode)) { if ((node instanceof DefaultMutableTreeNode)) {
node = ((DefaultMutableTreeNode)node).getUserObject(); node = ((DefaultMutableTreeNode)node).getUserObject();
} }
if (!(node instanceof ProjectDirectory)) { if (!(node instanceof TreeDirectory)) {
/* Computer node */ /* Computer node */
return false; return false;
} }
ProjectDirectory td = ((ProjectDirectory)node); TreeDirectory td = ((TreeDirectory)node);
return td.dir.isFile(); return td.dir.isFile();
} }
@ -730,11 +814,11 @@ class DirectoryTreePanel extends JPanel {
if ((parent instanceof DefaultMutableTreeNode)) { if ((parent instanceof DefaultMutableTreeNode)) {
parent = ((DefaultMutableTreeNode)parent).getUserObject(); parent = ((DefaultMutableTreeNode)parent).getUserObject();
} }
if (!(parent instanceof ProjectDirectory)) { if (!(parent instanceof TreeDirectory)) {
/* Computer node */ /* Computer node */
return computerNode.getChildCount(); return computerNode.getChildCount();
} }
ProjectDirectory td = ((ProjectDirectory)parent); TreeDirectory td = ((TreeDirectory)parent);
File[] children; File[] children;
if (td.subdirs != null) { if (td.subdirs != null) {
@ -752,11 +836,11 @@ class DirectoryTreePanel extends JPanel {
if ((parent instanceof DefaultMutableTreeNode)) { if ((parent instanceof DefaultMutableTreeNode)) {
parent = ((DefaultMutableTreeNode)parent).getUserObject(); parent = ((DefaultMutableTreeNode)parent).getUserObject();
} }
if (!(parent instanceof ProjectDirectory)) { if (!(parent instanceof TreeDirectory)) {
/* Computer node */ /* Computer node */
return computerNode.getChildAt(index); return computerNode.getChildAt(index);
} }
ProjectDirectory td = ((ProjectDirectory)parent); TreeDirectory td = ((TreeDirectory)parent);
File[] children; File[] children;
if (td.subdirs != null) { if (td.subdirs != null) {
@ -768,13 +852,13 @@ class DirectoryTreePanel extends JPanel {
if ((children == null) || (index >= children.length)) { if ((children == null) || (index >= children.length)) {
return null; return null;
} }
return new DefaultMutableTreeNode(new ProjectDirectory(children[index])); return new DefaultMutableTreeNode(new TreeDirectory(children[index]));
} }
public int getIndexOfChild(Object parent, Object child) { public int getIndexOfChild(Object parent, Object child) {
if ((parent instanceof DefaultMutableTreeNode)) { if ((parent instanceof DefaultMutableTreeNode)) {
parent = ((DefaultMutableTreeNode)parent).getUserObject(); parent = ((DefaultMutableTreeNode)parent).getUserObject();
} }
if (!(parent instanceof ProjectDirectory)) { if (!(parent instanceof TreeDirectory)) {
/* Computer node */ /* Computer node */
for(int i=0; i < computerNode.getChildCount(); i++) { for(int i=0; i < computerNode.getChildCount(); i++) {
if (computerNode.getChildAt(i).equals(child)) { if (computerNode.getChildAt(i).equals(child)) {
@ -782,7 +866,7 @@ class DirectoryTreePanel extends JPanel {
} }
} }
} }
ProjectDirectory td = ((ProjectDirectory)parent); TreeDirectory td = ((TreeDirectory)parent);
File[] children; File[] children;
if (td.subdirs != null) { if (td.subdirs != null) {
@ -797,7 +881,7 @@ class DirectoryTreePanel extends JPanel {
if (child instanceof DefaultMutableTreeNode) { if (child instanceof DefaultMutableTreeNode) {
child = ((DefaultMutableTreeNode)child).getUserObject(); child = ((DefaultMutableTreeNode)child).getUserObject();
} }
File subDir = ((ProjectDirectory)child).dir; File subDir = ((TreeDirectory)child).dir;
for(int i = 0; i < children.length; i++) { for(int i = 0; i < children.length; i++) {
if (subDir.equals(children[i])) { if (subDir.equals(children[i])) {
return i; return i;
@ -828,59 +912,41 @@ class DirectoryTreePanel extends JPanel {
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
class ConfigViewer extends JDialog { class ConfigViewer extends JDialog {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 6900340477602324582L;
private static Logger logger = Logger.getLogger(ConfigViewer.class);
public static void showDialog(Frame parentFrame, ProjectConfig config) { public static void showDialog(Frame parentFrame, ProjectConfig config) {
ConfigViewer myDialog = new ConfigViewer(parentFrame, config); ConfigViewer myDialog = new ConfigViewer(parentFrame, config);
myDialog.setLocationRelativeTo(parentFrame);
myDialog.setAlwaysOnTop(true); myDialog.setAlwaysOnTop(true);
myDialog.setSize(700, 300);
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); myDialog.setLocationRelativeTo(parentFrame);
if (maxSize != null &&
(myDialog.getSize().getWidth() > maxSize.getWidth()
|| myDialog.getSize().getHeight() > maxSize.getHeight())) {
Dimension newSize = new Dimension();
newSize.height = Math.min((int) maxSize.getHeight(), (int) myDialog.getSize().getHeight());
newSize.width = Math.min((int) maxSize.getWidth(), (int) myDialog.getSize().getWidth());
myDialog.setSize(newSize);
}
if (myDialog != null) {
myDialog.setVisible(true); myDialog.setVisible(true);
} }
}
public static void showDialog(Dialog parentDialog, ProjectConfig config) { public static void showDialog(Dialog parentDialog, ProjectConfig config) {
ConfigViewer myDialog = new ConfigViewer(parentDialog, config); ConfigViewer myDialog = new ConfigViewer(parentDialog, config);
myDialog.setLocationRelativeTo(parentDialog);
myDialog.setAlwaysOnTop(true); myDialog.setAlwaysOnTop(true);
myDialog.setSize(700, 300);
if (myDialog != null) { myDialog.setLocationRelativeTo(parentDialog);
myDialog.setVisible(true); myDialog.setVisible(true);
} }
}
private ConfigViewer(Dialog dialog, ProjectConfig config) { private ConfigViewer(Dialog dialog, ProjectConfig config) {
super(dialog, "Current class configuration", true); super(dialog, "Merged project configuration", true);
init(config); init(config);
} }
private ConfigViewer(Frame frame, ProjectConfig config) { private ConfigViewer(Frame frame, ProjectConfig config) {
super(frame, "Current class configuration", true); super(frame, "Merged project configuration", true);
init(config); init(config);
} }
private void init(ProjectConfig config) { private void init(ProjectConfig config) {
JPanel mainPane = new JPanel(new BorderLayout()); JPanel configPane = new JPanel(new BorderLayout());
JLabel label; JLabel label;
JButton button; JButton button;
// BOTTOM BUTTON PART /* Control */
JPanel buttonPane = new JPanel(); JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(Box.createHorizontalGlue());
button = new JButton("Close"); button = new JButton("Close");
@ -891,14 +957,17 @@ class ConfigViewer extends JDialog {
}); });
buttonPane.add(button); buttonPane.add(button);
// LIST PART /* Config */
JPanel keyPane = new JPanel(); JPanel keyPane = new JPanel();
keyPane.setBackground(Color.WHITE);
keyPane.setLayout(new BoxLayout(keyPane, BoxLayout.Y_AXIS)); keyPane.setLayout(new BoxLayout(keyPane, BoxLayout.Y_AXIS));
mainPane.add(keyPane, BorderLayout.WEST); keyPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
configPane.add(keyPane, BorderLayout.WEST);
JPanel valuePane = new JPanel(); JPanel valuePane = new JPanel();
valuePane.setBackground(Color.WHITE);
valuePane.setLayout(new BoxLayout(valuePane, BoxLayout.Y_AXIS)); valuePane.setLayout(new BoxLayout(valuePane, BoxLayout.Y_AXIS));
mainPane.add(valuePane, BorderLayout.CENTER); configPane.add(valuePane, BorderLayout.EAST);
label = new JLabel("KEY"); label = new JLabel("KEY");
label.setForeground(Color.RED); label.setForeground(Color.RED);
@ -919,20 +988,11 @@ class ConfigViewer extends JDialog {
} }
} }
// Add components
Container contentPane = getContentPane(); Container contentPane = getContentPane();
contentPane.add(new JScrollPane(mainPane), BorderLayout.CENTER); configPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
configPane.setBackground(Color.WHITE);
contentPane.add(new JScrollPane(configPane), BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.SOUTH); contentPane.add(buttonPane, BorderLayout.SOUTH);
pack(); pack();
/* Respect screen size */
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
if (maxSize != null && (getSize().width > maxSize.width)) {
setSize(maxSize.width, getSize().height);
}
if (maxSize != null && (getSize().height > maxSize.height)) {
setSize(getSize().width, maxSize.height);
}
} }
} }