darcula table header

This commit is contained in:
Konstantin Bulenkov
2012-10-26 00:48:21 +02:00
parent 180a5f1d94
commit d72ff4e29a
4 changed files with 254 additions and 0 deletions
@@ -0,0 +1,149 @@
package com.intellij.ide.ui.laf.darcula;
import javax.swing.*;
import javax.swing.plaf.UIResource;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
/**
* @author Konstantin Bulenkov
*/
public class DarculaDefaultTableHeaderRenderer extends DefaultTableCellRenderer implements UIResource {
public DarculaDefaultTableHeaderRenderer() {
setHorizontalAlignment(SwingConstants.CENTER);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
//if (table == null) {
// setBorder(DefaultTableCellRenderer.noFocusBorder);
// setValue(value);
// setOpaque(false);
// return this;
//}
//
//if (table.getTableHeader() == null) {
// return super.getTableCellRendererComponent(table, value,
// isSelected, hasFocus, row, column);
//}
//
//JTableHeader tableHeader = table.getTableHeader();
//TableHeaderUI tableHeaderUI = tableHeader.getUI();
//if (UIUtil.isUnderDarcula() && (tableHeaderUI instanceof DarculaTableHeaderUI)) {
// DarculaTableHeaderUI ui = (DarculaTableHeaderUI) tableHeaderUI;
// StateTransitionTracker.ModelStateInfo modelStateInfo = ui
// .getModelStateInfo(column);
// ComponentState currState = ui.getColumnState(column);
//
// if (modelStateInfo != null) {
// Map<ComponentState, StateContributionInfo> activeStates = modelStateInfo
// .getStateContributionMap();
// SubstanceColorScheme colorScheme = getColorSchemeForState(
// tableHeader, currState);
// if (currState.isDisabled() || (activeStates == null)
// || (activeStates.size() == 1)) {
// super.setForeground(new ColorUIResource(colorScheme
// .getForegroundColor()));
// } else {
// float aggrRed = 0;
// float aggrGreen = 0;
// float aggrBlue = 0;
//
// for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : modelStateInfo
// .getStateContributionMap().entrySet()) {
// ComponentState activeState = activeEntry.getKey();
// SubstanceColorScheme scheme = getColorSchemeForState(
// tableHeader, activeState);
// Color schemeFg = scheme.getForegroundColor();
// float contribution = activeEntry.getValue()
// .getContribution();
// aggrRed += schemeFg.getRed() * contribution;
// aggrGreen += schemeFg.getGreen() * contribution;
// aggrBlue += schemeFg.getBlue() * contribution;
// }
// super.setForeground(new ColorUIResource(new Color(
// (int) aggrRed, (int) aggrGreen, (int) aggrBlue)));
// }
// } else {
// SubstanceColorScheme scheme = getColorSchemeForState(
// tableHeader, currState);
// super.setForeground(new ColorUIResource(scheme
// .getForegroundColor()));
// }
//} else {
// super.setForeground(table.getForeground());
//}
//
//this.setBackground(tableHeader.getBackground());
//
//// fix for issue 319 - using font from the table header
//if (tableHeader.getFont() != null) {
// setFont(tableHeader.getFont());
//} else {
// setFont(table.getFont());
//}
//
//TableUI tableUI = table.getUI();
//if (SubstanceLookAndFeel.isCurrentLookAndFeel()
// && (tableUI instanceof SubstanceTableUI)) {
// this.setBorder(new EmptyBorder(((SubstanceTableUI) tableUI)
// .getCellRendererInsets()));
//}
//
//this.setValue(value);
//this.setOpaque(false);
//
//this.setEnabled(tableHeader.isEnabled() && table.isEnabled());
//
//// fix for defect 242 - not showing sort icon
//if (SubstanceLookAndFeel.isCurrentLookAndFeel()) {
// this.setIcon(null);
// RowSorter<? extends TableModel> rowSorter = table.getRowSorter();
// if (rowSorter != null) {
// setHorizontalTextPosition(JLabel.LEADING);
// java.util.List<? extends RowSorter.SortKey> sortKeys = rowSorter
// .getSortKeys();
// Icon sortIcon = null;
// SubstanceColorScheme scheme = null;
// if (tableHeaderUI instanceof SubstanceTableHeaderUI) {
// SubstanceTableHeaderUI ui = (SubstanceTableHeaderUI) tableHeaderUI;
// ComponentState state = ui.getColumnState(column);
// ColorSchemeAssociationKind colorSchemeAssociationKind = (state == ComponentState.ENABLED) ? ColorSchemeAssociationKind.MARK
// : ColorSchemeAssociationKind.HIGHLIGHT_MARK;
// scheme = SubstanceColorSchemeUtilities.getColorScheme(
// tableHeader, colorSchemeAssociationKind, state);
// } else {
// scheme = SubstanceColorSchemeUtilities.getColorScheme(
// tableHeader, ComponentState.ENABLED);
// }
//
// if (sortKeys.size() > 0
// && sortKeys.get(0).getColumn() == table
// .convertColumnIndexToModel(column)) {
// switch (sortKeys.get(0).getSortOrder()) {
// case ASCENDING:
// sortIcon = SubstanceImageCreator.getArrowIcon(
// SubstanceSizeUtils
// .getComponentFontSize(tableHeader),
// SwingConstants.NORTH, scheme);
// break;
// case DESCENDING:
// sortIcon = SubstanceImageCreator.getArrowIcon(
// SubstanceSizeUtils
// .getComponentFontSize(tableHeader),
// SwingConstants.SOUTH, scheme);
// break;
// case UNSORTED:
// sortIcon = null;
// }
// this.setIcon(sortIcon);
// }
// }
//}
return this;
}
}
@@ -0,0 +1,27 @@
package com.intellij.ide.ui.laf.darcula;
import com.intellij.util.ui.JBInsets;
import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
import java.awt.*;
/**
* @author Konstantin Bulenkov
*/
public class DarculaTableHeaderBorder implements Border, UIResource {
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
}
@Override
public Insets getBorderInsets(Component c) {
return JBInsets.NONE;
}
@Override
public boolean isBorderOpaque() {
return false;
}
}
@@ -0,0 +1,73 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.ui.laf.darcula;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.ui.ColorUtil;
import com.intellij.ui.Gray;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTableHeaderUI;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.util.Enumeration;
/**
* @author Konstantin Bulenkov
*/
public class DarculaTableHeaderUI extends BasicTableHeaderUI {
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
public static ComponentUI createUI(JComponent c) {
return new DarculaTableHeaderUI();
}
@Override
public void paint(Graphics g2, JComponent c) {
final Graphics2D g = (Graphics2D)g2;
final GraphicsConfig config = new GraphicsConfig(g);
final Color bg = c.getBackground();
g.setPaint(new GradientPaint(0,0, ColorUtil.shift(bg, 1.4), 0,c.getHeight(), ColorUtil.shift(bg, 0.9)));
final int h = c.getHeight();
final int w = c.getWidth();
g.fillRect(0,0, w, h);
g.setPaint(ColorUtil.shift(bg, 0.75));
g.drawLine(0, h-1, w, h-1);
g.drawLine(w-1, 0, w-1, h-1);
final Enumeration<TableColumn> columns = ((JTableHeader)c).getColumnModel().getColumns();
final Color lineColor = ColorUtil.shift(bg, 0.7);
final Color shadow = Gray._255.withAlpha(30);
int offset = 0;
while (columns.hasMoreElements()) {
final TableColumn column = columns.nextElement();
if (columns.hasMoreElements() && column.getWidth() > 0) {
offset += column.getWidth();
g.setColor(lineColor);
g.drawLine(offset-1, 1, offset-1, h-3);
g.setColor(shadow);
g.drawLine(offset, 1, offset, h-3);
}
}
config.restore();
super.paint(g, c);
}
}
@@ -19,6 +19,11 @@ control=3c3f41
link.foreground=589df6
ScrollBarUI=com.intellij.ide.ui.laf.darcula.ui.DarculaScrollBarUI
TableHeaderUI=com.intellij.ide.ui.laf.darcula.DarculaTableHeaderUI
#just to suppress border painters
TableHeader.cellBorder=com.intellij.ide.ui.laf.darcula.DarculaTableHeaderBorder
MenuBar.disabledBackground=3c3f41
MenuBar.shadow=3c3f41
TabbedPane.tabInsets=0,4,0,4