From 933d00adefe6ec66fc3d19719fb8bee5151a553c Mon Sep 17 00:00:00 2001 From: rlentieu Date: Sat, 21 May 2016 18:34:23 +0200 Subject: [PATCH] add JPaint --- JPAINT/Jpaint.sh | 3 +++ JPAINT/jpaint/.gitignore | 3 +++ JPAINT/jpaint/ColorBox$AdvancedListener.class | Bin 0 -> 710 bytes JPAINT/jpaint/ColorBox.class | Bin 0 -> 2900 bytes JPAINT/jpaint/ColorBox.java | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ColorBox.java~ | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ColorLabel.class | Bin 0 -> 1330 bytes JPAINT/jpaint/ColorLabel.java | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ColorPanel.class | Bin 0 -> 1429 bytes JPAINT/jpaint/ColorPanel.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ControlClass.class | Bin 0 -> 10344 bytes JPAINT/jpaint/ControlClass.java | 401 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ControlClass.java~ | 401 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/DrawingCanvas.class | Bin 0 -> 19618 bytes JPAINT/jpaint/DrawingCanvas.java | 994 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/DrawingCanvas.java~ | 994 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ExampleFileFilter.class | Bin 0 -> 2774 bytes JPAINT/jpaint/ExampleFileFilter.java | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ExampleFileFilter.java~ | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/FontChooser$1.class | Bin 0 -> 811 bytes JPAINT/jpaint/FontChooser$2.class | Bin 0 -> 824 bytes JPAINT/jpaint/FontChooser$3.class | Bin 0 -> 863 bytes JPAINT/jpaint/FontChooser$4.class | Bin 0 -> 654 bytes JPAINT/jpaint/FontChooser$5.class | Bin 0 -> 709 bytes JPAINT/jpaint/FontChooser$6.class | Bin 0 -> 980 bytes JPAINT/jpaint/FontChooser.class | Bin 0 -> 5257 bytes JPAINT/jpaint/FontChooser.java | 587 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/HelpDialog.class | Bin 0 -> 930 bytes JPAINT/jpaint/HelpDialog.java | 36 ++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/HelpDialog.java~ | 36 ++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/Images/0.gif | Bin 0 -> 339 bytes JPAINT/jpaint/Images/1.gif | Bin 0 -> 252 bytes JPAINT/jpaint/Images/10.gif | Bin 0 -> 176 bytes JPAINT/jpaint/Images/11.gif | Bin 0 -> 188 bytes JPAINT/jpaint/Images/12.gif | Bin 0 -> 207 bytes JPAINT/jpaint/Images/13.gif | Bin 0 -> 181 bytes JPAINT/jpaint/Images/14.gif | Bin 0 -> 214 bytes JPAINT/jpaint/Images/15.gif | Bin 0 -> 181 bytes JPAINT/jpaint/Images/2.gif | Bin 0 -> 246 bytes JPAINT/jpaint/Images/3.gif | Bin 0 -> 414 bytes JPAINT/jpaint/Images/4.gif | Bin 0 -> 250 bytes JPAINT/jpaint/Images/5.gif | Bin 0 -> 182 bytes JPAINT/jpaint/Images/6.gif | Bin 0 -> 197 bytes JPAINT/jpaint/Images/7.gif | Bin 0 -> 291 bytes JPAINT/jpaint/Images/8.gif | Bin 0 -> 198 bytes JPAINT/jpaint/Images/9.gif | Bin 0 -> 202 bytes JPAINT/jpaint/Images/JPaintSplash.jpg | Bin 0 -> 37750 bytes JPAINT/jpaint/Images/box.gif | Bin 0 -> 91 bytes JPAINT/jpaint/Images/boxPressed.gif | Bin 0 -> 681 bytes JPAINT/jpaint/Images/fill.gif | Bin 0 -> 87 bytes JPAINT/jpaint/Images/fillPressed.gif | Bin 0 -> 1435 bytes JPAINT/jpaint/Images/line.gif | Bin 0 -> 76 bytes JPAINT/jpaint/Images/linePressed.gif | Bin 0 -> 445 bytes JPAINT/jpaint/Images/normal.gif | Bin 0 -> 89 bytes JPAINT/jpaint/Images/normalPressed.gif | Bin 0 -> 1448 bytes JPAINT/jpaint/Images/outline.gif | Bin 0 -> 110 bytes JPAINT/jpaint/Images/outlinePressed.gif | Bin 0 -> 1403 bytes JPAINT/jpaint/Images/oval.gif | Bin 0 -> 95 bytes JPAINT/jpaint/Images/ovalPressed.gif | Bin 0 -> 686 bytes JPAINT/jpaint/ItemChooser$1.class | Bin 0 -> 786 bytes JPAINT/jpaint/ItemChooser$2.class | Bin 0 -> 770 bytes JPAINT/jpaint/ItemChooser$3.class | Bin 0 -> 1033 bytes JPAINT/jpaint/ItemChooser$Demo$1.class | Bin 0 -> 643 bytes JPAINT/jpaint/ItemChooser$Demo$2.class | Bin 0 -> 1255 bytes JPAINT/jpaint/ItemChooser$Demo$3.class | Bin 0 -> 1432 bytes JPAINT/jpaint/ItemChooser$Demo.class | Bin 0 -> 2065 bytes JPAINT/jpaint/ItemChooser$Event.class | Bin 0 -> 868 bytes JPAINT/jpaint/ItemChooser$Listener.class | Bin 0 -> 287 bytes JPAINT/jpaint/ItemChooser.class | Bin 0 -> 4873 bytes JPAINT/jpaint/JPaintFileChooser.class | Bin 0 -> 899 bytes JPAINT/jpaint/JPaintFileChooser.java | 37 +++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/JPaintFileChooser.java~ | 38 ++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/JPaintLayoutManager.class | Bin 0 -> 1758 bytes JPAINT/jpaint/JPaintLayoutManager.java | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/Main.class | Bin 0 -> 653 bytes JPAINT/jpaint/Main.java | 22 ++++++++++++++++++++++ JPAINT/jpaint/Main.java~ | 22 ++++++++++++++++++++++ JPAINT/jpaint/MainMenu.class | Bin 0 -> 3834 bytes JPAINT/jpaint/MainMenu.java | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/MainMenu.java~ | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/Makefile | 18 ++++++++++++++++++ JPAINT/jpaint/README.mdown | 10 ++++++++++ JPAINT/jpaint/RandomPoint.class | Bin 0 -> 1141 bytes JPAINT/jpaint/RandomPoint.java | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/SplashScreen.class | Bin 0 -> 1897 bytes JPAINT/jpaint/SplashScreen.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/SplashScreen.java~ | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/SubToolBox$FillListener.class | Bin 0 -> 790 bytes JPAINT/jpaint/SubToolBox$JRandom.class | Bin 0 -> 730 bytes JPAINT/jpaint/SubToolBox$JSprayListener.class | Bin 0 -> 788 bytes JPAINT/jpaint/SubToolBox$JTextListener.class | Bin 0 -> 743 bytes JPAINT/jpaint/SubToolBox$LineListener.class | Bin 0 -> 791 bytes JPAINT/jpaint/SubToolBox$NormalListener.class | Bin 0 -> 794 bytes JPAINT/jpaint/SubToolBox$OutlineListener.class | Bin 0 -> 796 bytes JPAINT/jpaint/SubToolBox$OvalListener.class | Bin 0 -> 790 bytes JPAINT/jpaint/SubToolBox$RectListener.class | Bin 0 -> 790 bytes JPAINT/jpaint/SubToolBox.class | Bin 0 -> 3824 bytes JPAINT/jpaint/SubToolBox.java | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/TabbedPanel.class | Bin 0 -> 796 bytes JPAINT/jpaint/TabbedPanel.java | 38 ++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/TextDialog.class | Bin 0 -> 2640 bytes JPAINT/jpaint/TextDialog.java | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ToolBar.class | Bin 0 -> 402 bytes JPAINT/jpaint/ToolBar.java | 16 ++++++++++++++++ JPAINT/jpaint/ToolBox.class | Bin 0 -> 1920 bytes JPAINT/jpaint/ToolBox.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ToolBox.java~ | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ JPAINT/jpaint/ToolIcon.class | Bin 0 -> 1181 bytes JPAINT/jpaint/ToolIcon.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ WiimoteWhiteboard/.WiimoteWhiteboard.sh.swp | Bin 0 -> 12288 bytes 110 files changed, 5569 insertions(+), 0 deletions(-) create mode 100755 JPAINT/Jpaint.sh create mode 100644 JPAINT/jpaint/.gitignore create mode 100644 JPAINT/jpaint/ColorBox$AdvancedListener.class create mode 100644 JPAINT/jpaint/ColorBox.class create mode 100644 JPAINT/jpaint/ColorBox.java create mode 100644 JPAINT/jpaint/ColorBox.java~ create mode 100644 JPAINT/jpaint/ColorLabel.class create mode 100644 JPAINT/jpaint/ColorLabel.java create mode 100644 JPAINT/jpaint/ColorPanel.class create mode 100644 JPAINT/jpaint/ColorPanel.java create mode 100644 JPAINT/jpaint/ControlClass.class create mode 100644 JPAINT/jpaint/ControlClass.java create mode 100644 JPAINT/jpaint/ControlClass.java~ create mode 100644 JPAINT/jpaint/DrawingCanvas.class create mode 100644 JPAINT/jpaint/DrawingCanvas.java create mode 100644 JPAINT/jpaint/DrawingCanvas.java~ create mode 100644 JPAINT/jpaint/ExampleFileFilter.class create mode 100644 JPAINT/jpaint/ExampleFileFilter.java create mode 100644 JPAINT/jpaint/ExampleFileFilter.java~ create mode 100644 JPAINT/jpaint/FontChooser$1.class create mode 100644 JPAINT/jpaint/FontChooser$2.class create mode 100644 JPAINT/jpaint/FontChooser$3.class create mode 100644 JPAINT/jpaint/FontChooser$4.class create mode 100644 JPAINT/jpaint/FontChooser$5.class create mode 100644 JPAINT/jpaint/FontChooser$6.class create mode 100644 JPAINT/jpaint/FontChooser.class create mode 100644 JPAINT/jpaint/FontChooser.java create mode 100644 JPAINT/jpaint/HelpDialog.class create mode 100644 JPAINT/jpaint/HelpDialog.java create mode 100644 JPAINT/jpaint/HelpDialog.java~ create mode 100644 JPAINT/jpaint/Images/0.gif create mode 100644 JPAINT/jpaint/Images/1.gif create mode 100644 JPAINT/jpaint/Images/10.gif create mode 100644 JPAINT/jpaint/Images/11.gif create mode 100644 JPAINT/jpaint/Images/12.gif create mode 100644 JPAINT/jpaint/Images/13.gif create mode 100644 JPAINT/jpaint/Images/14.gif create mode 100644 JPAINT/jpaint/Images/15.gif create mode 100644 JPAINT/jpaint/Images/2.gif create mode 100644 JPAINT/jpaint/Images/3.gif create mode 100644 JPAINT/jpaint/Images/4.gif create mode 100644 JPAINT/jpaint/Images/5.gif create mode 100644 JPAINT/jpaint/Images/6.gif create mode 100644 JPAINT/jpaint/Images/7.gif create mode 100644 JPAINT/jpaint/Images/8.gif create mode 100644 JPAINT/jpaint/Images/9.gif create mode 100644 JPAINT/jpaint/Images/JPaintSplash.jpg create mode 100644 JPAINT/jpaint/Images/box.gif create mode 100644 JPAINT/jpaint/Images/boxPressed.gif create mode 100644 JPAINT/jpaint/Images/fill.gif create mode 100644 JPAINT/jpaint/Images/fillPressed.gif create mode 100644 JPAINT/jpaint/Images/line.gif create mode 100644 JPAINT/jpaint/Images/linePressed.gif create mode 100644 JPAINT/jpaint/Images/normal.gif create mode 100644 JPAINT/jpaint/Images/normalPressed.gif create mode 100644 JPAINT/jpaint/Images/outline.gif create mode 100644 JPAINT/jpaint/Images/outlinePressed.gif create mode 100644 JPAINT/jpaint/Images/oval.gif create mode 100644 JPAINT/jpaint/Images/ovalPressed.gif create mode 100644 JPAINT/jpaint/ItemChooser$1.class create mode 100644 JPAINT/jpaint/ItemChooser$2.class create mode 100644 JPAINT/jpaint/ItemChooser$3.class create mode 100644 JPAINT/jpaint/ItemChooser$Demo$1.class create mode 100644 JPAINT/jpaint/ItemChooser$Demo$2.class create mode 100644 JPAINT/jpaint/ItemChooser$Demo$3.class create mode 100644 JPAINT/jpaint/ItemChooser$Demo.class create mode 100644 JPAINT/jpaint/ItemChooser$Event.class create mode 100644 JPAINT/jpaint/ItemChooser$Listener.class create mode 100644 JPAINT/jpaint/ItemChooser.class create mode 100644 JPAINT/jpaint/JPaintFileChooser.class create mode 100644 JPAINT/jpaint/JPaintFileChooser.java create mode 100644 JPAINT/jpaint/JPaintFileChooser.java~ create mode 100644 JPAINT/jpaint/JPaintLayoutManager.class create mode 100644 JPAINT/jpaint/JPaintLayoutManager.java create mode 100644 JPAINT/jpaint/Main.class create mode 100644 JPAINT/jpaint/Main.java create mode 100644 JPAINT/jpaint/Main.java~ create mode 100644 JPAINT/jpaint/MainMenu.class create mode 100644 JPAINT/jpaint/MainMenu.java create mode 100644 JPAINT/jpaint/MainMenu.java~ create mode 100644 JPAINT/jpaint/Makefile create mode 100644 JPAINT/jpaint/README.mdown create mode 100644 JPAINT/jpaint/RandomPoint.class create mode 100644 JPAINT/jpaint/RandomPoint.java create mode 100644 JPAINT/jpaint/SplashScreen.class create mode 100644 JPAINT/jpaint/SplashScreen.java create mode 100644 JPAINT/jpaint/SplashScreen.java~ create mode 100644 JPAINT/jpaint/SubToolBox$FillListener.class create mode 100644 JPAINT/jpaint/SubToolBox$JRandom.class create mode 100644 JPAINT/jpaint/SubToolBox$JSprayListener.class create mode 100644 JPAINT/jpaint/SubToolBox$JTextListener.class create mode 100644 JPAINT/jpaint/SubToolBox$LineListener.class create mode 100644 JPAINT/jpaint/SubToolBox$NormalListener.class create mode 100644 JPAINT/jpaint/SubToolBox$OutlineListener.class create mode 100644 JPAINT/jpaint/SubToolBox$OvalListener.class create mode 100644 JPAINT/jpaint/SubToolBox$RectListener.class create mode 100644 JPAINT/jpaint/SubToolBox.class create mode 100644 JPAINT/jpaint/SubToolBox.java create mode 100644 JPAINT/jpaint/TabbedPanel.class create mode 100644 JPAINT/jpaint/TabbedPanel.java create mode 100644 JPAINT/jpaint/TextDialog.class create mode 100644 JPAINT/jpaint/TextDialog.java create mode 100644 JPAINT/jpaint/ToolBar.class create mode 100644 JPAINT/jpaint/ToolBar.java create mode 100644 JPAINT/jpaint/ToolBox.class create mode 100644 JPAINT/jpaint/ToolBox.java create mode 100644 JPAINT/jpaint/ToolBox.java~ create mode 100644 JPAINT/jpaint/ToolIcon.class create mode 100644 JPAINT/jpaint/ToolIcon.java create mode 100644 WiimoteWhiteboard/.WiimoteWhiteboard.sh.swp diff --git a/JPAINT/Jpaint.sh b/JPAINT/Jpaint.sh new file mode 100755 index 0000000..56d8c00 --- /dev/null +++ b/JPAINT/Jpaint.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cd jpaint-master +java Main diff --git a/JPAINT/jpaint/.gitignore b/JPAINT/jpaint/.gitignore new file mode 100644 index 0000000..31c1c9f --- /dev/null +++ b/JPAINT/jpaint/.gitignore @@ -0,0 +1,3 @@ +*.swp +*.swo +.DS_Store diff --git a/JPAINT/jpaint/ColorBox$AdvancedListener.class b/JPAINT/jpaint/ColorBox$AdvancedListener.class new file mode 100644 index 0000000..82d3621 Binary files /dev/null and b/JPAINT/jpaint/ColorBox$AdvancedListener.class differ diff --git a/JPAINT/jpaint/ColorBox.class b/JPAINT/jpaint/ColorBox.class new file mode 100644 index 0000000..ee746c6 Binary files /dev/null and b/JPAINT/jpaint/ColorBox.class differ diff --git a/JPAINT/jpaint/ColorBox.java b/JPAINT/jpaint/ColorBox.java new file mode 100644 index 0000000..0874bcc --- /dev/null +++ b/JPAINT/jpaint/ColorBox.java @@ -0,0 +1,112 @@ +import java.awt.Label; +import java.awt.Color; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JPanel; +import javax.swing.JButton; + +/** + * The ColorBox class is a color pallette. It stores the color the user clicked + * with the right and left mouse button. It also contains a set of preset colors + * which can be changed with the advanced feature. + **/ +public class ColorBox extends JPanel +{ + public static Label foreGround, backGround; + public static int selectedSwatchX, selectedSwatchY; + public static ColorLabel[][] colorPal; + private JButton clrPnlBtn; + private ColorPanel clrPnl; + + /** Creates a default ColorBox. **/ + public ColorBox() + { + // sets the layout to null and sets a size to the color box + setLayout(null); + setSize(350,120); + // instantiates the Mouse Left and Mouse Right color labels + setForeBack(); + + // instantiates the Color Panel + clrPnl = new ColorPanel(); + + // instantiates a button that calls for advanced settings, sets the size + // and the x,y coordinates and adds it to screen + clrPnlBtn = new JButton("Advanced"); + clrPnlBtn.setBounds(100,65,100,20); + add(clrPnlBtn); + clrPnlBtn.addActionListener(new AdvancedListener()); + + // instantiates the color label and it finds its corresponding color + // depending on its x and y coordinates + colorPal = new ColorLabel[2][14]; + for(int i=0;i1) + { + tabbedCanvasHolder.remove(currentFile); + tabbedCanvasHolder.setSelectedIndex(0); + numFiles--; + } + } + + /** Handles a componentMoved event **/ + public void componentMoved(ComponentEvent e) + { + Point p = getLocation(); + xCoord = (int)p.getX() + tBar.getWidth() + 6; + yCoord = (int)p.getY() + extraY; + } + + /** Handles a componentHidden event **/ + public void componentHidden(ComponentEvent e){} + /** Handles a componentResized event **/ + public void componentResized(ComponentEvent e){} + /** Handles a componentShown event **/ + public void componentShown(ComponentEvent e){} +} \ No newline at end of file diff --git a/JPAINT/jpaint/ControlClass.java~ b/JPAINT/jpaint/ControlClass.java~ new file mode 100644 index 0000000..acfd4af --- /dev/null +++ b/JPAINT/jpaint/ControlClass.java~ @@ -0,0 +1,401 @@ +import javax.swing.JFrame; +import javax.swing.JTabbedPane; +import javax.swing.JPanel; +import javax.swing.JMenuItem; +import javax.swing.JFileChooser; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Color; +import java.awt.Point; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.event.ComponentListener; +import java.awt.event.ComponentEvent; +import java.util.ArrayList; +import java.awt.Robot; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.AWTException; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; +import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; +import java.awt.print.PageFormat; + +/** + * This is the control class where everything comes together. The menubar, + * tabbed pane, the color box and the color pallettes are all created here. + * Special fields are kept here to keep track of whats going on. + **/ +public class ControlClass extends JFrame implements ActionListener, ComponentListener +{ + public static int fileCount, currentFile, xCoord, yCoord, extraY, numFiles; + public static SubToolBox sBox; + public static ArrayList canvas; + private GridBagLayout layout; + private GridBagConstraints c; + private File file; + private ColorPanel colorPanel; + private ColorBox pallette; + private JPaintLayoutManager layoutManager; + private JPaintFileChooser fileChooser; + private MainMenu mainMenu; + private TabbedPanel tabbedCanvasHolder; + private ToolBar tBar; + + /** + * Default ControlClass constructor. + * Calls run(), which initializes all necessay objects in the ControlClass + **/ + public ControlClass() + { + setExtendedState(JFrame.MAXIMIZED_BOTH); + run(); + } + + /** + * Calls initAll(), and creates a new BufferedStrategy for the DrawingCanvas + * with two buffers. + **/ + public void run() + { + initAll(); + ((DrawingCanvas)canvas.get(0)).createBufferStrategy(2); + extraY = 71; + ((DrawingCanvas)canvas.get(0)).checkScreenSize(); + setXY(); + } + + /** + * Instantiates JPaints custom layout manager. + * Places the toolBox on the left side of the window + * and strecthes it vertically. + * Places the colorPallete at the bottom of the window and + * stretches it horizontally. + * Places the subToolBox inside the toolBox near the top. + * Places the tabbedCanvasHolder in all the space left over + * and places the DrawingCanvas inside the tabbedCanvasHolder, filling + * all avaialbe space + **/ + public void initLayout() + { + layoutManager = new JPaintLayoutManager(); + layoutManager.setComponent(sBox, 0,1, 1, 0, 100, 0, 0,0, GridBagConstraints.VERTICAL); + getContentPane().add(sBox); + layoutManager.setComponent(tBar, 0,0, 1,0, 100,0, 0,0, GridBagConstraints.VERTICAL); + layoutManager.setAnchor(GridBagConstraints.LINE_START); + getContentPane().add(tBar); + layoutManager.setComponent(tabbedCanvasHolder, 1 ,0, GridBagConstraints.REMAINDER,GridBagConstraints.RELATIVE, 800,600, 1, 1, GridBagConstraints.HORIZONTAL); + getContentPane().add(tabbedCanvasHolder); + layoutManager.setComponent(pallette, 1, 1, GridBagConstraints.REMAINDER,1, 350, 100, 0,0, GridBagConstraints.HORIZONTAL); + layoutManager.setAnchor(GridBagConstraints.LAST_LINE_START); + getContentPane().add(pallette); + } + + /** Instantiates the fileChooser **/ + public void initFileChooser() + { + fileChooser = new JPaintFileChooser(this); + } + + /** Instantiates the tool bar **/ + public void initToolBar() + { + tBar = new ToolBar(); + tBar.setSize(200, 200); + tBar.setBackground(Color.WHITE); + } + + /** Instantiates the subToolBox **/ + public void initSubToolBox() + { + sBox = new SubToolBox(); + sBox.setBackground(Color.WHITE); + } + + /** Instantiates the layoutManager **/ + public void initLayoutManager() + { + layout = new GridBagLayout(); + c = new GridBagConstraints(); + + getContentPane().setLayout(layout); + getContentPane().add(tabbedCanvasHolder); + } + + /** + * Instantiates the tabbedCanvasHolder with one tab. + * Tabs are positioned at the Top. Calls initFirstCanvas(). Then adds + * the canvas to the tabbedCanvasHolder + **/ + public void initTabbedCanvasHolder() + { + initFirstCanvas(); + + // instantiate the canvasHolder and add the initial canvas to it + tabbedCanvasHolder = new TabbedPanel(JTabbedPane.TOP); + tabbedCanvasHolder.add((DrawingCanvas)canvas.get(0)); + } + + /** + * Instantiates the DrawingCanvas. + * Sets its name to "untitled"+ fileCount, a static int which is also + * incremented by one in this method. + **/ + public void initFirstCanvas() + { + canvas = new ArrayList(); + DrawingCanvas tempCanvas = new DrawingCanvas(); + tempCanvas.setName("untitled-"+fileCount); + tempCanvas.setBackground(Color.WHITE); + canvas.add(tempCanvas); + fileCount++; + numFiles++; + } + + /** Instantiates the colorBox **/ + public void initPallette() + { + pallette = new ColorBox(); + } + + /** Instantiates the colorPanel **/ + public void initColorPanel() + { + colorPanel = new ColorPanel(); + } + + /** Instantiates the MainMenu, which is JPaints menu bar. **/ + public void initMenuBar() + { + mainMenu = new MainMenu(); + mainMenu.addActionListener(this); + setJMenuBar(mainMenu); + } + + /** + * Initializes the frame by setting its title, size, location, listeners, + * and other default attributes. + **/ + public void initFrame() + { + setTitle(".: JPaint :."); + getContentPane().setLayout(layoutManager); + setDefaultCloseOperation(EXIT_ON_CLOSE); + setSize(300, 600); + setLocation(0,0); + addComponentListener(this); + setVisible(true); + setXY(); + } + + /** + * This code checks sets the X and Y coords of where the drawing canvas + * begins. + **/ + public void setXY() + { + xCoord = tBar.getWidth() + 6; + yCoord = extraY; + } + + /** Calls all instantiating methods thereby instantiating all objects. **/ + public void initAll() + { + initTabbedCanvasHolder(); + initToolBar(); + initSubToolBox(); + initColorPanel(); + initPallette(); + initLayout(); + initFileChooser(); + initMenuBar(); + initFrame(); + } + + /** + * Reveals the fileOpen dialog. + * Retrieves the pathname of the selected file and calls openOperation(path) + * to display the image to th current canvas. + **/ + public void showFileOpen() + { + int returnVal = fileChooser.showOpenDialog(this); + if(returnVal == JFileChooser.APPROVE_OPTION) + { + String path = fileChooser.getSelectedFile().getPath(); + ((DrawingCanvas)canvas.get(currentFile)).openOperation(path); + } + } + + /** Allows user to print the image on the screen through any available printer. **/ + public void printImage() + { + ((DrawingCanvas)canvas.get(currentFile)).saveImageForPrinting(); + PrinterJob printJob = PrinterJob.getPrinterJob(); + PageFormat pf = printJob.pageDialog(printJob.defaultPage()); + printJob.setPrintable(((DrawingCanvas)canvas.get(currentFile))); + if(printJob.printDialog()) + try{printJob.print();}catch(PrinterException pe){ pe.printStackTrace();} + } + + /** + * Saves the image on the current canvas to a user specified path with + * the .png extension if the image has not previously been saved. + * Otherwise, updates the current file. + **/ + public void saveImage() + { + try + { + DrawingCanvas dc = ((DrawingCanvas)canvas.get(currentFile)); + BufferedImage screenCapture = new Robot().createScreenCapture( + new Rectangle(xCoord,yCoord,dc.getWidth(),dc.getHeight())); + + String title = tabbedCanvasHolder.getTitleAt(currentFile); + if(title.indexOf("untitled-") != -1) + saveImageAs(); + else + try{ + ImageIO.write(screenCapture, "png", file); + }catch(IOException ioe){} + }catch(AWTException awte){} + } + + /** + * Saves the image on the current canvas to a user specified path with + * the .png extension + **/ + public void saveImageAs() + { + try{ + DrawingCanvas dc = ((DrawingCanvas)canvas.get(currentFile)); + BufferedImage screenCapture = new Robot().createScreenCapture( + new Rectangle(xCoord,yCoord,dc.getWidth(),dc.getHeight())); + + int returnVal = fileChooser.showSaveDialog(this); + if(returnVal == JFileChooser.APPROVE_OPTION) + { + String path = fileChooser.getSelectedFile().getPath(); + if(path.indexOf(".png") == -1) + path+=".png"; + try + { + file = new File(path); + tabbedCanvasHolder.setTitleAt(currentFile,fileChooser.getName(file)); + ImageIO.write(screenCapture, "png", file); + }catch(IOException ioe){} + } + }catch(AWTException awte){} + } + + /** Clears the current canvas of any images **/ + public void clearImage() + { + ((DrawingCanvas)canvas.get(currentFile)).clearImage(); + } + + /** Allows the user to set the visible state of the tool box. **/ + public void viewToolBoxEvent() + { + tBar.setVisible(!tBar.isVisible()); + } + + /** Allows the user to set the visible state **/ + public void viewColorBoxEvent() + { + pallette.setVisible(!pallette.isVisible()); + } + + /** Displays the help dialog. **/ + public void helpAboutEvent() + { + HelpDialog help = new HelpDialog(); + } + + /** Exits JPaint. **/ + public void fileExitEvent() + { + System.exit(0); + } + + /** + * Creates a new DrawingCanvas and names it "untitled" + fileCount, a + * static variable which is incremented in this method. + **/ + public void fileNewEvent() + { + DrawingCanvas nextCanvas = new DrawingCanvas(); + nextCanvas.setBackground(Color.BLACK); + nextCanvas.setName("untitled-"+fileCount); + tabbedCanvasHolder.add(nextCanvas); + canvas.add(nextCanvas); + nextCanvas.createBufferStrategy(2); + fileCount++; + numFiles++; + } + + /** Handles all MenuBar events. **/ + public void actionPerformed(ActionEvent e) + { + JMenuItem hit = (JMenuItem)e.getSource(); + if(hit.equals(mainMenu.getJMenuItem("fileNew"))) + fileNewEvent(); + else if(hit.equals(mainMenu.getJMenuItem("fileExit"))) + fileExitEvent(); + else if(hit.equals(mainMenu.getJMenuItem("helpAbout"))) + helpAboutEvent(); + else if(hit.equals(mainMenu.getJMenuItem("viewColorBox"))) + viewColorBoxEvent(); + else if(hit.equals(mainMenu.getJMenuItem("viewToolBox"))) + viewToolBoxEvent(); + else if(hit.equals(mainMenu.getJMenuItem("fileOpen"))) + showFileOpen(); + else if(hit.equals(mainMenu.getJMenuItem("fileSave"))) + saveImage(); + else if(hit.equals(mainMenu.getJMenuItem("fileSaveAs"))) + saveImageAs(); + else if(hit.equals(mainMenu.getJMenuItem("fileClose"))) + closeProject(); + else if(hit.equals(mainMenu.getJMenuItem("filePrint"))) + printImage(); + else if(hit.equals(mainMenu.getJMenuItem("imageClear"))) + clearImage(); + else if(hit.equals(mainMenu.getJMenuItem("imageRotate"))) + ((DrawingCanvas)canvas.get(currentFile)).rotateOperation(); + else if(hit.equals(mainMenu.getJMenuItem("editCut"))) + ((DrawingCanvas)canvas.get(currentFile)).cutOperation(); + else if(hit.equals(mainMenu.getJMenuItem("editPaste"))) + ((DrawingCanvas)canvas.get(currentFile)).pasteOperation(); + else if(hit.equals(mainMenu.getJMenuItem("editCopy"))) + ((DrawingCanvas)canvas.get(currentFile)).copyOperation(); + } + + /** Closes an open project. **/ + public void closeProject() + { + if(numFiles>1) + { + tabbedCanvasHolder.remove(currentFile); + tabbedCanvasHolder.setSelectedIndex(0); + numFiles--; + } + } + + /** Handles a componentMoved event **/ + public void componentMoved(ComponentEvent e) + { + Point p = getLocation(); + xCoord = (int)p.getX() + tBar.getWidth() + 6; + yCoord = (int)p.getY() + extraY; + } + + /** Handles a componentHidden event **/ + public void componentHidden(ComponentEvent e){} + /** Handles a componentResized event **/ + public void componentResized(ComponentEvent e){} + /** Handles a componentShown event **/ + public void componentShown(ComponentEvent e){} +} \ No newline at end of file diff --git a/JPAINT/jpaint/DrawingCanvas.class b/JPAINT/jpaint/DrawingCanvas.class new file mode 100644 index 0000000..1b83c67 Binary files /dev/null and b/JPAINT/jpaint/DrawingCanvas.class differ diff --git a/JPAINT/jpaint/DrawingCanvas.java b/JPAINT/jpaint/DrawingCanvas.java new file mode 100644 index 0000000..f50b219 --- /dev/null +++ b/JPAINT/jpaint/DrawingCanvas.java @@ -0,0 +1,994 @@ +import java.awt.Color; +import java.awt.Canvas; +import java.awt.Graphics; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseEvent; +import java.io.File; +import java.awt.Image; +import javax.swing.ImageIcon; +import java.awt.Cursor; +import java.awt.Robot; +import java.awt.AWTException; +import java.awt.image.BufferedImage; +import java.awt.print.Printable; +import java.awt.print.PageFormat; +import java.awt.print.PrinterException; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.AWTException; +import java.awt.Font; +import java.awt.image.PixelGrabber; +import java.awt.image.MemoryImageSource; +import java.awt.geom.CubicCurve2D; +import java.awt.geom.CubicCurve2D.Float; +import java.awt.geom.Point2D; +import java.awt.event.FocusListener; +import java.awt.event.FocusEvent; +import java.awt.geom.AffineTransform; + +public class DrawingCanvas extends Canvas implements MouseListener, +MouseMotionListener, Printable, FocusListener +{ + public static final int FILL = 1, NORMAL = 2, OUTLINE = 3, RECT = 4, OVAL = 5, LINE = 6; + public static BufferedImage selectImage; + public static int extraOperations, lineWidth, radius, amtLines; + private Color drawColor, oppositeColor; + private BufferedImage printImage, resizeImage; + private CubicCurve2D c; + private Point2D p1, p2, p3, p4; + private boolean polyStart, arcStart, curveMade, curveMade2, save, dragSave; + private int mouseX, mouseY, prevX, prevY, originX, originY, width, height; + private int[] pixels; + + /** Creates a default DrawingCanvas. **/ + public DrawingCanvas() + { + // save is set to true unless the focus is lost + save = true; + // sets the default linewidth and the spray radius + lineWidth = 1; + radius = 5; + amtLines = 10; + // adds listeners and sets settings + setSize(400,400); + setBackground(Color.WHITE); + this.addMouseListener(this); + this.addMouseMotionListener(this); + this.addFocusListener(this); + } + + /** + * This methods adjusts the screen size of the user by taking a snapshot of + * the canvas and seeing if it shifts up or down and sets the pixels + * accordingly. + **/ + public void checkScreenSize() + { + saveFromResize(); + pixels = new int[getWidth()*getHeight()]; + PixelGrabber pg = new PixelGrabber(resizeImage, 0, 0, getWidth(), getHeight(), pixels, 0, getWidth()); + + try { + pg.grabPixels(); + } catch (InterruptedException ie) {} + + + if(pixels[0] != (Color.WHITE).getRGB()) + ControlClass.extraY = 78; + else + ControlClass.extraY = 71; + } + + /** Saves an image of the current screen so if the canvas resizes the image doesnt get deleted. **/ + public void saveFromResize() + { + try{ + resizeImage = new Robot().createScreenCapture( + new Rectangle(ControlClass.xCoord,ControlClass.yCoord,getWidth(),getHeight())); + }catch(AWTException awte){} + } + + /** Draws the image back to the screen after the canvas is resized **/ + public void pasteFromResize() + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.drawImage(resizeImage,0,0,null); + repaint(); + } + + /** Fills anything of the same color the first pixel selected. **/ + public void fillOperation(MouseEvent e) + { + // saves the image and then creates a pixel array + saveImageForPrinting(); + pixels = new int[getWidth()*getHeight()]; + + // grabs all the pixels from the image + PixelGrabber pg = new PixelGrabber(printImage, 0, 0, getWidth(), getHeight(), pixels, 0, getWidth()); + try { + pg.grabPixels(); + } catch (InterruptedException ie) {} + + // calls the start fill method, rgb is the color clicked on + int rgb = pixels[e.getY()*getWidth()+e.getX()]; + startFill(e.getX(),e.getY(),rgb); + + // creates an image from the pixel array and draws it back to the screen + Image img = createImage(new MemoryImageSource(getWidth(), getHeight(), pixels, 0, getWidth())); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.drawImage(img,0,0,null); + repaint(); + saveFromResize(); + } + + /** Changes the color of the pixel at the x and y coordinate. **/ + private void changePixel(int x, int y, int rgb) + { + pixels[y*getWidth()+x] = rgb; + } + + /** Gets the pixel at the x and y point **/ + private int getPixel(int x, int y) + { + return pixels[y*getWidth()+x]; + } + + /** Helper method for fillOperation. This method does the actually filling. **/ + public void startFill(int x, int y, int original) + { + int i = y*getWidth()+x; + if(pixels[i] != original) + return; + + // sets the pixel quete to the whole canvas + int pixelQueue[] = new int[getWidth() * getHeight()]; + int pixelQueueSize = 0; + + // sets the first pixel + pixelQueue[0] = (y << 16) + x; + pixelQueueSize = 1; + + changePixel(x,y,original); + + // loop to check and does a flood fill to the original color + while (pixelQueueSize > 0) + { + x = pixelQueue[0] & 0xffff; + y = (pixelQueue[0] >> 16) & 0xffff; + pixelQueueSize--; + pixelQueue[0] = pixelQueue[pixelQueueSize]; + + if (x > 0) + { + if (getPixel(x-1, y) == original) + { + changePixel(x-1, y, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = (y << 16) + x-1; + pixelQueueSize++; + } + } + + if (y > 0) + { + if (getPixel(x, y-1) == original) + { + changePixel(x, y-1, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = ((y-1) << 16) + x; + pixelQueueSize++; + } + } + if (x < getWidth()-1) + { + if (getPixel(x+1, y) == original) + { + changePixel(x+1, y, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = (y << 16) + x+1; + pixelQueueSize++; + } + } + if (y < getHeight()-1) + { + if (getPixel(x, y+1) == original) + { + changePixel(x, y+1, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = ((y+1) << 16) + x; + pixelQueueSize++; + } + } + } + } + + /** Helper method for the rotation. Sets the amount of rotation 90 degrees. **/ + private AffineTransform setRotation() + { + AffineTransform atright = AffineTransform.getRotateInstance(Math.PI / 2, getWidth() / 2, getHeight() / 2); + return atright; + } + + /** This method actually rotates the image 90 degrees. **/ + public void rotateOperation() + { + // saves the image and then clears it and draws it rotated 90 degrees. + Graphics g = getBufferStrategy().getDrawGraphics(); + Graphics2D g2 = (Graphics2D) g; + saveFromResize(); + clearImage(); + g2.drawImage(resizeImage, setRotation(), this); + repaint(); + } + + /** Saves the image so that it can be printed. **/ + public void saveImageForPrinting() + { + // saves the image of the screen + try{ + printImage = new Robot().createScreenCapture( + new Rectangle(ControlClass.xCoord,ControlClass.yCoord,getWidth(),getHeight())); + }catch(AWTException awte){} + } + + /** This is a helper method for print. Draws the image to be printed. **/ + public void drawImage(Graphics2D g2D) + { + // draws the print image out on paper + g2D.drawImage(printImage,0,0,null); + } + + /** Printing operation, it prints the image saved. **/ + public int print(Graphics g, PageFormat pf, int pIndex) throws PrinterException + { + if (pIndex > 0) + return Printable.NO_SUCH_PAGE; + + Graphics2D g2D = (Graphics2D)g; + drawImage(g2D); + return Printable.PAGE_EXISTS; + } + + /** Updates the screen and flips the buffers around. **/ + public void update(Graphics g) + { + getBufferStrategy().show(); + } + + /** Paints the image onto the screen. **/ + public void paint(Graphics g) + { + try{update(g);}catch(NullPointerException e){} + } + + /** Opens a selected image and draws it onto the screen. **/ + public void openOperation(String path) + { + // creates an image and draws it to the screen + Graphics g = getBufferStrategy().getDrawGraphics(); + ImageIcon ic = new ImageIcon(path); + g.drawImage((Image)ic.getImage(),0,0,null); + } + + /** Selects the image from the top left corner to the bottom right corner. **/ + public void selectOperation(MouseEvent e) + { + if(mouseHasMoved(e)) + { + // this checks if you select off screen, if your off screen then it will + // set the boundaries to the edge of the drawing canvas + int tOriginX = ControlClass.xCoord+e.getX(); + int tOriginY = ControlClass.yCoord+e.getY(); + + if(tOriginX > getWidth()+ControlClass.xCoord) + tOriginX = getWidth()+ControlClass.xCoord; + if(tOriginX < ControlClass.xCoord) + tOriginX = ControlClass.xCoord; + if(tOriginY > getHeight()+ControlClass.yCoord) + tOriginY = getHeight()+ControlClass.yCoord; + if(tOriginY < ControlClass.yCoord) + tOriginY = ControlClass.yCoord; + + // calculates the width and height of the area + width = tOriginX-(ControlClass.xCoord+originX); + height = tOriginY-(ControlClass.yCoord+originY); + + if(width < 0 && height < 0) + { + originX+=width; + originY+=height; + } + else if(width < 0 && height > 0) + originX+=width; + else if(width > 0 && height < 0) + originY+=height; + + width = Math.abs(width); + height = Math.abs(height); + } + } + + /** Copies the selected image **/ + public void copyOperation() + { + // copies the boundaries set by the mouse + try{ + DrawingCanvas.selectImage = new Robot().createScreenCapture( + new Rectangle(ControlClass.xCoord+originX,ControlClass.yCoord+originY, + width,height)); + }catch(AWTException awte){} + } + /** Copies the selected image and deletes the selected portion **/ + public void cutOperation() + { + // copies the image and then draws a rectangle over the selected area + copyOperation(); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(oppositeColor); + g.fillRect(originX,originY,width,height); + width = height = 0; + repaint(); + } + + /** Draws the image with regards to the mouse location. **/ + public void pasteOperation() + { + // draws the image of the selected image onto the screen + Graphics g = getBufferStrategy().getDrawGraphics(); + g.drawImage(DrawingCanvas.selectImage,originX,originY,null); + repaint(); + } + + /** Draws random lines of random colors on the screen. **/ + public void randomDraw() + { + RandomPoint rPt = new RandomPoint(getWidth(),getHeight()); + Graphics g = getBufferStrategy().getDrawGraphics(); + int i=0; + while(i< amtLines) + { + g.setColor(rPt.getColor()); + g.drawLine((int)rPt.getX(),(int)rPt.getY(),rPt.nextX(),rPt.nextY()); + i++; + } + repaint(); + } + + /** Opens up a text dialog in the selected area. **/ + public void textOperation(MouseEvent e) + { + // opens up a text dialog + setCursor(new Cursor(Cursor.TEXT_CURSOR)); + TextDialog tDialog = new TextDialog(e.getX(),e.getY()); + } + + /** Prints the text onto the screen **/ + public void textOperation2(String txt, int x, int y, Font f) + { + // draws the text onto the screen + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setFont(f); + g.setColor(drawColor); + g.drawString(txt,x,y); + g.setFont(new Font("Times New Roman", Font.PLAIN, 12)); + repaint(); + } + + /** An eraser that erases when the mouse is dragged. **/ + public void eraserOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(ColorBox.backGround.getBackground()); + + if (mouseHasMoved(e)) + g.fillRect(e.getX(),e.getY(),15,15); + + repaint(); + } + + /** Paint brush with different brushes like a square and a circle. **/ + public void brushOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.HAND_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // depending on which brush is selected it will change the brush to that shape + if (mouseHasMoved(e)) + if(extraOperations == OVAL) + g.fillOval(e.getX(),e.getY(),radius,radius); + else if(extraOperations == RECT) + g.fillRect(e.getX(),e.getY(),radius,radius); + repaint(); + } + + /** Creates a pen when can be operated when mouse is dragged. **/ + public void penOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.HAND_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // draws lines while your mouse is dragged + if (mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + g.drawLine(prevX,prevY,mouseX,mouseY); + + prevX = mouseX; + prevY = mouseY; + } + repaint(); + } + + /** Calls the line operation first and then starts the polygon operation **/ + public void prePolyOperation(MouseEvent e) + { + if(!polyStart) + { + lineOperation(e); + polyStart = true; + } + polyOperation(e); + } + + /** Starts a polygon shape by drawing many line. **/ + public void polyOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // draws a line on the screen + if(mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + g.drawLine(prevX, prevY, mouseX, mouseY); + + prevX = mouseX; + prevY = mouseY; + } + + // sets the polygon operation to false if the line is back at the origin + if(isBeginning(e)) + polyStart = false; + + repaint(); + } + + /** Helper method for the polygon to check if the line drawn is back at the origin. **/ + public boolean isBeginning(MouseEvent e) + { + // returns true or false if the range is five away from the beginning + return (Math.abs(originX-e.getX()) <= 5 && Math.abs(originY-e.getY()) <= 5); + } + + /** Checks if the polygon operation is deselected and stops it. **/ + public void checkPolyOff() + { + // if the polygon operation is on and the polygon tool is not selected then + // finish the line if it wasnt completed and reset the polygon operation + if(polyStart && ToolBox.toolSelected != ToolBox.POLYGON) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + g.drawLine(prevX,prevY,originX,originY); + polyStart = false; + } + } + + /** Checks if the curve line tool is deselected. **/ + public void checkCurveOff() + { + // if the tool is deselected then reset variables to default + if(ToolBox.toolSelected != ToolBox.CURVELINE) + curveMade = curveMade2 = false; + } + + /** Starts the curve line tool. **/ + public void curveLineOperation(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + if(mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + Graphics2D g2 = (Graphics2D)g; + + // if the first and second point are not choosen then draw a straight line + if(!curveMade && !curveMade2) + { + c = new CubicCurve2D.Float(); + p1 = new Point2D.Float(); + p2 = new Point2D.Float(); + p3 = new Point2D.Float(); + p4 = new Point2D.Float(); + p1.setLocation(originX, originY); + p4.setLocation(e.getX(), e.getY()); + curveMade = true; + g.drawLine(originX,originY,e.getX(),e.getY()); + repaint(); + } + // once one of the curves are made then you select a point + else if(curveMade && !curveMade2) + { + pasteFromResize(); + p2.setLocation(e.getX(), e.getY()); + p3.setLocation(e.getX(), e.getY()); + curveMade2 = true; + c.setCurve(p1, p2, p3, p4); + g2.draw(c); + repaint(); + } + // once both points are choosen then the curve is drawn onto the screen + else if(curveMade2 && curveMade) + { + pasteFromResize(); + p3.setLocation(e.getX(), e.getY()); + c.setCurve(p1, p2, p3, p4); + g2.draw(c); + curveMade = false; + curveMade2 = false; + } + } + repaint(); + } + + /** Changes the foreground color to the selected color. **/ + public void eyeDropperOperation(MouseEvent e) + { + // creates a screen shot and takes the pixel color where the mouse is situated + try{ + Robot robot = new Robot(); + ColorBox.foreGround.setBackground(robot.getPixelColor(ControlClass.xCoord+e.getX(),ControlClass.yCoord+e.getY())); + }catch(AWTException awt){} + } + + /** Creates a line from two points. **/ + public void lineOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + if (mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + g.drawLine(originX, originY, mouseX, mouseY); + + prevX = mouseX; + prevY = mouseY; + } + pasteFromResize(); + g.drawLine(originX, originY, mouseX, mouseY); + repaint(); + } + + /** + * Draw a rectangle from two given points. Draws a fill operation, a outlined + * rectangle or a outlined with fill operation. + **/ + public void drawRectangle(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // gets the mouse coordinate and gets the width and height + mouseX = e.getX(); + mouseY = e.getY(); + int width = mouseX-originX; + int height = mouseY-originY; + + // draws a filled rectangle + if(extraOperations == FILL) + { + if(width > 0 && height > 0) + g.fillRect(originX,originY,width,height); + else if(width < 0 && height < 0) + g.fillRect(originX+width,originY+height,Math.abs(width),Math.abs(height)); + else if(width < 0 && height > 0) + g.fillRect(originX+width,originY,Math.abs(width),height); + else if(width > 0 && height < 0) + g.fillRect(originX,originY+height,width,Math.abs(height)); + } + // draws a normal rectangle + else if(extraOperations == NORMAL) + { + if(width > 0 && height > 0) + for(int i=0;i 0) + for(int i=0;i 0 && height < 0) + for(int i=0;i 0 && height > 0) + { + g.fillRect(originX,originY,width,height); + g.setColor(oppositeColor); + g.fillRect(originX+lineWidth,originY+lineWidth,width-(lineWidth*2),height-(lineWidth*2)); + } + else if(width < 0 && height < 0) + { + g.fillRect(originX+width,originY+height,Math.abs(width),Math.abs(height)); + g.setColor(oppositeColor); + g.fillRect(originX+width+lineWidth,originY+height+lineWidth,Math.abs(width)-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + else if(width < 0 && height > 0) + { + g.fillRect(originX+width,originY,Math.abs(width),height); + g.setColor(oppositeColor); + g.fillRect(originX+width+lineWidth,originY+lineWidth,Math.abs(width)-(lineWidth*2),height-(lineWidth*2)); + } + else if(width > 0 && height < 0) + { + g.fillRect(originX,originY+height,width,Math.abs(height)); + g.setColor(oppositeColor); + g.fillRect(originX+lineWidth,originY+height+lineWidth,width-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + } + } + + /** Calls the drawRectangle operation. **/ + public void rectOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + + if (mouseHasMoved(e)) + drawRectangle(e); + + pasteFromResize(); + drawRectangle(e); + repaint(); + } + + /** This method draws a rectangle with rounded edges. **/ + public void drawRoundRectangle(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // gets the mouse coordinate and gets the width and height + mouseX = e.getX(); + mouseY = e.getY(); + int width = mouseX-originX; + int height = mouseY-originY; + + // draws a filled rounded rectangle + if(extraOperations == FILL) + { + if(width > 0 && height > 0) + g.fillRoundRect(originX,originY,width,height,25,25); + else if(width < 0 && height < 0) + g.fillRoundRect(originX+width,originY+height,Math.abs(width),Math.abs(height),25,25); + else if(width < 0 && height > 0) + g.fillRoundRect(originX+width,originY,Math.abs(width),height,25,25); + else if(width > 0 && height < 0) + g.fillRoundRect(originX,originY+height,width,Math.abs(height),25,25); + } + // draws a normal rounded rectangle + else if(extraOperations == NORMAL) + { + if(width > 0 && height > 0) + for(int i=0;i 0) + for(int i=0;i 0 && height < 0) + for(int i=0;i 0 && height > 0) + { + g.fillRoundRect(originX,originY,width,height,25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+lineWidth,originY+lineWidth,width-(lineWidth*2),height-(lineWidth*2),25,25); + } + else if(width < 0 && height < 0) + { + g.fillRoundRect(originX+width,originY+height,Math.abs(width),Math.abs(height),25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+width+lineWidth,originY+height+lineWidth,Math.abs(width)-(lineWidth*2),Math.abs(height)-(lineWidth*2),25,25); + } + else if(width < 0 && height > 0) + { + g.fillRoundRect(originX+width,originY,Math.abs(width),height,25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+width+lineWidth,originY+lineWidth,Math.abs(width)-(lineWidth*2),height-(lineWidth*2),25,25); + } + else if(width > 0 && height < 0) + { + g.fillRoundRect(originX,originY+height,width,Math.abs(height),25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+lineWidth,originY+height+lineWidth,width-(lineWidth*2),Math.abs(height)-(lineWidth*2),25,25); + } + } + } + + /** Calls the drawRoundRectangle operation. **/ + public void roundOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + + if (mouseHasMoved(e)) + drawRoundRectangle(e); + + pasteFromResize(); + drawRoundRectangle(e); + repaint(); + } + + /** Draws an oval onto the screen. **/ + public void drawOval(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // gets the mouse coordinate and gets the width and height + mouseX = e.getX(); + mouseY = e.getY(); + int width = mouseX-originX; + int height = mouseY-originY; + + // draws a filled oval + if(extraOperations == FILL) + { + if(width > 0 && height > 0) + g.fillOval(originX,originY,width,height); + else if(width < 0 && height < 0) + g.fillOval(originX+width,originY+height,Math.abs(width),Math.abs(height)); + else if(width < 0 && height > 0) + g.fillOval(originX+width,originY,Math.abs(width),height); + else if(width > 0 && height < 0) + g.fillOval(originX,originY+height,width,Math.abs(height)); + } + // draws a normal oval + else if(extraOperations == NORMAL) + { + if(width > 0 && height > 0) + for(int i=0;i 0) + for(int i=0;i 0 && height < 0) + for(int i=0;i 0 && height > 0) + { + g.fillOval(originX,originY,width,height); + g.setColor(oppositeColor); + g.fillOval(originX+lineWidth,originY+lineWidth,width-(lineWidth*2),height-(lineWidth*2)); + } + else if(width < 0 && height < 0) + { + g.fillOval(originX+width,originY+height,Math.abs(width),Math.abs(height)); + g.setColor(oppositeColor); + g.fillOval(originX+width+lineWidth,originY+height+lineWidth,Math.abs(width)-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + else if(width < 0 && height > 0) + { + g.fillOval(originX+width,originY,Math.abs(width),height); + g.setColor(oppositeColor); + g.fillOval(originX+width+lineWidth,originY+lineWidth,Math.abs(width)-(lineWidth*2),height-(lineWidth*2)); + } + else if(width > 0 && height < 0) + { + g.fillOval(originX,originY+height,width,Math.abs(height)); + g.setColor(oppositeColor); + g.fillOval(originX+lineWidth,originY+height+lineWidth,width-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + } + } + + /** Calls the drawOval operation. **/ + public void ovalOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + + if (mouseHasMoved(e)) + drawOval(e); + + pasteFromResize(); + drawOval(e); + repaint(); + } + + /** Drag Brush Operation. You draw a shape around as your brush. **/ + public void dragOperation(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + if (mouseHasMoved(e)) + if(extraOperations == LINE) + g.drawLine(e.getX(),e.getY(),e.getX()+radius,e.getY()-radius); + else if(extraOperations == RECT) + g.drawRect(e.getX(),e.getY(),radius,radius); + else if(extraOperations == OVAL) + g.drawOval(e.getX(),e.getY(),radius,radius); + repaint(); + } + + /** Spray brush tool. Draws many tiny dots within a set radius. **/ + public void sprayOperation(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + // sets random points to the origin and draws them onto the screen + for(int i=0;i 0) + { + x = pixelQueue[0] & 0xffff; + y = (pixelQueue[0] >> 16) & 0xffff; + pixelQueueSize--; + pixelQueue[0] = pixelQueue[pixelQueueSize]; + + if (x > 0) + { + if (getPixel(x-1, y) == original) + { + changePixel(x-1, y, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = (y << 16) + x-1; + pixelQueueSize++; + } + } + + if (y > 0) + { + if (getPixel(x, y-1) == original) + { + changePixel(x, y-1, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = ((y-1) << 16) + x; + pixelQueueSize++; + } + } + if (x < getWidth()-1) + { + if (getPixel(x+1, y) == original) + { + changePixel(x+1, y, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = (y << 16) + x+1; + pixelQueueSize++; + } + } + if (y < getHeight()-1) + { + if (getPixel(x, y+1) == original) + { + changePixel(x, y+1, drawColor.getRGB()); + pixelQueue[pixelQueueSize] = ((y+1) << 16) + x; + pixelQueueSize++; + } + } + } + } + + /** Helper method for the rotation. Sets the amount of rotation 90 degrees. **/ + private AffineTransform setRotation() + { + AffineTransform atright = AffineTransform.getRotateInstance(Math.PI / 2, getWidth() / 2, getHeight() / 2); + return atright; + } + + /** This method actually rotates the image 90 degrees. **/ + public void rotateOperation() + { + // saves the image and then clears it and draws it rotated 90 degrees. + Graphics g = getBufferStrategy().getDrawGraphics(); + Graphics2D g2 = (Graphics2D) g; + saveFromResize(); + clearImage(); + g2.drawImage(resizeImage, setRotation(), this); + repaint(); + } + + /** Saves the image so that it can be printed. **/ + public void saveImageForPrinting() + { + // saves the image of the screen + try{ + printImage = new Robot().createScreenCapture( + new Rectangle(ControlClass.xCoord,ControlClass.yCoord,getWidth(),getHeight())); + }catch(AWTException awte){} + } + + /** This is a helper method for print. Draws the image to be printed. **/ + public void drawImage(Graphics2D g2D) + { + // draws the print image out on paper + g2D.drawImage(printImage,0,0,null); + } + + /** Printing operation, it prints the image saved. **/ + public int print(Graphics g, PageFormat pf, int pIndex) throws PrinterException + { + if (pIndex > 0) + return Printable.NO_SUCH_PAGE; + + Graphics2D g2D = (Graphics2D)g; + drawImage(g2D); + return Printable.PAGE_EXISTS; + } + + /** Updates the screen and flips the buffers around. **/ + public void update(Graphics g) + { + getBufferStrategy().show(); + } + + /** Paints the image onto the screen. **/ + public void paint(Graphics g) + { + try{update(g);}catch(NullPointerException e){} + } + + /** Opens a selected image and draws it onto the screen. **/ + public void openOperation(String path) + { + // creates an image and draws it to the screen + Graphics g = getBufferStrategy().getDrawGraphics(); + ImageIcon ic = new ImageIcon(path); + g.drawImage((Image)ic.getImage(),0,0,null); + } + + /** Selects the image from the top left corner to the bottom right corner. **/ + public void selectOperation(MouseEvent e) + { + if(mouseHasMoved(e)) + { + // this checks if you select off screen, if your off screen then it will + // set the boundaries to the edge of the drawing canvas + int tOriginX = ControlClass.xCoord+e.getX(); + int tOriginY = ControlClass.yCoord+e.getY(); + + if(tOriginX > getWidth()+ControlClass.xCoord) + tOriginX = getWidth()+ControlClass.xCoord; + if(tOriginX < ControlClass.xCoord) + tOriginX = ControlClass.xCoord; + if(tOriginY > getHeight()+ControlClass.yCoord) + tOriginY = getHeight()+ControlClass.yCoord; + if(tOriginY < ControlClass.yCoord) + tOriginY = ControlClass.yCoord; + + // calculates the width and height of the area + width = tOriginX-(ControlClass.xCoord+originX); + height = tOriginY-(ControlClass.yCoord+originY); + + if(width < 0 && height < 0) + { + originX+=width; + originY+=height; + } + else if(width < 0 && height > 0) + originX+=width; + else if(width > 0 && height < 0) + originY+=height; + + width = Math.abs(width); + height = Math.abs(height); + } + } + + /** Copies the selected image **/ + public void copyOperation() + { + // copies the boundaries set by the mouse + try{ + DrawingCanvas.selectImage = new Robot().createScreenCapture( + new Rectangle(ControlClass.xCoord+originX,ControlClass.yCoord+originY, + width,height)); + }catch(AWTException awte){} + } + /** Copies the selected image and deletes the selected portion **/ + public void cutOperation() + { + // copies the image and then draws a rectangle over the selected area + copyOperation(); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(oppositeColor); + g.fillRect(originX,originY,width,height); + width = height = 0; + repaint(); + } + + /** Draws the image with regards to the mouse location. **/ + public void pasteOperation() + { + // draws the image of the selected image onto the screen + Graphics g = getBufferStrategy().getDrawGraphics(); + g.drawImage(DrawingCanvas.selectImage,originX,originY,null); + repaint(); + } + + /** Draws random lines of random colors on the screen. **/ + public void randomDraw() + { + RandomPoint rPt = new RandomPoint(getWidth(),getHeight()); + Graphics g = getBufferStrategy().getDrawGraphics(); + int i=0; + while(i< amtLines) + { + g.setColor(rPt.getColor()); + g.drawLine((int)rPt.getX(),(int)rPt.getY(),rPt.nextX(),rPt.nextY()); + i++; + } + repaint(); + } + + /** Opens up a text dialog in the selected area. **/ + public void textOperation(MouseEvent e) + { + // opens up a text dialog + setCursor(new Cursor(Cursor.TEXT_CURSOR)); + TextDialog tDialog = new TextDialog(e.getX(),e.getY()); + } + + /** Prints the text onto the screen **/ + public void textOperation2(String txt, int x, int y, Font f) + { + // draws the text onto the screen + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setFont(f); + g.setColor(drawColor); + g.drawString(txt,x,y); + g.setFont(new Font("Times New Roman", Font.PLAIN, 12)); + repaint(); + } + + /** An eraser that erases when the mouse is dragged. **/ + public void eraserOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(ColorBox.backGround.getBackground()); + + if (mouseHasMoved(e)) + g.fillRect(e.getX(),e.getY(),15,15); + + repaint(); + } + + /** Paint brush with different brushes like a square and a circle. **/ + public void brushOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.HAND_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // depending on which brush is selected it will change the brush to that shape + if (mouseHasMoved(e)) + if(extraOperations == OVAL) + g.fillOval(e.getX(),e.getY(),radius,radius); + else if(extraOperations == RECT) + g.fillRect(e.getX(),e.getY(),radius,radius); + repaint(); + } + + /** Creates a pen when can be operated when mouse is dragged. **/ + public void penOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.HAND_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // draws lines while your mouse is dragged + if (mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + g.drawLine(prevX,prevY,mouseX,mouseY); + + prevX = mouseX; + prevY = mouseY; + } + repaint(); + } + + /** Calls the line operation first and then starts the polygon operation **/ + public void prePolyOperation(MouseEvent e) + { + if(!polyStart) + { + lineOperation(e); + polyStart = true; + } + polyOperation(e); + } + + /** Starts a polygon shape by drawing many line. **/ + public void polyOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // draws a line on the screen + if(mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + g.drawLine(prevX, prevY, mouseX, mouseY); + + prevX = mouseX; + prevY = mouseY; + } + + // sets the polygon operation to false if the line is back at the origin + if(isBeginning(e)) + polyStart = false; + + repaint(); + } + + /** Helper method for the polygon to check if the line drawn is back at the origin. **/ + public boolean isBeginning(MouseEvent e) + { + // returns true or false if the range is five away from the beginning + return (Math.abs(originX-e.getX()) <= 5 && Math.abs(originY-e.getY()) <= 5); + } + + /** Checks if the polygon operation is deselected and stops it. **/ + public void checkPolyOff() + { + // if the polygon operation is on and the polygon tool is not selected then + // finish the line if it wasnt completed and reset the polygon operation + if(polyStart && ToolBox.toolSelected != ToolBox.POLYGON) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + g.drawLine(prevX,prevY,originX,originY); + polyStart = false; + } + } + + /** Checks if the curve line tool is deselected. **/ + public void checkCurveOff() + { + // if the tool is deselected then reset variables to default + if(ToolBox.toolSelected != ToolBox.CURVELINE) + curveMade = curveMade2 = false; + } + + /** Starts the curve line tool. **/ + public void curveLineOperation(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + if(mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + Graphics2D g2 = (Graphics2D)g; + + // if the first and second point are not choosen then draw a straight line + if(!curveMade && !curveMade2) + { + c = new CubicCurve2D.Float(); + p1 = new Point2D.Float(); + p2 = new Point2D.Float(); + p3 = new Point2D.Float(); + p4 = new Point2D.Float(); + p1.setLocation(originX, originY); + p4.setLocation(e.getX(), e.getY()); + curveMade = true; + g.drawLine(originX,originY,e.getX(),e.getY()); + repaint(); + } + // once one of the curves are made then you select a point + else if(curveMade && !curveMade2) + { + pasteFromResize(); + p2.setLocation(e.getX(), e.getY()); + p3.setLocation(e.getX(), e.getY()); + curveMade2 = true; + c.setCurve(p1, p2, p3, p4); + g2.draw(c); + repaint(); + } + // once both points are choosen then the curve is drawn onto the screen + else if(curveMade2 && curveMade) + { + pasteFromResize(); + p3.setLocation(e.getX(), e.getY()); + c.setCurve(p1, p2, p3, p4); + g2.draw(c); + curveMade = false; + curveMade2 = false; + } + } + repaint(); + } + + /** Changes the foreground color to the selected color. **/ + public void eyeDropperOperation(MouseEvent e) + { + // creates a screen shot and takes the pixel color where the mouse is situated + try{ + Robot robot = new Robot(); + ColorBox.foreGround.setBackground(robot.getPixelColor(ControlClass.xCoord+e.getX(),ControlClass.yCoord+e.getY())); + }catch(AWTException awt){} + } + + /** Creates a line from two points. **/ + public void lineOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + if (mouseHasMoved(e)) + { + mouseX = e.getX(); + mouseY = e.getY(); + + g.drawLine(originX, originY, mouseX, mouseY); + + prevX = mouseX; + prevY = mouseY; + } + pasteFromResize(); + g.drawLine(originX, originY, mouseX, mouseY); + repaint(); + } + + /** + * Draw a rectangle from two given points. Draws a fill operation, a outlined + * rectangle or a outlined with fill operation. + **/ + public void drawRectangle(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // gets the mouse coordinate and gets the width and height + mouseX = e.getX(); + mouseY = e.getY(); + int width = mouseX-originX; + int height = mouseY-originY; + + // draws a filled rectangle + if(extraOperations == FILL) + { + if(width > 0 && height > 0) + g.fillRect(originX,originY,width,height); + else if(width < 0 && height < 0) + g.fillRect(originX+width,originY+height,Math.abs(width),Math.abs(height)); + else if(width < 0 && height > 0) + g.fillRect(originX+width,originY,Math.abs(width),height); + else if(width > 0 && height < 0) + g.fillRect(originX,originY+height,width,Math.abs(height)); + } + // draws a normal rectangle + else if(extraOperations == NORMAL) + { + if(width > 0 && height > 0) + for(int i=0;i 0) + for(int i=0;i 0 && height < 0) + for(int i=0;i 0 && height > 0) + { + g.fillRect(originX,originY,width,height); + g.setColor(oppositeColor); + g.fillRect(originX+lineWidth,originY+lineWidth,width-(lineWidth*2),height-(lineWidth*2)); + } + else if(width < 0 && height < 0) + { + g.fillRect(originX+width,originY+height,Math.abs(width),Math.abs(height)); + g.setColor(oppositeColor); + g.fillRect(originX+width+lineWidth,originY+height+lineWidth,Math.abs(width)-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + else if(width < 0 && height > 0) + { + g.fillRect(originX+width,originY,Math.abs(width),height); + g.setColor(oppositeColor); + g.fillRect(originX+width+lineWidth,originY+lineWidth,Math.abs(width)-(lineWidth*2),height-(lineWidth*2)); + } + else if(width > 0 && height < 0) + { + g.fillRect(originX,originY+height,width,Math.abs(height)); + g.setColor(oppositeColor); + g.fillRect(originX+lineWidth,originY+height+lineWidth,width-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + } + } + + /** Calls the drawRectangle operation. **/ + public void rectOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + + if (mouseHasMoved(e)) + drawRectangle(e); + + pasteFromResize(); + drawRectangle(e); + repaint(); + } + + /** This method draws a rectangle with rounded edges. **/ + public void drawRoundRectangle(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // gets the mouse coordinate and gets the width and height + mouseX = e.getX(); + mouseY = e.getY(); + int width = mouseX-originX; + int height = mouseY-originY; + + // draws a filled rounded rectangle + if(extraOperations == FILL) + { + if(width > 0 && height > 0) + g.fillRoundRect(originX,originY,width,height,25,25); + else if(width < 0 && height < 0) + g.fillRoundRect(originX+width,originY+height,Math.abs(width),Math.abs(height),25,25); + else if(width < 0 && height > 0) + g.fillRoundRect(originX+width,originY,Math.abs(width),height,25,25); + else if(width > 0 && height < 0) + g.fillRoundRect(originX,originY+height,width,Math.abs(height),25,25); + } + // draws a normal rounded rectangle + else if(extraOperations == NORMAL) + { + if(width > 0 && height > 0) + for(int i=0;i 0) + for(int i=0;i 0 && height < 0) + for(int i=0;i 0 && height > 0) + { + g.fillRoundRect(originX,originY,width,height,25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+lineWidth,originY+lineWidth,width-(lineWidth*2),height-(lineWidth*2),25,25); + } + else if(width < 0 && height < 0) + { + g.fillRoundRect(originX+width,originY+height,Math.abs(width),Math.abs(height),25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+width+lineWidth,originY+height+lineWidth,Math.abs(width)-(lineWidth*2),Math.abs(height)-(lineWidth*2),25,25); + } + else if(width < 0 && height > 0) + { + g.fillRoundRect(originX+width,originY,Math.abs(width),height,25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+width+lineWidth,originY+lineWidth,Math.abs(width)-(lineWidth*2),height-(lineWidth*2),25,25); + } + else if(width > 0 && height < 0) + { + g.fillRoundRect(originX,originY+height,width,Math.abs(height),25,25); + g.setColor(oppositeColor); + g.fillRoundRect(originX+lineWidth,originY+height+lineWidth,width-(lineWidth*2),Math.abs(height)-(lineWidth*2),25,25); + } + } + } + + /** Calls the drawRoundRectangle operation. **/ + public void roundOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + + if (mouseHasMoved(e)) + drawRoundRectangle(e); + + pasteFromResize(); + drawRoundRectangle(e); + repaint(); + } + + /** Draws an oval onto the screen. **/ + public void drawOval(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + // gets the mouse coordinate and gets the width and height + mouseX = e.getX(); + mouseY = e.getY(); + int width = mouseX-originX; + int height = mouseY-originY; + + // draws a filled oval + if(extraOperations == FILL) + { + if(width > 0 && height > 0) + g.fillOval(originX,originY,width,height); + else if(width < 0 && height < 0) + g.fillOval(originX+width,originY+height,Math.abs(width),Math.abs(height)); + else if(width < 0 && height > 0) + g.fillOval(originX+width,originY,Math.abs(width),height); + else if(width > 0 && height < 0) + g.fillOval(originX,originY+height,width,Math.abs(height)); + } + // draws a normal oval + else if(extraOperations == NORMAL) + { + if(width > 0 && height > 0) + for(int i=0;i 0) + for(int i=0;i 0 && height < 0) + for(int i=0;i 0 && height > 0) + { + g.fillOval(originX,originY,width,height); + g.setColor(oppositeColor); + g.fillOval(originX+lineWidth,originY+lineWidth,width-(lineWidth*2),height-(lineWidth*2)); + } + else if(width < 0 && height < 0) + { + g.fillOval(originX+width,originY+height,Math.abs(width),Math.abs(height)); + g.setColor(oppositeColor); + g.fillOval(originX+width+lineWidth,originY+height+lineWidth,Math.abs(width)-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + else if(width < 0 && height > 0) + { + g.fillOval(originX+width,originY,Math.abs(width),height); + g.setColor(oppositeColor); + g.fillOval(originX+width+lineWidth,originY+lineWidth,Math.abs(width)-(lineWidth*2),height-(lineWidth*2)); + } + else if(width > 0 && height < 0) + { + g.fillOval(originX,originY+height,width,Math.abs(height)); + g.setColor(oppositeColor); + g.fillOval(originX+lineWidth,originY+height+lineWidth,width-(lineWidth*2),Math.abs(height)-(lineWidth*2)); + } + } + } + + /** Calls the drawOval operation. **/ + public void ovalOperation(MouseEvent e) + { + setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + + if (mouseHasMoved(e)) + drawOval(e); + + pasteFromResize(); + drawOval(e); + repaint(); + } + + /** Drag Brush Operation. You draw a shape around as your brush. **/ + public void dragOperation(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + + if (mouseHasMoved(e)) + if(extraOperations == LINE) + g.drawLine(e.getX(),e.getY(),e.getX()+radius,e.getY()-radius); + else if(extraOperations == RECT) + g.drawRect(e.getX(),e.getY(),radius,radius); + else if(extraOperations == OVAL) + g.drawOval(e.getX(),e.getY(),radius,radius); + repaint(); + } + + /** Spray brush tool. Draws many tiny dots within a set radius. **/ + public void sprayOperation(MouseEvent e) + { + Graphics g = getBufferStrategy().getDrawGraphics(); + g.setColor(drawColor); + // sets random points to the origin and draws them onto the screen + for(int i=0;i0 && i0 && i\n" + + "The quick brown fox jumps over the lazy dog"; + + /** Create a font chooser dialog for the specified frame. */ + public FontChooser(Frame owner) { + super(owner, "Choose a Font"); // Set dialog frame and title + + // This dialog must be used as a modal dialog. In order to be used + // as a modeless dialog, it would have to fire a PropertyChangeEvent + // whenever the selected font changed, so that applications could be + // notified of the user's selections. + setModal(true); + + // Figure out what fonts are available on the system + GraphicsEnvironment env = GraphicsEnvironment + .getLocalGraphicsEnvironment(); + fontFamilies = env.getAvailableFontFamilyNames(); + + // Set initial values for the properties + family = fontFamilies[0]; + style = Font.PLAIN; + size = 18; + selectedFont = new Font(family, style, size); + + // Create ItemChooser objects that allow the user to select font + // family, style, and size. + families = new ItemChooser("Family", fontFamilies, null, 0, + ItemChooser.COMBOBOX); + styles = new ItemChooser("Style", styleNames, styleValues, 0, + ItemChooser.COMBOBOX); + sizes = new ItemChooser("Size", sizeNames, null, 4, + ItemChooser.COMBOBOX); + + // Now register event listeners to handle selections + families.addItemChooserListener(new ItemChooser.Listener() { + public void itemChosen(ItemChooser.Event e) { + setFontFamily((String) e.getSelectedValue()); + } + }); + styles.addItemChooserListener(new ItemChooser.Listener() { + public void itemChosen(ItemChooser.Event e) { + setFontStyle(((Integer) e.getSelectedValue()).intValue()); + } + }); + sizes.addItemChooserListener(new ItemChooser.Listener() { + public void itemChosen(ItemChooser.Event e) { + setFontSize(Integer.parseInt((String) e.getSelectedValue())); + } + }); + + // Create a component to preview the font. + preview = new JTextArea(defaultPreviewString, 5, 40); + preview.setFont(selectedFont); + + // Create buttons to dismiss the dialog, and set handlers on them + okay = new JButton("Okay"); + cancel = new JButton("Cancel"); + okay.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + hide(); + } + }); + cancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + selectedFont = null; + hide(); + } + }); + + // Put the ItemChoosers in a Box + Box choosersBox = Box.createHorizontalBox(); + choosersBox.add(Box.createHorizontalStrut(15)); + choosersBox.add(families); + choosersBox.add(Box.createHorizontalStrut(15)); + choosersBox.add(styles); + choosersBox.add(Box.createHorizontalStrut(15)); + choosersBox.add(sizes); + choosersBox.add(Box.createHorizontalStrut(15)); + choosersBox.add(Box.createGlue()); + + // Put the dismiss buttons in another box + Box buttonBox = Box.createHorizontalBox(); + buttonBox.add(Box.createGlue()); + buttonBox.add(okay); + buttonBox.add(Box.createGlue()); + buttonBox.add(cancel); + buttonBox.add(Box.createGlue()); + + // Put the choosers at the top, the buttons at the bottom, and + // the preview in the middle. + Container contentPane = getContentPane(); + contentPane.add(new JScrollPane(preview), BorderLayout.CENTER); + contentPane.add(choosersBox, BorderLayout.NORTH); + contentPane.add(buttonBox, BorderLayout.SOUTH); + + // Set the dialog size based on the component size. + pack(); + } + + /** + * Call this method after show() to obtain the user's selection. If the user + * used the "Cancel" button, this will return null + */ + public Font getSelectedFont() { + return selectedFont; + } + + // These are other property getter methods + public String getFontFamily() { + return family; + } + + public int getFontStyle() { + return style; + } + + public int getFontSize() { + return size; + } + + // The property setter methods are a little more complicated. + // Note that none of these setter methods update the corresponding + // ItemChooser components as they ought to. + public void setFontFamily(String name) { + family = name; + changeFont(); + } + + public void setFontStyle(int style) { + this.style = style; + changeFont(); + } + + public void setFontSize(int size) { + this.size = size; + changeFont(); + } + + public void setSelectedFont(Font font) { + selectedFont = font; + family = font.getFamily(); + style = font.getStyle(); + size = font.getSize(); + preview.setFont(font); + } + + // This method is called when the family, style, or size changes + protected void changeFont() { + selectedFont = new Font(family, style, size); + preview.setFont(selectedFont); + } + + // Override this inherited method to prevent anyone from making us modeless + public boolean isModal() { + return true; + } + + public static void main(String[] args) { + // Create some components and a FontChooser dialog + final JFrame frame = new JFrame("demo"); + final JButton button = new JButton("Push Me!"); + final FontChooser chooser = new FontChooser(frame); + + // Handle button clicks + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // Pop up the dialog + chooser.show(); + // Get the user's selection + Font font = chooser.getSelectedFont(); + // If not cancelled, set the button font + if (font != null) + button.setFont(font); + } + }); + + // Display the demo + frame.getContentPane().add(button); + frame.setSize(200, 100); + frame.show(); + } +} +/** + * This class is a Swing component that presents a choice to the user. It allows + * the choice to be presented in a JList, in a JComboBox, or with a bordered + * group of JRadioButton components. Additionally, it displays the name of the + * choice with a JLabel. It allows an arbitrary value to be associated with each + * possible choice. Note that this component only allows one item to be selected + * at a time. Multiple selections are not supported. + */ + +class ItemChooser extends JPanel { + // These fields hold property values for this component + String name; // The overall name of the choice + + String[] labels; // The text for each choice option + + Object[] values; // Arbitrary values associated with each option + + int selection; // The selected choice + + int presentation; // How the choice is presented + + // These are the legal values for the presentation field + public static final int LIST = 1; + + public static final int COMBOBOX = 2; + + public static final int RADIOBUTTONS = 3; + + // These components are used for each of the 3 possible presentations + JList list; // One type of presentation + + JComboBox combobox; // Another type of presentation + + JRadioButton[] radiobuttons; // Yet another type + + // The list of objects that are interested in our state + ArrayList listeners = new ArrayList(); + + // The constructor method sets everything up + public ItemChooser(String name, String[] labels, Object[] values, + int defaultSelection, int presentation) { + // Copy the constructor arguments to instance fields + this.name = name; + this.labels = labels; + this.values = values; + this.selection = defaultSelection; + this.presentation = presentation; + + // If no values were supplied, use the labels + if (values == null) + this.values = labels; + + // Now create content and event handlers based on presentation type + switch (presentation) { + case LIST: + initList(); + break; + case COMBOBOX: + initComboBox(); + break; + case RADIOBUTTONS: + initRadioButtons(); + break; + } + } + + // Initialization for JList presentation + void initList() { + list = new JList(labels); // Create the list + list.setSelectedIndex(selection); // Set initial state + + // Handle state changes + list.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + ItemChooser.this.select(list.getSelectedIndex()); + } + }); + + // Lay out list and name label vertically + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // vertical + this.add(new JLabel(name)); // Display choice name + this.add(new JScrollPane(list)); // Add the JList + } + + // Initialization for JComboBox presentation + void initComboBox() { + combobox = new JComboBox(labels); // Create the combo box + combobox.setSelectedIndex(selection); // Set initial state + + // Handle changes to the state + combobox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + ItemChooser.this.select(combobox.getSelectedIndex()); + } + }); + + // Lay out combo box and name label horizontally + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + this.add(new JLabel(name)); + this.add(combobox); + } + + // Initialization for JRadioButton presentation + void initRadioButtons() { + // Create an array of mutually exclusive radio buttons + radiobuttons = new JRadioButton[labels.length]; // the array + ButtonGroup radioButtonGroup = new ButtonGroup(); // used for exclusion + ChangeListener listener = new ChangeListener() { // A shared listener + public void stateChanged(ChangeEvent e) { + JRadioButton b = (JRadioButton) e.getSource(); + if (b.isSelected()) { + // If we received this event because a button was + // selected, then loop through the list of buttons to + // figure out the index of the selected one. + for (int i = 0; i < radiobuttons.length; i++) { + if (radiobuttons[i] == b) { + ItemChooser.this.select(i); + return; + } + } + } + } + }; + + // Display the choice name in a border around the buttons + this.setBorder(new TitledBorder(new EtchedBorder(), name)); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + // Create the buttons, add them to the button group, and specify + // the event listener for each one. + for (int i = 0; i < labels.length; i++) { + radiobuttons[i] = new JRadioButton(labels[i]); + if (i == selection) + radiobuttons[i].setSelected(true); + radiobuttons[i].addChangeListener(listener); + radioButtonGroup.add(radiobuttons[i]); + this.add(radiobuttons[i]); + } + } + + // These simple property accessor methods just return field values + // These are read-only properties. The values are set by the constructor + // and may not be changed. + public String getName() { + return name; + } + + public int getPresentation() { + return presentation; + } + + public String[] getLabels() { + return labels; + } + + public Object[] getValues() { + return values; + } + + /** Return the index of the selected item */ + public int getSelectedIndex() { + return selection; + } + + /** Return the object associated with the selected item */ + public Object getSelectedValue() { + return values[selection]; + } + + /** + * Set the selected item by specifying its index. Calling this method + * changes the on-screen display but does not generate events. + */ + public void setSelectedIndex(int selection) { + switch (presentation) { + case LIST: + list.setSelectedIndex(selection); + break; + case COMBOBOX: + combobox.setSelectedIndex(selection); + break; + case RADIOBUTTONS: + radiobuttons[selection].setSelected(true); + break; + } + this.selection = selection; + } + + /** + * This internal method is called when the selection changes. It stores the + * new selected index, and fires events to any registered listeners. The + * event listeners registered on the JList, JComboBox, or JRadioButtons all + * call this method. + */ + protected void select(int selection) { + this.selection = selection; // Store the new selected index + if (!listeners.isEmpty()) { // If there are any listeners registered + // Create an event object to describe the selection + ItemChooser.Event e = new ItemChooser.Event(this, selection, + values[selection]); + // Loop through the listeners using an Iterator + for (Iterator i = listeners.iterator(); i.hasNext();) { + ItemChooser.Listener l = (ItemChooser.Listener) i.next(); + l.itemChosen(e); // Notify each listener of the selection + } + } + } + + // These methods are for event listener registration and deregistration + public void addItemChooserListener(ItemChooser.Listener l) { + listeners.add(l); + } + + public void removeItemChooserListener(ItemChooser.Listener l) { + listeners.remove(l); + } + + /** + * This inner class defines the event type generated by ItemChooser objects + * The inner class name is Event, so the full name is ItemChooser.Event + */ + public static class Event extends java.util.EventObject { + int selectedIndex; // index of the selected item + + Object selectedValue; // the value associated with it + + public Event(ItemChooser source, int selectedIndex, Object selectedValue) { + super(source); + this.selectedIndex = selectedIndex; + this.selectedValue = selectedValue; + } + + public ItemChooser getItemChooser() { + return (ItemChooser) getSource(); + } + + public int getSelectedIndex() { + return selectedIndex; + } + + public Object getSelectedValue() { + return selectedValue; + } + } + + /** + * This inner interface must be implemented by any object that wants to be + * notified when the current selection in a ItemChooser component changes. + */ + public interface Listener extends java.util.EventListener { + public void itemChosen(ItemChooser.Event e); + } + + /** + * This inner class is a simple demonstration of the ItemChooser component + * It uses command-line arguments as ItemChooser labels and values. + */ + public static class Demo { + public static void main(String[] args) { + // Create a window, arrange to handle close requests + final JFrame frame = new JFrame("ItemChooser Demo"); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + + // A "message line" to display results in + final JLabel msgline = new JLabel(" "); + + // Create a panel holding three ItemChooser components + JPanel chooserPanel = new JPanel(); + final ItemChooser c1 = new ItemChooser("Choice #1", args, null, 0, + ItemChooser.LIST); + final ItemChooser c2 = new ItemChooser("Choice #2", args, null, 0, + ItemChooser.COMBOBOX); + final ItemChooser c3 = new ItemChooser("Choice #3", args, null, 0, + ItemChooser.RADIOBUTTONS); + + // An event listener that displays changes on the message line + ItemChooser.Listener l = new ItemChooser.Listener() { + public void itemChosen(ItemChooser.Event e) { + msgline.setText(e.getItemChooser().getName() + ": " + + e.getSelectedIndex() + ": " + + e.getSelectedValue()); + } + }; + c1.addItemChooserListener(l); + c2.addItemChooserListener(l); + c3.addItemChooserListener(l); + + // Instead of tracking every change with a ItemChooser.Listener, + // applications can also just query the current state when + // they need it. Here's a button that does that. + JButton report = new JButton("Report"); + report.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // Note the use of multi-line italic HTML text + // with the JOptionPane message dialog box. + String msg = "" + c1.getName() + ": " + + c1.getSelectedValue() + "
" + c2.getName() + + ": " + c2.getSelectedValue() + "
" + + c3.getName() + ": " + c3.getSelectedValue() + + "
"; + JOptionPane.showMessageDialog(frame, msg); + } + }); + + // Add the 3 ItemChooser objects, and the Button to the panel + chooserPanel.add(c1); + chooserPanel.add(c2); + chooserPanel.add(c3); + chooserPanel.add(report); + + // Add the panel and the message line to the window + Container contentPane = frame.getContentPane(); + contentPane.add(chooserPanel, BorderLayout.CENTER); + contentPane.add(msgline, BorderLayout.SOUTH); + + // Set the window size and pop it up. + frame.pack(); + frame.show(); + } + } +} diff --git a/JPAINT/jpaint/HelpDialog.class b/JPAINT/jpaint/HelpDialog.class new file mode 100644 index 0000000..ccbeda8 Binary files /dev/null and b/JPAINT/jpaint/HelpDialog.class differ diff --git a/JPAINT/jpaint/HelpDialog.java b/JPAINT/jpaint/HelpDialog.java new file mode 100644 index 0000000..3f9a283 --- /dev/null +++ b/JPAINT/jpaint/HelpDialog.java @@ -0,0 +1,36 @@ +import javax.swing.JDialog; +import javax.swing.JLabel; + +/** + * A simple dialog that displays information about the program being used. + **/ + +public class HelpDialog extends JDialog +{ + /** + * Creates a new HelpDialog. Sets the title to "about". + */ + public HelpDialog() + { + setTitle("About"); + getContentPane().setLayout(null); + setSize(400, 300); + + JLabel lbl = new JLabel("JPaint "); + JLabel lbl2 = new JLabel("Created By: "); + JLabel lbl3 = new JLabel("LENTIEUL Romuald "); + JLabel lbl4 = new JLabel(" &"); + JLabel lbl5 = new JLabel("MAZIER Leo "); + lbl.setBounds(150,20,200,20); + lbl2.setBounds(20,40,200,20); + lbl3.setBounds(20,80,200,20); + lbl4.setBounds(20,120,200,20); + lbl5.setBounds(20,160,200,20); + getContentPane().add(lbl); + getContentPane().add(lbl2); + getContentPane().add(lbl3); + getContentPane().add(lbl4); + getContentPane().add(lbl5); + setVisible(true); + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/HelpDialog.java~ b/JPAINT/jpaint/HelpDialog.java~ new file mode 100644 index 0000000..3f9a283 --- /dev/null +++ b/JPAINT/jpaint/HelpDialog.java~ @@ -0,0 +1,36 @@ +import javax.swing.JDialog; +import javax.swing.JLabel; + +/** + * A simple dialog that displays information about the program being used. + **/ + +public class HelpDialog extends JDialog +{ + /** + * Creates a new HelpDialog. Sets the title to "about". + */ + public HelpDialog() + { + setTitle("About"); + getContentPane().setLayout(null); + setSize(400, 300); + + JLabel lbl = new JLabel("JPaint "); + JLabel lbl2 = new JLabel("Created By: "); + JLabel lbl3 = new JLabel("LENTIEUL Romuald "); + JLabel lbl4 = new JLabel(" &"); + JLabel lbl5 = new JLabel("MAZIER Leo "); + lbl.setBounds(150,20,200,20); + lbl2.setBounds(20,40,200,20); + lbl3.setBounds(20,80,200,20); + lbl4.setBounds(20,120,200,20); + lbl5.setBounds(20,160,200,20); + getContentPane().add(lbl); + getContentPane().add(lbl2); + getContentPane().add(lbl3); + getContentPane().add(lbl4); + getContentPane().add(lbl5); + setVisible(true); + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/Images/0.gif b/JPAINT/jpaint/Images/0.gif new file mode 100644 index 0000000..c90898c Binary files /dev/null and b/JPAINT/jpaint/Images/0.gif differ diff --git a/JPAINT/jpaint/Images/1.gif b/JPAINT/jpaint/Images/1.gif new file mode 100644 index 0000000..6b5847c Binary files /dev/null and b/JPAINT/jpaint/Images/1.gif differ diff --git a/JPAINT/jpaint/Images/10.gif b/JPAINT/jpaint/Images/10.gif new file mode 100644 index 0000000..c54bad8 Binary files /dev/null and b/JPAINT/jpaint/Images/10.gif differ diff --git a/JPAINT/jpaint/Images/11.gif b/JPAINT/jpaint/Images/11.gif new file mode 100644 index 0000000..8a1dc33 Binary files /dev/null and b/JPAINT/jpaint/Images/11.gif differ diff --git a/JPAINT/jpaint/Images/12.gif b/JPAINT/jpaint/Images/12.gif new file mode 100644 index 0000000..7c97e44 Binary files /dev/null and b/JPAINT/jpaint/Images/12.gif differ diff --git a/JPAINT/jpaint/Images/13.gif b/JPAINT/jpaint/Images/13.gif new file mode 100644 index 0000000..f53a144 Binary files /dev/null and b/JPAINT/jpaint/Images/13.gif differ diff --git a/JPAINT/jpaint/Images/14.gif b/JPAINT/jpaint/Images/14.gif new file mode 100644 index 0000000..d67b446 Binary files /dev/null and b/JPAINT/jpaint/Images/14.gif differ diff --git a/JPAINT/jpaint/Images/15.gif b/JPAINT/jpaint/Images/15.gif new file mode 100644 index 0000000..77a6f81 Binary files /dev/null and b/JPAINT/jpaint/Images/15.gif differ diff --git a/JPAINT/jpaint/Images/2.gif b/JPAINT/jpaint/Images/2.gif new file mode 100644 index 0000000..e986c6f Binary files /dev/null and b/JPAINT/jpaint/Images/2.gif differ diff --git a/JPAINT/jpaint/Images/3.gif b/JPAINT/jpaint/Images/3.gif new file mode 100644 index 0000000..ab7aeb5 Binary files /dev/null and b/JPAINT/jpaint/Images/3.gif differ diff --git a/JPAINT/jpaint/Images/4.gif b/JPAINT/jpaint/Images/4.gif new file mode 100644 index 0000000..8ff87d4 Binary files /dev/null and b/JPAINT/jpaint/Images/4.gif differ diff --git a/JPAINT/jpaint/Images/5.gif b/JPAINT/jpaint/Images/5.gif new file mode 100644 index 0000000..2ce4cb8 Binary files /dev/null and b/JPAINT/jpaint/Images/5.gif differ diff --git a/JPAINT/jpaint/Images/6.gif b/JPAINT/jpaint/Images/6.gif new file mode 100644 index 0000000..829e706 Binary files /dev/null and b/JPAINT/jpaint/Images/6.gif differ diff --git a/JPAINT/jpaint/Images/7.gif b/JPAINT/jpaint/Images/7.gif new file mode 100644 index 0000000..f693421 Binary files /dev/null and b/JPAINT/jpaint/Images/7.gif differ diff --git a/JPAINT/jpaint/Images/8.gif b/JPAINT/jpaint/Images/8.gif new file mode 100644 index 0000000..aaf236f Binary files /dev/null and b/JPAINT/jpaint/Images/8.gif differ diff --git a/JPAINT/jpaint/Images/9.gif b/JPAINT/jpaint/Images/9.gif new file mode 100644 index 0000000..708c754 Binary files /dev/null and b/JPAINT/jpaint/Images/9.gif differ diff --git a/JPAINT/jpaint/Images/JPaintSplash.jpg b/JPAINT/jpaint/Images/JPaintSplash.jpg new file mode 100644 index 0000000..c19007e Binary files /dev/null and b/JPAINT/jpaint/Images/JPaintSplash.jpg differ diff --git a/JPAINT/jpaint/Images/box.gif b/JPAINT/jpaint/Images/box.gif new file mode 100644 index 0000000..8dc4279 Binary files /dev/null and b/JPAINT/jpaint/Images/box.gif differ diff --git a/JPAINT/jpaint/Images/boxPressed.gif b/JPAINT/jpaint/Images/boxPressed.gif new file mode 100644 index 0000000..946d6aa Binary files /dev/null and b/JPAINT/jpaint/Images/boxPressed.gif differ diff --git a/JPAINT/jpaint/Images/fill.gif b/JPAINT/jpaint/Images/fill.gif new file mode 100644 index 0000000..25d4f29 Binary files /dev/null and b/JPAINT/jpaint/Images/fill.gif differ diff --git a/JPAINT/jpaint/Images/fillPressed.gif b/JPAINT/jpaint/Images/fillPressed.gif new file mode 100644 index 0000000..dd44e2d Binary files /dev/null and b/JPAINT/jpaint/Images/fillPressed.gif differ diff --git a/JPAINT/jpaint/Images/line.gif b/JPAINT/jpaint/Images/line.gif new file mode 100644 index 0000000..043e05a Binary files /dev/null and b/JPAINT/jpaint/Images/line.gif differ diff --git a/JPAINT/jpaint/Images/linePressed.gif b/JPAINT/jpaint/Images/linePressed.gif new file mode 100644 index 0000000..ea116fc Binary files /dev/null and b/JPAINT/jpaint/Images/linePressed.gif differ diff --git a/JPAINT/jpaint/Images/normal.gif b/JPAINT/jpaint/Images/normal.gif new file mode 100644 index 0000000..9e4f328 Binary files /dev/null and b/JPAINT/jpaint/Images/normal.gif differ diff --git a/JPAINT/jpaint/Images/normalPressed.gif b/JPAINT/jpaint/Images/normalPressed.gif new file mode 100644 index 0000000..ae94277 Binary files /dev/null and b/JPAINT/jpaint/Images/normalPressed.gif differ diff --git a/JPAINT/jpaint/Images/outline.gif b/JPAINT/jpaint/Images/outline.gif new file mode 100644 index 0000000..f1c02a6 Binary files /dev/null and b/JPAINT/jpaint/Images/outline.gif differ diff --git a/JPAINT/jpaint/Images/outlinePressed.gif b/JPAINT/jpaint/Images/outlinePressed.gif new file mode 100644 index 0000000..f173a82 Binary files /dev/null and b/JPAINT/jpaint/Images/outlinePressed.gif differ diff --git a/JPAINT/jpaint/Images/oval.gif b/JPAINT/jpaint/Images/oval.gif new file mode 100644 index 0000000..43dbcb2 Binary files /dev/null and b/JPAINT/jpaint/Images/oval.gif differ diff --git a/JPAINT/jpaint/Images/ovalPressed.gif b/JPAINT/jpaint/Images/ovalPressed.gif new file mode 100644 index 0000000..81f4fc0 Binary files /dev/null and b/JPAINT/jpaint/Images/ovalPressed.gif differ diff --git a/JPAINT/jpaint/ItemChooser$1.class b/JPAINT/jpaint/ItemChooser$1.class new file mode 100644 index 0000000..07e2d92 Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$1.class differ diff --git a/JPAINT/jpaint/ItemChooser$2.class b/JPAINT/jpaint/ItemChooser$2.class new file mode 100644 index 0000000..1dfe29b Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$2.class differ diff --git a/JPAINT/jpaint/ItemChooser$3.class b/JPAINT/jpaint/ItemChooser$3.class new file mode 100644 index 0000000..733c082 Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$3.class differ diff --git a/JPAINT/jpaint/ItemChooser$Demo$1.class b/JPAINT/jpaint/ItemChooser$Demo$1.class new file mode 100644 index 0000000..58eb580 Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$Demo$1.class differ diff --git a/JPAINT/jpaint/ItemChooser$Demo$2.class b/JPAINT/jpaint/ItemChooser$Demo$2.class new file mode 100644 index 0000000..4d5669f Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$Demo$2.class differ diff --git a/JPAINT/jpaint/ItemChooser$Demo$3.class b/JPAINT/jpaint/ItemChooser$Demo$3.class new file mode 100644 index 0000000..1df31b5 Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$Demo$3.class differ diff --git a/JPAINT/jpaint/ItemChooser$Demo.class b/JPAINT/jpaint/ItemChooser$Demo.class new file mode 100644 index 0000000..79030d2 Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$Demo.class differ diff --git a/JPAINT/jpaint/ItemChooser$Event.class b/JPAINT/jpaint/ItemChooser$Event.class new file mode 100644 index 0000000..72b1cdb Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$Event.class differ diff --git a/JPAINT/jpaint/ItemChooser$Listener.class b/JPAINT/jpaint/ItemChooser$Listener.class new file mode 100644 index 0000000..e73906b Binary files /dev/null and b/JPAINT/jpaint/ItemChooser$Listener.class differ diff --git a/JPAINT/jpaint/ItemChooser.class b/JPAINT/jpaint/ItemChooser.class new file mode 100644 index 0000000..55d1b5f Binary files /dev/null and b/JPAINT/jpaint/ItemChooser.class differ diff --git a/JPAINT/jpaint/JPaintFileChooser.class b/JPAINT/jpaint/JPaintFileChooser.class new file mode 100644 index 0000000..1b40e82 Binary files /dev/null and b/JPAINT/jpaint/JPaintFileChooser.class differ diff --git a/JPAINT/jpaint/JPaintFileChooser.java b/JPAINT/jpaint/JPaintFileChooser.java new file mode 100644 index 0000000..751501e --- /dev/null +++ b/JPAINT/jpaint/JPaintFileChooser.java @@ -0,0 +1,37 @@ +import javax.swing.JFileChooser; +import java.awt.Component; +import javax.swing.JDialog; +import javax.swing.JButton; + +/** + * JPaint File Chooser class opens up a file dialog where you can browse + * for the file you are looking for. You can either choose to save or open the + * file aftewards. + **/ +public class JPaintFileChooser extends JFileChooser +{ + private JDialog fileChooserDialog; + private ExampleFileFilter filter; + + /** + * Creates a default JPaintFileChooser Constructor and sets the extensions + * for files that are only allowed to be opened and saved. + **/ + public JPaintFileChooser(Component parent) + { + // creates a filter and adds the valid extensions on to it + filter = new ExampleFileFilter (); + filter.addExtension("jpg"); + filter.addExtension("gif"); + filter.addExtension("png"); + setFileFilter(filter); + // instantiates the file chooser dialog + fileChooserDialog = createDialog(parent); + } + + /** Returns the file chooser dialog. **/ + public JDialog getFileChooserDialog() + { + return fileChooserDialog; + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/JPaintFileChooser.java~ b/JPAINT/jpaint/JPaintFileChooser.java~ new file mode 100644 index 0000000..df50ebf --- /dev/null +++ b/JPAINT/jpaint/JPaintFileChooser.java~ @@ -0,0 +1,38 @@ +import javax.swing.JFileChooser; +import java.awt.Component; +import javax.swing.JDialog; +import javax.swing.JButton; + +/** + * JPaint File Chooser class opens up a file dialog where you can browse + * for the file you are looking for. You can either choose to save or open the + * file aftewards. + **/ +public class JPaintFileChooser extends JFileChooser +{ + private JDialog fileChooserDialog; + private ExampleFileFilter filter; + + /** + * Creates a default JPaintFileChooser Constructor and sets the extensions + * for files that are only allowed to be opened and saved. + **/ + public JPaintFileChooser(Component parent) + { + // creates a filter and adds the valid extensions on to it + filter = new ExampleFileFilter (); + filter.addExtension("jpg"); + filter.addExtension("gif"); + filter.addExtension("png"); + filter.addExtension("pdf"); + setFileFilter(filter); + // instantiates the file chooser dialog + fileChooserDialog = createDialog(parent); + } + + /** Returns the file chooser dialog. **/ + public JDialog getFileChooserDialog() + { + return fileChooserDialog; + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/JPaintLayoutManager.class b/JPAINT/jpaint/JPaintLayoutManager.class new file mode 100644 index 0000000..8db0fc5 Binary files /dev/null and b/JPAINT/jpaint/JPaintLayoutManager.class differ diff --git a/JPAINT/jpaint/JPaintLayoutManager.java b/JPAINT/jpaint/JPaintLayoutManager.java new file mode 100644 index 0000000..e070daf --- /dev/null +++ b/JPAINT/jpaint/JPaintLayoutManager.java @@ -0,0 +1,112 @@ +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Component; + +/** + * JPaintLayoutManager is an extension of GridBagLayout, this class is a helper + * class for the GridBagLayout. It makes using this layout easier. + **/ +public class JPaintLayoutManager extends GridBagLayout +{ + private GridBagConstraints gbc; + private Component comp; + + /** Creates a default JPaintLayoutManager. **/ + public JPaintLayoutManager() + { + gbc = new GridBagConstraints(); + } + + /** Sets the components necessary to get the layout started. **/ + public void setComponent(Component compo, int gridx, int gridy, int gridwidth, int gridHeight, + int ipadx, int ipady, int weightx, int weighty, int fill) + { + comp = compo; + gbc.gridx = gridx; + gbc.gridy = gridy; + gbc.gridwidth = gridwidth; + gbc.gridheight = gridHeight; + gbc.ipadx = ipadx; + gbc.ipady = ipady; + gbc.weightx = weightx; + gbc.weighty = weighty; + gbc.fill = fill; + setConstraints(compo, gbc); + } + + /** Sets the gridX. **/ + public void setgridx(int gridx) + { + gbc.gridx = gridx; + setConstraints(comp, gbc); + } + + /** Sets the gridY. **/ + public void setGridY(int gridy) + { + gbc.gridy = gridy; + setConstraints(comp, gbc); + } + + /** Sets the gridWidth. **/ + public void setGridWidth(int gridwidth) + { + gbc.gridwidth = gridwidth; + setConstraints(comp, gbc); + } + + /** Sets the gridHeight. **/ + public void setGridHeight(int gridheight) + { + gbc.gridheight = gridheight; + setConstraints(comp, gbc); + } + + /** Sets the ipadX. **/ + public void setIpadx(int ipadx) + { + gbc.ipadx = ipadx; + setConstraints(comp, gbc); + } + + /** Sets the ipadY. **/ + public void setIpady(int ipady) + { + gbc.ipady = ipady; + setConstraints(comp, gbc); + } + + /** Sets the xWeight. **/ + public void setWeightx(int weightx) + { + gbc.weightx = weightx; + setConstraints(comp, gbc); + } + + /** Sets the yWeight. **/ + public void setWeighty(int weighty) + { + gbc.weighty = weighty; + setConstraints(comp, gbc); + } + + /** Sets the anchor. **/ + public void setAnchor(int anchor) + { + gbc.anchor = anchor; + setConstraints(comp, gbc); + } + + /** Resets all the variables to its default settings. **/ + public void reset() + { + gbc.gridx = 0; + gbc.gridy = 0; + gbc.gridwidth = 0; + gbc.gridheight = 0; + gbc.ipadx = 0; + gbc.ipady = 0; + gbc.weightx = 0; + gbc.weighty= 0; + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/Main.class b/JPAINT/jpaint/Main.class new file mode 100644 index 0000000..0e73688 Binary files /dev/null and b/JPAINT/jpaint/Main.class differ diff --git a/JPAINT/jpaint/Main.java b/JPAINT/jpaint/Main.java new file mode 100644 index 0000000..8a2bd44 --- /dev/null +++ b/JPAINT/jpaint/Main.java @@ -0,0 +1,22 @@ +/** + * This is the main class which controls the splash screen loading and starts + * the program. + **/ +public class Main +{ + /** Main Class **/ + public static void main(String [] args) + { + ControlClass control; + //Freeware fware = new Freeware(); + String status = "HELLO !"; + + SplashScreen splash = new SplashScreen("Images\\JPaintSplash.jpg"); + + control = new ControlClass(); + + try{Thread.sleep(1000);}catch(InterruptedException ie){} + splash.closeWindow(); + + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/Main.java~ b/JPAINT/jpaint/Main.java~ new file mode 100644 index 0000000..dedaba0 --- /dev/null +++ b/JPAINT/jpaint/Main.java~ @@ -0,0 +1,22 @@ +/** + * This is the main class which controls the splash screen loading and starts + * the program. + **/ +public class Main +{ + /** Main Class **/ + public static void main(String [] args) + { + ControlClass control; + //Freeware fware = new Freeware(); + String status = "open"; + + SplashScreen splash = new SplashScreen("Images\\JPaintSplash.jpg"); + + control = new ControlClass(); + + try{Thread.sleep(1000);}catch(InterruptedException ie){} + splash.closeWindow(); + + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/MainMenu.class b/JPAINT/jpaint/MainMenu.class new file mode 100644 index 0000000..01e5c2a Binary files /dev/null and b/JPAINT/jpaint/MainMenu.class differ diff --git a/JPAINT/jpaint/MainMenu.java b/JPAINT/jpaint/MainMenu.java new file mode 100644 index 0000000..559345c --- /dev/null +++ b/JPAINT/jpaint/MainMenu.java @@ -0,0 +1,186 @@ +import javax.swing.JMenuBar; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.ActionEvent; +import javax.swing.KeyStroke; +import java.util.Map; +import java.util.HashMap; + +/** + * The MainMenu class will serve as the menu bar for JPaint. + * It will contain all basic functions, i.e. new file, etc. There are keyboard + * shorts cuts to speed up the process. + **/ +public class MainMenu extends JMenuBar +{ + private Map JMenuItemsMap; + private JMenu menuFile, menuEdit, menuView, menuHelp; + private JMenuItem fileNew, fileOpen, fileClose, fileSave, fileSaveAs, + filePrint, fileExit, editCut, editCopy, editPaste, editDelete, viewToolBox, + viewColorBox, imageClear, imageRotate, helpAbout; + + /** + * Creates a default constructor for the MainMenu. Instantiates the menus + * and the menu items and the keys. Creates a maps to make accessors easier. + **/ + public MainMenu() + { + // instantiations for menus, menuitems and hotkeys + initJMenus(); + initJMenuItems(); + initHotKeys(); + + // creates a hashmap and then adds the items to the hashmap + JMenuItemsMap = new HashMap(19); + addJMenuItemsToMap(); + + // adds everything onto the screen + addAll(); + } + + /** Adds the menubar onto the screen. **/ + public void addAll() + { + add(menuFile); + menuFile.add(fileNew); + menuFile.add(fileOpen); + menuFile.add(fileClose); + menuFile.addSeparator(); + menuFile.add(fileSave); + menuFile.add(fileSaveAs); + menuFile.addSeparator(); + menuFile.add(filePrint); + menuFile.addSeparator(); + menuFile.add(fileExit); + + add(menuEdit); + + menuEdit.add(editCut); + menuEdit.add(editCopy); + menuEdit.add(editPaste); + menuEdit.addSeparator(); + menuEdit.add(editDelete); + menuEdit.addSeparator(); + menuEdit.add(imageRotate); + menuEdit.addSeparator(); + menuEdit.add(imageClear); + + add(menuView); + + menuView.add(viewToolBox); + menuView.add(viewColorBox); + + add(menuHelp); + + menuHelp.add(helpAbout); + } + + /** Adds actionlisteners to each of the menu items. **/ + public void addActionListener(ActionListener listener) + { + fileNew.addActionListener(listener); + fileOpen.addActionListener(listener); + fileClose.addActionListener(listener); + fileSave.addActionListener(listener); + fileSaveAs.addActionListener(listener); + filePrint.addActionListener(listener); + fileExit.addActionListener(listener); + + editCut.addActionListener(listener); + editCopy.addActionListener(listener); + editPaste.addActionListener(listener); + editDelete.addActionListener(listener); + + viewToolBox.addActionListener(listener); + viewColorBox.addActionListener(listener); + + imageRotate.addActionListener(listener); + imageClear.addActionListener(listener); + + helpAbout.addActionListener(listener); + } + + /** This method instantiates all the menus. **/ + public void initJMenus() + { + menuFile = new JMenu("File"); + menuEdit = new JMenu("Edit"); + menuView = new JMenu("View"); + menuHelp = new JMenu("About"); + } + + /** This method instantiates all the jmenu items. **/ + public void initJMenuItems() + { + fileNew = new JMenuItem("New"); + fileOpen = new JMenuItem("Open"); + fileClose = new JMenuItem("Close"); + fileSave = new JMenuItem("Save"); + fileSaveAs = new JMenuItem("Save As"); + filePrint = new JMenuItem("Print"); + fileExit = new JMenuItem("Exit"); + + editCut = new JMenuItem("Cut"); + editCopy = new JMenuItem("Copy"); + editPaste = new JMenuItem("Paste"); + editDelete = new JMenuItem("Delete"); + + viewToolBox = new JMenuItem("ToolBox"); + viewColorBox = new JMenuItem("ColorBox"); + + imageClear = new JMenuItem("Clear Image"); + imageRotate = new JMenuItem("Rotate"); + + helpAbout = new JMenuItem("About JPaint"); + } + + /** This method sets all the hot keys for the menu items. **/ + public void initHotKeys() + { + fileNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); + fileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); + fileSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); + fileSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, ActionEvent.CTRL_MASK)); + filePrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); + fileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK)); + fileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); + viewToolBox.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); + viewColorBox.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK)); + editCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); + editCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); + editPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); + editDelete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK)); + imageRotate.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); + imageClear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)); + helpAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)); + } + + /** This method adds the menu items to the map. **/ + public void addJMenuItemsToMap() + { + JMenuItemsMap.put("fileNew", fileNew); + JMenuItemsMap.put("fileOpen", fileOpen); + JMenuItemsMap.put("fileClose", fileClose); + JMenuItemsMap.put("fileSave", fileSave); + JMenuItemsMap.put("fileSaveAs", fileSaveAs); + JMenuItemsMap.put("filePrint", filePrint); + JMenuItemsMap.put("fileExit", fileExit); + JMenuItemsMap.put("editCut", editCut); + JMenuItemsMap.put("editCopy", editCopy); + JMenuItemsMap.put("editPaste", editPaste); + JMenuItemsMap.put("editDelete", editDelete); + JMenuItemsMap.put("viewToolBox", viewToolBox); + JMenuItemsMap.put("viewColorBox", viewColorBox); + JMenuItemsMap.put("imageRotate", imageRotate); + JMenuItemsMap.put("imageClear", imageClear); + JMenuItemsMap.put("helpAbout", helpAbout); + } + + /** Returns the JMenuItem. **/ + public JMenuItem getJMenuItem(String str) + { + return (JMenuItem)JMenuItemsMap.get(str); + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/MainMenu.java~ b/JPAINT/jpaint/MainMenu.java~ new file mode 100644 index 0000000..559345c --- /dev/null +++ b/JPAINT/jpaint/MainMenu.java~ @@ -0,0 +1,186 @@ +import javax.swing.JMenuBar; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.ActionEvent; +import javax.swing.KeyStroke; +import java.util.Map; +import java.util.HashMap; + +/** + * The MainMenu class will serve as the menu bar for JPaint. + * It will contain all basic functions, i.e. new file, etc. There are keyboard + * shorts cuts to speed up the process. + **/ +public class MainMenu extends JMenuBar +{ + private Map JMenuItemsMap; + private JMenu menuFile, menuEdit, menuView, menuHelp; + private JMenuItem fileNew, fileOpen, fileClose, fileSave, fileSaveAs, + filePrint, fileExit, editCut, editCopy, editPaste, editDelete, viewToolBox, + viewColorBox, imageClear, imageRotate, helpAbout; + + /** + * Creates a default constructor for the MainMenu. Instantiates the menus + * and the menu items and the keys. Creates a maps to make accessors easier. + **/ + public MainMenu() + { + // instantiations for menus, menuitems and hotkeys + initJMenus(); + initJMenuItems(); + initHotKeys(); + + // creates a hashmap and then adds the items to the hashmap + JMenuItemsMap = new HashMap(19); + addJMenuItemsToMap(); + + // adds everything onto the screen + addAll(); + } + + /** Adds the menubar onto the screen. **/ + public void addAll() + { + add(menuFile); + menuFile.add(fileNew); + menuFile.add(fileOpen); + menuFile.add(fileClose); + menuFile.addSeparator(); + menuFile.add(fileSave); + menuFile.add(fileSaveAs); + menuFile.addSeparator(); + menuFile.add(filePrint); + menuFile.addSeparator(); + menuFile.add(fileExit); + + add(menuEdit); + + menuEdit.add(editCut); + menuEdit.add(editCopy); + menuEdit.add(editPaste); + menuEdit.addSeparator(); + menuEdit.add(editDelete); + menuEdit.addSeparator(); + menuEdit.add(imageRotate); + menuEdit.addSeparator(); + menuEdit.add(imageClear); + + add(menuView); + + menuView.add(viewToolBox); + menuView.add(viewColorBox); + + add(menuHelp); + + menuHelp.add(helpAbout); + } + + /** Adds actionlisteners to each of the menu items. **/ + public void addActionListener(ActionListener listener) + { + fileNew.addActionListener(listener); + fileOpen.addActionListener(listener); + fileClose.addActionListener(listener); + fileSave.addActionListener(listener); + fileSaveAs.addActionListener(listener); + filePrint.addActionListener(listener); + fileExit.addActionListener(listener); + + editCut.addActionListener(listener); + editCopy.addActionListener(listener); + editPaste.addActionListener(listener); + editDelete.addActionListener(listener); + + viewToolBox.addActionListener(listener); + viewColorBox.addActionListener(listener); + + imageRotate.addActionListener(listener); + imageClear.addActionListener(listener); + + helpAbout.addActionListener(listener); + } + + /** This method instantiates all the menus. **/ + public void initJMenus() + { + menuFile = new JMenu("File"); + menuEdit = new JMenu("Edit"); + menuView = new JMenu("View"); + menuHelp = new JMenu("About"); + } + + /** This method instantiates all the jmenu items. **/ + public void initJMenuItems() + { + fileNew = new JMenuItem("New"); + fileOpen = new JMenuItem("Open"); + fileClose = new JMenuItem("Close"); + fileSave = new JMenuItem("Save"); + fileSaveAs = new JMenuItem("Save As"); + filePrint = new JMenuItem("Print"); + fileExit = new JMenuItem("Exit"); + + editCut = new JMenuItem("Cut"); + editCopy = new JMenuItem("Copy"); + editPaste = new JMenuItem("Paste"); + editDelete = new JMenuItem("Delete"); + + viewToolBox = new JMenuItem("ToolBox"); + viewColorBox = new JMenuItem("ColorBox"); + + imageClear = new JMenuItem("Clear Image"); + imageRotate = new JMenuItem("Rotate"); + + helpAbout = new JMenuItem("About JPaint"); + } + + /** This method sets all the hot keys for the menu items. **/ + public void initHotKeys() + { + fileNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); + fileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); + fileSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); + fileSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, ActionEvent.CTRL_MASK)); + filePrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); + fileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK)); + fileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); + viewToolBox.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); + viewColorBox.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK)); + editCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); + editCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); + editPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); + editDelete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK)); + imageRotate.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); + imageClear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)); + helpAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)); + } + + /** This method adds the menu items to the map. **/ + public void addJMenuItemsToMap() + { + JMenuItemsMap.put("fileNew", fileNew); + JMenuItemsMap.put("fileOpen", fileOpen); + JMenuItemsMap.put("fileClose", fileClose); + JMenuItemsMap.put("fileSave", fileSave); + JMenuItemsMap.put("fileSaveAs", fileSaveAs); + JMenuItemsMap.put("filePrint", filePrint); + JMenuItemsMap.put("fileExit", fileExit); + JMenuItemsMap.put("editCut", editCut); + JMenuItemsMap.put("editCopy", editCopy); + JMenuItemsMap.put("editPaste", editPaste); + JMenuItemsMap.put("editDelete", editDelete); + JMenuItemsMap.put("viewToolBox", viewToolBox); + JMenuItemsMap.put("viewColorBox", viewColorBox); + JMenuItemsMap.put("imageRotate", imageRotate); + JMenuItemsMap.put("imageClear", imageClear); + JMenuItemsMap.put("helpAbout", helpAbout); + } + + /** Returns the JMenuItem. **/ + public JMenuItem getJMenuItem(String str) + { + return (JMenuItem)JMenuItemsMap.get(str); + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/Makefile b/JPAINT/jpaint/Makefile new file mode 100644 index 0000000..6a0d13d --- /dev/null +++ b/JPAINT/jpaint/Makefile @@ -0,0 +1,18 @@ + +JFLAGS = -g +JC = javac +RM = rm -f +.SUFFIXES: .java .class +.java.class: + $(JC) $(JFLAGS) $*.java + +CLASSES = \ + *.java \ + Main.java + +default: classes + +classes: $(CLASSES:.java=.class) + +clean: + $(RM) *.class diff --git a/JPAINT/jpaint/README.mdown b/JPAINT/jpaint/README.mdown new file mode 100644 index 0000000..17d4172 --- /dev/null +++ b/JPAINT/jpaint/README.mdown @@ -0,0 +1,10 @@ +JPaint +====== + +JPaint is an art development program created by Java. It has the standard functions of MSPaint with a few variations and some unique features. +Created: June 15/2005 +Tested on => Windows XP (Java 1.4.2) + +Disclaimer: This code might not work anymore as it was created several years ago. + +[![](http://i44.tinypic.com/lcd4j.png)](http://i44.tinypic.com/lcd4j.png) diff --git a/JPAINT/jpaint/RandomPoint.class b/JPAINT/jpaint/RandomPoint.class new file mode 100644 index 0000000..ee420e5 Binary files /dev/null and b/JPAINT/jpaint/RandomPoint.class differ diff --git a/JPAINT/jpaint/RandomPoint.java b/JPAINT/jpaint/RandomPoint.java new file mode 100644 index 0000000..3957567 --- /dev/null +++ b/JPAINT/jpaint/RandomPoint.java @@ -0,0 +1,75 @@ +import java.awt.Color; +/** + * RandomPoint class is similar to a point with a color. It stores points, + * it is used for the random drawing method. + **/ + public class RandomPoint +{ + private Color c; + private int x,y,width,height; + + /** Creates a default RandomPoint. **/ + public RandomPoint(){} + + /** Creates a RandomPoint and takes in the screen sizes width and height. **/ + public RandomPoint(int width, int height) + { + // takes in variables and then randomly generates a starting x + // and y location + this.width = width; + this.height = height; + x = (int)(Math.random()*width); + y = (int)(Math.random()*height); + } + + /** Figures out the next x location. **/ + public int nextX() + { + // checks if its a negative of a positive number then generates a random + // point up to 50 places away, if its out of bounds then it returns to + // the bounds + int sign = (int)(Math.random()*2); + if(sign == 0) + x = x + (int)(Math.random()*50+1); + else + x = x - (int)(Math.random()*50+1); + + if(x < 0) + x = 0; + if(x > width) + x = width; + + return x; + } + + /** Figures out the next y location. **/ + public int nextY() + { + // checks if its a negative of a positive number then generates a random + // point up to 50 places away, if its out of bounds then it returns to + // the bounds + int sign = (int)(Math.random()*2); + if(sign == 0) + y = y + (int)(Math.random()*200+1); + else + y = y - (int)(Math.random()*200+1); + + if(y < 0) + y = 0; + if(y > height) + y = height; + + return y; + } + + /** This method returns a random color. **/ + public Color getColor() + { + return new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)); + } + + /** This method returns the x value. **/ + public int getX(){return x;} + /** This method returns the y value. **/ + public int getY(){return y;} +} \ No newline at end of file diff --git a/JPAINT/jpaint/SplashScreen.class b/JPAINT/jpaint/SplashScreen.class new file mode 100644 index 0000000..34bf841 Binary files /dev/null and b/JPAINT/jpaint/SplashScreen.class differ diff --git a/JPAINT/jpaint/SplashScreen.java b/JPAINT/jpaint/SplashScreen.java new file mode 100644 index 0000000..76e67d4 --- /dev/null +++ b/JPAINT/jpaint/SplashScreen.java @@ -0,0 +1,57 @@ +import javax.swing.JLabel; +import javax.swing.ImageIcon; +import javax.swing.JPanel; +import java.awt.Dimension; +import java.awt.BorderLayout; +import java.awt.Window; +import java.awt.Frame; +import java.awt.Color; +import java.awt.Toolkit; + +/** + * Splash Screen loads up for this program. Before the program runs a screen + * with an image pops up for a second, then it loads the rest of the program. + **/ +public class SplashScreen extends Window +{ + JLabel lblStatus = new JLabel("LOADING JPaint is opening..."); + + /** + * Creates a default constructor. Creates a new frame and adds the + * background image onto it. + **/ + public SplashScreen(String strImageFileName) + { + super(new Frame()); + + ImageIcon imageScreen = new ImageIcon(strImageFileName); + JLabel lblImage = new JLabel(imageScreen); + lblStatus.setBackground(Color.black); + lblStatus.setForeground(Color.white); + JPanel pnlIm = new JPanel(new BorderLayout()); + pnlIm.add(lblImage, BorderLayout.CENTER); + pnlIm.add(lblStatus, BorderLayout.SOUTH); + pnlIm.setBackground(Color.black); + add(pnlIm); + pack(); + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension windowSize = getSize(); + this.setBounds((screenSize.width - windowSize.width)/2, (screenSize.height - windowSize.height)/2, windowSize.width, windowSize.height); + + setVisible(true); + } + + /** Updates the status bar with the new string. **/ + public void updateStatus(String temp) + { + lblStatus.setText(temp); + setVisible(true); + } + + /** Closes the splash screen. **/ + public void closeWindow() + { + dispose(); + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/SplashScreen.java~ b/JPAINT/jpaint/SplashScreen.java~ new file mode 100644 index 0000000..8b8c87d --- /dev/null +++ b/JPAINT/jpaint/SplashScreen.java~ @@ -0,0 +1,57 @@ +import javax.swing.JLabel; +import javax.swing.ImageIcon; +import javax.swing.JPanel; +import java.awt.Dimension; +import java.awt.BorderLayout; +import java.awt.Window; +import java.awt.Frame; +import java.awt.Color; +import java.awt.Toolkit; + +/** + * Splash Screen loads up for this program. Before the program runs a screen + * with an image pops up for a second, then it loads the rest of the program. + **/ +public class SplashScreen extends Window +{ + JLabel lblStatus = new JLabel("LOADING JPaint is opening..."); + + /** + * Creates a default constructor. Creates a new frame and adds the + * background image onto it. + **/ + public SplashScreen(String strImageFileName) + { + super(new Frame()); + + ImageIcon imageScreen = new ImageIcon(strImageFileName); + JLabel lblImage = new JLabel(imageScreen); + lblStatus.setBackground(Color.black); + lblStatus.setForeground(Color.black); + JPanel pnlIm = new JPanel(new BorderLayout()); + pnlIm.add(lblImage, BorderLayout.CENTER); + pnlIm.add(lblStatus, BorderLayout.SOUTH); + pnlIm.setBackground(Color.black); + add(pnlIm); + pack(); + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension windowSize = getSize(); + this.setBounds((screenSize.width - windowSize.width)/2, (screenSize.height - windowSize.height)/2, windowSize.width, windowSize.height); + + setVisible(true); + } + + /** Updates the status bar with the new string. **/ + public void updateStatus(String temp) + { + lblStatus.setText(temp); + setVisible(true); + } + + /** Closes the splash screen. **/ + public void closeWindow() + { + dispose(); + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/SubToolBox$FillListener.class b/JPAINT/jpaint/SubToolBox$FillListener.class new file mode 100644 index 0000000..23ba36a Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$FillListener.class differ diff --git a/JPAINT/jpaint/SubToolBox$JRandom.class b/JPAINT/jpaint/SubToolBox$JRandom.class new file mode 100644 index 0000000..3818654 Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$JRandom.class differ diff --git a/JPAINT/jpaint/SubToolBox$JSprayListener.class b/JPAINT/jpaint/SubToolBox$JSprayListener.class new file mode 100644 index 0000000..192c73c Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$JSprayListener.class differ diff --git a/JPAINT/jpaint/SubToolBox$JTextListener.class b/JPAINT/jpaint/SubToolBox$JTextListener.class new file mode 100644 index 0000000..2cca8db Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$JTextListener.class differ diff --git a/JPAINT/jpaint/SubToolBox$LineListener.class b/JPAINT/jpaint/SubToolBox$LineListener.class new file mode 100644 index 0000000..ad26604 Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$LineListener.class differ diff --git a/JPAINT/jpaint/SubToolBox$NormalListener.class b/JPAINT/jpaint/SubToolBox$NormalListener.class new file mode 100644 index 0000000..972db98 Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$NormalListener.class differ diff --git a/JPAINT/jpaint/SubToolBox$OutlineListener.class b/JPAINT/jpaint/SubToolBox$OutlineListener.class new file mode 100644 index 0000000..3b8e6b0 Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$OutlineListener.class differ diff --git a/JPAINT/jpaint/SubToolBox$OvalListener.class b/JPAINT/jpaint/SubToolBox$OvalListener.class new file mode 100644 index 0000000..11cb2e0 Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$OvalListener.class differ diff --git a/JPAINT/jpaint/SubToolBox$RectListener.class b/JPAINT/jpaint/SubToolBox$RectListener.class new file mode 100644 index 0000000..4e49dd8 Binary files /dev/null and b/JPAINT/jpaint/SubToolBox$RectListener.class differ diff --git a/JPAINT/jpaint/SubToolBox.class b/JPAINT/jpaint/SubToolBox.class new file mode 100644 index 0000000..f0d33fd Binary files /dev/null and b/JPAINT/jpaint/SubToolBox.class differ diff --git a/JPAINT/jpaint/SubToolBox.java b/JPAINT/jpaint/SubToolBox.java new file mode 100644 index 0000000..57f4e71 --- /dev/null +++ b/JPAINT/jpaint/SubToolBox.java @@ -0,0 +1,269 @@ +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.ImageIcon; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +/** + * SubToolBox contains special features for certain differnet tools. Such as + * setting the line width, setting the radius of the spray, choosing a brush, + * selecting whether you want to draw a normal, outline or filled shape. + */ +public class SubToolBox extends JPanel +{ + private JButton current; + + /** Creates a default SubToolBox. **/ + public SubToolBox() + { + // sets the default stuff and then starts off the choose panel method + setSize(40,66); + setLayout(null); + setVisible(true); + choosePanel(); + } + + /** Handles a switch in the toolbox panel with the corresponding tool. **/ + public void choosePanel() + { + // removes the current panel and adds the one corresponding to the selected tool. + removeAll(); + int tbs = ToolBox.toolSelected; + if(tbs == ToolBox.RECTANGLE || tbs == ToolBox.OVAL || tbs == ToolBox.ROUNDRECTANGLE) + shapePanel(); + else if(tbs == ToolBox.LINE) + linePanel(); + else if(tbs == ToolBox.SPRAY) + sprayPanel(); + else if(tbs == ToolBox.BRUSH) + brushPanel(); + else if(tbs == ToolBox.DRAG) + dragPanel(); + else if(tbs == ToolBox.RANDOMDRAW) + randomPanel(); + repaint(); + } + + /** Allows user to select settings for drawing random lines. **/ + public void randomPanel() + { + JTextField field = new JTextField(); + JButton submit = new JButton(); + field.setBounds(25,0,40,22); + submit.setBounds(25,22,40,22); + add(field); + add(submit); + submit.addActionListener(new JRandom(field)); + } + + /** Allows the user to set the thickness of a line. **/ + public void linePanel() + { + // creates a textbox and a button to submit the size of the line + JTextField field = new JTextField(); + JButton submit = new JButton(); + field.setBounds(25,0,40,22); + submit.setBounds(25,22,40,22); + add(field); + add(submit); + submit.addActionListener(new JTextListener(field)); + } + + /** Allows the user to set the size of the spray. **/ + public void sprayPanel() + { + // creates a field to set the size of the spray + JTextField field = new JTextField(); + JButton submit = new JButton(); + field.setBounds(25,0,40,22); + submit.setBounds(25,22,40,22); + add(field); + add(submit); + submit.addActionListener(new JSprayListener(field)); + } + + /** Allows the user to select the item to drag. **/ + public void dragPanel() + { + JButton rect = new JButton(new ImageIcon("Images//box.gif")); + JButton oval = new JButton(new ImageIcon("Images//oval.gif")); + rect.setSelectedIcon(new ImageIcon("Images//boxPressed.gif")); + oval.setSelectedIcon(new ImageIcon("Images//ovalPressed.gif")); + rect.setBounds(25,0,40,22); + oval.setBounds(25,22,40,22); + add(rect); + add(oval); + rect.addActionListener(new RectListener(rect)); + oval.addActionListener(new OvalListener(oval)); + JButton line = new JButton(new ImageIcon("Images//line.gif")); + line.setSelectedIcon(new ImageIcon("Images//linePressed.gif")); + line.setBounds(25,44,40,22); + add(line); + line.addActionListener(new LineListener(line)); + setCurrent(line); + DrawingCanvas.extraOperations = DrawingCanvas.LINE; + } + + /** Allows the user to select a style of brush. **/ + public void brushPanel() + { + // loads up the images when its pressed and when its not and sets + // its location and adds it to the screen. + JButton rect = new JButton(new ImageIcon("Images//box.gif")); + JButton oval = new JButton(new ImageIcon("Images//oval.gif")); + rect.setSelectedIcon(new ImageIcon("Images//boxPressed.gif")); + oval.setSelectedIcon(new ImageIcon("Images//ovalPressed.gif")); + rect.setBounds(25,0,40,22); + oval.setBounds(25,22,40,22); + add(rect); + add(oval); + rect.addActionListener(new RectListener(rect)); + oval.addActionListener(new OvalListener(oval)); + setCurrent(rect); + DrawingCanvas.extraOperations = DrawingCanvas.RECT; + } + + /** Creates a shapes panel and allows the user to choose the type. **/ + public void shapePanel() + { + // loads up the images when its pressed and when its not and sets + // its location and adds it to the screen. + JButton normal = new JButton(new ImageIcon("Images//normal.gif")); + JButton fill = new JButton(new ImageIcon("Images//fill.gif")); + JButton outline = new JButton(new ImageIcon("Images//outline.gif")); + normal.setSelectedIcon(new ImageIcon("Images//normalPressed.gif")); + fill.setSelectedIcon(new ImageIcon("Images//fillPressed.gif")); + outline.setSelectedIcon(new ImageIcon("Images//outlinePressed.gif")); + normal.setBounds(25,0,40,22); + fill.setBounds(25,22,40,22); + outline.setBounds(25,44,40,22); + add(normal); + add(fill); + add(outline); + normal.addActionListener(new NormalListener(normal)); + fill.addActionListener(new FillListener(fill)); + outline.addActionListener(new OutlineListener(outline)); + setCurrent(normal); + DrawingCanvas.extraOperations = DrawingCanvas.NORMAL; + } + + /** Sets the current special selection to the field. **/ + public void setCurrent(JButton b) + { + current = b; + current.setSelected(true); + } + /** Rectangle Listener, if button is pressed change field. **/ + public class RectListener implements ActionListener + { + private JButton b; + + public RectListener(JButton b){this.b=b;} + + public void actionPerformed(ActionEvent e) + { + current.setSelected(false); + setCurrent(b); + DrawingCanvas.extraOperations = DrawingCanvas.RECT; + } + } + /** Oval Listener, if button is pressed change field. **/ + public class OvalListener implements ActionListener + { + private JButton b; + + public OvalListener(JButton b){this.b=b;} + + public void actionPerformed(ActionEvent e) + { + current.setSelected(false); + setCurrent(b); + DrawingCanvas.extraOperations = DrawingCanvas.OVAL; + } + } + /** Line Listener, if button is pressed change field. **/ + public class LineListener implements ActionListener + { + private JButton b; + + public LineListener(JButton b){this.b=b;} + + public void actionPerformed(ActionEvent e) + { + current.setSelected(false); + setCurrent(b); + DrawingCanvas.extraOperations = DrawingCanvas.LINE; + } + } + /** Spray Listener, changes size of spray and brush. **/ + public class JSprayListener implements ActionListener + { + private JTextField f; + public JSprayListener(JTextField f){this.f=f;} + public void actionPerformed(ActionEvent e) + { + DrawingCanvas.radius = Math.abs(Integer.parseInt(f.getText())); + } + } + /** Random Listener, changes amount of lines. **/ + public class JRandom implements ActionListener + { + private JTextField f; + public JRandom (JTextField f){this.f=f;} + public void actionPerformed(ActionEvent e) + { + DrawingCanvas.amtLines = Integer.parseInt(f.getText()); + } + } + /** Text Listener, changes size of line. **/ + public class JTextListener implements ActionListener + { + private JTextField f; + public JTextListener(JTextField f){this.f=f;} + public void actionPerformed(ActionEvent e) + { + DrawingCanvas.lineWidth = Integer.parseInt(f.getText()); + } + } + /** Normal Listener, extra operations is set to normal. **/ + public class NormalListener implements ActionListener + { + private JButton b; + public NormalListener(JButton b){this.b=b;} + public void actionPerformed(ActionEvent e) + { + current.setSelected(false); + setCurrent(b); + DrawingCanvas.extraOperations = DrawingCanvas.NORMAL; + } + } + /** Fill Listener, extra operations is set to fill. **/ + public class FillListener implements ActionListener + { + private JButton b; + + public FillListener(JButton b){this.b=b;} + + public void actionPerformed(ActionEvent e) + { + current.setSelected(false); + setCurrent(b); + DrawingCanvas.extraOperations = DrawingCanvas.FILL; + } + } + /** Outline Listener, extra operations is set to outline. **/ + public class OutlineListener implements ActionListener + { + private JButton b; + + public OutlineListener(JButton b){this.b=b;} + + public void actionPerformed(ActionEvent e) + { + current.setSelected(false); + setCurrent(b); + DrawingCanvas.extraOperations = DrawingCanvas.OUTLINE; + } + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/TabbedPanel.class b/JPAINT/jpaint/TabbedPanel.class new file mode 100644 index 0000000..725f2a5 Binary files /dev/null and b/JPAINT/jpaint/TabbedPanel.class differ diff --git a/JPAINT/jpaint/TabbedPanel.java b/JPAINT/jpaint/TabbedPanel.java new file mode 100644 index 0000000..77baad4 --- /dev/null +++ b/JPAINT/jpaint/TabbedPanel.java @@ -0,0 +1,38 @@ +import javax.swing.JTabbedPane; +import java.awt.event.MouseListener; +import java.awt.event.MouseEvent; + +/** + * TabbedPanel holds all the drawing canvases together so you can have multiple + * documents opened all at once. This gives you multiple worksheets to work with. + **/ +public class TabbedPanel extends JTabbedPane implements MouseListener +{ + /** Creates a default TabbedPanel. **/ + //public TabbedPanel(){} + + /** Creates a TabbedPanel witht a unique id **/ + public TabbedPanel(int tabbedPlacement) + { + super(tabbedPlacement); + addMouseListener(this); + } + + /** If the mouse is pressed then change the currentFile id **/ + public void mousePressed(MouseEvent e) + { + ControlClass.currentFile = ((JTabbedPane)e.getSource()).getSelectedIndex(); + } + + /** Invoked when the mouse is clicked. **/ + public void mouseClicked(MouseEvent e){} + + /** Invoked when the mouse has entered a component. **/ + public void mouseEntered(MouseEvent e){} + + /** Invoked when the moues has exited a component. **/ + public void mouseExited(MouseEvent e){} + + /** Invoked when the mouse has been released. **/ + public void mouseReleased(MouseEvent e){} +} \ No newline at end of file diff --git a/JPAINT/jpaint/TextDialog.class b/JPAINT/jpaint/TextDialog.class new file mode 100644 index 0000000..9801a0d Binary files /dev/null and b/JPAINT/jpaint/TextDialog.class differ diff --git a/JPAINT/jpaint/TextDialog.java b/JPAINT/jpaint/TextDialog.java new file mode 100644 index 0000000..e577fd5 --- /dev/null +++ b/JPAINT/jpaint/TextDialog.java @@ -0,0 +1,90 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JTextField; +import java.awt.Graphics; +import java.awt.Frame; + +/** + * A TextDialog is created where you can input a string and there is an advanced + * setting method. Once you submit you draw the string onto the screen. + **/ +public class TextDialog extends JDialog implements ActionListener +{ + private JButton submit, advanced; + private JTextField text, xCoord, yCoord; + private JLabel x, y; + private FontChooser adText; + + /** Creates a TextDialog with parameters of the x and y coordinates clicked. **/ + public TextDialog(int xValue, int yValue) + { + // sets the title and other default settings + setTitle("Text Setup"); + getContentPane().setLayout(null); + setSize(160,200); + setVisible(true); + initialize(xValue,yValue); + } + /** + * Instantiates the fields for the text dialog, such as the text field, + * the x and y coordinate field and the advanced settings. + **/ + public void initialize(int xValue, int yValue) + { + x = new JLabel("X: "); + x.setBounds(20,50,20,20); + getContentPane().add(x); + + y = new JLabel("Y: "); + y.setBounds(20,80,20,20); + getContentPane().add(y); + + text = new JTextField(); + text.setBounds(20,20,120,20); + getContentPane().add(text); + + xCoord = new JTextField(xValue+""); + xCoord.setBounds(40,50,100,20); + getContentPane().add(xCoord); + + yCoord = new JTextField(yValue+""); + yCoord.setBounds(40,80,100,20); + getContentPane().add(yCoord); + + submit = new JButton("SUBMIT"); + submit.setBounds(20,110,120,20); + getContentPane().add(submit); + submit.addActionListener(this); + + advanced = new JButton("Advanced"); + advanced.setBounds(20,140,120,20); + getContentPane().add(advanced); + advanced.addActionListener(this); + + Frame[] frames = ControlClass.getFrames(); + adText = new FontChooser(frames[0]); + } + + /** + * Invoked if action performed. If the button clicked is submit then it + * will draw it to the screen other wise if its the advanced button then + * the advanced settings will pop up. + **/ + public void actionPerformed(ActionEvent e) + { + JButton hit = (JButton)e.getSource(); + if(hit == submit) + { + ((DrawingCanvas)ControlClass.canvas.get(ControlClass.currentFile)).textOperation2(text.getText(), + Integer.parseInt(xCoord.getText()),Integer.parseInt(yCoord.getText()), adText.getSelectedFont()); + setVisible(false); + } + if(hit == advanced) + { + adText.setVisible(true); + } + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/ToolBar.class b/JPAINT/jpaint/ToolBar.class new file mode 100644 index 0000000..8ac051f Binary files /dev/null and b/JPAINT/jpaint/ToolBar.class differ diff --git a/JPAINT/jpaint/ToolBar.java b/JPAINT/jpaint/ToolBar.java new file mode 100644 index 0000000..3f56f0f --- /dev/null +++ b/JPAINT/jpaint/ToolBar.java @@ -0,0 +1,16 @@ +import javax.swing.JPanel; +/** + * ToolBar class is a panel which holds the toolbox in it. + **/ +public class ToolBar extends JPanel +{ + private ToolBox toolBox; + + /** Creates a default ToolBar which creates a new toolbox. **/ + public ToolBar() + { + setLayout(null); + toolBox = new ToolBox(); + add(toolBox); + } +} \ No newline at end of file diff --git a/JPAINT/jpaint/ToolBox.class b/JPAINT/jpaint/ToolBox.class new file mode 100644 index 0000000..6569160 Binary files /dev/null and b/JPAINT/jpaint/ToolBox.class differ diff --git a/JPAINT/jpaint/ToolBox.java b/JPAINT/jpaint/ToolBox.java new file mode 100644 index 0000000..8cf2a11 --- /dev/null +++ b/JPAINT/jpaint/ToolBox.java @@ -0,0 +1,54 @@ +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Image; +import javax.swing.JPanel; + +/** + * ToolBox this is another main component of paint. This holds all the tools and + * all the different things can be done. + **/ +public class ToolBox extends JPanel +{ + public static int RANDOMDRAW = 0, ERASER = 1, EYEDROPPER = 2, PENCIL = 3, + SPRAY = 4, LINE = 5, RECTANGLE = 6, OVAL = 7, ROUNDRECTANGLE = 8, + POLYGON = 9, CURVELINE = 10, TEXT = 11, BRUSH = 12, DRAG = 13, FILL = 14, + SELECT = 15; + public static ToolIcon[] tools; + public static int toolSelected; + + /** Creates a default ToolBox. **/ + public ToolBox() + { + // sets the normal settings and calls the run method + setLayout(null); + setSize(200,300); + run(); + } + + /** + * Instantiates the tools and creates them in an array of ToolIcons. Sets + * bounds to them and a graphic and adds them to the screen. + **/ + public void run() + { + // instantiates and sets the background to white and then runs through + // a loop to go through 16 tools and sets a image to each one and sets + // a location and size for it + tools = new ToolIcon[16]; + setBackground(Color.white); + for(int i=0;i