123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296 |
- package ui.view;
- import classes.*;
- import com.google.gson.JsonParseException;
- import ui.controller.Control;
- import ui.controller.UpdateController;
- import ui.model.Consumer;
- import ui.model.DecoratedCable;
- import ui.model.DecoratedGroupNode;
- import ui.model.DecoratedHolonObject;
- import ui.model.DecoratedSwitch;
- import ui.model.Model;
- import ui.model.Passiv;
- import ui.model.Supplier;
- import ui.model.VisualRepresentationalState;
- import ui.model.DecoratedHolonObject.HolonObjectState;
- import ui.model.DecoratedSwitch.SwitchState;
- import utility.ImageImport;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.datatransfer.UnsupportedFlavorException;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.awt.geom.Line2D;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashSet;
- /**
- * This Class is the Canvas. All Objects will be visualized here
- *
- * @author Gruppe14
- */
- public class GroupNodeCanvas extends AbstractCanvas implements MouseListener, MouseMotionListener {
- private static final long serialVersionUID = 1L;
- // The UpperNode
- public GroupNode upperNode;
- // Path
- protected String path;
- int code;
- private JLabel breadCrumb;
- private int upperNodeID;
- private Component parent;
- private BufferedImage parentPreview;
- public boolean disable = false;
- /**
- * Constructor.
- *
- * @param mod the Model
- * @param control the Controller
- * @param unitGraph
- */
- GroupNodeCanvas(Model mod, Control control, UnitGraph unitGraph, GroupNode UpperNode, String parentPath, Component parentComponent) {
- toolTip = false;
- this.controller = control;
- this.model = mod;
- this.upperNode = UpperNode;
- upperNodeID = UpperNode.getId();
- this.code = UpperNode.hashCode();
- this.path = parentPath + upperNode.getName();
- this.breadCrumb = new JLabel(path);
- this.parent = parentComponent;
- parentPreview = this.getScaledImageOfComponent(parentComponent, 1f);
- // this.add(breadCrumb);
- scalediv20 = model.getScale() / 20;
- // Cps objecte aus dem border links schieben
- upperNode.setLeftBorder(/*(int) (50 + scalediv20 + scalediv20 + 10)*/ 0);
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
- if (cps.getPosition().x < model.getScaleDiv2() + upperNode.getLeftBorder() + 5) {
- cps.setPosition(
- new Position(upperNode.getLeftBorder() + 5 + model.getScaleDiv2(), cps.getPosition().y));
- }
- }
- showConnectionInformation = true;
- showedInformation[0] = true;
- showedInformation[1] = true;
- showedInformation[4] = true;
- popmenu.add(itemCut);
- popmenu.add(itemCopy);
- popmenu.add(itemPaste);
- popmenu.add(itemDelete);
- popmenu.add(itemAlign);
- popmenu.addSeparator();
- popmenu.add(itemGroup);
- popmenu.add(itemUngroup);
- popmenu.add(itemTrack);
- popmenu.add(itemUntrack);
- popmenu.add(itemCreateTemplate);
-
- itemAlign.setEnabled(true);
- itemDelete.setEnabled(false);
- itemCut.setEnabled(false);
- itemCopy.setEnabled(false);
- itemPaste.setEnabled(true);
- itemGroup.setEnabled(false);
- itemUngroup.setEnabled(false);
- itemTrack.setEnabled(false);
- itemUntrack.setEnabled(false);
-
- updCon = new UpdateController(model, controller);
-
- itemAlign.addActionListener(actionEvent -> {
- for(AbstractCanvasObject cps: model.getSelectedCpsObjects())
- align(cps, model.getScaleDiv2());
- repaint();
- });
-
- itemGroup.addActionListener(actionEvent -> {
- // calculate uppernode pos (taken from the controller)
- unPos = new Position(0, 0);
- animCps = new ArrayList<>();
- for (AbstractCanvasObject cps : model.getSelectedCpsObjects()) {
- animCps.add(cps); // add to animation Cps ArrayList
- unPos.x += cps.getPosition().x;
- unPos.y += cps.getPosition().y;
- }
- unPos.x /= animCps.size();
- unPos.y /= animCps.size();
- // save old Position
- savePos = new ArrayList<>();
- for (int i = 0; i < animCps.size(); i++) {
- savePos.add(new Position(0, 0));
- savePos.get(i).x = animCps.get(i).getPosition().x;
- savePos.get(i).y = animCps.get(i).getPosition().y;
- }
- animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
- if (animDuration - animDelay > 0 && animCps.size() > 1) {
- for (AbstractCanvasObject currentAnimCps : animCps) {
- double x1 = currentAnimCps.getPosition().x - unPos.x;
- double y1 = currentAnimCps.getPosition().y - unPos.y;
- currentAnimCps.getPosition().x -= x1 / animSteps;
- currentAnimCps.getPosition().y -= y1 / animSteps;
- }
- repaint();
- animDuration -= animDelay;
- animSteps--;
- } else {
- animDuration = ANIMTIME;
- animSteps = animDuration / animDelay;
- animT.stop();
- for (int i = 0; i < animCps.size(); i++) {
- animCps.get(i).getPosition().x = savePos.get(i).x;
- animCps.get(i).getPosition().y = savePos.get(i).y;
- }
- controller.addUpperNode("GroupNode", upperNode, model.getSelectedCpsObjects());
- controller.calculateStateAndVisualForCurrentTimeStep();
- repaint();
- }
- });
- animT.start();
- });
- itemUngroup.addActionListener(actionEvent -> {
- // save old Position
- closeUpperNodeTab(tempCps.getId());
- savePos = new ArrayList<>();
- animCps = ((GroupNode) tempCps).getNodes();
- controller.ungroupGroupNode((GroupNode) tempCps, upperNode);
- for (int i = 0; i < animCps.size(); i++) {
- savePos.add(new Position(0, 0));
- savePos.get(i).x = animCps.get(i).getPosition().x;
- savePos.get(i).y = animCps.get(i).getPosition().y;
- }
- for (AbstractCanvasObject cps : animCps) {
- int x = tempCps.getPosition().x;
- int y = tempCps.getPosition().y;
- cps.setPosition(new Position(x, y));
- }
- animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
- if (animDuration - animDelay >= 0) {
- for (int i = 0; i < animCps.size(); i++) {
- double x1 = animCps.get(i).getPosition().x - savePos.get(i).x;
- double y1 = animCps.get(i).getPosition().y - savePos.get(i).y;
- animCps.get(i).getPosition().x -= x1 / animSteps;
- animCps.get(i).getPosition().y -= y1 / animSteps;
- }
- repaint();
- animDuration -= animDelay;
- animSteps--;
- } else {
- animDuration = ANIMTIME;
- animSteps = animDuration / animDelay;
- animT.stop();
- for (int i = 0; i < animCps.size(); i++) {
- animCps.get(i).getPosition().x = savePos.get(i).x;
- animCps.get(i).getPosition().y = savePos.get(i).y;
- }
- controller.calculateStateAndVisualForCurrentTimeStep();
- repaint();
- }
- });
- animT.start();
- });
- itemTrack.addActionListener(actionEvent -> {
- for (AbstractCanvasObject o : model.getSelectedCpsObjects()) {
- if (o instanceof HolonObject) {
- boolean found = false;
- if (controller.getTrackingObj() != null) {
- for (AbstractCanvasObject obj : controller.getTrackingObj()) {
- if (obj instanceof HolonObject) {
- if (obj.getId() == o.getId()) {
- found = true;
- }
- }
- }
- }
- if (!found) {
- controller.addTrackingObj(o);
- ((HolonObject) o).updateTrackingInfo();
- }
- }
- }
- });
- itemUntrack.addActionListener(actionEvent -> {
- for (AbstractCanvasObject o : model.getSelectedCpsObjects()) {
- if (o instanceof HolonObject) {
- boolean found = false;
- if (controller.getTrackingObj() != null) {
- for (AbstractCanvasObject obj : controller.getTrackingObj()) {
- if (obj instanceof HolonObject) {
- if (obj.getId() == o.getId()) {
- found = true;
- }
- }
- }
- }
- if (found) {
- // Removed from tracking array and tracking
- // information reseted
- controller.removeTrackingObj(o);
- ((HolonObject) o).setTrackingProd(new float[100]);
- ((HolonObject) o).setTrackingCons(new float[100]);
- }
- }
- }
- System.out.println(controller.getTrackingObj());
- });
- itemDelete.addActionListener(actionEvent -> {
- // Remove the selected Object objects
- for (AbstractCanvasObject cps : model.getSelectedCpsObjects()) {
- if (upperNode.getNodes().contains(cps)) {
- controller.delObjUpperNode(cps, upperNode);
- // Removes the object from the tracked objects, in case
- // it was tracked
- controller.removeTrackingObj(cps);
- // Remove UpperNodeTab if UpperNode deleted
- if (cps instanceof GroupNode) {
- JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent().getParent();
- // Look if the uppernode is open in a Tab
- for (int i = 4; i < tabbedPane.getTabCount(); i++) {
- if (tabbedPane.getComponentAt(i) != null &&
- ((GroupNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
- .getComponent(0)).upperNode.getId() == cps.getId()) {
- ((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
- break;
- }
- }
-
- }
- }
- }
- toolTip = false;
- model.getSelectedCpsObjects().clear();
- tempCps = null;
- repaint();
- });
- itemCut.addActionListener(actionEvent -> {
- controller.cut(upperNode);
- itemPaste.setEnabled(true);
- repaint();
- });
- itemCopy.addActionListener(actionEvent -> {
- if(tempCps instanceof GroupNode)
- controller.getObjectsInDepth();
- controller.copy(upperNode);
- itemPaste.setEnabled(true);
- repaint();
- });
- itemPaste.addActionListener(actionEvent -> {
- try {
- controller.paste(upperNode, mousePosition);
- unitGraph.update(model.getSelectedCpsObjects());
- } catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
- JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
- JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
- }
- repaint();
- });
-
- /*
- * create Template
- */
- itemCreateTemplate.addActionListener(actionEvent -> {
- controller.createTemplate((HolonObject)tempCps, (JFrame)SwingUtilities.getRoot(this));
- });
- this.addMouseListener(this);
- this.addMouseMotionListener(this);
- }
- /**
- * Paints all Components on the Canvas.
- *
- * @param g
- * Graphics
- */
-
- private Color getStateColor(HolonObjectState state) {
- switch(state) {
- case NOT_SUPPLIED:
- return new Color(230, 120, 100);
- case NO_ENERGY:
- return Color.white;
- case OVER_SUPPLIED:
- return new Color(166, 78, 229);
- case PARTIALLY_SUPPLIED:
- return Color.yellow;
- case PRODUCER:
- return Color.lightGray;
- case SUPPLIED:
- return new Color(13, 175, 28);
- default:
- return Color.BLACK;
- }
- }
- private void paintCanvasObject(Graphics2D g, DecoratedHolonObject decoratedHolonObject){
- Position pos = decoratedHolonObject.getModel().getPosition();
- Color statecolor = getStateColor(decoratedHolonObject.getState());
- g.setColor(statecolor);
- g.fillRect(pos.x - controller.getScaleDiv2(), pos.y - controller.getScaleDiv2(), controller.getScale(), controller.getScale());
- drawCanvasObject(g, decoratedHolonObject.getModel().getImage(), pos);
- }
- private void drawCanvasObjectString(Graphics2D g, Position posOfCanvasObject, float energy, double voltage, double phase, double powerFactor, boolean slack) {
- MyCanvas.drawCanvasObjectString(controller, g, posOfCanvasObject, energy, voltage, phase, powerFactor, slack);
- }
- private void paintConsumer(Graphics2D g, Consumer con){
- paintCanvasObject(g, con);
- paintSupplyBar(g,con.getSupplyBarPercentage(), getStateColor(con.getState()), con.getModel().getPosition());
- drawCanvasObjectString(g, con.getModel().getPosition(), -con.getEnergyNeededFromNetwork(), con.getVoltage(), con.getPhaseDegrees(), con.getPowerFactor(), con.isSlack());
- }
- private void paintSupplier(Graphics2D g, Supplier sup){
- paintCanvasObject(g, sup);
- drawCanvasObjectString(g, sup.getModel().getPosition(), sup.getEnergyToSupplyNetwork(), sup.getVoltage(), sup.getPhaseDegrees(), -1, sup.isSlack());
- }
-
- private void drawCanvasObject(Graphics2D g, String Image, Position pos) {
- g.drawImage(ImageImport.loadImage(Image, controller.getScale(), controller.getScale()) ,
- pos.x - controller.getScaleDiv2(),
- pos.y - controller.getScaleDiv2(),
- controller.getScale(), controller.getScale() , null);
- }
-
- private void paintCable(Graphics2D g, DecoratedCable cable, boolean isSelected)
- {
- MyCanvas.paintCable(controller, g, cable, isSelected, showConnectionInformation);
- }
- private void paintSwitch(Graphics2D g, DecoratedSwitch dSwitch)
- {
- drawCanvasObject(g, dSwitch.getState() == SwitchState.Open ? HolonSwitch.getSwitchOpenImage(): HolonSwitch.getSwitchClosedImage() , dSwitch.getModel().getPosition());
- }
- private void paintGroupNode(Graphics2D g, DecoratedGroupNode dGroupNode) {
- Position pos = dGroupNode.getModel().getPosition();
- g.setColor(Color.lightGray);
- g.fillRect(pos.x - controller.getScaleDiv2(), pos.y - controller.getScaleDiv2(), controller.getScale(), controller.getScale());
- drawCanvasObject(g, "/Images/upper_node.png" , pos);
- paintGroupNodeBar(g, dGroupNode, pos);
- }
- private void paintGroupNodeBar(Graphics2D g, DecoratedGroupNode dGroupNode , Position pos) {
- // +1, -2, -1 little Adjustment for pixel perfect alignment
- int barWidth = (int) (controller.getScale());
- int barHeight = (int) (controller.getScale() / 5);
- g.setColor(Color.WHITE);
- g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) barWidth, barHeight);
- float[] percentages = getGroupNodeBarPercentages(dGroupNode);
- Color[] colors = new Color[6];
- colors[0] = getStateColor(HolonObjectState.PRODUCER);
- colors[1] = getStateColor(HolonObjectState.NOT_SUPPLIED);
- colors[2] = getStateColor(HolonObjectState.PARTIALLY_SUPPLIED);
- colors[3] = getStateColor(HolonObjectState.SUPPLIED);
- colors[4] = getStateColor(HolonObjectState.OVER_SUPPLIED);
- colors[5] = getStateColor(HolonObjectState.NO_ENERGY);
-
- for(int i = 5; i>=0; i--) {
- g.setColor(colors[i]);
- g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) (barWidth * percentages[i] - 1), barHeight);
- }
- // g.setColor(color);
- // g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
- g.setColor(Color.BLACK);
- g.setStroke(new BasicStroke(1));
- g.drawRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, barWidth - 1 , barHeight);
- }
- /**
- * HardCoded Stuff dont try at Home ;)
- * @param dGroupNode
- * @return
- */
- public float[] getGroupNodeBarPercentages(DecoratedGroupNode dGroupNode) {
- int[] amountOfObjects = new int[6];
- amountOfObjects[0] = dGroupNode.getAmountOfSupplier();
- amountOfObjects[1] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
- amountOfObjects[2] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
- amountOfObjects[3] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
- amountOfObjects[4] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
- amountOfObjects[5] = dGroupNode.getAmountOfPassiv();
- int countHolonObjects = amountOfObjects[0] + amountOfObjects[1] + amountOfObjects[2] + amountOfObjects[3] + amountOfObjects[4] + amountOfObjects[5];
- float[] percentages = new float[6];
- int count = 0;
- for(int i = 0; i < 6; i++) {
- count += amountOfObjects[i];
- percentages[i] = (float)count / (float)countHolonObjects;
- }
- return percentages;
- }
- private void paintExitCable(Graphics2D g, ExitCable eCable) {
- if (eCable.getStart() == null || eCable.getFinish() == null) {
- System.out.println("Null wrong exitcable");
- System.out.println(" wrongCable: " + " start:" + eCable.getStart() + " end:" + eCable.getFinish() + " state:" + eCable.getState());
- return;
- }
- Position start = eCable.getStart().getPosition();
- Position end = eCable.getFinish().getPosition();
- switch (eCable.getState()) {
- case DOWNUP:
- case UP:
- Vector2d vStart = start.toVector();
- Vector2d vEnd = end.toVector();
- float stretchFactor = Math.min(4 * model.getScale(), vStart.getDistance(vEnd));
- Vector2d vPosition = vStart.add(vEnd.subtract(vStart).normalize().multiply(stretchFactor));
- Position newEnd = new Position(vPosition);
- MyCanvas.paintExitCable(controller, g, start, newEnd, eCable, showConnectionInformation);
- drawCanvasObject(g, "/Images/arrowUp.png", newEnd);
- break;
- default:
- MyCanvas.paintExitCable(controller, g, eCable, showConnectionInformation);
- break;
- }
- }
- private void paintSupplyBar(Graphics2D g, float percentage, Color color, Position pos) {
- // +1, -2, -1 little Adjustment for pixel perfect alignment
- int barWidth = (int) (controller.getScale());
- int barHeight = (int) (controller.getScale() / 5);
- g.setColor(Color.WHITE);
- g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) barWidth, barHeight);
- g.setColor(color);
- g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
- g.setColor(Color.BLACK);
- g.setStroke(new BasicStroke(1));
- g.drawRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, barWidth - 1 , barHeight);
- g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
- String percentageString = (Math.round((percentage * 100))) + "%";
- int stringWidth = (int) g.getFontMetrics().getStringBounds(percentageString, g).getWidth();
- if(percentage > 1.0f) g.setColor(Color.WHITE); //Just to see better on purple
- g.drawString(percentageString, pos.x + 1 - stringWidth / 2, pos.y + controller.getScaleDiv2() - 1+ barHeight);
-
- }
-
- //old code
- void drawMarker(Graphics2D g) {
- Color transparentGrey = new Color(128, 174, 247, 40);
- if (sx > x && sy > y) {
- g.drawRect(x, y, sx - x, sy - y);
- g.setColor(transparentGrey);
- g.fillRect(x, y, sx - x, sy - y);
- } else if (sx < x && sy < y) {
- g.drawRect(sx, sy, x - sx, y - sy);
- g.setColor(transparentGrey);
- g.fillRect(sx, sy, x - sx, y - sy);
- } else if (sx >= x) {
- g.drawRect(x, sy, sx - x, y - sy);
- g.setColor(transparentGrey);
- g.fillRect(x, sy, sx - x, y - sy);
- } else if (sy >= y) {
- g.drawRect(sx, y, x - sx, sy - y);
- g.setColor(transparentGrey);
- g.fillRect(sx, y, x - sx, sy - y);
- }
- }
- private BufferedImage getScaledImageOfComponent(Component component, double scale) {
- BufferedImage bi = new BufferedImage(
- (int)(component.getWidth()*scale),
- (int)(component.getHeight()*scale),
- BufferedImage.TYPE_INT_RGB);
- Graphics2D gNew = bi.createGraphics();
- gNew.scale(scale, scale);
- component.paint(gNew);
- gNew.dispose();
- return bi;
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- Graphics2D g2d = (Graphics2D) g;
- g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON));
- //-->Old code
- if (drawEdge) {
- g2d.setColor(Color.BLACK);
- g2d.setStroke(new BasicStroke(1));
- g2d.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
- }
- //<--
- //SelectedCable
- HashSet<Edge> selectedEdges = new HashSet<Edge>();
- for(AbstractCanvasObject aCps: model.getSelectedCpsObjects()) {
- for(Edge edge: aCps.getConnections()) {
- selectedEdges.add(edge);
- }
- }
- if(model.getSelectedEdge() != null) selectedEdges.add(model.getSelectedEdge());
-
- DecoratedGroupNode actualGroupNode = controller.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().get(upperNode);
- //VisualState Representation:
- for(ExitCable cable : actualGroupNode.getExitCableList()) {
- paintExitCable(g2d, cable);
- }
- for(DecoratedCable cable : actualGroupNode.getInternCableList()) {
- paintCable(g2d, cable, selectedEdges.contains(cable.getModel()));
- }
-
-
- for(DecoratedGroupNode dGroupNode : actualGroupNode.getGroupNodeList()) {
- paintGroupNode(g2d, dGroupNode);
- }
- for(Consumer con: actualGroupNode.getConsumerList()) {
- paintConsumer(g2d, con);
- }
- for(Supplier sup: actualGroupNode.getSupplierList()) {
- paintSupplier(g2d, sup);
- }
- for(Passiv pas: actualGroupNode.getPassivList()) {
- paintCanvasObject(g2d, pas);
- }
- for(DecoratedSwitch dSwitch : actualGroupNode.getSwitchList()) {
- paintSwitch(g2d, dSwitch);
- }
- for(Node node : actualGroupNode.getNodeList()) {
- drawCanvasObject(g2d, "/Images/node.png" , node.getPosition());
- }
-
- //-->oldCode
- if (doMark) {
- g2d.setColor(Color.BLACK);
- g2d.setStroke(new BasicStroke(0));
- drawMarker(g2d);
- }
- //Test Selection
- //Objects:
- g2d.setColor(Color.BLUE);
- g2d.setStroke(new BasicStroke(1));
- Color transparentGrey = new Color(128, 174, 247, 40);
- for(AbstractCanvasObject aCps: model.getSelectedCpsObjects()) {
- if(aCps instanceof Node) {
- Position pos = aCps.getPosition();
- g2d.setColor(transparentGrey);
- g2d.fillOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.setStroke(new BasicStroke(2));
- g2d.drawOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
- }
- else {
- Position pos = aCps.getPosition();
- g2d.setColor(transparentGrey);
- g2d.fillRect(pos.x - (int) (controller.getScaleDiv2()* 1.5f), pos.y - (int) (controller.getScaleDiv2()* 1.5f), (int) (controller.getScale()* 1.5f) , (int) (controller.getScale()* 1.5f));
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.setStroke(new BasicStroke(2));
- g2d.drawRect(pos.x - (int) (controller.getScaleDiv2()* 1.5f), pos.y - (int) (controller.getScaleDiv2()* 1.5f), (int) (controller.getScale()* 1.5f) , (int) (controller.getScale()* 1.5f));
- }
- }
- //maybeReplace:
- if(mayBeReplaced != null){
- g2d.setColor(Color.RED);
- Position pos = mayBeReplaced.getPosition();
- g.drawImage(ImageImport.loadImage("/Images/replace.png") ,
- pos.x + controller.getScaleDiv2(),
- pos.y - controller.getScale(),
- controller.getScaleDiv2(), controller.getScaleDiv2(), null);
- }
- //<-- OldCode
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- if(!disable){
- triggerUpdateController();
- stopEditing();
- }
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- }
- @Override
- public void mouseExited(MouseEvent e) {
- }
- @Override
- public void mousePressed(MouseEvent e) {
- if(!disable){
- stopEditing();
- tempCps = null;
- dataSelected = null;
- edgeHighlight = null;
- controller.setSelecteEdge(null);
- controller.setSelectedObjectID(-1);
- // Object Selection
- // Erase old data in the PropertyTable
- if (model.getPropertyTable().getRowCount() > 0) {
- for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
- model.getPropertyTable().removeRow(i);
- }
- }
- if (e.getX() > upperNode.getLeftBorder()) {
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
- cx = cps.getPosition().x - model.getScaleDiv2();
- cy = cps.getPosition().y - model.getScaleDiv2();
- if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
- tempCps = cps;
- dragging = true;
- if (e.isControlDown() && tempCps != null) {
- if (model.getSelectedCpsObjects().contains(tempCps)) {
- controller.deleteSelectedObject(tempCps);
- } else {
- controller.addSelectedObject(tempCps);
- if(tempCps instanceof GroupNode)
- controller.getObjectsInDepth();
- }
- }
- // If drawing an Edge (CTRL down)
- if (tempCps.getClass() == HolonObject.class) {
- HolonObject tempObj = ((HolonObject) tempCps);
- dataSelected = tempObj.getElements();
- }
- if (e.isShiftDown()) {
- drawEdge = true;
- dragging = false;
- }
- break;
- }
- }
- } else {
- // look for objects connected to uppernode
- int count = 0;
- for (Edge ed : upperNode.getConnections()) {
- AbstractCanvasObject cps;
- if (ed.getA().equals(this.upperNode)) {
- cps = ed.getB();
- } else {
- cps = ed.getA();
- }
- if (x - controller.getScale() <= ((upperNode.getLeftBorder() >> 1) - model.getScaleDiv2())
- && y - controller.getScale() <= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)
- && x >= (upperNode.getLeftBorder() >> 1) - model.getScaleDiv2()
- && y >= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)) {
- tempCps = cps;
- // If drawing an Edge (CTRL down)
- if (tempCps.getClass() == HolonObject.class) {
- HolonObject tempObj = ((HolonObject) tempCps);
- dataSelected = tempObj.getElements();
- }
- if (e.isShiftDown()) {
- drawEdge = true;
- }
- }
- count++;
- }
- }
- // Selection of CpsObject
- // model.setSelectedCpsObject(tempCps);
- // Edge Selection
- if (e.getButton() == MouseEvent.BUTTON1) {
- if (tempCps == null) {
- edgeHighlight = mousePositionOnEdge(x, y);
- controller.setSelecteEdge(edgeHighlight);
- controller.setSelectedObjectID(0);
- if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
- model.getSelectedCpsObjects().clear();
- }
- updCon.deleteRows(model.getMultiTable());
- updCon.deleteRows(model.getSingleTable());
- }
- if (edgeHighlight == null && tempCps == null) {
- sx = e.getX();
- sy = e.getY();
- doMark = true;
- }
- // System.out.println("Selected Objects");
- // for (AbstractCpsObject temp : model.getSelectedCpsObjects()) {
- // System.out.println(temp.getName() + " " + temp.getID());
- // }
- repaint();
- }
- }
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- if(!disable){
- x = e.getX();
- y = e.getY();
- dragging = false;
- if (model.getSelectedCpsObjects().size() > 1) {
- model.getTableHolonElement().setModel(model.getMultiTable());
- } else if (model.getSelectedCpsObjects().size() == 1) {
- model.getTableHolonElement().setModel(model.getSingleTable());
- }
- if (drawEdge) {
- drawEdge = false;
- drawDeleteEdge();
- }
- if (dragged) {
- try {
- /**
- * Save State before performing NodePlacement, replacement e.g.
- */
- controller.autoSave();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
-
- /**
- * check if tempCps could replace an Object on the UpperNodeanvas
- */
- if(model.getSelectedCpsObjects().size() == 1 && checkForReplacement(upperNode.getNodes(), tempCps, tempCps.getPosition().x, tempCps.getPosition().y)){
- /**
- * if UpperNode would be replaced, close its tabs
- */
- if(mayBeReplaced instanceof GroupNode)
- closeUpperNodeTab(mayBeReplaced.getId());
- /**
- * replace on canvas
- */
- controller.replaceObjUpperNode(mayBeReplaced, tempCps, upperNode);
- mayBeReplaced=null;
- }
- }
- if (!e.isControlDown() && !dragged && tempCps != null && MouseEvent.BUTTON3 != e.getButton()) {
- model.getSelectedCpsObjects().clear();
- controller.addSelectedObject(tempCps);
- if(tempCps instanceof GroupNode)
- controller.getObjectsInDepth();
- }
- dragged = false;
- // Rightclick List
- setRightClickMenu(e);
- markObjects();
- if (doubleClick() && tempCps != null && tempCps instanceof HolonSwitch) {
- ((HolonSwitch) tempCps).switchState();
- }
- controller.calculateStateAndVisualForTimeStep(model.getCurIteration());
- triggerUpdateController();
- repaint();
- }
- }
- @Override
- public void mouseDragged(MouseEvent e) {
- if(!disable){
- // If Edge is drawn
- x = e.getX();
- y = e.getY();
- if (!model.getSelectedCpsObjects().contains(tempCps) && !doMark) {
- model.getSelectedCpsObjects().clear();
- if (tempCps != null) {
- controller.addSelectedObject(tempCps);
- }
- }
- if (dragging) {
- try {
- // tempCps in the upperNode? else its a connected Object from
- // outside
- if (upperNode.getNodes().contains(tempCps)) {
- dragged = true;
- float xDist, yDist; // Distance
- x = e.getX();
- y = e.getY();
- // Make sure its in bounds
- if (e.getX() < controller.getScaleDiv2() + upperNode.getLeftBorder() + 5)
- x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
- else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
- x = this.getWidth() - controller.getScaleDiv2();
- if (e.getY() < controller.getScaleDiv2())
- y = controller.getScaleDiv2();
- else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
- y = this.getHeight() - controller.getScaleDiv2();
- // Distance
- xDist = x - tempCps.getPosition().x;
- yDist = y - tempCps.getPosition().y;
- tempCps.setPosition(x, y); // Drag Position
- // TipText Position and name
- toolTip = true;
- toolTipText = tempCps.getName() + ", " + tempCps.getId();
- toolTipPos.x = tempCps.getPosition().x - model.getScaleDiv2();
- toolTipPos.y = tempCps.getPosition().y + model.getScaleDiv2();
- // All Selected Objects
- for (AbstractCanvasObject cps : model.getSelectedCpsObjects()) {
- if (cps != tempCps) {
- x = (int) (cps.getPosition().x + xDist);
- y = (int) (cps.getPosition().y + yDist);
- // Make sure its in bounds
- if (x < upperNode.getLeftBorder() + 5 + controller.getScaleDiv2())
- x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
- else if (x > this.getWidth() - controller.getScaleDiv2())
- x = this.getWidth() - controller.getScaleDiv2();
- if (y <= controller.getScaleDiv2())
- y = controller.getScaleDiv2();
- else if (y > this.getHeight() - controller.getScaleDiv2())
- y = this.getHeight() - controller.getScaleDiv2();
- cps.setPosition(x, y);
- }
- }
- }
- /**
- * check if something would be replaced
- */
- if(model.getSelectedCpsObjects().size()==1)
- checkForReplacement(upperNode.getNodes(), tempCps, x, y);
- repaint();
- } catch (Exception eex) {
- }
-
- }
- // Mark Objects
- if (doMark) {
- tempSelected.clear();
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
- int x1 = sx, x2 = x, y1 = sy, y2 = y;
- if (sx >= x) {
- x1 = x;
- x2 = sx;
- }
- if (sy >= y) {
- y1 = y;
- y2 = sy;
- }
- if (x1 <= cps.getPosition().x + model.getScaleDiv2() && y1 <= cps.getPosition().y + model.getScaleDiv2()
- && x2 >= cps.getPosition().x && y2 >= cps.getPosition().y) {
- tempSelected.add(cps);
- }
- }
- int count = 0;
- for (Edge ed : upperNode.getConnections()) {
- AbstractCanvasObject cps;
- if (ed.getA().equals(upperNode)) {
- cps = ed.getB();
- } else {
- cps = ed.getA();
- }
- int x1 = sx, x2 = x, y1 = sy, y2 = y;
- if (sx >= x) {
- x1 = x;
- x2 = sx;
- }
- if (sy >= y) {
- y1 = y;
- y2 = sy;
- }
- if (x1 <= upperNode.getLeftBorder() >> 1
- && y1 <= (int) (5 + (model.getScale() + scalediv20 + 10) * count) + model.getScaleDiv2()
- && x2 >= upperNode.getLeftBorder() >> 1
- && y2 >= (int) (5 + (model.getScale() + scalediv20 + 10) * count)) {
- tempSelected.add(cps);
- }
- count++;
- }
- }
- repaint();
- }
- }
- @Override
- public void mouseMoved(MouseEvent e) {
- {
- x = e.getX();
- y = e.getY();
- // Everything for the tooltip :)
- boolean on = false;
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
- cx = cps.getPosition().x - controller.getScaleDiv2();
- cy = cps.getPosition().y - controller.getScaleDiv2();
- on = setToolTipInfoAndPosition(on, cps);
- }
- int count = 0;
- for (Edge ed : upperNode.getConnections()) {
- AbstractCanvasObject cps;
- if (ed.getA().equals(this.upperNode)) {
- cps = ed.getB();
- } else {
- cps = ed.getA();
- }
- cx = upperNode.getLeftBorder() >> 1;
- cy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count);
- if (x - 50 <= cx && y - 50 <= cy && x >= cx && y >= cy) {
- on = true;
- toolTipPos.x = cx - 25;
- toolTipPos.y = cy + 50;
- toolTipText = cps.getName() + ", " + cps.getId();
- }
- count++;
- }
- toolTip = on;
- repaint();
- }
- }
- /**
- * Draws or Deletes an Edge.
- */
- void drawDeleteEdge() {
- boolean node = true; // new node?
- boolean newEdge = true;
- boolean onEdge = true;
- boolean deleteNode = false;
- boolean outsideCon = !upperNode.getNodes().contains(tempCps); // Connection to the outside
- boolean found = false; // dont search for outside connetion if inside
- // connection is found
- Edge e = null;
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
- cx = cps.getPosition().x - controller.getScaleDiv2();
- cy = cps.getPosition().y - controller.getScaleDiv2();
- if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
- && cps != tempCps) {
- found = true;
- node = false;
- onEdge = false;
- for (Edge p : tempCps.getConnections()) {
- if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
- newEdge = false;
- e = p;
- }
- }
- if (!newEdge) {
- if (outsideCon) {
- } else {
- controller.removeEdgesOnCanvas(e);
- }
- // Node ohne Edge?
- if (e.getA().getClass() == Node.class && e.getA().getConnections().isEmpty()) {
- tempCps = e.getA();
- deleteNode = true;
- }
- if (e.getB().getClass() == Node.class && e.getB().getConnections().isEmpty()) {
- deleteNode = true;
- }
- } else {
- if(!(cps instanceof GroupNode || tempCps instanceof GroupNode)) {
- e = new Edge(cps, tempCps, model.getMaxCapacity());
- controller.addEdgeOnCanvas(e);
- }else if (cps instanceof GroupNode && !(tempCps instanceof GroupNode)){
- GroupNode thisUpperNode = (GroupNode)cps;
- Object[] possibilities = thisUpperNode.getNodes().stream().map(aCps -> new ACpsHandle(aCps)).filter(aCpsHandle -> !(aCpsHandle.object instanceof GroupNode)).toArray();
- if(possibilities.length != 0) {
- ACpsHandle selected = (ACpsHandle) JOptionPane.showInputDialog(this, "Select a inside Object:", "Connection To?", JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
- if(selected != null) {
- e = new Edge(selected.object, tempCps, model.getMaxCapacity());
- controller.addEdgeOnCanvas(e);
- }
- }else {
- Node n = new Node("Node");
- n.setPosition(x, y);
- controller.addObjUpperNode(n, thisUpperNode);
- e = new Edge(n, tempCps, model.getMaxCapacity());
- controller.addEdgeOnCanvas(e);
- }
-
- }
- }
- }
- }
- if (!found && !outsideCon) {
- int count = 0;
- for (Edge ed : upperNode.getConnections()) {
- AbstractCanvasObject cps;
- if (ed.getA().equals(upperNode)) {
- cps = ed.getB();
- } else {
- cps = ed.getA();
- }
- cx = upperNode.getLeftBorder() >> 1;
- cy = (int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count);
- if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
- && cps != tempCps) {
- outsideCon = true;
- node = false;
- onEdge = false;
- for (Edge p : tempCps.getConnections()) {
- if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
- newEdge = false;
- e = p;
- }
- }
- if (!newEdge) {
- // Node ohne Edge?
- if (e.getA().getClass() == Node.class && e.getA().getConnections().isEmpty()) {
- tempCps = e.getA();
- deleteNode = true;
- }
- if (e.getB().getClass() == Node.class && e.getB().getConnections().isEmpty()) {
- deleteNode = true;
- }
- } else {
- Edge edge = new Edge(cps, tempCps, model.getMaxCapacity());
- if (outsideCon) {
- } else {
- controller.addEdgeOnCanvas(edge);
- }
- }
- }
- count++;
- }
- }
- // Edge auf eine Edge gezogen?
- if (onEdge && !checkForReplacement(x, y)) {
- Edge p = mousePositionOnEdge(x, y);
- if (p != null) {
- Edge e1;
- Edge e2;
- node = false;
- Node n = new Node("Node");
- n.setPosition(x, y);
- controller.addObjUpperNode(n, upperNode);
- AbstractCanvasObject r, k;
- r = p.getA();
- k = p.getB();
- e = new Edge(n, tempCps, model.getMaxCapacity());
- e1 = new Edge(n, r, model.getMaxCapacity());
- e2 = new Edge(n, k, model.getMaxCapacity());
- controller.addEdgeOnCanvas(e1);
- controller.addEdgeOnCanvas(e2);
- }
- }else{
- mayBeReplaced = null;
- }
- // ins leere Gedragged
- if (node && x > upperNode.getLeftBorder() && !checkForReplacement(x, y)) {
- Node n = new Node("Node");
- n.setPosition(x, y);
- controller.addObjUpperNode(n, upperNode);
- e = new Edge(n, tempCps, model.getMaxCapacity());
- }else{
- mayBeReplaced = null;
- }
- // Wenn ein Node ohne Connections da ist
- if (deleteNode) {
- controller.delCanvasObject(tempCps, true);
- tempCps = null;
- }
- }
- /**
- * Checks if the mouse is on an Edge.
- *
- * @param x Position of the Mouse
- * @param y Position of the Mouse
- * @return CpsEdge the Mouse is on, null if the mouse is not on an Edge
- */
- private Edge mousePositionOnEdge(int x, int y) {
- x += controller.getScaleDiv2();
- y += controller.getScaleDiv2();
- int lx, ly, hx, hy;
- //TODO: is this right
- // for (CpsEdge p : upperNode.getNodeEdges()) {
- // Line2D l = new Line2D.Float(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x,
- // p.getB().getPosition().y);
- //
- // int[] positions = determineMousePositionOnEdge(p);
- // lx = positions[0];
- // ly = positions[1];
- // hx = positions[2];
- // hy = positions[3];
- //
- // // distance from a point to a line and between both Objects
- // if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx && y > ly
- // && y < hy) {
- // return p;
- // }
- // }
- // edge to outside connection
- int count = 0;
- for (Edge e : upperNode.getConnections()) {
- AbstractCanvasObject cps;
- if (e.getA().equals(this.upperNode)) {
- cps = e.getB();
- } else {
- cps = e.getA();
- }
- for (Edge p : cps.getConnections()) {
- AbstractCanvasObject obj = null;
- boolean doTest = false;
- if (upperNode.getNodes().contains(p.getA())) {
- obj = p.getA();
- doTest = true;
- } else if (upperNode.getNodes().contains(p.getB())) {
- obj = p.getB();
- doTest = true;
- }
- // g2.drawImage(img, (borderPos >> 1) - 25, (int) (scalediv20 +
- // 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
- if (doTest) {
- Line2D l = new Line2D.Float((upperNode.getLeftBorder() >> 1) - 25,
- (int) (scalediv20 + 5 + 25 + (50 + scalediv20 + 10) * count), obj.getPosition().x,
- obj.getPosition().y);
- if ((upperNode.getLeftBorder() >> 1) > obj.getPosition().x) {
- hx = (upperNode.getLeftBorder() >> 1) - 25 + model.getScaleDiv2() + 7;
- lx = obj.getPosition().x + model.getScaleDiv2() - 7;
- } else {
- lx = (upperNode.getLeftBorder() >> 1) - 25 + model.getScaleDiv2() - 7;
- hx = obj.getPosition().x + model.getScaleDiv2() + 7;
- }
- if ((int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) > obj.getPosition().y) {
- hy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + model.getScaleDiv2() + 7;
- ly = obj.getPosition().y + model.getScaleDiv2() - 7;
- } else {
- ly = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + model.getScaleDiv2() - 7;
- hy = obj.getPosition().y + model.getScaleDiv2() + 7;
- }
- // distance from a point to a line and between both Objects
- if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx
- && y > ly && y < hy) {
- return p;
- }
- }
- }
- count++;
- }
- return null;
- }
- /**
- * copies a set of given informations
- *
- * @param informations
- */
- protected void setShowedInformation(boolean[] informations) {
- showedInformation = informations;
- }
- /**
- * set tooltIp
- *
- * @param bool
- */
- void setToolTip(boolean bool) {
- this.toolTip = bool;
- }
- /**
- * Set the Mouse Position on the UpperNodeCanvas;
- *
- * @param x
- * @param y
- */
- void setXY(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- @Override
- public boolean checkForReplacement(int x, int y) {
- return checkForReplacement(upperNode.getNodes(), null, x, y);
- }
-
- @Override
- public void tryToAlignObjects(){
- /**
- * Align all Objects
- */
- for(AbstractCanvasObject cps: upperNode.getNodes())
- align(cps,3*model.getScaleDiv2());
-
- /**
- * AutoSave new Positons
- */
- try{
- controller.autoSave();
- } catch (IOException ex) {
- System.err.println("AutoSave error by aligning");
- ex.printStackTrace();
- }
- }
- @Override
- public void closeUpperNodeTab(int upperNodeId) {
- JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
- for (int i = 4; i < tabbedPane.getTabCount(); i++) {
- if (((GroupNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
- .getComponent(0)).upperNode.getId() == upperNodeId) {
- tabbedPane.remove(i);
- break;
- }
- }
- }
- }
|