PictureManager Class This class has already been implemented.(Code at the Bottom
ID: 3758797 • Letter: P
Question
PictureManager Class
This class has already been implemented.(Code at the Bottom) This class provides several image processing options. You need to use methods of this class during the implementation of the PhotoProcessingSys class. A description of the methods follows.
displayPicture - Displays an image. The image could be in the Eclipse project or it could be a url that corresponds to an image on the web.
clearScreen - Removes any image that have been displayed.
displayLastPicture - Displays the last image that was displayed.
displayPictureBlackWhitePosterize - Takes an image and turns into black and white, posterizes it or both.
displayPictureSelectRedGreenBlue - Takes an image and select the red, green and blue components.
graphicalModeOff/graphicModeOn - In order to run public/secret/release tests we need to disable the image processing (e.g., displaying images). When graphicalModeOff is called only a string will be returned after calling any image processing function.
All the methods described above (except graphicalModeOff/graphicalModeOn) return a string representing the processing that took place.
package sysutilities;
import javax.swing.*;
import PictureLib.*;
public class PictureManager {
private static boolean GRAPHICAL_MODE = true;
public static void graphicalModeOff() {
GRAPHICAL_MODE = false;
}
public static void graphicalModeOn() {
GRAPHICAL_MODE = true;
}
public static void main(String[] args) {
graphicDemo();
nonGraphicDemo();
}
public static void graphicDemo() {
PictureManager.displayPicture("testudo.jpg");
PictureManager.displayPicture("http://www.cs.umd.edu/sites/all/themes/cs/logo.png");
JOptionPane.showMessageDialog(null, "Press OK to clear screen");
PictureManager.clearScreen();
JOptionPane.showMessageDialog(null, "Press OK to display last picture");
PictureManager.displayLastPicture();
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, false);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, true);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, false);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, true);
PictureManager.displayPictureSelectRedGreenBlue("testudo.jpg", true, false, false);
}
public static void nonGraphicDemo() {
StringBuffer activity = new StringBuffer();
PictureManager.graphicalModeOff();
activity.append(PictureManager.displayPicture("testudo.jpg"));
activity.append(PictureManager.displayPicture("http://www.cs.umd.edu/sites/all/themes/cs/logo.png"));
JOptionPane.showMessageDialog(null, "Press OK to clear screen");
PictureManager.clearScreen();
JOptionPane.showMessageDialog(null, "Press OK to display last picture");
activity.append(PictureManager.displayLastPicture());
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, false));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, true));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, false));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, true));
activity.append(PictureManager.displayPictureSelectRedGreenBlue("testudo.jpg", true, false, false));
System.out.println(activity);
}
public static String displayPicture(String name) {
if (GRAPHICAL_MODE) {
PictureUtil.show(new Image(name));
}
return "Display " + name + " ";
}
public static String clearScreen() {
if (GRAPHICAL_MODE) {
PictureUtil.clearScreen();
}
return "clearScreen ";
}
public static String displayLastPicture() {
if (GRAPHICAL_MODE) {
PictureUtil.show(PictureUtil.getLastPicDisplayed());
}
return "displayLastPicture ";
}
public static String displayPictureBlackWhitePosterize(String name, boolean blackAndWhite, boolean posterize) {
if (GRAPHICAL_MODE) {
Picture result = new Image(name);
if (blackAndWhite) {
result = new BlackAndWhite(result);
}
if (posterize) {
result = new Posterize(result);
}
PictureUtil.show(result);
}
return "displayPictureBlackWhitePosterize: " + name + ", " + blackAndWhite + posterize + " ";
}
public static String displayPictureSelectRedGreenBlue(String name, boolean red, boolean green, boolean blue) {
if (GRAPHICAL_MODE) {
PictureUtil.show(new SelectComponents(new Image(name), red, green, blue));
}
return "displayPictureSelectRedGreenBlue: " + name + ", " + red + green + blue + " ";
}
}
Explanation / Answer
NOTE : As PictureLib package was not available so I am not providing the output screenshot. You can copy the below code run in your system. It will be working fine.
CODE :
package sysutilities;
public class PhotoProcessingSys {
private static PictureManager pic=new PictureManager();
private static boolean GRAPHICAL_MODE = true;
public String displayPicture(String name)
{
return pic.displayPicture(name);
}
public static String clearScreen()
{
return pic.clearScreen();
}
public static String displayLastPicture()
{
return pic.displayLastPicture();
}
public static String displayPictureBlackWhitePosterize(String name, boolean blackAndWhite, boolean posterize)
{
return pic.displayPictureBlackWhitePosterize(name, blackAndWhite, posterize);
}
public static String displayPictureSelectRedGreenBlue(String name, boolean red, boolean green, boolean blue)
{
return pic.displayPictureSelectRedGreenBlue(name, red, green, blue);
}
public static void graphicalModeOff() {
GRAPHICAL_MODE = false;
}
public static void graphicalModeOn() {
GRAPHICAL_MODE = true;
}
public static void main(String args[])
{
PictureManager pic=new PictureManager();
}
}