use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class FreightDestinationPanel method addFreightTrainUnitsFromNode.
private void addFreightTrainUnitsFromNode(DataModel model, Node node, FreightAnalyser analyser) {
Locale locale = Locale.getDefault();
List<TimeInterval> intervals = analyser.getFreightTrainUnitIntervals(node);
List<Tuple<String>> trains = intervals.stream().map(i -> new Tuple<>(util.intervalToString(diagram, i, locale), util.intervalFreightTrainUnitToString(diagram, i).stream().collect(Collectors.joining(", ")))).collect(Collectors.toList());
model.addLinesWithEmpty(trains);
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class TCItemChangeDialog method updateFromTo.
private void updateFromTo(List<TimeInterval> intervals, TimeInterval from, TimeInterval to) {
fromComboBox.removeAllItems();
toComboBox.removeAllItems();
for (TimeInterval interval : intervals) {
if (interval.isNodeOwner()) {
Wrapper<TimeInterval> w = new Wrapper<>(interval);
fromComboBox.addItem(w);
toComboBox.addItem(w);
}
}
fromComboBox.setSelectedItem(new Wrapper<>(from));
toComboBox.setSelectedItem(new Wrapper<>(to));
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class GraphicalTimetableView method initComponents.
private void initComponents() {
popupMenu = new javax.swing.JPopupMenu();
routesMenu = new SelectionMenu<>();
javax.swing.JMenuItem routesEditMenuItem = new javax.swing.JMenuItem();
javax.swing.JSeparator jSeparator1 = new javax.swing.JSeparator();
typesMenu = new SelectionMenu<>();
sizesMenu = new SelectionMenu<>();
orientationMenu = new SelectionMenu<>();
preferencesMenu = new ChoicesMenu<>();
// NOI18N
routesMenu.setText(ResourceLoader.getString("gt.routes"));
popupMenu.add(routesMenu);
// NOI18N
routesEditMenuItem.setText(ResourceLoader.getString("gt.routes.edit"));
routesEditMenuItem.addActionListener(evt -> {
if (diagram == null) {
return;
}
getRouteDialog().setLocationRelativeTo(GraphicalTimetableView.this.getParent());
getRouteDialog().showDialog(diagram);
});
popupMenu.add(routesEditMenuItem);
popupMenu.add(jSeparator1);
// NOI18N
typesMenu.setText(ResourceLoader.getString("gt.type"));
// NOI18N
typesMenu.addItem(ResourceLoader.getString("gt.classic"), GTDraw.Type.CLASSIC);
// NOI18N
typesMenu.addItem(ResourceLoader.getString("gt.classic.station.stops"), GTDraw.Type.CLASSIC_STATION_STOPS);
// NOI18N
typesMenu.addItem(ResourceLoader.getString("gt.withtracks"), GTDraw.Type.WITH_TRACKS);
typesMenu.setSelectedItem(GTDraw.Type.CLASSIC);
typesMenu.addListener(value -> {
settings.set(Key.TYPE, value);
recreateDraw();
});
popupMenu.add(typesMenu);
// NOI18N
sizesMenu.setText(ResourceLoader.getString("gt.sizes"));
popupMenu.add(sizesMenu);
// NOI18N
orientationMenu.setText(ResourceLoader.getString("gt.orientation"));
// NOI18N
orientationMenu.addItem(ResourceLoader.getString("gt.orientation.left.right"), GTOrientation.LEFT_RIGHT);
// NOI18N
orientationMenu.addItem(ResourceLoader.getString("gt.orientation.top.down"), GTOrientation.TOP_DOWN);
orientationMenu.setSelectedItem(GTOrientation.LEFT_RIGHT);
orientationMenu.addListener(value -> {
settings.set(Key.ORIENTATION, value);
setSettings(settings);
});
popupMenu.add(orientationMenu);
orientationMenu.setVisible(false);
// NOI18N
preferencesMenu.setText(ResourceLoader.getString("gt.preferences"));
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.addigits"), Key.ARRIVAL_DEPARTURE_DIGITS);
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.extendedlines"), Key.EXTENDED_LINES);
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.trainnames"), Key.TRAIN_NAMES);
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.technological.time"), Key.TECHNOLOGICAL_TIME);
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.train.ends"), Key.TRAIN_ENDS);
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.ignore.time.limits"), Key.IGNORE_TIME_LIMITS);
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.to.train.scroll"), Key.TO_TRAIN_SCROLL);
// NOI18N
preferencesMenu.addItem(ResourceLoader.getString("gt.to.train.change.route"), Key.TO_TRAIN_CHANGE_ROUTE);
preferencesMenu.addListener((value, selected) -> {
settings.setOption(value, selected);
// recreate draw
recreateDraw();
});
popupMenu.add(preferencesMenu);
routesMenu.addListener(route -> setRoute(route));
javax.swing.JMenuItem zoomMenuItem = new javax.swing.JMenuItem(ResourceLoader.getString("gt.zoom"));
zoomMenuItem.addActionListener(e -> {
// select zoom
GTViewZoomDialog dialog = new GTViewZoomDialog((Window) getTopLevelAncestor(), true);
dialog.setLocationRelativeTo(getParent());
Float oldZoom = settings.get(Key.ZOOM, Float.class);
Float newZoom = dialog.showDialog(oldZoom);
if (newZoom != null && newZoom.floatValue() != oldZoom.floatValue()) {
settings.set(Key.ZOOM, newZoom);
recreateDraw();
}
});
popupMenu.add(zoomMenuItem);
setDoubleBuffered(false);
addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
if (!SwingUtilities.isLeftMouseButton(evt)) {
return;
}
// collector/selector
boolean selected = false;
for (RegionCollector<?> collector : gtStorage.collectors()) {
if (evt.getClickCount() % 2 == 0) {
// indicates double click
if (collector.editSelected()) {
break;
}
} else {
if (!selected) {
selected = collector.selectItemsRadiuses(evt.getX(), evt.getY(), 2, SELECTION_RADIUS);
} else {
collector.deselectItems();
}
}
}
repaint();
}
});
java.awt.event.MouseAdapter motionListener = new java.awt.event.MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
handle(e, MouseAction.EXIT);
}
@Override
public void mouseEntered(MouseEvent e) {
handle(e, MouseAction.ENTER);
}
@Override
public void mouseMoved(MouseEvent e) {
handle(e, MouseAction.MOVE);
}
private void handle(MouseEvent e, MouseAction action) {
MouseOverHandler moh = gtStorage.getParameter(MOUSE_OVER_HANDLER_KEY, MouseOverHandler.class);
if (moh != null) {
RegionCollector<TimeInterval> collector = getRegionCollector(TimeInterval.class);
if (collector != null) {
List<TimeInterval> items = collector.getItemsForPointRadiuses(e.getX(), e.getY(), 2, SELECTION_RADIUS);
moh.mouseOverIntervals(items);
}
}
}
};
addMouseListener(motionListener);
addMouseMotionListener(motionListener);
setLayout(null);
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class TrackCellEditor method getTableCellEditorComponent.
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
ignoreAction = true;
editor.removeAllItems();
TimeInterval interval = ((TrainTableModel) table.getModel()).getTrain().getTimeIntervalList().get(row);
List<? extends Track> tracks = interval.getOwner().getTracks();
for (Track track : tracks) {
editor.addItem(track);
}
editor.setSelectedItem(interval.getTrack());
ignoreAction = false;
return editor;
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class PreviousNextTrainValidator method checkAndUpdateTrackAndTimeAfter.
private void checkAndUpdateTrackAndTimeAfter(Train currentTrain, Train newNextTrain) {
if (newNextTrain != null) {
TimeInterval source = currentTrain.getLastInterval();
TimeInterval dest = newNextTrain.getFirstInterval();
checkAndUpdateTrack(source, dest);
checkAndUpdateTimeAfter(currentTrain);
} else {
currentTrain.setTimeAfter(0);
}
}
Aggregations