1 19 20 package org.netbeans.modules.html.palette.items; 21 import javax.swing.text.BadLocationException ; 22 import javax.swing.text.JTextComponent ; 23 import org.netbeans.modules.html.palette.HTMLPaletteUtilities; 24 import org.openide.text.ActiveEditorDrop; 25 26 27 31 public class SELECT implements ActiveEditorDrop { 32 33 public static final int OPTIONS_DEFAULT = 2; 34 public static final int OPTIONS_VISIBLE_DEFAULT = 1; 35 36 private String name = ""; 37 private int options = OPTIONS_DEFAULT; 38 private int optionsVisible = OPTIONS_VISIBLE_DEFAULT; 39 private boolean disabled = false; 40 private boolean multiple = false; 41 42 43 public SELECT() { 44 } 45 46 public boolean handleTransfer(JTextComponent targetComponent) { 47 48 SELECTCustomizer c = new SELECTCustomizer(this); 49 boolean accept = c.showDialog(); 50 if (accept) { 51 String body = createBody(); 52 try { 53 HTMLPaletteUtilities.insert(body, targetComponent); 54 } catch (BadLocationException ble) { 55 accept = false; 56 } 57 } 58 59 return accept; 60 } 61 62 private String createBody() { 63 64 String sBody = generateSBody(); 65 66 String strName = " name=\"" + name + "\""; 68 String strVisibleOptions = ""; 69 if (optionsVisible != OPTIONS_VISIBLE_DEFAULT) 70 strVisibleOptions = " size=\"" + optionsVisible + "\""; 72 String strMulti = (multiple ? " multiple=\"multiple\"" : ""); String strDisabled = (disabled ? " disabled=\"disabled\"" : ""); 75 String selBody = "<select" + strName + strVisibleOptions + strMulti + strDisabled + ">\n" + sBody + 77 "</select>"; 79 return selBody; 80 } 81 82 private String generateSBody() { 83 84 StringBuffer sb = new StringBuffer (); 85 for (int i = 0; i < options; i++) 86 sb.append("<option></option>\n"); 88 String sBody = sb.toString(); 89 90 return sBody; 91 } 92 93 public String getName() { 94 return name; 95 } 96 97 public void setName(String name) { 98 this.name = name; 99 } 100 101 public int getOptions() { 102 return options; 103 } 104 105 public void setOptions(int options) { 106 this.options = options; 107 } 108 109 public int getOptionsVisible() { 110 return optionsVisible; 111 } 112 113 public void setOptionsVisible(int optionsVisible) { 114 this.optionsVisible = optionsVisible; 115 } 116 117 public boolean isDisabled() { 118 return disabled; 119 } 120 121 public void setDisabled(boolean disabled) { 122 this.disabled = disabled; 123 } 124 125 public boolean isMultiple() { 126 return multiple; 127 } 128 129 public void setMultiple(boolean multiple) { 130 this.multiple = multiple; 131 } 132 133 } 134 | Popular Tags |