updated to use new cooja project class
This commit is contained in:
parent
7d26ad8426
commit
1d9ed108d4
2 changed files with 844 additions and 763 deletions
|
@ -26,13 +26,14 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
@ -293,6 +294,25 @@ public class ProjectConfig {
|
|||
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
|
||||
*/
|
||||
|
@ -338,7 +358,8 @@ public class ProjectConfig {
|
|||
*/
|
||||
public String getStringValue(String 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);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -40,7 +40,6 @@ import java.awt.Dimension;
|
|||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
@ -49,9 +48,9 @@ import java.awt.event.MouseAdapter;
|
|||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
|
@ -66,6 +65,7 @@ import javax.swing.JPanel;
|
|||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
@ -84,6 +84,7 @@ import javax.swing.tree.TreePath;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import se.sics.cooja.COOJAProject;
|
||||
import se.sics.cooja.GUI;
|
||||
import se.sics.cooja.ProjectConfig;
|
||||
|
||||
|
@ -100,10 +101,11 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
private GUI gui;
|
||||
|
||||
private JTable table = null;
|
||||
private JTextArea projectInfo = new JTextArea("Project information:");
|
||||
private DirectoryTreePanel treePanel = null;
|
||||
|
||||
private ArrayList<File> currentProjects = new ArrayList<File>();
|
||||
private File[] finalProjects = null;
|
||||
private ArrayList<COOJAProject> currentProjects = new ArrayList<COOJAProject>();
|
||||
private COOJAProject[] returnedProjects = null;
|
||||
|
||||
/**
|
||||
* Shows a blocking configuration dialog.
|
||||
|
@ -111,10 +113,10 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
*
|
||||
* @param parent Parent container
|
||||
* @param gui COOJA
|
||||
* @param currentProjects Current project configuration
|
||||
* @param currentProjects Current projects
|
||||
* @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()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -123,10 +125,10 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
dialog.gui = gui;
|
||||
dialog.setLocationRelativeTo(parent);
|
||||
dialog.setVisible(true);
|
||||
return dialog.finalProjects;
|
||||
return dialog.returnedProjects;
|
||||
}
|
||||
|
||||
private ProjectDirectoriesDialog(Container parent, File[] projects) {
|
||||
private ProjectDirectoriesDialog(Container parent, COOJAProject[] projects) {
|
||||
super(
|
||||
parent instanceof Dialog?(Dialog)parent:
|
||||
parent instanceof Window?(Window)parent:
|
||||
|
@ -145,16 +147,20 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
return rowIndex+1;
|
||||
}
|
||||
|
||||
if (!currentProjects.get(rowIndex).exists()) {
|
||||
return currentProjects.get(rowIndex) + " (directory not found)";
|
||||
COOJAProject p = currentProjects.get(rowIndex);
|
||||
if (!p.directoryExists()) {
|
||||
return p + " (not found)";
|
||||
}
|
||||
if (!new File(currentProjects.get(rowIndex), GUI.PROJECT_CONFIG_FILENAME).exists()) {
|
||||
return currentProjects.get(rowIndex) + " (no " + GUI.PROJECT_CONFIG_FILENAME + " found)";
|
||||
if (!p.configExists()) {
|
||||
return p + " (no config)";
|
||||
}
|
||||
|
||||
return currentProjects.get(rowIndex);
|
||||
if (!p.configRead()) {
|
||||
return p + " (config error)";
|
||||
}
|
||||
return p;
|
||||
}
|
||||
});
|
||||
table.setFillsViewportHeight(true);
|
||||
table.setTableHeader(null);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||
|
@ -163,6 +169,7 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
return;
|
||||
}
|
||||
selectTreeProject(currentProjects.get(table.getSelectedRow()));
|
||||
showProjectInfo(currentProjects.get(table.getSelectedRow()));
|
||||
}
|
||||
});
|
||||
table.getColumnModel().getColumn(0).setPreferredWidth(30);
|
||||
|
@ -172,25 +179,24 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
public Component getTableCellRendererComponent(JTable table,
|
||||
Object value, boolean isSelected, boolean hasFocus, int row,
|
||||
int column) {
|
||||
if (!new File(currentProjects.get(row), GUI.PROJECT_CONFIG_FILENAME).exists()) {
|
||||
if (currentProjects.get(row).hasError()) {
|
||||
setBackground(Color.RED);
|
||||
} else {
|
||||
setBackground(Color.WHITE);
|
||||
setBackground(table.getBackground());
|
||||
}
|
||||
|
||||
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
|
||||
row, column);
|
||||
}
|
||||
});
|
||||
|
||||
/* Add current projects */
|
||||
for (File projectDir : projects) {
|
||||
addProjectDir(projectDir);
|
||||
for (COOJAProject project : projects) {
|
||||
addProjectDir(project);
|
||||
}
|
||||
|
||||
Box mainPane = Box.createVerticalBox();
|
||||
Box buttonPane = Box.createHorizontalBox();
|
||||
JPanel smallPane;
|
||||
JPanel sortPane;
|
||||
JButton button;
|
||||
|
||||
/* Lower buttons */
|
||||
|
@ -201,28 +207,20 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
button = new JButton("View merged config");
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ProjectConfig config;
|
||||
try {
|
||||
config = new ProjectConfig(true);
|
||||
} catch (FileNotFoundException ex) {
|
||||
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;
|
||||
}
|
||||
/* Default config */
|
||||
ProjectConfig config = new ProjectConfig(true);
|
||||
|
||||
/* Merge configs */
|
||||
for (File project : getProjects()) {
|
||||
try {
|
||||
config.appendProjectDir(project);
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error when merging configurations: " + ex);
|
||||
return;
|
||||
}
|
||||
for (COOJAProject project : getProjects()) {
|
||||
config.appendConfig(project.config);
|
||||
}
|
||||
|
||||
ConfigViewer.showDialog(ProjectDirectoriesDialog.this, config);
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error when merging config: " + ex.getMessage(), ex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonPane.add(button);
|
||||
|
@ -231,7 +229,7 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
button = new JButton("Cancel");
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ProjectDirectoriesDialog.this.finalProjects = null;
|
||||
ProjectDirectoriesDialog.this.returnedProjects = null;
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
@ -245,12 +243,12 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
Object[] options = { "Ok", "Cancel" };
|
||||
|
||||
String newDefaultProjectDirs = "";
|
||||
for (File f: currentProjects) {
|
||||
for (COOJAProject p: currentProjects) {
|
||||
if (newDefaultProjectDirs != "") {
|
||||
newDefaultProjectDirs += ";";
|
||||
}
|
||||
|
||||
newDefaultProjectDirs += gui.createPortablePath(f, false).getPath();
|
||||
newDefaultProjectDirs += gui.createPortablePath(p.dir, false).getPath();
|
||||
}
|
||||
newDefaultProjectDirs = newDefaultProjectDirs.replace('\\', '/');
|
||||
|
||||
|
@ -277,7 +275,7 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
button = new JButton("OK");
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ProjectDirectoriesDialog.this.finalProjects = currentProjects.toArray(new File[0]);
|
||||
ProjectDirectoriesDialog.this.returnedProjects = currentProjects.toArray(new COOJAProject[0]);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
@ -287,16 +285,9 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
|
||||
/* Center: Tree and list*/
|
||||
{
|
||||
final JSplitPane listPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
||||
listPane.setLeftComponent(treePanel = new DirectoryTreePanel(this));
|
||||
listPane.setRightComponent(new JScrollPane(table));
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
listPane.setDividerLocation(0.5);
|
||||
}
|
||||
});
|
||||
treePanel = new DirectoryTreePanel(this);
|
||||
|
||||
smallPane = new JPanel(new BorderLayout());
|
||||
sortPane = new JPanel(new BorderLayout());
|
||||
Icon icon = UIManager.getLookAndFeelDefaults().getIcon("Table.ascendingSortIcon");
|
||||
if (icon == null) {
|
||||
button = new JButton("Up");
|
||||
|
@ -309,13 +300,13 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
if (selectedIndex <= 0) {
|
||||
return;
|
||||
}
|
||||
File file = currentProjects.get(selectedIndex);
|
||||
removeProjectDir(file);
|
||||
addProjectDir(file, selectedIndex - 1);
|
||||
COOJAProject project = currentProjects.get(selectedIndex);
|
||||
removeProjectDir(project);
|
||||
addProjectDir(project, 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");
|
||||
if (icon == null) {
|
||||
button = new JButton("Down");
|
||||
|
@ -331,14 +322,15 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
if (selectedIndex >= currentProjects.size() - 1) {
|
||||
return;
|
||||
}
|
||||
File file = currentProjects.get(selectedIndex);
|
||||
removeProjectDir(file);
|
||||
addProjectDir(file, selectedIndex + 1);
|
||||
COOJAProject project = currentProjects.get(selectedIndex);
|
||||
removeProjectDir(project);
|
||||
addProjectDir(project, selectedIndex + 1);
|
||||
table.getSelectionModel().setSelectionInterval(selectedIndex + 1, selectedIndex + 1);
|
||||
}
|
||||
});
|
||||
smallPane.add(BorderLayout.SOUTH, button);
|
||||
sortPane.add(BorderLayout.SOUTH, button);
|
||||
|
||||
{
|
||||
button = new JButton("X");
|
||||
button.setBackground(Color.RED);
|
||||
button.addActionListener(new ActionListener() {
|
||||
|
@ -350,28 +342,47 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
if (selectedIndex >= currentProjects.size()) {
|
||||
return;
|
||||
}
|
||||
File file = currentProjects.get(selectedIndex);
|
||||
COOJAProject project = currentProjects.get(selectedIndex);
|
||||
|
||||
String s1 = "Remove";
|
||||
String s2 = "Cancel";
|
||||
Object[] options = { s1, s2 };
|
||||
int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(),
|
||||
"Remove COOJA project?\n" + file.getAbsolutePath(),
|
||||
"Remove COOJA project?\n" + project,
|
||||
"Remove COOJA project?", JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE, null, options, s1);
|
||||
if (n != JOptionPane.YES_OPTION) {
|
||||
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 listPanelWithSort = new JPanel(new BorderLayout());
|
||||
listPanelWithSort.add(BorderLayout.CENTER, listPane);
|
||||
listPanelWithSort.add(BorderLayout.EAST, smallPane);
|
||||
mainPane.add(listPanelWithSort);
|
||||
JPanel tableAndSort = new JPanel(new BorderLayout());
|
||||
JScrollPane scroll = new JScrollPane(table);
|
||||
tableAndSort.add(BorderLayout.CENTER, scroll);
|
||||
tableAndSort.add(BorderLayout.EAST, sortPane);
|
||||
|
||||
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());
|
||||
|
@ -383,15 +394,72 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
setSize(700, 500);
|
||||
}
|
||||
|
||||
public File[] getProjects() {
|
||||
return currentProjects.toArray(new File[0]);
|
||||
protected void showProjectInfo(COOJAProject project) {
|
||||
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();
|
||||
}
|
||||
protected void addProjectDir(File projectDir, int index) {
|
||||
currentProjects.add(index, projectDir);
|
||||
protected void addProjectDir(File dir) {
|
||||
currentProjects.add(new COOJAProject(dir));
|
||||
((AbstractTableModel)table.getModel()).fireTableDataChanged();
|
||||
}
|
||||
protected void addProjectDir(COOJAProject project, int index) {
|
||||
currentProjects.add(index, project);
|
||||
((AbstractTableModel)table.getModel()).fireTableDataChanged();
|
||||
}
|
||||
protected void removeProjectDir(int index) {
|
||||
|
@ -399,20 +467,36 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
((AbstractTableModel)table.getModel()).fireTableDataChanged();
|
||||
}
|
||||
protected void removeProjectDir(File dir) {
|
||||
currentProjects.remove(dir);
|
||||
((AbstractTableModel)table.getModel()).fireTableDataChanged();
|
||||
COOJAProject ps[] = getProjects();
|
||||
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) {
|
||||
int i = getProjectListIndex(dir);
|
||||
/* Check if project exists */
|
||||
for (COOJAProject p: currentProjects) {
|
||||
if (dir.equals(p.dir)) {
|
||||
int i = getProjectListIndex(p);
|
||||
if (i >= 0) {
|
||||
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) {
|
||||
value = ((DefaultMutableTreeNode) value).getUserObject();
|
||||
}
|
||||
if (!(value instanceof ProjectDirectory)) {
|
||||
if (!(value instanceof TreeDirectory)) {
|
||||
return this;
|
||||
}
|
||||
ProjectDirectory td = (ProjectDirectory) value;
|
||||
TreeDirectory td = (TreeDirectory) value;
|
||||
|
||||
if (boldFont == null) {
|
||||
normalFont = getFont();
|
||||
|
@ -535,10 +619,10 @@ class DirectoryTreePanel extends JPanel {
|
|||
if (!(o instanceof DefaultMutableTreeNode)) {
|
||||
return;
|
||||
}
|
||||
if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof ProjectDirectory)) {
|
||||
if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof TreeDirectory)) {
|
||||
return;
|
||||
}
|
||||
ProjectDirectory pd = (ProjectDirectory) ((DefaultMutableTreeNode) o).getUserObject();
|
||||
TreeDirectory pd = (TreeDirectory) ((DefaultMutableTreeNode) o).getUserObject();
|
||||
Rectangle r = tree.getPathBounds(selPath);
|
||||
int delta = e.getX() - r.x;
|
||||
if (delta > 18 /* XXX Icon width */) {
|
||||
|
@ -566,10 +650,10 @@ class DirectoryTreePanel extends JPanel {
|
|||
if (!(o instanceof DefaultMutableTreeNode)) {
|
||||
return;
|
||||
}
|
||||
if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof ProjectDirectory)) {
|
||||
if (!(((DefaultMutableTreeNode) o).getUserObject() instanceof TreeDirectory)) {
|
||||
return;
|
||||
}
|
||||
ProjectDirectory pd = (ProjectDirectory) ((DefaultMutableTreeNode) o).getUserObject();
|
||||
TreeDirectory pd = (TreeDirectory) ((DefaultMutableTreeNode) o).getUserObject();
|
||||
if (pd.isProject()) {
|
||||
DirectoryTreePanel.this.parent.selectListProject(pd.dir);
|
||||
}
|
||||
|
@ -577,13 +661,13 @@ class DirectoryTreePanel extends JPanel {
|
|||
});
|
||||
|
||||
/* Try expand current COOJA projects */
|
||||
for (File projectDir: parent.getProjects()) {
|
||||
if (!projectDir.exists()) {
|
||||
logger.fatal("Project directory not found: " + projectDir);
|
||||
for (COOJAProject project: parent.getProjects()) {
|
||||
if (!project.dir.exists()) {
|
||||
logger.fatal("Project directory not found: " + project.dir);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
String projectCanonical = projectDir.getCanonicalPath();
|
||||
String projectCanonical = project.dir.getCanonicalPath();
|
||||
TreePath tp = new TreePath(tree.getModel().getRoot());
|
||||
tp = buildTreePath(projectCanonical, treeRoot, tp, tree);
|
||||
/*logger.info("Expanding: " + tp);*/
|
||||
|
@ -621,11 +705,11 @@ class DirectoryTreePanel extends JPanel {
|
|||
for (int i=0; i < tree.getModel().getChildCount(parent); i++) {
|
||||
DefaultMutableTreeNode child = (DefaultMutableTreeNode) tree.getModel().getChild(parent, i);
|
||||
Object userObject = child.getUserObject();
|
||||
if (!(userObject instanceof ProjectDirectory)) {
|
||||
if (!(userObject instanceof TreeDirectory)) {
|
||||
logger.fatal("Bad tree element: " + userObject.getClass());
|
||||
continue;
|
||||
}
|
||||
ProjectDirectory td = (ProjectDirectory) userObject;
|
||||
TreeDirectory td = (TreeDirectory) userObject;
|
||||
String treeCanonical = td.dir.getCanonicalPath();
|
||||
|
||||
projectCanonical = projectCanonical.replace('\\', '/');
|
||||
|
@ -649,17 +733,17 @@ class DirectoryTreePanel extends JPanel {
|
|||
return null;
|
||||
}
|
||||
|
||||
private class ProjectDirectory {
|
||||
private class TreeDirectory {
|
||||
File dir = null;
|
||||
File[] subdirs = null;
|
||||
|
||||
public ProjectDirectory(File file) {
|
||||
public TreeDirectory(File file) {
|
||||
this.dir = file;
|
||||
}
|
||||
|
||||
boolean isProject() {
|
||||
for (File project: parent.getProjects()) {
|
||||
if (project.equals(dir)) {
|
||||
for (COOJAProject project: parent.getProjects()) {
|
||||
if (project.dir.equals(dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -671,11 +755,11 @@ class DirectoryTreePanel extends JPanel {
|
|||
boolean subtreeContainsProject() {
|
||||
try {
|
||||
String dirCanonical = dir.getCanonicalPath();
|
||||
for (File project: parent.getProjects()) {
|
||||
if (!project.exists()) {
|
||||
for (COOJAProject project: parent.getProjects()) {
|
||||
if (!project.dir.exists()) {
|
||||
continue;
|
||||
}
|
||||
String projectCanonical = project.getCanonicalPath();
|
||||
String projectCanonical = project.dir.getCanonicalPath();
|
||||
if (projectCanonical.startsWith(dirCanonical)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -707,7 +791,7 @@ class DirectoryTreePanel extends JPanel {
|
|||
return;
|
||||
}
|
||||
for (File device: devices) {
|
||||
DefaultMutableTreeNode deviceNode = new DefaultMutableTreeNode(new ProjectDirectory(device));
|
||||
DefaultMutableTreeNode deviceNode = new DefaultMutableTreeNode(new TreeDirectory(device));
|
||||
computerNode.add(deviceNode);
|
||||
}
|
||||
}
|
||||
|
@ -718,11 +802,11 @@ class DirectoryTreePanel extends JPanel {
|
|||
if ((node instanceof DefaultMutableTreeNode)) {
|
||||
node = ((DefaultMutableTreeNode)node).getUserObject();
|
||||
}
|
||||
if (!(node instanceof ProjectDirectory)) {
|
||||
if (!(node instanceof TreeDirectory)) {
|
||||
/* Computer node */
|
||||
return false;
|
||||
}
|
||||
ProjectDirectory td = ((ProjectDirectory)node);
|
||||
TreeDirectory td = ((TreeDirectory)node);
|
||||
|
||||
return td.dir.isFile();
|
||||
}
|
||||
|
@ -730,11 +814,11 @@ class DirectoryTreePanel extends JPanel {
|
|||
if ((parent instanceof DefaultMutableTreeNode)) {
|
||||
parent = ((DefaultMutableTreeNode)parent).getUserObject();
|
||||
}
|
||||
if (!(parent instanceof ProjectDirectory)) {
|
||||
if (!(parent instanceof TreeDirectory)) {
|
||||
/* Computer node */
|
||||
return computerNode.getChildCount();
|
||||
}
|
||||
ProjectDirectory td = ((ProjectDirectory)parent);
|
||||
TreeDirectory td = ((TreeDirectory)parent);
|
||||
|
||||
File[] children;
|
||||
if (td.subdirs != null) {
|
||||
|
@ -752,11 +836,11 @@ class DirectoryTreePanel extends JPanel {
|
|||
if ((parent instanceof DefaultMutableTreeNode)) {
|
||||
parent = ((DefaultMutableTreeNode)parent).getUserObject();
|
||||
}
|
||||
if (!(parent instanceof ProjectDirectory)) {
|
||||
if (!(parent instanceof TreeDirectory)) {
|
||||
/* Computer node */
|
||||
return computerNode.getChildAt(index);
|
||||
}
|
||||
ProjectDirectory td = ((ProjectDirectory)parent);
|
||||
TreeDirectory td = ((TreeDirectory)parent);
|
||||
|
||||
File[] children;
|
||||
if (td.subdirs != null) {
|
||||
|
@ -768,13 +852,13 @@ class DirectoryTreePanel extends JPanel {
|
|||
if ((children == null) || (index >= children.length)) {
|
||||
return null;
|
||||
}
|
||||
return new DefaultMutableTreeNode(new ProjectDirectory(children[index]));
|
||||
return new DefaultMutableTreeNode(new TreeDirectory(children[index]));
|
||||
}
|
||||
public int getIndexOfChild(Object parent, Object child) {
|
||||
if ((parent instanceof DefaultMutableTreeNode)) {
|
||||
parent = ((DefaultMutableTreeNode)parent).getUserObject();
|
||||
}
|
||||
if (!(parent instanceof ProjectDirectory)) {
|
||||
if (!(parent instanceof TreeDirectory)) {
|
||||
/* Computer node */
|
||||
for(int i=0; i < computerNode.getChildCount(); i++) {
|
||||
if (computerNode.getChildAt(i).equals(child)) {
|
||||
|
@ -782,7 +866,7 @@ class DirectoryTreePanel extends JPanel {
|
|||
}
|
||||
}
|
||||
}
|
||||
ProjectDirectory td = ((ProjectDirectory)parent);
|
||||
TreeDirectory td = ((TreeDirectory)parent);
|
||||
|
||||
File[] children;
|
||||
if (td.subdirs != null) {
|
||||
|
@ -797,7 +881,7 @@ class DirectoryTreePanel extends JPanel {
|
|||
if (child instanceof DefaultMutableTreeNode) {
|
||||
child = ((DefaultMutableTreeNode)child).getUserObject();
|
||||
}
|
||||
File subDir = ((ProjectDirectory)child).dir;
|
||||
File subDir = ((TreeDirectory)child).dir;
|
||||
for(int i = 0; i < children.length; i++) {
|
||||
if (subDir.equals(children[i])) {
|
||||
return i;
|
||||
|
@ -828,59 +912,41 @@ class DirectoryTreePanel extends JPanel {
|
|||
* @author Fredrik Osterlind
|
||||
*/
|
||||
class ConfigViewer extends JDialog {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static Logger logger = Logger.getLogger(ConfigViewer.class);
|
||||
|
||||
private static final long serialVersionUID = 6900340477602324582L;
|
||||
public static void showDialog(Frame parentFrame, ProjectConfig config) {
|
||||
ConfigViewer myDialog = new ConfigViewer(parentFrame, config);
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
myDialog.setAlwaysOnTop(true);
|
||||
|
||||
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
|
||||
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.setSize(700, 300);
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
myDialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showDialog(Dialog parentDialog, ProjectConfig config) {
|
||||
ConfigViewer myDialog = new ConfigViewer(parentDialog, config);
|
||||
myDialog.setLocationRelativeTo(parentDialog);
|
||||
myDialog.setAlwaysOnTop(true);
|
||||
|
||||
if (myDialog != null) {
|
||||
myDialog.setSize(700, 300);
|
||||
myDialog.setLocationRelativeTo(parentDialog);
|
||||
myDialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigViewer(Dialog dialog, ProjectConfig config) {
|
||||
super(dialog, "Current class configuration", true);
|
||||
super(dialog, "Merged project configuration", true);
|
||||
init(config);
|
||||
}
|
||||
|
||||
private ConfigViewer(Frame frame, ProjectConfig config) {
|
||||
super(frame, "Current class configuration", true);
|
||||
super(frame, "Merged project configuration", true);
|
||||
init(config);
|
||||
}
|
||||
|
||||
private void init(ProjectConfig config) {
|
||||
JPanel mainPane = new JPanel(new BorderLayout());
|
||||
JPanel configPane = new JPanel(new BorderLayout());
|
||||
JLabel label;
|
||||
JButton button;
|
||||
|
||||
// BOTTOM BUTTON PART
|
||||
/* Control */
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
|
||||
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
|
||||
|
||||
buttonPane.add(Box.createHorizontalGlue());
|
||||
|
||||
button = new JButton("Close");
|
||||
|
@ -891,14 +957,17 @@ class ConfigViewer extends JDialog {
|
|||
});
|
||||
buttonPane.add(button);
|
||||
|
||||
// LIST PART
|
||||
/* Config */
|
||||
JPanel keyPane = new JPanel();
|
||||
keyPane.setBackground(Color.WHITE);
|
||||
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();
|
||||
valuePane.setBackground(Color.WHITE);
|
||||
valuePane.setLayout(new BoxLayout(valuePane, BoxLayout.Y_AXIS));
|
||||
mainPane.add(valuePane, BorderLayout.CENTER);
|
||||
configPane.add(valuePane, BorderLayout.EAST);
|
||||
|
||||
label = new JLabel("KEY");
|
||||
label.setForeground(Color.RED);
|
||||
|
@ -919,20 +988,11 @@ class ConfigViewer extends JDialog {
|
|||
}
|
||||
}
|
||||
|
||||
// Add components
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue