Browse Source

Completely removed the old resource loading code.
Optimized my solution slightly.

Ludwig Tietze 7 years ago
parent
commit
438765ffdd

+ 2 - 4
src/ui/view/AboutUsPopUp.java

@@ -51,10 +51,8 @@ public class AboutUsPopUp extends JFrame {
         contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
         contentPanel2.setLayout(new BoxLayout(contentPanel2, BoxLayout.Y_AXIS));
         contentPanel3.setLayout(new BoxLayout(contentPanel3, BoxLayout.Y_AXIS));
-
-        //this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
-        //        .getScaledInstance(30, 30, Image.SCALE_SMOOTH));//TODO: and here...
-        this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30, Image.SCALE_SMOOTH));
+        
+        this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30));
         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         setBounds(100, 100, 500, 800);
         setLocationRelativeTo(parentFrame);

+ 1 - 3
src/ui/view/AddElementPopUp.java

@@ -50,9 +50,7 @@ public class AddElementPopUp extends JDialog {
 	 */
 	AddElementPopUp(JFrame parentFrame) {
 		super((java.awt.Frame) null, true);
-		//this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
-		//		.getScaledInstance(30, 30, Image.SCALE_SMOOTH));//TODO: and here
-		this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30, Image.SCALE_SMOOTH));
+		this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30));
 		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
 		setBounds(100, 100, 400, 190);
 		setLocationRelativeTo(parentFrame);

+ 1 - 3
src/ui/view/AddObjectPopUp.java

@@ -71,9 +71,7 @@ public class AddObjectPopUp extends JDialog {
     AddObjectPopUp(boolean edit, AbstractCpsObject obj, String cat, JFrame parentFrame) {
         toEdit = obj;
 		editState = edit;
-		//this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
-		//		.getScaledInstance(30, 30, Image.SCALE_SMOOTH));//TODO: and here...
-		this.setIconImage(Util.loadImage(this, "/Images/Dummy_House.png",30,30, Image.SCALE_SMOOTH));
+		this.setIconImage(Util.loadImage(this, "/Images/Dummy_House.png",30,30));
 		setBounds(100, 100, 450, 342);
         setLocationRelativeTo(parentFrame);
         getContentPane().setLayout(new BorderLayout());

+ 1 - 3
src/ui/view/BackgroundPopUp.java

@@ -64,9 +64,7 @@ public class BackgroundPopUp extends JDialog {
 			imageWidth.setText("" + icon.getIconWidth());
 			imageHeight.setText("" + icon.getIconHeight());
 		}
-		//this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
-		//		.getScaledInstance(30, 30, Image.SCALE_SMOOTH));//TODO: here again...
-		this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30, Image.SCALE_SMOOTH));
+		this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30));
 		setBounds(100, 100, 600, 340);
         setLocationRelativeTo(parentFrame);
 

+ 1 - 3
src/ui/view/CanvasResizePopUp.java

@@ -38,9 +38,7 @@ public class CanvasResizePopUp extends JDialog {
 		this.canvas = canvas;
 
 		// properties and stuff
-		//this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
-		//		.getScaledInstance(30, 30, Image.SCALE_SMOOTH));//TODO: and again...
-		this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30, Image.SCALE_SMOOTH));
+		this.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30));
 		this.setTitle("Set the Size of the View");
 		setBounds(200, 100, 200, 100);
         setLocationRelativeTo(parentFrame);

+ 3 - 16
src/ui/view/GUI.java

@@ -560,9 +560,7 @@ public class GUI implements CategoryListener {
 
         frmCyberPhysical.setJMenuBar(menuBar);
 
-       // frmCyberPhysical.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
-       //         .getScaledInstance(30, 30, Image.SCALE_SMOOTH));//TODO: Fix here
-        frmCyberPhysical.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30,Image.SCALE_SMOOTH));
+        frmCyberPhysical.setIconImage(Util.loadImage(this,"/Images/Dummy_House.png",30,30));
         		
         menuBar.add(mnNewMenu);
 
