IrcChatPreferencesPanel.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
*
* 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.Color;
import java.awt.FlowLayout;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
/**
*
*/
public class IrcChatPreferencesPanel extends JPanel {
private JToggleButton mIrcTextStyleBoldButton;
// private JToggleButton mIrcTextStyleItalicsButton;
// private JToggleButton mIrcTextStyleUnderlineButton;
private JButton mIrcTextStyleColorButton;
private JComboBox mIrcTextStyleFontTypeCombo;
private JComboBox mIrcTextStyleFontSizeCombo;
private JButton mRestoreDefaultsButton;
private BaseFrame mFrame;
private JTextPane mTextPane;
private boolean mIsParentMainChatFrame = false;
private Style mStyle;
private static boolean sIsFirstTime = true;
private static String sDefaultFontType = "Lucida Sans";
private static int sDefaultFontSize = 14;
private static Color sDefaultFontRGBColor = Color.white;
private static Color sDefaultTextPaneRGBColor = Color.black;
private static boolean sDefaultSetBold = false;
// private static boolean sDefaultSetItalic = false;
// private static boolean sDefaultSetUnderline = false;
IrcChatPreferencesPanel(BaseFrame parent, JTextPane textPane, Style style) {
setLayout(new FlowLayout(FlowLayout.LEFT));
mFrame = parent;
mTextPane = textPane;
if (mFrame.getClass().getName().endsWith("MainFrame"))
mIsParentMainChatFrame = true;
else
// it is a Private Message Frame
mIsParentMainChatFrame = false;
mStyle = style;
init();
}
private void init() {
// The first time this panel is instantiated,
// get user prefs or defaults from furthur.cfg
// all other times, read prefs from this panel
if (sIsFirstTime) {
sIsFirstTime = !sIsFirstTime;
sDefaultFontType = ServiceManager.getCfg().mChatFontType;
sDefaultFontSize = Integer.parseInt(ServiceManager.getCfg().mChatFontSize);
sDefaultFontRGBColor = new Color(ServiceManager.getCfg().mChatFontRGBColor);
sDefaultTextPaneRGBColor = new Color(ServiceManager.getCfg().mChatTextPaneRGBColor);
sDefaultSetBold = ServiceManager.getCfg().mChatSetBold;
// sDefaultSetItalic = ServiceManager.sCfg.mChatSetItalic;
// sDefaultSetUnderline = ServiceManager.sCfg.mChatSetUnderline;
}
// initialize
StyleConstants.setBold(mStyle, sDefaultSetBold);
// StyleConstants.setItalic(mStyle, sDefaultSetItalic);
// StyleConstants.setUnderline(mStyle, sDefaultSetUnderline);
StyleConstants.setFontFamily(mStyle, sDefaultFontType);
StyleConstants.setFontSize(mStyle, sDefaultFontSize);
// StyleConstants.setBackground(mStyle, sDefaultTextPaneRGBColor);
StyleConstants.setForeground(mStyle, sDefaultFontRGBColor);
mIrcTextStyleBoldButton = new JToggleButton("<html><b>B</b></html>");
mIrcTextStyleBoldButton.setToolTipText(Res.getStr("Main.ChatTab.ChatPreferences.Bold.ToolTip"));
mIrcTextStyleBoldButton.setSelected(sDefaultSetBold);
// mIrcTextStyleItalicsButton = new JToggleButton("<html><i>I</i></html>");
// mIrcTextStyleItalicsButton.setToolTipText(Res.getStr("Main.ChatTab.ChatPreferences.Italics.ToolTip"));
// mIrcTextStyleItalicsButton.setSelected(sDefaultSetItalic);
//
// mIrcTextStyleUnderlineButton = new JToggleButton("<html><u>U</u></html>");
// mIrcTextStyleUnderlineButton.setToolTipText(Res.getStr("Main.ChatTab.ChatPreferences.Underline.ToolTip"));
// mIrcTextStyleUnderlineButton.setSelected(sDefaultSetUnderline);
mIrcTextStyleColorButton = new JButton("<html><b>Colors</b></html>");
mIrcTextStyleColorButton.setToolTipText(Res.getStr("Main.ChatTab.ChatPreferences.Colors.ToolTip"));
// mIrcTextStyleColorButton.setForeground(sDefaultFontRGBColor);
// mIrcTextStyleColorButton.setBackground(sDefaultTextPaneRGBColor);
mTextPane.setBackground(sDefaultTextPaneRGBColor);
mIrcTextStyleFontTypeCombo = new JComboBox();
// mIrcTextStyleFontTypeCombo.setSize(new Dimension(16, 40));
mIrcTextStyleFontTypeCombo.setToolTipText(Res.getStr("Main.ChatTab.ChatPreferences.FontType.ToolTip"));
String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for (int i = 0; i < fontNames.length; i++) {
mIrcTextStyleFontTypeCombo.addItem(fontNames[i]);
}
mIrcTextStyleFontTypeCombo.setSelectedItem(sDefaultFontType);
mIrcTextStyleFontSizeCombo = new JComboBox();
mIrcTextStyleFontSizeCombo.setToolTipText(Res.getStr("Main.ChatTab.ChatPreferences.FontSize.ToolTip"));
for (int i = 6; i < 33; i++) {
mIrcTextStyleFontSizeCombo.addItem(Integer.toString(i));
}
mIrcTextStyleFontSizeCombo.setSelectedItem(String.valueOf(sDefaultFontSize));
mRestoreDefaultsButton = new JButton("<html>Defaults</html>");
mRestoreDefaultsButton.setToolTipText(Res.getStr("Main.ChatTab.ChatPreferences.RestoreDefaults.ToolTip"));
mIrcTextStyleBoldButton.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
StyleConstants.setBold(mStyle, true);
if (mIsParentMainChatFrame)
sDefaultSetBold = true;
} else { //deselected
StyleConstants.setBold(mStyle, false);
if (mIsParentMainChatFrame)
sDefaultSetBold = false;
}
if (mIsParentMainChatFrame) {
MainFrame frame = (MainFrame)mFrame;
frame.chatPane().refreshIrcChatPane();
} else {
PrivateChatFrame pFrame = (PrivateChatFrame)mFrame;
pFrame.refreshIrcChatPane();
}
}
});
// mIrcTextStyleItalicsButton.addItemListener(new ItemListener() {
// public void itemStateChanged(ItemEvent e) {
// if (e.getStateChange() == ItemEvent.SELECTED) {
// StyleConstants.setItalic(mStyle, true);
// if (mIsParentMainChatFrame)
// sDefaultSetItalic = true;
// } else { //deselected
// StyleConstants.setItalic(mStyle, false);
// if (mIsParentMainChatFrame)
// sDefaultSetItalic = false;
// }
// if (mIsParentMainChatFrame) {
// MainFrame frame = (MainFrame)mFrame;
// frame.refreshIrcChatPane();
// } else {
// PrivateChatFrame pFrame = (PrivateChatFrame)mFrame;
// pFrame.refreshIrcChatPane();
// }
// }
// });
// mIrcTextStyleUnderlineButton.addItemListener(new ItemListener() {
// public void itemStateChanged(ItemEvent e) {
// if (e.getStateChange() == ItemEvent.SELECTED) {
// StyleConstants.setUnderline(mStyle, true);
// if (mIsParentMainChatFrame)
// sDefaultSetUnderline = true;
// } else { //deselected
// StyleConstants.setUnderline(mStyle, false);
// if (mIsParentMainChatFrame)
// sDefaultSetUnderline = false;
// }
// if (mIsParentMainChatFrame) {
// MainFrame frame = (MainFrame)mFrame;
// frame.refreshIrcChatPane();
// } else {
// PrivateChatFrame pFrame = (PrivateChatFrame)mFrame;
// pFrame.refreshIrcChatPane();
// }
// }
// });
mIrcTextStyleColorButton.addActionListener(new ActionListener() {
IrcChatColorChooserDialog colorSelectionDialog;
Color selectedBackgroundColor;
Color selectedForegroundColor;
public void actionPerformed(ActionEvent e) {
Color initialBackgroundColor = mTextPane.getBackground();
if (initialBackgroundColor == null) {
initialBackgroundColor = sDefaultTextPaneRGBColor;
}
// colorChooser.setBackgroundColor(initialBackgroundColor);
Color initialForegroundColor = StyleConstants.getForeground(mStyle);
if (initialForegroundColor == null) {
initialForegroundColor = sDefaultFontRGBColor;
}
// colorChooser.setForegroundColor(initialForegroundColor);
ActionListener okListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectedBackgroundColor = colorSelectionDialog.getBackgroundColor();
selectedForegroundColor = colorSelectionDialog.getForegroundColor();
colorSelectionDialog.hide();
if (selectedBackgroundColor != null) {
// mIrcTextStyleColorButton.setBackground(selectedBackgroundColor);
if (mIsParentMainChatFrame)
sDefaultTextPaneRGBColor = selectedBackgroundColor;
// Repaint label
// mIrcTextStyleColorButton.repaint();
// TODO StyleConstants.setBackground(mStyle, selectedBackgroundColor);
mTextPane.setBackground(selectedBackgroundColor);
}
if (selectedForegroundColor != null) {
// mIrcTextStyleColorButton.setForeground(selectedForegroundColor);
if (mIsParentMainChatFrame)
sDefaultFontRGBColor = selectedForegroundColor;
// Repaint label
// mIrcTextStyleColorButton.repaint();
StyleConstants.setForeground(mStyle, selectedForegroundColor);
}
if (mIsParentMainChatFrame) {
MainFrame frame = (MainFrame)mFrame;
frame.chatPane().refreshIrcChatPane();
} else {
PrivateChatFrame pFrame = (PrivateChatFrame)mFrame;
pFrame.refreshIrcChatPane();
}
}
};
colorSelectionDialog = new IrcChatColorChooserDialog
((JFrame)mFrame, initialBackgroundColor, initialForegroundColor, okListener);
colorSelectionDialog.setLocationRelativeTo((JFrame)mFrame);
colorSelectionDialog.setSize(colorSelectionDialog.getPreferredSize());
// colorSelectionDialog.setResizable(false);
colorSelectionDialog.setVisible(true);
}
});
mIrcTextStyleFontTypeCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cbx = (JComboBox) e.getSource();
String fontType = (String) cbx.getSelectedItem();
StyleConstants.setFontFamily(mStyle, fontType);
if (mIsParentMainChatFrame)
sDefaultFontType = fontType;
if (mIsParentMainChatFrame) {
MainFrame frame = (MainFrame)mFrame;
frame.chatPane().refreshIrcChatPane();
} else {
PrivateChatFrame pFrame = (PrivateChatFrame)mFrame;
pFrame.refreshIrcChatPane();
}
}
});
mIrcTextStyleFontSizeCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cbx = (JComboBox) e.getSource();
String fontSize = (String) cbx.getSelectedItem();
StyleConstants.setFontSize(mStyle, Integer.parseInt(fontSize));
if (mIsParentMainChatFrame)
sDefaultFontSize = Integer.parseInt(fontSize);
if (mIsParentMainChatFrame) {
MainFrame frame = (MainFrame)mFrame;
frame.chatPane().refreshIrcChatPane();
} else {
PrivateChatFrame pFrame = (PrivateChatFrame)mFrame;
pFrame.refreshIrcChatPane();
}
}
});
mRestoreDefaultsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setDefaults();
if (mIsParentMainChatFrame) {
MainFrame frame = (MainFrame)mFrame;
frame.chatPane().refreshIrcChatPane();
} else {
PrivateChatFrame pFrame = (PrivateChatFrame)mFrame;
pFrame.refreshIrcChatPane();
}
}
});
this.add(mIrcTextStyleBoldButton);
// no need for italics and underline (for now...)
// this.add(mIrcTextStyleItalicsButton);
// this.add(mIrcTextStyleUnderlineButton);
this.add(mIrcTextStyleColorButton);
this.add(mIrcTextStyleFontTypeCombo);
this.add(mIrcTextStyleFontSizeCombo);
this.add(mRestoreDefaultsButton);
}
private void setDefaults() {
String tempFontType = "Lucida Sans";
int tempFontSize = 14;
Color tempFontRGBColor = Color.white;
Color tempTextPaneRGBColor = Color.black;
boolean tempSetBold = false;
// boolean tempSetItalic = false;
// boolean tempSetUnderline = false;
StyleConstants.setBold(mStyle, tempSetBold);
// StyleConstants.setItalic(mStyle, tempSetItalic);
// StyleConstants.setUnderline(mStyle, tempSetUnderline);
StyleConstants.setFontFamily(mStyle, tempFontType);
StyleConstants.setFontSize(mStyle, tempFontSize);
StyleConstants.setForeground(mStyle, tempFontRGBColor);
// TODO StyleConstants.setBackground(mStyle, tempTextPaneRGBColor);
mIrcTextStyleBoldButton.setSelected(tempSetBold);
// mIrcTextStyleItalicsButton.setSelected(tempSetItalic);
// mIrcTextStyleUnderlineButton.setSelected(tempSetUnderline);
// mIrcTextStyleColorButton.setForeground(tempFontRGBColor);
// mIrcTextStyleColorButton.setBackground(tempTextPaneRGBColor);
mTextPane.setBackground(tempTextPaneRGBColor);
mIrcTextStyleFontTypeCombo.setSelectedItem(tempFontType);
mIrcTextStyleFontSizeCombo.setSelectedItem(String.valueOf(tempFontSize));
// if Main Chat frame, update static variables
if (mIsParentMainChatFrame) {
sDefaultFontType = tempFontType;
sDefaultFontSize = tempFontSize;
sDefaultFontRGBColor = tempFontRGBColor;
sDefaultTextPaneRGBColor = tempTextPaneRGBColor;
sDefaultSetBold = tempSetBold;
// sDefaultSetItalic = tempSetItalic;
// sDefaultSetUnderline = tempSetUnderline;
}
}
/**
* Save the user preferences in the Cfg object. This method will be called
* by the shutdown thread before calling Cfg.save().
*/
public static void save() {
ServiceManager.getCfg().mChatFontType = sDefaultFontType;
ServiceManager.getCfg().mChatFontSize = String.valueOf(sDefaultFontSize);
ServiceManager.getCfg().mChatFontRGBColor = sDefaultFontRGBColor.getRGB();
ServiceManager.getCfg().mChatTextPaneRGBColor = sDefaultTextPaneRGBColor.getRGB();
ServiceManager.getCfg().mChatSetBold = sDefaultSetBold;
// ServiceManager.sCfg.mChatSetItalic = sDefaultSetItalic;
// ServiceManager.sCfg.mChatSetUnderline = sDefaultSetUnderline;
}
}
The table below shows all metrics for IrcChatPreferencesPanel.java.




