DeityBasePanel.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
pcgen.gui.editor |
![]() |
![]() |
PCGen |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* DeityBasePanel.java
* Copyright 2002 (C) Greg Bingleman <byngl@hotmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Created on November 1, 2002, 9:27 AM
*
* @(#) $Id: DeityBasePanel.java 6641 2008-06-15 02:45:37Z jdempsey $
*/
package pcgen.gui.editor;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import pcgen.cdom.base.CDOMReference;
import pcgen.cdom.enumeration.ListKey;
import pcgen.cdom.enumeration.ObjectKey;
import pcgen.cdom.enumeration.StringKey;
import pcgen.cdom.reference.CDOMDirectSingleRef;
import pcgen.core.Description;
import pcgen.core.Globals;
import pcgen.core.PCAlignment;
import pcgen.core.PObject;
import pcgen.core.SettingsHandler;
import pcgen.core.WeaponProf;
import pcgen.gui.utils.JComboBoxEx;
import pcgen.persistence.PersistenceLayerException;
import pcgen.persistence.lst.GlobalLstToken;
import pcgen.persistence.lst.LstToken;
import pcgen.persistence.lst.TokenStore;
import pcgen.util.Logging;
import pcgen.util.PropertyFactory;
/**
* <code>DeityBasePanel</code>
*
* @author Greg Bingleman <byngl@hotmail.com>
* @version $Revision: 6641 $
*/
final class DeityBasePanel extends BasePanel
{
private AvailableSelectedPanel pnlFavoredWeapons;
private DescriptionPanel pnlDescription;
private JComboBoxEx cmbDeityAlignment;
private JLabel lblDeityAlignment;
private JLabel lblHolyItem;
private JPanel pnlDeityAlignment;
private JPanel pnlHolyItem;
private JTextField txtHolyItem;
/** Creates new form DeityBasePanel */
DeityBasePanel()
{
initComponents();
initComponentContents();
}
/**
* Set deity alignment
* @param aString
*/
public void setDeityAlignment(PCAlignment al)
{
if (al != null && al.isValidForDeity())
{
cmbDeityAlignment.setSelectedItem(al.getKeyName());
}
}
/**
* Get deity alignment
* @return deity alignment
*/
public String getDeityAlignment()
{
String aString = (String) cmbDeityAlignment.getSelectedItem();
if (aString != null)
{
final int dix = SettingsHandler.getGame().getIndexOfAlignment(aString);
if (dix >= 0)
{
return SettingsHandler.getGame().getShortAlignmentAtIndex(dix);
}
}
return null;
}
/**
* Set description is PI flag
* @param descIsPI
*/
public void setDescIsPI(final boolean descIsPI)
{
pnlDescription.setDescIsPI(descIsPI);
}
/**
* Get description is PI flag
* @return true if PI
*/
public boolean getDescIsPI()
{
return pnlDescription.getDescIsPI();
}
/**
* Set description text
* @param aString
*/
public void setDescriptionText(String aString)
{
pnlDescription.setText(aString);
}
/**
* Get description text
* @return description text
*/
public String getDescriptionText()
{
return pnlDescription.getText();
}
/**
* Set favoured weapons available list
* @param aList
* @param sort
*/
public void setFavoredWeaponsAvailableList(List<WeaponProf> aList, boolean sort)
{
pnlFavoredWeapons.setAvailableList(aList, sort);
}
/**
* Get the favoured weapons available list
* @return List of favoured weapons available
*/
public Object[] getFavoredWeaponsAvailableList()
{
return pnlFavoredWeapons.getAvailableList();
}
/**
* setFavoredWeaponsSelectedList
* @param aList
* @param sort
*/
public void setFavoredWeaponsSelectedList(List<WeaponProf> aList, boolean sort)
{
pnlFavoredWeapons.setSelectedList(aList, sort);
}
/**
* getFavoredWeaponsSelectedList
* @return getFavoredWeaponsSelectedList
*/
public Object[] getFavoredWeaponsSelectedList()
{
return pnlFavoredWeapons.getSelectedList();
}
/**
* Set holy item text
* @param aString
*/
public void setHolyItemText(String aString)
{
txtHolyItem.setText(aString);
}
/**
* Get holy item text
* @return holy item text
*/
public String getHolyItemText()
{
return txtHolyItem.getText().trim();
}
public void updateData(PObject thisPObject)
{
thisPObject.put(StringKey.HOLY_ITEM, getHolyItemText());
PCAlignment align = SettingsHandler.getGame().getAlignment(
getDeityAlignment());
thisPObject.put(ObjectKey.ALIGNMENT, align);
final String desc = getDescriptionText();
Map<String, LstToken> tokenMap = TokenStore.inst().getTokenMap(
GlobalLstToken.class);
GlobalLstToken tokenParser = (GlobalLstToken) tokenMap.get("DESC");
if (tokenParser != null)
{
final StringTokenizer tok = new StringTokenizer(".CLEAR\t"+desc, "\t");
while (tok.hasMoreTokens())
{
try
{
tokenParser.parse(thisPObject, tok.nextToken(), -9);
}
catch (PersistenceLayerException e)
{
Logging.errorPrint("Invalid Description: " + desc);
Logging.errorPrint(" Token Parse Failed: "
+ e.getLocalizedMessage());
}
}
}
thisPObject.put(ObjectKey.DESC_PI, getDescIsPI());
//
// Save favored weapon(s)
//
thisPObject.removeListFor(ListKey.DEITYWEAPON);
if (getFavoredWeaponsAvailableList().length == 0)
{
thisPObject.addToListFor(ListKey.DEITYWEAPON,
Globals.getContext().ref
.getCDOMAllReference(WeaponProf.class));
}
else
{
for (Object o : getFavoredWeaponsSelectedList())
{
CDOMReference<WeaponProf> ref = CDOMDirectSingleRef
.getRef(Globals.getContext().ref.silentlyGetConstructedCDOMObject(WeaponProf.class, o.toString()));
thisPObject.addToListFor(ListKey.DEITYWEAPON, ref);
}
}
}
public void updateView(PObject thisPObject)
{
setHolyItemText(thisPObject.get(StringKey.HOLY_ITEM));
final StringBuffer buf = new StringBuffer();
for ( final Description desc : thisPObject.getDescriptionList() )
{
if ( buf.length() != 0 )
{
buf.append("\t");
}
buf.append(desc.getPCCText());
}
setDescriptionText(buf.toString()); // don't want PI here
setDescIsPI(thisPObject.getSafe(ObjectKey.DESC_PI));
//
// Initialize the contents of the deity's alignment combo
//
setDeityAlignment(thisPObject.get(ObjectKey.ALIGNMENT));
//
// Initialize the contents of the available and selected favored weapons lists
//
List<WeaponProf> selectedList = new ArrayList<WeaponProf>();
List<WeaponProf> availableList = new ArrayList<WeaponProf>(Globals
.getContext().ref.getConstructedCDOMObjects(WeaponProf.class));
List<CDOMReference<WeaponProf>> dwp = thisPObject
.getSafeListFor(ListKey.DEITYWEAPON);
for (CDOMReference<WeaponProf> ref : dwp)
{
for (WeaponProf wp : ref.getContainedObjects())
{
selectedList.add(wp);
availableList.remove(wp);
}
}
setFavoredWeaponsAvailableList(availableList, true);
setFavoredWeaponsSelectedList(selectedList, true);
}
private void initComponentContents()
{
//
// Initialize the contents of the deity's alignment combo
//
List<String> availableList = new ArrayList<String>();
for (Iterator e = SettingsHandler.getGame().getUnmodifiableAlignmentList().iterator(); e.hasNext();)
{
final PCAlignment anAlignment = (PCAlignment) e.next();
if (anAlignment.isValidForDeity())
{
availableList.add(anAlignment.getKeyName());
}
}
cmbDeityAlignment.setModel(new DefaultComboBoxModel(availableList.toArray()));
}
/*
* This method is called from within the constructor to
* initialize the form.
*/
private void initComponents()
{
GridBagConstraints gridBagConstraints;
pnlHolyItem = new JPanel();
lblHolyItem = new JLabel();
txtHolyItem = new JTextField();
pnlDeityAlignment = new JPanel();
lblDeityAlignment = new JLabel();
cmbDeityAlignment = new JComboBoxEx();
pnlDescription = new DescriptionPanel();
pnlFavoredWeapons = new AvailableSelectedPanel();
setLayout(new GridBagLayout());
pnlHolyItem.setLayout(new GridBagLayout());
lblHolyItem.setLabelFor(txtHolyItem);
lblHolyItem.setText(PropertyFactory.getString("in_demHolyItem"));
lblHolyItem.setDisplayedMnemonic(PropertyFactory.getMnemonic("in_mn_demHolyItem"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new Insets(2, 5, 2, 5);
pnlHolyItem.add(lblHolyItem, gridBagConstraints);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new Insets(2, 5, 2, 5);
gridBagConstraints.weightx = 1.0;
pnlHolyItem.add(txtHolyItem, gridBagConstraints);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
add(pnlHolyItem, gridBagConstraints);
pnlDeityAlignment.setLayout(new GridBagLayout());
lblDeityAlignment.setLabelFor(cmbDeityAlignment);
lblDeityAlignment.setText(PropertyFactory.getString("in_demDeityAlign"));
lblDeityAlignment.setDisplayedMnemonic(PropertyFactory.getMnemonic("in_mn_demDeityAlign"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new Insets(2, 5, 2, 5);
pnlDeityAlignment.add(lblDeityAlignment, gridBagConstraints);
cmbDeityAlignment.setPreferredSize(new Dimension(180, 25));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new Insets(2, 5, 2, 5);
pnlDeityAlignment.add(cmbDeityAlignment, gridBagConstraints);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
add(pnlDeityAlignment, gridBagConstraints);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 3;
gridBagConstraints.gridheight = 2;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(pnlDescription, gridBagConstraints);
pnlFavoredWeapons.setHeader(PropertyFactory.getString("in_demFavWea"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 5;
gridBagConstraints.gridheight = 4;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(pnlFavoredWeapons, gridBagConstraints);
}
}
The table below shows all metrics for DeityBasePanel.java.




