OpenSeSim/src/sesim/ChartPanel.java

152 lines
4.0 KiB
Java
Raw Normal View History

package sesim;
2017-10-02 21:45:20 +02:00
import chart.painter.ChartPainter;
2017-10-02 21:45:20 +02:00
import gui.Globals;
2017-10-02 21:45:20 +02:00
import java.awt.Cursor;
2017-10-07 09:36:41 +02:00
2017-10-02 21:45:20 +02:00
import java.awt.Graphics;
import java.awt.Graphics2D;
2017-10-03 08:05:46 +02:00
import java.awt.Point;
2017-10-07 09:36:41 +02:00
2017-10-02 21:45:20 +02:00
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
2017-10-07 09:36:41 +02:00
2017-10-02 21:45:20 +02:00
import java.util.ArrayList;
import javax.swing.JScrollBar;
2017-10-07 09:36:41 +02:00
2017-10-02 21:45:20 +02:00
/**
*
* @author 7u83 <7u83@mail.ru>
*/
2017-10-03 15:50:18 +02:00
public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener {
2017-10-02 21:45:20 +02:00
2017-11-18 14:24:09 +01:00
public JScrollBar x_scrollbar = null;
2017-10-07 09:36:41 +02:00
ChartDef chartDef;
2017-11-18 14:24:09 +01:00
public boolean mouseEntered = false;
2017-10-02 21:45:20 +02:00
/**
* Creates new form Chart1
*/
public ChartPanel() {
initComponents();
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}
2017-10-07 09:36:41 +02:00
/**
* Add a horizontal scrollbar
2017-11-18 14:24:09 +01:00
*
* @param x_scrollbar
2017-10-07 09:36:41 +02:00
*/
2017-11-18 14:24:09 +01:00
public void setXSCrollBar(JScrollBar x_scrollbar) {
if (this.x_scrollbar != null) {
2017-10-03 15:50:18 +02:00
this.x_scrollbar.removeAdjustmentListener(this);
2017-11-18 14:24:09 +01:00
}
this.x_scrollbar = x_scrollbar;
if (this.x_scrollbar != null) {
2017-10-03 15:50:18 +02:00
this.x_scrollbar.addAdjustmentListener(this);
2017-11-18 14:24:09 +01:00
}
2017-10-03 15:50:18 +02:00
}
2017-11-18 14:24:09 +01:00
public void setChartDef(ChartDef def) {
2017-10-07 09:36:41 +02:00
chartDef = def;
}
2017-10-03 12:35:12 +02:00
private ArrayList<ChartPainter> chartPainters = new ArrayList<>();
2017-10-03 12:35:12 +02:00
2017-10-02 21:45:20 +02:00
/**
2017-10-03 12:35:12 +02:00
*
* @param p
2017-10-02 21:45:20 +02:00
*/
2017-10-03 12:35:12 +02:00
public void addChartPainter(ChartPainter p) {
2017-10-02 21:45:20 +02:00
chartPainters.add(p);
}
2017-11-18 14:24:09 +01:00
public void deleteAllChartPinters() {
chartPainters = new ArrayList<>();
}
2017-11-18 14:24:09 +01:00
public boolean delChartPainter(ChartPainter p) {
return true;
}
2017-10-02 21:45:20 +02:00
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
2017-10-03 12:35:12 +02:00
if (Globals.se == null) {
return;
}
2017-10-02 21:45:20 +02:00
2017-10-03 12:35:12 +02:00
for (ChartPainter painter : chartPainters) {
2017-10-07 09:36:41 +02:00
painter.drawChart((Graphics2D) g, this, chartDef);
2017-10-02 21:45:20 +02:00
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
2017-10-03 08:05:46 +02:00
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
formMouseMoved(evt);
}
});
2017-10-08 00:12:02 +02:00
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseExited(java.awt.event.MouseEvent evt) {
formMouseExited(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
formMouseEntered(evt);
}
});
2017-10-03 08:05:46 +02:00
2017-10-02 21:45:20 +02:00
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 498, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 341, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
public Point mouse = null;
2017-10-03 12:35:12 +02:00
2017-10-03 08:05:46 +02:00
private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
2017-10-03 12:35:12 +02:00
2017-10-03 08:05:46 +02:00
Point p = evt.getPoint();
mouse = p;
repaint();
2017-10-03 12:35:12 +02:00
}//GEN-LAST:event_formMouseMoved
2017-10-02 21:45:20 +02:00
2017-10-08 00:12:02 +02:00
private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered
2017-11-18 14:24:09 +01:00
this.mouseEntered = true;
2017-10-08 00:12:02 +02:00
}//GEN-LAST:event_formMouseEntered
private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
2017-11-18 14:24:09 +01:00
this.mouseEntered = false;
2017-10-08 00:12:02 +02:00
}//GEN-LAST:event_formMouseExited
2017-10-07 09:36:41 +02:00
@Override
2017-10-02 21:45:20 +02:00
public void adjustmentValueChanged(AdjustmentEvent e) {
this.repaint();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}