package art.servers.colorsserver.M.gui.diagrams;
|
|
import art.library.gui.FlatGUI;
|
import art.library.model.devices.colors.controller.M.M_ControllerConfiguration;
|
import art.library.model.devices.colors.controller.M.configuration.M_TrafficGroup;
|
import art.library.gui.flat.FlatButton;
|
import art.library.gui.flat.FlatPanel;
|
import art.library.gui.flat.FlatTableInput;
|
import java.awt.BasicStroke;
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Dimension;
|
import java.awt.Font;
|
import java.awt.FontMetrics;
|
import java.awt.Graphics;
|
import java.awt.Graphics2D;
|
import java.awt.geom.Line2D;
|
import java.awt.geom.Rectangle2D;
|
|
|
|
public class DiagramConflicts extends FlatPanel
|
{
|
|
private boolean editable = false;
|
private M_ControllerConfiguration m_configuration = null;
|
private FlatTableInput table1 = null;
|
private Color color = new FlatPanel().getLook().background;
|
|
public DiagramConflicts (M_ControllerConfiguration m_configuration)
|
{
|
setConfiguration(m_configuration);
|
}
|
|
|
public void setConfiguration(M_ControllerConfiguration m_configuration)
|
{
|
this.m_configuration = m_configuration;
|
this.removeAll();
|
this.setLayout(new BorderLayout());
|
this.add(new DiagramColumns(), BorderLayout.NORTH);
|
this.add(new DiagramRows(), BorderLayout.WEST);
|
this.add(new Diagram(), BorderLayout.CENTER);
|
|
}
|
|
|
|
public void editable(boolean editable)
|
{
|
this.editable = editable;
|
}
|
|
|
|
|
|
|
private class DiagramColumns extends FlatButton
|
{
|
private DiagramColumns()
|
{
|
setPreferredSize(new Dimension(0,22));
|
}
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
Font font = new FlatButton().getLook().font;
|
g2.setColor(new FlatButton().getLook().colorForeground);
|
|
double dx = (double)(w - 48) / ((double)m_configuration.ltrafficGroup.size());
|
dx = Math.min(64, dx);
|
|
for (int i=0; i<m_configuration.ltrafficGroup.size(); i++)
|
{
|
drawCenteredString(g2, "" + m_configuration.ltrafficGroup.get(i).number, new Rectangle2D.Double((dx * i) + 48, 0, dx, h), font);
|
}
|
|
g2.setColor(new FlatButton().getLook().colorBackground.darker());
|
|
for (int i=0; i<=m_configuration.ltrafficGroup.size(); i++)
|
{
|
g2.draw(new Line2D.Double((dx * i) + 48, 0, (dx * i) + 48, h));
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
|
|
|
|
|
private class DiagramRows extends FlatButton
|
{
|
private DiagramRows()
|
{
|
setPreferredSize(new Dimension(48,0));
|
}
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(color);
|
g2.clearRect(0, 0, w, h);
|
Font font = new FlatButton().getLook().font;
|
g2.setColor(new FlatButton().getLook().colorForeground);
|
|
double dy = (double)h / (double)m_configuration.ltrafficGroup.size();
|
dy = Math.min(64, dy);
|
|
for (int i=0; i<m_configuration.ltrafficGroup.size(); i++)
|
{
|
drawCenteredString(g2, "" + m_configuration.ltrafficGroup.get(i).number, new Rectangle2D.Double(0, dy * i, w, dy), font);
|
}
|
|
g2.setColor(new FlatButton().getLook().colorBackground.darker());
|
|
for (int i=0; i<=m_configuration.ltrafficGroup.size(); i++)
|
{
|
g2.draw(new Line2D.Double(0, dy * i, w, dy * i));
|
}
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
|
|
|
|
|
private class Diagram extends FlatButton
|
{
|
private int currenti = -1;
|
private int currentj = -1;
|
|
public Diagram ()
|
{
|
this.addMouseListener(new java.awt.event.MouseAdapter()
|
{
|
public void mousePressed(java.awt.event.MouseEvent evt)
|
{
|
if (editable == true) selection(evt.getX(), evt.getY(), false);
|
}
|
public void mouseExited(java.awt.event.MouseEvent evt)
|
{
|
currenti = -1;
|
currentj = -1;
|
repaint();
|
}
|
});
|
|
this.addMouseMotionListener(new java.awt.event.MouseAdapter()
|
{
|
public void mouseDragged(java.awt.event.MouseEvent evt)
|
{
|
if (editable == true) selection(evt.getX(), evt.getY(), true);
|
}
|
public void mouseMoved(java.awt.event.MouseEvent evt)
|
{
|
movement(evt.getX(), evt.getY());
|
}
|
});
|
}
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(FlatGUI.lookDesign.getColor("window.color.background.content"));
|
|
double dx = (double)w / ((double)m_configuration.ltrafficGroup.size());
|
double dy = (double)h / (double)m_configuration.ltrafficGroup.size();
|
|
dx = Math.min(64, dx);
|
dy = Math.min(64, dy);
|
g2.clearRect(0, 0, (int)(dx * m_configuration.ltrafficGroup.size()), (int)(dy * m_configuration.ltrafficGroup.size()));
|
|
|
g2.setColor(new FlatButton().getLook().colorBackground);
|
|
for (int i=0; i<m_configuration.ltrafficGroup.size(); i++)
|
{
|
g2.fill(new Rectangle2D.Double(dx * i, dy * i, dx, dy));
|
}
|
|
|
g2.setColor(Color.red);
|
|
for (M_TrafficGroup group1 : m_configuration.ltrafficGroup)
|
{
|
for (Integer group2 : group1.lincompatibility)
|
{
|
int i = group1.number - 1;
|
int j = group2.intValue() - 1;
|
g2.fill(new Rectangle2D.Double(dx * i, dy * j, dx, dy));
|
}
|
}
|
|
|
g2.setColor(new FlatButton().getLook().colorBackground.darker());
|
|
for (int i=0; i<=m_configuration.ltrafficGroup.size(); i++)
|
{
|
g2.draw(new Line2D.Double(dx * i, 0, dx * i, dy * m_configuration.ltrafficGroup.size()));
|
g2.draw(new Line2D.Double(0, dy * i, dx * m_configuration.ltrafficGroup.size(), dy * i));
|
}
|
|
g2.setStroke(new BasicStroke(1.0f));
|
|
if (editable == true)
|
{
|
g2.setColor(Color.black);
|
g2.draw(new Rectangle2D.Double(dx * (currenti - 1), dy * (currentj - 1), dx, dy));
|
}
|
|
g2.setColor(new FlatButton().getLook().colorBackground.darker());
|
g2.draw(new Rectangle2D.Double(0,0,dx * m_configuration.ltrafficGroup.size(),dy * m_configuration.ltrafficGroup.size()));
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
private int lasti = -1;
|
private int lastj = -1;
|
|
private void selection (int x, int y, boolean dragging)
|
{
|
try
|
{
|
double dx = (double)getWidth() / ((double)m_configuration.ltrafficGroup.size());
|
double dy = (double)getHeight() / (double)m_configuration.ltrafficGroup.size();
|
dx = Math.min(64, dx);
|
dy = Math.min(64, dy);
|
|
int i = (int)((double)x / dx) + 1;
|
int j = (int)((double)y / dy) + 1;
|
if (i == j) return;
|
currenti = i;
|
currentj = j;
|
|
if ((i != j) && ((lasti != i) || (lastj != j)) || (dragging == false))
|
{
|
reverseIncompatibility(m_configuration.getTrafficGroup(i), m_configuration.getTrafficGroup(j));
|
lasti = i;
|
lastj = j;
|
}
|
|
repaint();
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
private void movement (int x, int y)
|
{
|
try
|
{
|
double dx = (double)getWidth() / ((double)m_configuration.ltrafficGroup.size());
|
double dy = (double)getHeight() / (double)m_configuration.ltrafficGroup.size();
|
dx = Math.min(64, dx);
|
dy = Math.min(64, dy);
|
currenti = (int)((double)x / dx) + 1;
|
currentj = (int)((double)y / dy) + 1;
|
if (currenti > m_configuration.ltrafficGroup.size()) currenti = -1;
|
if (currentj > m_configuration.ltrafficGroup.size()) currentj = -1;
|
repaint();
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
|
|
|
|
|
|
|
|
private void drawCenteredString(Graphics2D g2, String text, Rectangle2D rect, Font font)
|
{
|
FontMetrics metrics = g2.getFontMetrics(font);
|
double x = rect.getX() + (rect.getWidth() - metrics.stringWidth(text)) / 2;
|
double y = rect.getY() + ((rect.getHeight() - metrics.getHeight()) / 2) + metrics.getAscent();
|
g2.setFont(font);
|
g2.drawString(text, (float)x, (float)y);
|
}
|
|
|
|
private void reverseIncompatibility(M_TrafficGroup group1, M_TrafficGroup group2)
|
{
|
for (Integer group : group1.lincompatibility)
|
{
|
if (group.intValue() == group2.number)
|
{
|
group1.lincompatibility.remove(group);
|
group2.lincompatibility.remove(new Integer(group1.number));
|
return;
|
}
|
}
|
|
|
group1.lincompatibility.add(new Integer(group2.number));
|
group2.lincompatibility.add(new Integer(group1.number));
|
}
|
|
}
|