moving common functions inhouse

This commit is contained in:
Denis Molony 2020-06-26 14:39:05 +10:00
parent 39bdb3d00a
commit 59f794906e
13 changed files with 144 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import javax.swing.Action;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// this is not being used
// -----------------------------------------------------------------------------------//

View File

@ -4,7 +4,7 @@ import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
class CreateDatabaseAction extends DefaultAction

View File

@ -9,9 +9,9 @@ import javax.swing.Action;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.duplicates.DiskDetails;
import com.bytezone.diskbrowser.duplicates.RootFolderData;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
public class DuplicateAction extends DefaultAction implements RootDirectoryChangeListener

View File

@ -5,8 +5,8 @@ import java.awt.event.ActionEvent;
import javax.swing.Action;
import javax.swing.KeyStroke;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
class InterleaveAction extends DefaultAction

View File

@ -17,7 +17,6 @@ import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
import com.bytezone.common.EnvironmentAction;
import com.bytezone.common.FontAction;
import com.bytezone.diskbrowser.applefile.AssemblerProgram;
import com.bytezone.diskbrowser.applefile.BasicProgram;
@ -28,6 +27,7 @@ import com.bytezone.diskbrowser.applefile.VisicalcFile;
import com.bytezone.diskbrowser.disk.DataDisk;
import com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.prodos.ProdosDisk;
import com.bytezone.diskbrowser.utilities.EnvironmentAction;
// -----------------------------------------------------------------------------------//
class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitListener,

View File

@ -8,7 +8,7 @@ import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// ********** not currently used ***********

View File

@ -10,7 +10,7 @@ import java.awt.print.PrinterJob;
import javax.swing.Action;
import javax.swing.KeyStroke;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
class PrintAction extends DefaultAction

View File

@ -6,7 +6,7 @@ import java.awt.event.KeyEvent;
import javax.swing.Action;
import javax.swing.KeyStroke;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
class RefreshTreeAction extends DefaultAction

View File

@ -11,8 +11,7 @@ import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.KeyStroke;
import com.bytezone.common.DefaultAction;
import com.bytezone.common.Platform;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
class RootDirectoryAction extends DefaultAction implements QuitListener
@ -40,7 +39,7 @@ class RootDirectoryAction extends DefaultAction implements QuitListener
public void actionPerformed (ActionEvent e)
// ---------------------------------------------------------------------------------//
{
JFileChooser chooser = new JFileChooser (Platform.userHome);
JFileChooser chooser = new JFileChooser (System.getProperty ("user.home"));
chooser.setDialogTitle ("Select FOLDER containing disk images");
chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
if (rootFolder != null)

View File

@ -9,7 +9,7 @@ import java.nio.file.StandardOpenOption;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
class SaveSectorsAction extends DefaultAction implements SectorSelectionListener
@ -35,8 +35,7 @@ class SaveSectorsAction extends DefaultAction implements SectorSelectionListener
System.out.println ("No sectors");
return;
}
byte[] buffer =
event.getFormattedDisk ().getDisk ().readBlocks (event.getSectors ());
byte[] buffer = event.getFormattedDisk ().getDisk ().readBlocks (event.getSectors ());
JFileChooser fileChooser = new JFileChooser ();
fileChooser.setDialogTitle ("Save sectors");

View File

@ -8,8 +8,8 @@ import java.nio.file.Files;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import com.bytezone.common.DefaultAction;
import com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.utilities.DefaultAction;
// -----------------------------------------------------------------------------------//
class SaveTempFileAction extends DefaultAction

View File

@ -0,0 +1,46 @@
package com.bytezone.diskbrowser.utilities;
import java.net.URL;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
// -----------------------------------------------------------------------------------//
public abstract class DefaultAction extends AbstractAction
// -----------------------------------------------------------------------------------//
{
final String baseURL;
// ---------------------------------------------------------------------------------//
public DefaultAction (String text, String tip)
// ---------------------------------------------------------------------------------//
{
super (text);
this.baseURL = null;
putValue (Action.SHORT_DESCRIPTION, tip);
}
// ---------------------------------------------------------------------------------//
public DefaultAction (String text, String tip, String baseURL)
// ---------------------------------------------------------------------------------//
{
super (text);
this.baseURL = baseURL;
putValue (Action.SHORT_DESCRIPTION, tip);
}
// ---------------------------------------------------------------------------------//
protected void setIcon (String iconType, String iconName)
// ---------------------------------------------------------------------------------//
{
if (baseURL == null)
{
System.out.println ("Base URL not set");
return;
}
URL url = this.getClass ().getResource (baseURL + iconName);
if (url != null)
putValue (iconType, new ImageIcon (url));
}
}

View File

@ -0,0 +1,85 @@
package com.bytezone.diskbrowser.utilities;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
// -----------------------------------------------------------------------------------//
public class EnvironmentAction extends AbstractAction
// -----------------------------------------------------------------------------------//
{
// ---------------------------------------------------------------------------------//
public EnvironmentAction ()
// ---------------------------------------------------------------------------------//
{
super ("Environment...");
putValue (Action.SHORT_DESCRIPTION, "Display java details");
int mask = Toolkit.getDefaultToolkit ().getMenuShortcutKeyMaskEx ();
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_E, mask));
}
// ---------------------------------------------------------------------------------//
@Override
public void actionPerformed (ActionEvent e)
// ---------------------------------------------------------------------------------//
{
TextFormatter textFormatter = new TextFormatter ();
textFormatter.addLine ("Java version", System.getProperty ("java.runtime.version"));
textFormatter.addLine ();
String path = System.getProperty ("java.class.path");
for (String s : path.split (File.pathSeparator))
textFormatter.addLine ("Classpath", s);
JOptionPane.showMessageDialog (null, textFormatter.toLabel (), "Java Environment",
JOptionPane.INFORMATION_MESSAGE);
}
// ---------------------------------------------------------------------------------//
class TextFormatter
// ---------------------------------------------------------------------------------//
{
List<String> titles = new ArrayList<> ();
List<String> texts = new ArrayList<> ();
void addLine (String title, String text)
{
titles.add (title);
texts.add (text);
}
void addLine ()
{
addLine ("", "");
}
JLabel toLabel ()
{
StringBuilder text = new StringBuilder ("<html>");
for (int i = 0; i < texts.size (); i++)
{
String title = titles.get (i);
if (title.length () == 0)
text.append ("<br>");
else
text.append (String.format ("%s : %s<br>", title, texts.get (i)));
}
text.append ("</html>");
JLabel label = new JLabel (text.toString ());
label.setFont (new Font ("Monospaced", Font.PLAIN, 13));
return label;
}
}
}