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();
}

}
}

Tuesday, June 07, 2005

akj Speechtools 1.1

I release new verion akJ Speechtools 1.1
This is Eclipse RCP Application which can speech.
it can both speech both English & Japanese.
it use FreeTTS & Mbrola & Gtalk(Japanese Voice).

You can download from here.
https://sourceforge.jp/projects/akjrcp/files/?release_id=15055#15055

Wednesday, March 30, 2005

how to wrap on and off Text Widget

I don't know is this a best way .

simply rebuild text widget.
keep text and selection.
----
public void createPartControl(Composite parent) {

textArea = new Text(parent,SWT.MULTI|SWT.V_SCROLL|SWT.H_SCROLL);

}

public void setWrap(boolean bool){
Composite parent=textArea.getParent();
String text=textArea.getText();
Point pt=textArea.getSelection();
textArea.dispose();
int style=SWT.H_SCROLL;
if(bool){
style=SWT.WRAP;
}
textArea = new Text(parent,SWT.MULTI|SWT.V_SCROLL|style);
textArea.setText(text);
textArea.setSelection(pt);

parent.layout();

on windows these character cant' use

on windows these character cant' use
public static char[] NON_FILENAME={'\\','/',':','*','?','<','>','|'};
and sample codes.
/*
* Created on 2005/03/31
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.rcp.speech.wizards;

import java.util.HashMap;

import java.io.IOException;

/**
*
*
*/
public class FileNameUtils {
public static char[] NON_FILENAME={'\\','/',':','*','?','<','>','|'};
public static String replaceNonFileName(String base,String replaceText,int maxlength){
StringBuffer result=new StringBuffer();
for(int i=0;i if(isNonFileNameChar(base.charAt(i))){
result.append(replaceText);
}else{
result.append(base.charAt(i));
}
}
return result.toString();
}
public static boolean isNonFileNameChar(char ch){
for (int i = 0; i < NON_FILENAME.length; i++) {
if(NON_FILENAME[i]==ch){
return true;
}
}
return false;
}

public static String[] avoidSameName(String filenames[],String[] otherNames) throws IOException{
int max=999999;
String result[]=new String[filenames.length];
HashMap map=new HashMap();
if(otherNames!=null){
for (int i = 0; i < otherNames.length; i++) {
map.put(otherNames[i],"");
}
}
for (int i = 0; i < result.length; i++) {

String newname=filenames[i];
int last=filenames[i].lastIndexOf(".");
String head=null;
String foot=null;
if(last!=-1){
head=filenames[i].substring(0,last);
foot=filenames[i].substring(last);
}else{
head=filenames[i];
foot="";
}

int sx=1;
while(map.get(newname)!=null){
newname=head+"_"+sx+foot;
sx++;
if(sx>max){
throw new IOException("can't filename renamed");
}
}
result[i]=newname;
map.put(newname,"");

}
return result;
}


}

Sunday, March 13, 2005

akj speechtools

today i upload my eclipse rcp speech tools.
http://sourceforge.jp/projects/akjrcp/files/?release_id=13713#13713

this is simply wrapped freetts & mbrola.

try it!

Saturday, March 12, 2005

create account in sourceforge.jp

If it was possible i'd like to create project at sourceforge.net.
but my project was rejected.and becouse of my poor enligh skills, i can't explain my projects.

any way.
check my site http://sourceforge.jp/projects/akjrcp/

Friday, March 11, 2005

how to change your eclipse rcp application's title and icon

if you hurry anyway,you can do that.

public class OptipngWrapperWorkbenchAdvisor extends WorkbenchAdvisor{

public void postWindowOpen(IWorkbenchWindowConfigurer configurer) {
configurer.setTitle(Messages.getString("optipng_title"));
Image logoImage=ImageDescriptor.createFromURL(OptipngWrapperPlugin.getDefault().find(new Path("icons/akj_eclipse.png"))).createImage(); //$NON-NLS-1$
configurer.getWindow().getShell().setImage(logoImage);
}

}

but this approach has problem. selected icon isn't deliverd to other shell (Help or Updates)
that's not so important thing.

but I recomend you use product extension point.
more detail see
http://eclipse.org/articles/Article-Branding/branding-your-application.html
<extension
id="product"
point="org.eclipse.core.runtime.products">
<product name="akJ Speech Tools"
application="org.jpn.xucker.rcp.speech.SpeechApplication"
>
<property name="windowImage" value="icons/akj.png"/>
</product>
</extension>

Thursday, March 10, 2005

How to IAction Disable or Enable

when you something action.you hope disable other action.
at first i didn't found them. finally i found that.
I don't know ,is that right?
but i use that code.
you call this method from view,or change 'this'.
on id-String .use Action ID.
private void setEnabled(boolean bool,String id){
IContributionItem ic=this.getViewSite().getActionBars().getToolBarManager().find(id);
if(ic!=null && ic instanceof ActionContributionItem){
IAction iaction=((ActionContributionItem)ic).getAction();
iaction.setEnabled(bool);
}
}

Wednesday, March 09, 2005

Open Editor on Eclipse RCP

see that samples.
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-text-home/development/rcp/examples/index.html

that's difficult.
even in open text files,i should create some classes.
and now I'dont know how to use other editor plugin.
when i open file.
it coused that error
org.eclipse.ui.PartInitException: Text editor does not have a document provider

maybe on 3.1,that become more easy.

give up handle moving view.

on Eclipse 3.01 Windows XP

I don't know how to handle movable views,and
I give up using them.

I choose 2 rules.
Rule 1.Never use folder.
Rule 2.Use setFixed(true) when use setEditorAreaVisible(false)

why folder is movable.
and folder can't back window.

when use setEditorAreaVisible(false) and all views go out,
view didn't come back alone.
maybe everyuser panic that.

Tuesday, March 08, 2005

Today I try to add preferences my application.
that is something easy.

if you wish use preferences. call that.

PreferenceManager m=PlatformUI.getWorkbench().getPreferenceManager();

PreferenceDialog dialog=new PreferenceDialog(window.getShell(),m);

dialog.open();

off course you should create preference extentions(org.eclipse.ui.preferencePages).


Saturday, March 05, 2005

try Eclipse UpdateManager

Today I try to implement UpdateManager.
I see the Update Sites of Eclipse Help.
and I create Feature Project and Update Site Project.
I confused version and other,but finnlay I succede.

but there are problem.if i use UpdateManagerUI.openInstaller(),
include too many other plugins. and my application became really fat size.

so i'd like to release my application as zip archive files.

my first eclipse rcp application (ak Optipng wrapper)

hello
this is my first eclipse rcp applicaltion.
http://www.xucker.jpn.org/product/akjoptipngwrapper.zip

this optimize png file size by calling the optipng which is command-line application.
soon i'd like to show source code,please wait finish to refactoring.

JSmooth example for Eclipse RCP

if you don't know how to use NSIS like me and you know how to use JSmooth,
maybe it's is userful for you.
You msut change applicationclass and exe-name.
---------



registry
javahome
jrepath
jdkpath
exepath
jview
-application org.jpn.xucker.rcp.optipngwrapper.OptipngWrapperApplication %*
startup.jar
.
false
akjoptipngwrapper.exe
icon.png
-1
org.eclipse.core.launcher.Main
-1


Windowed Wrapper

Message
Need Install Java


URL
http://www.java.com/


SingleProcess
0


Debug
0

how to get plugin dir on Eclipse RCP?

finally i choose that aproach.i don't that is best way.

public File toPluginDir(Plugin plugin){
return new File(Platform.getInstallLocation().getURL().getPath(),
"plugins/"
+plugin.getBundle().getSymbolicName()
+"_"
+plugin.getBundle().getHeaders().get("Bundle-Version"));
}

it's too difficult for me handle the Bundle Class.
it's sample of bundle.getHeaders() values.

Bundle-ClassPath='rcp_optipngwrapper.jar'
Bundle-Name='akJ OptipngWrapper Plug-in'
Bundle-Version='1.0.2'
Bundle-Localization='plugin'
Generated-from='1110021669453;type=2'
Bundle-SymbolicName='org.jpn.xucker.rcp.optipngwrapper; singleton=true'
Require-Bundle='org.jpn.xucker.commons,
org.eclipse.ui,
org.eclipse.core.runtime'
Bundle-Activator='org.jpn.xucker.rcp.optipngwrapper.OptipngWrapperPlugin'
Eclipse-AutoStart='true'
Bundle-Vendor='www.xucker.jpn.org'
Manifest-Version='1.0'
Provide-Package='org.jpn.xucker.rcp.optipngwrapper,
org.jpn.xucker.optipngwrapper'

Tuesday, March 01, 2005

Free Culture Srt-Sub File

Today I created srt-sub file from Free Culture Audio book.

now it's only 1 files.
but one day i'd like to create all file and post there

sample
-----
1
00:00:01,560 --> 00:00:03,670
At the end of his review of my first book

2
00:00:03,710 --> 00:00:05,690
Code: And Other Laws of Cyberspace
----

download from here
this works licensed under
Attribution-NonCommercial 2.0 Japan
http://creativecommons.org/licenses/by-nc/2.0/jp/

Monday, February 21, 2005

Test tritunus MP3Encocer


Today I test tritunus MP3Encocer,
http://www.tritonus.org/plugins.html (tritonus-mp3enc-2001-04-25.zip)
becouse i'd like to make converting wav to mp3 program.

it's successed.
if you carefull to dont't forget to contain lame_enc.dll and lametritonus.dll in classpath,
it is an easy work.

of cource i think calling lame.exe from commandline is simple way. You dont't think? :)
but maybe i think implementing some lame-args is hard work.
it's easy to use Tritunus MP3Encoder.

either using lame.exe or lame_enc.dll.
the users must install Lame munually.
We should create a manual which contain how to download Lame. Posted by Hello

my code

Hello ,I'm Aki.
Today I start my java log.

my codes are uploaded here.

Currently I create SWT-based applications.but I'd like to change them to Eclipse-RCP based applications.


one of my favorite sweet. Posted by Hello