All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lrgs.rtstat.NetlistMaintenanceDialog Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!
package lrgs.rtstat;

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ResourceBundle;

import javax.swing.*;

import ilex.gui.WindowUtility;
import ilex.util.EnvExpander;
import ilex.util.LoadResourceBundle;
import ilex.util.Logger;
import ilex.util.AuthException;
import lrgs.gui.DecodesInterface;
import lrgs.nledit.NetlistEditFrame;
import decodes.gui.GuiDialog;
import decodes.db.Database;
import decodes.db.NetworkListSpec;

public class NetlistMaintenanceDialog
    extends GuiDialog
{
    private static ResourceBundle labels = 
        RtStat.getLabels();
    private static ResourceBundle genericLabels = 
        RtStat.getGenericLabels();
    private JPanel mainPanel = new JPanel();
    private BorderLayout mainBorderLayout = new BorderLayout();
    private JPanel southButtonPanel = new JPanel();
    private FlowLayout flowLayout1 = new FlowLayout();
    private JButton okButton = new JButton();
    private JPanel centerPanel = new JPanel();
    private GridBagLayout gridBagLayout1 = new GridBagLayout();
    private JPanel serverListPanel = new JPanel();
    private JPanel serverActionPanel = new JPanel();
    private JButton refreshButton = new JButton();
    private GridBagLayout gridBagLayout2 = new GridBagLayout();
    private JButton retrieveButton = new JButton();
    private JButton installButton = new JButton();
    private BorderLayout serverListLayout = new BorderLayout();
    private JLabel serverListPanelHeader = new JLabel();
    private JPanel serverListSouthPanel = new JPanel();
    private JButton deleteFromServerButton = new JButton();
    private FlowLayout serverListSouthLayout = new FlowLayout();
    private JLabel emptyNorthLabel = new JLabel();
    private JScrollPane serverListScrollPane = new JScrollPane();
    private DefaultListModel serverListModel = new DefaultListModel();
    private JList serverList = new JList(serverListModel);
    private JPanel localListPanel = new JPanel();
    private JPanel localListButtonPanel = new JPanel();
    private JButton newLocalButton = new JButton();
    private GridBagLayout gridBagLayout3 = new GridBagLayout();
    private JButton editLocalButton = new JButton();
    private JLabel jLabel1 = new JLabel();
    private BorderLayout localListLayout = new BorderLayout();
    private JLabel localListHeader = new JLabel();
    private JPanel localListSouthPanel = new JPanel();
    private JButton deleteLocalCopyButton = new JButton();
    private FlowLayout localListSouthLayout = new FlowLayout();
    private JScrollPane localListScrollPane = new JScrollPane();
    private DefaultListModel localListModel = new DefaultListModel();
    private JList localList = new JList(localListModel);

    private DdsClientIf clientIf = null;
    private File localNlDir = null;
    private boolean dbOpenTried = false;
    private ArrayList netlistSpecs = null;

    /**
     * Constructor.
     * @param owner the owner
     */
    public NetlistMaintenanceDialog(Frame owner)
    {
        this(owner, labels.getString("NetlistMaintDialog.title"), false);
    }

    private NetlistMaintenanceDialog(Frame owner, String title, boolean modal)
    {
        super(owner, title, modal);
        try
        {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            mainPanel.setPreferredSize(new Dimension(650, 400));
            pack();
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
    }

    /**
     * Called from RtStatFrame prior to launching the dialog, this method
     * populates the lists.
     */
    public void startDialog(DdsClientIf clientIf, String nll[])
    {
        this.clientIf = clientIf;
        serverListModel.clear();
        if (nll != null)
        {
            Arrays.sort(nll);
            for(int i=0; i 0
            && "(DECODES)".equalsIgnoreCase(listname.substring(paren));
        if (paren>0)
            listname = listname.substring(0, paren-1);
        if (isDecodes)
        {
            for(NetworkListSpec nls : this.netlistSpecs)
                if (listname.equals(nls.getName()))
                {
                    decodes.db.NetworkList nl = 
                        new decodes.db.NetworkList(nls.getName(), 
                            nls.getTmType());
                    try
                    {
                        nl.read();
                        nl.prepareForExec();
                        String ds = nl.legacyNetworkList.toFileString();
                        clientIf.installNetlist(listname, ds.getBytes());
                    }
                    catch(Exception ex)
                    {
                        Logger.instance().warning(
                            "Cannot read DECODES netlist '"
                            + listname + "': " + ex);
                    }
                    break;
                }
        }
        else
        {
            File nl = new File(localNlDir, listname);
            try
            {
                FileInputStream fis = new FileInputStream(nl);
                byte data[] = new byte[(int)nl.length()];
                fis.read(data);
                fis.close();
                clientIf.installNetlist(listname, data);
            }
            catch(IOException ex)
            {
                showError(LoadResourceBundle.sprintf(
                        labels.getString(
                        "NetlistMaintDialog.readingFileErr"),
                        nl.getPath()) + ex);
            }
        }
    }

    private void deleteFromServerButton_actionPerformed()
    {
        try
        {
            int n = serverListModel.size();
            for(int i=0; i 0
            && "(DECODES)".equalsIgnoreCase(listname.substring(paren));
        if (paren>0)
            listname = listname.substring(0, paren-1);
        if (isDecodes)
        {
            showError("Cannot edit a DECODES list from this dialog."
                + " Use the DECODES Database Editor.");
            return;
        }
        NetlistEditFrame.netlistDir = localNlDir.getPath();
        NetlistEditFrame editor = new NetlistEditFrame();
        editor.setStandAlone(false);
        String path = localNlDir.getPath() + File.separator + listname;
        editor.openFile(path);
        WindowUtility.center(editor).setVisible(true);
    }

    private void deleteLocalCopyButton_actionPerformed(ActionEvent e)
    {
        int n = localListModel.size();
        for(int i=0; i 0
                    && "(DECODES)".equalsIgnoreCase(listname.substring(paren));
                if (paren>0)
                    listname = listname.substring(0, paren-1);
                if (isDecodes)
                {
                    showError("Cannot delete a DECODES list from this menu."
                        + " Use the DECODES Database Editor.");
                }
                else
                {
                    File fl = new File(localNlDir, listname);
                    if (!fl.delete())
                        System.out.println("Cannot delete '" + listname
                            + "' in directory '" + localNlDir + "'");
                }
            }
        refreshLocal();
    }

    private void refreshLocal()
    {
        localNlDir = new File(EnvExpander.expand("$LRGSHOME/netlist"));
        if (!localNlDir.isDirectory())
        {
            localNlDir = new File(EnvExpander.expand("$HOME/netlist"));
            if (!localNlDir.isDirectory())
            {
                localNlDir = new File(EnvExpander.expand(
                    "$DECODES_INSTALL_DIR/netlist"));
                if (!localNlDir.isDirectory())
                    localNlDir = new File(System.getProperty("user.dir"));
            }
        }
        Logger.instance().info("Reading network lists from '"
            + localNlDir.getPath() + "'");

        localListModel.clear();
        File files[] = localNlDir.listFiles();
        Arrays.sort(files);
        for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy