removed com.bytezone.common
This commit is contained in:
parent
3e1d9d65ca
commit
5191615953
|
@ -1,451 +1,451 @@
|
|||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
/***********************************************************************************************
|
||||
* Contains a single instance of FileSystemTab, and any number of AppleDiskTab instances.
|
||||
*
|
||||
*
|
||||
***********************************************************************************************/
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import com.bytezone.common.FontAction.FontChangeEvent;
|
||||
import com.bytezone.common.FontAction.FontChangeListener;
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.DualDosDisk;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.duplicates.DiskDetails;
|
||||
import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoListener;
|
||||
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class CatalogPanel extends JTabbedPane
|
||||
implements RedoListener, SectorSelectionListener, QuitListener, FontChangeListener,
|
||||
RootDirectoryChangeListener, DiskTableSelectionListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final String prefsLastDiskUsed = "Last disk used";
|
||||
private static final String prefsLastDosUsed = "Last dos used";
|
||||
private static final String prefsLastFileUsed = "Last file used";
|
||||
private static final String prefsLastSectorsUsed = "Last sectors used";
|
||||
|
||||
private Font font;
|
||||
private FileSystemTab fileTab;
|
||||
private final List<AppleDiskTab> diskTabs = new ArrayList<> ();
|
||||
private final DiskAndFileSelector selector = new DiskAndFileSelector ();
|
||||
private final RedoHandler redoHandler;
|
||||
private CloseTabAction closeTabAction;
|
||||
private File rootFolder;
|
||||
private boolean restored = false;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public CatalogPanel (RedoHandler redoHandler)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.redoHandler = redoHandler;
|
||||
|
||||
setTabPlacement (SwingConstants.BOTTOM);
|
||||
setPreferredSize (new Dimension (360, 802)); // width, height
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
rootFolder = newRootFolder;
|
||||
if (!restored)
|
||||
return; // restore will finish the task
|
||||
|
||||
// is the user replacing an existing root folder?
|
||||
if (fileTab != null)
|
||||
removeTabAt (0);
|
||||
|
||||
insertFileSystemTab (null);
|
||||
setSelectedIndex (0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void insertFileSystemTab (DiskSelectedEvent diskEvent)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
fileTab = new FileSystemTab (rootFolder, selector, redoHandler, font, diskEvent);
|
||||
fileTab.addTreeMouseListener (new MouseListener ()); // listen for disk selection
|
||||
insertTab ("Disk Tree", null, fileTab, "Display Apple disks", 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void activate ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (fileTab == null)
|
||||
{
|
||||
System.out.println ("No file tab");
|
||||
return;
|
||||
}
|
||||
|
||||
if (diskTabs.size () > 0)
|
||||
setSelectedIndex (1);
|
||||
else if (fileTab != null)
|
||||
setSelectedIndex (0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void setCloseTabAction (CloseTabAction action)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.closeTabAction = action;
|
||||
}
|
||||
|
||||
// called after a double-click in the fileTab
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addDiskPanel (FormattedDisk disk, boolean activate)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int tabNo = 1;
|
||||
for (AppleDiskTab tab : diskTabs)
|
||||
{
|
||||
if (tab.contains (disk))
|
||||
{
|
||||
setSelectedIndex (tabNo);
|
||||
return;
|
||||
}
|
||||
tabNo++;
|
||||
}
|
||||
|
||||
AppleDiskTab tab = new AppleDiskTab (disk, selector, redoHandler, font);
|
||||
diskTabs.add (tab);
|
||||
add (tab, "D" + diskTabs.size ());
|
||||
if (activate)
|
||||
setSelectedIndex (diskTabs.size ());
|
||||
}
|
||||
|
||||
// called from RefreshTreeAction
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void refreshTree ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
tab.refresh ();
|
||||
|
||||
// Any newly created disk needs to appear in the FileSystemTab's tree
|
||||
if (tab instanceof AppleDiskTab)
|
||||
fileTab.replaceDisk (((AppleDiskTab) tab).disk);
|
||||
}
|
||||
|
||||
// called from CloseTabAction
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void closeCurrentTab ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (!(tab instanceof AppleDiskTab) || diskTabs.size () < 2)
|
||||
return;
|
||||
|
||||
int index = getSelectedIndex ();
|
||||
remove (index);
|
||||
diskTabs.remove (tab);
|
||||
|
||||
for (int i = 1; i <= diskTabs.size (); i++)
|
||||
setTitleAt (i, "D" + i);
|
||||
|
||||
checkCloseTabAction ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void checkCloseTabAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (diskTabs.size () > 1 && tab instanceof AppleDiskTab)
|
||||
closeTabAction.setEnabled (true);
|
||||
else
|
||||
closeTabAction.setEnabled (false);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void quit (Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (fileTab == null)
|
||||
{
|
||||
prefs.put (prefsLastDiskUsed, "");
|
||||
prefs.putInt (prefsLastDosUsed, -1);
|
||||
prefs.put (prefsLastFileUsed, "");
|
||||
prefs.put (prefsLastSectorsUsed, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (diskTabs.size () == 0)
|
||||
{
|
||||
RedoEvent redoEvent = fileTab.redoData.getCurrentEvent ();
|
||||
if (redoEvent != null)
|
||||
{
|
||||
DiskSelectedEvent event = (DiskSelectedEvent) redoEvent.value;
|
||||
prefs.put (prefsLastDiskUsed, event.getFormattedDisk ().getAbsolutePath ());
|
||||
}
|
||||
prefs.put (prefsLastFileUsed, "");
|
||||
prefs.put (prefsLastSectorsUsed, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
AbstractTab selectedTab = (AbstractTab) getSelectedComponent ();
|
||||
if (selectedTab instanceof FileSystemTab)
|
||||
selectedTab = diskTabs.get (diskTabs.size () - 1);
|
||||
|
||||
FormattedDisk fd = ((AppleDiskTab) selectedTab).disk;
|
||||
prefs.put (prefsLastDiskUsed, fd.getAbsolutePath ());
|
||||
if (fd instanceof DualDosDisk)
|
||||
prefs.putInt (prefsLastDosUsed, ((DualDosDisk) fd).getCurrentDiskNo ());
|
||||
else
|
||||
prefs.putInt (prefsLastDosUsed, -1);
|
||||
|
||||
RedoEvent redoEvent = selectedTab.redoData.getCurrentEvent ();
|
||||
if (redoEvent != null)
|
||||
{
|
||||
EventObject event = redoEvent.value;
|
||||
|
||||
if (event instanceof FileSelectedEvent)
|
||||
{
|
||||
AppleFileSource afs = ((FileSelectedEvent) event).appleFileSource;
|
||||
prefs.put (prefsLastFileUsed, afs == null ? "" : afs.getUniqueName ());
|
||||
prefs.put (prefsLastSectorsUsed, "");
|
||||
}
|
||||
else if (event instanceof SectorSelectedEvent)
|
||||
{
|
||||
prefs.put (prefsLastFileUsed, "");
|
||||
prefs.put (prefsLastSectorsUsed, ((SectorSelectedEvent) event).toText ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void restore (Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String lastDiskUsed = prefs.get (prefsLastDiskUsed, "");
|
||||
int lastDosUsed = prefs.getInt (prefsLastDosUsed, -1);
|
||||
String lastFileUsed = prefs.get (prefsLastFileUsed, "");
|
||||
String lastSectorsUsed = prefs.get (prefsLastSectorsUsed, "");
|
||||
|
||||
if (false)
|
||||
{
|
||||
System.out.println ("Last disk : " + lastDiskUsed);
|
||||
System.out.println ("Last dos : " + lastDosUsed);
|
||||
System.out.println ("Last file : " + lastFileUsed);
|
||||
System.out.println ("Last sectors : " + lastSectorsUsed);
|
||||
}
|
||||
|
||||
FormattedDisk fd1 = null;
|
||||
DiskSelectedEvent diskEvent = null;
|
||||
if (!lastDiskUsed.isEmpty ())
|
||||
{
|
||||
diskEvent = DiskSelectedEvent.create (this, lastDiskUsed);
|
||||
if (diskEvent != null)
|
||||
{
|
||||
fd1 = diskEvent.getFormattedDisk ();
|
||||
if (lastDosUsed >= 0 && fd1 instanceof DualDosDisk)
|
||||
((DualDosDisk) fd1).setCurrentDiskNo (lastDosUsed);
|
||||
}
|
||||
}
|
||||
else
|
||||
System.out.println ("no disk selected");
|
||||
|
||||
if (rootFolder != null)
|
||||
insertFileSystemTab (diskEvent);
|
||||
|
||||
if (diskEvent != null)
|
||||
{
|
||||
AppleDiskTab tab = null;
|
||||
FormattedDisk fd = diskEvent.getFormattedDisk ();
|
||||
assert fd == fd1;
|
||||
|
||||
if (!lastFileUsed.isEmpty ())
|
||||
{
|
||||
AppleFileSource afs = fd.getFile (lastFileUsed);
|
||||
if (afs != null)
|
||||
{
|
||||
FileSelectedEvent fileEvent = new FileSelectedEvent (this, afs);
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font, fileEvent);
|
||||
}
|
||||
else
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font, lastFileUsed);
|
||||
}
|
||||
else if (!lastSectorsUsed.isEmpty ())
|
||||
{
|
||||
SectorSelectedEvent sectorEvent =
|
||||
SectorSelectedEvent.create (this, fd, lastSectorsUsed);
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font, sectorEvent);
|
||||
}
|
||||
else
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font);
|
||||
|
||||
if (tab != null)
|
||||
{
|
||||
diskTabs.add (tab);
|
||||
add (tab, "D" + diskTabs.size ());
|
||||
}
|
||||
else
|
||||
System.out.println ("No disk tab created");
|
||||
}
|
||||
addChangeListener (new TabChangeListener ());
|
||||
restored = true;
|
||||
}
|
||||
|
||||
// Pass through to DiskSelector
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addDiskSelectionListener (DiskSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
selector.addDiskSelectionListener (listener);
|
||||
}
|
||||
|
||||
// Pass through to DiskSelector
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addFileSelectionListener (FileSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
selector.addFileSelectionListener (listener);
|
||||
}
|
||||
|
||||
// Pass through to DiskSelector
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addFileNodeSelectionListener (FileNodeSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
selector.addFileNodeSelectionListener (listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private class TabChangeListener implements ChangeListener
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void stateChanged (ChangeEvent e)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (tab != null)
|
||||
{
|
||||
tab.activate ();
|
||||
checkCloseTabAction ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void redo (RedoEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
selector.redo = true;
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case "DiskEvent":
|
||||
case "FileNodeEvent":
|
||||
if (tab instanceof FileSystemTab)
|
||||
((FileSystemTab) tab).redoEvent (event);
|
||||
break;
|
||||
|
||||
case "FileEvent":
|
||||
if (tab instanceof AppleDiskTab)
|
||||
((AppleDiskTab) tab).redoEvent (event);
|
||||
break;
|
||||
|
||||
case "SectorEvent":
|
||||
// don't care
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println ("Unknown event type : " + event.type);
|
||||
}
|
||||
|
||||
selector.redo = false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void sectorSelected (SectorSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// user has clicked in the DiskLayoutPanel, so turn off any current file selection
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (tab instanceof AppleDiskTab)
|
||||
((AppleDiskTab) tab).tree.setSelectionPath (null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void changeFont (FontChangeEvent fontChangeEvent)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
font = fontChangeEvent.font;
|
||||
if (fileTab != null)
|
||||
fileTab.setTreeFont (font);
|
||||
for (AppleDiskTab tab : diskTabs)
|
||||
tab.setTreeFont (font);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private class MouseListener extends MouseAdapter
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void mousePressed (MouseEvent e)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
JTree tree = (JTree) e.getSource ();
|
||||
int selRow = tree.getRowForLocation (e.getX (), e.getY ());
|
||||
if (selRow < 0)
|
||||
return;
|
||||
|
||||
TreePath tp = tree.getPathForLocation (e.getX (), e.getY ());
|
||||
DefaultMutableTreeNode selectedNode =
|
||||
(DefaultMutableTreeNode) tp.getLastPathComponent ();
|
||||
FileNode node = (FileNode) selectedNode.getUserObject ();
|
||||
if (node.file.isDirectory ())
|
||||
{
|
||||
// lister.catalogLister.setNode (selectedNode);
|
||||
}
|
||||
else if (e.getClickCount () == 2)
|
||||
addDiskPanel (node.getFormattedDisk (), true);
|
||||
}
|
||||
}
|
||||
|
||||
// a disk has been selected from the Disk Duplicates Table
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void diskSelected (DiskDetails diskDetails)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
if (getSelectedIndex () != 0)
|
||||
setSelectedIndex (0);
|
||||
|
||||
fileTab.selectDisk (diskDetails.getRootName ());
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
/***********************************************************************************************
|
||||
* Contains a single instance of FileSystemTab, and any number of AppleDiskTab instances.
|
||||
*
|
||||
*
|
||||
***********************************************************************************************/
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.DualDosDisk;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.duplicates.DiskDetails;
|
||||
import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
||||
import com.bytezone.diskbrowser.gui.FontAction.FontChangeEvent;
|
||||
import com.bytezone.diskbrowser.gui.FontAction.FontChangeListener;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoListener;
|
||||
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class CatalogPanel extends JTabbedPane
|
||||
implements RedoListener, SectorSelectionListener, QuitListener, FontChangeListener,
|
||||
RootDirectoryChangeListener, DiskTableSelectionListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final String prefsLastDiskUsed = "Last disk used";
|
||||
private static final String prefsLastDosUsed = "Last dos used";
|
||||
private static final String prefsLastFileUsed = "Last file used";
|
||||
private static final String prefsLastSectorsUsed = "Last sectors used";
|
||||
|
||||
private Font font;
|
||||
private FileSystemTab fileTab;
|
||||
private final List<AppleDiskTab> diskTabs = new ArrayList<> ();
|
||||
private final DiskAndFileSelector selector = new DiskAndFileSelector ();
|
||||
private final RedoHandler redoHandler;
|
||||
private CloseTabAction closeTabAction;
|
||||
private File rootFolder;
|
||||
private boolean restored = false;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public CatalogPanel (RedoHandler redoHandler)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.redoHandler = redoHandler;
|
||||
|
||||
setTabPlacement (SwingConstants.BOTTOM);
|
||||
setPreferredSize (new Dimension (360, 802)); // width, height
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
rootFolder = newRootFolder;
|
||||
if (!restored)
|
||||
return; // restore will finish the task
|
||||
|
||||
// is the user replacing an existing root folder?
|
||||
if (fileTab != null)
|
||||
removeTabAt (0);
|
||||
|
||||
insertFileSystemTab (null);
|
||||
setSelectedIndex (0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void insertFileSystemTab (DiskSelectedEvent diskEvent)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
fileTab = new FileSystemTab (rootFolder, selector, redoHandler, font, diskEvent);
|
||||
fileTab.addTreeMouseListener (new MouseListener ()); // listen for disk selection
|
||||
insertTab ("Disk Tree", null, fileTab, "Display Apple disks", 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void activate ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (fileTab == null)
|
||||
{
|
||||
System.out.println ("No file tab");
|
||||
return;
|
||||
}
|
||||
|
||||
if (diskTabs.size () > 0)
|
||||
setSelectedIndex (1);
|
||||
else if (fileTab != null)
|
||||
setSelectedIndex (0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void setCloseTabAction (CloseTabAction action)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.closeTabAction = action;
|
||||
}
|
||||
|
||||
// called after a double-click in the fileTab
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addDiskPanel (FormattedDisk disk, boolean activate)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int tabNo = 1;
|
||||
for (AppleDiskTab tab : diskTabs)
|
||||
{
|
||||
if (tab.contains (disk))
|
||||
{
|
||||
setSelectedIndex (tabNo);
|
||||
return;
|
||||
}
|
||||
tabNo++;
|
||||
}
|
||||
|
||||
AppleDiskTab tab = new AppleDiskTab (disk, selector, redoHandler, font);
|
||||
diskTabs.add (tab);
|
||||
add (tab, "D" + diskTabs.size ());
|
||||
if (activate)
|
||||
setSelectedIndex (diskTabs.size ());
|
||||
}
|
||||
|
||||
// called from RefreshTreeAction
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void refreshTree ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
tab.refresh ();
|
||||
|
||||
// Any newly created disk needs to appear in the FileSystemTab's tree
|
||||
if (tab instanceof AppleDiskTab)
|
||||
fileTab.replaceDisk (((AppleDiskTab) tab).disk);
|
||||
}
|
||||
|
||||
// called from CloseTabAction
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void closeCurrentTab ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (!(tab instanceof AppleDiskTab) || diskTabs.size () < 2)
|
||||
return;
|
||||
|
||||
int index = getSelectedIndex ();
|
||||
remove (index);
|
||||
diskTabs.remove (tab);
|
||||
|
||||
for (int i = 1; i <= diskTabs.size (); i++)
|
||||
setTitleAt (i, "D" + i);
|
||||
|
||||
checkCloseTabAction ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void checkCloseTabAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (diskTabs.size () > 1 && tab instanceof AppleDiskTab)
|
||||
closeTabAction.setEnabled (true);
|
||||
else
|
||||
closeTabAction.setEnabled (false);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void quit (Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (fileTab == null)
|
||||
{
|
||||
prefs.put (prefsLastDiskUsed, "");
|
||||
prefs.putInt (prefsLastDosUsed, -1);
|
||||
prefs.put (prefsLastFileUsed, "");
|
||||
prefs.put (prefsLastSectorsUsed, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (diskTabs.size () == 0)
|
||||
{
|
||||
RedoEvent redoEvent = fileTab.redoData.getCurrentEvent ();
|
||||
if (redoEvent != null)
|
||||
{
|
||||
DiskSelectedEvent event = (DiskSelectedEvent) redoEvent.value;
|
||||
prefs.put (prefsLastDiskUsed, event.getFormattedDisk ().getAbsolutePath ());
|
||||
}
|
||||
prefs.put (prefsLastFileUsed, "");
|
||||
prefs.put (prefsLastSectorsUsed, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
AbstractTab selectedTab = (AbstractTab) getSelectedComponent ();
|
||||
if (selectedTab instanceof FileSystemTab)
|
||||
selectedTab = diskTabs.get (diskTabs.size () - 1);
|
||||
|
||||
FormattedDisk fd = ((AppleDiskTab) selectedTab).disk;
|
||||
prefs.put (prefsLastDiskUsed, fd.getAbsolutePath ());
|
||||
if (fd instanceof DualDosDisk)
|
||||
prefs.putInt (prefsLastDosUsed, ((DualDosDisk) fd).getCurrentDiskNo ());
|
||||
else
|
||||
prefs.putInt (prefsLastDosUsed, -1);
|
||||
|
||||
RedoEvent redoEvent = selectedTab.redoData.getCurrentEvent ();
|
||||
if (redoEvent != null)
|
||||
{
|
||||
EventObject event = redoEvent.value;
|
||||
|
||||
if (event instanceof FileSelectedEvent)
|
||||
{
|
||||
AppleFileSource afs = ((FileSelectedEvent) event).appleFileSource;
|
||||
prefs.put (prefsLastFileUsed, afs == null ? "" : afs.getUniqueName ());
|
||||
prefs.put (prefsLastSectorsUsed, "");
|
||||
}
|
||||
else if (event instanceof SectorSelectedEvent)
|
||||
{
|
||||
prefs.put (prefsLastFileUsed, "");
|
||||
prefs.put (prefsLastSectorsUsed, ((SectorSelectedEvent) event).toText ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void restore (Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String lastDiskUsed = prefs.get (prefsLastDiskUsed, "");
|
||||
int lastDosUsed = prefs.getInt (prefsLastDosUsed, -1);
|
||||
String lastFileUsed = prefs.get (prefsLastFileUsed, "");
|
||||
String lastSectorsUsed = prefs.get (prefsLastSectorsUsed, "");
|
||||
|
||||
if (false)
|
||||
{
|
||||
System.out.println ("Last disk : " + lastDiskUsed);
|
||||
System.out.println ("Last dos : " + lastDosUsed);
|
||||
System.out.println ("Last file : " + lastFileUsed);
|
||||
System.out.println ("Last sectors : " + lastSectorsUsed);
|
||||
}
|
||||
|
||||
FormattedDisk fd1 = null;
|
||||
DiskSelectedEvent diskEvent = null;
|
||||
if (!lastDiskUsed.isEmpty ())
|
||||
{
|
||||
diskEvent = DiskSelectedEvent.create (this, lastDiskUsed);
|
||||
if (diskEvent != null)
|
||||
{
|
||||
fd1 = diskEvent.getFormattedDisk ();
|
||||
if (lastDosUsed >= 0 && fd1 instanceof DualDosDisk)
|
||||
((DualDosDisk) fd1).setCurrentDiskNo (lastDosUsed);
|
||||
}
|
||||
}
|
||||
else
|
||||
System.out.println ("no disk selected");
|
||||
|
||||
if (rootFolder != null)
|
||||
insertFileSystemTab (diskEvent);
|
||||
|
||||
if (diskEvent != null)
|
||||
{
|
||||
AppleDiskTab tab = null;
|
||||
FormattedDisk fd = diskEvent.getFormattedDisk ();
|
||||
assert fd == fd1;
|
||||
|
||||
if (!lastFileUsed.isEmpty ())
|
||||
{
|
||||
AppleFileSource afs = fd.getFile (lastFileUsed);
|
||||
if (afs != null)
|
||||
{
|
||||
FileSelectedEvent fileEvent = new FileSelectedEvent (this, afs);
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font, fileEvent);
|
||||
}
|
||||
else
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font, lastFileUsed);
|
||||
}
|
||||
else if (!lastSectorsUsed.isEmpty ())
|
||||
{
|
||||
SectorSelectedEvent sectorEvent =
|
||||
SectorSelectedEvent.create (this, fd, lastSectorsUsed);
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font, sectorEvent);
|
||||
}
|
||||
else
|
||||
tab = new AppleDiskTab (fd, selector, redoHandler, font);
|
||||
|
||||
if (tab != null)
|
||||
{
|
||||
diskTabs.add (tab);
|
||||
add (tab, "D" + diskTabs.size ());
|
||||
}
|
||||
else
|
||||
System.out.println ("No disk tab created");
|
||||
}
|
||||
addChangeListener (new TabChangeListener ());
|
||||
restored = true;
|
||||
}
|
||||
|
||||
// Pass through to DiskSelector
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addDiskSelectionListener (DiskSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
selector.addDiskSelectionListener (listener);
|
||||
}
|
||||
|
||||
// Pass through to DiskSelector
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addFileSelectionListener (FileSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
selector.addFileSelectionListener (listener);
|
||||
}
|
||||
|
||||
// Pass through to DiskSelector
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addFileNodeSelectionListener (FileNodeSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
selector.addFileNodeSelectionListener (listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private class TabChangeListener implements ChangeListener
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void stateChanged (ChangeEvent e)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (tab != null)
|
||||
{
|
||||
tab.activate ();
|
||||
checkCloseTabAction ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void redo (RedoEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
selector.redo = true;
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case "DiskEvent":
|
||||
case "FileNodeEvent":
|
||||
if (tab instanceof FileSystemTab)
|
||||
((FileSystemTab) tab).redoEvent (event);
|
||||
break;
|
||||
|
||||
case "FileEvent":
|
||||
if (tab instanceof AppleDiskTab)
|
||||
((AppleDiskTab) tab).redoEvent (event);
|
||||
break;
|
||||
|
||||
case "SectorEvent":
|
||||
// don't care
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println ("Unknown event type : " + event.type);
|
||||
}
|
||||
|
||||
selector.redo = false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void sectorSelected (SectorSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// user has clicked in the DiskLayoutPanel, so turn off any current file selection
|
||||
Tab tab = (Tab) getSelectedComponent ();
|
||||
if (tab instanceof AppleDiskTab)
|
||||
((AppleDiskTab) tab).tree.setSelectionPath (null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void changeFont (FontChangeEvent fontChangeEvent)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
font = fontChangeEvent.font;
|
||||
if (fileTab != null)
|
||||
fileTab.setTreeFont (font);
|
||||
for (AppleDiskTab tab : diskTabs)
|
||||
tab.setTreeFont (font);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private class MouseListener extends MouseAdapter
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void mousePressed (MouseEvent e)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
JTree tree = (JTree) e.getSource ();
|
||||
int selRow = tree.getRowForLocation (e.getX (), e.getY ());
|
||||
if (selRow < 0)
|
||||
return;
|
||||
|
||||
TreePath tp = tree.getPathForLocation (e.getX (), e.getY ());
|
||||
DefaultMutableTreeNode selectedNode =
|
||||
(DefaultMutableTreeNode) tp.getLastPathComponent ();
|
||||
FileNode node = (FileNode) selectedNode.getUserObject ();
|
||||
if (node.file.isDirectory ())
|
||||
{
|
||||
// lister.catalogLister.setNode (selectedNode);
|
||||
}
|
||||
else if (e.getClickCount () == 2)
|
||||
addDiskPanel (node.getFormattedDisk (), true);
|
||||
}
|
||||
}
|
||||
|
||||
// a disk has been selected from the Disk Duplicates Table
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void diskSelected (DiskDetails diskDetails)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
if (getSelectedIndex () != 0)
|
||||
setSelectedIndex (0);
|
||||
|
||||
fileTab.selectDisk (diskDetails.getRootName ());
|
||||
}
|
||||
}
|
|
@ -25,8 +25,6 @@ import javax.swing.SwingWorker;
|
|||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import com.bytezone.common.FontAction.FontChangeEvent;
|
||||
import com.bytezone.common.FontAction.FontChangeListener;
|
||||
import com.bytezone.diskbrowser.applefile.ApplesoftBasicProgram;
|
||||
import com.bytezone.diskbrowser.applefile.AssemblerProgram;
|
||||
import com.bytezone.diskbrowser.applefile.HiResImage;
|
||||
|
@ -37,6 +35,8 @@ import com.bytezone.diskbrowser.applefile.SHRPictureFile2;
|
|||
import com.bytezone.diskbrowser.applefile.VisicalcFile;
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.SectorList;
|
||||
import com.bytezone.diskbrowser.gui.FontAction.FontChangeEvent;
|
||||
import com.bytezone.diskbrowser.gui.FontAction.FontChangeListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
||||
|
|
|
@ -5,12 +5,12 @@ import java.awt.Dimension;
|
|||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import com.bytezone.common.Platform;
|
||||
import com.bytezone.common.Platform.FontSize;
|
||||
import com.bytezone.common.Platform.FontType;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.disk.SectorType;
|
||||
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
|
||||
import com.bytezone.diskbrowser.utilities.FontUtility;
|
||||
import com.bytezone.diskbrowser.utilities.FontUtility.FontSize;
|
||||
import com.bytezone.diskbrowser.utilities.FontUtility.FontType;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskLegendPanel extends DiskPanel
|
||||
|
@ -25,7 +25,7 @@ class DiskLegendPanel extends DiskPanel
|
|||
public DiskLegendPanel ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
font = Platform.getFont (FontType.SANS_SERIF, FontSize.BASE);
|
||||
font = FontUtility.getFont (FontType.SANS_SERIF, FontSize.BASE);
|
||||
setBackground (Color.WHITE);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.EventListener;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.event.EventListenerList;
|
||||
|
||||
import com.bytezone.diskbrowser.utilities.DefaultAction;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class FontAction extends DefaultAction implements QuitListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final String prefsFontName = "prefsFontName";
|
||||
private static final String prefsFontSize = "prefsFontSize";
|
||||
private static Canvas canvas;
|
||||
|
||||
private final EventListenerList listenerList = new EventListenerList ();
|
||||
|
||||
private FontFrame frame;
|
||||
private String fontName;
|
||||
private String fontSize;
|
||||
private String text;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FontAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Set Font...", "Set display to a different font or font size",
|
||||
"/com/bytezone/loadlister/");
|
||||
int mask = Toolkit.getDefaultToolkit ().getMenuShortcutKeyMaskEx ();
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_F, mask));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (frame == null)
|
||||
{
|
||||
frame = new FontFrame (this);
|
||||
frame.setSelectedValue (fontName);
|
||||
frame.setSelectedSize (fontSize);
|
||||
frame.setText (text);
|
||||
}
|
||||
frame.setVisible (true);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void quit (Preferences preferences)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (frame != null)
|
||||
{
|
||||
String fontName = frame.getSelectedValue ();
|
||||
preferences.put (prefsFontName, fontName == null ? "Monospaced" : fontName);
|
||||
String fontSize = frame.getSelectedSize ();
|
||||
preferences.put (prefsFontSize, fontSize == null ? "12 point" : fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void restore (Preferences preferences)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String fontName = preferences.get (prefsFontName, "Monospaced");
|
||||
if (fontName.isEmpty ())
|
||||
fontName = "Monospaced";
|
||||
|
||||
this.fontName = fontName;
|
||||
if (frame != null)
|
||||
frame.setSelectedValue (fontName);
|
||||
|
||||
String fontSize = preferences.get (prefsFontSize, "12 point");
|
||||
if (fontSize.isEmpty ())
|
||||
fontSize = "12 point";
|
||||
|
||||
this.fontSize = fontSize;
|
||||
if (frame != null)
|
||||
frame.setSelectedSize (fontSize);
|
||||
|
||||
int pos = fontSize.indexOf (' ');
|
||||
int size = Integer.parseInt (fontSize.substring (0, pos));
|
||||
fireFontChangeEvent (new Font (fontName, Font.PLAIN, size));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setSampleText (String text)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.text = text;
|
||||
if (frame != null)
|
||||
frame.setText (text);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public interface FontChangeListener extends EventListener
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
public void changeFont (FontChangeEvent fontChangeEvent);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public class FontChangeEvent
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
public final Font font;
|
||||
public final FontMetrics fontMetrics;
|
||||
|
||||
public FontChangeEvent (Font font)
|
||||
{
|
||||
this.font = font;
|
||||
if (canvas == null)
|
||||
canvas = new Canvas ();
|
||||
fontMetrics = canvas.getFontMetrics (font);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addFontChangeListener (FontChangeListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.add (FontChangeListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void removeFontChangeListener (FontChangeListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.remove (FontChangeListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void fireFontChangeEvent (Font font)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
FontChangeEvent fontChangeEvent = new FontChangeEvent (font);
|
||||
FontChangeListener[] listeners =
|
||||
(listenerList.getListeners (FontChangeListener.class));
|
||||
for (FontChangeListener listener : listeners)
|
||||
listener.changeFont (fontChangeEvent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import com.bytezone.input.ButtonPanel;
|
||||
import com.bytezone.input.ColumnPanel;
|
||||
import com.bytezone.input.InputPanel;
|
||||
import com.bytezone.input.RadioButtonPanel;
|
||||
import com.bytezone.input.RowPanel;
|
||||
import com.bytezone.input.ScrollPanel;
|
||||
import com.bytezone.input.TextAreaPanel;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class FontFrame extends JFrame
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final JList<String> fontList =
|
||||
new JList<String> (new DefaultListModel<String> ());
|
||||
private final FontAction fontAction;
|
||||
|
||||
private String initialFont;
|
||||
private String initialSize;
|
||||
|
||||
private RadioButtonPanel fontSizePanel;
|
||||
private TextAreaPanel textPanel;
|
||||
private JButton btnCancel;
|
||||
private JButton btnOK;
|
||||
private JButton btnApply;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FontFrame (FontAction fontAction)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Font Selection");
|
||||
this.fontAction = fontAction;
|
||||
buildLayout ();
|
||||
getFonts ();
|
||||
setListeners ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void buildLayout ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
fontList.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
|
||||
JScrollPane sp = new JScrollPane (fontList);
|
||||
sp.setVerticalScrollBarPolicy (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
ScrollPanel listPanel = new ScrollPanel (sp, 200, 300); // width, height
|
||||
|
||||
fontSizePanel = new RadioButtonPanel (
|
||||
new String[][] { { "6 point", "7 point", "8 point", "9 point", "10 point",
|
||||
"11 point", "12 point", "13 point", "14 point", "15 point",
|
||||
"16 point", "18 point", } });
|
||||
|
||||
InputPanel.setTextLength (80);
|
||||
textPanel = new TextAreaPanel (10);
|
||||
|
||||
ButtonPanel buttonPanel = new ButtonPanel (new String[] { "Cancel", "OK", "Apply" });
|
||||
btnCancel = buttonPanel.getItem (0);
|
||||
btnOK = buttonPanel.getItem (1);
|
||||
btnApply = buttonPanel.getItem (2);
|
||||
|
||||
RowPanel rp = new RowPanel (new RowPanel ("Font", listPanel),
|
||||
new RowPanel ("Size", fontSizePanel), new RowPanel ("Sample code", textPanel));
|
||||
|
||||
add (new ColumnPanel (rp, buttonPanel));
|
||||
|
||||
pack ();
|
||||
setResizable (false);
|
||||
setLocationRelativeTo (null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setText (String text)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
textPanel.getItem (0).setText (text);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getSelectedValue ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String fontName = fontList.getSelectedValue ();
|
||||
return fontName;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setSelectedValue (String fontName)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
fontList.setSelectedValue (fontName, true);
|
||||
initialFont = fontName;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getSelectedSize ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String fontSize = fontSizePanel.getSelectedText ();
|
||||
return fontSize;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setSelectedSize (String fontSize)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
fontSizePanel.setSelected (fontSize);
|
||||
initialSize = fontSize;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void getFonts ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String fonts[] =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment ().getAvailableFontFamilyNames ();
|
||||
String pf[] =
|
||||
{ "Andale Mono", "Anonymous Pro", "Anonymous Pro Minus", "Apple2Forever",
|
||||
"Apple2Forever80", "Consolas", "Bitstream Vera Sans Mono", "Consolas",
|
||||
"Courier", "Courier New", "DejaVu Sans Mono", "Envy Code R", "Inconsolata",
|
||||
"Input Mono", "Input Mono Narrow", "Iosevka", "Lucida Sans Typewriter",
|
||||
"Luculent", "Menlo", "Monaco", "monofur", "Monospaced", "Nimbus Mono L",
|
||||
"PCMyungjo", "PR Number 3", "Pragmata", "Print Char 21", "ProFont", "ProFontX",
|
||||
"Proggy", "PT Mono", "Source Code Pro", "Ubuntu Mono" };
|
||||
|
||||
DefaultListModel<String> lm = (DefaultListModel<String>) fontList.getModel ();
|
||||
|
||||
int ptr = 0;
|
||||
for (String fontName : fonts)
|
||||
{
|
||||
while (ptr < pf.length)
|
||||
{
|
||||
int result = fontName.compareToIgnoreCase (pf[ptr]);
|
||||
if (result >= 0)
|
||||
{
|
||||
++ptr;
|
||||
if (result > 0)
|
||||
continue;
|
||||
lm.addElement (fontName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fontList.setSelectedValue (initialFont, true);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setListeners ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
addComponentListener (new ComponentAdapter ()
|
||||
{
|
||||
@Override
|
||||
public void componentShown (ComponentEvent e)
|
||||
{
|
||||
if (fontList.getModel ().getSize () == 0)
|
||||
getFonts ();
|
||||
|
||||
initialFont = getSelectedValue ();
|
||||
initialSize = getSelectedSize ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden (ComponentEvent e)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
fontList.addListSelectionListener (new ListSelectionListener ()
|
||||
{
|
||||
@Override
|
||||
public void valueChanged (ListSelectionEvent e)
|
||||
{
|
||||
if (e.getValueIsAdjusting ())
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.addActionListener (new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
setVisible (false);
|
||||
setSelectedValue (initialFont);
|
||||
setSelectedSize (initialSize);
|
||||
}
|
||||
});
|
||||
|
||||
btnOK.addActionListener (new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
setVisible (false);
|
||||
setSelection ();
|
||||
}
|
||||
});
|
||||
|
||||
btnApply.addActionListener (new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
setSelection ();
|
||||
}
|
||||
});
|
||||
|
||||
fontList.addListSelectionListener (new ListSelectionListener ()
|
||||
{
|
||||
@Override
|
||||
public void valueChanged (ListSelectionEvent e)
|
||||
{
|
||||
if (e.getValueIsAdjusting ())
|
||||
return;
|
||||
|
||||
Font font = getCurrentFont ();
|
||||
if (font != null)
|
||||
textPanel.getItem (0).setFont (font);
|
||||
}
|
||||
});
|
||||
|
||||
fontSizePanel.addActionListener (new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
textPanel.getItem (0).setFont (getCurrentFont ());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private Font getCurrentFont ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String fontName = getSelectedValue ();
|
||||
String fontSize = getSelectedSize ();
|
||||
if (fontSize.isEmpty ())
|
||||
return null;
|
||||
int pos = fontSize.indexOf (' ');
|
||||
int size = Integer.parseInt (fontSize.substring (0, pos));
|
||||
return new Font (fontName, Font.PLAIN, size);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setSelection ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
initialFont = getSelectedValue ();
|
||||
initialSize = getSelectedSize ();
|
||||
int pos = initialSize.indexOf (' ');
|
||||
int size = Integer.parseInt (initialSize.substring (0, pos));
|
||||
Font font = new Font (initialFont, Font.PLAIN, size);
|
||||
fontAction.fireFontChangeEvent (font);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ import javax.swing.JMenuItem;
|
|||
import javax.swing.JRadioButtonMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.FontAction;
|
||||
import com.bytezone.diskbrowser.applefile.AssemblerProgram;
|
||||
import com.bytezone.diskbrowser.applefile.BasicProgram;
|
||||
import com.bytezone.diskbrowser.applefile.HiResImage;
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.diskbrowser.utilities.DefaultAction;
|
||||
|
||||
// ********** not currently used ***********
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class PreferencesAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
JFrame owner;
|
||||
Preferences prefs;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public PreferencesAction (JFrame owner, Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Preferences...", "Set preferences", "/com/bytezone/diskbrowser/icons/");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt P"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_P);
|
||||
|
||||
setIcon (Action.LARGE_ICON_KEY, "script_gear_32.png");
|
||||
this.owner = owner;
|
||||
this.prefs = prefs;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
prefs ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void prefs ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
new PreferencesDialog (owner, prefs);
|
||||
}
|
||||
}
|
|
@ -1,230 +0,0 @@
|
|||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.InputMap;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SpringLayout;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.bytezone.common.FontTester;
|
||||
import com.bytezone.input.SpringUtilities;
|
||||
|
||||
// not currently used
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class PreferencesDialog extends JDialog
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
static final String prefsCatalogFont = "CatalogFont";
|
||||
static final String prefsDataFont = "DataFont";
|
||||
static final String prefsCatalogFontSize = "CatalogFontSize";
|
||||
static final String prefsDataFontSize = "DataFontSize";
|
||||
|
||||
static final String defaultFontName = "Lucida Sans Typewriter";
|
||||
static final int defaultFontSize = 12;
|
||||
static final String[] monoFonts = new FontTester ().getMonospacedFontList ();
|
||||
|
||||
private final JComboBox<String> catalogFontList = new JComboBox<String> (monoFonts);
|
||||
private final JComboBox<String> dataFontList = new JComboBox<String> (monoFonts);
|
||||
private final String[] sizes =
|
||||
{ "8", "9", "10", "11", "12", "13", "14", "15", "16", "18" };
|
||||
private final JComboBox<String> catalogFontSizes = new JComboBox<String> (sizes);
|
||||
private final JComboBox<String> dataFontSizes = new JComboBox<String> (sizes);
|
||||
private final Preferences prefs;
|
||||
|
||||
private final JButton apply = new JButton ("Apply");
|
||||
|
||||
private String catalogFontName;
|
||||
private String dataFontName;
|
||||
private int catalogFontSize;
|
||||
private int dataFontSize;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
PreferencesDialog (JFrame owner, Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (owner, "Set Preferences", false);
|
||||
|
||||
this.prefs = prefs;
|
||||
System.out.println ("********* not used ***********");
|
||||
|
||||
catalogFontName = prefs.get (prefsCatalogFont, defaultFontName);
|
||||
dataFontName = prefs.get (prefsDataFont, defaultFontName);
|
||||
catalogFontSize = prefs.getInt (prefsCatalogFontSize, defaultFontSize);
|
||||
dataFontSize = prefs.getInt (prefsDataFontSize, defaultFontSize);
|
||||
|
||||
catalogFontList.setSelectedItem (catalogFontName);
|
||||
dataFontList.setSelectedItem (dataFontName);
|
||||
catalogFontSizes.setSelectedItem (catalogFontSize + "");
|
||||
dataFontSizes.setSelectedItem (dataFontSize + "");
|
||||
|
||||
catalogFontList.setMaximumRowCount (30);
|
||||
dataFontList.setMaximumRowCount (30);
|
||||
catalogFontSizes.setMaximumRowCount (sizes.length);
|
||||
dataFontSizes.setMaximumRowCount (sizes.length);
|
||||
|
||||
Listener listener = new Listener ();
|
||||
catalogFontList.addActionListener (listener);
|
||||
dataFontList.addActionListener (listener);
|
||||
catalogFontSizes.addActionListener (listener);
|
||||
dataFontSizes.addActionListener (listener);
|
||||
|
||||
setDefaultCloseOperation (DISPOSE_ON_CLOSE);
|
||||
setResizable (false);
|
||||
addCancelByEscapeKey (); // doesn't seem to work
|
||||
|
||||
JPanel layoutPanel = new JPanel ();
|
||||
layoutPanel.setBorder (new EmptyBorder (10, 20, 0, 20)); // T/L/B/R
|
||||
layoutPanel.setLayout (new SpringLayout ());
|
||||
|
||||
layoutPanel.add (new JLabel ("Catalog panel font", JLabel.TRAILING));
|
||||
layoutPanel.add (catalogFontList);
|
||||
layoutPanel.add (catalogFontSizes);
|
||||
|
||||
layoutPanel.add (new JLabel ("Output panel font", JLabel.TRAILING));
|
||||
layoutPanel.add (dataFontList);
|
||||
layoutPanel.add (dataFontSizes);
|
||||
|
||||
SpringUtilities.makeCompactGrid (layoutPanel, 2, 3, //rows, cols
|
||||
10, 5, //initX, initY
|
||||
10, 5); //xPad, yPad
|
||||
|
||||
JPanel panel = new JPanel (new BorderLayout ());
|
||||
panel.add (layoutPanel, BorderLayout.CENTER);
|
||||
panel.add (getCommandPanel (), BorderLayout.SOUTH);
|
||||
getContentPane ().add (panel);
|
||||
|
||||
pack ();
|
||||
setLocationRelativeTo (owner);
|
||||
setVisible (true);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private JComponent getCommandPanel ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
JButton cancel = new JButton ("Cancel");
|
||||
cancel.addActionListener (new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent event)
|
||||
{
|
||||
closeDialog ();
|
||||
}
|
||||
});
|
||||
|
||||
apply.setEnabled (false);
|
||||
apply.addActionListener (new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent event)
|
||||
{
|
||||
updatePreferences ();
|
||||
apply.setEnabled (false);
|
||||
}
|
||||
});
|
||||
|
||||
JButton ok = new JButton ("OK");
|
||||
getRootPane ().setDefaultButton (ok);
|
||||
ok.addActionListener (new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent event)
|
||||
{
|
||||
updatePreferences ();
|
||||
closeDialog ();
|
||||
}
|
||||
});
|
||||
|
||||
JPanel commandPanel = new JPanel ();
|
||||
commandPanel.add (cancel);
|
||||
commandPanel.add (apply);
|
||||
commandPanel.add (ok);
|
||||
|
||||
return commandPanel;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void updatePreferences ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String newFontName = (String) catalogFontList.getSelectedItem ();
|
||||
if (!newFontName.equals (catalogFontName))
|
||||
{
|
||||
prefs.put (prefsCatalogFont, newFontName);
|
||||
catalogFontName = newFontName;
|
||||
}
|
||||
|
||||
newFontName = (String) dataFontList.getSelectedItem ();
|
||||
if (!newFontName.equals (dataFontName))
|
||||
{
|
||||
prefs.put (prefsDataFont, newFontName);
|
||||
dataFontName = newFontName;
|
||||
}
|
||||
|
||||
int newFontSize = Integer.parseInt ((String) catalogFontSizes.getSelectedItem ());
|
||||
if (newFontSize != catalogFontSize)
|
||||
{
|
||||
prefs.putInt (prefsCatalogFontSize, newFontSize);
|
||||
catalogFontSize = newFontSize;
|
||||
}
|
||||
|
||||
newFontSize = Integer.parseInt ((String) dataFontSizes.getSelectedItem ());
|
||||
if (newFontSize != dataFontSize)
|
||||
{
|
||||
prefs.putInt (prefsDataFontSize, newFontSize);
|
||||
dataFontSize = newFontSize;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addCancelByEscapeKey ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY";
|
||||
int noModifiers = 0;
|
||||
KeyStroke escapeKey = KeyStroke.getKeyStroke (KeyEvent.VK_ESCAPE, noModifiers, false);
|
||||
InputMap inputMap =
|
||||
getRootPane ().getInputMap (JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
inputMap.put (escapeKey, CANCEL_ACTION_KEY);
|
||||
AbstractAction cancelAction = new AbstractAction ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
closeDialog ();
|
||||
}
|
||||
};
|
||||
getRootPane ().getActionMap ().put (CANCEL_ACTION_KEY, cancelAction);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void closeDialog ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
dispose ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class Listener implements ActionListener
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
apply.setEnabled (true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,10 +8,10 @@ import java.awt.Rectangle;
|
|||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import com.bytezone.common.Platform;
|
||||
import com.bytezone.common.Platform.FontSize;
|
||||
import com.bytezone.common.Platform.FontType;
|
||||
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
|
||||
import com.bytezone.diskbrowser.utilities.FontUtility;
|
||||
import com.bytezone.diskbrowser.utilities.FontUtility.FontSize;
|
||||
import com.bytezone.diskbrowser.utilities.FontUtility.FontType;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class ScrollRuler extends JComponent
|
||||
|
@ -24,7 +24,7 @@ class ScrollRuler extends JComponent
|
|||
public static final int HORIZONTAL = 0;
|
||||
public static final int VERTICAL = 1;
|
||||
|
||||
private final Font font = Platform.getFont (FontType.SANS_SERIF, FontSize.BASE);
|
||||
private final Font font = FontUtility.getFont (FontType.SANS_SERIF, FontSize.BASE);
|
||||
private final int orientation;
|
||||
private boolean isHex = true;
|
||||
private boolean isTrackMode = true;
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package com.bytezone.diskbrowser.utilities;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
public class FontUtility
|
||||
{
|
||||
public static final String OS = System.getProperty ("os.name").toLowerCase ();
|
||||
public static final String userHome = System.getProperty ("user.home");
|
||||
public static final boolean MAC = OS.startsWith ("mac os");
|
||||
public static final boolean MAC_OS_X = OS.startsWith ("mac os x");
|
||||
public static final boolean LINUX = OS.equals ("linux");
|
||||
public static final boolean WINDOWS = OS.startsWith ("windows");
|
||||
public static final String USER = System.getProperty ("user.name");
|
||||
|
||||
private static GraphicsEnvironment ge =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment ();
|
||||
public static String[] fontNames = ge.getAvailableFontFamilyNames ();
|
||||
|
||||
public static enum FontType
|
||||
{
|
||||
PLAIN, SANS_SERIF, SERIF, MONOSPACED
|
||||
};
|
||||
|
||||
public static enum FontSize
|
||||
{
|
||||
BASE_MINUS_2, BASE_MINUS_1, BASE, BASE_PLUS_1, BASE_PLUS_2
|
||||
};
|
||||
|
||||
public static String fontName =
|
||||
MAC_OS_X ? "Monaco" : WINDOWS ? "Lucida Sans Typewriter" : "Lucida Sans Typewriter";
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public static boolean isFontAvailable (String name)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
for (String s : fontNames)
|
||||
if (s.equals (name))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public static Font getFont (FontType fontType, FontSize fontSize)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
switch (fontSize)
|
||||
{
|
||||
case BASE:
|
||||
return getFont (fontType, 12);
|
||||
case BASE_PLUS_1:
|
||||
return getFont (fontType, 14);
|
||||
case BASE_PLUS_2:
|
||||
return getFont (fontType, 16);
|
||||
case BASE_MINUS_1:
|
||||
return getFont (fontType, 10);
|
||||
case BASE_MINUS_2:
|
||||
return getFont (fontType, 8);
|
||||
}
|
||||
return getFont (fontType, 12);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public static Font getFont (FontType fontType, int type, int fontSize)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
assert isFontAvailable (fontName);
|
||||
|
||||
switch (fontType)
|
||||
{
|
||||
case PLAIN:
|
||||
return new Font (fontName, type, fontSize);
|
||||
case SANS_SERIF:
|
||||
return new Font (fontName, type, fontSize);
|
||||
case SERIF:
|
||||
return new Font ("Serif", type, fontSize);
|
||||
case MONOSPACED:
|
||||
return new Font ("Monospaced", type, fontSize);
|
||||
default:
|
||||
return new Font (fontName, type, fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public static Font getFont (FontType fontType, int fontSize)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return getFont (fontType, Font.PLAIN, fontSize);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue