Lines 46-79
Link Here
|
46 |
*/ |
46 |
*/ |
47 |
public final class DialogBinding { |
47 |
public final class DialogBinding { |
48 |
|
48 |
|
|
|
49 |
// ----------------------------------------------------------------------- |
50 |
// Public implementation |
51 |
// ----------------------------------------------------------------------- |
52 |
|
49 |
/** |
53 |
/** |
50 |
* Bind given component and given file together. |
54 |
* Bind given component and given file together. |
|
|
55 |
* |
51 |
* @param fileObject to bind |
56 |
* @param fileObject to bind |
52 |
* @param offset position at which content of the component will be virtually placed |
57 |
* @param offset position at which content of the component will be virtually placed |
53 |
* @param length how many characters replace from the original file |
58 |
* @param length how many characters replace from the original file |
54 |
* @param component component to bind |
59 |
* @param component component to bind |
55 |
*/ |
60 |
*/ |
56 |
public static void bindComponentToFile(final FileObject fileObject, int offset, int length, final JTextComponent component) { |
61 |
public static void bindComponentToFile(FileObject fileObject, int offset, int length, JTextComponent component) { |
57 |
Parameters.notNull("fileObject", fileObject); //NOI18N |
62 |
Parameters.notNull("fileObject", fileObject); //NOI18N |
58 |
Parameters.notNull("component", component); //NOI18N |
63 |
Parameters.notNull("component", component); //NOI18N |
59 |
if (!fileObject.isValid() || !fileObject.isData()) |
64 |
if (!fileObject.isValid() || !fileObject.isData()) { |
60 |
return; |
65 |
return; |
|
|
66 |
} |
67 |
if (offset < 0 || offset > fileObject.getSize()) { |
68 |
throw new IllegalArgumentException("Invalid offset=" + offset + "; file.size=" + fileObject.getSize()); //NOI18N |
69 |
} |
70 |
if (length < 0 || offset + length > fileObject.getSize()) { |
71 |
throw new IllegalArgumentException("Invalid lenght=" + length + "; offset=" + offset + ", file.size=" + fileObject.getSize()); //NOI18N |
72 |
} |
61 |
bind(component, null, fileObject, offset, -1, -1, length, fileObject.getMIMEType()); |
73 |
bind(component, null, fileObject, offset, -1, -1, length, fileObject.getMIMEType()); |
62 |
} |
74 |
} |
63 |
|
75 |
|
64 |
/** |
76 |
/** |
65 |
* Bind given component and given document together. |
77 |
* Bind given component and given document together. |
|
|
78 |
* |
66 |
* @param document to bind |
79 |
* @param document to bind |
67 |
* @param offset position at which content of the component will be virtually placed |
80 |
* @param offset position at which content of the component will be virtually placed |
68 |
* @param length how many characters replace from the original document |
81 |
* @param length how many characters replace from the original document |
69 |
* @param component component to bind |
82 |
* @param component component to bind |
70 |
*/ |
83 |
*/ |
71 |
public static void bindComponentToDocument(final Document document, int offset, int length, final JTextComponent component) { |
84 |
public static void bindComponentToDocument(Document document, int offset, int length, JTextComponent component) { |
72 |
Parameters.notNull("document", document); //NOI18N |
85 |
Parameters.notNull("document", document); //NOI18N |
73 |
Parameters.notNull("component", component); //NOI18N |
86 |
Parameters.notNull("component", component); //NOI18N |
|
|
87 |
if (offset < 0 || offset > document.getLength()) { |
88 |
throw new IllegalArgumentException("Invalid offset=" + offset + "; file.size=" + document.getLength()); //NOI18N |
89 |
} |
90 |
if (length < 0 || offset + length > document.getLength()) { |
91 |
throw new IllegalArgumentException("Invalid lenght=" + length + "; offset=" + offset + ", file.size=" + document.getLength()); //NOI18N |
92 |
} |
74 |
bind(component, document, null, offset, -1, -1, length, (String)document.getProperty("mimeType")); //NOI18N |
93 |
bind(component, document, null, offset, -1, -1, length, (String)document.getProperty("mimeType")); //NOI18N |
75 |
} |
94 |
} |
76 |
|
95 |
|
|
|
96 |
/** |
97 |
* Bind given component and given file together. |
98 |
* |
99 |
* @param fileObject to bind |
100 |
* @param line an index (zero based) of the line where to place the component's content |
101 |
* @param column position (number of characters) at the line where to place the content |
102 |
* @param length how many characters replace from the original file |
103 |
* @param component component to bind |
104 |
* |
105 |
* @since 1.24 |
106 |
*/ |
107 |
public static void bindComponentToFile(FileObject fileObject, int line, int column, int length, JTextComponent component) { |
108 |
Parameters.notNull("fileObject", fileObject); //NOI18N |
109 |
Parameters.notNull("component", component); //NOI18N |
110 |
if (!fileObject.isValid() || !fileObject.isData()) { |
111 |
return; |
112 |
} |
113 |
if (line < 0 || column < 0) { |
114 |
throw new IllegalArgumentException("Invalid line=" + line + " or column=" + column); //NOI18N |
115 |
} |
116 |
bind(component, null, fileObject, -1, line, column, length, fileObject.getMIMEType()); |
117 |
} |
118 |
|
119 |
/** |
120 |
* Bind given component and given document together. |
121 |
* |
122 |
* @param document to bind |
123 |
* @param line an index (zero based) of the line where to place the component's content |
124 |
* @param column position (number of characters) at the line where to place the content |
125 |
* @param length how many characters replace from the original document |
126 |
* @param component component to bind |
127 |
* |
128 |
* @since 1.24 |
129 |
*/ |
130 |
public static void bindComponentToDocument(Document document, int line, int column, int length, JTextComponent component) { |
131 |
Parameters.notNull("document", document); //NOI18N |
132 |
Parameters.notNull("component", component); //NOI18N |
133 |
if (line < 0 || column < 0) { |
134 |
throw new IllegalArgumentException("Invalid line=" + line + " or column=" + column); //NOI18N |
135 |
} |
136 |
bind(component, document, null, -1, line, column, length, (String)document.getProperty("mimeType")); //NOI18N |
137 |
} |
138 |
|
139 |
// ----------------------------------------------------------------------- |
140 |
// Private implementation |
141 |
// ----------------------------------------------------------------------- |
142 |
|
77 |
// -J-Dorg.netbeans.api.editor.DialogBinding.level=FINE |
143 |
// -J-Dorg.netbeans.api.editor.DialogBinding.level=FINE |
78 |
private static final Logger LOG = Logger.getLogger(DialogBinding.class.getName()); |
144 |
private static final Logger LOG = Logger.getLogger(DialogBinding.class.getName()); |
79 |
|
145 |
|