public inbox for rhdb@sourceware.org
 help / color / mirror / Atom feed
From: Deepak B <ibetthisidisavailable@yahoo.ca>
To: rhdb@sources.redhat.com
Subject: Re: Final set of changes to Administrator 2.0 (Java) for PostgreSQL 7.4 series.
Date: Wed, 09 Jun 2004 05:58:00 -0000	[thread overview]
Message-ID: <20040609055801.86333.qmail@web61104.mail.yahoo.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 503 bytes --]

 --- Deepak B <ibetthisidisavailable@yahoo.ca> wrote:
> A bit late, but better than never :)
> 
> This patch brings Administrator up to speed with
> 7.4.x. All privileges items have been fixed to allow

<snip>

Sorry, the PrivilegesCheckBoxPanel.java file was badly
intended.. didn't notice it till I saw the mail.
Attaching a correctly indented version with this
e-mail.

Deepak B

______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: PrivilegesCheckBoxPanel.java --]
[-- Type: text/x-java; name="PrivilegesCheckBoxPanel.java", Size: 15572 bytes --]

/*
 * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
 *
 * This software may be freely redistributed under the terms of the
 * GNU General Public License.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Component of: Administrator GUI tool for PostgreSQL - Red Hat Edition
 */

package com.redhat.rhdb.admin;

/**
 * A Check Box panel specifically for privileges.
 * <p>
 * Based on com.redhat.rhdb.admin.CheckBoxPanel by <a href="mailto:bbooth@redhat.com">Brian Booth</a>
 *
 * @author  <a href="mailto:ibetthisidisavailable@yahoo.ca">Deepak Bhole</a>
 *
 */

public class PrivilegesCheckBoxPanel extends javax.swing.JPanel implements java.awt.event.ActionListener {
	
	/** Creates a new instance of PrivilegesCheckBoxPanel */
	/**
	 * Creates a CheckBoxPanel with a title
	 *
	 * @param names An array of names associated with the CheckBoxes
	 * @param layout the layout of the panel. Must be either CheckBoxPanel.HORIZONTAL or CheckBoxPanel.VERTICAL
	 * @param title the title of the panel
	 *
	 */
	public PrivilegesCheckBoxPanel(String[] names, String title, String secondaryCheckBoxTitle) {
		
		jchButtons = new javax.swing.JCheckBox[names.length];
		jchSecondaryButtons = new javax.swing.JCheckBox[names.length];
		hasChanged = new boolean[names.length];
		hasSecondaryChanged = new boolean[names.length];
		
		hasSecondaryCBEnabled = true;
		hasSecondaryCB = !secondaryCheckBoxTitle.equals("");
		java.awt.GridLayout gl;
		
		setLayout(new java.awt.GridBagLayout());
		java.awt.GridBagConstraints gridBagConstraints;
		
		for (int i = 0; i < names.length; i++) {
			gridBagConstraints = new java.awt.GridBagConstraints();
			gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
			gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = i;
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.weighty = 1.0;
			jchButtons[i] = new javax.swing.JCheckBox(names[i]);
			jchButtons[i].setEnabled(false);
			add(jchButtons[i], gridBagConstraints);
			hasChanged[i] = false;
			jchButtons[i].addActionListener(this);
			
			if (hasSecondaryCB) {
				jchSecondaryButtons[i] = new javax.swing.JCheckBox(secondaryCheckBoxTitle);
				gridBagConstraints = new java.awt.GridBagConstraints();
				gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
				gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
				gridBagConstraints.gridx = 1;
				gridBagConstraints.gridy = i;
				gridBagConstraints.weightx = 1.0;
				gridBagConstraints.weighty = 1.0;
				hasSecondaryChanged[i] = false;
				jchSecondaryButtons[i].setEnabled(false);
				add(jchSecondaryButtons[i], gridBagConstraints);
				jchSecondaryButtons[i].addActionListener(this);
			}
		}
		
		setBorder(new javax.swing.border.TitledBorder(title));
	}
	
	/**.
	 * For IDE Use.
	 */
	public PrivilegesCheckBoxPanel() {
		super();
	}
	
	/**
	 * Enables or disables the CheckBoxes
	 *
	 * @param enabled true if the CheckBoxes are enabled, false otherwise.
	 *
	 */
	public void setEnabled(boolean enabled) {
		
		for (int i = 0; i < jchButtons.length; i++) {
			jchButtons[i].setEnabled(enabled);
			
			if (hasSecondaryCB && jchButtons[i].isSelected())
				jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && enabled);
		}
		
