Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.idea
/.classpath
/.factorypath
/.project
/.settings/
/target/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JAS-mine allows to separate data representation and management, which is automat

It has built-in utilities for communicating with an underlying relational database. In addition, the platform provides standard tools which are frequently used both in agent-based modelling and dynamic microsimulations, like design of experiments (DOE), run-time monitoring and visualization with plots and graphs (GUI), I/O communication, statistical analysis.

This repository contains the core libraries, for the gui libraries see https://github.com/jasmineRepo/JAS-mine-gui. See https://github.com/jasmineRepo for a list of JAS-mine projects including demonstration models.
See https://github.com/jasmineRepo for a list of JAS-mine projects including demonstration models.

See www.jas-mine.net for more details.

Expand Down
37 changes: 37 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,42 @@
<artifactId>h2</artifactId>
<version>2.4.240</version>
</dependency>

<!-- gui deps -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-dom</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-svggen</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.metawidget.modules</groupId>
<artifactId>metawidget-all</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.24</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.jdesktop</groupId>
<artifactId>beansbinding</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>3.7.1</version>
</dependency>
</dependencies>
</project>
177 changes: 177 additions & 0 deletions src/main/java/microsim/gui/GuiUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package microsim.gui;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyVetoException;

import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

import microsim.engine.SimulationManager;
import microsim.gui.probe.ProbeFrame;
import microsim.gui.shell.MicrosimShell;
import microsim.gui.shell.SimulationWindow;

public class GuiUtils {

public static class WindowGrabber extends WindowAdapter {
private JInternalFrame frame;

public WindowGrabber(JInternalFrame internalFrame) {
frame = internalFrame;
}

public void windowActivated(WindowEvent e) {
e.getWindow().setVisible(false);
frame.setVisible(true);
frame.setSize(e.getWindow().getSize());
}

public void windowClosed(WindowEvent e) {
frame.setVisible(false);
}
}

/**
* Opens a probe on the given object and return its reference.
*
* @param on
* Object to be probed. If on implements the IProbeFields
* interface the probe will use this set of fields.
* @param title
* The title of the probe frame.
* @param ownerModel
* The caller SimModel.
* @return A new instance of ProbeFrame.
*/
public static ProbeFrame openProbe(Object on, String title,
SimulationManager ownerModel) {
ProbeFrame pf = new ProbeFrame(on, title);
pf.setVisible(true);

return pf;
}

/**
* Opens a probe on the given object and return its reference.
*
* @param on
* Object to be probed. If on implements the IProbeFields
* interface the probe will use this set of fields.
* @param title
* The title of the probe frame.
* @return A new instance of ProbeFrame.
*/
public static ProbeFrame openProbe(Object on, String title) {
return openProbe(on, title, null);
}

public static void addWindow(Frame window) {
if (MicrosimShell.currentShell == null)
window.setVisible(true);
else {
if (window instanceof JFrame)
addWindow(buildInternalFrame((JFrame) window));
else {
SimulationWindow win = new SimulationWindow(null,
window.getTitle(), window);
win.setDefaultPosition(window.getBounds());

Rectangle r = win.getDefaultPosition();
window.setBounds(r.x, r.y, r.width, r.height);
window.setVisible(true);
}
}
}

public static void addWindow(Frame window, int x, int y, int width, int height) {

}

public static void addWindow(JInternalFrame window) {

final JDesktopPane desk = MicrosimShell.currentShell.getJDesktopPane();

desk.add(window);
window.show();

JInternalFrame[] allframes = desk.getAllFrames();
int count = allframes.length;
if (count == 0)
return;

// Determine the necessary grid size
int sqrt = (int) Math.sqrt(count);
int rows = sqrt;
int cols = sqrt;
if (rows * cols < count) {
cols++;
if (rows * cols < count) {
rows++;
}
}

// Define some initial values for size & location.
Dimension size = desk.getSize();

int x = 0;
int y = 0;

int maxH = 0;

for (int i = 0; i < allframes.length; i++) {
JInternalFrame f = allframes[i];
if (!f.isClosed() && f.isIcon()) {
try {
f.setIcon(false);
} catch (PropertyVetoException ignored) {
}
}

desk.getDesktopManager().resizeFrame(f, x, y, f.getWidth(), f.getHeight());
if (f.getHeight() > maxH)
maxH = f.getHeight();
x += f.getWidth();
if (x > size.width) {
x = 0;
y += maxH;
maxH = 0;
}
}
}

public static void addWindow(JInternalFrame window, int x, int y,
int width, int height) {
// SimulationWindow win = new SimulationWindow(null, window.getTitle(),
// window);
// win.setDefaultPosition(window.getBounds());

MicrosimShell.currentShell.getJDesktopPane().add(window);
// Rectangle r = win.getDefaultPosition();
window.reshape(x, y, width, height);
window.show();
}

public static JInternalFrame buildInternalFrame(JFrame frame) {
JInternalFrame intF = new JInternalFrame(frame.getTitle(),
frame.isResizable(), false, frame.isResizable(), true);

if (frame.getJMenuBar() != null)
intF.setJMenuBar(frame.getJMenuBar());

WindowGrabber wg = new WindowGrabber(intF);
frame.addWindowListener(wg);

intF.getContentPane().add(frame.getContentPane());
if (frame.getIconImage() != null)
intF.setFrameIcon(new ImageIcon(frame.getIconImage()));
intF.setSize(frame.getSize());
return intF;
}

}
66 changes: 66 additions & 0 deletions src/main/java/microsim/gui/colormap/ColorMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package microsim.gui.colormap;

