Commit 218b9c8f authored by Michael Ruecker's avatar Michael Ruecker
Browse files

Merge branch 'dev' into 'master'

Dev

See merge request !3
parents c859957d f2995c32
......@@ -12,6 +12,10 @@ GPLv3, siehe COPYING
Changelog:
==========
Version 1.3.5
- Support für Java 9+
Version 1.3.4:
+ Einfügen per Strg+V fügt Elemente nun an der aktuellen Mausposition ein
......
......@@ -19,28 +19,52 @@ You should have received a copy of the GNU General Public License
along with Versys. If not, see <http://www.gnu.org/licenses/>.
-->
<project name="Versys.swtjar" basedir=".">
<taskdef name="swtjar" classname="org.swtjar.ant.SWTJarTask"
classpath="./lib/swtjar.jar"/>
<!-- Package cross platform SWT Jar -->
<swtjar jarfile="./build/jars/Versys-1.3.4.jar"
targetmainclass="versys.Versys"
swtversion="4.2.2">
<!-- Application Classes -->
<fileset dir="./bin" includes="**/*.class" />
<!-- Application Resources -->
<fileset dir="./" includes="**/*.png" />
<!-- Library classes -->
<zipfileset excludes="META-INF/*.MF" src="lib/swt-grouplayout.jar"/>
<!-- SWT Jars -->
<fileset dir="./lib" includes="swt-*-4.2.2.jar" />
</swtjar>
<project name="Versys" basedir=".">
<target name="clean" description="Clean classes">
<delete dir="./build" />
</target>
<target name="build" description="Compile classes" depends="clean">
<mkdir dir="./build" />
<mkdir dir="./build/classes" />
<javac destdir="./build/classes" includeantruntime="false" debug="true" source="9" target="9">
<src path="./src"/>
<classpath>
<fileset dir="./lib" includes="*.jar" />
</classpath>
</javac>
</target>
<target name="jar" description="Create Jars" depends="build" >
<mkdir dir="./build/jars/" />
<taskdef name="swtjar" classname="org.swtjar.ant.SWTJarTask">
<classpath>
<pathelement location="./lib/swtjar.jar"/>
</classpath>
</taskdef>
<swtjar jarfile="./build/jars/Versys-1.3.5.jar"
targetmainclass="versys.Versys"
swtversion="4.2.2">
<manifest>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="./build/classes" includes="**/*.class" />
<fileset dir="./" includes="**/*.png" />
<fileset dir="./lib" includes="swt-*-4.2.2.jar" />
<zipfileset excludes="META-INF/*.MF" src="lib/swt-grouplayout.jar"/>
</swtjar>
</target>
</project>
\ No newline at end of file
No preview for this file type
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
*******************************************************************************/
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.swt;
import java.io.FileInputStream;
......@@ -40,13 +40,14 @@ import org.eclipse.swt.widgets.Display;
* @author scheglov_ke
* @author Dan Rubel
*/
@SuppressWarnings("ALL")
public class SWTResourceManager {
////////////////////////////////////////////////////////////////////////////
//
// Color
//
////////////////////////////////////////////////////////////////////////////
private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
private static final Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
/**
* Returns the system {@link Color} matching the specific ID.
*
......@@ -105,7 +106,7 @@ public class SWTResourceManager {
/**
* Maps image paths to images.
*/
private static Map<String, Image> m_imageMap = new HashMap<String, Image>();
private static final Map<String, Image> m_imageMap = new HashMap<String, Image>();
/**
* Returns an {@link Image} encoded by the specified {@link InputStream}.
*
......@@ -206,7 +207,7 @@ 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 final Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
/**
* Returns an {@link Image} composed of a base image decorated by another image.
*
......@@ -302,11 +303,11 @@ public class SWTResourceManager {
/**
* Maps font names to fonts.
*/
private static Map<String, Font> m_fontMap = new HashMap<String, Font>();
private static final Map<String, Font> m_fontMap = new HashMap<String, Font>();
/**
* Maps fonts to their bold versions.
*/
private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>();
private static final Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>();
/**
* Returns a {@link Font} based on its name, height and style.
*
......@@ -373,7 +374,7 @@ public class SWTResourceManager {
public static Font getBoldFont(Font baseFont) {
Font font = m_fontToBoldFontMap.get(baseFont);
if (font == null) {
FontData fontDatas[] = baseFont.getFontData();
FontData[] fontDatas = baseFont.getFontData();
FontData data = fontDatas[0];
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
m_fontToBoldFontMap.put(baseFont, font);
......@@ -403,7 +404,7 @@ public class SWTResourceManager {
/**
* Maps IDs to cursors.
*/
private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>();
private static final Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>();
/**
* Returns the system cursor matching the specific ID.
*
......
......@@ -30,19 +30,19 @@ import versys.petrinet.PetriNet;
* @author Michael Rücker
*
*/
public class AutoSimulation implements Runnable {
class AutoSimulation implements Runnable {
private Canvas m_canvas;
private RunLog m_runLog;
private final Canvas m_canvas;
private final RunLog m_runLog;
private String m_tID;
private PetriNet m_petriNet;
private final PetriNet m_petriNet;
private int m_n; // Current step.
private int m_num; // The amount of simulated steps.
private int m_delay; // Delay between each step in milliseconds.
private Versys m_versys;
private int m_id;
private final int m_num; // The amount of simulated steps.
private final int m_delay; // Delay between each step in milliseconds.
private final Versys m_versys;
private final int m_id;
/**
* Constructs a new AutoSimulation for the the given Petri net.
......
......@@ -73,14 +73,14 @@ public class EditorTab {
private static int s_numTabs = 1;
private int m_id;
private Versys m_versys;
private final Versys m_versys;
private Canvas m_canvas;
private RunLog m_runLog;
private int m_logWidth;
private SashForm m_sashForm;
private Composite m_composite;
private TabItem m_tab;
private final TabItem m_tab;
private PetriNet m_lastNet;
private PetriNet m_currentNet;
......@@ -214,8 +214,8 @@ public class EditorTab {
m_mousePos = new Point(0, 0);
m_selectionRect = new Rectangle(0, 0, 0, 0);
m_undoStack = new Stack<PetriNet>();
m_redoStack = new Stack<PetriNet>();
m_undoStack = new Stack<>();
m_redoStack = new Stack<>();
m_tab.setText("*"+m_tab.getText());
m_changed = true;
......@@ -365,8 +365,6 @@ public class EditorTab {
case 1:
leftMouseButtonDown(e);
break;
case 2:
break;
case 3:
rightMouseButtonDown(e);
break;
......@@ -382,8 +380,6 @@ public class EditorTab {
case 1:
leftMouseButtonUp(e);
break;
case 2:
break;
case 3:
rightMouseButtonUp(e);
break;
......@@ -413,7 +409,7 @@ public class EditorTab {
* Returns whether or not there are elements on the undo stack.
* @return {@code true} if the undo stack holds at least one element, {@code false} otherwise
*/
public boolean canUndo() {
private boolean canUndo() {
return (!m_rightMouseDown) && (m_undoStack.size() > 0) && (getState() == PNState.PN_STATE_EDIT);
}
......@@ -421,7 +417,7 @@ public class EditorTab {
* Returns whether or not there are elements on the redo stack.
* @return {@code true} if the redo stack holds at least one element, {@code false} otherwise
*/
public boolean canRedo() {
private boolean canRedo() {
return (!m_rightMouseDown) && (m_redoStack.size() > 0) && (getState() == PNState.PN_STATE_EDIT);
}
......@@ -497,7 +493,7 @@ public class EditorTab {
*/
public void startManualSimulation() {
m_runLog = new RunLog(m_sashForm, SWT.NONE);
m_runLog = new RunLog(m_sashForm);
m_runLog.addListener(SWT.Resize, new Listener() {
@Override
......@@ -643,7 +639,7 @@ public class EditorTab {
* @return the default name for the next new tab
*/
public static String getDefaultName() {
return new String("Petrinetz "+s_numTabs);
return "Petrinetz " + s_numTabs;
}
/**
......@@ -709,7 +705,7 @@ public class EditorTab {
Point pointer = new Point((int)(e.x*m_zoomFactor), (int)(e.y*m_zoomFactor));
Component c = null;
Component c;
switch (m_versys.getCurrentTool()) {
case TOOLS_SELECT:
......@@ -809,7 +805,7 @@ public class EditorTab {
if(c != null && c.getType() == CType.CTYPE_TRANS && ((Transition)c).isEnabled()) {
try{
((Transition)c).fire();
m_runLog.log( ((Transition)c).getLabel().getText() );
m_runLog.log( c.getLabel().getText() );
}
catch(Exception ex) {
ex.printStackTrace();
......@@ -866,7 +862,6 @@ public class EditorTab {
* Increases the zoom level, up to a maximum of 250%.
*/
public void zoomIn() {
System.out.println("Zoom in");
if(m_zoomFactor > .4)
setZoomFactor(m_zoomFactor-0.1);
}
......@@ -883,7 +878,6 @@ public class EditorTab {
* Decreases the zoom level, down to a minimum of 33%.
*/
public void zoomOut() {
System.out.println("Zoom out");
if(m_zoomFactor < 3.0)
setZoomFactor(m_zoomFactor+0.1);
}
......@@ -892,23 +886,9 @@ public class EditorTab {
* Resets the zoom level to 100%.
*/
public void resetZoom() {
System.out.println("Resetting zoom");
setZoomFactor(1.0);
}
/**
* Checks whether a given point lies within the tab's current editor space.
* @param p point to be checked
* @return true if the point lies within the tab's current editor space, false otherwise
*/
public boolean contains(Point p) {
Rectangle r = m_canvas.getBounds();
return (p.x >= 0) &&
(p.x <= r.width) &&
(p.y >= 0) &&
(p.y <= r.height);
}
/**
* Sets the zoom factor to the passed value.
* @param zoomFactor the new zoom factor (0, inf]
......
......@@ -32,15 +32,15 @@ import org.eclipse.wb.swt.layout.grouplayout.GroupLayout;
* @author Michael Rücker
*
*/
public class RunLog extends Composite {
private Table m_log;
class RunLog extends Composite {
private final Table m_log;
private int m_step;
/**
* Create the composite.
* @param parent
* @param style
* @param parent the parent composite
*
*/
public RunLog(Composite parent, int style) {
public RunLog(Composite parent) {
super(parent, SWT.BORDER);
setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
......
......@@ -20,17 +20,13 @@
package versys;
import java.util.ArrayList;
import java.util.Objects;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
//import org.eclipse.swt.events.KeyEvent;
//import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
//import org.eclipse.swt.graphics.DeviceData;
//import org.eclipse.swt.graphics.DeviceData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
......@@ -49,14 +45,11 @@ import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.wb.swt.layout.grouplayout.GroupLayout;
import org.eclipse.wb.swt.layout.grouplayout.LayoutStyle;
import versys.debug.Sleak;
//import versys.debug.Sleak;
import versys.dialogs.AboutDialog;
import versys.dialogs.ErrorDialog;
import versys.dialogs.NamingDialog;
import versys.dialogs.TokenColorDialog;
import versys.dialogs.UnsavedChangesDialog;
//import versys.petrinet.Component;
import versys.petrinet.PNState;
import versys.petrinet.PetriNet;
......@@ -96,17 +89,17 @@ public class Versys {
/**
* The application's revision version number. This will be increased with every minor revision or bug fix.
*/
public final static short RevisionVersion = 4;
public final static short RevisionVersion = 5;
/**
* Location of assets.
*/
public final static String ASSETS = "/assets/";
protected static Versys s_versys;
private static Versys s_versys;
protected Shell m_shlVersys;
protected Display m_display;
private Shell m_shlVersys;
private Display m_display;
private ToolBar m_toolBar;
private ToolBar m_tokenBar;
......@@ -121,9 +114,7 @@ public class Versys {
private Tool m_lastTool = Tool.TOOLS_SELECT;
private Tool m_currentTool = Tool.TOOLS_SELECT;
private int m_currTokenType = PetriNet.TOKEN_BLACK;
private TabFolder m_tabFolder;
private ArrayList<EditorTab> m_editorTabs;
private EditorTab m_currentTab;
......@@ -139,10 +130,7 @@ public class Versys {
try {
s_versys = new Versys();
s_versys.open();
} catch(SWTException swte) {
swte.printStackTrace();
} catch (Exception e) {
} catch(Exception e) {
e.printStackTrace();
}
}
......@@ -151,7 +139,7 @@ public class Versys {
/**
* Open the window.
*/
public void open() {
private void open() {
m_display = Display.getDefault();
......@@ -169,7 +157,7 @@ public class Versys {
/**
* Create contents of the window, i.e., menus, tool bars and editor tab folder.
*/
protected void createContents() {
private void createContents() {
// === Shell ===
......@@ -226,7 +214,7 @@ public class Versys {
NamingDialog newDialog = new NamingDialog(m_shlVersys, EditorTab.getDefaultName());
String name = newDialog.open();
if(name != "") {
if(!Objects.equals(name, "")) {
m_currentTab = new EditorTab(s_versys, m_tabFolder, name);
m_editorTabs.add(m_currentTab);
m_tabFolder.setSelection(m_editorTabs.size()-1);
......@@ -661,7 +649,7 @@ public class Versys {
}
});
m_editorTabs = new ArrayList<EditorTab>();
m_editorTabs = new ArrayList<>();
m_currentTab = null;
Menu menu_3 = new Menu(m_tabFolder);
......@@ -759,10 +747,10 @@ public class Versys {
* the operation secceeded, {@code false} otherwise.
* @return {@code true} if the tab was closed, {@code false otherwise}
*/
protected boolean closeCurrentTab() {
private boolean closeCurrentTab() {
if(m_tabFolder.getSelectionIndex() == -1) return false;
boolean close = false;
boolean close;
if(m_currentTab.isChanged()) {
UnsavedChangesDialog uscDialog = new UnsavedChangesDialog(m_shlVersys, m_currentTab);
close = uscDialog.open();
......@@ -791,7 +779,7 @@ public class Versys {
* @param state the PNState
* @see PNState
*/
protected void setMode(PNState state) {
private void setMode(PNState state) {
switch(state) {
case PN_STATE_EDIT:
// System.out.println("Setting edit mode");
......@@ -842,15 +830,6 @@ public class Versys {
public Tool getCurrentTool() {
return m_currentTool;
}
/**
* Returns the currently selected token type.
* @return currently selected token type
* @see versys.petrinet.PetriNet
*/
public int getCurrentTokenType() {
return m_currTokenType;
}
/**
* Updates the progress bar according to the passed values.
......@@ -901,7 +880,7 @@ public class Versys {
/**
* Sets the currently selected tool.
* @param tool
* @param tool the tool to be selected
*/
private void switchTool(Tool tool) {
m_currentTool = tool;
......@@ -940,11 +919,7 @@ public class Versys {
return;
Point mp = m_currentTab.getMousePos();
System.out.println("Mousepos: "+mp);
// if(!m_currentTab.contains(mp)) return;
Point c = m_clipboard.getCenter();
System.out.println("Center: "+c);
m_clipboard.translate(mp.x-c.x, mp.y-c.y);
}
......
......@@ -27,7 +27,7 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
......@@ -49,11 +49,8 @@ import versys.petrinet.Transition;
*
*/
public class VersysFile {
private final String m_xmlHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
private final String m_xmlFooter = "</pnml>";
private PetriNet m_petriNet;
private String m_xml;
......@@ -77,7 +74,7 @@ public class VersysFile {
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(path), "UTF-8"));
new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8));
m_xml = "";
String line = br.readLine();
......@@ -96,10 +93,12 @@ public class VersysFile {
* Returns the XML representation of the Petri net
* @return XML representation of the Petri net
*/
public String getXML() throws UnsupportedEncodingException {
String xml = m_xmlHeader+"<pnml>\n";
private String getXML() {
String xmlHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
String xml = xmlHeader +"<pnml>\n";
xml += m_petriNet.toXML();
xml += m_xmlFooter;
String xmlFooter = "</pnml>";
xml += xmlFooter;
return xml;
// return new String(xml.getBytes(), "UTF-8");
}
......@@ -118,7 +117,7 @@ public class VersysFile {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = factory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(m_xml.getBytes("UTF-8"));
InputStream is = new ByteArrayInputStream(m_xml.getBytes(StandardCharsets.UTF_8));
Document doc = dBuilder.parse(is);
// Parse universe
......@@ -136,7 +135,7 @@ public class VersysFile {
boolean ttEnabled = eTokenType.getAttribute("enabled").equals("true");
for(int k=0; k < PetriNet.TOKEN_NUM_TYPES; k++) {
if(new String(Component.s_tokenIDs[k]).equals(ttID)) {
if(Component.s_tokenIDs[k].equals(ttID)) {
universe[k] = (universe[k] || ttEnabled);
break;
}
......@@ -289,7 +288,7 @@ public class VersysFile {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = factory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(m_xml.getBytes("UTF-8"));
InputStream is = new ByteArrayInputStream(m_xml.getBytes(StandardCharsets.UTF_8));
Document doc = dBuilder.parse(is);
// Create Petri net
......@@ -313,7 +312,7 @@ public class VersysFile {
public void saveToXML(String path) {
m_path = path;
try {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(path), "UTF-8");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(path), StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(getXML());
bw.close();
......
......@@ -11,6 +11,7 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import java.io.*;
@SuppressWarnings("ALL")
public class Sleak {
Display display;
Shell shell;
......@@ -145,7 +146,7 @@ String objectName (Object object) {
String string = object.toString ();
int index = string.lastIndexOf ('.');
if (index == -1) return string;
return string.substring (index + 1, string.length ());
return string.substring (index + 1);
}
void toggleStackTrace () {
......
......@@ -36,12 +36,12 @@ import versys.Versys;