| 1 | /******************************************************************************* | |
| 2 | * Copyhacked (H) 2012-2025. | |
| 3 | * This program and the accompanying materials | |
| 4 | * are made available under no term at all, use it like | |
| 5 | * you want, but share and discuss it | |
| 6 | * every time possible with every body. | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * ron190 at ymail dot com - initial implementation | |
| 10 | ******************************************************************************/ | |
| 11 | package com.jsql.view.swing.action; | |
| 12 | ||
| 13 | import com.jsql.MainApp; | |
| 14 | import com.jsql.util.I18nUtil; | |
| 15 | import com.jsql.util.LogLevelUtil; | |
| 16 | import org.apache.commons.lang3.SystemUtils; | |
| 17 | import org.apache.logging.log4j.LogManager; | |
| 18 | import org.apache.logging.log4j.Logger; | |
| 19 | ||
| 20 | import javax.swing.*; | |
| 21 | import java.awt.event.ActionEvent; | |
| 22 | import java.awt.event.InputEvent; | |
| 23 | import java.awt.event.KeyEvent; | |
| 24 | import java.io.File; | |
| 25 | import java.io.IOException; | |
| 26 | import java.util.ArrayList; | |
| 27 | import java.util.Arrays; | |
| 28 | import java.util.List; | |
| 29 | ||
| 30 | /** | |
| 31 | * Open another jSQL instance in new process. | |
| 32 | */ | |
| 33 | public class ActionNewWindow extends AbstractAction { | |
| 34 | | |
| 35 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 36 | | |
| 37 | private static final String PATH = SystemUtils.JAVA_HOME + File.separator +"bin"+ File.separator +"java"; | |
| 38 | private static final List<String> COMMANDS_DEFAULT = Arrays.asList( | |
| 39 | "-cp", | |
| 40 | SystemUtils.JAVA_CLASS_PATH, | |
| 41 | MainApp.class.getName() | |
| 42 | ); | |
| 43 | | |
| 44 | private final List<String> commands; | |
| 45 | | |
| 46 | public ActionNewWindow() { | |
| 47 | this(I18nUtil.valueByKey("NEW_WINDOW_MENU")); | |
| 48 |
1
1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE |
this.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_N); |
| 49 |
1
1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE |
this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK)); |
| 50 | } | |
| 51 | ||
| 52 | public ActionNewWindow(String name, String... commands) { | |
| 53 | this.commands = new ArrayList<>(List.of(ActionNewWindow.PATH)); | |
| 54 | this.commands.addAll(Arrays.asList(commands)); | |
| 55 | this.commands.addAll(ActionNewWindow.COMMANDS_DEFAULT); | |
| 56 |
1
1. <init> : removed call to com/jsql/view/swing/action/ActionNewWindow::putValue → NO_COVERAGE |
this.putValue(Action.NAME, name); |
| 57 | } | |
| 58 | ||
| 59 | @Override | |
| 60 | public void actionPerformed(ActionEvent event) { | |
| 61 | LOGGER.log(LogLevelUtil.CONSOLE_INFORM, () -> I18nUtil.valueByKey("NEW_WINDOW_START")); | |
| 62 | var processBuilder = new ProcessBuilder(this.commands.toArray(new String[0])); | |
| 63 | try { | |
| 64 | processBuilder.start(); | |
| 65 | } catch (IOException e) { | |
| 66 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 67 | } | |
| 68 | } | |
| 69 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 56 |
1.1 |