11package com .codingpupper3033 .codebtekml .gui .screens ;
22
33import com .codingpupper3033 .codebtekml .KeyInit ;
4- import com .codingpupper3033 .codebtekml .gui .buttons .IconButton ;
54import com .codingpupper3033 .codebtekml .gui .widgets .BlockPreview ;
5+ import com .codingpupper3033 .codebtekml .gui .widgets .buttons .IconButton ;
66import com .codingpupper3033 .codebtekml .helpers .block .BlockNameConverter ;
77import com .codingpupper3033 .codebtekml .helpers .kmlfile .KMLParser ;
88import com .codingpupper3033 .codebtekml .helpers .map .Placemark ;
99import com .codingpupper3033 .codebtekml .helpers .map .altitude .GoundLevelProcessor ;
1010import com .codingpupper3033 .codebtekml .helpers .map .placemark .PlacemarkFactory ;
11+ import net .minecraft .client .Minecraft ;
1112import net .minecraft .client .gui .GuiButton ;
1213import net .minecraft .client .gui .GuiScreen ;
1314import net .minecraft .client .gui .GuiTextField ;
@@ -31,12 +32,16 @@ public class GuiDrawKML extends GuiScreen {
3132 // Parent
3233 private final GuiScreen parentScreen ;
3334
35+ // File Chooser
36+ final static JFileChooser FILE_CHOOSER = new JFileChooser ();
37+
3438 // File Name Text Box
3539 public static final int FILE_NAME_TEXT_BOX_ID = 1 ;
36- public static final String DEFAULT_FILE_NAME_TEXT_BOX_TEXT = javax .swing .filechooser .FileSystemView .getFileSystemView ().getHomeDirectory ().getAbsolutePath (); // Default path is Desktop cause why not
40+ // public static final String DEFAULT_FILE_NAME_TEXT_BOX_TEXT = javax.swing.filechooser.FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath(); // Default path is Desktop cause why not
3741 public static final int MAX_FILE_PATH_CHARACTERS = 260 ; // windows limit according to the first bing result, TODO maybe change to programmatic, but like very insignificant as you just shouldn't need this many characters bro.
3842 private static final int [] FILE_NAME_TEXT_BOX_POS = {-155 ,0 };
3943 public static final int [] FILE_NAME_TEXT_BOX_SIZE = {280 ,20 };
44+ private static String lastFileName = null ;
4045 private GuiTextField fileNameTextBox ;
4146
4247 // Select File Button
@@ -100,6 +105,11 @@ public GuiDrawKML(GuiScreen parentScreen) {
100105 public void initGui () {
101106 super .initGui ();
102107
108+ // Set up the filter for the file viewer
109+ FileNameExtensionFilter filter = new FileNameExtensionFilter ("kmz or kml file" ,"kmz" ,"kml" ); // Files generally supported (but not enforced)
110+ FILE_CHOOSER .setFileFilter (filter ); // Set filter to kmz/kml
111+ FILE_CHOOSER .setFileSelectionMode (JFileChooser .FILES_AND_DIRECTORIES ); // Allow directories
112+
103113 // Helper variables for adding gui elements
104114 int guiMiddleX = width /2 ;
105115 int guiStartY = height /6 ;
@@ -118,8 +128,14 @@ public void initGui() {
118128
119129 // File Name Text Box
120130 fileNameTextBox = new GuiTextField (FILE_NAME_TEXT_BOX_ID , mc .fontRenderer , guiMiddleX +FILE_NAME_TEXT_BOX_POS [0 ],guiStartY +FILE_NAME_TEXT_BOX_POS [1 ], FILE_NAME_TEXT_BOX_SIZE [0 ], FILE_NAME_TEXT_BOX_SIZE [1 ]);
121- fileNameTextBox .setText (DEFAULT_FILE_NAME_TEXT_BOX_TEXT );
122131 fileNameTextBox .setMaxStringLength (MAX_FILE_PATH_CHARACTERS );
132+ if (lastFileName != null ) {
133+ fileNameTextBox .setText (lastFileName );
134+ FILE_CHOOSER .setSelectedFile (null );
135+ } else {
136+ updateFileNameText (); // Set text to what the file chooser thinks it should be
137+ }
138+
123139
124140 // Select File Button
125141 selectFileButton = new IconButton (IconButton .ICON .FILE , SELECT_FILE_BUTTON_ID , guiMiddleX + SELECT_FILE_BUTTON_POS [0 ],guiStartY + SELECT_FILE_BUTTON_POS [1 ]);
@@ -238,24 +254,14 @@ protected void actionPerformed(GuiButton button) throws IOException {
238254
239255 switch (button .id ) { // Who did it?
240256 case SELECT_FILE_BUTTON_ID : // Selecting a file time
241- // Make open file dialog not look like as shit
242- try {
243- UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
244- }catch (Exception ex ) {
245- ex .printStackTrace ();
246- }
247- FileNameExtensionFilter filter = new FileNameExtensionFilter ("kmz or kml file" ,"kmz" ,"kml" ); // Files generally supported (but not enforced)
248-
249- //Create a file chooser
250- final JFileChooser fc = new JFileChooser ();
251- fc .setFileFilter (filter ); // Set filter to kmz/kml
252-
253- if (fc .showOpenDialog (null ) == JFileChooser .APPROVE_OPTION ) {
257+ JFrame parent = new JFrame ();
258+ parent .setAlwaysOnTop (true ); // can't hide the box, messing up minecraft
259+ if (FILE_CHOOSER .showOpenDialog (parent ) == JFileChooser .APPROVE_OPTION ) {
254260 // Set file name textbox to file name from dialog
255- fileNameTextBox . setText ( fc . getSelectedFile (). getAbsolutePath () );
261+ updateFileNameText ( );
256262 }
257263 break ;
258- case API_CHECK_BOX_ID : // Api setting
264+ case API_CHECK_BOX_ID : // API setting
259265 GoundLevelProcessor .defaultProcessor .enabled = apiCheckBox .isChecked (); // Can my boi process altitudes (using the internet)
260266 break ;
261267 case BUILD_BUTTON_ID : // Do ya thing!
@@ -287,15 +293,28 @@ public void build() {
287293 Placemark [] placemarks = PlacemarkFactory .getPlacemarks (documents );
288294
289295 // Process Altitudes
290- PlacemarkFactory .proccessPlacemarks (placemarks );
296+ PlacemarkFactory .processPlacemarks (placemarks );
297+
291298
292- close (); // Should have successfully processed the file, gui is not needed now
293- PlacemarkFactory .drawPlacemarks (placemarks , blockNameTextBox .getText ()); // Draw!
299+ // Should have successfully processed the file, gui is not needed now
300+ // Open loading screen
301+ Minecraft .getMinecraft ().displayGuiScreen (new GuiBuilding (placemarks , blockNameTextBox .getText ()));
294302 }).start ();
295303 }
296304
297305 // Bye bye!
298306 public void close () {
299307 mc .displayGuiScreen (parentScreen );
300308 }
309+
310+ public void updateFileNameText () {
311+ File file ;
312+ if (FILE_CHOOSER .getSelectedFile () != null ) { // Get File
313+ file = FILE_CHOOSER .getSelectedFile ();
314+ } else { // Get directory
315+ file = FILE_CHOOSER .getCurrentDirectory ();
316+ }
317+ fileNameTextBox .setText (file .getAbsolutePath ());
318+ lastFileName = fileNameTextBox .getText ();
319+ }
301320}
0 commit comments