helping Android & copy right-click menu for Lua editor
This commit is contained in:
parent
9d7792f453
commit
6d63e0b6de
|
@ -5,14 +5,11 @@ import com.rusefi.core.EngineState;
|
|||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.ui.storage.Node;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
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.util.Date;
|
||||
|
||||
|
@ -33,24 +30,7 @@ public class MessagesView {
|
|||
this.config = config;
|
||||
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());
|
||||
}
|
||||
});
|
||||
UiUtils.installPopupMenu(createPopupMenu(), messages);
|
||||
|
||||
StyledDocument d = (StyledDocument) messages.getDocument();
|
||||
bold = d.addStyle("StyleName", null);
|
||||
|
@ -84,14 +64,7 @@ public class MessagesView {
|
|||
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(UiUtils.createCopyMenu(messages));
|
||||
|
||||
menu.add(new JPopupMenu.Separator());
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.rusefi.ui.lua;
|
||||
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
|
@ -54,6 +56,14 @@ public class TextEditor {
|
|||
bottomArea.add(sizeLabel);
|
||||
|
||||
installUndoRedoKeystrokes();
|
||||
UiUtils.installPopupMenu(createPopupMenu(), textArea);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JPopupMenu createPopupMenu() {
|
||||
JPopupMenu menu = new JPopupMenu();
|
||||
menu.add(UiUtils.createCopyMenu(textArea));
|
||||
return menu;
|
||||
}
|
||||
|
||||
private void updateSize() {
|
||||
|
|
|
@ -7,7 +7,12 @@ import org.jetbrains.annotations.NotNull;
|
|||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -147,4 +152,35 @@ public class UiUtils {
|
|||
clearButton.setMnemonic('c');
|
||||
return clearButton;
|
||||
}
|
||||
|
||||
public static void installPopupMenu(JPopupMenu menu, JComponent component) {
|
||||
component.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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JMenuItem createCopyMenu(final JTextComponent control) {
|
||||
JMenuItem copy = new JMenuItem("Copy");
|
||||
copy.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
control.copy();
|
||||
}
|
||||
});
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue