diff --git a/src/enginuity/newmaps/swing/EnginuityFrame.java b/src/enginuity/newmaps/swing/EnginuityFrame.java index d679d98b..ce6eeddf 100644 --- a/src/enginuity/newmaps/swing/EnginuityFrame.java +++ b/src/enginuity/newmaps/swing/EnginuityFrame.java @@ -19,16 +19,16 @@ * */ -package enginuity.newmaps.gui; +package enginuity.newmaps.swing; import enginuity.newmaps.ecumetadata.TableMetadata; import javax.swing.JFrame; public abstract class EnginuityFrame extends JFrame { - + public EnginuityFrame(byte[] data, TableMetadata metadata) { - - + + } - + } \ No newline at end of file diff --git a/src/enginuity/newmaps/swing/EnginuityJTable.java b/src/enginuity/newmaps/swing/EnginuityJTable.java index 98a30b94..e38dc08f 100644 --- a/src/enginuity/newmaps/swing/EnginuityJTable.java +++ b/src/enginuity/newmaps/swing/EnginuityJTable.java @@ -1,4 +1,4 @@ -package enginuity.newmaps.gui; +package enginuity.newmaps.swing; import java.awt.Color; import java.awt.Point; @@ -17,75 +17,75 @@ import javax.swing.JTable; public class EnginuityJTable extends JTable { - + HashSet cellSelection = new HashSet(); HashSet currentSelection = new HashSet(); HashSet clipBoard = new HashSet(); Point lastSelectedCell = null; Point currentSelectedCell = null; - - + + private Color oldSelectionBackgroundColor; private Color copySelectionColour = Color.red; private Color cutSelectionColour = Color.yellow; - - + + private boolean check = false; - + public static final int COPY = 1; public static final int CUT = 2; - + private int action; - + public EnginuityJTable(int rows, int columns) { super (rows, columns); MouseMotionListener[] cls = (MouseMotionListener[])(this.getListeners(MouseMotionListener.class)); for ( int i = 0; i < cls.length; i++) - { + { if (i == 2) this.removeMouseMotionListener( cls[i] ); } - + this.addKeyListener( new EventKeyHandler(this) ); this.addMouseMotionListener( new MouseMotionH(this) ); this.setCellSelectionEnabled( true ); - this.setSelectionBackground( Color.blue ); + this.setSelectionBackground( Color.blue ); } - - + + public void changeSelection( int row, int column, boolean toggle, boolean extend) { super.changeSelection(row, column, toggle, extend); if (!check) - { + { oldSelectionBackgroundColor = getSelectionBackground(); check = true; } - - + + // Don't think this makes sense if (toggle && extend) { - //currentSelectedCell = new Point(row, column); + //currentSelectedCell = new Point(row, column); extendCellSelection(row, column); return; } if (toggle) - { + { if (currentSelectedCell!= null && !currentSelection.isEmpty()) - { + { cellSelection.addAll( currentSelection ); - currentSelection.clear(); + currentSelection.clear(); } toggleCellSelection(row, column); return; } if (extend) - { + { extendCellSelection(row, column); return; } @@ -95,7 +95,7 @@ public class EnginuityJTable extends JTable currentSelection.clear(); cellSelection.add(new Point(row, column)); lastSelectedCell = new Point(row, column); - + /*System.out.println(cellSelection); System.out.println(currentSelection);*/ this.setSelectionBackground( oldSelectionBackgroundColor ); @@ -116,12 +116,12 @@ public class EnginuityJTable extends JTable } private void extendCellSelection(int row, int column) - { + { currentSelectedCell = new Point(row, column); /*if a drag only into one cell*/ if (currentSelectedCell.equals( lastSelectedCell )) return; - currentSelection.clear(); + currentSelection.clear(); Point p = null; int minColumn; int minRow; @@ -137,7 +137,7 @@ public class EnginuityJTable extends JTable minColumn = lastSelectedCell.y; maxColumn = currentSelectedCell.y; } - + if (currentSelectedCell.x < lastSelectedCell.x) { minRow = currentSelectedCell.x; @@ -149,20 +149,20 @@ public class EnginuityJTable extends JTable maxRow = currentSelectedCell.x; } for ( int i = minRow; i <= maxRow ; i++) - { + { for ( int j = minColumn; j <= maxColumn; j++) { p = new Point( i, j ); currentSelection.add( p ); } } - + repaint(); - + } public boolean isCellSelected(int row, int column) - { + { return (cellSelection.contains(new Point(row, column))) || (currentSelection.contains(new Point(row, column))); } @@ -175,7 +175,7 @@ public class EnginuityJTable extends JTable { return false; } - + public Point getCurrentSelectedCell() { return currentSelectedCell; @@ -194,7 +194,7 @@ public class EnginuityJTable extends JTable public void setLastSelectedCell( Point lastSelectedCell ) { this.lastSelectedCell = lastSelectedCell; - } + } public HashSet getCellSelection() @@ -206,16 +206,16 @@ public class EnginuityJTable extends JTable { this.cellSelection = cellSelection; } - + public void clearSelection( ) { if ( cellSelection != null ) this.cellSelection.clear(); } - - - + + + /** * The set with the selected cells copied do a new HashSet that playes the role of the clpiboard */ @@ -226,25 +226,25 @@ public class EnginuityJTable extends JTable public void toClipBoard( int cut ) { - Point cell = null; + Point cell = null; HashSet clipBoardHS = new HashSet(); - + this.clipBoard.clear(); clipBoardHS.addAll( cellSelection ); clipBoardHS.addAll( currentSelection ); - + for ( Iterator iter = clipBoardHS.iterator(); iter.hasNext();) { - cell = (Point)iter.next(); + cell = (Point)iter.next(); clipBoard.add( new Cell(cell, this.getValueAt((int)cell.getX(), (int)cell.getY())) ); - + if (cut == EnginuityJTable.CUT) - { + { setSelectionBackground(this.cutSelectionColour); setAction( EnginuityJTable.CUT); } - else - if (cut == EnginuityJTable.COPY) + else + if (cut == EnginuityJTable.COPY) { setSelectionBackground(this.copySelectionColour); setAction( EnginuityJTable.COPY); @@ -252,39 +252,39 @@ public class EnginuityJTable extends JTable repaint(); } - + } - - public void moveToClipBoard( ) + + public void moveToClipBoard( ) { Point cell = null; HashSet clipBoardHS = new HashSet(); - + this.clipBoard.clear(); clipBoardHS.addAll( cellSelection ); clipBoardHS.addAll( currentSelection ); - + for ( Iterator iter = clipBoardHS.iterator(); iter.hasNext();) { - cell = (Point)iter.next(); + cell = (Point)iter.next(); clipBoard.add( new Cell((int)cell.getX(), (int)cell.getY(), this.getValueAt((int)cell.getX(), (int)cell.getY())) ); - + } - - - + + + } - + /** * Get the cell with the minimum X and the Minimum Y * If doesn't exists this cell then the paste cannot be made - * @throws Exception + * @throws Exception */ private Cell getMinCell(HashSet clipboard) { - - + + //sort by X Coordinate Object[] cells = clipboard.toArray(); Arrays.sort(cells, new XComparator()); @@ -293,20 +293,20 @@ public class EnginuityJTable extends JTable Arrays.sort((Object[])cells, new YComparator()); //System.out.println("orderedByY: " + (Cell)cells[0]); Cell minY = (Cell)cells[0]; - + //sort again by X coordinate Arrays.sort((Object[])cells, new XComparator()); Cell minX = (Cell)cells[0]; //System.out.println("orderedByX: " + (Cell)cells[0]); - + if (minX.equals(minY)) return minX; - - + + return null; } - - + + class MouseMotionH implements MouseMotionListener { private EnginuityJTable myJTable = null; @@ -319,56 +319,56 @@ public class EnginuityJTable extends JTable { Point p = e.getPoint(); - + int row = myJTable.rowAtPoint(p); - int column = myJTable.columnAtPoint(p); + int column = myJTable.columnAtPoint(p); myJTable.changeSelection(row, column, false, true); } public void mouseMoved( MouseEvent e ) { //System.out.println("move"); - + } } - + class EventKeyHandler extends KeyAdapter{ private EnginuityJTable myJTable = null; - - + + public EventKeyHandler(EnginuityJTable myJTable) { super(); this.myJTable = myJTable; } - + public void keyPressed(KeyEvent e) - { + { /*Copy*/ //System.out.println(e.getModifiers()); if ((e.isControlDown() && e.getKeyCode() == 67 )) { - myJTable.toClipBoard(EnginuityJTable.COPY); + myJTable.toClipBoard(EnginuityJTable.COPY); return; } else /*Paste*/ if ((e.isControlDown() && e.getKeyCode() == 86 )) - { + { Cell cell = getMinCell(clipBoard); Cell cutCell = null; - - + + if (cell != null) { - + if (myJTable.getAction() == EnginuityJTable.CUT) for ( Iterator iter = clipBoard.iterator(); iter.hasNext(); ) { - cutCell = (Cell)iter.next(); + cutCell = (Cell)iter.next(); myJTable.setValueAt( null ,(int)cutCell.getX(), (int)cutCell.getY() ); } - + int deltaX, deltaY; deltaX = lastSelectedCell.x - cell.getX(); deltaY = lastSelectedCell.y - cell.getY(); @@ -384,10 +384,10 @@ public class EnginuityJTable extends JTable System.err.println("Copy/Cut Selection ambigous. Could not Paste"); // throw new Exception ("Copy/Cut Selection ambigous"); } - + for ( Iterator iter = clipBoard.iterator(); iter.hasNext(); ) { - cell = (Cell)iter.next(); + cell = (Cell)iter.next(); if (cell.getX() < myJTable.getRowCount() && cell.getY() < myJTable.getColumnCount()) myJTable.setValueAt(cell.getValue(), cell.getX(), cell.getY()); } @@ -397,14 +397,14 @@ public class EnginuityJTable extends JTable /*Cut*/ if ((e.isControlDown() && e.getKeyCode() == 88 )) { - myJTable.toClipBoard(EnginuityJTable.CUT); + myJTable.toClipBoard(EnginuityJTable.CUT); return; } else if (e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK | InputEvent.BUTTON1_MASK )) - { + { //myJTable.changeSelection(5,5,false, true); - + } else if (e.getModifiers() == (InputEvent.SHIFT_MASK | InputEvent.BUTTON1_MASK)) @@ -416,39 +416,39 @@ public class EnginuityJTable extends JTable //System.out.println("SHIFT + CLICK"); }else if (e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.BUTTON1_MASK)) - { + { //currentSelection.clear(); myJTable.changeSelection((int)myJTable.getLastSelectedCell().getX(),(int)myJTable.getLastSelectedCell().getY(),false,true); repaint(); //System.out.println("CTRL + CLICK"); } - + } } - - + + class Cell { private Object value; private int x; private int y; - + public Cell(){}; - + public Cell(int x, int y, Object value) { this.x = x; this.y = y; this.value = value; } - + public Cell(Point p, Object value) { this.x = (int)p.getX(); this.y = (int)p.getY(); this.value = value; } - + public Object getValue() { return value; @@ -472,7 +472,7 @@ public class EnginuityJTable extends JTable public void setY( int y ) { this.y = y; - + } public boolean equals(Object o) @@ -480,20 +480,20 @@ public class EnginuityJTable extends JTable Cell cell = null; if (!(o instanceof Cell)) return false; - + cell = (Cell)o; if (cell.getX()==this.x && cell.getY() == this.y) return true; - + return false; } - + public String toString() { return "(" + this.x + ", " + this.y + ") = " + this.value; } } - + /** * order the Cells by the X coordinate * @author fane @@ -503,9 +503,9 @@ public class EnginuityJTable extends JTable { public int compare(T o1, T o2) { - return ((Cell)o1).getX() - ((Cell)o2).getX(); + return ((Cell)o1).getX() - ((Cell)o2).getX(); } - + } /** @@ -518,7 +518,7 @@ public class EnginuityJTable extends JTable public int compare(T o1, T o2) { return ((Cell)o1).getY() - ((Cell)o2).getY(); } - + } public Color getCopySelectioColour() { diff --git a/src/enginuity/newmaps/swing/Frame3D.java b/src/enginuity/newmaps/swing/Frame3D.java index df809c55..402612f5 100644 --- a/src/enginuity/newmaps/swing/Frame3D.java +++ b/src/enginuity/newmaps/swing/Frame3D.java @@ -19,7 +19,7 @@ * */ -package enginuity.newmaps.gui; +package enginuity.newmaps.swing; import enginuity.newmaps.ecumetadata.AxisMetadata; import enginuity.newmaps.ecumetadata.Scale; @@ -28,19 +28,19 @@ import enginuity.newmaps.ecumetadata.Table3DMetadata; import enginuity.newmaps.ecumetadata.Unit; import javax.swing.JScrollPane; - + public class Frame3D extends EnginuityFrame { - + EnginuityJTable xAxisTable; EnginuityJTable yAxisTable; EnginuityJTable table; - + public Frame3D(byte[] data, Table3DMetadata metadata) { - + super(data, (TableMetadata)metadata); - + table = new EnginuityJTable(5, 5); - + for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) { @@ -48,33 +48,33 @@ public class Frame3D extends EnginuityFrame { } JScrollPane scrollPane = new JScrollPane( table ); getContentPane().add( scrollPane ); - + this.pack(); - + } - - + + private void populateTable(byte[] data) { // // Do table first.. // - - + + } - - - - + + + + // // Test driver // public static void main(String[] args) { - + byte[] data = new byte[100]; for (int i = 0; i < data.length; i++) { data[i] = (byte)i; } - + // // Create table and axis // @@ -91,16 +91,16 @@ public class Frame3D extends EnginuityFrame { yAxis.setAddress(25); yAxis.setSize(5); table.setYaxis(yAxis); - + // - // Create scales + // Create scales // Unit tableUnit = new Unit("Table Unit"); tableUnit.setCoarseIncrement(2); tableUnit.setFineIncrement(1); tableUnit.setFormat("0.0"); tableUnit.setTo_byte("x / 2"); - tableUnit.setTo_real("x * 2"); + tableUnit.setTo_real("x * 2"); Scale tableScale = new Scale("Table Scale"); Unit[] tableUnits = {tableUnit}; tableScale.setUnits(tableUnits); @@ -108,13 +108,13 @@ public class Frame3D extends EnginuityFrame { tableScale.setEndian(Scale.ENDIAN_BIG); tableScale.setStorageType(Scale.STORAGE_TYPE_UINT16); table.setScale(tableScale); - + Unit xUnit = new Unit("X Unit"); xUnit.setCoarseIncrement(2); xUnit.setFineIncrement(1); xUnit.setFormat("0.0"); xUnit.setTo_byte("x / 2"); - xUnit.setTo_real("x * 2"); + xUnit.setTo_real("x * 2"); Scale xScale = new Scale("X Scale"); Unit[] xUnits = {xUnit}; xScale.setUnits(xUnits); @@ -122,22 +122,22 @@ public class Frame3D extends EnginuityFrame { xScale.setEndian(Scale.ENDIAN_LITTLE); xScale.setStorageType(Scale.STORAGE_TYPE_INT8); xAxis.setScale(xScale); - + Unit yUnit = new Unit("Y Unit"); yUnit.setCoarseIncrement(3); yUnit.setFineIncrement(2); yUnit.setFormat("0.00"); yUnit.setTo_byte("x * 2"); - yUnit.setTo_real("x / 2"); + yUnit.setTo_real("x / 2"); Scale yScale = new Scale("Y Scale"); Unit[] yUnits = {yUnit}; - yScale.setUnits(yUnits); + yScale.setUnits(yUnits); yScale.setDescription("This is the y scale"); yScale.setEndian(Scale.ENDIAN_LITTLE); yScale.setStorageType(Scale.STORAGE_TYPE_FLOAT); yAxis.setScale(yScale); - - + + // // Create frame // @@ -146,7 +146,7 @@ public class Frame3D extends EnginuityFrame { frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible(true); - + } - + } diff --git a/src/enginuity/newmaps/swing/TableSelectionModel.java b/src/enginuity/newmaps/swing/TableSelectionModel.java index ae43558b..f19ff41d 100644 --- a/src/enginuity/newmaps/swing/TableSelectionModel.java +++ b/src/enginuity/newmaps/swing/TableSelectionModel.java @@ -20,9 +20,9 @@ */ /** - * + * */ -package enginuity.newmaps.gui; +package enginuity.newmaps.swing; import java.util.Random; import javax.swing.DefaultListSelectionModel; @@ -33,11 +33,11 @@ import javax.swing.DefaultListSelectionModel; */ public class TableSelectionModel extends DefaultListSelectionModel { - - - + + + public static final int MULTIPLE_SELECTION = 3; - + private int selectionMode = MULTIPLE_INTERVAL_SELECTION; /* (non-Javadoc) diff --git a/src/enginuity/newmaps/swing/Test.java b/src/enginuity/newmaps/swing/Test.java index b309a5a5..a63af2bb 100644 --- a/src/enginuity/newmaps/swing/Test.java +++ b/src/enginuity/newmaps/swing/Test.java @@ -1,4 +1,4 @@ -package enginuity.newmaps.gui; +package enginuity.newmaps.swing; import javax.swing.JFrame; import javax.swing.JScrollPane;