2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 17e9b498 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck Committed by Daniel Lehmberg
Browse files

Misc gui fixes

parent a1a48e0b
......@@ -6,6 +6,7 @@ import com.jgoodies.forms.layout.FormLayout;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.vadere.gui.components.model.IDefaultModel;
import org.vadere.gui.projectview.view.JsonValidIndicator;
import org.vadere.gui.projectview.view.ProjectView;
......@@ -33,7 +34,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
private static final long serialVersionUID = -1567362675580536991L;
private static Logger logger = Logger.getLogger(ScenarioElementView.class);
private JTextArea txtrTextfiletextarea;
private RSyntaxTextArea txtrTextfiletextarea;
private IDefaultModel panelModel;
private DocumentListener documentListener;
......@@ -48,8 +49,15 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
this.panelModel.addSelectScenarioElementListener(this);
this.jsonValidIndicator = jsonValidIndicator;
CellConstraints cc = new CellConstraints();
JScrollPane scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new Dimension(1, Toolkit.getDefaultToolkit().getScreenSize().height));
txtrTextfiletextarea = new RSyntaxTextArea();
txtrTextfiletextarea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
txtrTextfiletextarea.setCodeFoldingEnabled(true);
RTextScrollPane sp = new RTextScrollPane(txtrTextfiletextarea);
sp.setFoldIndicatorEnabled(true);
sp.setLineNumbersEnabled(true);
sp.setPreferredSize(new Dimension(1, Toolkit.getDefaultToolkit().getScreenSize().height));
if (topComponent != null && this.jsonValidIndicator !=null) {
setLayout(new FormLayout("default:grow", "pref, default"));
......@@ -63,30 +71,22 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
jsonMeta.add(topComponent);
add(jsonMeta, cc.xy(1, 1));
add(scrollPane, cc.xy(1, 2));
add(sp, cc.xy(1, 2));
} else {
setLayout(new FormLayout("default:grow", "default"));
add(scrollPane, cc.xy(1, 1));
add(sp, cc.xy(1, 1));
}
// JScrollPane scrollPane = new JScrollPane();
// add(scrollPane, BorderLayout.CENTER);
RSyntaxTextArea textAreaLocal = new RSyntaxTextArea();
textAreaLocal.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
// set other color theme for text area...
InputStream in = getClass().getResourceAsStream("/syntaxthemes/idea.xml");
try {
Theme syntaxTheme = Theme.load(in);
syntaxTheme.apply(textAreaLocal);
syntaxTheme.apply(txtrTextfiletextarea);
} catch (IOException e) {
logger.error("could not loadFromFilesystem theme" + e.getMessage());
}
txtrTextfiletextarea = textAreaLocal;
scrollPane.setViewportView(txtrTextfiletextarea);
// documentListener = new JSONDocumentListener(defaultModel);
// txtrTextfiletextarea.getDocument().addDocumentListener(documentListener);
......@@ -112,6 +112,10 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
txtrTextfiletextarea.getDocument().addDocumentListener(documentListener);
}
public int textWidth(){
return txtrTextfiletextarea.getPreferredSize().width;
}
private void updateModel() {
// set the content for the view
// defaultModel.setJSONContent(event.getDocument().getText(0,
......
......@@ -52,6 +52,8 @@ import org.vadere.util.opencl.CLUtils;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.io.File;
import java.io.IOException;
......@@ -65,6 +67,7 @@ import java.util.Set;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.plaf.basic.BasicSplitPaneUI;
/**
* Main view of the Vadere GUI.
......@@ -95,6 +98,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
*/
private JPanel contentPane = new JPanel();
private JPanel controlPanel = new JPanel();
private JSplitPane mainSplitPanel = new JSplitPane();
private VTable scenarioTable;
private VTable outputTable;
private JButton btnRunSelectedScenario;
......@@ -356,7 +360,6 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
buildOutputTablePopup();
buildScenarioTablePopup(addScenarioAction);
buildToolBar();
buildRightSidePanel();
setScenariosRunning(false);
......@@ -518,7 +521,6 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
contentPane.setLayout(new BorderLayout(0, 0));
JPanel panel_1 = new JPanel();
contentPane.add(panel_1, BorderLayout.WEST);
panel_1.setLayout(new BorderLayout(0, 0));
panel_1.add(progressPanel, BorderLayout.SOUTH);
......@@ -530,10 +532,8 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
outputTable = model.createOutputTable();
buildScenarioTable(outputTableRenderer);
contentPane.add(scenarioTable.getTableHeader(), BorderLayout.CENTER);
buildOutputTable(outputTableRenderer);
contentPane.add(outputTable.getTableHeader(), BorderLayout.CENTER);
JSplitPane splitPane = new JSplitPane();
splitPane.setResizeWeight(0.6);
......@@ -551,6 +551,28 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
panel_1.add(controlPanel, BorderLayout.NORTH);
FlowLayout fl_controlPanel = (FlowLayout) controlPanel.getLayout();
fl_controlPanel.setAlignment(FlowLayout.LEFT);
JPanel panel_2 = buildRightSidePanel();
mainSplitPanel = new JSplitPane();
((BasicSplitPaneUI) mainSplitPanel.getUI()).getDivider().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2){
mainSplitPanel.setDividerLocation(scenarioTable.getSize().width + 5);
}
}
});
mainSplitPanel.setResizeWeight(0.4);
mainSplitPanel.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
JScrollPane panel_1_scroll = new JScrollPane(panel_1);
panel_1_scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
panel_1.setMinimumSize(new Dimension(1,1));
panel_2.setMinimumSize(new Dimension(1, 1));
mainSplitPanel.setLeftComponent(panel_1_scroll);
mainSplitPanel.setRightComponent(panel_2);
mainSplitPanel.resetToPreferredSizes();
contentPane.add(mainSplitPanel, BorderLayout.CENTER);
}
private void buildScenarioTable(OutputTableRenderer outputTableRenderer) {
......@@ -761,7 +783,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
buildKeyboardShortcuts(pauseScenarioAction, interruptScenariosAction);
}
private void buildRightSidePanel() {
private JPanel buildRightSidePanel() {
JPanel rightSidePanel = new JPanel();
rightSidePanel.setLayout(new BorderLayout(0, 0));
contentPane.add(rightSidePanel, BorderLayout.CENTER);
......@@ -773,6 +795,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
model.setScenarioNamePanel(scenarioNamePanel); // TODO [priority=low] [task=refactoring] breaking mvc pattern (?) - but I need access to refresh the scenarioName
model.addProjectChangeListener(scenarioJPanel);
rightSidePanel.add(scenarioJPanel, BorderLayout.CENTER);
return rightSidePanel;
}
private void addToProjectSpecificActions(Action action) {
......@@ -819,4 +842,13 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
public void updateScenarioJPanel() {
scenarioJPanel.updateScenario();
}
@Override
public void validate() {
int max_div = scenarioTable.getSize().width + 25;
super.validate();
if (mainSplitPanel.getDividerLocation() > max_div){
mainSplitPanel.setDividerLocation(max_div);
}
}
}
......@@ -6,10 +6,10 @@ import org.apache.commons.configuration2.Configuration;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.model.IScenarioChecker;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
......@@ -29,7 +29,6 @@ import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.prefs.Preferences;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
......@@ -65,7 +64,7 @@ public class TextView extends JPanel implements IJsonView {
private DocumentListener documentListener;
private IScenarioChecker scenarioChecker;
private JTextArea txtrTextfiletextarea;
private RSyntaxTextArea textfileTextarea;
private ActionListener saveToFileActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -75,7 +74,7 @@ public class TextView extends JPanel implements IJsonView {
return;
try {
IOUtils.writeTextFile(path.endsWith(".json") ? path : path + ".json", txtrTextfiletextarea.getText());
IOUtils.writeTextFile(path.endsWith(".json") ? path : path + ".json", textfileTextarea.getText());
File file = new File(path);
VadereConfig.getConfig().setProperty(default_resource, file.getParentFile().getAbsolutePath());
} catch (IOException e1) {
......@@ -98,7 +97,7 @@ public class TextView extends JPanel implements IJsonView {
String content = IOUtils.readTextFile(path);
File file = new File(path);
VadereConfig.getConfig().setProperty(default_resource, file.getParentFile().getAbsolutePath());
txtrTextfiletextarea.setText(content);
textfileTextarea.setText(content);
} catch (IOException e) {
logger.error("could not load from file: " + e.getMessage());
}
......@@ -129,11 +128,10 @@ public class TextView extends JPanel implements IJsonView {
jsonValidIndicator = new JsonValidIndicator();
panelTop.add(jsonValidIndicator);
JScrollPane scrollPane = new JScrollPane();
add(scrollPane, BorderLayout.CENTER);
RSyntaxTextArea textAreaLocal = new RSyntaxTextArea();
textAreaLocal.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
textAreaLocal.setCodeFoldingEnabled(true);
// set other color theme for text area...
InputStream in = getClass().getResourceAsStream("/syntaxthemes/idea.xml");
try {
......@@ -143,10 +141,15 @@ public class TextView extends JPanel implements IJsonView {
logger.error("could not loead theme " + e.getMessage());
}
txtrTextfiletextarea = textAreaLocal;
textfileTextarea = textAreaLocal;
scrollPane.setViewportView(txtrTextfiletextarea);
txtrTextfiletextarea.setText(Messages.getString("TextFileView.txtrTextfiletextarea.text"));
RTextScrollPane sp = new RTextScrollPane(textfileTextarea);
sp.setFoldIndicatorEnabled(true);
sp.setLineNumbersEnabled(true);
add(sp, BorderLayout.CENTER);
textfileTextarea.setText(Messages.getString("TextFileView.txtrTextfiletextarea.text"));
documentListener = new DocumentListener() {
@Override
......@@ -166,7 +169,7 @@ public class TextView extends JPanel implements IJsonView {
public void setScenarioContent() {
if (isEditable) {
String json = txtrTextfiletextarea.getText(); // TODO [priority=medium] [task=bugfix] this can sometimes give the wrong text if an integer is added at the end of
String json = textfileTextarea.getText(); // TODO [priority=medium] [task=bugfix] this can sometimes give the wrong text if an integer is added at the end of
// random-seed in simulation tab, very weird, investigate...
if (json.length() == 0)
return;
......@@ -231,7 +234,7 @@ public class TextView extends JPanel implements IJsonView {
Messages.getString("Tab.Model.confirmLoadTemplate.title"),
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
try {
txtrTextfiletextarea.setText(jsonString);
textfileTextarea.setText(jsonString);
} catch (Exception e1) {
e1.printStackTrace();
}
......@@ -257,42 +260,42 @@ public class TextView extends JPanel implements IJsonView {
switch (attributeType) {
case MODEL:
txtrTextfiletextarea.setText(StateJsonConverter.serializeMainModelAttributesModelBundle(
textfileTextarea.setText(StateJsonConverter.serializeMainModelAttributesModelBundle(
scenario.getModelAttributes(), scenario.getScenarioStore().getMainModel()));
break;
case SIMULATION:
txtrTextfiletextarea
textfileTextarea
.setText(StateJsonConverter.serializeAttributesSimulation(scenario.getAttributesSimulation()));
break;
case OUTPUTPROCESSOR:
txtrTextfiletextarea.setText(scenario.getDataProcessingJsonManager().serialize());
textfileTextarea.setText(scenario.getDataProcessingJsonManager().serialize());
break;
case TOPOGRAPHY:
Topography topography = scenario.getTopography().clone();
topography.removeBoundary();
txtrTextfiletextarea.setText(StateJsonConverter.serializeTopography(topography));
textfileTextarea.setText(StateJsonConverter.serializeTopography(topography));
break;
case EVENT:
EventInfoStore eventInfoStore = scenario.getScenarioStore().getEventInfoStore();
txtrTextfiletextarea.setText(StateJsonConverter.serializeEvents(eventInfoStore));
textfileTextarea.setText(StateJsonConverter.serializeEvents(eventInfoStore));
break;
default:
throw new RuntimeException("attribute type not implemented.");
}
txtrTextfiletextarea.setCaretPosition(0);
textfileTextarea.setCaretPosition(0);
}
@Override
public void isEditable(boolean isEditable) {
this.isEditable = isEditable;
btnLoadFromFile.setEnabled(isEditable);
txtrTextfiletextarea.setEnabled(isEditable);
textfileTextarea.setEnabled(isEditable);
if (isEditable) {
txtrTextfiletextarea.setBackground(Color.WHITE);
txtrTextfiletextarea.getDocument().addDocumentListener(documentListener);
textfileTextarea.setBackground(Color.WHITE);
textfileTextarea.getDocument().addDocumentListener(documentListener);
} else {
txtrTextfiletextarea.setBackground(Color.LIGHT_GRAY);
txtrTextfiletextarea.getDocument().removeDocumentListener(documentListener);
textfileTextarea.setBackground(Color.LIGHT_GRAY);
textfileTextarea.getDocument().removeDocumentListener(documentListener);
}
}
......@@ -301,15 +304,15 @@ public class TextView extends JPanel implements IJsonView {
}
public void setText(String text) {
txtrTextfiletextarea.setText(text);
textfileTextarea.setText(text);
}
public String getText() {
return txtrTextfiletextarea.getText();
return textfileTextarea.getText();
}
public void insertAtCursor(String text) {
txtrTextfiletextarea.insert(text, txtrTextfiletextarea.getCaretPosition());
textfileTextarea.insert(text, textfileTextarea.getCaretPosition());
}
public void setScenarioChecker(IScenarioChecker scenarioChecker) {
......
......@@ -55,10 +55,13 @@ import org.vadere.util.config.VadereConfig;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import javax.swing.undo.UndoManager;
import javax.swing.undo.UndoableEditSupport;
......@@ -121,7 +124,7 @@ public class TopographyWindow extends JPanel {
selectedElementLabel = new JLabelObserver(JLabelObserver.DEFAULT_TEXT);
JsonValidIndicator jsonValidIndicator = new JsonValidIndicator();
final ScenarioElementView textView = new ScenarioElementView(panelModel, jsonValidIndicator, selectedElementLabel);
final ScenarioElementView scenarioElementView = new ScenarioElementView(panelModel, jsonValidIndicator, selectedElementLabel);
final JPanel thisPanel = this;
......@@ -181,7 +184,6 @@ public class TopographyWindow extends JPanel {
panelModel.addViewportChangeListener(viewportChangeListener);
panelModel.addScrollPane(scrollPane);
// mainPanel.setPreferredSize(new Dimension(windowWidth, windowHeight));
mainPanel = new TopographyPanel(panelModel, new TopographyCreatorRenderer(panelModel), scrollPane);
mainPanel.addComponentListener(new PanelResizeListener(panelModel));
mainPanel.setBorder(BorderFactory.createLineBorder(Color.red));
......@@ -189,30 +191,35 @@ public class TopographyWindow extends JPanel {
panelModel.addObserver(mainPanel);
scrollPane.setViewportView(mainPanel);
/*
* JPanel textViewPanel = new JPanel();
* BorderLayout layoutManagerTextViewPanel = new BorderLayout();
* textViewPanel.setLayout(layoutManagerTextViewPanel);
*/
selectedElementLabel.setPanelModel(panelModel);
// textViewPanel.add(selectedElementLabel, BorderLayout.PAGE_START);
// textViewPanel.add(textView, BorderLayout.CENTER);
panelModel.addObserver(infoPanel);
textView.setPreferredSize(new Dimension(1, windowHeight));
scenarioElementView.setPreferredSize(new Dimension(1, windowHeight));
panelModel.addObserver(selectedElementLabel);
scrollPane.setMinimumSize(new Dimension(1, 1));
scenarioElementView.setMinimumSize(new Dimension(1, 1));
JSplitPane splitPane = new JSplitPane();
((BasicSplitPaneUI) splitPane.getUI()).getDivider().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2){
int newLocation = splitPane.getSize().width - (scenarioElementView.textWidth() + 65); // 65 magic number to take gutter into account
if (newLocation > 0)
splitPane.setDividerLocation(newLocation);
}
}
});
splitPane.setResizeWeight(0.8);
splitPane.resetToPreferredSizes();
splitPane.setLeftComponent(scrollPane);
splitPane.setRightComponent(scenarioElementView);
thisPanel.add(toolbar, cc.xyw(2, 2, 4));
thisPanel.add(scrollPane, cc.xy(2, 4));
thisPanel.add(splitPane, cc.xyw(2, 4, 4));
thisPanel.add(infoPanel, cc.xyw(2, 6, 4));
// thisPanel.add(textViewPanel, cc.xy(4, 4));
thisPanel.add(textView, cc.xy(4, 4));
/* close dialog action */
......@@ -269,7 +276,6 @@ public class TopographyWindow extends JPanel {
undoSupport),
basicAction);
List<Action> obstacleAndTargetDrawModes = new ArrayList<>();
List<Action> sourceDrawModes = new ArrayList<>();
List<Action> absorbingAreaDrawModes = new ArrayList<>();
......@@ -347,8 +353,6 @@ public class TopographyWindow extends JPanel {
ActionSelectSelectShape selectShape = new ActionSelectSelectShape("select shape mode", new ImageIcon(
Resources.class.getResource("/icons/select_shapes_icon.png")), panelModel, undoSupport);
/* resize Topography */
TopographyAction resizeTopographyBound = new ActionResizeTopographyBound(Messages.getString("TopographyBoundDialog.tooltip"),
new ImageIcon(Resources.class.getResource("/icons/topography_icon.png")),
......@@ -372,10 +376,6 @@ public class TopographyWindow extends JPanel {
new ImageIcon(Resources.class.getResource("/icons/auto_generate_ids.png")),
panelModel);
// /* Topography checker*/
// ActionScenarioChecker actionScenarioChecker =
// new ActionScenarioChecker("ScenarioChecker", panelModel, jsonValidIndicator);
int iconHeight = VadereConfig.getConfig().getInt("ProjectView.icon.height.value");
int iconWidth = VadereConfig.getConfig().getInt("ProjectView.icon.width.value");
AbstractAction polyImg = new ActionGeneratePoly(Messages.getString("ProjectView.btnPolySnapshot.tooltip"),
......@@ -431,7 +431,6 @@ public class TopographyWindow extends JPanel {
addActionToToolbar(toolbar, redoAction, "TopographyCreator.btnRedo.tooltip");
toolbar.add(Box.createHorizontalGlue());
addActionToToolbar(toolbar, actionTopographyMakroMenu, "TopographyCreator.btnGenerateIds.tooltip");
// addActionToToolbar(toolbar, actionScenarioChecker, "TopographyCreator.btnChecker.tooltip");
mainPanel.setBorder(BorderFactory.createLineBorder(Color.red));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment