You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ps...@apache.org on 2003/05/19 08:21:45 UTC
cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw LogUI.java ChainsawToolBarAndMenus.java
psmith 2003/05/18 23:21:45
Modified: src/java/org/apache/log4j/chainsaw LogUI.java
ChainsawToolBarAndMenus.java
Log:
added Look and feel defaults, user selection, and saving via preferences.
Defaults to the standard system look and feel of the local computer.
Revision Changes Path
1.56 +35 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java
Index: LogUI.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- LogUI.java 19 May 2003 04:22:23 -0000 1.55
+++ LogUI.java 19 May 2003 06:21:44 -0000 1.56
@@ -125,6 +125,8 @@
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
@@ -151,6 +153,7 @@
private static final String MAIN_WINDOW_X = "main.window.x";
private static final String TABLE_COLUMN_ORDER = "table.columns.order";
private static final String TABLE_COLUMN_WIDTHS = "table.columns.widths";
+ private static final String LOOK_AND_FEEL = "LookAndFeel";
ChainsawTabbledPane tabbedPane;
JToolBar toolbar;
private final Map tableModelMap = new HashMap();
@@ -195,7 +198,10 @@
* @param args
*/
public static void main(String[] args) {
+
LogUI logUI = new LogUI();
+ logUI.changeLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+
logUI.handler = new ChainsawAppenderHandler(logUI);
LogManager.getRootLogger().addAppender(logUI.handler);
logUI.activateViewer();
@@ -227,6 +233,12 @@
setSize(
event.asInt(LogUI.MAIN_WINDOW_WIDTH),
event.asInt(LogUI.MAIN_WINDOW_HEIGHT));
+
+ String lookAndFeel = event.getSetting(LogUI.LOOK_AND_FEEL);
+
+ if (lookAndFeel != null) {
+ changeLookAndFeel(lookAndFeel);
+ }
}
/**
@@ -238,6 +250,9 @@
event.saveSetting(LogUI.MAIN_WINDOW_WIDTH, getWidth());
event.saveSetting(LogUI.MAIN_WINDOW_HEIGHT, getHeight());
+
+ event.saveSetting(
+ LogUI.LOOK_AND_FEEL, UIManager.getLookAndFeel().getClass().getName());
}
/**
@@ -727,6 +742,24 @@
}
/**
+ * Changes the Look And Feel of the App
+ * @param string The FQN of the LookANdFeel
+ */
+ protected void changeLookAndFeel(String lookAndFeelClassName) {
+ LogLog.debug("Setting L&F -> " + lookAndFeelClassName);
+
+ try {
+ UIManager.setLookAndFeel(lookAndFeelClassName);
+ SwingUtilities.updateComponentTreeUI(this);
+ if (tbms!=null) {
+ tbms.stateChange();
+ }
+ } catch (Exception e) {
+ LogLog.error("Failed to change L&F", e);
+ }
+ }
+
+ /**
* Ensures that a specific popupMenu is displayed when the relevant
* mouse events are trapped.
*/
@@ -766,7 +799,7 @@
final JSplitPane lowerPanel;
final DetailThread detailThread;
final JPanel upperPanel;
- final JPanel eventsAndStatusPanel;
+ final JPanel eventsAndStatusPanel;
final JFrame f;
final DockablePanel externalPanel;
final Action dockingAction;
@@ -918,6 +951,7 @@
upperPanel.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 0));
final JLabel filterLabel = new JLabel("Filter: ");
+ filterLabel.setFont(new Font("SansSerif", Font.ITALIC, 10));
JPanel upperLeftPanel =
new JPanel(new FlowLayout(FlowLayout.CENTER, 3, 0));
1.20 +51 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
Index: ChainsawToolBarAndMenus.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ChainsawToolBarAndMenus.java 16 May 2003 07:46:18 -0000 1.19
+++ ChainsawToolBarAndMenus.java 19 May 2003 06:21:44 -0000 1.20
@@ -70,6 +70,10 @@
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
@@ -94,6 +98,8 @@
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
@@ -111,6 +117,8 @@
private LogUI logui;
private final JToolBar toolbar;
private final JMenuBar menuBar;
+ private final JMenu viewMenu = new JMenu("View");
+ private final Collection lookAndFeelMenus = new ArrayList();
private final Action lockToolbarAction;
private final Action toggleToolbarAction;
private final Action pauseAction;
@@ -213,6 +221,20 @@
detailPaneButton.getModel().setSelected(logPanel.isDetailPaneVisible());
}
+
+ String currentLookAndFeel =
+ UIManager.getLookAndFeel().getClass().getName();
+ String currentLookAndFeelName = UIManager.getLookAndFeel().getName();
+
+ for (Iterator iter = lookAndFeelMenus.iterator(); iter.hasNext();) {
+ JRadioButtonMenuItem element = (JRadioButtonMenuItem) iter.next();
+
+ if (element.getText().equals(currentLookAndFeelName)) {
+ element.setSelected(true);
+ } else {
+ element.setSelected(false);
+ }
+ }
}
private void find() {
@@ -571,7 +593,6 @@
}
private void createMenuBar() {
- JMenu viewMenu = new JMenu("View");
JMenu activeTabMenu = new JMenu("Current tab");
JMenuItem menuItemUseRightMouse =
@@ -629,10 +650,39 @@
new JMenu(ChainsawToolBarAndMenus.SETTING_RESPONSIVENESS);
responsiveNess.add(createResponsivenessSlider());
+ final JMenu lookAndFeelMenu = new JMenu("Look & Feel");
+
+ UIManager.LookAndFeelInfo[] lookAndFeels =
+ UIManager.getInstalledLookAndFeels();
+
+ final ButtonGroup lookAndFeelGroup = new ButtonGroup();
+
+ for (int i = 0; i < lookAndFeels.length; i++) {
+ final UIManager.LookAndFeelInfo lfInfo = lookAndFeels[i];
+ final JRadioButtonMenuItem lfItemMenu =
+ new JRadioButtonMenuItem(lfInfo.getName());
+ lfItemMenu.addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ SwingUtilities.invokeLater(
+ new Runnable() {
+ public void run() {
+ logui.changeLookAndFeel(lfInfo.getClassName());
+ }
+ });
+ }
+ });
+ lookAndFeelGroup.add(lfItemMenu);
+ lookAndFeelMenu.add(lfItemMenu);
+ lookAndFeelMenus.add(lfItemMenu);
+ }
+
tabMenu.add(tabsTop);
tabMenu.add(tabsBottom);
viewMenu.add(tabMenu);
viewMenu.add(responsiveNess);
+ viewMenu.addSeparator();
+ viewMenu.add(lookAndFeelMenu);
menuBar.add(fileMenu);
menuBar.add(viewMenu);
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org