You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Jiaojiao <fu...@gmail.com> on 2012/05/21 10:59:09 UTC

add Meter to TableView.column

Hi,
I want to add Meter to a TableView.column,I know I have to create a class
that extends Meter and implements TableView.CellRenderer. My question is in
this class after defined Meter how can I display it?There is an error if I
use "add(meter);" in the function:public void render(~~);
The second question is how can I reference this file in the BXML?
Thank you !

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: add Meter to TableView.column

Posted by Jiaojiao <fu...@gmail.com>.
Hi,
I know how to do now and sorry for boring you with such stupid question!

Bye

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544p4021895.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: add Meter to TableView.column

Posted by Jiaojiao <fu...@gmail.com>.
Hi Roger L,
I want to realize drag function in the TablePane.I get the files choosen
with FileList.How can I read every single file in the filelist and add the
name of the file to the TablePane.Row?I tried the sentences below:
     File[] file=null;
     file[0]=fileList.get(0);
Are they ok?Why can't my application work fine?
Thank you!

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544p4021885.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: add Meter to TableView.column

Posted by Jiaojiao <fu...@gmail.com>.
Hi Roger L,
Thank you for your advise.
This is on Windows and I didn't add the UTF-8 encoding specified in the bxml
file.However after adding it I still got the same error.
But I add the sentence below at the top of the bxml file and it's ok now.
     <?xml version="1.0"  encoding="gbk"?> 



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544p4020253.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: add Meter to TableView.column

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
Hi, can you check if the bxml file has the UTF-8 encoding specified (at the top of the file):
<?xml version="1.0" encoding="utf-8"?>
And then can you check if the characters are actually encoded as UTF-8 in the file (or if they are in one of the double-byte Chinese encodings)?

Is this on Windows or Linux or OSX?

Here is a little program that can read a file and check for a valid encoding.  To use it, do "javac CharsetCheck.java" then "java CharsetCheck filename" (you can use "java CharsetCheck -charsetname filename*" to specify another character set to use.

~Roger Whitcomb

CharsetCheck.java
-----------------
import java.io.*;
import java.nio.charset.*;


public class CharsetCheck
{
	private static Charset charset = null;


	private static void displayHelp() {
	    System.out.println("Usage: java CharsetCheck [-charset] file_name*");
	}

	public static void main(String[] args) {
	    if (args.length == 0) {
		displayHelp();
		return;
	    }
	    // Check for charset name
	    for (String arg : args) {
		String name = null;
		if (arg.startsWith("--")) {
		    name = arg.substring(2);
		}
		else if (arg.startsWith("-")) {
		    name = arg.substring(1);
		}
		if (name != null) {
		    try {
			charset = Charset.forName(name);
		    }
		    catch (IllegalCharsetNameException ex1) {
			System.err.format("Illegal charset name: '%1$s'%n", name);
		    }
		    catch (UnsupportedCharsetException ex2) {
			System.err.format("Unsupported charset: '%1$s'%n", name);
		    }
		}
	    }
	    // Use default charset of UTF-8 if none given
	    if (charset == null) {
		charset = Charset.forName("UTF-8");
	    }
	    // Now loop through all the files specified
	    for (String arg : args) {
		if (!arg.startsWith("-")) {
		    File file = new File(arg);
		    if (file.exists() && file.isFile() && file.canRead()) {
			long inputPos = 0L;
			InputStreamReader reader = null;
			int ch = 0;
			try {
			    FileInputStream fis = new FileInputStream(file);
			    CharsetDecoder decoder = charset.newDecoder();
			    decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
			    decoder.onMalformedInput(CodingErrorAction.REPORT);
			    reader = new InputStreamReader(fis, decoder);
			    while ((ch = reader.read()) != -1)
				inputPos++;
			    System.out.format("File '%1$s' appears to be correctly encoded in '%2$s' charset.%n", arg, charset.name());
			}
			catch (CharacterCodingException cce) {
			    System.out.format("Character coding exception: %1$s, previous character is '0x%2$x'%n  at offset 0x%3$x in file '%4$s'%n", cce.getMessage(), ch, inputPos+1, arg);
			}
			catch (IOException ioe) {
			    System.out.format("I/O exception: %1$s%n  at offset %2$d in file '%3$s'%n", ioe.getMessage(), inputPos, arg);
			}
			finally {
			    try {
				if (reader != null)
				    reader.close();
			    }
			    catch (IOException ignore) { }
			}
		    }
		    else {
			System.err.format("Cannot find or read the file '%1$s'!%n", arg);
		    }
		}
	    }
	}

}

-----Original Message-----
From: Jiaojiao [mailto:fujiaojiao1@gmail.com] 
Sent: Monday, May 28, 2012 8:32 PM
To: user@pivot.apache.org
Subject: Re: add Meter to TableView.column

Hi Sandro,
Thank you for your answer.
For adding Chinese contents in bxml files,I use sentences as follows:
     <ListButton bxml:id="listButton"  styles="{font:'SimSun 15'}"
	       listData="['电影', '电视剧', '综艺节目']"/>
But there is an ParseError:1bytes of UTF-8 sequence of bytes1 invalid.
Is there anything wrong?

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544p4020067.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: add Meter to TableView.column

Posted by Jiaojiao <fu...@gmail.com>.
Hi Sandro,
Thank you for your answer.
For adding Chinese contents in bxml files,I use sentences as follows:
     <ListButton bxml:id="listButton"  styles="{font:'SimSun 15'}"
	       listData="['电影', '电视剧', '综艺节目']"/>
But there is an ParseError:1bytes of UTF-8 sequence of bytes1 invalid.
Is there anything wrong?

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544p4020067.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: add Meter to TableView.column

Posted by Sandro Martini <sa...@gmail.com>.
Hi,

> I have too more questions now and need your help.
> Firstly,I want to add contents to ListButton and the contents are Chinese,How should I do?
A simple example (under Tutorials) is this:
http://pivot.apache.org/tutorials/list-buttons.html
that uses list_buttons.bxml , and related classes/other files.

The simplest test could be to change/add your content in bxml files
(but in Unicode format) and try to load it.
But important: remember to chose a Font that contains Chinese chars ...

> Secondly,how can I let the form's size change according to the contents?
A Form is a Container, so you can find some general Info on Pivot
Containers here:
http://pivot.apache.org/tutorials/component-and-container.html
Try to put if with relative sizing, and attention to parent containers.
Under tests you can find this: FormTest, could help you ...


Bye

Re: add Meter to TableView.column

Posted by Jiaojiao <fu...@gmail.com>.
Hi Sandro,
I have too more questions now and need your help.
Firstly,I want to add contents to ListButton and the contents are
Chinese,How should I do?
Secondly,how can I let the form's size change according to the contents?
Thank you!

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544p4019045.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: add Meter to TableView.column

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
sorry for the delay ...

> I rewrote the function TableViewFileRenderer() in the file TerraFileBrowserSkin.java,but I dont know how to refer to external java application in the .bxml file?
Why did you need to rewrite it ? Wouldn't it be better to write in a
your class, and use it (see bottom) ?
Or if useful, extend TerraFileBrowserSkin in your class, to have a
good starting point.

> In the example:File Drop Target Demo,there are sentences as follows:
>      <TableView.Column name="name" width="3*" headerData="File">
>               <cellRenderer>
>                      <terra:TerraFileBrowserSkin.TableViewFileRenderer/>
>               </cellRenderer>
>      </TableView.Column>
> What does this mean?
this means: use as a renderer an instance of the class
TerraFileBrowserSkin.TableViewFileRenderer (inner and public static
class), from the namespace defined in the package "terra" defined at
the beginning of that bxml file as:
    xmlns:terra="org.apache.pivot.wtk.skin.terra"

> When I add TerraFileBrowserSkin.java I've changed to the TableView.Column like this,I got an error:Property elements cannot have a namespace prefix.Why?
you have to write a full line like this:
<terra:TerraFileBrowserSkin.TableViewFileRenderer/>
because it's the right way (bxml-speaking ) to use
namespace:class.staticProperty

Remember, the "BXML Primer" is your (and our :-) ) friend:
http://pivot.apache.org/tutorials/bxml-primer.html
I read/re-read it often ...


