Compare commits

..

332 Commits

Author SHA1 Message Date
bancika a33923fdd7 2011-08-28 21:59:53 +00:00
bancika 5df467a254 2011-08-28 21:43:25 +00:00
bancika 7c4d82b28c added recently used tab 2011-08-28 21:31:49 +00:00
bancika 6b7d1c4277 Renumber selected components by X or Y axis 2011-08-28 17:09:10 +00:00
bancika a0ae53d53c fixed method finding issues 2011-08-28 16:23:35 +00:00
bancika bd79ef2817 Component edit dialog allows changing property values even when they are not the same 2011-08-28 16:10:38 +00:00
bancika 69e2296c23 show mutual properties across different component types 2011-08-27 20:36:37 +00:00
bancika 7d3a7c30ca check file permission before using auto-save 2011-08-26 18:31:36 +00:00
bancika bea19f326c Auto-increment component names when copy-pasting 2011-08-26 18:18:53 +00:00
bancika ba694add0c allow 0 ohm resistors 2011-08-26 17:59:50 +00:00
bancika f137a398dc double click on a component button to select all of that type 2011-08-26 17:56:33 +00:00
bancika 15ac8ff2e9 increase PNG resolution 2011-08-07 19:23:50 +00:00
bancika 1213dcaeac increase PNG resolution 2011-08-07 19:23:23 +00:00
bancika 2ebcd1fe96 ctrl+click should never clear selection 2011-08-07 19:07:19 +00:00
bancika 943d123ca9 outline mode
improved auto-create for pads
2011-03-05 19:53:19 +00:00
bancika 79c29dc349 2011-03-03 21:05:47 +00:00
bancika 746b5fbe1a 2011-03-03 20:56:56 +00:00
bancika 365c195091 fix for drawing area and optimization 2011-03-02 18:14:39 +00:00
bancika d89a500a5f fix for drawing area and optimization 2011-03-02 18:13:34 +00:00
bancika 085732fb2c 2011-03-01 00:17:53 +00:00
bancika eab7654883 Curved traces and wires can have 2, 3 and 4 control points 2011-02-28 00:09:13 +00:00
bancika 5488657984 config menu order 2011-02-27 23:38:11 +00:00
bancika 1a256716db tube socket improvement 2011-02-27 23:30:05 +00:00
bancika 2b9c76e876 add file version info
improve image serialization
serialize points referenced in inches
2011-02-27 23:26:11 +00:00
bancika 5ae8a3477e add file version info
improve image serialization
serialize points referenced in inches
2011-02-27 23:23:51 +00:00
bancika 209e970c00 catch drag end outside the area 2011-02-27 22:56:40 +00:00
bancika ae96fb9eef label has editable font 2011-02-27 21:58:57 +00:00
bancika 401f2b5e6f label has editable font 2011-02-27 21:56:08 +00:00
bancika e2da0b884d vertical vero board 2011-02-27 20:48:18 +00:00
bancika bcf390b888 switchable wheel zoom 2011-02-27 19:25:39 +00:00
bancika 144e8f0cfe standing resistors, capacitors and diodes 2011-02-27 19:09:15 +00:00
bancika 84d744a80b switchable wheel zoom 2011-02-27 18:34:33 +00:00
bancika 5430ca71a3 added 6 pin IC 2011-02-26 21:12:45 +00:00
bancika 4665d5d42e added tube 2011-02-26 21:05:40 +00:00
bancika 275918d079 dnd collision improvement 2011-02-26 15:35:53 +00:00
bancika a83093519f 2011-02-26 11:30:05 +00:00
bancika 2e14929eb1 send to back/front renamed 2011-02-26 11:28:40 +00:00
bancika a0b7cdc30e auto-save added 2011-02-26 11:26:49 +00:00
bancika ab5c9ad143 code cleanup 2011-02-24 00:05:27 +00:00
bancika 4154225e71 auto-edit mode 2011-02-24 00:02:32 +00:00
bancika 3856af3e18 continuous component creation 2011-02-23 23:44:00 +00:00
bancika 80e7ebcbe9 auto-create pads 2011-02-23 20:42:40 +00:00
bancika abdf02eac8 configurable snap to grid 2011-02-18 22:17:03 +00:00
bancika 746aadd8a2 improve bring to front/send to back 2011-02-18 13:17:56 +00:00
bancika ac4496040f improve bring to front/send to back 2011-02-18 13:16:58 +00:00
bancika d810096030 relax logging 2011-02-16 19:10:57 +00:00
bancika 4727017be7 fix for default browser 2011-02-15 20:36:18 +00:00
bancika b2dae15ee6 fix for default browser 2011-02-15 19:18:01 +00:00
bancika 56e112ff81 don't show grid on the thumbnail 2011-02-13 11:46:53 +00:00
bancika 6f5926e18e removed unused theme members 2011-02-13 09:43:27 +00:00
bancika b1f4773b10 2011-02-12 20:59:04 +00:00
bancika e5d33fb80d switchable sticky points
added themes
fixed ruler precision
improved board rendering
2011-02-12 20:35:09 +00:00
bancika b8545d27a1 line tracing fix 2011-02-06 20:38:21 +00:00
bancika 70ac30473b use clip to improve performance 2011-02-06 18:27:50 +00:00
bancika 4774e97ba2 use clip to improve performance 2011-02-06 18:22:30 +00:00
bancika de7378c722 2011-02-06 16:23:29 +00:00
bancika e2b3ed1b0e configurable render quality 2011-02-06 16:01:57 +00:00
bancika 99d38feb1c improved speed 2011-02-03 23:42:07 +00:00
bancika a561f6a3f9 tweaked boards 2011-02-03 23:10:23 +00:00
bancika 6eee1525ee better scaling
added marshall board and trimmer
2011-02-03 21:47:16 +00:00
bancika 02d38bed01 added eyelet/turret 2011-01-31 22:47:21 +00:00
bancika b96bad2688 cleanup component area map on loading
fixed lead area mapping bug
2011-01-31 22:05:05 +00:00
bancika 12ca93e2c9 fixed color code rounding 2011-01-31 21:49:01 +00:00
bancika d9b9542883 configurable jumper color 2011-01-31 20:03:41 +00:00
bancika 9e04cff806 fixed lead alignment issue 2011-01-31 20:03:22 +00:00
bancika 16600328cc copy paste doesn't work for some components 2011-01-31 19:32:18 +00:00
bancika 85d7d8a450 fixed lead alignment issue 2011-01-31 00:19:57 +00:00
bancika f358b5d87b fixed lead alignment issue 2011-01-31 00:18:39 +00:00
bancika fa02280292 code cleanup 2011-01-30 23:45:25 +00:00
bancika 8ea53b6876 added capacitor symbol 2011-01-30 23:35:07 +00:00
bancika 4d6e994555 added resistor wattage and capacitor voltage 2011-01-30 21:50:24 +00:00
bancika 10581c51fb added abstract class for leaded schematic symbols and resistor symbol 2011-01-30 21:33:08 +00:00
bancika 2cf6b573a7 added abstract class for leaded schematic symbols and resistor symbol 2011-01-30 21:31:42 +00:00
bancika 629fb5fff7 2011-01-30 18:46:38 +00:00
bancika bc154608f4 allow property edit validation 2011-01-30 17:21:42 +00:00
bancika a8cc661d09 better error handling when drawing 2011-01-30 14:10:38 +00:00
bancika 0b10f0bfe3 V1 file importer can recognize hookup wire and transistors 2011-01-30 12:02:29 +00:00
bancika f435571aae added keyboard shortcuts to some menu options 2011-01-30 11:43:54 +00:00
bancika 6bb248032f added square pad 2011-01-30 11:32:55 +00:00
bancika 1b04023a93 added axial electrolytic 2011-01-29 22:38:46 +00:00
bancika a32c8c4c8d added axial electrolytic 2011-01-29 22:35:09 +00:00
bancika 4a89159c80 reset component selection when switching tabs 2011-01-29 22:00:33 +00:00
bancika e5113e110e reset component selection when switching tabs 2011-01-29 22:00:01 +00:00
bancika c2051fcea2 improved electrolytic cap and resistor 2011-01-29 21:56:43 +00:00
bancika a42592410e improved electrolytic cap and resistor 2011-01-29 21:55:51 +00:00
bancika 22185a2d14 Potentiometer misdraw at 180 degrees 2011-01-29 18:31:25 +00:00
bancika ac6aaf4e06 added LED 2011-01-29 13:47:00 +00:00
bancika 1be52c1dfa improved zooming 2011-01-29 09:49:28 +00:00
bancika 328d09123b removed sysout 2011-01-29 09:02:19 +00:00
bancika 04cd80b561 added TO220 transistor
improved status text
2011-01-29 08:59:53 +00:00
bancika 3a419ba3bc added transistor 2011-01-28 20:05:37 +00:00
bancika 971ceb7160 added template support 2011-01-28 19:21:35 +00:00
bancika e0d8990954 added template support 2011-01-28 19:19:05 +00:00
bancika a70ec95822 added template support 2011-01-28 19:13:49 +00:00
bancika 8aacf915e3 added template support 2011-01-28 18:57:21 +00:00
bancika 777d3f6deb added template support 2011-01-28 18:55:40 +00:00
bancika 7de327b9bd fixed point visibility on curved trace
added option to hide color bands on the resistor
2011-01-28 17:48:46 +00:00
bancika 11b7756a59 added resistor color codes
fixed double value parsing
2011-01-27 22:34:41 +00:00
bancika b3351ef081 version info 2011-01-27 20:17:06 +00:00
bancika b1dbf4f1d2 added action to right click menu 2011-01-27 19:52:59 +00:00
bancika 9161182924 added send to back/bring to front 2011-01-27 19:49:33 +00:00
bancika 94f769f785 added send to back/bring to front 2011-01-27 19:44:37 +00:00
bancika 6dffcd6349 added send to back/bring to front 2011-01-27 19:41:36 +00:00
bancika 6fad7a2427 fixed NPE and wrong undo/redo for ungroup 2011-01-27 19:21:34 +00:00
bancika 4ab6231590 refactored actions out
added right click menu
2011-01-27 19:16:40 +00:00
bancika 5de6caf073 fixed bug with file name when creating new file 2011-01-26 23:57:09 +00:00
bancika be7ab3412d optimize image saving/loading 2011-01-26 23:50:48 +00:00
bancika 3dd4a4c5e3 added worker thread 2011-01-26 21:49:57 +00:00
bancika fb6f973a6e added worker thread 2011-01-26 21:48:57 +00:00
bancika e8d45e1426 added image alpha 2011-01-26 21:06:51 +00:00
bancika 51c916cbb5 added image component 2011-01-26 20:09:15 +00:00
bancika a8ba97dc77 revived cut action 2011-01-26 19:45:44 +00:00
bancika 103860a42b added update file 2011-01-26 19:04:51 +00:00
bancika 126d629cdc refactored awt.transferable out of the presenter
fixed copy/paste between instances
2011-01-26 18:44:40 +00:00
bancika f28dda37a6 optimize refresh when creating new component 2011-01-25 22:48:51 +00:00
bancika 3a7fdeb792 allow curve shape control points to overlap 2011-01-25 21:38:37 +00:00
bancika 13e0cec8ad better logging 2011-01-25 19:13:07 +00:00
bancika df33d7fd6e improved IC 2011-01-24 21:28:53 +00:00
bancika 2f672bf2b4 round corners 2011-01-24 21:02:33 +00:00
bancika e84f77a7ca pulled out scripting because of locale issues 2011-01-24 20:58:18 +00:00
bancika efeaf92ccb ability to center label 2011-01-24 20:12:51 +00:00
bancika 8927b2c326 tweak control point visibility 2011-01-24 20:00:11 +00:00
bancika 3476d3a608 import text component 2011-01-24 19:49:04 +00:00
bancika 6c052403d3 import electrolytics 2011-01-24 19:40:22 +00:00
bancika 1322f48918 removed unused ode 2011-01-24 19:23:03 +00:00
bancika 62cbe4826f improved stick mechanism when more than one point is stuck 2011-01-24 19:13:09 +00:00
bancika 2aa8aed874 improved importer for v1 2011-01-24 18:54:04 +00:00
bancika 6d361283a1 Configurable wheel zoom 2011-01-24 18:21:57 +00:00
bancika b33b6b6495 show selection size on demand
removed scroll buttons in toolbox
2011-01-24 18:17:13 +00:00
bancika fb5baf9571 added transparency to pot 2011-01-23 23:54:24 +00:00
bancika 2d6927993e fixed creation bug with d&d 2011-01-23 23:47:35 +00:00
bancika 5806d17e56 added v1 conversion warnings 2011-01-23 23:25:20 +00:00
bancika fcc001cb98 reduced number of base layers 2011-01-23 23:18:45 +00:00
bancika 1de1b9d6ec refactored some swing out of the core parts 2011-01-23 22:57:52 +00:00
bancika 726f17aa7f refactor some swing references 2011-01-23 19:58:47 +00:00
bancika 72ae295a09 fixed NPE 2011-01-23 18:51:04 +00:00
bancika 0aa61ecd8a 2011-01-23 18:34:15 +00:00
bancika 4106d2dad5 added label 2011-01-23 18:23:34 +00:00
bancika f9c08ecbaa changed curve position
synchronous messages
added pot
2011-01-23 17:26:34 +00:00
bancika a422c9ad2d don't stick to locked components 2011-01-22 13:23:58 +00:00
bancika 1cede9e071 added layer locking 2011-01-22 13:20:40 +00:00
bancika 664bf91852 added layer locking
added eyelet board
2011-01-22 13:17:43 +00:00
bancika 99d85a2d1f fixed drag&drop when spacing changes 2011-01-21 23:06:48 +00:00
bancika 9fdf7c3e46 added radial electrolytic 2011-01-21 22:03:52 +00:00
bancika 2c00a7a973 improved piece of code 2011-01-21 21:17:30 +00:00
bancika 91509c2bce added plastic diode 2011-01-21 21:10:57 +00:00
bancika abe9fbbbd5 added plastic diode 2011-01-21 21:09:17 +00:00
bancika 5e886ed90c turn off auto gc 2011-01-21 20:49:50 +00:00
bancika 7c5a125cd2 select components when dropped 2011-01-21 20:44:15 +00:00
bancika 3339a1b6eb added object cache 2011-01-21 20:41:08 +00:00
bancika d1603161a3 added object cache 2011-01-21 20:39:53 +00:00
bancika c51357f58c added object cache 2011-01-21 18:57:05 +00:00
bancika d67a0e7c87 fixed board collapsing bug 2011-01-21 08:44:33 +00:00
bancika 3f4aa807f0 fixed board collapsing bug 2011-01-21 08:35:18 +00:00
bancika 9ae74ac0a1 improved lead drawing 2011-01-20 23:34:33 +00:00
bancika be7e9a1d53 do not drag while creating new component 2011-01-20 23:23:40 +00:00
bancika dd53cfe569 don't allow selection rect when creating new
update selection when dropped
2011-01-20 21:52:51 +00:00
bancika 90f760dcd1 naming 2011-01-20 21:47:09 +00:00
bancika c875060e6a fixed compiler warning 2011-01-20 21:44:36 +00:00
bancika 0aeaa0dea0 refactored selection code 2011-01-20 21:40:53 +00:00
bancika 0c92d76d99 changed status text formatting 2011-01-20 21:24:07 +00:00
bancika a315bc06fa refactored instantiation code out the presenter 2011-01-20 21:19:32 +00:00
bancika 2309e80edc ctrl to unstuck components 2011-01-20 20:33:42 +00:00
bancika e0fd55c374 added component slot while creating
invalidate components when deleted
2011-01-20 19:03:04 +00:00
bancika 419293a956 fixed pdf scaling
changed few colors
2011-01-20 00:12:16 +00:00
bancika 55f7d2e057 added grid type
renamed few classes
2011-01-19 19:38:36 +00:00
bancika 69ef633af3 improved lead looks 2011-01-19 18:58:38 +00:00
bancika e38fb84621 boards don't disappear when points are flipped 2011-01-19 18:47:15 +00:00
bancika d4f2662bde fixed ghost painting 2011-01-19 18:42:08 +00:00
bancika be9a47753c removed old class 2011-01-19 18:30:20 +00:00
bancika 15b03b12a5 refactored file management out of presenter 2011-01-19 18:28:31 +00:00
bancika 69e961b296 refactored file management out of presenter 2011-01-19 18:24:13 +00:00
bancika 0d6fa98221 removed log for memory tracking 2011-01-19 18:14:37 +00:00
bancika 8a83bca7f2 do not show unnecessary decimals 2011-01-18 20:51:57 +00:00
bancika 7f1f7b60a5 fixed editing units 2011-01-18 20:39:28 +00:00
bancika 5e88aeedc1 2011-01-18 20:35:13 +00:00
bancika 8c4c884062 use enter and escape in the editor dialog 2011-01-17 23:14:33 +00:00
bancika fb46acad60 Adjust label angle if needed to make sure that it's readable 2011-01-17 23:07:46 +00:00
bancika a2ea8ee393 control point collision detection 2011-01-17 22:58:35 +00:00
bancika 5cea9f0193 persist zoom level 2011-01-17 22:48:43 +00:00
bancika b9aeaff6da bom tweak
anti-aliasing made as configurable item
2011-01-17 22:28:43 +00:00
bancika e866762b05 always show control point when creating new component
changed board alignment
fixed sticking to non-stickable points
2011-01-17 20:24:29 +00:00
bancika dcb5b668db fix main class 2011-01-17 19:57:31 +00:00
bancika f37e0dfc95 setup sticky and visibility policy for each point inidividually 2011-01-17 19:46:42 +00:00
bancika 7ad87076d3 added icons, fixed donate option 2011-01-17 19:20:02 +00:00
bancika 6dba12eab8 board improvements
show point for non-stretchable components too
2011-01-17 00:19:47 +00:00
bancika c02b37bcba fixed modified flag on drag end 2011-01-16 23:26:17 +00:00
bancika 584d84ff77 improved display of control points and status message 2011-01-16 23:18:15 +00:00
bancika 796276b1c1 object optimization 2011-01-16 23:08:31 +00:00
bancika c3d5556121 improved point-by-point creation 2011-01-16 23:04:32 +00:00
bancika 5b0eb295c8 show directories in file choosers 2011-01-16 21:17:03 +00:00
bancika 1d0f393931 added point by point component creation 2011-01-16 21:11:41 +00:00
bancika 8186841851 improved vero board 2011-01-16 13:35:53 +00:00
bancika 2478c7e51b temporary disable accessory in file choosers 2011-01-16 13:35:29 +00:00
bancika 1b2495f23e fixed save and save as to update the title bar 2011-01-16 13:28:34 +00:00
bancika 2af10da63c refactor drawing code out of presenter 2011-01-16 13:28:15 +00:00
bancika 6da2a6e94c refactor drawing code out of presenter 2011-01-16 13:27:45 +00:00
bancika 2660841ceb allow choosing name/value 2011-01-16 09:50:00 +00:00
bancika 6f6d802829 hotspot tracking optimization 2011-01-16 09:32:34 +00:00
bancika b81d633ce5 improve curve detection 2011-01-16 09:07:01 +00:00
bancika 63cf354c25 fixed paste translation 2011-01-16 08:47:17 +00:00
bancika e1377a8b09 painting optimization 2011-01-16 08:45:22 +00:00
bancika 1781c45317 outline optimization 2011-01-16 08:38:10 +00:00
bancika 7fd817191b optimize selection rect 2011-01-15 21:52:53 +00:00
bancika e8048d9d94 fix board name 2011-01-15 21:50:27 +00:00
bancika 657ce2e580 use acceleration 2011-01-15 21:48:36 +00:00
bancika 60e0ce6392 painting optimization 2011-01-15 21:05:31 +00:00
bancika 0ceed9a93a sort properties for project 2011-01-15 20:51:30 +00:00
bancika a470fb2abd title and desc non defaultable 2011-01-15 20:50:12 +00:00
bancika c8796102d9 moved utility method 2011-01-15 20:48:23 +00:00
bancika 1efe629f3d version # 2011-01-15 20:42:35 +00:00
bancika e9bcae11e3 improve paste 2011-01-15 20:41:31 +00:00
bancika 03444c3146 added helper methods for config reader 2011-01-15 20:32:46 +00:00
bancika 84818eef6a refresh selection on delete 2011-01-15 15:38:55 +00:00
bancika 3759fbc1ba allow expressions in double text field 2011-01-15 15:35:45 +00:00
bancika f05c3ccc86 save project default properties 2011-01-15 15:05:07 +00:00
bancika b99d438eb8 checks for file modifications 2011-01-15 14:19:36 +00:00
bancika 52df431beb checks for file modifications 2011-01-15 14:04:33 +00:00
bancika d16ee1d890 added menu item to edit selection 2011-01-15 11:13:19 +00:00
bancika cb1155e8fa fixed rounding to grid 2011-01-15 10:33:16 +00:00
bancika c677e98cad editable project properties 2011-01-15 10:31:07 +00:00
bancika dd4080accb make grid spacing flexible 2011-01-15 10:11:09 +00:00
bancika c8de2aa271 improved color editor 2011-01-14 16:23:00 +00:00
bancika 4420a97993 fixed double text field warning icon 2011-01-14 14:02:58 +00:00
bancika 1f5fa8ae14 fixed measure editing
fixed trace lead color
2011-01-14 13:57:51 +00:00
bancika 628d370019 changed about dialog 2011-01-14 13:41:55 +00:00
bancika 9652059ce7 added help items 2011-01-14 13:36:10 +00:00
bancika 8bc851875d added help items 2011-01-14 13:22:18 +00:00
bancika acf5b78a6c added help items 2011-01-14 13:21:44 +00:00
bancika d91d7baff3 added trace mask icon 2011-01-14 13:02:28 +00:00
bancika 0976a25c88 added trace mask icon 2011-01-14 12:49:51 +00:00
bancika a399fedfd7 improved d&d 2011-01-14 12:38:50 +00:00
bancika ef443925c2 added export trace
improved status message on selection
2011-01-14 10:00:04 +00:00
bancika e5c0b01aca include stuck components in drag 2011-01-13 21:34:45 +00:00
bancika f3ed8d1a7c tweak colors 2011-01-13 18:50:27 +00:00
bancika 7afeb48407 impoved bom 2011-01-12 23:59:34 +00:00
bancika 2dc7a50e2f zoom level doesn't reflect in the rulers 2011-01-12 23:57:47 +00:00
bancika aac45e8978 added project info component 2011-01-12 23:01:35 +00:00
bancika b9e5704225 improved few components 2011-01-12 22:48:00 +00:00
bancika 521e3fda5f added bom component 2011-01-12 20:50:13 +00:00
bancika 23f4cb7468 fixed npe 2011-01-12 20:43:51 +00:00
bancika dd1ec04f1c track string drawing 2011-01-12 20:43:40 +00:00
bancika f050ab5818 doc 2011-01-12 18:25:44 +00:00
bancika 09e4862bcc grouping improvement 2011-01-12 17:46:57 +00:00
bancika 27bac25c8b added group/ungroup 2011-01-12 00:39:39 +00:00
bancika a04c90b689 update prefixes 2011-01-11 23:38:35 +00:00
bancika d2bacdaa21 add ant build 2011-01-11 23:36:29 +00:00
bancika f8dd6a36c0 update prefixes 2011-01-11 23:31:25 +00:00
bancika 5d22d282fa use red when selected 2011-01-11 21:48:38 +00:00
bancika 19d561d35d show selection in status bar 2011-01-11 21:34:15 +00:00
bancika 070e3edf52 use red when selected 2011-01-11 21:22:07 +00:00
bancika e3a3dfe82e use red rectangle when selected 2011-01-11 19:22:48 +00:00
bancika a97f83f1ac use red rectangle when selected 2011-01-11 19:21:05 +00:00
bancika 37a7362d9e fixed d&d bug with multiple selection 2011-01-11 18:54:53 +00:00
bancika e9936e4adb select all works now 2011-01-11 18:47:40 +00:00
bancika cb72d596a3 editable colors for boards 2011-01-10 23:47:39 +00:00
bancika ce63511188 editable colors for boards 2011-01-10 23:43:01 +00:00
bancika c2e5b6d20c improved switch and IC 2011-01-10 23:32:47 +00:00
bancika dcbd351589 improved switch 2011-01-10 23:12:07 +00:00
bancika 56beaa7f9b draw leads on the top, useful for radial components 2011-01-10 23:06:23 +00:00
bancika c4cedd8946 better measure 2011-01-10 22:51:26 +00:00
bancika d141b9c477 added delete functionality 2011-01-10 22:38:50 +00:00
bancika e249667bbd allow custom cm and in spacing
more precise ruler
2011-01-10 19:45:05 +00:00
bancika ee01f390da better measurement 2011-01-10 19:37:13 +00:00
bancika 3fd425f2cd removed old code 2011-01-10 18:48:17 +00:00
bancika e17c0d5753 abstract class reorganization
sort properties by name
2011-01-10 18:43:23 +00:00
bancika dc1f0ac7bd 2011-01-10 18:32:14 +00:00
bancika 13cfcb16df editable board spacing 2011-01-10 18:31:24 +00:00
bancika 218126c85e renamed class 2011-01-10 18:26:49 +00:00
bancika e7784f442b added abstract curve 2011-01-10 00:07:22 +00:00
bancika 573b58902b jumper to blue 2011-01-09 23:49:58 +00:00
bancika 974c5bcf21 added trace cut 2011-01-09 23:38:55 +00:00
bancika 481c28d835 fixed npe 2011-01-09 23:38:37 +00:00
bancika 5f860348df change layer to double
added solder pad
2011-01-09 23:10:24 +00:00
bancika 7af112a28b added ic pins 2011-01-09 14:28:02 +00:00
bancika c898fee28e added color properties to abstract leaded comp 2011-01-09 13:11:46 +00:00
bancika f2fa8195b3 added some icons 2011-01-09 12:44:24 +00:00
bancika 41bcfec45e added some icons 2011-01-09 12:44:07 +00:00
bancika 32efad1490 process polygon line 2011-01-09 12:19:44 +00:00
bancika 6a80bcdbe6 process shape outline 2011-01-09 12:16:53 +00:00
bancika 37a74f7918 added wire 2011-01-09 12:16:27 +00:00
bancika 94c53a2344 doc 2011-01-09 00:46:24 +00:00
bancika 672aef6799 2011-01-09 00:42:00 +00:00
bancika 9a2fdc264f disable alpha on jumpers 2011-01-09 00:39:04 +00:00
bancika d43e098216 added transparency 2011-01-09 00:08:13 +00:00
bancika 300753bb85 sort categories 2011-01-08 19:24:06 +00:00
bancika fa2709efc0 moved logic to component processor 2011-01-08 18:37:11 +00:00
bancika 43d931a1e6 cleanup 2011-01-08 18:31:36 +00:00
bancika 4dd470f185 support for line recognition
recognize deprecated properties
2011-01-08 18:22:36 +00:00
bancika f3bc414676 Added jumper and trace 2011-01-08 18:19:57 +00:00
bancika 0b319cf46f 2011-01-08 15:50:51 +00:00
bancika 90e8f4004b changed switch 2011-01-08 15:48:15 +00:00
bancika 80fff261bb removed old code 2011-01-08 15:39:22 +00:00
bancika ad43ecd0ed added selection size 2011-01-08 15:35:33 +00:00
bancika a4309a169c fixed z-order selection 2011-01-08 14:18:05 +00:00
bancika ca1d71e2eb draw control points on the top 2011-01-08 14:13:55 +00:00
bancika 695887ba4c do not show control points of non-stretchable 2011-01-08 14:10:24 +00:00
bancika 33d03a377d do not look for setter if no annotation is found 2011-01-08 14:06:18 +00:00
bancika 2d942a3214 moved common code to the main project 2011-01-08 14:02:53 +00:00
bancika 746b7d4e97 reorganized packages
added toggle switch
2011-01-08 14:02:21 +00:00
bancika 8a115e5cbd fixed d&d jumping issue when zoomed 2011-01-08 14:00:56 +00:00
bancika 93ac7b24d1 Code cleanup 2011-01-08 10:56:59 +00:00
bancika a91e2c2617 fixed d&d jumping issue 2011-01-08 10:55:08 +00:00
bancika 69f1e8afcd Z-order component handling 2011-01-08 10:17:01 +00:00
bancika d2cc7cd214 Z-order component handling 2011-01-08 10:16:17 +00:00
bancika e0a3a64696 fixed dynamic jar loading 2011-01-08 10:03:27 +00:00
bancika b9fe3d84e2 Z-order component handling 2011-01-08 09:34:21 +00:00
bancika 5b0753c42c improved perfboard 2011-01-08 09:33:27 +00:00
bancika d4cece7f5a improved perfboard 2011-01-08 09:02:48 +00:00
bancika 435f8d62f2 added boards 2011-01-07 17:03:39 +00:00
bancika a5c5296365 moving library to new project 2011-01-07 16:37:37 +00:00
bancika a6b378c173 2011-01-07 16:34:40 +00:00
bancika defd97118a IC painting issue fix 2011-01-06 00:42:32 +00:00
bancika 53433f0836 increased repaint hack time 2011-01-06 00:39:52 +00:00
bancika e612b39b26 better d&d of control points
doc
2011-01-06 00:23:59 +00:00
bancika b33d1c3e37 improved IC 2011-01-05 23:54:57 +00:00
bancika 3b3a9baa82 warning fixed 2011-01-05 19:43:48 +00:00
bancika 1b3457623d warning fixed 2011-01-05 19:42:18 +00:00
bancika 7bd3245024 added enum editor 2011-01-05 19:41:32 +00:00
bancika 51eee908c2 changed control point api 2011-01-05 19:21:59 +00:00
bancika 8db24c2588 added project to component.draw
better logging
2011-01-05 01:00:16 +00:00
bancika dd50ccf785 simplified component framework 2011-01-05 00:20:09 +00:00
bancika 69acfcff2f simplified component framework 2011-01-05 00:09:11 +00:00
bancika d1892cae70 added more capacitors 2011-01-04 22:58:04 +00:00
bancika 2c994228f4 added more capacitors 2011-01-04 22:54:57 +00:00
bancika 74c7007b23 added capacitor 2011-01-04 22:47:41 +00:00
bancika 872293ea0e doc 2011-01-04 22:29:10 +00:00
bancika cb5c95478f abstract leaded component changes 2011-01-04 22:19:24 +00:00
bancika 2bd2ecd13d renamed BOM objects 2011-01-04 21:13:13 +00:00
bancika 32409b186f doc 2011-01-04 21:01:46 +00:00
bancika a88f0d0a45 refactored component framework 2011-01-04 20:55:35 +00:00
bancika 73da0f4a9b 2011-01-04 19:07:30 +00:00
222 changed files with 5492 additions and 8721 deletions
+2 -10
View File
@@ -1,18 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="src.library"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/junit-4.7.jar"/>
<classpathentry kind="lib" path="lib/iText-2.1.7.jar"/>
<classpathentry kind="lib" path="lib/cloning-1.5.jar"/>
<classpathentry kind="lib" path="lib/objenesis-1.1.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/bancika-gui-framework.jar"/>
<classpathentry kind="lib" path="lib/HttpProxy.jar"/>
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/poi-3.5-FINAL-20090928.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/DIYLC"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DIYLC</name>
<name>Library</name>
<comment></comment>
<projects>
</projects>
File diff suppressed because one or more lines are too long
+6 -15
View File
@@ -1,11 +1,10 @@
<project name="diylc" basedir="." default="jar">
<project name="main" basedir="." default="jar">
<property name="src.dir" value="src" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="build.dir" value="${basedir}/build" />
<property name="jar.dir" value="${build.dir}/jar" />
<property name="report.dir" value="${build.dir}/junitreport" />
<property name="main.class" value="com.diyfever.diylc.DIYLCStarter" />
<property name="classes.dir" value="${build.dir}/temp/${ant.project.name}/classes" />
<property name="test.classes.dir" value="${build.dir}/temp/${ant.project.name}/test.classes" />
@@ -14,11 +13,10 @@
<delete dir="${build.dir}" />
</target>
<!--change src dir-->
<target name="compile">
<mkdir dir="${classes.dir}" />
<echo>Compile with JDK ${java.runtime.version}</echo>
<javac encoding="8859_1" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="class.path" />
<javac encoding="8859_1" srcdir="${basedir}/${src.dir}" destdir="${classes.dir}" classpathref="class.path" />
</target>
<target name="resource.copy">
@@ -46,18 +44,11 @@
</fileset>
</path>
<manifestclasspath jarfile="${ant.project.name}.jar" property="manifest.class.path">
<classpath refid="class.path" />
</manifestclasspath>
<target name="jar" depends="clean, lib.copy, resource.copy, compile">
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Main-Class" value="${main.class}" />
<attribute name="Class-Path" value="${manifest.class.path}" />
</manifest>
</jar>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" />
<copy todir="../DIYLC/library" overwrite="true">
<fileset dir="${jar.dir}" includes="${ant.project.name}.jar" />
</copy>
</target>
<target name="javadoc">
-31
View File
@@ -1,31 +0,0 @@
<map>
<entry>
<string>defaults</string>
<map>
<entry>
<string>com.diyfever.diylc.components.MockComponentInstance:C</string>
<com.diyfever.diylc.model.measures.Capacitance>
<value>22.0</value>
<unit class="com.diyfever.diylc.model.measures.CapacitanceUnit">uF</unit>
</com.diyfever.diylc.model.measures.Capacitance>
</entry>
<entry>
<string>com.diyfever.diylc.components.MockComponentInstance:Color</string>
<awt-color>
<red>255</red>
<green>0</green>
<blue>0</blue>
<alpha>255</alpha>
</awt-color>
</entry>
</map>
</entry>
<entry>
<string>metric</string>
<boolean>true</boolean>
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
</map>
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
@@ -1,130 +0,0 @@
package org.diylc.components;
import java.awt.Point;
import org.diylc.model.IComponentInstance;
import org.diylc.model.VisibilityPolicy;
import org.diylc.model.annotations.BomName;
import org.diylc.model.annotations.ControlPoint;
import org.diylc.model.annotations.EditableProperty;
import org.diylc.model.measures.Size;
import org.diylc.utils.Constants;
/**
* Base class for all leaded components such as resistors or capacitors. Has two
* control points for leads and one control point for the label.
*
* @author Branislav Stojkovic
*/
public abstract class AbstractLeadedComponentInstance implements IComponentInstance {
private static final long serialVersionUID = 1L;
protected Size width;
protected Size height;
protected Point point1 = new Point(0, 0);
protected Point point2 = new Point((int) (Constants.GRID * 10), 0);
protected Point labelPoint = new Point((int) (Constants.GRID * 5), -(int) Constants.GRID);
protected String name = "New Component";
protected AbstractLeadedComponentInstance() {
super();
this.width = getDefaultWidth();
this.height = getDefaultHeight();
}
/**
* Returns the default component width.
*
* @return
*/
protected abstract Size getDefaultWidth();
/**
* Returns the default component height.
*
* @return
*/
protected abstract Size getDefaultHeight();
@BomName
@EditableProperty
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
public Point getPoint1() {
return point1;
}
public void setPoint1(Point point1) {
this.point1 = point1;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
public Point getPoint2() {
return point2;
}
public void setPoint2(Point point2) {
this.point2 = point2;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
public Point getLabelPoint() {
return labelPoint;
}
public void setLabelPoint(Point labelPoint) {
this.labelPoint = labelPoint;
}
@EditableProperty(defaultable = true)
public Size getWidth() {
return width;
}
public void setWidth(Size width) {
this.width = width;
}
@EditableProperty(defaultable = true)
public Size getHeight() {
return height;
}
public void setHeight(Size height) {
this.height = height;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AbstractLeadedComponentInstance other = (AbstractLeadedComponentInstance) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@@ -1,127 +0,0 @@
package org.diylc.components;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.model.ComponentState;
import org.diylc.model.IComponentInstance;
import org.diylc.model.VisibilityPolicy;
import org.diylc.model.annotations.BomName;
import org.diylc.model.annotations.BomValue;
import org.diylc.model.annotations.ControlPoint;
import org.diylc.model.annotations.EditableProperty;
import org.diylc.model.measures.Capacitance;
import org.diylc.model.measures.CapacitanceUnit;
import org.diylc.model.measures.Resistance;
import org.diylc.model.measures.ResistanceUnit;
import org.diylc.model.measures.Size;
import org.diylc.model.measures.SizeUnit;
public class MockComponentInstance implements IComponentInstance {
private static final long serialVersionUID = 1L;
private String testField = "Hello World";
private Capacitance c = new Capacitance(100d, CapacitanceUnit.uF);
private Resistance r = new Resistance(123d, ResistanceUnit.K);
private Size s = new Size(1d, SizeUnit.cm);
private Color color = Color.green;
private Point leftTopCorner = new Point(0, 0);
private String name = "something";
public MockComponentInstance(String testField, Capacitance c, Resistance r, Size s,
Color color, Point leftTopCorner) {
super();
this.testField = testField;
this.c = c;
this.r = r;
this.s = s;
this.color = color;
this.leftTopCorner = leftTopCorner;
}
public MockComponentInstance() {
super();
}
@BomName
@EditableProperty
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
public Point getLeftTopCorner() {
return leftTopCorner;
}
public void setLeftTopCorner(Point leftTopCorner) {
this.leftTopCorner = leftTopCorner;
}
@EditableProperty(name = "Test Field")
public String getTestField() {
return testField;
}
public void setTestField(String testField) {
this.testField = testField;
}
@BomValue
@EditableProperty(defaultable = true)
public Capacitance getC() {
return c;
}
public void setC(Capacitance c) {
this.c = c;
}
@EditableProperty(defaultable = true)
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
@EditableProperty
public Resistance getR() {
return r;
}
// Setter is commented out, ClassProcessor should ignore this property.
// public void setR(Resistance r) {
// this.r = r;
// }
// No annotation, so this property should be ignored.
public Size getS() {
return s;
}
public void setS(Size s) {
this.s = s;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
}
@Override
public MockComponentInstance clone() throws CloneNotSupportedException {
MockComponentInstance newInstance = new MockComponentInstance(testField, c.clone(), r
.clone(), s.clone(), color, (Point) leftTopCorner.clone());
return newInstance;
}
}
@@ -1,48 +0,0 @@
package org.diylc.components;
import javax.swing.Icon;
import org.diylc.images.IconLoader;
import org.diylc.model.ComponentLayer;
import org.diylc.model.IComponentInstance;
import org.diylc.model.IComponentType;
public class MockComponentType implements IComponentType {
@Override
public Class<? extends IComponentInstance> getComponentInstanceClass() {
return MockComponentInstance.class;
}
@Override
public String getInstanceNamePrefix() {
return "ABC";
}
@Override
public ComponentLayer getComponentLayer() {
return ComponentLayer.BOARD;
}
@Override
public String getDescription() {
return "Some description";
}
@Override
public Icon getIcon() {
return IconLoader.Gears.getIcon();
}
@Override
public String getName() {
return "Mock Component";
}
@Override
public String getCategory() {
return "Samples";
}
}
@@ -1,52 +0,0 @@
package org.diylc.components;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import org.diylc.model.ComponentState;
import org.diylc.model.annotations.EditableProperty;
import org.diylc.model.measures.Resistance;
import org.diylc.model.measures.ResistanceUnit;
import org.diylc.model.measures.Size;
import org.diylc.model.measures.SizeUnit;
public class ResistorInstance extends AbstractLeadedComponentInstance {
private static final long serialVersionUID = 1L;
private Resistance r = new Resistance(123d, ResistanceUnit.K);
private Color color = Color.green;
public ResistorInstance() {
super();
}
@EditableProperty
public Resistance getR() {
return r;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.setStroke(new BasicStroke(1));
if (componentState == ComponentState.DRAGGING) {
g2d.setStroke(new BasicStroke(1));
}
g2d.drawLine(point1.x, point1.y, point2.x, point2.y);
g2d.rotate(Math.PI / 4, (point1.x + point2.x) / 2, (point1.y + point2.y) / 2);
g2d.fillRect((point1.x + point2.x) / 2 - 10, (point1.y + point2.y) / 2 - 10, 20, 20);
}
@Override
protected Size getDefaultHeight() {
return new Size(3d, SizeUnit.mm);
}
@Override
protected Size getDefaultWidth() {
return new Size(10d, SizeUnit.mm);
}
}
@@ -1,48 +0,0 @@
package org.diylc.components;
import javax.swing.Icon;
import org.diylc.images.IconLoader;
import org.diylc.model.ComponentLayer;
import org.diylc.model.IComponentInstance;
import org.diylc.model.IComponentType;
public class ResistorType implements IComponentType {
@Override
public Class<? extends IComponentInstance> getComponentInstanceClass() {
return ResistorInstance.class;
}
@Override
public String getInstanceNamePrefix() {
return "R";
}
@Override
public ComponentLayer getComponentLayer() {
return ComponentLayer.COMPONENT;
}
@Override
public String getDescription() {
return "Some description";
}
@Override
public Icon getIcon() {
return IconLoader.Gears.getIcon();
}
@Override
public String getName() {
return "Resistor";
}
@Override
public String getCategory() {
return "Samples";
}
}
-108
View File
@@ -1,108 +0,0 @@
package org.diylc;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import javax.swing.UIManager;
import org.apache.log4j.PropertyConfigurator;
import org.diylc.gui.MainFrame;
import com.diyfever.gui.miscutils.PropertyInjector;
/**
*
* @author Branislav Stojkovic
*/
public class DIYLCStarter {
/**
* @param args
*/
public static void main(String[] args) {
URL url = DIYLCStarter.class.getResource("log4j.properties");
Properties properties = new Properties();
try {
properties.load(url.openStream());
PropertyConfigurator.configure(properties);
} catch (IOException e) {
e.printStackTrace();
}
url = DIYLCStarter.class.getResource("config.properties");
properties = new Properties();
try {
properties.load(url.openStream());
PropertyInjector.injectProperties(properties);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MainFrame mainFrame = new MainFrame();
// Presenter p = new Presenter(mainFrame);
//
// p.installPlugin(new ToolBox());
// p.installPlugin(new FileManager());
// p.installPlugin(new ClipboardManager());
// p.installPlugin(new StatusBar());
// p.installPlugin(new CanvasPlugin());
//
// Project project = new Project();
// project.getComponents().add(new MockComponentInstance());
// p.loadProject(project);
// panel.setPreferredSize(new Dimension(2000, 1500));
// RulerScrollPane scrollPane = new RulerScrollPane(panel);
// JFrame f = new JFrame("Test");
// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// f.add(scrollPane);
// f.setPreferredSize(new Dimension(800, 600));
// f.pack();
// f.setLocationRelativeTo(null);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
// List<Property> properties = ClassProcessor
// .extractProperties(MockComponent.class);
// MockComponent component = new MockComponent();
// for (Property p : properties) {
// try {
// p.readFrom(component);
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// PropertyEditorDialog.showFor(null, properties);
// for (Property p : properties) {
// try {
// p.writeTo(component);
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// System.out.println(p);
// }
// System.out.println(p.getComponentTypes());
}
}
@@ -1,7 +0,0 @@
package org.diylc.common;
public class BadPositionException extends Exception {
private static final long serialVersionUID = 1L;
}
@@ -1,52 +0,0 @@
package org.diylc.common;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.diylc.model.IComponentInstance;
/**
* Represents component selection as a {@link List} of
* {@link IComponentInstance} objects. Implements {@link Transferable}, so it is
* suitable for clipboard usage.
*
* @author Branislav Stojkovic
*/
public class ComponentSelection extends ArrayList<IComponentInstance> implements Transferable {
private static final long serialVersionUID = 1L;
public static final DataFlavor listFlavor = new DataFlavor(List.class, "Java List");
public ComponentSelection() {
super();
}
public ComponentSelection(Collection<IComponentInstance> selectedComponents) {
super(selectedComponents);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(listFlavor)) {
return this;
}
throw new UnsupportedFlavorException(flavor);
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { listFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(listFlavor);
}
}
@@ -1,120 +0,0 @@
package org.diylc.common;
import java.awt.Point;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.diylc.model.IComponentInstance;
import org.diylc.model.VisibilityPolicy;
/**
* Entity bean that represents a control point. Has methods for reading/writing
* {@link Point} value from/to a component.
*
* @author Branislav Stojkovic
*/
public class ControlPointWrapper {
private String name;
private Point value;
private Method setter;
private Method getter;
private boolean editable;
private boolean sticky;
private VisibilityPolicy visibilityPolicy;
public ControlPointWrapper(String name, Method getter, Method setter, boolean editable,
boolean sticky, VisibilityPolicy visibilityPolicy) {
super();
this.name = name;
this.getter = getter;
this.setter = setter;
this.editable = editable;
this.sticky = sticky;
this.visibilityPolicy = visibilityPolicy;
}
/**
* Reads value from the specified component by invoking it's
* <code>getter</code> method.
*
* @param component
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public void readFrom(IComponentInstance component) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
value = (Point) getter.invoke(component);
}
/**
* Writes the value into the specified component by invoking it's
* <code>setter</code> method.
*
* @param component
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public void writeTo(IComponentInstance component) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
setter.invoke(component, value);
}
public String getName() {
return name;
}
public boolean isEditable() {
return editable;
}
public boolean isSticky() {
return sticky;
}
public Point getValue() {
return value;
}
public void setValue(Point value) {
this.value = value;
}
public VisibilityPolicy getVisibilityPolicy() {
return visibilityPolicy;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ControlPointWrapper other = (ControlPointWrapper) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}
-36
View File
@@ -1,36 +0,0 @@
package org.diylc.common;
import java.awt.Graphics;
/**
* Enumerates all options that can be used when drawing a project.
*
* @see IPlugInPort#draw(java.awt.Graphics2D, java.util.EnumSet)
*
* @author Branislav Stojkovic
*/
public enum DrawOption {
/**
* Selection rectangle will be drawn when needed and selected components may
* be rendered differently.
*/
SELECTION,
/**
* Selected zoom level will be applied to scale the {@link Graphics} before
* drawing.
*/
ZOOM,
/**
* Grid lines are drawn.
*/
GRID,
/**
* Control points are drawn.
*/
CONTROL_POINTS,
/**
* Anti-aliasing is used when drawing.
*/
ANTIALIASING;
}
-56
View File
@@ -1,56 +0,0 @@
package org.diylc.common;
import java.awt.Rectangle;
import org.diylc.model.IComponentType;
import org.diylc.model.Project;
/**
* Enumerates all possible events between {@link IPlugInPort} and
* {@link IPlugIn}. Some events overlap so be careful which ones you subscribe
* for and how you process them.
*
* @author Branislav Stojkovic
*/
public enum EventType {
/**
* Called when zoom level changes. Typically only one parameter of type
* {@link Double} is passed with new zoom level.
*/
ZOOM_CHANGED,
/**
* Called when a new project is loaded. New {@link Project} is the first
* parameter. Boolean flag is the second parameter and it's true when new
* project is loaded, false when the same project has been either reloaded
* or loaded with undo/redo operations.
*/
PROJECT_LOADED,
/**
* Called when selection rectangle is changed. Object of type
* {@link Rectangle} is the only parameter and it contains the new selection
* rectangle.
*/
SELECTION_RECT_CHANGED,
/**
* Called when component selection is changed. New
* {@link ComponentSelection} is attached as a parameter.
*/
SELECTION_CHANGED,
/**
* Called when display needs to be repainted. No parameters are passed.
*/
REPAINT,
/**
* Called when new component slot has been changed. The only parameter is
* {@link IComponentType} and may be null.
*/
SLOT_CHANGED,
/**
* Called when the current project has been modified. Two instances of
* {@link Project} are passed as parameters, one before and one after the
* change. The third parameter is a string containing change description.
*/
PROJECT_MODIFIED, AVAILABLE_CTRL_POINTS_CHANGED, SELECTED_CTRL_POINTS_CHANGED, ;
}
-19
View File
@@ -1,19 +0,0 @@
package org.diylc.common;
import com.diyfever.gui.simplemq.IMessageListener;
/**
* Interface for plug-ins.
*
* @author Branislav Stojkovic
*/
public interface IPlugIn extends IMessageListener<EventType> {
/**
* Method that connects the plug-in with {@link IPlugInPort}. Called by the
* application when plug-in is installed.
*
* @param plugInPort
*/
void connect(IPlugInPort plugInPort);
}
-292
View File
@@ -1,292 +0,0 @@
package org.diylc.common;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Area;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.SwingConstants;
import javax.swing.JPopupMenu.Separator;
import org.diylc.model.ComponentLayer;
import org.diylc.model.IComponentInstance;
import org.diylc.model.IComponentType;
import org.diylc.model.Project;
import com.diyfever.gui.simplemq.IMessageListener;
import com.diyfever.gui.simplemq.MessageDispatcher;
import com.diyfever.gui.update.VersionNumber;
/**
* Interface for communication between plug-ins and the application. Plug-ins
* may acquire information or make changes through this interface. Application
* events are dispatched to plug-ins through {@link MessageDispatcher}
*
* @author Branislav Stojkovic
*
* @see IPlugIn
* @see MessageDispatcher
* @see IMessageListener
* @see EventType
*/
public interface IPlugInPort {
/**
* Returns size of the canvas that takes project dimensions into account as
* well as zoom level. Each dimension is calculated as the product of the
* actual size and the number of pixels per unit. If <code>useZoom</code> is
* set to true, the result is scaled by zoom factor.
*
* @param useZoom
*
* @return canvas dimensions
*/
Dimension getCanvasDimensions(boolean useZoom);
/**
* Returns an instance of {@link Cursor} that should be used at the
* specified location.
*
* Note: point coordinates are scaled for zoom factor.
*
* @param point
* @return cursor
*/
Cursor getCursorAt(Point point);
/**
* Returns an instance of currently loaded project.
*
* @return
*/
Project getCurrentProject();
/**
* Loads specified {@link Project}.
*
* @param project
* @param freshStart
*/
void loadProject(Project project, boolean freshStart);
/**
* Returns all available {@link IComponentType}s classified by category.
* Result is a {@link Map} between category name to a {@link List} of all
* {@link IComponentType}s that share that category name.
*
* @return
*/
Map<String, List<IComponentType>> getComponentTypes();
/**
* Draws project on the provided {@link Graphics2D}.
*
* @param g2d
*/
void draw(Graphics2D g2d, Set<DrawOption> drawProperties);
/**
* Injects a custom GUI panels provided by the plug-in and desired position
* in the window. Application will layout plug-in panels accordingly. <br>
* Valid positions are:
* <ul>
* <li> {@link SwingConstants#TOP}</li>
* <li> {@link SwingConstants#BOTTOM}</li>
* <li> {@link SwingConstants#LEFT}</li>
* <li> {@link SwingConstants#RIGHT}</li>
* </ul>
*
* Center position is reserved for the main canvas panel and cannot be used.
*
* @param component
* @param position
* @throws BadPositionException
* in case invalid position is specified
*/
void injectGUIComponent(JComponent component, int position) throws BadPositionException;
/**
* Injects a custom menu action into application's main menu. If
* <code>action</code> is set to null {@link Separator} will be added. If
* the specified menu does not exist it will be automatically created.
*
* @param action
* {@link Action} to inser
* @param menuName
* name of the menu to insert into
*/
public void injectMenuAction(Action action, String menuName);
/**
* Returns current zoom level where <code>zoomLevel = 1.0d</code> means
* 100%.
*
* @return current zoom level
*/
double getZoomLevel();
/**
* Changes current zoom level where <code>zoomLevel = 1.0d</code> means 100%
*
* @param zoomLevel
* new zoom leve
*/
void setZoomLevel(double zoomLevel);
/**
* Notifies the presenter that mouse is clicked.
*
* Note: point coordinates are display based, i.e. scaled for zoom factor.
*
* @param point
* @param ctrlDown
* @param shiftDown
* @param altDown
*/
void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
/**
* Notifies the presenter that mouse is moved.
*
* Note: point coordinates are display based, i.e. scaled for zoom factor.
*
* @param point
* @param ctrlDown
* @param shiftDown
* @param altDown
*/
void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
/**
* Returns the current {@link ComponentSelection}.
*
* @return
*/
ComponentSelection getSelectedComponents();
/**
* Returns the {@link Area} occupied by the component.
*
* @return
*/
Area getComponentArea(IComponentInstance component);
/**
* Notification that drag has been started from the specified point.
*
* Note: point coordinates are scaled for zoom factor.
*
* @param point
*/
void dragStarted(Point point);
/**
* Checks if it's possible to drop over the specified point.
*
* Note: point coordinates are scaled for zoom factor.
*
* @param point
* @return
*/
boolean dragOver(Point point);
/**
* Notification that drag has been ended in the specified point.
*
* Note: point coordinates are scaled for zoom factor.
*
* @param point
*/
void dragEnded(Point point);
/**
* Returns current version number.
*
* @return
*/
VersionNumber getCurrentVersionNumber();
/**
* Adds a list of components to the project.
*
* @param components
* @param preferredPoint
*/
void addComponents(List<IComponentInstance> components, Point preferredPoint);
/**
* Checks if a certain layer is locked for editing.
*
* @param layer
* @return
*/
boolean isLayerLocked(ComponentLayer layer);
/**
* Changes layer's locked state.
*
* @param layer
* @param locked
*/
void setLayerLocked(ComponentLayer layer, boolean locked);
/**
* Checks if a certain layer is visible.
*
* @param layer
* @return
*/
boolean isLayerVisible(ComponentLayer layer);
/**
* Changes layer visibility.
*
* @param layer
* @param visible
*/
void setLayerVisible(ComponentLayer layer, boolean visible);
/**
* Sets default value for the specified property name for currently selected
* component types.
*
* @param propertyName
* display name for property
* @param value
* new default value, must not be null
*/
void setDefaultPropertyValue(String propertyName, Object value);
/**
* Returns a list of properties that are mutual for all the selected
* components. Resulting list may be empty if selected components do not
* have mutual properties or can be null if the selection is empty.
*
* @return
*/
List<PropertyWrapper> getMutualSelectionProperties();
/**
* Applies specified properties to all the selected components. If some of
* the properties are not applicable to some of the selected components an
* exception will be thrown.
*
* @param properties
* @throws Exception
*/
void applyPropertiesToSelection(List<PropertyWrapper> properties) throws Exception;
// void setCursorIcon(Icon icon);
/**
* Sets the new component slot. Specified component type will be used to
* instantiate new component.
*/
void setNewComponentSlot(IComponentType componentType);
}
-144
View File
@@ -1,144 +0,0 @@
package org.diylc.common;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.diylc.model.IComponentInstance;
/**
* Entity class for editable properties extracted from component objects.
* Represents a single editable property together with it's current value.
*
* @author Branislav Stojkovic
*/
public class PropertyWrapper implements Cloneable {
private String name;
private Class<?> type;
private Object value;
private Method setter;
private Method getter;
private boolean defaultable;
public PropertyWrapper(String name, Class<?> type, Method getter, Method setter,
boolean defaultable) {
super();
this.name = name;
this.type = type;
this.getter = getter;
this.setter = setter;
this.defaultable = defaultable;
}
public void readFrom(IComponentInstance component) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
this.value = getter.invoke(component);
}
// public void readUniqueFrom(IComponentInstance component)
// throws IllegalArgumentException, IllegalAccessException,
// InvocationTargetException {
// Object newValue = getter.invoke(component);
// if (!newValue.equals(value)) {
// this.value = null;
// }
// }
public void writeTo(IComponentInstance component) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
setter.invoke(component, value);
}
public String getName() {
return name;
}
public Class<?> getType() {
return type;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public boolean isDefaultable() {
return defaultable;
}
public void setDefaultable(boolean defaultable) {
this.defaultable = defaultable;
}
// @Override
// public Object clone() throws CloneNotSupportedException {
// // Try to invoke clone method on value if possible.
// try {
// Method cloneMethod = value.getClass().getMethod("clone");
// return new Property(name, type, cloneMethod.invoke(value));
// } catch (Exception e) {
// }
// return new Property(name, type, value);
// }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (defaultable ? 1231 : 1237);
result = prime * result + ((getter == null) ? 0 : getter.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PropertyWrapper other = (PropertyWrapper) obj;
if (defaultable != other.defaultable)
return false;
if (getter == null) {
if (other.getter != null)
return false;
} else if (!getter.equals(other.getter))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (setter == null) {
if (other.setter != null)
return false;
} else if (!setter.equals(other.setter))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
@Override
public String toString() {
return name + " = " + value;
}
}
@@ -0,0 +1,124 @@
package org.diylc.components.boards;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
public abstract class AbstractBoard extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
public static Color BOARD_COLOR = Color.decode("#F8EBB3");
public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
protected String value = "";
protected Point[] controlPoints = new Point[] {
new Point(0, 0),
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels()) };
protected Point firstPoint = new Point();
protected Point secondPoint = new Point();
protected Color boardColor = BOARD_COLOR;
protected Color borderColor = BORDER_COLOR;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(boardColor);
g2d.fillRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y
- firstPoint.y);
g2d.setComposite(oldComposite);
}
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.drawRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y
- firstPoint.y);
// Do not track any changes that follow because the whole board has been
// tracked so far.
drawingObserver.stopTracking();
}
@EditableProperty(name = "Color")
public Color getBoardColor() {
return boardColor;
}
public void setBoardColor(Color boardColor) {
this.boardColor = boardColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.WHEN_SELECTED;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
firstPoint.setLocation(Math.min(controlPoints[0].x, controlPoints[1].x), Math.min(
controlPoints[0].y, controlPoints[1].y));
secondPoint.setLocation(Math.max(controlPoints[0].x, controlPoints[1].x), Math.max(
controlPoints[0].y, controlPoints[1].y));
}
@EditableProperty
@Override
public String getValue() {
return value;
}
@Override
public void setValue(String value) {
this.value = value;
}
}
@@ -0,0 +1,20 @@
package org.diylc.components.boards;
import java.awt.Graphics2D;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
@ComponentDescriptor(name = "Blank Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Blank circuit board")
public class BlankBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
}
}
@@ -0,0 +1,115 @@
package org.diylc.components.boards;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Eyelet Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with eyelets")
public class EyeletBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
public static Color BOARD_COLOR = Color.decode("#CCFFCC");
public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Color EYELET_COLOR = Color.decode("#C3E4ED");
public static Size SPACING = new Size(0.5d, SizeUnit.in);
public static Size EYELET_SIZE = new Size(0.2d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(0.1d, SizeUnit.in);
// private Area copperArea;
protected Size spacing = SPACING;
protected Color eyeletColor = EYELET_COLOR;
public EyeletBoard() {
super();
this.boardColor = BOARD_COLOR;
this.borderColor = BORDER_COLOR;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int diameter = getClosestOdd((int) EYELET_SIZE.convertToPixels());
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
p.y += spacing;
while (p.x < secondPoint.x - spacing - diameter) {
p.x += spacing;
g2d.setColor(eyeletColor);
g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
g2d.setColor(eyeletColor.darker());
g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
g2d.setColor(eyeletColor.darker());
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
}
}
}
}
@EditableProperty(name = "Eyelet color")
public Color getEyeletColor() {
return eyeletColor;
}
public void setEyeletColor(Color padColor) {
this.eyeletColor = padColor;
}
@EditableProperty
public Size getSpacing() {
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(EYELET_COLOR);
g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(EYELET_COLOR.darker());
g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 2, width / 2 - 2, 5, 5);
g2d.setColor(EYELET_COLOR.darker());
g2d.drawOval(width / 2 - 2, width / 2 - 2, 5, 5);
}
}
@@ -0,0 +1,109 @@
package org.diylc.components.boards;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Marshall Style Perf Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board as found on some Marshall and Trainwreck amps")
public class MarshallPerfBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
public static Color BOARD_COLOR = Color.decode("#CD8500");
public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Size SPACING = new Size(3 / 8d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(1 / 8d, SizeUnit.in);
// private Area copperArea;
protected Size spacing = SPACING;
public MarshallPerfBoard() {
super();
this.boardColor = BOARD_COLOR;
this.borderColor = BORDER_COLOR;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
p.y += spacing;
while (p.x < secondPoint.x - spacing - holeDiameter) {
p.x += spacing;
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
g2d.setColor(borderColor);
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
}
}
}
}
@EditableProperty
public Size getSpacing() {
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2, width / 3 - 2, 5, 5);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(width / 3 - 2, width / 3 - 2, 5, 5);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(2 * width / 3 - 2, width / 3 - 2, 5, 5);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(2 * width / 3 - 2, width / 3 - 2, 5, 5);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2, 2 * width / 3 - 2, 5, 5);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(width / 3 - 2, 2 * width / 3 - 2, 5, 5);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(2 * width / 3 - 2, 2 * width / 3 - 2, 5, 5);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(2 * width / 3 - 2, 2 * width / 3 - 2, 5, 5);
}
}
@@ -0,0 +1,107 @@
package org.diylc.components.boards;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Perf Board w/ Pads", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with solder pads")
public class PerfBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
public static Color COPPER_COLOR = Color.decode("#DA8A67");
public static Size SPACING = new Size(0.1d, SizeUnit.in);
public static Size PAD_SIZE = new Size(0.08d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
// private Area copperArea;
protected Size spacing = SPACING;
protected Color padColor = COPPER_COLOR;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int diameter = getClosestOdd((int) PAD_SIZE.convertToPixels());
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
p.y += spacing;
while (p.x < secondPoint.x - spacing - diameter) {
p.x += spacing;
g2d.setColor(padColor);
g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
g2d.setColor(padColor.darker());
g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
g2d.setColor(padColor.darker());
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
}
}
}
}
@EditableProperty(name = "Pad color")
public Color getPadColor() {
return padColor;
}
public void setPadColor(Color padColor) {
this.padColor = padColor;
}
@EditableProperty
public Size getSpacing() {
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(COPPER_COLOR);
g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(COPPER_COLOR.darker());
g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 2, width / 2 - 2, 5, 5);
g2d.setColor(COPPER_COLOR.darker());
g2d.drawOval(width / 2 - 2, width / 2 - 2, 5, 5);
}
}
@@ -0,0 +1,142 @@
package org.diylc.components.boards;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import org.diylc.common.OrientationHV;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Vero Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated FR4 board with copper strips connecting all holes in a row")
public class VeroBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
public static Color STRIP_COLOR = Color.decode("#DA8A67");
public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Size SPACING = new Size(0.1d, SizeUnit.in);
public static Size STRIP_SIZE = new Size(0.07d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
protected Size spacing = SPACING;
protected Color stripColor = STRIP_COLOR;
protected OrientationHV orientation = OrientationHV.HORIZONTAL;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int stripSize = getClosestOdd((int) STRIP_SIZE.convertToPixels());
int holeSize = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
if (orientation == OrientationHV.HORIZONTAL) {
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
p.y += spacing;
g2d.setColor(stripColor);
g2d.fillRect(p.x + spacing / 2, p.y - stripSize / 2, secondPoint.x - spacing
- p.x, stripSize);
g2d.setColor(stripColor.darker());
g2d.drawRect(p.x + spacing / 2, p.y - stripSize / 2, secondPoint.x - spacing
- p.x, stripSize);
while (p.x < secondPoint.x - spacing - holeSize) {
p.x += spacing;
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
g2d.setColor(stripColor.darker());
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
}
}
} else {
while (p.x < secondPoint.x - spacing) {
p.x += spacing;
p.y = firstPoint.y;
g2d.setColor(stripColor);
g2d.fillRect(p.x - stripSize / 2, p.y + spacing / 2, stripSize, secondPoint.y
- spacing - p.y);
g2d.setColor(stripColor.darker());
g2d.drawRect(p.x - stripSize / 2, p.y + spacing / 2, stripSize, secondPoint.y
- spacing - p.y);
while (p.y < secondPoint.y - spacing - holeSize) {
p.y += spacing;
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
g2d.setColor(stripColor.darker());
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
}
}
}
g2d.setComposite(oldComposite);
}
}
@EditableProperty(name = "Strip color")
public Color getStripColor() {
return stripColor;
}
public void setStripColor(Color padColor) {
this.stripColor = padColor;
}
@EditableProperty
public Size getSpacing() {
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
}
@EditableProperty
public OrientationHV getOrientation() {
return orientation;
}
public void setOrientation(OrientationHV orientation) {
this.orientation = orientation;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(STRIP_COLOR);
g2d.fillRect(4, width / 4, width - 8, width / 2);
g2d.setColor(STRIP_COLOR.darker());
g2d.drawRect(4, width / 4, width - 8, width / 2);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2, width / 2 - 2, 5, 5);
g2d.fillOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
g2d.setColor(STRIP_COLOR.darker());
g2d.drawOval(width / 3 - 2, width / 2 - 2, 5, 5);
g2d.drawOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
}
}
@@ -0,0 +1,15 @@
package org.diylc.components.connectivity;
public enum AWG {
_8, _10, _12, _14, _16, _18, _20, _22, _24, _26, _28, _30;
@Override
public String toString() {
return "#" + name().replace("_", "");
}
public int getValue() {
return Integer.parseInt(name().replace("_", ""));
}
}
@@ -0,0 +1,122 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Copper Trace", author = "Branislav Stojkovic", category = "Connectivity", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "Trace", description = "Straight copper trace", zOrder = IDIYComponent.TRACE)
public class CopperTrace extends AbstractLeadedComponent<Void> {
private static final long serialVersionUID = 1L;
public static Size THICKNESS = new Size(1d, SizeUnit.mm);
public static Color COLOR = Color.black;
private Color leadColor = COLOR;
private Size thickness = THICKNESS;
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(3));
g2d.setColor(COLOR);
g2d.drawLine(1, height - 2, width - 2, 1);
}
@Override
protected Color getLeadColor(ComponentState componentState) {
return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : leadColor;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.WHEN_SELECTED;
}
@EditableProperty(name = "Color")
public Color getLeadColor() {
return leadColor;
}
public void setLeadColor(Color leadColor) {
this.leadColor = leadColor;
}
@EditableProperty(name = "Width")
public Size getThickness() {
return thickness;
}
public void setThickness(Size thickness) {
this.thickness = thickness;
}
@Override
protected int getLeadThickness() {
return (int) getThickness().convertToPixels();
}
@Override
protected boolean shouldShadeLeads() {
return false;
}
public Color getBodyColor() {
return super.getBodyColor();
}
@Override
public Color getBorderColor() {
return super.getBorderColor();
}
@Override
public Byte getAlpha() {
return super.getAlpha();
}
@Override
public Size getLength() {
return super.getLength();
}
@Override
public Size getWidth() {
return super.getWidth();
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
@Override
protected Shape getBodyShape() {
return null;
}
@Override
protected Size getDefaultWidth() {
return null;
}
@Override
protected Size getDefaultLength() {
return null;
}
}
@@ -0,0 +1,68 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.CubicCurve2D;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractCurvedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Curved Trace", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "Trace", description = "Curved copper trace with two control points", zOrder = IDIYComponent.TRACE)
public class CurvedTrace extends AbstractCurvedComponent<Void> {
private static final long serialVersionUID = 1L;
public static Color COLOR = Color.black;
public static Size SIZE = new Size(1d, SizeUnit.mm);
protected Size size = SIZE;
@Override
protected Color getDefaultColor() {
return COLOR;
}
@Override
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
int thickness = (int) size.convertToPixels();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness));
Color curveColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color;
g2d.setColor(curveColor);
g2d.draw(curve);
}
@EditableProperty(name = "Width")
public Size getThickness() {
return size;
}
public void setThickness(Size size) {
this.size = size;
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
@Override
public Byte getAlpha() {
return super.getAlpha();
}
@Override
public void setAlpha(Byte alpha) {
super.setAlpha(alpha);
}
}
@@ -0,0 +1,139 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Eyelet", category = "Connectivity", author = "Branislav Stojkovic", description = "Eyelet or turret terminal", instanceNamePrefix = "Eyelet", stretchable = false, zOrder = IDIYComponent.TRACE + 0.1)
public class Eyelet extends AbstractComponent<String> {
private static final long serialVersionUID = 1L;
public static Size SIZE = new Size(0.2d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(0.1d, SizeUnit.in);
public static Color COLOR = Color.decode("#C3E4ED");
private Size size = SIZE;
private Size holeSize = HOLE_SIZE;
private Color color = COLOR;
private Point point = new Point(0, 0);
private String value = "";
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int diameter = getClosestOdd((int) size.convertToPixels());
int holeDiameter = getClosestOdd((int) holeSize.convertToPixels());
g2d.setColor(color);
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker());
g2d.drawOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter,
holeDiameter);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker());
g2d.drawOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter,
holeDiameter);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int diameter = getClosestOdd(width / 2);
int holeDiameter = 5;
g2d.setColor(COLOR);
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
g2d.setColor(COLOR.darker());
g2d.drawOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter,
holeDiameter);
g2d.setColor(COLOR.darker());
g2d.drawOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter,
holeDiameter);
}
@EditableProperty
public Size getSize() {
return size;
}
public void setSize(Size size) {
this.size = size;
}
@EditableProperty(name = "Hole size")
public Size getHoleSize() {
return holeSize;
}
public void setHoleSize(Size holeSize) {
this.holeSize = holeSize;
}
@Override
public String getName() {
return super.getName();
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public Point getControlPoint(int index) {
return point;
}
@Override
public void setControlPoint(Point point, int index) {
this.point.setLocation(point);
}
@EditableProperty(name = "Color")
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
@Override
@EditableProperty
public String getValue() {
return value;
}
@Override
public void setValue(String value) {
this.value = value;
}
}
@@ -0,0 +1,63 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.CubicCurve2D;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractCurvedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.COMPONENT)
public class HookupWire extends AbstractCurvedComponent<Void> {
private static final long serialVersionUID = 1L;
public static Color COLOR = Color.green;
public static double INSULATION_THICKNESS_PCT = 0.3;
protected AWG gauge = AWG._22;
@Override
protected Color getDefaultColor() {
return COLOR;
}
@Override
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * gauge.getValue())
* Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
Color curveColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker();
g2d.setColor(curveColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness));
g2d.draw(curve);
if (componentState == ComponentState.NORMAL) {
g2d.setColor(color);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness - 2));
g2d.draw(curve);
}
}
@EditableProperty(name = "AWG")
public AWG getGauge() {
return gauge;
}
public void setGauge(AWG gauge) {
this.gauge = gauge;
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
}
@@ -0,0 +1,97 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "J", description = "", zOrder = IDIYComponent.COMPONENT)
public class Jumper extends AbstractLeadedComponent<Void> {
private static final long serialVersionUID = 1L;
public static Color COLOR = Color.blue;
private Color color = COLOR;
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(3));
g2d.setColor(COLOR.darker());
g2d.drawLine(1, height - 2, width - 2, 1);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(COLOR);
g2d.drawLine(1, height - 2, width - 2, 1);
}
@Override
public Color getLeadColor(ComponentState componentState) {
return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color;
}
@EditableProperty
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public Color getBodyColor() {
return super.getBodyColor();
}
@Override
public Color getBorderColor() {
return super.getBorderColor();
}
@Override
public Byte getAlpha() {
return super.getAlpha();
}
@Override
public Size getLength() {
return super.getLength();
}
@Override
public Size getWidth() {
return super.getWidth();
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
@Override
protected Shape getBodyShape() {
return null;
}
@Override
protected Size getDefaultWidth() {
return null;
}
@Override
protected Size getDefaultLength() {
return null;
}
}
@@ -0,0 +1,139 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic", description = "test", instanceNamePrefix = "Pad", stretchable = false, zOrder = IDIYComponent.TRACE + 0.1)
public class SolderPad extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L;
public static Size SIZE = new Size(0.09d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(0.8d, SizeUnit.mm);
public static Color COLOR = Color.black;
private Size size = SIZE;
private Color color = COLOR;
private Point point = new Point(0, 0);
private Type type = Type.ROUND;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int diameter = getClosestOdd((int) size.convertToPixels());
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color);
if (type == Type.ROUND) {
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
} else {
g2d.fillRect(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
}
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter,
holeDiameter);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int diameter = getClosestOdd(width / 2);
int holeDiameter = 5;
g2d.setColor(COLOR);
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter,
holeDiameter);
}
@EditableProperty
public Size getSize() {
return size;
}
public void setSize(Size size) {
this.size = size;
}
@Override
public String getName() {
return super.getName();
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public Point getControlPoint(int index) {
return point;
}
@Override
public void setControlPoint(Point point, int index) {
this.point.setLocation(point);
}
@EditableProperty(name = "Color")
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
@EditableProperty
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
static enum Type {
ROUND, SQUARE;
@Override
public String toString() {
return name().substring(0, 1) + name().substring(1).toLowerCase();
}
}
}
@@ -0,0 +1,132 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Trace Cut", category = "Connectivity", author = "Branislav Stojkovic", description = "Designates the place where a trace on the vero board needs to be cut", instanceNamePrefix = "Cut", stretchable = false, zOrder = IDIYComponent.BOARD + 1)
public class TraceCut extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L;
public static Size SIZE = new Size(0.07d, SizeUnit.in);
public static Color FILL_COLOR = Color.white;
public static Color BORDER_COLOR = Color.red;
public static Color SELECTION_COLOR = Color.blue;
private Size size = SIZE;
private Color fillColor = FILL_COLOR;
private Color borderColor = BORDER_COLOR;
protected Point point = new Point(0, 0);
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int size = getClosestOdd((int) this.size.convertToPixels());
int dotDiameter = size - 6;
g2d.setColor(fillColor);
g2d.fillRect(point.x - size / 2, point.y - size / 2, size, size);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.drawRect(point.x - size / 2, point.y - size / 2, size, size);
g2d
.fillOval(point.x - dotDiameter / 2, point.y - dotDiameter / 2, dotDiameter,
dotDiameter);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int size = 16;
int dotDiameter = size / 4 * 2;
g2d.setColor(FILL_COLOR);
g2d.fillRect((width - size) / 2, (height - size) / 2, size, size);
g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.drawRect((width - size) / 2, (height - size) / 2, size, size);
g2d.fillOval((width - dotDiameter) / 2, (height - dotDiameter) / 2, dotDiameter,
dotDiameter);
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public Point getControlPoint(int index) {
return point;
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
this.point.setLocation(point);
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
@EditableProperty
public Size getSize() {
return size;
}
public void setSize(Size size) {
this.size = size;
}
@EditableProperty(name = "Fill")
public Color getFillColor() {
return fillColor;
}
public void setFillColor(Color fillColor) {
this.fillColor = fillColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
@Override
public String getName() {
return super.getName();
}
}
@@ -0,0 +1,270 @@
package org.diylc.components.electromechanical;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic", description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW")
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
private static final long serialVersionUID = 1L;
private static Size SPACING = new Size(0.2d, SizeUnit.in);
private static Size MARGIN = new Size(0.08d, SizeUnit.in);
private static Size CIRCLE_SIZE = new Size(0.09d, SizeUnit.in);
private static Size LUG_WIDTH = new Size(0.060d, SizeUnit.in);
private static Size LUG_HEIGHT = new Size(0.03d, SizeUnit.in);
private static Color BODY_COLOR = Color.decode("#3299CC");
private static Color BORDER_COLOR = BODY_COLOR.darker();
private static Color CIRCLE_COLOR = Color.red;
private static Color LUG_COLOR = Color.decode("#00B2EE");
protected Point[] controlPoints = new Point[] { new Point(0, 0) };
transient protected RoundRectangle2D body;
protected String name;
protected ToggleSwitchType switchType = ToggleSwitchType.DPDT;
public MiniToggleSwitch() {
super();
updateControlPoints();
}
private void updateControlPoints() {
Point firstPoint = controlPoints[0];
int spacing = (int) SPACING.convertToPixels();
switch (switchType) {
case SPST:
controlPoints = new Point[] { firstPoint,
new Point(firstPoint.x, firstPoint.y + spacing) };
break;
case SPDT:
controlPoints = new Point[] { firstPoint,
new Point(firstPoint.x, firstPoint.y + spacing),
new Point(firstPoint.x, firstPoint.y + 2 * spacing) };
break;
case DPDT:
controlPoints = new Point[] { firstPoint,
new Point(firstPoint.x, firstPoint.y + spacing),
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + spacing, firstPoint.y),
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing) };
break;
case _3PDT:
controlPoints = new Point[] { firstPoint,
new Point(firstPoint.x, firstPoint.y + spacing),
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + spacing, firstPoint.y),
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y),
new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * spacing) };
break;
case _4PDT:
controlPoints = new Point[] { firstPoint,
new Point(firstPoint.x, firstPoint.y + spacing),
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + spacing, firstPoint.y),
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y),
new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + 3 * spacing, firstPoint.y),
new Point(firstPoint.x + 3 * spacing, firstPoint.y + spacing),
new Point(firstPoint.x + 3 * spacing, firstPoint.y + 2 * spacing) };
break;
case _5PDT:
controlPoints = new Point[] { firstPoint,
new Point(firstPoint.x, firstPoint.y + spacing),
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + spacing, firstPoint.y),
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y),
new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + 3 * spacing, firstPoint.y),
new Point(firstPoint.x + 3 * spacing, firstPoint.y + spacing),
new Point(firstPoint.x + 3 * spacing, firstPoint.y + 2 * spacing),
new Point(firstPoint.x + 4 * spacing, firstPoint.y),
new Point(firstPoint.x + 4 * spacing, firstPoint.y + spacing),
new Point(firstPoint.x + 4 * spacing, firstPoint.y + 2 * spacing) };
break;
}
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
// Reset body shape.
body = null;
}
@EditableProperty
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@EditableProperty(name = "Type")
@Override
public ToggleSwitchType getValue() {
return switchType;
}
@Override
public void setValue(ToggleSwitchType value) {
this.switchType = value;
updateControlPoints();
// Reset body shape.
body = null;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
Shape body = getBody();
// Draw body if available.
if (body != null) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(body);
g2d.setComposite(oldComposite);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR;
}
g2d.setColor(finalBorderColor);
g2d.draw(body);
}
// Do not track these changes because the whole switch has been tracked
// so far.
drawingObserver.stopTracking();
// Draw lugs.
if (!outlineMode) {
int circleDiameter = getClosestOdd((int) CIRCLE_SIZE.convertToPixels());
int lugWidth = getClosestOdd((int) LUG_WIDTH.convertToPixels());
int lugHeight = getClosestOdd((int) LUG_HEIGHT.convertToPixels());
for (Point p : controlPoints) {
g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter,
circleDiameter);
g2d.setColor(LUG_COLOR);
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
}
}
}
public RoundRectangle2D getBody() {
if (body == null) {
Point firstPoint = controlPoints[0];
int margin = (int) MARGIN.convertToPixels();
int spacing = (int) SPACING.convertToPixels();
switch (switchType) {
case SPST:
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin,
2 * margin, 2 * margin + spacing, margin, margin);
break;
case SPDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin,
2 * margin, 2 * margin + 2 * spacing, margin, margin);
break;
case DPDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
* margin + spacing, 2 * margin + 2 * spacing, margin, margin);
break;
case _3PDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
* margin + 2 * spacing, 2 * margin + 2 * spacing, margin, margin);
break;
case _4PDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
* margin + 3 * spacing, 2 * margin + 2 * spacing, margin, margin);
break;
case _5PDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
* margin + 4 * spacing, 2 * margin + 2 * spacing, margin, margin);
break;
}
}
return body;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int circleSize = 5 * width / 32;
g2d.setColor(BODY_COLOR);
g2d.fillRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
g2d.setColor(CIRCLE_COLOR);
for (int i = 1; i <= 3; i++) {
g2d.fillOval(width / 2 - circleSize / 2, i * height / 4 - 3, circleSize, circleSize);
}
}
}
@@ -0,0 +1,11 @@
package org.diylc.components.electromechanical;
public enum ToggleSwitchType {
SPST, SPDT, DPDT, _3PDT, _4PDT, _5PDT;
@Override
public String toString() {
return name().replace("_", "");
}
}
+170
View File
@@ -0,0 +1,170 @@
package org.diylc.components.misc;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import java.util.List;
import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.swing.plugins.file.BomEntry;
import org.diylc.swing.plugins.file.BomMaker;
@ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "", instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, stretchable = false)
public class BOM extends AbstractComponent<Void> {
public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm);
public static Size SPACING = new Size(0.1d, SizeUnit.in);
public static Color COLOR = Color.black;
public static String DEFAULT_TEXT = "No components to show in the Bill of Materials";
private static final long serialVersionUID = 1L;
private Size size = DEFAULT_SIZE;
private Point point = new Point(0, 0);
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
List<BomEntry> bom = BomMaker.getInstance().createBom(project.getComponents());
// Cleanup entries that do not have a value set.
Iterator<BomEntry> iterator = bom.iterator();
while (iterator.hasNext()) {
BomEntry entry = iterator.next();
if (entry.getValue() == null || entry.getName().toLowerCase().contains("bom")) {
iterator.remove();
}
}
g2d.setFont(LABEL_FONT);
g2d.setColor(componentState == ComponentState.DRAGGING
|| componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR);
// Determine maximum name length and maximum value length to calculate
// number of columns.
FontMetrics fontMetrics = g2d.getFontMetrics();
int maxNameWidth = 0;
int maxValueWidth = 0;
int maxHeight = 0;
for (BomEntry entry : bom) {
Rectangle2D stringBounds = fontMetrics.getStringBounds(entry.getName(), g2d);
if (stringBounds.getWidth() > maxNameWidth) {
maxNameWidth = (int) stringBounds.getWidth();
}
if (stringBounds.getHeight() > maxHeight) {
maxHeight = (int) stringBounds.getHeight();
}
stringBounds = fontMetrics.getStringBounds(entry.getValue().toString(), g2d);
if (stringBounds.getWidth() > maxValueWidth) {
maxValueWidth = (int) stringBounds.getWidth();
}
if (stringBounds.getHeight() > maxHeight) {
maxHeight = (int) stringBounds.getHeight();
}
}
// Calculate maximum entry size.
int maxEntrySize = maxNameWidth + maxValueWidth + 2 * (int) SPACING.convertToPixels();
int columnCount = (int) size.convertToPixels() / maxEntrySize;
int columnWidth = (int) size.convertToPixels() / columnCount;
int entriesPerColumn = (int) Math.ceil(1.d * bom.size() / columnCount);
if (entriesPerColumn == 0) {
g2d.drawString(DEFAULT_TEXT, point.x, point.y);
return;
}
for (int i = 0; i < bom.size(); i++) {
int columnIndex = i / entriesPerColumn;
int rowIndex = i % entriesPerColumn;
int x = point.x + columnIndex * columnWidth;
int y = point.y + rowIndex * maxHeight;
g2d.drawString(bom.get(i).getName(), x, y);
x += maxNameWidth + SPACING.convertToPixels();
g2d.drawString(bom.get(i).getValue().toString(), x, y);
}
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(Color.white);
g2d.fillRect(width / 8, 0, 6 * width / 8, height - 1);
g2d.setColor(Color.black);
g2d.drawRect(width / 8, 0, 6 * width / 8, height - 1);
g2d.setFont(LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN));
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("BOM", g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically.
int x = (width - textWidth) / 2 + 1;
int y = textHeight + 2;
g2d.drawString("BOM", x, y);
g2d.setFont(g2d.getFont().deriveFont(1f * 5 * width / 32));
fontMetrics = g2d.getFontMetrics();
rect = fontMetrics.getStringBounds("resistors", g2d);
x = (width - textWidth) / 2 + 1;
y = height / 2 + 2;
g2d.drawString("resistors", x, y);
y += rect.getHeight() - 1;
g2d.drawString("tubes", x, y);
y += rect.getHeight() - 1;
g2d.drawString("diodes", x, y);
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public Point getControlPoint(int index) {
return point;
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
this.point.setLocation(point);
}
@EditableProperty(name = "Width")
public Size getSize() {
return size;
}
public void setSize(Size size) {
this.size = size;
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
}
@@ -0,0 +1,102 @@
package org.diylc.components.misc;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import org.apache.log4j.Logger;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
public class IconImageConverter implements Converter {
private static final Logger LOG = Logger.getLogger(IconImageConverter.class);
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
ImageIcon image = (ImageIcon) object;
int width = image.getIconWidth();
int height = image.getIconHeight();
int[] pixels = new int[width * height];
if (image != null) {
try {
PixelGrabber pg = new PixelGrabber(image.getImage(), 0, 0, width, height, pixels,
0, width);
pg.grabPixels();
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
LOG.error("Failed to load image contents");
}
} catch (InterruptedException e) {
LOG.error("Image load interrupted");
}
}
LOG.debug("Writing image to file: " + width + "x" + height);
writer.addAttribute("width", Integer.toString(width));
writer.addAttribute("height", Integer.toString(height));
StringBuilder dataBuilder = new StringBuilder();
int n = 0;
for (int pixel : pixels) {
dataBuilder.append(Integer.toString(pixel, 16));
dataBuilder.append(",");
n++;
if (n % 16 == 0) {
dataBuilder.append("\n");
}
}
writer.addAttribute("data", dataBuilder.toString());
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
int width = Integer.parseInt(reader.getAttribute("width"));
int height = Integer.parseInt(reader.getAttribute("height"));
LOG.debug("Reading image from file: " + width + "x" + height);
int[] pixels = new int[width * height];
String data = reader.getAttribute("data").replace("\n", "");
String[] splitData = data.split(",");
for (int i = 0; i < Math.min(splitData.length, pixels.length); i++) {
if (!splitData[i].trim().isEmpty()) {
try {
pixels[i] = Integer.parseInt(splitData[i].trim(), 16);
} catch (Exception e) {
pixels[i] = 0;
}
}
}
Toolkit toolkit = Toolkit.getDefaultToolkit();
ColorModel colorModel = ColorModel.getRGBdefault();
Image image = toolkit.createImage(new MemoryImageSource(width, height, colorModel, pixels,
0, width));
BufferedImage bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bimg.setRGB(0, 0, width, height, pixels, 0, width);
File outputfile = new File("c:\\saved.png");
try {
ImageIO.write(bimg, "png", outputfile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new ImageIcon(image);
}
@Override
public boolean canConvert(Class clazz) {
return ImageIcon.class.isAssignableFrom(clazz);
}
}
+131
View File
@@ -0,0 +1,131 @@
package org.diylc.components.misc;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import javax.swing.ImageIcon;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc", description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.TEXT, stretchable = false)
public class Image extends AbstractTransparentComponent<Void> {
private static final long serialVersionUID = 1L;
public static String DEFAULT_TEXT = "Double click to edit text";
private static ImageIcon ICON;
private static byte DEFAULT_SCALE = 50;
static {
String name = "image.png";
java.net.URL imgURL = Image.class.getResource(name);
if (imgURL != null) {
ICON = new ImageIcon(imgURL, name);
}
}
private Point point = new Point(0, 0);
@XStreamConverter(IconImageConverter.class)
private ImageIcon image = ICON;
private byte scale = 50;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
double s = 1d * scale / DEFAULT_SCALE;
Point endPoint = new Point((int) (image.getIconWidth() * s),
(int) (image.getIconHeight() * s));
Shape clip = g2d.getClip();
if (!clip.contains(point) && !clip.contains(endPoint)
&& !clip.contains(point.x, endPoint.y) && !clip.contains(endPoint.x, point.y)) {
return;
}
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.scale(s, s);
g2d.drawImage(image.getImage(), (int) (point.x / s), (int) (point.y / s), null);
if (componentState == ComponentState.SELECTED) {
g2d.setComposite(oldComposite);
g2d.scale(1 / s, 1 / s);
g2d.setColor(SELECTION_COLOR);
g2d.drawRect(point.x, point.y, endPoint.x, endPoint.y);
}
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.drawImage(ICON.getImage(), point.x, point.y, null);
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public Point getControlPoint(int index) {
return point;
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
this.point.setLocation(point);
}
@EditableProperty(defaultable = false)
public ImageIcon getImage() {
return image;
}
public void setImage(ImageIcon image) {
this.image = image;
}
@EditableProperty(defaultable = false)
public byte getScale() {
return scale;
}
public void setScale(byte scale) {
this.scale = scale;
}
@Override
public String getName() {
return super.getName();
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
}
+202
View File
@@ -0,0 +1,202 @@
package org.diylc.components.misc;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc", description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, stretchable = false)
public class Label extends AbstractComponent<Void> {
public static String DEFAULT_TEXT = "Double click to edit text";
private static final long serialVersionUID = 1L;
private Point point = new Point(0, 0);
private String text = DEFAULT_TEXT;
private Font font = LABEL_FONT;
private Color color = LABEL_COLOR;
private boolean center = true;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(text, g2d);
int textHeight = (int) rect.getHeight();
int textWidth = (int) rect.getWidth();
int x;
int y;
if (center) {
// Center text horizontally and vertically
x = point.x - textWidth / 2;
y = point.y - textHeight / 2 + fontMetrics.getAscent();
} else {
x = point.x;
y = point.y - textHeight;
}
g2d.drawString(text, x, y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(LABEL_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(13f * width / 32).deriveFont(Font.PLAIN));
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("Abc", g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically.
int x = (width - textWidth) / 2 + 1;
int y = (height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString("Abc", x, y);
}
@EditableProperty
public Font getFont() {
return font;
}
public void setFont(Font font) {
this.font = font;
}
// Bold and italic fields are named to be alphabetically after Font. This is
// important!
@EditableProperty(name = "Font Bold")
public boolean getBold() {
return font.isBold();
}
public void setBold(boolean bold) {
if (bold) {
if (font.isItalic()) {
font = font.deriveFont(Font.BOLD + Font.ITALIC);
} else {
font = font.deriveFont(Font.BOLD);
}
} else {
if (font.isItalic()) {
font = font.deriveFont(Font.ITALIC);
} else {
font = font.deriveFont(Font.PLAIN);
}
}
}
@EditableProperty(name = "Font Italic")
public boolean getItalic() {
return font.isItalic();
}
public void setItalic(boolean italic) {
if (italic) {
if (font.isBold()) {
font = font.deriveFont(Font.BOLD + Font.ITALIC);
} else {
font = font.deriveFont(Font.ITALIC);
}
} else {
if (font.isBold()) {
font = font.deriveFont(Font.BOLD);
} else {
font = font.deriveFont(Font.PLAIN);
}
}
}
@EditableProperty(name = "Font Size")
public int getFontSize() {
return font.getSize();
}
public void setFontSize(int size) {
font = font.deriveFont((float) size);
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public Point getControlPoint(int index) {
return point;
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
this.point.setLocation(point);
}
@EditableProperty(defaultable = false)
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@EditableProperty
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public boolean getCenter() {
return center;
}
public void setCenter(boolean center) {
this.center = center;
}
@Override
public String getName() {
return super.getName();
}
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@@ -0,0 +1,85 @@
package org.diylc.components.passive;
import java.awt.Point;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Resistance;
import org.diylc.core.measures.ResistanceUnit;
public abstract class AbstractPotentiometer extends
AbstractTransparentComponent<PotentiometerValue> {
private static final long serialVersionUID = 1L;
protected Point[] controlPoints;
protected Resistance resistance = new Resistance(100d, ResistanceUnit.K);
protected Orientation orientation = Orientation.DEFAULT;
protected Taper taper = Taper.LIN;
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@EditableProperty
public Resistance getResistance() {
return resistance;
}
public void setResistance(Resistance resistance) {
this.resistance = resistance;
}
@Override
public PotentiometerValue getValue() {
return new PotentiometerValue(resistance, taper);
}
@Override
public void setValue(PotentiometerValue value) {
this.resistance = value.getResistance();
this.taper = value.getTaper();
}
@EditableProperty
public Taper getTaper() {
return taper;
}
public void setTaper(Taper taper) {
this.taper = taper;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
}
}
@@ -0,0 +1,149 @@
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Electrolytic Capacitor (axial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Axial electrolytic capacitor, similar to Sprague Atom, F&T, etc", zOrder = IDIYComponent.COMPONENT)
public class AxialElectrolyticCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#EAADEA");
public static Color BORDER_COLOR = BODY_COLOR.darker();
public static Color MARKER_COLOR = Color.gray;
public static Color TICK_COLOR = Color.white;
private Capacitance value = new Capacitance(1d, CapacitanceUnit.uF);
private Voltage voltage = Voltage._63V;
private Color markerColor = MARKER_COLOR;
private Color tickColor = TICK_COLOR;
private boolean polarized = true;
public AxialElectrolyticCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@EditableProperty
public Voltage getVoltage() {
return voltage;
}
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
g2d.setColor(MARKER_COLOR);
g2d.fillRect(width - 9, height / 2 - 3, 5, 6);
g2d.setColor(TICK_COLOR);
g2d.drawLine(width - 6, height / 2 - 1, width - 6, height / 2 + 1);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@EditableProperty(name = "Marker")
public Color getMarkerColor() {
return markerColor;
}
public void setMarkerColor(Color coverColor) {
this.markerColor = coverColor;
}
@EditableProperty(name = "Tick")
public Color getTickColor() {
return tickColor;
}
public void setTickColor(Color tickColor) {
this.tickColor = tickColor;
}
@EditableProperty(name = "Polarized")
public boolean getPolarized() {
return polarized;
}
public void setPolarized(boolean polarized) {
this.polarized = polarized;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (polarized) {
int width = getClosestOdd(getWidth().convertToPixels());
int markerLength = (int) (getLength().convertToPixels() * 0.2);
if (!outlineMode) {
g2d.setColor(markerColor);
g2d.fillRect((int) getLength().convertToPixels() - markerLength, 0, markerLength,
width);
}
Color finalTickColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalTickColor = theme.getOutlineColor();
} else {
finalTickColor = tickColor;
}
g2d.setColor(finalTickColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
g2d.drawLine((int) getLength().convertToPixels() - markerLength / 2,
(int) (width / 2 - width * 0.15), (int) getLength().convertToPixels()
- markerLength / 2, (int) (width / 2 + width * 0.15));
}
}
}
@@ -0,0 +1,86 @@
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Film Capacitor (axial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Axial film capacitor, similar to Mallory 150s", zOrder = IDIYComponent.COMPONENT)
public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#FFE303");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = new Capacitance(22d, CapacitanceUnit.nF);
private Voltage voltage = Voltage._63V;
public AxialFilmCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@Override
protected boolean supportsStandingMode() {
return true;
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@EditableProperty
public Voltage getVoltage() {
return voltage;
}
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
}
@@ -0,0 +1,101 @@
package org.diylc.components.passive;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import org.diylc.components.AbstractSchematicLeadedSymbol;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Capacitor (schematic symbol)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Capacitor schematic symbol with an optional polarity sign", zOrder = IDIYComponent.COMPONENT)
public class CapacitorSymbol extends AbstractSchematicLeadedSymbol<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_LENGTH = new Size(0.05, SizeUnit.in);
public static Size DEFAULT_WIDTH = new Size(0.15, SizeUnit.in);
private Capacitance value = new Capacitance(22d, CapacitanceUnit.nF);
private Voltage voltage = Voltage._63V;
private boolean polarized = false;
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@EditableProperty
public Voltage getVoltage() {
return voltage;
}
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
@EditableProperty
public boolean getPolarized() {
return polarized;
}
public void setPolarized(boolean polarized) {
this.polarized = polarized;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, 13, height / 2);
g2d.drawLine(width - 13, height / 2, width, height / 2);
g2d.setColor(COLOR);
g2d.drawLine(14, height / 2 - 6, 14, height / 2 + 6);
g2d.drawLine(width - 14, height / 2 - 6, width - 14, height / 2 + 6);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_LENGTH;
}
@Override
protected Shape getBodyShape() {
GeneralPath polyline = new GeneralPath();
double length = getLength().convertToPixels();
double width = getWidth().convertToPixels();
polyline.moveTo(0, 0);
polyline.lineTo(0, width);
polyline.moveTo(length, 0);
polyline.lineTo(length, width);
return polyline;
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (polarized) {
// Draw + sign.
g2d.setColor(getBorderColor());
int plusSize = getClosestOdd(getWidth().convertToPixels() / 4);
int x = -plusSize;
int y = plusSize;
g2d.drawLine(x - plusSize / 2, y, x + plusSize / 2, y);
g2d.drawLine(x, y - plusSize / 2, x, y + plusSize / 2);
}
}
}
@@ -0,0 +1,279 @@
package org.diylc.components.passive;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Potentiometer (panel mount)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT, stretchable = false)
public class PotentiometerPanel extends AbstractPotentiometer {
private static final long serialVersionUID = 1L;
protected static Size BODY_DIAMETER = new Size(1d, SizeUnit.in);
protected static Size SPACING = new Size(0.3d, SizeUnit.in);
protected static Size LUG_DIAMETER = new Size(0.15d, SizeUnit.in);
protected static Color BODY_COLOR = Color.gray.brighter();
protected static Color BORDER_COLOR = Color.gray;
protected Size bodyDiameter = BODY_DIAMETER;
protected Size spacing = SPACING;
protected Size lugDiameter = LUG_DIAMETER;
protected Color bodyColor = BODY_COLOR;
protected Color borderColor = BORDER_COLOR;
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
transient protected Area[] body = null;
public PotentiometerPanel() {
controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0) };
updateControlPoints();
}
protected void updateControlPoints() {
int spacing = (int) this.spacing.convertToPixels();
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(controlPoints[0].x + spacing, controlPoints[0].y);
controlPoints[2].setLocation(controlPoints[0].x + 2 * spacing, controlPoints[0].y);
break;
case _90:
controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y + spacing);
controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y + 2 * spacing);
break;
case _180:
controlPoints[1].setLocation(controlPoints[0].x - spacing, controlPoints[0].y);
controlPoints[2].setLocation(controlPoints[0].x - 2 * spacing, controlPoints[0].y);
break;
case _270:
controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y - spacing);
controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y - 2 * spacing);
break;
default:
break;
}
}
public Area[] getBody() {
int spacing = (int) this.spacing.convertToPixels();
int diameter = getClosestOdd(bodyDiameter.convertToPixels());
if (body == null) {
body = new Area[7];
// Add lugs.
int lugDiameter = getClosestOdd(this.lugDiameter.convertToPixels());
int holeDiameter = getClosestOdd(this.lugDiameter.convertToPixels() / 2);
for (int i = 0; i < 3; i++) {
Area area = new Area(new Ellipse2D.Double(controlPoints[i].x - lugDiameter / 2,
controlPoints[i].y - lugDiameter / 2, lugDiameter, lugDiameter));
body[4 + i] = area;
}
switch (orientation) {
case DEFAULT:
body[3] = new Area(new Ellipse2D.Double(
controlPoints[0].x + spacing - diameter / 2, controlPoints[0].y - spacing
/ 2 - diameter, diameter, diameter));
for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double(
controlPoints[i].x - holeDiameter / 2, controlPoints[i].y
- (spacing + diameter) / 2, holeDiameter,
(spacing + diameter) / 2));
}
break;
case _90:
body[3] = new Area(new Ellipse2D.Double(controlPoints[0].x + spacing / 2,
controlPoints[0].y + spacing - diameter / 2, diameter, diameter));
for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double(controlPoints[i].x,
controlPoints[i].y - holeDiameter / 2, (spacing + diameter) / 2,
holeDiameter));
}
break;
case _180:
body[3] = new Area(new Ellipse2D.Double(
controlPoints[0].x - spacing - diameter / 2, controlPoints[0].y + spacing
/ 2, diameter, diameter));
for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double(
controlPoints[i].x - holeDiameter / 2, controlPoints[i].y,
holeDiameter, (spacing + diameter) / 2));
}
break;
case _270:
body[3] = new Area(new Ellipse2D.Double(
controlPoints[0].x - spacing / 2 - diameter, controlPoints[0].y - spacing
- diameter / 2, diameter, diameter));
for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double(controlPoints[i].x
- (spacing + diameter) / 2, controlPoints[i].y - holeDiameter / 2,
(spacing + diameter) / 2, holeDiameter));
}
break;
default:
break;
}
for (int i = 0; i < 3; i++) {
for (int j = 3; j < 7; j++) {
body[i].subtract(body[j]);
}
}
// Make holes in the lugs.
for (int i = 0; i < 3; i++) {
body[4 + i].subtract(new Area(new Ellipse2D.Double(controlPoints[i].x
- holeDiameter / 2, controlPoints[i].y - holeDiameter / 2, holeDiameter,
holeDiameter)));
}
}
return body;
}
@Override
public void setControlPoint(Point point, int index) {
super.setControlPoint(point, index);
body = null;
}
@Override
public void setOrientation(Orientation orientation) {
super.setOrientation(orientation);
updateControlPoints();
body = null;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
for (Area shape : getBody()) {
if (shape != null) {
g2d.setColor(bodyColor);
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.fill(shape);
g2d.setComposite(oldComposite);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.draw(shape);
}
}
// Draw caption.
g2d.setFont(LABEL_FONT);
g2d
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D bodyRect = getBody()[3].getBounds2D();
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) rect.getHeight();
int textWidth = (int) rect.getWidth();
int panelHeight = (int) bodyRect.getHeight();
int panelWidth = (int) bodyRect.getWidth();
int x = (panelWidth - textWidth) / 2;
int y = panelHeight / 2 - textHeight + fontMetrics.getAscent();
g2d.drawString(getName(), (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
// Draw value.
rect = fontMetrics.getStringBounds(getValue().toString(), g2d);
textHeight = (int) rect.getHeight();
textWidth = (int) rect.getWidth();
x = (panelWidth - textWidth) / 2;
y = panelHeight / 2 + fontMetrics.getAscent();
g2d.drawString(getValue().toString(), (int) (bodyRect.getX() + x),
(int) (bodyRect.getY() + y));
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 4 * width / 32;
int spacing = width / 3 - 1;
g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2 * width / 32));
g2d.drawLine(width / 2 - spacing, height / 2, width / 2 - spacing, height - margin);
g2d.drawLine(width / 2 + spacing, height / 2, width / 2 + spacing, height - margin);
g2d.drawLine(width / 2, height / 2, width / 2, height - margin);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(4 * width / 32));
g2d.drawLine(width / 2 - spacing, height - margin, width / 2 - spacing, height - margin);
g2d.drawLine(width / 2 + spacing, height - margin, width / 2 + spacing, height - margin);
g2d.drawLine(width / 2, height - margin, width / 2, height - margin);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(BODY_COLOR);
g2d.fillOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
}
@EditableProperty
public Size getSpacing() {
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
updateControlPoints();
body = null;
}
@EditableProperty(name = "Diameter")
public Size getBodyDiameter() {
return bodyDiameter;
}
public void setBodyDiameter(Size bodyDiameter) {
this.bodyDiameter = bodyDiameter;
}
@EditableProperty(name = "Lug size")
public Size getLugDiameter() {
return lugDiameter;
}
public void setLugDiameter(Size lugDiameter) {
this.lugDiameter = lugDiameter;
}
@EditableProperty(name = "Body")
public Color getBodyColor() {
return bodyColor;
}
public void setBodyColor(Color bodyColor) {
this.bodyColor = bodyColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
}
@@ -0,0 +1,28 @@
package org.diylc.components.passive;
import org.diylc.core.measures.Resistance;
public class PotentiometerValue {
private Resistance resistance;
private Taper taper;
public PotentiometerValue(Resistance resistance, Taper taper) {
super();
this.resistance = resistance;
this.taper = taper;
}
public Resistance getResistance() {
return resistance;
}
public Taper getTaper() {
return taper;
}
@Override
public String toString() {
return resistance.toString() + " " + taper.toString();
}
}
@@ -0,0 +1,18 @@
package org.diylc.components.passive;
public enum Power {
EIGHT("1/8W"), QUARTER("1/4W"), HALF("1/2W"), ONE("1W"), TWO("2W"), FIVE("5W"), TEN("10W"), FIFTY(
"50W"), HUNDRED("100W");
String label;
Power(String label) {
this.label = label;
}
@Override
public String toString() {
return label;
}
}
@@ -0,0 +1,80 @@
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Ceramic Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Standard radial ceramic capacitor", zOrder = IDIYComponent.COMPONENT)
public class RadialCeramicDiskCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#F0E68C");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = new Capacitance(470d, CapacitanceUnit.pF);
private Voltage voltage = Voltage._63V;
public RadialCeramicDiskCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@EditableProperty
public Voltage getVoltage() {
return voltage;
}
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillOval(4, height / 2 - 3, width - 8, 6);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(4, height / 2 - 3, width - 8, 6);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth()
.convertToPixels()));
}
}
@@ -0,0 +1,184 @@
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Electrolytic Capacitor", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Vertical mounted electrolytic capacitor, polarized or bipolar", zOrder = IDIYComponent.COMPONENT)
public class RadialElectrolytic extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_SIZE = new Size(1d / 2, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#EAADEA");
public static Color BORDER_COLOR = BODY_COLOR.darker();
public static Color MARKER_COLOR = Color.gray;
public static Color TICK_COLOR = Color.white;
private Capacitance value = new Capacitance(1d, CapacitanceUnit.uF);
private Voltage voltage = Voltage._63V;
private Color markerColor = MARKER_COLOR;
private Color tickColor = TICK_COLOR;
private boolean polarized = true;
public RadialElectrolytic() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@EditableProperty
public Voltage getVoltage() {
return voltage;
}
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BODY_COLOR);
int margin = 3;
Ellipse2D body = new Ellipse2D.Double(margin, margin, getClosestOdd(width - 2 * margin),
getClosestOdd(width - 2 * margin));
g2d.fill(body);
Area marker = new Area(body);
marker.subtract(new Area(new Rectangle2D.Double(margin, margin, width - 4 * margin,
getClosestOdd(width - 2 * margin))));
g2d.setColor(MARKER_COLOR);
g2d.fill(marker);
g2d.setColor(TICK_COLOR);
g2d.drawLine(width - 2 * margin, height / 2 - 2, width - 2 * margin, height / 2 + 2);
g2d.setColor(BORDER_COLOR);
g2d.draw(body);
// g2d.setColor(COVER_COLOR.darker());
// g2d.drawLine(innerMargin + 2, innerMargin + 2, width - innerMargin -
// 2, width - innerMargin
// - 2);
// g2d.drawLine(innerMargin + 2, width - innerMargin - 2, width -
// innerMargin - 2,
// innerMargin + 2);
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (polarized) {
int totalDiameter = getClosestOdd(getLength().convertToPixels());
if (!outlineMode) {
Area area = new Area(getBodyShape());
area.subtract(new Area(new Rectangle2D.Double(0, 0, totalDiameter * 0.8,
totalDiameter)));
g2d.setColor(markerColor);
g2d.fill(area);
}
Color finalTickColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalTickColor = theme.getOutlineColor();
} else {
finalTickColor = tickColor;
}
g2d.setColor(finalTickColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
g2d.drawLine((int) (totalDiameter * 0.9), totalDiameter / 2
- (int) (totalDiameter * 0.05), (int) (totalDiameter * 0.9), totalDiameter / 2
+ (int) (totalDiameter * 0.05));
}
// int coverDiameter = getClosestOdd(totalDiameter * 3 / 4);
// g2d.setColor(coverColor);
// int position = (totalDiameter - coverDiameter) / 2;
// g2d.fillOval(position, position, coverDiameter, coverDiameter);
// g2d.setColor(coverColor.darker());
// g2d.drawLine(position + coverDiameter / 5, position + coverDiameter /
// 5, position + 4
// * coverDiameter / 5, position + 4 * coverDiameter / 5);
// g2d.drawLine(position + coverDiameter / 5, position + 4 *
// coverDiameter / 5, position + 4
// * coverDiameter / 5, position + coverDiameter / 5);
}
@Override
protected Size getDefaultWidth() {
return null;
}
@Override
public Size getWidth() {
return super.getWidth();
}
@Override
protected Size getDefaultLength() {
// We'll reuse width property to set the diameter.
return DEFAULT_SIZE;
}
@EditableProperty(name = "Diameter")
@Override
public Size getLength() {
return super.getLength();
}
@EditableProperty(name = "Marker")
public Color getMarkerColor() {
return markerColor;
}
public void setMarkerColor(Color coverColor) {
this.markerColor = coverColor;
}
@EditableProperty(name = "Tick")
public Color getTickColor() {
return tickColor;
}
public void setTickColor(Color tickColor) {
this.tickColor = tickColor;
}
@EditableProperty(name = "Polarized")
public boolean getPolarized() {
return polarized;
}
public void setPolarized(boolean polarized) {
this.polarized = polarized;
}
@Override
protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getClosestOdd(getLength().convertToPixels()),
getClosestOdd(getLength().convertToPixels()));
}
}
@@ -0,0 +1,82 @@
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Film Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Radial film capacitor, similar to Sprague Orange Drop", zOrder = IDIYComponent.COMPONENT)
public class RadialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 4, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#FF8000");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
private Voltage voltage = Voltage._63V;
public RadialFilmCapacitor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
@EditableProperty
public Voltage getVoltage() {
return voltage;
}
public void setVoltage(Voltage voltage) {
this.voltage = voltage;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillRoundRect(4, height / 2 - 3, width - 8, 6, 5, 5);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(4, height / 2 - 3, width - 8, 6, 5, 5);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
double radius = getWidth().convertToPixels() * 0.7;
return new RoundRectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()), radius, radius);
}
}
@@ -0,0 +1,122 @@
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.ResistorColorCode;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Resistance;
import org.diylc.core.measures.ResistanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Resistor", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "R", description = "test", zOrder = IDIYComponent.COMPONENT)
public class Resistor extends AbstractLeadedComponent<Resistance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#82CFFD");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Resistance value = new Resistance(123d, ResistanceUnit.K);
private Power power = Power.HALF;
private ResistorColorCode colorCode = ResistorColorCode._5_BAND;
public Resistor() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@Override
protected boolean supportsStandingMode() {
return true;
}
@EditableProperty(validatorClass = PositiveMeasureValidator.class)
public Resistance getValue() {
return value;
}
public void setValue(Resistance value) {
this.value = value;
}
@EditableProperty
public Power getPower() {
return power;
}
public void setPower(Power power) {
this.power = power;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
g2d.setColor(Color.red);
g2d.drawLine(7, height / 2 - 3, 7, height / 2 + 3);
g2d.setColor(Color.orange);
g2d.drawLine(11, height / 2 - 3, 11, height / 2 + 3);
g2d.setColor(Color.black);
g2d.drawLine(15, height / 2 - 3, 15, height / 2 + 3);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@EditableProperty(name = "Color code")
public ResistorColorCode getColorCode() {
return colorCode;
}
public void setColorCode(ResistorColorCode colorCode) {
this.colorCode = colorCode;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
// int width = getWidth().convertToPixels();
if (colorCode == ResistorColorCode.NONE || outlineMode) {
return;
}
int height = getClosestOdd(getWidth().convertToPixels());
Color[] bands = value.getColorCode(colorCode);
int x = 4;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
for (int i = 0; i < bands.length; i++) {
g2d.setColor(bands[i]);
g2d.drawLine(x, 1, x, height - 1);
x += 5;
}
}
}
@@ -0,0 +1,84 @@
package org.diylc.components.passive;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import org.diylc.components.AbstractSchematicLeadedSymbol;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Resistance;
import org.diylc.core.measures.ResistanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Resistor (schematic symbol)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "R", description = "", zOrder = IDIYComponent.COMPONENT)
public class ResistorSymbol extends AbstractSchematicLeadedSymbol<Resistance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_LENGTH = new Size(0.3, SizeUnit.in);
public static Size DEFAULT_WIDTH = new Size(0.08, SizeUnit.in);
private Resistance value = new Resistance(100d, ResistanceUnit.K);
private Power power = Power.HALF;
@EditableProperty
public Resistance getValue() {
return value;
}
public void setValue(Resistance value) {
this.value = value;
}
@EditableProperty
public Power getPower() {
return power;
}
public void setPower(Power power) {
this.power = power;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, 4, height / 2);
g2d.drawLine(width - 4, height / 2, width, height / 2);
g2d.setColor(COLOR);
g2d.drawPolyline(new int[] { 4, 6, 10, 14, 18, 22, 26, 28 }, new int[] { height / 2,
height / 2 + 2, height / 2 - 2, height / 2 + 2, height / 2 - 2, height / 2 + 2,
height / 2 - 2, height / 2 }, 8);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_LENGTH;
}
@Override
protected Shape getBodyShape() {
GeneralPath polyline = new GeneralPath();
double length = getLength().convertToPixels();
double width = getWidth().convertToPixels();
polyline.moveTo(0, width / 2);
polyline.lineTo(length / 16, width);
polyline.lineTo(3 * length / 16, 0);
polyline.lineTo(5 * length / 16, width);
polyline.lineTo(7 * length / 16, 0);
polyline.lineTo(9 * length / 16, width);
polyline.lineTo(11 * length / 16, 0);
polyline.lineTo(13 * length / 16, width);
polyline.lineTo(15 * length / 16, 0);
polyline.lineTo(length, width / 2);
return polyline;
}
}
@@ -0,0 +1,28 @@
package org.diylc.components.passive;
import org.diylc.core.measures.Resistance;
public class ResistorValue {
private Resistance resistance;
private Power power;
public ResistorValue(Resistance resistance, Power power) {
super();
this.resistance = resistance;
this.power = power;
}
public Resistance getResistance() {
return resistance;
}
public Power getPower() {
return power;
}
@Override
public String toString() {
return resistance.toString() + power.toString();
}
}
@@ -0,0 +1,12 @@
package org.diylc.components.passive;
public enum Taper {
LIN, LOG, REV_LOG, W, S;
@Override
public String toString() {
return name().substring(0, 1).toUpperCase()
+ name().substring(1).toLowerCase().replace("_", " ");
}
}
@@ -0,0 +1,375 @@
package org.diylc.components.passive;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT, stretchable = false)
public class TrimmerPotentiometer extends AbstractPotentiometer {
private static final long serialVersionUID = 1L;
protected static Size FLAT_BODY_SIZE = new Size(9.5d, SizeUnit.mm);
protected static Size FLAT_SHAFT_SIZE = new Size(4d, SizeUnit.mm);
protected static Size VERTICAL_BODY_LENGTH = new Size(9.5d, SizeUnit.mm);
protected static Size VERTICAL_BODY_WIDTH = new Size(4.5d, SizeUnit.mm);
protected static Size SPACING = new Size(0.1d, SizeUnit.in);
private static Color BODY_COLOR = Color.decode("#FFFFE0");
private static Color BORDER_COLOR = Color.decode("#8E8E38");
private static Color SHAFT_COLOR = Color.decode("#FFFFE0");
private static Color SHAFT_BORDER_COLOR = Color.decode("#8E8E38");
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in);
protected Color bodyColor = BODY_COLOR;
protected Color borderColor = BORDER_COLOR;
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
transient protected Shape[] body = null;
protected TrimmerType type = TrimmerType.FLAT_SMALL;
public TrimmerPotentiometer() {
controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0) };
updateControlPoints();
}
protected void updateControlPoints() {
int spacing = (int) SPACING.convertToPixels();
int dx1 = 0;
int dy1 = 0;
int dx2 = 0;
int dy2 = 0;
switch (orientation) {
case DEFAULT:
switch (type) {
case FLAT_SMALL:
dx1 = 2 * spacing;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
case FLAT_LARGE:
dx1 = 4 * spacing;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
case VERTICAL_INLINE:
dx1 = 0;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
case VERTICAL_OFFSET:
dx1 = spacing;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
}
break;
case _90:
switch (type) {
case FLAT_SMALL:
dx1 = -spacing;
dy1 = 2 * spacing;
dx2 = -2 * spacing;
dy2 = 0;
break;
case FLAT_LARGE:
dx1 = -spacing;
dy1 = 4 * spacing;
dx2 = -2 * spacing;
dy2 = 0;
break;
case VERTICAL_INLINE:
dx1 = -spacing;
dy1 = 0;
dx2 = -2 * spacing;
dy2 = 0;
break;
case VERTICAL_OFFSET:
dx1 = -spacing;
dy1 = spacing;
dx2 = -2 * spacing;
dy2 = 0;
break;
}
break;
case _180:
switch (type) {
case FLAT_SMALL:
dx1 = -2 * spacing;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
case FLAT_LARGE:
dx1 = -4 * spacing;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
case VERTICAL_INLINE:
dx1 = 0;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
case VERTICAL_OFFSET:
dx1 = -spacing;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
}
break;
case _270:
switch (type) {
case FLAT_SMALL:
dx1 = spacing;
dy1 = -2 * spacing;
dx2 = 2 * spacing;
dy2 = 0;
break;
case FLAT_LARGE:
dx1 = spacing;
dy1 = -4 * spacing;
dx2 = 2 * spacing;
dy2 = 0;
break;
case VERTICAL_INLINE:
dx1 = spacing;
dy1 = 0;
dx2 = 2 * spacing;
dy2 = 0;
break;
case VERTICAL_OFFSET:
dx1 = spacing;
dy1 = -spacing;
dx2 = 2 * spacing;
dy2 = 0;
break;
}
break;
default:
break;
}
controlPoints[1].setLocation(controlPoints[0].x + dx1, controlPoints[0].y + dy1);
controlPoints[2].setLocation(controlPoints[0].x + dx2, controlPoints[0].y + dy2);
}
public Shape[] getBody() {
if (body == null) {
body = new Shape[2];
// Calculate the center point as center of the minimum bounding
// rectangle.
int centerX = (Math.max(Math.max(controlPoints[0].x, controlPoints[1].x),
controlPoints[2].x) + Math.min(
Math.min(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x)) / 2;
int centerY = (Math.max(Math.max(controlPoints[0].y, controlPoints[1].y),
controlPoints[2].y) + Math.min(
Math.min(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y)) / 2;
// Calculate body dimensions based on the selected type.
int length = 0;
int width = 0;
switch (type) {
case FLAT_LARGE:
case FLAT_SMALL:
length = getClosestOdd(FLAT_BODY_SIZE.convertToPixels());
width = length;
int shaftSize = getClosestOdd(FLAT_SHAFT_SIZE.convertToPixels());
Area shaft = new Area(new Ellipse2D.Double(centerX - shaftSize / 2, centerY
- shaftSize / 2, shaftSize, shaftSize));
Area slot = new Area(new Rectangle2D.Double(centerX - shaftSize / 2, centerY
- shaftSize / 8, shaftSize, shaftSize / 4));
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, centerX, centerY));
shaft.subtract(slot);
body[1] = shaft;
break;
case VERTICAL_INLINE:
case VERTICAL_OFFSET:
length = getClosestOdd(VERTICAL_BODY_LENGTH.convertToPixels());
width = getClosestOdd(VERTICAL_BODY_WIDTH.convertToPixels());
break;
}
if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
int p = length;
length = width;
width = p;
}
body[0] = new Rectangle2D.Double(centerX - length / 2, centerY - width / 2, length,
width);
}
return body;
}
@Override
public void setControlPoint(Point point, int index) {
super.setControlPoint(point, index);
body = null;
}
@Override
public void setOrientation(Orientation orientation) {
super.setOrientation(orientation);
updateControlPoints();
body = null;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Shape mainShape = getBody()[0];
Shape shaftShape = getBody()[1];
if (mainShape != null) {
g2d.setColor(bodyColor);
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.fill(mainShape);
if (shaftShape != null) {
g2d.setColor(SHAFT_COLOR);
g2d.fill(shaftShape);
g2d.setColor(SHAFT_BORDER_COLOR);
g2d.draw(shaftShape);
}
g2d.setComposite(oldComposite);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.draw(mainShape);
}
// Draw pins.
int pinSize = getClosestOdd(PIN_SIZE.convertToPixels());
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
// Draw label.
g2d.setFont(LABEL_FONT);
g2d
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D bodyRect = getBody()[0].getBounds2D();
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) rect.getHeight();
int textWidth = (int) rect.getWidth();
int panelHeight = (int) bodyRect.getHeight();
int panelWidth = (int) bodyRect.getWidth();
int x = (panelWidth - textWidth) / 2;
int y = (panelHeight - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(getName(), (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 4;
g2d.setColor(BODY_COLOR);
g2d.fillRect(margin, margin, width - 2 * margin, width - 2 * margin);
g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.drawRect(margin, margin, width - 2 * margin, width - 2 * margin);
int shaftSize = 11;
int slotSize = 2;
Area area = new Area(new Ellipse2D.Double(width / 2 - shaftSize / 2, width / 2 - shaftSize
/ 2, shaftSize, shaftSize));
Area slot = new Area(new Rectangle2D.Double(0, width / 2 - slotSize / 2, width, slotSize));
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, width / 2, width / 2));
area.subtract(slot);
g2d.setColor(SHAFT_COLOR);
g2d.fill(area);
g2d.setColor(SHAFT_BORDER_COLOR);
g2d.draw(area);
int pinSize = 3;
g2d.setColor(PIN_COLOR);
g2d.fillOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_COLOR);
g2d.fillOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_COLOR);
g2d.fillOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
}
@EditableProperty(name = "Body")
public Color getBodyColor() {
return bodyColor;
}
public void setBodyColor(Color bodyColor) {
this.bodyColor = bodyColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
@EditableProperty
public TrimmerType getType() {
return type;
}
public void setType(TrimmerType type) {
this.type = type;
updateControlPoints();
body = null;
}
public static enum TrimmerType {
FLAT_LARGE, FLAT_SMALL, VERTICAL_INLINE, VERTICAL_OFFSET;
@Override
public String toString() {
return name().substring(0, 1) + name().substring(1).toLowerCase().replace("_", " ");
}
}
}
@@ -0,0 +1,11 @@
package org.diylc.components.passive;
public enum Voltage {
_16V, _25V, _63V, _100V, _160V, _250V, _300V, _350V, _400V, _500V, _630V, _1KV;
@Override
public String toString() {
return name().replace("_", "");
}
}
@@ -0,0 +1,358 @@
package org.diylc.components.semiconductors;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "DIL IC", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "IC", description = "IC with rectangular housing and two parallel rows of pins", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class DIL_IC extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.gray;
public static Color BORDER_COLOR = Color.gray.darker();
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Color INDENT_COLOR = Color.gray.darker();
public static Color LABEL_COLOR = Color.white;
public static int EDGE_RADIUS = 6;
public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in);
public static Size INDENT_SIZE = new Size(0.07d, SizeUnit.in);
private String value = "";
private Orientation orientation = Orientation.DEFAULT;
private PinCount pinCount = PinCount._8;
private Size pinSpacing = new Size(0.1d, SizeUnit.in);
private Size rowSpacing = new Size(0.3d, SizeUnit.in);
private Point[] controlPoints = new Point[] { new Point(0, 0) };
// new Point(0, pinSpacing.convertToPixels()),
// new Point(0, 2 * pinSpacing.convertToPixels()),
// new Point(0, 3 * pinSpacing.convertToPixels()),
// new Point(3 * pinSpacing.convertToPixels(), 0),
// new Point(3 * pinSpacing.convertToPixels(),
// pinSpacing.convertToPixels()),
// new Point(3 * pinSpacing.convertToPixels(), 2 *
// pinSpacing.convertToPixels()),
// new Point(3 * pinSpacing.convertToPixels(), 3 *
// pinSpacing.convertToPixels()) };
transient private Area[] body;
public DIL_IC() {
super();
updateControlPoints();
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
// Reset body shape.
body = null;
}
@EditableProperty(name = "Pins")
public PinCount getPinCount() {
return pinCount;
}
public void setPinCount(PinCount pinCount) {
this.pinCount = pinCount;
updateControlPoints();
// Reset body shape;
body = null;
}
@EditableProperty(name = "Pin spacing")
public Size getPinSpacing() {
return pinSpacing;
}
public void setPinSpacing(Size pinSpacing) {
this.pinSpacing = pinSpacing;
}
@EditableProperty(name = "Row spacing")
public Size getRowSpacing() {
return rowSpacing;
}
public void setRowSpacing(Size rowSpacing) {
this.rowSpacing = rowSpacing;
updateControlPoints();
// Reset body shape;
body = null;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
body = null;
}
private void updateControlPoints() {
Point firstPoint = controlPoints[0];
controlPoints = new Point[pinCount.getValue()];
controlPoints[0] = firstPoint;
int pinSpacing = (int) this.pinSpacing.convertToPixels();
int rowSpacing = (int) this.rowSpacing.convertToPixels();
// Update control points.
int dx1;
int dy1;
int dx2;
int dy2;
for (int i = 0; i < pinCount.getValue() / 2; i++) {
switch (orientation) {
case DEFAULT:
dx1 = 0;
dy1 = i * pinSpacing;
dx2 = rowSpacing;
dy2 = i * pinSpacing;
break;
case _90:
dx1 = -i * pinSpacing;
dy1 = 0;
dx2 = -i * pinSpacing;
dy2 = rowSpacing;
break;
case _180:
dx1 = 0;
dy1 = -i * pinSpacing;
dx2 = -rowSpacing;
dy2 = -i * pinSpacing;
break;
case _270:
dx1 = i * pinSpacing;
dy1 = 0;
dx2 = i * pinSpacing;
dy2 = -rowSpacing;
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1);
controlPoints[i + pinCount.getValue() / 2] = new Point(firstPoint.x + dx2, firstPoint.y
+ dy2);
}
}
public Area[] getBody() {
if (body == null) {
body = new Area[2];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int width;
int height;
int pinSize = (int) PIN_SIZE.convertToPixels();
int pinSpacing = (int) this.pinSpacing.convertToPixels();
int rowSpacing = (int) this.rowSpacing.convertToPixels();
Area indentation = null;
int indentationSize = getClosestOdd(INDENT_SIZE.convertToPixels());
switch (orientation) {
case DEFAULT:
width = rowSpacing - pinSize;
height = (pinCount.getValue() / 2) * pinSpacing;
x += pinSize / 2;
y -= pinSpacing / 2;
indentation = new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y
- indentationSize / 2, indentationSize, indentationSize));
break;
case _90:
width = (pinCount.getValue() / 2) * pinSpacing;
height = rowSpacing - pinSize;
x -= (pinSpacing / 2) + width - pinSpacing;
y += pinSize / 2;
indentation = new Area(new Ellipse2D.Double(x + width - indentationSize / 2, y
+ height / 2 - indentationSize / 2, indentationSize, indentationSize));
break;
case _180:
width = rowSpacing - pinSize;
height = (pinCount.getValue() / 2) * pinSpacing;
x -= rowSpacing - pinSize / 2;
y -= (pinSpacing / 2) + height - pinSpacing;
indentation = new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y
+ height - indentationSize / 2, indentationSize, indentationSize));
break;
case _270:
width = (pinCount.getValue() / 2) * pinSpacing;
height = rowSpacing - pinSize;
x -= pinSpacing / 2;
y += pinSize / 2 - rowSpacing;
indentation = new Area(new Ellipse2D.Double(x - indentationSize / 2, y + height / 2
- indentationSize / 2, indentationSize, indentationSize));
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
body[0] = new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS,
EDGE_RADIUS));
body[1] = indentation;
if (indentation != null) {
indentation.intersect(body[0]);
}
}
return body;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
Area mainArea = getBody()[0];
if (!outlineMode) {
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(mainArea);
g2d.setComposite(oldComposite);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR;
}
g2d.setColor(finalBorderColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (outlineMode) {
Area area = new Area(mainArea);
area.subtract(getBody()[1]);
g2d.draw(area);
} else {
g2d.draw(mainArea);
if (getBody()[1] != null) {
g2d.setColor(INDENT_COLOR);
g2d.fill(getBody()[1]);
}
}
// Draw label.
g2d.setFont(LABEL_FONT);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(getName(), x, y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int radius = 6 * width / 32;
g2d.setColor(BODY_COLOR);
g2d.fillRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
int pinSize = 2 * width / 32;
g2d.setColor(PIN_COLOR);
for (int i = 0; i < 4; i++) {
g2d.fillRect(width / 6 - pinSize, (height / 5) * (i + 1) - 1, pinSize, pinSize);
g2d.fillRect(5 * width / 6 + 1, (height / 5) * (i + 1) - 1, pinSize, pinSize);
}
}
public static enum PinCount {
_4, _6, _8, _10, _12, _14, _16, _18, _20, _22, _24, _26, _28, _30, _32;
@Override
public String toString() {
return name().replace("_", "");
}
public int getValue() {
return Integer.parseInt(toString());
}
}
}
@@ -0,0 +1,112 @@
package org.diylc.components.semiconductors;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Diode (plastic)", author = "Branislav Stojkovic", category = "Semiconductors", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "D", description = "Plastic diode, like most rectifier, zener, schottky, etc.", zOrder = IDIYComponent.COMPONENT)
public class DiodePlastic extends AbstractLeadedComponent<String> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 4, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Size MARKER_WIDTH = new Size(1d, SizeUnit.mm);
public static Color BODY_COLOR = Color.darkGray;
public static Color MARKER_COLOR = Color.decode("#DDDDDD");
public static Color LABEL_COLOR = Color.white;
public static Color BORDER_COLOR = BODY_COLOR.darker();
private String value = "";
private Color markerColor = MARKER_COLOR;
public DiodePlastic() {
super();
this.labelColor = LABEL_COLOR;
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@Override
protected boolean supportsStandingMode() {
return true;
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
g2d.setColor(BODY_COLOR);
g2d.fillRect(6, height / 2 - 3, width - 12, 6);
g2d.setColor(MARKER_COLOR);
int markerWidth = 4 * width / 32;
g2d.fillRect(width - 6 - markerWidth, height / 2 - 3, markerWidth, 6);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(6, height / 2 - 3, width - 12, 6);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
Color finalMarkerColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalMarkerColor = theme.getOutlineColor();
} else {
finalMarkerColor = markerColor;
}
g2d.setColor(finalMarkerColor);
int width = (int) getLength().convertToPixels();
int markerWidth = (int) MARKER_WIDTH.convertToPixels();
g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getWidth()
.convertToPixels()));
}
@EditableProperty(name = "Marker")
public Color getMarkerColor() {
return markerColor;
}
public void setMarkerColor(Color markerColor) {
this.markerColor = markerColor;
}
}
@@ -0,0 +1,107 @@
package org.diylc.components.semiconductors;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "LED", author = "Branislav Stojkovic", category = "Semiconductors", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "D", description = "Light Emitting Diode", zOrder = IDIYComponent.COMPONENT)
public class LED extends AbstractLeadedComponent<String> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_SIZE = new Size(5d, SizeUnit.mm);
public static Color BODY_COLOR = Color.decode("#5DFC0A");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private String value = "";
public LED() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
int margin = 4 * width / 32;
Area area = new Area(new Ellipse2D.Double(margin, margin, width - 2 * margin, width - 2
* margin));
area.intersect(new Area(new Rectangle2D.Double(margin, margin, width - 5 * margin / 2,
width - 2 * margin)));
g2d.setColor(BODY_COLOR);
g2d.fill(area);
g2d.setColor(BORDER_COLOR);
g2d.draw(area);
g2d
.drawOval(margin * 2 - 1, margin * 2 - 1, width - 4 * margin + 2, width - 4
* margin + 2);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_SIZE;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_SIZE;
}
@Override
protected Shape getBodyShape() {
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
Area area = new Area(new Ellipse2D.Double(0, 0, size, size));
area.intersect(new Area(new Rectangle2D.Double(0, 0, getLength().convertToPixels() * 1.15,
size)));
return area;
}
@Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (!outlineMode) {
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
int innerSize = getClosestOdd(getLength().convertToPixels());
int x = (size - innerSize) / 2;
Shape s = new Ellipse2D.Double(x, x, innerSize, innerSize);
g2d.setColor(getBorderColor());
g2d.draw(s);
}
}
@EditableProperty(name = "Size")
@Override
public Size getLength() {
return super.getLength();
}
@Override
public Size getWidth() {
return super.getWidth();
}
}
@@ -0,0 +1,308 @@
package org.diylc.components.semiconductors;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Transistor (TO-220 package)", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class TransistorTO220 extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.gray;
public static Color BORDER_COLOR = Color.gray.darker();
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Color TAB_COLOR = Color.decode("#C3E4ED");
public static Color TAB_BORDER_COLOR = TAB_COLOR.darker();
public static Color LABEL_COLOR = Color.white;
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in);
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
public static Size BODY_WIDTH = new Size(0.4d, SizeUnit.in);
public static Size BODY_HEIGHT = new Size(4.5d, SizeUnit.mm);
public static Size TAB_THICKNESS = new Size(1d, SizeUnit.mm);
private String value = "";
private Orientation orientation = Orientation.DEFAULT;
private Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0) };
transient private Shape[] body;
private Color bodyColor = BODY_COLOR;
private Color borderColor = BORDER_COLOR;
private Color tabColor = TAB_COLOR;
private Color tabBorderColor = TAB_BORDER_COLOR;
public TransistorTO220() {
super();
updateControlPoints();
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
// Reset body shape;
body = null;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
body = null;
}
private void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points.
int x = controlPoints[0].x;
int y = controlPoints[0].y;
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(x, y + pinSpacing);
controlPoints[2].setLocation(x, y + 2 * pinSpacing);
break;
case _90:
controlPoints[1].setLocation(x - pinSpacing, y);
controlPoints[2].setLocation(x - 2 * pinSpacing, y);
break;
case _180:
controlPoints[1].setLocation(x, y - pinSpacing);
controlPoints[2].setLocation(x, y - 2 * pinSpacing);
break;
case _270:
controlPoints[1].setLocation(x + pinSpacing, y);
controlPoints[2].setLocation(x + 2 * pinSpacing, y);
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
}
public Shape[] getBody() {
if (body == null) {
body = new Shape[2];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels();
int bodyWidth = getClosestOdd(BODY_WIDTH.convertToPixels());
int bodyHeight = getClosestOdd(BODY_HEIGHT.convertToPixels());
int tabThickness = (int) TAB_THICKNESS.convertToPixels();
switch (orientation) {
case DEFAULT:
body[0] = new Rectangle2D.Double(x - bodyHeight / 2,
y + pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
body[1] = new Rectangle2D.Double(x + bodyHeight / 2 - tabThickness, y + pinSpacing
- bodyWidth / 2, tabThickness, bodyWidth);
break;
case _90:
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2,
y - bodyHeight / 2, bodyWidth, bodyHeight);
body[1] = new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + bodyHeight / 2
- tabThickness, bodyWidth, tabThickness);
break;
case _180:
body[0] = new Rectangle2D.Double(x - bodyHeight / 2,
y - pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
body[1] = new Rectangle2D.Double(x - bodyHeight / 2,
y - pinSpacing - bodyWidth / 2, tabThickness, bodyWidth);
break;
case _270:
body[0] = new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2,
y - bodyHeight / 2, bodyWidth, bodyHeight);
body[1] = new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2,
y - bodyHeight / 2, bodyWidth, tabThickness);
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
}
return body;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Shape mainArea = getBody()[0];
Shape tabArea = getBody()[1];
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
Color finalTabColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalTabColor = theme.getOutlineColor();
} else {
finalTabColor = tabColor;
}
g2d.setColor(finalTabColor);
g2d.fill(tabArea);
g2d.setComposite(oldComposite);
if (!outlineMode) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(tabBorderColor);
g2d.draw(tabArea);
}
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
}
g2d.setColor(finalBorderColor);
g2d.draw(mainArea);
// Draw pins.
if (!outlineMode) {
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
// Draw label.
g2d.setFont(LABEL_FONT);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(getName(), x, y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BODY_COLOR);
int margin = 2 * width / 32;
int thickness = 7 * width / 32;
g2d.fillRect(margin, (height - thickness) / 2, width - margin * 2, thickness);
g2d.setColor(TAB_COLOR);
g2d.fillRect(margin, (height + thickness) / 2 - margin - 1, width - margin * 2, margin);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(margin, (height - thickness) / 2, width - margin * 2, thickness);
}
@EditableProperty(name = "Body")
public Color getBodyColor() {
return bodyColor;
}
public void setBodyColor(Color bodyColor) {
this.bodyColor = bodyColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
@EditableProperty(name = "Tab")
public Color getTabColor() {
return tabColor;
}
public void setTabColor(Color tabColor) {
this.tabColor = tabColor;
}
@EditableProperty(name = "Tab border")
public Color getTabBorderColor() {
return tabBorderColor;
}
public void setTabBorderColor(Color tabBorderColor) {
this.tabBorderColor = tabBorderColor;
}
}
@@ -0,0 +1,268 @@
package org.diylc.components.semiconductors;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Transistor (TO-92 package)", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class TransistorTO92 extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.gray;
public static Color BORDER_COLOR = Color.gray.darker();
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Color LABEL_COLOR = Color.white;
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in);
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
public static Size BODY_DIAMETER = new Size(0.2d, SizeUnit.in);
private String value = "";
private Orientation orientation = Orientation.DEFAULT;
private Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0) };
transient private Area body;
private Color bodyColor = BODY_COLOR;
private Color borderColor = BORDER_COLOR;
public TransistorTO92() {
super();
updateControlPoints();
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
// Reset body shape;
body = null;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
body = null;
}
private void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points.
int x = controlPoints[0].x;
int y = controlPoints[0].y;
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(x, y + pinSpacing);
controlPoints[2].setLocation(x, y + 2 * pinSpacing);
break;
case _90:
controlPoints[1].setLocation(x - pinSpacing, y);
controlPoints[2].setLocation(x - 2 * pinSpacing, y);
break;
case _180:
controlPoints[1].setLocation(x, y - pinSpacing);
controlPoints[2].setLocation(x, y - 2 * pinSpacing);
break;
case _270:
controlPoints[1].setLocation(x + pinSpacing, y);
controlPoints[2].setLocation(x + 2 * pinSpacing, y);
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
}
public Area getBody() {
if (body == null) {
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels();
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
switch (orientation) {
case DEFAULT:
body = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y + pinSpacing
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter, y + pinSpacing
- bodyDiameter / 2, 3 * bodyDiameter / 4, bodyDiameter)));
break;
case _90:
body = new Area(new Ellipse2D.Double(x - pinSpacing - bodyDiameter / 2, y
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
body.subtract(new Area(new Rectangle2D.Double(x - pinSpacing - bodyDiameter / 2, y
- bodyDiameter, bodyDiameter, 3 * bodyDiameter / 4)));
break;
case _180:
body = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - pinSpacing
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
body.subtract(new Area(new Rectangle2D.Double(x + bodyDiameter / 4, y - pinSpacing
- bodyDiameter / 2, 3 * bodyDiameter / 4, bodyDiameter)));
break;
case _270:
body = new Area(new Ellipse2D.Double(x + pinSpacing - bodyDiameter / 2, y
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
body.subtract(new Area(new Rectangle2D.Double(x + pinSpacing - bodyDiameter / 2, y
+ bodyDiameter / 4, bodyDiameter, 3 * bodyDiameter / 4)));
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
}
return body;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Area mainArea = getBody();
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
g2d.setComposite(oldComposite);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
}
g2d.setColor(finalBorderColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.draw(mainArea);
if (!outlineMode) {
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
// Draw label.
g2d.setFont(LABEL_FONT);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(getName(), x, y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 3 * width / 32;
Area area = new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2
* margin));
// area.subtract(new Area(new Rectangle2D.Double(0, 0, 2 * margin,
// height)));
area.intersect(new Area(new Rectangle2D.Double(2 * margin, 0, width, height)));
g2d.setColor(BODY_COLOR);
g2d.fill(area);
g2d.setColor(BORDER_COLOR);
g2d.draw(area);
}
@EditableProperty(name = "Body")
public Color getBodyColor() {
return bodyColor;
}
public void setBodyColor(Color bodyColor) {
this.bodyColor = bodyColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
}
@@ -0,0 +1,328 @@
package org.diylc.components.tube;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Tube Socket", author = "Branislav Stojkovic", category = "Tubes", instanceNamePrefix = "V", description = "Various types of tube/valve sockets", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class TubeSocket extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
private static Color BODY_COLOR = Color.decode("#FFFFE0");
private static Color BORDER_COLOR = Color.decode("#8E8E38");
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Size PIN_SIZE = new Size(1d, SizeUnit.mm);
public static Size HOLE_SIZE = new Size(5d, SizeUnit.mm);
public static Size TICK_SIZE = new Size(2d, SizeUnit.mm);
private Base base = Base.B9A;
private String type = "";
private Orientation orientation = Orientation.DEFAULT;
// private Mount mount = Mount.CHASSIS;
private Point[] controlPoints = new Point[] { new Point(0, 0) };
transient private Shape body;
public TubeSocket() {
super();
updateControlPoints();
}
@EditableProperty
public Base getBase() {
return base;
}
public void setBase(Base base) {
this.base = base;
updateControlPoints();
// Reset body shape
body = null;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
// Reset body shape
body = null;
}
// @EditableProperty
// public Mount getMount() {
// return mount;
// }
//
// public void setMount(Mount mount) {
// this.mount = mount;
// }
private void updateControlPoints() {
Point firstPoint = controlPoints[0];
int pinCount;
int pinCircleDiameter;
boolean hasEmptySpace;
switch (base) {
case B7G:
pinCount = 7;
pinCircleDiameter = getClosestOdd(new Size(12d, SizeUnit.mm).convertToPixels());
hasEmptySpace = true;
break;
case OCTAL:
pinCount = 8;
pinCircleDiameter = getClosestOdd(new Size(17.5d, SizeUnit.mm).convertToPixels());
hasEmptySpace = false;
break;
case B9A:
pinCount = 9;
pinCircleDiameter = getClosestOdd(new Size(21d, SizeUnit.mm).convertToPixels());
hasEmptySpace = true;
break;
default:
throw new RuntimeException("Unexpected base: " + base);
}
double angleIncrement = Math.PI * 2 / (hasEmptySpace ? (pinCount + 1) : pinCount);
double initialAngleOffset = hasEmptySpace ? angleIncrement : (angleIncrement / 2);
double initialAngle;
switch (orientation) {
case DEFAULT:
initialAngle = Math.PI / 2 + initialAngleOffset;
break;
case _90:
initialAngle = Math.PI + initialAngleOffset;
break;
case _180:
initialAngle = 3 * Math.PI / 2 + initialAngleOffset;
break;
case _270:
initialAngle = initialAngleOffset;
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
controlPoints = new Point[pinCount + 1];
double angle = initialAngle;
controlPoints[0] = firstPoint;
for (int i = 0; i < pinCount; i++) {
controlPoints[i + 1] = new Point((int) (firstPoint.getX() + Math.cos(angle)
* pinCircleDiameter / 2), (int) (firstPoint.getY() + Math.sin(angle)
* pinCircleDiameter / 2));
angle += angleIncrement;
}
}
public Shape getBody() {
if (body == null) {
int bodyDiameter;
switch (base) {
case B7G:
bodyDiameter = getClosestOdd(new Size(17d, SizeUnit.mm).convertToPixels());
break;
case B9A:
bodyDiameter = getClosestOdd(new Size(19d, SizeUnit.mm).convertToPixels());
break;
case OCTAL:
bodyDiameter = getClosestOdd(new Size(24.5d, SizeUnit.mm).convertToPixels());
break;
default:
throw new RuntimeException("Unexpected base: " + base);
}
body = new Ellipse2D.Double(controlPoints[0].x - bodyDiameter / 2, controlPoints[0].y
- bodyDiameter / 2, bodyDiameter, bodyDiameter);
Area bodyArea = new Area(body);
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
bodyArea.subtract(new Area(new Ellipse2D.Double(controlPoints[0].x - holeSize / 2,
controlPoints[0].y - holeSize / 2, holeSize, holeSize)));
if (base == Base.OCTAL) {
int tickSize = getClosestOdd(TICK_SIZE.convertToPixels());
double angle = 0;
switch (orientation) {
case DEFAULT:
angle = Math.PI / 2;
break;
case _90:
angle = Math.PI;
break;
case _180:
angle = 3 * Math.PI / 2;
break;
case _270:
angle = 0;
break;
}
int centerX = (int) (controlPoints[0].x + Math.cos(angle) * holeSize / 2);
int centerY = (int) (controlPoints[0].y + Math.sin(angle) * holeSize / 2);
bodyArea.subtract(new Area(new Ellipse2D.Double(centerX - tickSize / 2, centerY
- tickSize / 2, tickSize, tickSize)));
}
body = bodyArea;
}
return body;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
// g2d.setColor(Color.black);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
// for (int i = 0; i < controlPoints.length; i++) {
// g2d.drawString(Integer.toString(i), controlPoints[i].x,
// controlPoints[i].y);
// }
// Draw body
Shape body = getBody();
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
if (componentState != ComponentState.DRAGGING) {
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(body);
}
g2d.setComposite(oldComposite);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR;
}
g2d.setColor(finalBorderColor);
g2d.draw(body);
// Draw pins
if (!outlineMode) {
int pinSize = getClosestOdd(PIN_SIZE.convertToPixels());
for (int i = 1; i < controlPoints.length; i++) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(controlPoints[i].x - pinSize / 2, controlPoints[i].y - pinSize / 2,
pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(controlPoints[i].x - pinSize / 2, controlPoints[i].y - pinSize / 2,
pinSize, pinSize);
}
}
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
Area area = new Area(new Ellipse2D.Double(1, 1, width - 2, width - 2));
int center = width / 2;
area.subtract(new Area(new Ellipse2D.Double(center - 2, center - 2, 5, 5)));
g2d.setColor(BODY_COLOR);
g2d.fill(area);
g2d.setColor(BORDER_COLOR);
g2d.draw(area);
int radius = width / 2 - 6;
for (int i = 0; i < 8; i++) {
int x = (int) (center + Math.cos(i * Math.PI / 4) * radius);
int y = (int) (center + Math.sin(i * Math.PI / 4) * radius);
g2d.setColor(PIN_COLOR);
g2d.fillOval(x - 1, y - 1, 3, 3);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(x - 1, y - 1, 3, 3);
}
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
@EditableProperty(name = "Type")
public String getValue() {
return type;
}
@Override
public void setValue(String value) {
this.type = value;
}
@Override
public boolean isControlPointSticky(int index) {
return index > 0;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
body = null;
}
static enum Base {
B9A("Noval B9A"), OCTAL("Octal"), B7G("Small-button B7G");
String name;
private Base(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
static enum Mount {
CHASSIS("Chassis"), PCB("PCB");
String name;
private Mount(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
}
-1
View File
@@ -1 +0,0 @@
Test=XYZ
-42
View File
@@ -1,42 +0,0 @@
package org.diylc.gui;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.Icon;
import javax.swing.JComponent;
public class CustomGlassPane extends JComponent {
private static final long serialVersionUID = 1L;
private Icon icon;
public CustomGlassPane() {
super();
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
if (icon != null) {
repaint();
}
}
});
}
public void setCursorIcon(Icon icon) {
this.icon = icon;
}
@Override
public void paint(Graphics g) {
Point cursor = getMousePosition();
if ((icon != null) && (cursor != null)) {
Graphics2D g2d = (Graphics2D) g;
icon.paintIcon(this, g2d, cursor.x + 10, cursor.y + 10);
}
}
}
-154
View File
@@ -1,154 +0,0 @@
package org.diylc.gui;
import java.io.File;
import java.util.List;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;
import org.diylc.common.PropertyWrapper;
import org.diylc.gui.components.OverwritePromptFileChooser;
import org.diylc.gui.editor.PropertyEditorDialog;
import org.diylc.plugins.file.BomDialog;
import org.diylc.plugins.file.BomEntry;
import org.diylc.plugins.online.view.LoginDialog;
import org.diylc.plugins.online.view.NewUserDialog;
import org.diylc.plugins.online.view.UploadDialog;
import com.diyfever.gui.AboutDialog;
import com.diyfever.gui.IFileChooserAccessory;
import com.diyfever.gui.ProgressDialog;
import com.diyfever.gui.miscutils.ConfigurationManager;
public class DialogFactory {
private static DialogFactory instance;
private static final String PATH_KEY = "lastPath";
public static DialogFactory getInstance() {
if (instance == null) {
instance = new DialogFactory();
}
return instance;
}
private JFrame mainFrame;
private File lastDirectory;
private DialogFactory() {
}
/**
* Sets the frame to be used as dialog parent. This should be called prior
* to any other methods in this class.
*
* @param mainFrame
*/
public void initialize(JFrame mainFrame) {
this.mainFrame = mainFrame;
String lastDirectoryPath = (String) ConfigurationManager.getInstance()
.getConfigurationItem(PATH_KEY);
if (lastDirectoryPath != null) {
lastDirectory = new File(lastDirectoryPath);
}
}
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties) {
PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties);
return editor;
}
public BomDialog createBomDialog(List<BomEntry> bom) {
BomDialog dialog = new BomDialog(mainFrame, bom);
return dialog;
}
public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
IFileChooserAccessory accessory) {
JFileChooser openFileChooser = new JFileChooser();
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory);
int result = openFileChooser.showOpenDialog(mainFrame);
return processFileChooserResult(result, openFileChooser, defaultExtension);
}
public File showSaveDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
IFileChooserAccessory accessory) {
JFileChooser saveFileChooser = new OverwritePromptFileChooser();
initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory);
int result = saveFileChooser.showSaveDialog(mainFrame);
return processFileChooserResult(result, saveFileChooser, defaultExtension);
}
private void initializeFileChooser(JFileChooser fileChooser, FileFilter fileFilter,
File initialFile, String defaultExtension, IFileChooserAccessory accessory) {
if (accessory != null) {
accessory.install(fileChooser);
}
for (FileFilter filter : fileChooser.getChoosableFileFilters()) {
fileChooser.removeChoosableFileFilter(filter);
}
if (fileChooser instanceof OverwritePromptFileChooser) {
((OverwritePromptFileChooser) fileChooser).setFileFilter(fileFilter, defaultExtension);
} else {
fileChooser.setFileFilter(fileFilter);
}
if (lastDirectory != null) {
fileChooser.setCurrentDirectory(lastDirectory);
}
fileChooser.setSelectedFile(initialFile);
}
private File processFileChooserResult(int result, JFileChooser fileChooser,
String defaultExtension) {
fileChooser.setAccessory(null);
if (result == JFileChooser.APPROVE_OPTION) {
lastDirectory = fileChooser.getCurrentDirectory();
ConfigurationManager.getInstance().setConfigurationItem(PATH_KEY,
lastDirectory.getAbsolutePath());
if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) {
return fileChooser.getSelectedFile();
} else {
return new File(fileChooser.getSelectedFile().getAbsoluteFile() + "."
+ defaultExtension);
}
} else {
return null;
}
}
public AboutDialog createAboutDialog(String appName, Icon icon, String version, String author,
String url, String mail, String htmlContent) {
AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version, author, url, mail,
htmlContent);
return dialog;
}
public NewUserDialog createNewUserDialog() {
NewUserDialog dialog = new NewUserDialog(mainFrame);
return dialog;
}
public LoginDialog createLoginDialog() {
LoginDialog dialog = new LoginDialog(mainFrame);
return dialog;
}
public UploadDialog createUploadDialog() {
UploadDialog dialog = new UploadDialog(mainFrame);
return dialog;
}
public ProgressDialog createProgressDialog(String title, String[] buttonCaptions,
String description, boolean useProgress) {
ProgressDialog dialog = new ProgressDialog(mainFrame, title, buttonCaptions, description,
useProgress);
return dialog;
}
}
-44
View File
@@ -1,44 +0,0 @@
package org.diylc.gui;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JComponent;
import org.diylc.common.BadPositionException;
import org.diylc.common.IPlugInPort;
/**
* Base interface for the main GUI component.
*
* @author Branislav Stojkovic
*/
public interface IView {
/**
* Adds a component to the view.
*
* @param component
* component to insert
* @param position
* target position
* @throws BadPositionException
*
* @see IPlugInPort#injectGUIComponent
*/
void addComponent(JComponent component, int position) throws BadPositionException;
/**
* Adds a menu action.
*
* @param action
* action to insert
* @param menuName
* target menu name
*
* @see IPlugInPort#injectMenuAction
*/
void addMenuAction(Action action, String menuName);
void setCursorIcon(Icon icon);
}
-203
View File
@@ -1,203 +0,0 @@
package org.diylc.gui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.Action;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import org.diylc.common.BadPositionException;
import org.diylc.model.Project;
import org.diylc.plugins.canvas.CanvasPlugin;
import org.diylc.plugins.clipboard.ClipboardManager;
import org.diylc.plugins.file.FileManager;
import org.diylc.plugins.help.HelpManager;
import org.diylc.plugins.online.OnlineManager;
import org.diylc.plugins.statusbar.StatusBar;
import org.diylc.plugins.toolbox.ToolBox;
import org.diylc.presenter.Presenter;
public class MainFrame extends JFrame implements IView {
private static final long serialVersionUID = 1L;
private JPanel centerPanel;
private JPanel leftPanel;
private JPanel rightPanel;
private JPanel topPanel;
private JPanel bottomPanel;
private Presenter presenter;
private JMenuBar mainMenuBar;
private Map<String, JMenu> menuMap;
private CanvasPlugin canvasPlugin;
public MainFrame() {
super("DIYLC4");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(800, 600));
createBasePanels();
menuMap = new HashMap<String, JMenu>();
DialogFactory.getInstance().initialize(this);
this.presenter = new Presenter(this);
setTitle(getTitle() + " " + presenter.getCurrentVersionNumber());
presenter.installPlugin(new ToolBox());
presenter.installPlugin(new FileManager());
presenter.installPlugin(new ClipboardManager());
presenter.installPlugin(new OnlineManager());
presenter.installPlugin(new HelpManager());
presenter.installPlugin(new StatusBar());
canvasPlugin = new CanvasPlugin();
presenter.installPlugin(canvasPlugin);
Project project = new Project();
// project.getComponents().add(new MockComponentInstance());
presenter.loadProject(project, true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
presenter.dispose();
}
@Override
public void windowClosing(WindowEvent e) {
presenter.dispose();
}
});
// setGlassPane(new CustomGlassPane());
// getGlassPane().setVisible(true);
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
// TODO: hack to prevent painting issues in the scroll bar rulers. Find
// a better fix if possible.
Timer timer = new Timer(50, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
canvasPlugin.refresh();
}
});
timer.setRepeats(false);
timer.start();
// if (b) {
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
//
// }
// });
// }
}
private void createBasePanels() {
Container c = new Container();
c.setLayout(new BorderLayout());
centerPanel = new JPanel(new BorderLayout());
c.add(centerPanel, BorderLayout.CENTER);
topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
c.add(topPanel, BorderLayout.NORTH);
leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.X_AXIS));
c.add(leftPanel, BorderLayout.WEST);
bottomPanel = new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
c.add(bottomPanel, BorderLayout.SOUTH);
rightPanel = new JPanel();
rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.X_AXIS));
c.add(rightPanel, BorderLayout.EAST);
setContentPane(c);
}
private JMenuBar getMainMenuBar() {
if (mainMenuBar == null) {
mainMenuBar = new JMenuBar();
setJMenuBar(mainMenuBar);
}
return mainMenuBar;
}
// IView
@Override
public void addComponent(JComponent component, int position) throws BadPositionException {
switch (position) {
case SwingConstants.TOP:
topPanel.add(component);
break;
case SwingConstants.LEFT:
leftPanel.add(component);
break;
case SwingConstants.BOTTOM:
bottomPanel.add(component);
break;
case SwingConstants.RIGHT:
rightPanel.add(component);
break;
case SwingConstants.CENTER:
centerPanel.add(component, BorderLayout.CENTER);
break;
default:
throw new BadPositionException();
}
pack();
}
@Override
public void addMenuAction(Action action, String menuName) {
JMenu menu;
if (menuMap.containsKey(menuName)) {
menu = menuMap.get(menuName);
} else {
menu = new JMenu(menuName);
menuMap.put(menuName, menu);
getMainMenuBar().add(menu);
}
if (action == null) {
menu.addSeparator();
} else {
menu.add(action);
}
}
@Override
public void setCursorIcon(Icon icon) {
// TODO Auto-generated method stub
}
}
@@ -1,38 +0,0 @@
package org.diylc.gui.components;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
public class OverwritePromptFileChooser extends JFileChooser {
private static final long serialVersionUID = 1L;
private String defaultExtension;
public void approveSelection() {
File lSelectedFile;
if (getSelectedFile().getAbsolutePath().contains(".")) {
lSelectedFile = getSelectedFile();
} else {
lSelectedFile = new File(getSelectedFile().getAbsoluteFile() + "." + defaultExtension);
}
if (lSelectedFile != null && lSelectedFile.exists()) {
int lResponse = JOptionPane.showConfirmDialog(this, lSelectedFile.getAbsolutePath()
+ " already exists.\nDo you " + "want to replace it?", "Warning",
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (lResponse != JOptionPane.YES_OPTION) {
return;
}
}
super.approveSelection();
}
public void setFileFilter(FileFilter filter, String defaultExtension) {
this.defaultExtension = defaultExtension;
super.setFileFilter(filter);
}
}
-40
View File
@@ -1,40 +0,0 @@
package org.diylc.gui.editor;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import org.diylc.common.PropertyWrapper;
public class ColorEditor extends JLabel {
private static final long serialVersionUID = 1L;
public ColorEditor(final PropertyWrapper property) {
super("Click to edit");
setOpaque(true);
setHorizontalAlignment(SwingConstants.CENTER);
setBorder(BorderFactory.createEtchedBorder());
setBackground((Color) property.getValue());
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Color newColor = JColorChooser.showDialog(ColorEditor.this, "Choose Color",
getBackground());
if (newColor != null) {
property.setValue(newColor);
setBackground(newColor);
}
}
});
}
}
@@ -1,27 +0,0 @@
package org.diylc.gui.editor;
import java.awt.Color;
import java.awt.Component;
import org.diylc.common.PropertyWrapper;
import org.diylc.model.measures.AbstractMeasure;
public class FieldEditorFactory {
public static Component createFieldEditor(PropertyWrapper property) {
if (property.getType().equals(String.class)) {
StringEditor editor = new StringEditor(property);
return editor;
}
if (property.getType().equals(Color.class)) {
ColorEditor editor = new ColorEditor(property);
return editor;
}
if (AbstractMeasure.class.isAssignableFrom(property.getType())) {
MeasureEditor editor = new MeasureEditor(property);
return editor;
}
return null;
}
}
@@ -1,66 +0,0 @@
package org.diylc.gui.editor;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.swing.JComboBox;
import org.diylc.common.PropertyWrapper;
import org.diylc.model.measures.AbstractMeasure;
import com.diyfever.gui.DoubleTextField;
public class MeasureEditor extends Container {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
public MeasureEditor(final PropertyWrapper property) {
setLayout(new BorderLayout());
final AbstractMeasure measure = ((AbstractMeasure) property.getValue());
DoubleTextField valueField = new DoubleTextField(measure.getValue());
valueField.addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY,
new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
measure.setValue((Double) evt.getNewValue());
}
});
add(valueField, BorderLayout.CENTER);
try {
Method method = measure.getUnit().getClass().getMethod("values");
final JComboBox unitBox = new JComboBox((Object[]) method.invoke(measure.getUnit()));
unitBox.setSelectedItem(measure.getUnit());
unitBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
measure.setUnit((Enum) unitBox.getSelectedItem());
}
});
add(unitBox, BorderLayout.EAST);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@@ -1,136 +0,0 @@
package org.diylc.gui.editor;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.diylc.common.PropertyWrapper;
import com.diyfever.gui.ButtonDialog;
public class PropertyEditorDialog extends ButtonDialog {
private static final Logger LOG = Logger.getLogger(PropertyEditorDialog.class);
private static final long serialVersionUID = 1L;
private static final String DEFAULT_BOX_TOOLTIP = "<html>If this box is checked application will use the current value as a<br>default when creating new components of the same type</html>";
private List<PropertyWrapper> properties;
private Set<PropertyWrapper> defaultedProperties;
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties) {
super(owner, "Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
LOG.debug("Creating property editor for: " + properties);
this.properties = properties;
this.defaultedProperties = new HashSet<PropertyWrapper>();
setMinimumSize(new Dimension(240, 40));
layoutGui();
setLocationRelativeTo(owner);
//
// setModal(true);
//
// JPanel holderPanel = new JPanel();
// holderPanel.setLayout(new BorderLayout());
// holderPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
//
// holderPanel.add(createEditorFields(), BorderLayout.CENTER);
// holderPanel.add(createButtonPanel(), BorderLayout.SOUTH);
//
// setContentPane(holderPanel);
//
//
// pack();
// setLocationRelativeTo(owner);
}
private JPanel createEditorFields() {
JPanel editorPanel = new JPanel(new GridBagLayout());
editorPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridy = 0;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.anchor = GridBagConstraints.LINE_START;
for (PropertyWrapper property : properties) {
gbc.gridx = 0;
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0;
editorPanel.add(new JLabel(property.getName() + ": "), gbc);
gbc.gridx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1;
editorPanel.add(FieldEditorFactory.createFieldEditor(property), gbc);
if (property.isDefaultable()) {
gbc.gridx = 2;
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0;
editorPanel.add(createDefaultCheckBox(property), gbc);
}
gbc.gridy++;
}
return editorPanel;
}
private JCheckBox createDefaultCheckBox(final PropertyWrapper property) {
final JCheckBox checkBox = new JCheckBox();
checkBox.setToolTipText(DEFAULT_BOX_TOOLTIP);
checkBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (checkBox.isSelected()) {
defaultedProperties.add(property);
} else {
defaultedProperties.remove(property);
}
}
});
return checkBox;
}
public Set<PropertyWrapper> getDefaultedProperties() {
return defaultedProperties;
}
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties);
editor.setVisible(true);
if (OK.equals(editor.getSelectedButtonCaption())) {
return true;
}
return false;
}
@Override
protected JComponent getMainComponent() {
return createEditorFields();
}
}
@@ -1,41 +0,0 @@
package org.diylc.gui.editor;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.diylc.common.PropertyWrapper;
public class StringEditor extends JTextField {
private static final long serialVersionUID = 1L;
private final PropertyWrapper property;
public StringEditor(PropertyWrapper property) {
super(property.getValue() == null ? "" : (String) property.getValue());
this.property = property;
getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
textChanged();
}
@Override
public void insertUpdate(DocumentEvent e) {
textChanged();
}
@Override
public void removeUpdate(DocumentEvent e) {
textChanged();
}
});
}
private void textChanged() {
property.setValue(getText());
}
}
-41
View File
@@ -1,41 +0,0 @@
package org.diylc.images;
import javax.swing.Icon;
import javax.swing.ImageIcon;
/**
* Loads image resources as Icons.
*
* @author Branislav Stojkovic
*/
public enum IconLoader {
Delete("delete.png"), Add("add.png"), FolderOut("folder_out.png"), Garbage("garbage.png"), DiskBlue(
"disk_blue.png"), SaveAs("save_as.png"), Exit("exit.png"), DocumentPlainYellow(
"document_plain_yellow.png"), PhotoScenery("photo_scenery.png"), LightBulbOn(
"lightbulb_on.png"), LightBulbOff("lightbulb_off.png"), NotebookAdd("notebook_add.png"), FormGreen(
"form_green.png"), Gears("gears.png"), About("about.png"), Donate("donate.gif"), WindowColors(
"window_colors.png"), WindowGear("window_gear.png"), NavigateCheck("navigate_check.png"), Undo(
"undo.png"), Error("error.png"), Warning("warning.png"), ZoomSmall("zoom_small.png"), MoveSmall(
"move_small.png"), Print("print.png"), PDF("pdf.png"), Excel("excel.png"), CSV(
"csv.png"), HTML("html.png"), Image("image.png"), Cut("cut.png"), Copy("copy.png"), Paste(
"paste.png"), Selection("selection.png"), BOM("bom.png"), BlackBoard("blackboard.png"), IdCard(
"id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench(
"wrench.png"), ;
protected String name;
private IconLoader(String name) {
this.name = name;
}
public Icon getIcon() {
java.net.URL imgURL = getClass().getResource(name);
if (imgURL != null) {
return new ImageIcon(imgURL, name);
} else {
System.err.println("Couldn't find file: " + name);
return null;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 714 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 993 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 863 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 708 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 960 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 914 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 876 B

Some files were not shown because too many files have changed in this diff Show More