save command history with configs

This commit is contained in:
Fredrik Osterlind 2012-01-26 16:16:02 +01:00
parent 207fddddf0
commit 3a02e43e09
1 changed files with 84 additions and 52 deletions

View File

@ -25,8 +25,6 @@
* LIABILITY, OR TORT (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: SerialUI.java,v 1.7 2010/10/07 13:09:28 joxe Exp $
*/
package se.sics.cooja.dialogs;
@ -39,11 +37,12 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Observable;
import java.util.Observer;
import org.jdom.Element;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
@ -52,7 +51,9 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.Mote;
import se.sics.cooja.interfaces.Log;
@ -214,7 +215,14 @@ public abstract class SerialUI extends Log implements SerialPort {
// Receive RS232 data visualizer
logTextPane.setOpaque(false);
logTextPane.setEditable(false);
logTextPane.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if ((e.getModifiers() & (MouseEvent.SHIFT_MASK|MouseEvent.CTRL_MASK)) != 0) {
return;
}
commandField.requestFocusInWindow();
}
});
if (getLastLogMessage() == null) {
logTextPane.setText("");
} else {
@ -272,10 +280,34 @@ public abstract class SerialUI extends Log implements SerialPort {
}
public Collection<Element> getConfigXML() {
StringBuilder sb = new StringBuilder();
for (String s: history) {
if (s == null) {
continue;
}
sb.append(s + "~;");
}
if (sb.length() == 0) {
return null;
}
ArrayList<Element> config = new ArrayList<Element>();
Element element = new Element("history");
element.setText(sb.toString());
config.add(element);
return config;
}
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
for (Element element : configXML) {
if (element.getName().equals("history")) {
String[] history = element.getText().split("~;");
System.arraycopy(history, 0, this.history, 0, history.length);
historyCount = history.length;
historyPos = historyCount;
}
}
}
private int tosChars = 0;