瀏覽代碼

Infinite capacity for edges

dominik.rieder 7 年之前
父節點
當前提交
bfbeaaa546
共有 5 個文件被更改,包括 81 次插入24 次删除
  1. 3 11
      src/classes/CpsEdge.java
  2. 31 6
      src/ui/view/EditEdgesPopUp.java
  3. 14 0
      src/ui/view/GUI.java
  4. 32 7
      src/ui/view/MyCanvas.java
  5. 1 0
      src/ui/view/ShowedInformationPopUp.java

+ 3 - 11
src/classes/CpsEdge.java

@@ -5,7 +5,6 @@ public class CpsEdge {
 	float maxCapacity;
 	float flow;
 	boolean isWorking;
-	boolean infinite;
 	
 	CpsObject A;
 	CpsObject B;
@@ -57,10 +56,10 @@ public class CpsEdge {
 	 */
 	public void setFlow(float flow) {
 		this.flow = flow;
-		if(flow > maxCapacity){
-			isWorking = false;
-		}else{
+		if(flow <= maxCapacity || flow == -1){
 			isWorking = true;
+		}else{
+			isWorking = false;
 		}
 	}
 	
@@ -99,12 +98,5 @@ public class CpsEdge {
 		return isWorking;
 	}
 	
-	public void setInfinite(boolean inf){
-		infinite = inf;
-	}
-	
-	public boolean getInfinite(){
-		return infinite;
-	}
 
 }

+ 31 - 6
src/ui/view/EditEdgesPopUp.java

@@ -32,6 +32,7 @@ public class EditEdgesPopUp extends JDialog{
 	private JRadioButton rdbtnChangeForAll_1;
 	private Control controller;
 	private MyCanvas canvas;
+	private JLabel lblenterinfiniteFor;
 	
 	/**
 	 * Launch the application.
@@ -51,7 +52,7 @@ public class EditEdgesPopUp extends JDialog{
 		super((java.awt.Frame) null, true);
 		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
 		this.setTitle("Edit Capacities of Edges");
-		setBounds(100, 100, 400, 220);
+		setBounds(100, 100, 438, 220);
 		getContentPane().setLayout(new BorderLayout());
 		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
 		getContentPane().add(contentPanel, BorderLayout.CENTER);
@@ -92,8 +93,8 @@ public class EditEdgesPopUp extends JDialog{
 		JButton btnOk_1 = new JButton("OK");
 		btnOk_1.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
-				try {
-					capacity = Float.parseFloat(capacityField.getText().toString());
+				if(capacityField.getText().equals("infinite")){
+					capacity = -1;
 					if(rdbtnChangeForAll.isSelected()){
 						changeForExisting(capacity);
 						dispose();
@@ -107,9 +108,29 @@ public class EditEdgesPopUp extends JDialog{
 						JOptionPane.showMessageDialog(new JFrame(),
 								"Please select one of the options");
 					}
-				} catch (NumberFormatException e1) {
-					JOptionPane.showMessageDialog(new JFrame(),
-							"Please enter a number in the Field for Maximum Capacity");
+				}else{
+					try {
+						capacity = Float.parseFloat(capacityField.getText().toString());
+						if(capacity < 0){
+							throw new NumberFormatException();
+						}
+						if(rdbtnChangeForAll.isSelected()){
+							changeForExisting(capacity);
+							dispose();
+						}else if (rdbtnChangeForNew.isSelected()){
+							changeForNew(capacity);
+							dispose();
+						}else if(rdbtnChangeForAll_1.isSelected()){
+							changeForExAndNew(capacity);
+							dispose();
+						}else{
+							JOptionPane.showMessageDialog(new JFrame(),
+									"Please select one of the options");
+						}
+					} catch (NumberFormatException e1) {
+						JOptionPane.showMessageDialog(new JFrame(),
+							"Please enter a number greater or equal 0 in the Field for Maximum Capacity");
+					}
 				}
 			}
 		});
@@ -120,6 +141,10 @@ public class EditEdgesPopUp extends JDialog{
 		bG.add(rdbtnChangeForAll_1);
 		bG.add(rdbtnChangeForNew);
 		bG.add(rdbtnChangeForAll);
+		
+		lblenterinfiniteFor = new JLabel("(enter \"infinite\" for infinite Capacity)");
+		lblenterinfiniteFor.setBounds(237, 11, 175, 14);
+		contentPanel.add(lblenterinfiniteFor);
 	}
 	
 	public void setCanvas(MyCanvas can){

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

@@ -196,6 +196,7 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem mntmRedo = new JMenuItem("Redo");
 	private final JMenuItem mntmEditEdges = new JMenuItem("Edit Edges");
 	private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
+	private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
 
 	/**
 	 * Create the application.
@@ -412,6 +413,19 @@ public class GUI<E> implements CategoryListener {
 		});
 		
 		mnNewMenu_1.add(mntmFindReplace);
+		mntmEditShowedInformation.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				try {
+					ShowedInformationPopUp dialog = new ShowedInformationPopUp(canvas);
+					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+					dialog.setVisible(true);
+				} catch (Exception e1) {
+					e1.printStackTrace();
+				}
+			}
+		});
+		
+		mnNewMenu_1.add(mntmEditShowedInformation);
 
 		menuBar.add(mnNewMenu_2);
 		mntmEditEdges.addActionListener(new ActionListener() {

+ 32 - 7
src/ui/view/MyCanvas.java

@@ -78,6 +78,8 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		this.controller = control;
 		this.model = model;
 
+		showedInformation[0] = true;
+		showedInformation[1] = false;
 		edgeCapacity = 10000;
 		popmenu.add(itemDelete);
 		itemDelete.setEnabled(false);
@@ -103,6 +105,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	 * 
 	 */
 	public void paintComponent(Graphics g) {
+		String maxCap;
 		super.paintComponent(g);
 		// Rendering
 		g2 = (Graphics2D) g;
@@ -121,9 +124,11 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		for (CpsEdge con : model.getEdgesOnCanvas()) {
 			if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID()
 					&& con != edgeHighlight) {
-				if (con.getFlow() <= con.getCapacity()) {
+				if (con.getFlow() <= con.getCapacity() || con.getCapacity() == -1) {
 					g2.setColor(Color.GREEN);
-					g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 4), 4)));
+					if(con.getCapacity() != -1){
+						g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 4), 4)));
+					}
 				} else {
 					g2.setColor(Color.RED);
 					g2.setStroke(new BasicStroke(2));
@@ -132,9 +137,17 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						con.getA().getPosition().y + controller.getScaleDiv2(),
 						con.getB().getPosition().x + controller.getScaleDiv2(),
 						con.getB().getPosition().y + controller.getScaleDiv2());
