Need help to open a subchart from a main chart? - java

I have the following chart:
Now my problem is I want to open a new chart containing the information for Linux OS when a user clicks on Linux portion of chart, shown in red. I have tried this:
//check if Linux OS is clicked on chart...
if("Linux".equals(chartMouseEvent.getEntity().getToolTipText()))
{
//open new chart having the information for Linux
}
But I think there may be some better alternate to do the same job.
So please help if you know how to achieve this.

ChartEntity is a good choice, but getToolTipText() is not the only resource available. The getURLText() method is also handy, using the information provided by the StandardPieURLGenerator. Alternatively, a custom implementation of PieURLGenerator can access the data set directly:
plot.setURLGenerator(new PieURLGenerator() {
public String generateURL(PieDataset dataset, Comparable key, int pieIndex) {
// access the dataset as required
}
});

Related

Create java applications with MacBook Pro touchbar support?

as the tile describe, I would love to have the ability to add some cool touchbar buttons to my java application for MacBook Pro 2016 users.. I've not seen yet if there is a way to implement it in java yet.
Anyone got some knowledge on that?
There is a new Java library for interacting with the NSTouchBar API called JTouchBar.
For example using SWT
Shell shell = ...
JTouchBar jTouchBar = new JTouchBar();
jTouchBar.setCustomizationIdentifier("MySWTJavaTouchBar");
// flexible space
jTouchBar.addItem(new TouchBarItem(TouchBarItem.NSTouchBarItemIdentifierFlexibleSpace));
// button
TouchBarButton touchBarButtonImg = new TouchBarButton();
touchBarButtonImg.setTitle("Button 1");
touchBarButtonImg.setAction(new TouchBarViewAction() {
#Override
public void onCall( TouchBarView view ) {
System.out.println("Clicked Button_1.");
}
});
Image image = new Image();
img.setName(ImageName.NSImageNameTouchBarColorPickerFill);
touchBarButtonImg.setImage(image);
jTouchBar.addItem(new TouchBarItem("Button_1", touchBarButtonImg, true));
// label
TouchBarTextField touchBarTextField = new TouchBarTextField();
touchBarTextField.setStringValue("TextField 1");
jTouchBar.addItem(new TouchBarItem("TextField_1", touchBarTextField, true));
// enable touchbar
jTouchBar.enableForShell(shell);
You can find the library on Github:
https://github.com/Thizzer/JTouchBar
By the looks of it, apple doesn't provide support for adding items to the touch bar, never mind doing it in java.
While going through some documentation for the touch bar, it would appear that you will also need an instance of the NSTouchBarItem class. Java doesn't have that, nor provide a way to get that. I doubt that using native methods would work as well, seeing how the instance is app specific and is passed to the application through apple.
Accessing the bar is possible, but only natively.

JAVA gwt - saving info after refreshing page

At the moment , im working with java gwt and i stopped studdenly because one problem occured. I want that my information (for example string) will save after refresh button is clicked.
// user enters something in TextArea textArea1 object
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(Window.ClosingEvent closingEvent) {
//maybe there is a function or what
pleaseSaveInfomation(textArea1);
}
});
I tried this , but i know how to implement it correctly to my source code:
https://stackoverflow.com/a/14220746/5010218
The last(worst) chance is to store data from textArea in file.txt , after refreshing i could read info from file and thats all. But maybe GWT has a specific handler/method/class or what to handle this.
Thats for your opinion and help.
I had the same problem. You can easily overcome it with this.
import com.google.gwt.storage.client.Storage;
private Storage stockStore = null;
stockStore = Storage.getLocalStorageIfSupported();
Please read documentation
http://www.gwtproject.org/doc/latest/DevGuideHtml5Storage.html#UsingStorage
When a browser close a window (because of a refresh, or the user has closed the window, changed the url, etc), a script is not allowed to prevent this action. It's not specific to GWT.
However, you can suggest to the browser-agent to show a confirmation to the user. You can do this with the message property of the closing event.
In GWT:
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(Window.ClosingEvent closingEvent) {
closingEvent.setMessage("Confirm ?");
}
});
You shouldn't rely on this event to store your data, as a lot of condition can prevent you to do this. You should maybe periodically store a draft to the local-storage or to the server.
You probably want to store your data in sessionStorage. In GWT, this the Storage class.

PathMustExists and FileMustExists in SWT FileDialog

To date I only used Swing to build graphical user interfaces but now I also want to make myself familiar with the Standard Widget Toolkit.
I already read the documentation and built a simple app.
My problem is now to use the FileDialog component.
I did the following code:
FileDialog openFileDialog = new FileDialog(shell, SWT.OPEN);
openFileDialog.setFilterExtensions(new String[] { "*.txt" });
openFileDialog.setFilterNames(new String[] { "Text files (*.txt)" });
openFileDialog.setText("Open file");
openFileDialog.open();
But I found no methods to set flags like "PathMustExists" or "FileMustExists".
Is this not possible with FileDialog?
Do I have to extend the class to implement that functionality? If so, how I have to proceed?
Or this there a better OpenFileDialog component (maybe in JFace) from which I don't know?
There are no options for this.
Since you are specifying SWT.OPEN you will get a file dialog specialized for opening existing files. Depending on which platform you are running on this dialog may not allow non-existent files to be selected at all (certainly true on Mac OS X). Still you should check the file after the dialog returns.

