Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 236223 Details for
Bug 418774
Eclipse crash
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Fully work project swing+JFXPanel ->crash windowbuilder+eclipse
Graph.java (text/x-java), 7.42 KB, created by
Roman Galaktionov
on 2013-10-08 11:14:09 EDT
(
hide
)
Description:
Fully work project swing+JFXPanel ->crash windowbuilder+eclipse
Filename:
MIME Type:
Creator:
Roman Galaktionov
Created:
2013-10-08 11:14:09 EDT
Size:
7.42 KB
patch
obsolete
>package sleep; > >import java.awt.EventQueue; > >import javafx.application.Platform; >import javafx.collections.ObservableList; >import javafx.embed.swing.JFXPanel; >import javafx.scene.Group; >import javafx.scene.Node; >import javafx.scene.Scene; >import javafx.scene.chart.AreaChart; >import javafx.scene.chart.BarChart; >import javafx.scene.chart.CategoryAxis; >import javafx.scene.chart.LineChart; >import javafx.scene.chart.NumberAxis; >import javafx.scene.chart.XYChart; >import javafx.scene.chart.XYChart.Data; >import javafx.scene.chart.XYChart.Series; >import javafx.scene.effect.Shadow; >import javafx.scene.paint.Color; >import javafx.scene.shape.Rectangle; >import javafx.scene.web.HTMLEditor; > >import javax.imageio.ImageIO; >import javax.swing.ImageIcon; >import javax.swing.JFrame; >import javax.swing.JLabel; >import javax.swing.JPanel; > >import java.awt.BorderLayout; >import java.io.IOException; >import java.net.MalformedURLException; >import java.net.URL; >import java.sql.Connection; >import java.sql.DriverManager; >import java.sql.ResultSet; >import java.sql.SQLException; >import java.sql.Statement; >import java.util.ArrayList; >import java.util.Collections; >import java.util.List; >import java.util.logging.Logger; > >import javax.swing.JButton; > >import java.awt.event.ActionListener; >import java.awt.event.ActionEvent; > >import javax.swing.BoxLayout; > >import java.awt.Component; > >import javax.swing.SwingConstants; > >public class Graph { > > private JFrame frame; > private static String uri; > private final static double AVG_INDEX = 60; > private String startTime, endTime; > private JFXPanel jfxp; > > /** > * Launch the application. > */ > public static void main(String[] args) { > try { > Class.forName("com.mysql.jdbc.Driver"); > uri = "jdbc:mysql://localhost:3306/motion"; > } catch (ClassNotFoundException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > System.exit(1); > } > > EventQueue.invokeLater(new Runnable() { > public void run() { > try { > Graph window = new Graph(); > window.frame.setVisible(true); > } catch (Exception e) { > e.printStackTrace(); > } > } > }); > } > > /** > * Create the application. > */ > public Graph() { > initialize(); > } > > /** > * Initialize the contents of the frame. > */ > private void initialize() { > > frame = new JFrame(); > frame.setBounds(100, 100, 450, 300); > // frame.setSize(466, 300); > frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); > > JPanel panel = new JPanel(); > frame.getContentPane().add(panel, BorderLayout.SOUTH); > panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); > > final JFXPanel jfx = new JFXPanel(); > jfx.setSize(560, 300); > jfx.setLocation(10, 40); > // defining the axes > CategoryAxis xAxis = new CategoryAxis(); > NumberAxis yAxis = new NumberAxis(); > xAxis.setLabel("ЧиÑло минÑÑ Ñ Ð½Ð°Ñала замеÑа"); > > final AreaChart<String, Number> lineChart = new AreaChart<>(xAxis, > yAxis); > Series<String, Number> data = graph(); > lineChart.getData().add(data); > lineChart.setTitle("ÐаÑало замеÑа: " + Graph.this.startTime > + " ÐавеÑÑение замеÑа: " + endTime); > > Platform.runLater(new Runnable() { > @Override > public void run() { > // creating the chart > Scene scene = new Scene(lineChart, 400, 300); > jfx.setScene(scene); > } > }); > > JButton btnUpdate = new JButton("Update"); > btnUpdate.setHorizontalAlignment(SwingConstants.LEADING); > btnUpdate.setAlignmentX(Component.CENTER_ALIGNMENT); > btnUpdate.addActionListener(new ActionListener() { > public void actionPerformed(ActionEvent e) { > Platform.runLater(new Runnable() { > @Override > public void run() { > lineChart.getData().clear(); > lineChart.getData().add(graph()); > } > }); > } > }); > panel.add(btnUpdate); > > JButton btnNewButton = new JButton("Truncate"); > btnNewButton.addActionListener(new ActionListener() { > public void actionPerformed(ActionEvent e) { > // TODO Auto-generated method stub > try (Connection con = DriverManager.getConnection(uri, "root", > "32167klub"); Statement st = con.createStatement()) { > st.execute("TRUNCATE TABLE motions"); > } catch (SQLException t) { > // TODO Auto-generated catch block > t.printStackTrace(); > System.exit(1); > } > } > }); > btnNewButton.setAlignmentX(Component.CENTER_ALIGNMENT); > panel.add(btnNewButton); > > frame.getContentPane().add(jfx, BorderLayout.CENTER); > } > > private Series<String, Number> graph() { > // EXAMPLE CODE START > > Series<String, Number> fluent = new XYChart.Series<>(); > fluent.setName("ÐвижениÑ"); > try (Connection con = DriverManager.getConnection(uri, "root", > "32167klub"); > Statement st = con.createStatement(); > ResultSet rs = st > .executeQuery("SELECT time,UNIX_TIMESTAMP(time) as t,SECOND(time) as s,MINUTE(time) as m,pixels FROM motions ORDER BY time")) { > int init = 0; > int pixels = 0; > double avg = 0; > int lastSecond = 0; > int second = 0; > int lastMinute = 0; > int minute = 0; > > while (rs.next()) { > if (init == 0) { > init = rs.getInt("t"); > startTime = rs.getString("time"); > } > second = rs.getInt("s"); > pixels = rs.getInt("pixels"); > avg = Math.max(avg, pixels); > if (lastSecond != second) { > minute = rs.getInt("m"); > if (lastMinute != minute) { > double elapsedTime = rs.getInt("t") - init; > elapsedTime /= AVG_INDEX; > XYChart.Data<String, Number> data = new XYChart.Data<String, Number>( > Integer.toString((int) Math.floor(elapsedTime)), > avg); > fluent.getData().add(data); > avg = 0; > lastMinute = minute; > endTime = rs.getString("time"); > } > lastSecond = second; > } > } > > List<Integer> max = new ArrayList<>(); > ObservableList<Data<String, Number>> data = fluent.getData(); > for (int i = 0; i < data.size(); i++) { > max.add(i); > } > max = maxis(data, max); > for (Integer i : max) { > Data<String, Number> curDataValue = data.get(i); > Rectangle r = new Rectangle(); > r.setWidth(5); > r.setHeight(5); > r.setArcWidth(2); > r.setArcHeight(2); > r.setFill(Color.RED); > curDataValue.setNode(r); > } > max = maxis(data, max); > for (Integer i : max) { > Data<String, Number> curDataValue = data.get(i); > Rectangle r = new Rectangle(); > r.setWidth(5); > r.setHeight(5); > r.setArcWidth(2); > r.setArcHeight(2); > r.setFill(Color.BLUE); > curDataValue.setNode(r); > } > max = maxis(data, max); > for (Integer i : max) { > Data<String, Number> curDataValue = data.get(i); > Rectangle r = new Rectangle(); > r.setWidth(5); > r.setHeight(5); > r.setArcWidth(2); > r.setArcHeight(2); > r.setFill(Color.GREEN); > curDataValue.setNode(r); > } > } catch (SQLException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > System.exit(1); > } > > return fluent; > } > > private List<Integer> maxis(ObservableList<Data<String, Number>> points, > List<Integer> max) { > double prevValue = 0; > double curValue = 0; > double nextValue = 0; > > List<Integer> ret = new ArrayList<>(); > > for (int i = 0; i < max.size(); i++) { > > if (i > 0) { > prevValue = (Double) points.get(max.get(i - 1)).getYValue(); > } else { > prevValue = 0; > } > > Data<String, Number> curDataValue = points.get(max.get(i)); > curValue = (Double) curDataValue.getYValue(); > > if (max.get(i) < points.size() - 1) { > nextValue = (Double) points.get(max.get(i + 1)).getYValue(); > } else { > nextValue = 0; > } > > if (curValue >= prevValue && curValue >= nextValue) { > ret.add(max.get(i)); > } > } > return ret; > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 418774
:
236158
|
236159
|
236182
|
236212
|
236221
|
236222
| 236223 |
236235