📄 showcase.java
字号:
// Link to GWT Homepage app.addLink(new HTML("<a href=\"" + ShowcaseConstants.GWT_HOMEPAGE + "\">" + constants.mainLinkHomepage() + "</a>")); // Link to More Examples app.addLink(new HTML("<a href=\"" + ShowcaseConstants.GWT_EXAMPLES + "\">" + constants.mainLinkExamples() + "</a>")); } /** * Setup all of the options in the main menu. * * @param constants the constant values to use */ private void setupMainMenu(ShowcaseConstants constants) { Tree mainMenu = app.getMainMenu(); // Widgets TreeItem catWidgets = mainMenu.addItem(constants.categoryWidgets()); setupMainMenuOption(catWidgets, new CwCheckBox(constants), images.catWidgets()); setupMainMenuOption(catWidgets, new CwRadioButton(constants), images.catWidgets()); setupMainMenuOption(catWidgets, new CwBasicButton(constants), images.catWidgets()); setupMainMenuOption(catWidgets, new CwCustomButton(constants), images.catWidgets()); setupMainMenuOption(catWidgets, new CwFileUpload(constants), images.catWidgets()); setupMainMenuOption(catWidgets, new CwHyperlink(constants), images.catWidgets()); // Lists TreeItem catLists = mainMenu.addItem(constants.categoryLists()); setupMainMenuOption(catLists, new CwListBox(constants), images.catLists()); setupMainMenuOption(catLists, new CwSuggestBox(constants), images.catLists()); setupMainMenuOption(catLists, new CwTree(constants), images.catLists()); setupMainMenuOption(catLists, new CwMenuBar(constants), images.catLists()); setupMainMenuOption(catLists, new CwStackPanel(constants), images.catLists()); // Text TreeItem catText = mainMenu.addItem(constants.categoryTextInput()); setupMainMenuOption(catText, new CwBasicText(constants), images.catTextInput()); setupMainMenuOption(catText, new CwRichText(constants), images.catTextInput()); // Popups TreeItem catPopup = mainMenu.addItem(constants.categoryPopups()); setupMainMenuOption(catPopup, new CwBasicPopup(constants), images.catPopups()); setupMainMenuOption(catPopup, new CwDialogBox(constants), images.catPopups()); // Panels TreeItem catPanels = mainMenu.addItem(constants.categoryPanels()); setupMainMenuOption(catPanels, new CwDecoratorPanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwFlowPanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwHorizontalPanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwVerticalPanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwAbsolutePanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwDockPanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwDisclosurePanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwTabPanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwHorizontalSplitPanel(constants), images.catPanels()); setupMainMenuOption(catPanels, new CwVerticalSplitPanel(constants), images.catPanels()); // Tables TreeItem catTables = mainMenu.addItem(constants.categoryTables()); setupMainMenuOption(catTables, new CwGrid(constants), images.catTables()); setupMainMenuOption(catTables, new CwFlexTable(constants), images.catTables()); // Internationalization TreeItem catI18N = mainMenu.addItem(constants.categoryI18N()); setupMainMenuOption(catI18N, new CwNumberFormat(constants), images.catI18N()); setupMainMenuOption(catI18N, new CwDateTimeFormat(constants), images.catI18N()); setupMainMenuOption(catI18N, new CwMessagesExample(constants), images.catI18N()); setupMainMenuOption(catI18N, new CwConstantsExample(constants), images.catI18N()); setupMainMenuOption(catI18N, new CwConstantsWithLookupExample(constants), images.catI18N()); setupMainMenuOption(catI18N, new CwDictionaryExample(constants), images.catI18N()); // Other TreeItem catOther = mainMenu.addItem(constants.categoryOther()); setupMainMenuOption(catOther, new CwAnimation(constants), images.catOther()); setupMainMenuOption(catOther, new CwCookies(constants), images.catOther()); } /** * Add an option to the main menu. * * @param parent the {@link TreeItem} that is the option * @param content the {@link ContentWidget} to display when selected * @param image the icon to display next to the {@link TreeItem} */ private void setupMainMenuOption(TreeItem parent, ContentWidget content, AbstractImagePrototype image) { // Create the TreeItem TreeItem option = parent.addItem(image.getHTML() + " " + content.getName()); // Map the item to its history token and content widget itemWidgets.put(option, content); itemTokens.put(getContentWidgetToken(content), option); } /** * Create the options that appear next to the title. */ private void setupOptionsPanel() { VerticalPanel vPanel = new VerticalPanel(); vPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); if (LocaleInfo.getCurrentLocale().isRTL()) { vPanel.getElement().setAttribute("align", "left"); } else { vPanel.getElement().setAttribute("align", "right"); } app.setOptionsWidget(vPanel); // Add the option to change the locale final ListBox localeBox = new ListBox(); String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName(); if (currentLocale.equals("default")) { currentLocale = "en"; } String[] localeNames = LocaleInfo.getAvailableLocaleNames(); for (String localeName : localeNames) { if (!localeName.equals("default")) { String nativeName = LocaleInfo.getLocaleNativeDisplayName(localeName); localeBox.addItem(nativeName, localeName); if (localeName.equals(currentLocale)) { localeBox.setSelectedIndex(localeBox.getItemCount() - 1); } } } localeBox.addChangeListener(new ChangeListener() { public void onChange(Widget sender) { String localeName = localeBox.getValue(localeBox.getSelectedIndex()); Window.open(getHostPageLocation() + "?locale=" + localeName, "_self", ""); } }); HorizontalPanel localeWrapper = new HorizontalPanel(); localeWrapper.add(images.locale().createImage()); localeWrapper.add(localeBox); vPanel.add(localeWrapper); // Add the option to change the style final HorizontalPanel styleWrapper = new HorizontalPanel(); vPanel.add(styleWrapper); for (int i = 0; i < ShowcaseConstants.STYLE_THEMES.length; i++) { final ThemeButton button = new ThemeButton( ShowcaseConstants.STYLE_THEMES[i]); styleWrapper.add(button); button.addClickListener(new ClickListener() { public void onClick(Widget sender) { // Update the current theme CUR_THEME = button.getTheme(); // Reload the current tab, loading the new theme if necessary TabBar bar = ((TabBar) app.getContentTitle()); bar.selectTab(bar.getSelectedTab()); // Load the new style sheets updateStyleSheets(); } }); } } /** * Create the title bar at the top of the application. * * @param constants the constant values to use */ private void setupTitlePanel(ShowcaseConstants constants) { // Get the title from the internationalized constants String pageTitle = "<h1>" + constants.mainTitle() + "</h1><h2>" + constants.mainSubTitle() + "</h2>"; // Add the title and some images to the title bar HorizontalPanel titlePanel = new HorizontalPanel(); titlePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); titlePanel.add(images.gwtLogo().createImage()); titlePanel.add(new HTML(pageTitle)); app.setTitleWidget(titlePanel); } /** * Update the style sheets to reflect the current theme and direction. */ private void updateStyleSheets() { // Generate the names of the style sheets to include String gwtStyleSheet = "gwt/" + CUR_THEME + "/" + CUR_THEME + ".css"; String showcaseStyleSheet = CUR_THEME + "/Showcase.css"; if (LocaleInfo.getCurrentLocale().isRTL()) { gwtStyleSheet = gwtStyleSheet.replace(".css", "_rtl.css"); showcaseStyleSheet = showcaseStyleSheet.replace(".css", "_rtl.css"); } // Find existing style sheets that need to be removed boolean styleSheetsFound = false; final HeadElement headElem = StyleSheetLoader.getHeadElement(); final List<Element> toRemove = new ArrayList<Element>(); NodeList<Node> children = headElem.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.getItem(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element elem = Element.as(node); if (elem.getTagName().equalsIgnoreCase("link") && elem.getPropertyString("rel").equalsIgnoreCase("stylesheet")) { styleSheetsFound = true; String href = elem.getPropertyString("href"); // If the correct style sheets are already loaded, then we should have // nothing to remove. if (!href.contains(gwtStyleSheet) && !href.contains(showcaseStyleSheet)) { toRemove.add(elem); } } } } // Return if we already have the correct style sheets if (styleSheetsFound && toRemove.size() == 0) { return; } // Detach the app while we manipulate the styles to avoid rendering issues RootPanel.get().remove(app); // Remove the old style sheets for (Element elem : toRemove) { headElem.removeChild(elem); } // Load the GWT theme style sheet String modulePath = GWT.getModuleBaseURL(); Command callback = new Command() { /** * The number of style sheets that have been loaded and executed this * command. */ private int numStyleSheetsLoaded = 0; public void execute() { // Wait until all style sheets have loaded before re-attaching the app numStyleSheetsLoaded++; if (numStyleSheetsLoaded < 2) { return; } // Different themes use different background colors for the body // element, but IE only changes the background of the visible content // on the page instead of changing the background color of the entire // page. By changing the display style on the body element, we force // IE to redraw the background correctly. RootPanel.getBodyElement().getStyle().setProperty("display", "none"); RootPanel.getBodyElement().getStyle().setProperty("display", ""); RootPanel.get().add(app); } }; StyleSheetLoader.loadStyleSheet(modulePath + gwtStyleSheet, getCurrentReferenceStyleName("gwt"), callback); // Load the showcase specific style sheet after the GWT theme style sheet so // that custom styles supercede the theme styles. StyleSheetLoader.loadStyleSheet(modulePath + showcaseStyleSheet, getCurrentReferenceStyleName("Application"), callback); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -