Coverage Report - org.jtheque.core.utils.ui.FilthyPanelBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
FilthyPanelBuilder
0 %
0/56
0 %
0/4
1.133
 
 1  
 package org.jtheque.core.utils.ui;
 2  
 
 3  
 import org.jdesktop.swingx.JXTree;
 4  
 import org.jtheque.core.managers.view.impl.components.JThequeI18nLabel;
 5  
 import org.jtheque.core.managers.view.impl.components.filthy.FilthyComboBox;
 6  
 import org.jtheque.core.managers.view.impl.components.filthy.FilthyList;
 7  
 import org.jtheque.core.managers.view.impl.components.filthy.FilthyPanel;
 8  
 
 9  
 import javax.swing.DefaultComboBoxModel;
 10  
 import javax.swing.JComboBox;
 11  
 import javax.swing.JComponent;
 12  
 import javax.swing.JLabel;
 13  
 import javax.swing.JList;
 14  
 import javax.swing.JPanel;
 15  
 import javax.swing.JScrollPane;
 16  
 import javax.swing.ListCellRenderer;
 17  
 import javax.swing.ListModel;
 18  
 import javax.swing.ListSelectionModel;
 19  
 import javax.swing.tree.TreeCellRenderer;
 20  
 import javax.swing.tree.TreeModel;
 21  
 import java.awt.Color;
 22  
 import java.awt.LayoutManager;
 23  
 
 24  
 /*
 25  
  * This file is part of JTheque.
 26  
  *            
 27  
  * JTheque is free software: you can redistribute it and/or modify
 28  
  * it under the terms of the GNU General Public License as published by
 29  
  * the Free Software Foundation, either version 3 of the License. 
 30  
  *
 31  
  * JTheque is distributed in the hope that it will be useful,
 32  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 33  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 34  
  * GNU General Public License for more details.
 35  
  *
 36  
  * You should have received a copy of the GNU General Public License
 37  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 38  
  */
 39  
 
 40  
 /**
 41  
  * A filthy panel builder. It has the same functionality of <code>PanelBuilder</code> but when a filthy component
 42  
  * exists, the builder use it instead of the normal component.
 43  
  *
 44  
  * @author Baptiste Wicht
 45  
  */
 46  
 public final class FilthyPanelBuilder extends PanelBuilder {
 47  
     /**
 48  
      * Construct a new FilthyPanelBuilder for a new panel.
 49  
      */
 50  
     public FilthyPanelBuilder() {
 51  0
         super();
 52  0
     }
 53  
 
 54  
     /**
 55  
      * Construct a new FilthyPanelBuilder for a specific panel.
 56  
      *
 57  
      * @param panel The panel to build.
 58  
      */
 59  
     public FilthyPanelBuilder(JPanel panel) {
 60  0
         super(panel);
 61  0
     }
 62  
 
 63  
     /**
 64  
      * Construct a new FilthyPanelBuilder with a specific layout.
 65  
      *
 66  
      * @param layout The layout to set to the builded panel.
 67  
      */
 68  
     public FilthyPanelBuilder(LayoutManager layout){
 69  0
         super(new FilthyPanel(layout), false);
 70  0
     }
 71  
 
 72  
         /**
 73  
          * Construct a new FilthyPanelBuilder with a specific panel.
 74  
          *
 75  
          * @param panel The panel to build.
 76  
          * @param layout Indicate if we must set a default layout on the panel or keep the existing one. 
 77  
          */
 78  
     public FilthyPanelBuilder(JPanel panel, boolean layout) {
 79  0
         super(panel, layout);
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public JLabel addLabel(String text, Object constraints) {
 84  0
         JLabel label = super.addLabel(text, constraints);
 85  
 
 86  0
         label.setForeground(Color.white);
 87  
 
 88  0
         return label;
 89  
     }
 90  
 
 91  
     @Override
 92  
     public JThequeI18nLabel addI18nLabel(String key, Object constraints) {
 93  0
         JThequeI18nLabel label = super.addI18nLabel(key, constraints);
 94  
 
 95  0
         label.setForeground(Color.white);
 96  
 
 97  0
         return label;
 98  
     }
 99  
 
 100  
     @Override
 101  
     public JThequeI18nLabel addI18nLabel(String key, int style, Object constraints) {
 102  0
         JThequeI18nLabel label = super.addI18nLabel(key, style, constraints);
 103  
 
 104  0
         label.setForeground(Color.white);
 105  
 
 106  0
         return label;
 107  
     }
 108  
 
 109  
     @Override
 110  
     void initJThequeDefaults() {
 111  0
         getPanel().setOpaque(false);
 112  0
         getPanel().setBorder(Borders.EMPTY_BORDER);
 113  0
     }
 114  
 
 115  
     @Override
 116  
     public JList addList(ListModel model, ListCellRenderer renderer, Object constraints) {
 117  0
         JList list = new FilthyList(model);
 118  
 
 119  0
         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 120  0
         list.setVisibleRowCount(10);
 121  0
         list.setValueIsAdjusting(true);
 122  
 
 123  0
         if (renderer != null) {
 124  0
             list.setCellRenderer(renderer);
 125  
         }
 126  
 
 127  0
         addScrolled(list, constraints);
 128  
 
 129  0
         return list;
 130  
     }
 131  
 
 132  
     @Override
 133  
     public void addScrolled(JComponent view, Object constraints) {
 134  0
         JScrollPane scrollPane = new JScrollPane(view);
 135  
 
 136  0
         scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
 137  0
         scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
 138  0
         scrollPane.setOpaque(false);
 139  0
         scrollPane.setBorder(Borders.EMPTY_BORDER);
 140  0
         scrollPane.getViewport().setOpaque(false);
 141  
 
 142  0
         add(scrollPane, constraints);
 143  0
     }
 144  
 
 145  
     @Override
 146  
     public JComboBox addComboBox(DefaultComboBoxModel model, Object constraints) {
 147  0
         return add(new FilthyComboBox(model), constraints);
 148  
     }
 149  
 
 150  
     @Override
 151  
     public JComboBox addComboBox(DefaultComboBoxModel model, ListCellRenderer renderer, Object constraints) {
 152  0
         JComboBox combo = add(new FilthyComboBox(model), constraints);
 153  
 
 154  0
         combo.setRenderer(renderer);
 155  
 
 156  0
         return combo;
 157  
     }
 158  
 
 159  
     @Override
 160  
     public PanelBuilder addPanel(Object constraints) {
 161  0
         PanelBuilder builder = new FilthyPanelBuilder();
 162  
 
 163  0
         add(builder.getPanel(), constraints);
 164  
 
 165  0
         return builder;
 166  
     }
 167  
 
 168  
     @Override
 169  
     public PanelBuilder addPanel(LayoutManager layout, Object constraints){
 170  0
         PanelBuilder builder = new FilthyPanelBuilder(layout);
 171  
 
 172  0
         add(builder.getPanel(), constraints);
 173  
 
 174  0
         return builder;
 175  
     }
 176  
 
 177  
     @Override
 178  
     public JXTree addScrolledTree(TreeModel model, TreeCellRenderer renderer, Object constraints){
 179  0
         JXTree tree = new JXTree(model);
 180  0
         tree.setRootVisible(false);
 181  0
         tree.setShowsRootHandles(true);
 182  0
         tree.setOpaque(false);
 183  0
         tree.setBorder(Borders.EMPTY_BORDER);
 184  0
         tree.putClientProperty("JTree.lineStyle", "None");
 185  
 
 186  0
         if(renderer != null){
 187  0
             tree.setCellRenderer(renderer);
 188  
         }
 189  
 
 190  0
         addScrolled(tree, constraints);
 191  
 
 192  0
         return tree;
 193  
     }
 194  
 }