Revision: 6219
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6219&view=rev
Author: wis775
Date: 2011-03-27 19:58:47 +0000 (Sun, 27 Mar 2011)
Log Message:
-----------
Feature Request 3185630: SQL Panel layout:
- Squirrel uses a vertical layout for the SQL Panel. Now, this layout can be changed to horizontal,
which might be useful on wide screen displays. This can be configured within the
Session Properties and New Session Properties => Tab General => Combo Box: SQL Panel layout
- A double click on the divider restores the divider position to the default value.
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/SQLPanel.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/GeneralSessionPropertiesPanel.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionProperties.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionPropertiesBeanInfo.java
trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/session/properties/I18NStrings.properties
trunk/sql12/doc/src/main/resources/changes.txt
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/SQLPanel.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/SQLPanel.java 2011-03-27 02:04:52 UTC (rev 6218)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/SQLPanel.java 2011-03-27 19:58:47 UTC (rev 6219)
@@ -27,6 +27,8 @@
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.sql.SQLException;
@@ -35,13 +37,26 @@
import java.util.List;
import java.util.prefs.Preferences;
-import javax.swing.*;
-import javax.swing.text.JTextComponent;
+import javax.swing.Action;
+import javax.swing.Box;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingUtilities;
+import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.EventListenerList;
+import javax.swing.plaf.SplitPaneUI;
+import javax.swing.plaf.basic.BasicSplitPaneUI;
import net.sourceforge.squirrel_sql.client.IApplication;
import net.sourceforge.squirrel_sql.client.gui.builders.UIFactory;
@@ -155,6 +170,7 @@
transient private ISQLPanelAPI _panelAPI;
private static final String PREFS_KEY_SPLIT_DIVIDER_LOC = "squirrelSql_sqlPanel_divider_loc";
+ private static final String PREFS_KEY_SPLIT_DIVIDER_LOC_HORIZONTAL = "squirrelSql_sqlPanel_divider_loc_horizontal";
/**
* true if this panel is within a SessionInternalFrame
@@ -404,8 +420,8 @@
if(_hasBeenVisible)
{
- int dividerLoc = _splitPane.getDividerLocation();
- Preferences.userRoot().putInt(PREFS_KEY_SPLIT_DIVIDER_LOC, dividerLoc);
+ saveOrientationDependingDividerLocation();
+
}
_sqlCombo.removeActionListener(_sqlComboListener);
@@ -426,6 +442,20 @@
}
+ /**
+ * Save the location of the divider depending on the orientation.
+ * @see #PREFS_KEY_SPLIT_DIVIDER_LOC
+ * @see #PREFS_KEY_SPLIT_DIVIDER_LOC_HORIZONTAL
+ */
+ private void saveOrientationDependingDividerLocation() {
+ int dividerLoc = _splitPane.getDividerLocation();
+ if(_splitPane.getOrientation() == JSplitPane.VERTICAL_SPLIT){
+ Preferences.userRoot().putInt(PREFS_KEY_SPLIT_DIVIDER_LOC, dividerLoc);
+ }else{
+ Preferences.userRoot().putInt(PREFS_KEY_SPLIT_DIVIDER_LOC_HORIZONTAL, dividerLoc);
+ }
+ }
+
private void installSQLEntryPanel(ISQLEntryPanel pnl)
{
if (pnl == null)
@@ -838,7 +868,10 @@
add(pnl, BorderLayout.NORTH);
}
- createSplitPaneWithHackToSetSplitLocation();
+ // TODO Stefan, clean up one of this
+ createSplitPaneAndSetSplitLocation();
+// createSplitPaneWithHackToSetSplitLocation();
+
_splitPane.setOneTouchExpandable(true);
installSQLEntryPanel(
@@ -867,10 +900,12 @@
});
}
+ // TODO Stefan, if createSplitPaneAndSetSplitLocation works correctly, remove this.
private void createSplitPaneWithHackToSetSplitLocation()
{
- final int dividerLoc = Preferences.userRoot().getInt(PREFS_KEY_SPLIT_DIVIDER_LOC, 50);
-
+ final int spOrientation = getSession().getProperties().getSqlPanelOrientation();
+ final int dividerLoc = calculateDivederLocation(spOrientation, false);
+
final Timer timer = new Timer(500, new ActionListener()
{
public void actionPerformed(ActionEvent e)
@@ -881,7 +916,7 @@
timer.setRepeats(false);
- _splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT)
+ _splitPane = new JSplitPane(spOrientation)
{
// @Override
// public void setDividerLocation(double proportionalLocation)
@@ -923,9 +958,131 @@
timer.restart();
}
});
+ /*
+ * Add a PropertyChangeListener for the SessionProperties for changing the orientation
+ * of the split pane, if the user change the settings.
+ */
+ getSession().getProperties().addPropertyChangeListener(new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ if(SessionProperties.IPropertyNames.SQL_PANEL_ORIENTATION.equals(evt.getPropertyName())){
+ saveOrientationDependingDividerLocation();
+ _splitPane.setOrientation((Integer) evt.getNewValue());
+ _splitPane.setDividerLocation(calculateDivederLocation(_splitPane.getOrientation(), false));
+ _splitPane.repaint();
+ }
+ }
+ });
+
+ /*
+ * Add a mouse event listener to the divider, so that we can reset the divider location when a doulbe click
+ * occurs on the divider.
+ */
+ SplitPaneUI spUI = _splitPane.getUI();
+ if (spUI instanceof BasicSplitPaneUI) {
+ BasicSplitPaneUI bspUI = (BasicSplitPaneUI) spUI;
+ bspUI.getDivider().addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
+ _splitPane.setDividerLocation(calculateDivederLocation(_splitPane.getOrientation(), true));
+ }
+ }
+ });
+
+ }
+
+ }
+
+
+ private void createSplitPaneAndSetSplitLocation()
+ {
+ final int spOrientation = getSession().getProperties().getSqlPanelOrientation();
+ _splitPane = new JSplitPane(spOrientation);
+
+ int dividerLoc = calculateDivederLocation(spOrientation, false);
+ _splitPane.setDividerLocation(dividerLoc);
+
+ /*
+ * Add a PropertyChangeListener for the SessionProperties for changing the orientation
+ * of the split pane, if the user change the settings.
+ */
+ getSession().getProperties().addPropertyChangeListener(new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ if(SessionProperties.IPropertyNames.SQL_PANEL_ORIENTATION.equals(evt.getPropertyName())){
+ saveOrientationDependingDividerLocation();
+ _splitPane.setOrientation((Integer) evt.getNewValue());
+ _splitPane.setDividerLocation(calculateDivederLocation(_splitPane.getOrientation(), false));
+ _splitPane.repaint();
+ }
+ }
+ });
+
+
+ /*
+ * Add a mouse event listener to the divider, so that we can reset the divider location when a doulbe click
+ * occurs on the divider.
+ */
+ SplitPaneUI spUI = _splitPane.getUI();
+ if (spUI instanceof BasicSplitPaneUI) {
+ BasicSplitPaneUI bspUI = (BasicSplitPaneUI) spUI;
+ bspUI.getDivider().addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
+ _splitPane.setDividerLocation(calculateDivederLocation(_splitPane.getOrientation(), true));
+ }
+ }
+ });
+
+ }
+
}
+ /**
+ * Calculates the divider location of the split pane, depending on a orientation.
+ * @param useDefault TODO
+ * @see #PREFS_KEY_SPLIT_DIVIDER_LOC
+ * @see #PREFS_KEY_SPLIT_DIVIDER_LOC_HORIZONTAL
+ */
+ private int calculateDivederLocation(int orientation, boolean useDefault) {
+ int dividerLoc;
+
+ // TODO Stefan: If createSplitPaneAndSetSplitLocation works, than there is no need for a default dimension, as the panel could not be null.
+
+ /*
+ * Parent size for calculating the default location.
+ * If the split pane isnt' initialized, assume a default dimension.
+ */
+ Dimension parentDim;
+
+ if(_splitPane != null){
+ parentDim = _splitPane.getSize();
+ }else{
+ parentDim = new Dimension(500,500);
+ }
+
+ if(orientation == JSplitPane.VERTICAL_SPLIT){
+ int def = parentDim.height-200;
+ if(useDefault == false){
+ dividerLoc = Preferences.userRoot().getInt(PREFS_KEY_SPLIT_DIVIDER_LOC, def);
+ }else{
+ dividerLoc = def;
+ }
+ }else{
+ int def = parentDim.width/2;
+ if(useDefault == false){
+ dividerLoc = Preferences.userRoot().getInt(PREFS_KEY_SPLIT_DIVIDER_LOC_HORIZONTAL, def);
+ }else{
+ dividerLoc = def;
+ }
+ }
+ return dividerLoc;
+
+ }
+
public Action getUndoAction()
{
return _undoHandler.getUndoAction();
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/GeneralSessionPropertiesPanel.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/GeneralSessionPropertiesPanel.java 2011-03-27 02:04:52 UTC (rev 6218)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/GeneralSessionPropertiesPanel.java 2011-03-27 19:58:47 UTC (rev 6219)
@@ -81,6 +81,8 @@
String DATA_TYPE1 = s_stringMgr.getString("generalSessionPropertiesPanel.dataTYpe1");
// i18n[generalSessionPropertiesPanel.dataTYpe2='General Preferences' window under the 'Data Type Controls' tab.]
String DATA_TYPE2 = s_stringMgr.getString("generalSessionPropertiesPanel.dataTYpe2");
+
+ String SQL_PANEL_ORIENTATION = s_stringMgr.getString("generalSessionPropertiesPanel.sqlPanelOrientation");
}
private SessionProperties _props;
@@ -152,6 +154,7 @@
private OutputTypeCombo _sqlResultsCmb = new OutputTypeCombo(true);
private JCheckBox _chkKeepTableLayoutOnRerun = new JCheckBox();
private OutputTypeCombo _tableContentsCmb = new OutputTypeCombo(true);
+ private SplitPaneOrientationCombo _splitPaneOrientationCmb = new SplitPaneOrientationCombo();
MyPanel()
{
@@ -223,6 +226,24 @@
_sqlResultsTabPlacementCmb.setSelectedIndex(0);
}
+ int splitPaneOrientation = props.getSqlPanelOrientation();
+
+
+ for (int i = 0, limit = _splitPaneOrientationCmb.getModel().getSize(); i < limit; ++i)
+ {
+ SplitPaneOrientation spo = (SplitPaneOrientation)_splitPaneOrientationCmb.getItemAt(i);
+ if (spo.getValue() == splitPaneOrientation)
+ {
+ _splitPaneOrientationCmb.setSelectedIndex(i);
+ break;
+ }
+ }
+ if (_splitPaneOrientationCmb.getSelectedIndex() == -1)
+ {
+ _splitPaneOrientationCmb.setSelectedIndex(0);
+ }
+
+
_metaDataCmb.selectClassName(props.getMetaDataOutputClassName());
_sqlResultsCmb.selectClassName(props.getSQLResultsOutputClassName());
_chkKeepTableLayoutOnRerun.setSelected(props.getKeepTableLayoutOnRerun());
@@ -248,6 +269,9 @@
tp = (TabPlacement)_sqlResultsTabPlacementCmb.getSelectedItem();
props.setSQLResultsTabPlacement(tp.getValue());
+
+ SplitPaneOrientation spOrientation = (SplitPaneOrientation) _splitPaneOrientationCmb.getSelectedItem();
+ props.setSqlPanelOrientation(spOrientation.getValue());
}
private void createGUI()
@@ -317,7 +341,17 @@
++gbc.gridx;
gbc.weightx = 0.5;
pnl.add(_sqlResultsTabPlacementCmb, gbc);
+
+ gbc.gridx = 0;
+ ++gbc.gridy;
+ pnl.add(new JLabel(GeneralSessionPropertiesPanelI18n.SQL_PANEL_ORIENTATION, SwingConstants.RIGHT), gbc);
+ ++gbc.gridx;
+ gbc.weightx = 0.5;
+ gbc.gridwidth=3;
+ pnl.add(_splitPaneOrientationCmb, gbc);
+
+
return pnl;
}
@@ -494,4 +528,40 @@
return ((OutputType) getSelectedItem()).getPanelClassName();
}
}
+
+ private static final class SplitPaneOrientation
+ {
+ static final SplitPaneOrientation HORIZONTAL = new SplitPaneOrientation(s_stringMgr.getString("generalPropertiesPanel.horizontal"), JSplitPane.HORIZONTAL_SPLIT);
+ static final SplitPaneOrientation VERTICAL = new SplitPaneOrientation(s_stringMgr.getString("generalPropertiesPanel.vertical"), JSplitPane.VERTICAL_SPLIT);
+
+ private final String _name;
+ private final int _value;
+
+ SplitPaneOrientation(String name, int value)
+ {
+ super();
+ _name = name;
+ _value = value;
+ }
+
+ public String toString()
+ {
+ return _name;
+ }
+
+ int getValue()
+ {
+ return _value;
+ }
+ }
+
+ private static final class SplitPaneOrientationCombo extends JComboBox
+ {
+ SplitPaneOrientationCombo()
+ {
+ super();
+ addItem(SplitPaneOrientation.VERTICAL);
+ addItem(SplitPaneOrientation.HORIZONTAL);
+ }
+ }
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionProperties.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionProperties.java 2011-03-27 02:04:52 UTC (rev 6218)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionProperties.java 2011-03-27 19:58:47 UTC (rev 6219)
@@ -21,6 +21,7 @@
import java.beans.PropertyChangeListener;
import java.io.Serializable;
+import javax.swing.JSplitPane;
import javax.swing.SwingConstants;
import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetViewerEditableTablePanel;
@@ -69,6 +70,7 @@
String LIMIT_SQL_ENTRY_HISTORY_SIZE = "limitSqlEntryHistorySize";
String LOAD_SCHEMAS_CATALOGS = "loadCatalogsSchemas";
String MAIN_TAB_PLACEMENT = "mainTabPlacement";
+ String SQL_PANEL_ORIENTATION = "sqlPanelOrientation";
String META_DATA_OUTPUT_CLASS_NAME = "metaDataOutputClassName";
String OBJECT_TAB_PLACEMENT = "objectTabPlacement";
String SQL_ENTRY_HISTORY_SIZE = "sqlEntryHistorySize";
@@ -187,6 +189,12 @@
*/
private int _sqlEntryHistorySize = 100;
+ /** Orientation of the split pane dividing sql entry area from result area
+ * @see JSplitPane#VERTICAL_SPLIT
+ * @see JSplitPane#HORIZONTAL_SPLIT
+ * */
+ private int _sqlPanelOrientation = JSplitPane.VERTICAL_SPLIT;
+
/** Placement of main tabs. See javax.swing.SwingConstants for valid values. */
private int _mainTabPlacement = SwingConstants.TOP;
@@ -812,6 +820,25 @@
oldValue, _sqlEntryHistorySize);
}
+
+ public int getSqlPanelOrientation()
+ {
+ return _sqlPanelOrientation;
+ }
+
+ public void setSqlPanelOrientation(int value)
+ {
+ if (_sqlPanelOrientation != value)
+ {
+ final int oldValue = _sqlPanelOrientation;
+ _sqlPanelOrientation = value;
+ getPropertyChangeReporter().firePropertyChange(
+ IPropertyNames.SQL_PANEL_ORIENTATION,
+ oldValue, _sqlPanelOrientation);
+ }
+ }
+
+
public int getMainTabPlacement()
{
return _mainTabPlacement;
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionPropertiesBeanInfo.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionPropertiesBeanInfo.java 2011-03-27 02:04:52 UTC (rev 6218)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/properties/SessionPropertiesBeanInfo.java 2011-03-27 19:58:47 UTC (rev 6219)
@@ -91,6 +91,8 @@
"getSQLExecutionTabPlacement", "setSQLExecutionTabPlacement"),
new PropertyDescriptor(IPropNames.SQL_RESULTS_TAB_PLACEMENT, SessionProperties.class,
"getSQLResultsTabPlacement", "setSQLResultsTabPlacement"),
+ new PropertyDescriptor(IPropNames.SQL_PANEL_ORIENTATION, SessionProperties.class,
+ "getSqlPanelOrientation", "setSqlPanelOrientation"),
new PropertyDescriptor(IPropNames.SQL_USE_FETCH_SIZE, SessionProperties.class,
"getSQLFetchSize", "setSQLFetchSize"),
new PropertyDescriptor(IPropNames.SQL_FETCH_SIZE, SessionProperties.class,
Modified: trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/session/properties/I18NStrings.properties
===================================================================
--- trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/session/properties/I18NStrings.properties 2011-03-27 02:04:52 UTC (rev 6218)
+++ trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/session/properties/I18NStrings.properties 2011-03-27 19:58:47 UTC (rev 6219)
@@ -50,6 +50,8 @@
generalPropertiesPanel.right=Right
generalPropertiesPanel.rows=rows
generalPropertiesPanel.top=Top
+generalPropertiesPanel.horizontal=Horizontal
+generalPropertiesPanel.vertical=Vertical
generalSessionPropertiesPanel.appearance=Appearance
generalSessionPropertiesPanel.dataTYpe1=Properties for the individual Data Types may be set in the
generalSessionPropertiesPanel.dataTYpe2='General Preferences' window under the 'Data Type Controls' tab.
@@ -64,6 +66,7 @@
generalSessionPropertiesPanel.sqlResults=SQL Results:
generalSessionPropertiesPanel.tableContents=Table Contents:
generalSessionPropertiesPanel.text=Text
+generalSessionPropertiesPanel.sqlPanelOrientation=SQL panel layout:
sessionObjectTreePropetiesPanel.filters=Filters
sessionPropertiesPanel.catalogPrefix=Limit Catalog Objects using these comma-delimited prefixes:
sessionPropertiesPanel.limitRowsContents=Contents - Limit rows
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2011-03-27 02:04:52 UTC (rev 6218)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2011-03-27 19:58:47 UTC (rev 6219)
@@ -7,6 +7,13 @@
Enhancements:
+Feature Request 3185630: SQL Panel layout:
+ - Squirrel uses a vertical layout for the SQL Panel. Now, this layout can be changed to horizontal,
+ which might be useful on wide screen displays. This can be configured within the
+ Session Properties and New Session Properties => Tab General => Combo Box: SQL Panel layout
+ - A double click on the divider restores the divider position to the default value.
+
+
Editing numeric values: Now, Squirrel has the same behavior for signed values for all different numeric data types.
A minus sign is allowed only at the first position and if the data type is signed.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|