Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Vertical Text in Columnheader(Vertical Text in Columnheader)
Vertical Text in Columnheader [message #915020] Sun, 16 September 2012 03:17 Go to next message
dhruba kumar is currently offline dhruba kumar
Messages: 40
Registered: September 2012
Member
Hi i want Label in COLUMNHEADER in nattable will be like this:


|-|------|
|C|Column|
|O|Name |
|L|and |
| |Text |
|1| |
--------------

can u pls give me some code to achieve this.

Re: Vertical Text in Columnheader [message #915375 is a reply to message #915020] Mon, 17 September 2012 02:52 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1067
Registered: July 2012
Senior Member
Sorry, I don't understand what your are trying to achieve.
Re: Vertical Text in Columnheader [message #915990 is a reply to message #915375] Tue, 18 September 2012 07:16 Go to previous messageGo to next message
dhruba kumar is currently offline dhruba kumar
Messages: 40
Registered: September 2012
Member
Sorry Dirk,
acctualy I want a table which have Two Columns and its columnheader text allign should be like this:
For First Column the ColumnHeader Text Allign is :
F
I
R
S
T

C
O
L

The secondColumn the ColumnHeader Text Allign is :
FIRST
COLUMN



Can u please give some code snipplet.
Re: Vertical Text in Columnheader [message #915994 is a reply to message #915990] Tue, 18 September 2012 07:27 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1067
Registered: July 2012
Senior Member
Ah ok, in fact I haven't ever tried to mix the TextPainters in ColumnHeader, but it should work.

You'll have to add a special label to to the cell in the first column of your column header. And then apply the VerticalTextPainter to that label via configuration.

http://eclipse.org/nattable/documentation.php?page=styling should help you on this.
Re: Vertical Text in Columnheader [message #916943 is a reply to message #915994] Wed, 19 September 2012 13:06 Go to previous messageGo to next message
dhruba kumar is currently offline dhruba kumar
Messages: 40
Registered: September 2012
Member
Hi Dirk, I ve used vertical textpainter but text is not showing like this
C
O
L

F
I
R
S
T

I ve also tried to Create own Painter ::


package myapp.mygrid2;

import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.AbstractTextPainter;
import net.sourceforge.nattable.painter.cell.GraphicsUtils;
import net.sourceforge.nattable.resize.command.ColumnResizeCommand;
import net.sourceforge.nattable.resize.command.RowResizeCommand;
import net.sourceforge.nattable.style.CellStyleUtil;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;

// Referenced classes of package net.sourceforge.nattable.painter.cell:
// AbstractTextPainter, GraphicsUtils

public class TextVerticalPainter extends AbstractTextPainter
{

public TextVerticalPainter()
{
this(false, true);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg)
{
this(wrapText, paintBg, 0);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg, int spacing)
{
this(wrapText, paintBg, spacing, false);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg, boolean calculate)
{
this(wrapText, paintBg, 0, calculate);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg, int spacing, boolean calculate)
{
super(wrapText, paintBg, spacing, calculate);
}

public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry)
{
setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry));
return gc.textExtent(convertDataType(cell, configRegistry)).x;
}

public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry)
{
setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry));
return getLengthFromCache(gc, convertDataType(cell, configRegistry)) + spacing * + 1;
}

public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry)
{
/*Paint cell Logic for Painting
C
O
L

T
X
T
*/

}

protected void setNewMinLength(LayerCell cell, int contentHeight)
{
int cellLength = cell.getBounds().height;
if(cellLength < contentHeight)
{
ILayer layer = cell.getLayer();
int row = layer.getRowIndexByPosition(cell.getRowPosition());
layer.doCommand(new RowResizeCommand(layer, row, contentHeight));
}
}

public String insertNewLine(String txt)
{
String newtxt="";
for(int i=0;i<txt.length();i++)
newtxt+=txt.charAt(i)+"\n";

return newtxt;

}

protected int calculatePadding(LayerCell cell, int availableLength)
{
return cell.getBounds().height - availableLength;
}
}

pls guide for the paint cell logic.




Re: Vertical Text in Columnheader [message #917520 is a reply to message #916943] Thu, 20 September 2012 02:51 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1067
Registered: July 2012
Senior Member
Oh ok, this is really special then. Sorry for missunderstanding. In this case I would suggest to use the TextPainter and before painting you should modify the text to show by adding a line break after each character. The TextPainter then needs to be created with the parameter calculate = true. This way the row height will be calculated.
Re: Vertical Text in Columnheader [message #917653 is a reply to message #917520] Thu, 20 September 2012 05:41 Go to previous messageGo to next message
dhruba kumar is currently offline dhruba kumar
Messages: 40
Registered: September 2012
Member
Hi Dirk Thanks I ve created custom Vertical Text Painter as per your advice

The code is:


import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.AbstractTextPainter;
import net.sourceforge.nattable.painter.cell.GraphicsUtils;
import net.sourceforge.nattable.resize.command.ColumnResizeCommand;
import net.sourceforge.nattable.resize.command.RowResizeCommand;
import net.sourceforge.nattable.style.CellStyleUtil;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;

// Referenced classes of package net.sourceforge.nattable.painter.cell:
// AbstractTextPainter, GraphicsUtils

public class TextVerticalPainter extends AbstractTextPainter
{

public TextVerticalPainter()
{
this(false, true);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg)
{
this(wrapText, paintBg, 0);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg, int spacing)
{
this(wrapText, paintBg, spacing, false);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg, boolean calculate)
{
this(wrapText, paintBg, 0, calculate);
}

public TextVerticalPainter(boolean wrapText, boolean paintBg, int spacing, boolean calculate)
{
super(wrapText, paintBg, spacing, calculate);
}

public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry)
{
setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry));
return gc.textExtent(/*insertNewLine*/(convertDataType(cell, configRegistry))).x;
}

