id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
aaffeb50-87c5-4116-87a8-218f155c789c | public int getBasicPixel(int x, int y)
{
return bufferedImage.getRGB(x,y);
} |
98333cfe-c39b-4b52-803b-d03377d4f5fc | public void setBasicPixel(int x, int y, int rgb)
{
bufferedImage.setRGB(x,y,rgb);
} |
f1a8d123-5177-417c-a8f2-99ae9099189d | public Pixel getPixel(int x, int y)
{
// create the pixel object for this picture and the given x and y location
Pixel pixel = new Pixel(this,x,y);
return pixel;
} |
5d4fec14-8a2e-4ad4-9d47-90ad9fd41f90 | public Pixel[] getPixels()
{
int width = getWidth();
int height = getHeight();
Pixel[] pixelArray = new Pixel[width * height];
// loop through height rows from top to bottom
for (int row = 0; row < height; row++)
for (int col = 0; col < width; col++)
pixelArray[row * width + col] = new... |
66e67ba4-e3ee-4ac0-bab1-013bef7860dc | public Pixel[][] getPixels2D()
{
int width = getWidth();
int height = getHeight();
Pixel[][] pixelArray = new Pixel[height][width];
// loop through height rows from top to bottom
for (int row = 0; row < height; row++)
for (int col = 0; col < width; col++)
pixelArray[row][col] = new Pix... |
8bceab07-c972-4137-9740-e1b93c0416cc | public void load(Image image)
{
// get a graphics context to use to draw on the buffered image
Graphics2D graphics2d = bufferedImage.createGraphics();
// draw the image on the buffered image starting at 0,0
graphics2d.drawImage(image,0,0,null);
// show the new image
show();
} |
61f0a79f-ccb4-49c3-8352-96f930b1015a | public void show()
{
// if there is a current picture frame then use it
if (pictureFrame != null)
pictureFrame.updateImageAndShowIt();
// else create a new picture frame with this picture
else
pictureFrame = new PictureFrame(this);
} |
b2b8b9d1-c3d9-41a7-a556-279c911c57a9 | public void hide()
{
if (pictureFrame != null)
pictureFrame.setVisible(false);
} |
e888bab5-6ddf-4636-b34f-e9c605ddf9c6 | public void setVisible(boolean flag)
{
if (flag)
this.show();
else
this.hide();
} |
1b24706e-747f-497d-8fc7-35f6eda82e7f | public void explore()
{
// create a copy of the current picture and explore it
new PictureExplorer(new SimplePicture(this));
} |
a27abe89-e90b-42c9-9a9d-bd591b033d8e | public void repaint()
{
// if there is a picture frame tell it to repaint
if (pictureFrame != null)
pictureFrame.repaint();
// else create a new picture frame
else
pictureFrame = new PictureFrame(this);
} |
605f3899-cfa1-4e10-919f-cf3025704b31 | public void loadOrFail(String fileName) throws IOException
{
// set the current picture's file name
this.fileName = fileName;
// set the extension
int posDot = fileName.indexOf('.');
if (posDot >= 0)
this.extension = fileName.substring(posDot + 1);
// if the current title is null use th... |
da5a11aa-a038-4414-9cc0-827892e82833 | public boolean load(String fileName)
{
try {
this.loadOrFail(fileName);
return true;
} catch (Exception ex) {
System.out.println("There was an error trying to open " + fileName);
bufferedImage = new BufferedImage(600,200,
Buffere... |
5225bf9e-5a6e-4457-8271-9f306153625a | public boolean loadImage(String fileName)
{
return load(fileName);
} |
02dc4fdf-6668-41a2-9107-210e747f51f3 | public void addMessage(String message, int xPos, int yPos)
{
// get a graphics context to use to draw on the buffered image
Graphics2D graphics2d = bufferedImage.createGraphics();
// set the color to white
graphics2d.setPaint(Color.white);
// set the font to Helvetica bold style and size 16
g... |
cd874689-e157-4e3b-a840-5fb0b1c83ad3 | public void drawString(String text, int xPos, int yPos)
{
addMessage(text,xPos,yPos);
} |
a50e277e-8168-44c8-b466-bfaa07b400b4 | public Picture scale(double rFactor, double cFactor)
{
// set up the scale tranform
AffineTransform scaleTransform = new AffineTransform();
scaleTransform.scale(cFactor,rFactor);
// create a new picture object that is the right size
Picture result = new Picture((int) (getHeight() * rFactor),
... |
be05fb6a-39f1-417d-89ae-353cff3eb2d8 | public Picture getPictureWithWidth(int width)
{
// set up the scale tranform
double xFactor = (double) width / this.getWidth();
Picture result = scale(xFactor,xFactor);
return result;
} |
c4f0668f-e494-4112-8c99-40ebb30b49b0 | public Picture getPictureWithHeight(int height)
{
// set up the scale tranform
double yFactor = (double) height / this.getHeight();
Picture result = scale(yFactor,yFactor);
return result;
} |
3c90a63b-7754-4f5f-abe0-038837bb352c | public boolean loadPictureAndShowIt(String fileName)
{
boolean result = true; // the default is that it worked
// try to load the picture into the buffered image from the file name
result = load(fileName);
// show the picture in a picture frame
show();
return result;
} |
fcba392c-27af-4014-a0f4-d1e6fbee1e9e | public void writeOrFail(String fileName) throws IOException
{
String extension = this.extension; // the default is current
// create the file object
File file = new File(fileName);
File fileLoc = file.getParentFile(); // directory name
// if there is no parent directory use the current media dir... |
3990274c-d2b5-4587-98d6-671f8a302b53 | public boolean write(String fileName)
{
try {
this.writeOrFail(fileName);
return true;
} catch (Exception ex) {
System.out.println("There was an error trying to write " + fileName);
ex.printStackTrace();
return false;
}
} |
d81e4e90-feb1-4ec5-a442-381bbbd0165b | public static String getMediaPath(String fileName) {
return FileChooser.getMediaPath(fileName);
} |
8d132839-a52d-4d6d-a6e0-15c5988afd3c | public Rectangle2D getTransformEnclosingRect(AffineTransform trans)
{
int width = getWidth();
int height = getHeight();
double maxX = width - 1;
double maxY = height - 1;
double minX, minY;
Point2D.Double p1 = new Point2D.Double(0,0);
Point2D.Double p2 = new Point2D.Double(maxX,0);
Poi... |
cccd0924-fbe7-4822-9c39-02d1ad8c4ff8 | public Rectangle2D getTranslationEnclosingRect(AffineTransform trans)
{
return getTransformEnclosingRect(trans);
} |
781ebf8c-7916-4393-88a8-e345b06af458 | public String toString()
{
String output = "Simple Picture, filename " + fileName +
" height " + getHeight() + " width " + getWidth();
return output;
} |
859da39d-81eb-46d0-a99d-0d5540e5f7e0 | public PictureFrame()
{
// set up the frame
initFrame();
} |
5aaedfa8-ff40-46ff-9c2c-bfb7914447fc | public PictureFrame(DigitalPicture picture)
{
// set the current object's picture to the passed in picture
this.picture = picture;
// set up the frame
initFrame();
} |
d39ab2c4-84cb-43ab-9466-4268678dc182 | public void setPicture(Picture picture)
{
this.picture = picture;
imageIcon.setImage(picture.getImage());
frame.pack();
frame.repaint();
} |
f63d2279-9402-4183-84d1-1f0435513715 | public void updateImage()
{
// only do this if there is a picture
if (picture != null)
{
// set the image for the image icon from the picture
imageIcon.setImage(picture.getImage());
// set the title of the frame to the title of the picture
frame.setTitle(picture.getTitle());... |
09f61f7f-c4a6-456b-97c7-2392ab083ea4 | public void updateImageAndShowIt()
{
// first update the image
updateImage();
// now make sure it is shown
frame.setVisible(true);
} |
cc7c9673-526c-455d-a6c6-717575477d70 | public void displayImage()
{
frame.setVisible(true);
} |
6b76bee4-4e58-4a3b-9384-f2b6cfaf8b0a | public void hide()
{
frame.setVisible(false);
} |
9db524a2-5fb5-4d7f-ab48-27930146a691 | public void setVisible(boolean flag)
{
frame.setVisible(flag);
} |
55a27c41-1f6a-4926-9910-1aa79c6da284 | public void close()
{
frame.setVisible(false);
frame.dispose();
} |
f88e2253-6a32-4bd8-8aca-8d56114cadcf | public void setTitle(String title)
{
frame.setTitle(title);
} |
08dbbe46-5c76-42d9-8b5b-fb8e1c6c59a5 | public void repaint()
{
// make it visible
frame.setVisible(true);
// update the image from the picture
updateImage();
// tell the JFrame to handle the repaint
frame.repaint();
} |
d292458c-843f-431c-9c2b-0998e2c7d5be | private void initFrame()
{
// set the image for the picture frame
updateImage();
// add the label to the frame
frame.getContentPane().add(label);
// pack the frame (set the size to as big as it needs to be)
frame.pack();
// make the frame visible
frame.setVisible(... |
18bbeccb-c8e9-4fc4-a503-8a222181a8e5 | public String getFileName(); // get the file name that the picture came from |
dbdbeeca-407f-4e0f-82df-3225bcd6a0fe | public String getTitle(); // get the title of the picture |
dc54b105-ac9f-4793-9cfc-79690367873b | public void setTitle(String title); // set the title of the picture |
b94cca1c-577a-44f0-8f7f-040e92696cf8 | public int getWidth(); // get the width of the picture in pixels |
003a00e2-a53d-4fee-a067-2e72954f8215 | public int getHeight(); // get the height of the picture in pixels |
1b552ea6-f698-412f-a62f-39051cdb0d8f | public Image getImage(); // get the image from the picture |
ba2d50a6-b147-499e-8c71-ee68d3a39659 | public BufferedImage getBufferedImage(); // get the buffered image |
2bad3db8-a0d5-4dbd-9328-5d9cef411007 | public int getBasicPixel(int x, int y); // get the pixel information as an int |
8f6ade91-438e-4200-85fa-28119930e79e | public void setBasicPixel(int x, int y, int rgb); // set the pixel information |
7cd271d9-9edd-4f6e-af65-792cf7b8beb0 | public Pixel getPixel(int x, int y); // get the pixel information as an object |
af0613c6-645a-4fa9-86e4-e6d7232cd0b3 | public Pixel[] getPixels(); // get all pixels in row-major order |
939001e6-25ae-4772-aad0-828433d459f0 | public Pixel[][] getPixels2D(); // get 2-D array of pixels in row-major order |
769d2824-05bd-4851-84f6-b772d41b8a1d | public void load(Image image); // load the image into the picture |
b32f7292-f54b-4407-b77a-2ebf7bfd2f90 | public boolean load(String fileName); // load the picture from a file |
ddb457b9-2038-4f3a-a7af-1c0c519faac1 | public void show(); // show the picture |
e928a371-7cec-46e0-83dd-c94a3054487d | public void explore(); // explore the picture |
9eec676e-4b68-4e75-9da4-947f48d0dabc | public boolean write(String fileName); // write out a file |
e6b90fb9-c81e-45d7-b017-57a24dcf22db | public static Color pickAColor()
{
Color color = Color.white;
// create a JFrame to be the parent of the color chooser open dialog
// if you don't do this then you may not see the dialog.
JFrame frame = new JFrame();
frame.setAlwaysOnTop(true);
// use the color chooser to pick t... |
c7f2d708-0cc0-4b0c-9a63-0bcb43acd872 | public static void main(String[] args)
{
Color pickedColor = ColorChooser.pickAColor();
System.out.println(pickedColor);
} |
2f0479ba-045a-4350-8f1d-de5b513e8453 | public PictureExplorer(DigitalPicture picture)
{
// set the fields
this.picture=picture;
zoomFactor=1;
// create the window and set things up
createWindow();
} |
1cb62d83-4ce1-42b7-afbd-aa578a7523cd | public void changeToBaseOne()
{
numberBase=1;
} |
8fdf9df6-9a67-451e-90ec-e8307ccd793e | public void setTitle(String title)
{
pictureFrame.setTitle(title);
} |
9f6d2393-b589-4d96-a2be-ae803fd41ad0 | private void createAndInitPictureFrame()
{
pictureFrame = new JFrame(); // create the JFrame
pictureFrame.setResizable(true); // allow the user to resize it
pictureFrame.getContentPane().setLayout(new BorderLayout()); // use border layout
pictureFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)... |
f5949fc2-811f-4ec8-a396-61c1c19ac200 | private void setUpMenuBar()
{
//create menu
menuBar = new JMenuBar();
zoomMenu = new JMenu("Zoom");
twentyFive = new JMenuItem("25%");
fifty = new JMenuItem("50%");
seventyFive = new JMenuItem("75%");
hundred = new JMenuItem("100%");
hundred.setEnabled(false);
hundredFifty = new JM... |
9df9c9fc-7bb2-41ae-af07-2801d63a114e | private void createAndInitScrollingImage()
{
scrollPane = new JScrollPane();
BufferedImage bimg = picture.getBufferedImage();
imageDisplay = new ImageDisplay(bimg);
imageDisplay.addMouseMotionListener(this);
imageDisplay.addMouseListener(this);
imageDisplay.setToolTipText("Click a mouse b... |
afb15279-5b82-4ced-a1da-23041b2c7c0b | private void createWindow()
{
// create the picture frame and initialize it
createAndInitPictureFrame();
// set up the menu bar
setUpMenuBar();
//create the information panel
createInfoPanel();
//creates the scrollpane for the picture
createAndInitScrollingImage();
... |
c50a6ed9-33f0-4fc9-8168-0edb0724b823 | private void setUpNextAndPreviousButtons()
{
// create the image icons for the buttons
Icon prevIcon = new ImageIcon(DigitalPicture.class.getResource("leftArrow.gif"),
"previous index");
Icon nextIcon = new ImageIcon(DigitalPicture.class.getResource("rightArrow.gif"),
... |
91d8b797-ce08-42ae-a3d2-0abd8a76b8e4 | public void actionPerformed(ActionEvent evt) {
colIndex--;
if (colIndex < 0)
colIndex = 0;
displayPixelInformation(colIndex,rowIndex);
} |
1af79c26-1c60-4d1d-9ae1-8fb2ec64de80 | public void actionPerformed(ActionEvent evt) {
rowIndex--;
if (rowIndex < 0)
rowIndex = 0;
displayPixelInformation(colIndex,rowIndex);
} |
1dc63234-97f6-47e7-8b38-8cd1df5e6ccd | public void actionPerformed(ActionEvent evt) {
colIndex++;
if (colIndex >= picture.getWidth())
colIndex = picture.getWidth() - 1;
displayPixelInformation(colIndex,rowIndex);
} |
7fea19e3-27aa-4d94-a828-2319e8436112 | public void actionPerformed(ActionEvent evt) {
rowIndex++;
if (rowIndex >= picture.getHeight())
rowIndex = picture.getHeight() - 1;
displayPixelInformation(colIndex,rowIndex);
} |
dff2b799-b688-4ba9-bd0b-e38a05de1de1 | public JPanel createLocationPanel(Font labelFont) {
// create a location panel
JPanel locationPanel = new JPanel();
locationPanel.setLayout(new FlowLayout());
Box hBox = Box.createHorizontalBox();
// create the labels
rowLabel = new JLabel("Row:");
colLabel = new JLabel("Column:");... |
a1fd0d4f-1f85-4083-9f62-a283f241d0fa | public void actionPerformed(ActionEvent e) {
displayPixelInformation(colValue.getText(),rowValue.getText());
} |
de79a177-eb22-4519-9c11-1efe313c5f7c | public void actionPerformed(ActionEvent e) {
displayPixelInformation(colValue.getText(),rowValue.getText());
} |
b9cd2cba-b87f-4c5a-a8ee-697bad07065d | private JPanel createColorInfoPanel(Font labelFont)
{
// create a color info panel
JPanel colorInfoPanel = new JPanel();
colorInfoPanel.setLayout(new FlowLayout());
// get the pixel at the x and y
Pixel pixel = new Pixel(picture,colIndex,rowIndex);
// create the labels
rValue = n... |
f9b62c8c-eb67-44ab-bb8c-9be05eef94e3 | private void createInfoPanel()
{
// create the info panel and set the layout
JPanel infoPanel = new JPanel();
infoPanel.setLayout(new BorderLayout());
// create the font
Font largerFont = new Font(infoPanel.getFont().getName(),
infoPanel.getFont().getStyle(),14)... |
e9cf5a5e-f787-4a14-938e-cf6ada218333 | public void checkScroll()
{
// get the x and y position in pixels
int xPos = (int) (colIndex * zoomFactor);
int yPos = (int) (rowIndex * zoomFactor);
// only do this if the image is larger than normal
if (zoomFactor > 1) {
// get the rectangle that defines the current view
... |
4267a9ae-2375-451e-a003-bed71e1fc673 | public void zoom(double factor)
{
// save the current zoom factor
zoomFactor = factor;
// calculate the new width and height and get an image that size
int width = (int) (picture.getWidth()*zoomFactor);
int height = (int) (picture.getHeight()*zoomFactor);
BufferedImage bimg = picture.getB... |
cdd4e514-cfc9-4e0a-8f97-50e50b21d4e1 | public void repaint()
{
pictureFrame.repaint();
} |
d15a07ae-2c21-42fb-b645-8f614e57220a | public void mouseDragged(MouseEvent e)
{
displayPixelInformation(e);
} |
8cc75cd6-314d-4869-aa53-e4a9da71d193 | private boolean isLocationInPicture(int column, int row)
{
boolean result = false; // the default is false
if (column >= 0 && column < picture.getWidth() &&
row >= 0 && row < picture.getHeight())
result = true;
return result;
} |
35b801fa-3236-4116-9db9-91a2981b3b2c | public void displayPixelInformation(String xString, String yString)
{
int x = -1;
int y = -1;
try {
x = Integer.parseInt(xString);
x = x - numberBase;
y = Integer.parseInt(yString);
y = y - numberBase;
} catch (Exception ex) {
}
if (x >= 0 && y >= 0) {
displa... |
d9e8d19b-9e56-43a1-beab-6e007ebb7f5b | private void displayPixelInformation(int pictureX, int pictureY)
{
// check that this x and y are in range
if (isLocationInPicture(pictureX, pictureY))
{
// save the current x and y index
colIndex = pictureX;
rowIndex = pictureY;
// get the pixel at the x and y
Pixel p... |
caa81105-e273-4ab5-98f1-a11b61ab301c | private void displayPixelInformation(MouseEvent e)
{
// get the cursor x and y
int cursorX = e.getX();
int cursorY = e.getY();
// get the x and y in the original (not scaled image)
int pictureX = (int) (cursorX / zoomFactor + numberBase);
int pictureY = (int) (cursorY / zoomFactor + ... |
cc5ce56e-42fe-45bf-ba75-c53c36ae8022 | private void clearInformation()
{
colValue.setText("N/A");
rowValue.setText("N/A");
rValue.setText("R: N/A");
gValue.setText("G: N/A");
bValue.setText("B: N/A");
colorPanel.setBackground(Color.black);
colIndex = -1;
rowIndex = -1;
} |
b52677cf-5676-436a-8d1c-9385e33631e2 | public void mouseMoved(MouseEvent e)
{} |
32f02d1f-224d-491e-bf28-cbaaf6dd82f5 | public void mouseClicked(MouseEvent e)
{
displayPixelInformation(e);
} |
4c7e873a-ef3a-4d86-92ed-f23ce7c8abca | public void mousePressed(MouseEvent e)
{
displayPixelInformation(e);
} |
81cd4c99-91fb-440a-89e1-0b72f2449185 | public void mouseReleased(MouseEvent e)
{
} |
25dde3fa-2e79-4f53-b104-b33d33445a24 | public void mouseEntered(MouseEvent e)
{
} |
a8056859-b115-4d21-a5f3-d745ef45563c | public void mouseExited(MouseEvent e)
{
} |
940f3377-80f4-4d45-8ac7-00749850a4ad | private void enableZoomItems()
{
twentyFive.setEnabled(true);
fifty.setEnabled(true);
seventyFive.setEnabled(true);
hundred.setEnabled(true);
hundredFifty.setEnabled(true);
twoHundred.setEnabled(true);
fiveHundred.setEnabled(true);
} |
73d7afc8-18cf-49a4-ba6d-5a9ab0f6c930 | public void actionPerformed(ActionEvent a)
{
if(a.getActionCommand().equals("Update"))
{
this.repaint();
}
if(a.getActionCommand().equals("25%"))
{
this.zoom(.25);
enableZoomItems();
twentyFive.setEnabled(false);
}
if(a.getActionCommand().equals("50%"... |
af30a4ce-79db-42f3-8cb5-5cf57036f542 | public Component getComponentAfter(Container focusCycleRoot,
Component aComponent) {
if (aComponent.equals(colValue))
return rowValue;
else
return colValue;
} |
b4a603a9-fed2-45f6-8dbc-58a23b032009 | public Component getComponentBefore(Container focusCycleRoot,
Component aComponent) {
if (aComponent.equals(colValue))
return rowValue;
else
return colValue;
} |
35d598ad-6e8a-44d7-ba0f-547a418bec7e | public Component getDefaultComponent(Container focusCycleRoot) {
return colValue;
} |
a58c8b46-53b5-4bb0-b466-e785f3d45dcf | public Component getLastComponent(Container focusCycleRoot) {
return rowValue;
} |
a8e88648-4350-499e-8e20-4f0276688a28 | public Component getFirstComponent(Container focusCycleRoot) {
return colValue;
} |
48011f0f-f18d-4663-969a-b7c69b886f52 | public static void main( String args[])
{
Picture pix = new Picture("beach.jpg");
pix.explore();
} |
7595118d-4c48-475c-a2f3-8ba0887e9333 | public Pixel(DigitalPicture picture, int x, int y)
{
// set the picture
this.picture = picture;
// set the x location
this.x = x;
// set the y location
this.y = y;
} |
77d2e1c0-e1ef-4caa-90e9-0a33608de4c6 | public int getX() { return x; } |
c3e51a60-ca18-4932-890e-0b7e5d2602d7 | public int getY() { return y; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.