Skip to content

Commit

Permalink
persist ServerList bounds in the Workspace individually for every Stu…
Browse files Browse the repository at this point in the history
…dioWindow
  • Loading branch information
dzmipt committed Feb 16, 2024
1 parent 0b78f08 commit ca980ce
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 28 deletions.
2 changes: 2 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Persist location of the server list frame for every Studio window

`dz4.1` 2024.01.29
-----
* Added line inspection (new popup menu in the table result)
Expand Down
10 changes: 8 additions & 2 deletions src/studio/kdb/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import studio.kdb.config.AbstractConfig;
import studio.kdb.config.ActionOnExit;
import studio.kdb.config.KdbMessageLimitAction;
import studio.ui.ServerList;
import studio.utils.*;
import studio.utils.log4j.EnvConfig;

Expand All @@ -34,7 +33,6 @@ public class Config extends AbstractConfig {
public static final String SHOW_SERVER_COMBOBOX = configDefault("showServerComboBox", ConfigType.BOOLEAN, true);
public static final String AUTO_SAVE = configDefault("isAutoSave", ConfigType.BOOLEAN, false);
public static final String ACTION_ON_EXIT = configDefault("actionOnExit", ConfigType.ENUM, ActionOnExit.SAVE);
public static final String SERVER_LIST_BOUNDS = configDefault("serverList", ConfigType.BOUNDS, new Dimension(ServerList.DEFAULT_WIDTH, ServerList.DEFAULT_HEIGHT));
public static final String CHART_BOUNDS = configDefault("chartBounds", ConfigType.BOUNDS, 0.5);
public static final String CELL_RIGHT_PADDING = configDefault("cellRightPadding", ConfigType.DOUBLE, 0.5);
public static final String CELL_MAX_WIDTH = configDefault("cellMaxWidth", ConfigType.INT, 200);
Expand Down Expand Up @@ -368,6 +366,13 @@ private void migrateSaveOnExit() {
}
}

private void removeServerListConfig() {
config.remove("serverList.x");
config.remove("serverList.y");
config.remove("serverList.width");
config.remove("serverList.height");
}

