home *** CD-ROM | disk | FTP | other *** search
Java Source | 2001-06-23 | 11.9 KB | 393 lines |
- /**
- * mainFrame.java
- *
- * Title: ASCII Shop
- * Description: The goal of this program is to provide many functionalities of photoshop, with ASCII art.
- * @author Expotech
- * @version
- */
-
- package asciiShop;
-
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
-
- public class mainFrame extends java.awt.Frame {
-
- char[][] artBuffer2;
- int useLength, length1, length2;
- int globalCount = 0;
- PrintWriter writeToFile;
- String bigString;
- int i, j, k;
- int countForOpenFile, countForOpenFileSave;
- FileDialog newFile;
- String pathToFile;
- String file;
- BufferedReader openFile;
- String[] artBuffer;
- String[][] layerBuffer;
-
-
- // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
- // every time the form is saved. All manual changes will be overwritten.
- // BEGIN GENERATED CODE
- // member declarations
- java.awt.TextArea fileBuffer = new java.awt.TextArea();
- java.awt.List layers = new java.awt.List();
- java.awt.MenuBar menuBar1 = new java.awt.MenuBar();
- java.awt.Menu menuFile = new java.awt.Menu();
- java.awt.MenuItem menuFileOpen = new java.awt.MenuItem();
- java.awt.MenuItem menuFileWriteOut = new java.awt.MenuItem();
- java.awt.MenuItem menuFileQuit = new java.awt.MenuItem();
- java.awt.MenuItem menuFileRefreshArt = new java.awt.MenuItem();
- java.awt.MenuItem menuFileReplaceCharacters = new java.awt.MenuItem();
- java.awt.Menu menuLayers = new java.awt.Menu();
- java.awt.MenuItem menuLayersAddLayer = new java.awt.MenuItem();
- java.awt.MenuItem menuLayersRemoveLayer = new java.awt.MenuItem();
- java.awt.MenuItem menuLayersRedrawLayers = new java.awt.MenuItem();
- java.awt.Menu menumirror = new java.awt.Menu();
- java.awt.MenuItem menumirrorSideWays = new java.awt.MenuItem();
- java.awt.MenuItem menumirrorFlipVerticle = new java.awt.MenuItem();
- java.awt.Menu menuLineTools = new java.awt.Menu();
- java.awt.MenuItem menuLineToolsVerticleLine = new java.awt.MenuItem();
- java.awt.MenuItem menuLineToolsHorizantalLine = new java.awt.MenuItem();
- // END GENERATED CODE
-
- public mainFrame() {
- }
-
- public void initComponents() throws Exception {
- // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
- // every time the form is saved. All manual changes will be overwritten.
- // BEGIN GENERATED CODE
- // the following code sets the frame's initial state
-
- fileBuffer.setLocation(new java.awt.Point(60, 70));
- fileBuffer.setVisible(true);
- fileBuffer.setSize(new java.awt.Dimension(480, 360));
-
- layers.setLocation(new java.awt.Point(570, 270));
- layers.setVisible(true);
- layers.setSize(new java.awt.Dimension(130, 160));
-
- menuBar1.add(menuFile);
- menuBar1.add(menuLayers);
- menuBar1.add(menumirror);
- menuBar1.add(menuLineTools);
-
- menuFile.setLabel("File");
- menuFile.add(menuFileOpen);
- menuFile.add(menuFileWriteOut);
- menuFile.add(menuFileQuit);
- menuFile.add(menuFileRefreshArt);
- menuFile.add(menuFileReplaceCharacters);
-
- menuFileOpen.setLabel("Open");
-
- menuFileWriteOut.setLabel("Write Out");
-
- menuFileQuit.setLabel("Quit");
-
- menuFileRefreshArt.setLabel("Refresh Art");
-
- menuFileReplaceCharacters.setLabel("Replace Characters");
-
- menuLayers.setLabel("Layers");
- menuLayers.add(menuLayersAddLayer);
- menuLayers.add(menuLayersRemoveLayer);
- menuLayers.add(menuLayersRedrawLayers);
-
- menuLayersAddLayer.setLabel("Add Layer");
-
- menuLayersRemoveLayer.setLabel("Remove Layer");
-
- menuLayersRedrawLayers.setLabel("Redraw Layers");
-
- menumirror.setLabel("mirror");
- menumirror.add(menumirrorSideWays);
- menumirror.add(menumirrorFlipVerticle);
-
- menumirrorSideWays.setLabel("invert");
-
- menumirrorFlipVerticle.setLabel("Flip Characters Verticle");
-
- menuLineTools.setLabel("Line Tools");
- menuLineTools.add(menuLineToolsVerticleLine);
- menuLineTools.add(menuLineToolsHorizantalLine);
-
- menuLineToolsVerticleLine.setLabel("Verticle Line");
-
- menuLineToolsHorizantalLine.setLabel("Horizantal Line");
-
- setLocation(new java.awt.Point(5, 40));
- setTitle("asciiShop.mainFrame");
- setLayout(null);
- setMenuBar(menuBar1);
- setSize(new java.awt.Dimension(736, 520));
- add(fileBuffer);
- add(layers);
-
-
- fileBuffer.addTextListener(new java.awt.event.TextListener() {
- public void textValueChanged(java.awt.event.TextEvent e) {
- fileBufferTextValueChanged(e);
- }
- });
- layers.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent e) {
- layersItemStateChanged(e);
- }
- });
- menuFileOpen.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuFileOpenActionPerformed(e);
- }
- });
- menuFileWriteOut.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuFileWriteOutActionPerformed(e);
- }
- });
- menuFileRefreshArt.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuFileRefreshArtActionPerformed(e);
- }
- });
- menuFileReplaceCharacters.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuFileReplaceCharactersActionPerformed(e);
- }
- });
- menuLayersAddLayer.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuLayersAddLayerActionPerformed(e);
- }
- });
- menumirrorSideWays.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menumirrorSideWaysActionPerformed(e);
- }
- });
- menumirrorFlipVerticle.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menumirrorFlipVerticleActionPerformed(e);
- }
- });
- menuLineToolsVerticleLine.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuLineToolsVerticleLineActionPerformed(e);
- }
- });
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosing(java.awt.event.WindowEvent e) {
- thisWindowClosing(e);
- }
- });
-
- // END GENERATED CODE
- }
-
- private boolean mShown = false;
-
- public void addNotify() {
- super.addNotify();
-
- if (mShown)
- return;
-
- // move components to account for insets
- Insets insets = getInsets();
- Component[] components = getComponents();
- for (int i = 0; i < components.length; i++) {
- Point location = components[i].getLocation();
- location.move(location.x, location.y + insets.top);
- components[i].setLocation(location);
- }
-
- mShown = true;
- }
-
- // Close the window when the close box is clicked
- void thisWindowClosing(java.awt.event.WindowEvent e) {
- setVisible(false);
- dispose();
- System.exit(0);
- }
-
- public void list1ItemStateChanged(java.awt.event.ItemEvent e) {
- }
-
- public void layersItemStateChanged(java.awt.event.ItemEvent e) {
- }
-
- public void fileBufferTextValueChanged(java.awt.event.TextEvent e) {
- }
-
- public void menuFileOpenActionPerformed(java.awt.event.ActionEvent e) {
- bigString = new String("");
- countForOpenFile = 0; // To get the number of lines to use with artBuffer
- newFile = new FileDialog(this, "Open File", FileDialog.LOAD); // Opens and open file dialog box
- newFile.setVisible(true);
- pathToFile = newFile.getDirectory();
- file = newFile.getFile();
- artBuffer = new String[200];
- try {
- System.out.println(pathToFile + file);
- openFile = new BufferedReader(new FileReader(pathToFile + file));
- } catch(FileNotFoundException badStuff) {
- System.out.println("The file could not be found... DAMN MICROSOFT!!!");
- }
- try {
- while( (artBuffer[countForOpenFile] = openFile.readLine()).equals("***end***") == false)
- {
- countForOpenFile++;
- }
- } catch(IOException badStuff) {
- System.out.println("HOW THE HELL DiD YOU GET THIS ERROR!?");
- }
- System.out.println("How many lines in the art: " + countForOpenFile);
- for(i = 0; i < countForOpenFile; i++) {
- bigString = bigString + artBuffer[i] + "\n";
- }
- fileBuffer.setText(bigString);
- countForOpenFileSave = countForOpenFile;
- }
-
- public void menuFileWriteOutActionPerformed(java.awt.event.ActionEvent e) {
- newFile = new FileDialog(this, "Save File", FileDialog.SAVE);
- newFile.setVisible(true);
- pathToFile = newFile.getDirectory();
- file = newFile.getFile();
- try {
- writeToFile = new PrintWriter(new FileWriter(pathToFile + file), true);
- System.out.println("Wrote to file: " + pathToFile + file);
- } catch(IOException badStuff) {
- System.out.println("GODDAMN HOW THE HELL DID YOU MANAGE TO GET THIS ERROR!?");
- }
- bigString = fileBuffer.getText();
- writeToFile.println(bigString + "\n***end***");
- System.out.println("Wrote out to file: " + pathToFile + file + "\n" + bigString + "***end***");
- return;
- }
-
- public void menuLayersAddLayerActionPerformed(java.awt.event.ActionEvent e) {
- {
- String [][] temp;
-
- temp = layerBuffer;
- layerBuffer = new String[globalCount+1][200];
- for(int i=0; i < globalCount; i++)
- layerBuffer[i] = temp[i];
- }
- countForOpenFile = 0; // To get the number of lines to use with artBuffer
- newFile = new FileDialog(this, "Add Layer", FileDialog.LOAD); // Opens and open file dialog box
- newFile.setVisible(true);
- pathToFile = newFile.getDirectory();
- file = newFile.getFile();
- layerBuffer[globalCount] = new String[200];
- System.out.println("Trying to apply layer: " + pathToFile + file);
- try {
- openFile = new BufferedReader(new FileReader(pathToFile + file));
- } catch(IOException badStuff) {
- System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? - 3");
- }
- try {
- while( (layerBuffer[globalCount][countForOpenFile] = openFile.readLine()).equals("***end***") == false)
- {
- countForOpenFile++;
- }
- } catch(IOException badStuff) {
- System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? -2");
- }
- length1 = artBuffer[0].length();
- length2 = layerBuffer[globalCount][0].length();
- if(length1 < length2) {
- useLength = length2;
- }
- else {
- useLength = length1;
- }
-
- artBuffer2 = new char[200][200];
-
- for(i = 0; i < countForOpenFileSave; i++) {
- for(k = 0; k < useLength; k++) {
- artBuffer2[i][k] = artBuffer[i].charAt(k);
- }
- for(j = 0; j < useLength; j++) {
- if(layerBuffer[i][j].charAt(j) != ' ') {
- artBuffer2[i][j] = layerBuffer[i][j].charAt(j);
- }
- else {
- artBuffer2[i][j] = ' ';
- }
- }
- }
- for(i = 0; i < countForOpenFileSave; i++) {
- for(k = 0; k < useLength; k++) {
- System.out.println(artBuffer2[i][k]);
- }
- }
- for(i = 0; i < countForOpenFileSave; i++) {
- System.out.println(artBuffer[i]);
- }
- globalCount++;
- }
-
- public void menumirrorSideWaysActionPerformed(java.awt.event.ActionEvent e) {
- asciiLibs foo = new asciiLibs(artBuffer);
- foo.invert(countForOpenFile);
- refresh();
- }
-
- public void menuFileRefreshArtActionPerformed(java.awt.event.ActionEvent e) {
- bigString = "";
- //fileBuffer.setText("");
- for(i = 0; i < countForOpenFile; i++) {
- bigString = bigString + artBuffer[i] + "\n";
- }
- fileBuffer.setText(bigString);
- //fileBuffer.replaceText(bigString, 0, 40000);
- }
- public void refresh() {
- bigString = "";
- for(i = 0; i < countForOpenFile; i++) {
- bigString = bigString + artBuffer[i] + "\n";
- }
- fileBuffer.setText(bigString);
- }
-
- public void menumirrorFlipVerticleActionPerformed(java.awt.event.ActionEvent e) {
- asciiLibs foo = new asciiLibs(artBuffer);
- foo.invertVert(countForOpenFile);
- refresh();
- }
-
- public void menuLineToolsVerticleLineActionPerformed(java.awt.event.ActionEvent e) {
- asciiLibs foo = new asciiLibs(artBuffer);
- foo.horizontalLine(countForOpenFile);
- refresh();
- }
-
- public void menuFileReplaceCharactersActionPerformed(java.awt.event.ActionEvent e) {
- try {
- asciiLibs foo = new asciiLibs(artBuffer);
- foo.replaceChar(countForOpenFileSave);
- refresh();
- } catch (IOException badStuff) {
- System.out.println("Bad stuff has occurred -1");
- }
- }
-
-
-
-
-
-
- /*layerBuffer = new String[globalCount][];
- layerBuffer[2] = new String[2]{"blah","soo"};
- system.out.println(layerBuffer[2][1])*/
- }
-