Skip to content

Commit

Permalink
improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
marregui committed Oct 5, 2023
1 parent ee9f57e commit e1be704
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 416 deletions.
4 changes: 4 additions & 0 deletions src/main/java/io/questdb/desktop/GTk.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ public static JMenuItem menuItem(Icon icon, String title, int keyEvent, ActionLi
return menuItem(new JMenuItem(), icon, title, null, keyEvent, listener);
}

public static JMenuItem menuItem(Icon icon, String title, ActionListener listener) {
return menuItem(new JMenuItem(), icon, title, null, Keyboard.NO_KEY_EVENT, listener);
}

public static JMenuItem menuItem(Icon icon, String title, String tooltip, int keyEvent, ActionListener listener) {
return menuItem(new JMenuItem(), icon, title, tooltip, keyEvent, listener);
}
Expand Down
48 changes: 11 additions & 37 deletions src/main/java/io/questdb/desktop/Main.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2023 QuestDB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/

package io.questdb.desktop;

import java.awt.*;
Expand All @@ -44,21 +20,19 @@
import io.questdb.desktop.model.Store;
import io.questdb.ServerMain;
import io.questdb.desktop.ui.connectivity.Conns;
import io.questdb.desktop.ui.editor.QuestsEditor;
import io.questdb.desktop.ui.editor.MainEditor;
import io.questdb.desktop.ui.EventProducer;
import io.questdb.desktop.ui.results.SQLResultsTable;
import io.questdb.log.Log;
import io.questdb.log.LogFactory;
import io.questdb.std.Misc;

import static io.questdb.desktop.GTk.menuItem;


public final class Main {
private static final Log LOG = LogFactory.getLog(Main.class);

private final JFrame frame;
private final QuestsEditor commands;
private final MainEditor commands;
private final Conns conns;
private final SQLResultsTable results;
private final SQLExecutor executor;
Expand All @@ -79,7 +53,7 @@ private Main() {
meta = new Metadata(frame, "Metadata Files", this::dispatchEvent);
plot = new Plot(frame, "Plot", this::dispatchEvent);
conns = new Conns(frame, this::dispatchEvent);
commands = new QuestsEditor(this::dispatchEvent);
commands = new MainEditor(this::dispatchEvent);
commands.setPreferredSize(new Dimension(0, dividerHeight));
results = new SQLResultsTable(frame.getWidth(), dividerHeight);
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, commands, results);
Expand Down Expand Up @@ -191,8 +165,8 @@ private void onTogglePlot(ActionEvent event) {
return;
}
plot.setDataSet(
new TableColumn("x", table, 1, Color.WHITE),
new TableColumn("y", table, 2, GTk.Editor.MATCH_FOREGROUND_COLOR)
new TableColumn("x", table, 1, Color.WHITE),
new TableColumn("y", table, 2, GTk.Editor.MATCH_FOREGROUND_COLOR)
);
plot.setVisible(true);
togglePlot.setText("Close Plot");
Expand All @@ -214,10 +188,10 @@ private void onToggleQuestDB(ActionEvent event) {
}
} else {
if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
frame,
"Shutdown QuestDB?",
"Choice",
JOptionPane.YES_NO_OPTION)
frame,
"Shutdown QuestDB?",
"Choice",
JOptionPane.YES_NO_OPTION)
) {
questDb.close();
questDb = null;
Expand All @@ -230,7 +204,7 @@ private void onToggleQuestDB(ActionEvent event) {

private void dispatchEvent(EventProducer<?> source, Enum<?> event, Object data) {
GTk.invokeLater(() -> {
if (source instanceof QuestsEditor) {
if (source instanceof MainEditor) {
onCommandEvent(EventProducer.eventType(event), (SQLExecutionRequest) data);
} else if (source instanceof SQLExecutor) {
onSQLExecutorEvent(EventProducer.eventType(event), (SQLExecutionResponse) data);
Expand All @@ -244,7 +218,7 @@ private void dispatchEvent(EventProducer<?> source, Enum<?> event, Object data)
});
}

private void onCommandEvent(QuestsEditor.EventType event, SQLExecutionRequest req) {
private void onCommandEvent(MainEditor.EventType event, SQLExecutionRequest req) {
switch (event) {
case COMMAND_AVAILABLE -> {
DbConn conn = commands.getConnection();
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/io/questdb/desktop/ui/editor/Content.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.questdb.desktop.ui.editor;

import io.questdb.desktop.GTk;
import io.questdb.desktop.model.StoreEntry;

public class Content extends StoreEntry {
private static final String ATTR_NAME = "content";

public Content() {
this("default");
}

public Content(String name) {
super(name);
setAttr(ATTR_NAME, GTk.BANNER);
}

@SuppressWarnings("unused")
public Content(StoreEntry other) {
super(other);
}

@Override
public final String getUniqueId() {
return getName();
}

public String getContent() {
return getAttr(ATTR_NAME);
}

public void setContent(String content) {
setAttr(ATTR_NAME, content);
}
}
Loading

0 comments on commit e1be704

Please sign in to comment.