Itext : set zoom level of external hyper link in pdf

I am using following code to set external hyperlink using itext library in Java.
Chunk chunk = new Chunk("Click to Open File");
PdfAction action = new PdfAction("externalfile.pdf");
action.put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
action.put(PdfName.ZOOM, PdfName.FIT);
chunk.setAction(action);
I want to set zoom level of external hyper link: when I click on hyper link file should be open and FIT page.
I tried using action.put(PdfName.ZOOM, PdfName.FIT); but it's not working.
Please don't ever create PDF object manually without consulting ISO-32000-1.
You want to create a GoToR action. Such an action is expressed as a PDF dictionary that can contain the following keys:
There is no key named Zoom in that table, hence your code is wrong.
You need the D key and as you want to link to a page and define a zoom factor, you need to define a destination:
In other words, the destination needs to be a PdfArray! PdfName.FIT isn't sufficient!
(All screen shots are taken from the copy of ISO-32000-1 that is provided by Adobe on its web site.)
Update:
If you want to add a link to a remote page, you can also follow the example on page 197-198 of iText in Action - Second Edition: see the LinkActions example that uses the gotoRemotePage() method.
Internally, this method looks like this:
public static PdfAction gotoRemotePage(String filename, String dest, boolean isName, boolean newWindow) {
PdfAction action = new PdfAction();
action.put(PdfName.F, new PdfString(filename));
action.put(PdfName.S, PdfName.GOTOR);
if (isName)
action.put(PdfName.D, new PdfName(dest));
else
action.put(PdfName.D, new PdfString(dest, PdfObject.TEXT_UNICODE));
if (newWindow)
action.put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
return action;
}
Note that this assumes that you have a named destination in the target file.
I think that you'd rather want to use the constructor that takes a page number:
public PdfAction(String filename, int page) {
put(PdfName.S, PdfName.GOTOR);
put(PdfName.F, new PdfString(filename));
put(PdfName.D, new PdfLiteral("[" + (page - 1) + " /FitH 10000]"));
}
Of course, this doesn't use PdfName.FIT. If you really want to define the destination yourself, you need a line that looks like this:
put(PdfName.D, new PdfLiteral("[" + (page - 1) + " /Fit]"));

Render and Export FusionCharts on the Server

I am trying to render and export FusionCharts completely on the server. I am aware of solutions such as FCimg and FusionCharts .NET Solution. I have also implemented a Java solution that uses the Process class to run wkhtmltoimage.
However, I am trying to find a pure Java solution of doing this. I have an html file that includes FusionCharts JS Libraries and code to generate the fusion chart. I found JxBrowser that properly renders the chart but it requires X-Server for it to work on Linux. I also have tried Cobra/Lobo Browser but it does not fully support JavaScript. Are there any other ways to render and export fusion charts on the server or atleast render an html file that includes JavaScript completely in Java (and that does not require xserver)?
Thanks in advance for all the help!
Update: Solution that does not require xserver: WebRenderer. The Swing Edition is the only edition that supports HTML5 as of July 9th, 2012. You can use the swing edition to capture the image without a GUI.
I found a way that uses Eclipse's SWT Browser. However this cannot be run in an headless mode. You will have to use xserver to implement this. See this question.
Since this requires xserver and cannot be run in an headless mode, I would suggest using JxBrowser. It is a lot simpler and all you need is to generate an html file with all the fusion charts scripts. See #1, #2, #3
You have to create a template.html file that contains the header
(<html><head>), jquery.min.js, FusionCharts.js,
FusionCharts.HC.js, FusionCharts.HC.Charts.js. Make sure each of
these scripts are in their own script tags (<script type="text/javascript"> [js code] </script>)
Now add another JavaScript function with its own script tags containing the steps to render the chart. For example:
function load() { FusionCharts.setCurrentRenderer('javascript'); var chart = new FusionCharts("swf", 'chart0', "width", "height", "0", "1"); chart.setXMLData("XML DATA HERE"); chart.render("divNAMEHere"); }
Now you need to call the load() function onload, create a div to render the chart in, and end the html file. For example:
`
test
`
Create a new class that imports the eclipse swt browser libraries. Instantiate Display, Shell, and Browser (use this as a guideline to help understand what is happening: http://www.roseindia.net/tutorials/swt/swt-browser.shtml).
Set the text of the browser (browser.setText("htmlcode")) to the html code from template.html. The best way to do this would be to read the file using BufferedReader.
Lastly, the image takes some time to render. Now there is probably a better way to do this but if you want to just get it working, I set up a count and it captures the image after a certain number. This is what you need to add to the end:
int i = 0;
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
i++;
// System.out.println(i);
if(i==100)
{
GC source = new GC (shell);
Image image = new Image(display, browser.getClientArea());
source.copyArea(image, 0, 0);
ImageLoader io = new ImageLoader ();
io.data = new ImageData[] { image.getImageData() };
File f = new File (currentDir+"/workpng.png");
io.save (f.getAbsolutePath(), SWT.IMAGE_PNG);
}
}
}

Categories