A first pass at making the main table look a little more Mac like when on a Mac. It's definitely pretty; who knows if users'll like it, though.
| 932 | 1022 | |
|---|---|---|
| 16 | 16 | import com.jbidwatcher.ui.table.TableColumnController; |
| 17 | 17 | |
| 18 | 18 | import javax.swing.*; |
| 19 | import javax.swing.border.Border; | |
| 19 | 20 | import javax.swing.table.DefaultTableCellRenderer; |
| 20 | 21 | import java.awt.*; |
| 21 | 22 | import java.util.HashMap; |
| --- | --- | |
| 76 | 77 | } else { |
| 77 | 78 | setHorizontalAlignment(JLabel.LEFT); |
| 78 | 79 | } |
| 79 | Component returnComponent = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); | |
| 80 | JComponent returnComponent = (JComponent)super.getTableCellRendererComponent(table, value, isSelected, false, row, column); | |
| 80 | 81 | |
| 81 | 82 | AuctionEntry ae = (AuctionEntry)table.getValueAt(row, -1); |
| 83 | returnComponent.setOpaque(false); | |
| 82 | 84 | if(ae == null) return returnComponent; |
| 83 | 85 | |
| 84 | 86 | Color foreground = chooseForeground(ae, column, table.getForeground()); |
| 85 | Color background = chooseBackground(ae, column, table.getBackground()); | |
| 86 | 87 | |
| 87 | 88 | mRow = row; |
| 88 | 89 | |
| 89 | if( (row % 2) == 1) { | |
| 90 | if(darkBG == null) { | |
| 91 | int r = background.getRed(); | |
| 92 | int g = background.getGreen(); | |
| 93 | int b = background.getBlue(); | |
| 94 | r = Math.max(0, r - 20); | |
| 95 | g = Math.max(0, g - 20); | |
| 96 | b = Math.max(0, b - 20); | |
| 97 | darkBG = new Color(r, g, b); | |
| 98 | } | |
| 90 | if(!Platform.isMac()) { | |
| 91 | Color background = chooseBackground(ae, column, table.getBackground()); | |
| 92 | if ((row % 2) == 1) { | |
| 93 | if (darkBG == null) darkBG = darken(background); | |
| 99 | 94 | |
| 100 | if (column != 2 || !ae.isMultiSniped()) { | |
| 101 | if ((column != TableColumnController.SNIPE_OR_MAX && column != TableColumnController.SNIPE_TOTAL) || !ae.isMultiSniped()) { | |
| 102 | if(JConfig.queryConfiguration("display.alternate", "true").equals("true")) { | |
| 95 | if (column != 2 || !ae.isMultiSniped()) { | |
| 96 | if ((column != TableColumnController.SNIPE_OR_MAX && column != TableColumnController.SNIPE_TOTAL) || !ae.isMultiSniped()) { | |
| 97 | if (JConfig.queryConfiguration("display.alternate", "true").equals("true")) { | |
| 98 | background = darkBG; | |
| 99 | } | |
| 100 | } | |
| 103 | 101 | } |
| 104 | background = darkBG; | |
| 105 | } | |
| 106 | 102 | } |
| 103 | if (isSelected) { | |
| 104 | Colors selectionColors = getSelectionColors(column, ae, foreground, background); | |
| 105 | ||
| 106 | foreground = selectionColors.getForeground(); | |
| 107 | background = selectionColors.getBackground(); | |
| 108 | } | |
| 109 | returnComponent.setBackground(background); | |
| 107 | 110 | } |
| 108 | 111 | |
| 109 | 112 | mSelected = isSelected; |
| 110 | if(isSelected) { | |
| 111 | Colors selectionColors = getSelectionColors(column, ae, foreground, background); | |
| 112 | 113 | |
| 113 | foreground = selectionColors.getForeground(); | |
| 114 | background = selectionColors.getBackground(); | |
| 115 | } | |
| 116 | ||
| 117 | 114 | Font foo = chooseFont(returnComponent.getFont(), ae, column); |
| 118 | 115 | returnComponent.setFont(foo); |
| 119 | 116 | returnComponent.setForeground(foreground); |
| 120 | returnComponent.setBackground(background); | |
| 121 | 117 | |
| 122 | 118 | return(returnComponent); |
| 123 | 119 | } |
| 124 | 120 | |
| 121 | private Color darken(Color background) { | |
| 122 | int r = background.getRed(); | |
| 123 | int g = background.getGreen(); | |
| 124 | int b = background.getBlue(); | |
| 125 | r = Math.max(0, r - 20); | |
| 126 | g = Math.max(0, g - 20); | |
| 127 | b = Math.max(0, b - 20); | |
| 128 | return new Color(r, g, b); | |
| 129 | } | |
| 130 | ||
| 131 | private Color lighten(Color background) { | |
| 132 | int r = background.getRed(); | |
| 133 | int g = background.getGreen(); | |
| 134 | int b = background.getBlue(); | |
| 135 | r = Math.min(255, r + 20); | |
| 136 | g = Math.min(255, g + 20); | |
| 137 | b = Math.min(255, b + 20); | |
| 138 | return new Color(r, g, b); | |
| 139 | } | |
| 140 | ||
| 125 | 141 | private Map<Integer, GradientPaint> gradientCache = new HashMap<Integer, GradientPaint>(); |
| 126 | 142 | |
| 143 | private final static String evenList = "List.evenRowBackgroundPainter"; | |
| 144 | private final static String oddList = "List.oddRowBackgroundPainter"; | |
| 145 | ||
| 127 | 146 | public void paintComponent(Graphics g) { |
| 147 | boolean painted = false; | |
| 128 | 148 | if(g != null) { |
| 129 | 149 | if(JConfig.queryDisplayProperty("background.complex", "false").equals("true")) { |
| 130 | 150 | Graphics2D g2d = (Graphics2D) g; |
| --- | --- | |
| 139 | 159 | } |
| 140 | 160 | g2d.fillRect((int) bounds.getX(), (int) bounds.getY(), (int) bounds.getWidth(), (int) bounds.getHeight()); |
| 141 | 161 | } |
| 162 | } else { | |
| 163 | if(Platform.isMac()) { | |
| 164 | if(mSelected) { | |
| 165 | Color selected = UIManager.getColor("Table.selectionBackground"); | |
| 166 | renderGradient(g, selected); | |
| 167 | } else { | |
| 168 | Border bgPaint = UIManager.getBorder((mRow % 2) == 0 ? evenList : oddList); | |
| 169 | bgPaint.paintBorder(this, g, 0, 0, getWidth(), getHeight()); | |
| 170 | super.paintComponent(g); | |
| 171 | painted = true; | |
| 172 | ||
| 173 | Graphics2D g2d = (Graphics2D) g; | |
| 174 | float alpha = .1f; | |
| 175 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); | |
| 176 | g.setColor(Color.BLACK); | |
| 177 | g.drawLine(0, getHeight()-1, getWidth(), getHeight()-1); | |
| 178 | } | |
| 179 | } | |
| 142 | 180 | } |
| 143 | super.paintComponent(g); | |
| 181 | if(!painted) super.paintComponent(g); | |
| 144 | 182 | } |
| 145 | 183 | } |
| 146 | 184 | |
| 185 | private void renderGradient(Graphics g, Color selected) { | |
| 186 | GradientPaint paint; | |
| 187 | paint = gradientCache.get(cacheMapper()); | |
| 188 | if(paint == null) { | |
| 189 | paint = new GradientPaint(0, 0, lighten(selected), 0, getHeight(), selected, false); | |
| 190 | gradientCache.put(cacheMapper(), paint); | |
| 191 | } | |
| 192 | Graphics2D g2d = (Graphics2D) g; | |
| 193 | g2d.setPaint(paint); | |
| 194 | Rectangle bounds = g2d.getClipBounds(); | |
| 195 | g2d.fillRect((int) bounds.getX(), (int) bounds.getY(), (int) bounds.getWidth(), (int) bounds.getHeight()); | |
| 196 | } | |
| 197 | ||
| 147 | 198 | private int cacheMapper() {return 10000 * (mRow % 2) + getHeight();} |
| 148 | 199 | |
| 149 | 200 | private GradientPaint getGradientPaint() { |