public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry)
{
setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry));
return getLengthFromCache(gc, /*insertNewLine*/(convertDataType(cell, configRegistry))) + spacing * + 1;
}

public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry)
{
if(paintBg)
{
super.paintCell(cell, gc, rectangle, configRegistry);
}
// if(paintFg)
{
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
net.sourceforge.nattable.style.IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
int fontHeight = gc.getFontMetrics().getHeight();
String text = convertDataType(cell, configRegistry);
text = insertNewLine(getTextToDisplay(cell, gc, rectangle.width, text));
int numberOfNewLines = getNumberOfNewLines(text);
int contentHeight = fontHeight * numberOfNewLines;
int contentToCellDiff = cell.getBounds().height - rectangle.height;
if(contentHeight > rectangle.height && calculate)
{
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + spacing * 2 + contentToCellDiff));
}
if(numberOfNewLines == 1)
{
int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.width);
gc.drawText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth + spacing), rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight + spacing), 3);
} else
{
int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight);
String lines[] = text.split("\n");
String as[];
int j = (as = lines).length;
for(int i = 0; i < j; i++)
{
String line = as[i];
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.width);
gc.drawText(line, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth + spacing), yStartPos + spacing, 3);
yStartPos += fontHeight;
}

}
gc.setClipping(originalClipping);
}
}

protected void setNewMinLength(LayerCell cell, int contentHeight)
{
int cellLength = cell.getBounds().height;
if(cellLength < contentHeight)
{
ILayer layer = cell.getLayer();
int row = layer.getRowIndexByPosition(cell.getRowPosition());
layer.doCommand(new RowResizeCommand(layer, row, contentHeight));
}
}

public String insertNewLine(String txt)
{
String newtxt="";
for(int i=0;i<txt.length();i++)
newtxt+=txt.charAt(i)+"\n";

return newtxt;

}

protected int calculatePadding(LayerCell cell, int availableLength)
{
return cell.getBounds().height - availableLeng
th;
}
}



When Test this custom Painter with example TextPainter_example it works as my expectation.

But I am acctually using NattableBuilder Extension and when I use this with NattableBuilder ,the header only shows signgle character.
I am using this code:

rightbuilder = new NatTableBuilder(...);

ColumnHeaderLayer columnHeaderLayer= rightbuilder.getColumnHeaderLayerStack().getColumnHeaderLayer();


columnHeaderLayer.addConfiguration(new DefaultColumnHeaderLayerConfiguration() {
protected void addColumnHeaderStyleConfig() {
addConfiguration(new DefaultColumnHeaderStyleConfiguration() {
{
cellPainter = new BeveledBorderDecorator(new TextVerticalPainter(true,true,true));
}
});
}
});



pls help

Re: Vertical Text in Columnheader [message #917660 is a reply to message #917653] Thu, 20 September 2012 05:52 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1067
Registered: July 2012
Senior Member
Sorry, I haven't used the NatTableBuilder extension before. I assume you are adding the configuration to late in process and need to configure your text painter earlier. But unfortunately I can't give you detailed advice here.
Re: Vertical Text in Columnheader [message #931567 is a reply to message #917660] Wed, 03 October 2012 06:19 Go to previous messageGo to next message
dhruba kumar is currently offline dhruba kumar
Messages: 40
Registered: September 2012
Member
hi Dirk,
recently I ve moved from net.sourceforge to org.eclipse.nebula after taht all of my code is working properly ,but My custom Vertical Text is not working properly(header height is not increasing).Text is not showing vertically.Can u pls provide me the link for the source code of VerticalTextPainter and TextPainter and can u also mention the changes in the AbstractTextPainter that is causing problem
Re: Vertical Text in Columnheader [message #931607 is a reply to message #931567] Wed, 03 October 2012 06:52 Go to previous message
dhruba kumar is currently offline dhruba kumar
Messages: 40
Registered: September 2012
Member
Hi Now It is solved New AbstractTextPainter uses ILayer instead of Layer in all methods.
Previous Topic:NatTable 0.9.0 Release
Next Topic:NatTable TreeGridExample cell styling
Goto Forum:
  


Current Time: Thu Apr 24 14:59:54 EDT 2014

Powered by FUDForum. Page generated in 0.05201 seconds