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.M_SubcontrollerConfiguration;
|
import art.library.model.devices.colors.controller.M.configuration.M_Phase;
|
import art.library.gui.flat.FlatButton;
|
import art.library.gui.flat.FlatPanel;
|
import art.servers.Shared;
|
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.RenderingHints;
|
import java.awt.geom.Line2D;
|
import java.awt.geom.Rectangle2D;
|
|
|
|
public class DiagramPhases extends FlatPanel
|
{
|
private boolean editable = false;
|
private M_ControllerConfiguration m_controllerConfiguration = null;
|
private M_SubcontrollerConfiguration m_subcontrollerConfiguration = null;
|
private Color color = new FlatPanel().getLook().background;
|
private int selectedColor = 0;
|
|
public DiagramPhases(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration)
|
{
|
setConfiguration(m_controllerConfiguration, m_subcontrollerConfiguration);
|
}
|
|
|
public void setConfiguration(M_ControllerConfiguration m_controllerConfiguration, M_SubcontrollerConfiguration m_subcontrollerConfiguration)
|
{
|
this.m_controllerConfiguration = m_controllerConfiguration;
|
this.m_subcontrollerConfiguration = m_subcontrollerConfiguration;
|
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 setSelectedColor(int color)
|
{
|
this.selectedColor = color;
|
}
|
|
|
public void editable(boolean editable)
|
{
|
this.editable = editable;
|
}
|
|
|
|
|
|
private class DiagramColumns extends FlatPanel
|
{
|
private DiagramColumns()
|
{
|
setPreferredSize(new Dimension(0,22));
|
}
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
|
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
|
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_subcontrollerConfiguration.lphaseStable.size());
|
|
for (int i=0; i<m_subcontrollerConfiguration.lphaseStable.size(); i++)
|
{
|
drawCenteredString(g2, Shared.getMessage("mnemonic-Fixed") + m_subcontrollerConfiguration.lphaseStable.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_subcontrollerConfiguration.lphaseStable.size(); i++)
|
{
|
g2.draw(new Line2D.Double((dx * i) + 48, 0, (dx * i) + 48, h));
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
|
|
|
|
|
private class DiagramRows extends FlatPanel
|
{
|
private DiagramRows()
|
{
|
setPreferredSize(new Dimension(48,0));
|
}
|
|
|
public void paint (Graphics g)
|
{
|
try
|
{
|
Graphics2D g2 = (Graphics2D)g;
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
|
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
|
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_subcontrollerConfiguration.ltrafficGroup.size();
|
|
for (int i=0; i<m_subcontrollerConfiguration.ltrafficGroup.size(); i++)
|
{
|
drawCenteredString(g2, Shared.getMessage("mnemonic-Group") + m_subcontrollerConfiguration.ltrafficGroup.get(i), new Rectangle2D.Double(0, dy * i, w, dy), font);
|
}
|
|
g2.setColor(new FlatButton().getLook().colorBackground.darker());
|
|
for (int i=0; i<m_subcontrollerConfiguration.ltrafficGroup.size(); i++)
|
{
|
g2.draw(new Line2D.Double(0, dy * i, w, dy * i));
|
}
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
|
|
|
|
|
private class Diagram extends FlatPanel
|
{
|
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;
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
|
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
|
int w = getWidth();
|
int h = getHeight();
|
g2.setBackground(FlatGUI.lookDesign.getColor("window.color.background.content"));
|
g2.clearRect(0, 0, w, h);
|
|
double dx = (double)w / ((double)m_subcontrollerConfiguration.lphaseStable.size());
|
double dy = (double)h / (double)m_subcontrollerConfiguration.ltrafficGroup.size();
|
|
for (int i=0; i<m_subcontrollerConfiguration.lphaseStable.size(); i++)
|
{
|
M_Phase m_phase = m_subcontrollerConfiguration.lphaseStable.get(i);
|
|
for (int j=0; j<m_phase.lcolor.size(); j++)
|
{
|
int color = m_phase.lcolor.get(j);
|
double x = dx * i;
|
double y = dy * j;
|
if (dy > 36) y = y + (dy-36)/2;
|
DiagramColors.paint(g2, x, y, dx, Math.min(36, dy), color);
|
}
|
}
|
|
|
g2.setColor(FlatGUI.lookDesign.getColor("window.color.background.content"));
|
g2.setStroke(new BasicStroke(2.0f));
|
for (int i=0; i<m_subcontrollerConfiguration.ltrafficGroup.size(); i++)
|
{
|
g2.draw(new Line2D.Double(0, dy * i, w, dy * i));
|
}
|
|
g2.setStroke(new BasicStroke(5.0f));
|
for (int i=0; i<m_subcontrollerConfiguration.lphaseStable.size(); i++)
|
{
|
g2.draw(new Line2D.Double((dx * i), 0, (dx * i), h));
|
}
|
|
|
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,w,h));
|
|
}
|
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_subcontrollerConfiguration.lphaseStable.size());
|
double dy = (double)getHeight() / (double)m_subcontrollerConfiguration.ltrafficGroup.size();
|
int i = (int)((double)x / dx) + 1;
|
int j = (int)((double)y / dy) + 1;
|
currenti = i;
|
currentj = j;
|
|
if (((lasti != i) || (lastj != j)) || (dragging == false))
|
{
|
m_subcontrollerConfiguration.lphaseStable.get(i-1).lcolor.set(j-1, new Integer(selectedColor));
|
m_subcontrollerConfiguration.updatePhase(m_subcontrollerConfiguration.lphaseStable.get(i-1).number);
|
lasti = i;
|
lastj = j;
|
}
|
|
repaint();
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
private void movement (int x, int y)
|
{
|
try
|
{
|
double dx = (double)getWidth() / ((double)m_subcontrollerConfiguration.lphaseStable.size());
|
double dy = (double)getHeight() / (double)m_subcontrollerConfiguration.ltrafficGroup.size();
|
currenti = (int)((double)x / dx) + 1;
|
currentj = (int)((double)y / dy) + 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);
|
}
|
|
|
|
|
}
|