wow weird API but at least it clicks
This commit is contained in:
parent
1f6684fb8f
commit
5869e287c5
|
@ -2,6 +2,7 @@ package com.rusefi.ui;
|
||||||
|
|
||||||
import com.rusefi.CodeWalkthrough;
|
import com.rusefi.CodeWalkthrough;
|
||||||
import com.rusefi.config.Field;
|
import com.rusefi.config.Field;
|
||||||
|
import com.rusefi.core.Pair;
|
||||||
import com.rusefi.core.Sensor;
|
import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.enums.live_data_e;
|
import com.rusefi.enums.live_data_e;
|
||||||
import com.rusefi.ldmp.StateDictionary;
|
import com.rusefi.ldmp.StateDictionary;
|
||||||
|
@ -13,18 +14,18 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.event.TreeSelectionEvent;
|
||||||
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.event.TreeSelectionListener;
|
||||||
import javax.swing.tree.MutableTreeNode;
|
import javax.swing.tree.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import static com.rusefi.autoupdate.AutoupdateUtil.wrap;
|
import static com.rusefi.autoupdate.AutoupdateUtil.wrap;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
* Andrey Belomutskiy, (c) 2013-2020
|
||||||
|
*
|
||||||
* @see LiveDataParserPanel
|
* @see LiveDataParserPanel
|
||||||
* See LiveDataPaneSandbox
|
* See LiveDataPaneSandbox
|
||||||
*/
|
*/
|
||||||
|
@ -46,30 +47,43 @@ public class LiveDataPane {
|
||||||
JPanel legend = populateLegend();
|
JPanel legend = populateLegend();
|
||||||
|
|
||||||
|
|
||||||
// DefaultMutableTreeNode root = new DefaultMutableTreeNode("JTree");
|
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
||||||
JTree leftList = new JTree();
|
|
||||||
leftList.setRootVisible(false);
|
|
||||||
DefaultTreeModel model = (DefaultTreeModel) leftList.getModel();
|
|
||||||
MutableTreeNode root = (MutableTreeNode) model.getRoot();
|
|
||||||
for (live_data_e view : live_data_e.values()) {
|
for (live_data_e view : live_data_e.values()) {
|
||||||
String fileName = StateDictionary.INSTANCE.getFileName(view) + CPP_SUFFIX;
|
String fileName = StateDictionary.INSTANCE.getFileName(view) + CPP_SUFFIX;
|
||||||
Field[] values = StateDictionary.INSTANCE.getFields(view);
|
Field[] values = StateDictionary.INSTANCE.getFields(view);
|
||||||
JPanel liveDataParserContent = LiveDataParserPanel.createLiveDataParserPanel(uiContext, view, values, fileName).getContent();
|
JPanel liveDataParserContent = LiveDataParserPanel.createLiveDataParserPanel(uiContext, view, values, fileName).getContent();
|
||||||
|
|
||||||
JButton shortCut = new JButton(fileName);
|
|
||||||
shortCut.addActionListener(e -> {
|
|
||||||
scroll.getVerticalScrollBar().setValue(liveDataParserContent.getLocation().y);
|
|
||||||
// we want focus there so that mouse wheel scrolling would be active
|
|
||||||
scroll.requestFocus();
|
|
||||||
});
|
|
||||||
DefaultMutableTreeNode child = new DefaultMutableTreeNode(fileName);
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(fileName);
|
||||||
|
child.setUserObject(new PanelAndName(liveDataParserContent, fileName));
|
||||||
|
DefaultMutableTreeNode method1 = new DefaultMutableTreeNode();
|
||||||
|
method1.setUserObject(new Pair<String, String>(fileName, "method"));
|
||||||
|
child.add(method1);
|
||||||
|
|
||||||
model.insertNodeInto(child, root, root.getChildCount());
|
root.add(child);
|
||||||
|
|
||||||
vertical.add(liveDataParserContent, "grow, wrap");
|
vertical.add(liveDataParserContent, "grow, wrap");
|
||||||
}
|
}
|
||||||
|
|
||||||
content.add(leftList, BorderLayout.WEST);
|
JTree tree = new JTree(new DefaultTreeModel(root));
|
||||||
|
tree.setRootVisible(false);
|
||||||
|
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||||
|
|
||||||
|
MouseListener ml = new MouseAdapter() {
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
|
||||||
|
tree.getLastSelectedPathComponent();
|
||||||
|
Object payload = node.getUserObject();
|
||||||
|
|
||||||
|
if (payload instanceof PanelAndName) {
|
||||||
|
PanelAndName panel = (PanelAndName) payload;
|
||||||
|
scroll.getVerticalScrollBar().setValue(panel.panel.getLocation().y);
|
||||||
|
// we want focus there so that mouse wheel scrolling would be active
|
||||||
|
scroll.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tree.addMouseListener(ml);
|
||||||
|
content.add(tree, BorderLayout.WEST);
|
||||||
content.add(scroll, BorderLayout.CENTER);
|
content.add(scroll, BorderLayout.CENTER);
|
||||||
content.add(legend, BorderLayout.EAST);
|
content.add(legend, BorderLayout.EAST);
|
||||||
|
|
||||||
|
@ -128,4 +142,19 @@ public class LiveDataPane {
|
||||||
public JPanel getContent() {
|
public JPanel getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class PanelAndName {
|
||||||
|
public final JPanel panel;
|
||||||
|
public final String name;
|
||||||
|
|
||||||
|
public PanelAndName(JPanel panel, String name) {
|
||||||
|
this.panel = panel;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue