Pages

about my opensource eclipse java applications recently i'm studying GWT and Android

Thursday, August 18, 2005

What is Insets?[GEF/Draw2D]


How many pixels inset a figure by a border on top,bottom,left and right.

Some layouts take care that value.
And I guess it help to know if a border was clicked.

Anyway,generally a border overdraw a figure in insets.



Maybe you could know if events happen inside a border like below.





public class MouseClicked extends MouseListener.Stub{

public void mousePressed(MouseEvent me) {
Figure figure=(Figure)me.getSource();
//I guess there are other better way.
if(figure.getBounds().contains(me.x,me.y) && !figure.getBounds().getCropped(figure.getInsets()).contains(me.x,me.y)){
shell.setText("click border");
}else{
shell.setText("click inside");
}
}

}

Thursday, August 11, 2005

like WaveFormGraph and zoom in and zoom out and stretch[GEF/Draw2D]


Of course my way is tricky.
But I don't know how to set different scale both width and height.
please see code anyway,it's difficult to explain how to do that.

In my program,I use ScaledPane and ToolbarLayout.
So It's easy zoom in and zoom out.
but When I wish fix height,I would do something.

In my code,I change my graph figure return 1x1 dimension everytime.
because on scaled changed,height length would be changed.

public Dimension getPreferredSize(int hintW,int hintH){
System.out.println(getParentScale());
if(horizontal){
//return new Dimension(values.length*space,maxValue-minValue);
//return new Dimension(values.length*space,(int)((maxValue-minValue)/getParentScale()));
return new Dimension(values.length*space,1);
}else{
return new Dimension(hintW,hintH);
}
}

Once you do that,it's ToolbarLayout and height would be stretched automatic.

Codes
ScaledToolbarLayoutTest.java
ScaledWavFormGraphTest.java

Tuesday, August 09, 2005

my Ecliipse RCP Application for Windows -akJ OptipngWrapper

















There are Optimizing PNG File Application - Optipng
And This is Optipng Wrapper Application.

In this application I didn't use draw2d yet.
It's simple Eclipse RCP Application.

It may work under Windows Platform.
If there were not .exe file.No one use this application.
I don't know how to support other platform.
And more it include command-line exe.

you can download this application from sourceforge.jp

And this is Opensource Application,
and you can see code cvs.sourceforge.jp
but be carefull,I didn't refactoring yet.

Monday, August 08, 2005

Scroll ScrollPane by MouseWheel [Draw2D]

Create class implement SelectionListener and write that.

public class WheelMove implements SelectionListener{

public void widgetSelected(SelectionEvent arg0) {
ScrollBar bar=scrollpane.getHorizontalScrollBar();
int direction=1;//16777218
if(arg0.detail==16777217){
direction=-1;
}
bar.setValue(bar.getValue()+direction*bar.getStepIncrement());

}
public void widgetDefaultSelected(SelectionEvent arg0) {
}
}

and get Real ScrollBar of FigureCanvas and add a addSelectionListener.

FigureCanvas canvas = new FigureCanvas(shell);
canvas.getVerticalBar().addSelectionListener(new WheelMove());

FullCode
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/akjrcp/draw2dexample/src/example/draw2d/NonOpaqueViewPort.java?rev=HEAD&content-type=text/vnd.viewcvs-markup

Change isOpaque() of ScrollPane [Draw2D]

Finaly,I upload sample codes to cvs.
see here
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/akjrcp/draw2dexample/src/example/draw2d/

I'm sorry,I don't have any way to know other platform results.
So I guess sometime on non-windows platrom it's didn't work correctly.

isOpaque methods of Scrollpane return always true.
but if you don't like it,overwrite it.

public class NoOpaqueScrollPane extends ScrollPane{
public boolean isOpaque(){
return false;
}
}


FullCode
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/akjrcp/draw2dexample/src/example/draw2d/NonOpaqueViewPort.java?rev=HEAD&content-type=text/vnd.viewcvs-markup

Sunday, August 07, 2005

Customize BorderLayout of Draw2D


If you customized BorderLayout.java ,you could do such things.

Certainly,If you overwrited getPreferedSize(),and you could do.
But If you did customize BorderLayout,You could control center figure of BorderLayout.
It's simple and usefull.

I copy from BorderLayout.java to CustomBorderLayout.java

and new field.
and create both of get and set methods.
private boolean stretchCenterWidth=true;
private boolean stretchCenterHeight=false;


and ,on layout() methods,
I replace code to when stretchCenter* is true,layoutmanager stretch figure width or height.
if(!stretchCenterHeight){
if (childSize.height <>
area.y += (area.height - childSize.height) / 2;
area.height = childSize.height;
}
}

if(!stretchCenterWidth){
if (childSize.width <>
area.x += (area.width - childSize.width) / 2;
area.width = childSize.width;
}
}
finally use call in your program like this.
CustomBorderLayout layout=new CustomBorderLayout(); layout.setStretchCenterWidth(true);
layout.setStretchCenterHeight(true);


FullCode
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/akjrcp/draw2dexample/src/example/draw2d/CustomBorderLayoutTest.java?rev=1.1&content-type=text/vnd.viewcvs-markup

Saturday, August 06, 2005

like transparent figure on Draw2D


In this here,I'd like to explain how to create like transparent figure.
but this way is only create 1x1 sized image which has alpha and draw fill bounds of figure.
So If you add figures insert this figure,it would never be transparent.

Although,If you add one more this way figure as shadow,It would be neat.

I use this tips in my Eclipse RCP Application;akJ Subplayer

-Example
In this example,add two AlphaLayerFigures.
---add first AlphaLayerFigure
On Constracter It send color and alpha(0-255) arugments.

AlphaLayerFigure figure1=new AlphaLayerFigure(ColorConstants.red,128);
figure1.setBounds(new Rectangle(0,0,100,100));
figure1.add(new Label("layer1"));
panel.add(figure1);
---add second AlphaLayerFigure
This code use FlowLayout to layout label to align left.

AlphaLayerFigure figure2=new AlphaLayerFigure(ColorConstants.orange,128);
figure2.setBounds(new Rectangle(5,5,100,100));
FlowLayout layout=new FlowLayout();
layout.setMajorAlignment(FlowLayout.ALIGN_RIGHTBOTTOM);
figure2.setLayoutManager(layout);
figure2.add(new Label("layer2"));
panel.add(figure2);
---AlphaLayerFigure
----Constracter
In Constracter,Palette was Created by a color argument.
And a image sized 1x1 was created by that Palette with alpha value.

public AlphaLayerFigure(Color color,int alpha){
super();
this.color=color;

PaletteData palette=new PaletteData(new RGB[]{color.getRGB()});
imageData = new ImageData(1,1,8,palette);
imageData.alpha=alpha;
imageData.setPixel(0,0,0);
layerImage = new Image(null,imageData);


}
---On Color Changed;setColor()
When color was changed,Image would be create again and paint.

this.color=color;
imageData.palette.colors[0]=color.getRGB();
if(layerImage!=null && !layerImage.isDisposed()){
layerImage.dispose();
}
layerImage=new Image(null,imageData);
repaint();
---On Alpah Changed;setAlpha()
Do same as color changed.

public void setAlpha(int alpha){

imageData.alpha=alpha;
if(layerImage!=null && !layerImage.isDisposed()){
layerImage.dispose();
}
layerImage=new Image(null,imageData);
repaint();
}

FullCode
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/akjrcp/draw2dexample/src/example/draw2d/AlphaTest.java?rev=1.1&content-type=text/vnd.viewcvs-markup

Friday, August 05, 2005

First Draw2D


You need draw2d.jar of GEF and swt.jar to run below program.


At first it's need to create FigureCanvas.
FigureCanvas connect Components and Figures.
Besides that there are LightweightSystem

FigureCanvas canvas = new FigureCanvas(shell);

Next ,it need to create Panel of Draw2D which is one of Figures. And set FlowLayout as Layout. On Draw2D figure is set as tree ,So it's need root Figure. And Method setContens() set root Figure .

Panel panel=new Panel(); panel.setLayoutManager(new FlowLayout(false)); canvas.setContents(panel);
Finally,it add labels of Draw2D. On Draw2D,there are no need to add a parent Figure argument,because it add a children figure to a parent Figure directly.

for(int i=0;i<3;i++){
Label label=new Label("draw2d "+i);
panel.add(label);


---
//all codes.

/*
* Created on 2005/07/28
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package example.draw2d;

import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Panel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
*
*
*/
public class Draw2DLabel {


public Draw2DLabel(Shell shell) {

shell.setBounds(0,0,150,150);
shell.setLayout(new FillLayout(SWT.VERTICAL));

FigureCanvas canvas = new FigureCanvas(shell);
Panel panel=new Panel();
panel.setLayoutManager(new FlowLayout(false));
canvas.setContents(panel);

for(int i=0;i<3;i++){
Label label=new Label("draw2d "+i);
panel.add(label);
}
}

public static void main(String[] args) {
Display display=new Display();
Shell shell=new Shell(display);


Draw2DLabel app=new Draw2DLabel(shell);


shell.open();

while(!shell.isDisposed()){
if (!display.readAndDispatch ()){
display.sleep ();
}
}
display.dispose();
}

}
}