Browse Source

Some Stuff for Transformer's Properties

Edgardo Palza 7 years ago
parent
commit
4f61bb1747
3 changed files with 35 additions and 13 deletions
  1. 9 3
      src/classes/HolonTransformer.java
  2. 12 3
      src/ui/view/DefaulTable.java
  3. 14 7
      src/ui/view/GUI.java

+ 9 - 3
src/classes/HolonTransformer.java

@@ -4,8 +4,8 @@ public class HolonTransformer extends CpsObject {
 
 	/* Ratio of the transformer */
 	float transformRatio;
-	
-	/*Fixed transform value */
+
+	/* Fixed transform value */
 	float transformFixed;
 
 	/**
@@ -45,7 +45,7 @@ public class HolonTransformer extends CpsObject {
 	public float getTransformRatio() {
 		return this.transformRatio;
 	}
-	
+
 	/**
 	 * Set fixed Transform Value
 	 * 
@@ -64,4 +64,10 @@ public class HolonTransformer extends CpsObject {
 	public float getTransformFixed() {
 		return this.transformFixed;
 	}
+
+	public float getOutput() {
+		float output = 0;
+		return output;
+
+	}
 }

+ 12 - 3
src/ui/view/DefaulTable.java

@@ -1,6 +1,7 @@
 package ui.view;
 
 import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableCellEditor;
 
 public class DefaulTable extends DefaultTableModel {
 	private boolean[][] editable_cells; // 2d array to represent rows and
@@ -12,9 +13,7 @@ public class DefaulTable extends DefaultTableModel {
 	}
 
 	@Override
-	public boolean isCellEditable(int row, int column) { // custom //
-														// isCellEditable
-															// function
+	public boolean isCellEditable(int row, int column) {
 		return this.editable_cells[row][column];
 	}
 
@@ -22,4 +21,14 @@ public class DefaulTable extends DefaultTableModel {
 		this.editable_cells[row][col] = value; // set cell true/false
 		this.fireTableCellUpdated(row, col);
 	}
+
+	@Override
+	public TableCellEditor getCellEditor(int row, int column) {
+		if (column == 1) {
+			Object value = getValueAt(row, column);
+			if (value != null)
+				return getDefaultEditor(value.getClass());
+		}
+		return super.getCellEditor(row, column);
+	}
 }

+ 14 - 7
src/ui/view/GUI.java

@@ -106,7 +106,7 @@ public class GUI<E> implements CategoryListener {
 	private JTable tableHolonElement = new JTable();
 	private PropertyTable tableModelHolonElement = new PropertyTable();
 	private final JPanel scrollElements = new JPanel();
-	JScrollPane tableHolonElementScrollPane = new JScrollPane();
+	private JScrollPane tableHolonElementScrollPane = new JScrollPane();
 
 	// In this section are all the properties that correspond to the clicked
 	// HolonObject, such as connections, name, Type, etc.
@@ -435,8 +435,12 @@ public class GUI<E> implements CategoryListener {
 				try {
 					Object temp;
 					if (getActualCps() != null) {
-						temp = tableModelProperties.getValueAt(0, 1);
-						getActualCps().setName(temp.toString());
+						if (getActualCps() instanceof HolonObject) {
+							temp = tableModelProperties.getValueAt(0, 1);
+							getActualCps().setName(temp.toString());
+						} else if (getActualCps() instanceof HolonTransformer) {
+							// get Info of the Properties for Transformer
+						}
 					} else {
 						temp = tableModelProperties.getValueAt(2, 1);
 						Float ftemp = Float.parseFloat(temp.toString());
@@ -691,6 +695,9 @@ public class GUI<E> implements CategoryListener {
 						refreshTableHolonElement();
 						Object[] tempEnergy = { "Total Energy", ((HolonObject) temp).getCurrentEnergy() };
 						tableModelProperties.addRow(tempEnergy);
+					} else if (temp instanceof HolonTransformer) {
+						Object[] tempRatioPerc = { "Ratio Type", true };
+						tableModelProperties.addRow(tempRatioPerc);
 					}
 					tableModelProperties.setCellEditable(0, 1, true);
 					tableModelProperties.setCellEditable(2, 1, false);
@@ -714,13 +721,11 @@ public class GUI<E> implements CategoryListener {
 									Object[] tempConnection = { "",
 											temp2.getA().getName() + " with ID: " + temp2.getA().getID() };
 									tableModelProperties.addRow(tempConnection);
-
 								} else {
 									Object[] tempConnection = { "",
 											temp2.getB().getName() + " with ID: " + temp2.getB().getID() };
 									tableModelProperties.addRow(tempConnection);
 								}
-
 							}
 						}
 					}
@@ -783,7 +788,7 @@ public class GUI<E> implements CategoryListener {
 		frmCyberPhysical.getContentPane().add(splitPane);
 
 		mntmNew.addActionListener(new ActionListener() {
-			
+
 			@Override
 			public void actionPerformed(ActionEvent arg0) {
 				model.getEdgesOnCanvas().removeAll(model.getEdgesOnCanvas());
@@ -797,7 +802,7 @@ public class GUI<E> implements CategoryListener {
 				canvas.repaint();
 			}
 		});
-		
+
 		mntmOpen.addActionListener(new java.awt.event.ActionListener() {
 			@Override
 			public void actionPerformed(java.awt.event.ActionEvent evt) {
@@ -1038,6 +1043,8 @@ public class GUI<E> implements CategoryListener {
 			tableModelProperties.removeRow(2);
 			Object[] tempEnergy = { "Total Energy", ((HolonObject) tempCps).getCurrentEnergy() };
 			tableModelProperties.insertRow(2, tempEnergy);
+		} else if (tempCps instanceof HolonTransformer) {
+			// Refresh Transformer Info
 		}
 	}