001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.gui.preferences; 020 021import icy.gui.util.ComponentUtil; 022 023import java.awt.BorderLayout; 024 025import javax.swing.BorderFactory; 026import javax.swing.Box; 027import javax.swing.BoxLayout; 028import javax.swing.JLabel; 029import javax.swing.JPanel; 030import javax.swing.JSeparator; 031import javax.swing.SwingConstants; 032import javax.swing.tree.DefaultMutableTreeNode; 033 034/** 035 * @author Fabrice de Chaumont 036 */ 037public abstract class PreferencePanel extends JPanel 038{ 039 private static final long serialVersionUID = 4602116758638991276L; 040 041 protected final PreferenceFrame parentFrame; 042 043 protected final String parentName; 044 protected final DefaultMutableTreeNode node; 045 046 protected final JPanel mainPanel; 047 048 public PreferencePanel(PreferenceFrame parentFrame, String name, String parentName) 049 { 050 super(); 051 052 setName(name); 053 054 this.parentFrame = parentFrame; 055 this.parentName = parentName; 056 057 node = new DefaultMutableTreeNode(name); 058 059 final JPanel topPanel = new JPanel(); 060 topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.PAGE_AXIS)); 061 062 final JLabel titleLabel = new JLabel(" " + name); 063 064 ComponentUtil.increaseFontSize(titleLabel, 2); 065 ComponentUtil.setFontBold(titleLabel); 066 067 topPanel.add(Box.createVerticalStrut(6)); 068 topPanel.add(titleLabel); 069 topPanel.add(Box.createVerticalStrut(6)); 070 topPanel.add(new JSeparator(SwingConstants.HORIZONTAL)); 071 072 mainPanel = new JPanel(); 073 mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); 074 075 setLayout(new BorderLayout()); 076 077 add(topPanel, BorderLayout.NORTH); 078 add(mainPanel, BorderLayout.CENTER); 079 } 080 081 /** 082 * called when panel is closed 083 */ 084 protected void closed() 085 { 086 087 } 088 089 public PreferenceFrame getPreferenceFrame() 090 { 091 return parentFrame; 092 } 093 094 public PreferencePanel getPreferencePanel(Class<? extends PreferencePanel> type) 095 { 096 for (PreferencePanel panel : parentFrame.preferencePanels) 097 if (type.isInstance(panel)) 098 return panel; 099 100 return null; 101 } 102 103 public DefaultMutableTreeNode getNode() 104 { 105 return node; 106 } 107 108 public String getParentName() 109 { 110 return parentName; 111 } 112 113 protected abstract void load(); 114 115 protected abstract void save(); 116 117}