Skip to content

Commit

Permalink
Merge pull request #22 from HaleyWang/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
HaleyWang committed Aug 15, 2020
2 parents 0496a6d + 04a6173 commit efa6b4f
Show file tree
Hide file tree
Showing 33 changed files with 595 additions and 273 deletions.
Binary file modified build/libs/SpringRemote-0.1.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
1 change: 0 additions & 1 deletion src/main/java/com/haleywang/putty/SpringRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class SpringRemote {
private static final Logger LOGGER = LoggerFactory.getLogger(SpringRemote.class);

public static void main(String[] args) {

try {
UIManager.setLookAndFeel(SpringRemoteView.getLookAndFeel());
FontUtils.setWindowsDefaultUiFont();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/haleywang/putty/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ private Constants() {

public static final String PATH_ROOT = PathUtils.getRoot();
public static final String PATH_DELIMITER = "/";
public static final String AT_CHAR = "@";
public static final int DOUBLE_CLICK_NUM = 2;
public static final int TERM_TWO = 2;

}
8 changes: 3 additions & 5 deletions src/main/java/com/haleywang/putty/dto/GroupDto.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.haleywang.putty.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* @author haley
*/
public class GroupDto<T> implements GroupItem, Serializable {
public class GroupDto<T> implements GroupItem {

private String name;

private ArrayList<T> children;
private List<T> children;


@Override
Expand All @@ -27,7 +25,7 @@ public List<T> getChildren() {
return children;
}

public void setChildren(ArrayList<T> children) {
public void setChildren(List<T> children) {
this.children = children;
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/haleywang/putty/dto/SettingDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @author haley
*/
public class SettingDto implements Serializable {
public static final int LIMIT_FRAME_WIDTH = 300;
public static final int LIMIT_FRAME_HEIGHT = 300;
private int tabLayout;
private String theme;
private String localFolder;
Expand Down Expand Up @@ -64,7 +66,7 @@ public void setLocalFile(String localFile) {
}

public int getFrameWidth() {
if (frameWidth < 300) {
if (frameWidth < LIMIT_FRAME_WIDTH) {
return 880;
}
return frameWidth;
Expand All @@ -75,7 +77,7 @@ public void setFrameWidth(int frameWidth) {
}

public int getFrameHeight() {
if (frameHeight < 300) {
if (frameHeight < LIMIT_FRAME_HEIGHT) {
return 700;
}
return frameHeight;
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/haleywang/putty/util/AesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* @author haley
*/
public class AesUtil {

public static final int KEY_LENGTH = 16;

private AesUtil() {
}

Expand Down Expand Up @@ -45,10 +48,10 @@ public static String generateKey(String in) {
}

String input = in.toLowerCase();
if (input.length() > 16) {
return input.substring(0, 16);
if (input.length() > KEY_LENGTH) {
return input.substring(0, KEY_LENGTH);
}
while (input.length() < 16) {
while (input.length() < KEY_LENGTH) {
input = appendA(input);
}
return input;
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/haleywang/putty/util/FontUtilities.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.haleywang.putty.util;
import sun.swing.SwingLazyValue;

import java.awt.Font;
import java.util.HashMap;
import java.util.Map;
import javax.swing.UIManager;
import sun.swing.SwingLazyValue;

/**
* @author haley
* @date 2020/2/2
*/
public class FontUtilities {

private FontUtilities(){}

private static Map<String, Font> originals;

public static void setFontScale(float scale) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/haleywang/putty/util/FontUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import java.awt.Font;
import java.util.Enumeration;

/**
* @author haley
* @date 2020/2/2
*/
public class FontUtils {
private FontUtils() {
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/haleywang/putty/util/IoTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -25,7 +26,7 @@ private IoTool() {

public static List<String> readLines(File file) {
List<String> lines = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
String line = null;
while ((line = br.readLine()) != null) {
lines.add(line);
Expand All @@ -51,7 +52,7 @@ public static String read(File file) {

private static String read(InputStream in) {
List<String> lines = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"))) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
String line = null;
while ((line = br.readLine()) != null) {
lines.add(line);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/haleywang/putty/util/Md5Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.haleywang.putty.common.SpringRemoteException;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

Expand All @@ -16,9 +16,9 @@ public class Md5Utils {
private Md5Utils() {
}

private static String getMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
private static String getMd5(String str) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes("UTF-8"));
md.update(str.getBytes(StandardCharsets.UTF_8));
return new BigInteger(1, md.digest()).toString(16);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/haleywang/putty/util/PathUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.haleywang.putty.util;

import com.haleywang.putty.common.Constants;

import java.io.File;


Expand All @@ -26,7 +28,7 @@ public static String getRoot() {
}
res = res.replace("/target/test-classes", "");
res = res.replace("/target/classes", "");
if (res.endsWith("/")) {
if (res.endsWith(Constants.PATH_DELIMITER)) {
res = res.substring(0, res.length() - 1);
}
return res;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/haleywang/putty/util/SshUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public static String sendCommand(Session sesConnection, String command) throws J
readByte = commandOutput.read();
}


channelExec.disconnect();


return outputBuffer.toString();
}
}
9 changes: 5 additions & 4 deletions src/main/java/com/haleywang/putty/view/ActionsDialog.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.haleywang.putty.view;

import com.haleywang.putty.common.Constants;
import com.haleywang.putty.dto.Action;
import com.haleywang.putty.service.ActionExecuteService;
import com.haleywang.putty.service.action.ActionCategoryEnum;
import com.haleywang.putty.service.action.ActionsData;
import com.haleywang.putty.util.StringUtils;
import com.haleywang.putty.view.side.SideView;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.DrawUtil;
import org.demo.Autocomplete;
import org.jdesktop.swingx.JXTable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -175,8 +176,8 @@ private void doSearch() {
String text = searchField.getText();
String categoryText = "";
String queryText = StringUtils.ifBlank(text, "").toLowerCase().trim();
if (queryText.startsWith("@")) {
int index = queryText.indexOf(" ");
if (queryText.startsWith(Constants.AT_CHAR)) {
int index = queryText.indexOf(' ');
index = index <= 0 ? queryText.length() : index;

categoryText = queryText.substring(1, index);
Expand Down Expand Up @@ -309,7 +310,7 @@ void populate() {
}
model.fireTableDataChanged();

if (UIUtil.isUnderDarcula()) {
if (DrawUtil.isUnderDarcula()) {
setColor(table, new Color[]{Color.DARK_GRAY, new Color(78, 78, 78)});

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/haleywang/putty/view/HelpDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public HelpDialog(SpringRemoteView omegaRemote) {
MyGridBagConstraints cs = new MyGridBagConstraints();
cs.insets = new Insets(6, 6, 6, 6);

System.out.println(getClass().getPackage().getImplementationVersion());
LOGGER.info("getImplementationVersion: {}", getClass().getPackage().getImplementationVersion());
ProjectInfo projectInfo = getProperties();

String helpUrl = "https://github.com/HaleyWang/SpringRemote";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/haleywang/putty/view/LeftMenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private LeftMenuView() {
sideTabPanel.add(connectionsTabBtn);

this.commandsJsonTabBtn = VerticalButton.rotateLeftBtn("Commands json");
this.commandTabBtn = VerticalButton.rotateLeftBtn("Command");
this.commandTabBtn = VerticalButton.rotateLeftBtn("Edit command");

Font font = commandsJsonTabBtn.getFont();
Font newFont = new java.awt.Font(
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/haleywang/putty/view/LoginDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class LoginDialog extends JDialog {
private static final GridConstraints GC_LB_PASSWORD = new GridConstraints().ofGridx(0).ofGridy(1).ofGridwidth(1);
private static final GridConstraints GC_TF_PASSWORD = new GridConstraints().ofGridx(1).ofGridy(1).ofGridwidth(2);

private JTextField tfUsername;
private JPasswordField pfPassword;
private final JTextField tfUsername;
private final JPasswordField pfPassword;
private boolean succeeded;
private SpringRemoteView omegaRemote;
private final SpringRemoteView omegaRemote;

public LoginDialog(SpringRemoteView omegaRemote) {
super(omegaRemote, LOGIN, true);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/haleywang/putty/view/MenuView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.haleywang.putty.view;

import com.haleywang.putty.common.Constants;
import com.haleywang.putty.dto.Action;
import com.haleywang.putty.service.NotificationsService;
import com.haleywang.putty.service.action.ActionsData;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void changeLayoutButtonsStatus(int termCount, int or) {
}
layoutButtonsGroup.clearSelection();

if (JSplitPane.VERTICAL_SPLIT == or && termCount == 2) {
if (JSplitPane.VERTICAL_SPLIT == or && termCount == Constants.TERM_TWO) {
layoutButtonsGroup.setSelected(layoutBtns.get(termCount).getModel(), true);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/haleywang/putty/view/MyFileBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public boolean isCellEditable(int row, int column) {
final JButton addButton = new JButton("Open");
addButton.addActionListener(e -> {
String selectedPath = currentPath + Constants.PATH_DELIMITER + aTextField.getText();
selectedPath = selectedPath.replaceAll("//", Constants.PATH_DELIMITER);
selectedPath = selectedPath.replaceAll("[/]{2}", Constants.PATH_DELIMITER);
openActionListener.doOpen(selectedPath);
setVisible(false);
});
Expand Down Expand Up @@ -258,7 +258,7 @@ private void mouseClickFile(int modelSelectedRow) {
}

private void mouseClickFolder(MouseEvent e, ChannelSftp.LsEntry item, int modelSelectedRow) {
if (e.getClickCount() == 2) {
if (e.getClickCount() == Constants.DOUBLE_CLICK_NUM) {
// your valueChanged overridden method

try {
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/com/haleywang/putty/view/MyJsonTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

/**
* @author haley
* @date 2020/2/2
*/
public class MyJsonTextArea extends RSyntaxTextArea {

public interface AfterFormatAction {

/**
* do something after format
*/
void doAfterFormat();
}

private AfterFormatAction afterFormatAction;
private transient AfterFormatAction afterFormatAction;

public MyJsonTextArea(int rows, int cols) {
super(rows, cols);
Expand All @@ -34,11 +41,9 @@ protected JPopupMenu createPopupMenu() {

formatMenu.addActionListener(e -> {

String text = MyJsonTextArea.this.getText();

Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(MyJsonTextArea.this.getText());
String prettyJsonString = gson.toJson(je);
String prettyJsonString = getFormatString(text);

MyJsonTextArea.this.setText(prettyJsonString);
if (afterFormatAction != null) {
Expand All @@ -49,4 +54,14 @@ protected JPopupMenu createPopupMenu() {
popupMenu.add(formatMenu);
return popupMenu;
}

public static String getFormatString(String text) {
if(text == null) {
return null;
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(text);
return gson.toJson(je);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import java.awt.Graphics2D;
import java.awt.RenderingHints;


/**
* @author haley
* @date 2020/2/2
*/
@SuppressWarnings("serial")
public class PlaceholderTextField extends JTextField {

Expand Down
Loading

0 comments on commit efa6b4f

Please sign in to comment.