/* * The MIT License * * Copyright 2010 Georgios Migdos <cyberpython@gmail.com>. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package minijed; import java.awt.Color; import java.awt.Component; import java.awt.Font; import javax.swing.JList; import javax.swing.ListCellRenderer; import javax.swing.UIManager; /** * * @author cyberpython */ public class CompilerMessagesListCellRenderer extends javax.swing.JPanel implements ListCellRenderer{ private Font normalFont; private Font boldFont; private Color bgColor; private Color fgColor; private Color bgColorSelected; private Color fgColorSelected; private Color errorColor; /** Creates new form CompilerMessagesListCellRenderer */ public CompilerMessagesListCellRenderer() { initComponents(); this.normalFont = jLabel1.getFont(); this.boldFont = this.normalFont.deriveFont(Font.BOLD); this.bgColor = UIManager.getColor("text"); this.fgColor = UIManager.getColor("textText"); this.bgColorSelected = UIManager.getColor("textHighlight"); this.fgColorSelected = UIManager.getColor("textHighlightText"); this.errorColor = Color.red; } public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { //setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); setBackground(isSelected ? bgColorSelected : bgColor); setForeground(isSelected ? fgColorSelected : fgColor); if(value instanceof CompilerErrorMessage){ jLabel1.setForeground(errorColor); jLabel1.setFont(this.boldFont); } else if(value instanceof CompilerSuccessMessage){ jLabel1.setForeground(isSelected ? fgColorSelected : fgColor); jLabel1.setFont(this.boldFont); } else{ jLabel1.setForeground(isSelected ? fgColorSelected : fgColor); jLabel1.setFont(this.normalFont); } jLabel1.setText(value.toString()); return this; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); setName("Form"); // NOI18N org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(minijed.MiniJedApp.class).getContext().getResourceMap(CompilerMessagesListCellRenderer.class); jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }