@Override public void actionPerformed(ActionEvent action) { if (lastFrame == null || !lastFrame.isDisplayable()) { // only one instance LightFrameAction frame = new LightFrameAction(lightService); frame.setVisible(true); this.lastFrame = frame; } } }
@Inject public LightFrameAction(LightService lightService) { this.lightService = lightService; load(); }
private boolean validate(Double direction, Double angle) { boolean directionError = direction == null || direction < 0 || direction > 360; boolean angleError = angle == null || angle < 0 || angle > 90; ValidateUtil.setComponentError(getDirectionText(), directionError); ValidateUtil.setComponentError(getAngleText(), angleError); return !(directionError || angleError); }
private void fillForm(LightConfiguration light) { getDirectionText().setText("" + light.getDirection()); getAngleText().setText("" + light.getAngle()); getLblAmbientColor().setBackground(light.getAmbientColor()); getLblDiffuseColor().setBackground(light.getDiffuseColor()); }
@Override public void run() { try { LightFrame frame = new LightFrameAction(new kendzi3d.light.service.impl.LightService(new MemoryLightDao())); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } });
@Override protected void onDefault() { LightConfiguration light = lightService.loadDefault(); fillForm(light); }
@Override protected void onSelectAmbientColor() { Color color = JColorChooser.showDialog(this, "Select color", getLblAmbientColor().getBackground()); getLblAmbientColor().setBackground(color); }
@Override protected void onSelectDiffuseColor() { Color color = JColorChooser.showDialog(this, "Select color", getLblDiffuseColor().getBackground()); getLblDiffuseColor().setBackground(color); }
@Override protected void onOk() { String directionText = getDirectionText().getText(); String angleText = getAngleText().getText(); Color ambientColor = getLblAmbientColor().getBackground(); Color diffuseColor = getLblDiffuseColor().getBackground(); Double direction = ParseUtil.parseDouble(directionText); Double angle = ParseUtil.parseDouble(angleText); if (validate(direction, angle)) { lightService.save(new LightConfiguration(direction, angle, ambientColor, diffuseColor)); // dispose(); } }
private void load() { LightConfiguration light = lightService.load(); if (light == null) { light = lightService.loadDefault(); } fillForm(light); }