fix sonarlint messages

This commit is contained in:
Eyck Jentzsch 2021-01-09 23:24:00 +01:00
parent 6c8e149be2
commit 916215c0c2
15 changed files with 278 additions and 275 deletions

View File

@ -111,7 +111,7 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
pcs.firePropertyChange(IWaveformDbLoader.LOADING_FINISHED, null, null); pcs.firePropertyChange(IWaveformDbLoader.LOADING_FINISHED, null, null);
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException } catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
| InvocationTargetException | SQLException | IntrospectionException e) { | InvocationTargetException | SQLException | IntrospectionException e) {
throw new InputFormatException(); throw new InputFormatException(e.toString());
} }
} }

View File

@ -165,8 +165,8 @@ public class TextDbLoader implements IWaveformDbLoader {
try { try {
mapDbFile = File.createTempFile("." + file.getName(), ".mapdb", null /* file.parentFile */); mapDbFile = File.createTempFile("." + file.getName(), ".mapdb", null /* file.parentFile */);
Files.delete(Paths.get(mapDbFile.getPath())); Files.delete(Paths.get(mapDbFile.getPath()));
} catch (IOException e1) { } catch (IOException e) {
throw new InputFormatException(); throw new InputFormatException(e.toString());
} }
mapDb = DBMaker.fileDB(mapDbFile).fileMmapEnable() // Always enable mmap mapDb = DBMaker.fileDB(mapDbFile).fileMmapEnable() // Always enable mmap
.fileMmapEnableIfSupported().fileMmapPreclearDisable().allocateStartSize(512l * 1024l * 1024l) .fileMmapEnableIfSupported().fileMmapPreclearDisable().allocateStartSize(512l * 1024l * 1024l)
@ -180,9 +180,7 @@ public class TextDbLoader implements IWaveformDbLoader {
transactions = parser.txSink.create(); transactions = parser.txSink.create();
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) { } catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
} catch (Exception e) { } catch (Exception e) {
System.out.println("---->>> Exception " + e.toString() + " caught while loading database"); throw new InputFormatException(e.toString());
e.printStackTrace();
throw new InputFormatException();
} }
for (TxStream stream : txStreams.values()) { for (TxStream stream : txStreams.values()) {
Thread t = new Thread() { Thread t = new Thread() {
@ -297,8 +295,9 @@ public class TextDbLoader implements IWaveformDbLoader {
* *
* @param inputStream the input stream * @param inputStream the input stream
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
* @throws InputFormatException Signals that the input format is wrong
*/ */
void parseInput(InputStream inputStream) throws IOException { void parseInput(InputStream inputStream) throws IOException, InputFormatException {
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String curLine = reader.readLine(); String curLine = reader.readLine();
String nextLine = null; String nextLine = null;
@ -336,8 +335,9 @@ public class TextDbLoader implements IWaveformDbLoader {
* @param nextLine the next line * @param nextLine the next line
* @return the string * @return the string
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
* @throws InputFormatException Signals that the input format is wrong
*/ */
private String parseLine(String curLine, String nextLine) throws IOException { private String parseLine(String curLine, String nextLine) throws IOException, InputFormatException {
String[] tokens = curLine.split("\\s+"); String[] tokens = curLine.split("\\s+");
if ("tx_record_attribute".equals(tokens[0])) { if ("tx_record_attribute".equals(tokens[0])) {
Long id = Long.parseLong(tokens[1]); Long id = Long.parseLong(tokens[1]);
@ -441,10 +441,8 @@ public class TextDbLoader implements IWaveformDbLoader {
} }
} else if (")".equals(tokens[0])) { } else if (")".equals(tokens[0])) {
generator = null; generator = null;
} else if ("a".equals(tokens[0])) {// matcher = line =~ /^a\s+(.+)$/
System.out.println("Don't know what to do with: '" + curLine + "'");
} else } else
System.out.println("Don't know what to do with: '" + curLine + "'"); throw new InputFormatException("Don't know what to do with: '" + curLine + "'");
return nextLine; return nextLine;
} }

View File

@ -771,8 +771,6 @@ public class WaveformView implements IWaveformView {
if (currentTxSelection != null) if (currentTxSelection != null)
currentTxSelection = null; currentTxSelection = null;
selectionChanged = true; selectionChanged = true;
} else {
System.err.println("Invalid selection");
} }
} }
} else { } else {

View File

@ -29,14 +29,17 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
/** /**
* Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc. * Utility class for managing OS resources associated with SWT controls such as
* colors, fonts, images, etc.
* <p> * <p>
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the * !!! IMPORTANT !!! Application code must explicitly invoke the
* operating system resources managed by cached objects when those objects and OS resources are no longer * <code>dispose()</code> method to release the operating system resources
* managed by cached objects when those objects and OS resources are no longer
* needed (e.g. on application shutdown) * needed (e.g. on application shutdown)
* <p> * <p>
* This class may be freely distributed as part of any application or plugin. * This class may be freely distributed as part of any application or plugin.
* <p> * <p>
*
* @author scheglov_ke * @author scheglov_ke
* @author Dan Rubel * @author Dan Rubel
*/ */
@ -46,57 +49,54 @@ public class SWTResourceManager {
// Color // Color
// //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>(); private static Map<RGB, Color> colorMap = new HashMap<>();
private SWTResourceManager() {}
/** /**
* Returns the system {@link Color} matching the specific ID. * Returns the system {@link Color} matching the specific ID.
* *
* @param systemColorID * @param systemColorID the ID value for the color
* the ID value for the color
* @return the system {@link Color} matching the specific ID * @return the system {@link Color} matching the specific ID
*/ */
public static Color getColor(int systemColorID) { public static Color getColor(int systemColorID) {
Display display = Display.getCurrent(); Display display = Display.getCurrent();
return display.getSystemColor(systemColorID); return display.getSystemColor(systemColorID);
} }
/** /**
* Returns a {@link Color} given its red, green and blue component values. * Returns a {@link Color} given its red, green and blue component values.
* *
* @param r * @param r the red component of the color
* the red component of the color * @param g the green component of the color
* @param g * @param b the blue component of the color
* the green component of the color * @return the {@link Color} matching the given red, green and blue component
* @param b * values
* the blue component of the color
* @return the {@link Color} matching the given red, green and blue component values
*/ */
public static Color getColor(int r, int g, int b) { public static Color getColor(int r, int g, int b) {
return getColor(new RGB(r, g, b)); return getColor(new RGB(r, g, b));
} }
/** /**
* Returns a {@link Color} given its RGB value. * Returns a {@link Color} given its RGB value.
* *
* @param rgb * @param rgb the {@link RGB} value of the color
* the {@link RGB} value of the color
* @return the {@link Color} matching the RGB value * @return the {@link Color} matching the RGB value
*/ */
public static Color getColor(RGB rgb) { public static Color getColor(RGB rgb) {
Color color = m_colorMap.get(rgb); return colorMap.computeIfAbsent(rgb, k -> new Color(Display.getCurrent(), rgb));
if (color == null) {
Display display = Display.getCurrent();
color = new Color(display, rgb);
m_colorMap.put(rgb, color);
}
return color;
} }
/** /**
* Dispose of all the cached {@link Color}'s. * Dispose of all the cached {@link Color}'s.
*/ */
public static void disposeColors() { public static void disposeColors() {
for (Color color : m_colorMap.values()) { for (Color color : colorMap.values()) {
color.dispose(); color.dispose();
} }
m_colorMap.clear(); colorMap.clear();
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// //
// Image // Image
@ -105,12 +105,12 @@ public class SWTResourceManager {
/** /**
* Maps image paths to images. * Maps image paths to images.
*/ */
private static Map<String, Image> m_imageMap = new HashMap<String, Image>(); private static Map<String, Image> imageMap = new HashMap<>();
/** /**
* Returns an {@link Image} encoded by the specified {@link InputStream}. * Returns an {@link Image} encoded by the specified {@link InputStream}.
* *
* @param stream * @param stream the {@link InputStream} encoding the image data
* the {@link InputStream} encoding the image data
* @return the {@link Image} encoded by the specified input stream * @return the {@link Image} encoded by the specified input stream
*/ */
protected static Image getImage(InputStream stream) throws IOException { protected static Image getImage(InputStream stream) throws IOException {
@ -125,52 +125,55 @@ public class SWTResourceManager {
stream.close(); stream.close();
} }
} }
/** /**
* Returns an {@link Image} stored in the file at the specified path. * Returns an {@link Image} stored in the file at the specified path.
* *
* @param path * @param path the path to the image file
* the path to the image file
* @return the {@link Image} stored in the file at the specified path * @return the {@link Image} stored in the file at the specified path
*/ */
public static Image getImage(String path) { public static Image getImage(String path) {
Image image = m_imageMap.get(path); Image image = imageMap.get(path);
if (image == null) { if (image == null) {
try { try {
image = getImage(new FileInputStream(path)); image = getImage(new FileInputStream(path));
m_imageMap.put(path, image); imageMap.put(path, image);
} catch (Exception e) { } catch (Exception e) {
image = getMissingImage(); image = getMissingImage();
m_imageMap.put(path, image); imageMap.put(path, image);
} }
} }
return image; return image;
} }
/** /**
* Returns an {@link Image} stored in the file at the specified path relative to the specified class. * Returns an {@link Image} stored in the file at the specified path relative to
* the specified class.
* *
* @param clazz * @param clazz the {@link Class} relative to which to find the image
* the {@link Class} relative to which to find the image * @param path the path to the image file, if starts with <code>'/'</code>
* @param path
* the path to the image file, if starts with <code>'/'</code>
* @return the {@link Image} stored in the file at the specified path * @return the {@link Image} stored in the file at the specified path
*/ */
public static Image getImage(Class<?> clazz, String path) { public static Image getImage(Class<?> clazz, String path) {
String key = clazz.getName() + '|' + path; String key = clazz.getName() + '|' + path;
Image image = m_imageMap.get(key); Image image = imageMap.get(key);
if (image == null) { if (image == null) {
try { try {
image = getImage(clazz.getResourceAsStream(path)); image = getImage(clazz.getResourceAsStream(path));
m_imageMap.put(key, image); imageMap.put(key, image);
} catch (Exception e) { } catch (Exception e) {
image = getMissingImage(); image = getMissingImage();
m_imageMap.put(key, image); imageMap.put(key, image);
} }
} }
return image; return image;
} }
private static final int MISSING_IMAGE_SIZE = 10; private static final int MISSING_IMAGE_SIZE = 10;
/** /**
* @return the small {@link Image} that can be used as placeholder for missing image. * @return the small {@link Image} that can be used as placeholder for missing
* image.
*/ */
private static Image getMissingImage() { private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
@ -182,6 +185,7 @@ public class SWTResourceManager {
// //
return image; return image;
} }
/** /**
* Style constant for placing decorator image in top left corner of base image. * Style constant for placing decorator image in top left corner of base image.
*/ */
@ -191,11 +195,13 @@ public class SWTResourceManager {
*/ */
public static final int TOP_RIGHT = 2; public static final int TOP_RIGHT = 2;
/** /**
* Style constant for placing decorator image in bottom left corner of base image. * Style constant for placing decorator image in bottom left corner of base
* image.
*/ */
public static final int BOTTOM_LEFT = 3; public static final int BOTTOM_LEFT = 3;
/** /**
* Style constant for placing decorator image in bottom right corner of base image. * Style constant for placing decorator image in bottom right corner of base
* image.
*/ */
public static final int BOTTOM_RIGHT = 4; public static final int BOTTOM_RIGHT = 4;
/** /**
@ -206,83 +212,77 @@ public class SWTResourceManager {
* Maps images to decorated images. * Maps images to decorated images.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; private static Map<Image, Map<Image, Image>>[] decoratedImageMap = new Map[LAST_CORNER_KEY];
/** /**
* Returns an {@link Image} composed of a base image decorated by another image. * Returns an {@link Image} composed of a base image decorated by another image.
* *
* @param baseImage * @param baseImage the base {@link Image} that should be decorated
* the base {@link Image} that should be decorated * @param decorator the {@link Image} to decorate the base image
* @param decorator
* the {@link Image} to decorate the base image
* @return {@link Image} The resulting decorated image * @return {@link Image} The resulting decorated image
*/ */
public static Image decorateImage(Image baseImage, Image decorator) { public static Image decorateImage(Image baseImage, Image decorator) {
return decorateImage(baseImage, decorator, BOTTOM_RIGHT); return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
} }
/** /**
* Returns an {@link Image} composed of a base image decorated by another image. * Returns an {@link Image} composed of a base image decorated by another image.
* *
* @param baseImage * @param baseImage the base {@link Image} that should be decorated
* the base {@link Image} that should be decorated * @param decorator the {@link Image} to decorate the base image
* @param decorator * @param corner the corner to place decorator image
* the {@link Image} to decorate the base image
* @param corner
* the corner to place decorator image
* @return the resulting decorated {@link Image} * @return the resulting decorated {@link Image}
*/ */
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
if (corner <= 0 || corner >= LAST_CORNER_KEY) { if (corner <= 0 || corner >= LAST_CORNER_KEY) {
throw new IllegalArgumentException("Wrong decorate corner"); throw new IllegalArgumentException("Wrong decorate corner");
} }
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; Map<Image, Map<Image, Image>> cornerDecoratedImageMap = decoratedImageMap[corner];
if (cornerDecoratedImageMap == null) { if (cornerDecoratedImageMap == null) {
cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); cornerDecoratedImageMap = new HashMap<>();
m_decoratedImageMap[corner] = cornerDecoratedImageMap; decoratedImageMap[corner] = cornerDecoratedImageMap;
} }
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); Map<Image, Image> decoratedMap = cornerDecoratedImageMap.computeIfAbsent(baseImage,
if (decoratedMap == null) { k -> new HashMap<Image, Image>());
decoratedMap = new HashMap<Image, Image>(); return decoratedMap.computeIfAbsent(decorator, k -> {
cornerDecoratedImageMap.put(baseImage, decoratedMap);
}
//
Image result = decoratedMap.get(decorator);
if (result == null) {
Rectangle bib = baseImage.getBounds(); Rectangle bib = baseImage.getBounds();
Rectangle dib = decorator.getBounds(); Rectangle dib = decorator.getBounds();
// Image result = new Image(Display.getCurrent(), bib.width, bib.height);
result = new Image(Display.getCurrent(), bib.width, bib.height);
//
GC gc = new GC(result); GC gc = new GC(result);
gc.drawImage(baseImage, 0, 0); gc.drawImage(baseImage, 0, 0);
if (corner == TOP_LEFT) { switch (corner) {
case TOP_LEFT:
gc.drawImage(decorator, 0, 0); gc.drawImage(decorator, 0, 0);
} else if (corner == TOP_RIGHT) { break;
case TOP_RIGHT:
gc.drawImage(decorator, bib.width - dib.width, 0); gc.drawImage(decorator, bib.width - dib.width, 0);
} else if (corner == BOTTOM_LEFT) { break;
case BOTTOM_LEFT:
gc.drawImage(decorator, 0, bib.height - dib.height); gc.drawImage(decorator, 0, bib.height - dib.height);
} else if (corner == BOTTOM_RIGHT) { break;
case BOTTOM_RIGHT:
gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
break;
default:
// do nothing
} }
gc.dispose(); gc.dispose();
//
decoratedMap.put(decorator, result);
}
return result; return result;
});
} }
/** /**
* Dispose all of the cached {@link Image}'s. * Dispose all of the cached {@link Image}'s.
*/ */
public static void disposeImages() { public static void disposeImages() {
// dispose loaded images // dispose loaded images
{ for (Image image : imageMap.values()) {
for (Image image : m_imageMap.values()) {
image.dispose(); image.dispose();
} }
m_imageMap.clear(); imageMap.clear();
}
// dispose decorated images // dispose decorated images
for (int i = 0; i < m_decoratedImageMap.length; i++) { for (int i = 0; i < decoratedImageMap.length; i++) {
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; Map<Image, Map<Image, Image>> cornerDecoratedImageMap = decoratedImageMap[i];
if (cornerDecoratedImageMap != null) { if (cornerDecoratedImageMap != null) {
for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
for (Image image : decoratedMap.values()) { for (Image image : decoratedMap.values()) {
@ -294,6 +294,7 @@ public class SWTResourceManager {
} }
} }
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// //
// Font // Font
@ -302,45 +303,39 @@ public class SWTResourceManager {
/** /**
* Maps font names to fonts. * Maps font names to fonts.
*/ */
private static Map<String, Font> m_fontMap = new HashMap<String, Font>(); private static Map<String, Font> fontMap = new HashMap<>();
/** /**
* Maps fonts to their bold versions. * Maps fonts to their bold versions.
*/ */
private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>(); private static Map<Font, Font> fontToBoldFontMap = new HashMap<>();
/** /**
* Returns a {@link Font} based on its name, height and style. * Returns a {@link Font} based on its name, height and style.
* *
* @param name * @param name the name of the font
* the name of the font * @param height the height of the font
* @param height * @param style the style of the font
* the height of the font
* @param style
* the style of the font
* @return {@link Font} The font matching the name, height and style * @return {@link Font} The font matching the name, height and style
*/ */
public static Font getFont(String name, int height, int style) { public static Font getFont(String name, int height, int style) {
return getFont(name, height, style, false, false); return getFont(name, height, style, false, false);
} }
/** /**
* Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline * Returns a {@link Font} based on its name, height and style. Windows-specific
* flags are also supported. * strikeout and underline flags are also supported.
* *
* @param name * @param name the name of the font
* the name of the font * @param size the size of the font
* @param size * @param style the style of the font
* the size of the font * @param strikeout the strikeout flag (warning: Windows only)
* @param style * @param underline the underline flag (warning: Windows only)
* the style of the font * @return {@link Font} The font matching the name, height, style, strikeout and
* @param strikeout * underline
* the strikeout flag (warning: Windows only)
* @param underline
* the underline flag (warning: Windows only)
* @return {@link Font} The font matching the name, height, style, strikeout and underline
*/ */
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
Font font = m_fontMap.get(fontName); return fontMap.computeIfAbsent(fontName, k -> {
if (font == null) {
FontData fontData = new FontData(name, size, style); FontData fontData = new FontData(name, size, style);
if (strikeout || underline) { if (strikeout || underline) {
try { try {
@ -354,47 +349,45 @@ public class SWTResourceManager {
logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
} }
} }
} catch (Throwable e) { } catch (Exception e) {
System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
font = new Font(Display.getCurrent(), fontData); return new Font(Display.getCurrent(), fontData);
m_fontMap.put(fontName, font);
} });
return font;
} }
/** /**
* Returns a bold version of the given {@link Font}. * Returns a bold version of the given {@link Font}.
* *
* @param baseFont * @param baseFont the {@link Font} for which a bold version is desired
* the {@link Font} for which a bold version is desired
* @return the bold version of the given {@link Font} * @return the bold version of the given {@link Font}
*/ */
public static Font getBoldFont(Font baseFont) { public static Font getBoldFont(Font baseFont) {
Font font = m_fontToBoldFontMap.get(baseFont); return fontToBoldFontMap.computeIfAbsent(baseFont, k -> {
if (font == null) { FontData[] fontDatas = baseFont.getFontData();
FontData fontDatas[] = baseFont.getFontData();
FontData data = fontDatas[0]; FontData data = fontDatas[0];
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD); return new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
m_fontToBoldFontMap.put(baseFont, font); });
}
return font;
} }
/** /**
* Dispose all of the cached {@link Font}'s. * Dispose all of the cached {@link Font}'s.
*/ */
public static void disposeFonts() { public static void disposeFonts() {
// clear fonts // clear fonts
for (Font font : m_fontMap.values()) { for (Font font : fontMap.values()) {
font.dispose(); font.dispose();
} }
m_fontMap.clear(); fontMap.clear();
// clear bold fonts // clear bold fonts
for (Font font : m_fontToBoldFontMap.values()) { for (Font font : fontToBoldFontMap.values()) {
font.dispose(); font.dispose();
} }
m_fontToBoldFontMap.clear(); fontToBoldFontMap.clear();
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// //
// Cursor // Cursor
@ -403,40 +396,38 @@ public class SWTResourceManager {
/** /**
* Maps IDs to cursors. * Maps IDs to cursors.
*/ */
private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>(); private static Map<Integer, Cursor> idToCursorMap = new HashMap<>();
/** /**
* Returns the system cursor matching the specific ID. * Returns the system cursor matching the specific ID.
* *
* @param id * @param id int The ID value for the cursor
* int The ID value for the cursor
* @return Cursor The system cursor matching the specific ID * @return Cursor The system cursor matching the specific ID
*/ */
public static Cursor getCursor(int id) { public static Cursor getCursor(int id) {
Integer key = Integer.valueOf(id); Integer key = Integer.valueOf(id);
Cursor cursor = m_idToCursorMap.get(key); return idToCursorMap.computeIfAbsent(key, k -> new Cursor(Display.getDefault(), id));
if (cursor == null) {
cursor = new Cursor(Display.getDefault(), id);
m_idToCursorMap.put(key, cursor);
}
return cursor;
} }
/** /**
* Dispose all of the cached cursors. * Dispose all of the cached cursors.
*/ */
public static void disposeCursors() { public static void disposeCursors() {
for (Cursor cursor : m_idToCursorMap.values()) { for (Cursor cursor : idToCursorMap.values()) {
cursor.dispose(); cursor.dispose();
} }
m_idToCursorMap.clear(); idToCursorMap.clear();
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// //
// General // General
// //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
/** /**
* Dispose of cached objects and their underlying OS resources. This should only be called when the cached * Dispose of cached objects and their underlying OS resources. This should only
* objects are no longer needed (e.g. on application shutdown). * be called when the cached objects are no longer needed (e.g. on application
* shutdown).
*/ */
public static void dispose() { public static void dispose() {
disposeColors(); disposeColors();

View File

@ -113,9 +113,9 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
moduleStack=null; moduleStack=null;
} catch(IOException e) { } catch(IOException e) {
moduleStack=null; moduleStack=null;
throw new InputFormatException(); throw new InputFormatException(e.toString());
} }
if(!res) throw new InputFormatException(); if(!res) throw new InputFormatException("Could not parse VCD file");
// calculate max time of this database // calculate max time of this database
for(IWaveform waveform:signals) { for(IWaveform waveform:signals) {
NavigableMap<Long, IEvent[]> events =waveform.getEvents(); NavigableMap<Long, IEvent[]> events =waveform.getEvents();

View File

@ -15,6 +15,18 @@ package com.minres.scviewer.database;
*/ */
public class InputFormatException extends Exception { public class InputFormatException extends Exception {
/** The message. */
public final String message;
/**
* Instantiates a new input format exception.
*
* @param string the string
*/
public InputFormatException(String string) {
message=string;
}
/** The Constant serialVersionUID. */ /** The Constant serialVersionUID. */
private static final long serialVersionUID = 8676129878197783368L; private static final long serialVersionUID = 8676129878197783368L;

View File

@ -287,5 +287,5 @@
<addons xmi:id="_95PftnNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/> <addons xmi:id="_95PftnNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
<addons xmi:id="_95Pft3NmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/> <addons xmi:id="_95Pft3NmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
<addons xmi:id="_95PfuHNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/> <addons xmi:id="_95PfuHNmEeWBq8z1Dv39LA" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
<addons xmi:id="_zSk-cIkcEeWxJ_wPkM6yGQ" elementId="org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon"/> <addons xmi:id="_zSk-cIkcEeWxJ_wPkM6yGQ" elementId="org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon"/>
</application:Application> </application:Application>

View File

@ -8,7 +8,7 @@ public class AppModelId {
public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENCH_COMMANDS_MODEL = "org.eclipse.e4.ui.workbench.commands.model"; public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENCH_COMMANDS_MODEL = "org.eclipse.e4.ui.workbench.commands.model";
public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENCH_CONTEXTS_MODEL = "org.eclipse.e4.ui.workbench.contexts.model"; public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENCH_CONTEXTS_MODEL = "org.eclipse.e4.ui.workbench.contexts.model";
public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENCH_HANDLER_MODEL = "org.eclipse.e4.ui.workbench.handler.model"; public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENCH_HANDLER_MODEL = "org.eclipse.e4.ui.workbench.handler.model";
public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENC__H_ADDONS_DNDADDON_DNDADDON = "org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon"; public static final String ADDON_ORG_ECLIPSE_E4_UI_WORKBENCH_ADDONS_DNDADDON_DNDADDON = "org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon";
public static final String APPLICATION_ORG_ECLIPSE_E4_IDE_APPLICATION = "org.eclipse.e4.ide.application"; public static final String APPLICATION_ORG_ECLIPSE_E4_IDE_APPLICATION = "org.eclipse.e4.ide.application";
public static final String BINDINGCONTEXT_ORG_ECLIPSE_UI_CONTEXTS_DIALOG = "org.eclipse.ui.contexts.dialog"; public static final String BINDINGCONTEXT_ORG_ECLIPSE_UI_CONTEXTS_DIALOG = "org.eclipse.ui.contexts.dialog";
public static final String BINDINGCONTEXT_ORG_ECLIPSE_UI_CONTEXTS_DIALOGANDWINDOW = "org.eclipse.ui.contexts.dialogAndWindow"; public static final String BINDINGCONTEXT_ORG_ECLIPSE_UI_CONTEXTS_DIALOGANDWINDOW = "org.eclipse.ui.contexts.dialogAndWindow";
@ -152,4 +152,6 @@ public class AppModelId {
public static final String TRIMBAR_ORG_ECLIPSE_UI_MAIN_TOOLBAR = "org.eclipse.ui.main.toolbar"; public static final String TRIMBAR_ORG_ECLIPSE_UI_MAIN_TOOLBAR = "org.eclipse.ui.main.toolbar";
public static final String TRIMBAR_ORG_ECLIPSE_UI_TRIM_STATUS = "org.eclipse.ui.trim.status"; public static final String TRIMBAR_ORG_ECLIPSE_UI_TRIM_STATUS = "org.eclipse.ui.trim.status";
public static final String WINDOW_COM_MINRES_SCVIEWER_E4_APPLICATION_DIALOG_ABOUTSCVIEWER = "com.minres.scviewer.e4.application.dialog.aboutscviewer"; public static final String WINDOW_COM_MINRES_SCVIEWER_E4_APPLICATION_DIALOG_ABOUTSCVIEWER = "com.minres.scviewer.e4.application.dialog.aboutscviewer";
private AppModelId(){}
} }

View File

@ -12,12 +12,12 @@ package com.minres.scviewer.e4.application;
import java.io.IOException; import java.io.IOException;
import javax.annotation.PostConstruct;
import javax.inject.Inject; import javax.inject.Inject;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
@ -32,9 +32,6 @@ import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.eclipse.e4.core.services.log.Logger;
import com.minres.scviewer.e4.application.options.Options; import com.minres.scviewer.e4.application.options.Options;
import com.minres.scviewer.e4.application.options.Options.Multiplicity; import com.minres.scviewer.e4.application.options.Options.Multiplicity;
@ -50,15 +47,6 @@ public class E4LifeCycle {
@Inject private Logger logger; @Inject private Logger logger;
/**
* Post construct.
*
* @param eventBroker the event broker
*/
@PostConstruct
private static void postConstruct(final IEventBroker eventBroker) {
}
/** /**
* Post context create. Open a database if given on command line using the OpenViewHandler * Post context create. Open a database if given on command line using the OpenViewHandler
* *
@ -79,9 +67,7 @@ public class E4LifeCycle {
System.exit(1); System.exit(1);
} }
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() { eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, event -> {
@Override
public void handleEvent(Event event) {
Location instanceLocation = Platform.getInstanceLocation(); Location instanceLocation = Platform.getInstanceLocation();
try { try {
boolean isLocked = instanceLocation.isLocked(); boolean isLocked = instanceLocation.isLocked();
@ -105,7 +91,6 @@ public class E4LifeCycle {
ctx.modify("config", confFile); //$NON-NLS-1$ ctx.modify("config", confFile); //$NON-NLS-1$
}); });
} }
}
}); });
} }

View File

@ -53,8 +53,34 @@ public class HeapStatus extends Composite {
private Image disabledGcImage; private Image disabledGcImage;
/** The arm col. */ /** The arm col. */
private Color bgCol, usedMemCol, lowMemCol, freeMemCol, topLeftCol, bottomRightCol, sepCol, textCol, markCol, private Color bgCol;
armCol;
/** The used mem col. */
private Color usedMemCol;
/** The low mem col. */
private Color lowMemCol;
/** The free mem col. */
private Color freeMemCol;
/** The top left col. */
private Color topLeftCol;
/** The bottom right col. */
private Color bottomRightCol;
/** The sep col. */
private Color sepCol;
/** The text col. */
private Color textCol;
/** The mark col. */
private Color markCol;
/** The arm col. */
private Color armCol;
/** The button. */ /** The button. */
private Canvas button; private Canvas button;
@ -241,6 +267,11 @@ public class HeapStatus extends Composite {
}); });
} }
/**
* Sets the background.
*
* @param color the new background
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -254,6 +285,11 @@ public class HeapStatus extends Composite {
button.update(); button.update();
} }
/**
* Sets the foreground.
*
* @param color the new foreground
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -272,6 +308,11 @@ public class HeapStatus extends Composite {
button.update(); button.update();
} }
/**
* Gets the foreground.
*
* @return the foreground
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -329,6 +370,14 @@ public class HeapStatus extends Composite {
} }
} }
/**
* Compute size.
*
* @param wHint the w hint
* @param hHint the h hint
* @param changed the changed
* @return the point
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -681,6 +730,9 @@ public class HeapStatus extends Composite {
super("&Set Mark"); super("&Set Mark");
} }
/**
* Run.
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -704,6 +756,9 @@ public class HeapStatus extends Composite {
super("&Clear Mark"); super("&Clear Mark");
} }
/**
* Run.
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -729,6 +784,9 @@ public class HeapStatus extends Composite {
setChecked(showMax); setChecked(showMax);
} }
/**
* Run.
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View File

@ -109,10 +109,7 @@ public class AboutDialog extends Dialog {
styleRange.fontStyle = SWT.BOLD; styleRange.fontStyle = SWT.BOLD;
styledText.setStyleRange(styleRange); styledText.setStyleRange(styleRange);
///^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ ///^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
Pattern pattern = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w\\.-]*)*\\/?"); //$NON-NLS-1$ Pattern pattern = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w\\.-]*)*\\/?"/*, Pattern.CASE_INSENSITIVE*/); //$NON-NLS-1$
// in case you would like to ignore case sensitivity,
// you could use this statement:
// Pattern pattern = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(productTitle+copyrightText); Matcher matcher = pattern.matcher(productTitle+copyrightText);
// check all occurance // check all occurance
while (matcher.find()) { while (matcher.find()) {

View File

@ -46,6 +46,7 @@ import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.wb.swt.ResourceManager; import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;
import com.minres.scviewer.e4.application.Constants; import com.minres.scviewer.e4.application.Constants;
@ -249,7 +250,7 @@ public class FileBrowserDialog extends TrayDialog {
fileNameEntry = new Text(bottomBar, SWT.BORDER); fileNameEntry = new Text(bottomBar, SWT.BORDER);
fileNameEntry.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); fileNameEntry.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
fileNameEntry.setEditable(false); //TODO: temporary disabled fileNameEntry.setEditable(false);
fileNameEntry.setEnabled(false); fileNameEntry.setEnabled(false);
filterCombo = new Combo(bottomBar, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); filterCombo = new Combo(bottomBar, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
@ -457,7 +458,7 @@ public class FileBrowserDialog extends TrayDialog {
@Override @Override
public Color getForeground(Object element) { public Color getForeground(Object element) {
return globber.matches(element) || ((File)element).isDirectory()? null: ResourceManager.getColor(SWT.COLOR_GRAY); return globber.matches(element) || ((File)element).isDirectory()? null: SWTResourceManager.getColor(SWT.COLOR_GRAY);
} }
} }

View File

@ -138,8 +138,10 @@ public class ResourceManager extends SWTResourceManager {
decoratedImageMap[corner] = cornerDecoratedImageMap; decoratedImageMap[corner] = cornerDecoratedImageMap;
} }
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.computeIfAbsent(baseImage, k -> new HashMap<Image, Image>()); Map<Image, Image> decoratedMap = cornerDecoratedImageMap.computeIfAbsent(baseImage, k -> new HashMap<Image, Image>());
Image result = decoratedMap.get(decorator); return decoratedMap.computeIfAbsent(decorator, k -> createImage(baseImage, decorator, corner));
if (result == null) { }
private static Image createImage(final Image baseImage, final Image decorator, final int corner) {
final Rectangle bib = baseImage.getBounds(); final Rectangle bib = baseImage.getBounds();
final Rectangle dib = decorator.getBounds(); final Rectangle dib = decorator.getBounds();
final Point baseImageSize = new Point(bib.width, bib.height); final Point baseImageSize = new Point(bib.width, bib.height);
@ -162,11 +164,7 @@ public class ResourceManager extends SWTResourceManager {
return baseImageSize; return baseImageSize;
} }
}; };
// return compositImageDesc.createImage();
result = compositImageDesc.createImage();
decoratedMap.put(decorator, result);
}
return result;
} }
private static ImageDataProvider getUnzoomedImageDataProvider(ImageData imageData) { private static ImageDataProvider getUnzoomedImageDataProvider(ImageData imageData) {

View File

@ -5,11 +5,12 @@ Bundle-SymbolicName: com.minres.scviewer.database.test
Bundle-Version: 1.0.1.qualifier Bundle-Version: 1.0.1.qualifier
Bundle-Vendor: MINRES Technologies GmbH Bundle-Vendor: MINRES Technologies GmbH
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.junit, Require-Bundle: com.minres.scviewer.database,
com.minres.scviewer.database,
com.minres.scviewer.database.sqlite;bundle-version="1.0.0", com.minres.scviewer.database.sqlite;bundle-version="1.0.0",
com.minres.scviewer.database.text;bundle-version="1.0.0", com.minres.scviewer.database.text;bundle-version="1.0.0",
com.minres.scviewer.database.vcd;bundle-version="1.0.0" com.minres.scviewer.database.vcd;bundle-version="1.0.0",
org.junit,
org.junit.jupiter.api
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/component.xml Service-Component: OSGI-INF/component.xml
Automatic-Module-Name: com.minres.scviewer.database.test Automatic-Module-Name: com.minres.scviewer.database.test

View File

@ -17,22 +17,15 @@ import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NavigableMap;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.minres.scviewer.database.AssociationType;
import com.minres.scviewer.database.DataType;
import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.IEvent; import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory; import com.minres.scviewer.database.IWaveformDbFactory;
import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.database.tx.ITxAttribute;
import com.minres.scviewer.database.tx.ITxEvent;
public class DatabaseServicesTest { public class DatabaseServicesTest {
@ -127,37 +120,6 @@ public class DatabaseServicesTest {
assertEquals(1, waveformDb.getChildNodes().size()); assertEquals(1, waveformDb.getChildNodes().size());
} }
//@Test
public void testTxLDb() throws Exception {
File f = new File("inputs/my_ldb.txldb").getAbsoluteFile();
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
assertEquals(1, waveformDb.getChildNodes().size());
List<IWaveform> waves = waveformDb.getAllWaves();
assertEquals(3, waves.size());
IWaveform stream = waves.get(0);
NavigableMap<Long, IEvent[]> eventsList = stream.getEvents();
assertEquals(27, eventsList.size());
Entry<Long, IEvent[]> eventEntry = eventsList.firstEntry();
assertEquals(100000000L, (long) eventEntry.getKey());
IEvent[] events = eventEntry.getValue();
assertEquals(1, events.length);
IEvent event = events[0];
assertEquals(EventKind.BEGIN, event.getKind());
assertTrue(event instanceof ITxEvent);
ITx tx = ((ITxEvent)event).getTransaction();
assertEquals(3L, (long) tx.getId());
List<ITxAttribute> attrs = tx.getAttributes();
assertEquals(1, attrs.size());
ITxAttribute attr = attrs.get(0);
assertEquals("data", attr.getName());
assertEquals(DataType.UNSIGNED, attr.getDataType());
assertEquals(AssociationType.END, attr.getType());
assertTrue(attr.getValue() instanceof Integer);
assertEquals(0, (int) attr.getValue());
}
@Test @Test
public void testHierarchicalVCD() throws Exception { public void testHierarchicalVCD() throws Exception {
File f = new File("inputs/simple_system.vcd").getAbsoluteFile(); File f = new File("inputs/simple_system.vcd").getAbsoluteFile();