-				g2.drawString(con.getFlow() + "/" + con.getCapacity(),
-						(con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
-						(con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
+				
+				if(con.getCapacity() == -1){
+					maxCap = Character.toString('\u221e');
+				}else{
+					maxCap = String.valueOf(con.getCapacity());
+				}
+				if(showedInformation[0]){
+					g2.drawString(con.getFlow() + "/" + maxCap,
+							(con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
+							(con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
+				}
 			}
 		}
 
@@ -153,8 +166,14 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 							con.getA().getPosition().y + controller.getScaleDiv2(),
 							con.getB().getPosition().x + controller.getScaleDiv2(),
 							con.getB().getPosition().y + controller.getScaleDiv2());
+					
+					if(con.getCapacity() == -1){
+						maxCap = Character.toString('\u221e');
+					}else{
+						maxCap = String.valueOf(con.getCapacity());
+					}
 					if(showedInformation[0]){
-						g2.drawString(con.getFlow() + "/" + con.getCapacity(),
+						g2.drawString(con.getFlow() + "/" + maxCap,
 								(con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
 								(con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
 					}
@@ -167,8 +186,14 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					edgeHighlight.getA().getPosition().y + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().x + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().y + controller.getScaleDiv2());
+			
+			if(edgeHighlight.getCapacity() == -1){
+				maxCap = Character.toString('\u221e');
+			}else{
+				maxCap = String.valueOf(edgeHighlight.getCapacity());
+			}
 			if(showedInformation[0]){
-				g2.drawString(edgeHighlight.getFlow() + "/" + edgeHighlight.getCapacity(),
+				g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
 						(edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2
 							+ controller.getScaleDiv2(),
 							(edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2

+ 1 - 0
src/ui/view/ShowedInformationPopUp.java

@@ -60,5 +60,6 @@ public class ShowedInformationPopUp extends JDialog{
 	
 	private void setInformation(boolean connection, boolean object){
 		canvas.setShowedInformation(connection, object);
+		canvas.repaint();
 	}
 }