Skip to content

Commit

Permalink
refractive index wrong state was fixed
Browse files Browse the repository at this point in the history
2D plot for ampl
redraw plot after resize
reload a file viewer after file changing
fit 2D plot OX axis
  • Loading branch information
dsmunev committed Jun 23, 2021
1 parent c47bb38 commit e9fb506
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 92 deletions.
2 changes: 0 additions & 2 deletions src/main/java/adda/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public static void main(String[] args) {
public void run() {
try {
// BasicLookAndFeel darcula = new DarculaLaf();
UIManager.put("TextField.disabledBackground", Color.lightGray);
UIManager.put("TextField.inactiveBackground", Color.lightGray);
UIManager.setLookAndFeel(new FlatLightLaf());
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// UIManager.put("Label.disabledForeground",Color.lightGray);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/adda/application/MainForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<border type="none"/>
<children/>
</grid>
<grid id="851e1" layout-manager="GridBagLayout">
<grid id="851e1" binding="bottomPanel" layout-manager="GridBagLayout">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="1.0" weighty="1.0"/>
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/adda/application/MainForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MainForm {
private JTextArea actualCommandLineTextArea;
private JTextArea consoleTextArea;
private JScrollPane treeScroll;
private JPanel bottomPanel;


public JPanel getMainPanel() {
Expand Down Expand Up @@ -58,6 +59,10 @@ public void setLoadingVisible(boolean isVisible) {
overlay.setVisible(isVisible);
}

public JPanel getBottomPanel() {
return bottomPanel;
}

JPanel bufferPanel;
JPanel overlay;

Expand Down Expand Up @@ -99,6 +104,7 @@ public MainForm() {
treeScroll.getVerticalScrollBar().setUnitIncrement(16);
treeScroll.getHorizontalScrollBar().setUnitIncrement(16);

bottomPanel.setMinimumSize(new Dimension(300, 100));

}

Expand Down Expand Up @@ -152,16 +158,16 @@ public MainForm() {
gbc.weighty = 5.0;
gbc.fill = GridBagConstraints.BOTH;
panel1.add(centerPanel, gbc);
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridBagLayout());
bottomPanel = new JPanel();
bottomPanel.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 2;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
panel1.add(panel2, gbc);
panel1.add(bottomPanel, gbc);
final JTabbedPane tabbedPane1 = new JTabbedPane();
tabbedPane1.setBackground(new Color(-855310));
gbc = new GridBagConstraints();
Expand All @@ -170,7 +176,7 @@ public MainForm() {
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
panel2.add(tabbedPane1, gbc);
bottomPanel.add(tabbedPane1, gbc);
actualCommandLinePanel = new JPanel();
actualCommandLinePanel.setLayout(new BorderLayout(0, 0));
actualCommandLinePanel.setBackground(new Color(-855310));
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/adda/item/root/lineChart/LineChartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.geom.Rectangle2D;
import java.text.AttributedString;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -143,6 +145,12 @@ public void initFromModel(IModel model) {
panel.add(topPanel, BorderLayout.NORTH);
chartWrapperPanel = new JPanel();
panel.add(chartWrapperPanel);
panel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
refreshChart(model);
}
});
refreshChart(model);


Expand Down Expand Up @@ -200,6 +208,10 @@ public void refreshChart(IModel model) {
XYSeries series = new XYSeries(lineChartModel.getHeaders()[oyIndex]);
double maxY = Double.NEGATIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;

double maxX = Double.NEGATIVE_INFINITY;
double minX = Double.POSITIVE_INFINITY;

for (int i = 0; i < lineChartModel.getData()[0].length; i++) {
final double x = lineChartModel.getData()[oxIndex][i];
final double y = lineChartModel.getData()[oyIndex][i];
Expand All @@ -210,10 +222,16 @@ public void refreshChart(IModel model) {
if (y < minY) {
minY = y;
}
if (x > maxX) {
maxX = x;
}
if (x < minX) {
minX = x;
}
}
NumberAxis xAxis = new NumberAxis(lineChartModel.getHeaders()[oxIndex]);
xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

xAxis.setRange(minX, maxX+1);
ValueAxis yAxis;
if (lineChartModel.isLog()) {
if (minY > 0) {
Expand All @@ -231,6 +249,7 @@ public void refreshChart(IModel model) {
}
} else {
yAxis = new NumberAxis(lineChartModel.getHeaders()[oyIndex]);
yAxis.setRange(minY * (minY > 0 ? 0.99 : 1.01), maxY*(maxY > 0 ? 1.01 : 0.99));
}


Expand Down
144 changes: 141 additions & 3 deletions src/main/java/adda/item/root/numberedText/NumberedTextModel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package adda.item.root.numberedText;

import adda.Context;
import adda.base.events.IModelPropertyChangeEvent;
import adda.base.models.IModel;
import adda.base.models.IModelObserver;
import adda.base.models.ModelBase;
import adda.item.root.projectTree.ProjectTreeModel;
import net.contentobjects.jnotify.JNotify;
import net.contentobjects.jnotify.JNotifyException;
import net.contentobjects.jnotify.JNotifyListener;

import java.io.BufferedReader;
import java.io.FileReader;
Expand All @@ -11,11 +19,18 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import java.io.File;
import java.nio.file.*;
import java.nio.file.WatchEvent.Kind;

import static java.nio.file.StandardWatchEventKinds.*;

public class NumberedTextModel extends ModelBase {

public static final String DISPLAY_NAME_FIELD_NAME = "displayName";
public static final String DESCRIPTION_FIELD_NAME = "description";
public static final String TEXT_FIELD_NAME = "text";
public static final String REFRESH_FIELD_NAME = "REFRESH";
public static final String APPEND_FIELD_NAME = "append";

public String displayName;
Expand Down Expand Up @@ -55,15 +70,67 @@ public void setText(String text) {
}
}

Thread worker;
Thread watcher;

String path;

public void bindWithFile(String path) {

this.path = path;
javax.swing.SwingUtilities.invokeLater(() ->
Context.getInstance().getProjectTreeModel().addObserver(new IModelObserver() {
@Override
public void modelPropertyChanged(IModel sender, IModelPropertyChangeEvent event) {
if (ProjectTreeModel.FILE_MODIFIED_FIELD_NAME.equals(event.getPropertyName()) && event.getPropertyValue() != null) {
String generalizedPath = path.replace("\\", "/");
String generalizedEventPath = event.getPropertyValue().toString().replace("\\", "/");
if (generalizedPath.startsWith(generalizedEventPath)) {
loadFromFileAsync(path);
}
}
}
})
);

// final FileWatcher fileWatcher = new FileWatcher(path) {
// @Override
// public void onModified() {
// javax.swing.SwingUtilities.invokeLater(() -> loadFromFileAsync(path));
// }
// };
// watcher = new Thread(() -> {
// try {
// fileWatcher.watchFile();
// } catch (Exception e) {
// e.printStackTrace();
// }
// });
// watcher.start();



loadFromFileAsync(this.path);
}

public void loadFromFileAsync(String path) {
Thread t = new Thread(() -> {
if (worker != null && worker.isAlive()) {
worker.interrupt();
}

worker = new Thread(() -> {
try (BufferedReader in = new BufferedReader(new FileReader(path))) {
String str;
int bulkVolume = 1000;
int counter = 0;
StringBuilder part = new StringBuilder();
StringBuilder full = new StringBuilder();
text = "";
javax.swing.SwingUtilities.invokeLater(() -> notifyObservers(REFRESH_FIELD_NAME, text));
while ((str = in.readLine()) != null) {
if(Thread.interrupted()){
return;
}
//jtextArea.append(str);
part.append(str);
part.append("\n");
Expand All @@ -82,8 +149,79 @@ public void loadFromFileAsync(String path) {
text = full.toString();
final String s = part.toString();
javax.swing.SwingUtilities.invokeLater(() -> notifyObservers(APPEND_FIELD_NAME, s));
} catch (IOException ignored) {}
}
catch (IOException ignored) {}
});
t.start();
worker.start();
}

// public abstract class FileWatcher
// {
// private Path folderPath;
// private String watchFile;
//
// public FileWatcher(String watchFile)
// {
// Path filePath = Paths.get(watchFile);
//
// boolean isRegularFile = Files.isRegularFile(filePath);
//
// if (!isRegularFile)
// {
// // Do not allow this to be a folder since we want to watch files
// throw new IllegalArgumentException(watchFile + " is not a regular file");
// }
//
// // This is always a folder
// folderPath = filePath.getParent();
//
// // Keep this relative to the watched folder
// this.watchFile = watchFile.replace(folderPath.toString() + File.separator, "");
// }
//
// public void watchFile() throws Exception
// {
// // We obtain the file system of the Path
// FileSystem fileSystem = folderPath.getFileSystem();
//
// // We create the new WatchService using the try-with-resources block
// try (WatchService service = fileSystem.newWatchService())
// {
// // We watch for modification events
// folderPath.register(service, ENTRY_MODIFY);
//
// // Start the infinite polling loop
// while (true)
// {
// // Wait for the next event
// WatchKey watchKey = service.take();
//
// for (WatchEvent<?> watchEvent : watchKey.pollEvents())
// {
// // Get the type of the event
// Kind<?> kind = watchEvent.kind();
//
// if (kind == ENTRY_MODIFY)
// {
// Path watchEventPath = (Path) watchEvent.context();
//
// // Call this if the right file is involved
// if (watchEventPath.toString().equals(watchFile))
// {
// onModified();
// }
// }
// }
//
// if (!watchKey.reset())
// {
// // Exit if no longer valid
// break;
// }
// }
// }
// }
//
// public abstract void onModified();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void modelPropertyChanged(IModel sender, IModelPropertyChangeEvent event)
descriptionTextPane.setText(numberedTextModel.getDescription());
}

if (NumberedTextModel.REFRESH_FIELD_NAME.equals(event.getPropertyName())) {
textPane.setText("");
}

if (NumberedTextModel.APPEND_FIELD_NAME.equals(event.getPropertyName())) {
try {
double percent = 1.0*scroll.getVerticalScrollBar().getValue()/scroll.getVerticalScrollBar().getMaximum();
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/adda/item/root/projectArea/ProjectAreaModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@ public void loadNestedModelList() {
for (IModel model : nestedModelList) {

if (RefractiveIndexAggregatorModel.class.equals(model.getClass())) {
RefractiveIndexAggregatorModel refractiveIndexAggregatorModel = (RefractiveIndexAggregatorModel) model;
final int[] index = {0};
refractiveIndexAggregatorModel.getShapeBoxes().forEach(box -> {
box.getModel().copyProperties(refractiveIndexModelList.get(index[0]++));
//using SwingUtilities.invokeLater is required since RefractiveIndexAggregatorModel constructor has SwingUtilities.invokeLater
SwingUtilities.invokeLater(() -> {
RefractiveIndexAggregatorModel refractiveIndexAggregatorModel = (RefractiveIndexAggregatorModel) model;
final int[] index = {0};
refractiveIndexAggregatorModel.getShapeBoxes().forEach(box -> {
box.getModel().copyProperties(refractiveIndexModelList.get(index[0]++));
});
refractiveIndexAggregatorModel.getGranulBox().getModel().copyProperties(refractiveIndexModelList.get(index[0]++));
});
refractiveIndexAggregatorModel.getGranulBox().getModel().copyProperties(refractiveIndexModelList.get(index[0]++));
continue;
}

Expand Down
Loading

0 comments on commit e9fb506

Please sign in to comment.