Created ChartPainterInterface and moved ChartPainter intto sesim package
This commit is contained in:
46
src/sesim/ChartDef.java
Normal file
46
src/sesim/ChartDef.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
import javax.swing.JScrollBar;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ChartDef {
|
||||
|
||||
|
||||
/**
|
||||
* width of an x unit in em
|
||||
*/
|
||||
public double x_unit_width=1.0;
|
||||
|
||||
public ChartDef(){
|
||||
|
||||
}
|
||||
|
||||
}
|
36
src/sesim/ChartPainterInterface.java
Normal file
36
src/sesim/ChartPainterInterface.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public interface ChartPainterInterface {
|
||||
abstract public void drawChart(Graphics2D g, ChartPanel p, ChartDef def);
|
||||
}
|
33
src/sesim/ChartPanel.form
Normal file
33
src/sesim/ChartPanel.form
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<Events>
|
||||
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="formMouseMoved"/>
|
||||
<EventHandler event="mouseExited" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="formMouseExited"/>
|
||||
<EventHandler event="mouseEntered" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="formMouseEntered"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="498" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="341" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Form>
|
151
src/sesim/ChartPanel.java
Normal file
151
src/sesim/ChartPanel.java
Normal file
@ -0,0 +1,151 @@
|
||||
package sesim;
|
||||
|
||||
import chart.painter.ChartPainter;
|
||||
import gui.Globals;
|
||||
|
||||
import java.awt.Cursor;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.JScrollBar;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ChartPanel extends javax.swing.JPanel implements AdjustmentListener {
|
||||
|
||||
public JScrollBar x_scrollbar = null;
|
||||
ChartDef chartDef;
|
||||
public boolean mouseEntered = false;
|
||||
|
||||
/**
|
||||
* Creates new form Chart1
|
||||
*/
|
||||
public ChartPanel() {
|
||||
initComponents();
|
||||
|
||||
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a horizontal scrollbar
|
||||
*
|
||||
* @param x_scrollbar
|
||||
*/
|
||||
public void setXSCrollBar(JScrollBar x_scrollbar) {
|
||||
if (this.x_scrollbar != null) {
|
||||
this.x_scrollbar.removeAdjustmentListener(this);
|
||||
}
|
||||
this.x_scrollbar = x_scrollbar;
|
||||
if (this.x_scrollbar != null) {
|
||||
this.x_scrollbar.addAdjustmentListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setChartDef(ChartDef def) {
|
||||
chartDef = def;
|
||||
}
|
||||
|
||||
private ArrayList<ChartPainter> chartPainters = new ArrayList<>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p
|
||||
*/
|
||||
public void addChartPainter(ChartPainter p) {
|
||||
chartPainters.add(p);
|
||||
}
|
||||
|
||||
public void deleteAllChartPinters() {
|
||||
chartPainters = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean delChartPainter(ChartPainter p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ChartPainter painter : chartPainters) {
|
||||
painter.drawChart((Graphics2D) g, this, chartDef);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
||||
public void mouseMoved(java.awt.event.MouseEvent evt) {
|
||||
formMouseMoved(evt);
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
|
||||
|
||||
Point p = evt.getPoint();
|
||||
mouse = p;
|
||||
repaint();
|
||||
|
||||
}//GEN-LAST:event_formMouseMoved
|
||||
|
||||
private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered
|
||||
this.mouseEntered = true;
|
||||
|
||||
}//GEN-LAST:event_formMouseEntered
|
||||
|
||||
private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
|
||||
this.mouseEntered = false;
|
||||
}//GEN-LAST:event_formMouseExited
|
||||
|
||||
@Override
|
||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
Reference in New Issue
Block a user