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 TEXTAREA implements ActiveEditorDrop { 32 33 public static final String STATE_DISABLED = "disabled"; public static final String STATE_READONLY = "readonly"; 36 public static final int ROWS_DEFAULT = 4; 37 public static final int COLS_DEFAULT = 20; 38 39 private String name = ""; 40 private String value = ""; 41 private boolean disabled = false; 42 private boolean readonly = false; 43 private int rows = ROWS_DEFAULT; 44 private int cols = COLS_DEFAULT; 45 46 public TEXTAREA() { 47 } 48 49 public boolean handleTransfer(JTextComponent targetComponent) { 50 51 TEXTAREACustomizer c = new TEXTAREACustomizer(this); 52 boolean accept = c.showDialog(); 53 if (accept) { 54 String body = createBody(); 55 try { 56 HTMLPaletteUtilities.insert(body, targetComponent); 57 } catch (BadLocationException ble) { 58 accept = false; 59 } 60 } 61 62 return accept; 63 } 64 65 private String createBody() { 66 67 String strName = " name=\"" + name + "\""; 69 String strValue = value; 70 if (value.length() > 0) 71 strValue += "\n"; 72 73 String strReadOnly = (readonly ? " readonly=\"readonly\"" : ""); String strDisabled = (disabled ? " disabled=\"disabled\"" : ""); 76 String strRows = " rows=\"" + rows + "\""; String strCols = " cols=\"" + cols + "\""; 79 String taBody = "<textarea" + strName + strRows + strCols + strReadOnly + strDisabled + ">\n" + strValue + 81 "</textarea>"; 83 return taBody; 84 } 85 86 public String getName() { 87 return name; 88 } 89 90 public String getValue() { 91 return value; 92 } 93 94 public boolean isDisabled() { 95 return disabled; 96 } 97 98 public void setDisabled(boolean disabled) { 99 this.disabled = disabled; 100 } 101 102 public boolean isReadonly() { 103 return readonly; 104 } 105 106 public void setReadonly(boolean readonly) { 107 this.readonly = readonly; 108 } 109 110 public int getRows() { 111 return rows; 112 } 113 114 public void setRows(int rows) { 115 this.rows = rows; 116 } 117 118 public int getCols() { 119 return cols; 120 } 121 122 public void setCols(int cols) { 123 this.cols = cols; 124 } 125 126 public void setName(String name) { 127 this.name = name; 128 } 129 130 public void setValue(String value) { 131 this.value = value; 132 } 133 134 } 135 | Popular Tags |