AbstractTableMapperListener, JDiagram updates

thobaben_diagram
Harald Wolff 2016-06-08 23:05:45 +02:00
parent 9f2215eaf4
commit e727197d6b
12 changed files with 209 additions and 19 deletions

View File

@ -6,5 +6,11 @@ public abstract class AbstractTableMapperListener implements
@Override
public void ValueChanged(int row, int column) {
}
@Override
public boolean editorRequest(TableMapper tableMapper, Object row) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -423,6 +423,14 @@ public class TableMapper extends AbstractTableModel
private void openEditor()
{
System.err.println("TableMapper.openEditor()");
for (TableMapperListener listener: this.tableMapperListeners){
if (listener.editorRequest(this, getSelectedRow())){
return;
}
}
try {
Object editorObject = getEditorObject();

View File

@ -4,4 +4,6 @@ public interface TableMapperListener {
public void ValueChanged(int row,int column);
public boolean editorRequest(TableMapper tableMapper,Object row);
}

View File

@ -25,7 +25,8 @@ public class JDiagram extends JComponent {
plotProvider;
private PlotLabeler
defaultLabeler;
defaultLabeler,
abszissLabeler;
// Innenabstand zu Zeichnungselementen
private int bTop,
@ -75,7 +76,7 @@ public class JDiagram extends JComponent {
setDoubleBuffered(true);
defaultLabeler = new SimplePlotLabeler();
abszissLabeler = defaultLabeler;
bTop = bBottom = bLeft = 10;
bRight = 30;
@ -193,6 +194,14 @@ public class JDiagram extends JComponent {
this.autoScaleMargins = autoScaleMargins;
}
public PlotLabeler getAbszissLabeler() {
return abszissLabeler;
}
public void setAbszissLabeler(PlotLabeler abszissLabeler) {
this.abszissLabeler = abszissLabeler;
}
public void autoscale(){
int ordinate;
Double[] max,min;
@ -277,6 +286,9 @@ public class JDiagram extends JComponent {
public void paintOrdinates(Graphics2D g){
double[][] labelValues = new double[ ordinateViews.length ][];
Integer last_y = null,
y = null,
d = null;
for (int ordinate=0; ordinate < ordinateViews.length; ordinate++){
labelValues[ ordinate ] = getordinateLabelHints(ordinate);
@ -294,6 +306,7 @@ public class JDiagram extends JComponent {
for (int i=0;i<=nMarkers;i++){
labels[i] = this.defaultLabeler.getOrdinateLabel(
this,
ordinate,
labelValues[ordinate][i]
);
labelWidths[i] = g.getFontMetrics().stringWidth(labels[i]);
@ -303,13 +316,26 @@ public class JDiagram extends JComponent {
}
plotWidth -= maxWidth + 5;
last_y = null;
for (int i=0; i<=nMarkers ;i++){
g.drawString(
y = bTop + plotHeight - this.ordinateViews[ ordinate ].scaler.getPosition(labelValues[ordinate][i]) + (fontLineHeight/4);
if (last_y == null){
d = null;
} else {
d = y -last_y;
if (d<0)
d = -d;
};
if ((d == null) || (d > fontLineHeight )) {
g.drawString(
labels[i],
getWidth() - bRight - plotWidth - labelWidths[i],
bTop + plotHeight - this.ordinateViews[ ordinate ].scaler.getPosition(labelValues[ordinate][i]) + (fontLineHeight/4)
y
);
last_y = y;
}
}
plotWidth -= axMarkerLength;
@ -373,6 +399,7 @@ public class JDiagram extends JComponent {
bTop + plotHeight
);
if (nMarker > 0)
for (int n=0;n <= nMarker; n++){
int xpos = plotWidth * n / nMarker;
double pos = abszissMinimum + (abszissWindow * n / nMarker);

View File

@ -3,6 +3,7 @@ package org.hwo.ui;
import javax.swing.JTable;
import org.hwo.models.TableMapper.TableMapper;
import org.hwo.models.TableMapper.TableMapperListener;
public class JMappedTable extends JTable {
@ -14,6 +15,15 @@ public class JMappedTable extends JTable {
public TableMapper getTableMapper() {
return tableMapper;
}
public void addTableMapperListener(TableMapperListener tableMapperListener){
this.tableMapper.addTableMapperListener(tableMapperListener);
}
public void removeTableMapperListener(TableMapperListener tableMapperListener){
this.tableMapper.removeTableMapperListener(tableMapperListener);
}
}

View File

@ -3,11 +3,19 @@ package org.hwo.ui;
import javax.swing.JComponent;
import java.awt.GridBagLayout;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JLabel;
public class JTimeSpanEditor extends JComponent {
public class JTimeSpanEditor extends JComponent implements FocusListener {
private JSpinner spDays;
private JSpinner spHours;
private JSpinner spMinutes;
@ -15,11 +23,13 @@ public class JTimeSpanEditor extends JComponent {
private JLabel lblD;
private JLabel lblNewLabel;
private JLabel label;
private List<FocusListener> focusListeners;
private List<Component> components;
public JTimeSpanEditor() {
this.focusListeners = new LinkedList<FocusListener>();
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0};
gridBagLayout.rowHeights = new int[]{0, 0};
@ -28,6 +38,9 @@ public class JTimeSpanEditor extends JComponent {
setLayout(gridBagLayout);
spDays = new JSpinner();
spDays.addFocusListener(this);
spDays.getEditor().addFocusListener(this);
spDays.setModel(new SpinnerNumberModel(0, 0, 366, 1));
GridBagConstraints gbc_spDays = new GridBagConstraints();
gbc_spDays.fill = GridBagConstraints.BOTH;
gbc_spDays.insets = new Insets(0, 0, 0, 5);
@ -43,6 +56,10 @@ public class JTimeSpanEditor extends JComponent {
add(lblD, gbc_lblD);
spHours = new JSpinner();
spHours.addFocusListener(this);
spHours.setFocusable(true);
spHours.getEditor().addFocusListener(this);
spHours.setModel(new SpinnerNumberModel(0, 0, 23, 1));
GridBagConstraints gbc_spHours = new GridBagConstraints();
gbc_spHours.fill = GridBagConstraints.BOTH;
gbc_spHours.insets = new Insets(0, 0, 0, 5);
@ -58,6 +75,9 @@ public class JTimeSpanEditor extends JComponent {
add(lblNewLabel, gbc_lblNewLabel);
spMinutes = new JSpinner();
spMinutes.addFocusListener(this);
spMinutes.getEditor().addFocusListener(this);
spMinutes.setModel(new SpinnerNumberModel(0, 0, 59, 1));
GridBagConstraints gbc_spMinutes = new GridBagConstraints();
gbc_spMinutes.fill = GridBagConstraints.BOTH;
gbc_spMinutes.insets = new Insets(0, 0, 0, 5);
@ -73,14 +93,49 @@ public class JTimeSpanEditor extends JComponent {
add(label, gbc_label);
spSeconds = new JSpinner();
spSeconds.addFocusListener(this);
spSeconds.getEditor().addFocusListener(this);
spSeconds.setModel(new SpinnerNumberModel(0, 0, 59, 1));
GridBagConstraints gbc_spSeconds = new GridBagConstraints();
gbc_spSeconds.fill = GridBagConstraints.BOTH;
gbc_spSeconds.gridx = 6;
gbc_spSeconds.gridy = 0;
add(spSeconds, gbc_spSeconds);
components = UIHelper.getComponentsRecursive(this);
setupFocusListeners();
}
private void setupFocusListeners(){
setupFocusListener(UIHelper.getComponentsRecursive(spDays));
setupFocusListener(UIHelper.getComponentsRecursive(spHours));
setupFocusListener(UIHelper.getComponentsRecursive(spMinutes));
setupFocusListener(UIHelper.getComponentsRecursive(spSeconds));
}
private void setupFocusListener(List<Component> cl){
for (Component c: cl)
c.addFocusListener(this);
}
@Override
public synchronized void addFocusListener(FocusListener l) {
focusListeners.add(l);
}
@Override
public synchronized void removeFocusListener(FocusListener l) {
focusListeners.remove(l);
}
private void fireFocusLost(Component other){
FocusEvent fe = new FocusEvent(this, FocusEvent.FOCUS_LOST, false, other);
for (FocusListener l:focusListeners)
l.focusLost(fe);
}
private void fireFocusGained(Component other){
FocusEvent fe = new FocusEvent(this, FocusEvent.FOCUS_GAINED, false, other);
for (FocusListener l:focusListeners)
l.focusGained(fe);
}
public Integer getValue(){
if (!spSeconds.isEnabled())
@ -107,18 +162,48 @@ public class JTimeSpanEditor extends JComponent {
spHours.setEnabled(true);
spDays.setEnabled(true);
spDays.setValue(mod / 86400);
if (spDays.isVisible())
spDays.setValue(mod / 86400);
mod %= 86400;
spHours.setValue(mod / 3600);
mod %= 3600;
spMinutes.setValue(mod / 60);
mod %= 60;
spSeconds.setValue(mod);
}
}
public boolean isDaysEnabled(){
return spDays.isVisible();
}
public void setDaysEnabled(boolean daysEnabled){
if (!daysEnabled){
spDays.setValue(new Integer(0));
}
spDays.setVisible(daysEnabled);
spDays.setEnabled(daysEnabled);
lblD.setVisible(daysEnabled);
}
public void focusLost(FocusEvent e) {
if (!components.contains(e.getOppositeComponent())){
System.err.println("JTimeSpanEditor: Focus Lost " + this);
System.err.println("Source: " + e.getSource());
System.err.println("Other: " + e.getOppositeComponent());
System.err.println("");
fireFocusLost(e.getOppositeComponent());
}
}
public void focusGained(FocusEvent e) {
if (!components.contains(e.getOppositeComponent())){
System.err.println("JTimeSpanEditor: Focus Gained " + this);
System.err.println("Source: " + e.getSource());
System.err.println("Other: " + e.getOppositeComponent());
System.err.println("");
fireFocusGained(e.getOppositeComponent());
}
}
}

View File

@ -79,12 +79,17 @@ public class JUITest extends JFrame {
values = p.getPlot(1);
for (int i=0;i<p.getLength();i++){
//values[i] = 5 + (float)Math.sin(Math.PI * i / 8) * 4;
values[i] = (float)(10 + (((float)i/4)*10.0));
//values[i] = (float)(10 + (((float)i/4)*10.0));
//values[i] = 1.0f + (float)( ((float)i/4) * ((float)i/4));
values[i] = (float)Math.exp(i/5.0);
}
values = p.getPlot(2);
for (int i=0;i<p.getLength();i++){
//values[i] = 5 + (float)Math.sin(Math.PI * i / 8) * 4;
values[i] = (float)(10 + (((float)i/4)*10.0));
//values[i] = (float)(10 + (((float)i/4)*10.0));
//values[i] = 1.0f + (float)( ((float)i/4) * ((float)i/4));
values[i] = (float)Math.exp(i/5.0);
}
p.setOrdinate(1, 1);

View File

@ -0,0 +1,27 @@
package org.hwo.ui;
import java.awt.Component;
import java.awt.Container;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.InflaterInputStream;
public class UIHelper {
public static void getComponentsRecursive(Container comp,List<Component> list){
for (Component c:comp.getComponents()){
list.add(c);
if (Container.class.isInstance(c)){
getComponentsRecursive((Container)c, list);
}
}
}
public static List<Component> getComponentsRecursive(Container comp){
List<Component> components = new LinkedList<Component>();
getComponentsRecursive(comp, components);
return components;
}
}

View File

@ -35,7 +35,7 @@ public class AnnotatedSortedMapPlotProvider<T> extends AnnotatedPlotProvider imp
}
@Override
public String getOrdinateLabel(JDiagram diagram, Double value) {
public String getOrdinateLabel(JDiagram diagram, int ordinate, Double value) {
return value.toString();
}

View File

@ -1,6 +1,8 @@
package org.hwo.ui.diagram;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class LogarithmicScaler implements Scaler {
@ -126,6 +128,9 @@ public class LogarithmicScaler implements Scaler {
hints.add(hValue);
}
}
Collections.sort(hints);
Collections.reverse(hints);
double[] result = new double[ hints.size() ];
for (int i=0;i<result.length;i++)

View File

@ -4,7 +4,7 @@ import org.hwo.ui.JDiagram;
public interface PlotLabeler {
public String getOrdinateLabel(JDiagram diagram,Double value);
public String getOrdinateLabel(JDiagram diagram,int ordinate,Double value);
public String getAbzisseLabel(JDiagram diagram,Double pos);
}

View File

@ -26,12 +26,27 @@ public class SimplePlotLabeler implements PlotLabeler {
@Override
public String getOrdinateLabel(JDiagram diagram, Double value) {
public String getOrdinateLabel(JDiagram diagram,int ordinate,Double value) {
if (value == null)
return "";
if (value.isNaN())
return "";
return String.format(this.ordinateFormat,value);
return "";
Double window = diagram.getScaler(ordinate).getWindow();
int digits = ((Double)Math.log10(window)).intValue();
digits -= 4;
if (digits < 0){
return String.format(
String.format("%%.%df",-digits),
value
);
} else {
return String.format(
String.format("%%%d.2f",-digits),
value
);
}
}
@Override