Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
more work on node-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
prasincs committed May 5, 2011
1 parent 149edbc commit a806a9c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
27 changes: 18 additions & 9 deletions library/experiments/power-degradation-distance.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@


(def transmitter (new-node
{:device "phone-1"
:location {:x 250 :y 10}} ; start at very top
{:name "transmitter"
:device "phone-1"
:location {:x 250 :y 50}} ; start at very top
))

(def receiver (new-node
{:device "phone-1"
:location {:x 250 :y 11}}
{:name "receiver"
:device "phone-1"
:location {:x 250 :y 51}}
)) ; start at distance 1 away from transmitter

(def power-loss-time (atom ()))
Expand Down Expand Up @@ -123,16 +125,23 @@
(get-battery-capacity receiver)
)
;(println (get-battery-capacity receiver))
(swap! power-loss-time conj
(:power-received
( let [power-received (:power-received
(get-message-network-attrs
(send-network-message
"test"
transmitter
receiver
{:time (get-current-time)})
)))
(node-viewer-update-nodes {:text "Test"})
))
))]
(swap! power-loss-time conj
power-received )
(node-viewer-update-nodes {:text
(format
"Distance:%f\nPower Received: %f\nBattery Capacity:%f"
(get-distance-between-nodes transmitter receiver)
power-received
(get-battery-capacity receiver) )
})
)))

(simulation-run)
2 changes: 1 addition & 1 deletion src/thor/lang.clj
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
:or {
time (get-current-time)
text ""}}]
(thor.ui.node-viewer/add-nodes time {:text ""
(thor.ui.node-viewer/add-nodes time {:text text
:nodes
(deref-all
@*nodelist*)})
Expand Down
6 changes: 4 additions & 2 deletions src/thor/node.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@


(defrecord Node
[id
[id
name
memory
location ; x y coordinate in graph pos type
speed
Expand All @@ -33,9 +34,10 @@
)

(defn create-node "create a node based on given info"
[{:keys [id location memory-size device-attrs network-attrs ] :or {:device-attrs {} :network-attrs {}}} ]
[{:keys [id name location memory-size device-attrs network-attrs ] :or { :device-attrs {} :network-attrs {}}} ]
(Node.
id
name
(create-memory memory-size)
location
0
Expand Down
23 changes: 18 additions & 5 deletions src/thor/ui/node_viewer.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns
thor.ui.node-viewer
(:import [javax.swing JFrame JList JButton BoxLayout JPanel DefaultListModel BoxLayout ListSelectionModel JScrollPane ScrollPaneConstants ]
(:import [javax.swing JFrame JList JButton BoxLayout JPanel DefaultListModel BoxLayout ListSelectionModel JScrollPane JViewport JLabel ScrollPaneConstants ]
[java.awt Dimension GridBagLayout BorderLayout]

[javax.swing.event ListSelectionListener]
Expand All @@ -10,7 +10,7 @@
(def frame
(doto (JFrame. "Project Thor")
(.setDefaultCloseOperation (JFrame/EXIT_ON_CLOSE))
(.setSize (Dimension. 500 500))
(.setSize (Dimension. 700 500))
))

(def radius 100)
Expand All @@ -29,11 +29,20 @@
)
)
(def statesListScrollPane
(let [header
(doto
(JViewport. )
(.setView
(JLabel. "Time"))
)]
(doto
(JScrollPane.
stateList
ScrollPaneConstants/VERTICAL_SCROLLBAR_ALWAYS
ScrollPaneConstants/HORIZONTAL_SCROLLBAR_AS_NEEDED
))
)
(.setColumnHeader header)
)))

(defn add-states-to-list [model elements]
(doseq [elem elements]
Expand Down Expand Up @@ -70,8 +79,12 @@
(fill 64 187 128 100)
;(println loc)
(ellipse (:x loc) (:y loc) radius radius)
(fill 0)
(text (format "(%d, %d)" (:x loc) (:y loc)) (:x loc) (:y loc))
(fill 250 79 45)
(text (if (nil? (:name n))
(format "Node %d" (:id n))
(:name n)
) (:x loc) (:y loc))
;(text (format "(%d, %d)" (:x loc) (:y loc)) (:x loc) (:y loc))
;(text (format "Node %d" (:id n)) (:x loc) (:y loc))
))

Expand Down

0 comments on commit a806a9c

Please sign in to comment.