List of usage examples for com.google.gwt.user.client.ui Label setText
public void setText(String text)
From source file:asquare.gwt.tkdemo.client.demos.DialogPanel.java
License:Apache License
private Widget createModalDialogDemo() { BasicPanel panel = new BasicPanel("div", "block"); panel.setStyleName("example division"); DomUtil.setStyleAttribute(panel, "whiteSpace", "nowrap"); panel.add(new HTML("<h4>ModalDialog examples</h4>")); class CloseListener implements ClickHandler { private final ModalDialog m_dialog; public CloseListener(ModalDialog dialog) { m_dialog = dialog;// w ww. j a v a2 s .co m } public void onClick(ClickEvent event) { m_dialog.hide(); } } class CloseButton extends Button { public CloseButton(ModalDialog dialog) { super("Close"); addClickHandler(new CloseListener(dialog)); } public CloseButton(ModalDialog dialog, String text) { super(text); addClickHandler(new CloseListener(dialog)); } } final Button plainDialog = new Button("Plain"); plainDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Caption area", false); dialog.add(new Label("Content area")); dialog.add(new CloseButton(dialog)); dialog.show(plainDialog); } }); panel.add(plainDialog); final Button verboseDialog = new Button("Verbose"); verboseDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Verbose dialog", false); dialog.add(new Label("Twas brillig, and the slithy toves " + " Did gyre and gimble in the wabe: " + "All mimsy were the borogoves, " + " And the mome raths outgrabe " + "Beware the Jabberwock, my son! " + "The jaws that bite, the claws that catch! " + "Beware the Jubjub bird, and shun " + "The frumious Bandersnatch!")); dialog.add(new CloseButton(dialog)); dialog.show(verboseDialog); } }); panel.add(verboseDialog); final Button captionLessDialog = new Button("No caption"); captionLessDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.add(new Label("Captionless dialog")); dialog.add(new CloseButton(dialog)); dialog.show(captionLessDialog); } }); panel.add(captionLessDialog); final Button loadingDialog = new Button("Loading..."); loadingDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); final Label label = new Label("0% loaded"); dialog.add(label); dialog.show(loadingDialog); new Timer() { private int m_count = 0; public void run() { label.setText(++m_count + "% loaded"); if (m_count == 100) { dialog.hide(); cancel(); } } }.scheduleRepeating(1); } }); panel.add(loadingDialog); final Button undraggableDialog = new Button("Drag disabled"); undraggableDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog() { protected List<Controller> createCaptionControllers() { List<Controller> result = new ArrayList<Controller>(); result.add(ControlSurfaceController.getInstance()); return result; } }; dialog.setCaption("Drag disabled", false); dialog.add(new Label( "This dialog uses a custom controller in the header which does not provide drag support.")); dialog.add(new CloseButton(dialog)); dialog.show(undraggableDialog); } }); panel.add(undraggableDialog); final Button styledDragDialog = new Button("Drag style"); styledDragDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); String oldPrimaryName = dialog.getStylePrimaryName(); dialog.setStylePrimaryName("dialog-dragstyle"); dialog.addStyleName(oldPrimaryName); dialog.setCaption("Drag me", false); dialog.add(new Label( "This dialog employs the \"tk-ModalDialog-dragging\" style which is applied while dragging. ")); dialog.add(new CloseButton(dialog)); dialog.show(styledDragDialog); } }); panel.add(styledDragDialog); final Button focusManagementDialog = new Button("Focus management"); focusManagementDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Register", false); FocusModel fModel = dialog.getFocusModel(); final int FIELD_COUNT = 3; Grid table = new Grid(FIELD_COUNT, 2); dialog.add(table); Widget[] labels = new Widget[FIELD_COUNT]; labels[0] = new Label("User name: "); labels[1] = new Label("Password: "); labels[2] = new Label("Retype password: "); FocusWidget[] fields = new FocusWidget[FIELD_COUNT]; fields[0] = new TextBox(); fields[1] = new PasswordTextBox(); fields[2] = new PasswordTextBox(); CellFormatter formatter = table.getCellFormatter(); for (int i = 0; i < labels.length; i++) { table.setWidget(i, 0, labels[i]); formatter.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_LEFT); table.setWidget(i, 1, fields[i]); /* * Manually add fields to focus cycle. (The dialog does not * scan the children of panels for focusable widgets.) */ fModel.add(fields[i]); } // this widget will be focused when the dialog is shown fModel.setFocusWidget(fields[0]); ColumnPanel buttonPanel = new ColumnPanel(); buttonPanel.setWidth("100%"); dialog.add(buttonPanel); Button closeButton = new CloseButton(dialog, "Register!"); fModel.add(closeButton); buttonPanel.add(closeButton); Button cancelButton = new CloseButton(dialog, "Cancel"); fModel.add(cancelButton); buttonPanel.addWidget(cancelButton, false); buttonPanel.setCellHorizontalAlignment(ColumnPanel.ALIGN_RIGHT); dialog.show(focusManagementDialog); } }); panel.add(focusManagementDialog); final Button explicitlyPositionedDialog = new Button("Explicitly positioned"); explicitlyPositionedDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.removeController(dialog.getController(ModalDialog.PositionDialogController.class)); int contentWidth = 300; int contentHeight = 100; dialog.setContentWidth(contentWidth + "px"); dialog.setContentHeight(contentHeight + "px"); dialog.setPopupPosition(100, 100); dialog.setCaption("Explicitly positioned dialog", false); dialog.add(new Label( "Automatic positioning is disabled. Dimensions and position are set explicitly. ")); dialog.add(new CloseButton(dialog)); dialog.show(explicitlyPositionedDialog); } }); panel.add(explicitlyPositionedDialog); final Button multipleDialogs = new Button("Multiple dialogs"); multipleDialogs.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { ModalDialog dialog = new ModalDialog(); dialog.setCaption("First dialog", false); FocusModel fModel = dialog.getFocusModel(); RowPanel outer = new RowPanel(); dialog.add(new HTML("")); final UrlLocation urlBox = new UrlLocation(); urlBox.setText("http://www.asquare.net"); urlBox.setWidth("350px"); fModel.add(urlBox); outer.add(urlBox); Button goButton = new Button("Go"); fModel.add(goButton); fModel.setFocusWidget(goButton); outer.addWidget(goButton, false); ListBox addressList = new ListBox(); addressList.addItem("Select an address"); addressList.addItem("http://www.asquare.net"); addressList.addItem("http://www.google.com"); addressList.addItem("http://www.sourceforge.net"); addressList.addItem("http://www.apache.org"); fModel.add(addressList); outer.add(addressList); final Frame frame = new Frame(); frame.setSize("400px", "200px"); outer.add(frame); urlBox.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { frame.setUrl(urlBox.getURL()); } }); goButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { frame.setUrl(urlBox.getURL()); } }); addressList.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { ListBox list = (ListBox) event.getSource(); if (list.getSelectedIndex() > 0) { urlBox.setText(list.getItemText(list.getSelectedIndex())); frame.setUrl(list.getItemText(list.getSelectedIndex())); } } }); final Button secondDialog = new Button("Show second dialog"); secondDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.setCaption("Second dialog", false); dialog.add(new Label("Note that you cannot manipulate the widgets in the first dialog. ")); dialog.add(new CloseButton(dialog)); dialog.show(secondDialog); } }); fModel.add(secondDialog); outer.add(secondDialog); Button closeButton = new CloseButton(dialog); fModel.add(closeButton); outer.add(closeButton); dialog.add(outer); dialog.show(multipleDialogs); } }); panel.add(multipleDialogs); final Button styledDialog = new Button("Styled"); styledDialog.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { final ModalDialog dialog = new ModalDialog(); dialog.addStyleName("dialog-styled"); HorizontalPanel caption = new HorizontalPanel(); caption.setWidth("100%"); Label captionText = new Label("Oopsie!"); caption.add(captionText); caption.setCellWidth(captionText, "100%"); Image close = new Image("close.gif"); close.addClickHandler(new CloseListener(dialog)); caption.add(close); dialog.setCaption(caption); dialog.add(new Label("I've been a bad, bad browser.")); dialog.add(new Button("Deny ice cream", new CloseListener(dialog))); dialog.show(styledDialog); } }); panel.add(styledDialog); return panel; }
From source file:bingo.client.Bingo.java
License:Open Source License
/** * This is the entry point method./*w w w .j a v a 2 s .com*/ */ public void onModuleLoad() { Label titleLabel = new Label(); titleLabel.setText(strings.title()); RootPanel.get("title").add(titleLabel); // This is the general notification text box RootPanel.get("message").add(message); // Cheking if the user has already an user id final String cookie = Cookies.getCookie(COOKIE_ID); // Validating the cookie bingoService.statusUserId(cookie, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); Cookies.removeCookie(COOKIE_ID); } @Override public void onSuccess(Integer status) { // TODO: Control the logged status (I should not get a user if s/he is already logged) if (status.intValue() == BingoService.NO_LOGGED || status.intValue() == BingoService.LOGGED) { bingoService.getUserId(new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { message.setText(strings.errorUserCreation()); } @Override public void onSuccess(String result) { userId = result; } }); message.setHTML(""); // Showing image to enter ImageResource imageResource = BingoResources.INSTANCE.entry(); Image entryImage = new Image(imageResource.getSafeUri()); RootPanel.get("buttons").add(entryImage); // Selecting behavior (admin / voter) HorizontalPanel entryPoint = new HorizontalPanel(); entryPoint.setStyleName("mainSelectorPanel"); entryPoint.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); entryPoint.setSpacing(50); // // CREATING A BINGO // VerticalPanel leftPanel = new VerticalPanel(); leftPanel.setStyleName("selectorPanel"); Label leftPanelTitle = new Label(); leftPanelTitle.setStyleName("selectorPanelTitle"); leftPanelTitle.setText(strings.leftPanelTitle()); leftPanel.add(leftPanelTitle); leftPanel.setCellHorizontalAlignment(leftPanelTitle, HasHorizontalAlignment.ALIGN_CENTER); Grid leftSubPanel = new Grid(2, 2); leftSubPanel.setWidget(0, 0, new Label(strings.createBingoName())); final TextBox bingoNameBox = new TextBox(); leftSubPanel.setWidget(0, 1, bingoNameBox); leftSubPanel.setWidget(1, 0, new Label(strings.createBingoPassword())); final PasswordTextBox bingoPasswordBox = new PasswordTextBox(); leftSubPanel.setWidget(1, 1, bingoPasswordBox); leftPanel.add(leftSubPanel); final Button createButton = new Button("Create"); createButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { bingoService.createBingo(userId, bingoNameBox.getText(), bingoPasswordBox.getText(), new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(final String gameId) { final BingoGrid bingoGrid = new BingoGrid(); initAdminGrid(userId, bingoGrid, false); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); message.setText(strings.welcomeMessageCreation()); // Setting the cookie Date expirationDate = new Date(); expirationDate.setHours(expirationDate.getHours() + EXPIRATION_VALUE); Cookies.setCookie(COOKIE_ID, userId, expirationDate); } }); } }); leftPanel.add(createButton); leftPanel.setCellHorizontalAlignment(createButton, HasHorizontalAlignment.ALIGN_CENTER); entryPoint.add(leftPanel); // // JOINING // VerticalPanel rightPanel = new VerticalPanel(); rightPanel.setStyleName("selectorPanel"); Label rightPanelTitle = new Label(); rightPanelTitle.setStyleName("selectorPanelTitle"); rightPanelTitle.setText(strings.rightPanelTitle()); rightPanel.add(rightPanelTitle); rightPanel.setCellHorizontalAlignment(rightPanelTitle, HasHorizontalAlignment.ALIGN_CENTER); Grid rightSubPanel = new Grid(2, 2); rightSubPanel.setWidget(0, 0, new Label(strings.joinToBingoName())); final ListBox joinExistingBingoBox = new ListBox(); bingoService.getBingos(new AsyncCallback<String[][]>() { @Override public void onFailure(Throwable caught) { joinExistingBingoBox.addItem(strings.noBingos()); } @Override public void onSuccess(String[][] result) { if (result == null) { joinExistingBingoBox.addItem(strings.noBingos()); } else { for (int i = 0; i < result.length; i++) { String gameName = result[i][0]; String gameId = result[i][1]; joinExistingBingoBox.addItem(gameName, gameId); } } } }); rightSubPanel.setWidget(0, 1, joinExistingBingoBox); rightSubPanel.setWidget(1, 0, new Label(strings.joinToBingoPassword())); final PasswordTextBox joinBingoPasswordBox = new PasswordTextBox(); rightSubPanel.setWidget(1, 1, joinBingoPasswordBox); rightPanel.add(rightSubPanel); final Button joinButton = new Button("Join"); joinButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { int index = joinExistingBingoBox.getSelectedIndex(); if (index < 0) message.setText(strings.noSelectedItem()); else { final String gameId = joinExistingBingoBox.getValue(index); if (gameId == null) message.setText(strings.noSelectedItem()); else { bingoService.joinBingo(userId, gameId, joinBingoPasswordBox.getText(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Void result) { final BingoGrid bingoGrid = new BingoGrid(); initUserGrid(bingoGrid); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); message.setText(strings.welcomeMessageJoin()); // Setting the cookie Date expirationDate = new Date(); expirationDate .setHours(expirationDate.getHours() + EXPIRATION_VALUE); Cookies.setCookie(COOKIE_ID, userId, expirationDate); } }); } } } }); rightPanel.add(joinButton); rightPanel.setCellHorizontalAlignment(joinButton, HasHorizontalAlignment.ALIGN_CENTER); entryPoint.add(rightPanel); RootPanel.get("bingoTable").add(entryPoint); } else if (status.intValue() == BingoService.ADMIN) { message.setText("Detected cookie: " + cookie + " as admin"); userId = cookie; bingoService.statusBingo(userId, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Integer result) { int status = result.intValue(); final BingoGrid bingoGrid = new BingoGrid(); if (status == BingoService.RUNNING) { initAdminGrid(userId, bingoGrid, false); message.setText(strings.welcomeMessageCreation()); } else if (status == BingoService.FINISHED) { initAdminGrid(userId, bingoGrid, true); message.setText(strings.finishMessage()); } RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); } }); } else if (status.intValue() == BingoService.PARTICIPANT) { message.setText("Detected cookie: " + cookie + " as participant"); userId = cookie; final BingoGrid bingoGrid = new BingoGrid(); initUserGrid(bingoGrid); updateUserGrid(bingoGrid, null); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); } } }); }
From source file:bingo.client.Bingo.java
License:Open Source License
private void initAdminGrid(final String userId, final BingoGrid bingoGrid, final boolean hasFinished) { final Timer timer = new Timer() { int totalParticipants = 0; @Override/*from w ww . j a v a 2s . c o m*/ public void run() { bingoService.getTotalParticipants(userId, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(Integer result) { totalParticipants = result.intValue(); } }); bingoService.getVotes(userId, new AsyncCallback<int[][]>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(int[][] result) { if (result == null) { result = new int[BingoGrid.ROW][BingoGrid.COL]; for (int i = 0; i < BingoGrid.ROW; i++) for (int j = 0; j < BingoGrid.COL; j++) result[i][j] = 0; } for (int row = 0; row < BingoGrid.ROW; ++row) for (int col = 0; col < BingoGrid.COL; ++col) { bingoGrid.setVoteString(row, col, String.valueOf(result[row][col]), String.valueOf(totalParticipants)); } } }); } }; // If the game is not finished, repeat; if so, run once if (!hasFinished) timer.scheduleRepeating(ADMIN_TIMER); else timer.run(); HorizontalPanel panel = new HorizontalPanel(); panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); final Button finishButton = new Button(); // If the game is not finished, allow finishing it; if so, allow download data if (!hasFinished) finishButton.setText(strings.finishBingo()); else finishButton.setText(strings.download()); finishButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!hasFinished) bingoService.finishBingo(userId, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Void result) { message.setText(strings.finishedBingo()); finishButton.setText(strings.download()); timer.cancel(); } }); bingoService.getVotes(userId, new AsyncCallback<int[][]>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(int[][] result) { // Create a popup dialog box final DialogBox box = new DialogBox(); box.setText(strings.info()); box.setAnimationEnabled(true); final Button boxAcceptButton = new Button(strings.accept()); boxAcceptButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { box.hide(); } }); Label boxLabel = new Label(); boxLabel.setText(strings.finishMessage()); HTML voteData = new HTML(); if (result == null) { result = new int[BingoGrid.ROW][BingoGrid.COL]; for (int i = 0; i < BingoGrid.ROW; i++) for (int j = 0; j < BingoGrid.COL; j++) result[i][j] = 0; } String cellKey = ""; String cellString = ""; String voteDataString = ""; for (int row = 0; row < BingoGrid.ROW; ++row) for (int col = 0; col < BingoGrid.COL; ++col) { cellKey = "cell" + row + col; cellString = strings.map().get(cellKey); voteDataString += " " + cellString + " = " + result[row][col] + "<br>"; } voteData.setHTML(voteDataString); voteData.addStyleName("boxData"); VerticalPanel boxPanel = new VerticalPanel(); boxPanel.addStyleName("boxPanel"); boxPanel.add(boxLabel); boxPanel.add(voteData); HorizontalPanel buttonsPanel = new HorizontalPanel(); buttonsPanel.add(boxAcceptButton); boxPanel.add(buttonsPanel); boxPanel.setCellHorizontalAlignment(buttonsPanel, HasHorizontalAlignment.ALIGN_CENTER); box.setWidget(boxPanel); box.center(); } }); } }); panel.add(finishButton); final Button terminateButton = new Button(strings.terminateButton()); terminateButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // Create a popup dialog box final DialogBox box = new DialogBox(); box.setText(strings.warning()); box.setAnimationEnabled(true); final Button boxCancelButton = new Button(strings.cancel()); boxCancelButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { box.hide(); } }); final Button boxAcceptButton = new Button(strings.accept()); boxAcceptButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { bingoService.terminateBingo(userId, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Void result) { message.setText(strings.terminatedBingo()); timer.cancel(); } }); box.hide(); } }); final Label boxLabel = new Label(); boxLabel.setText(strings.terminateMessage()); VerticalPanel boxPanel = new VerticalPanel(); boxPanel.addStyleName("boxPanel"); boxPanel.add(boxLabel); HorizontalPanel buttonsPanel = new HorizontalPanel(); buttonsPanel.add(boxCancelButton); buttonsPanel.add(boxAcceptButton); boxPanel.add(buttonsPanel); box.setWidget(boxPanel); box.center(); } }); panel.add(terminateButton); RootPanel.get("buttons").clear(); RootPanel.get("buttons").add(panel); }
From source file:bingo.client.BingoCell.java
License:Open Source License
public BingoCell(SafeUri uri, String label, String votes) { super(3, 1);// www. j a va2s .c o m this.setCellPadding(3); FlowPanel imagePanel = new FlowPanel(); imagePanel.setSize(IMAGE_WIDTH, IMAGE_HEIGHT); Image cellImage = new Image(uri); cellImage.setStyleName("cell-image"); imagePanel.add(cellImage); Label labelText = new Label(); labelText.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); labelText.setText(label); labelText.setStyleName("cell-label"); Label votesText = new Label(votes); this.votes = votesText; this.votes.setStyleName("cell-votes"); this.voted = false; this.setWidget(0, 0, imagePanel); this.getCellFormatter().setHeight(0, 0, IMAGE_HEIGHT); this.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); this.setWidget(1, 0, labelText); this.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER); this.setWidget(2, 0, this.votes); this.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER); }
From source file:bufferings.ktr.wjr.client.ui.widget.WjrListBox.java
License:Apache License
/** * Adds the item.//from w w w . j av a2 s.co m * * @param item * The item to add. * @throws NullPointerException * If the item parameter is null. */ public void addItem(String item) { checkNotNull(item, "The item parameter is null."); Label label = new HoverableAndClickableLabel(); label.setStyleName(Resources.INSTANCE.css().itemStyle()); // Use trimedItem not to show prefix tab on the tooltip. String trimedItem = item.trim(); label.setTitle(trimedItem); if (trimedItem.length() == 0) { // Allows to show empty line. label.getElement().setInnerHTML(" "); } else { // HTML element is escaped. label.setText(item); } mainPanel.add(label); }
From source file:ca.nanometrics.gflot.client.example.MarkingsExample.java
License:Open Source License
public Widget createExample() { final Label selectedPointLabel = new Label(INSTRUCTION); PlotWithOverviewModel model = new PlotWithOverviewModel(PlotModelStrategy.defaultStrategy()); PlotOptions plotOptions = new PlotOptions(); plotOptions.setDefaultLineSeriesOptions(new LineSeriesOptions().setLineWidth(1).setShow(true)); plotOptions.setDefaultPointsOptions(new PointsSeriesOptions().setRadius(2).setShow(true)); plotOptions.setDefaultShadowSize(1); plotOptions.setLegendOptions(new LegendOptions().setShow(false)); plotOptions.setSelectionOptions(new SelectionOptions().setDragging(true).setMode("x")); final PlotWithOverview plot = new PlotWithOverview(model, plotOptions); // add hover listener plot.addHoverListener(new PlotHoverListener() { public void onPlotHover(Plot plot, PlotPosition position, PlotItem item) { if (item != null) { selectedPointLabel .setText("x: " + item.getDataPoint().getX() + ", y: " + item.getDataPoint().getY()); } else { selectedPointLabel.setText(INSTRUCTION); }/*w w w . ja v a2s.co m*/ } }, false); plot.addSelectionListener(new SelectionListener() { public void selected(double x1, double y1, double x2, double y2) { plot.setLinearSelection(x1, x2); } }); SeriesHandler s = plot.getModel().addSeries("Series 1"); s.add(new DataPoint(1, 2)); s.add(new DataPoint(2, 5)); s.add(new DataPoint(3, 7)); s.add(new DataPoint(4, 5)); s.add(new DataPoint(5, 3)); s.add(new DataPoint(6, 2)); s.add(new DataPoint(7, 5)); s.add(new DataPoint(8, 7)); s.add(new DataPoint(9, 5)); s.add(new DataPoint(10, 3)); // Start of Marking Code Marking m = new Marking(); m.setX(new Range(2, 4)); m.setColor("#3BEFc3"); Marking m2 = new Marking(); m2.setX(new Range(5, 7)); m2.setColor("#cccccc"); Marking m3 = new Marking(); Range a = new Range(); a.setFrom(8); m3.setX(a); m3.setColor("#000000"); Markings ms = new Markings(); ms.addMarking(m); ms.addMarking(m2); ms.addMarking(m3); // End of Marking Code // Add Markings Objects to Grid Options plotOptions.setGridOptions(new GridOptions().setHoverable(true).setMarkings(ms)); plot.setHeight(250); plot.setOverviewHeight(60); FlowPanel panel = new FlowPanel() { @Override protected void onLoad() { super.onLoad(); plot.setLinearSelection(0, 10); plot.redraw(); } }; panel.add(selectedPointLabel); panel.add(plot); return panel; }
From source file:cc.alcina.framework.gwt.client.util.ClientUtils.java
License:Apache License
public static String trimToWidth(String s, String style, int pxWidth, String ellipsis) { if (pxWidth <= 20) { return s; }//from w w w .j av a 2 s . co m ellipsis = ellipsis == null ? "\u2026" : ellipsis; int r0 = 0; int r1 = s.length(); Label l = new Label(); setElementStyle(l.getElement(), style); Style cStyle = l.getElement().getStyle(); cStyle.setPosition(Position.ABSOLUTE); cStyle.setLeft(0, Unit.PX); cStyle.setTop(0, Unit.PX); cStyle.setDisplay(Display.INLINE_BLOCK); cStyle.setProperty("whitespace", "nowrap"); cStyle.setProperty("visibility", "hidden"); RootPanel.get().add(l); boolean tried = false; while (true) { int mid = (r1 - r0) / 2 + r0; String t = tried ? s.substring(0, mid) + ellipsis : s; l.setText(t); if (l.getOffsetWidth() <= pxWidth) { if (!tried || (r1 - r0) <= 1) { RootPanel.get().remove(l); return t; } r0 = mid; } else { if (!tried) { tried = true; } else { r1 = mid; } } } }
From source file:cc.kune.gspace.client.licensewizard.pages.LicenseWizardFirstForm.java
License:GNU Affero Public License
/** * Instantiates a new license wizard first form. * //ww w .j a va 2s. c o m * @param i18n * the i18n */ @Inject public LicenseWizardFirstForm(final I18nTranslationService i18n) { super.setFrame(true); super.setPadding(10); super.setAutoHeight(true); // super.setHeight(LicenseWizardView.HEIGHT); final Label intro = new Label(); intro.setText( i18n.t("Select the license you prefer using for sharing your group contents with other people:")); intro.addStyleName("kune-Margin-10-b"); final FieldSet fieldSet = new FieldSet(); // fieldSet.setTitle(i18n.t("license recommended")); fieldSet.addStyleName("margin-left: 105px"); fieldSet.setWidth(250); copyleftRadio = DefaultFormUtils.createRadio(fieldSet, i18n.t("Use a copyleft license (recommended)"), RADIO_FIELD_NAME, null, RADIO_COPYLEFT_ID); anotherLicenseRadio = DefaultFormUtils.createRadio(fieldSet, i18n.t("Use another kind of license (advanced)"), RADIO_FIELD_NAME, null, RADIO_ANOTHER_ID); final RadioGroup radioGroup = new RadioGroup(); radioGroup.add(copyleftRadio); radioGroup.add(anotherLicenseRadio); radioGroup.setOrientation(Orientation.VERTICAL); radioGroup.setHideLabel(true); radioGroup.addListener(Events.Change, new Listener<BaseEvent>() { @Override public void handleEvent(final BaseEvent be) { onChange.onCallback(); } }); final FieldSet infoFS = new FieldSet(); infoFS.setHeadingHtml("Info"); // infoFS.setFrame(false); // infoFS.setIcon("k-info-icon"); infoFS.setCollapsible(false); infoFS.setAutoHeight(true); final HTML recommendCopyleft = new HTML(); final HTML whyALicense = new HTML(); final HTML youCanChangeTheLicenseLater = new HTML(); recommendCopyleft.setHTML(POINT + i18n.t("We recommend [%s] licenses, specially for practical works", TextUtils.generateHtmlLink("http://en.wikipedia.org/wiki/Copyleft", i18n.t("copyleft")))); whyALicense.setHTML(POINT + TextUtils.generateHtmlLink("http://mirrors.creativecommons.org/getcreative/", i18n.t("Why do we need a license?"))); youCanChangeTheLicenseLater.setHTML(POINT + i18n.t("You can change this license later")); infoFS.addStyleName("kune-Margin-20-t"); add(intro); add(radioGroup); infoFS.add(recommendCopyleft); infoFS.add(whyALicense); infoFS.add(youCanChangeTheLicenseLater); add(infoFS); }
From source file:cc.kune.gspace.client.licensewizard.pages.LicenseWizardFrdForm.java
License:GNU Affero Public License
/** * Instantiates a new license wizard frd form. * * @param i18n//from www . jav a2s. c om * the i18n * @param session * the session */ @Inject public LicenseWizardFrdForm(final I18nTranslationService i18n, final Session session) { final Label intro = new Label(); intro.setText(i18n.t("Select other kind of licenses:")); intro.addStyleName("kune-Margin-10-b"); final ChosenOptions options = new ChosenOptions(); options.setNoResultsText(i18n.t("License not found")); options.setPlaceholderText(i18n.t("Select license")); options.setSearchContains(true); licenseChoose = new ChosenListBox(false, options); // First empty licenseChoose.addItem("", ""); for (final LicenseDTO license : session.getLicenses()) { if (!license.isCC()) { licenseChoose.addItem(license.getLongName(), license.getShortName()); } } licenseChoose.addChosenChangeHandler(new ChosenChangeHandler() { @Override public void onChange(final ChosenChangeEvent event) { onChange.onCallback(); } }); add(licenseChoose); }
From source file:cc.kune.gspace.client.licensewizard.pages.LicenseWizardSndForm.java
License:GNU Affero Public License
/** * Instantiates a new license wizard snd form. * /* ww w .jav a 2 s. co m*/ * @param i18n * the i18n */ @Inject public LicenseWizardSndForm(final I18nTranslationService i18n) { setFrame(true); super.setPadding(10); // super.setHeight(LicenseWizardView.HEIGHT); super.setAutoHeight(true); final Label intro = new Label(); intro.setText(i18n.t("Select the license type:")); intro.addStyleName("kune-Margin-10-b"); final FieldSet fieldSet = new FieldSet(); // fieldSet.setTitle("license type"); fieldSet.addStyleName("margin-left: 105px"); fieldSet.setWidth(250); commonLicensesRadio = DefaultFormUtils.createRadio(fieldSet, i18n.t("Common licenses for cultural works"), RADIO_FIELD_NAME, i18n.t("Select a Creative Commons license (recommended for cultural works)"), COMMON_LICENSES_ID); otherLicensesRadio = DefaultFormUtils.createRadio(fieldSet, i18n.t("Other kind of licenses"), RADIO_FIELD_NAME, i18n.t("Use the GNU licenses (recommended for free software works) and other kind of licenses"), OTHER_LICENSES_ID); add(intro); add(commonLicensesRadio); add(otherLicensesRadio); }