Revision: 6630
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6630&view=rev
Author: gerdwagner
Date: 2012-06-07 20:39:24 +0000 (Thu, 07 Jun 2012)
Log Message:
-----------
Graph Plugin: Tables can be selected by rectangle selection like icons on a desktop of modern operating systems.
Modified Paths:
--------------
trunk/sql12/doc/src/main/resources/changes.txt
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/DataSetViewerTablePanel.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopPane.java
Added Paths:
-----------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionHandler.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionListener.java
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2012-05-28 22:19:35 UTC (rev 6629)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2012-06-07 20:39:24 UTC (rev 6630)
@@ -9,6 +9,8 @@
Enhancements:
+Graph Plugin: Tables can be selected by rectangle selection like icons on a desktop of modern operating systems.
+
SQL Execution: The execution panel that is displayed while an SQL statement is being processed is now closeable.
Before the panel is closed the cancel action gets executed.
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/DataSetViewerTablePanel.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/DataSetViewerTablePanel.java 2012-05-28 22:19:35 UTC (rev 6629)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/datasetviewer/DataSetViewerTablePanel.java 2012-06-07 20:39:24 UTC (rev 6630)
@@ -28,7 +28,6 @@
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionAdapter;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
@@ -45,6 +44,7 @@
import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.CellComponentFactory;
import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.RestorableJTextField;
import net.sourceforge.squirrel_sql.fw.gui.ButtonTableHeader;
+import net.sourceforge.squirrel_sql.fw.gui.RectangleSelectionHandler;
import net.sourceforge.squirrel_sql.fw.gui.SortableTableModel;
import net.sourceforge.squirrel_sql.fw.gui.TablePopupMenu;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
@@ -251,8 +251,8 @@
private TablePopupMenu _tablePopupMenu;
private IDataSetTableControls _creator;
- private Point _dragBeginPoint = null;
- private Point _dragEndPoint = null;
+
+ private RectangleSelectionHandler _rectangleSelectionHandler = new RectangleSelectionHandler(this);
private RowNumberTableColumn _rntc;
private ButtonTableHeader _tableHeader = new ButtonTableHeader();
@@ -284,58 +284,14 @@
* to move through cells.
*/
- addMouseListener(new MouseAdapter()
- {
- public void mousePressed(MouseEvent e)
- {
- _dragBeginPoint = e.getPoint();
- }
- public void mouseReleased(MouseEvent e)
- {
- _dragBeginPoint = null;
- _dragEndPoint = null;
- repaint();
- }
- });
-
- addMouseMotionListener(new MouseMotionAdapter()
- {
- public void mouseDragged(MouseEvent e)
- {
- onMouseDragged(e);
- repaint();
- }
- });
-
}
- private void onMouseDragged(MouseEvent e)
- {
- if(null == _dragBeginPoint)
- {
- _dragBeginPoint = e.getPoint();
- }
- _dragEndPoint = e.getPoint();
- }
-
public void paint(Graphics g)
{
super.paint(g);
-
- if(null != _dragBeginPoint && null != _dragEndPoint && false == _dragBeginPoint.equals(_dragEndPoint))
- {
- int x = Math.min(_dragBeginPoint.x, _dragEndPoint.x);
- int y = Math.min(_dragBeginPoint.y, _dragEndPoint.y);
- int width = Math.abs(_dragBeginPoint.x - _dragEndPoint.x);
- int heigh = Math.abs(_dragBeginPoint.y - _dragEndPoint.y);
-
- Color colBuf = g.getColor();
- g.setColor(getForeground());
- g.drawRect(x,y,width,heigh);
- g.setColor(colBuf);
- }
+ _rectangleSelectionHandler.paintRectWhenNeeded(g);
}
public IDataSetTableControls getCreator() {
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionHandler.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionHandler.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionHandler.java 2012-06-07 20:39:24 UTC (rev 6630)
@@ -0,0 +1,114 @@
+package net.sourceforge.squirrel_sql.fw.gui;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+
+public class RectangleSelectionHandler
+{
+ private JComponent _comp;
+ private Point _dragBeginPoint = null;
+ private Point _dragEndPoint = null;
+ private RectangleSelectionListener _rectangleSelectionListener;
+
+
+ public RectangleSelectionHandler(JComponent comp)
+ {
+ setComponent(comp);
+ }
+
+ public RectangleSelectionHandler()
+ {
+ }
+
+ private void onMouseDragged(MouseEvent e)
+ {
+ if(null == _dragBeginPoint )
+ {
+ initBeginPoint(e);
+ }
+
+ _dragEndPoint = e.getPoint();
+
+ _comp.repaint();
+
+ }
+
+ /**
+ * Call this method from your component's paint method.
+ */
+ public void paintRectWhenNeeded(Graphics g)
+ {
+ if(null != _dragBeginPoint && null != _dragEndPoint && false == _dragBeginPoint.equals(_dragEndPoint))
+ {
+ int x = Math.min(_dragBeginPoint.x, _dragEndPoint.x);
+ int y = Math.min(_dragBeginPoint.y, _dragEndPoint.y);
+ int width = Math.abs(_dragBeginPoint.x - _dragEndPoint.x);
+ int heigh = Math.abs(_dragBeginPoint.y - _dragEndPoint.y);
+
+ Color colBuf = g.getColor();
+ g.setColor(_comp.getForeground());
+ g.drawRect(x,y,width,heigh);
+ g.setColor(colBuf);
+ }
+ }
+
+ public void setComponent(JComponent comp)
+ {
+ _comp = comp;
+
+ _comp.addMouseListener(new MouseAdapter()
+ {
+ public void mousePressed(MouseEvent e)
+ {
+ initBeginPoint(e);
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ onMouseReleased();
+ }
+ });
+
+ _comp.addMouseMotionListener(new MouseMotionAdapter()
+ {
+ public void mouseDragged(MouseEvent e)
+ {
+ onMouseDragged(e);
+ }
+ });
+ }
+
+ private void onMouseReleased()
+ {
+ if (null != _rectangleSelectionListener && null != _dragBeginPoint && null != _dragEndPoint)
+ {
+ _rectangleSelectionListener.rectSelected(_dragBeginPoint, _dragEndPoint);
+ }
+ _dragBeginPoint = null;
+ _dragEndPoint = null;
+ _comp.repaint();
+ }
+
+ private void initBeginPoint(MouseEvent e)
+ {
+ if (InputEvent.BUTTON1_MASK == e.getModifiers() && 0 == (e.getModifiers() & MouseEvent.CTRL_MASK))
+ {
+ _dragBeginPoint = e.getPoint();
+ }
+ }
+
+ public void setRectangleSelectionListener(RectangleSelectionListener rectangleSelectionListener)
+ {
+ _rectangleSelectionListener = rectangleSelectionListener;
+ }
+
+ public static boolean rectHit(Rectangle bounds, Point p1, Point p2)
+ {
+ Rectangle selRect = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p1.x - p2.x), Math.abs(p1.y - p2.y));
+ return bounds.intersects(selRect);
+ }
+}
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionListener.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionListener.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/RectangleSelectionListener.java 2012-06-07 20:39:24 UTC (rev 6630)
@@ -0,0 +1,8 @@
+package net.sourceforge.squirrel_sql.fw.gui;
+
+import java.awt.*;
+
+public interface RectangleSelectionListener
+{
+ void rectSelected(Point dragBeginPoint, Point dragEndPoint);
+}
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java 2012-05-28 22:19:35 UTC (rev 6629)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java 2012-06-07 20:39:24 UTC (rev 6630)
@@ -2,6 +2,8 @@
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeDndTransfer;
+import net.sourceforge.squirrel_sql.fw.gui.RectangleSelectionHandler;
+import net.sourceforge.squirrel_sql.fw.gui.RectangleSelectionListener;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
@@ -66,6 +68,7 @@
private JMenuItem _mnuAllFilteredSelectedOrder;
private GraphPluginResources _graphPluginResources;
private GraphControllerPopupListener _currentGraphControllerPopupListener;
+ private final RectangleSelectionHandler _rectangleSelectionHandler = new RectangleSelectionHandler();
public GraphDesktopController(GraphDesktopListener listener, ISession session, GraphPlugin plugin, ModeManager modeManager, boolean showDndDesktopImageAtStartup)
@@ -82,7 +85,17 @@
startUpImage = _graphPluginResources.getIcon(GraphPluginResources.IKeys.DND);
}
- _desktopPane = new GraphDesktopPane(_session.getApplication(), startUpImage);
+ _desktopPane = new GraphDesktopPane(_session.getApplication(), startUpImage, _rectangleSelectionHandler);
+ _rectangleSelectionHandler.setComponent(_desktopPane);
+
+ _rectangleSelectionHandler.setRectangleSelectionListener(new RectangleSelectionListener(){
+ @Override
+ public void rectSelected(Point dragBeginPoint, Point dragEndPoint)
+ {
+ onRectSelected(dragBeginPoint, dragEndPoint);
+ }
+ });
+
_desktopPane.setBackground(Color.white);
_modeManager = modeManager;
@@ -518,6 +531,18 @@
}
}
+ private void onRectSelected(Point dragBeginPoint, Point dragEndPoint)
+ {
+ for (JInternalFrame f : _desktopPane.getAllFrames())
+ {
+ if (f instanceof TableFrame && RectangleSelectionHandler.rectHit(f.getBounds(), dragBeginPoint, dragEndPoint))
+ {
+ _desktopPane.addGroupFrame((TableFrame) f);
+ }
+ }
+ }
+
+
private void onSelectTablesByName()
{
String namePattern=JOptionPane.showInputDialog(_desktopPane, s_stringMgr.getString("graph.selectTablesByName.message"), s_stringMgr.getString("graph.selectTablesByName.title"), JOptionPane.QUESTION_MESSAGE);
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopPane.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopPane.java 2012-05-28 22:19:35 UTC (rev 6629)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopPane.java 2012-06-07 20:39:24 UTC (rev 6630)
@@ -21,6 +21,7 @@
import net.sourceforge.squirrel_sql.client.IApplication;
import net.sourceforge.squirrel_sql.client.gui.desktopcontainer.ScrollableDesktopPane;
+import net.sourceforge.squirrel_sql.fw.gui.RectangleSelectionHandler;
public class GraphDesktopPane extends ScrollableDesktopPane implements GraphPrintable
@@ -33,6 +34,7 @@
private transient Set<TableFrame> _groupFrames = new HashSet<TableFrame>();
/////////////////////////////////////////////////////////
+ private RectangleSelectionHandler _rectangleSelectionHandler;
/////////////////////////////////////////////////////////
// Printing
private double _formatWidthInPixel;
@@ -44,7 +46,7 @@
//
/////////////////////////////////////////////////////////
- public GraphDesktopPane(IApplication app, ImageIcon desktopImage)
+ public GraphDesktopPane(IApplication app, ImageIcon desktopImage, RectangleSelectionHandler rectangleSelectionHandler)
{
super(app);
@@ -77,6 +79,7 @@
});
/////////////////////////////////////////////////////////
+ _rectangleSelectionHandler = rectangleSelectionHandler;
}
@@ -140,6 +143,9 @@
paintGraphComponents(g);
super.paintChildren(g);
+
+ _rectangleSelectionHandler.paintRectWhenNeeded(g);
+
}
private void paintStartupImage(Graphics g)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|