Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [nebula-dev] save as bmp, or tif-fileswt xygraph

Hi trig
Thank you very much, you helped me a lot!!!! I used JFilechooser at first, my boss wants some changes in the program,
therefore the components are mixed!
 
Kind regards
 
lars
 
Gesendet: Donnerstag, 24. November 2016 um 00:20 Uhr
Von: "Trig Chen" <trigchen@xxxxxxxxx>
An: "Nebula Dev" <nebula-dev@xxxxxxxxxxx>
Betreff: Re: [nebula-dev] save as bmp, or tif-fileswt xygraph
Hi Lars,
 
In my previous message I posted the implemention of taking snapshot in ToolbarArmedGraph is for you to implement taking snapshot out side of XYGraph which don't have a armed toolbar.
 
You don't need to create extra buttons as you have created the XYGraph with a armed toolbar which already had a button to take snapshot.
So, your  public void addButton(Clickable button) method is redundant. 
 
BTW:  
Since your application is based on Eclipse & SWT, you can use org.eclipse.swt.widgets.FileDialog instead of javax.swing.JFileChooser.
 
 
Best regards,
 
Trig
 
2016-11-23 18:54 GMT+08:00 Lars Ohmann <sohm63@xxxxxx>:
Hi
 
I tried to check it out this example you sent me. I have got an additional question:
 
I tried to implement the method: addButton(snapShotButton); From the google I got:
public void addButton(Clickable button){ 
  button.setPreferredSize(BUTTON_SIZE, BUTTON_SIZE); 
  add(button); 
 
 
So I added it, but I could not implement "add(button)" ; I imported a lot of nebula...
 
So I send the code snippet concerning this problem. Where is "add(button)" defined ???
 
Here the code:
 
import java.io.File;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
 
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
 
import org.eclipse.core.*;
import org.eclipse.core.commands.*;
import org.eclipse.equinox.*;
import org.eclipse.osgi.*;
import org.eclipse.draw2d.*;
import org.eclipse.nebula.visualization.xygraph.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider;
import org.eclipse.nebula.visualization.xygraph.figures.*;
import org.eclipse.nebula.visualization.xygraph.figures.Trace.PointStyle;
import org.eclipse.nebula.visualization.xygraph.figures.Trace.TraceType;
import org.eclipse.nebula.visualization.xygraph.util.XYGraphMediaFactory;
import org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph;
 
import org.eclipse.nebula.visualization.xygraph.figures.XYGraphToolbar;
 
import org.eclipse.draw2d.Button;
//import org.eclipse.draw2d.ButtonGroup;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Clickable;
 
 
 
public class PlotKomp  // wird von Fileread.java aufgerufen
{   
       public void addButton(Clickable button)
       {
          button.setPreferredSize(25, 25);
          add(button);                                                                DOES NOT WORK
       }
 
      
       public void drawGraph(String pfad)
       {
Display display = Display.getDefault();
          Shell shell = new Shell(display);
         
       
             shell.setSize(600, 450);
             shell.open()
             shell.setLocation(100, 100)
             LightweightSystem lwssio2 = new LightweightSystem(shell);
             XYGraph xysio2graph = new XYGraph();
            
            
             ToolbarArmedXYGraph toolbarArmedXYGraph = new ToolbarArmedXYGraph(xysio2graph);  //23.11
          
             xysio2graph.setTitle("SiO2");
              //23.11            lwssio2.setContents(xysio2graph);
             lwssio2.setContents(toolbarArmedXYGraph);
            
            
             // Configure XYGraph
             xysio2graph.primaryXAxis.setShowMajorGrid(true);
             xysio2graph.primaryYAxis.setShowMajorGrid(true);
           
             // Bezeichnung der Achsen
             xysio2graph.primaryXAxis.setTitle("XRD-Value [%]");
             xysio2graph.primaryYAxis.setTitle("XRF-Value [%]");
            
             // Create a trace data provider, which will provide the data to the trace XRD and XRF        
             CircularBufferDataProvider tdpsio2 = new CircularBufferDataProvider(false);
             tdpsio2.setBufferSize(200);  
    
             tdpsio2.setCurrentXDataArray(arrsio2xrdend);
             tdpsio2.setCurrentYDataArray(arrsio2rfaend);
          // Create a trace data provider for the line
            
             Trace tracesio2 = new Trace("SiO2-XY Plot", xysio2graph.primaryXAxis, xysio2graph.primaryYAxis, tdpsio2);
             tracesio2.setTraceType(TraceType.POINT);
             tracesio2.setPointStyle(PointStyle.FILLED_DIAMOND);
             tracesio2.setPointSize(10);
             tracesio2.setAreaAlpha(250);
             tracesio2.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_BLUE));
           
             xysio2graph.addTrace(tracesio2);
 
             CircularBufferDataProvider tdpsio2line = new CircularBufferDataProvider(false);
             tdpsio2line.setBufferSize(200);           
             tdpsio2line.setCurrentXDataArray(new double[]{0.0, 50.0, 100.0});
             tdpsio2line.setCurrentYDataArray(new double[]{0.0, 50.0, 100.0});
            
             Trace tracesio2line = new Trace("SiO2-XY Plot", xysio2graph.primaryXAxis, xysio2graph.primaryYAxis, tdpsio2line);
            
             tracesio2line.setTraceType(TraceType.SOLID_LINE);
             tracesio2line.setLineWidth(2);
             tracesio2line.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_BLACK));
            
             xysio2graph.addTrace(tracesio2line);
       
 
