usability; right-click menu
This commit is contained in:
parent
5fd33fc70e
commit
898c605ad6
|
@ -22,6 +22,7 @@ public class CommandQueue {
|
||||||
public static final int DEFAULT_TIMEOUT = 500;
|
public static final int DEFAULT_TIMEOUT = 500;
|
||||||
private static final int COMMAND_CONFIRMATION_TIMEOUT = 1000;
|
private static final int COMMAND_CONFIRMATION_TIMEOUT = 1000;
|
||||||
public static final int SLOW_CONFIRMATION_TIMEOUT = 5000;
|
public static final int SLOW_CONFIRMATION_TIMEOUT = 5000;
|
||||||
|
public static final Class<CommandQueue> COMMAND_QUEUE_CLASS = CommandQueue.class;
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
/**
|
/**
|
||||||
* One complex use-case is when we send out a bunch of commands and then we need to handle all the configurations
|
* One complex use-case is when we send out a bunch of commands and then we need to handle all the configurations
|
||||||
|
@ -38,7 +39,7 @@ public class CommandQueue {
|
||||||
@SuppressWarnings("InfiniteLoopStatement")
|
@SuppressWarnings("InfiniteLoopStatement")
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MessagesCentral.getInstance().postMessage(CommandQueue.class, "SerialIO started");
|
MessagesCentral.getInstance().postMessage(COMMAND_QUEUE_CLASS, "SerialIO started");
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
sendPendingCommand();
|
sendPendingCommand();
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
public class EngineState {
|
public class EngineState {
|
||||||
public static final String SEPARATOR = ",";
|
public static final String SEPARATOR = ",";
|
||||||
public static final String PACKING_DELIMITER = ":";
|
public static final String PACKING_DELIMITER = ":";
|
||||||
|
public static final Class<EngineState> ENGINE_STATE_CLASS = EngineState.class;
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
|
|
||||||
public void replaceStringValueAction(String key, ValueCallback<String> callback) {
|
public void replaceStringValueAction(String key, ValueCallback<String> callback) {
|
||||||
|
@ -68,7 +69,7 @@ public class EngineState {
|
||||||
registerStringValueAction("msg", new ValueCallback<String>() {
|
registerStringValueAction("msg", new ValueCallback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(String value) {
|
public void onUpdate(String value) {
|
||||||
MessagesCentral.getInstance().postMessage(EngineState.class, value);
|
MessagesCentral.getInstance().postMessage(ENGINE_STATE_CLASS, value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||||
* @see EngineSnifferPanel
|
* @see EngineSnifferPanel
|
||||||
*/
|
*/
|
||||||
public class Launcher {
|
public class Launcher {
|
||||||
public static final int CONSOLE_VERSION = 20190815;
|
public static final int CONSOLE_VERSION = 20190818;
|
||||||
public static final String INPUT_FILES_PATH = System.getProperty("input_files_path", "..");
|
public static final String INPUT_FILES_PATH = System.getProperty("input_files_path", "..");
|
||||||
public static final String TOOLS_PATH = System.getProperty("tools_path", ".");
|
public static final String TOOLS_PATH = System.getProperty("tools_path", ".");
|
||||||
private static final String TAB_INDEX = "main_tab";
|
private static final String TAB_INDEX = "main_tab";
|
||||||
|
|
|
@ -6,8 +6,6 @@ import com.rusefi.ui.widgets.AnyCommand;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This panel displays plain-text 'msg' plain-text debug messages
|
* This panel displays plain-text 'msg' plain-text debug messages
|
||||||
|
@ -32,20 +30,12 @@ public class MessagesPanel {
|
||||||
// buttonPanel.setBorder(BorderFactory.createLineBorder(Color.cyan));
|
// buttonPanel.setBorder(BorderFactory.createLineBorder(Color.cyan));
|
||||||
|
|
||||||
final JButton pauseButton = UiUtils.createPauseButton();
|
final JButton pauseButton = UiUtils.createPauseButton();
|
||||||
pauseButton.addActionListener(new ActionListener() {
|
pauseButton.addActionListener(event -> setPaused(pauseButton, !messagesView.isPaused()));
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setPaused(pauseButton, !messagesView.isPaused);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JButton clearButton = UiUtils.createClearButton();
|
JButton clearButton = UiUtils.createClearButton();
|
||||||
clearButton.addActionListener(new ActionListener() {
|
clearButton.addActionListener(event -> {
|
||||||
@Override
|
messagesView.clear();
|
||||||
public void actionPerformed(ActionEvent event) {
|
setPaused(pauseButton, false);
|
||||||
messagesView.clear();
|
|
||||||
setPaused(pauseButton, false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonPanel.add(clearButton);
|
buttonPanel.add(clearButton);
|
||||||
|
@ -55,8 +45,8 @@ public class MessagesPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPaused(JButton pauseButton, boolean isPaused) {
|
private void setPaused(JButton pauseButton, boolean isPaused) {
|
||||||
messagesView.isPaused = isPaused;
|
messagesView.setPaused(isPaused);
|
||||||
UiUtils.setPauseButtonText(pauseButton, messagesView.isPaused);
|
UiUtils.setPauseButtonText(pauseButton, messagesView.isPaused());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getButtonPanel() {
|
public JPanel getButtonPanel() {
|
||||||
|
@ -81,6 +71,6 @@ public class MessagesPanel {
|
||||||
Font f = getFont();
|
Font f = getFont();
|
||||||
int size = config.getIntProperty(FONT_SIZE, f.getSize());
|
int size = config.getIntProperty(FONT_SIZE, f.getSize());
|
||||||
String name = config.getProperty(FONT_NAME, f.getName());
|
String name = config.getProperty(FONT_NAME, f.getName());
|
||||||
setFont(new Font(f.getName(), f.getStyle(), size), config);
|
setFont(new Font(name, f.getStyle(), size), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,28 @@
|
||||||
package com.rusefi.ui;
|
package com.rusefi.ui;
|
||||||
|
|
||||||
import com.rusefi.FileLog;
|
import com.rusefi.FileLog;
|
||||||
|
import com.rusefi.core.EngineState;
|
||||||
import com.rusefi.core.MessagesCentral;
|
import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.io.CommandQueue;
|
import com.rusefi.io.CommandQueue;
|
||||||
import com.rusefi.io.serial.PortHolder;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.text.*;
|
import javax.swing.text.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class MessagesView {
|
public class MessagesView {
|
||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(FileLog.DATE_PATTERN);
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(FileLog.DATE_PATTERN);
|
||||||
private static final int MAX_SIZE = 50000;
|
private static final int MAX_SIZE = 50000;
|
||||||
|
|
||||||
private final Style bold;
|
private final Style bold;
|
||||||
private final Style italic;
|
private final Style italic;
|
||||||
protected boolean isPaused;
|
|
||||||
|
private boolean isPaused;
|
||||||
|
|
||||||
protected final JTextPane messages = new JTextPane() {
|
protected final JTextPane messages = new JTextPane() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,6 +36,26 @@ public class MessagesView {
|
||||||
|
|
||||||
public MessagesView() {
|
public MessagesView() {
|
||||||
messages.setEditable(false);
|
messages.setEditable(false);
|
||||||
|
|
||||||
|
JPopupMenu menu = createPopupMenu();
|
||||||
|
|
||||||
|
messages.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
pop(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
pop(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pop(MouseEvent e) {
|
||||||
|
if (e.isPopupTrigger())
|
||||||
|
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
StyledDocument d = (StyledDocument) messages.getDocument();
|
StyledDocument d = (StyledDocument) messages.getDocument();
|
||||||
bold = d.addStyle("StyleName", null);
|
bold = d.addStyle("StyleName", null);
|
||||||
bold.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
|
bold.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
|
||||||
|
@ -46,6 +73,43 @@ public class MessagesView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private JPopupMenu createPopupMenu() {
|
||||||
|
JPopupMenu menu = new JPopupMenu();
|
||||||
|
|
||||||
|
/*
|
||||||
|
JMenuItem selectAll = new JMenuItem("Select All");
|
||||||
|
selectAll.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
messages.selectAll();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(selectAll);
|
||||||
|
does not work? maybe wrong UI colors since control is not editable?
|
||||||
|
*/
|
||||||
|
JMenuItem copy = new JMenuItem("Copy");
|
||||||
|
copy.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
messages.copy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(copy);
|
||||||
|
|
||||||
|
menu.add(new JPopupMenu.Separator());
|
||||||
|
|
||||||
|
JMenuItem pause = new JMenuItem("Pause/Resume");
|
||||||
|
pause.addActionListener(e -> setPaused(!isPaused));
|
||||||
|
menu.add(pause);
|
||||||
|
|
||||||
|
JMenuItem clear = new JMenuItem("Clear");
|
||||||
|
clear.addActionListener(e -> clear());
|
||||||
|
menu.add(clear);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
private void append(String line, Class clazz) {
|
private void append(String line, Class clazz) {
|
||||||
Document d = messages.getDocument();
|
Document d = messages.getDocument();
|
||||||
if (d.getLength() > MAX_SIZE)
|
if (d.getLength() > MAX_SIZE)
|
||||||
|
@ -58,13 +122,15 @@ public class MessagesView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets different font style depending on message source
|
||||||
|
* <p>
|
||||||
|
* this is ugly as hell, but that's so much better then nothing...
|
||||||
|
*/
|
||||||
private AttributeSet getStyle(Class clazz) {
|
private AttributeSet getStyle(Class clazz) {
|
||||||
/**
|
if (clazz == CommandQueue.COMMAND_QUEUE_CLASS)
|
||||||
* this is ugly as hell, but that's so much better then nothing...
|
|
||||||
*/
|
|
||||||
if (clazz == CommandQueue.class)
|
|
||||||
return bold;
|
return bold;
|
||||||
if (clazz == PortHolder.class)
|
if (clazz == EngineState.ENGINE_STATE_CLASS)
|
||||||
return italic;
|
return italic;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -82,4 +148,12 @@ public class MessagesView {
|
||||||
Document d = messages.getDocument();
|
Document d = messages.getDocument();
|
||||||
clearMessages(d);
|
clearMessages(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPaused(boolean isPaused) {
|
||||||
|
this.isPaused = isPaused;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPaused() {
|
||||||
|
return isPaused;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue