com.dal.a.ui.DalAppConsole.java Source code

Java tutorial

Introduction

Here is the source code for com.dal.a.ui.DalAppConsole.java

Source

/*
 * Copyright (C) 1995-2016Dal Solutions, Inc.
 * All Rights Reserved
 * Inquire at License@dal-solutions.com
 */
package com.dal.a.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File;

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Dan Adams
 */
public abstract class DalAppConsole extends JFrame {

    private static final File CONFIG_FILE = new File("dal.cfg");
    private static final Logger LOG = LoggerFactory.getLogger(DalAppConsole.class);
    private static final long serialVersionUID = -2986263433548969718L;
    private JPanel detailView = new JPanel();
    private JPanel listView = new JPanel();
    private JPanel treeView = new JPanel();
    private JSplitPane parentPane = new JSplitPane();
    private JSplitPane centerPane = new JSplitPane();
    private Configuration config;

    public DalAppConsole() {
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setDefaultLookAndFeelDecorated(true);

        try {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } catch (ConfigurationException theX) {
            LOG.error("Config Failure", theX);
            throw new RuntimeException("Error reading in configuration", theX);
        }

        coreInit();
        coreSetup();
        init();
        setup();
        coreCleanup();
    }

    public void config(CommandLine cli) {
        for (Option opt : cli.getOptions()) {
            config.addProperty(opt.getOpt(), opt.getValues());
        }
    }

    public JPanel getDetailView() {
        return detailView;
    }

    public void setDetailView(JPanel detailView) {
        this.detailView = detailView;
    }

    public JPanel getListView() {
        return listView;
    }

    public void setListView(JPanel listView) {
        this.listView = listView;
    }

    public JPanel getTreeView() {
        return treeView;
    }

    public void setTreeView(JPanel treeView) {
        this.treeView = treeView;
    }

    public Configuration getConfig() {
        return config;
    }

    public void setConfig(Configuration config) {
        this.config = config;
    }

    public abstract void init();

    public abstract void setup();

    private void coreCleanup() {
        invalidate();
        setPreferredSize(new Dimension(800, 600));
        pack();
        parentPane.setDividerLocation(0.25);
        centerPane.setDividerLocation(0.25);

    }

    private void coreInit() {
    }

    private void coreSetup() {
        setLayout(new BorderLayout());
        setJMenuBar(initializeMenu());
        add(new DalStatusBar(), BorderLayout.SOUTH);

        parentPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
        parentPane.setTopComponent(treeView);
        parentPane.setBottomComponent(centerPane);

        centerPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
        centerPane.setLeftComponent(listView);
        centerPane.setRightComponent(detailView);

        add(parentPane, BorderLayout.CENTER);
    }

    private JMenuBar initializeMenu() {
        JMenuBar result = new JMenuBar();

        return result;
    }

}