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);
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
| InvocationTargetException | SQLException | IntrospectionException e) {
throw new InputFormatException();
throw new InputFormatException(e.toString());
}
}

View File

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

View File

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

View File

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

View File

@ -113,9 +113,9 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
moduleStack=null;
} catch(IOException e) {
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
for(IWaveform waveform:signals) {
NavigableMap<Long, IEvent[]> events =waveform.getEvents();

View File

@ -15,6 +15,18 @@ package com.minres.scviewer.database;
*/
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. */
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="_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="_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>

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_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_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 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";
@ -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_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";
private AppModelId(){}
}

View File

@ -12,12 +12,12 @@ package com.minres.scviewer.e4.application;
import java.io.IOException;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.IEclipseContext;
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.ui.basic.MPart;
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.osgi.service.datalocation.Location;
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.Multiplicity;
@ -49,15 +46,6 @@ import com.minres.scviewer.e4.application.options.Options.Separator;
public class E4LifeCycle {
@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
@ -68,47 +56,44 @@ public class E4LifeCycle {
@PostContextCreate
void postContextCreate(IApplicationContext appContext, final IEventBroker eventBroker,
final IEclipseContext workbenchContext) {
final String[] args = (String[])appContext.getArguments().get(IApplicationContext.APPLICATION_ARGS);
final Options opt = new Options(args, 0, Integer.MAX_VALUE);
opt.getSet()
.addOption("clearPersistedState", Multiplicity.ZERO_OR_ONE)
.addOption("c", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
.addOption("clearPersistedState", Multiplicity.ZERO_OR_ONE)
.addOption("c", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
if (!opt.check(Options.DEFAULT_SET, true, false)) {
logger.error(opt.getCheckErrors());
System.exit(1);
}
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() {
@Override
public void handleEvent(Event event) {
Location instanceLocation = Platform.getInstanceLocation();
try {
boolean isLocked = instanceLocation.isLocked();
if(isLocked)
instanceLocation.release();
} catch (IOException e) { }
if(!opt.getSet().getData().isEmpty()) {
Display.getCurrent().timerExec (100, () -> {
MApplication app= workbenchContext.get(MApplication.class);
EModelService modelService = workbenchContext.get(EModelService.class);
EPartService partService= workbenchContext.get(EPartService.class);
MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); //$NON-NLS-1$
part.setLabel(opt.getSet().getData().get(0));
MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$
partStack.getChildren().add(part);
partService.showPart(part, PartState.CREATE);
partService.showPart(part, PartState.ACTIVATE);
IEclipseContext ctx = part.getContext();
ctx.modify("input", opt.getSet().getData());
String confFile =opt.getSet().isSet("c")?opt.getSet().getOption("c").getResultValue(0):"";
ctx.modify("config", confFile); //$NON-NLS-1$
});
}
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, event -> {
Location instanceLocation = Platform.getInstanceLocation();
try {
boolean isLocked = instanceLocation.isLocked();
if(isLocked)
instanceLocation.release();
} catch (IOException e) { }
if(!opt.getSet().getData().isEmpty()) {
Display.getCurrent().timerExec (100, () -> {
MApplication app= workbenchContext.get(MApplication.class);
EModelService modelService = workbenchContext.get(EModelService.class);
EPartService partService= workbenchContext.get(EPartService.class);
MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); //$NON-NLS-1$
part.setLabel(opt.getSet().getData().get(0));
MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$
partStack.getChildren().add(part);
partService.showPart(part, PartState.CREATE);
partService.showPart(part, PartState.ACTIVATE);
IEclipseContext ctx = part.getContext();
ctx.modify("input", opt.getSet().getData());
String confFile =opt.getSet().isSet("c")?opt.getSet().getOption("c").getResultValue(0):"";
ctx.modify("config", confFile); //$NON-NLS-1$
});
}
});
}
/**
* Pre save.
*

View File

@ -53,8 +53,34 @@ public class HeapStatus extends Composite {
private Image disabledGcImage;
/** The arm col. */
private Color bgCol, usedMemCol, lowMemCol, freeMemCol, topLeftCol, bottomRightCol, sepCol, textCol, markCol,
armCol;
private Color bgCol;
/** 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. */
private Canvas button;
@ -241,6 +267,11 @@ public class HeapStatus extends Composite {
});
}
/**
* Sets the background.
*
* @param color the new background
*/
/*
* (non-Javadoc)
*
@ -254,6 +285,11 @@ public class HeapStatus extends Composite {
button.update();
}
/**
* Sets the foreground.
*
* @param color the new foreground
*/
/*
* (non-Javadoc)
*
@ -272,6 +308,11 @@ public class HeapStatus extends Composite {
button.update();
}
/**
* Gets the foreground.
*
* @return the foreground
*/
/*
* (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)
*
@ -681,6 +730,9 @@ public class HeapStatus extends Composite {
super("&Set Mark");
}
/**
* Run.
*/
/*
* (non-Javadoc)
*
@ -704,6 +756,9 @@ public class HeapStatus extends Composite {
super("&Clear Mark");
}
/**
* Run.
*/
/*
* (non-Javadoc)
*
@ -729,6 +784,9 @@ public class HeapStatus extends Composite {
setChecked(showMax);
}
/**
* Run.
*/
/*
* (non-Javadoc)
*

View File

@ -109,10 +109,7 @@ public class AboutDialog extends Dialog {
styleRange.fontStyle = SWT.BOLD;
styledText.setStyleRange(styleRange);
///^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
Pattern pattern = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w\\.-]*)*\\/?"); //$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);
Pattern pattern = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w\\.-]*)*\\/?"/*, Pattern.CASE_INSENSITIVE*/); //$NON-NLS-1$
Matcher matcher = pattern.matcher(productTitle+copyrightText);
// check all occurance
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.ToolItem;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;
import com.minres.scviewer.e4.application.Constants;
@ -249,7 +250,7 @@ public class FileBrowserDialog extends TrayDialog {
fileNameEntry = new Text(bottomBar, SWT.BORDER);
fileNameEntry.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
fileNameEntry.setEditable(false); //TODO: temporary disabled
fileNameEntry.setEditable(false);
fileNameEntry.setEnabled(false);
filterCombo = new Combo(bottomBar, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
@ -457,7 +458,7 @@ public class FileBrowserDialog extends TrayDialog {
@Override
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,35 +138,33 @@ public class ResourceManager extends SWTResourceManager {
decoratedImageMap[corner] = cornerDecoratedImageMap;
}
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.computeIfAbsent(baseImage, k -> new HashMap<Image, Image>());
Image result = decoratedMap.get(decorator);
if (result == null) {
final Rectangle bib = baseImage.getBounds();
final Rectangle dib = decorator.getBounds();
final Point baseImageSize = new Point(bib.width, bib.height);
CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {
@Override
protected void drawCompositeImage(int width, int height) {
drawImage(createCachedImageDataProvider(baseImage), 0, 0);
if (corner == TOP_LEFT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()) , 0, 0);
} else if (corner == TOP_RIGHT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, 0);
} else if (corner == BOTTOM_LEFT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), 0, bib.height - dib.height);
} else if (corner == BOTTOM_RIGHT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, bib.height - dib.height);
}
return decoratedMap.computeIfAbsent(decorator, k -> createImage(baseImage, decorator, corner));
}
private static Image createImage(final Image baseImage, final Image decorator, final int corner) {
final Rectangle bib = baseImage.getBounds();
final Rectangle dib = decorator.getBounds();
final Point baseImageSize = new Point(bib.width, bib.height);
CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {
@Override
protected void drawCompositeImage(int width, int height) {
drawImage(createCachedImageDataProvider(baseImage), 0, 0);
if (corner == TOP_LEFT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()) , 0, 0);
} else if (corner == TOP_RIGHT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, 0);
} else if (corner == BOTTOM_LEFT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), 0, bib.height - dib.height);
} else if (corner == BOTTOM_RIGHT) {
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, bib.height - dib.height);
}
@Override
protected Point getSize() {
return baseImageSize;
}
};
//
result = compositImageDesc.createImage();
decoratedMap.put(decorator, result);
}
return result;
}
@Override
protected Point getSize() {
return baseImageSize;
}
};
return compositImageDesc.createImage();
}
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-Vendor: MINRES Technologies GmbH
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.junit,
com.minres.scviewer.database,
Require-Bundle: com.minres.scviewer.database,
com.minres.scviewer.database.sqlite;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
Service-Component: OSGI-INF/component.xml
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.util.List;
import java.util.Map.Entry;
import java.util.NavigableMap;
import org.junit.After;
import org.junit.Before;
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.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
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 {
@ -127,37 +120,6 @@ public class DatabaseServicesTest {
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
public void testHierarchicalVCD() throws Exception {
File f = new File("inputs/simple_system.vcd").getAbsoluteFile();