/*
* @(#)ODGPropertiesPanel.java
*
* Copyright (c) 2007 The authors and contributors of JHotDraw.
* You may not use, copy or modify this file, except in compliance with the
* accompanying license terms.
*/
package org.jhotdraw.samples.odg;
import org.jhotdraw.draw.gui.JAttributeSlider;
import org.jhotdraw.draw.event.FigureAttributeEditorHandler;
import org.jhotdraw.text.JavaNumberFormatter;
import java.awt.*;
import javax.swing.*;
import org.jhotdraw.draw.*;
import org.jhotdraw.gui.*;
import org.jhotdraw.util.*;
import static org.jhotdraw.samples.svg.SVGAttributeKeys.*;
/**
* The ODGPropertiesPanel allows to edit properties (attributes and other things)
* of a ODGFigure.
*
* @author Werner Randelshofer
* @version $Id$
*/
@SuppressWarnings("rawtypes")
public class ODGPropertiesPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.odg.Labels");
private DrawingEditor editor;
private JAttributeSlider opacitySlider;
private FigureAttributeEditorHandler<Double> opacityFieldHandler;
private FigureAttributeEditorHandler<Double> opacitySliderHandler;
private FigureAttributeEditorHandler<String> linkFieldHandler;
/** Creates new instance. */
@SuppressWarnings("unchecked")
public ODGPropertiesPanel() {
initComponents();
opacitySlider = new JAttributeSlider(JSlider.VERTICAL, 0, 100, 100);
opacityPopupButton.add(opacitySlider);
opacityPopupButton.putClientProperty("JButton.buttonType","toolbar");
add(opacityPopupButton);
opacityField.setFormatterFactory(JavaNumberFormatter.createFormatterFactory(0d, 1d, 100d));
opacityFieldHandler = new FigureAttributeEditorHandler<Double>(OPACITY, opacityField, editor);
opacitySliderHandler = new FigureAttributeEditorHandler<Double>(OPACITY, opacitySlider, editor);
linkFieldHandler = new FigureAttributeEditorHandler<String>(LINK, linkField, editor);
// set fonts
Font font = getFont().deriveFont(11f);
for (Component c : getComponents()) {
c.setFont(font);
}
opacitySlider.setFont(font);
}
public void setEditor(DrawingEditor editor) {
this.editor = editor;
linkFieldHandler.setEditor(editor);
opacitySliderHandler.setEditor(editor);
opacityFieldHandler.setEditor(editor);
}
public void setView(DrawingView view) {
opacityFieldHandler.setView(view);
opacitySliderHandler.setView(view);
linkFieldHandler.setView(view);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("rawtypes")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
linkLabel = new javax.swing.JLabel();
linkField = new org.jhotdraw.draw.gui.JAttributeTextField();
opacityLabel = new javax.swing.JLabel();
opacityField = new org.jhotdraw.draw.gui.JAttributeTextField();
opacityPopupButton = new org.jhotdraw.gui.JPopupButton();
setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
setLayout(new java.awt.GridBagLayout());
linkLabel.setLabelFor(linkField);
linkLabel.setText(labels.getString("link")); // NOI18N
add(linkLabel, new java.awt.GridBagConstraints());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
add(linkField, gridBagConstraints);
opacityLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jhotdraw/draw/action/images/attributeOpacity.png"))); // NOI18N
opacityLabel.setToolTipText(labels.getString("opacity")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
add(opacityLabel, gridBagConstraints);
opacityField.setColumns(3);
add(opacityField, new java.awt.GridBagConstraints());
opacityPopupButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jhotdraw/draw/action/images/popupIcon.png"))); // NOI18N
add(opacityPopupButton, new java.awt.GridBagConstraints());
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private org.jhotdraw.draw.gui.JAttributeTextField linkField;
private javax.swing.JLabel linkLabel;
private org.jhotdraw.draw.gui.JAttributeTextField opacityField;
private javax.swing.JLabel opacityLabel;
private org.jhotdraw.gui.JPopupButton opacityPopupButton;
// End of variables declaration//GEN-END:variables
}