【发布时间】:2018-03-04 19:23:00
【问题描述】:
我正在尝试构建一个 Eclipse 插件。该插件有 2 个以下组件。 1) 文件浏览器。 2) 一个 JFreeChart
目标:用文件浏览器浏览并选择一个文件后,JFreeChart 会用选中的文件制作一个图表。 无论我选择多少次不同的文件,图表都会将这些文件投影到我需要的图表中。
我有一个视图部分。 File-Browser 和 JFreeChart 都使用父组合。我已经实现了静态部分,这意味着我可以使用我的插件浏览文件,并且图表可以表示任何文件(不是我浏览的文件,这就是我卡住的地方)。 在这里我想制作一个图表,当我浏览不同的文件时会更新。请看我的代码。
FileChooser.java
mButton = new Button(this, SWT.NONE);
mButton.setText("Browse");
//mText.setText("F:\\Java Works\\Ground\\bin\\test.txt");
mText.setText("");
chartDraw = mText.getText();
mButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
FileDialog dlg = new FileDialog(mButton.getShell(), SWT.OPEN );
dlg.setText("Open");
path = dlg.open();
if (path == null) return;
mText.setText(path);
chartDraw = mText.getText();
}
});
ChartView.java
public void createPartControl(Composite parent){
Composite top = new Composite(parent, SWT.NONE);// embedded Composite
// setup the layout of top to be GridLayout.
GridLayout layout1 = new GridLayout();
layout1.marginHeight = 0;
layout1.marginWidth = 0;
top.setLayout(layout1);
// top banner
Composite banner = new Composite(top, SWT.NONE);// banner is added to
// "top"
banner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL,
GridData.VERTICAL_ALIGN_BEGINNING, true, false));
layout1 = new GridLayout();
layout1.marginHeight = 5;
layout1.marginWidth = 10;
layout1.numColumns = 1;
banner.setLayout(layout1);
// setup bold font
Font boldFont = JFaceResources.getFontRegistry().getBold(
JFaceResources.DEFAULT_FONT);
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.minimumWidth = 400;
gridData.minimumHeight = 50;
gridData.grabExcessHorizontalSpace = true;
Label l = new Label(banner, SWT.WRAP);
l.setText("Source File:");
l.setFont(boldFont);
final FileChooser fileChooser = new FileChooser(banner);
gridData.heightHint = 25;
fileChooser.setLayoutData(gridData);
ami = fileChooser.getchartDraw();
// Viewing Chart Starts Here
FetchDataChart chart1 = new FetchDataChart();
//XYSeriesCollection dataset = chart1.createDataset();
XYSeriesCollection dataset = chart1.createDataset(fileChooser.getchartDraw()); // I am extracting the file path and drawing the chart.
JFreeChart chart;
try {
chart = chart1.createChart(dataset);
ChartComposite frame = new ChartComposite(parent, SWT.NONE, chart, true);
frame.pack();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public String getAmi() {
return ami;
}
现在我的问题是如何连接 FileBrowser 和 JFreeChart,以便在文件路径更改后立即知道文件路径,并且视图部分将图表显示为 FileBrowser 中的文件更改?一些指导和参考会有所帮助。对于您的友好信息,我在 Eclipse PDE/RCP 区域是全新的。
感谢您的帮助。如果您想了解更多信息来解决此问题,请告诉我。
【问题讨论】:
标签: java eclipse-plugin eclipse-rcp rcp