Révision 660
tmp/org.txm.rcp/src/main/java/org/eclipse/wb/swt/SWTResourceManager.java (revision 660) | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* Copyright (c) 2011 Google, Inc. |
|
3 |
* All rights reserved. This program and the accompanying materials |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
5 |
* which accompanies this distribution, and is available at |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
7 |
* |
|
8 |
* Contributors: |
|
9 |
* Google, Inc. - initial API and implementation |
|
10 |
*******************************************************************************/ |
|
11 |
package org.eclipse.wb.swt; |
|
12 |
|
|
13 |
import java.io.FileInputStream; |
|
14 |
import java.io.IOException; |
|
15 |
import java.io.InputStream; |
|
16 |
import java.util.HashMap; |
|
17 |
import java.util.Map; |
|
18 |
|
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.graphics.Color; |
|
21 |
import org.eclipse.swt.graphics.Cursor; |
|
22 |
import org.eclipse.swt.graphics.Font; |
|
23 |
import org.eclipse.swt.graphics.FontData; |
|
24 |
import org.eclipse.swt.graphics.GC; |
|
25 |
import org.eclipse.swt.graphics.Image; |
|
26 |
import org.eclipse.swt.graphics.ImageData; |
|
27 |
import org.eclipse.swt.graphics.RGB; |
|
28 |
import org.eclipse.swt.graphics.Rectangle; |
|
29 |
import org.eclipse.swt.widgets.Display; |
|
30 |
|
|
31 |
/** |
|
32 |
* Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc. |
|
33 |
* <p> |
|
34 |
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the |
|
35 |
* operating system resources managed by cached objects when those objects and OS resources are no longer |
|
36 |
* needed (e.g. on application shutdown) |
|
37 |
* <p> |
|
38 |
* This class may be freely distributed as part of any application or plugin. |
|
39 |
* <p> |
|
40 |
* @author scheglov_ke |
|
41 |
* @author Dan Rubel |
|
42 |
*/ |
|
43 |
public class SWTResourceManager { |
|
44 |
//////////////////////////////////////////////////////////////////////////// |
|
45 |
// |
|
46 |
// Color |
|
47 |
// |
|
48 |
//////////////////////////////////////////////////////////////////////////// |
|
49 |
private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>(); |
|
50 |
/** |
|
51 |
* Returns the system {@link Color} matching the specific ID. |
|
52 |
* |
|
53 |
* @param systemColorID |
|
54 |
* the ID value for the color |
|
55 |
* @return the system {@link Color} matching the specific ID |
|
56 |
*/ |
|
57 |
public static Color getColor(int systemColorID) { |
|
58 |
Display display = Display.getCurrent(); |
|
59 |
return display.getSystemColor(systemColorID); |
|
60 |
} |
|
61 |
/** |
|
62 |
* Returns a {@link Color} given its red, green and blue component values. |
|
63 |
* |
|
64 |
* @param r |
|
65 |
* the red component of the color |
|
66 |
* @param g |
|
67 |
* the green component of the color |
|
68 |
* @param b |
|
69 |
* the blue component of the color |
|
70 |
* @return the {@link Color} matching the given red, green and blue component values |
|
71 |
*/ |
|
72 |
public static Color getColor(int r, int g, int b) { |
|
73 |
return getColor(new RGB(r, g, b)); |
|
74 |
} |
|
75 |
/** |
|
76 |
* Returns a {@link Color} given its RGB value. |
|
77 |
* |
|
78 |
* @param rgb |
|
79 |
* the {@link RGB} value of the color |
|
80 |
* @return the {@link Color} matching the RGB value |
|
81 |
*/ |
|
82 |
public static Color getColor(RGB rgb) { |
|
83 |
Color color = m_colorMap.get(rgb); |
|
84 |
if (color == null) { |
|
85 |
Display display = Display.getCurrent(); |
|
86 |
color = new Color(display, rgb); |
|
87 |
m_colorMap.put(rgb, color); |
|
88 |
} |
|
89 |
return color; |
|
90 |
} |
|
91 |
/** |
|
92 |
* Dispose of all the cached {@link Color}'s. |
|
93 |
*/ |
|
94 |
public static void disposeColors() { |
|
95 |
for (Color color : m_colorMap.values()) { |
|
96 |
color.dispose(); |
|
97 |
} |
|
98 |
m_colorMap.clear(); |
|
99 |
} |
|
100 |
//////////////////////////////////////////////////////////////////////////// |
|
101 |
// |
|
102 |
// Image |
|
103 |
// |
|
104 |
//////////////////////////////////////////////////////////////////////////// |
|
105 |
/** |
|
106 |
* Maps image paths to images. |
|
107 |
*/ |
|
108 |
private static Map<String, Image> m_imageMap = new HashMap<String, Image>(); |
|
109 |
/** |
|
110 |
* Returns an {@link Image} encoded by the specified {@link InputStream}. |
|
111 |
* |
|
112 |
* @param stream |
|
113 |
* the {@link InputStream} encoding the image data |
|
114 |
* @return the {@link Image} encoded by the specified input stream |
|
115 |
*/ |
|
116 |
protected static Image getImage(InputStream stream) throws IOException { |
|
117 |
try { |
|
118 |
Display display = Display.getCurrent(); |
|
119 |
ImageData data = new ImageData(stream); |
|
120 |
if (data.transparentPixel > 0) { |
|
121 |
return new Image(display, data, data.getTransparencyMask()); |
|
122 |
} |
|
123 |
return new Image(display, data); |
|
124 |
} finally { |
|
125 |
stream.close(); |
|
126 |
} |
|
127 |
} |
|
128 |
/** |
|
129 |
* Returns an {@link Image} stored in the file at the specified path. |
|
130 |
* |
|
131 |
* @param path |
|
132 |
* the path to the image file |
|
133 |
* @return the {@link Image} stored in the file at the specified path |
|
134 |
*/ |
|
135 |
public static Image getImage(String path) { |
|
136 |
Image image = m_imageMap.get(path); |
|
137 |
if (image == null) { |
|
138 |
try { |
|
139 |
image = getImage(new FileInputStream(path)); |
|
140 |
m_imageMap.put(path, image); |
|
141 |
} catch (Exception e) { |
|
142 |
image = getMissingImage(); |
|
143 |
m_imageMap.put(path, image); |
|
144 |
} |
|
145 |
} |
|
146 |
return image; |
|
147 |
} |
|
148 |
/** |
|
149 |
* Returns an {@link Image} stored in the file at the specified path relative to the specified class. |
|
150 |
* |
|
151 |
* @param clazz |
|
152 |
* the {@link Class} relative to which to find the image |
|
153 |
* @param path |
|
154 |
* the path to the image file, if starts with <code>'/'</code> |
|
155 |
* @return the {@link Image} stored in the file at the specified path |
|
156 |
*/ |
|
157 |
public static Image getImage(Class<?> clazz, String path) { |
|
158 |
String key = clazz.getName() + '|' + path; |
|
159 |
Image image = m_imageMap.get(key); |
|
160 |
if (image == null) { |
|
161 |
try { |
|
162 |
image = getImage(clazz.getResourceAsStream(path)); |
|
163 |
m_imageMap.put(key, image); |
|
164 |
} catch (Exception e) { |
|
165 |
image = getMissingImage(); |
|
166 |
m_imageMap.put(key, image); |
|
167 |
} |
|
168 |
} |
|
169 |
return image; |
|
170 |
} |
|
171 |
private static final int MISSING_IMAGE_SIZE = 10; |
|
172 |
/** |
|
173 |
* @return the small {@link Image} that can be used as placeholder for missing image. |
|
174 |
*/ |
|
175 |
private static Image getMissingImage() { |
|
176 |
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); |
|
177 |
// |
|
178 |
GC gc = new GC(image); |
|
179 |
gc.setBackground(getColor(SWT.COLOR_RED)); |
|
180 |
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); |
|
181 |
gc.dispose(); |
|
182 |
// |
|
183 |
return image; |
|
184 |
} |
|
185 |
/** |
|
186 |
* Style constant for placing decorator image in top left corner of base image. |
|
187 |
*/ |
|
188 |
public static final int TOP_LEFT = 1; |
|
189 |
/** |
|
190 |
* Style constant for placing decorator image in top right corner of base image. |
|
191 |
*/ |
|
192 |
public static final int TOP_RIGHT = 2; |
|
193 |
/** |
|
194 |
* Style constant for placing decorator image in bottom left corner of base image. |
|
195 |
*/ |
|
196 |
public static final int BOTTOM_LEFT = 3; |
|
197 |
/** |
|
198 |
* Style constant for placing decorator image in bottom right corner of base image. |
|
199 |
*/ |
|
200 |
public static final int BOTTOM_RIGHT = 4; |
|
201 |
/** |
|
202 |
* Internal value. |
|
203 |
*/ |
|
204 |
protected static final int LAST_CORNER_KEY = 5; |
|
205 |
/** |
|
206 |
* Maps images to decorated images. |
|
207 |
*/ |
|
208 |
@SuppressWarnings("unchecked") |
|
209 |
private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; |
|
210 |
/** |
|
211 |
* Returns an {@link Image} composed of a base image decorated by another image. |
|
212 |
* |
|
213 |
* @param baseImage |
|
214 |
* the base {@link Image} that should be decorated |
|
215 |
* @param decorator |
|
216 |
* the {@link Image} to decorate the base image |
|
217 |
* @return {@link Image} The resulting decorated image |
|
218 |
*/ |
|
219 |
public static Image decorateImage(Image baseImage, Image decorator) { |
|
220 |
return decorateImage(baseImage, decorator, BOTTOM_RIGHT); |
|
221 |
} |
|
222 |
/** |
|
223 |
* Returns an {@link Image} composed of a base image decorated by another image. |
|
224 |
* |
|
225 |
* @param baseImage |
|
226 |
* the base {@link Image} that should be decorated |
|
227 |
* @param decorator |
|
228 |
* the {@link Image} to decorate the base image |
|
229 |
* @param corner |
|
230 |
* the corner to place decorator image |
|
231 |
* @return the resulting decorated {@link Image} |
|
232 |
*/ |
|
233 |
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { |
|
234 |
if (corner <= 0 || corner >= LAST_CORNER_KEY) { |
|
235 |
throw new IllegalArgumentException("Wrong decorate corner"); |
|
236 |
} |
|
237 |
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; |
|
238 |
if (cornerDecoratedImageMap == null) { |
|
239 |
cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); |
|
240 |
m_decoratedImageMap[corner] = cornerDecoratedImageMap; |
|
241 |
} |
|
242 |
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); |
|
243 |
if (decoratedMap == null) { |
|
244 |
decoratedMap = new HashMap<Image, Image>(); |
|
245 |
cornerDecoratedImageMap.put(baseImage, decoratedMap); |
|
246 |
} |
|
247 |
// |
|
248 |
Image result = decoratedMap.get(decorator); |
|
249 |
if (result == null) { |
|
250 |
Rectangle bib = baseImage.getBounds(); |
|
251 |
Rectangle dib = decorator.getBounds(); |
|
252 |
// |
|
253 |
result = new Image(Display.getCurrent(), bib.width, bib.height); |
|
254 |
// |
|
255 |
GC gc = new GC(result); |
|
256 |
gc.drawImage(baseImage, 0, 0); |
|
257 |
if (corner == TOP_LEFT) { |
|
258 |
gc.drawImage(decorator, 0, 0); |
|
259 |
} else if (corner == TOP_RIGHT) { |
|
260 |
gc.drawImage(decorator, bib.width - dib.width, 0); |
|
261 |
} else if (corner == BOTTOM_LEFT) { |
|
262 |
gc.drawImage(decorator, 0, bib.height - dib.height); |
|
263 |
} else if (corner == BOTTOM_RIGHT) { |
|
264 |
gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); |
|
265 |
} |
|
266 |
gc.dispose(); |
|
267 |
// |
|
268 |
decoratedMap.put(decorator, result); |
|
269 |
} |
|
270 |
return result; |
|
271 |
} |
|
272 |
/** |
|
273 |
* Dispose all of the cached {@link Image}'s. |
|
274 |
*/ |
|
275 |
public static void disposeImages() { |
|
276 |
// dispose loaded images |
|
277 |
{ |
|
278 |
for (Image image : m_imageMap.values()) { |
|
279 |
image.dispose(); |
|
280 |
} |
|
281 |
m_imageMap.clear(); |
|
282 |
} |
|
283 |
// dispose decorated images |
|
284 |
for (int i = 0; i < m_decoratedImageMap.length; i++) { |
|
285 |
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; |
|
286 |
if (cornerDecoratedImageMap != null) { |
|
287 |
for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { |
|
288 |
for (Image image : decoratedMap.values()) { |
|
289 |
image.dispose(); |
|
290 |
} |
|
291 |
decoratedMap.clear(); |
|
292 |
} |
|
293 |
cornerDecoratedImageMap.clear(); |
|
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
//////////////////////////////////////////////////////////////////////////// |
|
298 |
// |
|
299 |
// Font |
|
300 |
// |
|
301 |
//////////////////////////////////////////////////////////////////////////// |
|
302 |
/** |
|
303 |
* Maps font names to fonts. |
|
304 |
*/ |
|
305 |
private static Map<String, Font> m_fontMap = new HashMap<String, Font>(); |
|
306 |
/** |
|
307 |
* Maps fonts to their bold versions. |
|
308 |
*/ |
|
309 |
private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>(); |
|
310 |
/** |
|
311 |
* Returns a {@link Font} based on its name, height and style. |
|
312 |
* |
|
313 |
* @param name |
|
314 |
* the name of the font |
|
315 |
* @param height |
|
316 |
* the height of the font |
|
317 |
* @param style |
|
318 |
* the style of the font |
|
319 |
* @return {@link Font} The font matching the name, height and style |
|
320 |
*/ |
|
321 |
public static Font getFont(String name, int height, int style) { |
|
322 |
return getFont(name, height, style, false, false); |
|
323 |
} |
|
324 |
/** |
|
325 |
* Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline |
|
326 |
* flags are also supported. |
|
327 |
* |
|
328 |
* @param name |
|
329 |
* the name of the font |
|
330 |
* @param size |
|
331 |
* the size of the font |
|
332 |
* @param style |
|
333 |
* the style of the font |
|
334 |
* @param strikeout |
|
335 |
* the strikeout flag (warning: Windows only) |
|
336 |
* @param underline |
|
337 |
* the underline flag (warning: Windows only) |
|
338 |
* @return {@link Font} The font matching the name, height, style, strikeout and underline |
|
339 |
*/ |
|
340 |
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { |
|
341 |
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; |
|
342 |
Font font = m_fontMap.get(fontName); |
|
343 |
if (font == null) { |
|
344 |
FontData fontData = new FontData(name, size, style); |
|
345 |
if (strikeout || underline) { |
|
346 |
try { |
|
347 |
Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$ |
|
348 |
Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$ |
|
349 |
if (logFont != null && logFontClass != null) { |
|
350 |
if (strikeout) { |
|
351 |
logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ |
|
352 |
} |
|
353 |
if (underline) { |
|
354 |
logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ |
|
355 |
} |
|
356 |
} |
|
357 |
} catch (Throwable e) { |
|
358 |
System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$ |
|
359 |
} |
|
360 |
} |
|
361 |
font = new Font(Display.getCurrent(), fontData); |
|
362 |
m_fontMap.put(fontName, font); |
|
363 |
} |
|
364 |
return font; |
|
365 |
} |
|
366 |
/** |
|
367 |
* Returns a bold version of the given {@link Font}. |
|
368 |
* |
|
369 |
* @param baseFont |
|
370 |
* the {@link Font} for which a bold version is desired |
|
371 |
* @return the bold version of the given {@link Font} |
|
372 |
*/ |
|
373 |
public static Font getBoldFont(Font baseFont) { |
|
374 |
Font font = m_fontToBoldFontMap.get(baseFont); |
|
375 |
if (font == null) { |
|
376 |
FontData fontDatas[] = baseFont.getFontData(); |
|
377 |
FontData data = fontDatas[0]; |
|
378 |
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD); |
|
379 |
m_fontToBoldFontMap.put(baseFont, font); |
|
380 |
} |
|
381 |
return font; |
|
382 |
} |
|
383 |
/** |
|
384 |
* Dispose all of the cached {@link Font}'s. |
|
385 |
*/ |
|
386 |
public static void disposeFonts() { |
|
387 |
// clear fonts |
|
388 |
for (Font font : m_fontMap.values()) { |
|
389 |
font.dispose(); |
|
390 |
} |
|
391 |
m_fontMap.clear(); |
|
392 |
// clear bold fonts |
|
393 |
for (Font font : m_fontToBoldFontMap.values()) { |
|
394 |
font.dispose(); |
|
395 |
} |
|
396 |
m_fontToBoldFontMap.clear(); |
|
397 |
} |
|
398 |
//////////////////////////////////////////////////////////////////////////// |
|
399 |
// |
|
400 |
// Cursor |
|
401 |
// |
|
402 |
//////////////////////////////////////////////////////////////////////////// |
|
403 |
/** |
|
404 |
* Maps IDs to cursors. |
|
405 |
*/ |
|
406 |
private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>(); |
|
407 |
/** |
|
408 |
* Returns the system cursor matching the specific ID. |
|
409 |
* |
|
410 |
* @param id |
|
411 |
* int The ID value for the cursor |
|
412 |
* @return Cursor The system cursor matching the specific ID |
|
413 |
*/ |
|
414 |
public static Cursor getCursor(int id) { |
|
415 |
Integer key = Integer.valueOf(id); |
|
416 |
Cursor cursor = m_idToCursorMap.get(key); |
|
417 |
if (cursor == null) { |
|
418 |
cursor = new Cursor(Display.getDefault(), id); |
|
419 |
m_idToCursorMap.put(key, cursor); |
|
420 |
} |
|
421 |
return cursor; |
|
422 |
} |
|
423 |
/** |
|
424 |
* Dispose all of the cached cursors. |
|
425 |
*/ |
|
426 |
public static void disposeCursors() { |
|
427 |
for (Cursor cursor : m_idToCursorMap.values()) { |
|
428 |
cursor.dispose(); |
|
429 |
} |
|
430 |
m_idToCursorMap.clear(); |
|
431 |
} |
|
432 |
//////////////////////////////////////////////////////////////////////////// |
|
433 |
// |
|
434 |
// General |
|
435 |
// |
|
436 |
//////////////////////////////////////////////////////////////////////////// |
|
437 |
/** |
|
438 |
* Dispose of cached objects and their underlying OS resources. This should only be called when the cached |
|
439 |
* objects are no longer needed (e.g. on application shutdown). |
|
440 |
*/ |
|
441 |
public static void dispose() { |
|
442 |
disposeColors(); |
|
443 |
disposeImages(); |
|
444 |
disposeFonts(); |
|
445 |
disposeCursors(); |
|
446 |
} |
|
447 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorporaView.java (revision 660) | ||
---|---|---|
400 | 400 |
|
401 | 401 |
/** |
402 | 402 |
* Opens the Corpora view if not already opened. |
403 |
* @return |
|
403 |
* @return the corpora view if opened
|
|
404 | 404 |
*/ |
405 | 405 |
public static CorporaView openView() { |
406 | 406 |
// open Unit View if not opened |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/actions/SaveBeforeExecutionDialog.java (revision 660) | ||
---|---|---|
33 | 33 |
import org.eclipse.swt.widgets.Composite; |
34 | 34 |
import org.eclipse.swt.widgets.Control; |
35 | 35 |
import org.eclipse.swt.widgets.Shell; |
36 |
// TODO: Auto-generated Javadoc |
|
36 |
|
|
37 | 37 |
/** |
38 | 38 |
* Allow the user to choose : the type of the graphic the structural units, |
39 | 39 |
* property and values to be shown the queries of each curves. |
... | ... | |
48 | 48 |
* Instantiates a new progression dialog. |
49 | 49 |
* |
50 | 50 |
* @param parentShell the parent shell |
51 |
* @param corpus the corpus |
|
52 | 51 |
*/ |
53 | 52 |
public SaveBeforeExecutionDialog(Shell parentShell, File script) { |
54 | 53 |
super(parentShell); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/CopyFile.java (revision 660) | ||
---|---|---|
35 | 35 |
import org.eclipse.jface.viewers.ISelection; |
36 | 36 |
import org.eclipse.jface.viewers.IStructuredSelection; |
37 | 37 |
import org.eclipse.ui.handlers.HandlerUtil; |
38 |
// TODO: Auto-generated Javadoc |
|
39 | 38 |
/** |
40 | 39 |
* Handler: copy the selected file. |
41 | 40 |
* |
42 |
* @mdecorde |
|
41 |
* @author mdecorde
|
|
43 | 42 |
*/ |
44 | 43 |
public class CopyFile extends AbstractHandler { |
45 | 44 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/base/DeleteObject.java (revision 660) | ||
---|---|---|
145 | 145 |
* TODO: select the parent object of the deleted object |
146 | 146 |
* |
147 | 147 |
* @param objects the objects to delete |
148 |
* @return |
|
148 |
* @return the e
|
|
149 | 149 |
*/ |
150 | 150 |
public synchronized static HashSet<Object> delete(final List<Object> objects) { |
151 | 151 |
StatusLine.setMessage(NLS.bind(RCPMessages.DeleteObject_5, objects)); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/ExecuteGroovyScript.java (revision 660) | ||
---|---|---|
73 | 73 |
/** |
74 | 74 |
* Execute a Groovy script |
75 | 75 |
* |
76 |
* @mdecorde |
|
76 |
* @author mdecorde
|
|
77 | 77 |
*/ |
78 | 78 |
public class ExecuteGroovyScript extends AbstractHandler { |
79 | 79 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/ImportFormEditor.java (revision 660) | ||
---|---|---|
106 | 106 |
/** |
107 | 107 |
* Do save as. |
108 | 108 |
* |
109 |
* @see org.eclipse.lyon gournd zeroui.part.EditorPart#doSaveAs()
|
|
109 |
* @see org.eclipse.part.EditorPart#doSaveAs() |
|
110 | 110 |
*/ |
111 | 111 |
@Override |
112 | 112 |
public void doSaveAs() { |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/CorpusPage.java (revision 660) | ||
---|---|---|
903 | 903 |
|
904 | 904 |
/** |
905 | 905 |
* Called by "startImport". Save the field values in the Parameter file |
906 |
* @return |
|
906 |
* @return true if import parameters are saved
|
|
907 | 907 |
*/ |
908 | 908 |
public boolean saveConfig() { |
909 | 909 |
System.out.println(RCPMessages.CorpusPage_52); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 660) | ||
---|---|---|
387 | 387 |
* |
388 | 388 |
* @param result |
389 | 389 |
* @param editorPartId |
390 |
* @return |
|
391 | 390 |
*/ |
392 | 391 |
public static void openEditor(TXMResult result, String editorPartId) { |
393 | 392 |
//openEditor(new TXMResultEditorInput(result), editorPartId); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/SWTResourceManager.java (revision 660) | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* Copyright (c) 2011 Google, Inc. |
|
3 |
* All rights reserved. This program and the accompanying materials |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
5 |
* which accompanies this distribution, and is available at |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
7 |
* |
|
8 |
* Contributors: |
|
9 |
* Google, Inc. - initial API and implementation |
|
10 |
*******************************************************************************/ |
|
11 |
package org.txm.rcp.editors; |
|
12 |
|
|
13 |
import java.io.FileInputStream; |
|
14 |
import java.io.IOException; |
|
15 |
import java.io.InputStream; |
|
16 |
import java.util.HashMap; |
|
17 |
import java.util.Map; |
|
18 |
|
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.graphics.Color; |
|
21 |
import org.eclipse.swt.graphics.Cursor; |
|
22 |
import org.eclipse.swt.graphics.Font; |
|
23 |
import org.eclipse.swt.graphics.FontData; |
|
24 |
import org.eclipse.swt.graphics.GC; |
|
25 |
import org.eclipse.swt.graphics.Image; |
|
26 |
import org.eclipse.swt.graphics.ImageData; |
|
27 |
import org.eclipse.swt.graphics.RGB; |
|
28 |
import org.eclipse.swt.graphics.Rectangle; |
|
29 |
import org.eclipse.swt.widgets.Display; |
|
30 |
|
|
31 |
/** |
|
32 |
* Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc. |
|
33 |
* <p> |
|
34 |
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the |
|
35 |
* operating system resources managed by cached objects when those objects and OS resources are no longer |
|
36 |
* needed (e.g. on application shutdown) |
|
37 |
* <p> |
|
38 |
* This class may be freely distributed as part of any application or plugin. |
|
39 |
* <p> |
|
40 |
* @author scheglov_ke |
|
41 |
* @author Dan Rubel |
|
42 |
*/ |
|
43 |
public class SWTResourceManager { |
|
44 |
//////////////////////////////////////////////////////////////////////////// |
|
45 |
// |
|
46 |
// Color |
|
47 |
// |
|
48 |
//////////////////////////////////////////////////////////////////////////// |
|
49 |
private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>(); |
|
50 |
/** |
|
51 |
* Returns the system {@link Color} matching the specific ID. |
|
52 |
* |
|
53 |
* @param systemColorID |
|
54 |
* the ID value for the color |
|
55 |
* @return the system {@link Color} matching the specific ID |
|
56 |
*/ |
|
57 |
public static Color getColor(int systemColorID) { |
|
58 |
Display display = Display.getCurrent(); |
|
59 |
return display.getSystemColor(systemColorID); |
|
60 |
} |
|
61 |
/** |
|
62 |
* Returns a {@link Color} given its red, green and blue component values. |
|
63 |
* |
|
64 |
* @param r |
|
65 |
* the red component of the color |
|
66 |
* @param g |
|
67 |
* the green component of the color |
|
68 |
* @param b |
|
69 |
* the blue component of the color |
|
70 |
* @return the {@link Color} matching the given red, green and blue component values |
|
71 |
*/ |
|
72 |
public static Color getColor(int r, int g, int b) { |
|
73 |
return getColor(new RGB(r, g, b)); |
|
74 |
} |
|
75 |
/** |
|
76 |
* Returns a {@link Color} given its RGB value. |
|
77 |
* |
|
78 |
* @param rgb |
|
79 |
* the {@link RGB} value of the color |
|
80 |
* @return the {@link Color} matching the RGB value |
|
81 |
*/ |
|
82 |
public static Color getColor(RGB rgb) { |
|
83 |
Color color = m_colorMap.get(rgb); |
|
84 |
if (color == null) { |
|
85 |
Display display = Display.getCurrent(); |
|
86 |
color = new Color(display, rgb); |
|
87 |
m_colorMap.put(rgb, color); |
|
88 |
} |
|
89 |
return color; |
|
90 |
} |
|
91 |
/** |
|
92 |
* Dispose of all the cached {@link Color}'s. |
|
93 |
*/ |
|
94 |
public static void disposeColors() { |
|
95 |
for (Color color : m_colorMap.values()) { |
|
96 |
color.dispose(); |
|
97 |
} |
|
98 |
m_colorMap.clear(); |
|
99 |
} |
|
100 |
//////////////////////////////////////////////////////////////////////////// |
|
101 |
// |
|
102 |
// Image |
|
103 |
// |
|
104 |
//////////////////////////////////////////////////////////////////////////// |
|
105 |
/** |
|
106 |
* Maps image paths to images. |
|
107 |
*/ |
|
108 |
private static Map<String, Image> m_imageMap = new HashMap<String, Image>(); |
|
109 |
/** |
|
110 |
* Returns an {@link Image} encoded by the specified {@link InputStream}. |
|
111 |
* |
|
112 |
* @param stream |
|
113 |
* the {@link InputStream} encoding the image data |
|
114 |
* @return the {@link Image} encoded by the specified input stream |
|
115 |
*/ |
|
116 |
protected static Image getImage(InputStream stream) throws IOException { |
|
117 |
try { |
|
118 |
Display display = Display.getCurrent(); |
|
119 |
ImageData data = new ImageData(stream); |
|
120 |
if (data.transparentPixel > 0) { |
|
121 |
return new Image(display, data, data.getTransparencyMask()); |
|
122 |
} |
|
123 |
return new Image(display, data); |
|
124 |
} finally { |
|
125 |
stream.close(); |
|
126 |
} |
|
127 |
} |
|
128 |
/** |
|
129 |
* Returns an {@link Image} stored in the file at the specified path. |
|
130 |
* |
|
131 |
* @param path |
|
132 |
* the path to the image file |
|
133 |
* @return the {@link Image} stored in the file at the specified path |
|
134 |
*/ |
|
135 |
public static Image getImage(String path) { |
|
136 |
Image image = m_imageMap.get(path); |
|
137 |
if (image == null) { |
|
138 |
try { |
|
139 |
image = getImage(new FileInputStream(path)); |
|
140 |
m_imageMap.put(path, image); |
|
141 |
} catch (Exception e) { |
|
142 |
image = getMissingImage(); |
|
143 |
m_imageMap.put(path, image); |
|
144 |
} |
|
145 |
} |
|
146 |
return image; |
|
147 |
} |
|
148 |
/** |
|
149 |
* Returns an {@link Image} stored in the file at the specified path relative to the specified class. |
|
150 |
* |
|
151 |
* @param clazz |
|
152 |
* the {@link Class} relative to which to find the image |
|
153 |
* @param path |
|
154 |
* the path to the image file, if starts with <code>'/'</code> |
|
155 |
* @return the {@link Image} stored in the file at the specified path |
|
156 |
*/ |
|
157 |
public static Image getImage(Class<?> clazz, String path) { |
|
158 |
String key = clazz.getName() + '|' + path; |
|
159 |
Image image = m_imageMap.get(key); |
|
160 |
if (image == null) { |
|
161 |
try { |
|
162 |
image = getImage(clazz.getResourceAsStream(path)); |
|
163 |
m_imageMap.put(key, image); |
|
164 |
} catch (Exception e) { |
|
165 |
image = getMissingImage(); |
|
166 |
m_imageMap.put(key, image); |
|
167 |
} |
|
168 |
} |
|
169 |
return image; |
|
170 |
} |
|
171 |
private static final int MISSING_IMAGE_SIZE = 10; |
|
172 |
/** |
|
173 |
* @return the small {@link Image} that can be used as placeholder for missing image. |
|
174 |
*/ |
|
175 |
private static Image getMissingImage() { |
|
176 |
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); |
|
177 |
// |
|
178 |
GC gc = new GC(image); |
|
179 |
gc.setBackground(getColor(SWT.COLOR_RED)); |
|
180 |
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); |
|
181 |
gc.dispose(); |
|
182 |
// |
|
183 |
return image; |
|
184 |
} |
|
185 |
/** |
|
186 |
* Style constant for placing decorator image in top left corner of base image. |
|
187 |
*/ |
|
188 |
public static final int TOP_LEFT = 1; |
|
189 |
/** |
|
190 |
* Style constant for placing decorator image in top right corner of base image. |
|
191 |
*/ |
|
192 |
public static final int TOP_RIGHT = 2; |
|
193 |
/** |
|
194 |
* Style constant for placing decorator image in bottom left corner of base image. |
|
195 |
*/ |
|
196 |
public static final int BOTTOM_LEFT = 3; |
|
197 |
/** |
|
198 |
* Style constant for placing decorator image in bottom right corner of base image. |
|
199 |
*/ |
|
200 |
public static final int BOTTOM_RIGHT = 4; |
|
201 |
/** |
|
202 |
* Internal value. |
|
203 |
*/ |
|
204 |
protected static final int LAST_CORNER_KEY = 5; |
|
205 |
/** |
|
206 |
* Maps images to decorated images. |
|
207 |
*/ |
|
208 |
@SuppressWarnings("unchecked") |
|
209 |
private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; |
|
210 |
/** |
|
211 |
* Returns an {@link Image} composed of a base image decorated by another image. |
|
212 |
* |
|
213 |
* @param baseImage |
|
214 |
* the base {@link Image} that should be decorated |
|
215 |
* @param decorator |
|
216 |
* the {@link Image} to decorate the base image |
|
217 |
* @return {@link Image} The resulting decorated image |
|
218 |
*/ |
|
219 |
public static Image decorateImage(Image baseImage, Image decorator) { |
|
220 |
return decorateImage(baseImage, decorator, BOTTOM_RIGHT); |
|
221 |
} |
|
222 |
/** |
|
223 |
* Returns an {@link Image} composed of a base image decorated by another image. |
|
224 |
* |
|
225 |
* @param baseImage |
|
226 |
* the base {@link Image} that should be decorated |
|
227 |
* @param decorator |
|
228 |
* the {@link Image} to decorate the base image |
|
229 |
* @param corner |
|
230 |
* the corner to place decorator image |
|
231 |
* @return the resulting decorated {@link Image} |
|
232 |
*/ |
|
233 |
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { |
|
234 |
if (corner <= 0 || corner >= LAST_CORNER_KEY) { |
|
235 |
throw new IllegalArgumentException("Wrong decorate corner"); |
|
236 |
} |
|
237 |
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; |
|
238 |
if (cornerDecoratedImageMap == null) { |
|
239 |
cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); |
|
240 |
m_decoratedImageMap[corner] = cornerDecoratedImageMap; |
|
241 |
} |
|
242 |
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); |
|
243 |
if (decoratedMap == null) { |
|
244 |
decoratedMap = new HashMap<Image, Image>(); |
|
245 |
cornerDecoratedImageMap.put(baseImage, decoratedMap); |
|
246 |
} |
|
247 |
// |
|
248 |
Image result = decoratedMap.get(decorator); |
|
249 |
if (result == null) { |
|
250 |
Rectangle bib = baseImage.getBounds(); |
|
251 |
Rectangle dib = decorator.getBounds(); |
|
252 |
// |
|
253 |
result = new Image(Display.getCurrent(), bib.width, bib.height); |
|
254 |
// |
|
255 |
GC gc = new GC(result); |
|
256 |
gc.drawImage(baseImage, 0, 0); |
|
257 |
if (corner == TOP_LEFT) { |
|
258 |
gc.drawImage(decorator, 0, 0); |
|
259 |
} else if (corner == TOP_RIGHT) { |
|
260 |
gc.drawImage(decorator, bib.width - dib.width, 0); |
|
261 |
} else if (corner == BOTTOM_LEFT) { |
|
262 |
gc.drawImage(decorator, 0, bib.height - dib.height); |
|
263 |
} else if (corner == BOTTOM_RIGHT) { |
|
264 |
gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); |
|
265 |
} |
|
266 |
gc.dispose(); |
|
267 |
// |
|
268 |
decoratedMap.put(decorator, result); |
|
269 |
} |
|
270 |
return result; |
|
271 |
} |
|
272 |
/** |
|
273 |
* Dispose all of the cached {@link Image}'s. |
|
274 |
*/ |
|
275 |
public static void disposeImages() { |
|
276 |
// dispose loaded images |
|
277 |
{ |
|
278 |
for (Image image : m_imageMap.values()) { |
|
279 |
image.dispose(); |
|
280 |
} |
|
281 |
m_imageMap.clear(); |
|
282 |
} |
|
283 |
// dispose decorated images |
|
284 |
for (int i = 0; i < m_decoratedImageMap.length; i++) { |
|
285 |
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; |
|
286 |
if (cornerDecoratedImageMap != null) { |
|
287 |
for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { |
|
288 |
for (Image image : decoratedMap.values()) { |
|
289 |
image.dispose(); |
|
290 |
} |
|
291 |
decoratedMap.clear(); |
|
292 |
} |
|
293 |
cornerDecoratedImageMap.clear(); |
|
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
//////////////////////////////////////////////////////////////////////////// |
|
298 |
// |
|
299 |
// Font |
|
300 |
// |
|
301 |
//////////////////////////////////////////////////////////////////////////// |
|
302 |
/** |
|
303 |
* Maps font names to fonts. |
|
304 |
*/ |
|
305 |
private static Map<String, Font> m_fontMap = new HashMap<String, Font>(); |
|
306 |
/** |
|
307 |
* Maps fonts to their bold versions. |
|
308 |
*/ |
|
309 |
private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>(); |
|
310 |
/** |
|
311 |
* Returns a {@link Font} based on its name, height and style. |
|
312 |
* |
|
313 |
* @param name |
|
314 |
* the name of the font |
|
315 |
* @param height |
|
316 |
* the height of the font |
|
317 |
* @param style |
|
318 |
* the style of the font |
|
319 |
* @return {@link Font} The font matching the name, height and style |
|
320 |
*/ |
|
321 |
public static Font getFont(String name, int height, int style) { |
|
322 |
return getFont(name, height, style, false, false); |
|
323 |
} |
|
324 |
/** |
|
325 |
* Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline |
|
326 |
* flags are also supported. |
|
327 |
* |
|
328 |
* @param name |
|
329 |
* the name of the font |
|
330 |
* @param size |
|
331 |
* the size of the font |
|
332 |
* @param style |
|
333 |
* the style of the font |
|
334 |
* @param strikeout |
|
335 |
* the strikeout flag (warning: Windows only) |
|
336 |
* @param underline |
|
337 |
* the underline flag (warning: Windows only) |
|
338 |
* @return {@link Font} The font matching the name, height, style, strikeout and underline |
|
339 |
*/ |
|
340 |
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { |
|
341 |
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; |
|
342 |
Font font = m_fontMap.get(fontName); |
|
343 |
if (font == null) { |
|
344 |
FontData fontData = new FontData(name, size, style); |
|
345 |
if (strikeout || underline) { |
|
346 |
try { |
|
347 |
Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$ |
|
348 |
Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$ |
|
349 |
if (logFont != null && logFontClass != null) { |
|
350 |
if (strikeout) { |
|
351 |
logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ |
|
352 |
} |
|
353 |
if (underline) { |
|
354 |
logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ |
|
355 |
} |
|
356 |
} |
|
357 |
} catch (Throwable e) { |
|
358 |
System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$ |
|
359 |
} |
|
360 |
} |
|
361 |
font = new Font(Display.getCurrent(), fontData); |
|
362 |
m_fontMap.put(fontName, font); |
|
363 |
} |
|
364 |
return font; |
|
365 |
} |
|
366 |
/** |
|
367 |
* Returns a bold version of the given {@link Font}. |
|
368 |
* |
|
369 |
* @param baseFont |
|
370 |
* the {@link Font} for which a bold version is desired |
|
371 |
* @return the bold version of the given {@link Font} |
|
372 |
*/ |
|
373 |
public static Font getBoldFont(Font baseFont) { |
|
374 |
Font font = m_fontToBoldFontMap.get(baseFont); |
|
375 |
if (font == null) { |
|
376 |
FontData fontDatas[] = baseFont.getFontData(); |
|
377 |
FontData data = fontDatas[0]; |
|
378 |
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD); |
|
379 |
m_fontToBoldFontMap.put(baseFont, font); |
|
380 |
} |
|
381 |
return font; |
|
382 |
} |
|
383 |
/** |
|
384 |
* Dispose all of the cached {@link Font}'s. |
|
385 |
*/ |
|
386 |
public static void disposeFonts() { |
|
387 |
// clear fonts |
|
388 |
for (Font font : m_fontMap.values()) { |
|
389 |
font.dispose(); |
|
390 |
} |
|
391 |
m_fontMap.clear(); |
|
392 |
// clear bold fonts |
|
393 |
for (Font font : m_fontToBoldFontMap.values()) { |
|
394 |
font.dispose(); |
|
395 |
} |
|
396 |
m_fontToBoldFontMap.clear(); |
|
397 |
} |
|
398 |
//////////////////////////////////////////////////////////////////////////// |
|
399 |
// |
|
400 |
// Cursor |
|
401 |
// |
|
402 |
//////////////////////////////////////////////////////////////////////////// |
|
403 |
/** |
|
404 |
* Maps IDs to cursors. |
|
405 |
*/ |
|
406 |
private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>(); |
|
407 |
/** |
|
408 |
* Returns the system cursor matching the specific ID. |
|
409 |
* |
|
410 |
* @param id |
|
411 |
* int The ID value for the cursor |
|
412 |
* @return Cursor The system cursor matching the specific ID |
|
413 |
*/ |
|
414 |
public static Cursor getCursor(int id) { |
|
415 |
Integer key = Integer.valueOf(id); |
|
416 |
Cursor cursor = m_idToCursorMap.get(key); |
|
417 |
if (cursor == null) { |
|
418 |
cursor = new Cursor(Display.getDefault(), id); |
|
419 |
m_idToCursorMap.put(key, cursor); |
|
420 |
} |
|
421 |
return cursor; |
|
422 |
} |
|
423 |
/** |
|
424 |
* Dispose all of the cached cursors. |
|
425 |
*/ |
|
426 |
public static void disposeCursors() { |
|
427 |
for (Cursor cursor : m_idToCursorMap.values()) { |
|
428 |
cursor.dispose(); |
|
429 |
} |
|
430 |
m_idToCursorMap.clear(); |
|
431 |
} |
|
432 |
//////////////////////////////////////////////////////////////////////////// |
|
433 |
// |
|
434 |
// General |
|
435 |
// |
|
436 |
//////////////////////////////////////////////////////////////////////////// |
|
437 |
/** |
|
438 |
* Dispose of cached objects and their underlying OS resources. This should only be called when the cached |
|
439 |
* objects are no longer needed (e.g. on application shutdown). |
|
440 |
*/ |
|
441 |
public static void dispose() { |
|
442 |
disposeColors(); |
|
443 |
disposeImages(); |
|
444 |
disposeFonts(); |
|
445 |
disposeCursors(); |
|
446 |
} |
|
447 |
} |
|
0 | 448 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TestEditor.java (revision 660) | ||
---|---|---|
23 | 23 |
import org.eclipse.ui.PartInitException; |
24 | 24 |
import org.eclipse.ui.part.EditorPart; |
25 | 25 |
import org.eclipse.swt.custom.StackLayout; |
26 |
import org.eclipse.wb.swt.SWTResourceManager; |
|
27 | 26 |
import org.eclipse.swt.layout.FillLayout; |
28 | 27 |
import org.eclipse.swt.layout.FormLayout; |
29 | 28 |
import org.eclipse.swt.layout.FormData; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMResultEditorInput.java (revision 660) | ||
---|---|---|
79 | 79 |
|
80 | 80 |
/** |
81 | 81 |
* Deletes the linked TXM result. |
82 |
* @return |
|
82 |
* @return true if the object is deleted
|
|
83 | 83 |
*/ |
84 | 84 |
public boolean deleteResult() { |
85 | 85 |
try { |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/parameters/ParametersDialog.java (revision 660) | ||
---|---|---|
378 | 378 |
* If all variables are set by "args" then don't show the dialog box |
379 | 379 |
* |
380 | 380 |
* @param bean |
381 |
* @return |
|
381 |
* @return true if the user has clicked on the "OK" button
|
|
382 | 382 |
*/ |
383 | 383 |
public static boolean open(final Object bean) { |
384 | 384 |
errorOpen = true; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/StructuralUnitsCombosGroup.java (revision 660) | ||
---|---|---|
72 | 72 |
* @param selectedSU |
73 | 73 |
* @param selectedSUP |
74 | 74 |
* @param addEmptyEntries |
75 |
* @param multiSelection |
|
76 | 75 |
*/ |
77 | 76 |
public StructuralUnitsCombosGroup(Composite parent, TXMEditor editor, boolean autoCompute, StructuralUnit selectedSU, StructuralUnitProperty selectedSUP, boolean addEmptyEntries) { |
78 | 77 |
this(parent, SWT.NONE, editor, autoCompute, selectedSU, selectedSUP, addEmptyEntries); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/BaseAbstractHandler.java (revision 660) | ||
---|---|---|
24 | 24 |
|
25 | 25 |
/** |
26 | 26 |
* Checks the Statistics Engine running status and displays a message if it's not running. |
27 |
* @return |
|
27 |
* @return true if the stat engine is available
|
|
28 | 28 |
*/ |
29 | 29 |
public boolean checkStatsEngine() { |
30 | 30 |
if (!RStatsEngine.isStarted()) { |
... | ... | |
38 | 38 |
|
39 | 39 |
/** |
40 | 40 |
* Checks the Corpus Engine running status and displays a message if it's not running. |
41 |
* @return |
|
41 |
* @return true if the corpus engine is available
|
|
42 | 42 |
*/ |
43 | 43 |
public boolean checkCorpusEngine() { |
44 | 44 |
if (!CQPEngine.isInitialized()) { |
... | ... | |
55 | 55 |
|
56 | 56 |
/** |
57 | 57 |
* Gets the current selected object. |
58 |
* @param event the ExecutionEvent that provok the command call. |
|
59 |
* @return |
|
58 |
* @param event the ExecutionEvent that provoke the command call.
|
|
59 |
* @return the corpora view current selection
|
|
60 | 60 |
*/ |
61 | 61 |
public Object getSelection(ExecutionEvent event) { |
62 | 62 |
|
... | ... | |
82 | 82 |
Log.severe("Can not execute command " + this.getClass() + " with the selection " + selection); |
83 | 83 |
return false; |
84 | 84 |
} |
85 |
|
|
86 | 85 |
} |
tmp/org.txm.jodconverter.core/src/main/java/org/artofsolving/jodconverter/office/DefaultOfficeManagerConfiguration.java (revision 660) | ||
---|---|---|
100 | 100 |
* Defaults to the system temporary directory as specified by the <code>java.io.tmpdir</code> system property. |
101 | 101 |
* |
102 | 102 |
* @param workDir |
103 |
* @return |
|
103 |
* @return the DefaultOfficeManagerConfiguration
|
|
104 | 104 |
*/ |
105 | 105 |
public DefaultOfficeManagerConfiguration setWorkDir(File workDir) { |
106 | 106 |
checkArgumentNotNull("workDir", workDir); |
tmp/org.txm.internalview.core/src/org/txm/internalview/core/functions/InternalView.java (revision 660) | ||
---|---|---|
144 | 144 |
|
145 | 145 |
/** |
146 | 146 |
* |
147 |
* @return |
|
147 |
* @return the current page content map
|
|
148 | 148 |
* @throws CqiClientException |
149 | 149 |
*/ |
150 | 150 |
public HashMap<Property, List<String>> getCurrentPageContent() throws CqiClientException { |
tmp/org.txm.utils/src/org/txm/utils/xml/UpdateXSLParameters.java (revision 660) | ||
---|---|---|
30 | 30 |
* update the content of "param" elements which name attribute exists in the parameters map with the parameter map value. |
31 | 31 |
* |
32 | 32 |
* @param parameters |
33 |
* @return |
|
33 |
* @return true if document if successfully saved
|
|
34 | 34 |
* @throws ParserConfigurationException |
35 | 35 |
* @throws SAXException |
36 | 36 |
* @throws IOException |
37 |
* |
|
37 | 38 |
*/ |
38 | 39 |
public boolean process(HashMap<String, String> parameters) throws ParserConfigurationException, SAXException, IOException { |
39 | 40 |
if (!xslFile.exists()) { |
tmp/org.txm.utils/src/org/txm/utils/xml/DomUtils.java (revision 660) | ||
---|---|---|
91 | 91 |
* |
92 | 92 |
* @param element the doc |
93 | 93 |
* @param writer the writer |
94 |
* @return true, if successful
|
|
94 |
* @return true if successful |
|
95 | 95 |
*/ |
96 | 96 |
public static boolean save(Document doc, Writer writer) |
97 | 97 |
{ |
... | ... | |
141 | 141 |
* Save. |
142 | 142 |
* |
143 | 143 |
* @param doc the doc |
144 |
* @param outfile the outfile |
|
144 |
* @param outfile the output file
|
|
145 | 145 |
* @return true, if successful |
146 | 146 |
* @throws FileNotFoundException |
147 | 147 |
* @throws UnsupportedEncodingException |
148 |
* @return true if successful |
|
148 | 149 |
*/ |
149 | 150 |
public static boolean save(Document doc, File outfile) throws UnsupportedEncodingException, FileNotFoundException |
150 | 151 |
{ |
tmp/org.txm.utils/src/org/txm/utils/zip/GZip.java (revision 660) | ||
---|---|---|
31 | 31 |
* |
32 | 32 |
* @param gzFile |
33 | 33 |
* @param outDir |
34 |
* @return |
|
34 |
* @return the extracted file
|
|
35 | 35 |
* @throws IOException |
36 | 36 |
*/ |
37 | 37 |
public static File uncompress(File gzFile, File outDir) throws IOException { |
tmp/org.txm.utils/src/org/txm/utils/zip/Zip.java (revision 660) | ||
---|---|---|
281 | 281 |
* @param file the file |
282 | 282 |
* @param folder the folder |
283 | 283 |
* @param deleteZipAfter the delete zip after |
284 |
* @param monitor, change progress state |
|
284 |
* @param monitor change progress state |
|
285 |
* |
|
285 | 286 |
* @throws IOException Signals that an I/O exception has occurred. |
286 | 287 |
*/ |
287 | 288 |
public static void decompress(final File file, final File folder, final boolean deleteZipAfter, IProgressMonitor monitor) |
... | ... | |
492 | 493 |
* Try to get the root folder of the archive. If there is no root folder, the Zip filename is used |
493 | 494 |
* |
494 | 495 |
* @param zipFile |
495 |
* @return |
|
496 |
* @return the root directory of the archive
|
|
496 | 497 |
*/ |
497 | 498 |
public static String getRoot(File zipFile) |
498 | 499 |
{ |
... | ... | |
518 | 519 |
* List the ZIP file content |
519 | 520 |
* |
520 | 521 |
* @param zipFile |
521 |
* @return |
|
522 |
* @return the list of files in the archive
|
|
522 | 523 |
*/ |
523 | 524 |
public static ArrayList<String> listFiles(File zipFile) |
524 | 525 |
{ |
tmp/org.txm.utils/src/org/txm/utils/messages/Utf8NLS.java (revision 660) | ||
---|---|---|
18 | 18 |
|
19 | 19 |
/** |
20 | 20 |
* Initializes messages using UTF-8 encoding. |
21 |
* @param baseName |
|
21 |
* |
|
22 |
* The base name is built using the class fullname |
|
23 |
* |
|
22 | 24 |
* @param clazz |
23 | 25 |
*/ |
24 | 26 |
public static void initializeMessages(final Class<?> clazz) { |
tmp/org.txm.utils/src/org/txm/utils/i18n/DetectBOM.java (revision 660) | ||
---|---|---|
8 | 8 |
|
9 | 9 |
/** |
10 | 10 |
* Simple class to detect BOM in a file |
11 |
* {@link} http://blog.ymango.com/2010/09/16/29
|
|
11 |
* @see http://blog.ymango.com/2010/09/16/29
|
|
12 | 12 |
* |
13 | 13 |
* @author mdecorde |
14 | 14 |
* |
tmp/org.txm.index.rcp/src/org/txm/index/rcp/editors/IndexEditor.java (revision 660) | ||
---|---|---|
775 | 775 |
} |
776 | 776 |
|
777 | 777 |
/** |
778 |
* Fill display area. |
|
778 |
* Fill display area using the index top index and index number of result per page parameters.
|
|
779 | 779 |
* |
780 |
* @param from the from |
|
781 |
* @param to the to |
|
782 | 780 |
*/ |
783 | 781 |
public void fillDisplayArea() { |
784 | 782 |
// System.out.println("call fill from "+from+" to "+to); |
tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 660) | ||
---|---|---|
397 | 397 |
/** |
398 | 398 |
* keep the vmax lines more frequents. |
399 | 399 |
* |
400 |
* @param vmax the vmax |
|
401 | 400 |
*/ |
402 | 401 |
public void cut() { |
403 | 402 |
if (pVmaxFilter == null) return; |
... | ... | |
432 | 431 |
|
433 | 432 |
|
434 | 433 |
/** |
435 |
* remove linen which frequency is not in the [Fmin,Fmax] interval. |
|
434 |
* remove linen which frequency is not in the [Fmin,Fmax] interval parameters.
|
|
436 | 435 |
* |
437 |
* @param Fmin the fmin |
|
438 |
* @param Fmax the fmax |
|
439 |
*/ |
|
436 |
**/ |
|
440 | 437 |
public void filterLines() { |
441 | 438 |
if (pFminFilter == null && pFmaxFilter == null) return; |
442 | 439 |
if (!(pFminFilter > 0 && pFmaxFilter > 0 && pFminFilter <= pFmaxFilter)) return; |
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/results/ChartResult.java (revision 660) | ||
---|---|---|
137 | 137 |
|
138 | 138 |
/** |
139 | 139 |
* |
140 |
* @param update |
|
141 |
* @return |
|
140 |
* @return true if the chart has been rendered |
|
142 | 141 |
* @throws Exception |
143 | 142 |
*/ |
144 | 143 |
protected boolean renderChart() throws Exception { |
tmp/org.txm.annotation.core/src/org/txm/annotation/core/KRAnnotationEngine.java (revision 660) | ||
---|---|---|
73 | 73 |
* Utility method to get a knowledge repository configuration |
74 | 74 |
* |
75 | 75 |
* @param name the repository name |
76 |
* @return |
|
76 |
* @return the KR configuration map
|
|
77 | 77 |
*/ |
78 | 78 |
public static HashMap<String, HashMap<String, ?>> getKnowledgeRepositoryConfiguration(String name, Element e) { |
79 | 79 |
HashMap<String, HashMap<String, ?>> repConfiguration = new HashMap<String, HashMap<String, ?>>(); |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/query/Query.java (revision 660) | ||
---|---|---|
103 | 103 |
|
104 | 104 |
/** |
105 | 105 |
* Normalize white chars. |
106 |
* |
|
107 |
* @param str the str |
|
108 |
* @return the string with white chars normalized |
|
109 |
* @author sheiden |
|
110 |
*/ |
|
111 |
public static String normalizeWhiteChars(String str) { |
|
112 |
|
|
113 |
/* |
|
106 |
* |
|
107 |
* SLH algorithm : |
|
114 | 108 |
* - first normalize white chars : We don't know from where the query |
115 | 109 |
* comes from and how it was produced (pasted from a text editor after |
116 | 110 |
* having been double-clicked and copied, typed in the query input |
... | ... | |
145 | 139 |
* |
146 | 140 |
* In case of doubt, the user should be able to switch to another |
147 | 141 |
* strategy. |
148 |
*/ |
|
142 |
* |
|
143 |
* @param str the str |
|
144 |
* @return the string with white chars normalized |
|
145 |
*/ |
|
146 |
public static String normalizeWhiteChars(String str) { |
|
149 | 147 |
|
150 | 148 |
// normalize everything white to space |
151 | 149 |
String str1 = str.replaceAll("\\s+", " "); //$NON-NLS-1$ //$NON-NLS-2$ |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/query/Match.java (revision 660) | ||
---|---|---|
62 | 62 |
/** |
63 | 63 |
* Instantiates a new match. |
64 | 64 |
* |
65 |
* @param queryResult |
|
66 |
* the query result |
|
67 | 65 |
* @param start |
68 | 66 |
* the cqp index of the start of the match |
69 | 67 |
* @param end |
tmp/org.txm.searchengine.cqp.core/src/org/txm/importer/cwb/BuildCwbEncodeArgsFromWTC.java (revision 660) | ||
---|---|---|
67 | 67 |
/** The tagattrs. */ |
68 | 68 |
HashMap<String, HashSet<String>> tagattrs = new HashMap<String, HashSet<String>>(); |
69 | 69 |
int nWordProps = 0; |
70 |
|
|
70 | 71 |
/** |
71 | 72 |
* process !!!. |
72 | 73 |
* |
73 | 74 |
* @param wtcfile the xmlfile |
74 | 75 |
* @param wordstag the wordstag |
75 |
* @return true, if successful
|
|
76 |
* @return true if successful |
|
76 | 77 |
* @throws XMLStreamException the xML stream exception |
77 | 78 |
* @throws FactoryConfigurationError the factory configuration error |
78 | 79 |
* @throws IOException Signals that an I/O exception has occurred. |
tmp/org.txm.searchengine.cqp.core/src/org/txm/importer/cwb/CwbEncode.java (revision 660) | ||
---|---|---|
76 | 76 |
* |
77 | 77 |
* @param pathToExecutable the path to the executable |
78 | 78 |
* @param pathToData the path to data |
79 |
* @param inputFile the input file
|
|
79 |
* @param inputFiles the input files
|
|
80 | 80 |
* @param pathToRegistry the path to the registry |
81 | 81 |
* @param pAttributes the positional attribute |
82 |
* @param sAttributes the structural atribute |
|
83 |
* @return true, if successful
|
|
82 |
* @param sAttributes the structural attribute
|
|
83 |
* @return true if successful |
|
84 | 84 |
* @throws ServerNotFoundException the server not found exception |
85 | 85 |
* @throws IOException |
86 | 86 |
* @throws InterruptedException |
... | ... | |
154 | 154 |
* |
155 | 155 |
* @param pathToExecutable the path to the executable of cwb-encode |
156 | 156 |
* @param pathToData the path to cwb indexes |
157 |
* @param inputFile the input file |
|
157 |
* @param inputFiles the input file
|
|
158 | 158 |
* @param pathToRegistry the path to registry |
159 | 159 |
* @param pAttributes the attributes |
160 | 160 |
* @param sAttributes the s attributes |
... | ... | |
290 | 290 |
* |
291 | 291 |
* @param wtcFiles |
292 | 292 |
* @param allwtcFile |
293 |
* @return |
|
293 |
* @return true if the WTC files are concatenated
|
|
294 | 294 |
* @throws IOException |
295 | 295 |
*/ |
296 | 296 |
public static boolean concat(ArrayList<File> wtcFiles, File allwtcFile) throws IOException { |
tmp/org.txm.referencer.core/src/org/txm/referencer/core/functions/Referencer.java (revision 660) | ||
---|---|---|
143 | 143 |
* Instantiates a new referencer. |
144 | 144 |
* |
145 | 145 |
* @param corpus the corpus |
146 |
* @param pQuery the query |
|
147 |
* @param pProperty the prop |
|
148 |
* @param pPattern the pattern |
|
149 |
* @param pHierarchicSort the hierarchic sort |
|
150 | 146 |
*/ |
151 | 147 |
public Referencer(Corpus corpus) { |
152 | 148 |
super(corpus); |
tmp/org.txm.libs.cqp/src/org/txm/libs/cqp/Utils.java (revision 660) | ||
---|---|---|
23 | 23 |
* @throws IOException |
24 | 24 |
* @throws FileNotFoundException |
25 | 25 |
* |
26 |
* @return The {@File} with the ungzipped content.
|
|
26 |
* @return The @see java.io.File with the ungzipped content.
|
|
27 | 27 |
*/ |
28 | 28 |
public static File unGzip(final File inputFile, final File outputDir) throws FileNotFoundException, IOException { |
29 | 29 |
|
... | ... | |
47 | 47 |
* @return |
48 | 48 |
* @throws FileNotFoundException |
49 | 49 |
* @throws IOException |
50 |
* @return the number of extracted files |
|
50 | 51 |
*/ |
51 | 52 |
public static int unGzipFilesInDirectory(final File inputDir) throws FileNotFoundException, IOException { |
52 | 53 |
File[] gzFiles = inputDir.listFiles(new FilenameFilter() { |
tmp/org.txm.core/src/java/org/txm/objects/SavedQuery.java (revision 660) | ||
---|---|---|
70 | 70 |
/** |
71 | 71 |
* Instantiates a new query log. |
72 | 72 |
* |
73 |
* @param b the b
|
|
73 |
* @param c the corpus
|
|
74 | 74 |
* @param query the query |
75 | 75 |
* @param examples the examples |
76 | 76 |
*/ |
tmp/org.txm.core/src/java/org/txm/objects/Edition.java (revision 660) | ||
---|---|---|
169 | 169 |
return pages.get(no); |
170 | 170 |
} |
171 | 171 |
|
172 |
public static final Pattern findNumbersPattern = Pattern.compile("([0-9]{1,10}+)"); //$NON-NLS-1$ |
|
173 |
|
|
172 | 174 |
/** |
173 | 175 |
* Gets the int. |
174 | 176 |
* |
175 | 177 |
* @param wordid the wordid |
176 | 178 |
* @return the int |
177 | 179 |
*/ |
178 |
public static final Pattern findNumbersPattern = Pattern.compile("([0-9]{1,10}+)"); //$NON-NLS-1$ |
|
179 | 180 |
private int getInt(String wordid) { |
180 | 181 |
|
181 | 182 |
int r = 0; |
Formats disponibles : Unified diff