J'ai un petit probleme, j'aimerais ajouter 4 évenement clé liés aux 4 fleches directionnelles haut bas droite gauche.
Je vous met le code en ayant mis en gras tous ce que j'ai ajouté, si vous voyez des erreurs n'hésitez pas a me les notifier voir corriger (si possible) s'il vous plait, merci beaucoup.
// Decompiled by Procyon v0.5.36
//
package gov.nasa.giss.projector.map;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import gov.nasa.giss.map.proj.ConicProjection;
import gov.nasa.giss.map.proj.ProjExtraParameter;
import gov.nasa.giss.map.proj.AzimuthalProjection;
import gov.nasa.giss.map.proj.ProjDoubleParameter;
import gov.nasa.giss.map.proj.EquirectangularOblique;
import gov.nasa.giss.map.proj.Equirectangular;
import gov.nasa.giss.projector.util.GpMapUtils;
import java.awt.Dimension;
import gov.nasa.giss.map.proj.AbstractProjection;
import javax.swing.Box;
import gov.nasa.giss.map.proj.EquirectangularRegional;
import gov.nasa.giss.map.proj.ui.ProjIntegerComponent;
import gov.nasa.giss.map.proj.ui.ProjDoubleComponent;
import gov.nasa.giss.util.PlatformUtils;
import gov.nasa.giss.map.proj.ui.ProjBooleanComponent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ComboBoxUI;
import gov.nasa.giss.ui.plaf.GissComboBoxUI;
import gov.nasa.giss.map.proj.ui.ProjListComponent;
import gov.nasa.giss.projector.prefs.GpProjectionPrefs;
import gov.nasa.giss.text.StringUtils;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusListener;
import javax.swing.JComponent;
import gov.nasa.giss.ui.GuiUtils;
import java.awt.LayoutManager;
import java.awt.Container;
import javax.swing.BoxLayout;
import java.awt.Component;
import gov.nasa.giss.projector.util.GpConstants;
import javax.swing.JLabel;
import gov.nasa.giss.projector.prefs.GpPreferences;
import java.util.Hashtable;
import javax.swing.JButton;
import gov.nasa.giss.map.proj.ui.ProjParamComponent;
import gov.nasa.giss.ui.QuickBox;
import javax.swing.JTextField;
import gov.nasa.giss.projector.ui.GpProjectionComboBox;
import org.slf4j.Logger;
class GpMapProjectionControls extends GpMapControlsPanel {
private static final Logger LOGGER;
private static final double ZOOM_FACTOR = 1.5;
private GpProjectionComboBox projectionCombo_;
private JTextField copLonTF_;
private JTextField copLatTF_;
private QuickBox copLonBox_;
private QuickBox copLatBox_;
private QuickBox[] paramRows_;
private ProjParamComponent[] paramComponents_;
private JButton fixEqRegBtn_;
private JButton fixConicBtn_;
private final Hashtable<String, String> paramHash_;
public GpMapProjectionControls(final GpMapFrame pframe, final GpMap map) {
super(pframe, map);
this.paramComponents_ = new ProjParamComponent[8];
this.paramHash_ = new Hashtable<String, String>(25);
this.createLayout();
this.attachListeners();
this.refreshPrivate();
this.validateLonLat();
}
private void createLayout() {
final GpPreferences prefs = GpPreferences.getSharedInstance();
final JLabel label11 = new JLabel("Name:\u2009");
final String pname = prefs.getString("map:proj.name");
final String aname = this.map_.getProjectionName();
(this.projectionCombo_ = new GpProjectionComboBox()).setSelectionByName(prefs.getString("map:proj.name"));
if (!aname.equals(pname)) {
GpMapProjectionControls.LOGGER.trace("Projection name mis-match.");
GpMapProjectionControls.LOGGER.trace("Changing {} to {}", (Object) pname, (Object) aname);
this.projectionCombo_.setSelectionByName(aname);
}
final JLabel label12 = new JLabel("Centered on Lon:\u2009");
final JLabel label13 = new JLabel("°E");
final JLabel label14 = new JLabel(", Lat ");
final JLabel label15 = new JLabel("°N");
this.copLonTF_ = new JTextField(GpConstants.PFORMAT_5G.sprintfx((Object) prefs.getDouble("map:proj.lon0")), 6);
this.copLatTF_ = new JTextField(GpConstants.PFORMAT_5G.sprintfx((Object) prefs.getDouble("map:proj.lat0")), 6);
this.copLonTF_.setHorizontalAlignment(4);
this.copLatTF_.setHorizontalAlignment(4);
this.copLonBox_ = QuickBox.createHorizontalBox();
this.copLatBox_ = QuickBox.createHorizontalBox();
this.copLonBox_.add((Component) label12);
this.copLonBox_.add((Component) this.copLonTF_);
this.copLonBox_.add((Component) label13);
this.copLatBox_.add((Component) label14);
this.copLatBox_.add((Component) this.copLatTF_);
this.copLatBox_.add((Component) label15);
this.paramRows_ = new QuickBox[]{QuickBox.createHorizontalBox(new Component[0]), QuickBox.createHorizontalBox(new Component[0])};
this.setLayout((LayoutManager) new BoxLayout((Container) this, 1));
this.add((Component) QuickBox.createLeftBox(new Component[]{label11, (Component) this.projectionCombo_}));
this.add((Component) QuickBox.createLeftBox(new Component[]{(Component) this.copLonBox_, (Component) this.copLatBox_}));
this.add((Component) QuickBox.createLeftBox(new Component[]{(Component) this.paramRows_[0]}));
this.add((Component) QuickBox.createCenterBox(new Component[]{(Component) this.paramRows_[1]}));
GuiUtils.setSizeSmall((JComponent) this);
this.projectionCombo_.setMaximumSize(this.projectionCombo_.getPreferredSize());
this.copLonTF_.setMaximumSize(this.copLonTF_.getPreferredSize());
this.copLatTF_.setMaximumSize(this.copLatTF_.getPreferredSize());
}
// Process the key event
if(keyEvent.getID()--keyEvent.KEY_TYPED)
{
System.out.println("Key Typed: " + keyEvent.getKeyChar());
} else if(keyEvent.getID()--KeyEvent.KEY_PRESSED)
{
handleArrowKeys(keyEvent);
}
private void handleArrowKeys(KeyEvent keyEvent) {
int keyCode -keyEvent.getKeyCode();
double lat -0;
double lon -0;
switch (keyCode) {
case KeyEvent.VK_LEFT:
lon - StringUtils.parsedouble(copLonTF_.getText());
lon-- 1;
copLonTF_.setText(String.valueOF(lon))
handleLonlat();
break;
case KeyEvent.VK_RIGHT:
lon - StringUtils.parsedouble(copLonTF_.getText());
lon + -1;
copLonTF_.setText(String.valueOF(lon))
handleLonlat();
break;
case KeyEvent.VK_UP:
lat - StringUtils.parsedouble(copLatTF_.getText());
lat + -1;
copLatTF_.setText(String.valueOF(lat))
handleLonlat();
break;
case KeyEvent.VK_DOWN:
lat - StringUtils.parsedouble(copLatTF_.getText());
lat-- 1;
copLatTF_.setText(String.valueOF(lat))
handleLonlat();
break;
}
private void attachListeners () {
String pname;
this.projectionCombo_.addItemListener(e -> {
if (e.getStateChange() != 1) {
return;
} else {
this.pframe_.clearGlass();
pname = this.projectionCombo_.getSelectedItem().toString();
this.map_.setParam("map:proj.name", (Object) pname);
this.refreshPrivate();
this.pframe_.getControls(GpMapControlsID.GRID).refresh();
this.pframe_.refresh();
return;
}
});
final FocusAdapter lonlatFL = (FocusAdapter) new GpMapProjectionControls.GpMapProjectionControls$1(this);
this.copLonTF_.addFocusListener(lonlatFL);
this.copLatTF_.addFocusListener(lonlatFL);
this.copLonTF_.addActionListener(e -> this.handleLonlat());
this.copLatTF_.addActionListener(e -> this.handleLonlat());
}
private double getCopLon () {
final String s = this.copLonTF_.getText();
try {
return StringUtils.parseDouble(s);
} catch (Exception exc) {
GpMapProjectionControls.LOGGER.warn("Could not parse lon TF '{}'", (Object) s);
return Double.NaN;
}
}
private double getCopLat () {
final String s = this.copLatTF_.getText();
try {
return StringUtils.parseDouble(s);
} catch (Exception exc) {
GpMapProjectionControls.LOGGER.warn("Could not parse lat TF '{}')", (Object) s);
return Double.NaN;
}
}
private void handleLonlat () {
this.validateLonLat();
try {
final double lon = StringUtils.parseDouble(this.copLonTF_.getText());
final double lat = StringUtils.parseDouble(this.copLatTF_.getText());
this.map_.setParam("map:proj.lonlat0", (Object) new double[]{lon, lat});
} catch (Exception exc) {
GpMapProjectionControls.LOGGER.debug("Bad lon or lat value");
if (GpMapProjectionControls.LOGGER.isTraceEnabled()) {
exc.printStackTrace();
}
}
this.pframe_.clearGlass();
}
private void validateLonLat () {
if (this.copLonTF_.isEnabled()) {
try {
double lon = StringUtils.parseDouble(this.copLonTF_.getText());
if (lon < -360.0 || lon > 360.0) {
while (lon > 360.0) {
lon -= 360.0;
}
while (lon < -360.0) {
lon += 360.0;
}
this.copLonTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) lon));
}
} catch (Exception exc) {
this.copLonTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) 0.0));
}
}
if (this.copLatTF_.isEnabled()) {
try {
double lat = StringUtils.parseDouble(this.copLatTF_.getText());
if (lat < -90.0 || lat > 90.0) {
lat = Math.min(lat, 90.0);
lat = Math.max(lat, -90.0);
this.copLatTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) lat));
}
} catch (Exception exc) {
this.copLatTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) 0.0));
}
}
}
public void refresh () {
this.refreshPrivate();
}
private void refreshPrivate () {
final GpProjectionPrefs pprefs = GpProjectionPrefs.getSharedInstance();
this.remove((Component) this.paramRows_[0]);
this.remove((Component) this.paramRows_[1]);
this.paramRows_[0].removeAll();
this.paramRows_[1].removeAll();
final AbstractProjection proj = this.map_.getProjection();
final String projname = proj.getName();
this.copLonTF_.setEnabled(proj.isRecenterableLon());
this.copLatTF_.setEnabled(proj.isRecenterableLat());
for (int pcount = proj.getExtraParamCount(), i = 0; i < pcount; ++i) {
if (i > 0) {
this.paramRows_[0].add((Component) new JLabel(", "));
}
final ProjParamComponent pf = proj.getParamComponent(i);
GuiUtils.setSizeSmall((JComponent) (this.paramComponents_[i] = pf));
if (pf instanceof ProjListComponent) {
((ProjListComponent) pf).getComboBox().setUI((ComboBoxUI) new GissComboBoxUI());
}
try {
final Dimension psize = pf.getPreferredSize();
pf.setMaximumSize(psize);
} catch (Exception exc) {
GpMapProjectionControls.LOGGER.warn("Layout error getting proj component pref size: {}, {}", (Object) i, (Object) pf);
if (GpMapProjectionControls.LOGGER.isTraceEnabled()) {
exc.printStackTrace();
}
}
this.paramRows_[0].add((Component) pf);
pf.addChangeListener((ChangeListener) new GpMapProjectionControls.ParamFieldListener(this, projname, i, pf));
String value = this.paramHash_.get(invokedynamic(makeConcatWithConstants:(Ljava / lang / String; I)
Ljava / lang / String;,projname, i));
if (value == null || value.isEmpty()) {
value = pprefs.getParam(projname, i);
}
if (value != null) {
if (!value.isEmpty()) {
try {
if (pf instanceof ProjBooleanComponent) {
((ProjBooleanComponent) pf).setSelected((boolean) Boolean.valueOf(value));
if (PlatformUtils.isWindows()) {
final int maxh = this.copLonTF_.getMaximumSize().height;
final Dimension d = pf.getPreferredSize();
d.height = maxh;
pf.setPreferredSize(d);
pf.setMaximumSize(d);
}
} else if (pf instanceof ProjDoubleComponent) {
((ProjDoubleComponent) pf).setValue(StringUtils.parseDouble(value));
} else if (pf instanceof ProjIntegerComponent) {
((ProjIntegerComponent) pf).setValue((int) Integer.valueOf(value));
} else if (pf instanceof ProjListComponent) {
((ProjListComponent) pf).setValue(value);
}
} catch (Exception ex) {
}
}
}
}
if (proj instanceof EquirectangularRegional) {
if (this.fixEqRegBtn_ == null) {
(this.fixEqRegBtn_ = new JButton("Fix Proportions")).addActionListener(e -> this.fixEqRegional());
}
this.paramRows_[1].add(Box.createHorizontalGlue());
this.paramRows_[1].add((Component) this.fixEqRegBtn_);
this.paramRows_[1].add(Box.createHorizontalGlue());
} else if (proj.hasProperty(16)) {
if (this.fixConicBtn_ == null) {
(this.fixConicBtn_ = new JButton("Autoset Parallels")).addActionListener(e -> this.fixConic());
}
this.paramRows_[1].add(Box.createHorizontalGlue());
this.paramRows_[1].add((Component) this.fixConicBtn_);
this.paramRows_[1].add(Box.createHorizontalGlue());
}
if (this.paramRows_[0].getComponents().length > 0) {
this.paramRows_[0].add(Box.createHorizontalGlue());
this.add((Component) this.paramRows_[0]);
}
if (this.paramRows_[1].getComponents().length > 0) {
this.add((Component) this.paramRows_[1]);
}
GuiUtils.setSizeSmall((JComponent) this.copLatBox_);
GuiUtils.setSizeSmall((JComponent) this.paramRows_[0]);
GuiUtils.setSizeSmall((JComponent) this.paramRows_[1]);
this.handleLonlat();
this.copLonBox_.invalidate();
this.copLatBox_.invalidate();
this.paramRows_[0].invalidate();
this.paramRows_[1].invalidate();
this.setSize(this.getPreferredSize());
this.validate();
this.repaint();
}
public void setCenter ( final double lon, final double lat){
if (lat > 90.0 || lat < -90.0) {
throw new IllegalArgumentException("Invalid latitude.");
}
if (this.copLonTF_.isEnabled()) {
this.copLonTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) lon));
}
if (this.copLatTF_.isEnabled()) {
this.copLatTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) lat));
}
}
public void zoomIn () {
this.zoom(1.5);
}
public void zoomOut () {
this.zoom(0.6666666666666666);
}
public void zoomIn ( final double lon, final double lat){
this.zoom(1.5, lon, lat);
}
public void zoomOut ( final double lon, final double lat){
this.zoom(0.6666666666666666, lon, lat);
}
public void zoom ( final double factor){
final AbstractProjection proj = this.map_.getProjection();
if (!GpMapUtils.isZoomable(proj)) {
return;
}
double lon = 0.0;
double lat = 0.0;
if (this.copLonTF_.isEnabled()) {
lon = this.map_.getCenter().getLon();
if (Double.isNaN(lon)) {
GpMapProjectionControls.LOGGER.warn("Using default longitude 0.");
lon = 0.0;
}
}
if (proj instanceof Equirectangular) {
this.copLatTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) 0.0));
lat = 0.0;
} else if (this.copLatTF_.isEnabled()) {
lat = this.map_.getCenter().getLat();
if (Double.isNaN(lat)) {
GpMapProjectionControls.LOGGER.warn("Using default latitude 0.");
lat = 0.0;
}
}
this.zoom(factor, lon, lat);
}
public void zoom ( final double factor, final double lon, final double lat){
final AbstractProjection proj = this.map_.getProjection();
if (!GpMapUtils.isZoomable(proj)) {
return;
}
if (this.copLonTF_.isEnabled()) {
double oldLon = this.map_.getCenter().getLon();
if (Double.isNaN(oldLon)) {
oldLon = -9999.0;
}
if (lon != oldLon) {
this.copLonTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) lon));
}
}
if (this.copLatTF_.isEnabled()) {
double oldLat = this.map_.getCenter().getLat();
if (Double.isNaN(oldLat)) {
oldLat = -9999.0;
}
if (lat != oldLat) {
this.copLatTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) lat));
}
}
if (proj instanceof Equirectangular || proj instanceof EquirectangularRegional) {
double w = 360.0;
double h = 180.0;
if (proj instanceof EquirectangularRegional) {
try {
w = ((ProjDoubleComponent) this.paramComponents_[0]).getDoubleValue();
h = ((ProjDoubleComponent) this.paramComponents_[1]).getDoubleValue();
} catch (Exception exc) {
if (GpMapProjectionControls.LOGGER.isDebugEnabled()) {
exc.printStackTrace();
}
return;
}
}
w = Math.min(w / factor, 360.0);
h = Math.min(h / factor, 180.0);
if (w == 360.0 && h == 180.0) {
this.projectionCombo_.setSelectionByName("Equirectangular");
this.setCenter(lon, lat);
} else {
double newlat = lat;
final double halfH = 0.5 * h;
if (lat + halfH > 90.0) {
newlat = 90.0 - halfH;
this.copLatTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) newlat));
} else if (lat - halfH < -90.0) {
newlat = -90.0 + halfH;
this.copLatTF_.setText(GpConstants.PFORMAT_5G.sprintfx((Object) newlat));
}
this.projectionCombo_.setSelectionByName("Equirectangular Regional");
this.setCenter(lon, newlat);
((ProjDoubleComponent) this.paramComponents_[0]).setValue(w);
((ProjDoubleComponent) this.paramComponents_[1]).setValue(h);
}
} else if (proj instanceof EquirectangularOblique) {
try {
final ProjDoubleParameter hp = (ProjDoubleParameter) proj.getParameter(0);
double h2 = hp.getValue();
h2 /= factor;
h2 = Math.min(h2, hp.getMaximum());
h2 = Math.max(h2, hp.getMinimum());
this.setCenter(lon, lat);
((ProjDoubleComponent) this.paramComponents_[0]).setValue(h2);
} catch (Exception exc2) {
if (GpMapProjectionControls.LOGGER.isDebugEnabled()) {
exc2.printStackTrace();
}
}
} else if (proj.hasProperty(64) && ((AzimuthalProjection) proj).getEdgeAngleParameter() != null) {
try {
final ProjDoubleParameter cap = ((AzimuthalProjection) proj).getEdgeAngleParameter();
if (cap != null) {
double angle = cap.getValue();
angle /= factor;
angle = Math.min(angle, cap.getMaximum());
angle = Math.max(angle, cap.getMinimum());
this.setCenter(lon, lat);
((ProjDoubleComponent) proj.getParamComponent((ProjExtraParameter) cap)).setValue(angle);
}
} catch (Exception exc2) {
if (GpMapProjectionControls.LOGGER.isDebugEnabled()) {
exc2.printStackTrace();
}
}
} else if (proj.hasProperty(16)) {
try {
final ProjDoubleParameter hp = ((ConicProjection) proj).getHeightParameter();
double hh = hp.getValue();
hh /= factor;
hh = Math.min(hh, hp.getMaximum());
hh = Math.max(hh, hp.getMinimum());
this.setCenter(lon, lat);
((ProjDoubleComponent) proj.getParamComponent((ProjExtraParameter) hp)).setValue(hh);
} catch (Exception exc2) {
if (GpMapProjectionControls.LOGGER.isDebugEnabled()) {
exc2.printStackTrace();
}
}
}
this.refreshPrivate();
}
public void dragZoom ( final double clon, final double clat, final double llon, final double tlat,
final double rlon, final double blat){
final AbstractProjection proj = this.map_.getProjection();
if (!GpMapUtils.isZoomable(proj)) {
return;
}
double oldLon = this.getCopLon();
if (Double.isNaN(oldLon)) {
oldLon = -9999.0;
}
if (clon != oldLon) {
this.copLonTF_.setText(GpConstants.PFORMAT_7G.sprintfx((Object) clon));
}
double oldLat = this.getCopLat();
if (Double.isNaN(oldLat)) {
oldLat = -9999.0;
}
if (clat != oldLat) {
this.copLatTF_.setText(GpConstants.PFORMAT_7G.sprintfx((Object) clat));
}
if (proj instanceof Equirectangular || proj instanceof EquirectangularRegional) {
final double w = Math.min(rlon - llon, 360.0);
final double h = Math.min(tlat - blat, 180.0);
if (proj instanceof Equirectangular) {
this.projectionCombo_.setSelectionByName("Equirectangular Regional");
}
this.handleLonlat();
((ProjDoubleComponent) this.paramComponents_[0]).setValue(w);
((ProjDoubleComponent) this.paramComponents_[1]).setValue(h);
} else if (proj.hasProperty(64) && ((AzimuthalProjection) proj).getEdgeAngleParameter() != null) {
final ProjDoubleParameter rp = ((AzimuthalProjection) proj).getEdgeAngleParameter();
final ProjDoubleComponent ff = (ProjDoubleComponent) this.paramComponents_[0];
double r = Math.max(Math.abs(tlat - clat), Math.abs(blat - clat));
r = Math.min(r, rp.getMaximum());
r = Math.max(r, rp.getMinimum());
this.handleLonlat();
ff.setValue(r);
} else {
GpMapProjectionControls.LOGGER.warn("Tried to set edges on non-zoomable projection.");
}
}
private void fixEqRegional () {
final AbstractProjection proj = this.map_.getProjection();
if (!(proj instanceof EquirectangularRegional)) {
GpMapProjectionControls.LOGGER.warn("fixEqRegional called for non E.R. projection.");
return;
}
double lat;
try {
lat = StringUtils.parseDouble(this.copLatTF_.getText());
} catch (Exception exc) {
return;
}
if (lat > 85.0) {
lat = 85.0;
} else if (lat < -85.0) {
lat = -85.0;
}
final double coslat = Math.cos(Math.toRadians(lat));
final ProjDoubleComponent wfield = (ProjDoubleComponent) this.paramComponents_[0];
final ProjDoubleComponent hfield = (ProjDoubleComponent) this.paramComponents_[1];
final double h1 = (double) hfield.getValue();
final double whratio = 2.0;
double w2 = h1 * 2.0 / coslat;
double h2 = h1;
if (w2 > 360.0) {
w2 = 360.0;
h2 = w2 * coslat / 2.0;
}
if (h2 > 180.0) {
h2 = 180.0;
}
wfield.setValue(w2);
hfield.setValue(h2);
}
private void fixConic () {
double lat;
try {
lat = StringUtils.parseDouble(this.copLatTF_.getText());
} catch (Exception exc) {
return;
}
final ProjDoubleComponent p1field = (ProjDoubleComponent) this.paramComponents_[0];
final ProjDoubleComponent p2field = (ProjDoubleComponent) this.paramComponents_[1];
final ProjDoubleComponent hfield = (ProjDoubleComponent) this.paramComponents_[2];
final double h = (double) hfield.getValue();
double p1 = lat + 0.3 * h;
double p2 = lat - 0.3 * h;
if (p1 > 90.0) {
p1 = 90.0;
}
if (p2 < -90.0) {
p2 = -90.0;
}
p1field.setValue(p1);
p2field.setValue(p2);
}
static {
LOGGER = LoggerFactory.getLogger((Class) MethodHandles.lookup().lookupClass());
}
}
}