auto-sync

This commit is contained in:
rusEfi 2015-04-30 22:09:40 -04:00
parent e725aaa34e
commit bb64d9ce77
6 changed files with 245 additions and 102 deletions

View File

@ -80,9 +80,7 @@ public class Launcher {
ConnectionWatchdog.start();
RpmPanel mainGauges = new RpmPanel(getConfig().getRoot().getChild("main_gauges"));
tabbedPane.addTab("Main", mainGauges.createRpmPanel());
tabbedPane.addTab("Gauges", new GaugesPanel().getContent());
tabbedPane.addTab("Gauges", new GaugesPanel(getConfig().getRoot().getChild("gauges")).getContent());
tabbedPane.addTab("Engine Sniffer", engineSnifferPanel.getPanel());
tabbedPane.addTab("Sensor Sniffer", new SensorSnifferPane().getPanel());

View File

@ -1,36 +1,99 @@
package com.rusefi.ui;
import com.rusefi.FileLog;
import com.rusefi.core.Sensor;
import com.rusefi.ui.storage.Node;
import com.rusefi.ui.util.FrameHelper;
import com.rusefi.ui.util.UiUtils;
import com.rusefi.ui.widgets.PopupMenuButton;
import com.rusefi.ui.widgets.RpmCommand;
import com.rusefi.ui.widgets.SensorGauge;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Date: 2/5/13
* (c) Andrey Belomutskiy
*/
public class GaugesPanel {
public class GaugesPanel {
private final JPanel content = new JPanel(new BorderLayout());
private final JPanel box2 = new JPanel(new GridLayout(3, 5));
public static void main(String[] args) {
FrameHelper fh = new FrameHelper();
fh.showFrame(new GaugesPanel().getContent());
}
private boolean showRpmPanel = true;
private boolean showMessagesPanel = true;
private JPanel lowerRpmPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
private JPanel smallMessagePanel = new JPanel(new BorderLayout());
public GaugesPanel() {
public GaugesPanel(Node config) {
// Radial radial2 = createRadial("title");
MessagesPanel mp = new MessagesPanel(config, false);
smallMessagePanel.add(BorderLayout.NORTH, mp.getButtonPanel());
smallMessagePanel.add(BorderLayout.CENTER, mp.getMessagesScroll());
JButton saveImageButton = UiUtils.createSaveImageButton();
saveImageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String fileName = FileLog.getDate() + "_gauges.png";
JPanel upperPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
upperPanel.add(saveImageButton);
UiUtils.saveImageWithPrompt(fileName, content, box2);
}
});
JPanel box2 = new JPanel(new GridLayout(3, 5));
JPanel rightUpperPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
final JPopupMenu selectorMenu = new JPopupMenu();
selectorMenu.add(new SizeSelectorPanel(new SizeSelectorPanel.SizeSelectorListener() {
@Override
public void onSelected(int row, int column) {
System.out.println("new size " + row + "/" + column);
}
}));
lowerRpmPanel.add(new RpmLabel(15).getContent());
JButton selector = new JButton("O");
selector.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Component c = (Component) e.getSource();
selectorMenu.show(c, -1, c.getHeight());
}
});
rightUpperPanel.add(selector);
JPopupMenu menu = new JPopupMenu();
final JCheckBoxMenuItem showRpmItem = new JCheckBoxMenuItem("Show RPM");
showRpmItem.setSelected(showRpmPanel);
showRpmItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GaugesPanel.this.showRpmPanel = showRpmItem.isSelected();
applyShowFlags();
}
});
menu.add(showRpmItem);
JCheckBoxMenuItem showCommandsItem = new JCheckBoxMenuItem("Show Commands");
showCommandsItem.setSelected(showMessagesPanel);
menu.add(showCommandsItem);
menu.add(new JPopupMenu.Separator());
menu.add(new JPopupMenu("Reset Config"));
JButton menuButton = new PopupMenuButton("#", menu);
rightUpperPanel.add(menuButton);
JPanel leftUpperPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
leftUpperPanel.add(saveImageButton);
leftUpperPanel.add(new RpmLabel(2).getContent());
JPanel upperPanel = new JPanel(new BorderLayout());
upperPanel.add(leftUpperPanel, BorderLayout.CENTER);
upperPanel.add(rightUpperPanel, BorderLayout.EAST);
box2.add(createControls());
box2.add(SensorGauge.createGauge(Sensor.RPM));
@ -75,11 +138,22 @@ public class GaugesPanel {
box2.add(SensorGauge.createGauge(Sensor.TIMING));
JPanel middlePanel = new JPanel(new BorderLayout());
middlePanel.add(box2, BorderLayout.CENTER);
middlePanel.add(lowerRpmPanel, BorderLayout.SOUTH);
//add(rpmGauge);
content.add(upperPanel, BorderLayout.NORTH);
content.add(box2, BorderLayout.CENTER);
content.add(middlePanel, BorderLayout.CENTER);
content.add(smallMessagePanel, BorderLayout.EAST);
content.add(new WarningPanel().getPanel(), BorderLayout.SOUTH);
// add(new JLabel("fd"), BorderLayout.EAST);
applyShowFlags();
}
private void applyShowFlags() {
lowerRpmPanel.setVisible(showRpmPanel);
}
public JComponent getContent() {

View File

@ -1,86 +0,0 @@
package com.rusefi.ui;
import com.rusefi.core.Sensor;
import com.rusefi.ui.storage.Node;
import com.rusefi.ui.widgets.*;
import com.rusefi.ui.widgets.SensorGauge;
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import java.awt.*;
/**
* Date: 1/7/13
* (c) Andrey Belomutskiy
*/
public class RpmPanel {
private final Node config;
private RpmLabel rpmLabel = new RpmLabel(15);
// that's for CKP signal emulation
public final WaveInfoPanel wave0 = new WaveInfoPanel(0);
public final WaveInfoPanel wave1 = new WaveInfoPanel(1);
public final WaveInfoPanel wave2 = new WaveInfoPanel(2);
public RpmPanel(Node config) {
this.config = config;
}
public JComponent createRpmPanel() {
// JPanel leftSideControls = createControls();
JPanel gauges = new JPanel(new GridLayout(2, 3));
gauges.setBorder(BorderFactory.createLineBorder(Color.black));
gauges.add(SensorGauge.createGauge(Sensor.CLT));
gauges.add(SensorGauge.createGauge(Sensor.FUEL));
gauges.add(SensorGauge.createGauge(Sensor.TIMING));
gauges.add(SensorGauge.createGauge(Sensor.VBATT));
gauges.add(SensorGauge.createGauge(Sensor.MAF));
gauges.add(SensorGauge.createGauge(Sensor.TPS));
JPanel smallMessagePanel = new JPanel(new BorderLayout());
MessagesPanel mp = new MessagesPanel(config, false);
smallMessagePanel.add(BorderLayout.NORTH, mp.getButtonPanel());
smallMessagePanel.add(BorderLayout.CENTER, mp.getMessagesScroll());
JPanel msgPanel = new JPanel(new BorderLayout());
msgPanel.add(smallMessagePanel, BorderLayout.CENTER);
JComponent rpmPanel = new JPanel(new BorderLayout());
rpmPanel.setBorder(BorderFactory.createLineBorder(Color.white));
rpmPanel.add(rpmLabel.getContent(), BorderLayout.NORTH);
// rpmPanel.add(leftSideControls, BorderLayout.WEST);
rpmPanel.add(gauges, BorderLayout.CENTER);
rpmPanel.add(msgPanel, BorderLayout.EAST);
rpmPanel.add(new WarningPanel().getPanel(), BorderLayout.SOUTH);
return rpmPanel;
}
/*
private JPanel createControls() {
JPanel controls = new JPanel(new MigLayout());
controls.setBorder(BorderFactory.createLineBorder(Color.red));
controls.add(new RpmCommand(), "grow, wrap");
// controls.add(new PotCommand(0).panel, "grow, wrap");
// controls.add(new PotCommand(1).panel, "grow, wrap");
controls.add(wave0.getControl(), "grow, wrap");
controls.add(wave1.getControl(), "grow, wrap");
controls.add(wave2.getControl(), "grow, wrap");
controls.add(new AdcDebugControl().getControl(), "grow, wrap");
// controls.add(new InjectorControl(0, Sensor.INJECTOR_0_STATUS).getControl(), "grow, wrap");
// controls.add(new InjectorControl(1, Sensor.INJECTOR_1_STATUS).getControl(), "grow, wrap");
// controls.add(new InjectorControl(2, Sensor.INJECTOR_2_STATUS).getControl(), "grow, wrap");
// controls.add(new InjectorControl(3, Sensor.INJECTOR_3_STATUS).getControl(), "grow, wrap");
controls.add(new LogModeWidget().getPanel(), "grow, wrap");
return controls;
}
*/
}

View File

@ -0,0 +1,81 @@
package com.rusefi.ui;
import com.rusefi.ui.util.UiUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
public class SizeSelectorPanel extends JPanel {
private static final int WIDTH = 7;
private static final int HEIGHT = 3;
private List<Element> elements = new ArrayList<>();
private int selectedRow = 1;
private int selectedColumn = 1;
public SizeSelectorPanel(final SizeSelectorListener sizeSelectorListener) {
super(new GridLayout(HEIGHT, WIDTH));
MouseListener listener = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
Element selected = (Element) e.getSource();
selectedColumn = selected.column;
selectedRow = selected.row;
UiUtils.trueLayout(SizeSelectorPanel.this);
UiUtils.trueRepaint(SizeSelectorPanel.this);
System.out.println(selectedColumn + " r=" + selectedRow);
}
@Override
public void mouseClicked(MouseEvent e) {
// close the menu
MenuSelectionManager.defaultManager().clearSelectedPath();
Element selected = (Element) e.getSource();
sizeSelectorListener.onSelected(selected.row, selected.column);
}
};
// addMouseListener(listener);
for (int r = 0; r < HEIGHT; r++) {
for (int c = 0; c < WIDTH; c++) {
Element e = new Element(r, c);
e.addMouseListener(listener);
elements.add(e);
add(e);
}
}
}
class Element extends JPanel {
private final int row;
private final int column;
public Element(int row, int column) {
this.row = row;
this.column = column;
}
@Override
public Dimension getPreferredSize() {
return new Dimension(25, 25);
}
@Override
public void paint(Graphics g) {
super.paint(g);
boolean isSelected = row <= selectedRow && column <= selectedColumn;
g.setColor(isSelected ? Color.black : Color.white);
g.drawOval(5, 5, 15, 15);
}
}
interface SizeSelectorListener {
void onSelected(int row, int column);
}
}

