Initialer Commit
commit
b5e498c3e4
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo"/>
|
||||
<classpathentry kind="lib" path="miglayout15-swing.jar" sourcepath="miglayout-src.zip"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1,4 @@
|
|||
.DS_Store
|
||||
bin/*
|
||||
|
||||
/bin
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.hwo.ui</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -0,0 +1,132 @@
|
|||
package org.hwo.models;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Column {
|
||||
private int MODE_FIELD = 1;
|
||||
private int MODE_GETSET = 2;
|
||||
|
||||
private int mode;
|
||||
private String fieldName;
|
||||
private boolean readonly;
|
||||
private Class p_class;
|
||||
private Field field;
|
||||
private Method getter;
|
||||
private Method setter;
|
||||
|
||||
public Column(Class classInfo,String fieldName,boolean readonly) throws NoSuchFieldException
|
||||
{
|
||||
this.fieldName = fieldName;
|
||||
this.readonly = readonly;
|
||||
this.p_class = classInfo;
|
||||
this.getter = null;
|
||||
this.setter = null;
|
||||
|
||||
try
|
||||
{
|
||||
mode = MODE_FIELD;
|
||||
this.field = this.p_class.getDeclaredField(fieldName);
|
||||
this.field.setAccessible(true);
|
||||
} catch (NoSuchFieldException nsfex)
|
||||
{
|
||||
mode = MODE_GETSET;
|
||||
// Kein deklariertes Feld, also suchen wir eine get... und set... Methode...
|
||||
Method[] methods = this.p_class.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
// passender getter?
|
||||
if (("get"+fieldName.toLowerCase()).equals(method.getName().toLowerCase()))
|
||||
getter = method;
|
||||
// passender setter?
|
||||
if (("set"+fieldName.toLowerCase()).equals(method.getName().toLowerCase()))
|
||||
setter = method;
|
||||
}
|
||||
if (getter == null)
|
||||
throw nsfex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getFieldName()
|
||||
{
|
||||
return this.fieldName;
|
||||
}
|
||||
|
||||
public boolean getReadOnly()
|
||||
{
|
||||
if ((mode == MODE_GETSET) && (setter == null))
|
||||
return true;
|
||||
|
||||
return this.readonly;
|
||||
}
|
||||
public void setReadOnly(boolean readOnly)
|
||||
{
|
||||
this.readonly = readOnly;
|
||||
}
|
||||
|
||||
public Class getColumnClass()
|
||||
{
|
||||
if (mode == MODE_GETSET)
|
||||
return this.getter.getReturnType();
|
||||
|
||||
return this.field.getType();
|
||||
}
|
||||
|
||||
Object getValue(Object o)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (mode == MODE_GETSET)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object ro = this.getter.invoke(o, null);
|
||||
return ro;
|
||||
} catch (InvocationTargetException itex)
|
||||
{
|
||||
System.err.println(itex.toString());
|
||||
itex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return this.field.get(o);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.println("IllegalArgument! " + e.toString());
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
System.err.println("IllegalAccess! " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
void setValue(Object o,Object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (mode == MODE_GETSET)
|
||||
{
|
||||
if (this.setter != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.setter.invoke(o,new Object[]{ value });
|
||||
} catch (InvocationTargetException itex)
|
||||
{
|
||||
System.err.println(itex.toString());
|
||||
itex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.field.set(o,value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.println("IllegalArgument! " + e.toString());
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
System.err.println("IllegalAccess! " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.hwo.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.AbstractListModel;
|
||||
|
||||
public class FlexibleObjectListModel<T> extends AbstractListModel {
|
||||
|
||||
private List<T> items;
|
||||
|
||||
public FlexibleObjectListModel() {
|
||||
this.items = new ArrayList<T>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(int index) {
|
||||
return this.items.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return this.items.size();
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.items.clear();
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
|
||||
public List<T> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<T> items) {
|
||||
this.items = items;
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
|
||||
public void addItem(T o)
|
||||
{
|
||||
this.items.add(o);
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
|
||||
public void removeItem(T o)
|
||||
{
|
||||
int index = this.items.indexOf(o);
|
||||
this.items.remove(o);
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package org.hwo.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
public class FlexibleObjectTableModel<T> extends AbstractTableModel{
|
||||
|
||||
List<Column> columns;
|
||||
List<T> rows;
|
||||
|
||||
Class p_classinfo;
|
||||
|
||||
public FlexibleObjectTableModel(Class tClass)
|
||||
{
|
||||
this.columns = new ArrayList<Column>();
|
||||
this.rows = new ArrayList<T>();
|
||||
|
||||
this.p_classinfo = tClass;
|
||||
}
|
||||
|
||||
|
||||
public void addColumn(String fieldName)
|
||||
{
|
||||
this.addColumn(fieldName,true);
|
||||
}
|
||||
public void addColumn(String fieldName,boolean readOnly)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.columns.add(new Column(this.p_classinfo,fieldName,readOnly));
|
||||
fireTableStructureChanged();
|
||||
} catch (NoSuchFieldException nsfex)
|
||||
{
|
||||
System.err.println(nsfex.toString());
|
||||
nsfex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<T> getRows()
|
||||
{
|
||||
return this.rows;
|
||||
}
|
||||
public void setRows(List<T> rows)
|
||||
{
|
||||
this.rows = rows;
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
public int indexOf(Object o)
|
||||
{
|
||||
return this.rows.indexOf(o);
|
||||
}
|
||||
|
||||
public void addRow(T o)
|
||||
{
|
||||
this.rows.add(o);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
public void removeRow(T o)
|
||||
{
|
||||
this.rows.remove(o);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
public void removeRow(int row)
|
||||
{
|
||||
this.rows.remove(row);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return this.columns.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return this.rows.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int arg0, int arg1) {
|
||||
return this.columns.get(arg1).getValue(this.rows.get(arg0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex)
|
||||
{
|
||||
return this.columns.get(columnIndex).getFieldName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object aValue,
|
||||
int rowIndex,
|
||||
int columnIndex)
|
||||
{
|
||||
this.columns.get(columnIndex).setValue(this.rows.get(rowIndex), aValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex,int columnIndex)
|
||||
{
|
||||
return !this.columns.get(columnIndex).getReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int columnIndex)
|
||||
{
|
||||
return this.columns.get(columnIndex).getColumnClass();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.hwo.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
public class ListTableModel extends AbstractTableModel {
|
||||
|
||||
private List<Object[]> rows;
|
||||
|
||||
public ListTableModel()
|
||||
{
|
||||
rows = new ArrayList<Object[]>();
|
||||
rows.add(new Object[]{"Eins","Zwei","Drei"});
|
||||
}
|
||||
|
||||
|
||||
private Integer calcColumnCount()
|
||||
{
|
||||
Integer max = 0;
|
||||
|
||||
for (Object[] record:rows)
|
||||
if (record.length > max)
|
||||
max = record.length;
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return calcColumnCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return rows.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
return rows.get(rowIndex)[columnIndex];
|
||||
}
|
||||
|
||||
|
||||
public List<Object[]> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
public void setRows(List<Object[]> rows) {
|
||||
this.rows = rows;
|
||||
fireTableStructureChanged();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.hwo.models.TableMapper;
|
||||
|
||||
public abstract class AbstractTableMapperListener implements
|
||||
TableMapperListener {
|
||||
|
||||
@Override
|
||||
public void ValueChanged(int row, int column) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.hwo.models.TableMapper;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TableColumn {
|
||||
|
||||
String label() default "";
|
||||
boolean readonly() default false;
|
||||
boolean visible() default true;
|
||||
int width() default 100;
|
||||
String after() default "";
|
||||
boolean firstColumn() default false;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,692 @@
|
|||
package org.hwo.models.TableMapper;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
import org.hwo.csv.CSV;
|
||||
import org.hwo.csv.CSVRecord;
|
||||
import org.hwo.interactiveobjects.InteractiveObjectHelper;
|
||||
import org.hwo.ui.KeyStrokeHelper;
|
||||
import org.hwo.ui.KeyStrokeListener;
|
||||
import org.hwo.ui.KeyStrokeParameters;
|
||||
|
||||
public class TableMapper extends AbstractTableModel
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = -6556060772230310664L;
|
||||
|
||||
public class ColumnInfo
|
||||
{
|
||||
private TableColumn p_annotation;
|
||||
|
||||
private Field p_field;
|
||||
private Method p_method;
|
||||
private String p_label;
|
||||
private boolean p_readonly;
|
||||
private Class<?> p_columnclass;
|
||||
private int width;
|
||||
private TableColumn tableColumn;
|
||||
|
||||
private ColumnInfo nextColumn;
|
||||
|
||||
protected ColumnInfo(TableColumn tc,Field field)
|
||||
{
|
||||
tableColumn = tc;
|
||||
p_annotation = field.getAnnotation(TableColumn.class);
|
||||
|
||||
p_method = null;
|
||||
p_field = field;
|
||||
p_columnclass = field.getType();
|
||||
|
||||
initialize();
|
||||
|
||||
if (p_label.equals(""))
|
||||
p_label = field.getName();
|
||||
|
||||
field.setAccessible(true);
|
||||
}
|
||||
protected ColumnInfo(TableColumn tc,Method method)
|
||||
{
|
||||
tableColumn = tc;
|
||||
p_annotation = method.getAnnotation(TableColumn.class);
|
||||
|
||||
p_method = method;
|
||||
p_field = null;
|
||||
p_columnclass = method.getReturnType();
|
||||
|
||||
initialize();
|
||||
|
||||
if (p_label.equals(""))
|
||||
p_label = method.getName();
|
||||
|
||||
method.setAccessible(true);
|
||||
|
||||
p_readonly = true;
|
||||
}
|
||||
|
||||
private void initialize()
|
||||
{
|
||||
p_label = p_annotation.label();
|
||||
p_readonly = p_annotation.readonly();
|
||||
setWidth(p_annotation.width());
|
||||
}
|
||||
|
||||
public void appendAtEnd(ColumnInfo column)
|
||||
{
|
||||
if (nextColumn == null)
|
||||
nextColumn = column;
|
||||
else
|
||||
nextColumn.appendAtEnd(column);
|
||||
}
|
||||
|
||||
public List<ColumnInfo> toList()
|
||||
{
|
||||
List<ColumnInfo> list = new LinkedList<TableMapper.ColumnInfo>();
|
||||
appendToList(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public void appendToList(List<ColumnInfo> list)
|
||||
{
|
||||
list.add(this);
|
||||
if (nextColumn != null)
|
||||
nextColumn.appendToList(list);
|
||||
}
|
||||
|
||||
public void removeColumn(ColumnInfo ci)
|
||||
{
|
||||
if (nextColumn == ci)
|
||||
{
|
||||
nextColumn = ci.nextColumn;
|
||||
ci.nextColumn = null;
|
||||
} else if (nextColumn != null)
|
||||
nextColumn.removeColumn(ci);
|
||||
}
|
||||
|
||||
public ColumnInfo findColumnByName(String name)
|
||||
{
|
||||
if (this.p_label.equals(name))
|
||||
return this;
|
||||
if (nextColumn!=null)
|
||||
return nextColumn.findColumnByName(name);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public void append(ColumnInfo ci)
|
||||
{
|
||||
ci.nextColumn = nextColumn;
|
||||
nextColumn = ci;
|
||||
}
|
||||
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return this.p_label;
|
||||
}
|
||||
public void setLabel(String label)
|
||||
{
|
||||
this.p_label = label;
|
||||
}
|
||||
|
||||
public boolean getReadOnly()
|
||||
{
|
||||
return this.p_readonly;
|
||||
}
|
||||
public void setReadOnly(boolean readOnly)
|
||||
{
|
||||
this.p_readonly = readOnly;
|
||||
}
|
||||
|
||||
public void setColumnClass(Class<?> cl)
|
||||
{
|
||||
this.p_columnclass = cl;
|
||||
}
|
||||
public Class<?> getColumnClass()
|
||||
{
|
||||
return this.p_columnclass;
|
||||
}
|
||||
|
||||
public Object getValue(Object instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
||||
{
|
||||
if (p_field != null)
|
||||
return p_field.get(instance);
|
||||
if (p_method != null)
|
||||
return p_method.invoke(instance, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue(Object instance,Object value) throws IllegalAccessException
|
||||
{
|
||||
if (p_field != null)
|
||||
p_field.set(instance, value);
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public ColumnInfo getNextColumn() {
|
||||
return nextColumn;
|
||||
}
|
||||
|
||||
public void setNextColumn(ColumnInfo nextColumn) {
|
||||
this.nextColumn = nextColumn;
|
||||
}
|
||||
|
||||
public TableColumn getTableColumn() {
|
||||
return tableColumn;
|
||||
}
|
||||
|
||||
public void setTableColumn(TableColumn tableColumn) {
|
||||
this.tableColumn = tableColumn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Class<?> p_class;
|
||||
|
||||
private ColumnInfo firstColumn;
|
||||
|
||||
private List<Object> p_rows;
|
||||
private List<ColumnInfo> p_columns;
|
||||
private boolean p_readonly; // Table readonly...
|
||||
|
||||
private TableMapperColumnModel
|
||||
columnModel;
|
||||
|
||||
private JTable jTable;
|
||||
|
||||
private TableMapperObject
|
||||
tableMapperObject;
|
||||
private Field editorObjectField;
|
||||
private Class<?> editorObjectClass;
|
||||
|
||||
private MouseAdapter mouseAdapter;
|
||||
|
||||
private boolean editorEnabled;
|
||||
|
||||
private LinkedList<TableMapperListener> tableMapperListeners;
|
||||
|
||||
private KeyStrokeHelper keyStrokeHelper;
|
||||
|
||||
public TableMapper(Class<?> clazz,JTable table)
|
||||
{
|
||||
this.tableMapperListeners = new LinkedList<TableMapperListener>();
|
||||
this.p_class = clazz;
|
||||
this.jTable = table;
|
||||
|
||||
this.firstColumn = null;
|
||||
|
||||
this.p_rows = new LinkedList<Object>();
|
||||
this.p_columns = new ArrayList<TableMapper.ColumnInfo>();
|
||||
this.p_readonly = false;
|
||||
|
||||
this.keyStrokeHelper = new KeyStrokeHelper(jTable);
|
||||
this.keyStrokeHelper.registerKeyStrokeListener(new KeyStrokeListener() {
|
||||
|
||||
@Override
|
||||
public void keyStroke(KeyStrokeParameters parameters) {
|
||||
switch (parameters.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_ENTER:
|
||||
openEditor();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.keyStrokeHelper.addKeyCode(KeyEvent.VK_ENTER);
|
||||
|
||||
initializeMapper();
|
||||
initializeColumnInfo();
|
||||
|
||||
table.setModel(this);
|
||||
table.setColumnModel(new TableMapperColumnModel(this));
|
||||
|
||||
table.setAutoCreateRowSorter(true);
|
||||
|
||||
mouseAdapter = new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
switch (e.getButton())
|
||||
{
|
||||
case 1:
|
||||
if (e.getClickCount()==2)
|
||||
{
|
||||
openEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (InteractiveObjectHelper.isInteractiveObject(editorObjectClass))
|
||||
setEditorEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
private void initializeMapper()
|
||||
{
|
||||
tableMapperObject = p_class.getAnnotation(TableMapperObject.class);
|
||||
if (tableMapperObject != null)
|
||||
{
|
||||
if (tableMapperObject.editorField() != null)
|
||||
{
|
||||
try {
|
||||
editorObjectField = p_class.getDeclaredField(tableMapperObject.editorField());
|
||||
editorObjectField.setAccessible(true);
|
||||
|
||||
editorObjectClass = editorObjectField.getType();
|
||||
|
||||
} catch (SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
} else
|
||||
{
|
||||
editorObjectClass = p_class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addListSelectionListener(ListSelectionListener listener)
|
||||
{
|
||||
jTable.getSelectionModel().addListSelectionListener(listener);
|
||||
}
|
||||
public void removeListSelectionListener(ListSelectionListener listener)
|
||||
{
|
||||
jTable.getSelectionModel().removeListSelectionListener(listener);
|
||||
}
|
||||
|
||||
public void addTableMapperListener(TableMapperListener listener)
|
||||
{
|
||||
tableMapperListeners.add(listener);
|
||||
}
|
||||
public void removeTableMapperListener(TableMapperListener listener)
|
||||
{
|
||||
tableMapperListeners.remove(listener);
|
||||
}
|
||||
|
||||
protected void fireValueChanged(int row,int column)
|
||||
{
|
||||
for (TableMapperListener listener: tableMapperListeners)
|
||||
listener.ValueChanged(row, column);
|
||||
}
|
||||
|
||||
private Object getEditorObject()
|
||||
{
|
||||
if (jTable.getSelectedRow()!=-1)
|
||||
{
|
||||
int row = jTable.convertRowIndexToModel(jTable.getSelectedRow());
|
||||
Object rowObject = p_rows.get(row);
|
||||
if (editorObjectField == null)
|
||||
return rowObject;
|
||||
|
||||
try {
|
||||
Object editorObject = editorObjectField.get(rowObject);
|
||||
return editorObject;
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void openEditor()
|
||||
{
|
||||
Object editorObject = getEditorObject();
|
||||
if (editorObject!=null)
|
||||
InteractiveObjectHelper.showEditor(editorObject);
|
||||
}
|
||||
|
||||
public List<ColumnInfo> getColumnInfo()
|
||||
{
|
||||
return p_columns;
|
||||
}
|
||||
|
||||
public void setRows(List rows)
|
||||
{
|
||||
this.p_rows = rows;
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public void setRows(Object[] rows)
|
||||
{
|
||||
this.p_rows = Arrays.asList(rows);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public List getRows()
|
||||
{
|
||||
return this.p_rows;
|
||||
}
|
||||
|
||||
public <T> List<T> getRows(Class<T> clazz)
|
||||
{
|
||||
return (List<T>) p_rows;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.p_rows.clear();
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public boolean isEditorEnabled()
|
||||
{
|
||||
return editorEnabled;
|
||||
}
|
||||
|
||||
public void setEditorEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled)
|
||||
jTable.addMouseListener(mouseAdapter);
|
||||
else
|
||||
jTable.removeMouseListener(mouseAdapter);
|
||||
|
||||
editorEnabled = enabled;
|
||||
}
|
||||
|
||||
private void addColumnInfo(ColumnInfo ci)
|
||||
{
|
||||
if (ci.getTableColumn().firstColumn())
|
||||
p_columns.add(0,ci);
|
||||
else
|
||||
p_columns.add(ci);
|
||||
/*
|
||||
if (firstColumn == null)
|
||||
firstColumn = ci;
|
||||
else
|
||||
{
|
||||
if (ci.getTableColumn().firstColumn())
|
||||
{
|
||||
ci.setNextColumn(firstColumn);
|
||||
firstColumn = ci;
|
||||
} else
|
||||
firstColumn.appendAtEnd(ci);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void addFieldsOfClass(Class<?> clazz)
|
||||
{
|
||||
if (clazz.getSuperclass() != null)
|
||||
addFieldsOfClass(clazz.getSuperclass());
|
||||
|
||||
for (Field field: clazz.getDeclaredFields())
|
||||
{
|
||||
if (field.getAnnotation(TableColumn.class)!=null)
|
||||
{
|
||||
ColumnInfo ci = new ColumnInfo(field.getAnnotation(TableColumn.class),field);
|
||||
addColumnInfo(ci);
|
||||
}
|
||||
}
|
||||
|
||||
for (Method method: clazz.getDeclaredMethods())
|
||||
{
|
||||
if (method.getAnnotation(TableColumn.class)!=null)
|
||||
{
|
||||
ColumnInfo ci = new ColumnInfo(method.getAnnotation(TableColumn.class),method);
|
||||
addColumnInfo(ci);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private int findColumnIndexByName(String name)
|
||||
{
|
||||
for (int i=0;i<p_columns.size();i++)
|
||||
{
|
||||
if (p_columns.get(i).p_label.equals(name))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void reorderColumns()
|
||||
{
|
||||
List<ColumnInfo> lc = new ArrayList<TableMapper.ColumnInfo>(p_columns);
|
||||
|
||||
for (ColumnInfo ci:lc)
|
||||
{
|
||||
if (!ci.getTableColumn().after().equals(""))
|
||||
{
|
||||
int indColumn = p_columns.indexOf(ci);
|
||||
int indBefore = findColumnIndexByName(ci.getTableColumn().after());
|
||||
if (indBefore != -1)
|
||||
{
|
||||
if (indBefore < indColumn)
|
||||
{
|
||||
List<ColumnInfo> subset = new ArrayList<TableMapper.ColumnInfo>(p_columns.subList(indColumn, p_columns.size()));
|
||||
p_columns.removeAll(subset);
|
||||
p_columns.addAll(indBefore+1, subset);
|
||||
} else
|
||||
{
|
||||
List<ColumnInfo> subset = new ArrayList<TableMapper.ColumnInfo>(p_columns.subList(indColumn, indBefore));
|
||||
p_columns.removeAll(subset);
|
||||
p_columns.addAll(indColumn+1, subset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeColumnInfo()
|
||||
{
|
||||
addFieldsOfClass(p_class);
|
||||
reorderColumns();
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly)
|
||||
{
|
||||
this.p_readonly = readOnly;
|
||||
}
|
||||
public boolean getReadOnly()
|
||||
{
|
||||
return this.p_readonly;
|
||||
}
|
||||
|
||||
public void addRow(Object row)
|
||||
{
|
||||
this.p_rows.add(row);
|
||||
//fireTableRowsInserted(getRowCount()-1, getRowCount()-1);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
public void removeRow(Object row)
|
||||
{
|
||||
int index = this.p_rows.indexOf(row);
|
||||
if (index != -1)
|
||||
{
|
||||
this.p_rows.remove(index);
|
||||
fireTableRowsDeleted(index, index);
|
||||
};
|
||||
}
|
||||
|
||||
public Object getRow(int index)
|
||||
{
|
||||
return this.p_rows.get(index);
|
||||
}
|
||||
|
||||
public <T> T getRow(int index,Class<T> clazz)
|
||||
{
|
||||
return (T)this.p_rows.get(index);
|
||||
}
|
||||
|
||||
public Object appendNewInstance()
|
||||
{
|
||||
try
|
||||
{
|
||||
Object instance = this.p_class.newInstance();
|
||||
if (instance != null)
|
||||
addRow(instance);
|
||||
return instance;
|
||||
} catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return this.p_columns.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return this.p_rows.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
if ( (rowIndex < this.p_rows.size()) && (columnIndex < this.p_columns.size()))
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.p_columns.get(columnIndex).getValue(this.p_rows.get(rowIndex));
|
||||
} catch (Exception ex)
|
||||
{
|
||||
System.err.println("Exception: " + ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object aValue,
|
||||
int rowIndex,
|
||||
int columnIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.p_columns.get(columnIndex).setValue(this.p_rows.get(rowIndex), aValue);
|
||||
fireValueChanged(rowIndex, columnIndex);
|
||||
} catch (IllegalAccessException ex)
|
||||
{
|
||||
System.err.println("IllegalAccessException: " + ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex,int columnIndex)
|
||||
{
|
||||
if (this.p_readonly)
|
||||
return false;
|
||||
return !this.p_columns.get(columnIndex).getReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int columnIndex)
|
||||
{
|
||||
Class<?> c = this.p_columns.get(columnIndex).getColumnClass();
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex)
|
||||
{
|
||||
return this.p_columns.get(columnIndex).getLabel();
|
||||
}
|
||||
|
||||
public Object getSelectedRow()
|
||||
{
|
||||
if (jTable.getSelectedRow()!=-1)
|
||||
{
|
||||
return this.p_rows.get(jTable.convertRowIndexToModel(jTable.getSelectedRow()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getSelectedRows()
|
||||
{
|
||||
int[] idx = jTable.getSelectedRows();
|
||||
Object[] result = new Object[ idx.length ];
|
||||
|
||||
for (int i=0;i<result.length;i++){
|
||||
result[i] = this.p_rows.get(jTable.convertRowIndexToModel(idx[i]));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> T[] getSelectedRows(T[] template){
|
||||
Object[] l = getSelectedRows();
|
||||
T[] result = Arrays.copyOf(template, l.length);
|
||||
|
||||
for (int i=0;i<l.length;i++){
|
||||
result[i] = (T)l[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean exportToFile(File exportFile)
|
||||
{
|
||||
CSV csv = new CSV();
|
||||
|
||||
List<CSVRecord> cells = csv.getRecords();
|
||||
|
||||
CSVRecord header = new CSVRecord();
|
||||
for (int i=0;i<getColumnCount();i++)
|
||||
header.appendValue(p_columns.get(i).getLabel());
|
||||
|
||||
cells.add(header);
|
||||
|
||||
for (int row=0;row<getRowCount();row++)
|
||||
{
|
||||
CSVRecord record = new CSVRecord();
|
||||
|
||||
for (int column=0;column<getColumnCount();column++)
|
||||
if (getValueAt(row, column)!=null)
|
||||
record.appendValue(getValueAt(row, column).toString());
|
||||
else
|
||||
record.appendValue("");
|
||||
|
||||
cells.add(record);
|
||||
}
|
||||
|
||||
csv.saveToFile(exportFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,170 @@
|
|||
package org.hwo.models.TableMapper;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.DefaultListSelectionModel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.TableColumnModelListener;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
import org.hwo.models.TableMapper.TableMapper.ColumnInfo;
|
||||
|
||||
class TableMapperColumnModel implements TableColumnModel{
|
||||
|
||||
private TableMapper tableMapper;
|
||||
private LinkedList<TableColumnModelListener> listeners;
|
||||
|
||||
private ArrayList<TableColumn> tableColumns;
|
||||
|
||||
private int margin;
|
||||
|
||||
private ListSelectionModel listSelectionModel;
|
||||
|
||||
public TableMapperColumnModel(TableMapper tableMapper)
|
||||
{
|
||||
this.tableMapper = tableMapper;
|
||||
this.listeners = new LinkedList<TableColumnModelListener>();
|
||||
this.tableColumns = new ArrayList<TableColumn>();
|
||||
this.listSelectionModel = new DefaultListSelectionModel();
|
||||
|
||||
for (int i=0;i<tableMapper.getColumnCount();i++)
|
||||
{
|
||||
ColumnInfo ci = tableMapper.getColumnInfo().get(i);
|
||||
TableColumn tc = new TableColumn(i, ci.getWidth());
|
||||
tc.setPreferredWidth(ci.getWidth());
|
||||
tc.setHeaderValue(ci.getLabel());
|
||||
tc.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent arg0) {
|
||||
fireColumnMarginChanged();
|
||||
}
|
||||
});
|
||||
tableColumns.add(tc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void fireColumnMarginChanged()
|
||||
{
|
||||
for (TableColumnModelListener listener:listeners)
|
||||
listener.columnMarginChanged(new ChangeEvent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumn(TableColumn aColumn) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumnModelListener(TableColumnModelListener x) {
|
||||
listeners.add(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColumnModelListener(TableColumnModelListener x) {
|
||||
listeners.remove(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public TableColumn getColumn(int columnIndex) {
|
||||
return tableColumns.get(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return tableColumns.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnIndex(Object columnIdentifier) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnIndexAtX(int xPosition) {
|
||||
int pos = 0;
|
||||
for (int i=0;i<tableColumns.size();i++)
|
||||
{
|
||||
pos += tableColumns.get(i).getWidth();
|
||||
|
||||
if (xPosition < pos)
|
||||
return i;
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnMargin() {
|
||||
return margin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getColumnSelectionAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<TableColumn> getColumns() {
|
||||
return new Vector<TableColumn>(tableColumns).elements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSelectedColumnCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSelectedColumns() {
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListSelectionModel getSelectionModel() {
|
||||
return listSelectionModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalColumnWidth() {
|
||||
int width = 0;
|
||||
for (TableColumn tc:tableColumns)
|
||||
width += tc.getWidth();
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveColumn(int columnIndex, int newIndex) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColumn(TableColumn column) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColumnMargin(int newMargin) {
|
||||
margin = newMargin;
|
||||
fireColumnMarginChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColumnSelectionAllowed(boolean flag) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectionModel(ListSelectionModel newModel) {
|
||||
listSelectionModel = newModel;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.hwo.models.TableMapper;
|
||||
|
||||
public interface TableMapperListener {
|
||||
|
||||
public void ValueChanged(int row,int column);
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.hwo.models.TableMapper;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TableMapperObject {
|
||||
|
||||
String editorField();
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import org.hwo.ui.treetable.TreeTable;
|
||||
|
||||
public interface CellEditor {
|
||||
|
||||
public void addCellEditorListener(CellEditorListener listener);
|
||||
public void removeCellEditorListener(CellEditorListener listener);
|
||||
|
||||
public boolean editBegin(TreeTable treeTable,Rectangle rect,Object value);
|
||||
public void editCancel();
|
||||
public void editFinish();
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import org.hwo.ui.treetable.TreeTable;
|
||||
|
||||
public class CellEditorArgs {
|
||||
|
||||
private CellEditor cellEditor;
|
||||
private Object value;
|
||||
private TreeTable treeTable;
|
||||
|
||||
public CellEditorArgs(CellEditor cellEditor,Object value,TreeTable treeTable)
|
||||
{
|
||||
this.cellEditor = cellEditor;
|
||||
this.value = value;
|
||||
this.treeTable = treeTable;
|
||||
}
|
||||
|
||||
public CellEditor getCellEditor() {
|
||||
return cellEditor;
|
||||
}
|
||||
public void setCellEditor(CellEditor cellEditor) {
|
||||
this.cellEditor = cellEditor;
|
||||
}
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
public TreeTable getTreeTable() {
|
||||
return treeTable;
|
||||
}
|
||||
public void setTreeTable(TreeTable treeTable) {
|
||||
this.treeTable = treeTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
public interface CellEditorListener {
|
||||
|
||||
public void editBegin(CellEditorArgs args);
|
||||
public void editCanceled(CellEditorArgs args);
|
||||
public void editFinished(CellEditorArgs args);
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
public interface CellRenderer {
|
||||
|
||||
public void renderCell(Graphics g,int row,int column,Rectangle cellRect,Object value,Object rowObject);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.hwo.ui.treetable.TreeTable;
|
||||
|
||||
public class DefaultCellEditor implements CellEditor {
|
||||
|
||||
private List<CellEditorListener> editorListeners;
|
||||
|
||||
private JTextField textField;
|
||||
private TreeTable treeTable;
|
||||
private Object value;
|
||||
|
||||
public DefaultCellEditor()
|
||||
{
|
||||
editorListeners = new LinkedList<CellEditorListener>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCellEditorListener(CellEditorListener listener) {
|
||||
editorListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCellEditorListener(CellEditorListener listener) {
|
||||
editorListeners.remove(listener);
|
||||
}
|
||||
|
||||
private void fireEditBegin()
|
||||
{
|
||||
CellEditorArgs args = new CellEditorArgs(this, value, treeTable);
|
||||
for (CellEditorListener listener: editorListeners)
|
||||
listener.editBegin(args);
|
||||
}
|
||||
private void fireEditFinish()
|
||||
{
|
||||
CellEditorArgs args = new CellEditorArgs(this, value, treeTable);
|
||||
for (CellEditorListener listener: editorListeners)
|
||||
listener.editFinished(args);
|
||||
}
|
||||
private void fireEditCancel()
|
||||
{
|
||||
CellEditorArgs args = new CellEditorArgs(this, value, treeTable);
|
||||
for (CellEditorListener listener: editorListeners)
|
||||
listener.editCanceled(args);
|
||||
}
|
||||
|
||||
private void destroyTextField()
|
||||
{
|
||||
textField.setVisible(false);
|
||||
Container parent = textField.getParent();
|
||||
|
||||
parent.remove(textField);
|
||||
|
||||
textField = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean editBegin(TreeTable treeTable, Rectangle rect, Object value) {
|
||||
if (textField != null)
|
||||
editCancel();
|
||||
|
||||
this.treeTable = treeTable;
|
||||
this.value = value;
|
||||
|
||||
this.textField = new JTextField();
|
||||
treeTable.add(textField);
|
||||
|
||||
textField.setBounds(rect);
|
||||
textField.requestFocusInWindow();
|
||||
textField.repaint();
|
||||
|
||||
fireEditBegin();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editCancel() {
|
||||
if (textField != null)
|
||||
{
|
||||
destroyTextField();
|
||||
|
||||
fireEditCancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editFinish() {
|
||||
if (this.textField != null)
|
||||
{
|
||||
this.value = this.textField.getText();
|
||||
destroyTextField();
|
||||
|
||||
fireEditFinish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
public class DefaultCellRenderer implements CellRenderer{
|
||||
|
||||
@Override
|
||||
public void renderCell(Graphics g,int row,int column, Rectangle cellRect, Object value,Object rowObject)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
g.drawString( value.toString(),
|
||||
cellRect.x + 2,
|
||||
cellRect.y + cellRect.height - 4
|
||||
);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import org.hwo.models.FlexibleObjectTableModel;
|
||||
|
||||
public class FlexibleJTable<T> extends JTable {
|
||||
private FlexibleObjectTableModel<T> model;
|
||||
|
||||
public FlexibleJTable(Class class_t)
|
||||
{
|
||||
this.model = new FlexibleObjectTableModel<T>(class_t);
|
||||
this.setModel(this.model);
|
||||
}
|
||||
|
||||
public FlexibleObjectTableModel<T> getModel()
|
||||
{
|
||||
return this.model;
|
||||
}
|
||||
|
||||
public T getSelectedObject()
|
||||
{
|
||||
if (this.getSelectedRow()==-1)
|
||||
return null;
|
||||
return this.model.getRows().get(this.getSelectedRow());
|
||||
}
|
||||
|
||||
public void addListSelectionListener(ListSelectionListener listener)
|
||||
{
|
||||
this.getSelectionModel().addListSelectionListener(listener);
|
||||
}
|
||||
|
||||
public void removeListSelectionListener(ListSelectionListener listener)
|
||||
{
|
||||
this.getSelectionModel().removeListSelectionListener(listener);
|
||||
}
|
||||
|
||||
public void addColumn(String column)
|
||||
{
|
||||
this.addColumn(column, true);
|
||||
}
|
||||
|
||||
public void addColumn(String column,boolean readonly)
|
||||
{
|
||||
this.model.addColumn(column,readonly);
|
||||
}
|
||||
|
||||
public void setRows(List<T> rows)
|
||||
{
|
||||
this.model.setRows(rows);
|
||||
}
|
||||
|
||||
public void addRow(T o)
|
||||
{
|
||||
this.model.addRow(o);
|
||||
}
|
||||
|
||||
public int getRowCount()
|
||||
{
|
||||
return this.model.getRowCount();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JList;
|
||||
|
||||
import org.hwo.interactiveobjects.IInteractiveObjectEditor;
|
||||
import org.hwo.interactiveobjects.InteractiveObjectHelper;
|
||||
|
||||
public class InteractiveObjectListView extends JList {
|
||||
|
||||
DefaultListModel pModel;
|
||||
|
||||
public InteractiveObjectListView()
|
||||
{
|
||||
this.addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
if (arg0.getClickCount()==2)
|
||||
openEditor();
|
||||
}
|
||||
});
|
||||
pModel = new DefaultListModel();
|
||||
setModel(pModel);
|
||||
}
|
||||
|
||||
private void openEditor()
|
||||
{
|
||||
if (getSelectedIndex() != -1)
|
||||
{
|
||||
IInteractiveObjectEditor oe = InteractiveObjectHelper.getEditor(getSelectedValue());
|
||||
if (oe != null)
|
||||
oe.setVisible(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setItems(List items)
|
||||
{
|
||||
pModel.clear();
|
||||
for (Object o:items)
|
||||
{
|
||||
pModel.addElement(o);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class JBackgroundPane extends JPanel {
|
||||
|
||||
private Image backgroundImage;
|
||||
private boolean scaleBackground;
|
||||
|
||||
public JBackgroundPane()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics arg0) {
|
||||
super.paintComponent(arg0);
|
||||
if (backgroundImage != null)
|
||||
{
|
||||
int w,h;
|
||||
if (scaleBackground)
|
||||
{
|
||||
w = getWidth();
|
||||
h = getHeight();
|
||||
} else
|
||||
{
|
||||
w = backgroundImage.getWidth(null);
|
||||
h = backgroundImage.getHeight(null);
|
||||
}
|
||||
arg0.drawImage(backgroundImage, 0, 0, w, h, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Image getBackgroundImage() {
|
||||
return backgroundImage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setBackgroundImage(Image backgroundImage) {
|
||||
this.backgroundImage = backgroundImage;
|
||||
|
||||
Dimension pSize = new Dimension(backgroundImage.getWidth(null), backgroundImage.getHeight(null) );
|
||||
this.setPreferredSize(pSize);
|
||||
}
|
||||
|
||||
public boolean isScaleBackground() {
|
||||
return scaleBackground;
|
||||
}
|
||||
|
||||
public void setScaleBackground(boolean scaleBackground) {
|
||||
this.scaleBackground = scaleBackground;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JButton;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.awt.Dimension;
|
||||
|
||||
public class JCalendar extends JPanel {
|
||||
private JTextField tfDate;
|
||||
|
||||
private Date date;
|
||||
private JButton btnLookup;
|
||||
private boolean nullable;
|
||||
|
||||
public JCalendar() {
|
||||
setMaximumSize(new Dimension(32767, 30));
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{100, 134, 0};
|
||||
gridBagLayout.rowHeights = new int[]{29, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
tfDate = new JTextField();
|
||||
GridBagConstraints gbc_tfDate = new GridBagConstraints();
|
||||
gbc_tfDate.fill = GridBagConstraints.BOTH;
|
||||
gbc_tfDate.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_tfDate.gridx = 0;
|
||||
gbc_tfDate.gridy = 0;
|
||||
add(tfDate, gbc_tfDate);
|
||||
tfDate.setColumns(10);
|
||||
|
||||
btnLookup = new JButton("X");
|
||||
btnLookup.setMaximumSize(new Dimension(25, 29));
|
||||
btnLookup.setPreferredSize(new Dimension(25, 29));
|
||||
btnLookup.setMinimumSize(new Dimension(25, 29));
|
||||
GridBagConstraints gbc_btnLookup = new GridBagConstraints();
|
||||
gbc_btnLookup.fill = GridBagConstraints.BOTH;
|
||||
gbc_btnLookup.gridx = 1;
|
||||
gbc_btnLookup.gridy = 0;
|
||||
add(btnLookup, gbc_btnLookup);
|
||||
}
|
||||
|
||||
private void updateView()
|
||||
{
|
||||
tfDate.setEnabled(false);
|
||||
|
||||
if (date != null)
|
||||
{
|
||||
btnLookup.setEnabled(false);
|
||||
tfDate.setText( SimpleDateFormat.getInstance().format(date));
|
||||
} else
|
||||
{
|
||||
btnLookup.setEnabled(false);
|
||||
tfDate.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
updateView();
|
||||
}
|
||||
|
||||
public void setValue(Object value)
|
||||
{
|
||||
setDate((Date)value);
|
||||
}
|
||||
public Object getValue()
|
||||
{
|
||||
return this.getDate();
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
public void setNullable(boolean nullable) {
|
||||
this.nullable = nullable;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
public class JComboBoxEx extends JComboBox {
|
||||
|
||||
|
||||
public void selectEqualItem(Object o)
|
||||
{
|
||||
for (int i=0;i<getItemCount();i++)
|
||||
if (getItemAt(i).equals(o))
|
||||
{
|
||||
setSelectedIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void setItems(Object[] items){
|
||||
removeAllItems();
|
||||
for (Object o:items)
|
||||
addItem(o);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.hwo.ui.diagram.Diagram;
|
||||
|
||||
public class JDiagram extends JPanel {
|
||||
|
||||
private Diagram diagram;
|
||||
|
||||
public JDiagram(){
|
||||
setMinimumSize(new Dimension(80, 80));
|
||||
diagram = new Diagram();
|
||||
diagram.setFont( getFont() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
this.diagram.plot((Graphics2D)g, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
public Diagram getDiagram() {
|
||||
return diagram;
|
||||
}
|
||||
public void setDiagram(Diagram diagram) {
|
||||
this.diagram = diagram;
|
||||
}
|
||||
|
||||
public int getNumLabels(){
|
||||
return this.diagram.getNumLabels();
|
||||
}
|
||||
public void setNumLabels(int nLabels){
|
||||
this.diagram.setNumLabels(nLabels);
|
||||
}
|
||||
|
||||
public String getLabelFormatSpec(){
|
||||
return this.diagram.getLabelFormatSpec();
|
||||
}
|
||||
public void setLabelFormatSpec(String spec){
|
||||
this.diagram.setLabelFormatSpec(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Font getFont() {
|
||||
return super.getFont();
|
||||
}
|
||||
@Override
|
||||
public void setFont(Font font) {
|
||||
if (diagram != null)
|
||||
diagram.setFont(font);
|
||||
super.setFont(font);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
import javax.swing.JList;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
|
||||
public class JObjectSelector extends JDialog {
|
||||
|
||||
public static Object execute(Object[] items){
|
||||
|
||||
JObjectSelector os = new JObjectSelector();
|
||||
os.setItems(items);
|
||||
os.setVisible(true);
|
||||
return os.selectedItem;
|
||||
}
|
||||
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JList lItems;
|
||||
|
||||
private Object[] items;
|
||||
private Object selectedItem;
|
||||
private JLabel lText;
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public JObjectSelector() {
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
setTitle("Auswahl\u2026");
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
lText = new JLabel("-");
|
||||
GridBagConstraints gbc_lText = new GridBagConstraints();
|
||||
gbc_lText.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lText.gridx = 0;
|
||||
gbc_lText.gridy = 0;
|
||||
contentPanel.add(lText, gbc_lText);
|
||||
}
|
||||
{
|
||||
lItems = new JList();
|
||||
GridBagConstraints gbc_lItems = new GridBagConstraints();
|
||||
gbc_lItems.fill = GridBagConstraints.BOTH;
|
||||
gbc_lItems.gridx = 0;
|
||||
gbc_lItems.gridy = 1;
|
||||
contentPanel.add(lItems, gbc_lItems);
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
accept();
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void accept()
|
||||
{
|
||||
selectedItem = lItems.getSelectedValue();
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public void cancel(){
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public void setItems(Object[] items) {
|
||||
this.items = items;
|
||||
DefaultListModel dlm = new DefaultListModel();
|
||||
for (Object o:items){
|
||||
dlm.addElement(o);
|
||||
}
|
||||
lItems.setModel(dlm);
|
||||
}
|
||||
public Object[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setText(String text){
|
||||
this.lText.setText(text);
|
||||
}
|
||||
public String getText(){
|
||||
return this.lText.getText();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class JOptionGroup extends JComponent {
|
||||
JCheckBox checkBoxes[];
|
||||
private String[] options;
|
||||
|
||||
private String[] selectedOptions;
|
||||
|
||||
public JOptionGroup()
|
||||
{
|
||||
FlowLayout layout = new FlowLayout(FlowLayout.LEADING);
|
||||
|
||||
setLayout(layout);
|
||||
options = new String[0];
|
||||
checkBoxes = new JCheckBox[0];
|
||||
|
||||
setPreferredSize(new Dimension(270, 29));
|
||||
}
|
||||
|
||||
public String[] getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public void setOptions(String[] options) {
|
||||
this.options = options;
|
||||
if (options == null)
|
||||
options = new String[0];
|
||||
|
||||
rebuildOptions();
|
||||
|
||||
if (selectedOptions != null)
|
||||
setSelectedOptions(selectedOptions);
|
||||
|
||||
}
|
||||
|
||||
private void rebuildOptions()
|
||||
{
|
||||
for (JCheckBox cb:checkBoxes)
|
||||
{
|
||||
remove(cb);
|
||||
}
|
||||
|
||||
checkBoxes = new JCheckBox[ options.length ];
|
||||
|
||||
for (int n=0; n < options.length; n++)
|
||||
{
|
||||
checkBoxes[n] = new JCheckBox();
|
||||
checkBoxes[n].setText(options[n]);
|
||||
|
||||
add(checkBoxes[n]);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public int getOptionIndex(String option)
|
||||
{
|
||||
for (int n=0; n < options.length; n++)
|
||||
{
|
||||
if (options[n].equals(option))
|
||||
return n;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Boolean isOptionSelected(String option)
|
||||
{
|
||||
int no = getOptionIndex(option);
|
||||
if (no >= 0)
|
||||
{
|
||||
return checkBoxes[no].isSelected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void selectOption(String option)
|
||||
{
|
||||
int no = getOptionIndex(option);
|
||||
if (no >= 0)
|
||||
{
|
||||
checkBoxes[no].setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void unselectOption(String option)
|
||||
{
|
||||
int no = getOptionIndex(option);
|
||||
if (no >= 0)
|
||||
{
|
||||
checkBoxes[no].setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getSelectedOptions()
|
||||
{
|
||||
ArrayList<String> ol = new ArrayList<String>();
|
||||
for (int n=0; n < options.length; n++)
|
||||
{
|
||||
if (checkBoxes[n].isSelected())
|
||||
ol.add(options[n]);
|
||||
}
|
||||
return ol.toArray(new String[0]);
|
||||
}
|
||||
public void setSelectedOptions(String[] selectedOptions)
|
||||
{
|
||||
this.selectedOptions = selectedOptions;
|
||||
|
||||
for (int n=0; n < options.length; n++)
|
||||
checkBoxes[n].setSelected(false);
|
||||
|
||||
for (String option:selectedOptions)
|
||||
selectOption(option);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,324 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SingleSelectionModel;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import org.hwo.datetime.JTimeOfDay;
|
||||
import org.hwo.models.TableMapper.TableMapper;
|
||||
import org.hwo.ui.wellknown.WellKnown;
|
||||
import org.hwo.ui.wellknown.WellKnownClass;
|
||||
import org.hwo.ui.wellknown.WellKnownSearch;
|
||||
|
||||
public class JSearchTextField extends JTextField implements FocusListener {
|
||||
|
||||
private Class<?> searchClazz;
|
||||
private JTable tResults;
|
||||
private TableMapper tmResults;
|
||||
|
||||
private JPopupMenu popupList;
|
||||
|
||||
private Timer searchTimer;
|
||||
|
||||
private WellKnownClass wellKnownClass;
|
||||
private WellKnownSearch wellKnownSearch;
|
||||
|
||||
private Object selectedObject;
|
||||
|
||||
private List<ActionListener> actionListeners;
|
||||
|
||||
public JSearchTextField()
|
||||
{
|
||||
actionListeners = new LinkedList<ActionListener>();
|
||||
|
||||
setPreferredSize(new Dimension(120, 24));
|
||||
|
||||
searchClazz = null;
|
||||
|
||||
popupList = new JPopupMenu();
|
||||
popupList.setFocusable(false);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
tResults = new JTable();
|
||||
|
||||
tResults.setCellSelectionEnabled(false);
|
||||
tResults.setColumnSelectionAllowed(false);
|
||||
tResults.setRowSelectionAllowed(true);
|
||||
|
||||
scrollPane.setViewportView(tResults);
|
||||
popupList.add(scrollPane);
|
||||
|
||||
addFocusListener(this);
|
||||
|
||||
getDocument().addDocumentListener(new DocumentListener() {
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent arg0) {
|
||||
searchTimer.stop();
|
||||
searchTimer.start();
|
||||
showPopup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent arg0) {
|
||||
//showPopup();
|
||||
}
|
||||
});
|
||||
|
||||
KeyStrokeHelper helper = new KeyStrokeHelper(this);
|
||||
helper.registerKeyStrokeListener(new KeyStrokeListener() {
|
||||
|
||||
@Override
|
||||
public void keyStroke(KeyStrokeParameters parameters) {
|
||||
switch (parameters.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
popupList.setVisible(false);
|
||||
break;
|
||||
case KeyEvent.VK_UP:
|
||||
selectionUp();
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
selectionDown();
|
||||
break;
|
||||
case KeyEvent.VK_ENTER:
|
||||
selectObject();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
helper.addKeyCode(KeyEvent.VK_ESCAPE)
|
||||
.addKeyCode(KeyEvent.VK_UP)
|
||||
.addKeyCode(KeyEvent.VK_DOWN)
|
||||
.addKeyCode(KeyEvent.VK_ENTER);
|
||||
|
||||
|
||||
searchTimer = new Timer(250, new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
search();
|
||||
}
|
||||
});
|
||||
searchTimer.setRepeats(false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addActionListener(ActionListener l) {
|
||||
actionListeners.add(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeActionListener(ActionListener l) {
|
||||
actionListeners.remove(l);
|
||||
}
|
||||
|
||||
protected void fireNewActionPerformed()
|
||||
{
|
||||
for (ActionListener l:actionListeners)
|
||||
l.actionPerformed(new ActionEvent(this, 0, ""));
|
||||
}
|
||||
|
||||
private void selectObject()
|
||||
{
|
||||
if (!popupList.isVisible())
|
||||
return;
|
||||
|
||||
Object o = tmResults.getSelectedRow();
|
||||
if (o != null)
|
||||
{
|
||||
setSelectedObject(o);
|
||||
fireNewActionPerformed();
|
||||
transferFocus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void search()
|
||||
{
|
||||
System.err.println("searching...");
|
||||
if (wellKnownSearch != null)
|
||||
{
|
||||
List<Object> l = wellKnownSearch.keywordSearch(searchClazz, getText());
|
||||
tmResults.setRows(l);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectionDown()
|
||||
{
|
||||
if (!popupList.isVisible())
|
||||
showPopup();
|
||||
|
||||
if (tResults.getSelectedRow()!=-1)
|
||||
{
|
||||
if (tResults.getSelectedRow() < tmResults.getRowCount() - 1)
|
||||
{
|
||||
tResults.setRowSelectionInterval(tResults.getSelectedRow() + 1,tResults.getSelectedRow() + 1);
|
||||
System.err.println("down");
|
||||
}
|
||||
} else
|
||||
{
|
||||
System.err.println("Select first");
|
||||
tResults.setRowSelectionInterval(0, 0);
|
||||
}
|
||||
|
||||
selectedObject = null;
|
||||
|
||||
}
|
||||
|
||||
private void selectionUp()
|
||||
{
|
||||
if (!popupList.isVisible())
|
||||
return;
|
||||
|
||||
if (tResults.getSelectedRow()!=-1)
|
||||
{
|
||||
if (tResults.getSelectedRow() > 0)
|
||||
{
|
||||
tResults.setRowSelectionInterval(tResults.getSelectedRow()-1,tResults.getSelectedRow()-1);
|
||||
System.err.println("up");
|
||||
}
|
||||
} else
|
||||
{
|
||||
System.err.println("Select last");
|
||||
tResults.setRowSelectionInterval(tmResults.getRowCount() - 1, tmResults.getRowCount() - 1);
|
||||
}
|
||||
|
||||
selectedObject = null;
|
||||
|
||||
}
|
||||
|
||||
private void showPopup()
|
||||
{
|
||||
if (searchClazz == null)
|
||||
return;
|
||||
|
||||
if (!popupList.isVisible())
|
||||
{
|
||||
popupList.setPopupSize(getSize().width, 250);
|
||||
popupList.show(this, 0, getHeight());
|
||||
popupList.setVisible(true);
|
||||
grabFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void focusGained(FocusEvent arg0) {
|
||||
if (selectedObject != null)
|
||||
selectAll();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent arg0) {
|
||||
if (popupList.isVisible())
|
||||
popupList.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
public Class<?> getSearchClazz() {
|
||||
return searchClazz;
|
||||
}
|
||||
|
||||
public void setSearchClazz(Class<?> searchClazz) {
|
||||
this.searchClazz = searchClazz;
|
||||
|
||||
tmResults = new TableMapper(searchClazz, tResults);
|
||||
tmResults.setReadOnly(true);
|
||||
tmResults.setEditorEnabled(false);
|
||||
|
||||
tResults.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2))
|
||||
{
|
||||
Object so = tmResults.getSelectedRow();
|
||||
if (so != null)
|
||||
{
|
||||
setSelectedObject(so);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
wellKnownClass = WellKnown.getWellKnownClass(searchClazz);
|
||||
if (wellKnownClass != null)
|
||||
{
|
||||
if (wellKnownClass.search() != null)
|
||||
{
|
||||
Class<? extends WellKnownSearch> clazz = wellKnownClass.search();
|
||||
try {
|
||||
wellKnownSearch = clazz.newInstance();
|
||||
wellKnownSearch.setClazz(searchClazz);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setMaxPopupHeight(int maxPopupHeight)
|
||||
{
|
||||
Dimension dim = popupList.getMaximumSize();
|
||||
dim.height = maxPopupHeight;
|
||||
popupList.setMaximumSize(dim);
|
||||
}
|
||||
public int getMaxPopupHeight()
|
||||
{
|
||||
return (int)popupList.getMaximumSize().getHeight();
|
||||
}
|
||||
|
||||
public Object getSelectedObject() {
|
||||
return selectedObject;
|
||||
}
|
||||
|
||||
public void setSelectedObject(Object selectedObject) {
|
||||
this.selectedObject = selectedObject;
|
||||
|
||||
if (selectedObject == null)
|
||||
{
|
||||
setText("");
|
||||
} else
|
||||
{
|
||||
setText(WellKnown.getDisplayLabel(selectedObject));
|
||||
}
|
||||
|
||||
popupList.setVisible(false);
|
||||
fireNewActionPerformed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
import org.hwo.ui.toolbar.UITool;
|
||||
|
||||
public class JToolButtonBar extends JPanel {
|
||||
|
||||
LinkedList<UITool> tools;
|
||||
LinkedList<JToggleButton> buttons;
|
||||
|
||||
UITool selectedTool;
|
||||
|
||||
|
||||
public JToolButtonBar() {
|
||||
tools = new LinkedList<UITool>();
|
||||
buttons = new LinkedList<JToggleButton>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addTool(final UITool tool){
|
||||
tools.add(tool);
|
||||
|
||||
JToggleButton button = new JToggleButton();
|
||||
button.setSize(32, 32);
|
||||
button.setText( tool.getLabel() );
|
||||
button.setToolTipText(tool.getHelp());
|
||||
|
||||
button.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
selectTool(tool);
|
||||
}
|
||||
});
|
||||
|
||||
buttons.add(button);
|
||||
|
||||
add(button);
|
||||
}
|
||||
|
||||
public void selectTool(UITool tool){
|
||||
if (selectedTool != null) {
|
||||
selectedTool.unselect();
|
||||
int idx = tools.indexOf(selectedTool);
|
||||
if (idx != -1){
|
||||
buttons.get(idx).setSelected(false);
|
||||
}
|
||||
selectedTool = null;
|
||||
}
|
||||
|
||||
if (tool != null){
|
||||
int idx = tools.indexOf(tool);
|
||||
if (idx != -1){
|
||||
buttons.get(idx).setSelected(true);
|
||||
}
|
||||
tool.select();
|
||||
selectedTool = tool;
|
||||
}
|
||||
}
|
||||
|
||||
public UITool getSelectedTool() {
|
||||
return selectedTool;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.hwo.ui.diagram.CirclePlotPainter;
|
||||
import org.hwo.ui.diagram.SimplePlotProvider;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
|
||||
public class JUITest extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
private JDiagram diagram;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
JUITest frame = new JUITest();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public JUITest() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 1111, 342);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{186, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
diagram = new JDiagram();
|
||||
diagram.setLabelFormatSpec("%.2f");
|
||||
diagram.setNumLabels(6);
|
||||
diagram.setFont(new Font("Nimbus Mono L", Font.PLAIN, 14));
|
||||
GridBagConstraints gbc_diagram = new GridBagConstraints();
|
||||
gbc_diagram.fill = GridBagConstraints.BOTH;
|
||||
gbc_diagram.gridx = 0;
|
||||
gbc_diagram.gridy = 0;
|
||||
contentPane.add(diagram, gbc_diagram);
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
SimplePlotProvider p = new SimplePlotProvider(2, 32);
|
||||
|
||||
Float f = 0.0f;
|
||||
Float[] values = p.getMatrix()[0];
|
||||
for (int i=0;i<p.getPoints();i++){
|
||||
f += (float)(Math.random()-0.5f)*0.5f;
|
||||
values[i] = f;
|
||||
}
|
||||
p.getColors()[0] = Color.BLUE;
|
||||
|
||||
values = p.getMatrix()[1];
|
||||
for (int i=0;i<p.getPoints();i++){
|
||||
if ((i&1) == 0){
|
||||
f += (float)(Math.random()-0.5f)*0.5f;
|
||||
values[i] = f;
|
||||
} else {
|
||||
values[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
diagram.getDiagram().setPlotPainter(new CirclePlotPainter());
|
||||
diagram.getDiagram().setPlotProvider(p);
|
||||
|
||||
diagram.getDiagram().setYoffset(-3.0f);
|
||||
diagram.getDiagram().setYscale(6.0f);
|
||||
|
||||
//diagram.getDiagram().autoScale();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
public class KeyStrokeHelper {
|
||||
|
||||
private class KeyStrokeActionListener implements ActionListener
|
||||
{
|
||||
int keycode;
|
||||
|
||||
public KeyStrokeActionListener(int keycode)
|
||||
{
|
||||
this.keycode = keycode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fireKeyStroke(keycode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ArrayList<KeyStrokeListener> keystrokeListeners;
|
||||
JComponent component;
|
||||
JFrame frame;
|
||||
private boolean focusedWindow;
|
||||
|
||||
public KeyStrokeHelper(JComponent component)
|
||||
{
|
||||
keystrokeListeners = new ArrayList<KeyStrokeListener>();
|
||||
this.component = component;
|
||||
focusedWindow = false;
|
||||
}
|
||||
|
||||
public KeyStrokeHelper(JFrame frame)
|
||||
{
|
||||
keystrokeListeners = new ArrayList<KeyStrokeListener>();
|
||||
this.frame = frame;
|
||||
this.component = frame.getRootPane();
|
||||
this.focusedWindow = true;
|
||||
}
|
||||
|
||||
public KeyStrokeHelper addKeyCode(int keyCode)
|
||||
{
|
||||
int focused;
|
||||
|
||||
if (focusedWindow)
|
||||
focused = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
||||
else
|
||||
focused = JComponent.WHEN_FOCUSED;
|
||||
component.registerKeyboardAction(new KeyStrokeActionListener(keyCode), KeyStroke.getKeyStroke(keyCode, 0), focused);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void removeKey(int keyCode)
|
||||
{
|
||||
if (focusedWindow)
|
||||
frame.getRootPane().unregisterKeyboardAction(KeyStroke.getKeyStroke(keyCode, 0));
|
||||
else
|
||||
component.unregisterKeyboardAction(KeyStroke.getKeyStroke(keyCode, 0));
|
||||
}
|
||||
|
||||
public void registerKeyStrokeListener(KeyStrokeListener listener)
|
||||
{
|
||||
keystrokeListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeKeyStrokeListener(KeyStrokeListener listener)
|
||||
{
|
||||
keystrokeListeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
private void fireKeyStroke(int keyCode)
|
||||
{
|
||||
for (KeyStrokeListener listener:keystrokeListeners)
|
||||
listener.keyStroke(new KeyStrokeParameters(keyCode));
|
||||
}
|
||||
|
||||
public boolean isFocusedWindow() {
|
||||
return focusedWindow;
|
||||
}
|
||||
|
||||
public void setFocusedWindow(boolean focusedWindow) {
|
||||
this.focusedWindow = focusedWindow;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
public abstract class KeyStrokeListener {
|
||||
|
||||
public abstract void keyStroke(KeyStrokeParameters parameters);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
public class KeyStrokeParameters {
|
||||
|
||||
private int keyCode;
|
||||
|
||||
public KeyStrokeParameters(int keyCode)
|
||||
{
|
||||
this.keyCode = keyCode;
|
||||
}
|
||||
|
||||
public int getKeyCode() {
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
public void setKeyCode(int keyCode) {
|
||||
this.keyCode = keyCode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public abstract class MousePopupListener extends MouseAdapter {
|
||||
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
checkPopup(arg0);
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
checkPopup(arg0);
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
checkPopup(arg0);
|
||||
}
|
||||
|
||||
public void checkPopup(MouseEvent e)
|
||||
{
|
||||
if (e.isPopupTrigger())
|
||||
popupTriggered(e.getX(),e.getY());
|
||||
}
|
||||
|
||||
public abstract void popupTriggered(int x,int y);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import org.hwo.thread.ThreadedOperation;
|
||||
import org.hwo.thread.ThreadedOperationUpdateArgs;
|
||||
import org.hwo.thread.ThreadedOperationUpdateListener;
|
||||
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
public class ProgressDialog extends JDialog implements ThreadedOperationUpdateListener{
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JProgressBar pSchritt;
|
||||
private JProgressBar pGesamt;
|
||||
private JTextArea taStatus;
|
||||
private JLabel lblSchritt;
|
||||
|
||||
private int operationResult;
|
||||
private boolean operationFinished;
|
||||
|
||||
|
||||
public static int executeOperation(ThreadedOperation operation)
|
||||
{
|
||||
ProgressDialog dialog = new ProgressDialog();
|
||||
operation.addThreadedOperationUpdateListener(dialog);
|
||||
dialog.setTitle(operation.getName());
|
||||
operation.start();
|
||||
dialog.setVisible(true);
|
||||
operation.removeThreadedOperationUpdateListener(dialog);
|
||||
return dialog.getOperationResult();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
protected ProgressDialog() {
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent arg0) {
|
||||
if (!operationFinished)
|
||||
setVisible(true);
|
||||
}
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
}
|
||||
});
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
setBounds(100, 100, 691, 270);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[] {0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{1.0};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JLabel lblBitteWarten = new JLabel("Bitte warten...");
|
||||
lblBitteWarten.setFont(new Font("Lucida Grande", Font.PLAIN, 32));
|
||||
GridBagConstraints gbc_lblBitteWarten = new GridBagConstraints();
|
||||
gbc_lblBitteWarten.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblBitteWarten.gridx = 0;
|
||||
gbc_lblBitteWarten.gridy = 0;
|
||||
contentPanel.add(lblBitteWarten, gbc_lblBitteWarten);
|
||||
}
|
||||
{
|
||||
JLabel lblGesamtfortschritt = new JLabel("Gesamtfortschritt:");
|
||||
GridBagConstraints gbc_lblGesamtfortschritt = new GridBagConstraints();
|
||||
gbc_lblGesamtfortschritt.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblGesamtfortschritt.gridx = 0;
|
||||
gbc_lblGesamtfortschritt.gridy = 1;
|
||||
contentPanel.add(lblGesamtfortschritt, gbc_lblGesamtfortschritt);
|
||||
}
|
||||
{
|
||||
pGesamt = new JProgressBar();
|
||||
GridBagConstraints gbc_pGesamt = new GridBagConstraints();
|
||||
gbc_pGesamt.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_pGesamt.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_pGesamt.gridx = 0;
|
||||
gbc_pGesamt.gridy = 2;
|
||||
contentPanel.add(pGesamt, gbc_pGesamt);
|
||||
}
|
||||
{
|
||||
lblSchritt = new JLabel("Arbeitsschritt:");
|
||||
GridBagConstraints gbc_lblSchritt = new GridBagConstraints();
|
||||
gbc_lblSchritt.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblSchritt.gridx = 0;
|
||||
gbc_lblSchritt.gridy = 3;
|
||||
contentPanel.add(lblSchritt, gbc_lblSchritt);
|
||||
}
|
||||
{
|
||||
pSchritt = new JProgressBar();
|
||||
GridBagConstraints gbc_pSchritt = new GridBagConstraints();
|
||||
gbc_pSchritt.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_pSchritt.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_pSchritt.gridx = 0;
|
||||
gbc_pSchritt.gridy = 4;
|
||||
contentPanel.add(pSchritt, gbc_pSchritt);
|
||||
}
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "Status", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 5;
|
||||
contentPanel.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
taStatus = new JTextArea();
|
||||
GridBagConstraints gbc_taStatus = new GridBagConstraints();
|
||||
gbc_taStatus.fill = GridBagConstraints.BOTH;
|
||||
gbc_taStatus.gridx = 0;
|
||||
gbc_taStatus.gridy = 0;
|
||||
panel.add(taStatus, gbc_taStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getOperationResult() {
|
||||
return operationResult;
|
||||
}
|
||||
|
||||
|
||||
public void setOperationResult(int operationResult) {
|
||||
this.operationResult = operationResult;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void threadedOperationUpdate(ThreadedOperationUpdateArgs args) {
|
||||
if (args.getProgressOperation()!=null)
|
||||
pGesamt.setValue(args.getProgressOperation());
|
||||
if (args.getProgressStep()!=null)
|
||||
pSchritt.setValue(args.getProgressStep());
|
||||
if (args.getStepLabel()!=null)
|
||||
lblSchritt.setText(args.getStepLabel());
|
||||
if (args.getStatusText()!=null)
|
||||
taStatus.setText(args.getStatusText());
|
||||
if (args.getTitleText()!=null)
|
||||
setTitle(args.getTitleText());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void threadedOperationFinished(int result) {
|
||||
operationResult = result;
|
||||
operationFinished = true;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
public enum SelectionMode {
|
||||
NONE,
|
||||
CELL,
|
||||
ROW,
|
||||
COLUMN
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class CirclePlotPainter implements PlotPainter {
|
||||
|
||||
int radius;
|
||||
|
||||
public CirclePlotPainter() {
|
||||
this.radius = 3;
|
||||
}
|
||||
|
||||
public CirclePlotPainter(int radius){
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintPoint(Graphics2D g, Color color, int x, int y) {
|
||||
g.setColor(color);
|
||||
g.drawArc(x - radius, y - radius, 2*radius, 2*radius, 0, 360);
|
||||
g.fillArc(x - radius, y - radius, 2*radius, 2*radius, 0, 360);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class ColoredBackground {
|
||||
|
||||
Float min,max;
|
||||
Color color;
|
||||
|
||||
public ColoredBackground(Color color,float min,float max){
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public Float getMax() {
|
||||
return max;
|
||||
}
|
||||
public void setMax(Float max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Float getMin() {
|
||||
return min;
|
||||
}
|
||||
public void setMin(Float min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,234 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ObjectInputStream.GetField;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Diagram {
|
||||
|
||||
private PlotProvider plotProvider;
|
||||
private PlotPainter plotPainter;
|
||||
|
||||
private int x0,
|
||||
x1,
|
||||
y0,
|
||||
y1;
|
||||
|
||||
int yh,xw;
|
||||
|
||||
private float yscale;
|
||||
private float yoffset;
|
||||
|
||||
private Font font;
|
||||
|
||||
private int numLabels;
|
||||
|
||||
private String labelFormatSpec;
|
||||
|
||||
|
||||
private LinkedList<ColoredBackground> coloredBackgrounds;
|
||||
|
||||
public Diagram(){
|
||||
coloredBackgrounds = new LinkedList<ColoredBackground>();
|
||||
yoffset = -1.0f;
|
||||
yscale = 2.0f;
|
||||
plotProvider = new SimplePlotProvider(2, 2);
|
||||
plotPainter = new LinePlotPainter();
|
||||
font = new Font("Arial", Font.PLAIN, 24);
|
||||
numLabels = 0;
|
||||
labelFormatSpec = "%.4f";
|
||||
|
||||
coloredBackgrounds.add(new ColoredBackground(new Color(0.7f, 1.0f, 0.7f),-0.25f,0.25f));
|
||||
coloredBackgrounds.add(new ColoredBackground(new Color(1.0f, 1.0f, 0.5f),-0.5f,-0.25f));
|
||||
coloredBackgrounds.add(new ColoredBackground(new Color(1.0f, 1.0f, 0.5f),0.25f,0.5f));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public float getYoffset() {
|
||||
return yoffset;
|
||||
}
|
||||
public void setYoffset(float yoffset) {
|
||||
this.yoffset = yoffset;
|
||||
}
|
||||
public float getYscale() {
|
||||
return yscale;
|
||||
}
|
||||
public void setYscale(float yscale) {
|
||||
this.yscale = yscale;
|
||||
}
|
||||
|
||||
public Font getFont() {
|
||||
return font;
|
||||
}
|
||||
public void setFont(Font font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public int getNumLabels() {
|
||||
return numLabels;
|
||||
}
|
||||
public void setNumLabels(int numLabels) {
|
||||
this.numLabels = numLabels;
|
||||
}
|
||||
|
||||
public PlotPainter getPlotPainter() {
|
||||
return plotPainter;
|
||||
}
|
||||
public void setPlotPainter(PlotPainter plotPainter) {
|
||||
this.plotPainter = plotPainter;
|
||||
}
|
||||
|
||||
public PlotProvider getPlotProvider() {
|
||||
return plotProvider;
|
||||
}
|
||||
public void setPlotProvider(PlotProvider plotProvider) {
|
||||
this.plotProvider = plotProvider;
|
||||
}
|
||||
|
||||
public String getLabelFormatSpec() {
|
||||
return labelFormatSpec;
|
||||
}
|
||||
public void setLabelFormatSpec(String labelFormatSpec) {
|
||||
this.labelFormatSpec = labelFormatSpec;
|
||||
}
|
||||
|
||||
public List<ColoredBackground> getColoredBackgrounds() {
|
||||
return coloredBackgrounds;
|
||||
}
|
||||
|
||||
|
||||
public void autoScale(){
|
||||
Float max = Float.MIN_VALUE,min = Float.MAX_VALUE;
|
||||
Float[][] matrix = this.plotProvider.getMatrix();
|
||||
|
||||
|
||||
for (Float[] p:matrix){
|
||||
for (Float value: p){
|
||||
if (value < min)
|
||||
min = value;
|
||||
if (value > max)
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
|
||||
yoffset = min;
|
||||
yscale = max - min;
|
||||
|
||||
System.err.println(String.format("AutoScale: %f x %f", yoffset, yscale));
|
||||
}
|
||||
|
||||
public BufferedImage plot(int width,int height){
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
|
||||
plot(image.createGraphics(),width,height);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private int value2y(float value){
|
||||
return y0 - (int)(yh * ((value - yoffset)/yscale));
|
||||
}
|
||||
private int point2x(int point){
|
||||
return x0 + (xw * point / (this.plotProvider.getPoints()-1));
|
||||
}
|
||||
|
||||
public void plot(Graphics2D g,int width,int height){
|
||||
int lineHeight = font.getSize() * Toolkit.getDefaultToolkit().getScreenResolution() / 72 ;
|
||||
int nLabels = numLabels;
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, width, height);
|
||||
|
||||
y0 = height - lineHeight - 10;
|
||||
y1 = 10;
|
||||
yh = y0 - y1;
|
||||
x0 = 0;
|
||||
x1 = width - 10;
|
||||
|
||||
if (nLabels == 0){
|
||||
nLabels = ((y0 - y1) / lineHeight);
|
||||
}
|
||||
if (nLabels == 0)
|
||||
nLabels = 1;
|
||||
|
||||
for (ColoredBackground bg: coloredBackgrounds){
|
||||
int ya = value2y(bg.getMin());
|
||||
int yb = value2y(bg.getMax());
|
||||
|
||||
g.setColor(bg.getColor());
|
||||
g.fillRect(0, yb, width, ya - yb);
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
if (this.font != null)
|
||||
g.setFont(this.font);
|
||||
|
||||
for (int i=0;i<=nLabels;i++){
|
||||
String l = String.format(labelFormatSpec, (yoffset + (yscale * i / nLabels)));
|
||||
int lw = g.getFontMetrics().stringWidth(l);
|
||||
|
||||
if (lw > x0)
|
||||
x0 = lw;
|
||||
}
|
||||
for (int i=0;i<=nLabels;i++){
|
||||
String l = String.format(labelFormatSpec, (yoffset + (yscale * i / nLabels)));
|
||||
int lw = g.getFontMetrics().stringWidth(l);
|
||||
|
||||
g.drawString(l, 2 + (x0 - lw), y0 - (yh * i / nLabels) + (lineHeight/4));
|
||||
}
|
||||
x0 += 10;
|
||||
xw = x1 - x0;
|
||||
|
||||
for (int i=0;i<=nLabels;i++){
|
||||
g.drawLine(x0 - 5, y0 - (yh * i / nLabels) , x0, y0 - (yh * i / nLabels));
|
||||
}
|
||||
|
||||
for (int i=0;i<this.plotProvider.getPoints();i++){
|
||||
g.drawLine(point2x(i), y0, point2x(i), y0 + 5);
|
||||
|
||||
String xlabel = this.plotProvider.getPointLabel(i);
|
||||
int lw = g.getFontMetrics().stringWidth(xlabel);
|
||||
|
||||
g.drawString(xlabel, point2x(i) - (lw/2), y0 + lineHeight);
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.drawLine(x0, y0 + 5, x0, y1 - 10);
|
||||
g.drawLine(x0, y1 - 10 , x0 - 5, y1 - 5);
|
||||
g.drawLine(x0, y1 - 10 , x0 + 5, y1 - 5);
|
||||
|
||||
g.drawLine(x0, y0, x1 + 10, y0);
|
||||
g.drawLine(x1 + 10 , y0, x1 + 5, y0 - 5);
|
||||
g.drawLine(x1 + 10 , y0, x1 + 5, y0 + 5);
|
||||
|
||||
g.setColor(Color.RED);
|
||||
|
||||
Float[][] matrix = this.plotProvider.getMatrix();
|
||||
Color[] colors = this.plotProvider.getColors();
|
||||
|
||||
for (int n=0;n<this.plotProvider.getPlots();n++){
|
||||
plotPainter.reset();
|
||||
for (int i=0;i<this.plotProvider.getPoints();i++){
|
||||
int x,y;
|
||||
|
||||
if (matrix[n][i] != null){
|
||||
x = point2x(i);
|
||||
y = value2y(matrix[n][i]);
|
||||
|
||||
plotPainter.paintPoint(g, colors[n], x, y);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class LinePlotPainter implements PlotPainter {
|
||||
|
||||
int lx,ly;
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
lx = -1;
|
||||
ly = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintPoint(Graphics2D g, Color color, int x, int y) {
|
||||
if (lx != -1){
|
||||
g.setColor(color);
|
||||
g.drawLine(lx, ly, x, y);
|
||||
}
|
||||
|
||||
lx = x;
|
||||
ly = y;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Plot {
|
||||
|
||||
private Diagram diagram;
|
||||
|
||||
private String label;
|
||||
|
||||
private Float[] values;
|
||||
|
||||
protected Plot(Diagram diagram){
|
||||
this.diagram = diagram;
|
||||
this.values = new Float[0];
|
||||
}
|
||||
|
||||
public Diagram getDiagram() {
|
||||
return diagram;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Float[] getValues() {
|
||||
return this.values;
|
||||
};
|
||||
public void setValues(Float[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public Float getValue(int index){
|
||||
return this.values[index];
|
||||
}
|
||||
public void setValue(int index,Float value){
|
||||
this.values[index] = value;
|
||||
}
|
||||
|
||||
public Float getMin(){
|
||||
Float min = Float.MAX_VALUE;
|
||||
|
||||
for (Float f: values)
|
||||
if (f < min)
|
||||
min = f;
|
||||
|
||||
return min;
|
||||
};
|
||||
public Float getMax(){
|
||||
Float max = Float.MIN_VALUE;
|
||||
|
||||
for (Float f: values)
|
||||
if (f > max)
|
||||
max = f;
|
||||
|
||||
return max;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void resize(int points){
|
||||
int l = Math.min(this.values.length,points);
|
||||
Float[] nv = new Float[points];
|
||||
System.arraycopy(this.values, 0, nv, 0, l);
|
||||
this.values = nv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public interface PlotPainter {
|
||||
|
||||
void reset();
|
||||
void paintPoint(Graphics2D g,Color color,int x,int y);
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public interface PlotProvider {
|
||||
|
||||
int getPoints();
|
||||
int getPlots();
|
||||
|
||||
Float[][] getMatrix();
|
||||
|
||||
String getLabel(int plot);
|
||||
String getPointLabel(int point);
|
||||
|
||||
Color[] getColors();
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SimplePlotProvider implements PlotProvider {
|
||||
|
||||
int points;
|
||||
int xmin;
|
||||
|
||||
ArrayList<Float[]> plots;
|
||||
ArrayList<String> labels;
|
||||
Color[] colors;
|
||||
|
||||
public SimplePlotProvider(int plots,int points) {
|
||||
this.points = points;
|
||||
this.plots = new ArrayList<Float[]>();
|
||||
this.labels = new ArrayList<String>();
|
||||
this.xmin = 0;
|
||||
this.colors = new Color[plots];
|
||||
|
||||
for (int i=0;i<plots;i++){
|
||||
this.plots.add(new Float[points]);
|
||||
this.labels.add(String.format("Plot %d", i));
|
||||
Arrays.fill(this.plots.get(i), 0.0f);
|
||||
this.colors[i] = new Color(255,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
public int getXmin() {
|
||||
return xmin;
|
||||
}
|
||||
public void setXmin(int xmin) {
|
||||
this.xmin = xmin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlots() {
|
||||
return this.plots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float[][] getMatrix() {
|
||||
return this.plots.toArray(new Float[][]{});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel(int plot) {
|
||||
return this.labels.get(plot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPointLabel(int point) {
|
||||
return String.format("%d", (this.xmin + point));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color[] getColors() {
|
||||
return this.colors;
|
||||
}
|
||||
|
||||
public void setPlot(int plot,Float[] values){
|
||||
Float[] cv = Arrays.copyOf(values, points);
|
||||
this.plots.set(plot, cv);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package org.hwo.ui.dialog;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.io.SerialPort;
|
||||
import org.hwo.ui.JComboBoxEx;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class SerialPortChooser extends JDialog {
|
||||
|
||||
|
||||
public static SerialPort execute()
|
||||
{
|
||||
return execute(null);
|
||||
}
|
||||
public static SerialPort execute(String selectedPortName)
|
||||
{
|
||||
SerialPortChooser spc = new SerialPortChooser();
|
||||
|
||||
if (selectedPortName != null)
|
||||
spc.setSelectedSerialPort(selectedPortName);
|
||||
|
||||
spc.setVisible(true);
|
||||
|
||||
return spc.getSelectedSerialPort();
|
||||
}
|
||||
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
private SerialPort selectedSerialPort;
|
||||
private JComboBoxEx cbPortList;
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public SerialPortChooser() {
|
||||
setTitle(Messages.getString("SerialPortChooser.0"));
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 491, 169);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JLabel lblSchnittstelle = new JLabel(Messages.getString("interface"));
|
||||
GridBagConstraints gbc_lblSchnittstelle = new GridBagConstraints();
|
||||
gbc_lblSchnittstelle.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblSchnittstelle.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblSchnittstelle.gridx = 0;
|
||||
gbc_lblSchnittstelle.gridy = 0;
|
||||
contentPanel.add(lblSchnittstelle, gbc_lblSchnittstelle);
|
||||
}
|
||||
{
|
||||
cbPortList = new JComboBoxEx();
|
||||
GridBagConstraints gbc_cbPortList = new GridBagConstraints();
|
||||
gbc_cbPortList.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_cbPortList.gridx = 1;
|
||||
gbc_cbPortList.gridy = 0;
|
||||
contentPanel.add(cbPortList, gbc_cbPortList);
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton(Messages.getString("ok"));
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
accept();
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton(Messages.getString("cancel"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize()
|
||||
{
|
||||
selectedSerialPort = null;
|
||||
|
||||
cbPortList.removeAllItems();
|
||||
|
||||
for (String portName: SerialPort.getPortNames())
|
||||
cbPortList.addItem(portName);
|
||||
}
|
||||
|
||||
private void accept()
|
||||
{
|
||||
selectedSerialPort = SerialPort.newInstance();
|
||||
selectedSerialPort.setPortName(cbPortList.getSelectedItem().toString());
|
||||
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
private void cancel()
|
||||
{
|
||||
selectedSerialPort = null;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public SerialPort getSelectedSerialPort() {
|
||||
return selectedSerialPort;
|
||||
}
|
||||
|
||||
public void setSelectedSerialPort(SerialPort selectedSerialPort) {
|
||||
cbPortList.selectEqualItem(selectedSerialPort.getPortName());
|
||||
}
|
||||
|
||||
public void setSelectedSerialPort(String portName) {
|
||||
cbPortList.selectEqualItem(portName);
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,96 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.datetime.DateTime;
|
||||
|
||||
public class BaseNetPlanObject implements INetPlanObject {
|
||||
|
||||
private DateTime startTime,
|
||||
endTime;
|
||||
|
||||
private String label,
|
||||
detailedLabel;
|
||||
|
||||
List<INetPlanObject> dependencies;
|
||||
List<INetPlanResource> resources;
|
||||
|
||||
public BaseNetPlanObject() {
|
||||
dependencies = new LinkedList<INetPlanObject>();
|
||||
resources = new LinkedList<INetPlanResource>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime getStartTime() {
|
||||
return new DateTime(this.startTime);
|
||||
}
|
||||
@Override
|
||||
public void setStartTime(DateTime startTime) {
|
||||
this.startTime = new DateTime(startTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime getEndTime() {
|
||||
return new DateTime(this.endTime);
|
||||
}
|
||||
@Override
|
||||
public void setEndTime(DateTime endTime) {
|
||||
this.endTime = new DateTime(endTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMove() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canStretch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INetPlanObject[] getDependencies() {
|
||||
return this.dependencies.toArray(new INetPlanObject[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDependency(INetPlanObject depend) {
|
||||
if (!this.dependencies.contains(depend))
|
||||
this.dependencies.add(depend);
|
||||
}
|
||||
@Override
|
||||
public void removeDependency(INetPlanObject depend) {
|
||||
this.dependencies.remove(depend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public INetPlanResource[] getResources() {
|
||||
return this.resources.toArray(new INetPlanResource[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResource(INetPlanResource resource) {
|
||||
if (!this.resources.contains(resource))
|
||||
this.resources.add(resource);
|
||||
}
|
||||
@Override
|
||||
public void removeResource(INetPlanResource resource) {
|
||||
this.resources.remove(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDetailedLabel() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}public void setDetailedLabel(String detailedLabel) {
|
||||
this.detailedLabel = detailedLabel;
|
||||
}
|
||||
public String getShortLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setShortLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import org.hwo.datetime.DateTime;
|
||||
|
||||
public class BaseNetPlanResource implements INetPlanResource {
|
||||
|
||||
private String shortLabel;
|
||||
private String detailedLabel;
|
||||
private int maxParallelUsage;
|
||||
|
||||
private ResourceAvailability resourceAvailability;
|
||||
|
||||
public BaseNetPlanResource(String shortLabel,String detailedLabel) {
|
||||
this.shortLabel = shortLabel;
|
||||
this.detailedLabel = detailedLabel;
|
||||
this.maxParallelUsage = 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return this.shortLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDetailedLabel() {
|
||||
return this.detailedLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceAvailability getAvailability() {
|
||||
return resourceAvailability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceAvailability getAvailability(DateTime fromDateTime) {
|
||||
return resourceAvailability.findAvailableAfter(fromDateTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxParallelUsage() {
|
||||
return this.maxParallelUsage;
|
||||
}
|
||||
|
||||
public void setMaxParallelUsage(int maxParallelUsage) {
|
||||
this.maxParallelUsage = maxParallelUsage;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import org.hwo.datetime.DateTime;
|
||||
|
||||
public interface INetPlanObject {
|
||||
|
||||
boolean canMove(); // Startzeitpunkt kann verändert werden
|
||||
boolean canStretch(); // Dauer kann verändert werden
|
||||
|
||||
/* Startzeitpunkt setzen */
|
||||
DateTime getStartTime();
|
||||
void setStartTime(DateTime startTime);
|
||||
|
||||
/* Endzeitpunkt setzen */
|
||||
DateTime getEndTime();
|
||||
void setEndTime(DateTime endTime);
|
||||
|
||||
/* Text für Anzeige im Plan*/
|
||||
String getShortLabel();
|
||||
/* Text für Detailierte Anzeige als Bubble */
|
||||
String getDetailedLabel();
|
||||
|
||||
/* Abhängige Objekte */
|
||||
INetPlanObject[] getDependencies();
|
||||
|
||||
void addDependency(INetPlanObject depend);
|
||||
void removeDependency(INetPlanObject depend);
|
||||
|
||||
/* Notwendige Resourcen */
|
||||
INetPlanResource[] getResources();
|
||||
|
||||
void addResource(INetPlanResource resource);
|
||||
void removeResource(INetPlanResource resource);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import org.hwo.datetime.DateTime;
|
||||
|
||||
public interface INetPlanResource {
|
||||
|
||||
String getLabel();
|
||||
String getDetailedLabel();
|
||||
|
||||
int getMaxParallelUsage();
|
||||
|
||||
ResourceAvailability getAvailability();
|
||||
ResourceAvailability getAvailability(DateTime fromDateTime);
|
||||
|
||||
}
|
|
@ -0,0 +1,339 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.Scrollable;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
|
||||
public class JNetPlan extends JComponent {
|
||||
|
||||
List<INetPlanObject> netPlanObjects;
|
||||
List<INetPlanResource> netPlanResources;
|
||||
|
||||
Date firstDate;
|
||||
int days;
|
||||
|
||||
boolean timeVisible;
|
||||
|
||||
|
||||
boolean relevantChange;
|
||||
|
||||
JViewport topPane,
|
||||
leftPane;
|
||||
|
||||
|
||||
|
||||
public JNetPlan() {
|
||||
netPlanObjects = new ArrayList<INetPlanObject>();
|
||||
netPlanResources = new ArrayList<INetPlanResource>();
|
||||
|
||||
firstDate = new Date();
|
||||
days = 31;
|
||||
|
||||
timeVisible = false;
|
||||
|
||||
relevantChange = true;
|
||||
|
||||
setDoubleBuffered(true);
|
||||
|
||||
topPane = new JViewport();
|
||||
topPane.add(new TopPane());
|
||||
leftPane = new JViewport();
|
||||
leftPane.add(new Leftpane());
|
||||
}
|
||||
|
||||
public void addNetPlanObject(INetPlanObject object){
|
||||
if (!this.netPlanObjects.contains(object))
|
||||
this.netPlanObjects.add(object);
|
||||
|
||||
for (INetPlanResource res: object.getResources()){
|
||||
addNetPlanResource(res);
|
||||
}
|
||||
}
|
||||
public void removeNetPlanObject(INetPlanObject object){
|
||||
this.netPlanObjects.remove(object);
|
||||
}
|
||||
public INetPlanObject[] getNetPlanObjects(){
|
||||
return this.netPlanObjects.toArray(new INetPlanObject[0]);
|
||||
}
|
||||
|
||||
public void addNetPlanResource(INetPlanResource resource){
|
||||
if (!this.netPlanResources.contains(resource))
|
||||
this.netPlanResources.add(resource);
|
||||
}
|
||||
public void removeNetPlanResource(INetPlanResource resource){
|
||||
this.netPlanResources.remove(resource);
|
||||
}
|
||||
public INetPlanResource[] getNetPlanResources(){
|
||||
return this.netPlanResources.toArray(new INetPlanResource[0]);
|
||||
}
|
||||
|
||||
public Date getFirstDate() {
|
||||
return new Date(firstDate);
|
||||
}
|
||||
public void setFirstDate(Date firstDate) {
|
||||
this.firstDate = new Date(firstDate);
|
||||
}
|
||||
|
||||
public int getDays() {
|
||||
return days;
|
||||
}
|
||||
public void setDays(int days) {
|
||||
this.days = days;
|
||||
}
|
||||
|
||||
public void setTimeVisible(boolean timeVisible) {
|
||||
this.timeVisible = timeVisible;
|
||||
}
|
||||
public boolean isTimeVisible(){
|
||||
return this.timeVisible;
|
||||
}
|
||||
|
||||
/*********
|
||||
* Layout variables...
|
||||
*/
|
||||
|
||||
int resourceLines;
|
||||
int lineHeight;
|
||||
int resourceBaseHeight;
|
||||
|
||||
int leftColumnWidth;
|
||||
|
||||
int dayColumnWidth;
|
||||
|
||||
int minHeight;
|
||||
int minWidth;
|
||||
|
||||
@Override
|
||||
public void paint(Graphics _g) {
|
||||
Graphics2D g = (Graphics2D)_g;
|
||||
|
||||
int n;
|
||||
|
||||
updateSizes();
|
||||
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
// g.drawLine(leftColumnWidth, 0, leftColumnWidth, getHeight());
|
||||
|
||||
Date date = getFirstDate();
|
||||
|
||||
for (n = 0; n < days; n++){
|
||||
int l = ((n) * dayColumnWidth);
|
||||
|
||||
g.drawLine(((n+1) * dayColumnWidth), 0, ((n+1) * dayColumnWidth), minHeight);
|
||||
}
|
||||
|
||||
|
||||
n = 0;
|
||||
for (INetPlanResource resource: this.netPlanResources){
|
||||
n += resource.getMaxParallelUsage();
|
||||
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
|
||||
g.drawLine(0, 4 + (n * lineHeight), minWidth, 4 + (n * lineHeight));
|
||||
}
|
||||
|
||||
for (INetPlanObject object: netPlanObjects){
|
||||
|
||||
|
||||
|
||||
g.setColor(Color.RED);
|
||||
//g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void updateSizes(){
|
||||
if (!relevantChange)
|
||||
return;
|
||||
|
||||
Graphics2D g = (Graphics2D)getGraphics();
|
||||
FontMetrics fm = getFontMetrics(getFont());
|
||||
|
||||
//lineHeight = (int)(getFont().getSize2D()*72) + 4;
|
||||
lineHeight = getFont().getSize() + 4;
|
||||
|
||||
resourceBaseHeight = lineHeight * 3;
|
||||
|
||||
if (isTimeVisible())
|
||||
dayColumnWidth = 96;
|
||||
else
|
||||
dayColumnWidth = ((int)fm.getStringBounds("WWW", g).getWidth()) + 10;
|
||||
|
||||
resourceLines = 0;
|
||||
leftColumnWidth = 0;
|
||||
for (INetPlanResource resource: this.netPlanResources){
|
||||
int lw = (int)fm.getStringBounds(resource.getLabel(), g).getWidth();
|
||||
|
||||
if (lw > leftColumnWidth)
|
||||
leftColumnWidth = lw;
|
||||
|
||||
resourceLines += resource.getMaxParallelUsage();
|
||||
}
|
||||
|
||||
leftColumnWidth += 5;
|
||||
|
||||
|
||||
minHeight = 4 + (lineHeight * resourceLines);
|
||||
minWidth = ( dayColumnWidth * days );
|
||||
|
||||
setPreferredSize(new Dimension(minWidth, minHeight));
|
||||
|
||||
leftPane.setSize(new Dimension(leftColumnWidth,minHeight));
|
||||
topPane.setSize(new Dimension(minWidth, 4 * lineHeight));
|
||||
|
||||
relevantChange = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class TopPane extends JComponent {
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(minWidth,4 * lineHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics _g) {
|
||||
Graphics2D g = (Graphics2D)_g;
|
||||
|
||||
int n;
|
||||
|
||||
updateSizes();
|
||||
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
// g.drawLine(leftColumnWidth, 0, leftColumnWidth, getHeight());
|
||||
|
||||
g.drawLine(0, resourceBaseHeight, getWidth(), resourceBaseHeight);
|
||||
|
||||
Date date = getFirstDate();
|
||||
|
||||
for (n = 0; n < days; n++){
|
||||
int l = ((n) * dayColumnWidth);
|
||||
|
||||
g.drawLine(((n+1) * dayColumnWidth), resourceBaseHeight - (2 * lineHeight), ((n+1) * dayColumnWidth), minHeight);
|
||||
|
||||
g.drawString(String.format("%d", date.getDay()), l + 2, resourceBaseHeight - lineHeight - 2);
|
||||
g.drawString(String.format("%s", date.weekdays[date.getWeekDay()]), l + 2, resourceBaseHeight - 2);
|
||||
|
||||
date.addDays(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Leftpane extends JComponent {
|
||||
|
||||
public Leftpane() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(leftColumnWidth,minHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics _g) {
|
||||
Graphics2D g = (Graphics2D)_g;
|
||||
|
||||
int n;
|
||||
|
||||
updateSizes();
|
||||
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
// g.drawLine(leftColumnWidth, 0, leftColumnWidth, getHeight());
|
||||
|
||||
// g.drawLine(0, 0, getWidth(), 0);
|
||||
|
||||
n = 0;
|
||||
for (INetPlanResource resource: netPlanResources){
|
||||
n += resource.getMaxParallelUsage();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawString(resource.getLabel(), 2, 1 + (n * lineHeight));
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
|
||||
g.drawLine(0, 4 + (n * lineHeight), getWidth(), 4 + (n * lineHeight));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public Dimension getPreferredScrollableViewportSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollableBlockIncrement(Rectangle visibleRect,
|
||||
int orientation, int direction) {
|
||||
if (orientation == SwingConstants.HORIZONTAL)
|
||||
return visibleRect.width / 2;
|
||||
else
|
||||
return visibleRect.height / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportHeight() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportWidth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollableUnitIncrement(Rectangle visibleRect,
|
||||
int orientation, int direction) {
|
||||
if (orientation == SwingConstants.HORIZONTAL)
|
||||
return 10;
|
||||
else
|
||||
return lineHeight;
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
|
||||
if (JViewport.class.isInstance(getParent()) && JScrollPane.class.isInstance(getParent().getParent()))
|
||||
{
|
||||
JScrollPane sp = (JScrollPane)getParent().getParent();
|
||||
sp.setColumnHeader(topPane);
|
||||
sp.setRowHeader(leftPane);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public void removeNotify() {
|
||||
super.removeNotify();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
import org.hwo.datetime.DateTime;
|
||||
import org.hwo.datetime.TimeOfDay;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
|
||||
public class JNetPlanTestDialog extends JDialog {
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JNetPlan netPlan;
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public JNetPlanTestDialog() {
|
||||
setModal(true);
|
||||
setTitle("JNetPlan Test Dialog");
|
||||
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 975, 481);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 0;
|
||||
contentPanel.add(scrollPane, gbc_scrollPane);
|
||||
{
|
||||
netPlan = new JNetPlan();
|
||||
netPlan.setDays(45);
|
||||
netPlan.setFont(new Font("Courier 10 Pitch", Font.PLAIN, 12));
|
||||
netPlan.setBackground(Color.WHITE);
|
||||
scrollPane.setViewportView(netPlan);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
for (int i=0;i<10;i++){
|
||||
BaseNetPlanResource res = new BaseNetPlanResource(String.format("Resource %d",i), "-");
|
||||
if (i == 3)
|
||||
res.setMaxParallelUsage(2);
|
||||
netPlan.addNetPlanResource(res);
|
||||
}
|
||||
|
||||
Date d = new Date();
|
||||
|
||||
d.addDays(3);
|
||||
|
||||
BaseNetPlanObject o = new BaseNetPlanObject();
|
||||
o.setStartTime(new DateTime(d, new TimeOfDay()));
|
||||
o.setEndTime(new DateTime(d, TimeOfDay.beforeMidnight()));
|
||||
|
||||
o.setShortLabel("Eine Aufgabe");
|
||||
o.addResource(netPlan.getNetPlanResources()[3]);
|
||||
|
||||
netPlan.addNetPlanObject(o);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
public class NetPlanException extends Exception {
|
||||
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
import org.hwo.datetime.DateTime;
|
||||
import org.hwo.datetime.TimeOfDay;
|
||||
|
||||
public class ResourceAvailability {
|
||||
|
||||
private DateTime startTime;
|
||||
private DateTime endTime;
|
||||
|
||||
private String label;
|
||||
|
||||
private ResourceAvailability
|
||||
next;
|
||||
|
||||
public ResourceAvailability(){
|
||||
this.setStartTime(new DateTime());
|
||||
this.setEndTime(new DateTime(getStartTime()));
|
||||
this.getEndTime().getDate().addDays(3650);
|
||||
}
|
||||
|
||||
public ResourceAvailability(DateTime startTime){
|
||||
this.setStartTime(startTime);
|
||||
this.setEndTime(new DateTime(getStartTime()));
|
||||
this.getEndTime().getDate().addDays(3650);
|
||||
}
|
||||
|
||||
ResourceAvailability getNextAvailability(){
|
||||
return this.getNext();
|
||||
}
|
||||
|
||||
public DateTime getStartTime() {
|
||||
return new DateTime(startTime);
|
||||
}
|
||||
|
||||
public void setStartTime(DateTime startTime) {
|
||||
this.startTime = new DateTime(startTime);
|
||||
}
|
||||
|
||||
public DateTime getEndTime() {
|
||||
return new DateTime(endTime);
|
||||
}
|
||||
|
||||
public void setEndTime(DateTime endTime) {
|
||||
this.endTime = new DateTime(endTime);
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public ResourceAvailability getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public void setNext(ResourceAvailability next) {
|
||||
this.next = next;
|
||||
};
|
||||
|
||||
|
||||
public void makeAvailable(DateTime from,DateTime to){
|
||||
makeAvailable(from, to, "-");
|
||||
}
|
||||
public void makeAvailable(DateTime from,DateTime to,String label){
|
||||
ResourceAvailability a = findLastAvailableBefore(from);
|
||||
|
||||
if (a != null){
|
||||
|
||||
ResourceAvailability na = new ResourceAvailability(from);
|
||||
na.setEndTime(to);
|
||||
na.setLabel(label);
|
||||
|
||||
na.setNext(a.getNext());
|
||||
a.setNext(na);
|
||||
|
||||
if (a.getEndTime().isAfter(from)){
|
||||
a.setEndTime(from);
|
||||
}
|
||||
|
||||
a = na;
|
||||
while (a.getNext() != null){
|
||||
if (a.getNext().getStartTime().isBefore(na.getEndTime())){
|
||||
if (a.getNext().getEndTime().isBefore(na.getEndTime())){
|
||||
a.setNext( a.getNext().getNext() );
|
||||
continue;
|
||||
}
|
||||
a.getNext().setStartTime(na.getEndTime());
|
||||
}
|
||||
a = a.getNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void makeUnAvailable(DateTime from,DateTime to){
|
||||
ResourceAvailability a = findLastAvailableBefore(from);
|
||||
|
||||
if (a != null){
|
||||
|
||||
if (a.getEndTime().isAfter(from)){
|
||||
a.setEndTime(from);
|
||||
}
|
||||
|
||||
while (a.getNext()!=null){
|
||||
if (a.getNext().getStartTime().isBefore(to)){
|
||||
if (a.getNext().getEndTime().isBefore(to)){
|
||||
a.setNext(a.getNext().getNext());
|
||||
continue;
|
||||
}
|
||||
a.getNext().setStartTime(to);
|
||||
}
|
||||
a = a.getNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceAvailability findLastAvailableBefore(DateTime dateTime){
|
||||
if (this.startTime.isAfter(dateTime))
|
||||
return null;
|
||||
|
||||
if (next != null){
|
||||
ResourceAvailability a = next.findLastAvailableBefore(dateTime);
|
||||
if (a != null)
|
||||
return a;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceAvailability findAvailableAfter(DateTime dateTime){
|
||||
if (this.endTime.isAfter(dateTime))
|
||||
return this;
|
||||
|
||||
if (next != null){
|
||||
ResourceAvailability a = next.findAvailableAfter(dateTime);
|
||||
if (a != null)
|
||||
return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
ResourceAvailability ra = this;
|
||||
while (ra != null){
|
||||
sb.append(String.format("%s %s - %s %s\n",Date.weekdays[ra.getStartTime().getDate().getWeekDay()],ra.getStartTime().toString(),Date.weekdays[ra.getEndTime().getDate().getWeekDay()],ra.getEndTime().toString()));
|
||||
ra = ra.getNext();
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static ResourceAvailability generateWeekly(Date from,int days,boolean[] available){
|
||||
return generateWeekly(from, days, available,new TimeOfDay(),TimeOfDay.beforeMidnight());
|
||||
}
|
||||
public static ResourceAvailability generateWeekly(Date from,int days,boolean[] available,TimeOfDay timeStart,TimeOfDay timeEnd){
|
||||
from.addDays(-1);
|
||||
ResourceAvailability head = new ResourceAvailability(new DateTime(from, new TimeOfDay()));
|
||||
head.setEndTime(new DateTime(from, TimeOfDay.beforeMidnight()));
|
||||
|
||||
for (int i=0;i<days;i++){
|
||||
from.addDays(1);
|
||||
|
||||
DateTime aStart = new DateTime(from, timeStart);
|
||||
DateTime aEnd = new DateTime(from, timeEnd);
|
||||
|
||||
if (available[from.getWeekDay()])
|
||||
head.makeAvailable(aStart, aEnd, Date.weekdays[from.getWeekDay()]);
|
||||
|
||||
}
|
||||
return head.getNext();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.hwo.ui.netplan;
|
||||
|
||||
import java.io.Console;
|
||||
|
||||
import javax.swing.JApplet;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
import org.hwo.datetime.DateTime;
|
||||
import org.hwo.datetime.TimeOfDay;
|
||||
|
||||
public class TestNetPlan {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ResourceAvailability ra = ResourceAvailability.generateWeekly(new Date(), 60, new boolean[]{false,true,true,true,true,true,false}, new TimeOfDay(8, 0, 0),new TimeOfDay(16, 59, 59));
|
||||
|
||||
ra.makeAvailable(new DateTime(new Date(2015,8,8),new TimeOfDay(8,0,0)),new DateTime(new Date(2015,8,8),new TimeOfDay(22, 0, 0)));
|
||||
ra.makeAvailable(new DateTime(new Date(2015,8,9),new TimeOfDay(8,0,0)),new DateTime(new Date(2015,8,9),new TimeOfDay(12, 0, 0)));
|
||||
|
||||
ra.makeUnAvailable(new DateTime(new Date(2015,8,10),new TimeOfDay(0,0,0)),new DateTime(new Date(2015,8,11),new TimeOfDay(23, 59, 59)));
|
||||
|
||||
|
||||
System.err.println(ra.toString());
|
||||
|
||||
JNetPlanTestDialog dialog = new JNetPlanTestDialog();
|
||||
|
||||
dialog.setVisible(true);
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import org.hwo.bitfields.BitField;
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
import org.hwo.bitfields.ui.BitFieldEditor;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class BitFieldServiceRegister extends ServiceRegister {
|
||||
|
||||
BitField bitField;
|
||||
BitFieldEditor
|
||||
editor;
|
||||
|
||||
|
||||
public BitFieldServiceRegister(ServiceLink serviceLink) {
|
||||
super(serviceLink);
|
||||
|
||||
editor = new BitFieldEditor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegisterNode(Element registerNode) {
|
||||
super.setRegisterNode(registerNode);
|
||||
|
||||
Element fieldsNode = (Element)registerNode.getElementsByTagName("Fields").item(0);
|
||||
bitField = new BitField(fieldsNode);
|
||||
|
||||
editor.setBitField(bitField);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTextRepresentation() {
|
||||
if (bitField == null)
|
||||
return "-";
|
||||
return bitField.toText(readIntegerValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getEditorComponent() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptEditorValue() {
|
||||
writeIntegerValue( editor.getIntValue() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEditorValue() {
|
||||
editor.setIntValue( readIntegerValue() );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
public class FloatRegisterEditor extends JPanel implements ServiceRegisterControl {
|
||||
|
||||
private ServiceRegister serviceRegister;
|
||||
private JTextField tfValue;
|
||||
|
||||
public FloatRegisterEditor()
|
||||
{
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
tfValue = new JTextField();
|
||||
GridBagConstraints gbc_tfValue = new GridBagConstraints();
|
||||
gbc_tfValue.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfValue.gridx = 0;
|
||||
gbc_tfValue.gridy = 0;
|
||||
add(tfValue, gbc_tfValue);
|
||||
tfValue.setColumns(10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
||||
this.serviceRegister = serviceRegister;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeValue() {
|
||||
this.serviceRegister.writeFloatValue(Float.parseFloat(tfValue.getText()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readValue() {
|
||||
tfValue.setText(this.serviceRegister.readFloatValue().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestFocusInWindow() {
|
||||
return tfValue.requestFocusInWindow();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
|
||||
public class FloatServiceRegister extends ServiceRegister {
|
||||
|
||||
FloatRegisterEditor editor;
|
||||
|
||||
public FloatServiceRegister(ServiceLink serviceLink)
|
||||
{
|
||||
super(serviceLink);
|
||||
editor = new FloatRegisterEditor();
|
||||
editor.setServiceRegister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTextRepresentation() {
|
||||
Float f = readFloatValue();
|
||||
if (f == null)
|
||||
return "";
|
||||
return String.format("0x%08X %f",Float.floatToIntBits(f),f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getEditorComponent() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptEditorValue() {
|
||||
editor.writeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEditorValue() {
|
||||
editor.readValue();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
import org.hwo.ui.JComboBoxEx;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
public class IndexedListRegisterEditor extends JPanel implements ServiceRegisterControl {
|
||||
|
||||
public static class IndexedItem {
|
||||
private Integer index;
|
||||
private String label;
|
||||
|
||||
public IndexedItem(Integer index,String label) {
|
||||
this.index = index;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%d: %s", this.index, this.label);
|
||||
}
|
||||
|
||||
public Integer getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(Integer index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private ServiceRegister serviceRegister;
|
||||
private JComboBoxEx cbValue;
|
||||
|
||||
private IndexedItem[] items;
|
||||
|
||||
|
||||
public IndexedListRegisterEditor()
|
||||
{
|
||||
super();
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
cbValue = new JComboBoxEx();
|
||||
GridBagConstraints gbc_tfValue = new GridBagConstraints();
|
||||
gbc_tfValue.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfValue.gridx = 0;
|
||||
gbc_tfValue.gridy = 0;
|
||||
add(cbValue, gbc_tfValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
||||
this.serviceRegister = serviceRegister;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeValue() {
|
||||
this.serviceRegister.writeIntegerValue(((IndexedItem)cbValue.getSelectedItem()).getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readValue() {
|
||||
Integer i = this.serviceRegister.readIntegerValue();
|
||||
if ( i == null )
|
||||
i = 0;
|
||||
|
||||
for (IndexedItem item : items) {
|
||||
if (item.getIndex().equals(i)) {
|
||||
cbValue.setSelectedItem(item);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
IndexedItem item = new IndexedItem(i, "Unkown Index");
|
||||
cbValue.setSelectedItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestFocusInWindow() {
|
||||
return cbValue.requestFocusInWindow();
|
||||
}
|
||||
|
||||
public IndexedItem[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(IndexedItem[] items) {
|
||||
this.items = items;
|
||||
|
||||
cbValue.removeAllItems();
|
||||
for (IndexedItem item: items){
|
||||
cbValue.addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import org.hwo.bitfields.BitField;
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
import org.hwo.ui.servicelink.register.IndexedListRegisterEditor.IndexedItem;
|
||||
import org.hwo.xml.NodeListIterator;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class IndexedListServiceRegister extends ServiceRegister {
|
||||
|
||||
IndexedListRegisterEditor editor;
|
||||
Hashtable<Integer, IndexedItem> items;
|
||||
|
||||
public IndexedListServiceRegister(ServiceLink serviceLink)
|
||||
{
|
||||
super(serviceLink);
|
||||
editor = new IndexedListRegisterEditor();
|
||||
editor.setServiceRegister(this);
|
||||
|
||||
items = new Hashtable<Integer, IndexedListRegisterEditor.IndexedItem>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegisterNode(Element registerNode) {
|
||||
super.setRegisterNode(registerNode);
|
||||
|
||||
Element listNode = (Element)registerNode.getElementsByTagName("List").item(0);
|
||||
|
||||
LinkedList<IndexedItem> items = new LinkedList<IndexedListRegisterEditor.IndexedItem>();
|
||||
|
||||
for (Element listItem: new NodeListIterator(listNode.getElementsByTagName("Item"))){
|
||||
IndexedItem item = new IndexedItem(Integer.parseInt(listItem.getAttribute("index")), listItem.getTextContent());
|
||||
items.add(item);
|
||||
this.items.put(item.getIndex(), item);
|
||||
}
|
||||
editor.setItems(items.toArray(new IndexedItem[0]));
|
||||
}
|
||||
|
||||
private IndexedItem getIndexedItem(Integer index) {
|
||||
if (this.items.containsKey(index)) {
|
||||
return this.items.get(index);
|
||||
}
|
||||
IndexedItem unknown = new IndexedItem(index, "Unkown");
|
||||
return unknown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTextRepresentation() {
|
||||
Integer i = readIntegerValue();
|
||||
if (i == null)
|
||||
return "";
|
||||
return getIndexedItem(i).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getEditorComponent() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptEditorValue() {
|
||||
editor.writeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEditorValue() {
|
||||
editor.readValue();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
public class IntegerRegisterEditor extends JPanel implements ServiceRegisterControl {
|
||||
|
||||
private ServiceRegister serviceRegister;
|
||||
private JTextField tfValue;
|
||||
|
||||
public IntegerRegisterEditor()
|
||||
{
|
||||
super();
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
tfValue = new JTextField();
|
||||
GridBagConstraints gbc_tfValue = new GridBagConstraints();
|
||||
gbc_tfValue.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfValue.gridx = 0;
|
||||
gbc_tfValue.gridy = 0;
|
||||
add(tfValue, gbc_tfValue);
|
||||
tfValue.setColumns(10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
||||
this.serviceRegister = serviceRegister;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeValue() {
|
||||
this.serviceRegister.writeIntegerValue(Integer.decode(tfValue.getText()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readValue() {
|
||||
Integer i = this.serviceRegister.readIntegerValue();
|
||||
if ( i == null )
|
||||
i = 0;
|
||||
tfValue.setText(i.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestFocusInWindow() {
|
||||
return tfValue.requestFocusInWindow();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
|
||||
public class IntegerServiceRegister extends ServiceRegister {
|
||||
|
||||
IntegerRegisterEditor editor;
|
||||
|
||||
public IntegerServiceRegister(ServiceLink serviceLink)
|
||||
{
|
||||
super(serviceLink);
|
||||
editor = new IntegerRegisterEditor();
|
||||
editor.setServiceRegister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTextRepresentation() {
|
||||
Integer i = readIntegerValue();
|
||||
if (i == null)
|
||||
return "";
|
||||
return String.format("0x%08x %d", i, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getEditorComponent() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptEditorValue() {
|
||||
editor.writeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEditorValue() {
|
||||
editor.readValue();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import org.hwo.interactiveobjects.InteractiveObject;
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
import org.hwo.io.servicelink.ServiceLink.ServiceTelegram;
|
||||
import org.hwo.io.servicelink.ServiceLinkException;
|
||||
import org.hwo.models.TableMapper.TableColumn;
|
||||
import org.hwo.ui.servicelink.register.bitfield.BitFieldEditor;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
@InteractiveObject(editor=ServiceRegisterEditorDialog.class)
|
||||
public abstract class ServiceRegister {
|
||||
|
||||
static HashMap<String, Class<? extends ServiceRegister>> serviceRegisterTypes;
|
||||
public static void addServiceRegisterType(String typename,Class<? extends ServiceRegister> clazz)
|
||||
{
|
||||
serviceRegisterTypes.put(typename, clazz);
|
||||
}
|
||||
|
||||
public static ServiceRegister createServiceRegister(ServiceLink serviceLink,String typeName)
|
||||
{
|
||||
ServiceRegister sr = null;
|
||||
|
||||
Class<? extends ServiceRegister> clazz = serviceRegisterTypes.get(typeName);
|
||||
if (clazz != null)
|
||||
{
|
||||
try {
|
||||
sr = clazz.getDeclaredConstructor(ServiceLink.class).newInstance(serviceLink);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sr;
|
||||
}
|
||||
public static ServiceRegister createServiceRegister(ServiceLink serviceLink,Element registerNode)
|
||||
{
|
||||
ServiceRegister sr = null;
|
||||
String registerType = registerNode.getAttribute("type");
|
||||
|
||||
if (registerType == null || registerType.equals(""))
|
||||
registerType = "Integer";
|
||||
|
||||
sr = createServiceRegister(serviceLink, registerType);
|
||||
if (sr != null)
|
||||
{
|
||||
sr.setRegisterNode(registerNode);
|
||||
}
|
||||
return sr;
|
||||
}
|
||||
|
||||
private Element registerNode;
|
||||
|
||||
private ServiceLink serviceLink;
|
||||
private Integer ax,
|
||||
node,
|
||||
register;
|
||||
|
||||
private String registerType;
|
||||
private String registerName;
|
||||
|
||||
private ServiceRegisterControl
|
||||
serviceRegisterControl;
|
||||
|
||||
public ServiceRegister(ServiceLink serviceLink)
|
||||
{
|
||||
this.serviceLink = serviceLink;
|
||||
}
|
||||
|
||||
@TableColumn(label="Bezeichnung",after="Register",width=400)
|
||||
public String getRegisterName() {
|
||||
return registerName;
|
||||
}
|
||||
public void setRegisterName(String registerName) {
|
||||
this.registerName = registerName;
|
||||
}
|
||||
|
||||
@TableColumn(label="Register",firstColumn=true,width=80)
|
||||
public Integer getRegister() {
|
||||
return register;
|
||||
}
|
||||
public void setRegister(Integer register) {
|
||||
this.register = register;
|
||||
}
|
||||
|
||||
@TableColumn(label="Wert",after="Bezeichnung",width=250)
|
||||
abstract public String getTextRepresentation();
|
||||
|
||||
abstract public JComponent getEditorComponent();
|
||||
abstract public void acceptEditorValue();
|
||||
abstract public void updateEditorValue();
|
||||
|
||||
public Element getRegisterNode()
|
||||
{
|
||||
return registerNode;
|
||||
};
|
||||
public void setRegisterNode(Element registerNode)
|
||||
{
|
||||
this.registerNode = registerNode;
|
||||
|
||||
if (this.registerNode != null)
|
||||
{
|
||||
Element labelNode = (Element)this.registerNode.getElementsByTagName("Label").item(0);
|
||||
Element addressNode = (Element)this.registerNode.getElementsByTagName("Address").item(0);
|
||||
|
||||
register = Integer.decode(addressNode.getTextContent());
|
||||
registerName = labelNode.getTextContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ServiceLink getServiceLink() {
|
||||
return serviceLink;
|
||||
}
|
||||
public void setServiceLink(ServiceLink serviceLink) {
|
||||
this.serviceLink = serviceLink;
|
||||
}
|
||||
|
||||
|
||||
public Integer getAx() {
|
||||
return ax;
|
||||
}
|
||||
public void setAx(Integer ax) {
|
||||
this.ax = ax;
|
||||
}
|
||||
|
||||
|
||||
public Integer getNode() {
|
||||
return node;
|
||||
}
|
||||
public void setNode(Integer node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public Float readFloatValue()
|
||||
{
|
||||
return serviceLink.getServiceRegisterCache().getCachedFloat(ax, node, register);
|
||||
}
|
||||
public void writeFloatValue(Float value)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.serviceLink.writeFloat(ax.byteValue(), node.byteValue(), register,value);
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer readIntegerValue()
|
||||
{
|
||||
return serviceLink.getServiceRegisterCache().getCachedInteger(ax, node, register);
|
||||
}
|
||||
public void writeIntegerValue(Integer value)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.serviceLink.writeInt(ax.byteValue(), node.byteValue(), register,value);
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
serviceRegisterTypes = new HashMap<String, Class<? extends ServiceRegister>>();
|
||||
|
||||
serviceRegisterTypes.put("Integer", IntegerServiceRegister.class);
|
||||
serviceRegisterTypes.put("Float", FloatServiceRegister.class);
|
||||
serviceRegisterTypes.put("BitField", BitFieldServiceRegister.class);
|
||||
serviceRegisterTypes.put("IndexedList", IndexedListServiceRegister.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
|
||||
public interface ServiceRegisterControl {
|
||||
|
||||
public boolean requestFocusInWindow();
|
||||
|
||||
public Component getComponent();
|
||||
|
||||
public void setServiceRegister(ServiceRegister serviceRegister);
|
||||
|
||||
public void writeValue();
|
||||
public void readValue();
|
||||
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
package org.hwo.ui.servicelink.register;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.hwo.interactiveobjects.IInteractiveObjectEditor;
|
||||
import org.hwo.ui.KeyStrokeHelper;
|
||||
import org.hwo.ui.KeyStrokeListener;
|
||||
import org.hwo.ui.KeyStrokeParameters;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.BoxLayout;
|
||||
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
public class ServiceRegisterEditorDialog extends JDialog implements IInteractiveObjectEditor{
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
private ServiceRegister serviceRegister;
|
||||
private JTextField tfAx;
|
||||
private JTextField tfNode;
|
||||
private JTextField tfRegister;
|
||||
private JPanel panelEditorControl;
|
||||
private JTextField tfRegname;
|
||||
|
||||
private KeyStrokeHelper keyStrokeHelper;
|
||||
private JScrollPane scrollPane;
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public ServiceRegisterEditorDialog() {
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
if (serviceRegister != null)
|
||||
serviceRegister.getEditorComponent().requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
setBounds(100, 100, 327, 318);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "Service Register", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 0;
|
||||
contentPanel.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0};
|
||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
JLabel lblAchse = new JLabel("Achse:");
|
||||
GridBagConstraints gbc_lblAchse = new GridBagConstraints();
|
||||
gbc_lblAchse.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblAchse.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblAchse.gridx = 0;
|
||||
gbc_lblAchse.gridy = 0;
|
||||
panel.add(lblAchse, gbc_lblAchse);
|
||||
}
|
||||
{
|
||||
tfAx = new JTextField();
|
||||
tfAx.setEditable(false);
|
||||
GridBagConstraints gbc_tfAx = new GridBagConstraints();
|
||||
gbc_tfAx.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_tfAx.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfAx.gridx = 1;
|
||||
gbc_tfAx.gridy = 0;
|
||||
panel.add(tfAx, gbc_tfAx);
|
||||
tfAx.setColumns(10);
|
||||
}
|
||||
{
|
||||
JLabel lblKnoten = new JLabel("Knoten:");
|
||||
GridBagConstraints gbc_lblKnoten = new GridBagConstraints();
|
||||
gbc_lblKnoten.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblKnoten.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblKnoten.gridx = 0;
|
||||
gbc_lblKnoten.gridy = 1;
|
||||
panel.add(lblKnoten, gbc_lblKnoten);
|
||||
}
|
||||
{
|
||||
tfNode = new JTextField();
|
||||
tfNode.setEditable(false);
|
||||
GridBagConstraints gbc_tfNode = new GridBagConstraints();
|
||||
gbc_tfNode.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_tfNode.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfNode.gridx = 1;
|
||||
gbc_tfNode.gridy = 1;
|
||||
panel.add(tfNode, gbc_tfNode);
|
||||
tfNode.setColumns(10);
|
||||
}
|
||||
{
|
||||
JLabel lblRegister = new JLabel("Register:");
|
||||
GridBagConstraints gbc_lblRegister = new GridBagConstraints();
|
||||
gbc_lblRegister.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblRegister.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblRegister.gridx = 0;
|
||||
gbc_lblRegister.gridy = 2;
|
||||
panel.add(lblRegister, gbc_lblRegister);
|
||||
}
|
||||
{
|
||||
tfRegister = new JTextField();
|
||||
tfRegister.setEditable(false);
|
||||
GridBagConstraints gbc_tfRegister = new GridBagConstraints();
|
||||
gbc_tfRegister.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_tfRegister.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfRegister.gridx = 1;
|
||||
gbc_tfRegister.gridy = 2;
|
||||
panel.add(tfRegister, gbc_tfRegister);
|
||||
tfRegister.setColumns(10);
|
||||
}
|
||||
{
|
||||
JLabel lblNewLabel = new JLabel("Bezeichnung:");
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 3;
|
||||
panel.add(lblNewLabel, gbc_lblNewLabel);
|
||||
}
|
||||
{
|
||||
tfRegname = new JTextField();
|
||||
tfRegname.setEditable(false);
|
||||
GridBagConstraints gbc_tfRegname = new GridBagConstraints();
|
||||
gbc_tfRegname.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfRegname.gridx = 1;
|
||||
gbc_tfRegname.gridy = 3;
|
||||
panel.add(tfRegname, gbc_tfRegname);
|
||||
tfRegname.setColumns(10);
|
||||
}
|
||||
}
|
||||
{
|
||||
panelEditorControl = new JPanel();
|
||||
GridBagConstraints gbc_panelEditorControl = new GridBagConstraints();
|
||||
gbc_panelEditorControl.fill = GridBagConstraints.BOTH;
|
||||
gbc_panelEditorControl.gridx = 0;
|
||||
gbc_panelEditorControl.gridy = 1;
|
||||
contentPanel.add(panelEditorControl, gbc_panelEditorControl);
|
||||
panelEditorControl.setLayout(new BoxLayout(panelEditorControl, BoxLayout.X_AXIS));
|
||||
{
|
||||
scrollPane = new JScrollPane();
|
||||
panelEditorControl.add(scrollPane);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
accept();
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize()
|
||||
{
|
||||
keyStrokeHelper = new KeyStrokeHelper(this.getRootPane());
|
||||
keyStrokeHelper.setFocusedWindow(true);
|
||||
keyStrokeHelper.registerKeyStrokeListener(new KeyStrokeListener() {
|
||||
|
||||
@Override
|
||||
public void keyStroke(KeyStrokeParameters parameters) {
|
||||
switch (parameters.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
keyStrokeHelper.addKeyCode(KeyEvent.VK_ESCAPE);
|
||||
}
|
||||
|
||||
private void accept()
|
||||
{
|
||||
serviceRegister.acceptEditorValue();
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
private void cancel()
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
private void initializeView()
|
||||
{
|
||||
scrollPane.setViewportView(null);
|
||||
if (serviceRegister != null)
|
||||
{
|
||||
tfAx.setText(serviceRegister.getAx().toString());
|
||||
tfNode.setText(serviceRegister.getNode().toString());
|
||||
tfRegister.setText(serviceRegister.getRegister().toString());
|
||||
tfRegname.setText(serviceRegister.getRegisterName());
|
||||
scrollPane.setViewportView(serviceRegister.getEditorComponent());
|
||||
serviceRegister.updateEditorValue();
|
||||
}
|
||||
doLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInteractiveObject(Object o) {
|
||||
serviceRegister = (ServiceRegister)o;
|
||||
initializeView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInteractiveObject() {
|
||||
return serviceRegister;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
package org.hwo.ui.servicelink.register.bitfield;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink;
|
||||
import org.hwo.ui.servicelink.register.ServiceRegister;
|
||||
import org.hwo.ui.servicelink.register.ServiceRegisterControl;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
|
||||
public class BitFieldEditor extends JPanel implements ServiceRegisterControl {
|
||||
|
||||
private ServiceRegister serviceRegister;
|
||||
|
||||
private JCheckBox[] checkboxes;
|
||||
private JScrollPane scrollPane;
|
||||
private JPanel pBits;
|
||||
|
||||
private Integer intValue;
|
||||
|
||||
private List<Field> fields;
|
||||
|
||||
public class Field
|
||||
{
|
||||
int start,
|
||||
len;
|
||||
|
||||
String text;
|
||||
|
||||
JCheckBox checkbox;
|
||||
|
||||
public Field(int start,int len)
|
||||
{
|
||||
this.start = start;
|
||||
this.len = len;
|
||||
this.text = String.format("B%d",start);
|
||||
}
|
||||
|
||||
public Field(int start)
|
||||
{
|
||||
this.start = start;
|
||||
this.len = 1;
|
||||
this.text = String.format("B%d",start);
|
||||
}
|
||||
|
||||
public void setText(String text)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
public String getText()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getTextRepresentation()
|
||||
{
|
||||
if (BitFieldEditor.this.getIntValue() != null)
|
||||
{
|
||||
if ((BitFieldEditor.this.getIntValue() & (1<<start)) != 0)
|
||||
{
|
||||
return getText();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public Component getComponent()
|
||||
{
|
||||
if (checkbox == null)
|
||||
{
|
||||
checkbox = new JCheckBox();
|
||||
checkbox.setText(getText());
|
||||
}
|
||||
return checkbox;
|
||||
}
|
||||
public void sync()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public BitFieldEditor() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 0;
|
||||
add(scrollPane, gbc_scrollPane);
|
||||
|
||||
pBits = new JPanel();
|
||||
scrollPane.setViewportView(pBits);
|
||||
pBits.setLayout(new BoxLayout(pBits, BoxLayout.Y_AXIS));
|
||||
|
||||
checkboxes = new JCheckBox[0];
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize()
|
||||
{
|
||||
removeAllFieldComponents();
|
||||
createFieldControls();
|
||||
|
||||
doLayout();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
protected void createFieldControls()
|
||||
{
|
||||
fields = new ArrayList<BitFieldEditor.Field>();
|
||||
for (int i=0;i<32;i++)
|
||||
{
|
||||
Field field = new Field(i);
|
||||
fields.add(field);
|
||||
addFieldComponent(field.getComponent());
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeAllFieldComponents()
|
||||
{
|
||||
pBits.removeAll();
|
||||
}
|
||||
protected void addFieldComponent(Component component)
|
||||
{
|
||||
pBits.add(component);
|
||||
}
|
||||
|
||||
public void synchronize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
||||
this.serviceRegister = serviceRegister;
|
||||
}
|
||||
|
||||
public Integer getIntValue()
|
||||
{
|
||||
return this.intValue;
|
||||
}
|
||||
public void setIntValue(Integer value)
|
||||
{
|
||||
this.intValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeValue() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readValue() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.hwo.ui.shapes;
|
||||
|
||||
import java.awt.Polygon;
|
||||
|
||||
public class Rectangle extends Polygon {
|
||||
|
||||
public Rectangle(int left,int top,int width,int height)
|
||||
{
|
||||
super(new int[]{left,left + width - 1,left + width - 1,left},new int[]{ top,top,top + height - 1,top + height - 1 },4);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.hwo.ui.shapes;
|
||||
|
||||
import java.awt.Polygon;
|
||||
|
||||
public class Triangle extends Polygon {
|
||||
|
||||
public Triangle(int x1,int y1,int x2,int y2,int x3,int y3)
|
||||
{
|
||||
super(new int[]{x1,x2,x3},new int[]{y1,y2,y3},3);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package org.hwo.ui.toolbar;
|
||||
|
||||
import java.awt.Image;
|
||||
|
||||
|
||||
public class UITool {
|
||||
|
||||
private Object tool;
|
||||
private String label;
|
||||
private String help;
|
||||
private Image image;
|
||||
|
||||
private boolean selected;
|
||||
|
||||
public UITool(){
|
||||
|
||||
}
|
||||
|
||||
public Object getTool() {
|
||||
return tool;
|
||||
}
|
||||
public void setTool(Object tool) {
|
||||
this.tool = tool;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return help;
|
||||
}
|
||||
public void setHelp(String help) {
|
||||
this.help = help;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
public void setImage(Image image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
|
||||
public void select(){
|
||||
this.selected = true;
|
||||
}
|
||||
public void unselect(){
|
||||
this.selected = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.ui.CellRenderer;
|
||||
|
||||
public class DefaultTreeTableColumnModel implements TreeTableColumnModel {
|
||||
|
||||
public class Column
|
||||
{
|
||||
private String label;
|
||||
private int width;
|
||||
private int modelColumn;
|
||||
private CellRenderer
|
||||
cellRenderer;
|
||||
private TreeTablePopupListener
|
||||
popupListener;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
fireColumnsChanged();
|
||||
}
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public Column setWidth(int width) {
|
||||
this.width = width;
|
||||
fireColumnsChanged();
|
||||
|
||||
return this;
|
||||
}
|
||||
public int getModelColumn() {
|
||||
return modelColumn;
|
||||
}
|
||||
public Column setModelColumn(int modelColumn) {
|
||||
this.modelColumn = modelColumn;
|
||||
fireColumnsChanged();
|
||||
|
||||
return this; }
|
||||
public CellRenderer getCellRenderer() {
|
||||
return cellRenderer;
|
||||
}
|
||||
public Column setCellRenderer(CellRenderer cellRenderer) {
|
||||
this.cellRenderer = cellRenderer;
|
||||
|
||||
return this;
|
||||
}
|
||||
public TreeTablePopupListener getPopupListener() {
|
||||
return popupListener;
|
||||
}
|
||||
public Column setPopupListener(TreeTablePopupListener popupListener) {
|
||||
this.popupListener = popupListener;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Column> columns;
|
||||
private List<TreeTableModelListener> treeTableModelListener;
|
||||
|
||||
public DefaultTreeTableColumnModel()
|
||||
{
|
||||
treeTableModelListener = new LinkedList<TreeTableModelListener>();
|
||||
|
||||
columns = new ArrayList<DefaultTreeTableColumnModel.Column>();
|
||||
Column column = new Column();
|
||||
column.label = "";
|
||||
column.width = 280;
|
||||
columns.add(column);
|
||||
}
|
||||
|
||||
public Column addColumn(String label)
|
||||
{
|
||||
return addColumn(label,100);
|
||||
}
|
||||
|
||||
public Column addColumn(String label,int width)
|
||||
{
|
||||
return addColumn(label, width, -1);
|
||||
}
|
||||
|
||||
public Column addColumn(String label,int width,int modelColumn)
|
||||
{
|
||||
Column column = new Column();
|
||||
column.label = label;
|
||||
column.width = width;
|
||||
columns.add(column);
|
||||
|
||||
if (modelColumn == -1)
|
||||
column.modelColumn = columns.indexOf(column);
|
||||
else
|
||||
column.modelColumn = modelColumn;
|
||||
|
||||
fireColumnsChanged();
|
||||
return column;
|
||||
}
|
||||
|
||||
public void removeColumn(int column)
|
||||
{
|
||||
columns.remove(column);
|
||||
fireColumnsChanged();
|
||||
}
|
||||
|
||||
public Column getColumn(int column)
|
||||
{
|
||||
return columns.get(column);
|
||||
}
|
||||
|
||||
public int indexOfColumn(Column column)
|
||||
{
|
||||
return columns.indexOf(column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columns.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnLabel(int column) {
|
||||
return columns.get(column).getLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnWidth(int column) {
|
||||
return columns.get(column).getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnPos(int column) {
|
||||
int x = 0;
|
||||
for (int i=0;i<column;i++)
|
||||
x += getColumnWidth(i);
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTreeTableModelListener(TreeTableModelListener listener) {
|
||||
treeTableModelListener.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTreeTableModelListener(TreeTableModelListener listener) {
|
||||
treeTableModelListener.remove(listener);
|
||||
}
|
||||
|
||||
private void fireColumnsChanged()
|
||||
{
|
||||
for (TreeTableModelListener listener:treeTableModelListener)
|
||||
listener.rowsChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnAtX(int x) {
|
||||
for (int i=0;i<columns.size();i++)
|
||||
{
|
||||
if (x < getColumnPos(i+1))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellRenderer getColumnCellRenderer(int column) {
|
||||
return columns.get(column).getCellRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnModelColumn(int x)
|
||||
{
|
||||
return getColumn(x).modelColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeTablePopupListener getPopup(int row, int column) {
|
||||
TreeTablePopupListener listener;
|
||||
|
||||
listener = getPopupFromColumn(column);
|
||||
if (listener == null)
|
||||
listener = getPopupFromRow(row);
|
||||
|
||||
return listener;
|
||||
}
|
||||
|
||||
protected TreeTablePopupListener getPopupFromRow(int row)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected TreeTablePopupListener getPopupFromColumn(int column)
|
||||
{
|
||||
return columns.get(column).getPopupListener();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultTreeTableModel implements TreeTableModel {
|
||||
|
||||
private TreeTableElement rootNode;
|
||||
private List<TreeTableModelListener> treeTableModelListener;
|
||||
|
||||
public DefaultTreeTableModel()
|
||||
{
|
||||
treeTableModelListener = new LinkedList<TreeTableModelListener>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object node) {
|
||||
return ((TreeTableElement)node).getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildCount(Object parent) {
|
||||
return ((TreeTableElement)parent).getChildCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getChild(Object parent, int index) {
|
||||
return ((TreeTableElement)parent).getChild(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRoot() {
|
||||
return getRootNode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isLeaf(Object node) {
|
||||
if (((TreeTableElement)node).getChildCount()==0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(Object node, int column) {
|
||||
return ((TreeTableElement)node).getValue(column);
|
||||
}
|
||||
|
||||
|
||||
public TreeTableElement getRootNode() {
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
public void setRootNode(TreeTableElement rootNode) {
|
||||
this.rootNode = rootNode;
|
||||
fireRowsChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeTableColumnModel getDefaultColumnModel() {
|
||||
return new DefaultTreeTableColumnModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTreeTableModelListener(TreeTableModelListener listener) {
|
||||
treeTableModelListener.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTreeTableModelListener(TreeTableModelListener listener) {
|
||||
treeTableModelListener.remove(listener);
|
||||
}
|
||||
|
||||
private void fireRowsChanged()
|
||||
{
|
||||
for (TreeTableModelListener listener:treeTableModelListener)
|
||||
listener.rowsChanged();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,661 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.Scrollable;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import org.hwo.ui.CellEditor;
|
||||
import org.hwo.ui.CellEditorArgs;
|
||||
import org.hwo.ui.CellEditorListener;
|
||||
import org.hwo.ui.CellRenderer;
|
||||
import org.hwo.ui.DefaultCellEditor;
|
||||
import org.hwo.ui.DefaultCellRenderer;
|
||||
import org.hwo.ui.SelectionMode;
|
||||
import org.hwo.ui.shapes.Triangle;
|
||||
import org.hwo.ui.treetable.DefaultTreeTableColumnModel.Column;
|
||||
|
||||
public class TreeTable extends JComponent implements Scrollable, TreeTableModelListener, CellEditorListener {
|
||||
|
||||
class NodeState
|
||||
{
|
||||
private boolean opened;
|
||||
|
||||
public int indentation;
|
||||
|
||||
public boolean isOpened() {
|
||||
return opened;
|
||||
}
|
||||
|
||||
public void setOpened(boolean opened) {
|
||||
this.opened = opened;
|
||||
}
|
||||
}
|
||||
public class HeaderView extends JComponent
|
||||
{
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
|
||||
g.drawLine(0, getHeight()-1, TreeTable.this.preferredSize.width - 1, getHeight()-1);
|
||||
|
||||
for (int i=0;i<columnModel.getColumnCount();i++)
|
||||
{
|
||||
int left = columnModel.getColumnPos(i);
|
||||
int width = columnModel.getColumnWidth(i);
|
||||
int right = left + width - 1;
|
||||
|
||||
g.setColor(getForeground());
|
||||
g.drawString(columnModel.getColumnLabel(i), left + 2, rowHeight - 3);
|
||||
g.drawLine( right, 0, right, getHeight());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TreeTableModel model;
|
||||
private TreeTableColumnModel
|
||||
columnModel;
|
||||
|
||||
private int rowHeight;
|
||||
|
||||
private List<Object> rowObjects;
|
||||
private Hashtable<Object, NodeState>
|
||||
nodeStates;
|
||||
|
||||
private Hashtable<Class<?>, CellRenderer> cellRendererList;
|
||||
private Hashtable<Class<?>, CellEditor> cellEditorList;
|
||||
|
||||
private JViewport headerViewport;
|
||||
private Dimension preferredSize;
|
||||
|
||||
private List<TreeTablePopupListener> popupListener;
|
||||
private List<TreeTableMouseListener> mouseListener;
|
||||
|
||||
private CellEditor activeEditor;
|
||||
|
||||
private SelectionMode selectionMode;
|
||||
private int selectedRow;
|
||||
|
||||
|
||||
public TreeTable()
|
||||
{
|
||||
popupListener = new LinkedList<TreeTablePopupListener>();
|
||||
mouseListener = new LinkedList<TreeTableMouseListener>();
|
||||
|
||||
preferredSize = new Dimension(1,1);
|
||||
|
||||
rowHeight = 20;
|
||||
setBackground(Color.WHITE);
|
||||
|
||||
cellRendererList = new Hashtable<Class<?>, CellRenderer>();
|
||||
cellRendererList.put(Object.class, new DefaultCellRenderer());
|
||||
|
||||
cellEditorList = new Hashtable<Class<?>, CellEditor>();
|
||||
addCellEditor(Object.class, new DefaultCellEditor());
|
||||
|
||||
rowObjects = new ArrayList<Object>();
|
||||
nodeStates = new Hashtable<Object, TreeTable.NodeState>();
|
||||
setModel(new DefaultTreeTableModel());
|
||||
|
||||
addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger())
|
||||
firePopupRequestedFromMouseEvent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger())
|
||||
firePopupRequestedFromMouseEvent(e);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row,column;
|
||||
|
||||
row = e.getY() / rowHeight;
|
||||
column = columnModel.getColumnAtX(e.getX());
|
||||
|
||||
TreeTable.this.mouseClicked(e.getX(), e.getY(), e.getClickCount(), row, column);
|
||||
|
||||
if (e.isPopupTrigger())
|
||||
firePopupRequestedFromMouseEvent(e);
|
||||
else
|
||||
fireMouseClicked(e);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
prepareWidth();
|
||||
prepareHeight();
|
||||
|
||||
selectedRow = -1;
|
||||
}
|
||||
|
||||
public Point mouseToCell(int x,int y)
|
||||
{
|
||||
Point p = new Point();
|
||||
p.x = columnModel.getColumnAtX(x);
|
||||
p.y = y / rowHeight;
|
||||
|
||||
if ((p.x >= columnModel.getColumnCount()) || (p.y >= rowObjects.size()))
|
||||
return null;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public Object getRowObject(int row)
|
||||
{
|
||||
return this.rowObjects.get(row);
|
||||
}
|
||||
|
||||
private CellRenderer findCellRenderer(Class<?> clazz)
|
||||
{
|
||||
if (clazz == null)
|
||||
return new DefaultCellRenderer();
|
||||
if (cellRendererList.containsKey(clazz))
|
||||
return cellRendererList.get(clazz);
|
||||
if (clazz.getSuperclass()!=null)
|
||||
return findCellRenderer(clazz.getSuperclass());
|
||||
return new DefaultCellRenderer();
|
||||
}
|
||||
|
||||
public void addCellEditor(Class<?> clazz,CellEditor editor)
|
||||
{
|
||||
editor.addCellEditorListener(this);
|
||||
cellEditorList.put(clazz,editor);
|
||||
}
|
||||
|
||||
private CellEditor findCellEditor(Class<?> clazz)
|
||||
{
|
||||
if (clazz == null)
|
||||
return null;
|
||||
if (cellEditorList.containsKey(clazz))
|
||||
return cellEditorList.get(clazz);
|
||||
|
||||
return cellEditorList.get(Object.class);
|
||||
|
||||
}
|
||||
|
||||
private void mouseClicked(int x,int y,int clickCount,int row,int column)
|
||||
{
|
||||
System.err.println("Click: " + x + "/" + y + " ( " + row + " : " + column + " )");
|
||||
if (clickCount == 1)
|
||||
{
|
||||
if (column == 0)
|
||||
{
|
||||
if (x < rowHeight)
|
||||
{
|
||||
NodeState state = getState(rowObjects.get(row));
|
||||
setOpened(rowObjects.get(row), !state.opened);
|
||||
} else if (selectionMode == SelectionMode.ROW)
|
||||
{
|
||||
selectedRow = row;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareWidth()
|
||||
{
|
||||
preferredSize.width = columnModel.getColumnPos(columnModel.getColumnCount());
|
||||
}
|
||||
|
||||
private void prepareHeight()
|
||||
{
|
||||
prepareRows();
|
||||
preferredSize.height = rowHeight * rowObjects.size();
|
||||
}
|
||||
|
||||
private void prepareRow(Object row)
|
||||
{
|
||||
if (row!=null)
|
||||
{
|
||||
int ind = getState(row).indentation;
|
||||
|
||||
rowObjects.add(row);
|
||||
if (model.getChildCount(row)>0)
|
||||
{
|
||||
if (getState(row).isOpened())
|
||||
{
|
||||
for (int i=0;i<model.getChildCount(row);i++)
|
||||
{
|
||||
Object child = model.getChild(row, i);
|
||||
getState(child).indentation = ind + 1 ;
|
||||
prepareRow( child );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void prepareRows()
|
||||
{
|
||||
if (rowObjects == null)
|
||||
return;
|
||||
|
||||
rowObjects.clear();
|
||||
|
||||
if (model.getRoot()!=null)
|
||||
{
|
||||
getState(model.getRoot()).indentation = 0;
|
||||
prepareRow(model.getRoot());
|
||||
};
|
||||
}
|
||||
|
||||
private NodeState getState(Object node)
|
||||
{
|
||||
if (!nodeStates.containsKey(node))
|
||||
nodeStates.put(node, new NodeState());
|
||||
return nodeStates.get(node);
|
||||
}
|
||||
|
||||
private Rectangle getCellRect(int row,int column)
|
||||
{
|
||||
int left = columnModel.getColumnPos(column);
|
||||
int width = columnModel.getColumnWidth(column);
|
||||
int top = rowHeight * row;
|
||||
|
||||
return new Rectangle(left, top, width, rowHeight);
|
||||
}
|
||||
|
||||
public void paintRow(Graphics g,int row)
|
||||
{
|
||||
Object ro = rowObjects.get(row);
|
||||
NodeState state = getState(ro);
|
||||
int top = rowHeight * row;
|
||||
int bottom = top + rowHeight - 1;
|
||||
|
||||
if (selectedRow == row)
|
||||
{
|
||||
g.setColor(Color.BLUE);
|
||||
g.fillRect(0, top, getColumnModel().getColumnPos(getColumnModel().getColumnCount()) - 1, rowHeight - 1);
|
||||
}
|
||||
|
||||
g.setColor(Color.black);
|
||||
g.drawLine(0, bottom, getWidth(), bottom);
|
||||
|
||||
for (int column = 0; column < columnModel.getColumnCount(); column++)
|
||||
{
|
||||
int left = columnModel.getColumnPos(column);
|
||||
int width = columnModel.getColumnWidth(column);
|
||||
int right = left + width - 1;
|
||||
|
||||
g.drawLine(right , top, right, bottom);
|
||||
|
||||
|
||||
if (column==0)
|
||||
{
|
||||
int a = rowHeight / 4;
|
||||
int b = rowHeight / 2;
|
||||
|
||||
left += state.indentation * 5;
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
if (model.getChildCount(ro)>0)
|
||||
{
|
||||
if (!state.isOpened())
|
||||
{
|
||||
g.drawPolygon(new Triangle(left + a, top + a, left + b, top + b, left + a, bottom - a));
|
||||
} else
|
||||
{
|
||||
g.drawPolygon(new Triangle(left + a, top + b, left + a + b, top + b, left + b, bottom - a ));
|
||||
}
|
||||
}
|
||||
|
||||
left += rowHeight;
|
||||
}
|
||||
|
||||
g.setColor(getForeground());
|
||||
|
||||
Object value = model.getValue(ro, columnModel.getColumnModelColumn(column));
|
||||
CellRenderer renderer = columnModel.getColumnCellRenderer(column);
|
||||
|
||||
if (renderer == null)
|
||||
if (value != null)
|
||||
renderer = findCellRenderer(value.getClass());
|
||||
else
|
||||
renderer = findCellRenderer(null);
|
||||
|
||||
Rectangle rect = new Rectangle(left, top, width, rowHeight);
|
||||
|
||||
Rectangle clipRestore = g.getClipBounds();
|
||||
|
||||
if (clipRestore.intersects(rect))
|
||||
{
|
||||
Rectangle rectClip = clipRestore.intersection(rect);
|
||||
|
||||
g.setClip(rectClip);
|
||||
renderer.renderCell(g, row, column, rect, value, ro);
|
||||
g.setClip(clipRestore);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
prepareRows();
|
||||
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
for (int i=0;i<rowObjects.size();i++)
|
||||
{
|
||||
paintRow(g, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void firePopupRequestedFromMouseEvent(MouseEvent event)
|
||||
{
|
||||
Point p = mouseToCell(event.getX(), event.getY());
|
||||
TreeTablePopupArgs args = new TreeTablePopupArgs(this, p.y,p.x, event.getX(), event.getY());
|
||||
firePopupRequested(args);
|
||||
}
|
||||
private void firePopupRequested(TreeTablePopupArgs args)
|
||||
{
|
||||
TreeTablePopupListener listener = columnModel.getPopup(args.getRow(), args.getColumn());
|
||||
if (listener != null)
|
||||
listener.popupRequest(args);
|
||||
else
|
||||
for (TreeTablePopupListener l:popupListener)
|
||||
l.popupRequest(args);
|
||||
}
|
||||
|
||||
public void addPopupListener(TreeTablePopupListener listener)
|
||||
{
|
||||
popupListener.add(listener);
|
||||
}
|
||||
public void removePopupListener(TreeTablePopupListener listener)
|
||||
{
|
||||
popupListener.remove(listener);
|
||||
}
|
||||
|
||||
private void fireMouseClicked(MouseEvent event)
|
||||
{
|
||||
TreeTableMouseArgs args = new TreeTableMouseArgs(this,event);
|
||||
|
||||
if (args.getMouseEvent().getClickCount()==2)
|
||||
{
|
||||
if (args.getRowObject() != null)
|
||||
{
|
||||
startEditor(args.getRow(),args.getColumn());
|
||||
}
|
||||
}
|
||||
|
||||
for (TreeTableMouseListener listener:mouseListener)
|
||||
listener.mouseClicked(args);
|
||||
}
|
||||
|
||||
public void addMouseListener(TreeTableMouseListener listener)
|
||||
{
|
||||
mouseListener.add(listener);
|
||||
}
|
||||
public void removeMouseListener(TreeTableMouseListener listener)
|
||||
{
|
||||
mouseListener.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredScrollableViewportSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollableBlockIncrement(Rectangle visibleRect,
|
||||
int orientation, int direction) {
|
||||
if (orientation == SwingConstants.HORIZONTAL)
|
||||
return visibleRect.width / 2;
|
||||
else
|
||||
return visibleRect.height / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportHeight() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportWidth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollableUnitIncrement(Rectangle visibleRect,
|
||||
int orientation, int direction) {
|
||||
if (orientation == SwingConstants.HORIZONTAL)
|
||||
return 10;
|
||||
else
|
||||
return rowHeight;
|
||||
}
|
||||
|
||||
public TreeTableModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public DefaultTreeTableModel getDefaultModel()
|
||||
{
|
||||
return (DefaultTreeTableModel)model;
|
||||
}
|
||||
|
||||
public void setModel(TreeTableModel model) {
|
||||
|
||||
if (this.model != null)
|
||||
this.model.removeTreeTableModelListener(this);
|
||||
|
||||
rowObjects.clear();
|
||||
nodeStates.clear();
|
||||
|
||||
this.model = model;
|
||||
this.model.addTreeTableModelListener(this);
|
||||
|
||||
TreeTableColumnModel cm = model.getDefaultColumnModel();
|
||||
if (cm != null)
|
||||
setColumnModel(cm);
|
||||
|
||||
prepareRows();
|
||||
}
|
||||
|
||||
public int getRowHeight() {
|
||||
return rowHeight;
|
||||
}
|
||||
|
||||
public void setRowHeight(int rowHeight) {
|
||||
this.rowHeight = rowHeight;
|
||||
}
|
||||
|
||||
|
||||
public void setOpened(Object node,boolean opened)
|
||||
{
|
||||
getState(node).opened = opened;
|
||||
prepareHeight();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public TreeTableColumnModel getColumnModel() {
|
||||
return columnModel;
|
||||
}
|
||||
|
||||
public void setColumnModel(TreeTableColumnModel columnModel) {
|
||||
if (this.columnModel != null)
|
||||
this.columnModel.removeTreeTableModelListener(this);
|
||||
this.columnModel = columnModel;
|
||||
|
||||
this.columnModel.addTreeTableModelListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void columnsChanged() {
|
||||
buildHeader();
|
||||
prepareWidth();
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rowsChanged() {
|
||||
prepareHeight();
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repaint() {
|
||||
invalidate();
|
||||
|
||||
if (getParent()!=null)
|
||||
getParent().validate();
|
||||
|
||||
super.repaint();
|
||||
}
|
||||
|
||||
private void buildHeader()
|
||||
{
|
||||
if (headerViewport == null)
|
||||
headerViewport = new JViewport();
|
||||
|
||||
headerViewport.removeAll();
|
||||
|
||||
HeaderView hv = new HeaderView();
|
||||
hv.setSize(columnModel.getColumnPos(columnModel.getColumnCount()),24);
|
||||
hv.setPreferredSize(new Dimension(columnModel.getColumnPos(columnModel.getColumnCount()),24));
|
||||
headerViewport.setView(hv);
|
||||
}
|
||||
|
||||
private JViewport getHeaderViewport()
|
||||
{
|
||||
if (headerViewport == null)
|
||||
buildHeader();
|
||||
return headerViewport;
|
||||
}
|
||||
|
||||
private void configureEnclosingScrollPane()
|
||||
{
|
||||
prepareWidth();
|
||||
prepareHeight();
|
||||
|
||||
if (JViewport.class.isInstance(getParent()) && JScrollPane.class.isInstance(getParent().getParent()))
|
||||
{
|
||||
JScrollPane sp = (JScrollPane)getParent().getParent();
|
||||
sp.setColumnHeader(getHeaderViewport());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNotify() {
|
||||
configureEnclosingScrollPane();
|
||||
super.addNotify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNotify() {
|
||||
super.removeNotify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return preferredSize;
|
||||
}
|
||||
|
||||
|
||||
public void cancelEditor()
|
||||
{
|
||||
if (activeEditor != null)
|
||||
{
|
||||
activeEditor.editCancel();
|
||||
activeEditor = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void startEditor(int row,int column)
|
||||
{
|
||||
if (activeEditor != null)
|
||||
cancelEditor();
|
||||
|
||||
Object value = getModel().getValue(rowObjects.get(row), column);
|
||||
|
||||
activeEditor = findCellEditor(value.getClass());
|
||||
|
||||
if (activeEditor != null)
|
||||
{
|
||||
activeEditor.editBegin(this, getCellRect(row, column), value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editBegin(CellEditorArgs args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editCanceled(CellEditorArgs args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editFinished(CellEditorArgs args) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int getSelectedRow() {
|
||||
return selectedRow;
|
||||
}
|
||||
|
||||
public void setSelectedRow(int selectedRow) {
|
||||
this.selectedRow = selectedRow;
|
||||
}
|
||||
|
||||
public SelectionMode getSelectionMode() {
|
||||
return selectionMode;
|
||||
}
|
||||
|
||||
public void setSelectionMode(SelectionMode selectionMode) {
|
||||
this.selectionMode = selectionMode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
import org.hwo.ui.CellRenderer;
|
||||
|
||||
public interface TreeTableColumnModel {
|
||||
|
||||
public void addTreeTableModelListener(TreeTableModelListener listener);
|
||||
public void removeTreeTableModelListener(TreeTableModelListener listener);
|
||||
|
||||
public int getColumnCount();
|
||||
public String getColumnLabel(int column);
|
||||
public int getColumnWidth(int column);
|
||||
|
||||
public int getColumnPos(int column);
|
||||
|
||||
public int getColumnAtX(int x);
|
||||
|
||||
public int getColumnModelColumn(int x);
|
||||
|
||||
public CellRenderer
|
||||
getColumnCellRenderer(int column);
|
||||
|
||||
public TreeTablePopupListener
|
||||
getPopup(int row,int column);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
public interface TreeTableElement {
|
||||
|
||||
public TreeTableElement
|
||||
getParent();
|
||||
|
||||
public Object getValue(int column);
|
||||
|
||||
public int getChildCount();
|
||||
public TreeTableElement
|
||||
getChild(int index);
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
public interface TreeTableModel {
|
||||
|
||||
public void addTreeTableModelListener(TreeTableModelListener listener);
|
||||
public void removeTreeTableModelListener(TreeTableModelListener listener);
|
||||
|
||||
public Object getParent(Object node);
|
||||
|
||||
public int getChildCount(Object parent);
|
||||
public Object getChild(Object parent,int index);
|
||||
|
||||
public Object getRoot();
|
||||
|
||||
public boolean isLeaf(Object node);
|
||||
|
||||
public Object getValue(Object node,int column);
|
||||
|
||||
public TreeTableColumnModel
|
||||
getDefaultColumnModel();
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
public interface TreeTableModelListener {
|
||||
|
||||
public void columnsChanged();
|
||||
public void rowsChanged();
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class TreeTableMouseArgs {
|
||||
|
||||
private MouseEvent mouseEvent;
|
||||
private int row, column;
|
||||
private TreeTable treeTable;
|
||||
|
||||
private Object rowObject;
|
||||
|
||||
|
||||
public TreeTableMouseArgs(TreeTable treeTable,MouseEvent event)
|
||||
{
|
||||
this.treeTable = treeTable;
|
||||
mouseEvent = event;
|
||||
|
||||
Point p = treeTable.mouseToCell(event.getX(), event.getY());
|
||||
|
||||
row = p.y;
|
||||
column = p.x;
|
||||
|
||||
rowObject = treeTable.getRowObject(row);
|
||||
|
||||
}
|
||||
|
||||
public MouseEvent getMouseEvent() {
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public void setMouseEvent(MouseEvent mouseEvent) {
|
||||
this.mouseEvent = mouseEvent;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return row;
|
||||
}
|
||||
|
||||
public void setRow(int row) {
|
||||
this.row = row;
|
||||
}
|
||||
|
||||
public int getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(int column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public TreeTable getTreeTable() {
|
||||
return treeTable;
|
||||
}
|
||||
|
||||
public void setTreeTable(TreeTable treeTable) {
|
||||
this.treeTable = treeTable;
|
||||
}
|
||||
|
||||
public Object getRowObject() {
|
||||
return rowObject;
|
||||
}
|
||||
|
||||
public void setRowObject(Object rowObject) {
|
||||
this.rowObject = rowObject;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
public interface TreeTableMouseListener {
|
||||
|
||||
public void mouseClicked(TreeTableMouseArgs args);
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
public class TreeTablePopupArgs {
|
||||
|
||||
private TreeTable treeTable;
|
||||
private int row,
|
||||
column;
|
||||
private int mouseX,
|
||||
mouseY;
|
||||
|
||||
public TreeTablePopupArgs(TreeTable treeTable,int row,int column,int x,int y)
|
||||
{
|
||||
this.setTreeTable(treeTable);
|
||||
this.setRow(row);
|
||||
this.setColumn(column);
|
||||
this.setMouseX(x);
|
||||
this.setMouseY(y);
|
||||
}
|
||||
|
||||
public int getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(int column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public TreeTable getTreeTable() {
|
||||
return treeTable;
|
||||
}
|
||||
|
||||
public void setTreeTable(TreeTable treeTable) {
|
||||
this.treeTable = treeTable;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return row;
|
||||
}
|
||||
|
||||
public void setRow(int row) {
|
||||
this.row = row;
|
||||
}
|
||||
|
||||
public int getMouseX() {
|
||||
return mouseX;
|
||||
}
|
||||
|
||||
public void setMouseX(int mouseX) {
|
||||
this.mouseX = mouseX;
|
||||
}
|
||||
|
||||
public int getMouseY() {
|
||||
return mouseY;
|
||||
}
|
||||
|
||||
public void setMouseY(int mouseY) {
|
||||
this.mouseY = mouseY;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.hwo.ui.treetable;
|
||||
|
||||
public interface TreeTablePopupListener {
|
||||
|
||||
public void popupRequest(TreeTablePopupArgs args);
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package org.hwo.ui.wellknown;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
public class WellKnown {
|
||||
|
||||
|
||||
|
||||
public static WellKnownClass getWellKnownClass(Class<?> clazz)
|
||||
{
|
||||
WellKnownClass wk = clazz.getAnnotation(WellKnownClass.class);
|
||||
if (wk != null)
|
||||
return wk;
|
||||
if (clazz.getSuperclass() != null)
|
||||
return getWellKnownClass(clazz.getSuperclass());
|
||||
return null;
|
||||
}
|
||||
|
||||
static public Method findAnnotatedMethod(Class<?> clazz,Class<? extends Annotation> annotationClass)
|
||||
{
|
||||
for (Method method:clazz.getDeclaredMethods())
|
||||
{
|
||||
Object anno = method.getAnnotation(annotationClass);
|
||||
if (anno != null)
|
||||
return method;
|
||||
}
|
||||
if (clazz.getSuperclass() != null)
|
||||
return findAnnotatedMethod(clazz.getSuperclass(), annotationClass);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static public String getDisplayLabel(Object o)
|
||||
{
|
||||
Method m = findAnnotatedMethod(o.getClass(), WellKnownDisplayLabel.class);
|
||||
if (m != null)
|
||||
{
|
||||
m.setAccessible(true);
|
||||
try {
|
||||
Object result = m.invoke(o, null);
|
||||
return result.toString();
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.hwo.ui.wellknown;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface WellKnownClass {
|
||||
|
||||
class DefaultWellKnownSearch implements WellKnownSearch
|
||||
{
|
||||
@Override
|
||||
public List<Object> keywordSearch(Class<?> clazz, String keyword) {
|
||||
return new ArrayList<Object>();
|
||||
}
|
||||
@Override
|
||||
public void setClazz(Class<?> clazz) {
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultWellKnownEditor implements WellKnownEditor
|
||||
{
|
||||
@Override
|
||||
public void getValue() {
|
||||
}
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
}
|
||||
@Override
|
||||
public void show(boolean modal) {
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultWellKnownIdentity implements WellKnownIdentity
|
||||
{
|
||||
|
||||
@Override
|
||||
public Object getIdentity(Object o) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object loadWithIdentity(Class<?> clazz, Object identity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Object o) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Class<? extends WellKnownSearch> search() default DefaultWellKnownSearch.class;
|
||||
public Class<? extends WellKnownEditor> editor() default DefaultWellKnownEditor.class;
|
||||
public Class<? extends WellKnownIdentity> identity() default DefaultWellKnownIdentity.class;
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.hwo.ui.wellknown;
|
||||
|
||||
public @interface WellKnownDisplayLabel {
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.hwo.ui.wellknown;
|
||||
|
||||
public interface WellKnownEditor {
|
||||
|
||||
public void setValue(Object value);
|
||||
public void getValue();
|
||||
|
||||
public void show(boolean modal);
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.hwo.ui.wellknown;
|
||||
|
||||
public interface WellKnownIdentity {
|
||||
|
||||
public Object getIdentity(Object o);
|
||||
public Object loadWithIdentity(Class<?> clazz,Object identity);
|
||||
public void save(Object o);
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.hwo.ui.wellknown;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface WellKnownSearch {
|
||||
|
||||
public List<Object> keywordSearch(Class<?> clazz,String keyword);
|
||||
public void setClazz(Class<?> clazz);
|
||||
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
package org.hwo.ui.windowstate;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public abstract class AbstractStatedWindowManager implements StatedWindowManager {
|
||||
|
||||
private Class<? extends JFrame> clazzFrame;
|
||||
private Hashtable<JFrame, WindowState> windows;
|
||||
|
||||
protected AbstractStatedWindowManager(Class<? extends JFrame> clazzFrame)
|
||||
{
|
||||
this.clazzFrame = clazzFrame;
|
||||
this.windows = new Hashtable<JFrame, WindowState>();
|
||||
|
||||
WindowManager.getInstance().registerWindowManager(this);
|
||||
}
|
||||
|
||||
public WindowState getStateOfWindow(JFrame frame)
|
||||
{
|
||||
if (!windows.containsKey(frame))
|
||||
registerNewWindow(frame);
|
||||
|
||||
return windows.get(frame);
|
||||
}
|
||||
|
||||
public void saveState(JFrame frame)
|
||||
{
|
||||
saveWindowPosition(getStateOfWindow(frame));
|
||||
}
|
||||
|
||||
public void restoreState(JFrame frame)
|
||||
{
|
||||
restoreWindowPosition(getStateOfWindow(frame));
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends JFrame> getManagedClass() {
|
||||
return clazzFrame;
|
||||
}
|
||||
|
||||
private void restoreWindowPosition(WindowState state){
|
||||
Rectangle bounds = new Rectangle();
|
||||
bounds.x = Integer.decode(state.getProperties().getProperty("left", "0"));
|
||||
bounds.y = Integer.decode(state.getProperties().getProperty("top", "0"));
|
||||
bounds.width = Integer.decode(state.getProperties().getProperty("width", "0"));
|
||||
bounds.height = Integer.decode(state.getProperties().getProperty("height", "0"));
|
||||
state.jframe.setBounds(bounds);
|
||||
}
|
||||
|
||||
private void saveWindowPosition(WindowState state) {
|
||||
Rectangle bounds = state.jframe.getBounds();
|
||||
|
||||
state.getProperties().setProperty("left", Integer.toString(bounds.x));
|
||||
state.getProperties().setProperty("top", Integer.toString(bounds.y));
|
||||
state.getProperties().setProperty("width", Integer.toString(bounds.width));
|
||||
state.getProperties().setProperty("height", Integer.toString(bounds.height));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllWindows(){
|
||||
for (JFrame frame: new ArrayList<JFrame>(windows.keySet()))
|
||||
{
|
||||
frame.setVisible(false);
|
||||
unregisterWindow(frame);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNewWindow(JFrame window) {
|
||||
if (!windows.containsKey(window))
|
||||
{
|
||||
windows.put(window, new WindowState(window));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterWindow(JFrame window) {
|
||||
windows.remove(window);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWindows(String[] states) {
|
||||
|
||||
for (String state: states)
|
||||
{
|
||||
JFrame frame = createWindow();
|
||||
WindowState ws = getStateOfWindow(frame);
|
||||
ws.setState(state);
|
||||
restoreState(frame);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] saveWindows() {
|
||||
ArrayList<String> states = new ArrayList<String>();
|
||||
|
||||
for (JFrame frame: windows.keySet())
|
||||
{
|
||||
if (!frame.isVisible())
|
||||
continue;
|
||||
|
||||
WindowState ws = getStateOfWindow(frame);
|
||||
saveState(frame);
|
||||
states.add(ws.getState());
|
||||
}
|
||||
return states.toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JFrame[] getWindows() {
|
||||
return windows.keySet().toArray(new JFrame[0]);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package org.hwo.ui.windowstate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public interface StatedWindowManager {
|
||||
|
||||
Class<? extends JFrame> getManagedClass();
|
||||
|
||||
void registerNewWindow(JFrame window);
|
||||
void unregisterWindow(JFrame window);
|
||||
|
||||
void restoreWindows(String[] states);
|
||||
String[]
|
||||
saveWindows();
|
||||
|
||||
JFrame[]
|
||||
getWindows();
|
||||
JFrame createWindow();
|
||||
|
||||
void closeAllWindows();
|
||||
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
package org.hwo.ui.windowstate;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.hwo.ByteArrayHexlifier;
|
||||
|
||||
public class WindowManager {
|
||||
|
||||
private static WindowManager instance;
|
||||
|
||||
public static WindowManager getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
Hashtable<Class<? extends JFrame>, StatedWindowManager> windowManagers;
|
||||
|
||||
protected WindowManager()
|
||||
{
|
||||
windowManagers = new Hashtable<Class<? extends JFrame>, StatedWindowManager>();
|
||||
}
|
||||
|
||||
public void registerWindowManager(StatedWindowManager manager)
|
||||
{
|
||||
windowManagers.put(manager.getManagedClass(), manager);
|
||||
}
|
||||
|
||||
public StatedWindowManager getStatedWindowManager(Class<? extends JFrame> clazz)
|
||||
{
|
||||
return windowManagers.get(clazz);
|
||||
}
|
||||
|
||||
public StatedWindowManager getStatedWindowManager(String clazz)
|
||||
{
|
||||
for (StatedWindowManager manager: windowManagers.values())
|
||||
{
|
||||
if (manager.getManagedClass().getName().equals(clazz))
|
||||
return manager;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void restoreWindows(String states)
|
||||
{
|
||||
Hashtable<String, ArrayList<String>> htstates;
|
||||
try
|
||||
{
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(ByteArrayHexlifier.stringToByteArray(states));
|
||||
ObjectInputStream ois = new ObjectInputStream(bis);
|
||||
htstates = (Hashtable<String, ArrayList<String>>)ois.readObject();
|
||||
ois.close();
|
||||
bis.close();
|
||||
|
||||
for (String fclazz: htstates.keySet())
|
||||
{
|
||||
System.err.println("Restoring Windows of Class: " + fclazz);
|
||||
StatedWindowManager manager = getStatedWindowManager(fclazz);
|
||||
if (manager != null)
|
||||
{
|
||||
manager.restoreWindows(htstates.get(fclazz).toArray(new String[]{}));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
List<Class<? extends JFrame>> getKnownWindowClasses()
|
||||
{
|
||||
return new ArrayList<Class<? extends JFrame>>(windowManagers.keySet());
|
||||
}
|
||||
|
||||
public String saveWindows()
|
||||
{
|
||||
Hashtable<String, ArrayList<String>> states = new Hashtable<String, ArrayList<String>>();
|
||||
|
||||
for (Class<? extends JFrame> wc: getKnownWindowClasses())
|
||||
{
|
||||
ArrayList<String> wcstates = new ArrayList<String>();
|
||||
|
||||
for (String ws: windowManagers.get(wc).saveWindows())
|
||||
wcstates.add(ws);
|
||||
|
||||
states.put(wc.getName(), wcstates);
|
||||
}
|
||||
try
|
||||
{
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(states);
|
||||
oos.close();
|
||||
bos.close();
|
||||
|
||||
return ByteArrayHexlifier.byteArrayToString(bos.toByteArray());
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public void closeAllWindows()
|
||||
{
|
||||
for (StatedWindowManager manager: windowManagers.values())
|
||||
{
|
||||
manager.closeAllWindows();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
instance = new WindowManager();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.hwo.ui.windowstate;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class WindowState {
|
||||
|
||||
StatedWindowManager statedWindowManager;
|
||||
JFrame jframe;
|
||||
Properties props;
|
||||
|
||||
public WindowState(JFrame frame){
|
||||
props = new Properties();
|
||||
jframe = frame;
|
||||
}
|
||||
|
||||
public JFrame getStatedWindow() {
|
||||
return null;
|
||||
};
|
||||
|
||||
public Class<? extends StatedWindowManager> getWindowManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Properties getProperties(){
|
||||
return this.props;
|
||||
}
|
||||
|
||||
public String getState()
|
||||
{
|
||||
try {
|
||||
StringWriter sw = new StringWriter();
|
||||
this.props.store(sw, "");
|
||||
return sw.toString();
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setState(String state)
|
||||
{
|
||||
try{
|
||||
StringReader sr = new StringReader(state);
|
||||
this.props.load(sr);
|
||||
sr.close();
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue