Skip to content

Commit 0fc054b

Browse files
committed
add logbook
1 parent 62e4427 commit 0fc054b

32 files changed

Lines changed: 192 additions & 191 deletions

build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ dependencies {
4444
compile ":cookxml:"
4545

4646
testCompile 'junit:junit:4.12'
47-
compile 'log4j:log4j:1.2.14'
47+
48+
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
49+
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
50+
4851
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4952
compile "org.jetbrains:annotations:13.0"
5053
compile 'net.java.dev.jna:jna:4.5.0'
@@ -58,11 +61,13 @@ dependencies {
5861
compile 'com.google.guava:guava:25.1-jre'
5962

6063
compile 'com.google.code.gson:gson:2.8.5'
61-
compile 'org.slf4j:slf4j-log4j12:1.7.26'
6264
compile 'com.formdev:flatlaf:0.22'
6365

6466
compile 'org.swinglabs:swingx:1.6.1'
6567

68+
69+
70+
6671
}
6772

6873
mainClassName = "com.haleywang.putty.SpringRemoteApp"

build/libs/SpringRemote-0.1.jar

610 KB
Binary file not shown.

src/main/java/com/haleywang/putty/SpringRemoteApp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public static void main(String[] args) {
2222
} catch (Exception e) {
2323
LOGGER.error("setLookAndFeel error", e);
2424
}
25-
25+
LOGGER.info("start SpringRemoteView");
2626
EventQueue.invokeLater(SpringRemoteView::getInstance);
27+
2728
}
2829
}

