Phase one clean up! (windows style file loader/saver WANTED)
Hi everyone! I finally have a nicely working version of my program and I am looking to clean up the file input/output.
Currently I have used Strings, Files, and URLs, in a blended mess of concatenation, and though it all works perfectly,
I need to expand in re-usability, and professionalism. My desire is to make your "Standard" file opener, exactly like say Microsoft word.
The viewer will allow the user to look through the folder visually and select a file to load, as well as when saving see if they are saving
over a file name already being used.
If anyone knows of a good library that already has a class that does this, I would be extremely grateful, as putting together the GUI to do it from scratch seems almost as complex as my program itself.
An example of the code I use currently to achieve these results:
Code :
public CenterGrid(String fileName) {
JPanel gridHolder = new JPanel();
File file = new File(fileName); //Not responsible for checking for valid fileName. That is up to the loader.
BufferedReader reader;
// TODO: z CONVERTING URL EXAMPLE: (Project Aid)
// System.getProperty("user.dir") = C:\Users\Jons\Desktop\TestFile Loading
// curLineInfo = /Images/Terrain/Grass.png
// URL NEEDS TO LOOK LIKE = file:/C:/Users/Jons/Desktop/TestFile Loading/Images/Terrain/Grass.png
try {
reader = new BufferedReader(new FileReader(file));
String curLineInfo;
myHeight = Integer.parseInt(reader.readLine());// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
myLength = Integer.parseInt(reader.readLine());// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
tiles = new Tile[myHeight*myLength]; //creates array long enough for the area of Tile objects.
gridHolder.setLayout(new GridLayout(myHeight,myLength));
int idx = 0;// keeps track of the array index
while ((curLineInfo = reader.readLine()) != null) {// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
Tile tile = new Tile();
String terrainStringURL = ("file:/" + System.getProperty("user.dir").replace('\\','/') + curLineInfo); //build curLineInfo into a useable URL
Terrain terrainFromFile = new Terrain(new URL(terrainStringURL), tile);
tile.addTerrain(terrainFromFile);
gridHolder.add(tile);
tiles[idx]=(tile);
idx++;
}
} catch(FileNotFoundException e){} catch (IOException ex) {}// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
add(gridHolder);
gridHolder.setVisible(true);
}
So I have sections of zoo like appearance I would prefer to clean up before I handle my programs ability to load multiple folders.
I will write a class to clean up the "on the spot" code look, but before I do, I wanted to see if I could get the golden apple and instead
get the windows style loader, and just rewrite to use that classes functionality instead.
Hopefully I am being clear.
I will post a .zip file that has the .jar and the folders needed to run the program so you can get a feel for what is is capable of.
Thanks as always,
Jonathan
1 Attachment(s)
Re: Phase one clean up! (windows style file loader/saver WANTED)
imported classes for my .jar program (attempting to ensure a malware free promise)
import java.awt.*;
import java.io.*;
import java.net.*;
import java.awt.event.*;
import javax.swing.*;
There are no infinite loops, or memory leaks.
The program has no hidden agenda other then its very visual functionality.
I have run it using windows 7 and JDK 7u3-nb-7_1 with netbeans 7.1.1-ml-javase
it has the ability to make a large amount of JPanels, but I have caped the users input to 100x100, 10,000. the default is 20x30, 600.
Currently the loader automatically loads test.txt from the Maps folder.
I have not done any error checking involving a user creating bad data to load, but it will most certainly just result in the program not loading pictures to JPanels.
If I could get some basic testing on other platforms that would be amazing.
Thanks,
Jonathan
Re: Phase one clean up! (windows style file loader/saver WANTED)
Re: Phase one clean up! (windows style file loader/saver WANTED)
looks very promising, Ill let you know tomorrow when i get it all working.
Thanks Copeg (as usual) once I get this thing running and hopefully marketed, Ill be sure to send you some meager royalties lol.