IrcChatColorChooserDialog.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.furthurnet.furi |
![]() |
![]() |
Furthurnet |
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.
/**
* FURI - A distributed peer-to-peer file sharing system.
* Copyright (C) 2000-2005 Furthur Network
* All rights reserved.
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.furthurnet.furi;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* @author Vinay Doma
*
*/
public class IrcChatColorChooserDialog extends JDialog implements ActionListener, ChangeListener {
private JColorChooser colorChooser;
private PreviewPanel previewPanel;
private JButton okButton;
private JButton cancelButton;
private JButton resetButton;
private JPanel buttonPanel;
private Color selectedBackgroundColor;
private Color selectedForegroundColor;
private static Color initialBackgroundColor;
private static Color initialForegroundColor;
IrcChatColorChooserDialog(JFrame parent, Color background, Color foreground, ActionListener okListener){
super(JOptionPane.getFrameForComponent(parent), "Select Text and Background Colors", true);
initialBackgroundColor = background;
initialForegroundColor = foreground;
previewPanel = new PreviewPanel(initialBackgroundColor, initialForegroundColor);
previewPanel.setPreferredSize(new Dimension(140, 80));
previewPanel.setSize(previewPanel.getPreferredSize());
colorChooser = new JColorChooser();
colorChooser.getSelectionModel().addChangeListener(this);
colorChooser.setPreviewPanel(new JPanel());
buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
okButton = new JButton("OK");
okButton.addActionListener(okListener);
cancelButton = new JButton("Cancel");
cancelButton.addActionListener(this);
resetButton = new JButton("Reset");
resetButton.addActionListener(this);
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
// buttonPanel.add(resetButton); //TODO: add reset functionality later...
getRootPane().setDefaultButton(okButton);
// add panels
getContentPane().add(previewPanel, BorderLayout.NORTH);
getContentPane().add(colorChooser, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == cancelButton) {
hide();
}
if (e.getSource() == resetButton) {
reset();
}
}
public void show() {
initialForegroundColor = colorChooser.getColor();
super.show();
}
public void reset() {
previewPanel.setBackgroundColor(initialBackgroundColor);
previewPanel.setForegroundColor(initialForegroundColor);
// colorChooser.setColor(initialForegroundColor);
}
public void stateChanged(ChangeEvent evt) {
Color c = colorChooser.getColor();
if (c != null) {
if (previewPanel.isBackgroundColorButtonSelected())
previewPanel.setBackgroundColor(c);
else
previewPanel.setForegroundColor(c);
}
}
public void setBackgroundColor(Color c) {
selectedBackgroundColor = c;
}
public Color getBackgroundColor() {
return previewPanel.getBackgroundColor();
}
public void setForegroundColor(Color c) {
selectedForegroundColor = c;
}
public Color getForegroundColor() {
return previewPanel.getForegroundColor();
}
}
class PreviewPanel extends JPanel{
protected JLabel mBannerLabel;
protected JToggleButton mBackgroundColorButton;
protected JToggleButton mForegroundColorButton;
protected boolean mIsSelected = false;
public PreviewPanel(Color background,Color foreground) {
JPanel componentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
ButtonGroup buttonGroup = new ButtonGroup();
mForegroundColorButton = new JToggleButton("<html><b>Text Color</b></html>");
mForegroundColorButton.setSelected(true);
buttonGroup.add(mForegroundColorButton);
componentPanel.add(mForegroundColorButton);
mBackgroundColorButton = new JToggleButton("<html><b>Background Color</b></html>");
buttonGroup.add(mBackgroundColorButton);
componentPanel.add(mBackgroundColorButton);
add(componentPanel, BorderLayout.NORTH);
JPanel bannerPanel = new JPanel(new BorderLayout());
mBannerLabel = new JLabel("FurthurNet Colors", JLabel.CENTER);
mBannerLabel.setBackground(background);
mBannerLabel.setForeground(foreground);
mBannerLabel.setFont(new Font("Lucida Sans", Font.BOLD, 24));
mBannerLabel.setOpaque(true);
mBannerLabel.setSize(mBannerLabel.getPreferredSize());
bannerPanel.add(mBannerLabel, BorderLayout.CENTER);
bannerPanel.setPreferredSize(new Dimension(400, 40));
add(bannerPanel, BorderLayout.SOUTH);
}
public boolean isBackgroundColorButtonSelected() {
return mBackgroundColorButton.isSelected();
}
public boolean isForegroundColorButtonSelected() {
return mForegroundColorButton.isSelected();
}
public void setBackgroundColor(Color c) {
mBannerLabel.setBackground(c);
}
public Color getBackgroundColor() {
return mBannerLabel.getBackground();
}
public void setForegroundColor(Color c) {
mBannerLabel.setForeground(c);
}
public Color getForegroundColor() {
return mBannerLabel.getForeground();
}
}
The table below shows all metrics for IrcChatColorChooserDialog.java.




