Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.10 KB | None | 0 0
  1. package com.example.LoginStuff;
  2.  
  3. import javax.servlet.annotation.WebServlet;
  4.  
  5. import com.vaadin.annotations.Theme;
  6. import com.vaadin.annotations.VaadinServletConfiguration;
  7. import com.vaadin.data.Property;
  8. import com.vaadin.data.Property.ValueChangeEvent;
  9. import com.vaadin.server.FontAwesome;
  10. import com.vaadin.server.VaadinRequest;
  11. import com.vaadin.server.VaadinServlet;
  12. import com.vaadin.shared.ui.label.ContentMode;
  13. import com.vaadin.shared.ui.slider.SliderOrientation;
  14. import com.vaadin.ui.Alignment;
  15. import com.vaadin.ui.Button;
  16. import com.vaadin.ui.Button.ClickEvent;
  17. import com.vaadin.ui.Button.ClickListener;
  18. import com.vaadin.ui.Component;
  19. import com.vaadin.ui.CssLayout;
  20. import com.vaadin.ui.HorizontalLayout;
  21. import com.vaadin.ui.Label;
  22. import com.vaadin.ui.ProgressBar;
  23. import com.vaadin.ui.Slider;
  24. import com.vaadin.ui.TextField;
  25. import com.vaadin.ui.UI;
  26. import com.vaadin.ui.VerticalLayout;
  27.  
  28.  
  29. @Theme("mytheme")
  30. public class MyUI extends UI {
  31.  
  32.     @Override
  33.     protected void init(VaadinRequest vaadinRequest) {
  34.         /*I start off defining the layouts */
  35.         final VerticalLayout layout = new VerticalLayout();
  36.         final CssLayout cssForBtns = new CssLayout(){
  37.             protected String getCss(Component c){
  38.                 if(c instanceof Button){
  39.                 return "color: blue; font-size:35px;align:center;text-align:center;padding:10px;margin:20px;margin-left:60px;";
  40.                 }
  41.                 else return "";
  42.             }
  43.            
  44.         };
  45.         cssForBtns.setWidth("300px");
  46.         cssForBtns.setHeight("150px"); /*
  47.         here end the layouts. Begin the form.
  48.         */
  49.         final TextField userName = new TextField();
  50.         userName.setCaption("Username:");
  51.         final TextField password = new TextField();
  52.         password.setCaption("Password:");/* here ends the form */
  53.        
  54.         /* button starts here */
  55.         password.setIcon(FontAwesome.LOCK);
  56.         userName.setIcon(FontAwesome.USER);
  57.         Button logInBtn = new Button("Log in");
  58.         logInBtn.setIcon(FontAwesome.LAPTOP);
  59.         logInBtn.setWidth("60%");
  60.         logInBtn.setHeight("50%");
  61.         logInBtn.addClickListener( e -> {
  62.             /* Here I'd make a method that actually checks whether the user is valid and stuff. So far, it only returns a warning that it's not. */
  63.             logInBtn.setEnabled(false);
  64.            
  65.             if(password.getValue().equals("")){
  66.                 layout.removeAllComponents();
  67.                 CssLayout lay = new CssLayout(){
  68.                     protected String getCss(Component c){
  69.                         return "background:green";
  70.                     }
  71.                
  72.                 };
  73.                 int w = 400;
  74.                 int h = 400;
  75.                 Label rect = new Label(" ",ContentMode.HTML);
  76.                 rect.setWidth(Integer.toString(w)+"px");
  77.                 rect.setHeight(Integer.toString(h)+"px");
  78.                 lay.addComponent(rect);
  79.                 Slider vertSlider = new Slider(1,500);
  80.                 vertSlider.setOrientation(SliderOrientation.VERTICAL);
  81.  
  82.                 vertSlider.addValueChangeListener(
  83.                         new Property.ValueChangeListener() {
  84.                         public void valueChange(ValueChangeEvent event) {
  85.                             double value = (Double) vertSlider.getValue();
  86.                           rect.setHeight(Double.toString(value)+"px");
  87.                            
  88.                         }
  89.                     });
  90.                
  91.                 Slider horiSlider = new Slider(1,500);
  92.                 horiSlider.addValueChangeListener(
  93.                         new Property.ValueChangeListener() {
  94.                         public void valueChange(ValueChangeEvent event) {
  95.                             double value = (Double) horiSlider.getValue();
  96.                           rect.setWidth(Double.toString(value)+"px");
  97.                            
  98.                         }
  99.                     });
  100.                 vertSlider.setHeight("400px");
  101.                 horiSlider.setWidth("400px");
  102.                 HorizontalLayout horiLay = new HorizontalLayout();
  103.                 horiLay.addComponents(lay,vertSlider);
  104.                 layout.addComponents(horiLay,horiSlider);
  105.                 layout.setComponentAlignment(horiLay, Alignment.TOP_CENTER);
  106.                 layout.setComponentAlignment(horiSlider, Alignment.TOP_CENTER);
  107.                
  108.             }
  109.            
  110.             else {
  111.                 layout.removeAllComponents();
  112.                 ProgressBar bar = new ProgressBar(0.0f);
  113.                 layout.addComponent(bar);
  114.                 layout.setComponentAlignment(bar, Alignment.TOP_CENTER);
  115.                 layout.addComponent(new Button("Next",
  116.                         new ClickListener() {
  117.                         @Override
  118.                         public void buttonClick(ClickEvent event) {
  119.                             float current = bar.getValue();
  120.                             if (current < 1.0f)
  121.                                 {bar.setValue(current + 0.34f);}
  122.                             if(bar.getValue()>= 1.0f) {/* No use of else so that the click that fills the bar activates this sequence */
  123.                                 layout.removeAllComponents();
  124.                                 Label warningSign = new Label("<br/><div style=\"color:red;text-align:center;\">We're sorry, your username doesn't exist.</div>",ContentMode.HTML);
  125.                                 layout.addComponent(warningSign);
  126.                                 layout.setComponentAlignment(warningSign, Alignment.BOTTOM_CENTER);
  127.                             }
  128.                         }
  129.                     }));
  130.                 layout.setComponentAlignment(layout.getComponent(1), Alignment.BOTTOM_CENTER);
  131.                 }
  132.            
  133.         });
  134.         cssForBtns.addComponent(logInBtn);
  135.         /* the button ends here */
  136.        
  137.        
  138.         /* I start adding the stuff to the layout here. */
  139.         layout.addComponents(userName,password, cssForBtns);
  140.         layout.setComponentAlignment(userName, Alignment.MIDDLE_CENTER);
  141.         layout.setComponentAlignment(password, Alignment.MIDDLE_CENTER);
  142.         layout.setComponentAlignment(cssForBtns, Alignment.BOTTOM_CENTER);
  143.         setContent(layout);
  144.     }
  145.  
  146.     @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
  147.     @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
  148.     public static class MyUIServlet extends VaadinServlet {
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement