Author: al Date: Sat Jun 8 11:06:48 2013 New Revision: 1490957 URL: http://svn.apache.org/r1490957 Log: WAVE-270: Add color and backcolor buttons to edit toolbar
By Vicente J. Ruiz Jurado https://reviews.apache.org/r/9841/ Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/AbstractColorPicker.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorHelper.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorPopup.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.css (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/OnColorChooseListener.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SampleCustomColorPicker.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.css (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages.java (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_en.properties (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_es.properties (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/backcolor.png (with props) incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/color.png (with props) Modified: incubator/wave/trunk/src/org/waveprotocol/wave/client/testing/UndercurrentHarness.java incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.css incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditorToolbarResources.java Modified: incubator/wave/trunk/src/org/waveprotocol/wave/client/testing/UndercurrentHarness.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/testing/UndercurrentHarness.java?rev=1490957&r1=1490956&r2=1490957&view=diff ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/testing/UndercurrentHarness.java (original) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/testing/UndercurrentHarness.java Sat Jun 8 11:06:48 2013 @@ -41,6 +41,8 @@ import org.waveprotocol.wave.client.conc import org.waveprotocol.wave.client.util.ClientFlags; import org.waveprotocol.wave.client.util.NullTypedSource; import org.waveprotocol.wave.client.util.OverridingTypedSource; +import org.waveprotocol.wave.client.wavepanel.impl.toolbar.color.ComplexColorPicker; +import org.waveprotocol.wave.client.wavepanel.impl.toolbar.color.SampleCustomColorPicker; import org.waveprotocol.wave.common.bootstrap.FlagConstants; import org.waveprotocol.wave.concurrencycontrol.channel.WaveViewService; import org.waveprotocol.wave.model.conversation.Conversation; @@ -203,6 +205,9 @@ public class UndercurrentHarness impleme .withBoolean(FlagConstants.ENABLE_UNDERCURRENT_EDITING, true) .build()); + // Only for test additional color pickers + new SampleCustomColorPicker(ComplexColorPicker.getInstance()); + return new StageThree.DefaultProvider(two) { @Override protected void onStageInit() { Modified: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.css URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.css?rev=1490957&r1=1490956&r2=1490957&view=diff ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.css (original) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.css Sat Jun 8 11:06:48 2013 @@ -15,6 +15,14 @@ * author: [email protected] (Pat Coleman) */ +@sprite .backcolor { + gwt-image: 'backcolor'; +} + +@sprite .color { + gwt-image: 'color'; +} + @sprite .bold { gwt-image: 'bold'; } Modified: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java?rev=1490957&r1=1490956&r2=1490957&view=diff ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java (original) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java Sat Jun 8 11:06:48 2013 @@ -20,13 +20,11 @@ package org.waveprotocol.wave.client.wavepanel.impl.toolbar; import com.google.common.base.Preconditions; -import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.http.client.URL; -import org.waveprotocol.wave.client.doodad.link.Link; import org.waveprotocol.wave.client.editor.Editor; import org.waveprotocol.wave.client.editor.EditorContext; import org.waveprotocol.wave.client.editor.EditorContextAdapter; @@ -43,6 +41,7 @@ import org.waveprotocol.wave.client.edit import org.waveprotocol.wave.client.editor.util.EditorAnnotationUtil; import org.waveprotocol.wave.client.gadget.GadgetXmlUtil; import org.waveprotocol.wave.client.wavepanel.impl.toolbar.attachment.AttachmentPopupWidget; +import org.waveprotocol.wave.client.wavepanel.impl.toolbar.color.ColorHelper; import org.waveprotocol.wave.client.wavepanel.impl.toolbar.gadget.GadgetInfoProviderImpl; import org.waveprotocol.wave.client.wavepanel.impl.toolbar.gadget.GadgetSelectorWidget; import org.waveprotocol.wave.client.wavepanel.impl.toolbar.gadget.GwtGadgetInfoParser; @@ -159,6 +158,10 @@ public class EditToolbar { createHeadingButton(group); group = toolbarUi.addGroup(); + createFontColorButton(group); + createFontBackColorButton(group); + + group = toolbarUi.addGroup(); createIndentButton(group); createOutdentButton(group); @@ -202,6 +205,28 @@ public class EditToolbar { .applyTo(b, createTextSelectionController(b, "textDecoration", "underline")); } + private void createFontBackColorButton(ToolbarView toolbar) { + final ToolbarClickButton button = toolbar.addClickButton(); + new ToolbarButtonViewBuilder() + .setIcon(css.backcolor()) + .applyTo(button, new ToolbarClickButton.Listener() { + @Override public void onClicked() { + ColorHelper.onSetBackColor(editor, button); + } + }); + } + + private void createFontColorButton(ToolbarView toolbar) { + final ToolbarClickButton button = toolbar.addClickButton(); + new ToolbarButtonViewBuilder() + .setIcon(css.color()) + .applyTo(button, new ToolbarClickButton.Listener() { + @Override public void onClicked() { + ColorHelper.onSetColor(editor, button); + } + }); + } + private void createStrikethroughButton(ToolbarView toolbar) { ToolbarToggleButton b = toolbar.addToggleButton(); new ToolbarButtonViewBuilder() Modified: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditorToolbarResources.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditorToolbarResources.java?rev=1490957&r1=1490956&r2=1490957&view=diff ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditorToolbarResources.java (original) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditorToolbarResources.java Sat Jun 8 11:06:48 2013 @@ -32,6 +32,8 @@ import com.google.gwt.resources.client.I */ public interface EditorToolbarResources extends ClientBundle { interface Css extends CssResource { + String color(); + String backcolor(); String bold(); String italic(); String underline(); @@ -57,6 +59,8 @@ public interface EditorToolbarResources String insertAttachment(); } + @Source("images/edit/backcolor.png") ImageResource backcolor(); + @Source("images/edit/color.png") ImageResource color(); @Source("images/edit/bold.png") ImageResource bold(); @Source("images/edit/italic.png") ImageResource italic(); @Source("images/edit/underline.png") ImageResource underline(); Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/AbstractColorPicker.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/AbstractColorPicker.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/AbstractColorPicker.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/AbstractColorPicker.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color; + +import com.google.gwt.user.client.ui.Composite; + +/** + * The Class AbstractColorPicker is used to extend in a simple way + * {@link ComplexColorPicker}. + * + * @author [email protected] (Vicente J. Ruiz Jurado) + */ +public abstract class AbstractColorPicker extends Composite { + + protected final ComplexColorPicker colorPicker; + + public AbstractColorPicker(ComplexColorPicker colorPicker) { + this.colorPicker = colorPicker; + } + + protected void onColorChoose(String color) { + colorPicker.onColorChoose(color); + } +} Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/AbstractColorPicker.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorHelper.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorHelper.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorHelper.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorHelper.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color; + +import com.google.gwt.user.client.Window; + +import org.waveprotocol.wave.client.editor.EditorContext; +import org.waveprotocol.wave.client.editor.content.misc.StyleAnnotationHandler; +import org.waveprotocol.wave.client.editor.util.EditorAnnotationUtil; +import org.waveprotocol.wave.client.widget.toolbar.buttons.ToolbarClickButton; +import org.waveprotocol.wave.model.document.util.FocusedRange; +import org.waveprotocol.wave.model.document.util.Range; + +/** + * The Class ColorHelper is a utility for manage text colors of a wave + * while editing a document via the toolbar or via shortcuts. + * + * @author [email protected] (Vicente J. Ruiz Jurado) + */ +public class ColorHelper { + + /** + * On set color of document selection. + * + * @param editor the editor + * @param button the button (to show a popup near it) + */ + public static void onSetColor(EditorContext editor, ToolbarClickButton button) { + showPopup(editor, button, "color", false); + } + + /** + * On set back color of document selection. + * + * @param editor the editor + * @param button the button (to show a popup near it) + */ + public static void onSetBackColor(final EditorContext editor, ToolbarClickButton button) { + showPopup(editor, button, "backgroundColor", true); + } + + /** + * Show popup with a color picker and set/clear the color on the range. + * + * @param editor the editor + * @param button the button + * @param suffix the key suffix + * @param allowNone the allow none color (in background color) + */ + private static void showPopup(final EditorContext editor, ToolbarClickButton button, + final String suffix, boolean allowNone) { + FocusedRange focusedRange = editor.getSelectionHelper().getSelectionRange(); + if (focusedRange == null) { + // Lets try to focus + editor.focus(false); + } + focusedRange = editor.getSelectionHelper().getSelectionRange(); + if (focusedRange == null) { + Window.alert(ComplexColorPicker.messages.selectSomeText()); + return; + } + final Range range = focusedRange.asRange(); + final ColorPopup popup = new ColorPopup(button.getButton().hackGetWidget().getElement(), allowNone); + popup.show(new OnColorChooseListener() { + @Override + public void onColorChoose(String color) { + EditorAnnotationUtil. + setAnnotationOverRange(editor.getDocument(), editor.getCaretAnnotations(), + StyleAnnotationHandler.key(suffix), color, range.getStart(), range.getEnd()); + popup.hide(); + editor.focus(false); + } + + @Override + public void onNoneColorChoose() { + EditorAnnotationUtil. + clearAnnotationsOverRange(editor.getDocument(), editor.getCaretAnnotations(), + new String[] {StyleAnnotationHandler.key(suffix)}, range.getStart(), range.getEnd()); + popup.hide(); + editor.focus(false); + }}); + } +} Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorHelper.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorPopup.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorPopup.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorPopup.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorPopup.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color; + +import com.google.gwt.dom.client.Element; + +import org.waveprotocol.wave.client.widget.popup.AlignedPopupPositioner; +import org.waveprotocol.wave.client.widget.popup.PopupChrome; +import org.waveprotocol.wave.client.widget.popup.PopupChromeFactory; +import org.waveprotocol.wave.client.widget.popup.PopupFactory; +import org.waveprotocol.wave.client.widget.popup.UniversalPopup; + +/** + * The Class ColorPopup shows a popup with a extensible color picker. + * + * @author [email protected] (Vicente J. Ruiz Jurado) + */ +public class ColorPopup { + + /** The extensible color picker. */ + private ComplexColorPicker colorPicker; + + /** The popup. */ + private UniversalPopup popup; + + /** + * Instantiates a new color popup. + * + * @param relative the relative + * @param allowNone the allow none + */ + public ColorPopup(Element relative, boolean allowNone) { + colorPicker = ComplexColorPicker.getInstance(); + colorPicker.setAllowNone(allowNone); + PopupChrome chrome = PopupChromeFactory.createPopupChrome(); + popup = PopupFactory.createPopup(relative, AlignedPopupPositioner.ABOVE_RIGHT, chrome, true); + popup.add(colorPicker); + } + + /** + * Show the popup with the color picker. + * + * @param listener the listener + */ + public void show(OnColorChooseListener listener) { + colorPicker.setListener(listener); + colorPicker.show(); + popup.show(); + } + + /** + * Hide the popup with the color picker. + */ + public void hide() { + popup.hide(); + } +} Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ColorPopup.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.css URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.css?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.css (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.css Sat Jun 8 11:06:48 2013 @@ -0,0 +1,59 @@ +/* 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. + * + * CSS Stylesheet for blips. + * + * author: [email protected] (Vicente J. Ruiz Jurado) + */ + +@external .customColorPushbutton, .customColorPushbutton-down-hovering, .customColorPushbutton-up-hovering; + +.fl { + float: left; +} + +.fr { + float: right; +} + +.toolbar { + margin: 0 10px; + cursor: hand; + cursor: pointer; +} + +.buttonsMargins { + margin: -10px 10px 10px; +} + +.margins { + margin: 10px; +} + +button.toolbar { + margin-top: 10px; + cursor: hand; + cursor: pointer; +} + +.customColorPushbutton { + cursor: hand; + cursor: pointer; + padding: 5px; +} + +.customColorPushbutton-down-hovering { +} + +.customColorPushbutton-up-hovering { + background-color: #F2F2F2; +} \ No newline at end of file Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.css ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,170 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.CssResource; +import com.google.gwt.user.client.ui.DeckPanel; +import com.google.gwt.user.client.ui.IsWidget; +import com.google.gwt.user.client.ui.PushButton; +import com.google.gwt.user.client.ui.VerticalPanel; + +import org.waveprotocol.wave.client.wavepanel.impl.toolbar.color.i18n.ColorPickerMessages; + +/** + * The Class ComplexColorPicker is used to show a simple color picker but can be + * extensible with other color pickers. See {@link SampleCustomColorPicker}. + * + * @author [email protected] (Vicente J. Ruiz Jurado) + */ +public class ComplexColorPicker extends DeckPanel { + + /** Resources used by this widget. */ + public interface Resources extends ClientBundle { + + @Source("ComplexColorPicker.css") + Style style(); + } + + /** The Constant messages. */ + public static final ColorPickerMessages messages = GWT.create(ColorPickerMessages.class); + + /** + * The Interface Style. + */ + public interface Style extends CssResource { + + String fl(); + + String fr(); + + String margins(); + + String buttonsMargins(); + + String toolbar(); + + String customColorPushbutton(); + + } + + /** The instance. */ + private static ComplexColorPicker instance; + + /** + * Gets the single instance of ComplexColorPicker (singleton in the + * WebClient). + * + * @return single instance of ComplexColorPicker + */ + public static ComplexColorPicker getInstance() { + if (instance != null) { + return instance; + } + instance = new ComplexColorPicker(); + return instance; + } + + /** The CSS style. */ + final public static Style style = GWT.<Resources> create(Resources.class).style(); + + private OnColorChooseListener listener; + private SimpleColorPicker simplePicker; + private VerticalPanel vp; + private PushButton noneBtn; + + public ComplexColorPicker() { + style.ensureInjected(); + + // The background color can be set to "none" + noneBtn = new PushButton(messages.none()); + noneBtn.addStyleName(ComplexColorPicker.style.buttonsMargins()); + noneBtn.setStylePrimaryName(ComplexColorPicker.style.customColorPushbutton()); + noneBtn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + listener.onNoneColorChoose(); + } + }); + + vp = new VerticalPanel(); + + // We use a simple color picker by default + simplePicker = new SimpleColorPicker(this); + vp.add(simplePicker); + vp.add(noneBtn); + super.add(vp); + } + + /** + * Sets the listener. + * + * @param listener the new listener + */ + public void setListener(OnColorChooseListener listener) { + this.listener = listener; + } + + /** + * On color choose. + * + * @param color the color + */ + public void onColorChoose(String color) { + listener.onColorChoose(color); + } + + /** + * Show. + */ + public void show() { + this.showWidget(0); + } + + /** + * Adds an additional color pickers (to the DeckPanel). + * + * @param colorPicker the widget + */ + public void addColorPicker(AbstractColorPicker colorPicker) { + super.add(colorPicker); + } + + /** + * Adds the widget to bottom (useful to add buttons). + * + * @param widget the widget + */ + public void addToBottom(IsWidget widget) { + vp.add(widget); + } + + /** + * Sets the allow none (if the none button is visible or not). + * + * @param allowNone the new allow none + */ + public void setAllowNone(boolean allowNone) { + noneBtn.setVisible(allowNone); + } + +} Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/ComplexColorPicker.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/OnColorChooseListener.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/OnColorChooseListener.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/OnColorChooseListener.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/OnColorChooseListener.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color; + +/** + * The listener interface for receiving onColorChoose events. + * + * @author [email protected] (Vicente J. Ruiz Jurado) + */ +public interface OnColorChooseListener { + + void onColorChoose(String color); + + void onNoneColorChoose(); + +} Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/OnColorChooseListener.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SampleCustomColorPicker.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SampleCustomColorPicker.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SampleCustomColorPicker.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SampleCustomColorPicker.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,103 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color; + +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.event.dom.client.KeyUpEvent; +import com.google.gwt.event.dom.client.KeyUpHandler; +import com.google.gwt.user.client.ui.PushButton; +import com.google.gwt.user.client.ui.TextBox; + +/** + * The Class SampleCustomColorPicker is a sample of how the ColorPicker can + * extended with other color pickers. + * + * @author [email protected] (Vicente J. Ruiz Jurado) + */ +public class SampleCustomColorPicker extends AbstractColorPicker { + + /** The textbox used in this sample to set hex colors. */ + private TextBox textbox; + + /** + * Instantiates a new sample custom color picker. + * + * @param colorPicker the color picker + */ + public SampleCustomColorPicker(final ComplexColorPicker colorPicker) { + super(colorPicker); + textbox = new TextBox(); + textbox.setVisibleLength(8); + textbox.setValue("#000000"); + textbox.addStyleName(ComplexColorPicker.style.margins()); + + PushButton custom = new PushButton("Custom..."); + custom.addStyleName(ComplexColorPicker.style.buttonsMargins()); + custom.setStylePrimaryName(ComplexColorPicker.style.customColorPushbutton()); + custom.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + // ComplexColorPicker is a DeckPanel, so we show our widget + colorPicker.showWidget(1); + textbox.setFocus(true); + textbox.selectAll(); + } + }); + + textbox.addChangeHandler(new ChangeHandler() { + @Override + public void onChange(ChangeEvent event) { + chooseColor(); + } + }); + + textbox.addKeyUpHandler(new KeyUpHandler() { + @Override + public void onKeyUp(final KeyUpEvent event) { + if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { + if (textbox.getText().length() > 0) { + chooseColor(); + } + } + } + }); + + initWidget(textbox); + setWidth("50px"); + + // We add the button and the panel to the ComplexColorPicker (the button + // opens the panel) + colorPicker.addToBottom(custom); + colorPicker.addColorPicker(this); + + } + + /** + * Choose the color of the textbox. + */ + private void chooseColor() { + onColorChoose(textbox.getValue()); + } + +} Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SampleCustomColorPicker.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.css URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.css?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.css (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.css Sat Jun 8 11:06:48 2013 @@ -0,0 +1,40 @@ +/* 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. + * + * CSS Stylesheet for blips. + * + * author: [email protected] (Vicente J. Ruiz Jurado) + */ + +@external .simplecolorbutton, .simplecolorbutton-down-hovering, .simplecolorbutton-up-hovering; + +.grid { + margin: 10px; +} + +tr.firstRow>td { + padding-bottom: 6px; +} + +.simplecolorbutton { + cursor: hand; + cursor: pointer; + border: 1px solid transparent; +} + +.simplecolorbutton-down-hovering { + border: 1px solid red; +} + +.simplecolorbutton-up-hovering { + border: 1px solid black; +} \ No newline at end of file Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.css ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,139 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.CssResource; +import com.google.gwt.user.client.ui.Grid; +import com.google.gwt.user.client.ui.HTMLTable.Cell; +import com.google.gwt.user.client.ui.PushButton; +import com.google.gwt.user.client.ui.Widget; + +/** + * The Class SimpleColorPicker implements a color picker similar to the Google docs one. + */ +public class SimpleColorPicker extends AbstractColorPicker { + + /** The Constant COLS. */ + private static final int COLS = 10; + + /** The Constant ROWS. */ + private static final int ROWS = 8; + + /** Resources used by this widget. */ + public interface Resources extends ClientBundle { + @Source("SimpleColorPicker.css") + Style style(); + } + + + /** + * The Interface Style. + */ + interface Style extends CssResource { + + String grid(); + + String firstRow(); + + String simplecolorbutton(); + + } + + /** The Constant COLORS. */ + private static final String[] COLORS = new String[] { "rgb(0, 0, 0)", "rgb(67, 67, 67)", + "rgb(102, 102, 102)", "rgb(153, 153, 153)", "rgb(183, 183, 183)", "rgb(204, 204, 204)", + "rgb(217, 217, 217)", "rgb(239, 239, 239)", "rgb(243, 243, 243)", "rgb(255, 255, 255)", + "rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)", + "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)", + "rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", + "rgb(217, 234, 211)", "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", + "rgb(217, 210, 233)", "rgb(234, 209, 220)", "rgb(221, 126, 107)", "rgb(234, 153, 153)", + "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)", "rgb(162, 196, 201)", + "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)", + "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", + "rgb(147, 196, 125)", "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", + "rgb(142, 124, 195)", "rgb(194, 123, 160)", "rgb(166, 28, 0)", "rgb(204, 0, 0)", + "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)", "rgb(69, 129, 142)", + "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)", + "rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)", + "rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)", + "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)", + "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)" }; + + /** The Constant CELL_SIZE defines the size of each color button. */ + private static final String CELL_SIZE = "13px"; + + /** The Constant style. */ + final static Style style = GWT.<Resources> create(Resources.class).style(); + + /** + * Instantiates a new simple color picker. + * + * @param colopicker the colopicker + */ + public SimpleColorPicker(ComplexColorPicker colopicker) { + super(colopicker); + style.ensureInjected(); + + final Grid grid = new Grid(ROWS, COLS); + grid.setCellSpacing(0); + grid.getRowFormatter().getElement(0).addClassName(style.firstRow()); + grid.getRowFormatter().getElement(1).addClassName(style.firstRow()); + int row; + int col; + int num = 0; + for (final String c : COLORS) { + row = num / COLS; + col = num % COLS; + grid.setWidget(row, col, createCell(c)); + num++; + } + grid.addClickHandler(new ClickHandler() { + public void onClick(final ClickEvent event) { + Cell cell = grid.getCellForEvent(event); + if (cell != null) { + String color = COLORS[cell.getRowIndex() * COLS + cell.getCellIndex()]; + onColorChoose(color); + } + } + }); + grid.addStyleName(style.grid()); + initWidget(grid); + } + + /** + * Creates the cell for each color. + * + * @param color the color + * @return the widget + */ + private Widget createCell(final String color) { + final PushButton button = new PushButton(); + button.setStylePrimaryName(style.simplecolorbutton()); + button.setSize(CELL_SIZE, CELL_SIZE); + button.getElement().getStyle().setBackgroundColor(color); + return button; + } + +} Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/SimpleColorPicker.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages.java URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages.java?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages.java (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages.java Sat Jun 8 11:06:48 2013 @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.waveprotocol.wave.client.wavepanel.impl.toolbar.color.i18n; + +import com.google.gwt.i18n.client.Messages; + +public interface ColorPickerMessages extends Messages { + @DefaultMessage("Custom...") + String custom(); + + @DefaultMessage("None") + String none(); + + @DefaultMessage("Select some text to change the color") + String selectSomeText(); +} \ No newline at end of file Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_en.properties URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_en.properties?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_en.properties (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_en.properties Sat Jun 8 11:06:48 2013 @@ -0,0 +1,5 @@ +custom = Custom... + +none = None + +selectSomeText = Select some text to change the color \ No newline at end of file Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_en.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_es.properties URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_es.properties?rev=1490957&view=auto ============================================================================== --- incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_es.properties (added) +++ incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_es.properties Sat Jun 8 11:06:48 2013 @@ -0,0 +1,5 @@ +custom = Otro... + +none = Ninguno + +selectSomeText = Selecciona un text para cambiarle el color \ No newline at end of file Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/color/i18n/ColorPickerMessages_es.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/backcolor.png URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/backcolor.png?rev=1490957&view=auto ============================================================================== Binary file - no diff available. Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/backcolor.png ------------------------------------------------------------------------------ svn:mime-type = image/png Added: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/color.png URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/color.png?rev=1490957&view=auto ============================================================================== Binary file - no diff available. Propchange: incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/images/edit/color.png ------------------------------------------------------------------------------ svn:mime-type = image/png
