List of usage examples for com.vaadin.ui Window setWidth
@Override public void setWidth(String width)
From source file:facs.components.Settings.java
License:Open Source License
private void addNewDevice() { final Window subWindow = new Window("Add Device"); FormLayout form = new FormLayout(); form.setMargin(true);/*from ww w. ja v a 2s .c o m*/ final TextField name = new TextField(); name.setImmediate(true); name.addValidator(new StringLengthValidator("The name must be 1-85 letters long (Was {0}).", 1, 85, true)); name.setCaption("Name of new device"); form.addComponent(name); final TextArea description = new TextArea(); description.setImmediate(true); description.addValidator( new StringLengthValidator("The name must be 1-255 letters long (Was {0}).", 1, 255, true)); description.setCaption("Description"); form.addComponent(description); final OptionGroup restricted = new OptionGroup("Is Device restricted by operators?"); restricted.addItem("yes"); restricted.setMultiSelect(true); form.addComponent(restricted); HorizontalLayout buttons = new HorizontalLayout(); Button save = new Button("save"); buttons.addComponent(save); Button discard = new Button("discard"); discard.setDescription("discarding will abort the process of adding a new device into the databse."); buttons.addComponent(discard); buttons.setSpacing(true); form.addComponent(buttons); subWindow.setContent(form); form.setMargin(true); form.setSpacing(true); buttons.setMargin(true); buttons.setSpacing(true); // Center it in the browser window subWindow.center(); subWindow.setModal(true); subWindow.setWidth("50%"); // Open it in the UI UI.getCurrent().addWindow(subWindow); discard.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = -5808910314649620731L; @Override public void buttonClick(ClickEvent event) { subWindow.close(); } }); save.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = 3748395242651585005L; @Override public void buttonClick(ClickEvent event) { if (name.isValid() && description.isValid()) { Set<String> restr = (Set<String>) restricted.getValue(); int deviceId = DBManager.getDatabaseInstance().addDevice(name.getValue(), description.getValue(), (restr.size() == 1)); DeviceBean bean = new DeviceBean(deviceId, name.getValue(), description.getValue(), (restr.size() == 1)); devicesGrid.addRow(bean); } else { Notification.show("Failed to add device to database."); } } }); // DeviceBean db = new DeviceBean(0, "Device 1","some description1", false); // TODO // add to database /* * boolean added = false;//DBManager.getDatabaseInstance().addDevice(db); //TODO test //add to * grid if(added){ devicesGrid.addRow(db); }else{ //TODO log failed operation * Notification.show("Failed to add device to database.", Type.ERROR_MESSAGE); } */ }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void setUserMeter(final Main main, final Base base, final Meter m) { final Database database = main.getDatabase(); final Window subwindow = new Window("Aseta mittarin arvo", new VerticalLayout()); subwindow.setModal(true);//from www . j av a2 s . c o m subwindow.setWidth("350px"); subwindow.setResizable(false); final VerticalLayout winLayout = (VerticalLayout) subwindow.getContent(); winLayout.setMargin(true); winLayout.setSpacing(true); String caption = m.getCaption(database); if (caption != null && !caption.isEmpty()) { final Label header = new Label(caption); header.addStyleName(ValoTheme.LABEL_LARGE); winLayout.addComponent(header); } final Indicator indicator = m.getPossibleIndicator(database); if (indicator == null) return; Datatype dt = indicator.getDatatype(database); if (!(dt instanceof EnumerationDatatype)) return; final Label l = new Label("Selite: " + indicator.getValueShortComment()); AbstractField<?> forecastField = dt.getEditor(main, base, indicator, true, new CommentCallback() { @Override public void runWithComment(String shortComment, String comment) { l.setValue("Selite: " + indicator.getValueShortComment()); } @Override public void canceled() { } }); forecastField.setWidth("100%"); forecastField.setCaption("Ennuste"); winLayout.addComponent(forecastField); AbstractField<?> currentField = dt.getEditor(main, base, indicator, false, new CommentCallback() { @Override public void runWithComment(String shortComment, String comment) { l.setValue("Selite: " + indicator.getValueShortComment()); } @Override public void canceled() { } }); currentField.setWidth("100%"); currentField.setCaption("Toteuma"); winLayout.addComponent(currentField); winLayout.addComponent(l); l.setWidth("100%"); winLayout.setComponentAlignment(l, Alignment.BOTTOM_CENTER); HorizontalLayout hl = new HorizontalLayout(); winLayout.addComponent(hl); winLayout.setComponentAlignment(hl, Alignment.BOTTOM_CENTER); Button ok = new Button("Sulje", new Button.ClickListener() { private static final long serialVersionUID = 1364802814012491490L; public void buttonClick(ClickEvent event) { main.removeWindow(subwindow); } }); Button define = new Button("Mrit", new Button.ClickListener() { private static final long serialVersionUID = 1364802814012491490L; public void buttonClick(ClickEvent event) { Meter.editMeter(main, base, m); } }); hl.addComponent(ok); hl.setComponentAlignment(ok, Alignment.BOTTOM_LEFT); hl.addComponent(define); hl.setComponentAlignment(define, Alignment.BOTTOM_LEFT); main.addWindow(subwindow); }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void editTextAndId(final Main main, String title, final Base container) { final Database database = main.getDatabase(); final Window subwindow = new Window(title, new VerticalLayout()); subwindow.setModal(true);//from www . j a va 2 s . com subwindow.setWidth("400px"); subwindow.setHeight("500px"); subwindow.setResizable(false); VerticalLayout winLayout = (VerticalLayout) subwindow.getContent(); winLayout.setMargin(true); winLayout.setSpacing(true); final TextField tf = new TextField(); tf.setCaption("Lyhytnimi:"); tf.addStyleName(ValoTheme.TEXTFIELD_SMALL); tf.setValue(container.getId(database)); tf.setWidth("100%"); winLayout.addComponent(tf); final TextArea ta = new TextArea(); ta.setCaption("Teksti:"); ta.setValue(container.getText(database)); ta.setWidth("100%"); ta.setHeight("290px"); winLayout.addComponent(ta); Button save = new Button("Tallenna", new Button.ClickListener() { private static final long serialVersionUID = 6641880870005364983L; public void buttonClick(ClickEvent event) { String idValue = tf.getValue(); String value = ta.getValue(); main.removeWindow(subwindow); container.modifyId(main, idValue); container.modifyText(main, value); Collection<String> tags = Tag.extractTags(value); database.assertTags(tags); ArrayList<Tag> tagObjects = new ArrayList<Tag>(); for (String s : tags) tagObjects.add(database.getOrCreateTag(s)); container.assertRelatedTags(database, tagObjects); Updates.update(main, true); Property emails = Property.find(database, Property.EMAIL); String addr = emails.getPropertyValue(container); if (addr != null && !addr.isEmpty()) { String[] addrs = addr.split(","); if (addrs.length > 0) { try { Email.send(addrs, "Muutos strategiakartassa: " + container.getId(database), "Kyttj " + main.account.getId(database) + " on muuttanut strategiakarttaa.<br/><br/>Lyhytnimi: " + container.getId(database) + "<br/><br/>Teksti: " + container.getText(database)); } catch (MessagingException e) { e.printStackTrace(); } } } } }); Button discard = new Button("Peru muutokset", new Button.ClickListener() { private static final long serialVersionUID = -784522457615993823L; public void buttonClick(ClickEvent event) { Updates.update(main, true); main.removeWindow(subwindow); } }); HorizontalLayout hl2 = new HorizontalLayout(); hl2.setSpacing(true); hl2.addComponent(save); hl2.addComponent(discard); winLayout.addComponent(hl2); winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER); main.addWindow(subwindow); ta.setCursorPosition(ta.getValue().length()); }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void editTags(final Main main, String title, final Base container) { final Database database = main.getDatabase(); final Window subwindow = new Window(title, new VerticalLayout()); subwindow.setModal(true);/*from ww w . j av a 2 s. c om*/ subwindow.setWidth("400px"); subwindow.setHeight("360px"); subwindow.setResizable(true); VerticalLayout winLayout = (VerticalLayout) subwindow.getContent(); winLayout.setMargin(true); winLayout.setSpacing(true); // Add some content; a label and a close-button final List<String> tags = new ArrayList<String>(); for (Tag t : container.getRelatedTags(database)) tags.add(t.getId(database)); final CssLayout vl = new CssLayout(); vl.setCaption("Kytss olevat aihetunnisteet:"); fillTagEditor(database, vl, tags, Account.canWrite(main, container)); winLayout.addComponent(vl); HorizontalLayout hl = new HorizontalLayout(); hl.setWidth("100%"); hl.setSpacing(true); final TagCombo combo = new TagCombo(); final CustomLazyContainer comboContainer = new CustomLazyContainer(database, combo, Tag.enumerate(database)); combo.setWidth("100%"); combo.setCaption("Uusi aihetunniste:"); combo.setInputPrompt("valitse listasta tai kirjoita"); combo.setFilteringMode(FilteringMode.STARTSWITH); combo.setTextInputAllowed(true); combo.setImmediate(true); combo.setNullSelectionAllowed(false); combo.setInvalidAllowed(true); combo.setInvalidCommitted(true); combo.setItemCaptionMode(ItemCaptionMode.PROPERTY); combo.setItemCaptionPropertyId("id"); //should set combo.setContainerDataSource(comboContainer); hl.addComponent(combo); hl.setExpandRatio(combo, 1.0f); Button add = new Button("Lis", new Button.ClickListener() { private static final long serialVersionUID = -2848576385076605664L; public void buttonClick(ClickEvent event) { String filter = (String) combo.getValue(); if (filter != null && filter.length() > 0) { Tag t = database.getOrCreateTag(filter); if (tags.contains(t.getId(database))) return; tags.add(t.getId(database)); fillTagEditor(database, vl, tags, main.account != null); combo.clear(); } } }); hl.addComponent(add); hl.setComponentAlignment(add, Alignment.BOTTOM_LEFT); hl.setExpandRatio(add, 0.0f); winLayout.addComponent(hl); Button close = new Button("Tallenna", new Button.ClickListener() { private static final long serialVersionUID = -451523776456589591L; public void buttonClick(ClickEvent event) { main.removeWindow(subwindow); List<Tag> newTags = new ArrayList<Tag>(); for (String s : tags) newTags.add(database.getOrCreateTag(s)); container.setRelatedTags(database, newTags); Updates.update(main, true); } }); Button discard = new Button("Peru muutokset", new Button.ClickListener() { private static final long serialVersionUID = -2387057110951581993L; public void buttonClick(ClickEvent event) { main.removeWindow(subwindow); } }); HorizontalLayout hl2 = new HorizontalLayout(); hl2.setSpacing(true); hl2.addComponent(close); hl2.addComponent(discard); winLayout.addComponent(hl2); winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER); main.addWindow(subwindow); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * are el dilogo para autenticarse//from w w w. j a va2 s .c om */ private void openLoginDialog(boolean gohome) { // Create a sub-window and set the content Window subWindow = new Window("Login"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); TextField l; f.addComponent(l = new TextField("Username")); PasswordField p; f.addComponent(p = new PasswordField("Password")); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button forgot = new Button("Forgot password", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Asking for email..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().forgotPassword(l.getValue(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("Email sent. Please check your inbox"); } }); } }); //forgot.addStyleName(ValoTheme.BUTTON_); Button ok = new Button("Login", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Authenticating..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().authenticate(l.getValue(), p.getValue(), new AsyncCallback<UserData>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(UserData result) { e.setValue("OK!"); getApp().setUserData(result); VaadinSession.getCurrent().setAttribute("usuario", "admin"); subWindow.close(); if (MateuUI.getApp().isFavouritesAvailable()) linkFavoritos.setVisible(true); if (MateuUI.getApp().isLastEditedAvailable()) linkUltimosRegistros.setVisible(true); if (MateuUI.getApp().isFavouritesAvailable()) linkNuevoFavorito.setVisible(true); refreshSettings(); refreshMenu(null, null); System.out.println("STATE:" + navigator.getState()); System.out.println("URIFRAGMENT:" + Page.getCurrent().getUriFragment()); navigator.navigateTo((gohome) ? "" : navigator.getState()); } }); } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, forgot, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar el password * *//*from ww w . j a v a 2 s .c om*/ private void changePassword() { // Create a sub-window and set the content Window subWindow = new Window("Change password"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); PasswordField l; f.addComponent(l = new PasswordField("Current password")); PasswordField p; f.addComponent(p = new PasswordField("New password")); PasswordField p2; f.addComponent(p2 = new PasswordField("Repeat password")); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { if (l.getValue() == null || "".equals(l.getValue().trim())) e.setValue("Old password is required"); else if (p.getValue() == null || "".equals(p.getValue().trim())) e.setValue("New password is required"); else if (p2.getValue() == null || "".equals(p2.getValue().trim())) e.setValue("New password repeated is required"); else if (!p.getValue().equals(p2.getValue())) e.setValue("New password and new password repeated must be equal"); else { e.setValue("Changing password..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().changePassword( getApp().getUserData().getLogin(), l.getValue(), p.getValue(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); subWindow.close(); } }); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para editar el perfil/* www . java2s . c o m*/ * */ private void editProfile() { // Create a sub-window and set the content Window subWindow = new Window("My profile"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); TextField l; f.addComponent(l = new TextField("Name")); l.setValue(getApp().getUserData().getName()); TextField p; f.addComponent(p = new TextField("Email")); p.setValue(getApp().getUserData().getEmail()); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Update it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Authenticating..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().updateProfile( getApp().getUserData().getLogin(), l.getValue(), p.getValue(), null, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setName(l.getValue()); getApp().getUserData().setEmail(p.getValue()); subWindow.close(); refreshSettings(); } }); } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar la foto/* w w w . j a v a2 s . c om*/ * * */ private void uploadFoto() { // Create a sub-window and set the content Window subWindow = new Window("My photo"); subWindow.setWidth("475px"); FormLayout f = new FormLayout(); f.setMargin(true); Label e = new Label(); Image image = new Image(); class MyUploader implements Upload.Receiver, Upload.SucceededListener { File file; public File getFile() { return file; } public OutputStream receiveUpload(String fileName, String mimeType) { // Create and return a file output stream System.out.println("receiveUpload(" + fileName + "," + mimeType + ")"); FileOutputStream os = null; if (fileName != null && !"".equals(fileName)) { long id = fileId++; String extension = ".tmp"; if (fileName == null || "".equals(fileName.trim())) fileName = "" + id + extension; if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")); } File temp = null; try { temp = File.createTempFile(fileName, extension); os = new FileOutputStream(file = temp); } catch (IOException e) { e.printStackTrace(); } } return os; } public void uploadSucceeded(Upload.SucceededEvent event) { // Show the uploaded file in the image viewer image.setSource(new FileResource(file)); System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")"); } public FileLocator getFileLocator() throws IOException { String extension = ".tmp"; String fileName = file.getName(); if (file.getName() == null || "".equals(file.getName().trim())) fileName = "" + getId(); if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_"); } java.io.File temp = (System.getProperty("tmpdir") == null) ? java.io.File.createTempFile(fileName, extension) : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension); System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); System.out.println("Temp file : " + temp.getAbsolutePath()); if (System.getProperty("tmpdir") == null || !temp.exists()) { System.out.println("writing temp file to " + temp.getAbsolutePath()); Files.copy(file, temp); } else { System.out.println("temp file already exists"); } String baseUrl = System.getProperty("tmpurl"); URL url = null; try { if (baseUrl == null) { url = file.toURI().toURL(); } else url = new URL(baseUrl + "/" + file.getName()); } catch (MalformedURLException e) { e.printStackTrace(); } return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath()); } } ; MyUploader receiver = new MyUploader(); Upload upload = new Upload(null, receiver); //upload.setImmediateMode(false); upload.addSucceededListener(receiver); f.addComponent(image); f.addComponent(upload); f.addComponent(e); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Changing photo..."); try { FileLocator loc = receiver.getFileLocator(); io.mateu.ui.core.client.app.MateuUI.getBaseService() .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setPhoto(loc.getUrl()); foto = (getApp().getUserData().getPhoto() != null) ? new ExternalResource(getApp().getUserData().getPhoto()) : new ClassResource("profile-pic-300px.jpg"); subWindow.close(); refreshSettings(); } }); } catch (IOException e1) { e1.printStackTrace(); io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage()); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); upload.focus(); }
From source file:it.vige.greenarea.bpm.custom.ui.dettaglio.KmlDocumentViewer.java
License:Apache License
public KmlDocumentViewer(String focusedFeature, Coordinate coordinate) { super();//from w w w . j a va2s . c o m setImmediate(true); loadDocument(); setWidth(100, UNITS_PERCENTAGE); addComponent(ufu); addLayer(osm); addLayer(vectorLayer); extractStyles(doc); displayFeatures(focusedFeature); vectorLayer.setSelectionMode(SIMPLE); vectorLayer.setImmediate(true); vectorLayer.addListener(new VectorSelectedListener() { public void vectorSelected(VectorSelectedEvent event) { final Area component = (Area) event.getVector(); final String data = (String) component.getData(); final Window window = new Window("Details"); window.getContent().setSizeFull(); window.setHeight("50%"); window.setWidth("50%"); Button button = new Button("Focus this feature"); button.addListener(new ClickListener() { private static final long serialVersionUID = 3286851301965195290L; @Override public void buttonClick(ClickEvent event) { ufu.setFragment(data); displayFeatures(data); window.getParent().removeWindow(window); } }); window.addComponent(button); window.setClosable(true); window.center(); getWindow().addWindow(window); vectorLayer.setSelectedVector(null); } }); if (coordinate != null) { // Definig a Marker Layer MarkerLayer markerLayer = new MarkerLayer(); // Defining a new Marker final Marker marker = new Marker(coordinate.getLongitude(), coordinate.getLatitude()); // URL of marker Icon marker.setIcon(new ThemeResource("img/marker.png"), 60, 60); markerLayer.addComponent(marker); addLayer(markerLayer); setCenter(coordinate.getLongitude(), coordinate.getLatitude()); } }
From source file:kn.uni.gis.ui.GameApplication.java
License:Apache License
private Window createGameWindow() { tabsheet = new TabSheet(); tabsheet.setImmediate(true);//from w ww.j ava 2s. c om tabsheet.setCloseHandler(new CloseHandler() { @Override public void onTabClose(TabSheet tabsheet, Component tabContent) { Game game = ((GameComposite) tabContent).getGame(); GameComposite remove = gameMap.remove(game); // closes the game and the running thread! remove.getLayer().handleApplicationClosedEvent(new ApplicationClosedEvent()); eventBus.unregister(remove); eventBus.unregister(remove.getLayer()); map.removeLayer(remove.getLayer()); tabsheet.removeComponent(tabContent); if (gameMap.isEmpty()) { pi.setVisible(false); } } }); final Window mywindow = new Window("Games"); mywindow.setPositionX(0); mywindow.setPositionY(0); mywindow.setHeight("50%"); mywindow.setWidth("25%"); VerticalLayout layout = new VerticalLayout(); HorizontalLayout lay = new HorizontalLayout(); final Button button_1 = new Button(); button_1.setCaption("Open Game"); button_1.setWidth("-1px"); button_1.setHeight("-1px"); button_1.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { final String id = textField_1.getValue().toString(); if (id.length() < 5) { window.showNotification("id must have at least 5 characters", Notification.TYPE_ERROR_MESSAGE); } else { String sql = String.format("select player_id,player_name,min(timestamp),max(timestamp) from %s" + " where id LIKE ? group by player_id, player_name", GisResource.FOX_HUNTER); final Game game = new Game(id); final PreparedStatement statement = geoUtil.getConn() .prepareStatement("select poly_geom,timestamp from " + GisResource.FOX_HUNTER + " where id LIKE ? and player_id=? and timestamp > ? order by timestamp LIMIT " + MAX_STATES_IN_MEM); try { geoUtil.getConn().executeSafeQuery(sql, new DoWithin() { @Override public void doIt(ResultSet executeQuery) throws SQLException { while (executeQuery.next()) { if (statement == null) { } String playerId = executeQuery.getString(1); Timestamp min = executeQuery.getTimestamp(3); Timestamp max = executeQuery.getTimestamp(4); game.addPlayer(playerId, executeQuery.getString(2), min, max, new TimingIterator(geoUtil, id, playerId, min.getTime(), statement)); } } }, id + "%"); } catch (SQLException e) { LOGGER.info("error on sql!", e); } game.finish(statement); if (!!!gameMap.containsKey(game)) { if (game.getStates().size() == 0) { window.showNotification("game not found!"); } else { LOGGER.info("received game info: {},{} ", game.getId(), game.getStates().size()); GameVectorLayer gameVectorLayer = new GameVectorLayer(GameApplication.this, eventBus, game, createColorMap(game)); final GameComposite gameComposite = new GameComposite(GameApplication.this, game, gameVectorLayer, eventBus); eventBus.register(gameComposite); eventBus.register(gameVectorLayer); map.addLayer(gameVectorLayer); gameMap.put(game, gameComposite); // Add the component to the tab sheet as a new tab. Tab addTab = tabsheet.addTab(gameComposite); addTab.setCaption(game.getId().substring(0, 5)); addTab.setClosable(true); pi.setVisible(true); // pl.get PlayerState playerState = game.getStates().get(game.getFox()).peek(); map.zoomToExtent(new Bounds(CPOINT_TO_POINT.apply(playerState.getPoint()))); } } } } private Map<Player, Integer> createColorMap(Game game) { Function<Double, Double> scale = HardTasks.scale(0, game.getStates().size()); ImmutableMap.Builder<Player, Integer> builder = ImmutableMap.builder(); int i = 0; for (Player play : game.getStates().keySet()) { builder.put(play, getColor(scale.apply((double) i++))); } return builder.build(); } private Integer getColor(double dob) { int toReturn = 0; toReturn = toReturn | 255 - (int) Math.round(255 * dob); toReturn = toReturn | (int) ((Math.round(255 * dob)) << 16); return toReturn; // return (int) (10000 + 35000 * dob + 5000 * dob + 1000 * dob + // 5 * dob); } }); Button button_2 = new Button(); button_2.setCaption("All seeing Hunter"); button_2.setImmediate(false); button_2.setWidth("-1px"); button_2.setHeight("-1px"); button_2.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (adminWindow == null) { adminWindow = new AdminWindow(password, geoUtil, new ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { textField_1.setValue(event.getItemId().toString()); mywindow.bringToFront(); button_1.focus(); } }); window.addWindow(adminWindow); adminWindow.setWidth("30%"); adminWindow.setHeight("40%"); adminWindow.addListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { adminWindow = null; } }); } } }); lay.addComponent(button_1); textField_1 = new TextField(); textField_1.setImmediate(false); textField_1.setWidth("-1px"); textField_1.setHeight("-1px"); lay.addComponent(textField_1); lay.addComponent(button_2); lay.addComponent(pi); lay.setComponentAlignment(pi, Alignment.TOP_RIGHT); layout.addComponent(lay); layout.addComponent(tabsheet); mywindow.addComponent(layout); mywindow.setClosable(false); /* Add the window inside the main window. */ return mywindow; }