dmolony-DiskBrowser/src/com/bytezone/diskbrowser/gui/WindowState.java

65 lines
2.3 KiB
Java
Raw Permalink Normal View History

2019-10-12 02:47:21 +00:00
package com.bytezone.diskbrowser.gui;
import java.awt.Dimension;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import javax.swing.JFrame;
2020-02-08 22:20:08 +00:00
// -----------------------------------------------------------------------------------//
2019-10-12 02:47:21 +00:00
class WindowState
2020-02-08 22:20:08 +00:00
// -----------------------------------------------------------------------------------//
2019-10-12 02:47:21 +00:00
{
private static final String PREF_WINDOW_WIDTH = "WindowWidth";
private static final String PREF_WINDOW_HEIGHT = "WindowHeight";
private static final String PREF_WINDOW_STATE = "WindowExtendedState";
public Preferences preferences;
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
WindowState (Preferences preferences)
// ---------------------------------------------------------------------------------//
2019-10-12 02:47:21 +00:00
{
this.preferences = preferences;
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
void clear ()
// ---------------------------------------------------------------------------------//
2019-10-12 02:47:21 +00:00
{
try
{
preferences.clear ();
2019-10-12 07:30:08 +00:00
System.out.println ("Preferences cleared");
2019-10-12 02:47:21 +00:00
}
catch (BackingStoreException e)
{
e.printStackTrace ();
}
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
Dimension getWindowSize (int defaultWidth, int defaultHeight)
// ---------------------------------------------------------------------------------//
2019-10-12 02:47:21 +00:00
{
int width = preferences.getInt (PREF_WINDOW_WIDTH, defaultWidth);
int height = preferences.getInt (PREF_WINDOW_HEIGHT, defaultHeight);
return new Dimension (width, height);
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
int getExtendedState (int defaultState)
// ---------------------------------------------------------------------------------//
2019-10-12 02:47:21 +00:00
{
return preferences.getInt (PREF_WINDOW_STATE, defaultState);
}
2020-02-08 22:20:08 +00:00
// ---------------------------------------------------------------------------------//
void save (JFrame window)
// ---------------------------------------------------------------------------------//
2019-10-12 02:47:21 +00:00
{
preferences.putInt (PREF_WINDOW_WIDTH, window.getWidth ());
preferences.putInt (PREF_WINDOW_HEIGHT, window.getHeight ());
preferences.putInt (PREF_WINDOW_STATE, window.getExtendedState ());
}
}