Refactored code packages, com.jdbernard -> com.jdblabs

* Updated contact info, package declarations, and config to match.
* Removed com.jdbernard.timestamper.core, it is becoming a seperate library
  project.
This commit is contained in:
Jonathan Bernard
2011-06-16 12:33:54 -05:00
parent d08d054fbe
commit 98071f270d
30 changed files with 82 additions and 1016 deletions

View File

@ -0,0 +1,10 @@
package com.jdblabs.timestamper.gui
import javax.swing.JDialog
dialog = dialog(new JDialog(model.mainMVC.view.frame),
title: 'Error Messages...',
modal: false) {
logger.trace( "Building LogDialog view." )
}

View File

@ -0,0 +1,65 @@
package com.jdblabs.timestamper.gui
import java.awt.Color
import java.awt.Point
import java.awt.Rectangle
import java.awt.Toolkit
import javax.swing.BoxLayout
import javax.swing.JDialog
import net.miginfocom.swing.MigLayout
Point mousePressRelativeToDialog
Point offsetFromMainFrame = new Point(0,0)
boolean coupledToMainFrame = false
mousePressed = { evt -> mousePressRelativeToDialog = evt?.point }
mouseDragged = { evt ->
GUIUtil.componentDragged(dialog, evt, mousePressRelativeToDialog,
new Rectangle(Toolkit.defaultToolkit.screenSize),
model.mainMVC.view.frame.bounds)
offsetFromMainFrame = GUIUtil.calculateOffset(
model.mainMVC.view.frame, dialog)
coupledToMainFrame = GUIUtil.componentsCoupled(dialog,
model.mainMVC.view.frame);
}
dialog = dialog(new JDialog(model.mainMVC.view.frame),
title: 'Notes',
modal: false,
undecorated: true,
minimumSize: [325, 200],
mousePressed: mousePressed,
mouseDragged: mouseDragged,
iconImage: imageIcon('/16-em-pencil.png').image,
iconImages: [imageIcon('/16-em-pencil.png').image],
location: bind(source: model.mainMVC.model,
sourceProperty: 'absoluteLocation',
converter: { loc ->
if (coupledToMainFrame) {
Point p = new Point(offsetFromMainFrame)
p.translate((int) loc.x, (int) loc.y)
return p
} else return dialog.location })
) {
logger.trace('Building NotesDialog GUI')
panel(
border:lineBorder(color: Color.BLACK, thickness:1, parent:true),
layout: new MigLayout('insets 10 10 10 10, fill')
) {
scrollPane(constraints: 'growx, growy') {
notesTextArea = textArea(lineWrap: true, columns: 20, rows: 5,
wrapStyleWord: true,
text: bind(source: model.mainMVC.model,
sourceProperty: 'currentMarker',
sourceValue: { model.mainMVC.model.currentMarker?.notes}),
keyReleased: {
if (model.mainMVC.model.currentMarker != null)
model.mainMVC.model.currentMarker.notes =
notesTextArea.text})
}
}
}

View File

