|
| 1 | +/* |
| 2 | + * Copyright (C) 2024 GK Spencer |
| 3 | + * |
| 4 | + * JFileServer is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * JFileServer is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Lesser General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public License |
| 15 | + * along with JFileServer. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.filesys.server.filesys.clientapi.json; |
| 19 | + |
| 20 | +import com.google.gson.annotations.SerializedName; |
| 21 | + |
| 22 | +import java.util.HashMap; |
| 23 | + |
| 24 | +/** |
| 25 | + * Action Icon Class |
| 26 | + * |
| 27 | + * <p>Contains details of a client side icon to be used by a server action context menu</p> |
| 28 | + * |
| 29 | + * @author gkspencer |
| 30 | + */ |
| 31 | +public class ActionIcon { |
| 32 | + |
| 33 | + // Application icon indexes |
| 34 | + public static final int APPICON_FILESYSORG_ALFRESCO = -1; |
| 35 | + public static final int APPICON_FILESYSORG = -2; |
| 36 | + public static final int APPICON_ALFRESCO_CHECKIN = -3; |
| 37 | + public static final int APPICON_ALFRESCO_CHECKOUT = -4; |
| 38 | + |
| 39 | + // Shell icon indexes |
| 40 | + public static final int SHELLICON_SCRIPT = -16822; |
| 41 | + public static final int SHELLICON_WEBBROWSER = -512; |
| 42 | + public static final int SHELLICON_FOLDER = -4; |
| 43 | + public static final int SHELLICON_PRINTER = -17; |
| 44 | + public static final int SHELLICON_MAGNIFY = -23; |
| 45 | + public static final int SHELLICON_STAR = -44; |
| 46 | + public static final int SHELLICON_LOCK = -48; |
| 47 | + public static final int SHELLICON_MOVIE = -224; |
| 48 | + public static final int SHELLICON_AUDIO = -225; |
| 49 | + public static final int SHELLICON_CAMERA = -226; |
| 50 | + public static final int SHELLICON_INFORMATION = -16783; |
| 51 | + public static final int SHELLICON_HOME = -51380; |
| 52 | + public static final int SHELLICON_GEAR = -16826; |
| 53 | + |
| 54 | + // Mapping of icon name to action icon |
| 55 | + private static HashMap<String, ActionIcon> _iconMap; |
| 56 | + |
| 57 | + /** |
| 58 | + * Icon Types Enum Class |
| 59 | + */ |
| 60 | + public enum IconType { |
| 61 | + App, // built in icons, in the client side application DLL |
| 62 | + Shell, // icon in the Windows shell32.dll |
| 63 | + Custom // icon in another system DLL |
| 64 | + } |
| 65 | + |
| 66 | + // Icon type |
| 67 | + @SerializedName( value = "icon_type") |
| 68 | + private IconType m_iconType; |
| 69 | + |
| 70 | + // Icon index |
| 71 | + @SerializedName( value = "icon_index") |
| 72 | + private int m_iconIndex; |
| 73 | + |
| 74 | + // Optional icon DLL name/path |
| 75 | + @SerializedName( value = "icon_lib") |
| 76 | + private String m_iconLib; |
| 77 | + |
| 78 | + /** |
| 79 | + * Class constructor |
| 80 | + * |
| 81 | + * @param iconTyp IconType |
| 82 | + * @param iconIdx int |
| 83 | + * @param iconLib String |
| 84 | + */ |
| 85 | + protected ActionIcon( IconType iconTyp, int iconIdx, String iconLib ) { |
| 86 | + m_iconType = iconTyp; |
| 87 | + m_iconIndex = iconIdx; |
| 88 | + m_iconLib = iconLib; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Return the icon type |
| 93 | + * |
| 94 | + * @return IconType |
| 95 | + */ |
| 96 | + public IconType getIconType() { return m_iconType; } |
| 97 | + |
| 98 | + /** |
| 99 | + * Return the icon index |
| 100 | + * |
| 101 | + * @return int |
| 102 | + */ |
| 103 | + public int getIconIndex() { return m_iconIndex; } |
| 104 | + |
| 105 | + /** |
| 106 | + * Return the icon library name |
| 107 | + * |
| 108 | + * @return String |
| 109 | + */ |
| 110 | + public final String getIconLib() { return m_iconLib; } |
| 111 | + |
| 112 | + /** |
| 113 | + * Create an application icon |
| 114 | + * |
| 115 | + * @param iconIdx int |
| 116 | + * @return ActionIcon |
| 117 | + */ |
| 118 | + public static ActionIcon createAppIcon( int iconIdx) { |
| 119 | + return new ActionIcon( IconType.App, iconIdx, null); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Create a shell icon |
| 124 | + * |
| 125 | + * @param iconIdx int |
| 126 | + * @return ActionIcon |
| 127 | + */ |
| 128 | + public static ActionIcon createShellIcon( int iconIdx) { |
| 129 | + return new ActionIcon( IconType.Shell, iconIdx, null); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Create a custom icon |
| 134 | + * |
| 135 | + * @param iconIdx int |
| 136 | + * @param iconLib String |
| 137 | + * @return ActionIcon |
| 138 | + */ |
| 139 | + public static ActionIcon createCustomIcon( int iconIdx, String iconLib) { |
| 140 | + return new ActionIcon( IconType.Custom, iconIdx, iconLib); |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Create an action icon by name |
| 145 | + * |
| 146 | + * @param name String |
| 147 | + * @return ActionIcon |
| 148 | + */ |
| 149 | + public static ActionIcon createByName( String name) { |
| 150 | + |
| 151 | + // Get the icon mapping, if valid |
| 152 | + return _iconMap.get( name.toUpperCase()); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Return the action icon details as a string |
| 157 | + * |
| 158 | + * @return String |
| 159 | + */ |
| 160 | + public String toString() { |
| 161 | + StringBuilder str = new StringBuilder(); |
| 162 | + |
| 163 | + str.append("[Icon type="); |
| 164 | + str.append( getIconType()); |
| 165 | + str.append(", index="); |
| 166 | + str.append( getIconIndex()); |
| 167 | + |
| 168 | + if ( getIconType() == IconType.Custom) { |
| 169 | + str.append(", lib="); |
| 170 | + str.append( getIconLib()); |
| 171 | + } |
| 172 | + str.append("]"); |
| 173 | + |
| 174 | + return str.toString(); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * Static initializer |
| 179 | + */ |
| 180 | + static { |
| 181 | + |
| 182 | + // Initialise the icon map |
| 183 | + _iconMap = new HashMap<String, ActionIcon>( 32); |
| 184 | + |
| 185 | + _iconMap.put( "FILESYSORGALFRESCO", createAppIcon( APPICON_FILESYSORG_ALFRESCO)); |
| 186 | + _iconMap.put( "FILESYSORG", createAppIcon( APPICON_FILESYSORG)); |
| 187 | + _iconMap.put( "ALFRESCOCHECKIN", createAppIcon( APPICON_ALFRESCO_CHECKIN)); |
| 188 | + _iconMap.put( "ALFRESCOCHECKOUT", createAppIcon( APPICON_ALFRESCO_CHECKOUT)); |
| 189 | + |
| 190 | + _iconMap.put( "SHELLSCRIPT", createShellIcon( SHELLICON_SCRIPT)); |
| 191 | + _iconMap.put( "SHELLWEBBROWSER", createShellIcon( SHELLICON_WEBBROWSER)); |
| 192 | + _iconMap.put( "SHELLFOLDER", createShellIcon( SHELLICON_FOLDER)); |
| 193 | + _iconMap.put( "SHELLPRINTER", createShellIcon( SHELLICON_PRINTER)); |
| 194 | + _iconMap.put( "SHELLMAGNIFY", createShellIcon( SHELLICON_MAGNIFY)); |
| 195 | + _iconMap.put( "SHELLSTAR", createShellIcon( SHELLICON_STAR)); |
| 196 | + _iconMap.put( "SHELLOCK", createShellIcon( SHELLICON_LOCK)); |
| 197 | + _iconMap.put( "SHELLMOVIE", createShellIcon( SHELLICON_MOVIE)); |
| 198 | + _iconMap.put( "SHELLAUDIO", createShellIcon( SHELLICON_AUDIO)); |
| 199 | + _iconMap.put( "SHELLCAMERA", createShellIcon( SHELLICON_CAMERA)); |
| 200 | + _iconMap.put( "SHELLINFORMATION", createShellIcon( SHELLICON_INFORMATION)); |
| 201 | + _iconMap.put( "SHELLHOME", createShellIcon( SHELLICON_HOME)); |
| 202 | + _iconMap.put( "SHELLGEAR", createShellIcon( SHELLICON_GEAR)); |
| 203 | + } |
| 204 | +} |
0 commit comments