Overview
JDesignCanvas is an interactive design surface for creating label layouts. It supports drag-and-drop field placement, reordering, and zoom controls for barcode/label design applications.Constructor
Core Methods
Layout Configuration
Sets the number of text line slots on the label
Number of text line slots to display
- Clears existing slots and creates new ones
- Barcode area is always added at the bottom
- Each slot can accept dragged fields
Zoom Control
Increases the canvas zoom level by 10%
- Maximum zoom: 200% (2.0x)
- Smooth scale transform
Decreases the canvas zoom level by 10%
- Minimum zoom: 50% (0.5x)
- Smooth scale transform
Data Export
Exports the current label design configurationReturns a map containing:
"slots": List of slot configurations in order
"type":"text"or"barcode""fieldId": Field identifier (if assigned)
Reset
Resets the canvas to initial state
- Clears all slots
- Resets barcode area to placeholder
- Resets zoom to 100%
Drag & Drop Behavior
Accepting Drops
The canvas accepts drag gestures with string data (field IDs):Drop Targets
- Text Line Slots: Accept any field, display as uppercase label
- Barcode Area: Accepts field, displays as visual barcode representation
- Reordering: Slots can be reordered by dragging within the canvas
Slot Reordering
Internal drag operations use the prefix_REORDER_ + index:
- Drag from any slot
- Drop on another slot to swap positions
- Visual feedback during drag
Visual Design
Label Media
- Size: 420×320px (simulates physical label)
- White background with subtle shadow
- Rounded corners (16px radius)
- Centered on canvas with padding
Slots
- Dashed border when empty
- Solid background when filled
- Height: 60px per text line
- Spacing: 15px between slots
Barcode Area
- Height: 100px
- Displays visual barcode pattern when assigned
- 30 random-width black lines when filled
Example Usage
Design Data Format
Styling
Style classes:.j-design-canvas- Main container.label-media- The white label surface.canvas-slot- Each droppable slot.barcode-drop-zone- Barcode area.drag-over- Applied during drag hover
Internal Components
Label Surface Properties
- Background: Pure white (
#ffffff) - Border: Light gray (
#e2e8f0) - Shadow: Soft drop shadow with 30px blur
- Padding: 25px
- Border radius: 16px
Canvas Background
- Color:
#f8fafc(studio gray) - Padding: 40px
- Simulates design workspace
Notes
- Uses JavaFX
Scaletransform for zoom (maintains quality) - Pivot point is center of label media
- Drag feedback via opacity and border color changes
- Automatically handles slot index updates during reordering
- Barcode visualization uses random bar widths (2px or 4px)
- All field IDs are converted to lowercase in exported data