164 lines
6.9 KiB
Groovy
164 lines
6.9 KiB
Groovy
package com.jdbernard.timestamper
|
|
|
|
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.jdbernard.GUIUtil
|
|
import com.jdbernard.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.traceIfEnabled('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 }))
|
|
}
|
|
}
|
|
}
|
|
}
|