Button     snapShotButton = new Button(XYGraphMediaFactory.getInstance().getImage("images/camera.png"));  //
        snapShotButton.setToolTip(new Label("Save Snapshot to PNG file"));
      //  addButton...
 
Thanks in advance!
 
 
Gesendet: Freitag, 18. November 2016 um 12:07 Uhr
Von: "Trig Chen" <trigchen@xxxxxxxxx>
An: "Nebula Dev" <nebula-dev@xxxxxxxxxxx>
Betreff: Re: [nebula-dev] save as bmp, or tif-fileswt xygraph
Hi Lars,
 
You can create the plot with a toolbar. The toolbar has export button. The sample code is in:
http://git.eclipse.org/c/nebula/org.eclipse.nebula.git/plain/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/visualization/SimpleToolbarArmedXYGraphExample.java
The relatived code in org.eclipse.nebula.visualization.xygraph.figures.XYGraphToolbar.java is: 
	private void addSnapshotButton() {
		Button snapShotButton = new Button(XYGraphMediaFactory.getInstance().getImage("images/camera.png"));
		snapShotButton.setToolTip(new Label("Save Snapshot to PNG file"));
		addButton(snapShotButton);
		snapShotButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				// Have valid name, so get image
				ImageLoader loader = new ImageLoader();
				Image image = xyGraph.getImage();
				loader.data = "" ImageData[] { image.getImageData() };
				image.dispose();
				// Prompt for file name
				String path = SingleSourceHelper2.getImageSavePath();
				if (path == null || path.length() <= 0)
					return;
				// Assert *.png at end of file name
				if (!path.toLowerCase().endsWith(".png"))
					path = path + ".png";
				// Save
				loader.save(path, SWT.IMAGE_PNG);
			}
		});
	}
 
 
 
Best regards,
 
Trig
 
2016-11-18 17:56 GMT+08:00 Lars Ohmann <sohm63@xxxxxx>:
Hello
 
below is the code! It is easy, it just gives a simple plot. How can I save this plot (xygraph) as
a bmp or jpg-file on the PC ? I posted the question on several forums, either the answer is too
complicated or the problem is too trivial for the community.
 
A hint would be very helpful!
 
thanks!
 
package org.eclipse.nebula.visualization.xygraph.examples;

/*******************************************************************************
* Copyright (c) 2010 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider;
import org.eclipse.nebula.visualization.xygraph.figures.Ixygraph;
import org.eclipse.nebula.visualization.xygraph.figures.Trace;
import org.eclipse.nebula.visualization.xygraph.figures.xygraph;
import org.eclipse.nebula.visualization.xygraph.figures.Trace.PointStyle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* A very simple example.
*
* @author Xihui Chen
*
*/
public class SimpleExample {
public static void main(String[] args) {
final Shell shell = new Shell();
shell.setSize(300, 250);
shell.open();

// use LightweightSystem to create the bridge between SWT and draw2D
final LightweightSystem lws = new LightweightSystem(shell);

// create a new XY Graph.
Ixygraph xygraph = new xygraph();
xygraph.setTitle("Simple Example");
// set it as the content of LightwightSystem
lws.setContents(xygraph);

// create a trace data provider, which will provide the data to the
// trace.
CircularBufferDataProvider traceDataProvider = new CircularBufferDataProvider(false);
traceDataProvider.setBufferSize(100);
traceDataProvider.setCurrentXDataArray(new double[] { 10, 23, 34, 45, 56, 78, 88, 99 });
traceDataProvider.setCurrentYDataArray(new double[] { 11, 44, 55, 45, 88, 98, 52, 23 });

// create the trace
Trace trace = new Trace("Trace1-XY Plot", xygraph.getPrimaryXAxis(), xygraph.getPrimaryYAxis(), traceDataProvider);

// set trace property
trace.setPointStyle(PointStyle.XCROSS);

// add the trace to xygraph
xygraph.addTrace(trace);

Display display = Display.getDefault();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

}
}

_______________________________________________
nebula-dev mailing list
nebula-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/nebula-dev
_______________________________________________ nebula-dev mailing list nebula-dev@xxxxxxxxxxx To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/nebula-dev
_______________________________________________ nebula-dev mailing list nebula-dev@xxxxxxxxxxx To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/nebula-dev

_______________________________________________
nebula-dev mailing list
nebula-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/nebula-dev
_______________________________________________ nebula-dev mailing list nebula-dev@xxxxxxxxxxx To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/nebula-dev

Back to the top