/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.gwt.wysiwyg.client.plugin.symbol;
import org.xwiki.gwt.user.client.ui.CompositeDialogBox;
import org.xwiki.gwt.wysiwyg.client.Images;
import org.xwiki.gwt.wysiwyg.client.Strings;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Image;
/**
* A popup panel which allows you to pick a symbol from a symbol palette by clicking on that symbol.
*
* @version $Id: 3d70c4e572c88e5fd34eaf0587fc1d9a4a5c6eb9 $
*/
public class SymbolPicker extends CompositeDialogBox implements SelectionHandler<String>
{
/**
* The default list of symbols.
*/
private static final Object[][] SYMBOLS = {
{" ", " ", true, "no-break space"},
{"&", "&", true, "ampersand"},
{""", """, true, "quotation mark"},
// finance
{"¢", "¢", true, "cent sign"},
{"€", "€", true, "euro sign"},
{"£", "£", true, "pound sign"},
{"¥", "¥", true, "yen sign"},
// signs
{"©", "©", true, "copyright sign"},
{"®", "®", true, "registered sign"},
{"™", "™", true, "trade mark sign"},
{"‰", "‰", true, "per mille sign"},
{"µ", "µ", true, "micro sign"},
{"·", "·", true, "middle dot"},
{"•", "•", true, "bullet"},
{"…", "…", true, "three dot leader"},
{"′", "′", true, "minutes / feet"},
{"″", "″", true, "seconds / inches"},
{"§", "§", true, "section sign"},
{"¶", "¶", true, "paragraph sign"},
{"ß", "ß", true, "sharp s / ess-zed"},
// quotations
{"‹", "‹", true, "single left-pointing angle quotation mark"},
{"›", "›", true, "single right-pointing angle quotation mark"},
{"«", "«", true, "left pointing guillemet"},
{"»", "»", true, "right pointing guillemet"},
{"‘", "‘", true, "left single quotation mark"},
{"’", "’", true, "right single quotation mark"},
{"“", "“", true, "left double quotation mark"},
{"”", "”", true, "right double quotation mark"},
{"‚", "‚", true, "single low-9 quotation mark"},
{"„", "„", true, "double low-9 quotation mark"},
{"<", "<", true, "less-than sign"},
{">", ">", true, "greater-than sign"},
{"≤", "≤", true, "less-than or equal to"},
{"≥", "≥", true, "greater-than or equal to"},
{"–", "–", true, "en dash"},
{"—", "—", true, "em dash"},
{"¯", "¯", true, "macron"},
{"‾", "‾", true, "overline"},
{"¤", "¤", true, "currency sign"},
{"¦", "¦", true, "broken bar"},
{"¨", "¨", true, "diaeresis"},
{"¡", "¡", true, "inverted exclamation mark"},
{"¿", "¿", true, "turned question mark"},
{"ˆ", "ˆ", true, "circumflex accent"},
{"˜", "˜", true, "small tilde"},
{"°", "°", true, "degree sign"},
{"−", "−", true, "minus sign"},
{"±", "±", true, "plus-minus sign"},
{"÷", "÷", true, "division sign"},
{"⁄", "⁄", true, "fraction slash"},
{"×", "×", true, "multiplication sign"},
{"¹", "¹", true, "superscript one"},
{"²", "²", true, "superscript two"},
{"³", "³", true, "superscript three"},
{"¼", "¼", true, "fraction one quarter"},
{"½", "½", true, "fraction one half"},
{"¾", "¾", true, "fraction three quarters"},
// math / logical
{"ƒ", "ƒ", true, "function / florin"},
{"∫", "∫", true, "integral"},
{"∑", "∑", true, "n-ary sumation"},
{"∞", "∞", true, "infinity"},
{"√", "√", true, "square root"},
{"∼", "∼", false, "similar to"},
{"≅", "≅", false, "approximately equal to"},
{"≈", "≈", true, "almost equal to"},
{"≠", "≠", true, "not equal to"},
{"≡", "≡", true, "identical to"},
{"∈", "∈", false, "element of"},
{"∉", "∉", false, "not an element of"},
{"∋", "∋", false, "contains as member"},
{"∏", "∏", true, "n-ary product"},
{"∧", "∧", false, "logical and"},
{"∨", "∨", false, "logical or"},
{"¬", "¬", true, "not sign"},
{"∩", "∩", true, "intersection"},
{"∪", "∪", false, "union"},
{"∂", "∂", true, "partial differential"},
{"∀", "∀", false, "for all"},
{"∃", "∃", false, "there exists"},
{"∅", "∅", false, "diameter"},
{"∇", "∇", false, "backward difference"},
{"∗", "∗", false, "asterisk operator"},
{"∝", "∝", false, "proportional to"},
{"∠", "∠", false, "angle"},
// undefined
{"´", "´", true, "acute accent"},
{"¸", "¸", true, "cedilla"},
{"ª", "ª", true, "feminine ordinal indicator"},
{"º", "º", true, "masculine ordinal indicator"},
{"†", "†", true, "dagger"},
{"‡", "‡", true, "double dagger"},
// alphabetical special chars
{"À", "À", true, "A - grave"},
{"Á", "Á", true, "A - acute"},
{"Â", "Â", true, "A - circumflex"},
{"Ã", "Ã", true, "A - tilde"},
{"Ä", "Ä", true, "A - diaeresis"},
{"Å", "Å", true, "A - ring above"},
{"Æ", "Æ", true, "ligature AE"},
{"Ç", "Ç", true, "C - cedilla"},
{"È", "È", true, "E - grave"},
{"É", "É", true, "E - acute"},
{"Ê", "Ê", true, "E - circumflex"},
{"Ë", "Ë", true, "E - diaeresis"},
{"Ì", "Ì", true, "I - grave"},
{"Í", "Í", true, "I - acute"},
{"Î", "Î", true, "I - circumflex"},
{"Ï", "Ï", true, "I - diaeresis"},
{"Ð", "Ð", true, "ETH"},
{"Ñ", "Ñ", true, "N - tilde"},
{"Ò", "Ò", true, "O - grave"},
{"Ó", "Ó", true, "O - acute"},
{"Ô", "Ô", true, "O - circumflex"},
{"Õ", "Õ", true, "O - tilde"},
{"Ö", "Ö", true, "O - diaeresis"},
{"Ø", "Ø", true, "O - slash"},
{"Œ", "Œ", true, "ligature OE"},
{"Š", "Š", true, "S - caron"},
{"Ù", "Ù", true, "U - grave"},
{"Ú", "Ú", true, "U - acute"},
{"Û", "Û", true, "U - circumflex"},
{"Ü", "Ü", true, "U - diaeresis"},
{"Ý", "Ý", true, "Y - acute"},
{"Ÿ", "Ÿ", true, "Y - diaeresis"},
{"Þ", "Þ", true, "THORN"},
{"à", "à", true, "a - grave"},
{"á", "á", true, "a - acute"},
{"â", "â", true, "a - circumflex"},
{"ã", "ã", true, "a - tilde"},
{"ä", "ä", true, "a - diaeresis"},
{"å", "å", true, "a - ring above"},
{"æ", "æ", true, "ligature ae"},
{"ç", "ç", true, "c - cedilla"},
{"è", "è", true, "e - grave"},
{"é", "é", true, "e - acute"},
{"ê", "ê", true, "e - circumflex"},
{"ë", "ë", true, "e - diaeresis"},
{"ì", "ì", true, "i - grave"},
{"í", "í", true, "i - acute"},
{"î", "î", true, "i - circumflex"},
{"ï", "ï", true, "i - diaeresis"},
{"ð", "ð", true, "eth"},
{"ñ", "ñ", true, "n - tilde"},
{"ò", "ò", true, "o - grave"},
{"ó", "ó", true, "o - acute"},
{"ô", "ô", true, "o - circumflex"},
{"õ", "õ", true, "o - tilde"},
{"ö", "ö", true, "o - diaeresis"},
{"ø", "ø", true, "o slash"},
{"œ", "œ", true, "ligature oe"},
{"š", "š", true, "s - caron"},
{"ù", "ù", true, "u - grave"},
{"ú", "ú", true, "u - acute"},
{"û", "û", true, "u - circumflex"},
{"ü", "ü", true, "u - diaeresis"},
{"ý", "ý", true, "y - acute"},
{"þ", "þ", true, "thorn"},
{"ÿ", "ÿ", true, "y - diaeresis"},
{"Α", "Α", true, "Alpha"},
{"Β", "Β", true, "Beta"},
{"Γ", "Γ", true, "Gamma"},
{"Δ", "Δ", true, "Delta"},
{"Ε", "Ε", true, "Epsilon"},
{"Ζ", "Ζ", true, "Zeta"},
{"Η", "Η", true, "Eta"},
{"Θ", "Θ", true, "Theta"},
{"Ι", "Ι", true, "Iota"},
{"Κ", "Κ", true, "Kappa"},
{"Λ", "Λ", true, "Lambda"},
{"Μ", "Μ", true, "Mu"},
{"Ν", "Ν", true, "Nu"},
{"Ξ", "Ξ", true, "Xi"},
{"Ο", "Ο", true, "Omicron"},
{"Π", "Π", true, "Pi"},
{"Ρ", "Ρ", true, "Rho"},
{"Σ", "Σ", true, "Sigma"},
{"Τ", "Τ", true, "Tau"},
{"Υ", "Υ", true, "Upsilon"},
{"Φ", "Φ", true, "Phi"},
{"Χ", "Χ", true, "Chi"},
{"Ψ", "Ψ", true, "Psi"},
{"Ω", "Ω", true, "Omega"},
{"α", "α", true, "alpha"},
{"β", "β", true, "beta"},
{"γ", "γ", true, "gamma"},
{"δ", "δ", true, "delta"},
{"ε", "ε", true, "epsilon"},
{"ζ", "ζ", true, "zeta"},
{"η", "η", true, "eta"},
{"θ", "θ", true, "theta"},
{"ι", "ι", true, "iota"},
{"κ", "κ", true, "kappa"},
{"λ", "λ", true, "lambda"},
{"μ", "μ", true, "mu"},
{"ν", "ν", true, "nu"},
{"ξ", "ξ", true, "xi"},
{"ο", "ο", true, "omicron"},
{"π", "π", true, "pi"},
{"ρ", "ρ", true, "rho"},
{"ς", "ς", true, "final sigma"},
{"σ", "σ", true, "sigma"},
{"τ", "τ", true, "tau"},
{"υ", "υ", true, "upsilon"},
{"φ", "φ", true, "phi"},
{"χ", "χ", true, "chi"},
{"ψ", "ψ", true, "psi"},
{"ω", "ω", true, "omega"},
// symbols
{"ℵ", "ℵ", false, "alef symbol"},
{"ϖ", "ϖ", false, "pi symbol"},
{"ℜ", "ℜ", false, "real part symbol"},
{"ϑ", "ϑ", false, "theta symbol"},
{"ϒ", "ϒ", false, "upsilon - hook symbol"},
{"℘", "℘", false, "Weierstrass p"},
{"ℑ", "ℑ", false, "imaginary part"},
// arrows
{"←", "←", true, "leftwards arrow"},
{"↑", "↑", true, "upwards arrow"},
{"→", "→", true, "rightwards arrow"},
{"↓", "↓", true, "downwards arrow"},
{"↔", "↔", true, "left right arrow"},
{"↵", "↵", false, "carriage return"},
{"⇐", "⇐", false, "leftwards double arrow"},
{"⇑", "⇑", false, "upwards double arrow"},
{"⇒", "⇒", false, "rightwards double arrow"},
{"⇓", "⇓", false, "downwards double arrow"},
{"⇔", "⇔", false, "left right double arrow"},
{"∴", "∴", false, "therefore"},
{"⊂", "⊂", false, "subset of"},
{"⊃", "⊃", false, "superset of"},
{"⊄", "⊄", false, "not a subset of"},
{"⊆", "⊆", false, "subset of or equal to"},
{"⊇", "⊇", false, "superset of or equal to"},
{"⊕", "⊕", false, "circled plus"},
{"⊗", "⊗", false, "circled times"},
{"⊥", "⊥", false, "perpendicular"},
{"⋅", "⋅", false, "dot operator"},
{"⌈", "⌈", false, "left ceiling"},
{"⌉", "⌉", false, "right ceiling"},
{"⌊", "⌊", false, "left floor"},
{"⌋", "⌋", false, "right floor"},
{"〈", "〈", false, "left-pointing angle bracket"},
{"〉", "〉", false, "right-pointing angle bracket"},
{"◊", "◊", true, "lozenge"},
{"♠", "♠", false, "black spade suit"},
{"♣", "♣", true, "black club suit"},
{"♥", "♥", true, "black heart suit"},
{"♦", "♦", true, "black diamond suit"},
{" ", " ", false, "en space"},
{" ", " ", false, "em space"},
{" ", " ", false, "thin space"},
{"", "", false, "zero width non-joiner"},
{"", "", false, "zero width joiner"},
{"", "", false, "left-to-right mark"},
{"", "", false, "right-to-left mark"},
{"", "", false, "soft hyphen"}};
/**
* The default number of rows in the grid that makes up the symbol palette.
*/
private static final int SYMBOLS_PER_ROW = 20;
/**
* The default number of columns in the grid that makes up the symbol palette.
*/
private static final int SYMBOLS_PER_COL = 10;
/**
* The symbol palette used for picking the symbol.
*/
private final SymbolPalette symbolPalette;
/**
* Creates a new symbol picker using the default list of symbols.
*/
public SymbolPicker()
{
super(false, true);
getDialog().setIcon(new Image(Images.INSTANCE.charmap()));
getDialog().setCaption(Strings.INSTANCE.charmap());
getDialog().addStyleName("xSymbolPicker");
symbolPalette = new SymbolPalette(SYMBOLS, SYMBOLS_PER_ROW, SYMBOLS_PER_COL);
symbolPalette.addSelectionHandler(this);
initWidget(symbolPalette);
}
@Override
public void onSelection(SelectionEvent<String> event)
{
if (event.getSource() == symbolPalette) {
hide();
}
}
/**
* @return the selected symbol
*/
public String getSymbol()
{
return symbolPalette.getSelectedSymbol();
}
@Override
public void center()
{
// Reset the selected symbol each time the symbol picker is shown.
symbolPalette.setSelectedSymbol(null);
super.center();
}
}