use of java.awt.event.KeyListener in project mafscaling by vimsh.
the class LogView method createGraghPanel.
private void createGraghPanel() {
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setFocusable(true);
chartPanel.setAutoscrolls(true);
chartPanel.setPopupMenu(null);
chart.setBackgroundPaint(chartColor);
rpmDataset = new XYSeriesCollection();
rpmPlotRenderer = new XYLineAndShapeRenderer();
dataset = new XYSeriesCollection();
plotRenderer = new XYLineAndShapeRenderer();
NumberAxis xAxis = new NumberAxis();
xAxis.setTickLabelsVisible(false);
xAxis.setTickLabelPaint(Color.WHITE);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelsVisible(false);
yAxis.setTickLabelPaint(Color.WHITE);
yAxis.setAutoRangeIncludesZero(false);
NumberAxis y2Axis = new NumberAxis();
y2Axis.setTickLabelsVisible(false);
y2Axis.setTickLabelPaint(Color.WHITE);
y2Axis.setAutoRangeIncludesZero(false);
plot = chartPanel.getChart().getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
plot.setBackgroundPaint(chartBgColor);
plot.setDataset(0, rpmDataset);
plot.setRenderer(0, rpmPlotRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
plot.setDataset(1, dataset);
plot.setRenderer(1, plotRenderer);
plot.setRangeAxis(1, y2Axis);
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);
LegendTitle legend = new LegendTitle(plot);
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
legend.setItemPaint(Color.WHITE);
chart.addLegend(legend);
xMarker = new XYDomainMutilineAnnotation();
xMarker.setDefaultPaint(Color.WHITE);
plot.addAnnotation(xMarker);
chartMouseListener = new ChartMouseListener() {
@Override
public void chartMouseMoved(ChartMouseEvent event) {
try {
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
if (setMarkers(x, isLeft)) {
try {
int selectedCol = logDataTable.getTable().getSelectedColumn();
if (selectedCol < 0)
selectedCol = 0;
if (logPlayWindow == null || startMarker != null || endMarker != null) {
logDataTable.getTable().setRowSelectionInterval((int) x, (int) x);
logDataTable.getTable().changeSelection((int) x, selectedCol, false, false);
} else {
logPlayWindow.setProgressBar((int) x);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void chartMouseClicked(ChartMouseEvent event) {
chartPanel.requestFocusInWindow();
if (logPlayWindow == null)
return;
if (xMarker.count() == 0)
return;
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
if (x < 0 || (int) x >= logDataTable.getRowCount())
return;
if (SwingUtilities.isLeftMouseButton(event.getTrigger())) {
if (startMarker == null) {
startMarker = new ValueMarker(x);
startMarker.setPaint(Color.GREEN);
startMarker.setStroke(new BasicStroke(1.5f));
plot.addDomainMarker(startMarker);
} else {
plot.removeDomainMarker(startMarker);
startMarker = null;
}
} else if (SwingUtilities.isRightMouseButton(event.getTrigger())) {
if (endMarker == null) {
endMarker = new ValueMarker(x);
endMarker.setPaint(Color.GREEN);
endMarker.setStroke(new BasicStroke(1.5f));
plot.addDomainMarker(endMarker);
} else {
plot.removeDomainMarker(endMarker);
endMarker = null;
}
}
chartPanel.repaint();
logPlayWindow.setStartEndArea(startMarker, endMarker);
}
};
chartPanel.addChartMouseListener(chartMouseListener);
chartPanel.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (!chartPanel.hasFocus())
return;
int keyCode = e.getKeyCode();
if (keyCode < KeyEvent.VK_LEFT || keyCode > KeyEvent.VK_DOWN)
return;
ValueAxis axis = null;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT)
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getDomainAxis();
else
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getRangeAxis();
if (axis != null) {
double delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_DOWN)
axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta);
else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_RIGHT)
axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta);
}
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
}
});
}
use of java.awt.event.KeyListener in project com.revolsys.open by revolsys.
the class MouseOverlay method keyPressed.
@Override
public void keyPressed(final KeyEvent e) {
for (final Component overlay : getOverlays()) {
if (overlay instanceof KeyListener) {
final KeyListener listener = (KeyListener) overlay;
listener.keyPressed(e);
if (e.isConsumed()) {
return;
}
}
}
}
use of java.awt.event.KeyListener in project com.revolsys.open by revolsys.
the class MouseOverlay method keyReleased.
@Override
public void keyReleased(final KeyEvent e) {
for (final Component overlay : getOverlays()) {
if (overlay instanceof KeyListener) {
final KeyListener listener = (KeyListener) overlay;
listener.keyReleased(e);
if (e.isConsumed()) {
return;
}
}
}
}
use of java.awt.event.KeyListener in project jmulticard by ctt-gob-es.
the class CustomDialogSmartcard method showConfirmDialog.
/**
* Muestra un diálogo con un mensaje que pide la interación del usuario.
* @param componentParent Componente padre.
* @param modal Modal.
* @param message Mensaje a mostrar.
* @param title Titulo del diálogo.
* @param typeOption Opciones de interación.
* @param iconPath Ruta hacia el icono del diálogo.
* @return respuesta del usuario.
*/
public static int showConfirmDialog(final Component componentParent, final boolean modal, final String message, final String title, final int typeOption, final String iconPath) {
final CustomDialogSmartcard customDialog = CustomDialogSmartcard.getInstanceCustomDialog(componentParent, modal, message, title, false, iconPath);
CustomDialogSmartcard.okButton.setEnabled(true);
customDialog.getRootPane().setDefaultButton(null);
// Restricciones
final GridBagConstraints cons = new GridBagConstraints();
cons.fill = GridBagConstraints.HORIZONTAL;
cons.gridy = 0;
// right padding
cons.insets = new Insets(0, 0, 0, 10);
// Se comprueba el tipo de dialogo
if (typeOption == JOptionPane.YES_NO_OPTION) {
// Boton Si
// $NON-NLS-1$
CustomDialogSmartcard.okButton.setText(Messages.getString("CustomDialog.confirmDialog.yes"));
CustomDialogSmartcard.okButton.setMnemonic(KeyEvent.VK_S);
// Boton no
// $NON-NLS-1$
customDialog.noButton = customDialog.getButton(Messages.getString("CustomDialog.confirmDialog.no"), KeyEvent.VK_N);
customDialog.noButton.addKeyListener(new KeyListener() {
@Override
public void keyTyped(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyReleased(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyPressed(final KeyEvent ke) {
if (10 == ke.getKeyCode()) {
customDialog.getNoButton().doClick();
}
}
});
final JPanel noPanel = new JPanel();
noPanel.add(customDialog.noButton);
customDialog.buttonsPanel.add(noPanel, cons);
customDialog.noButton.addActionListener(customDialog);
} else {
// $NON-NLS-1$
throw new UnsupportedOperationException("Solo se soportan dialogos de tipo Si/No");
}
// Se centra el texto
customDialog.infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
customDialog.pack();
// Hacemos un resize para forzar un repintado
customDialog.setSize(customDialog.getInitialWidth() + 1, customDialog.getInitialHeight() + 1);
customDialog.setVisible(true);
return customDialog.getAnswer();
}
use of java.awt.event.KeyListener in project jmulticard by ctt-gob-es.
the class CustomDialogSmartcard method showInputPasswordDialog.
/**
* Muestra un diálogo de solicitud de contraseña.
* @param componentParent Componente padre para la modalidad
* @param modal <code>true</code> si se desea que el diálogo sea modal,
* <code>false</code> en caso contrario.
* @param message Mensaje a mostrar.
* @param mnemonic Atajo de teclado.
* @param title Título del diálogo.
* @param iconPath Ruta hacia el icono del diálogo.
* @return Contraseña introducida por el usuario.
*/
public static char[] showInputPasswordDialog(final Component componentParent, final boolean modal, final String message, final int mnemonic, final String title, final String iconPath) {
final CustomDialogSmartcard customDialog = CustomDialogSmartcard.getInstanceCustomDialog(componentParent, modal, message, title, true, iconPath);
CustomDialogSmartcard.okButton.setEnabled(false);
customDialog.getRootPane().setDefaultButton(null);
// Restricciones para el panel de datos
final GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridx = 1;
c.gridy = 1;
c.weightx = 0.0;
c.weighty = 0.5;
c.gridwidth = 2;
// right padding
c.insets = new Insets(2, 5, 2, 10);
// campo de password del dialogo
customDialog.component = new JSecurePasswordLabel(16);
customDialog.component.addKeyListener(new KeyListener() {
@Override
public void keyTyped(final KeyEvent arg0) {
/* Vacio */
}
@Override
public void keyReleased(final KeyEvent ke) {
final int length = customDialog.getComponent().getPasswordLength();
// Control de los botones aceptar/cancelar
if (length >= PIN_MIN_LENGTH && length <= PIN_MAX_LENGTH) {
getOkButton().setEnabled(true);
if (10 == ke.getKeyCode()) {
getOkButton().doClick();
}
} else {
getOkButton().setEnabled(false);
}
}
@Override
public void keyPressed(final KeyEvent arg0) {
/* Vacio */
}
});
customDialog.component.addAncestorListener(new RequestFocusListener());
Utils.remarcar(customDialog.component);
Utils.setContrastColor(customDialog.component);
Utils.setFontBold(customDialog.component);
customDialog.component.getAccessibleContext().setAccessibleName(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
message.replaceAll(Constants.HTML_SALTO_LINEA, "") + " ALT + " + mnemonic + ". ");
// Se anade el campo de texto al panel de informacion general
customDialog.mainPanel.add(customDialog.component, c);
// Etiqueta principal
// Se relaciona la etiqueta con el componente
customDialog.infoLabel.setLabelFor(customDialog.component);
// Se asigna un atajo
customDialog.infoLabel.setDisplayedMnemonic(mnemonic);
// Se muestra el atajo
final String text = Utils.remarkMnemonic(customDialog.infoLabel.getText(), mnemonic);
customDialog.infoLabel.setText(text);
// Restricciones para el check
// right padding
c.insets = new Insets(0, 0, 0, 10);
c.gridy = 2;
// Se anade el check al panel de informacion general
// customDialog.mainPanel.add(panelCheckShowPass, c);
// Restricciones del panel de botones
final GridBagConstraints cons = new GridBagConstraints();
// right padding
cons.insets = new Insets(0, 0, 0, 10);
// Cancel button
cancelButton = customDialog.getButton(cancellText, KeyEvent.VK_C);
final JPanel cancelPanel = new JPanel();
cancelPanel.add(cancelButton);
customDialog.buttonsPanel.add(cancelPanel, cons);
cancelButton.addActionListener(customDialog);
cancelButton.addKeyListener(new KeyListener() {
@Override
public void keyTyped(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyReleased(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyPressed(final KeyEvent ke) {
if (10 == ke.getKeyCode()) {
getCancelButton().doClick();
}
}
});
// Se centra el texto
customDialog.infoLabel.setHorizontalAlignment(SwingConstants.LEFT);
// Se hace visible el campo de texto
customDialog.component.setVisible(true);
cancelButton.addActionListener(customDialog);
customDialog.pack();
// Hacemos un resize para forzar un repintado
customDialog.setSize(customDialog.getInitialWidth() + 1, customDialog.getInitialHeight() + 1);
customDialog.setVisible(true);
// Control para saber si se ha pulsado el boton cancelar
if (customDialog.getAnswer() == JOptionPane.YES_OPTION) {
final char[] finalPin = customDialog.getComponent().getPassword();
// Por precaucion borramos el PIN y dejamos sus componentes relacionados
// listos para ser descartados
// $NON-NLS-1$
customDialog.getComponent().setText("");
customDialog.getComponent().setText(null);
// customDialog.getComponent().setDocument(new PlainDocument());
customDialog.component = null;
customDialog.dispose();
System.runFinalization();
System.gc();
return finalPin;
}
// $NON-NLS-1$
throw new CancelledOperationException("La insercion de contrasena ha sido cancelada por el usuario");
}
Aggregations