Java tutorial
// Description: Java 7 Swing Finder JInternalFrame implementation for EnPhrase. /* * CFEnSyntax * * Copyright (c) 2014 Mark Sobkow * * This program is available as free software under the GNU GPL v3, or * under a commercial license from Mark Sobkow. For commercial licensing * details, please contact msobkow@sasktel.net. * * Under the terms of the GPL: * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * This source code incorporates modified modules originally licensed * under the Apache 2.0 license by MSS Code Factory including CFSecurity * (net-sourceforge-msscodefactory-2.1-cfsecurity.xml), * CFInternet (net-sourceforge-msscodefactory-2.1-cfinternet.xml), and * CFCrm 2.1 (net-sourceforge-msscodefactory-2.1-cfcrm.xml), with all of the * required models being available as part of the MSS Code Factory 2.0 * distribution source and install zips. * * You can download installations of MSS Code Factory 2.0 from * http://msscodefactory.sourceforge.net/ * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfensyntax.v2_1.CFEnSyntaxSwing; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import net.sourceforge.msscodefactory.cflib.v2_1.CFLib.*; import net.sourceforge.msscodefactory.cflib.v2_1.CFLib.Swing.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cfensyntax.v2_1.CFEnSyntax.*; import net.sourceforge.msscodefactory.cfensyntax.v2_1.CFEnSyntaxObj.*; /** * CFEnSyntaxSwingEnPhraseFinderJInternalFrame Swing Finder JInternalFrame implementation * for EnPhrase. */ public class CFEnSyntaxSwingEnPhraseFinderJInternalFrame extends CFJInternalFrame implements ICFEnSyntaxSwingEnPhraseJPanelCommon { protected ICFEnSyntaxSwingSchema swingSchema = null; protected JPanel swingFinderJPanel = null; protected JMenuBar finderMenuBar = null; protected JMenu menuFile = null; protected Action actionClose = null; protected JMenu menuAdd = null; protected ViewEditInternalFrameListener viewEditInternalFrameListener = null; protected Action actionAddEnPhrase = null; protected ActionViewSelectedEnPhrase actionViewSelected = null; protected ActionEditSelectedEnPhrase actionEditSelected = null; protected ActionDeleteSelectedEnPhrase actionDeleteSelected = null; protected class ViewEditInternalFrameListener implements InternalFrameListener { public ViewEditInternalFrameListener() { } public void internalFrameActivated(InternalFrameEvent e) { } public void internalFrameClosed(InternalFrameEvent e) { ((ICFJRefreshCallback) swingFinderJPanel).refreshMe(); } public void internalFrameClosing(InternalFrameEvent e) { } public void internalFrameDeactivated(InternalFrameEvent e) { } public void internalFrameIconified(InternalFrameEvent e) { } public void internalFrameDeiconified(InternalFrameEvent e) { } public void internalFrameOpened(InternalFrameEvent e) { } } protected class ActionClose extends AbstractAction { public ActionClose() { super(); putValue(Action.NAME, "Close"); setEnabled(true); } public void actionPerformed(ActionEvent e) { try { setClosed(true); } catch (Exception x) { } } } protected class ActionViewSelectedEnPhrase extends AbstractAction { public ActionViewSelectedEnPhrase() { super(); putValue(Action.NAME, "View Selected..."); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; ICFEnSyntaxSchemaObj schemaObj = swingSchema.getSchema(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "schemaObj"); } ICFEnSyntaxEnPhraseObj selectedInstance = getSwingFocusAsEnPhrase(); if (selectedInstance != null) { String classCode = selectedInstance.getClassCode(); if ("ENPH".equals(classCode)) { JInternalFrame frame = swingSchema.getEnPhraseFactory() .newViewEditJInternalFrame(selectedInstance); frame.addInternalFrameListener(getViewEditInternalFrameListener()); ((ICFEnSyntaxSwingEnPhraseJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View); getDesktopPane().add(frame); frame.setVisible(true); frame.show(); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "selectedInstance", selectedInstance, "ICFEnSyntaxEnPhraseObj"); } } } } protected class ActionEditSelectedEnPhrase extends AbstractAction { public ActionEditSelectedEnPhrase() { super(); putValue(Action.NAME, "Edit Selected..."); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; ICFEnSyntaxSchemaObj schemaObj = swingSchema.getSchema(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "schemaObj"); } ICFEnSyntaxEnPhraseObj selectedInstance = getSwingFocusAsEnPhrase(); if (selectedInstance != null) { String classCode = selectedInstance.getClassCode(); if ("ENPH".equals(classCode)) { JInternalFrame frame = swingSchema.getEnPhraseFactory() .newViewEditJInternalFrame(selectedInstance); frame.addInternalFrameListener(getViewEditInternalFrameListener()); ((ICFEnSyntaxSwingEnPhraseJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.Edit); getDesktopPane().add(frame); frame.setVisible(true); frame.show(); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "selectedInstance", selectedInstance, "ICFEnSyntaxEnPhraseObj"); } } } } protected class ActionDeleteSelectedEnPhrase extends AbstractAction { public ActionDeleteSelectedEnPhrase() { super(); putValue(Action.NAME, "Delete Selected..."); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; ICFEnSyntaxSchemaObj schemaObj = swingSchema.getSchema(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "schemaObj"); } ICFEnSyntaxEnPhraseObj selectedInstance = getSwingFocusAsEnPhrase(); if (selectedInstance != null) { String classCode = selectedInstance.getClassCode(); if ("ENPH".equals(classCode)) { JInternalFrame frame = swingSchema.getEnPhraseFactory() .newAskDeleteJInternalFrame(selectedInstance); ((ICFEnSyntaxSwingEnPhraseJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View); frame.addInternalFrameListener(getViewEditInternalFrameListener()); getDesktopPane().add(frame); frame.setVisible(true); frame.show(); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "selectedInstance", selectedInstance, "ICFEnSyntaxEnPhraseObj"); } } } } protected class ActionAddEnPhrase extends AbstractAction { public ActionAddEnPhrase() { super(); putValue(Action.NAME, "Add EnPhrase..."); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; ICFEnSyntaxSchemaObj schemaObj = swingSchema.getSchema(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "schemaObj"); } ICFEnSyntaxEnPhraseObj obj = schemaObj.getEnPhraseTableObj().newInstance(); ICFEnSyntaxEnPhraseEditObj edit = (ICFEnSyntaxEnPhraseEditObj) (obj.beginEdit()); if (edit == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "edit"); } JInternalFrame frame = swingSchema.getEnPhraseFactory().newViewEditJInternalFrame(obj); frame.addInternalFrameListener(getViewEditInternalFrameListener()); ICFEnSyntaxSwingEnPhraseJPanelCommon jpanelCommon = (ICFEnSyntaxSwingEnPhraseJPanelCommon) frame; jpanelCommon.setPanelMode(CFJPanel.PanelMode.Add); getDesktopPane().add(frame); frame.setVisible(true); frame.show(); } } public CFEnSyntaxSwingEnPhraseFinderJInternalFrame(ICFEnSyntaxSwingSchema argSchema) { super(); final String S_ProcName = "construct-schema-focus"; if (argSchema == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "argSchema"); } setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); swingSchema = argSchema; swingFinderJPanel = argSchema.getEnPhraseFactory().newFinderJPanel(); setContentPane(swingFinderJPanel); Dimension dim = new Dimension(1024, 480); setSize(dim); dim = new Dimension(320, 240); setMinimumSize(dim); setTitle("Find EnPhrase"); setJMenuBar(getFinderMenuBar()); setIconifiable(true); setMaximizable(true); setResizable(true); setClosable(false); adjustFinderMenuBar(); } public ICFEnSyntaxSwingSchema getSwingSchema() { return (swingSchema); } public JMenuBar getFinderMenuBar() { if (finderMenuBar == null) { JMenuItem menuItem; finderMenuBar = new JMenuBar(); menuFile = new JMenu("File"); actionAddEnPhrase = new ActionAddEnPhrase(); menuItem = new JMenuItem(actionAddEnPhrase); menuFile.add(menuItem); actionViewSelected = new ActionViewSelectedEnPhrase(); menuItem = new JMenuItem(actionViewSelected); menuFile.add(menuItem); actionEditSelected = new ActionEditSelectedEnPhrase(); menuItem = new JMenuItem(actionEditSelected); menuFile.add(menuItem); actionDeleteSelected = new ActionDeleteSelectedEnPhrase(); menuItem = new JMenuItem(actionDeleteSelected); menuFile.add(menuItem); actionClose = new ActionClose(); menuItem = new JMenuItem(actionClose); menuFile.add(menuItem); finderMenuBar.add(menuFile); } return (finderMenuBar); } public void setSwingFocus(ICFLibAnyObj value) { final String S_ProcName = "setSwingFocus"; if ((value == null) || (value instanceof ICFEnSyntaxEnPhraseObj)) { super.setSwingFocus(value); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "value", value, "ICFEnSyntaxEnPhraseObj"); } adjustFinderMenuBar(); } public ICFEnSyntaxEnPhraseObj getSwingFocusAsEnPhrase() { return ((ICFEnSyntaxEnPhraseObj) getSwingFocus()); } public void setSwingFocusAsEnPhrase(ICFEnSyntaxEnPhraseObj value) { setSwingFocus(value); } public void adjustFinderMenuBar() { JMenuItem menuItem; Action act; String itemLabel; ICFEnSyntaxEnPhraseObj selectedObj = getSwingFocusAsEnPhrase(); boolean enableState; if (selectedObj == null) { enableState = false; } else { enableState = true; } if (actionViewSelected != null) { actionViewSelected.setEnabled(enableState); } if (actionEditSelected != null) { actionEditSelected.setEnabled(enableState); } if (actionDeleteSelected != null) { actionDeleteSelected.setEnabled(enableState); } if (actionAddEnPhrase != null) { actionAddEnPhrase.setEnabled(true); } if (menuFile != null) { int itemCount = menuFile.getItemCount(); for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { menuItem = menuFile.getItem(itemIdx); act = menuItem.getAction(); if (act != null) { if (act == actionViewSelected) { menuItem.setEnabled(enableState); } else if (act == actionEditSelected) { menuItem.setEnabled(enableState); } else if (act == actionDeleteSelected) { menuItem.setEnabled(enableState); } else if (act == actionAddEnPhrase) { menuItem.setEnabled(true); } } } } } protected ViewEditInternalFrameListener getViewEditInternalFrameListener() { if (viewEditInternalFrameListener == null) { viewEditInternalFrameListener = new ViewEditInternalFrameListener(); } return (viewEditInternalFrameListener); } }