private void setUpTransitions(int length) { List<Value> sequences = sequenceToShowChooser.getSelectedValuesList(); if (this.serializeSequencesBox.isSelected() && sequences.size() > 1) { int numSeq = sequences.size(); timeController.setEndTime(length * numSeq); addTransitionsSerialized(timeController.getAllFadedTime(), true); } else { timeController.setEndTime(length); addTransitions(timeController.getAllFadedTime(), true); } }
/** * @todo Copy and paste code, refactor. Maybe it is best to add the transitions once they are * known and not every time a button is pressed. The buttons would then change only the time * controller and not affect the canvas items directly. */ private void addTransitionsSerialized(final double newTargetTime, final boolean highlightStates) { List<Value> selected = sequenceToShowChooser.getSelectedValuesList(); List<ArrayList<FCAElement>> objectSequences = calculateObjectSequences(); Iterator<Value> seqValIt = sequenceValues.iterator(); int seqNum = 0; int seqLength = timelineValues.size(); List<FCAElement> lastSequence = null; ArrowStyle[] styles = DiagramSchema.getCurrentSchema().getArrowStyles(); ArrowStyle style = null; int trailCount = 0; for (ArrayList<FCAElement> sequence : objectSequences) { Value curSequenceValue = seqValIt.next(); if (!selected.contains(curSequenceValue)) { seqNum++; continue; } if (lastSequence != null) { Color nextColor = styles[seqNum % styles.length].getColor(); DiagramNode endLast = findObjectConceptNode(lastSequence.get(lastSequence.size() - 1)); DiagramNode startNew = findObjectConceptNode(sequence.get(0)); if (endLast == null) { continue; } if (endLast != startNew) { SimpleLineDiagram diagram = (SimpleLineDiagram) diagramView.getDiagram(); diagram.addExtraCanvasItem( new InterSequenceTransitionArrow( endLast, startNew, style, nextColor, trailCount * seqLength + 0.5, timeController)); } } style = styles[seqNum % styles.length]; if (lastSequence == null) { this.targetTime = newTargetTime; this.lastAnimationTime = 0; } addTransitions(curSequenceValue, sequence, style, highlightStates, trailCount * seqLength); seqNum++; trailCount++; lastSequence = sequence; } }
private void addTransitions(double newTargetTime, boolean highlightStates) { List<Value> selected = sequenceToShowChooser.getSelectedValuesList(); List<ArrayList<FCAElement>> objectSequences = calculateObjectSequences(); Iterator<Value> seqValIt = sequenceValues.iterator(); int styleNum = 0; boolean start = true; for (List<FCAElement> sequence : objectSequences) { Value curSequenceValue = seqValIt.next(); if (start) { start = false; this.targetTime = newTargetTime; this.lastAnimationTime = 0; } ArrowStyle[] styles = DiagramSchema.getCurrentSchema().getArrowStyles(); if (selected.contains(curSequenceValue)) { addTransitions(curSequenceValue, sequence, styles[styleNum], highlightStates, 0); } styleNum = (styleNum + 1) % styles.length; } }
private void fillSequenceChooser() { sequenceToShowChooser.setListData(sequenceValues.toArray(new Value[sequenceValues.size()])); sequenceToShowChooser.setSelectionInterval(0, sequenceValues.size() - 1); }
private Component createArrowSettingsPanel() { final ArrowStyle[] styles = DiagramSchema.getCurrentSchema().getArrowStyles(); final JList<ArrowStyle> listView = new JList<>(styles); listView.setCellRenderer( new ListCellRenderer<ArrowStyle>() { public Component getListCellRendererComponent( final JList list, final ArrowStyle style, final int index, final boolean isSelected, final boolean cellHasFocus) { JPanel retVal = new JPanel() { @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; AffineTransform oldTransform = g2d.getTransform(); Paint oldPaint = g2d.getPaint(); Stroke oldStroke = g2d.getStroke(); Shape arrow = TransitionArrow.getArrowShape(style, getWidth() * 0.9); g2d.setPaint(style.getColor()); g2d.translate(getWidth() * 0.95, getHeight() / 2); g2d.fill(arrow); if (style.getBorderWidth() != 0) { g2d.setStroke(new BasicStroke(style.getBorderWidth())); g2d.setPaint(Color.BLACK); g2d.draw(arrow); } g2d.setPaint(oldPaint); g2d.setStroke(oldStroke); g2d.setTransform(oldTransform); } }; Dimension size = new Dimension(150, 30); retVal.setMinimumSize(size); retVal.setPreferredSize(size); if (sequenceValues.size() > index) { retVal.setToolTipText(sequenceValues.get(index).getDisplayString()); } else { retVal.setToolTipText("n/a"); } return retVal; } }); listView.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getClickCount() != 2) { return; } int index = listView.getSelectedIndex(); ListModel listModel = listView.getModel(); ArrowStyle style = (ArrowStyle) listModel.getElementAt(index); ArrowStyle newStyle = ArrowStyleChooser.showDialog(listView, "Edit arrow style", style); if (newStyle != null) { style.copyValues(newStyle); DiagramSchema.getCurrentSchema().store(); diagramView.repaint(); } } }); MouseInputAdapter dragHandler = new MouseInputAdapter() { private boolean isDragging = false; private int dragStartIndex; @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { dragStartIndex = listView.getSelectedIndex(); } } @Override public void mouseReleased(MouseEvent e) { isDragging = false; } @Override public void mouseDragged(MouseEvent e) { if (isDragging) { int currentIndex = listView.locationToIndex(e.getPoint()); if (currentIndex != dragStartIndex) { int dragTargetIndex = listView.getSelectedIndex(); ArrowStyle sourceStyle = styles[dragStartIndex]; styles[dragStartIndex] = styles[dragTargetIndex]; styles[dragTargetIndex] = sourceStyle; dragStartIndex = currentIndex; } } isDragging = true; } }; listView.addMouseListener(dragHandler); listView.addMouseMotionListener(dragHandler); return new JScrollPane(listView); }