1- /*
2- * Licensed to the Apache Software Foundation (ASF) under one
3- * or more contributor license agreements. See the NOTICE file
4- * distributed with this work for additional information
5- * regarding copyright ownership. The ASF licenses this file
6- * to you under the Apache License, Version 2.0 (the
7- * "License"); you may not use this file except in compliance
8- * with the License. You may obtain a copy of the License at
9- *
10- * http://www.apache.org/licenses/LICENSE-2.0
11- *
12- * Unless required by applicable law or agreed to in writing,
13- * software distributed under the License is distributed on an
14- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15- * KIND, either express or implied. See the License for the
16- * specific language governing permissions and limitations
17- * under the License.
18- */
191package org .apache .click .examples .page .control ;
202
3+ import lombok .extern .slf4j .Slf4j ;
4+ import lombok .val ;
5+ import org .apache .click .Control ;
216import org .apache .click .control .Form ;
227import org .apache .click .control .ImageSubmit ;
238import org .apache .click .control .Label ;
249import org .apache .click .examples .page .BorderPage ;
25-
26-
27-
28- /**
29- * Provides an ImageSubmit control example.
30- */
31- public class ImageDemo extends BorderPage {
32-
33- private static final long serialVersionUID = 1L ;
34-
35- private ImageSubmit colorSubmit ;
36-
37- private Form buttonsForm = new Form ("buttonsForm" );
38- private Form form = new Form ("form" );
39-
40- // Constructor ------------------------------------------------------------
41-
42- public ImageDemo () {
43- addControl (form );
44- addControl (buttonsForm );
45-
46- // Buttons Form
47- ImageSubmit editSubmit = new ImageSubmit ("edit" , "/assets/images/edit.gif" );
48- editSubmit .setListener (this , "onEditClick" );
49- editSubmit .setTitle ("Edit" );
50- buttonsForm .add (editSubmit );
51-
52- ImageSubmit deleteSubmit = new ImageSubmit ("delete" , "/assets/images/delete.gif" );
53- deleteSubmit .setListener (this , "onDeleteClick" );
54- deleteSubmit .setTitle ("Delete" );
55- buttonsForm .add (deleteSubmit );
56-
57- // Colors Form
58- form .add (new Label ("label" , "<b>Color Chooser</b>" ));
59-
60- colorSubmit = new ImageSubmit ("save" , "/assets/images/colors.gif" );
61- colorSubmit .setListener (this , "onColorClick" );
62- form .add (colorSubmit );
63- }
64-
65- // Event Handlers ---------------------------------------------------------
66-
67- public boolean onEditClick () {
68- addModel ("buttonMsg" , "Edit" );
69- return true ;
70- }
71-
72- public boolean onDeleteClick () {
73- addModel ("buttonMsg" , "Delete" );
74- return true ;
75- }
76-
77- public boolean onColorClick () {
78- int x = colorSubmit .getX ();
79- int y = colorSubmit .getY ();
80-
81- String color = "no color" ;
82-
83- if (x > 3 && x < 31 ) {
84- if (y > 3 && y < 31 ) {
85- color = "Red" ;
86- } else if (y > 44 && y < 71 ) {
87- color = "Green" ;
88- }
89- } else if (x > 44 && x < 71 ) {
90- if (y > 3 && y < 31 ) {
91- color = "Blue" ;
92- } else if (y > 44 && y < 71 ) {
93- color = "White" ;
94- }
95- }
96-
97- String colorMsg = "<b>" + color + "</b>. <p/> " +
98- "[ x=" + x + ", y=" + y + " ]" ;
99-
100- addModel ("colorMsg" , colorMsg );
101-
102- return true ;
103- }
10+ import org .springframework .context .Lifecycle ;
11+ import org .springframework .stereotype .Component ;
12+
13+ import javax .annotation .PostConstruct ;
14+ import java .io .Serial ;
15+
16+ /** Provides an ImageSubmit control example */
17+ @ Component
18+ @ Slf4j
19+ public class ImageDemo extends BorderPage implements Lifecycle {
20+ @ Serial private static final long serialVersionUID = 1L ;
21+ private final ImageSubmit colorSubmit = new ImageSubmit ("save" , "/assets/images/colors.gif" );
22+
23+ public ImageDemo () {
24+ val form = new Form ("form" );
25+ addControl (form );
26+ val buttonsForm = new Form ("buttonsForm" );
27+ addControl (buttonsForm );
28+
29+ // Buttons Form
30+ val editSubmit = new ImageSubmit ("edit" , "/assets/images/edit.gif" );
31+ editSubmit .setActionListener (this ::onEditClick );
32+ editSubmit .setTitle ("🔞 Edit" );
33+ buttonsForm .add (editSubmit );
34+
35+ val deleteSubmit = new ImageSubmit ("delete" , "/assets/images/delete.gif" );
36+ deleteSubmit .setActionListener (this ::onDeleteClick );
37+ deleteSubmit .setTitle ("✖ Delete" );
38+ buttonsForm .add (deleteSubmit );
39+
40+ // Colors Form
41+ form .add (new Label ("label" , "<b>Color Chooser</b>" ));
42+
43+ colorSubmit .setActionListener (this ::onColorClick );
44+ form .add (colorSubmit );
45+ }
46+
47+ public boolean onEditClick (Control source ) {
48+ addModel ("buttonMsg" , "Edit" );
49+ return true ;
50+ }
51+
52+ public boolean onDeleteClick (Control source ) {
53+ addModel ("buttonMsg" , "Delete" );
54+ return true ;
55+ }
56+
57+ public boolean onColorClick (Control source ) {
58+ int x = colorSubmit .getX ();
59+ int y = colorSubmit .getY ();
60+ String color = "no color" ;
61+
62+ if (x > 3 && x < 31 ){
63+ if (y > 3 && y < 31 ){
64+ color = "Red" ;
65+ } else if (y > 44 && y < 71 ){
66+ color = "Green" ;
67+ }
68+ } else if (x > 44 && x < 71 ){
69+ if (y > 3 && y < 31 ){
70+ color = "Blue" ;
71+ } else if (y > 44 && y < 71 ){
72+ color = "White" ;
73+ }
74+ }
75+ addModel ("colorMsg" , "<b>%s</b>. <p/> [ x=%d, y=%d ]" .formatted (color , x , y ));
76+ return true ;
77+ }
78+
79+ @ PostConstruct
80+ public void afterPropertiesSet () {
81+ log .warn ("INFO: ImageDemo afterPropertiesSet" );
82+ }
83+
84+ @ Override
85+ public void start () {
86+ log .warn ("INFO: start ✅ is called" );
87+ }
88+
89+ @ Override
90+ public void stop () {
91+ log .warn ("INFO: stop 🛑 is called" );
92+ }
93+
94+ @ Override
95+ public boolean isRunning () {
96+ log .warn ("INFO: isRunning ❔ is called" );
97+ return false ;
98+ }
10499}
0 commit comments