@ -0,0 +1,162 @@
package com.jdblabs.timestamper.gui
import java.awt.Color
import java.awt.Point
import java.awt.Toolkit
import java.awt.Rectangle
import java.text.SimpleDateFormat
import javax.swing.JDialog
import java.util.Calendar
import javax.swing.SwingConstants
import com.jdblabs.timestamper.gui.TimelineDayDisplay
import com.toedter.calendar.JDateChooser
import net.miginfocom.swing.MigLayout
Point mousePressRelativeToDialog
Point offsetFromMainFrame = new Point(0,0)
boolean coupledToMainFrame = false
dateFormatter = new SimpleDateFormat("EEE MMM dd")
mousePressed = { evt -> mousePressRelativeToDialog = evt?.point }
mouseDragged = { evt ->
GUIUtil.componentDragged(dialog, evt, mousePressRelativeToDialog,
new Rectangle(Toolkit.defaultToolkit.screenSize),
model.mainMVC.view.frame.bounds)
offsetFromMainFrame = GUIUtil.calculateOffset(
model.mainMVC.view.frame, dialog)
coupledToMainFrame = GUIUtil.componentsCoupled(dialog,
model.mainMVC.view.frame);
}
dialog = dialog(new JDialog(model.mainMVC.view.frame),
title: 'Punchcard',
modal: false,
undecorated: true,
mousePressed: mousePressed,
mouseDragged: mouseDragged,
iconImage: imageIcon('/16-file-archive.png').image,
iconImages: [imageIcon('/16-file-archive.png').image],
minimumSize: [450, 500],
location: bind(source: model.mainMVC.model,
sourceProperty: 'absoluteLocation',
converter: { loc ->
if (coupledToMainFrame) {
Point p = new Point(offsetFromMainFrame)
p.translate((int) loc.x, (int) loc.y)
return p
} else return dialog.location })
) {
logger.trace('Building PunchcardDialog GUI')
panel(
border:lineBorder(color: Color.BLACK, thickness:1, parent:true),
layout: new MigLayout('fill, insets 10 10 10 10',
'[grow]', '[grow]10[grow 0]')
) {
dayDisplay = widget(constraints: 'grow, gp 200',
new TimelineDayDisplay(model.mainMVC.model.timeline),
timeline: bind(source: model.mainMVC.model,
sourceProperty: 'timeline'),
stateChanged: bind(source: model.mainMVC.model,
sourceProperty: 'currentMarker'))
panel(
border: lineBorder(color: Color.BLACK, thickness: 1),
constraints: 'growx, growy 0, newline, bottom',
layout: new MigLayout('fill, insets 0 10 0 10',
'[grow]10[grow 0]', '[][][grow 0]')
) {
dateChooser = widget(new JDateChooser(),
constraints: 'growx, gaptop 10',
dateFormatString: 'MMM d, yyyy HH:mm',
date: bind(source: dayDisplay,
sourceProperty: 'selectedTimelineMarker',
converter: { it?.timestamp }))
panel(constraints: 'spany 3, wrap, al trailing',
layout: new MigLayout('insets 0', '[]0[]0[]0[]0[]',
'[]0[]0[]0[]0[]')
) {
label(background: [255, 255, 153],
constraints: 'growx, spanx 5, wrap',
horizontalAlignment: SwingConstants.CENTER,
opaque: true,
text: bind(source: dayDisplay,
sourceProperty: 'rangeStart',
converter: { dateFormatter.format(it) }))
Calendar calendar = Calendar.getInstance()
button(icon: imageIcon('/previous-week.png'),
border: emptyBorder(4),
actionPerformed: {
calendar.time = dayDisplay.rangeStart
calendar.add(Calendar.WEEK_OF_YEAR, -1)
dayDisplay.day = calendar.time })
button(icon: imageIcon('/previous-day.png'),
border: emptyBorder(4),
actionPerformed: {
calendar.time = dayDisplay.rangeStart
calendar.add(Calendar.DAY_OF_YEAR, -1)
dayDisplay.day = calendar.time })
button(text: 'Today',
border: emptyBorder(4),
actionPerformed: {
calendar = Calendar.getInstance()
dayDisplay.day = calendar.time })
button(icon: imageIcon('/next-day.png'),
border: emptyBorder(4),
actionPerformed: {
calendar.time = dayDisplay.rangeStart
calendar.add(Calendar.DAY_OF_YEAR, 1)
dayDisplay.day = calendar.time })
button(icon: imageIcon('/next-week.png'),
constraints: 'wrap',
border: emptyBorder(4),
actionPerformed: {
calendar.time = dayDisplay.rangeStart
calendar.add(Calendar.WEEK_OF_YEAR, 1)
dayDisplay.day = calendar.time })
button(text: 'New Marker', icon: imageIcon('/new-marker.png'),
constraints: 'growx, spanx 5, wrap',
horizontalAlignment: SwingConstants.CENTER,
actionPerformed: {
model.mainMVC.controller.newTask(markTextField.text,
notesTextField.text, dateChooser.date) })
button(text: 'Delete Marker',
icon: imageIcon('/delete-marker.png'),
constraints: 'growx, spanx 5, wrap',
horizontalAlignment: SwingConstants.CENTER,
actionPerformed: {
model.mainMVC.controller.deleteTask(
dayDisplay.selectedTimelineMarker) })
button(text: 'Apply Changes',
icon: imageIcon('/document-save-16x16.png'),
constraints: 'growx, spanx 5',
horizontalAlignment: SwingConstants.CENTER,
actionPerformed: {
Date d = dateChooser.date
String m = markTextField.text
String n = notesTextField.text
model.mainMVC.controller.deleteTask(
dayDisplay.selectedTimelineMarker)
model.mainMVC.controller.newTask(m, n, d) })
}
markTextField = textField(constraints: 'growx, wrap',
text: bind(source: dayDisplay,
sourceProperty: 'selectedTimelineMarker',
converter: { it?.mark }))
scrollPane(constraints: 'growx, gapbottom 10',
minimumSize: [0, 50]) {
notesTextField = textArea( wrapStyleWord: true, lineWrap: true,
text: bind(source: dayDisplay,
sourceProperty: 'selectedTimelineMarker',
converter: { it?.notes }))
}
}
}
}

