From fd9f67672b5cd14008ef1171d203fdc8ae5bf394 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 10 Jun 2007 13:14:02 +0200 Subject: [PATCH] Remove unused main module files These files don't seem to be used by anything and resides in subdirectories named "old" and "temp", so it should probably be safe to remove them. --- DIKUClientMainModule/old/gui/Console.java | 847 --------------------- .../old/gui/ConsoleInputStream.java | 67 -- .../old/gui/ConsoleOutputStream.java | 44 -- DIKUClientMainModule/old/gui/FlashImageFilter.java | 40 - DIKUClientMainModule/old/gui/LogIFrame.java | 172 ----- DIKUClientMainModule/old/gui/LogListIFrame.java | 138 ---- DIKUClientMainModule/old/gui/LoginDialog.java | 147 ---- DIKUClientMainModule/old/gui/MainWindow.java | 371 --------- DIKUClientMainModule/old/gui/MoteConsoleView.java | 42 - .../old/gui/MoteControlListIFrame.java | 169 ---- DIKUClientMainModule/old/gui/MoteIFrame.java | 101 --- .../old/gui/MoteLedsActivePanel.java | 33 - DIKUClientMainModule/old/gui/MoteLedsPanel.java | 77 -- DIKUClientMainModule/old/gui/MoteLedsRenderer.java | 28 - DIKUClientMainModule/old/gui/MoteListIFrame.java | 115 --- .../old/gui/MoteStatusIndicator.java | 48 -- DIKUClientMainModule/old/gui/MoteToolBar.java | 87 --- DIKUClientMainModule/old/gui/UniqueIFrame.java | 26 - .../old/gui/UniqueIFrameListener.java | 52 -- .../old/util/IntegerComparator.java | 17 - DIKUClientMainModule/old/util/KeyAdder.java | 5 - .../old/util/KeyListTransferHandler.java | 64 -- .../old/util/KeyListTransferable.java | 37 - DIKUClientMainModule/old/util/KeyTable.java | 7 - DIKUClientMainModule/old/util/KeyedTable.java | 48 -- DIKUClientMainModule/old/util/MoteControl.java | 118 --- .../old/util/MoteControlTable.java | 235 ------ .../old/util/MoteStatusRenderer.java | 65 -- DIKUClientMainModule/old/util/SortedTable.java | 37 - DIKUClientMainModule/old/util/TableSorter.java | 488 ------------ DIKUClientMainModule/temp/ConfirmText.java | 78 -- 31 files changed, 3803 deletions(-) delete mode 100644 DIKUClientMainModule/old/gui/Console.java delete mode 100644 DIKUClientMainModule/old/gui/ConsoleInputStream.java delete mode 100644 DIKUClientMainModule/old/gui/ConsoleOutputStream.java delete mode 100644 DIKUClientMainModule/old/gui/FlashImageFilter.java delete mode 100644 DIKUClientMainModule/old/gui/LogIFrame.java delete mode 100644 DIKUClientMainModule/old/gui/LogListIFrame.java delete mode 100644 DIKUClientMainModule/old/gui/LoginDialog.java delete mode 100644 DIKUClientMainModule/old/gui/MainWindow.java delete mode 100644 DIKUClientMainModule/old/gui/MoteConsoleView.java delete mode 100644 DIKUClientMainModule/old/gui/MoteControlListIFrame.java delete mode 100644 DIKUClientMainModule/old/gui/MoteIFrame.java delete mode 100644 DIKUClientMainModule/old/gui/MoteLedsActivePanel.java delete mode 100644 DIKUClientMainModule/old/gui/MoteLedsPanel.java delete mode 100644 DIKUClientMainModule/old/gui/MoteLedsRenderer.java delete mode 100644 DIKUClientMainModule/old/gui/MoteListIFrame.java delete mode 100644 DIKUClientMainModule/old/gui/MoteStatusIndicator.java delete mode 100644 DIKUClientMainModule/old/gui/MoteToolBar.java delete mode 100644 DIKUClientMainModule/old/gui/UniqueIFrame.java delete mode 100644 DIKUClientMainModule/old/gui/UniqueIFrameListener.java delete mode 100644 DIKUClientMainModule/old/util/IntegerComparator.java delete mode 100644 DIKUClientMainModule/old/util/KeyAdder.java delete mode 100644 DIKUClientMainModule/old/util/KeyListTransferHandler.java delete mode 100644 DIKUClientMainModule/old/util/KeyListTransferable.java delete mode 100644 DIKUClientMainModule/old/util/KeyTable.java delete mode 100644 DIKUClientMainModule/old/util/KeyedTable.java delete mode 100644 DIKUClientMainModule/old/util/MoteControl.java delete mode 100644 DIKUClientMainModule/old/util/MoteControlTable.java delete mode 100644 DIKUClientMainModule/old/util/MoteStatusRenderer.java delete mode 100644 DIKUClientMainModule/old/util/SortedTable.java delete mode 100644 DIKUClientMainModule/old/util/TableSorter.java delete mode 100644 DIKUClientMainModule/temp/ConfirmText.java diff --git a/DIKUClientMainModule/old/gui/Console.java b/DIKUClientMainModule/old/gui/Console.java deleted file mode 100644 index 3913c85..0000000 --- a/DIKUClientMainModule/old/gui/Console.java +++ /dev/null @@ -1,847 +0,0 @@ -package gui; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.io.IOException; -import java.io.InterruptedIOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import javax.swing.JTextPane; -import javax.swing.SwingUtilities; -import javax.swing.Timer; -import javax.swing.text.*; - -/** - * A TextArea that supports terminal like functionality. - * @author Tony Johnson (tonyj@slac.stanford.edu) - * @version $Id: Console.java,v 1.1 2006/07/12 14:59:23 esbenzeuthen Exp $ - */ - -/* - * TODO: Support insert/overstrike mode - * TODO: Cut should only be allowed in input area - * TODO: Limit size of document - * TODO: Make Ctrl^C work properly - * TODO: Add support for command completion - * TODO: Abilty to write images (a la BeanShell) -- maybe done JTextPane has insertIcon method - * TODO: Worry about key bindings (PageUp, PageDown etc) - * TODO: *Document uses too much memory when lots of output! - */ -public class Console extends JTextPane -{ - /** - * - */ - private static final long serialVersionUID = -6492939159097843176L; -private final static String defaultPrompt = "> "; - private String currentPrompt; - private List history = new LinkedList(); - private List list = new ArrayList(); - private List queue = new LinkedList(); - private ListEntry last; - private Object lock = new Object(); - private PrintStream logStream; - private ConsoleInputStream theInputStream; - private SimpleAttributeSet defStyle; - private SimpleAttributeSet promptStyle; - - // We maintain several queues in this code. They are: - // 1) The typeAhead buffer, stuff which has been typed while the program attached to the console - // is busy. As soon as an Return is entered the contents of the typeAhead buffer is moved to the - // pasteAhead buffer. - // 2) The pasteAhead buffer. Complete commands that have been entered, but not yet echoed to the - // console because the program attached to the console is busy. - // 3) The queue, commands that have been entered, echoed to the conole (if appropriate) but not - // yet read by the input stream. - - // Stuff pasted while not waiting for input goes into the pasteAhead buffer - private StringBuffer pasteAhead = new StringBuffer(); - - // Stuff typed while not waiting for input goes into the typeAhead buffer - private StringBuffer typeAhead = new StringBuffer(); - private MyTimer timer; - private boolean log; - private boolean waitingForInput = false; // True while inputStream waiting for input - private int historyPos = -1; - private int maxHistory = 100; - private int start; // Of input area! - private int startLastLine; // Start of last line (before prompt) - - /** Create a new Console */ - public Console() - { - setFont(new Font("Courier", Font.PLAIN, 12)); - // setPreferredSize(new Dimension(300, 200)); - CKeyListener l = new CKeyListener(); - addKeyListener(l); - timer = new MyTimer(l); - setEditable(false); - - defStyle = new SimpleAttributeSet() - { - /** - * - */ - private static final long serialVersionUID = 1L; - - public Object getAttribute(Object key) - { - if (key.equals(StyleConstants.Foreground)) - { - return getForeground(); - } - else return super.getAttribute(key); - } - }; - promptStyle = new SimpleAttributeSet(); - promptStyle.addAttribute(StyleConstants.Foreground, new Color(0, 153, 51)); - } - - /** Create an input stream for reading user input from the console. - * The input stream will use the default prompt. - * @return The newly created input stream - */ - public ConsoleInputStream getInputStream() - { - return getInputStream(defaultPrompt); - } - - /** Create an input stream for reading user input from the console. - * @param initialPrompt The prompt to use for user input - * @return The newly created input stream - */ - public ConsoleInputStream getInputStream(String initialPrompt) - { - if (theInputStream == null) theInputStream = new CInputStream(initialPrompt); - return theInputStream; - } - - /** Sets a stream to use for writing logging output. - * All input/output to the console will be logged to this - * output stream. - * @param out The output stream to use, or null to turn off logging. - */ - public synchronized void setLogStream(OutputStream out) - { - log = !(out == null); - if (logStream != null) logStream.flush(); - if (log) logStream = new PrintStream(out); - else logStream = null; - } - - /** Get the current log stream - * @return The current log stream, or null if no current stream - */ - public OutputStream getLogStream() - { - return logStream; - } - - /** Temporarily disables/enables logging. - * @param log true to enable logging. - */ - public synchronized void setLoggingEnabled(boolean log) - { - this.log = log && (logStream != null); - } - - /** Test if logging is currently enabled - * @return true if logging enabled. - */ - public boolean isLoggingEnabled() - { - return log; - } - - /** Get an output stream for writing to the console. - * @param set The attributes for text created by this output stream, or null for the default - * attributes. - * @param autoShow If true the console will "pop to the front" when new output is written. - * @return The newly created output stream - */ - public ConsoleOutputStream getOutputStream(AttributeSet set, boolean autoShow) - { - return new COutputStream(set, autoShow); - } - public ConsoleOutputStream getOutputStream(AttributeSet set) - { - return getOutputStream(set, false); - } - - /** Adds a listener for CTRL^C events - * @param l The listener to add. - */ - public void addInterruptListener(ActionListener l) - { - listenerList.add(ActionListener.class, l); - } - /** Cleans up resources associated with this console. Closes any input streams - * associated with this console. - */ - public void dispose() - { - setLogStream(null); - if (theInputStream != null) - { - try - { - synchronized (lock) - { - theInputStream.close(); - theInputStream = null; - lock.notify(); - } - } - catch (IOException x) - { - } - } - } - /** - * Insert text (command(s)) as if it were typed by the user. - * The text will be sent to the Console's input stream. Any text already - * typed by the user will not be included in the text sent. - * @param text text to send - */ - public void insertTextAsIfTypedByUser(String text) - { - if (!isEditable()) throw new RuntimeException("Cannot send text to non-editable console"); - if (!text.endsWith("\n")) text += "\n"; - if (waitingForInput) - { - try - { - int pos = text.indexOf('\n'); - String firstLine = text.substring(0, pos); - // Take anything currently on the input line and move it to the end of the pasteAhead buffer - String originalText = lastLine(); - Document doc = getDocument(); - doc.remove(start, doc.getLength() - start); - doc.insertString(start, firstLine + "\n", null); - sendToInputStream(firstLine); - pasteAhead.append(text.substring(pos+1)); - pasteAhead.append(originalText); - } - catch (Throwable x) - { - x.printStackTrace(); // Should never happen - } - } - else - { - pasteAhead.append(text); - if (!text.endsWith("\n")) pasteAhead.append('\n'); - } - } - public void paste() - { - if (!isEditable()) - { - getToolkit().beep(); - } - else - { - try - { - Transferable t = getToolkit().getSystemClipboard().getContents(this); - String text = (String) t.getTransferData(DataFlavor.stringFlavor); - text = removeIllegalCharacters(text); - if (waitingForInput) - { - int pos = text.indexOf('\n'); - boolean containsEOL = pos >= 0; - String firstLine = containsEOL ? text.substring(0, pos) : text; - - // If there is a current selection _in the editable area_ delete it - int sStart = Math.max(start,getSelectionStart()); - int sEnd = Math.max(start,getSelectionEnd()); - if (sEnd-sStart > 0) getDocument().remove(sStart,sEnd-sStart); - // Add first line of pasted text to any current added text, at the insertion point - int cPos = getCaretPosition(); - - // If there is a new line in the pasted text, queue the whole line. - if (containsEOL) - { - getDocument().insertString(cPos, firstLine + "\n", null); - sendToInputStream(firstLine); - pasteAhead.append(text.substring(pos + 1)); - } - else - { - getDocument().insertString(cPos, firstLine, null); - } - } - else - { - pasteAhead.append(text); - } - } - catch (Throwable x) - { - getToolkit().beep(); - } - } - } - private String removeIllegalCharacters(String in) - { - StringBuffer out = null; - int l = in.length(); - for (int i=0; i 0) - { - ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_FIRST, "Break"); - ActionListener[] listeners = (ActionListener[]) listenerList.getListeners(ActionListener.class); - for (int i = listeners.length; i-- > 0;) - { - listeners[i].actionPerformed(event); - } - } - } - /** - * Clears any output from the Console - */ - public void clear() - { - try - { - Document d = getDocument(); - d.remove(0, d.getLength()); - if (waitingForInput) - { - synchronized (lock) - { - lock.notify(); - } - } - } - catch (BadLocationException x) - { - } - } - - private void setLastLine(String line) - { - try - { - int end = getDocument().getLength(); - if (end > start) - { - getDocument().remove(start, end - start); - } - getDocument().insertString(start, line, null); - } - catch (BadLocationException x) - { - x.printStackTrace(); - } - } - - private void consume(KeyEvent event) - { - event.consume(); - getToolkit().beep(); - } - - private void prepareToFlush() - { - if (waitingForInput) - { - try - { - // Take anything currently on the input line and move it to the typeAhead buffer - typeAhead.append(lastLine()); - Document doc = getDocument(); - doc.remove(startLastLine, doc.getLength() - startLastLine); - - // TODO: Fixme, what if temporary prompt was set! Plus we dont want to add the - // initial entry again, as it was already put into the typeahead. - writePrompt(theInputStream.getCurrentPrompt(), null); - } - catch (Throwable x) - { - x.printStackTrace(); // Should never happen - } - } - else flush(); - } - private void flush() - { - try - { - List old = list; - synchronized (this) - { - list = new ArrayList(); - last = null; - } - - Document doc = getDocument(); - for (Iterator i = old.iterator(); i.hasNext();) - { - ListEntry entry = (ListEntry) i.next(); - doc.insertString(doc.getLength(), entry.string.toString(), entry.set); - } - setCaretPosition(doc.getLength()); - } - catch (BadLocationException x) - { - } - } - - private boolean inLastLine() - { - int caret = getCaretPosition(); - return caret >= start; - } - - private String lastLine() - { - try - { - Document doc = getDocument(); - return doc.getText(start, doc.getLength() - start); - } - catch (BadLocationException x) - { - return null; - } - } - - private void sendToInputStream(String line) - { - if (log) logStream.println(currentPrompt+line); - synchronized (lock) - { - boolean wasEmpty = queue.isEmpty(); - queue.add(line + "\n"); - if (line.length() > 0) - { - history.add(line); - } - while (history.size() >= maxHistory) history.remove(0); - historyPos = history.size(); - if (wasEmpty) - { - lock.notify(); - waitingForInput = false; - } - } - } - // Overriden to make sure text entered at the keyboard doesnt inherit the prompt color - public MutableAttributeSet getInputAttributes() { - return defStyle; - } - private void writeMessage(String line, AttributeSet style) - { - try - { - Document doc = getDocument(); - doc.insertString(doc.getLength(), line, style == null ? defStyle : style); - setCaretPosition(doc.getLength()); - } - catch (BadLocationException x) - { - } - } - // This method can be called on any thread, so rather than directly updating the - // console data is added to a queue (list). - private void writeOutput(String s, AttributeSet set) throws IOException - { - synchronized (this) - { - boolean wasEmpty = list.isEmpty(); - // If the attributes are the same as last time, simply append to - // existing ListEntry, otherwise create a new entry. - if ((last != null) && (set == last.set)) - { - last.string.append(s); - } - else - { - list.add(last = new ListEntry(s, set)); - } - if (wasEmpty) - { - timer.startLater(); - } - } - } - - private void writePrompt(String prompt, String initialEntry) - { - flush(); // Flush any output still to be sent to the console - startLastLine = getDocument().getLength(); - try - { - Rectangle r = modelToView(startLastLine); - Insets insets = this.getInsets(); - if (r.x > insets.left) - { - writeMessage("\n", defStyle); - startLastLine = getDocument().getLength(); - } - } - catch (BadLocationException x) {} // Can't happen - currentPrompt = prompt; - if (prompt != null) - { - writeMessage(prompt, promptStyle); - } - start = getDocument().getLength(); - - if (pasteAhead.length() > 0) - { - int pos = pasteAhead.indexOf("\n"); - boolean hasEOL = pos >= 0; - if (hasEOL) - { - String ta = pasteAhead.substring(0, pos); - writeMessage(ta + "\n", null); - pasteAhead.delete(0, pos + 1); - - String text = lastLine(); - setCaretPosition(getDocument().getLength()); - text = text.substring(0, text.length() - 1); // trim \n - sendToInputStream(text); - return; // without setting waitingForInput to true - } - else - { - writeMessage(pasteAhead.toString(), null); - pasteAhead.setLength(0); - if (typeAhead.length() > 0) - { - writeMessage(typeAhead.toString(), null); - typeAhead.setLength(0); - } - } - } - else - { - if (initialEntry != null) - { - writeMessage(initialEntry, null); - } - if (typeAhead.length() > 0) - { - writeMessage(typeAhead.toString(), null); - typeAhead.setLength(0); - } - } - setEditable(true); - // Normally the cursor is automatically made visible when the focus is - // gained. However if setEditable(true) is done when we already have the - // focus then this doesn't work, so... - if (!getCaret().isVisible() && hasFocus()) getCaret().setVisible(true); - waitingForInput = true; - } - - /** Getter for property promptColor. - * @return Value of property promptColor. - * - */ - public Color getPromptColor() - { - return (Color) promptStyle.getAttribute(StyleConstants.Foreground); - } - - /** Setter for property promptColor. - * @param promptColor New value of property promptColor. - * - */ - public void setPromptColor(Color promptColor) - { - promptStyle.addAttribute(StyleConstants.Foreground, promptColor); - } - - public void addNotify() - { - super.addNotify(); - requestFocusInWindow(); - } - - private class CInputStream extends ConsoleInputStream implements Runnable - { - int pos; - private byte[] buffer; - - CInputStream(String prompt) - { - setPrompt(prompt); - } - - public int read() throws IOException - { - if ((buffer == null) || (pos >= buffer.length)) - { - if (!fillBuffer()) return -1; - } - - return buffer[pos++]; - } - - public int read(byte[] b, int off, int len) throws IOException - { - if ((buffer == null) || (pos >= buffer.length)) - { - if (!fillBuffer()) return -1; - } - - int l = Math.min(len, buffer.length - pos); - System.arraycopy(buffer, pos, b, off, l); - pos += l; - - return l; - } - - public void run() - { - writePrompt(getCurrentPrompt(), getInitialEntry()); - } - // Called by the input stream when it needs more input - private boolean fillBuffer() throws IOException - { - synchronized (lock) - { - while (queue.isEmpty()) - { - try - { - SwingUtilities.invokeLater(this); - lock.wait(); - // In case someone disposed of the console while we were waiting - if (theInputStream == null) return false; - } - catch (InterruptedException x) - { - throw new InterruptedIOException(); - } - } - - String line = queue.remove(0).toString(); - buffer = line.getBytes("ISO-8859-1"); - pos = 0; - } - return true; - } - } - - private class CKeyListener extends KeyAdapter implements ActionListener - { - public void keyPressed(KeyEvent keyEvent) - { - if ((keyEvent.getKeyCode() == KeyEvent.VK_C) && ((keyEvent.getModifiers() & keyEvent.CTRL_MASK) != 0)) - { - fireInterruptAction(); - } - else if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) - { - if (!waitingForInput) - { - keyEvent.consume(); - } - else - { - setCaretPosition(getDocument().getLength()); - } - } - else if (!inLastLine()) - { - keyEvent.consume(); // No Beep - } - else if (keyEvent.getKeyCode() == keyEvent.VK_LEFT) - { - if (getCaretPosition() == start) - { - consume(keyEvent); - } - } - else if (keyEvent.getKeyCode() == KeyEvent.VK_UP) - { - if (historyPos <= 0) - { - consume(keyEvent); - } - else - { - String line = history.get(--historyPos).toString(); - setLastLine(line); - keyEvent.consume(); - } - } - else if (keyEvent.getKeyCode() == KeyEvent.VK_DOWN) - { - if (historyPos >= (history.size() - 1)) - { - consume(keyEvent); - } - else - { - String line = history.get(++historyPos).toString(); - setLastLine(line); - keyEvent.consume(); - } - } - } - - public void keyTyped(KeyEvent keyEvent) - { - if (waitingForInput) - { - if (!inLastLine()) - { - setCaretPosition(getDocument().getLength()); - } - else - { - // if the selection spans more than the current line (for instance the prompt) - // Then we need to remove the extra region - Caret caret = getCaret(); - if (caret.getMark() < start) - { - int pos = caret.getDot(); - caret.setDot(start); - caret.moveDot(pos); - } - } - if (keyEvent.getKeyChar() == KeyEvent.VK_BACK_SPACE) - { - int cPos = getCaretPosition(); - if (cPos == start) - { - consume(keyEvent); - } - } - else if (keyEvent.getKeyChar() == keyEvent.VK_ENTER) - { - theInputStream.clearOneTimePrompt(); - String text = lastLine(); - setCaretPosition(getDocument().getLength()); - text = text.substring(0, text.length() - 1); // trim \n - sendToInputStream(text); - } - } - else - { - if (keyEvent.getKeyChar() == KeyEvent.VK_BACK_SPACE) - { - int l = typeAhead.length(); - if (l > 0) - { - typeAhead.deleteCharAt(l - 1); - } - } - else if (keyEvent.getKeyChar() == keyEvent.VK_ENTER) - { - // Move the contents of the typeAhead buffer to the pasteAhead buffer - pasteAhead.append(typeAhead); - pasteAhead.append('\n'); - typeAhead.setLength(0); - } - else if ((keyEvent.getModifiers() & keyEvent.CTRL_MASK) == 0) - { - typeAhead.append(keyEvent.getKeyChar()); - } - keyEvent.consume(); - } - } - // called (on event thread), when new output to be written to console. - public void actionPerformed(ActionEvent e) - { - // If there is stuff which still needs to be flushed, then flush it - if (!list.isEmpty()) prepareToFlush(); - } - } - - class COutputStream extends ConsoleOutputStream - { - COutputStream(AttributeSet set, boolean autoRun) - { - super(set,autoRun); - } - - public void write(byte[] b, int off, int len, AttributeSet set) throws IOException - { - if (log) logStream.write(b,off,len); - writeOutput(new String(b, off, len), set); - } - } - - private static class ListEntry - { - AttributeSet set; - StringBuffer string; - - ListEntry(String string, AttributeSet set) - { - this.string = new StringBuffer(string); - this.set = set; - } - } - private static class MyTimer extends Timer implements Runnable - { - MyTimer(ActionListener l) - { - super(10, l); - setRepeats(false); - } - public void run() - { - start(); - } - void startLater() - { - SwingUtilities.invokeLater(this); - } - } -} \ No newline at end of file diff --git a/DIKUClientMainModule/old/gui/ConsoleInputStream.java b/DIKUClientMainModule/old/gui/ConsoleInputStream.java deleted file mode 100644 index f043759..0000000 --- a/DIKUClientMainModule/old/gui/ConsoleInputStream.java +++ /dev/null @@ -1,67 +0,0 @@ -package gui; - -import java.io.InputStream; - - -/** - * An InputStream for reading input typed into a console. - * @author tonyj - * @version $Id: ConsoleInputStream.java,v 1.1 2006/07/12 14:59:23 esbenzeuthen Exp $ - */ -public abstract class ConsoleInputStream extends InputStream -{ - private String prompt; - private String oneTimePrompt; - private String entry; - - /** - * Sets the prompt. The prompt will be displayed in the console when input - * is needed from the user. - * @param prompt The prompt string - */ - public void setPrompt(String prompt) - { - this.prompt = prompt; - } - /** - * Sets the prompt. The new prompt will be used only once and then the default - * prompt will be restored. - * @param prompt The prompt string - */ - public void setOneTimePrompt(String prompt) - { - this.oneTimePrompt = prompt; - } - - /** Get the current (permanent) prompt. - * @return The prompt string - */ - public String getPrompt() - { - return prompt; - } - String getCurrentPrompt() - { - return oneTimePrompt != null ? oneTimePrompt : prompt; - } - void clearOneTimePrompt() - { - oneTimePrompt = null; - } - /** - * The initial entry is prefilled into the input area following the prompt. - * Unlike the prompt it can be cleared by the user (using backspace for example). - * The initial entry is used only for a single prompt, and is then cleared. - * @param entry The string to pre fill the input area. - */ - public void setInitialEntry(String entry) - { - this.entry = entry; - } - String getInitialEntry() - { - String result = entry; - entry = null; - return result; - } -} \ No newline at end of file diff --git a/DIKUClientMainModule/old/gui/ConsoleOutputStream.java b/DIKUClientMainModule/old/gui/ConsoleOutputStream.java deleted file mode 100644 index f961597..0000000 --- a/DIKUClientMainModule/old/gui/ConsoleOutputStream.java +++ /dev/null @@ -1,44 +0,0 @@ -package gui; - -import java.io.IOException; -import java.io.OutputStream; -import javax.swing.text.AttributeSet; - -/** - * @author Tony Johnson (tonyj@slac.stanford.edu) - * @version $Id: ConsoleOutputStream.java,v 1.1 2006/07/12 14:59:23 esbenzeuthen Exp $ - */ -public abstract class ConsoleOutputStream extends OutputStream -{ - private AttributeSet set; - private boolean autoShow; - private byte[] one = new byte[1]; - - ConsoleOutputStream(AttributeSet set, boolean autoShow) - { - this.set = set; - this.autoShow = autoShow; - } - - public void write(int b) throws IOException - { - one[0] = (byte) b; - write(one, 0, 1, set); - } - - public void write(byte[] b, int off, int len) throws IOException - { - write(b, off, len, set); - } - - AttributeSet getAttributeSet() - { - return set; - } - boolean isAutoShow() - { - return autoShow; - } - - abstract void write(byte[] b, int off, int len, AttributeSet set) throws IOException; -} \ No newline at end of file diff --git a/DIKUClientMainModule/old/gui/FlashImageFilter.java b/DIKUClientMainModule/old/gui/FlashImageFilter.java deleted file mode 100644 index 00c68fe..0000000 --- a/DIKUClientMainModule/old/gui/FlashImageFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -package gui; -import java.io.File; -import javax.swing.filechooser.*; - -/* ImageFilter.java is a 1.4 example used by FileChooserDemo2.java. */ -public class FlashImageFilter extends FileFilter { - public boolean accept(File f) { - if (f.isDirectory()) { - return true; - } - - String extension = getExtension(f); - if (extension != null) { - if (extension.equals("s19")) - { - return true; - } else { - return false; - } - } - - return false; - } - - //The description of this filter - public String getDescription() { - return "Flash images (*.s19)"; - } - - public static String getExtension(File f) { - String ext = null; - String s = f.getName(); - int i = s.lastIndexOf('.'); - - if (i > 0 && i < s.length() - 1) { - ext = s.substring(i+1).toLowerCase(); - } - return ext; - } -} \ No newline at end of file diff --git a/DIKUClientMainModule/old/gui/LogIFrame.java b/DIKUClientMainModule/old/gui/LogIFrame.java deleted file mode 100644 index 292d4b6..0000000 --- a/DIKUClientMainModule/old/gui/LogIFrame.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Created on Sep 28, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package gui; - -import java.awt.BorderLayout; -import java.awt.event.*; -import java.awt.*; - -import javax.swing.*; - -import util.KeyAdder; -import util.KeyedTable; - -import diku.distlab.servicewrappers.LogManagerWrapper; - - -/** - * @author zept - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class LogIFrame extends UniqueIFrame implements ActionListener, KeyAdder -{ - private static final long serialVersionUID = -5459823858980348526L; - static final int xOffset = 10, yOffset = 10; - static int openFrameCount = 0; - static UniqueIFrameListener frameListener = new UniqueIFrameListener(); - - private long log_id; - private JPanel panel; - private KeyedTable table; - private JScrollPane scrollPane; - private JToolBar toolBar; - private String project; - - private LogIFrame(long p_log_id, String project) throws Exception - { - super( new Long(p_log_id) ); - this.setClosable(true); - this.setResizable(true); - Object[] row = (Object[])LogManagerWrapper.getLogIndex().get(new Long(p_log_id)); - this.setTitle((String)row[1]+ " - Log"); - log_id = p_log_id; - // create GUI - this.project = project; - table = new KeyedTable(LogManagerWrapper.getLogMoteList(log_id)); - table.setKeyAdder(this); - panel = new JPanel(new BorderLayout()); - scrollPane = new JScrollPane(table); - scrollPane.setMinimumSize(new Dimension(10,10)); - - toolBar = new JToolBar(); - - createButtons(); - - // ...Then set the window size or call pack... - setSize(300,300); - - // Set the window's location. - setLocation(300+xOffset*openFrameCount++, 100+yOffset*openFrameCount++); - - getContentPane().add(panel); - panel.add(toolBar,BorderLayout.PAGE_START); - panel.add(scrollPane,BorderLayout.CENTER); - } - - public void addKeys(long keys[]) - { - try - { - for (int i = 0 ; i < keys.length ; i ++) - LogManagerWrapper.addMoteToLog(keys[i],log_id); - refreshTable(); - } - catch (Exception e) - { - e.printStackTrace(); - } - - } - - private void createButtons() - { - toolBar.setFloatable(false); - toolBar.add(MainWindow.createButton("refresh","/toolbarButtonGraphics/general/Refresh16.gif","Refresh the mote list.",this)); - toolBar.addSeparator(); - toolBar.add(MainWindow.createButton("enable","/toolbarButtonGraphics/media/Play16.gif","Enable logging.",this)); - toolBar.add(MainWindow.createButton("disable","/toolbarButtonGraphics/media/Stop16.gif","Disable logging.",this)); - toolBar.add(MainWindow.createButton("remove","/toolbarButtonGraphics/general/Remove16.gif","Remove the selected mote from this log.",this)); - toolBar.add(MainWindow.createButton("data","/toolbarButtonGraphics/general/Remove16.gif","Retrieve data from the selected mote.",this)); - } - - private void refreshTable() throws Exception - { - table.setDataTable(LogManagerWrapper.getLogMoteList(log_id)); - } - - public void actionPerformed(ActionEvent e) - { - String cmd = e.getActionCommand(); - int i; - long ids[]; - - try - { - if (cmd.equals("refresh")) - { - refreshTable(); - } - if (cmd.equals("enable")) - { - LogManagerWrapper.activateLog(log_id); - refreshTable(); - } - if (cmd.equals("disable")) - { - LogManagerWrapper.deactivateLog(log_id); - refreshTable(); - } - - if (cmd.equals("remove")) - { - if (JOptionPane.showConfirmDialog(this,"Remove selected motes from log?","Confirm removal",JOptionPane.YES_NO_OPTION) - == JOptionPane.YES_OPTION) - { - ids = table.getSelectedKeys(); - for (i = 0; i< ids.length; i++) - { - LogManagerWrapper.removeMoteFromLog(ids[i],log_id); - } - refreshTable(); - } - } - - if (cmd.equals("data")) - { - ids = table.getSelectedKeys(); - if (ids.length > 0) - { - byte[] data = LogManagerWrapper.getDataLog(log_id,ids[0]); - System.out.print(new String(data)); - } - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - public static void openLogFrame(long log_id, String project) throws Exception - { - LogIFrame logFrame = (LogIFrame)frameListener.displayFrame(new Long(log_id)); - if (logFrame == null) - { - logFrame = new LogIFrame(log_id,project); - MainWindow.getMainWindow().addFrame(logFrame); - frameListener.add(logFrame); - } - } - - public static void closeLogFrame( long log_id ) throws Exception - { - LogIFrame logFrame = (LogIFrame)frameListener.displayFrame(new Long(log_id)); - if (logFrame != null ) logFrame.setClosed(true); - } -} diff --git a/DIKUClientMainModule/old/gui/LogListIFrame.java b/DIKUClientMainModule/old/gui/LogListIFrame.java deleted file mode 100644 index 76c6fc5..0000000 --- a/DIKUClientMainModule/old/gui/LogListIFrame.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Created on Sep 28, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package gui; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.*; -import javax.swing.event.InternalFrameAdapter; -import javax.swing.event.InternalFrameEvent; - -import util.KeyedTable; - -import diku.distlab.servicewrappers.LogManagerWrapper; - -/** - * @author zept - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class LogListIFrame extends JInternalFrame implements ActionListener -{ - /** - * - */ - private static final long serialVersionUID = -9053887444556503752L; - static final int xOffset = 800, yOffset = 0; - static int openFrameCount = 0; - - private JPanel panel; - private KeyedTable table; - private JScrollPane scrollPane; - private JToolBar toolBar; - private String project; - - public LogListIFrame(String projectName) throws Exception - { - super( "Log manager", - true, //resizable - true, //closable - true, //maximizable - true );//iconifiable - this.project = projectName; - this.addInternalFrameListener(new InternalFrameAdapter() { - public void internalFrameActivated(InternalFrameEvent e) { - LogManagerWrapper.updateLogList(); - table.setDataTable(LogManagerWrapper.getLogList()); - } - }); - this.setDefaultCloseOperation(HIDE_ON_CLOSE); - // create GUI - LogManagerWrapper.updateLogList(); - table = new KeyedTable(LogManagerWrapper.getLogList()); - - panel = new JPanel(new BorderLayout()); - scrollPane = new JScrollPane(table); - - toolBar = new JToolBar(); - - createButtons(); - - // ...Then set the window size or call pack... - setSize(300,300); - - // Set the window's location. - setLocation(xOffset, yOffset); - - getContentPane().add(panel); - panel.add(toolBar,BorderLayout.PAGE_START); - panel.add(scrollPane,BorderLayout.CENTER); - - } - - private void createButtons() - { - toolBar.setFloatable(false); - toolBar.add(MainWindow.createButton("refresh","/toolbarButtonGraphics/general/Refresh16.gif","Refresh the log list.",this)); - toolBar.addSeparator(); - toolBar.add(MainWindow.createButton("new","/toolbarButtonGraphics/general/New16.gif","Create a new log.",this)); - toolBar.add(MainWindow.createButton("delete","/toolbarButtonGraphics/general/Delete16.gif","Delete the selected log.",this)); - toolBar.add(MainWindow.createButton("manage","/toolbarButtonGraphics/general/Edit16.gif","Manage the selected log.",this)); - } - - public void actionPerformed(ActionEvent e) - { - long logids[]; - int i; - String cmd = e.getActionCommand(); - - try - { - if (cmd.equals("refresh")) - { - LogManagerWrapper.updateLogList(); - table.setDataTable(LogManagerWrapper.getLogList()); - } - if (cmd.equals("new")) - { - String name = (String)JOptionPane.showInputDialog(this,"Enter name of new log session:"); - LogManagerWrapper.addLog(name); - LogManagerWrapper.updateLogList(); - table.setDataTable(LogManagerWrapper.getLogList()); - } - if (cmd.equals("delete")) - { - if (JOptionPane.showConfirmDialog(this,"Delete selected logs?","Confirm delete",JOptionPane.YES_NO_OPTION) - == JOptionPane.YES_OPTION) - { - logids = table.getSelectedKeys(); - for (i = 0; i< logids.length; i++) - { - LogManagerWrapper.deleteLog(logids[i]); - LogIFrame.closeLogFrame(logids[i]); - } - LogManagerWrapper.updateLogList(); - table.setDataTable(LogManagerWrapper.getLogList()); - } - } - if (cmd.equals("manage")) - { - logids = table.getSelectedKeys(); - for (i = 0; i< logids.length; i++) - { - LogIFrame.openLogFrame(logids[i],project); - } - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } -} diff --git a/DIKUClientMainModule/old/gui/LoginDialog.java b/DIKUClientMainModule/old/gui/LoginDialog.java deleted file mode 100644 index 381f639..0000000 --- a/DIKUClientMainModule/old/gui/LoginDialog.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Created on Oct 3, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package gui; - - -import javax.swing.*; -import java.awt.event.ActionListener; -import java.awt.*; -/** - * @author zept - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class LoginDialog extends JDialog { - - /** - * - */ - private static final long serialVersionUID = -2677961240523912621L; - private JLabel heading, serverlabel,projectlabel, userlabel, passwordlabel; - private JComboBox servername, projectname, username; - private JPasswordField password; - private Container panel; - private JButton bOK,bQuit; - - LoginDialog(JFrame f,ActionListener a) - { - super(f,"Log on to mote server...",true); - servername = new JComboBox(); - projectname = new JComboBox(); - username = new JComboBox(); - password = new JPasswordField(); - - String serverName = MainWindow.getMainWindow().getSettings().getProperty("serverName",null); - if (serverName != null) - { - servername.addItem(serverName); - } - - String projectName = MainWindow.getMainWindow().getSettings().getProperty("projectName",null); - if (projectName != null) - { - projectname.addItem(projectName); - } - - String userName = MainWindow.getMainWindow().getSettings().getProperty("userName",null); - if (userName != null) - { - username.addItem(userName); - } - - servername.setEditable(true); - projectname.setEditable(true); - username.setEditable(true); - - panel = getContentPane(); - GridBagLayout gl = new GridBagLayout(); - panel.setLayout(gl); - - heading = new JLabel("Specifiy server and login credentials"); - heading.setHorizontalAlignment(JLabel.CENTER); - serverlabel = new JLabel("Server:"); - projectlabel = new JLabel("Project:"); - userlabel = new JLabel("User:"); - passwordlabel = new JLabel("Password:"); - bOK = new JButton("Log on..."); - bOK.setActionCommand("connect"); - bOK.addActionListener(a); - - bQuit = new JButton("Quit"); - bQuit.setActionCommand("quit"); - bQuit.addActionListener(a); - - setResizable(false); - setSize(400,290); - - GridBagConstraints c = new GridBagConstraints(); - - c.fill = GridBagConstraints.HORIZONTAL; - c.insets = new Insets(10,15,0,15); - - c.gridx = 1; - c.gridwidth = 8; - - panel.add(heading,c); - - c.weightx = 0.3; - c.gridy = 1; - panel.add(serverlabel,c); - c.gridy = 3; - panel.add(projectlabel,c); - c.gridy = 5; - panel.add(userlabel,c); - c.gridy = 7; - panel.add(passwordlabel,c); - - c.gridx = 1; - c.insets = new Insets(0,15,0,15); - c.weightx = 0.8; - c.gridy = 2; - panel.add(servername,c); - c.gridy = 4; - panel.add(projectname,c); - c.gridy = 6; - panel.add(username,c); - c.gridy = 8; - panel.add(password,c); - - c.gridy = 10; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.LINE_END; - - c.weightx = 0; - c.gridwidth = GridBagConstraints.RELATIVE; - c.gridx = 7; - c.insets = new Insets(20,15,0,15); - panel.add(bOK,c); - c.gridx=8; - panel.add(bQuit,c); - } - - public String getServerName() - { - return (String)(servername.getSelectedItem()); - } - - public String getUserName() - { - return (String)(username.getSelectedItem()); - } - - public String getProjectName() - { - return (String)(projectname.getSelectedItem()); - } - - public String getPassword() - { - return new String(password.getPassword()); - } - -} diff --git a/DIKUClientMainModule/old/gui/MainWindow.java b/DIKUClientMainModule/old/gui/MainWindow.java deleted file mode 100644 index 48a871b..0000000 --- a/DIKUClientMainModule/old/gui/MainWindow.java +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Created on Sep 18, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ - -package gui; - -import diku.distlab.motecontrolclientlib.client.*; -import diku.distlab.servicewrappers.InfrastructureWrapper; -import diku.distlab.servicewrappers.LogManagerWrapper; - -import javax.swing.JOptionPane; -import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import java.util.Properties; -/** - * @author zept - * - * TODO To change the template for this generated type comment go to Window - - * Preferences - Java - Code Style - Code Templates - */ -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JDesktopPane; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JMenuBar; - - -import java.awt.event.*; -import java.awt.*; -import java.io.*; - -/* - * InternalFrameDemo.java is a 1.4 application that requires: - * MyInternalFrame.java - */ -public class MainWindow extends JFrame implements ActionListener, ClientEventListener { - /** - * - */ - private static final long serialVersionUID = 7086473991527334525L; - - private JDesktopPane desktop; - - private static MainWindow mainWindow = null; - - private Client client = null; - private ConnectionInfo currentConnection = null; - - private Properties settings = new Properties(); - - private LogListIFrame logListFrame = null; - - private MoteListIFrame moteListFrame; - - private MoteControlListIFrame moteControlListFrame; - - private LoginDialog loginDialog; - - static Insets buttonInsets = new Insets(0, 0, 0, 0); - - public MainWindow() { - super("Re-Mote - Not connected"); - // Make the big window be indented 50 pixels from each edge - // of the screen. - int inset = 50; - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - - inset * 2); - - // Set up the GUI. - desktop = new JDesktopPane(); // a specialized layered pane - setContentPane(desktop); - setJMenuBar(createMenuBar()); - // create the one and only client object - SimpleMoteManager mm = new SimpleMoteManager(); - client = new Client(mm); - client.addClientListener(this); - - // Make dragging a little faster but perhaps uglier. - desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); - try { - readSettings(); - } catch (Exception e) { - e.printStackTrace(); - } - - } - - public static JButton createButton(String command, String imagepath, - String tooltip, ActionListener listener) { - - java.net.URL imageURL = MainWindow.class.getResource(imagepath); - - ImageIcon icon = new ImageIcon(imageURL); - JButton button = new JButton(icon); - button.setMargin(buttonInsets); - button.setActionCommand(command); - button.setToolTipText(tooltip); - button.addActionListener(listener); - return button; - } - - protected JMenuBar createMenuBar() { - JMenuBar menuBar = new JMenuBar(); - - JMenu menu = new JMenu("Session"); - menu.setMnemonic(KeyEvent.VK_S); - menuBar.add(menu); - - JMenuItem menuItem = new JMenuItem("Disconnect..."); - menuItem.setActionCommand("disconnect"); - menuItem.addActionListener(this); - menu.add(menuItem); - - menuItem = new JMenuItem("Quit"); - menuItem.setActionCommand("quit"); - menuItem.addActionListener(this); - menu.add(menuItem); - - menu = new JMenu("View"); - menu.setMnemonic(KeyEvent.VK_V); - menuBar.add(menu); - - menuItem = new JMenuItem("All motes"); - menuItem.setActionCommand("motelist"); - menuItem.addActionListener(this); - menu.add(menuItem); - - menuItem = new JMenuItem("Controlled motes"); - menuItem.setActionCommand("motecontrollist"); - menuItem.addActionListener(this); - menu.add(menuItem); - - menuItem = new JMenuItem("Log manager"); - menuItem.setActionCommand("logmanager"); - menuItem.addActionListener(this); - menu.add(menuItem); - - return menuBar; - } - - // React to menu selections. - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - try { - if ("motelist".equals(cmd)) { - createMoteListFrame(); - } else if ("motecontrollist".equals(cmd)) { - createMoteControlListFrame(); - } else if ("logmanager".equals(cmd)) { - createLogListFrame(); - } else if ("disconnect".equals(cmd)) { - client.disconnect(); - } else if ("connect".equals(cmd)) { - connect(); - } else { // quit - quit(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - private void connect() { - try { - String server, user, project, pass; - - server = loginDialog.getServerName(); - project = loginDialog.getProjectName(); - user = loginDialog.getUserName(); - pass = loginDialog.getPassword(); - - loginDialog.dispose(); - - if (project == null) - project = ""; - - if (user == null) - user = ""; - - settings.setProperty("serverName", server); - settings.setProperty("projectName", project); - settings.setProperty("userName", user); - MainWindow.getMainWindow().saveSettings(); - - LogManagerWrapper.logon(server,project,user,pass); - - currentConnection = new ConnectionInfo(server,project,user,pass,10000); - client.connect(currentConnection); - if (client.isConnected()) { - InfrastructureWrapper.setServerName(server); - } else { - JOptionPane.showMessageDialog(this, - "Could not connect with the supplied credentials."); - createLoginDialog(); - } - - } catch (Exception ex) { - JOptionPane.showMessageDialog(this, "Login error: " - + ex.getMessage()); - ex.printStackTrace(); - createLoginDialog(); - } - } - - public void saveSettings() throws Exception { - File settingsFile = new File(".re-mote"); - if (settingsFile.exists()) - settingsFile.delete(); - settingsFile.createNewFile(); - - FileOutputStream so = new FileOutputStream(settingsFile); - settings.store(so, null); - - } - - protected void readSettings() throws Exception { - File settingsFile = new File(".re-mote"); - - if (settingsFile.exists()) { - FileInputStream si = new FileInputStream(settingsFile); - settings.load(si); - si.close(); - } - } - - public void addFrame(JInternalFrame frame) { - frame.setVisible(true); // necessary as of 1.3 - desktop.add(frame); - try { - frame.setSelected(true); - } catch (java.beans.PropertyVetoException e) { - } - } - -protected void createLoginDialog() - { - if (loginDialog == null) - { - loginDialog = new LoginDialog(this,this); - } - loginDialog.setLocationRelativeTo(this); - loginDialog.setVisible(true); - loginDialog.toFront(); - System.out.println("Created login dialog"); - } - -protected void createMoteControlListFrame() { - if (moteControlListFrame == null) { - moteControlListFrame = new MoteControlListIFrame( - "Controlled motes", (SimpleMoteManager)client.getMoteManager()); - addFrame(moteControlListFrame); - } else { - moteControlListFrame.setVisible(true); - moteControlListFrame.toFront(); - } - } - - protected void createLogListFrame() throws Exception { - if (logListFrame == null) { - logListFrame = new LogListIFrame(currentConnection.getProjectName()); - addFrame(logListFrame); - } else { - logListFrame.setVisible(true); - logListFrame.toFront(); - } - - } - - protected void createMoteListFrame() throws Exception { - if (moteListFrame == null) { - moteListFrame = new MoteListIFrame("All motes",(SimpleMoteManager)client.getMoteManager()); - addFrame(moteListFrame); - } else { - moteListFrame.setVisible(true); - moteListFrame.toFront(); - } - } - - // Quit the application. - protected void quit() { - // if (client != null) client.disconnect(); - System.exit(0); - } - - /** - * Create the GUI and show it. For thread safety, this method should be - * invoked from the event-dispatching thread. - */ - private static void createAndShowGUI() { - // Make sure we have nice window decorations. - JFrame.setDefaultLookAndFeelDecorated(true); - - // Create and set up the window. - MainWindow frame = new MainWindow(); - mainWindow = frame; - - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - // Display the window. - frame.setVisible(true); - } - - /*public void update(Observable obs, Object obj) { - String projectName, serverName, userName; - // check connection status - if (obj == null) { - - } - - if (obj != null && obj.getClass() == ConfirmText.class) { - ConfirmText msg = (ConfirmText) obj; - Object[] row = (Object[]) diku.distlab.tablemodel.ServerTables.getMoteIndex().get( - new Long(msg.getMote_id())); - JOptionPane.showMessageDialog(this, "Mote at site " - + (String) row[2] + ":\n" + msg.getMessage(), "Error!", - JOptionPane.ERROR_MESSAGE); - } - - }*/ - - public static void main(String[] args) throws Exception { - // Schedule a job for the event-dispatching thread: - // creating and showing this application's GUI. - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - try { - createAndShowGUI(); - mainWindow.createLoginDialog(); - mainWindow.createMoteListFrame(); - mainWindow.createMoteControlListFrame(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - - } - - public static MainWindow getMainWindow() { - return mainWindow; - } - - public Client getClient() { - return client; - } - - public Properties getSettings() { - return settings; - } - - public void eventFired(Client client,ClientEvent event) - { - switch (event.getId()) - { - case ClientEvent.CONNECTED: - ConnectionInfo c = currentConnection; - setTitle("Re-Mote - " + c.getProjectName() + - "(" + c.getUserName() + ")" - + "@" + c.getServerName()); - break; - case ClientEvent.DISCONNECTED: - createLoginDialog(); - break; - } - } -} diff --git a/DIKUClientMainModule/old/gui/MoteConsoleView.java b/DIKUClientMainModule/old/gui/MoteConsoleView.java deleted file mode 100644 index 3ba8a21..0000000 --- a/DIKUClientMainModule/old/gui/MoteConsoleView.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Created on Sep 18, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package gui; -import javax.swing.*; -import diku.distlab.motecontrolclientlib.client.*; -import java.util.*; -import java.awt.event.*; -import java.awt.BorderLayout; -import util.MoteControl; -/** - * @author zept - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class MoteConsoleView extends JPanel { - - private static final long serialVersionUID = 2666563646974168408L; - private MoteControl moteControl; - private JScrollPane scrollpane; - private Console text; - - public MoteConsoleView(MoteControl moteControl) - { - super(new BorderLayout()); - - text = new Console(); - moteControl.attachOutputStream(text.getOutputStream(null)); - moteControl.attachInputStream(text.getInputStream(null)); - - scrollpane = new JScrollPane(text,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - - add(scrollpane,BorderLayout.CENTER); - - } - - -} diff --git a/DIKUClientMainModule/old/gui/MoteControlListIFrame.java b/DIKUClientMainModule/old/gui/MoteControlListIFrame.java deleted file mode 100644 index 7606c9b..0000000 --- a/DIKUClientMainModule/old/gui/MoteControlListIFrame.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Created on Sep 28, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package gui; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.FileInputStream; - -import javax.swing.*; - -import util.MoteControl; -import util.MoteControlTable; -import util.MoteStatusRenderer; -import util.TableSorter; -import util.IntegerComparator; -import diku.distlab.motecontrolclientlib.client.*; -/** - * @author zept - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class MoteControlListIFrame extends JInternalFrame implements ActionListener -{ - /** - * - */ - private static final long serialVersionUID = 7446251238116499722L; - static final int xOffset = 300, yOffset = 0; - static int openFrameCount = 0; - - private JPanel panel; - private JTable table; - private JScrollPane scrollPane; - private JToolBar toolBar; - private MoteControlTable moteTableModel; - private TableSorter sorter; - - private SimpleMoteManager moteManager; - - public MoteControlListIFrame(String title,SimpleMoteManager moteManager) - { - super( title, - true, //resizable - true, //closable - true, //maximizable - true );//iconifiable - this.setDefaultCloseOperation(HIDE_ON_CLOSE); - this.moteManager = moteManager; - // create GUI - moteTableModel = new MoteControlTable(moteManager.getMoteList()); - panel = new JPanel(new BorderLayout()); - sorter = new TableSorter(moteTableModel); - table = new JTable(sorter); - table.setDefaultRenderer(SimpleMoteStatus.class,new MoteStatusRenderer()); - table.setDefaultRenderer(LedsInputStream.class,new MoteLedsRenderer()); - sorter.setTableHeader(table.getTableHeader()); - sorter.setColumnComparator(Integer.class,new IntegerComparator()); - sorter.setColumnComparator(SimpleMoteStatus.class,new MoteStatusRenderer()); - scrollPane = new JScrollPane(table); - toolBar = new JToolBar(); - - createButtons(); - - // ...Then set the window size or call pack... - setSize(500,300); - - // Set the window's location. - setLocation(xOffset, yOffset); - - getContentPane().add(panel); - panel.add(toolBar,BorderLayout.PAGE_START); - panel.add(scrollPane,BorderLayout.CENTER); - - } - - private void createButtons() - { - toolBar.setFloatable(false); - toolBar.add(MainWindow.createButton("release","/toolbarButtonGraphics/general/Remove16.gif","Stop using the selected mote(s).",this)); - toolBar.addSeparator(); - toolBar.add(MainWindow.createButton("console","/toolbarButtonGraphics/development/Host16.gif","Open console windows for the selected mote(s).",this)); - toolBar.addSeparator(); - toolBar.add(MainWindow.createButton("program","/toolbarButtonGraphics/general/SaveAll16.gif","Upload a program to the selected mote(s).",this)); - toolBar.add(MainWindow.createButton("start","/toolbarButtonGraphics/media/Play16.gif","Start the selected mote(s).",this)); - toolBar.add(MainWindow.createButton("stop","/toolbarButtonGraphics/media/Stop16.gif","Stop the selected mote(s).",this)); - toolBar.add(MainWindow.createButton("reset","/toolbarButtonGraphics/media/StepForward16.gif","Reset the selected mote(s).",this)); - } - - - - public void actionPerformed(ActionEvent e) - { - String cmd = e.getActionCommand(); - int i; - int rows[]; - long motes[]; - rows = table.getSelectedRows(); - if (rows.length > 0) - { - motes = new long[rows.length]; - for (i=0;i s1.longValue()) return 1; - return 0; - } - -} diff --git a/DIKUClientMainModule/old/util/KeyAdder.java b/DIKUClientMainModule/old/util/KeyAdder.java deleted file mode 100644 index 61ed219..0000000 --- a/DIKUClientMainModule/old/util/KeyAdder.java +++ /dev/null @@ -1,5 +0,0 @@ -package util; - -public interface KeyAdder { - public void addKeys(long keys[]); -} diff --git a/DIKUClientMainModule/old/util/KeyListTransferHandler.java b/DIKUClientMainModule/old/util/KeyListTransferHandler.java deleted file mode 100644 index d4e3a1e..0000000 --- a/DIKUClientMainModule/old/util/KeyListTransferHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -package util; - -import javax.swing.TransferHandler; -import javax.swing.JComponent; -import java.awt.datatransfer.*; -import java.util.ArrayList; - -public class KeyListTransferHandler extends TransferHandler { - - /** - * - */ - private static final long serialVersionUID = -6355189408049194085L; - - public KeyListTransferHandler() - { - super(); - } - - public int getSourceActions(JComponent c) { - return COPY_OR_MOVE; - } - - public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) - { - // TODO: this is unsafe! - return true; - } - - protected Transferable createTransferable(JComponent c) - { - Transferable t = null; - try - { - t = new KeyListTransferable(((KeyTable)c).getSelectedKeys()); - } - catch (Exception e) - { - e.printStackTrace(); - } - return t; - } - - public boolean importData(JComponent comp, Transferable t) - { - try - { - ArrayList keyList = (ArrayList)t.getTransferData(t.getTransferDataFlavors()[0]); - long keys[] = new long[keyList.size()]; - for (int i=0; i=0) - { - try { - sink.write(b); - } - catch (Exception e) - { - sink = null; - } - - } - } - } - catch (Exception e) - { - sink = null; - } - } - }; - - - Thread dataThread = new Thread(r); - dataThread.start(); - } - - public SimpleMote getMote() { - return mote; - } - - public LedsInputStream getMoteLeds() { - return moteLeds; - } - - public boolean isLedsEnabled() { - return ledsEnabled; - } - - public void enableLeds() { - if (this.ledsEnabled) return; - this.moteIn = this.moteLeds; - this.ledsEnabled = true; - } - - public void disableLeds() { - this.moteIn = this.dataSink; - this.ledsEnabled = false; - } - - protected InputStream getMoteIn() - { - return this.moteIn; - } - -} diff --git a/DIKUClientMainModule/old/util/MoteControlTable.java b/DIKUClientMainModule/old/util/MoteControlTable.java deleted file mode 100644 index 1d40569..0000000 --- a/DIKUClientMainModule/old/util/MoteControlTable.java +++ /dev/null @@ -1,235 +0,0 @@ -package util; - -import java.util.Observable; -import java.util.Vector; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Observer; -import javax.swing.table.AbstractTableModel; -import diku.distlab.motecontrolclientlib.client.*; -import diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MsgCommand; -import diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MsgResult; -import diku.distlab.servicewrappers.InfrastructureWrapper; - - -public class MoteControlTable extends AbstractTableModel implements MoteListListener, SimpleMoteStatusListener { - - private static final long serialVersionUID = -8759189345776880210L; - - protected Hashtable moteControlMap; - protected Vector moteControlVector; - - protected class LedsListenerWrapper implements LedsListener - { - MoteControlTable table; - SimpleMote mote; - - public LedsListenerWrapper(MoteControlTable table, SimpleMote mote) { - super(); - this.table = table; - this.mote = mote; - } - - public void ledsChanged(LedsInputStream leds) { - this.table.ledsChange(mote); - } - - } - - public MoteControlTable(MoteList moteList) - { - moteControlMap = new Hashtable(); - // create mote controls and add to the list - Iterator i = moteList.getCollectionView().iterator(); - while (i.hasNext()) - { - this.addMote((SimpleMote)i.next()); - } - this.refreshTable(); - moteList.addListener(this); - - } - - public Class getColumnClass(int columnIndex) - { - switch (columnIndex) - { - case 0: - return Short.class; - case 1: - return String.class; - case 2: - return SimpleMoteStatus.class; - case 3: - return String.class; - case 4: - return LedsInputStream.class; - default: - return null; - } - } - - public int getColumnCount() - { - return 4; - } - - public int getRowCount() - { - return this.moteControlVector.size(); - } - - public String getColumnName(int columnIndex) - { - switch (columnIndex) - { - case 0: - return "TOS address"; - case 1: - return "Site"; - case 2: - return "Status"; - case 3: - return "Last request"; - case 4: - return "Leds"; - default: - return ""; - } - } - - public Object getValueAt(int rowIndex, int columnIndex) - { - Long id; - Object[] row; - MoteControl moteControl = (MoteControl)this.moteControlVector.get(rowIndex); - SimpleMote mote = moteControl.mote; - switch (columnIndex) - { - case -2: - return this.moteControlVector.get(rowIndex); - case -1: - return new Long(mote.getId()); - case 0: // TOS ADDRESS - id = new Long(mote.getId()); - row =(Object[])(InfrastructureWrapper.getMoteIndex().get(id)); - return row[6]; - case 1: // SITE NAME - id = new Long(mote.getId()); - row =(Object[])(InfrastructureWrapper.getMoteIndex().get(id)); - return (String)(row[2]); - case 2: - return mote.getStatus(); - case 3: - return decodeLastCommandResult(mote.getStatus()); - case 4: - return moteControl.moteLeds; - default: - return ""; - } - } - - protected void addMote(SimpleMote mote) - { - MoteControl moteControl = new MoteControl(mote,true); - LedsListenerWrapper ledsobs = new LedsListenerWrapper(this,mote); - // moteControl.getMoteLeds().addListener(ledsobs); - this.moteControlMap.put(mote,moteControl); - mote.getStatus().addChangeListener(this); - } - - protected void removeMote(SimpleMote mote) - { - mote.getStatus().removeChangeListener(this); - this.moteControlMap.remove(mote); - // TODO: stop the mote control??? - } - - protected void refreshTable() - { - this.moteControlVector = new Vector(this.moteControlMap.values()); - this.fireTableDataChanged(); - } - - public void addedMote(MoteList moteList, Mote mote) { - this.addMote((SimpleMote)mote); - this.refreshTable(); - } - - public void removedMote(MoteList moteList, Mote mote) { - this.removeMote((SimpleMote)mote); - this.refreshTable(); - } - - public void cleared(MoteList moteList) - { - moteControlMap.clear(); - this.refreshTable(); - } - - public void simpleMoteStatusChange(SimpleMote mote) { - int index = this.moteControlVector.indexOf(this.moteControlMap.get(mote)); - if (index >= 0) - { - this.fireTableRowsUpdated(index,index); - } - } - - public MoteControl getMoteControl(int index) - { - return (MoteControl)this.moteControlVector.get(index); - } - - public void ledsChange(SimpleMote mote) - { - int index = this.moteControlVector.indexOf(this.moteControlMap.get(mote)); - if (index >= 0) - { - this.fireTableCellUpdated(index,4); - } - } - - protected String decodeLastCommandResult(SimpleMoteStatus s) - { - String prefix,suffix; - switch(s.getLastCommand()) - { - case MsgCommand.CANCELPROGRAMMING: - prefix = "Cancel programming "; - break; - case MsgCommand.PROGRAM: - prefix = "Programming "; - break; - case MsgCommand.RESET: - prefix = "Reset "; - break; - case MsgCommand.START: - prefix = "Start "; - break; - case MsgCommand.STATUS: - prefix = "Status request "; - break; - case MsgCommand.STOP: - prefix = "Stop "; - break; - default: - prefix = "Unknown command "; - } - - switch(s.getLastResult()) - { - case MsgResult.FAILURE: - suffix = "failed"; - break; - case MsgResult.NOT_SUPPORTED: - suffix = "is not supported"; - break; - case MsgResult.SUCCESS: - suffix = "succesful"; - break; - default: - suffix = "returned unkown result"; - } - return prefix+suffix; - } -} diff --git a/DIKUClientMainModule/old/util/MoteStatusRenderer.java b/DIKUClientMainModule/old/util/MoteStatusRenderer.java deleted file mode 100644 index bfc0e41..0000000 --- a/DIKUClientMainModule/old/util/MoteStatusRenderer.java +++ /dev/null @@ -1,65 +0,0 @@ -package util; - -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.table.TableCellRenderer; -import java.awt.Component; -import java.util.Comparator; - -import diku.distlab.motecontrolclientlib.client.*; - -public class MoteStatusRenderer extends JLabel implements TableCellRenderer, Comparator { - - /** - * - */ - private static final long serialVersionUID = 6986857411085856617L; - - public MoteStatusRenderer() - { - - } - - public Component getTableCellRendererComponent( - JTable table, Object value, - boolean isSelected, boolean hasFocus, - int row, int column) { - setText(getText(((SimpleMoteStatus)value).getStatus())); - return this; - } - - public static String getText(short s) - { - switch(s) - { - case SimpleMoteStatus.UNAVAILABLE: - return "Control unavailable!"; - case SimpleMoteStatus.REQ_CANCELPROGRAMMING: - return "Cancelling programming..."; - case SimpleMoteStatus.REQ_PROGRAM: - case SimpleMoteStatus.PROGRAMMING: - return "Programming..."; - case SimpleMoteStatus.REQ_RESET: - return "Resetting..."; - case SimpleMoteStatus.REQ_START: - return "Starting..."; - case SimpleMoteStatus.REQ_STOP: - return "Stopping.."; - case SimpleMoteStatus.RUNNING: - return "Running"; - case SimpleMoteStatus.STOPPED: - return "Stopped"; - case SimpleMoteStatus.UNKNOWN: - return "Status unknown"; - default: - return "Invalid status "+s; - } - } - - public int compare(Object arg0, Object arg1) { - SimpleMoteStatus s0,s1; - s0 = (SimpleMoteStatus)arg0; - s1 = (SimpleMoteStatus)arg1; - return getText(s0.getStatus()).compareTo(getText(s1.getStatus())); - } -} diff --git a/DIKUClientMainModule/old/util/SortedTable.java b/DIKUClientMainModule/old/util/SortedTable.java deleted file mode 100644 index 78dd533..0000000 --- a/DIKUClientMainModule/old/util/SortedTable.java +++ /dev/null @@ -1,37 +0,0 @@ -package util; - -import javax.swing.JTable; -import diku.distlab.infrastructure.SimpleTable; -import diku.distlab.servicewrappers.SimpleTableModel; - -public class SortedTable extends JTable { - - /** - * - */ - private static final long serialVersionUID = 8597769976271616046L; - - protected SimpleTable dataTable; - - - protected SimpleTableModel tableModel; - - - public SortedTable(SimpleTable p_dataTable) { - super(new TableSorter(new SimpleTableModel(p_dataTable))); - tableModel = (SimpleTableModel)((TableSorter)dataModel).getTableModel(); - ((TableSorter)dataModel).setTableHeader(getTableHeader()); - ((TableSorter)dataModel).setColumnComparator(Short.class,new IntegerComparator()); - dataTable = p_dataTable; - } - - public SimpleTable getDataTable() { - return dataTable; - } - - public void setDataTable(SimpleTable dataTable) { - tableModel.setTable(dataTable); - this.dataTable = dataTable; - } - -} diff --git a/DIKUClientMainModule/old/util/TableSorter.java b/DIKUClientMainModule/old/util/TableSorter.java deleted file mode 100644 index 354e1f0..0000000 --- a/DIKUClientMainModule/old/util/TableSorter.java +++ /dev/null @@ -1,488 +0,0 @@ -package util; - -import java.awt.*; -import java.awt.event.*; -import java.util.*; -import java.util.List; - -import javax.swing.*; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.table.*; - -/** - * TableSorter is a decorator for TableModels; adding sorting - * functionality to a supplied TableModel. TableSorter does - * not store or copy the data in its TableModel; instead it maintains - * a map from the row indexes of the view to the row indexes of the - * model. As requests are made of the sorter (like getValueAt(row, col)) - * they are passed to the underlying model after the row numbers - * have been translated via the internal mapping array. This way, - * the TableSorter appears to hold another copy of the table - * with the rows in a different order. - *

- * TableSorter registers itself as a listener to the underlying model, - * just as the JTable itself would. Events recieved from the model - * are examined, sometimes manipulated (typically widened), and then - * passed on to the TableSorter's listeners (typically the JTable). - * If a change to the model has invalidated the order of TableSorter's - * rows, a note of this is made and the sorter will resort the - * rows the next time a value is requested. - *

- * When the tableHeader property is set, either by using the - * setTableHeader() method or the two argument constructor, the - * table header may be used as a complete UI for TableSorter. - * The default renderer of the tableHeader is decorated with a renderer - * that indicates the sorting status of each column. In addition, - * a mouse listener is installed with the following behavior: - *

    - *
  • - * Mouse-click: Clears the sorting status of all other columns - * and advances the sorting status of that column through three - * values: {NOT_SORTED, ASCENDING, DESCENDING} (then back to - * NOT_SORTED again). - *
  • - * SHIFT-mouse-click: Clears the sorting status of all other columns - * and cycles the sorting status of the column through the same - * three values, in the opposite order: {NOT_SORTED, DESCENDING, ASCENDING}. - *
  • - * CONTROL-mouse-click and CONTROL-SHIFT-mouse-click: as above except - * that the changes to the column do not cancel the statuses of columns - * that are already sorting - giving a way to initiate a compound - * sort. - *
- *

- * This is a long overdue rewrite of a class of the same name that - * first appeared in the swing table demos in 1997. - * - * @author Philip Milne - * @author Brendon McLean - * @author Dan van Enckevort - * @author Parwinder Sekhon - * @version 2.0 02/27/04 - */ - -public class TableSorter extends AbstractTableModel { - /** - * - */ - private static final long serialVersionUID = 6285498045473220499L; - - protected TableModel tableModel; - - public static final int DESCENDING = -1; - public static final int NOT_SORTED = 0; - public static final int ASCENDING = 1; - - private static Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED); - - public static final Comparator COMPARABLE_COMAPRATOR = new Comparator() { - public int compare(Object o1, Object o2) { - return ((Comparable) o1).compareTo(o2); - } - }; - public static final Comparator LEXICAL_COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - return o1.toString().compareTo(o2.toString()); - } - }; - - private Row[] viewToModel; - private int[] modelToView; - - private JTableHeader tableHeader; - private MouseListener mouseListener; - private TableModelListener tableModelListener; - private Map columnComparators = new HashMap(); - private List sortingColumns = new ArrayList(); - - public TableSorter() { - this.mouseListener = new MouseHandler(); - this.tableModelListener = new TableModelHandler(); - } - - public TableSorter(TableModel tableModel) { - this(); - setTableModel(tableModel); - } - - public TableSorter(TableModel tableModel, JTableHeader tableHeader) { - this(); - setTableHeader(tableHeader); - setTableModel(tableModel); - } - - private void clearSortingState() { - viewToModel = null; - modelToView = null; - } - - public TableModel getTableModel() { - return tableModel; - } - - public void setTableModel(TableModel tableModel) { - if (this.tableModel != null) { - this.tableModel.removeTableModelListener(tableModelListener); - } - - this.tableModel = tableModel; - if (this.tableModel != null) { - this.tableModel.addTableModelListener(tableModelListener); - } - - clearSortingState(); - fireTableStructureChanged(); - } - - public JTableHeader getTableHeader() { - return tableHeader; - } - - public void setTableHeader(JTableHeader tableHeader) { - if (this.tableHeader != null) { - this.tableHeader.removeMouseListener(mouseListener); - TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer(); - if (defaultRenderer instanceof SortableHeaderRenderer) { - this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer); - } - } - this.tableHeader = tableHeader; - if (this.tableHeader != null) { - this.tableHeader.addMouseListener(mouseListener); - this.tableHeader.setDefaultRenderer( - new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer())); - } - } - - public boolean isSorting() { - return sortingColumns.size() != 0; - } - - private Directive getDirective(int column) { - for (int i = 0; i < sortingColumns.size(); i++) { - Directive directive = (Directive)sortingColumns.get(i); - if (directive.column == column) { - return directive; - } - } - return EMPTY_DIRECTIVE; - } - - public int getSortingStatus(int column) { - return getDirective(column).direction; - } - - private void sortingStatusChanged() { - clearSortingState(); - fireTableDataChanged(); - if (tableHeader != null) { - tableHeader.repaint(); - } - } - - public void setSortingStatus(int column, int status) { - Directive directive = getDirective(column); - if (directive != EMPTY_DIRECTIVE) { - sortingColumns.remove(directive); - } - if (status != NOT_SORTED) { - sortingColumns.add(new Directive(column, status)); - } - sortingStatusChanged(); - } - - protected Icon getHeaderRendererIcon(int column, int size) { - Directive directive = getDirective(column); - if (directive == EMPTY_DIRECTIVE) { - return null; - } - return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive)); - } - - private void cancelSorting() { - sortingColumns.clear(); - sortingStatusChanged(); - } - - public void setColumnComparator(Class type, Comparator comparator) { - if (comparator == null) { - columnComparators.remove(type); - } else { - columnComparators.put(type, comparator); - } - } - - protected Comparator getComparator(int column) { - Class columnType = tableModel.getColumnClass(column); - Comparator comparator = (Comparator) columnComparators.get(columnType); - if (comparator != null) { - return comparator; - } - if (Comparable.class.isAssignableFrom(columnType)) { - return COMPARABLE_COMAPRATOR; - } - return LEXICAL_COMPARATOR; - } - - private Row[] getViewToModel() { - if (viewToModel == null) { - int tableModelRowCount = tableModel.getRowCount(); - viewToModel = new Row[tableModelRowCount]; - for (int row = 0; row < tableModelRowCount; row++) { - viewToModel[row] = new Row(row); - } - - if (isSorting()) { - Arrays.sort(viewToModel); - } - } - return viewToModel; - } - - public int modelIndex(int viewIndex) { - return getViewToModel()[viewIndex].modelIndex; - } - - private int[] getModelToView() { - if (modelToView == null) { - int n = getViewToModel().length; - modelToView = new int[n]; - for (int i = 0; i < n; i++) { - modelToView[modelIndex(i)] = i; - } - } - return modelToView; - } - - // TableModel interface methods - - public int getRowCount() { - return (tableModel == null) ? 0 : tableModel.getRowCount(); - } - - public int getColumnCount() { - return (tableModel == null) ? 0 : tableModel.getColumnCount(); - } - - public String getColumnName(int column) { - return tableModel.getColumnName(column); - } - - public Class getColumnClass(int column) { - return tableModel.getColumnClass(column); - } - - public boolean isCellEditable(int row, int column) { - return tableModel.isCellEditable(modelIndex(row), column); - } - - public Object getValueAt(int row, int column) { - return tableModel.getValueAt(modelIndex(row), column); - } - - public void setValueAt(Object aValue, int row, int column) { - tableModel.setValueAt(aValue, modelIndex(row), column); - } - - // Helper classes - - private class Row implements Comparable { - private int modelIndex; - - public Row(int index) { - this.modelIndex = index; - } - - public int compareTo(Object o) { - int row1 = modelIndex; - int row2 = ((Row) o).modelIndex; - - for (Iterator it = sortingColumns.iterator(); it.hasNext();) { - Directive directive = (Directive) it.next(); - int column = directive.column; - Object o1 = tableModel.getValueAt(row1, column); - Object o2 = tableModel.getValueAt(row2, column); - - int comparison = 0; - // Define null less than everything, except null. - if (o1 == null && o2 == null) { - comparison = 0; - } else if (o1 == null) { - comparison = -1; - } else if (o2 == null) { - comparison = 1; - } else { - comparison = getComparator(column).compare(o1, o2); - } - if (comparison != 0) { - return directive.direction == DESCENDING ? -comparison : comparison; - } - } - return 0; - } - } - - private class TableModelHandler implements TableModelListener { - public void tableChanged(TableModelEvent e) { - // If we're not sorting by anything, just pass the event along. - if (!isSorting()) { - clearSortingState(); - fireTableChanged(e); - return; - } - - // If the table structure has changed, cancel the sorting; the - // sorting columns may have been either moved or deleted from - // the model. - if (e.getFirstRow() == TableModelEvent.HEADER_ROW) { - cancelSorting(); - fireTableChanged(e); - return; - } - - // We can map a cell event through to the view without widening - // when the following conditions apply: - // - // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, - // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and, - // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and, - // d) a reverse lookup will not trigger a sort (modelToView != null) - // - // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS. - // - // The last check, for (modelToView != null) is to see if modelToView - // is already allocated. If we don't do this check; sorting can become - // a performance bottleneck for applications where cells - // change rapidly in different parts of the table. If cells - // change alternately in the sorting column and then outside of - // it this class can end up re-sorting on alternate cell updates - - // which can be a performance problem for large tables. The last - // clause avoids this problem. - int column = e.getColumn(); - if (e.getFirstRow() == e.getLastRow() - && column != TableModelEvent.ALL_COLUMNS - && getSortingStatus(column) == NOT_SORTED - && modelToView != null) { - int viewIndex = getModelToView()[e.getFirstRow()]; - fireTableChanged(new TableModelEvent(TableSorter.this, - viewIndex, viewIndex, - column, e.getType())); - return; - } - - // Something has happened to the data that may have invalidated the row order. - clearSortingState(); - fireTableDataChanged(); - return; - } - } - - private class MouseHandler extends MouseAdapter { - public void mouseClicked(MouseEvent e) { - JTableHeader h = (JTableHeader) e.getSource(); - TableColumnModel columnModel = h.getColumnModel(); - int viewColumn = columnModel.getColumnIndexAtX(e.getX()); - int column = columnModel.getColumn(viewColumn).getModelIndex(); - if (column != -1) { - int status = getSortingStatus(column); - if (!e.isControlDown()) { - cancelSorting(); - } - // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or - // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. - status = status + (e.isShiftDown() ? -1 : 1); - status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1} - setSortingStatus(column, status); - } - } - } - - private static class Arrow implements Icon { - private boolean descending; - private int size; - private int priority; - - public Arrow(boolean descending, int size, int priority) { - this.descending = descending; - this.size = size; - this.priority = priority; - } - - public void paintIcon(Component c, Graphics g, int x, int y) { - Color color = c == null ? Color.GRAY : c.getBackground(); - // In a compound sort, make each succesive triangle 20% - // smaller than the previous one. - int dx = (int)(size/2*Math.pow(0.8, priority)); - int dy = descending ? dx : -dx; - // Align icon (roughly) with font baseline. - y = y + 5*size/6 + (descending ? -dy : 0); - int shift = descending ? 1 : -1; - g.translate(x, y); - - // Right diagonal. - g.setColor(color.darker()); - g.drawLine(dx / 2, dy, 0, 0); - g.drawLine(dx / 2, dy + shift, 0, shift); - - // Left diagonal. - g.setColor(color.brighter()); - g.drawLine(dx / 2, dy, dx, 0); - g.drawLine(dx / 2, dy + shift, dx, shift); - - // Horizontal line. - if (descending) { - g.setColor(color.darker().darker()); - } else { - g.setColor(color.brighter().brighter()); - } - g.drawLine(dx, 0, 0, 0); - - g.setColor(color); - g.translate(-x, -y); - } - - public int getIconWidth() { - return size; - } - - public int getIconHeight() { - return size; - } - } - - private class SortableHeaderRenderer implements TableCellRenderer { - private TableCellRenderer tableCellRenderer; - - public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) { - this.tableCellRenderer = tableCellRenderer; - } - - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { - Component c = tableCellRenderer.getTableCellRendererComponent(table, - value, isSelected, hasFocus, row, column); - if (c instanceof JLabel) { - JLabel l = (JLabel) c; - l.setHorizontalTextPosition(JLabel.LEFT); - int modelColumn = table.convertColumnIndexToModel(column); - l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize())); - } - return c; - } - } - - private static class Directive { - private int column; - private int direction; - - public Directive(int column, int direction) { - this.column = column; - this.direction = direction; - } - } -} diff --git a/DIKUClientMainModule/temp/ConfirmText.java b/DIKUClientMainModule/temp/ConfirmText.java deleted file mode 100644 index 99dddbd..0000000 --- a/DIKUClientMainModule/temp/ConfirmText.java +++ /dev/null @@ -1,78 +0,0 @@ -package gui; - -import diku.distlab.motecontrolclientlib.protocols.*; - -public class ConfirmText { - String message; - - long mote_id; - - public ConfirmText(long mote_id, short type, int result) { - this.mote_id = mote_id; - if (result != MsgResult.SUCCESS) { - switch (type) { - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_GETHANDLE: - message = "Control request failed."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_DROPHANDLE: - message = "Release failed."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_REPROGRAM: - message = "Programming failed."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_STATUS: - message = "Status request failed."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_RESET: - message = "Reset failed."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_STOP: - message = "Stop failed."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_START: - message = "Start failed."; - break; - } - } else { - switch (type) { - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_GETHANDLE: - message = "Control request successful."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_DROPHANDLE: - message = "Release successful."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_REPROGRAM: - message = "Programming successful."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_STATUS: - message = "Status request successful."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_RESET: - message = "Reset successful."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_STOP: - message = "Stop successful."; - break; - case diku.distlab.motecontrolclientlib.protocols.simplemotecontrol.MOTE_START: - message = "Start successful."; - break; - } - } - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public long getMote_id() { - return mote_id; - } - - public void setMote_id(long mote_id) { - this.mote_id = mote_id; - } -} -- 2.11.4.GIT