📄 showcase.java
字号:
/* * Copyright 2008 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.google.gwt.sample.showcase.client;import com.google.gwt.core.client.EntryPoint;import com.google.gwt.core.client.GWT;import com.google.gwt.dom.client.Element;import com.google.gwt.dom.client.HeadElement;import com.google.gwt.dom.client.Node;import com.google.gwt.dom.client.NodeList;import com.google.gwt.i18n.client.LocaleInfo;import com.google.gwt.sample.showcase.client.Application.ApplicationListener;import com.google.gwt.sample.showcase.client.content.i18n.CwConstantsExample;import com.google.gwt.sample.showcase.client.content.i18n.CwConstantsWithLookupExample;import com.google.gwt.sample.showcase.client.content.i18n.CwDateTimeFormat;import com.google.gwt.sample.showcase.client.content.i18n.CwDictionaryExample;import com.google.gwt.sample.showcase.client.content.i18n.CwMessagesExample;import com.google.gwt.sample.showcase.client.content.i18n.CwNumberFormat;import com.google.gwt.sample.showcase.client.content.lists.CwListBox;import com.google.gwt.sample.showcase.client.content.lists.CwMenuBar;import com.google.gwt.sample.showcase.client.content.lists.CwStackPanel;import com.google.gwt.sample.showcase.client.content.lists.CwSuggestBox;import com.google.gwt.sample.showcase.client.content.lists.CwTree;import com.google.gwt.sample.showcase.client.content.other.CwAnimation;import com.google.gwt.sample.showcase.client.content.other.CwCookies;import com.google.gwt.sample.showcase.client.content.panels.CwAbsolutePanel;import com.google.gwt.sample.showcase.client.content.panels.CwDecoratorPanel;import com.google.gwt.sample.showcase.client.content.panels.CwDisclosurePanel;import com.google.gwt.sample.showcase.client.content.panels.CwDockPanel;import com.google.gwt.sample.showcase.client.content.panels.CwFlowPanel;import com.google.gwt.sample.showcase.client.content.panels.CwHorizontalPanel;import com.google.gwt.sample.showcase.client.content.panels.CwHorizontalSplitPanel;import com.google.gwt.sample.showcase.client.content.panels.CwTabPanel;import com.google.gwt.sample.showcase.client.content.panels.CwVerticalPanel;import com.google.gwt.sample.showcase.client.content.panels.CwVerticalSplitPanel;import com.google.gwt.sample.showcase.client.content.popups.CwBasicPopup;import com.google.gwt.sample.showcase.client.content.popups.CwDialogBox;import com.google.gwt.sample.showcase.client.content.tables.CwFlexTable;import com.google.gwt.sample.showcase.client.content.tables.CwGrid;import com.google.gwt.sample.showcase.client.content.text.CwBasicText;import com.google.gwt.sample.showcase.client.content.text.CwRichText;import com.google.gwt.sample.showcase.client.content.widgets.CwBasicButton;import com.google.gwt.sample.showcase.client.content.widgets.CwCheckBox;import com.google.gwt.sample.showcase.client.content.widgets.CwCustomButton;import com.google.gwt.sample.showcase.client.content.widgets.CwFileUpload;import com.google.gwt.sample.showcase.client.content.widgets.CwHyperlink;import com.google.gwt.sample.showcase.client.content.widgets.CwRadioButton;import com.google.gwt.user.client.Command;import com.google.gwt.user.client.History;import com.google.gwt.user.client.HistoryListener;import com.google.gwt.user.client.Window;import com.google.gwt.user.client.ui.AbstractImagePrototype;import com.google.gwt.user.client.ui.ChangeListener;import com.google.gwt.user.client.ui.ClickListener;import com.google.gwt.user.client.ui.HTML;import com.google.gwt.user.client.ui.HasHorizontalAlignment;import com.google.gwt.user.client.ui.HasVerticalAlignment;import com.google.gwt.user.client.ui.HorizontalPanel;import com.google.gwt.user.client.ui.ListBox;import com.google.gwt.user.client.ui.RootPanel;import com.google.gwt.user.client.ui.TabBar;import com.google.gwt.user.client.ui.ToggleButton;import com.google.gwt.user.client.ui.Tree;import com.google.gwt.user.client.ui.TreeItem;import com.google.gwt.user.client.ui.VerticalPanel;import com.google.gwt.user.client.ui.Widget;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;/** * Entry point classes define <code>onModuleLoad()</code>. */public class Showcase implements EntryPoint { /** * The type passed into the * {@link com.google.gwt.sample.showcase.generator.ShowcaseGenerator}. */ private static final class GeneratorInfo { } /** * A special version of the ToggleButton that cannot be clicked if down. If * one theme button is pressed, all of the others are depressed. */ private static class ThemeButton extends ToggleButton { private static List<ThemeButton> allButtons = null; private String theme; public ThemeButton(String theme) { super(); this.theme = theme; addStyleName("sc-ThemeButton-" + theme); // Add this button to the static list if (allButtons == null) { allButtons = new ArrayList<ThemeButton>(); setDown(true); } allButtons.add(this); } public String getTheme() { return theme; } @Override protected void onClick() { if (!isDown()) { // Raise all of the other buttons for (ThemeButton button : allButtons) { if (button != this) { button.setDown(false); } } // Fire the click listeners super.onClick(); } } } /** * The static images used throughout the Showcase. */ public static final ShowcaseImages images = (ShowcaseImages) GWT.create(ShowcaseImages.class); /** * The current style theme. */ public static String CUR_THEME = ShowcaseConstants.STYLE_THEMES[0]; /** * Get the URL of the page, without an hash of query string. * * @return the location of the page */ private static native String getHostPageLocation() /*-{ var s = $doc.location.href; // Pull off any hash. var i = s.indexOf('#'); if (i != -1) s = s.substring(0, i); // Pull off any query string. i = s.indexOf('?'); if (i != -1) s = s.substring(0, i); // Ensure a final slash if non-empty. return s; }-*/; /** * The {@link Application}. */ private Application app = new Application(); /** * A mapping of history tokens to their associated menu items. */ private Map<String, TreeItem> itemTokens = new HashMap<String, TreeItem>(); /** * A mapping of menu items to the widget display when the item is selected. */ private Map<TreeItem, ContentWidget> itemWidgets = new HashMap<TreeItem, ContentWidget>(); /** * This is the entry point method. */ public void onModuleLoad() { // Generate the source code and css for the examples GWT.create(GeneratorInfo.class); // Create the constants ShowcaseConstants constants = (ShowcaseConstants) GWT.create(ShowcaseConstants.class); // Swap out the style sheets for the RTL versions if needed. updateStyleSheets(); // Create the application setupTitlePanel(constants); setupMainLinks(constants); setupOptionsPanel(); setupMainMenu(constants); // Setup a history listener to reselect the associate menu item final HistoryListener historyListener = new HistoryListener() { public void onHistoryChanged(String historyToken) { TreeItem item = itemTokens.get(historyToken); if (item == null) { item = app.getMainMenu().getItem(0).getChild(0); } // Select the associated TreeItem app.getMainMenu().setSelectedItem(item, false); app.getMainMenu().ensureSelectedItemVisible(); // Show the associated ContentWidget displayContentWidget(itemWidgets.get(item)); } }; History.addHistoryListener(historyListener); // Add an listener that sets the content widget when a menu item is selected app.setListener(new ApplicationListener() { public void onMenuItemSelected(TreeItem item) { ContentWidget content = itemWidgets.get(item); if (content != null && !content.equals(app.getContent())) { History.newItem(getContentWidgetToken(content)); } } }); // Show the initial example String initToken = History.getToken(); if (initToken.length() > 0) { historyListener.onHistoryChanged(initToken); } else { // Use the first token available TreeItem firstItem = app.getMainMenu().getItem(0).getChild(0); app.getMainMenu().setSelectedItem(firstItem, false); app.getMainMenu().ensureSelectedItemVisible(); displayContentWidget(itemWidgets.get(firstItem)); } } /** * Set the content to the {@link ContentWidget}. * * @param content the {@link ContentWidget} to display */ private void displayContentWidget(ContentWidget content) { if (content != null) { app.setContent(content); app.setContentTitle(content.getTabBar()); } } /** * Get the token for a given content widget. * * @return the content widget token. */ private String getContentWidgetToken(ContentWidget content) { String className = content.getClass().getName(); className = className.substring(className.lastIndexOf('.') + 1); return className; } /** * Get the style name of the reference element defined in the current GWT * theme style sheet. * * @param prefix the prefix of the reference style name * @return the style name */ private String getCurrentReferenceStyleName(String prefix) { String gwtRef = prefix + "-Reference-" + CUR_THEME; if (LocaleInfo.getCurrentLocale().isRTL()) { gwtRef += "-rtl"; } return gwtRef; } /** * Create the main links at the top of the application. * * @param constants the constants with text */ private void setupMainLinks(ShowcaseConstants constants) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -