/** * @param active the color of the selection when it is active * @param inactive the color of the selection when it is inactive */ public void setSelectionColor(Color active, Color inactive) { selectionColor = active; inactiveSelectionColor = inactive; if (inactiveSelectionColor == null) { float r = 0.6f * selectionColor.getRed() / 255f + 0.4f * Color.LIGHT_GRAY.getRed() / 255f; float g = 0.6f * selectionColor.getGreen() / 255f + 0.4f * Color.LIGHT_GRAY.getGreen() / 255f; float b = 0.6f * selectionColor.getBlue() / 255f + 0.4f * Color.LIGHT_GRAY.getBlue() / 255f; inactiveSelectionColor = new Color(r, g, b); } }
@Override public int getColor(VisualItem item) { // highlight border of glyphs for which search is true // TODO: thicker borders? more outstanding highlighting? // do (inefficient) manual comparison (for now) Iterator itemsInGroup = m_vis.getGroup(Visualization.SEARCH_ITEMS).tuples(); while (itemsInGroup.hasNext()) { Tuple itemInGroup = (Tuple) itemsInGroup.next(); if (item.getString(DocumentGridTable.NODE_NAME) .equals(itemInGroup.getString(DocumentGridTable.NODE_NAME))) { // debug // System.out.println("debug: "+this.getClass().getName()+": item in // group! "+item.toString()); return ColorLib.rgb(191, 99, 130); } } if (item.isHover()) { return Color.LIGHT_GRAY.getRGB(); } // default border color // return ColorLib.gray(50); return Color.DARK_GRAY.getRGB(); }
/** * Class to store mouse start location when dragging, and to deselect any selected components when * the mouse is pressed * * @author Alex Billingsley */ public class MseSelectListener extends MouseAdapter { private Point xy1; public static final Color DESELECT = new Color(Color.WHITE.getRGB()); public static final Color SELECT = new Color(Color.LIGHT_GRAY.getRGB()); /** Creates a new instance of MouseSelectionListener */ public MseSelectListener() {} public void mousePressed(MouseEvent e) { xy1 = new Point(e.getX(), e.getY()); JPanel layer = (JPanel) e.getComponent(); deSelect(layer); } public static void deSelect(JPanel layer) { Component[] components = layer.getComponents(); int i = 0; while (i < components.length) { if (components[i].getClass().getName().equals("javax.swing.JLabel")) { if (components[i].getBackground().equals(SELECT)) { JLabel temp = (JLabel) components[i]; temp.setOpaque(false); components[i].setBackground(DESELECT); } } if (components[i].getClass().getName().equals("Display.TextBox")) { if (components[i].getBackground().equals(SELECT)) { components[i].setBackground(DESELECT); } } // If panel is selected, de-select all components nested on panel if (components[i].getClass().getName().equals("javax.swing.JPanel")) { if (components[i].getBackground().equals(SELECT)) { components[i].setBackground(DESELECT); } deSelect((JPanel) components[i]); } i++; } } /** * Getter for property xy1. * * @return Value of property xy1. */ public Point getXy1() { return this.xy1; } }
private static BufferedImage createAlphaBackground(int width, int height) { BufferedImage background = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); DataBufferInt dataBuffer = (DataBufferInt) background.getRaster().getDataBuffer(); int[] data = dataBuffer.getData(); int gray = Color.LIGHT_GRAY.getRGB(); int white = Color.WHITE.getRGB(); for (int i = 0; i < data.length; i++) { int x = i % width; int y = i / width; data[i] = ((x / 4) % 2 == (y / 4) % 2) ? gray : white; } return background; }
@Override public void draw(Graphics g) { if (WinPanel.isVisible()) { g.setColor(Color.LIGHT_GRAY); if (isMouseOn()) { g.setColor(Color.LIGHT_GRAY.brighter()); } g.fillRect(x, y, width, height); g.setColor(Color.BLACK); Font font = new Font("Tahoma", Font.PLAIN, 20); DrawingUtility.drawStringInBox( "PLAY AGAIN", font, x, y, width, height - 5, DrawingUtility.TEXT_CENTER, g); } }