@@ -1247,15 +1245,7 @@ public class GUI implements CategoryListener {
                     for (Category cat : model.getCategories()) {
                         for (AbstractCpsObject cps : cat.getObjects()) {
                             if (value.toString().compareTo(cps.getObjName()) == 0) {
-                                File checkPath = new File(cps.getImage());
-                                //if (checkPath.exists()) {
-                                //    imgR = (cps.getImage()).getImage().getScaledInstance(50, 50,
-                                //            java.awt.Image.SCALE_SMOOTH);//TODO: fix here
-                                //} else {
-                                    //imgR = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
-                                    //        .getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);//TODO: fix here
-                                	imgR = Util.loadImage(this,cps.getImage(),50,50,java.awt.Image.SCALE_SMOOTH);
-                                //}//TODO: Apparently this was a semi-fix by someone else?
+                                imgR = Util.loadImage(this,cps.getImage(),50,50);
                                 if (imgR != null) {
                                     label.setIcon(new ImageIcon(imgR));
                                 }
@@ -1272,7 +1262,6 @@ public class GUI implements CategoryListener {
                 if (label.getText().length() == 0) {
                     label.setText(value.toString());
                     if (value.toString().compareTo("Categories") != 0) {
-                        //label.setIcon(new ImageIcon(this.getClass().getResource("/Images/folder.png")));//TODO: fix here
                     	label.setIcon(new ImageIcon(Util.loadImage(this, "/Images/folder.png")));
                     }
                 }
@@ -1397,9 +1386,7 @@ public class GUI implements CategoryListener {
                                         img = new ImageIcon(cps.getImage()).getImage().getScaledInstance(32, 32,
                                                 java.awt.Image.SCALE_SMOOTH);
                                     } else {
-                                        //img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
-                                        //        .getScaledInstance(32, 32, java.awt.Image.SCALE_SMOOTH);//TODO: help me
-                                    	img = Util.loadImage(this,cps.getImage(),32,32, Image.SCALE_SMOOTH);
+                                    	img = Util.loadImage(this,cps.getImage(),32,32);
                                     }
                                     tempCps = cps;
                                     dragging = true;

+ 7 - 18
src/ui/view/TimePanel.java

@@ -138,27 +138,22 @@ public class TimePanel extends JPanel {
 		playBtn.setContentAreaFilled(false);
 		playBtn.setBorderPainted(false);
 		playBtn.setBorder(null);
-		//playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/play.png")).getImage()
-		//		.getScaledInstance(30, 30, Image.SCALE_SMOOTH)));//TODO:Fix here
-		playBtn.setIcon(new ImageIcon(Util.loadImage(this, "/Button_Images/play.png",30,30, Image.SCALE_SMOOTH)));
+		playBtn.setIcon(new ImageIcon(Util.loadImage(this, "/Button_Images/play.png",30,30)));
 		playBtn.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				running = !running;
+				playBtn.setIcon(new ImageIcon(Util.loadImage(this,"/Button_Images/pause.png",30,30)));//relocated this here. as it was duplicate before.
 				if (running) {
 					if (!model.getIsSimRunning()) {
 						controller.setIsSimRunning(true);
 					}
 					timer.start();
 					timer.setDelay(model.getTimerSpeed());
-					//playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/pause.png"))
-					//		.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));//TODO: Soon...
-					playBtn.setIcon(new ImageIcon(Util.loadImage(this,"/Button_Images/pause.png",30,30,Image.SCALE_SMOOTH)));
+					//playBtn.setIcon(new ImageIcon(Util.loadImage(this,"/Button_Images/pause.png",30,30)));
 				} else {
 					timer.stop();
-					//playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/play.png"))
-					//		.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));//TODO: this is the exact same as above. why
-					playBtn.setIcon(new ImageIcon(Util.loadImage(this,"/Button_Images/pause.png",30,30,Image.SCALE_SMOOTH)));
+					//playBtn.setIcon(new ImageIcon(Util.loadImage(this,"/Button_Images/pause.png",30,30)));
 				}
 			}
 		});
@@ -166,9 +161,7 @@ public class TimePanel extends JPanel {
 
 		timeResetBtn.setContentAreaFilled(false);
 		timeResetBtn.setBorder(null);
-		//timeResetBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/reset.png"))
-		//		.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));//TODO: fix here
-		timeResetBtn.setIcon(new ImageIcon(Util.loadImage(this, "/Button_Images/reset.png", 30, 30, Image.SCALE_SMOOTH)));
+		timeResetBtn.setIcon(new ImageIcon(Util.loadImage(this, "/Button_Images/reset.png", 30, 30)));
 		timeResetBtn.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getMinimum());
@@ -184,9 +177,7 @@ public class TimePanel extends JPanel {
 
 		timeForwardBtn.setContentAreaFilled(false);
 		timeForwardBtn.setBorder(null);
-		//timeForwardBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/forward.png"))
-		//		.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));//TODO: fix here
-		timeForwardBtn.setIcon(new ImageIcon(Util.loadImage(this,"/Button_Images/forward.png",30,30,Image.SCALE_SMOOTH)));//TODO: fix here
+		timeForwardBtn.setIcon(new ImageIcon(Util.loadImage(this,"/Button_Images/forward.png",30,30)));
 		timeForwardBtn.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent ae) {
 				if (!model.getIsSimRunning()) {
@@ -199,9 +190,7 @@ public class TimePanel extends JPanel {
 		timeBackwardBtn.setToolTipText(Languages.getLanguage()[92]);
 
 		timeBackwardBtn.setBorder(null);
-		//timeBackwardBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/backward.png"))
-		//		.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));//TODO: fix here
-		timeBackwardBtn.setIcon(new ImageIcon(Util.loadImage(this, "/Button_Images/backward.png", 30,30, Image.SCALE_SMOOTH)));
+		timeBackwardBtn.setIcon(new ImageIcon(Util.loadImage(this, "/Button_Images/backward.png", 30,30)));
 		timeBackwardBtn.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() - 1);

+ 3 - 0
src/ui/view/Util.java

@@ -12,6 +12,9 @@ public class Util {
 		return loadImage(origin,url)
 				.getScaledInstance(w, h, scale);
 	}
+	static Image loadImage(Object origin, String url, int w, int h){//note: this may have to be a different class.
+		return loadImage(origin,url,w,h, Image.SCALE_SMOOTH);
+	}
 	static Image loadImage(Object origin, String url){//note: this may have to be a different class.
 		System.out.println(url);
 		try{