Skip to content

Commit 211c324

Browse files
committed
Simplied the demo code into a single remote main.
1 parent a14fdef commit 211c324

7 files changed

Lines changed: 53 additions & 57 deletions

File tree

src/matlabcontrol/demo/DemoFrame.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@ public class DemoFrame extends JFrame {
6868
RETURN_PANEL_SIZE = new Dimension(PANEL_WIDTH, 250),
6969
METHOD_PANEL_SIZE = new Dimension(PANEL_WIDTH, 110 + 28 * ArrayPanel.NUM_ENTRIES),
7070
DESCRIPTION_PANE_SIZE = new Dimension(PANEL_WIDTH, 200),
71-
COMMAND_PANEL_SIZE = new Dimension(PANEL_WIDTH, METHOD_PANEL_SIZE.height +
72-
DESCRIPTION_PANE_SIZE.height),
73-
MAIN_PANEL_SIZE = new Dimension(PANEL_WIDTH, CONNECTION_PANEL_SIZE.height +
74-
COMMAND_PANEL_SIZE.height +
75-
RETURN_PANEL_SIZE.height);
71+
COMMAND_PANEL_SIZE = new Dimension(PANEL_WIDTH, METHOD_PANEL_SIZE.height + DESCRIPTION_PANE_SIZE.height),
72+
MAIN_PANEL_SIZE = new Dimension(PANEL_WIDTH, CONNECTION_PANEL_SIZE.height + COMMAND_PANEL_SIZE.height + RETURN_PANEL_SIZE.height);
7673
//Factory to create proxy
7774
private final MatlabProxyFactory _factory;
7875

@@ -86,7 +83,7 @@ public class DemoFrame extends JFrame {
8683

8784
public static BufferedImage getIcon() {
8885
try {
89-
return ImageIO.read(DemoFrame.class.getResource("/matlabcontrol/demo/icon.png"));
86+
return ImageIO.read(DemoFrame.class.getResource("/matlabcontrol/demo/logo_128.png"));
9087
} catch (Exception e) {
9188
e.printStackTrace();
9289
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
@@ -190,7 +187,6 @@ public void run() {
190187
status = STATUS_CONNECTED_EXISTING;
191188
} else {
192189
status = STATUS_CONNECTED_LAUNCHED;
193-
194190
}
195191
connectionPanel.setBorder(BorderFactory.createTitledBorder(status));
196192

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Code licensed under new-style BSD (see LICENSE).
3+
* All code up to tags/original: Copyright (c) 2013, Joshua Kaplan
4+
* All code after tags/original: Copyright (c) 2015, DiffPlug
5+
*/
6+
package matlabcontrol.demo;
7+
8+
import java.awt.EventQueue;
9+
import java.net.URL;
10+
import java.net.URLClassLoader;
11+
12+
import javax.swing.WindowConstants;
13+
14+
public class DemoMain {
15+
public static void main(String[] args) {
16+
new DemoMain();
17+
}
18+
19+
public DemoMain() {
20+
final int closeOperation = isRunningInsideMATLAB() ? WindowConstants.HIDE_ON_CLOSE : WindowConstants.EXIT_ON_CLOSE;
21+
EventQueue.invokeLater(new Runnable() {
22+
@Override
23+
public void run() {
24+
DemoFrame frame = new DemoFrame("matlabcontrol demo - Running Inside MATLAB", null);
25+
frame.setDefaultCloseOperation(closeOperation);
26+
frame.setVisible(true);
27+
}
28+
});
29+
}
30+
31+
private static boolean isRunningInsideMATLAB() {
32+
ClassLoader cl = ClassLoader.getSystemClassLoader();
33+
URL[] urls = ((URLClassLoader) cl).getURLs();
34+
for (URL url : urls) {
35+
if (url.toExternalForm().contains("matlab")) {
36+
return true;
37+
}
38+
}
39+
return false;
40+
}
41+
}

src/matlabcontrol/demo/InsideMatlab.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package matlabcontrol.demo;
77

88
import java.awt.EventQueue;
9+
import java.net.URL;
10+
import java.net.URLClassLoader;
911

1012
import javax.swing.WindowConstants;
1113

@@ -18,10 +20,13 @@
1820
* @author <a href="mailto:nonother@gmail.com">Joshua Kaplan</a>
1921
*/
2022
class InsideMatlab {
21-
/**
22-
* Launches the demo.
23-
*/
24-
public InsideMatlab() {
23+
public static void main(String[] args) {
24+
ClassLoader cl = ClassLoader.getSystemClassLoader();
25+
URL[] urls = ((URLClassLoader) cl).getURLs();
26+
for (URL url : urls) {
27+
System.out.println(url.getFile());
28+
}
29+
2530
EventQueue.invokeLater(new Runnable() {
2631
@Override
2732
public void run() {

src/matlabcontrol/demo/OSXAppearance.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/matlabcontrol/demo/RemoteMain.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
*/
1717
public class RemoteMain {
1818
public static void main(String[] args) {
19-
OSXAppearance.applyIfApplicable();
20-
2119
final String matlabLocation = (args.length == 1 ? args[0] : null);
22-
2320
EventQueue.invokeLater(new Runnable() {
2421
@Override
2522
public void run() {

src/matlabcontrol/demo/icon.png

-7.29 KB
Binary file not shown.
10.2 KB
Loading

0 commit comments

Comments
 (0)