Skip to content

Commit

Permalink
moved, and refactored editor*; #23 scrolls now on selection update
Browse files Browse the repository at this point in the history
  • Loading branch information
GavriYashar committed Sep 21, 2016
1 parent 0e75831 commit 40c1a9d
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/at/justin/matlab/gui/fileStructure/FileStructure.java
@@ -1,10 +1,7 @@
package at.justin.matlab.gui.fileStructure;

/**
* Created by Andreas Justin on 2016 - 02 - 24.
*/

import at.justin.matlab.EditorWrapper;
import at.justin.matlab.editor.EditorWrapper;
import at.justin.matlab.gui.components.JTextFieldSearch;
import at.justin.matlab.gui.components.UndecoratedFrame;
import at.justin.matlab.meta.MetaClass;
Expand All @@ -30,10 +27,10 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/** Created by Andreas Justin on 2016 - 02 - 24. */
public class FileStructure extends UndecoratedFrame {
private static final int IFW = JComponent.WHEN_IN_FOCUSED_WINDOW;
private static FileStructure INSTANCE;
private static EditorWrapper ew;
private static Editor editor;
private static JTextFieldSearch jTFS;
private static JTextArea jTextArea;
Expand All @@ -51,7 +48,7 @@ public void actionPerformed(ActionEvent e) {
if (jTree.getMaxSelectionRow() < 0) return;
Node node = (Node) jTree.getSelectionPath().getLastPathComponent();
if (node.hasNode()) {
EditorWrapper.getInstance().goToLine(node.node().getStartLine(), false);
EditorWrapper.goToLine(node.node().getStartLine(), false);
}
}
};
Expand All @@ -60,7 +57,7 @@ public FileStructure() {
setLayout();
}

public static FileStructure getINSTANCE() {
public static FileStructure getInstance() {
if (INSTANCE != null) return INSTANCE;
INSTANCE = new FileStructure();
return INSTANCE;
Expand Down Expand Up @@ -114,6 +111,7 @@ private static Node forClassMeta(String fullQualifiedName, MTree mTree) {
}

private void setLayout() {
setTitle("FileStructureViewer");
int width = ScreenSize.getWidth();
int height = ScreenSize.getHeight();

Expand Down Expand Up @@ -191,6 +189,7 @@ public void actionPerformed(ActionEvent e) {
jTree.setSelectionRow(0);
}
jTree.setSelectionRow(row - 1); // zero is top, so up means -1
jTree.scrollRowToVisible(jTree.getMaxSelectionRow());
}
});

Expand All @@ -206,6 +205,7 @@ public void actionPerformed(ActionEvent e) {
if (jTree.getRowCount() - 1 > row) {
jTree.setSelectionRow(row + 1); // zero is top, so down means +1
}
jTree.scrollRowToVisible(jTree.getMaxSelectionRow());
}
});
}
Expand All @@ -227,7 +227,7 @@ private JPanel createSettingsPanel() {
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ew != null) populate();
populateTree();
}
};
cells.addActionListener(actionListener);
Expand Down Expand Up @@ -282,6 +282,7 @@ public void valueChanged(TreeSelectionEvent e) {
if (jTree.getMaxSelectionRow() < 0) return;
Node node = (Node) jTree.getSelectionPath().getLastPathComponent();
jTextArea.setText(node.getDocumentation());
moveBarsDocuScrollpane();
}
});

Expand Down Expand Up @@ -327,7 +328,7 @@ private void populate() {
// inherited.setEnabled(classes.isSelected());
inherited.setEnabled(false);

Node root = new Node(ew.getShortName());
Node root = new Node(EditorWrapper.getShortName());
MTree mTree = MTree.parse(editor.getText());

Tree<MTree.Node> nodeTree = mTree.findAsTree(nodeType);
Expand All @@ -336,7 +337,7 @@ private void populate() {
nodeType = MTree.NodeType.FUNCTION;
nodeTree = mTree.findAsTree(nodeType);
} else if (nodeType.equals(MTree.NodeType.CLASSDEF) & nodeTree.getChildCount(nodeTree.getRoot()) > 0) {
String fqn = ew.getFullQualifiedClass();
String fqn = EditorWrapper.getFullQualifiedClass();
root = forClassMeta(fqn, mTree);
setTreeRoot(root, false);
return;
Expand All @@ -350,10 +351,9 @@ private void populate() {
}
}

public void populate(final EditorWrapper ew) {
if (editor != ew.gae()) jTFS.setText(""); // resetting search if editor has been changed
FileStructure.ew = ew;
editor = ew.gae();
public void populateTree() {
if (editor != EditorWrapper.getActiveEditor()) jTFS.setText(""); // resetting search if editor has been changed
editor = EditorWrapper.getActiveEditor();

// (disable/enable) class RadioButton if the current file (is no/is) class
MTree mTree = MTree.parse(editor.getText());
Expand Down Expand Up @@ -395,11 +395,15 @@ public void setVisible(boolean visible) {
// setAlwaysOnTop(visible);
if (visible) {
jTextArea.setFont(new Font("Courier New", Font.PLAIN, Settings.getPropertyInt("fs.fontSizeDocu")));
docuScrollPane.getHorizontalScrollBar().setValue(docuScrollPane.getHorizontalScrollBar().getMinimum());
docuScrollPane.getVerticalScrollBar().setValue(docuScrollPane.getVerticalScrollBar().getMinimum());
moveBarsDocuScrollpane();
}
}

private void moveBarsDocuScrollpane() {
docuScrollPane.getHorizontalScrollBar().setValue(docuScrollPane.getHorizontalScrollBar().getMinimum());
docuScrollPane.getVerticalScrollBar().setValue(docuScrollPane.getVerticalScrollBar().getMinimum());
}

public void expandAll() {
for (int i = 0; i < jTree.getRowCount(); i++) {
jTree.expandRow(i);
Expand Down

0 comments on commit 40c1a9d

Please sign in to comment.