Added Toolbar to ETable

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@579 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Tgui 2007-03-20 02:33:31 +00:00
parent 747a6c06f9
commit 00ebe18b73
8 changed files with 273 additions and 37 deletions

View File

@ -16,6 +16,7 @@ import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
@ -27,7 +28,8 @@ import javax.swing.tree.TreeSelectionModel;
import enginuity.NewGUI.data.ApplicationStateManager;
import enginuity.NewGUI.data.TableNodeMetaData;
import enginuity.NewGUI.etable.EJTable;
import enginuity.NewGUI.etable.ETable;
import enginuity.NewGUI.etable.EToolBar;
import enginuity.NewGUI.interfaces.TuningEntity;
import enginuity.NewGUI.interfaces.TuningEntityListener;
import enginuity.NewGUI.tree.ETree;
@ -48,7 +50,7 @@ public class NewGUI extends JFrame implements ActionListener, TreeSelectionListe
private JSplitPane splitPane = new JSplitPane();
private JDesktopPane rightDesktopPane = new JDesktopPane();
private ETreeNode rootNode = new ETreeNode(ETreeNode.RESERVED_ROOT, "Enginuity", null);
private ETreeNode rootNode = new ETreeNode("Enginuity", new TableNodeMetaData(TableNodeMetaData.RESERVED_ROOT,0.0,0.0,new Object[0],false,""));
private ETree leftJTree = new ETree(rootNode);
private NewGUI(){
@ -157,12 +159,23 @@ public class NewGUI extends JFrame implements ActionListener, TreeSelectionListe
}
public void displayInternalFrameTable(double[][] data, TableNodeMetaData tableMetaData){
EToolBar toolBar = new EToolBar(tableMetaData);
ETable newTable = new ETable(tableMetaData, data);
JScrollPane scrollPane = new JScrollPane(newTable);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
// Add internal frame
JInternalFrame newInternalFrame = new JInternalFrame(tableMetaData.getTableName(), true, true, true, true);
EJTable newTable = new EJTable(tableMetaData, data);
newInternalFrame.add(newTable);
newInternalFrame.setLayout(new BorderLayout());
newInternalFrame.add(toolBar, BorderLayout.NORTH);
newInternalFrame.add(scrollPane, BorderLayout.CENTER);
newInternalFrame.setVisible(true);
newInternalFrame.setSize(300,300);
newInternalFrame.setSize(470,450);
this.rightDesktopPane.add(newInternalFrame);
}
}

View File

