Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Select Individual Table Cells (multiple columns)
Select Individual Table Cells (multiple columns) [message #439695] Wed, 14 July 2004 18:57 Go to next message
No real name is currently offline No real nameFriend
Messages: 13
Registered: July 2009
Junior Member
I have a file exploring frame, and I'm trying to implement a Small Icons
view. I have a table that creates columns to fit the screen and then I
place the number of columns worth of files into each TableItem. Basically,
it works fine, except that you can only select from the first column.
Is there any way to make each cell in the table selectable?

I've also played around with multiple tables to replace the columns, but
then the tables each have their own selection, and I have to place a
deselectAll() for the previously selected table in the selection listener
of newly selected Table, and there is a notable difference in behaviour as
both are selected until the mouse is released.

Any Suggestions?
TIA,
-Tej
Re: Select Individual Table Cells (multiple columns) [message #439973 is a reply to message #439695] Mon, 19 July 2004 20:50 Go to previous messageGo to next message
Jelle Herold is currently offline Jelle HeroldFriend
Messages: 42
Registered: July 2009
Member
Hi,

On 2004-07-14, Tej <swt.10.tej@spamgourmet.com> wrote:
> I have a file exploring frame, and I'm trying to implement a Small Icons
> view. I have a table that creates columns to fit the screen and then I
> place the number of columns worth of files into each TableItem. Basically,
> it works fine, except that you can only select from the first column.
> Is there any way to make each cell in the table selectable?
>
> I've also played around with multiple tables to replace the columns, but
> then the tables each have their own selection, and I have to place a
> deselectAll() for the previously selected table in the selection listener
> of newly selected Table, and there is a notable difference in behaviour as
> both are selected until the mouse is released.
>
> Any Suggestions?

You could use a custom layout manager that lays out labels with icons in
a grid. A nice example is the PlanLayout (www.quirk.co.za/resources/) by
Craig Raw.

I've modified it to do, euh, something. I think it was change the x/y
coordinate and fixed the size of each cell to a specific width/height.
Just in case it can be of any use, here is the source code:

---- PlanLayout.java ----

package tool;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.*;

/**
* PlanLayout is a simple layout manager that arranges widgets in columns
* and rows like a spreadsheet. All columns and rows are the same width
* and height respectively. A widget can be specified to span multiple rows
* or columns in its <code>PlanData</code> layout data object. A widget
* will be resized to fit into its allotted cells exactly.
* <p>
* The number of rows and columns can be set when <code>PlanLayout</code> is
* constructed. This can be later changed by assigning a new value and calling
* <code>layout()</code> on the <code>Composite</code>.
* </p>
* <p>
* The following code creates a 4 column by 5 row <code>PlanLayout</code> and
* adds two widgets to it:
* </p>
* <pre>
* public static void main( String args[] )
* {
* // Create a shell
* Display display = new Display();
* Shell shell = new Shell( display );
* <spc>
* PlanLayout layout = new PlanLayout( 4, 5 );
* shell.setLayout( layout );
* <spc>
* // Add some widgets
* Button btnTop = new Button( shell, SWT.NONE );
* btnTop.setLayoutData( new PlanData( 0, 0, 4, 1 ) );
* btnTop.setText( "Top" );
* Button btnLeft = new Button( shell, SWT.NONE );
* btnLeft.setLayoutData( new PlanData( 0, 1, 1, 4 ) );
* btnLeft.setText( "Left" );
* <spc>
* // Show the shell
* shell.setSize( 100, 150 );
* shell.open();
* <spc>
* while( !shell.isDisposed() )
* {
* if( !display.readAndDispatch( ) )
* {
* display.sleep();
* }
* }
* <spc>
* display.dispose();
* }
* </pre>
*
* @author Craig Raw
*
* @version 1.0
*/
public class PlanLayout extends Layout
{
public int unitWidth = 64;
public int unitHeight = 24;

/**
* Constructs an instance of PlanLayout. This PlanLayout will have
* a unitWidth of 64 and unitHeight of 24.
*/
public PlanLayout()
{

}

/**
* Constructs an instance of PlanLayout.
*
* @param unitWidth Width of a single unit in pixels
* @param unitHeight Height of a single unit in pixels
*/
public PlanLayout(int unitWidth, int unitHeight)
{
this.unitWidth = unitWidth;
this.unitHeight = unitHeight;
}

/**
* Computes and returns the size of the specified
* composite's client area according to this layout.
* <p>
* This method computes the minimum size that the
* client area of the composite must be in order to
* position all children at their minimum size inside
* the composite according to the layout algorithm
* encoded by this layout.
* </p>
* <p>
* When a width or height hint is supplied, it is
* used to constrain the result. For example, if a
* width hint is provided that is less than the minimum
* width of the client area, the layout may choose
* to wrap and increase height, clip, overlap, or
* otherwise constrain the children.
* </p>
*
* @param composite a composite widget using this layout
* @param wHint width (<code>SWT.DEFAULT</code> for minimum)
* @param hHint height (<code>SWT.DEFAULT</code> for minimum)
* @param flushCache <code>true</code> means flush cached layout values
* @return a point containing the computed size (width, height)
*
* @see "computeTrim, getClientArea for controls that implement them"
*/
protected Point computeSize(Composite composite, int wHint, int hHint,
boolean flushCache)
{
int width = 0;
int height = 0;

Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++)
{
PlanData data = (PlanData) children[i].getLayoutData();
width = Math.max(width, data.x + data.width);
height = Math.max(height, data.y + data.height);
}

return new Point(width * unitWidth, height * unitHeight);
}

/**
* Lays out the children of the specified composite
* according to this layout.
* <p>
* This method positions and sizes the children of a
* composite using the layout algorithm encoded by this
* layout. Children of the composite are positioned in
* the client area of the composite. The position of
* the composite is not altered by this method.
* </p>
* <p>
* When the flush cache hint is true, the layout is
* instructed to flush any cached values associated
* with the children. Typically, a layout will cache
* the preferred sizes of the children to avoid the
* expense of computing these values each time the
* widget is layed out.
* </p>
* <p>
* When layout is triggered explicitly by the programmer
* the flush cache hint is true. When layout is triggered
* by a resize, either caused by the programmer or by the
* user, the hint is false.
* </p>
*
* @param composite a composite widget using this layout
* @param flushCache <code>true</code> means flush cached layout values
*/
protected void layout(Composite composite, boolean flushCache)
{
final int cellWidth = unitWidth;//rectClient.width / numColumns;
final int cellHeight = unitHeight;//rectClient.height / numRows;

Control[] children = composite.getChildren();

for (int i = 0; i < children.length; i++)
{
PlanData data = (PlanData) children[i].getLayoutData();
if (data == null)
{
data = new PlanData();
children[i].setLayoutData(data);
}

int x = cellWidth * data.x;
int y = cellHeight * data.y;
int width = cellWidth * data.width;
int height = cellHeight * data.height;

children[i].setBounds(x, y, width, height);
}
}



protected void setPosition(PlanData pd, int x, int y)
{
pd.x = (x / unitWidth);
pd.y = (y / unitHeight);
}
}

Good luck,
Jelle
--
http://o2w.nl/~jelle/
http://defekt.nl/
Re: Select Individual Table Cells (multiple columns) [message #439997 is a reply to message #439973] Tue, 20 July 2004 13:04 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
You could probably get the same thing with either GridLayout or RowLayout.

"Jelle Herold" <jelle@defekt.nl> wrote in message
news:cdhc6t$9b7$1@eclipse.org...
> Hi,
>
> On 2004-07-14, Tej <swt.10.tej@spamgourmet.com> wrote:
> > I have a file exploring frame, and I'm trying to implement a Small Icons
> > view. I have a table that creates columns to fit the screen and then I
> > place the number of columns worth of files into each TableItem.
Basically,
> > it works fine, except that you can only select from the first column.
> > Is there any way to make each cell in the table selectable?
> >
> > I've also played around with multiple tables to replace the columns, but
> > then the tables each have their own selection, and I have to place a
> > deselectAll() for the previously selected table in the selection
listener
> > of newly selected Table, and there is a notable difference in behaviour
as
> > both are selected until the mouse is released.
> >
> > Any Suggestions?
>
> You could use a custom layout manager that lays out labels with icons in
> a grid. A nice example is the PlanLayout (www.quirk.co.za/resources/) by
> Craig Raw.
>
> I've modified it to do, euh, something. I think it was change the x/y
> coordinate and fixed the size of each cell to a specific width/height.
> Just in case it can be of any use, here is the source code:
>
> ---- PlanLayout.java ----
>
> package tool;
>
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.graphics.Rectangle;
> import org.eclipse.swt.widgets.*;
>
> /**
> * PlanLayout is a simple layout manager that arranges widgets in columns
> * and rows like a spreadsheet. All columns and rows are the same width
> * and height respectively. A widget can be specified to span multiple
rows
> * or columns in its <code>PlanData</code> layout data object. A widget
> * will be resized to fit into its allotted cells exactly.
> * <p>
> * The number of rows and columns can be set when <code>PlanLayout</code>
is
> * constructed. This can be later changed by assigning a new value and
calling
> * <code>layout()</code> on the <code>Composite</code>.
> * </p>
> * <p>
> * The following code creates a 4 column by 5 row <code>PlanLayout</code>
and
> * adds two widgets to it:
> * </p>
> * <pre>
> * public static void main( String args[] )
> * {
> * // Create a shell
> * Display display = new Display();
> * Shell shell = new Shell( display );
> * <spc>
> * PlanLayout layout = new PlanLayout( 4, 5 );
> * shell.setLayout( layout );
> * <spc>
> * // Add some widgets
> * Button btnTop = new Button( shell, SWT.NONE );
> * btnTop.setLayoutData( new PlanData( 0, 0, 4, 1 ) );
> * btnTop.setText( "Top" );
> * Button btnLeft = new Button( shell, SWT.NONE );
> * btnLeft.setLayoutData( new PlanData( 0, 1, 1, 4 ) );
> * btnLeft.setText( "Left" );
> * <spc>
> * // Show the shell
> * shell.setSize( 100, 150 );
> * shell.open();
> * <spc>
> * while( !shell.isDisposed() )
> * {
> * if( !display.readAndDispatch( ) )
> * {
> * display.sleep();
> * }
> * }
> * <spc>
> * display.dispose();
> * }
> * </pre>
> *
> * @author Craig Raw
> *
> * @version 1.0
> */
> public class PlanLayout extends Layout
> {
> public int unitWidth = 64;
> public int unitHeight = 24;
>
> /**
> * Constructs an instance of PlanLayout. This PlanLayout will have
> * a unitWidth of 64 and unitHeight of 24.
> */
> public PlanLayout()
> {
>
> }
>
> /**
> * Constructs an instance of PlanLayout.
> *
> * @param unitWidth Width of a single unit in pixels
> * @param unitHeight Height of a single unit in pixels
> */
> public PlanLayout(int unitWidth, int unitHeight)
> {
> this.unitWidth = unitWidth;
> this.unitHeight = unitHeight;
> }
>
> /**
> * Computes and returns the size of the specified
> * composite's client area according to this layout.
> * <p>
> * This method computes the minimum size that the
> * client area of the composite must be in order to
> * position all children at their minimum size inside
> * the composite according to the layout algorithm
> * encoded by this layout.
> * </p>
> * <p>
> * When a width or height hint is supplied, it is
> * used to constrain the result. For example, if a
> * width hint is provided that is less than the minimum
> * width of the client area, the layout may choose
> * to wrap and increase height, clip, overlap, or
> * otherwise constrain the children.
> * </p>
> *
> * @param composite a composite widget using this layout
> * @param wHint width (<code>SWT.DEFAULT</code> for minimum)
> * @param hHint height (<code>SWT.DEFAULT</code> for minimum)
> * @param flushCache <code>true</code> means flush cached layout values
> * @return a point containing the computed size (width, height)
> *
> * @see "computeTrim, getClientArea for controls that implement them"
> */
> protected Point computeSize(Composite composite, int wHint, int hHint,
> boolean flushCache)
> {
> int width = 0;
> int height = 0;
>
> Control[] children = composite.getChildren();
> for (int i = 0; i < children.length; i++)
> {
> PlanData data = (PlanData) children[i].getLayoutData();
> width = Math.max(width, data.x + data.width);
> height = Math.max(height, data.y + data.height);
> }
>
> return new Point(width * unitWidth, height * unitHeight);
> }
>
> /**
> * Lays out the children of the specified composite
> * according to this layout.
> * <p>
> * This method positions and sizes the children of a
> * composite using the layout algorithm encoded by this
> * layout. Children of the composite are positioned in
> * the client area of the composite. The position of
> * the composite is not altered by this method.
> * </p>
> * <p>
> * When the flush cache hint is true, the layout is
> * instructed to flush any cached values associated
> * with the children. Typically, a layout will cache
> * the preferred sizes of the children to avoid the
> * expense of computing these values each time the
> * widget is layed out.
> * </p>
> * <p>
> * When layout is triggered explicitly by the programmer
> * the flush cache hint is true. When layout is triggered
> * by a resize, either caused by the programmer or by the
> * user, the hint is false.
> * </p>
> *
> * @param composite a composite widget using this layout
> * @param flushCache <code>true</code> means flush cached layout values
> */
> protected void layout(Composite composite, boolean flushCache)
> {
> final int cellWidth = unitWidth;//rectClient.width / numColumns;
> final int cellHeight = unitHeight;//rectClient.height / numRows;
>
> Control[] children = composite.getChildren();
>
> for (int i = 0; i < children.length; i++)
> {
> PlanData data = (PlanData) children[i].getLayoutData();
> if (data == null)
> {
> data = new PlanData();
> children[i].setLayoutData(data);
> }
>
> int x = cellWidth * data.x;
> int y = cellHeight * data.y;
> int width = cellWidth * data.width;
> int height = cellHeight * data.height;
>
> children[i].setBounds(x, y, width, height);
> }
> }
>
>
>
> protected void setPosition(PlanData pd, int x, int y)
> {
> pd.x = (x / unitWidth);
> pd.y = (y / unitHeight);
> }
> }
>
> Good luck,
> Jelle
> --
> http://o2w.nl/~jelle/
> http://defekt.nl/
Previous Topic:Word MenuItems disabled (Headers/Footers)
Next Topic:Modifying an in memory bitmap ...
Goto Forum:
  


Current Time: Thu Apr 25 04:35:48 GMT 2024

Powered by FUDForum. Page generated in 0.03051 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top