View File

@ -19,15 +19,15 @@ import static com.rusefi.ui.util.LocalizedMessages.RESUME;
public class UiUtils {
private static final String SAVE_IMAGE = "save image";
public static void saveImageWithPrompt(String fileName, Component parent, Component component) {
public static void saveImageWithPrompt(String fileName, Component parentForDialog, Component content) {
JFileChooser fc = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("PNG files", "png");
fc.setFileFilter(filter);
fc.addChoosableFileFilter(filter);
fc.setSelectedFile(new File(fileName));
if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
if (fc.showSaveDialog(parentForDialog) == JFileChooser.APPROVE_OPTION) {
fileName = fc.getSelectedFile().getAbsolutePath();
UiUtils.saveImage(fileName, component);
UiUtils.saveImage(fileName, content);
}
}

View File

@ -0,0 +1,76 @@
package com.rusefi.ui.widgets;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PopupMenuButton extends JButton {
// Is the popup showing or not?
private boolean isShowingPopup = false;
public PopupMenuButton(String text, final JPopupMenu menu) {
super(text);
// FocusListener on the JPopupMenu
menu.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
System.out.println("LOST FOCUS");
isShowingPopup = false;
}
@Override
public void focusGained(FocusEvent e) {
System.out.println("GAINED FOCUS");
}
});
// ComponentListener on the JPopupMenu
menu.addComponentListener(new ComponentListener() {
@Override
public void componentShown(ComponentEvent e) {
System.out.println("SHOWN");
}
@Override
public void componentResized(ComponentEvent e) {
System.out.println("RESIZED");
}
@Override
public void componentMoved(ComponentEvent e) {
System.out.println("MOVED");
}
@Override
public void componentHidden(ComponentEvent e) {
System.out.println("HIDDEN");
}
});
// ActionListener on the JButton
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("isShowingPopup: " + isShowingPopup);
if (isShowingPopup) {
menu.requestFocus();
isShowingPopup = false;
} else {
Component c = (Component) e.getSource();
menu.show(c, -1, c.getHeight());
isShowingPopup = true;
}
}
});
// Skip when navigating with TAB.
setFocusable(true); // Was false first and should be false in the end.
menu.setFocusable(true);
}
}