@ -1,13 +1,24 @@
package enginuity.NewGUI.data;
public class TableNodeMetaData {
public static final int DATA1D = 0;
public static final int DATA2D = 1;
public static final int DATA3D = 3;
public static final int CATEGORY = 4;
public static final int RESERVED_ROOT = 5;
private double maxValue;
private double minValue;
private Object[] ignoredValues;
private boolean isInvertedColoring;
private String tableName;
private int dimensions;
public TableNodeMetaData(double minValue, double maxValue, Object[] ignoredValues, boolean isInvertedColoring, String tableName) {
public TableNodeMetaData(int dimensions, double minValue, double maxValue, Object[] ignoredValues, boolean isInvertedColoring, String tableName) {
this.dimensions = dimensions;
this.maxValue = maxValue;
this.minValue = minValue;
this.ignoredValues = ignoredValues;
@ -36,4 +47,8 @@ public class TableNodeMetaData {
public String getTableName() {
return tableName;
}
public int getNodeType() {
return dimensions;
}
}

View File

@ -5,11 +5,11 @@ import javax.swing.ListSelectionModel;
import enginuity.NewGUI.data.TableNodeMetaData;
public class EJTable extends JTable{
public class ETable extends JTable{
private ETableModel theModel;
public EJTable(TableNodeMetaData metaData, double[][] data){
public ETable(TableNodeMetaData metaData, double[][] data){
@ -18,6 +18,7 @@ public class EJTable extends JTable{
//TODO update, possible issue here
super.setModel(this.theModel);
//this.setSelectionModel(ListSelectionModel.)
this.setCellSelectionEnabled(true);

View File

@ -0,0 +1,219 @@
package enginuity.NewGUI.etable;
import static javax.swing.BorderFactory.createLineBorder;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import enginuity.NewGUI.data.TableNodeMetaData;
import enginuity.maps.Table;
public class EToolBar extends JToolBar implements MouseListener, ItemListener,ActionListener {
private JButton incrementFine = new JButton(new ImageIcon("./graphics/icon-incfine.png"));
private JButton decrementFine = new JButton(new ImageIcon("./graphics/icon-decfine.png"));
private JButton incrementCoarse = new JButton(new ImageIcon("./graphics/icon-inccoarse.png"));
private JButton decrementCoarse = new JButton(new ImageIcon("./graphics/icon-deccoarse.png"));
private JButton enable3d = new JButton(new ImageIcon("./graphics/3d_render.png"));
private JButton setValue = new JButton("Set");
private JButton multiply = new JButton("Mul");
private JFormattedTextField incrementByFine = new JFormattedTextField(new DecimalFormat("#.####"));
private JFormattedTextField incrementByCoarse = new JFormattedTextField(new DecimalFormat("#.####"));
private JFormattedTextField setValueText = new JFormattedTextField(new DecimalFormat("#.####"));
private JComboBox scaleSelection = new JComboBox();
private JCheckBox overlayLog = new JCheckBox("Overlay Log");
private JButton clearOverlay = new JButton("Clear Overlay");
private JLabel liveDataValue = new JLabel();
public EToolBar(TableNodeMetaData tableMetaData) {
this.setFloatable(false);
this.setLayout(new FlowLayout(FlowLayout.LEFT));
JPanel finePanel = new JPanel();
finePanel.add(incrementFine);
finePanel.add(decrementFine);
finePanel.add(incrementByFine);
this.add(finePanel);
JPanel coarsePanel = new JPanel();
coarsePanel.add(incrementCoarse);
coarsePanel.add(decrementCoarse);
coarsePanel.add(incrementByCoarse);
this.add(coarsePanel);
JPanel setValuePanel = new JPanel();
setValuePanel.add(setValueText);
setValuePanel.add(setValue);
setValuePanel.add(multiply);
this.add(setValuePanel);
// Only add the 3d button if table includes 3d data
if (tableMetaData.getNodeType() == TableNodeMetaData.DATA3D) {
this.add(enable3d);
}
// this.add(scaleSelection);
/*
if (table.isLiveDataSupported()) {
JPanel liveDataPanel = new JPanel();
liveDataPanel.add(overlayLog);
liveDataPanel.add(clearOverlay);
// liveDataPanel.add(liveDataValue);
this.add(liveDataPanel);
}
*/
incrementFine.setPreferredSize(new Dimension(33, 33));
incrementFine.setBorder(createLineBorder(new Color(150, 150, 150), 1));
decrementFine.setPreferredSize(new Dimension(33, 33));
decrementFine.setBorder(createLineBorder(new Color(150, 150, 150), 1));
incrementCoarse.setPreferredSize(new Dimension(33, 33));
incrementCoarse
.setBorder(createLineBorder(new Color(150, 150, 150), 1));
decrementCoarse.setPreferredSize(new Dimension(33, 33));
decrementCoarse
.setBorder(createLineBorder(new Color(150, 150, 150), 1));
enable3d.setPreferredSize(new Dimension(33, 33));
enable3d.setBorder(createLineBorder(new Color(150, 150, 150), 1));
setValue.setPreferredSize(new Dimension(33, 23));
setValue.setBorder(createLineBorder(new Color(150, 150, 150), 1));
multiply.setPreferredSize(new Dimension(33, 23));
multiply.setBorder(createLineBorder(new Color(150, 150, 150), 1));
scaleSelection.setPreferredSize(new Dimension(80, 23));
scaleSelection.setFont(new Font("Tahoma", Font.PLAIN, 11));
clearOverlay.setPreferredSize(new Dimension(75, 23));
clearOverlay.setBorder(createLineBorder(new Color(150, 150, 150), 1));
incrementByFine.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
incrementByFine.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
incrementByFine.setPreferredSize(new Dimension(45, 23));
incrementByCoarse.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
incrementByCoarse.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
incrementByCoarse.setPreferredSize(new Dimension(45, 23));
setValueText.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
setValueText.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
setValueText.setPreferredSize(new Dimension(45, 23));
incrementFine.setToolTipText("Increment Value (Fine)");
decrementFine.setToolTipText("Decrement Value (Fine)");
incrementCoarse.setToolTipText("Increment Value (Coarse)");
decrementCoarse.setToolTipText("Decrement Value (Coarse)");
enable3d.setToolTipText("Render data in 3d");
setValue.setToolTipText("Set Absolute Value");
setValueText.setToolTipText("Set Absolute Value");
incrementByFine.setToolTipText("Fine Value Adjustment");
incrementByCoarse.setToolTipText("Coarse Value Adjustment");
multiply.setToolTipText("Multiply Value");
overlayLog.setToolTipText("Enable Overlay Of Real Time Log Data");
clearOverlay.setToolTipText("Clear Log Data Overlay Highlights");
incrementFine.addMouseListener(this);
decrementFine.addMouseListener(this);
incrementCoarse.addMouseListener(this);
decrementCoarse.addMouseListener(this);
enable3d.addMouseListener(this);
setValue.addMouseListener(this);
multiply.addMouseListener(this);
scaleSelection.addItemListener(this);
overlayLog.addItemListener(this);
clearOverlay.addActionListener(this);
/*
try {
incrementByFine.setValue(Math.abs(table.getScale()
.getFineIncrement()));
incrementByCoarse.setValue(Math.abs(table.getScale()
.getCoarseIncrement()));
} catch (Exception ex) {
// scaling units haven't been added yet -- no problem
}
*/
// key binding actions
Action enterAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
//getTable().requestFocus();
//setValue();
}
};
// set input mapping
InputMap im = getInputMap(WHEN_IN_FOCUSED_WINDOW);
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
im.put(enter, "enterAction");
getActionMap().put(im.get(enter), enterAction);
incrementFine.getInputMap().put(enter, "enterAction");
decrementFine.getInputMap().put(enter, "enterAction");
incrementCoarse.getInputMap().put(enter, "enterAction");
decrementCoarse.getInputMap().put(enter, "enterAction");
incrementByFine.getInputMap().put(enter, "enterAction");
incrementByCoarse.getInputMap().put(enter, "enterAction");
setValueText.getInputMap().put(enter, "enterAction");
setValue.getInputMap().put(enter, "enterAction");
incrementFine.getInputMap().put(enter, "enterAction");
//setScales(table.getScales());
}
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}

View File

@ -7,6 +7,7 @@ import java.awt.event.MouseListener;
import javax.swing.JTree;
import enginuity.NewGUI.data.ApplicationStateManager;
import enginuity.NewGUI.data.TableNodeMetaData;
import enginuity.swing.RomCellRenderer;
public class ETree extends JTree implements MouseListener {
@ -39,7 +40,7 @@ public class ETree extends JTree implements MouseListener {
ETreeNode theNode = (ETreeNode)selectedObject;
// If this is a table that contains data, then open it in the right pane in an internal frame
if(theNode.getNodeType() == ETreeNode.DATA1D || theNode.getNodeType() == ETreeNode.DATA2D || theNode.getNodeType() == ETreeNode.DATA3D){
if(theNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA1D || theNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA2D || theNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA3D){
System.out.println("Table data");
double[][] tableData = ApplicationStateManager.getCurrentTuningEntity().getTableData(theNode.getNodeName());
ApplicationStateManager.getEnginuityInstance().displayInternalFrameTable(tableData, theNode.getTableMetaData());

View File

@ -16,6 +16,7 @@ import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import enginuity.NewGUI.data.ApplicationStateManager;
import enginuity.NewGUI.data.TableNodeMetaData;
public class ETreeCellRenderer implements TreeCellRenderer{
@ -37,18 +38,18 @@ public class ETreeCellRenderer implements TreeCellRenderer{
namedJPanel.setBackground(Color.WHITE);
// Define appropriate ICON to use for node
if(eTreeNode.getNodeType() == ETreeNode.DATA1D){
if(eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA1D){
nodeName = new JLabel(eTreeNode.getNodeName() + " ", new ImageIcon("./graphics/1d.gif"), JLabel.LEFT);
}else if(eTreeNode.getNodeType() == ETreeNode.DATA2D){
}else if(eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA2D){
nodeName = new JLabel(eTreeNode.getNodeName() + " ", new ImageIcon("./graphics/2d.gif"), JLabel.LEFT);
}else if(eTreeNode.getNodeType() == ETreeNode.DATA3D){
}else if(eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA3D){
nodeName = new JLabel(eTreeNode.getNodeName() + " ", new ImageIcon("./graphics/3d.gif"), JLabel.LEFT);
}else if(eTreeNode.getNodeType() == ETreeNode.CATEGORY){
}else if(eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.CATEGORY){
nodeName = new JLabel(eTreeNode.getNodeName() + " ", new ImageIcon("./graphics/1d.gif"), JLabel.LEFT);
}
if(eTreeNode.getNodeType() == ETreeNode.CATEGORY){
if(eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.CATEGORY){
nodeName = new JLabel(eTreeNode.getNodeName(), JLabel.LEFT);
nodeName.setFont(new Font("Tahoma", Font.PLAIN, 11));
@ -68,7 +69,7 @@ public class ETreeCellRenderer implements TreeCellRenderer{
namedJPanel.setEnabled(tree.isEnabled());
returnValue = namedJPanel;
}else if(eTreeNode.getNodeType() == ETreeNode.DATA3D || eTreeNode.getNodeType() == ETreeNode.DATA2D || eTreeNode.getNodeType() == ETreeNode.DATA1D){
}else if(eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA3D || eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA2D || eTreeNode.getTableMetaData().getNodeType() == TableNodeMetaData.DATA1D){
namedJPanel.add(nodeName);
nodeName.setFont(new Font("Tahoma", Font.PLAIN, 11));

View File

@ -5,33 +5,18 @@ import enginuity.NewGUI.data.ApplicationStateManager;
import enginuity.NewGUI.data.TableNodeMetaData;
public class ETreeNode extends DefaultMutableTreeNode{
public static final int DATA1D = 0;
public static final int DATA2D = 1;
public static final int DATA3D = 3;
public static final int CATEGORY = 4;
public static final int RESERVED_ROOT = 5;
private int userLevel = ApplicationStateManager.USER_LEVEL_1;
private int nodeType;
private String nodeName = "";
private TableNodeMetaData tableMetaData = null;
public ETreeNode(int nodeType, String nodeName, TableNodeMetaData tableMetaData){
public ETreeNode(String nodeName, TableNodeMetaData tableMetaData){
super(nodeName);
this.nodeType = nodeType;
this.nodeName = nodeName;
this.tableMetaData = tableMetaData;
}
public int getNodeType() {
return nodeType;
}
public void setNodeType(int nodeType) {
this.nodeType = nodeType;
}
public String getNodeName() {
return nodeName;
}

View File

@ -168,7 +168,7 @@ public class UtecTuningEntityImpl implements TuningEntity{
this.theTEL = theTEL;
// Initialise tree
ETreeNode root = new ETreeNode(ETreeNode.CATEGORY, "UTEC: No map selected....", null);
ETreeNode root = new ETreeNode("UTEC: No map selected....", new TableNodeMetaData(TableNodeMetaData.CATEGORY,0.0,0.0,new Object[0],false,""));
// Inform main GUI of initial tree
@ -282,15 +282,16 @@ public class UtecTuningEntityImpl implements TuningEntity{
// Initialise tree
ETreeNode root = new ETreeNode(ETreeNode.CATEGORY, "UTEC:"+UtecDataManager.getCurrentMapData().getMapName()+", "+UtecDataManager.getCurrentMapData().getMapComment(), null);
ETreeNode root = new ETreeNode("UTEC:"+UtecDataManager.getCurrentMapData().getMapName()+", "+UtecDataManager.getCurrentMapData().getMapComment(), new TableNodeMetaData(TableNodeMetaData.CATEGORY,0.0,0.0,new Object[0],false,""));
Object[] ignored = {new Double(-100.0)};
ETreeNode fuel = new ETreeNode(ETreeNode.DATA3D, "Fuel", new TableNodeMetaData(Double.parseDouble(UtecProperties.getProperties("utec.fuelMapMin")[0]), Double.parseDouble(UtecProperties.getProperties("utec.fuelMapMax")[0]), ignored, false, "Fuel" ));
ETreeNode fuel = new ETreeNode("Fuel", new TableNodeMetaData(TableNodeMetaData.DATA3D, Double.parseDouble(UtecProperties.getProperties("utec.fuelMapMin")[0]), Double.parseDouble(UtecProperties.getProperties("utec.fuelMapMax")[0]), ignored, false, "Fuel" ));
Object[] ignored2 = {new Double(-100.0)};
ETreeNode timing = new ETreeNode(ETreeNode.DATA3D, "Timing", new TableNodeMetaData(Double.parseDouble(UtecProperties.getProperties("utec.timingMapMin")[0]), Double.parseDouble(UtecProperties.getProperties("utec.timingMapMax")[0]), ignored, false, "Timing" ));
ETreeNode timing = new ETreeNode("Timing", new TableNodeMetaData(TableNodeMetaData.DATA3D, Double.parseDouble(UtecProperties.getProperties("utec.timingMapMin")[0]), Double.parseDouble(UtecProperties.getProperties("utec.timingMapMax")[0]), ignored, false, "Timing" ));
Object[] ignored3 = {new Double(-100.0)};
ETreeNode boost = new ETreeNode(ETreeNode.DATA3D, "Boost", new TableNodeMetaData(Double.parseDouble(UtecProperties.getProperties("utec.boostMapMin")[0]), Double.parseDouble(UtecProperties.getProperties("utec.boostMapMax")[0]), ignored, false, "Boost" ));
ETreeNode boost = new ETreeNode("Boost", new TableNodeMetaData(TableNodeMetaData.DATA3D, Double.parseDouble(UtecProperties.getProperties("utec.boostMapMin")[0]), Double.parseDouble(UtecProperties.getProperties("utec.boostMapMax")[0]), ignored, false, "Boost" ));
root.add(fuel);
root.add(timing);
root.add(boost);