From f711908a31da594cd2460214ecda3a1a5d9df8be Mon Sep 17 00:00:00 2001 From: Chris Bitmead Date: Mon, 10 Nov 2025 22:08:36 +0800 Subject: [PATCH] one frame per connection --- .../docktabdesktop/DesktopTabbedPane.java | 30 +++++++++++++++---- .../docktabdesktop/DockTabDesktopPane.java | 19 ++++++++++-- .../docktabdesktop/TabWindowController.java | 7 +++-- .../preferences/GeneralPreferencesGUI.java | 30 +++++++++++++++---- .../client/preferences/I18NStrings.properties | 3 +- .../preferences/SquirrelPreferences.java | 21 ++++++++++++- .../SquirrelPreferencesBeanInfo.java | 1 + 7 files changed, 95 insertions(+), 16 deletions(-) diff --git a/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DesktopTabbedPane.java b/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DesktopTabbedPane.java index 4e24917b9a..28d1473919 100644 --- a/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DesktopTabbedPane.java +++ b/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DesktopTabbedPane.java @@ -1,9 +1,9 @@ package net.sourceforge.squirrel_sql.client.gui.desktopcontainer.docktabdesktop; -import java.awt.Component; -import java.awt.Dimension; +import java.awt.*; import java.awt.event.MouseEvent; -import javax.swing.Icon; +import javax.swing.*; +import javax.swing.plaf.metal.MetalTabbedPaneUI; import net.sourceforge.squirrel_sql.client.IApplication; import net.sourceforge.squirrel_sql.client.gui.builders.dndtabbedpane.DnDTabbedPane; @@ -13,13 +13,32 @@ public class DesktopTabbedPane extends DnDTabbedPane { + boolean _hideTabBar = false; + JLabel _titleLabel; + public DesktopTabbedPane(IApplication app) { super(app.getMultipleWindowsHandler().getOutwardDndTabbedPaneChanel()); + _hideTabBar = app.getSquirrelPreferences().getUseNewFramePerConnection(); setPaintScrollArea(false); setPaintGhost(true); - - GUIUtils.listenToMouseWheelClickOnTab(this, (tabIndex, tabComponent) -> ((ButtonTabComponent)tabComponent).doClickClose()); + setUI(new MetalTabbedPaneUI() { + @Override + protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) { + if (!_hideTabBar) { + super.paintContentBorder(g, tabPlacement, selectedIndex); + } + } + @Override + protected int calculateTabAreaHeight(int tab_placement, int run_count, int max_tab_height) { + if (_hideTabBar && DesktopTabbedPane.this.getTabCount() <= 1) { + return 0; + } else { + return super.calculateTabAreaHeight(tab_placement, run_count, max_tab_height); + } + } + }); + GUIUtils.listenToMouseWheelClickOnTab(this, (tabIndex, tabComponent) -> ((ButtonTabComponent)tabComponent).doClickClose()); } @@ -40,6 +59,7 @@ public void setTitleAt(int index, String title) { ButtonTabComponent btc = (ButtonTabComponent) getTabComponentAt(index); btc.setTitle(title); + _titleLabel.setText(title.replaceAll("^[0-9]* - ", "")); } @Override diff --git a/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DockTabDesktopPane.java b/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DockTabDesktopPane.java index e0caec2a9e..f1ded8a356 100644 --- a/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DockTabDesktopPane.java +++ b/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/DockTabDesktopPane.java @@ -44,6 +44,8 @@ public enum TabClosingMode private DockPanel _pnlDock = new DockPanel(); + private JPanel _titlePanel = new JPanel(new BorderLayout()); + private JLabel _titleLabel = new JLabel(); private DesktopTabbedPane _tabbedPane; private JSplitPane _split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); @@ -58,10 +60,12 @@ public enum TabClosingMode private DockTabDesktopManager _dockTabDesktopManager = new DockTabDesktopManager(); private ScrollableTabHandler _scrollableTabHandler; + private boolean _useNewFramePerConnection = false; public DockTabDesktopPane(IApplication app, boolean belongsToMainApplicationWindow, DockTabDesktopPaneListener dockTabDesktopPaneListener) { _app = app; + _useNewFramePerConnection = app.getSquirrelPreferences().getUseNewFramePerConnection(); _belongsToMainApplicationWindow = belongsToMainApplicationWindow; _dockTabDesktopPaneListener = dockTabDesktopPaneListener; @@ -85,7 +89,15 @@ public void stateChanged(ChangeEvent e) } }); - _split.setRightComponent(_tabbedPane); + _tabbedPane._titleLabel = _titleLabel; + if (_useNewFramePerConnection && !belongsToMainApplicationWindow) { + _titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + _titlePanel.add(_tabbedPane, BorderLayout.CENTER); + _titlePanel.add(_titleLabel, BorderLayout.NORTH); + _split.setRightComponent(_titlePanel); + } else { + _split.setRightComponent(_tabbedPane); + } add(_split, BorderLayout.CENTER); @@ -216,6 +228,9 @@ public void actionPerformed(ActionEvent e) _tabbedPane.setSelectedIndex(tabIx); _scrollableTabHandler.tabAdded(); + if (_belongsToMainApplicationWindow && _useNewFramePerConnection) { + onToWindow(tabHandle); + } return tabHandle; } @@ -232,7 +247,7 @@ private void onToWindow(TabHandle tabHandle) Dimension size = getSelectedHandle().getWidget().getContentPane().getSize(); // //////////////////////////////////////////////////////////////////////////////////// - TabWindowController tabWindowController = new TabWindowController(locationOnScreen, size, _app); + TabWindowController tabWindowController = new TabWindowController(_titleLabel.getText(), locationOnScreen, size, _app); _app.getMultipleWindowsHandler().registerDesktop(tabWindowController); diff --git a/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/TabWindowController.java b/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/TabWindowController.java index b92a4b7ad4..7a989980b4 100644 --- a/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/TabWindowController.java +++ b/sql12/core/src/net/sourceforge/squirrel_sql/client/gui/desktopcontainer/docktabdesktop/TabWindowController.java @@ -35,13 +35,16 @@ public class TabWindowController implements DockTabDesktopPaneHolder private IApplication _app; private final JMenu _mnuSession; private final JFrame _tabWindowFrame; + String _title; private static class MoveTabBackToMainWinMarker {} - public TabWindowController(Point locationOnScreen, Dimension size, final IApplication app) + public TabWindowController(String title, Point locationOnScreen, Dimension size, final IApplication app) { + // Kind of a hack, would be better if the title code was refactored + _title = title.replaceAll("^[0-9]* - ", ""); _app = app; - _tabWindowFrame = new JFrame(_app.getMainFrame().getTitle() + " " +s_stringMgr.getString("docktabdesktop.TabWindowController.titlePostFix")); + _tabWindowFrame = new JFrame(title); _tabWindowFrame.setLocation(locationOnScreen); _tabWindowFrame.setSize(size); diff --git a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/GeneralPreferencesGUI.java b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/GeneralPreferencesGUI.java index d42682582b..a4b1248775 100644 --- a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/GeneralPreferencesGUI.java +++ b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/GeneralPreferencesGUI.java @@ -28,7 +28,8 @@ final class GeneralPreferencesGUI extends JPanel private static final StringManager s_stringMgr = StringManagerFactory.getStringManager(GeneralPreferencesGUI.class); private JRadioButton _tabbedStyle = new JRadioButton(s_stringMgr.getString("GeneralPreferencesPanel.tabbedStyle")); - private JRadioButton _internalFrameStyle = new JRadioButton(s_stringMgr.getString("GeneralPreferencesPanel.internalFrameStyle")); + private JRadioButton _internalFrameStyle = new JRadioButton(s_stringMgr.getString("GeneralPreferencesPanel.internalFrameStyle")); + private JRadioButton _useNewFramePerConnection = new JRadioButton(s_stringMgr.getString("GeneralPreferencesPanel.useNewFramePerConnection")); private JCheckBox _useScrollableTabbedPanesForSessionTabs = new JCheckBox(s_stringMgr.getString("GeneralPreferencesPanel.useScrollableTabbedPanesForSessionTabs")); private JCheckBox _showContents = new JCheckBox(s_stringMgr.getString("GeneralPreferencesPanel.showwindowcontents")); private JCheckBox _maximimizeSessionSheet = new JCheckBox(s_stringMgr.getString("GeneralPreferencesPanel.maxonopen")); @@ -82,9 +83,18 @@ final class GeneralPreferencesGUI extends JPanel void loadData(SquirrelPreferences prefs) { - _tabbedStyle.setSelected(prefs.getTabbedStyle()); + if (prefs.getUseNewFramePerConnection()) + { + _useNewFramePerConnection.setSelected(true); + _tabbedStyle.setSelected(false); + _internalFrameStyle.setSelected(false); + } + else { + _tabbedStyle.setSelected(prefs.getTabbedStyle()); + _internalFrameStyle.setSelected(!prefs.getTabbedStyle()); + _useNewFramePerConnection.setSelected(false); + } _useScrollableTabbedPanesForSessionTabs.setSelected(prefs.getUseScrollableTabbedPanesForSessionTabs()); - _internalFrameStyle.setSelected(!prefs.getTabbedStyle()); onStyleChanged(); _showTabbedStyleHint.setSelected(prefs.getShowTabbedStyleHint()); @@ -122,8 +132,8 @@ void loadData(SquirrelPreferences prefs) LocaleWrapper.setSelectedLocalePrefsString(_localeChooser, prefs.getPreferredLocale()); _tabbedStyle.addActionListener(e -> onStyleChanged()); - _internalFrameStyle.addActionListener(e -> onStyleChanged()); + _useNewFramePerConnection.addActionListener(e -> onStyleChanged()); _messagePrefsCtrl.loadData(prefs); @@ -142,7 +152,13 @@ private void onStyleChanged() void applyChanges(SquirrelPreferences prefs) { - prefs.setTabbedStyle(_tabbedStyle.isSelected()); + if (_useNewFramePerConnection.isSelected()) { + prefs.setUseNewFramePerConnection(true); + prefs.setTabbedStyle(true); + } else { + prefs.setUseNewFramePerConnection(false); + prefs.setTabbedStyle(_tabbedStyle.isSelected()); + } prefs.setUseScrollableTabbedPanesForSessionTabs(_useScrollableTabbedPanesForSessionTabs.isSelected()); prefs.setShowContentsWhenDragging(_showContents.isSelected()); prefs.setShowTabbedStyleHint(_showTabbedStyleHint.isSelected()); @@ -211,6 +227,7 @@ private JPanel createAppearancePanel() g.add(_tabbedStyle); g.add(_internalFrameStyle); + g.add(_useNewFramePerConnection); final GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(2, 4, 2, 4); @@ -225,6 +242,9 @@ private JPanel createAppearancePanel() _internalFrameStyle.setName("internalFrameStyleRadioButton"); pnl.add(_internalFrameStyle, gbc); ++gbc.gridy; + _useNewFramePerConnection.setName("useNewFramePerConnectionRadioButton"); + pnl.add(_useNewFramePerConnection, gbc); + ++gbc.gridy; _useScrollableTabbedPanesForSessionTabs.setName("useScrollableTabbedPanes"); pnl.add(_useScrollableTabbedPanesForSessionTabs, gbc); diff --git a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/I18NStrings.properties b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/I18NStrings.properties index d5ab22254f..1bd7c12a8a 100644 --- a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/I18NStrings.properties +++ b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/I18NStrings.properties @@ -132,6 +132,7 @@ GeneralPreferencesPanel.tabbedStyle=Use tabbed layout (needs restart) GeneralPreferencesPanel.useScrollableTabbedPanesForSessionTabs=Use scrollable tabbed panes for Session tabs (needs restart) GeneralPreferencesPanel.internalFrameStyle=Use MDI/Internal Frame layout (needs restart) GeneralPreferencesPanel.showTabbedStyleHint=Warn MDI/Internal Frame layout is deprecated +GeneralPreferencesPanel.useNewFramePerConnection=Use new Frame per connection (needs restart) GeneralPreferencesPanel.savePreferencesImmediatelyWarning_new=Warning:\nSaving Aliases and Drivers immediately may significantly slow down\nediting Aliases and Drivers if many Aliases or Drivers exist.\nSaving Preferences immediately may significantly slow down SQL execution\nif multiple statements are executed or if SQL history size is big\n(see menu 'New Session Properties' --> tab 'SQL' --> SQL History). @@ -153,4 +154,4 @@ SQLPreferencesPanel.reload.changetrack.hint=Note: When the change tracking toolb SQLPreferencesPanel.notify.external.file.changes=Notify external file changes (requires application restart) -SQLPreferencesPanel.use.statement.separator.as.current.bounds=Use statement separator (instead of empty line) as bounds of current SQL \ No newline at end of file +SQLPreferencesPanel.use.statement.separator.as.current.bounds=Use statement separator (instead of empty line) as bounds of current SQL diff --git a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferences.java b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferences.java index ff537a2aef..2c24165f1a 100755 --- a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferences.java +++ b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferences.java @@ -86,6 +86,7 @@ public interface IPropertyNames String SHOW_ALIASES_TOOL_BAR = "showAliasesToolBar"; String SHOW_CONTENTS_WHEN_DRAGGING = "showContentsWhenDragging"; String TABBED_STYLE = "tabbedStyle"; + String USE_NEW_FRAME_PER_CONNECTION = "useNewFramePerConnection"; String USE_SCROLLABLE_TABBED_PANES_FOR_SESSION_TABS = "useScrollableTabbedPanesForSessionTabs"; String SHOW_TABBED_STYLE_HINT = "showTabbedStyleHint"; String SHOW_DRIVERS_TOOL_BAR = "showDriversToolBar"; @@ -188,6 +189,8 @@ public interface IJdbcDebugTypes private boolean _tabbedStyle = true; + private boolean _useNewFramePerConnection = false; + private boolean _useScrollableTabbedPanesForSessionTabs; private boolean _showTabbedStyleHint = true; @@ -424,7 +427,12 @@ public boolean getTabbedStyle() return _tabbedStyle; } - public synchronized void setTabbedStyle(boolean data) + public boolean getUseNewFramePerConnection() + { + return _useNewFramePerConnection; + } + + public synchronized void setTabbedStyle(boolean data) { if (data != _tabbedStyle) { @@ -435,6 +443,17 @@ public synchronized void setTabbedStyle(boolean data) } } + public synchronized void setUseNewFramePerConnection(boolean data) + { + if (data != _useNewFramePerConnection) + { + final boolean oldValue = _useNewFramePerConnection; + _useNewFramePerConnection = data; + getPropertyChangeReporter().firePropertyChange(IPropertyNames.USE_NEW_FRAME_PER_CONNECTION, + oldValue, _useNewFramePerConnection); + } + } + public boolean getUseScrollableTabbedPanesForSessionTabs() { return _useScrollableTabbedPanesForSessionTabs; diff --git a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferencesBeanInfo.java b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferencesBeanInfo.java index 135a7412c6..bbbd0d0d64 100755 --- a/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferencesBeanInfo.java +++ b/sql12/core/src/net/sourceforge/squirrel_sql/client/preferences/SquirrelPreferencesBeanInfo.java @@ -50,6 +50,7 @@ public PropertyDescriptor[] getPropertyDescriptors() prop(SHOW_CONTENTS_WHEN_DRAGGING, SquirrelPreferences.class, "getShowContentsWhenDragging", "setShowContentsWhenDragging"), prop(TABBED_STYLE, SquirrelPreferences.class, "getTabbedStyle", "setTabbedStyle"), + prop(USE_NEW_FRAME_PER_CONNECTION, SquirrelPreferences.class, "getUseNewFramePerConnection", "setUseNewFramePerConnection"), prop(USE_SCROLLABLE_TABBED_PANES_FOR_SESSION_TABS, SquirrelPreferences.class, "getUseScrollableTabbedPanesForSessionTabs", "setUseScrollableTabbedPanesForSessionTabs"), prop(SHOW_TABBED_STYLE_HINT, SquirrelPreferences.class, "getShowTabbedStyleHint", "setShowTabbedStyleHint"),