auto-sync

This commit is contained in:
rusEfi 2014-11-12 22:03:14 -06:00
parent a3d972c406
commit 16d17d5e5f
4 changed files with 85 additions and 14 deletions

View File

@ -0,0 +1,8 @@
package com.rusefi;
public enum KeyStrokeShortcut {
PREVIOUS_PAGE,
NEXT_PAGE,
ZOOM_IN,
ZOOM_OUT;
}

View File

@ -1,9 +1,12 @@
package com.rusefi.ui;
import com.rusefi.KeyStrokeShortcut;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.concurrent.atomic.AtomicInteger;
/**
@ -14,11 +17,13 @@ public class ChartScrollControl {
private final JPanel content = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
private final AtomicInteger index = new AtomicInteger();
private static final JLabel info = new JLabel();
private ChartRepository.CRListener listener;
public ChartScrollControl(final ChartRepository.CRListener listener) {
content.setBorder(BorderFactory.createLineBorder(Color.red));
this.listener = listener;
content.setBorder(BorderFactory.createLineBorder(Color.red));
setInfoText(index);
@ -27,11 +32,7 @@ public class ChartScrollControl {
prev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (index.intValue() > 0) {
index.decrementAndGet();
listener.onDigitalChart(ChartRepository.getInstance().getChart(index.get()));
setInfoText(index);
}
previousPage();
}
});
@ -41,11 +42,7 @@ public class ChartScrollControl {
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (index.intValue() < ChartRepository.getInstance().getSize() - 1) {
index.incrementAndGet();
listener.onDigitalChart(ChartRepository.getInstance().getChart(index.get()));
setInfoText(index);
}
nextPage();
}
});
@ -53,6 +50,41 @@ public class ChartScrollControl {
content.add(info);
content.add(next);
bindKeyStrokeActions();
}
private void previousPage() {
if (index.intValue() > 0) {
index.decrementAndGet();
listener.onDigitalChart(ChartRepository.getInstance().getChart(index.get()));
setInfoText(index);
}
}
private void nextPage() {
if (index.intValue() < ChartRepository.getInstance().getSize() - 1) {
index.incrementAndGet();
listener.onDigitalChart(ChartRepository.getInstance().getChart(index.get()));
setInfoText(index);
}
}
private void bindKeyStrokeActions() {
InputMap inputMap = content.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), KeyStrokeShortcut.PREVIOUS_PAGE);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), KeyStrokeShortcut.NEXT_PAGE);
content.getActionMap().put(KeyStrokeShortcut.PREVIOUS_PAGE, new AbstractAction() {
public void actionPerformed(ActionEvent event) {
previousPage();
}
});
content.getActionMap().put(KeyStrokeShortcut.NEXT_PAGE, new AbstractAction() {
public void actionPerformed(ActionEvent event) {
nextPage();
}
});
}
public JPanel getContent() {

View File

@ -106,7 +106,7 @@ public class LogViewer extends JPanel {
throw new IllegalStateException("Not directory: " + folder);
File[] files = folder.listFiles(FILE_FILTER);
fileList.removeAll();
fileListModel.removeAllElements();
for (File file : files)
fileListModel.addElement(getFileDesc(file));

View File

@ -1,11 +1,13 @@
package com.rusefi.ui;
import com.irnems.waves.ZoomProvider;
import com.rusefi.KeyStrokeShortcut;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
/**
* 7/7/13
@ -46,7 +48,7 @@ public class ZoomControl extends JPanel {
plus.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setValue(value * 1.1);
zoomIn();
}
});
plus.setToolTipText("Zoom in");
@ -67,11 +69,40 @@ public class ZoomControl extends JPanel {
minus.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setValue(value / 1.1);
zoomOut();
}
});
minus.setToolTipText("Zoom out");
add(minus);
bindKeyStrokeActions();
}
private void bindKeyStrokeActions() {
InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), KeyStrokeShortcut.ZOOM_IN);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0), KeyStrokeShortcut.ZOOM_OUT);
getActionMap().put(KeyStrokeShortcut.ZOOM_IN, new AbstractAction() {
public void actionPerformed(ActionEvent event) {
zoomIn();
}
});
getActionMap().put(KeyStrokeShortcut.ZOOM_OUT, new AbstractAction() {
public void actionPerformed(ActionEvent event) {
zoomOut();
}
});
}
private void zoomIn() {
setValue(value * 1.1);
}
private void zoomOut() {
setValue(value / 1.1);
}
private void setValue(double value) {