Преглед на файлове

fixes missingSupplyBars and supplyBar Interactions in UpperNodeCanvas

Andreas T. Meyer-Berg преди 7 години
родител
ревизия
6dca4165dc
променени са 4 файла, в които са добавени 415 реда и са изтрити 517 реда
  1. 56 0
      src/ui/view/AbstractCanvas.java
  2. 355 468
      src/ui/view/GUI.java
  3. 3 48
      src/ui/view/MyCanvas.java
  4. 1 1
      src/ui/view/UpperNodeCanvas.java

+ 56 - 0
src/ui/view/AbstractCanvas.java

@@ -156,6 +156,62 @@ public abstract class AbstractCanvas extends JPanel {
         return maxCap;
     }
 
+    /**
+	 * Paints the SupplyBar for the given cps object on the canvas
+	 * 
+	 * @param g Graphics used
+	 * @param cps cpsObject which the supplyBar should be drawn for
+	 */
+	protected void paintSupplyBar(Graphics g, AbstractCpsObject cps) {
+		/**
+		 * draw and fill the supply Bar
+		 */
+		if (model.getShowSupplyBars() && cps instanceof HolonObject) {
+			HolonObject hl = (HolonObject) cps;
+			if (hl != null
+					&& (hl.getState() == HolonObject.NOT_SUPPLIED || hl
+							.getState() == HolonObject.PARTIALLY_SUPPLIED)) {
+				// calculate Positons:
+				int barX = (int) (cps.getPosition().x
+						- controller.getScaleDiv2() - scalediv20);
+				int barY = (int) (cps.getPosition().y
+						- controller.getScaleDiv2() + controller.getScale() + 1);
+				int barWidth = (int) (controller.getScale()
+						+ ((scalediv20) * 2) - 1);
+				int barHeight = (int) (controller.getScale() / 5);
+
+				// draw Rectangle under the image
+				g2.setStroke(new BasicStroke(1));
+				g2.drawRect(barX, barY, barWidth, barHeight);
+
+				// get supplied status
+				float percentage = hl.getSuppliedPercentage();
+
+				// set Color
+				g2.setColor(hl.getColor());
+
+				// fill it accordingly
+				g2.fillRect(barX + 1, barY + 1,
+						(int) ((barWidth - 1) * percentage), barHeight - 1);
+
+				// write percentage
+				g2.setColor(Color.BLACK);
+				Font oldFont = g2.getFont();
+				g.setFont(new Font("TimesRoman", Font.PLAIN,
+						(int) (barHeight * 1.5) - 2));
+
+				String percentageString = (Math.round((percentage * 100)))
+						+ "%";
+
+				int stringWidth = (int) g2.getFontMetrics()
+						.getStringBounds(percentageString, g2).getWidth();
+				g2.drawString(percentageString, barX + barWidth / 2 + 1
+						- stringWidth / 2, barY + barHeight);
+
+				g2.setFont(oldFont);
+			}
+		}
+	}
 
     void setEdgePictureAndHighlighting(AbstractCpsObject cps) {
         // node image

Файловите разлики са ограничени, защото са твърде много
+ 355 - 468
src/ui/view/GUI.java


+ 3 - 48
src/ui/view/MyCanvas.java

@@ -484,54 +484,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 					cps.getPosition().y - controller.getScaleDiv2(),
 					controller.getScale(), controller.getScale(), null);
 
-			/**
-			 * draw and fill the supply Bar
-			 */
-			if (model.getShowSupplyBars() && cps instanceof HolonObject) {
-				HolonObject hl = (HolonObject) cps;
-				if (hl != null
-						&& (hl.getState() == HolonObject.NOT_SUPPLIED || hl
-								.getState() == HolonObject.PARTIALLY_SUPPLIED)) {
-					// calculate Positons:
-					int barX = (int) (cps.getPosition().x
-							- controller.getScaleDiv2() - scalediv20);
-					int barY = (int) (cps.getPosition().y
-							- controller.getScaleDiv2() + controller.getScale() + 1);
-					int barWidth = (int) (controller.getScale()
-							+ ((scalediv20) * 2) - 1);
-					int barHeight = (int) (controller.getScale() / 5);
-
-					// draw Rectangle under the image
-					g2.setStroke(new BasicStroke(1));
-					g2.drawRect(barX, barY, barWidth, barHeight);
-
-					// get supplied status
-					float percentage = hl.getSuppliedPercentage();
-
-					// set Color
-					g2.setColor(hl.getColor());
-
-					// fill it accordingly
-					g2.fillRect(barX + 1, barY + 1,
-							(int) ((barWidth - 1) * percentage), barHeight - 1);
-
-					// write percentage
-					g2.setColor(Color.BLACK);
-					Font oldFont = g2.getFont();
-					g.setFont(new Font("TimesRoman", Font.PLAIN,
-							(int) (barHeight * 1.5) - 2));
-
-					String percentageString = (Math.round((percentage * 100)))
-							+ "%";
-
-					int stringWidth = (int) g2.getFontMetrics()
-							.getStringBounds(percentageString, g2).getWidth();
-					g2.drawString(percentageString, barX + barWidth / 2 + 1
-							- stringWidth / 2, barY + barHeight);
-
-					g2.setFont(oldFont);
-				}
-			}
+			paintSupplyBar(g, cps);
 
 		}
 
@@ -545,6 +498,8 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 		showTooltip(g);
 	}
 
+	
+
 	@Override
 	public void mouseClicked(MouseEvent e) {
 		if (e.getButton() == MouseEvent.BUTTON1) {

+ 1 - 1
src/ui/view/UpperNodeCanvas.java

@@ -464,7 +464,6 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
             // node image
             if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
                     || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
-                //img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();//TODO: ONE MORE
             	img = Util.loadImage(this,"/Images/node_selected.png");
             } else {
                 if (cps instanceof HolonSwitch) {
@@ -552,6 +551,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
 
             g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
                     controller.getScale(), controller.getScale(), null);
+            paintSupplyBar(g2,cps);
         }
 
         // Dragged marker Highlighting

Някои файлове не бяха показани, защото твърде много файлове са промени