		super.setEnabled(enabled);
	}
	
	/**
	 * Deselects all checkboxes and clears history
	 *
	 */
	public void reset() {
		
		for (int i = 0; i < jchButtons.length; i++) {
			jchButtons[i].setSelected(false);
			
			if (hasSecondaryCB) {
				jchSecondaryButtons[i].setSelected(false);
				jchSecondaryButtons[i].setEnabled(false);
			}
			
			hasChanged[i] = false;
			hasSecondaryChanged[i] = false;
		}
		
	}
	
	/**
	 * Gets the text of the selected CheckBoxes
	 *
	 * @return the text associated with the selected CheckBoxes
	 *
	 */
	public String[] getSelectedBoxes() {
		
		int size = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (jchButtons[i].isSelected())
				size++;
		
		String[] names = new String[size];
		
		int index = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (jchButtons[i].isSelected()) {
				names[index] = jchButtons[i].getText();
				index++;
			}
		
		return names;
		
	}
	
	/**
	 * Gets the text of the selected CheckBoxes
	 *
	 * @return the text associated with the selected CheckBoxes
	 *
	 */
	public String[] getPrimaryOnlySelectedBoxes() {
		
		int size = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (jchButtons[i].isSelected() && !(hasSecondaryCB && jchSecondaryButtons[i].isSelected()))
				size++;
		
		String[] names = new String[size];
		
		int index = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (jchButtons[i].isSelected() && !(hasSecondaryCB && jchSecondaryButtons[i].isSelected())) {
				names[index] = jchButtons[i].getText();
				index++;
			}
		
		return names;
		
	}
	
	/**
	 * Gets the text of the selected secondary CheckBoxes
	 *
	 * @return the text associated with the selected secondary CheckBoxes
	 *
	 */
	public String[] getSelectedSecondaryBoxes() {
		
		int size = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected())
				size++;
		
		String[] names = new String[size];
		
		int index = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected()) {
				names[index] = jchButtons[i].getText();
				index++;
			}
		
		return names;
	}
	
	/**
	 * Gets the indexes of the selected CheckBoxes
	 *
	 * @return the indexes associated with the selected CheckBoxes
	 *
	 */
	public int[] getSelectedIndexes() {
		
		int size = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (jchButtons[i].isSelected())
				size++;
		
		int[] indexes = new int[size];
		
		int index = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (jchButtons[i].isSelected()) {
				indexes[index] = i;
				index++;
			}
		
		return indexes;
	}
	
	/**
	 * Gets the indexes of the selected and enabled secondary CheckBoxes
	 *
	 * @return the indexes associated with the selected and enabled secondary CheckBoxes
	 */
	
	public int[] getSelectedSecondaryIndexes() {
		
		int size = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected())
				size++;
		
		int[] indexes = new int[size];
		
		int index = 0;
		
		for (int i = 0; i < jchButtons.length; i++)
			if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected()) {
				indexes[index] = i;
				index++;
			}
		
		return indexes;
	}
	
	/**
	 * Checks if the chechbox is selected at the given index
	 *
	 * @return  Returns true if the checkbox at 'index' is selected and
	 * 		false otherwise
	 *
	 */
	public boolean isSelected(int index) {
		return jchButtons[index].isSelected();
	}
	
	/**
	 * Checks if the secondary chechbox is selected at the given index
	 *
	 * @return  Returns true if the checkbox at 'index' is selected and
	 * 		false otherwise
	 *
	 */
	public boolean isSecondarySelected(int index) {
		if (hasSecondaryCB)
			return jchSecondaryButtons[index].isSelected();
		else
			return false;
	}
	
	/**
	 * Sets the Selection mode of the CheckBox at the given index
	 *
	 * @param index the index of the RadioButton you want to select
	 * @param isSelect true if the CheckBox is selected, false otherwise
	 *
	 */
	public void setSelectedBox(int index, boolean isSelect) {
		jchButtons[index].setSelected(isSelect);
		
		if (isSelect)
			jchSecondaryButtons[index].setEnabled(true);
	}
	
	/**
	 * Sets the Selection mode of the secondary CheckBox at the given index
	 *
	 * @param index the index of the RadioButton you want to select
	 * @param isSelect true if the CheckBox is selected, false otherwise
	 *
	 */
	public void setSelectedSecondaryBox(int index, boolean isSelect) {
		if (hasSecondaryCB)
			jchButtons[index].setSelected(isSelect);
	}
	
	/**
	 * Sets the Selection mode of the CheckBoxes at the given indexes
	 *
	 * @param indexes the indexes of the CheckBoxes you want to select
	 * @param isSelect true if the CheckBoxes are selected, false otherwise
	 *
	 */
	public void setSelectedBoxes(int[] indexes, boolean isSelect) {
		for (int i = 0; i < indexes.length; i++) {
			jchButtons[indexes[i]].setSelected(isSelect);
			
			if (hasSecondaryCB && isSelect)
				jchSecondaryButtons[indexes[i]].setEnabled(hasSecondaryCBEnabled && true);
		}
	}
	
	/**
	 * Sets the Selection mode of the Secondary CheckBoxes at the given indexes.
	 * Secondary CB's can be selected iff the primary is selected.
	 *
	 *
	 * @param indexes the indexes of the CheckBoxes you want to select
	 * @param isSelect true if the CheckBoxes are selected, false otherwise
	 *
	 */
	public void setSelectedSecondaryBoxes(int[] indexes, boolean isSelect) {
		if (!hasSecondaryCB)
			return;
		
		for (int i = 0; i < indexes.length; i++) {
			if (jchButtons[indexes[i]].isSelected())
				jchSecondaryButtons[indexes[i]].setSelected(isSelect);
		}
	}
	
	/**
	 * Sets the Selection mode of the first CheckBox with the given text
	 *
	 * @param str the text associated with the CheckBox you want to select
	 * @param isSelect true if the CheckBox is selected, false otherwise
	 *
	 */
	public void setSelectedBox(String str, boolean isSelect) {
		for (int i = 0; i < jchButtons.length; i++)
			if (str.equals(jchButtons[i].getText())) {
				jchButtons[i].setSelected(isSelect);
				
				if (hasSecondaryCB && isSelect)
					jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && true);
				
			}
	}
	
	/**
	 * Sets the Selection mode of the first secondary CheckBox with the given text (for the primary)
	 *
	 * @param str the text associated with the CheckBox whose secondary you want to select
	 * @param isSelect true if the CheckBox is selected, false otherwise
	 *
	 */
	
	public void setSelectedSecondaryBox(String str, boolean isSelect) {
		for (int i = 0; i < jchButtons.length; i++)
			if (hasSecondaryCB && str.equals(jchButtons[i].getText()) && jchButtons[i].isSelected())
				jchSecondaryButtons[i].setSelected(isSelect);
	}
	
	/**
	 * Sets the Selection mode of the CheckBoxes that have the given text
	 *
	 * @param str the text associated with the CheckBoxes you want to select
	 * @param isSelect true if the CheckBoxes are selected, false otherwise
	 *
	 */
	public void setSelectedBoxes(String[] str, boolean isSelect) {
		for (int i = 0; i < jchButtons.length; i++)
			for (int j = 0; j < str.length; j++)
				if (str[j].equals(jchButtons[i].getText())) {
					jchSecondaryButtons[i].setSelected(isSelect);
					
					if (hasSecondaryCB && isSelect)
						jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && true);
				}
	}
	
	/**
	 * Sets the Selection mode of the secondary CheckBoxes whose primary have the given text
	 *
	 * @param str the text associated with the CheckBoxes whose secondary you want to select
	 * @param isSelect true if the CheckBoxes are selected, false otherwise
	 *
	 */
	public void setSelectedSecondaryBoxes(String[] str, boolean isSelect) {
		for (int i = 0; i < jchButtons.length; i++)
			for (int j = 0; j < str.length; j++)
				if (hasSecondaryCB && str[j].equals(jchButtons[i].getText()) && jchButtons[i].isSelected())
					jchSecondaryButtons[i].setSelected(isSelect);
	}
	
	/**
	 * Gets the indexes of the CheckBoxes whose values have changed (Primary or Secondary).
	 *
	 * @return the indexes associated with the CheckBoxes whose values have changed.
	 *
	 */
	public int[] getChangedIndexes() {
		int size = 0;
		
		for (int i = 0; i < hasChanged.length; i++) {
			if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i]))
				size++;
		}
		
		int[] toReturn = new int[size];
		int index = 0;
		
		for (int i = 0; i < hasChanged.length; i++)
			if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i])) {
				toReturn[index] = i;
				index++;
			}
		
		return toReturn;
	}
	
	/**
	 * Gets the indexes of the primary CheckBoxes whose values have changed.
	 *
	 * @return the indexes associated with the CheckBoxes whose values have changed.
	 *
	 */
	public int[] getChangedPrimaryIndexes() {
		int size = 0;
		
		for (int i = 0; i < hasChanged.length; i++)
			if (hasChanged[i])
				size++;
		
		int[] toReturn = new int[size];
		int index = 0;
		
		for (int i = 0; i < hasChanged.length; i++)
			if (hasChanged[i]) {
				toReturn[index] = i;
				index++;
			}
		
		return toReturn;
	}
	
	/**
	 * Gets the indexes of the secondary CheckBoxes whose values have changed.
	 *
	 * @return the indexes associated with the CheckBoxes whose values have changed.
	 *
	 */
	public int[] getChangedSecondaryIndexes() {
		
		if (!hasSecondaryCB) {
			return new int[0];
		}
		
		int size = 0;
		
		for (int i = 0; i < hasChanged.length; i++)
			if (hasChanged[i])
				size++;
		
		int[] toReturn = new int[size];
		int index = 0;
		
		for (int i = 0; i < hasChanged.length; i++)
			if (hasChanged[i]) {
				toReturn[index] = i;
				index++;
			}
		
		return toReturn;
	}
	
	/**
	 * Gets the text of the CheckBoxes whose values have changed.
	 *
	 * @return the text associated with the CheckBoxes whose values have changed.
	 *
	 */
	public String[] getChangedStrings() {
		int size = 0;
		
		for (int i = 0; i < hasChanged.length; i++)
			if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i]))
				size++;
		
		String[] toReturn = new String[size];
		int index = 0;
		
		for (int i = 0; i < hasChanged.length; i++)
			if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i])) {
				toReturn[index] = jchButtons[i].getText();
				index++;
			}
		
		return toReturn;
	}
	
	/**
	 * Set all secondary checkboxes to given state (selected items are unselected).
	 *
	 * @param enabled The state to set the boxes to.
	 */
	
	public void setSecondaryCBEnabled(boolean enabled) {
		if (!hasSecondaryCB)
			return;
		
		hasSecondaryCBEnabled = enabled;
		for (int i=0; i < jchSecondaryButtons.length; i++) {
			jchSecondaryButtons[i].setSelected(false);
			jchSecondaryButtons[i].setEnabled(enabled);
		}
	}
	
	/**
	 * Run whenever a CheckBoxes value changes. Fires a PropertyChangedEvent
	 *
	 * @param evt the selection or de-selection of a CheckBox
	 *
	 */
	public void actionPerformed(java.awt.event.ActionEvent evt) {
		for (int i = 0; i < jchButtons.length; i++) {
			if (evt.getSource() == jchButtons[i])
				hasChanged[i] = !hasChanged[i];
			
			if (hasSecondaryCB && evt.getSource() == jchSecondaryButtons[i]) {
				hasSecondaryChanged[i] = !hasSecondaryChanged[i];
			}
			
			if (evt.getSource() == jchButtons[i]) {
				if (jchButtons[i].isSelected()) {
					if (hasSecondaryCB)
						jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && true);
				} else {
					if (hasSecondaryCB)
						jchSecondaryButtons[i].setEnabled(false);
				}
			}
		}
		
		firePropertyChange(SELECTION_MADE, !hasChanged[0], hasChanged[0]);
	}
	
	protected javax.swing.JCheckBox[] jchButtons = new javax.swing.JCheckBox[0];
	protected javax.swing.JCheckBox[] jchSecondaryButtons = new javax.swing.JCheckBox[0];
	protected boolean[] hasChanged = new boolean[0];
	protected boolean[] hasSecondaryChanged = new boolean[0];
	
	private boolean hasSecondaryCB = false;
	private boolean hasSecondaryCBEnabled = true;
	
	/** Name of the PropertyChangeEvent */
	public static final String SELECTION_MADE = "Check Box Selected";
}

             reply	other threads:[~2004-06-09  5:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-09  5:58 Deepak B [this message]
2004-06-09 13:14 ` Fernando Nasser
  -- strict thread matches above, loose matches on Subject: below --
2004-06-09 19:06 Deepak B
2004-06-09  5:49 Deepak B

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040609055801.86333.qmail@web61104.mail.yahoo.com \
    --to=ibetthisidisavailable@yahoo.ca \
    --cc=rhdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).