private void doPopUp(MouseEvent e) { if (e.isPopupTrigger()) { this.button = (ColorIndexSupplier) e.getComponent(); int colorIndex = button.getColorCell(); for (int i = 0; i < groups.length; i++) { JMenuItem m = (JMenuItem) getSubElements()[Palette.split(colorIndex, i) + 64 * i]; m.setSelected(true); } show(e.getComponent(), e.getX(), e.getY()); } }
public PaletteButton(Palette palette, int table, int index) { super(); this.index = index; this.table = table; this.palette = palette; setIcon(createIcon()); setMinimumSize(new Dimension(32, 32)); setPreferredSize(new Dimension(42, 42)); setFocusPainted(false); addMouseListener(PalettePopup.createPalettePopup(palette, table)); palette.addChangeListener(this, table, index); }
public PaletteIcon(int cell, int cellSize) { colors = new Color[cellSize]; for (int i = 0; i < colors.length; i++) { this.colors[i] = Palette.toRGB(Palette.split(cell, i)); } }
public void setColorCell(int value) { palette.beginUpdate(); palette.setColorCell(value, this.table, this.index); palette.endUpdate(); }
public int getColorCell() { return palette.getColorCell(this.table, this.index); }
protected PaletteIcon createIcon() { return new PaletteIcon(palette.getColorCell(table, index), palette.getCellSize(table)); }
private void doSelect(ActionEvent e) { button.setColorCell( Palette.combine( IntStream.range(0, groups.length).map(i -> findSelected(groups[i])).toArray())); }
public static MouseListener createPalettePopup(Palette palette, int table) { return palettePopups.computeIfAbsent(table, k -> new PalettePopup(palette.getCellSize(table))) .listener; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(Palette.toRGB(index)); g.fillRect(x, y, getIconWidth(), getIconHeight()); }