Permalink
Browse files

new approach

  • Loading branch information...
1 parent 428bd82 commit c5609e61f8cc55b50fa7b6582490ddb600b528e9 @mcmenaminadrian committed Apr 29, 2012
Showing with 245 additions and 22 deletions.
  1. +142 −0 hexedit/HexxedStatus.groovy
  2. +82 −0 hexedit/HexxedWindow.groovy
  3. +21 −8 {hexxed → hexedit}/hexxed.groovy
  4. +0 −14 hexxed/HexxedStatus.groovy
View
142 hexedit/HexxedStatus.groovy
@@ -0,0 +1,142 @@
+package hexedit
+
+class HexxedStatus {
+
+ private HexxedStatus() {}
+ private static final currentStatus = new HexxedStatus()
+ static getCurrentStatus() { return currentStatus}
+ def littleEndian
+ def bigEndian
+ def bitWidth
+ def useBlocks
+ def blockSize
+ def windowEdit
+
+ def subscribersLittleEndian = []
+ def subscribersBigEndian = []
+ def subscribersBitWidth = []
+ def subscribersUseBlocks = []
+ def subscribersBlockSize = []
+
+
+
+ void setLittleEndian(def le)
+ {
+ littleEndian = le
+ notifyLE(subscribersLittleEndian)
+ }
+
+ void setBigEndian(def be)
+ {
+ bigEndian = be
+ notifyBE(subscribersBigEndian)
+ }
+
+ void setBitWidth(def bw)
+ {
+ bitWidth = bw
+ notifyBW(subscribersBitWidth)
+ }
+
+ void setUseBlocks(def ub)
+ {
+ useBlocks = ub
+ notifyUB(subscribersUseBlocks)
+ }
+
+ void setBlockSize(def bs)
+ {
+ blockSize = bs
+ notifyBS(subscribersBlockSize)
+ }
+
+ void setWindowEdit(def we)
+ {
+ windowEdit = we
+ }
+
+ void notifyBE(def list)
+ {
+ list.each{$it.updateBE(bigEndian)}
+ }
+
+ void notifyLE(def list)
+ {
+ list.each{$it.updateLE(littleEndian)}
+ }
+
+ void notifyBW(def list)
+ {
+ list.each{$it.updateBW(bitWidth)}
+ }
+
+ void notifyUB(def list)
+ {
+ list.each{$it.updateUB(useBlocks)}
+ }
+
+ void notifyBS(def list)
+ {
+ list.each{$it.updateBS(blockSize)}
+ }
+
+ void subscribeBigEndian(def subscriber)
+ {
+ //cannot subscribe twice
+ subscribersBigEndian -= subscriber
+ subscribersBigEndian << subscriber
+ }
+
+ void unsubscribeBigEndian(def subscriber)
+ {
+ subscribersBigEndian -= subscriber
+ }
+
+ void subscribeLittleEndian(def subscriber)
+ {
+ //cannot subscribe twice
+ subscribersLittleEndian -= subscriber
+ subscribersLittleEndian << subscriber
+ }
+
+ void unsubscribeLittleEndian(def subscriber)
+ {
+ subscribersLittleEndian -= subscriber
+ }
+
+ void subscribeBitWidth(def subscriber)
+ {
+ //cannot subscribe twice
+ subscribersBitWidth -= subscriber
+ subscribersBitWidth << subscriber
+ }
+
+ void unsubscribeBitWidth(def subscriber)
+ {
+ subscribersBitWidth -= subscriber
+ }
+ void subscribeUseBlocks(def subscriber)
+ {
+ //cannot subscribe twice
+ subscribersUseBlocks -= subscriber
+ subscribersUseBlocks << subscriber
+ }
+
+ void unsubscribeUseBlocks(def subscriber)
+ {
+ subscribersUseBlocks -= subscriber
+ }
+
+ void subscribeBlockSize(def subscriber)
+ {
+ //cannot subscribe twice
+ subscribersBlockSize -= subscriber
+ subscribersBlockSize << subscriber
+ }
+
+ void unsubscribeBlockSize(def subscriber)
+ {
+ subscribersBlockSize -= subscriber
+ }
+
+}
View
82 hexedit/HexxedWindow.groovy
@@ -0,0 +1,82 @@
+package hexedit
+
+import groovy.swing.SwingBuilder
+import javax.swing.*
+
+class HexxedWindow {
+
+ def swingWindow
+ def swingBuilder
+ def statusHolder
+
+ HexxedWindow(def x, def y, def controller)
+ {
+ statusHolder = controller
+ //create basic window
+ //then create menus
+ swingBuilder = new SwingBuilder()
+ swingWindow = swingBuilder.frame(title: "HEXXED", size: [x, y],
+ show: true) {
+ //menu
+ menuBar() {
+ menu(text: "File", mnemonic: 'F'){
+ menuItem(text: "Load", mnemonic: 'L',
+ actionPerformed: { loadFile() })
+ menuItem(text: "Quit", mnemonic: 'Q',
+ actionPerformed: { dispose() })
+ }
+ menu(text: "Display", mnemonic: 'D'){
+ menuItem(text: "Set width", mnemonic: 'w',
+ actionPerformed: { setWidth() })
+ }
+ menu(text: "Navigate", mnemonic: 'N'){
+ menuItem(text: "Forwards", mnemonic: 'F',
+ actionPerformed: { forward() })
+ menuItem(text: "Backwards", mnemonic: 'B',
+ actionPerformed: { backward() })
+ menuItem(text: "Next block", mnemonic: 'x',
+ actionPerformed: { nextBlock() })
+ menuItem(text: "Previous block", mnemonic: 'P',
+ actionPerformed: { previousBlock() })
+ }
+ menu(text: "About", mnemonic: 'A'){
+ menuItem(text: "Help", mnemonic: 'H',
+ actionPerformed: { helpMenu()})
+ menuItem(text: "Licence", mnemonic: 'L',
+ actionPerformed: { displayGPL() })
+ }
+ }
+ }
+ }
+
+
+ def setWidth()
+ {}
+
+ def loadFile()
+ {
+ def loadDialog = swingBuilder.fileChooser(
+ dialogTitle: "Choose a file to open"
+ )
+ loadDialog.showOpenDialog()
+ //fileHandler.setNewFile(loadDialog.getSelectedFile())
+ }
+
+ def forward()
+ {}
+
+ def backward()
+ {}
+
+ def nextBlock()
+ {}
+
+ def previousBlock()
+ {}
+
+ def helpMenu()
+ {}
+
+ def displayGPL()
+ {}
+}
View
29 hexxed/hexxed.groovy → hexedit/hexxed.groovy
@@ -1,4 +1,4 @@
-package hexxed
+package hexedit
import java.nio.channels.FileChannel
@@ -7,18 +7,22 @@ class HexxedStart
{
HexxedStart(littleEndian, bigEndian, bitWidth, offsetInFile, blockSize,
- useBlocks, fileToEdit)
+ useBlocks, fileToEdit, x, y)
{
def hexxedStatus //Model - a singleton
def hexxedWindow //View
def hexxedFile //Container
hexxedStatus = HexxedStatus.currentStatus
- hexxedStatus.littleEndian = littleEndian
- hexxedStatus.bigEndian = bigEndian
- hexxedStatus.bitWidth = bitWidth
- hexxedStatus.useBlocks = useBlocks
- hexxedStatus.blockSize = blockSize
+ hexxedStatus.setLittleEndian(littleEndian)
+ hexxedStatus.setBigEndian(bigEndian)
+ hexxedStatus.setBitWidth(bitWidth)
+ hexxedStatus.setUseBlocks(useBlocks)
+ hexxedStatus.setBlockSize(blockSize)
+
+ hexxedWindow = new HexxedWindow(x, y)
+ hexxedStatus.setWindowEdit(hexxedWindow)
+
}
}
@@ -40,6 +44,8 @@ def hexCli = new CliBuilder
'interpret data as big endian - default is cpu endianness');
hexCli.u(longOpt: 'usage', 'show this information')
hexCli.f(longOpt: 'file', args: 1, 'file to edit')
+ hexCli.x(longOpt: 'x', args: 1, 'width of window (default 640 pixels)')
+ hexCli.y(longOpt: 'y', args: 1, 'height of window (default 480 pixels)')
def hexParse = hexCli.parse(args)
if (hexParse.u) {
@@ -52,6 +58,8 @@ def hexCli = new CliBuilder
def blocks = false
def offset = 0
def fileToEdit
+ def xw = 640
+ def yh = 480
if (hexParse.f)
fileToEdit = hexParse.f
@@ -87,7 +95,12 @@ def hexCli = new CliBuilder
if (hexParse.o)
offset = Integer.parseInt(hexParse.o)
+
+ if (hexParse.x)
+ xw = Integer.parseInt(hexParse.x)
+ if (hexParse.y)
+ yh = Integer.parseInt(hexParse.y)
def hexFileHandler = new HexxedStart(le, be, bits, offset, bs,
- blocks, fileToEdit)
+ blocks, fileToEdit, xw, yh)
}
View
14 hexxed/HexxedStatus.groovy
@@ -1,14 +0,0 @@
-package hexxed
-
-class HexxedStatus {
-
- private HexxedStatus() {}
- private static final currentStatus = new HexxedStatus()
- static getCurrentStatus() { return currentStatus}
- def littleEndian
- def bigEndian
- def bitWidth
- def useBlocks
- def blockSize
-
-}

0 comments on commit c5609e6

Please sign in to comment.