Hope this helps,
Sandro

Re: add Meter to TableView.column

Posted by Jiaojiao <fu...@gmail.com>.
Hi Sandro,


Thank you for your answer.They are very useful.

I rewrote the function TableViewFileRenderer() in the file
TerraFileBrowserSkin.java,but I dont know how to refer to external java
application in the .bxml file?

In the example:File Drop Target Demo,there are sentences as follows:
      <TableView.Column name="name" width="3*" headerData="File">
               <cellRenderer>
                      <terra:TerraFileBrowserSkin.TableViewFileRenderer/>
               </cellRenderer>
      </TableView.Column>
What does this mean?When I add TerraFileBrowserSkin.java I've changed to the
TableView.Column like this,I got an error:Property elements cannot have a
namespace prefix.Why?
  


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/add-Meter-to-TableView-column-tp4004544p4014899.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: add Meter to TableView.column

Posted by Sandro Martini <sa...@gmail.com>.
Hi,

> I want to add Meter to a TableView.column,I know I have to create a class that extends Meter and implements TableView.CellRenderer.
sorry I haven't tried something like this, maybe you can find some
info in the following links:

http://apache-pivot-users.399431.n3.nabble.com/TableView-Custom-Rendered-td1757203.html

https://pivot.apache.org/2.0.1/docs/api/org/apache/pivot/wtk/class-use/Renderer.html


> My question is in this class after defined Meter how can I display it?There is an error if Iuse "add(meter);" in the function:public void render(~~);
as seen here:
https://pivot.apache.org/2.0.1/docs/api/org/apache/pivot/wtk/Renderer.html
Renderers are used to customize the appearance of a component's content.
you can't add components to it, you have to use it only to display contents.
I think the right way should be to add your component to the table
cell, and create a custom implementation of TableView.CellRenderer
(inside Pivot there are some for basic cases, like
TableViewCellRenderer for text labels) and from it read your component
data and display as required.
Of course with Meters you could have other Thread doing some work in
background, so pay attention even to this ...


> The second question is how can I reference this file in the BXML?
maybe this could help:
http://apache-pivot-users.399431.n3.nabble.com/pivot-lt-bxml-include-value-quot-abc-quot-gt-lt-bxml-include-src-quot-abc-js-quot-gt-td2240141.html


Working with custom components is an area in Pivot that probably we
should extend and for sure document better (I don't remember if we
have at least a sample), so if you have some suggestions/improvements,
tell us ...
For example an interesting thing could be try to package a custom
component (code and maybe even its bxml files) in a jar, and use it
from an application, if someone has done something like this, please
tell us ... or add an issue in jira for 2.1, could be an interesting
thing to show.


Keep us updated.

Sandro