/**
* A generic interface for color mappers. This interface
* is required by {@code Layer<NativeType>Drawer} objects to
* paint values on the screen.
*
* <p>
* Title: JAS
* </p>
* <p>
* Description: Java Agent-based Simulation library
* </p>
* <p>
* Copyright (C) 2002 Michele Sonnessa
* </p>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms
* of the GNU Lesser General Public License as published by the Free Software
* Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* @author Michele Sonnessa
* <p>
*/
public interface ColorMap {

/**
* Return the components of the color stored at given index.
*
* @param index The index of the color. It is a 0-based index of the color
* corresponding to the adding order.
* @return An array of 3 integers representing the RGB components of the color.
*/
public int[] getColorComponents(int index);

/**
* Return the index of the color mapped to the given value.
*
* @param value The value mapped to the color.
* @return The array index of the requested color.
*/
public int getColorIndex(int value);

/**
* Return the index of the color mapped to the given value.
*
* @param value The value mapped to the color.
* @return The array index of the requested color.
*/
public int getColorIndex(double value);

}
62 changes: 62 additions & 0 deletions src/main/java/microsim/gui/colormap/DoubleRangeColorMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package microsim.gui.colormap;

import java.awt.Color;

/**
* It builds automatically a color map varying between two colors on a variable
* range.
* <p>
* Title: JAS
* </p>
* <p>
* Description: Java Agent-based Simulation library
* </p>
* <p>
* Copyright: Copyright (c) 2002 under GPL library
* </p>
*
* @author Matteo Morini and Michele Sonnessa
*/

public class DoubleRangeColorMap extends FixedColorMap {
private int redStart, blueStart, greenStart;
private int redEnd, blueEnd, greenEnd;
private double rangeSize;

public DoubleRangeColorMap(int gradients, Color bottomColor, Color topColor,
double minValue, double maxValue) {
super(gradients);

if (maxValue <= minValue)
throw new ArrayIndexOutOfBoundsException("ColorDualRangeMap: range parameters are not corrected.");

redStart = bottomColor.getRed();
blueStart = bottomColor.getBlue();
greenStart = bottomColor.getGreen();

redEnd = topColor.getRed();
blueEnd = topColor.getBlue();
greenEnd = topColor.getGreen();

rangeSize = (maxValue - minValue) / gradients;

for (int i = 0; i < gradients; i++) {
// int[] c = getComponents(getBoundedCol(i * gap));
int[] c = new int[] { 0, 0, 0 };
c[0] = redStart + (int) ((redEnd - redStart) * i / gradients);
c[1] = greenStart + (int) ((greenEnd - redStart) * i / gradients);
c[2] = blueStart + (int) ((blueEnd - redStart) * i / gradients);

addColor(i, new Color(c[0], c[1], c[2]));
}
}

public int getColorIndex(double value) {
int i = (int) (value * rangeSize);
if (i < 0)
i = 0;
if (i >= colorList.length)
i = colorList.length - 1;
return i;
}
}
Loading
Loading