Java tutorial
// Description: Java 8 Swing Ask Delete JPanel implementation for DomainBase. /* * Code Factory Asterisk 11 Configuration Model * * Copyright (c) 2014-2015 Mark Sobkow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*; import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.Swing.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*; /** * CFAsteriskSwingDomainBaseAskDeleteJPanel Swing Ask Delete JPanel implementation * for DomainBase. */ public class CFAsteriskSwingDomainBaseAskDeleteJPanel extends CFJPanel implements ICFAsteriskSwingDomainBaseJPanelCommon { protected ICFAsteriskSwingSchema swingSchema = null; protected JTextArea textAreaMessage = null; protected class ActionOk extends AbstractAction { public ActionOk() { super(); putValue(Action.NAME, "Ok"); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; Container cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { JInternalFrame frame = (JInternalFrame) cont; if (frame instanceof ICFAsteriskSwingDomainBaseJPanelCommon) { ICFAsteriskSwingDomainBaseJPanelCommon jpanelCommon = (ICFAsteriskSwingDomainBaseJPanelCommon) frame; jpanelCommon.setPanelMode(CFJPanel.PanelMode.Delete); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "frame", frame, "ICFAsteriskSwingDomainBaseJPanelCommon"); } try { frame.setClosed(true); } catch (Exception x) { } } } } protected class ActionCancel extends AbstractAction { public ActionCancel() { super(); putValue(Action.NAME, "Cancel"); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; Container cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { JInternalFrame frame = (JInternalFrame) cont; if (frame instanceof ICFAsteriskSwingDomainBaseJPanelCommon) { ICFAsteriskSwingDomainBaseJPanelCommon jpanelCommon = (ICFAsteriskSwingDomainBaseJPanelCommon) frame; jpanelCommon.setPanelMode(CFJPanel.PanelMode.Unknown); ICFAsteriskDomainBaseEditObj editObj = (ICFAsteriskDomainBaseEditObj) jpanelCommon .getSwingFocusAsDomainBase().getEdit(); if (editObj != null) { editObj.endEdit(); } } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "frame", frame, "ICFAsteriskSwingDomainBaseJPanelCommon"); } try { frame.setClosed(true); } catch (Exception x) { } } } } protected Action actionOk = null; protected Action actionCancel = null; protected JButton buttonOk = null; protected JButton buttonCancel = null; protected JScrollPane scrollPane = null; protected JPanel attrJPanel = null; public CFAsteriskSwingDomainBaseAskDeleteJPanel(ICFAsteriskSwingSchema argSchema, ICFInternetDomainBaseObj argFocus) { super(); final String S_ProcName = "construct-schema-focus"; if (argSchema == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "argSchema"); } // argFocus is optional; focus may be set later during execution as // conditions of the runtime change. swingSchema = argSchema; swingFocus = argFocus; // Construct the various objects textAreaMessage = new JTextArea("Are you sure you want to delete this DomainBase?"); actionOk = new ActionOk(); actionCancel = new ActionCancel(); buttonOk = new JButton(actionOk); buttonCancel = new JButton(actionCancel); attrJPanel = argSchema.getDomainBaseFactory().newAttrJPanel(argFocus); scrollPane = new CFHSlaveJScrollPane(attrJPanel); // Lay out the widgets setSize(1024, 480); Dimension min = new Dimension(480, 300); setMinimumSize(min); add(textAreaMessage); textAreaMessage.setBounds(0, 0, 1024, 50); int xparts = (768 - (2 * 125)) / 3; add(buttonOk); buttonOk.setBounds(xparts, 55, 125, 40); add(buttonCancel); buttonCancel.setBounds(xparts + 125 + xparts, 55, 125, 40); add(scrollPane); scrollPane.setBounds(0, 100, 1024, 480 - 100); } public ICFAsteriskSwingSchema getSwingSchema() { return (swingSchema); } public void setSwingFocus(ICFLibAnyObj value) { final String S_ProcName = "setSwingFocus"; if ((value == null) || (value instanceof ICFInternetDomainBaseObj)) { super.setSwingFocus(value); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "value", value, "ICFInternetDomainBaseObj"); } } public ICFInternetDomainBaseObj getSwingFocusAsDomainBase() { return ((ICFInternetDomainBaseObj) getSwingFocus()); } public void setSwingFocusAsDomainBase(ICFInternetDomainBaseObj value) { swingFocus = value; if (attrJPanel != null) { ((ICFAsteriskSwingDomainBaseJPanelCommon) attrJPanel).setSwingFocus(value); } } public void doLayout() { Dimension sz = getSize(); textAreaMessage.setBounds(0, 0, sz.width, 50); int xparts = (sz.width - (2 * 125)) / 3; buttonOk.setBounds(xparts, 55, 125, 40); buttonCancel.setBounds(xparts + 125 + xparts, 55, 125, 40); scrollPane.setBounds(0, 100, sz.width, sz.height - 100); scrollPane.doLayout(); } public void setPanelMode(CFJPanel.PanelMode value) { final String S_ProcName = "setPanelMode"; CFJPanel.PanelMode oldMode = getPanelMode(); if (oldMode == value) { return; } if ((value != CFJPanel.PanelMode.Unknown) && (value != CFJPanel.PanelMode.View) && (value != CFJPanel.PanelMode.Delete)) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "AskDeleteJPanels only support PanelMode Unknown, View or Delete"); } super.setPanelMode(value); if (attrJPanel != null) { ((ICFAsteriskSwingDomainBaseJPanelCommon) attrJPanel).setPanelMode(value); } } }