rewrote project dialog, for easier import and management of cooja projects

This commit is contained in:
fros4943 2010-05-19 17:32:53 +00:00
parent 56a3a71108
commit b229e9aa59
3 changed files with 647 additions and 419 deletions

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: GUI.java,v 1.168 2010/04/26 08:19:32 fros4943 Exp $
* $Id: GUI.java,v 1.169 2010/05/19 17:32:54 fros4943 Exp $
*/
package se.sics.cooja;
@ -419,7 +419,7 @@ public class GUI extends Observable {
if (isVisualized()) {
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
"Default projects could not load, reconfigure project directories:" +
"\n\tMenu->Settings->Manage project directories" +
"\n\tMenu->Settings->COOJA projects" +
"\n\nSee console for stack trace with more information.",
"Project loading error", JOptionPane.ERROR_MESSAGE);
}
@ -898,7 +898,7 @@ public class GUI extends Observable {
menuItem.setToolTipText("Not available in applet version");
}
menuItem = new JMenuItem("Manage project directories");
menuItem = new JMenuItem("COOJA projects");
menuItem.setActionCommand("manage projects");
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
@ -906,7 +906,7 @@ public class GUI extends Observable {
menuItem.setEnabled(false);
menuItem.setToolTipText("Not available in applet version");
}
menuItem = new JMenuItem("Compiler configuration wizard");
menuItem.setActionCommand("configuration wizard");
menuItem.addActionListener(guiEventHandler);
@ -2878,7 +2878,7 @@ public class GUI extends Observable {
if (isVisualized()) {
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
"Configured projects could not load, reconfigure project directories:" +
"\n\tMenu->Settings->Manage project directories" +
"\n\tMenu->Settings->COOJA projects" +
"\n\nSee console for stack trace with more information.",
"Project loading error", JOptionPane.ERROR_MESSAGE);
}

View file

@ -1,148 +0,0 @@
package se.sics.cooja.dialogs;
import java.beans.*;
import java.io.File;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import org.apache.log4j.Logger;
class ProjectDirectoryInputDialog extends JDialog implements ActionListener, PropertyChangeListener {
private static Logger logger = Logger.getLogger(ProjectDirectoryInputDialog.class);
private File projectDirectoryPath = null;
private JTextField textField;
private JOptionPane optionPane;
private String buttonAdd = "Add";
private String buttonCancel = "Cancel";
public ProjectDirectoryInputDialog(Window window) {
super(window, ModalityType.APPLICATION_MODAL);
setupDialog();
}
public ProjectDirectoryInputDialog(Dialog dialog) {
super(dialog, ModalityType.APPLICATION_MODAL);
setupDialog();
}
public ProjectDirectoryInputDialog(Frame frame) {
super(frame, ModalityType.APPLICATION_MODAL);
setupDialog();
}
public void setupDialog() {
setTitle("Enter path");
textField = new JTextField(10);
textField.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
pathChanged();
}
public void removeUpdate(DocumentEvent e) {
pathChanged();
}
public void changedUpdate(DocumentEvent e) {
pathChanged();
}
});
Object[] objects = {"Enter path to project directory", textField};
Object[] options = {buttonAdd, buttonCancel};
optionPane = new JOptionPane(objects,
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION,
null,
options,
options[0]);
setContentPane(optionPane);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
optionPane.setValue(new Integer(
JOptionPane.CLOSED_OPTION));
}
});
addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent ce) {
textField.requestFocusInWindow();
}
});
textField.addActionListener(this);
optionPane.addPropertyChangeListener(this);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
pathChanged();
}
});
}
public File getProjectDirectory() {
return projectDirectoryPath;
}
private void pathChanged() {
String newPath = textField.getText();
File projectDir = new File(newPath);
if (!projectDir.exists()) {
textField.setBackground(Color.RED);
textField.setToolTipText("Directory does not exist");
return;
}
if (!projectDir.isDirectory()) {
textField.setBackground(Color.RED);
textField.setToolTipText("Not a directory");
return;
}
// if (!new File(projectDir, GUI.PROJECT_CONFIG_FILENAME).exists()) {
// textField.setBackground(Color.LIGHT_GRAY);
// textField.setToolTipText("No configuration file found");
// return;
// }
textField.setBackground(Color.WHITE);
textField.setToolTipText("");
}
public void actionPerformed(ActionEvent e) {
optionPane.setValue(buttonAdd);
}
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (isVisible() && (e.getSource() == optionPane)
&& (JOptionPane.VALUE_PROPERTY.equals(prop) ||
JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
Object value = optionPane.getValue();
if (value == JOptionPane.UNINITIALIZED_VALUE) {
return;
}
optionPane.setValue(
JOptionPane.UNINITIALIZED_VALUE);
if (buttonAdd.equals(value)) {
projectDirectoryPath = new File(textField.getText());
close();
} else {
projectDirectoryPath = null;
close();
}
}
}
public void close() {
textField.setText(null);
setVisible(false);
}
}