private void checkForUpgrade() {
if (config.size() == 0) {
log.info("Found no or empty config");
Expand All @@ -391,6 +396,7 @@ private void checkForUpgrade() {
}
initServerHistory();
migrateSaveOnExit();
removeServerListConfig();

config.setProperty("version", VERSION);
}
Expand Down
53 changes: 42 additions & 11 deletions src/studio/kdb/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Workspace {
private final static String Y = "y";
private final static String WIDTH = "width";
private final static String HEIGHT = "height";
private final static String SERVER_LIST = "serverlist.";
private final static String WINDOW = "window";
private final static String TAB = "tab";
private final static String LEFT = "left";
Expand All @@ -37,6 +38,7 @@ public class Workspace {
private final static String LINE_ENDING = "lineEnding";
private final static String CARET = "caret";

private final static Rectangle DEFAULT_BOUNDS = new Rectangle(-1,-1,0,0);

private final static Logger log = LogManager.getLogger();

Expand Down Expand Up @@ -64,6 +66,10 @@ private static int getInt(Properties p, String key, int defValue) {
}
}

private static void setInt(Properties p, String key, int value) {
p.setProperty(key, Integer.toString(value));
}

private static double getDouble(Properties p, String key, double defValue) {
try {
return Double.parseDouble(p.getProperty(key, "" + defValue));
Expand All @@ -72,6 +78,26 @@ private static double getDouble(Properties p, String key, double defValue) {
}
}

private static void setDouble(Properties p, String key, double value) {
p.setProperty(key, Double.toString(value));
}

private static Rectangle getBounds(Properties p, String prefix, Rectangle defValue) {
int x = getInt(p, prefix + X, defValue.x);
int y = getInt(p, prefix + Y, defValue.y);
int width = getInt(p, prefix + WIDTH, defValue.width);
int height = getInt(p, prefix + HEIGHT, defValue.height);

return new Rectangle(x, y, width, height);
}

public static void setBounds(Properties p, String prefix, Rectangle value) {
setInt(p, prefix + X, value.x);
setInt(p, prefix + Y, value.y);
setInt(p, prefix + WIDTH, value.width);
setInt(p, prefix + HEIGHT, value.height);
}

private static boolean hasKeysWithPrefix(Properties p, String prefix) {
for(Object key : p.keySet() ) {
if (key.toString().startsWith(prefix)) return true;
Expand Down Expand Up @@ -220,6 +246,7 @@ private Window loadChild(String prefix, Properties p) {
public static class TopWindow extends Window {
private double resultDividerLocation = 0.5;
private Rectangle location;
private Rectangle serverListBounds;

public TopWindow() {}

Expand All @@ -244,24 +271,28 @@ public void setLocation(Rectangle location) {
this.location = location;
}

protected void load(String prefix, Properties p) {
resultDividerLocation = Double.parseDouble(p.getProperty(prefix + RESULT_DIVIDER_LOCATION, "0.5"));
int x = Integer.parseInt(p.getProperty(prefix + X, "-1"));
int y = Integer.parseInt(p.getProperty(prefix + Y, "-1"));
int width = Integer.parseInt(p.getProperty(prefix + WIDTH, "0"));
int height = Integer.parseInt(p.getProperty(prefix + HEIGHT, "0"));
location = new Rectangle(x,y, width, height);
public Rectangle getServerListBounds() {
return serverListBounds;
}

public void setServerListBounds(Rectangle serverListBounds) {
this.serverListBounds = serverListBounds;
}

protected void load(String prefix, Properties p) {
resultDividerLocation = getDouble(p, prefix + RESULT_DIVIDER_LOCATION, 0.5);
location = getBounds(p, prefix, DEFAULT_BOUNDS);
serverListBounds = getBounds(p, prefix + SERVER_LIST, DEFAULT_BOUNDS);
super.load(prefix, p);
}

protected void save(String prefix, Properties p) {
p.setProperty(prefix + RESULT_DIVIDER_LOCATION, Double.toString(resultDividerLocation));
if (location != null) {
p.setProperty(prefix + X, Integer.toString(location.x));
p.setProperty(prefix + Y, Integer.toString(location.y));
p.setProperty(prefix + WIDTH, Integer.toString(location.width));
p.setProperty(prefix + HEIGHT, Integer.toString(location.height));
setBounds(p, prefix, location);
}
if (serverListBounds != null) {
setBounds(p, prefix + SERVER_LIST, serverListBounds);
}

super.save(prefix, p);
Expand Down
20 changes: 19 additions & 1 deletion src/studio/ui/ServerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,27 @@ public class ServerList extends EscapeDialog implements TreeExpansionListener {
private static final int menuShortcutKeyMask = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
private final KeyStroke TREE_VIEW_KEYSTROKE = KeyStroke.getKeyStroke(KeyEvent.VK_T, menuShortcutKeyMask);

public ServerList(JFrame parent) {
public ServerList(JFrame parent, Rectangle bounds) {
super(parent, "Server List");
initComponents();

if (bounds != null && Util.fitToScreen(bounds)) {
setBounds(bounds);
} else {
setBounds(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
Util.centerChildOnParent(this, parent);
}
}


public Server showServerTree(Server activeServer, List<Server> serverHistory, boolean selectHistoryTab) {
updateServerTree(Config.getInstance().getServerTree(), activeServer);
updateServerHistory(serverHistory);
selectHistoryTab(selectHistoryTab);
setVisible(true);

return getSelectedServer();
}

public void updateServerTree(ServerTreeNode serverTree, Server activeServer) {
Expand Down
21 changes: 7 additions & 14 deletions src/studio/ui/StudioWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -1061,22 +1061,13 @@ private void selectConnectionString() {
}
}

private void showServerList(boolean selectHistory) {
if (serverList == null) {
serverList = new ServerList(this);
}
Rectangle bounds = Config.getInstance().getBounds(Config.SERVER_LIST_BOUNDS);
serverList.setBounds(bounds);

serverList.updateServerTree(CONFIG.getServerTree(), editor.getServer());
serverList.updateServerHistory(serverHistory);
serverList.selectHistoryTab(selectHistory);
serverList.setVisible(true);
public ServerList getServerList() {
return serverList;
}

bounds = serverList.getBounds();
CONFIG.setBounds(Config.SERVER_LIST_BOUNDS, bounds);
private void showServerList(boolean selectHistory) {
Server selectedServer = serverList.showServerTree(editor.getServer(), serverHistory, selectHistory);

Server selectedServer = serverList.getSelectedServer();
if (selectedServer == null || selectedServer.equals(editor.getServer())) return;

setServer(selectedServer);
Expand Down Expand Up @@ -1355,6 +1346,7 @@ public StudioWindow(Workspace.TopWindow workspaceWindow) {
topPanel.add(rootEditorsPanel, BorderLayout.CENTER);

initFrame(workspaceWindow.getLocation(), toolbar, splitpane, mainStatusBar);
serverList = new ServerList(this, workspaceWindow.getServerListBounds());
splitpane.setDividerLocation(workspaceWindow.getResultDividerLocation());

rootEditorsPanel.loadDividerLocation(workspaceWindow);
Expand Down Expand Up @@ -1743,6 +1735,7 @@ public static Workspace getWorkspace() {
Workspace.TopWindow workspaceWindow = workspace.addWindow(window == activeWindow);
workspaceWindow.setResultDividerLocation(Util.getDividerLocation(window.splitpane));
workspaceWindow.setLocation(window.getBounds());
workspaceWindow.setServerListBounds(window.getServerList().getBounds());
window.rootEditorsPanel.getWorkspace(workspaceWindow);
}
return workspace;
Expand Down

0 comments on commit ca980ce

Please sign in to comment.