Files
VisualSapfor/src/_VisualDVM/Visual/Windows/FileForm.java

388 lines
14 KiB
Java
Raw Normal View History

2024-10-09 22:15:56 +03:00
package _VisualDVM.Visual.Windows;
2024-10-07 14:22:52 +03:00
import Common.CommonConstants;
import Common.Visual.FormWithSplitters;
import Common.Visual.Tables.DataTable;
2024-10-14 15:19:13 +03:00
import Common.Visual.Trees.TreeForm;
import Common.Visual.UI;
import _VisualDVM.Global;
2024-10-09 22:21:57 +03:00
import _VisualDVM.GlobalData.Settings.SettingName;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Passes.PassCode;
2024-10-09 22:21:57 +03:00
import _VisualDVM.ProjectData.Files.DBProjectFile;
import _VisualDVM.ProjectData.Files.UI.Editor.SPFEditor;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.ProjectData.SapforData.Arrays.UI.FileArraysTree;
import _VisualDVM.ProjectData.SapforData.Functions.UI.FileFunctionsTree;
import _VisualDVM.ProjectData.SapforData.Loops.UI.FileLoopsTree;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Visual.Editor.Viewer;
2024-10-09 22:01:19 +03:00
import _VisualDVM.Visual.Interface.FileWindow;
import _VisualDVM.Visual.Interface.SPFEditorInterface;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Visual.Menus.FileMenuBar.FileMenuBar;
2023-09-17 22:13:42 +03:00
import com.sun.org.glassfish.gmbal.Description;
import org.fife.ui.rtextarea.RTextScrollPane;
import javax.swing.*;
import java.awt.*;
public class FileForm implements FileWindow, FormWithSplitters {
//контролы в столбцах
//https://stackoverflow.com/questions/7137786/how-can-i-put-a-control-in-the-jtableheader-of-a-jtable
//todo _ временно
2024-10-07 14:22:52 +03:00
public static int current_file_line = CommonConstants.Nan;
2023-09-17 22:13:42 +03:00
private final Viewer compilationOutput;
private final Viewer runOutput;
private final Viewer gcovLog;
private final DBProjectFile file;
//-
public JSplitPane SC1;
public JSplitPane SC12;
@Description("IGNORE")
protected boolean events_on = true;
2024-10-15 13:35:33 +03:00
FileMenuBar fileMenuBar = null;
2024-10-14 15:19:13 +03:00
//-
private JPanel content;
2023-09-17 22:13:42 +03:00
private JButton bClose;
private JToolBar Tools;
private JPanel editorPanel;
private JTabbedPane messagesTabs;
private JPanel notesPanel;
private JPanel warningsPanel;
private JPanel errorsPanel;
private JTabbedPane graphsTabs;
private JPanel loopsGraphPanel;
private JPanel functionsGraphPanel;
private JPanel arraysGraphPanel;
private JPanel gcov_log_panel;
private JPanel compilation_out_panel;
private JPanel run_out_panel;
//---------------->
private JPanel recommendationsPanel;
private JPanel graphsBackground;
private JPanel messagesBackground;
private JPanel editorBackground;
2023-09-17 22:13:42 +03:00
//--------------->
//-
private TreeForm loopsForm; //рудиментарно. следует сделать интерфейс такой же как у таблиц
private TreeForm functionsForm;
private TreeForm arraysForm;
//-
private SPFEditor Body = null; //времянка? не очень красиво.
//-
public FileForm(DBProjectFile file_in) {
LoadSplitters();
//--
file = file_in;
//--
loopsForm = new TreeForm(FileLoopsTree.class, loopsGraphPanel);
functionsForm = new TreeForm(FileFunctionsTree.class, functionsGraphPanel);
arraysForm = new TreeForm(FileArraysTree.class, arraysGraphPanel);
//--
2023-09-17 22:13:42 +03:00
file.father.db.notes.mountUI(notesPanel);
file.father.db.warnings.mountUI(warningsPanel);
file.father.db.errors.mountUI(errorsPanel);
file.father.db.recommendations.mountUI(recommendationsPanel);
//---------------------------------------------------------------------------
compilation_out_panel.add(new JScrollPane(compilationOutput = new Viewer()));
run_out_panel.add(new JScrollPane(runOutput = new Viewer()));
gcov_log_panel.add(new JScrollPane(gcovLog = new Viewer()));
//----------------------------------------------------------------------------
ShowText();
ShowMessages();
ShowGCOVLog();
ShowAllAnalyses();
Body.addCaretListener(ce -> ShowCaretInfo());
2024-10-14 21:55:58 +03:00
editorPanel.add(fileMenuBar = new FileMenuBar(Body), BorderLayout.NORTH);
2023-09-17 22:13:42 +03:00
ShowCaretInfo();
Body.requestFocus();
RefreshTabsNames();
2024-10-14 21:55:58 +03:00
fileMenuBar.sToGo.addChangeListener(e -> Body.gotoLine((Integer) fileMenuBar.sToGo.getValue()));
2023-09-17 22:13:42 +03:00
ShowProperties();
Global.mainModule.getPass(PassCode.Save).setControlsEnabled(false);
//-
if (Global.properties.collapseFileGraphs)
CollapseGraphs();
//-
if (Global.properties.collapseFileMessages)
CollapseMessages();
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowLanguage() {
Body.switching_language = true;
if (file.languageName.equals(LanguageName.fortran)) {
switch (file.style) {
case fixed:
case extended:
case none:
Body.setSyntaxEditingStyle("text/FortranSPF");
break;
case free:
Body.setSyntaxEditingStyle("text/FreeFortranSPF");
break;
}
} else
Body.setSyntaxEditingStyle(file.languageName.getStyleKey());
Body.setCodeFoldingEnabled(true);
Body.switching_language = false;
2024-10-14 21:55:58 +03:00
fileMenuBar.ShowLanguage();
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowType() {
2024-10-14 21:55:58 +03:00
fileMenuBar.ShowType();
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowStyle() {
Body.switching_language = true;
int m = file.style.getMargin();
Body.setMarginLineEnabled(true);
Body.setMarginLinePosition(m);
if (m <= 0)
Body.setMarginLineEnabled(false);
if (file.languageName.equals(LanguageName.fortran)) {
switch (file.style) {
case fixed:
case extended:
case none:
Body.setSyntaxEditingStyle("text/FortranSPF");
break;
case free:
Body.setSyntaxEditingStyle("text/FreeFortranSPF");
break;
}
}
Body.switching_language = false;
2024-10-14 21:55:58 +03:00
fileMenuBar.ShowStyle();
2023-09-17 22:13:42 +03:00
}
@Override
public SPFEditorInterface getEditor() {
return Body;
}
@Override
public void FocusLoops() {
graphsTabs.setSelectedIndex(0);
}
@Override
public void FocusFunctions() {
graphsTabs.setSelectedIndex(1);
}
@Override
public void FocusArrays() {
graphsTabs.setSelectedIndex(2);
}
//----
@Override
public void ShowWarningsCount() {
2024-10-12 00:17:51 +03:00
boolean flag = (Global.mainModule.getDb()).settings.get(SettingName.ShowFullTabsNames).toBoolean();
2024-10-20 16:19:43 +03:00
messagesTabs.setTitleAt(1, (flag ? "Предупреждения: " : "") + file.father.db.warnings.getUI().getRowCount());
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowErrorsCount() {
2024-10-12 00:17:51 +03:00
boolean flag = (Global.mainModule.getDb()).settings.get(SettingName.ShowFullTabsNames).toBoolean();
2024-10-20 16:19:43 +03:00
messagesTabs.setTitleAt(2, (flag ? "Ошибки: " : "") + file.father.db.errors.getUI().getRowCount());
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowNotesCount() {
2024-10-12 00:17:51 +03:00
boolean flag = (Global.mainModule.getDb()).settings.get(SettingName.ShowFullTabsNames).toBoolean();
2024-10-20 16:19:43 +03:00
messagesTabs.setTitleAt(0, (flag ? "Примечания: " : "") + file.father.db.notes.getUI().getRowCount());
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowRecommendationsCount() {
2024-10-12 00:17:51 +03:00
boolean flag = (Global.mainModule.getDb()).settings.get(SettingName.ShowFullTabsNames).toBoolean();
2024-10-20 16:19:43 +03:00
messagesTabs.setTitleAt(3, (flag ? "Рекомендации: " : "") + file.father.db.recommendations.getUI().getRowCount());
2023-09-17 22:13:42 +03:00
}
//---
@Override
public void RefreshTabsNames() {
2024-10-12 00:17:51 +03:00
boolean flag = (Global.mainModule.getDb()).settings.get(SettingName.ShowFullTabsNames).toBoolean();
UI.ShowTabsNames(graphsTabs, flag);
2023-09-17 22:13:42 +03:00
//--
ShowNotesCount();
ShowWarningsCount();
ShowErrorsCount();
ShowRecommendationsCount();
//--
messagesTabs.setTitleAt(4, (flag ? "Компиляция" : ""));
messagesTabs.setTitleAt(5, (flag ? "Запуск" : ""));
messagesTabs.setTitleAt(6, (flag ? "Журнал GCOV" : ""));
}
@Override
public void FocusCompilationOut() {
messagesTabs.setSelectedIndex(4);
}
@Override
2024-02-14 17:58:52 +03:00
public void FocusCompilationErrors() {
messagesTabs.setSelectedIndex(5);
}
@Override
2023-09-17 22:13:42 +03:00
public void ShowText() {
UI.Clear(editorPanel);
2023-09-17 22:13:42 +03:00
editorPanel.add(new RTextScrollPane(Body = new SPFEditor(file)));
Global.mainModule.getUI().getSearchReplaceWindow().updateEditor(Body);
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowMessages() {
file.father.db.notes.ShowUI();
file.father.db.warnings.ShowUI();
file.father.db.errors.ShowUI();
file.father.db.recommendations.ShowUI();
ShowNotesCount();
ShowWarningsCount();
ShowErrorsCount();
ShowRecommendationsCount();
//-
FocusMessagesPriority();
}
@Override
public void ShowNoMessages() {
2024-10-12 00:17:51 +03:00
boolean full_tiles = (Global.mainModule.getDb()).settings.get(SettingName.ShowFullTabsNames).toBoolean();
2023-09-17 22:13:42 +03:00
file.father.db.notes.ClearUI();
file.father.db.warnings.ClearUI();
file.father.db.errors.ClearUI();
file.father.db.recommendations.ClearUI();
messagesTabs.setTitleAt(0, (full_tiles ? "Примечания: " : "") + "-");
messagesTabs.setTitleAt(1, (full_tiles ? "Предупреждения: " : "") + "-");
messagesTabs.setTitleAt(2, (full_tiles ? "Ошибки: " : "") + "-");
messagesTabs.setTitleAt(3, (full_tiles ? "Рекомендации: " : "") + "-");
}
@Override
public void ShowLoops() {
loopsForm.Show();
Body.HighlightLoops();
}
@Override
public void ShowNoLoops() {
loopsForm.Clear();
Body.ClearLoopsHighLights();
}
@Override
public void ShowGCOVLog() {
gcovLog.setText(file.GCOVLog);
}
@Override
public void ShowGCOV() {
Body.HighlightGCOV();
}
@Override
public void ShowNoGCOVLog() {
gcovLog.setText("");
}
@Override
public void FocusGCOVLog() {
messagesTabs.setSelectedIndex(6);
}
@Override
public void ShowNoGCOV() {
Body.ClearGOCVHighlights();
}
@Override
public void ShowFunctions() {
functionsForm.Show();
}
@Override
public void ShowNoFunctions() {
functionsForm.Clear();
}
@Override
public void ShowArrays() {
arraysForm.Show();
}
@Override
public void ShowNoArrays() {
arraysForm.Clear();
}
public void EventsOn() {
events_on = true;
}
public void EventsOff() {
events_on = false;
}
@Override
public void ShowCaretInfo() {
int new_current_line = Body.getCurrentLine();
boolean line_changed = (new_current_line != current_file_line);
current_file_line = new_current_line;
2024-10-14 21:55:58 +03:00
fileMenuBar.sToGo.setModel(new SpinnerNumberModel(current_file_line,
2023-09-17 22:13:42 +03:00
1, Body.getLineCount(), 1
));
//-
2024-10-14 21:55:58 +03:00
fileMenuBar.ShowLinesCount();
fileMenuBar.CurrentSymbolLabel.setText(String.valueOf(Body.getCurrentSymbol()));
2023-09-17 22:13:42 +03:00
//если выделяем строку из графа, то тоже надо отключиьт события.
//чтобы по ней не начался поиск.
if (events_on && line_changed) {
if (loopsForm.getTree() != null)
loopsForm.getTree().SelectNodeByCriteria(current_file_line);
if (functionsForm.getTree() != null)
functionsForm.getTree().SelectNodeByCriteria(current_file_line);
if (arraysForm.getTree() != null)
arraysForm.getTree().SelectNodeByCriteria(current_file_line);
}
}
@Override
public void FocusMessagesPriority() {
switch (file.state) {
case HasErrors:
messagesTabs.setSelectedIndex(2);
break;
case HasWarnings:
messagesTabs.setSelectedIndex(1);
break;
default:
messagesTabs.setSelectedIndex(0);
break;
}
}
@Override
public void ShowFirstError() {
2024-10-17 20:44:11 +03:00
if (file.father.db.errors.getUI().getRowCount() > 0)
2024-10-20 17:44:30 +03:00
((DataTable) file.father.db.errors.getUI().getControl()).SelectRow(0);
2023-09-17 22:13:42 +03:00
}
@Override
public void ShowCompilationOutput() {
compilationOutput.setText(file.father.compilation_output);
}
@Override
public void ShowNoCompilationOutput() {
compilationOutput.setText("");
}
@Override
public void ShowRunOutput() {
runOutput.setText(file.father.run_output);
}
@Override
public void ShowNoRunOutput() {
runOutput.setText("");
}
@Override
public JPanel getContent() {
return content;
}
//--
@Override
public void CollapseGraphs() {
2024-10-12 00:17:51 +03:00
Global.mainModule.getDb().splitters.get("SC12").position = SC12.getDividerLocation();
UI.Clear(editorBackground);
editorBackground.add(editorPanel);
}
@Override
public void ExpandGraphs() {
UI.Clear(editorBackground);
SC12.setRightComponent(editorPanel);
editorBackground.add(SC12);
//--
2024-10-12 00:17:51 +03:00
SC12.setDividerLocation(Global.mainModule.getDb().splitters.get("SC12").position);
SC12.updateUI();
}
@Override
public void CollapseMessages() {
2024-10-12 00:17:51 +03:00
Global.mainModule.getDb().splitters.get("SC1").position = SC1.getDividerLocation();
UI.Clear(content);
content.add(editorBackground);
}
@Override
public void ExpandMessages() {
UI.Clear(content);
SC1.setLeftComponent(editorBackground);
content.add(SC1);
2024-10-12 00:17:51 +03:00
SC1.setDividerLocation(Global.mainModule.getDb().splitters.get("SC1").position);
SC1.updateUI();
}
2023-09-17 22:13:42 +03:00
}