src/main/java/com/haleywang/putty/view/ActionsDialog.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ActionsDialog extends JDialog {
5050
public static final String ACTIONS = "Actions";
5151
private static final List<Action> ACTIONS_DATA = new ArrayList<>();
5252
private final JXTable table;
53-
private JTextField searchField;
53+
private final JTextField searchField;
5454

5555
public ActionsDialog(SpringRemoteView omegaRemote) {
5656
super(omegaRemote, ACTIONS, true);
@@ -128,7 +128,7 @@ private JTextField initSearchField() {
128128
mainTextField.setFocusTraversalKeysEnabled(false);
129129

130130
// Our words to complete
131-
ArrayList keywords = new ArrayList<String>(5);
131+
List<String> keywords = new ArrayList<>(5);
132132

133133
for (ActionCategoryEnum item : ActionCategoryEnum.values()) {
134134
keywords.add("@" + item.getName().toLowerCase());
@@ -189,22 +189,21 @@ private void doSearch() {
189189
final String category = categoryText.toLowerCase();
190190
ACTIONS_DATA.clear();
191191

192-
List<Action> allActionData = new ArrayList<>();
193-
194192
List<Action> staticData = ActionsData.getActionsData();
195193
List<Action> userData = new ArrayList<>();
196-
allActionData.addAll(staticData);
194+
List<Action> allActionData = new ArrayList<>(staticData);
195+
197196
DefaultMutableTreeNode commandsTreeNode = (DefaultMutableTreeNode) SideView.getInstance().getCommandsTreeView().getModel().getRoot();
198197
DefaultMutableTreeNode connectionsTreeNode = (DefaultMutableTreeNode) SideView.getInstance().getConnectionsInfoTreeView().getModel().getRoot();
199198

200-
parseTreeNodes(userData, commandsTreeNode, ActionCategoryEnum.COMMAND);
201-
parseTreeNodes(userData, connectionsTreeNode, ActionCategoryEnum.SSH);
199+
parseTreeNodes(userData, commandsTreeNode);
200+
parseTreeNodes(userData, connectionsTreeNode);
202201
allActionData.addAll(userData);
203202

204-
allActionData.stream()
203+
ACTIONS_DATA.addAll(allActionData.stream()
205204
.filter(o -> StringUtils.isBlank(category) || o.getCategoryName().toLowerCase().contains(category))
206-
.filter(o -> StringUtils.isBlank(query) || o.searchText().toLowerCase().contains(query)).collect(Collectors.toList()).forEach(ACTIONS_DATA::add
207-
);
205+
.filter(o -> StringUtils.isBlank(query) || o.searchText().toLowerCase().contains(query))
206+
.collect(Collectors.toList()));
208207

209208
populate();
210209

@@ -214,7 +213,7 @@ private void doSearch() {
214213
}
215214

216215

217-
void parseTreeNodes(List<Action> actions, DefaultMutableTreeNode data, ActionCategoryEnum category) {
216+
void parseTreeNodes(List<Action> actions, DefaultMutableTreeNode data) {
218217

219218
for (int i = 0, n = data.getChildCount(); i < n; i++) {
220219
TreeNode child = data.getChildAt(i);
@@ -234,7 +233,7 @@ void parseTreeNodes(List<Action> actions, DefaultMutableTreeNode data, ActionCat
234233
}
235234

236235
} else {
237-
parseTreeNodes(actions, treeChild, category);
236+
parseTreeNodes(actions, treeChild);
238237
}
239238

240239
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.haleywang.putty.view;
2+
3+
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
4+
5+
public class CommandEditor extends RSyntaxTextArea {
6+
7+
8+
}

src/main/java/com/haleywang/putty/view/puttypanel/connector/ssh/AbstractJschTtyConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.jcraft.jsch.Session;
1111
import com.jediterm.terminal.Questioner;
1212
import com.jediterm.terminal.TtyConnector;
13-
import org.apache.log4j.Logger;
13+
import org.slf4j.Logger;
1414

1515
import java.awt.Dimension;
1616
import java.io.IOException;
@@ -25,7 +25,7 @@
2525
* @author haley
2626
*/
2727
public abstract class AbstractJschTtyConnector<T extends Channel> implements TtyConnector {
28-
public static final Logger LOG = Logger.getLogger(AbstractJschTtyConnector.class);
28+
public static final Logger LOG = org.slf4j.LoggerFactory.getLogger(AbstractJschTtyConnector.class);
2929

3030
public static final int DEFAULT_SSH_PORT = 22;
3131

src/main/java/com/haleywang/putty/view/side/SideView.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static class SingletonHolder {
8686

8787
private String aesKey;
8888

89-
private FileStorage fileStorage = FileStorage.INSTANCE;
89+
private static final FileStorage FILE_STORAGE = FileStorage.INSTANCE;
9090

9191
private SideView() {
9292
super(JSplitPane.VERTICAL_SPLIT);
@@ -103,30 +103,27 @@ public void changeTheme() {
103103

104104
public void reloadData() {
105105

106-
String str = fileStorage.getCommandsData();
107-
if (str != null) {
108-
updateCommandsJsonTextArea.setText(str);
109-
} else {
106+
String commandsData = FILE_STORAGE.getCommandsData();
107+
if (commandsData == null) {
110108
try {
111-
str = IoTool.read(this.getClass(), "/myCommandsExample.json");
112-
updateCommandsJsonTextArea.setText(str);
109+
commandsData = IoTool.read(this.getClass(), "/myCommandsExample.json");
113110
} catch (Exception e) {
114111
LOGGER.error("reload CommandsJson error", e);
115112
}
116113
}
117114

118-
String connectionsInfoData = fileStorage.getConnectionsInfoData();
119-
if (connectionsInfoData != null) {
120-
updateConnectionsJsonTextArea.setText(connectionsInfoData);
121-
} else {
115+
updateCommandsJsonTextArea.setText(commandsData);
116+
117+
String connectionsInfoData = FILE_STORAGE.getConnectionsInfoData();
118+
if (connectionsInfoData == null) {
122119
try {
123-
String str1 = IoTool.read(this.getClass(), "/myConnectionsInfoExample.json");
124-
updateConnectionsJsonTextArea.setText(str1);
120+
connectionsInfoData = IoTool.read(this.getClass(), "/myConnectionsInfoExample.json");
125121
} catch (Exception e) {
126122
LOGGER.error("reload ConnectionsJson error", e);
127-
128123
}
129124
}
125+
updateConnectionsJsonTextArea.setText(connectionsInfoData);
126+
130127

131128
commandsTreePanel.getCommandsTreeView().updateUI();
132129
connectionsTreePanel.getConnectionsInfoTreeView().updateUI();
@@ -286,7 +283,7 @@ public void saveCommandsDataAndChangeCommandsTree() {
286283
}
287284

288285
public void saveCommandsData() {
289-
fileStorage.saveCommandsData(updateCommandsJsonTextArea.getText());
286+
FILE_STORAGE.saveCommandsData(updateCommandsJsonTextArea.getText());
290287
}
291288

292289

@@ -301,7 +298,7 @@ public void saveCommand() {
301298
Gson gson = new GsonBuilder().setPrettyPrinting().create();
302299

303300
String commandsJson = gson.toJson(userDataObject);
304-
fileStorage.saveCommandsData(commandsJson);
301+
FILE_STORAGE.saveCommandsData(commandsJson);
305302

306303
reloadData();
307304
});
@@ -408,7 +405,7 @@ private void changeCommandsTree() {
408405
}
409406

410407
private Map<String, Object> getConnectionsPasswordsMap() {
411-
String text = fileStorage.getConnectionsPasswords();
408+
String text = FILE_STORAGE.getConnectionsPasswords();
412409
if (text == null) {
413410
return new HashMap<>(6);
414411
}
@@ -421,7 +418,7 @@ private Map<String, Object> getConnectionsPasswordsMap() {
421418
}
422419

423420
public AccountDto getConnectionAccountByNodeName(String nodeName) {
424-
Map map = getConnectionsPasswordsMap();
421+
Map<String, Object> map = getConnectionsPasswordsMap();
425422
String accountKey = getAccountKey(nodeName);
426423
String pwdKey = getAccountPwdKey(nodeName);
427424

src/main/java/com/haleywang/putty/view/side/subview/CommandEditorPanel.java

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@
22

33
import com.haleywang.putty.dto.CommandDto;
44
import com.haleywang.putty.util.StringUtils;
5+
import com.haleywang.putty.view.CommandEditor;
56
import com.haleywang.putty.view.PlaceholderTextField;
67
import com.haleywang.putty.view.SpringRemoteView;
78
import com.haleywang.putty.view.side.SideView;
9+
import com.mindbright.util.StringUtil;
10+
import org.fife.ui.rsyntaxtextarea.FoldingAwareIconRowHeader;
11+
import org.fife.ui.rtextarea.Gutter;
12+
import org.fife.ui.rtextarea.GutterIconInfo;
13+
import org.fife.ui.rtextarea.RTextScrollPane;
814
import org.slf4j.Logger;
915
import org.slf4j.LoggerFactory;
1016

17+
import javax.swing.ImageIcon;
1118
import javax.swing.JButton;
1219
import javax.swing.JPanel;
13-
import javax.swing.JScrollPane;
1420
import javax.swing.JTextArea;
1521
import javax.swing.SwingUtilities;
1622
import javax.swing.border.EmptyBorder;
1723
import javax.swing.border.LineBorder;
1824
import java.awt.BorderLayout;
1925
import java.awt.Color;
26+
import java.awt.Component;
27+
import java.awt.Cursor;
2028
import java.awt.event.KeyAdapter;
2129
import java.awt.event.KeyEvent;
30+
import java.awt.event.MouseAdapter;
31+
import java.awt.event.MouseEvent;
32+
import java.net.URL;
33+
import java.util.Arrays;
2234

2335

2436
/**
@@ -31,6 +43,7 @@ public class CommandEditorPanel extends JPanel implements TextAreaMenu.RunAction
3143
private JTextArea updateCommandTextArea;
3244
private PlaceholderTextField commandNameTextField;
3345
private CommandDto currentEditCommand;
46+
private Gutter gutter;
3447

3548
public CommandEditorPanel() {
3649
createUpdateCommandPanel();
@@ -40,9 +53,58 @@ private void createUpdateCommandPanel() {
4053
JPanel updateCommandPanel = this;
4154
updateCommandPanel.setLayout(new BorderLayout());
4255

43-
updateCommandTextArea = new TextAreaMenu(this);
56+
updateCommandTextArea = new CommandEditor();
57+
58+
RTextScrollPane sp = new RTextScrollPane(updateCommandTextArea);
59+
sp.setIconRowHeaderEnabled(true);
60+
61+
gutter = sp.getGutter();
62+
63+
gutter.getIconArea().addMouseListener(new MouseAdapter() {
64+
65+
@Override
66+
public void mouseClicked(MouseEvent e) {
67+
Component[] comps = gutter.getComponents();
68+
FoldingAwareIconRowHeader iconComp = (FoldingAwareIconRowHeader) Arrays.stream(comps)
69+
.filter(o -> o instanceof FoldingAwareIconRowHeader)
70+
.findFirst().orElse(null);
71+
if(iconComp == null) {
72+
return;
73+
}
74+
int offs = gutter.getTextArea().viewToModel(e.getPoint());
75+
try {
76+
int currLine = gutter.getTextArea().getLineOfOffset(offs);
77+
GutterIconInfo[] trackingIcons = iconComp.getTrackingIcons(currLine);
78+
79+
if(trackingIcons.length >= 1){
80+
//run command
81+
int lineStartOffset = gutter.getTextArea().getLineStartOffset(currLine);
82+
83+
int lineEndOffset = gutter.getTextArea().getLineEndOffset(currLine);
84+
String commandText = gutter.getTextArea().getText(lineStartOffset, (lineEndOffset - lineStartOffset));
85+
commandText = StringUtils.trim(commandText);
86+
SideView.getInstance().runWithSelectedText(commandText);
87+
return;
88+
}
89+
gutter.removeAllTrackingIcons();
90+
91+
URL url = ClassLoader.getSystemClassLoader().getResource("Play16.png");
92+
assert url != null;
93+
ImageIcon icon = new ImageIcon(url);
94+
95+
gutter.addOffsetTrackingIcon(offs, icon, "Run");
96+
} catch (Exception ex) {
97+
LOGGER.error("click run icon error", ex);
98+
}
99+
100+
}
101+
102+
103+
104+
});
105+
106+
44107

45-
JScrollPane sp = new JScrollPane(updateCommandTextArea);
46108
updateCommandTextArea.setLineWrap(true);
47109

48110
updateCommandTextArea.setEditable(true);
@@ -95,6 +157,9 @@ public void keyReleased(KeyEvent e) {
95157
updateCommandOuterPanel.setLayout(new BorderLayout());
96158
updateCommandOuterPanel.add(updateCommandPanel);
97159
updateCommandOuterPanel.setBorder(new EmptyBorder(2, 2, 2, 2));
160+
161+
Arrays.stream(gutter.getComponents()).filter(o -> o instanceof FoldingAwareIconRowHeader)
162+
.findFirst().ifPresent(o -> o.setCursor(new Cursor(Cursor.HAND_CURSOR)));
98163
}
99164

100165
@Override

src/main/javaopen/com/intellij/openapi/diagnostic/DefaultLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import com.intellij.openapi.util.text.StringUtil;
1919
import com.intellij.util.ExceptionUtil;
20-
import org.apache.log4j.Level;
20+
import org.slf4j.event.Level;
2121
import org.jetbrains.annotations.NonNls;
2222
import org.jetbrains.annotations.NotNull;
2323
import org.jetbrains.annotations.Nullable;

0 commit comments

Comments
 (0)