Results 1 to 16 of 16

Thread: Best way to save a particular file when multiple windows are open

  1. #1
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts

    Best way to save a particular file when multiple windows are open

    Sorry if the title is rather vague, but I am writing a simple application, sort of a multifunctional xml ide/text editor kinda thing and was wondering if you editied a file in window1 suppose, and you have 3 windows open, so when you click the save button how do you make sure that you save the one that you want? I mean by default usually it is the text window that is already selected or the one that is higher above in the layering scheme right? How would you recommend going about it? I know how to write to the disk but I am wondering how i would get the particular file windows contents that I modified to save. Thanks a lot. If my post does not make sense let me know and I will repost.

  2. #2
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Surely it would only refer to the current instance of the file file in that window? I've never done it myself but that's what i would've thought. If you create an instance (or if you've opened up a file) in that window, it should refer to the current file in that window instance?

  3. #3
    Registered+
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked
    0 times in 0 posts
    Use a variable to record which is the 'active' window?

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Yes I aree with you Kezzer and rickyboy. My first thought was to have a listener that would change the title bar of the window to something like filename.txt to filename.txt* and then when I hit the save button, there would be a method that would quickly go thru the titles of the open windows and find the one with the star and save that one regardless of which window instance I am currently selecting. IF there are multiple windows that need to have their content saved, then my process of checking and saving would take care of all of them...so I might end up requiring a data structure like an ArrayList that keeps track of the window titles. Hmm this is kind of more difficult than I thought hehe. Any better suggestions?

  5. #5
    Registered+
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked
    0 times in 0 posts
    Surely clicking 'save' should only save the active window and not all open windows? 'Save all' would be more suited to what you are describing.

  6. #6
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    But then how would i detect the active window? Like a FocusListener or something?

  7. #7
    Sam
    Sam is offline
    Registered+
    Join Date
    Oct 2003
    Posts
    22
    Thanks
    0
    Thanked
    0 times in 0 posts
    Just have a variable called lastEditedWindow and update that as users edit in different windows. Then call save on that when they click the save / print / close / reload button.

  8. #8
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,901
    Thanks
    67
    Thanked
    182 times in 136 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    You should be able to tell which window has focus somehow (can decribe it in C but not Java ).

  9. #9
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Hmm it is so easy you know when you are using an app but when you try writing an app with features we are all kind of used to it is quite damningly difficult lol. I am still stuck on this haha

  10. #10
    Sam
    Sam is offline
    Registered+
    Join Date
    Oct 2003
    Posts
    22
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by Butcher
    You should be able to tell which window has focus somehow (can decribe it in C but not Java ).
    But as soon as he clicks onto the toolbar, that will gain focus.

  11. #11
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Right Sam so you are recommending the use of a FocusListener then in Java? Never worked with it but I can figure it out (I hope!) :-)

  12. #12
    Sam
    Sam is offline
    Registered+
    Join Date
    Oct 2003
    Posts
    22
    Thanks
    0
    Thanked
    0 times in 0 posts
    It doesn't matter what you use, but your toolbar frame (or whatever you use for the toolbar) can have a reference to the last active window. Inside each editing window add a focus listener that when it gains focus it sets the lastActiveWindow reference inside the toolbar (so it'll need a reference to that object).

  13. #13
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,901
    Thanks
    67
    Thanked
    182 times in 136 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    Quote Originally Posted by Sam
    But as soon as he clicks onto the toolbar, that will gain focus.
    Toolbars aren't focusable objects (in windows). If you click a toolbar the document window retains focus.

  14. #14
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,901
    Thanks
    67
    Thanked
    182 times in 136 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    FWIW, in C you'd sent the MDI client window a WM_MDIGETACTIVE message which returns the active child window. Pretty easy really. No idea if Java has similar functionality (you'd think so though, since it's meant to be easy to do guis, right? )

  15. #15
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Butcher, I am not quite that familiar with all the Listeners and so on that are available. I still consider myself a noob when it comes to Java. I am actually planning on taking the Sun Java Programmers certification exam in a month or so. I ordered a book from Amazon. After I conquer that it will be time to move to the developers exam. I think Java Swing is brilliantly done and I dont think I would use anything else besides Swing to create a GUI. People say it is slow and clunky, but you try to run a graphically intense app on a virtual machine and of course it will run slow. I think java can be compiled to native code and so have a .exe without all the layers in between and get the app getting to work faster that way.

    Sam I am going to give your idea a shot since it sounds quite probable. Sorry for all these questions fellas but you guys have been most helpful hehe. I'll be back!

  16. #16
    Sam
    Sam is offline
    Registered+
    Join Date
    Oct 2003
    Posts
    22
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by Butcher
    Toolbars aren't focusable objects (in windows). If you click a toolbar the document window retains focus.
    I didn't know that, I very rarely program GUIs.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 63
    Last Post: 14-11-2011, 09:17 AM
  2. Nero vision express saying:'Burn process failed'
    By johnnr892 in forum Help! Quick Relief From Tech Headaches
    Replies: 15
    Last Post: 11-12-2005, 11:43 PM
  3. New Windows Updates out peeps
    By Skii in forum Software
    Replies: 10
    Last Post: 04-08-2004, 06:19 AM
  4. windows 2000, corrupt file... help!
    By streetster in forum Software
    Replies: 4
    Last Post: 05-11-2003, 09:21 AM
  5. Windows Update flaw 'left PCs open' to MSBlast
    By Bunjiweb in forum Software
    Replies: 10
    Last Post: 19-08-2003, 02:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •