Exemple #1
0
 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());
   }
 }
Exemple #2
0
 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);
 }
Exemple #3
0
 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));
   }
 }
Exemple #4
0
 public void setColorCell(int value) {
   palette.beginUpdate();
   palette.setColorCell(value, this.table, this.index);
   palette.endUpdate();
 }
Exemple #5
0
 public int getColorCell() {
   return palette.getColorCell(this.table, this.index);
 }
Exemple #6
0
 protected PaletteIcon createIcon() {
   return new PaletteIcon(palette.getColorCell(table, index), palette.getCellSize(table));
 }
Exemple #7
0
 private void doSelect(ActionEvent e) {
   button.setColorCell(
       Palette.combine(
           IntStream.range(0, groups.length).map(i -> findSelected(groups[i])).toArray()));
 }
Exemple #8
0
 public static MouseListener createPalettePopup(Palette palette, int table) {
   return palettePopups.computeIfAbsent(table, k -> new PalettePopup(palette.getCellSize(table)))
       .listener;
 }
Exemple #9
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Palette.toRGB(index));
   g.fillRect(x, y, getIconWidth(), getIconHeight());
 }