1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.wizards.web; 24 25 import javax.swing.ListModel; 26 27 import com.sun.star.awt.Size; 28 import com.sun.star.lang.XMultiServiceFactory; 29 import com.sun.star.wizards.common.ConfigSet; 30 import com.sun.star.wizards.common.FileAccess; 31 import com.sun.star.wizards.common.PropertyNames; 32 import com.sun.star.wizards.ui.ImageList; 33 import com.sun.star.wizards.web.data.CGIconSet; 34 35 /** 36 * @author rpiterman 37 * The dialog class for choosing an icon set. 38 * This class simulates a model, though it does not functions really as one, 39 * since it does not cast events. 40 * It also implements the ImageList.ImageRenderer interface, to handle 41 * its own objects. 42 */ 43 public class IconsDialog extends ImageListDialog implements ImageList.IImageRenderer, ListModel 44 { 45 46 private ConfigSet set; 47 String htmlexpDirectory; 48 /** 49 * this icons filename prefixes are used to display the icons. 50 */ 51 private String[] icons = new String[] 52 { 53 "firs", "prev", "next", "last", "nav", "text", "up", "down" 54 }; 55 private Integer[] objects; 56 57 /** 58 * @param xmsf 59 * @param set_ the configuration set of the supported 60 * icon sets. 61 */ IconsDialog(XMultiServiceFactory xmsf, ConfigSet set_, WebWizardDialogResources resources)62 public IconsDialog(XMultiServiceFactory xmsf, 63 ConfigSet set_, 64 WebWizardDialogResources resources) 65 throws Exception 66 { 67 super(xmsf, WWHID.HID_IS, new String[] 68 { 69 resources.resIconsDialog, 70 resources.resIconsDialogCaption, 71 resources.resOK, 72 resources.resCancel, 73 resources.resHelp, 74 resources.resDeselect, 75 resources.resOther, 76 resources.resCounter 77 }); 78 79 htmlexpDirectory = FileAccess.getOfficePath(xmsf, "Gallery", "share", PropertyNames.EMPTY_STRING); 80 set = set_; 81 objects = new Integer[set.getSize() * icons.length]; 82 for (int i = 0; i < objects.length; i++) 83 { 84 objects[i] = new Integer(i); 85 } 86 il.setListModel(this); 87 il.setRenderer(this); 88 il.setRows(4); 89 il.setCols(8); 90 il.setImageSize(new Size(20, 20)); 91 il.setShowButtons(false); 92 il.setRowSelect(true); 93 il.scaleImages = Boolean.FALSE; 94 95 showDeselectButton = true; 96 showOtherButton = false; 97 98 build(); 99 } 100 getIconset()101 public String getIconset() 102 { 103 if (getSelected() == null) 104 { 105 return null; 106 } 107 else 108 { 109 return (String) set.getKey(((Number) getSelected()).intValue() / icons.length); 110 } 111 } 112 setIconset(String iconset)113 public void setIconset(String iconset) 114 { 115 int icon = set.getIndexOf(set.getElement(iconset)) * icons.length; 116 this.setSelected(icon >= 0 ? objects[icon] : null); 117 } 118 119 /** 120 * dummy 121 */ addListDataListener(javax.swing.event.ListDataListener listener)122 public synchronized void addListDataListener(javax.swing.event.ListDataListener listener) 123 { 124 } 125 126 /** 127 * dummy 128 */ removeListDataListener(javax.swing.event.ListDataListener listener)129 public synchronized void removeListDataListener(javax.swing.event.ListDataListener listener) 130 { 131 } 132 133 /* (non-Javadoc) 134 * @see javax.swing.ListModel#getSize() 135 */ getSize()136 public int getSize() 137 { 138 return set.getSize() * icons.length; 139 } 140 /* (non-Javadoc) 141 * @see javax.swing.ListModel#getElementAt(int) 142 */ 143 getElementAt(int arg0)144 public Object getElementAt(int arg0) 145 { 146 return objects[arg0]; 147 } 148 149 /* (non-Javadoc) 150 * @see com.sun.star.wizards.ui.ImageList.ImageRenderer#getImageUrls(java.lang.Object) 151 */ getImageUrls(Object listItem)152 public Object[] getImageUrls(Object listItem) 153 { 154 int i = ((Number) listItem).intValue(); 155 int iset = getIconsetNum(i); 156 int icon = getIconNum(i); 157 String[] sRetUrls = new String[2]; 158 sRetUrls[0] = htmlexpDirectory + "/htmlexpo/" + 159 getIconsetPref(iset) + 160 icons[icon] + 161 getIconsetPostfix(iset); 162 sRetUrls[1] = sRetUrls[0]; 163 //System.out.println(s); 164 return sRetUrls; 165 } 166 /* (non-Javadoc) 167 * @see com.sun.star.wizards.common.Renderer#render(java.lang.Object) 168 */ 169 render(Object object)170 public String render(Object object) 171 { 172 if (object == null) 173 { 174 return PropertyNames.EMPTY_STRING; 175 } 176 int i = ((Number) object).intValue(); 177 int iset = getIconsetNum(i); 178 return getIconset(iset).cp_Name; 179 } 180 getIconsetNum(int i)181 private int getIconsetNum(int i) 182 { 183 return i / icons.length; 184 } 185 getIconNum(int i)186 private int getIconNum(int i) 187 { 188 return i % icons.length; 189 } 190 getIconsetPref(int iconset)191 private String getIconsetPref(int iconset) 192 { 193 return getIconset(iconset).cp_FNPrefix; 194 } 195 getIconsetPostfix(int iconset)196 private String getIconsetPostfix(int iconset) 197 { 198 return getIconset(iconset).cp_FNPostfix; 199 } 200 getIconset(int i)201 private CGIconSet getIconset(int i) 202 { 203 return (CGIconSet) set.getElementAt(i); 204 } 205 } 206