View File

@ -0,0 +1,205 @@
package com.jdblabs.timestamper.gui
import java.awt.Color
import java.awt.Font
import java.awt.Point
import java.awt.Rectangle
import java.awt.Toolkit
import java.awt.event.KeyEvent
import javax.swing.BoxLayout
import javax.swing.JDialog
import javax.swing.JFileChooser
import javax.swing.SwingConstants
import javax.swing.Timer
import com.jdblabs.timestamper.core.Timeline
import net.miginfocom.swing.MigLayout
/* ========== *
* GUI Events *
* ========== */
taskTextFieldChanged = { evt = null ->
if (evt.keyCode == KeyEvent.VK_ENTER) {
taskTextField.font = taskBoldFont
controller.newTask(taskTextField.text)
}
else if (evt.keyCode == KeyEvent.VK_ESCAPE) {
taskTextField.font = taskBoldFont
taskTextField.text = model.currentMarker.mark
}
else if (!evt.isActionKey())
taskTextField.font = taskThinFont
}
showNotes = { evt = null ->
model.notesDialogMVC.view.dialog.visible = notesVisibleButton.selected
}
showPunchcard = { evt = null ->
model.punchcardDialogMVC.view.dialog.visible = punchcardVisibleButton.selected
}
mousePressed = { evt = null ->
mousePressRelativeToFrame = evt?.point
}
mouseDragged = { evt = null ->
GUIUtil.componentDragged(frame, evt, mousePressRelativeToFrame,
new Rectangle(Toolkit.defaultToolkit.screenSize))
}
/* ============== *
* GUI Definition *
* ============== */
updateTimer = new Timer(1000, action(name: 'GUI Refresh', closure: {
Date currentTime = new Date()
currentTimeLabel.text = Timeline.shortFormat.format(currentTime)
if (model.currentMarker != null) {
long seconds = currentTime.time - model.currentMarker.timestamp.time
seconds /= 1000
long minutes = seconds / 60
seconds = seconds % 60
long hours = minutes / 60
minutes %= 60
long days = hours / 24
hours %= 24
StringBuilder sb = new StringBuilder()
if (days > 0) sb.append(days + "day ")
if (hours > 0) sb.append(hours + "hr ")
if (minutes > 0) sb.append(minutes + "min ")
sb.append(seconds + "sec")
totalTimeLabel.text = sb.toString()
} else totalTimeLabel.text = ""
}))
updateTimer.start()
optionsMenu = popupMenu() {
menuItem(icon: imageIcon('/document-save-16x16.png'), text: 'Save Timeline',
actionPerformed: { model.timelineProperties.save() })
menuItem(icon: imageIcon('/document-save-as-16x16.png'),
text: 'Save a new copy...', actionPerformed: controller.&saveas)
menuItem(icon: imageIcon('/document-open-16x16.png'),
text: 'Load Timeline...', actionPerformed: {
if (fileDialog.showOpenDialog(frame) ==
JFileChooser.APPROVE_OPTION)
controller.load(fileDialog.selectedFile) })
checkBoxMenuItem(text: 'Save on update?',
selected: bind(source: model, sourceProperty: 'timelineProperties',
sourceValue: { model.timelineProperties?.persistOnUpdate }),
actionPerformed: {
model.timelineProperties.persistOnUpdate = it.source.selected })
aboutMenuItem = checkBoxMenuItem(text: 'About...',
actionPerformed: { aboutDialog.visible = aboutMenuItem.selected })
}
fileDialog = fileChooser();
frame = application(title:'TimeStamper',
location:[50,50],
locationByPlatform:true,
minimumSize: [325, 0],
pack:true,
undecorated:true,
iconImage: imageIcon('/appointment-new-32x32.png').image,
iconImages: [imageIcon('/appointment-new-32x32.png').image,
imageIcon('/appointment-new-16x16.png').image],
componentMoved: { evt -> model.absoluteLocation = frame.location }
) {
logger.trace('Building TimeStamperMain GUI')
panel(
border:lineBorder(color:Color.BLACK, thickness:1, parent:true),
layout: new MigLayout('insets 0 5 0 0, fill','', '[]0[]0[]'),
mousePressed: mousePressed,
mouseDragged: mouseDragged
) {
def mainFont = new Font(Font.SANS_SERIF, Font.BOLD, 12)
def timeFont = new Font(Font.SANS_SERIF, Font.BOLD, 14)
label("Current task started at ", font: mainFont)
label(constraints: 'align leading', font: timeFont,
foreground: [0, 102, 102],
text: bind(source: model, sourceProperty: 'currentMarker',
sourceValue: {
model.currentMarker == null ? "00:00:00" :
Timeline.shortFormat.format(model.currentMarker.timestamp)
}))
panel(constraints: 'alignx trailing, aligny top, wrap') {
boxLayout(axis: BoxLayout.X_AXIS)
button(mouseClicked: { evt ->
optionsMenu.show(evt.component, evt.x, evt.y) },
icon: imageIcon('/16-tool-a.png'),
rolloverIcon: imageIcon('/16-tool-a-hover.png'),
border: emptyBorder(0),
contentAreaFilled: false,
hideActionText: true,
toolTipText: 'Options Menu')
button(actionPerformed: controller.&exitGracefully,
icon: imageIcon('/16-em-cross.png'),
rolloverIcon: imageIcon('/16-em-cross-hover.png'),
border: emptyBorder(0),
contentAreaFilled: false,
hideActionText: true,
toolTipText: 'Close Application')
}
taskTextField = textField("Task name",
constraints: "growx, span 2, w 250::",
keyReleased: taskTextFieldChanged,
toolTipText: 'The current task',
text: bind(source: model, sourceProperty: 'currentMarker',
sourceValue: { model.currentMarker?.mark }))
taskThinFont = taskTextField.font
taskBoldFont = taskTextField.font.deriveFont(Font.BOLD)
panel(constraints: 'alignx leading, aligny top, gapright 5px, wrap') {
boxLayout(axis: BoxLayout.X_AXIS)
notesVisibleButton = toggleButton(
actionPerformed: showNotes,
icon: imageIcon('/16-em-pencil.png'),
hideActionText: true,
border: emptyBorder(4),
toolTipText: 'Show/hide task notes.')
punchcardVisibleButton = toggleButton(
actionPerformed: showPunchcard,
icon: imageIcon('/16-file-archive.png'),
hideActionText: true,
border: emptyBorder(4),
toolTipText: 'Show/hide the timeline display.')
}
totalTimeLabel = label("", constraints: 'alignx leading',
font: timeFont, foreground: [0, 153, 0])
currentTimeLabel = label("00:00:00", constraints: 'align trailing',
font: timeFont, foreground: [204, 0, 0])
}
}
aboutDialog = dialog(new JDialog(frame),
visible: false,
locationRelativeTo: null,
pack: true,
undecorated: true,
title: "About TimeStamper v" + app.applicationProperties.'app.version'
) {
panel(layout: new MigLayout('fill'),
border: lineBorder(color: Color.BLACK, thickness: 1)) {
label(font: new Font(Font.SANS_SERIF, Font.PLAIN, 18),
text: "TimeStamper", constraints: 'growx, wrap',
horizontalAlignment: SwingConstants.CENTER)
label(text: "version " + app.applicationProperties.'app.version'
+ " by Jonathan Bernard", constraints: 'growx, wrap',
horizontalAlignment: SwingConstants.CENTER)
textField(text: 'http://www.jdb-labs.com/timestamper',
constraints: 'growx', foreground: [0,0,200], editable: false,
horizontalAlignment: SwingConstants.CENTER)
}
}