/**
* Copyright (c) 2014, WonderBuilders, Inc., All Rights Reserved
*/
package org.jdesktop.wonderland.modules.placemarks.client;
import com.jme.renderer.ColorRGBA;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.io.File;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
*
* @author Abhishek Upadhyay
*/
public class CoverScreenPropertyPanel extends javax.swing.JPanel {
private ColorRGBA newBackColor;
private ColorRGBA newTextColor;
private File image=null;
CoverScreenPropertyPanel() {
initComponents();
fileChooser.setAcceptAllFileFilterUsed(false);
txtImage.setEditable(false);
}
private void openFileChooser() {
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
image = file;
txtImage.setText(file.getAbsolutePath());
} catch (Exception ex) {
}
}
}
private void openColorChooser(final MouseEvent evt) {
final JColorChooser chooser = new JColorChooser();
JDialog dialog = JColorChooser.createDialog(this, "Select color", true
, chooser, new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(((JPanel)evt.getSource()).getName().equalsIgnoreCase("pnlBackColor")) {
Color newCol = chooser.getColor();
float[] comps = new float[3];
comps = newCol.getComponents(null);
newBackColor = new ColorRGBA(comps[0],comps[1],comps[2],newCol.getTransparency());
pnlBackColor.setBackground(newCol);
} else {
Color newCol = chooser.getColor();
float[] comps = new float[3];
comps = newCol.getComponents(null);
newCol.getComponents(comps);
newTextColor = new ColorRGBA(comps[0],comps[1],comps[2],newCol.getTransparency());
pnlTextColor.setBackground(newCol);
}
}
},null);
dialog.setVisible(true);
}
public ColorRGBA getBackColor() {
return newBackColor;
}
public void setBackColor(ColorRGBA backColor) {
float[] comps = new float[3];
comps = backColor.getColorArray();
newBackColor=backColor;
pnlBackColor.setBackground(new Color(comps[0],comps[1],comps[2]));
}
public ColorRGBA getTextColor() {
return newTextColor;
}
public void setTextColor(ColorRGBA textColor) {
float[] comps = new float[3];
comps = textColor.getColorArray();
newTextColor=textColor;
pnlTextColor.setBackground(new Color(comps[0],comps[1],comps[2]));
}
public File getImage() {
return image;
}
public String getMessage() {
return txtMessage.getText();
}
public void setMessage(String message) {
txtMessage.setText(message);
}
public String getImageURL() {
return txtImage.getText();
}
public void setImageURL(String imageURL) {
txtImage.setText(imageURL);
}
public JTextField getMessageTf() {
return txtMessage;
}
public JTextField getImageTf() {
return txtImage;
}
public JPanel getBackColorPanel() {
return pnlBackColor;
}
public JPanel getTextColorPanel() {
return pnlTextColor;
}
public JLabel getTitleCoverScreen() {
return titleCoverScreen;
}
/**
* 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("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
fileChooser = new javax.swing.JFileChooser(){
};
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
pnlBackColor = new javax.swing.JPanel();
pnlTextColor = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
txtImage = new javax.swing.JTextField();
btnImage = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
txtMessage = new javax.swing.JTextField();
titleCoverScreen = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
fileChooser.setDialogTitle("Select Image");
fileChooser.addChoosableFileFilter(new
FileNameExtensionFilter("Image File","jpeg","JPEG"
,"bmp","BMP","jpg","JPG","gif","GIF"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
jLabel1.setText("Background Color : ");
jLabel2.setText("Text Color : ");
pnlBackColor.setBackground(new java.awt.Color(0, 0, 0));
pnlBackColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
pnlBackColor.setPreferredSize(new java.awt.Dimension(29, 29));
pnlBackColor.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
pnlBackColorMouseClicked(evt);
}
});
pnlBackColor.setName("pnlBackColor");
javax.swing.GroupLayout pnlBackColorLayout = new javax.swing.GroupLayout(pnlBackColor);
pnlBackColor.setLayout(pnlBackColorLayout);
pnlBackColorLayout.setHorizontalGroup(
pnlBackColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 27, Short.MAX_VALUE)
);
pnlBackColorLayout.setVerticalGroup(
pnlBackColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
pnlTextColor.setBackground(new java.awt.Color(255, 255, 255));
pnlTextColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
pnlTextColor.setPreferredSize(new java.awt.Dimension(29, 29));
pnlTextColor.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
pnlTextColorMouseClicked(evt);
}
});
pnlTextColor.setName("pnlTextColor");
javax.swing.GroupLayout pnlTextColorLayout = new javax.swing.GroupLayout(pnlTextColor);
pnlTextColor.setLayout(pnlTextColorLayout);
pnlTextColorLayout.setHorizontalGroup(
pnlTextColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 27, Short.MAX_VALUE)
);
pnlTextColorLayout.setVerticalGroup(
pnlTextColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
jLabel3.setText("Image (Optional) : ");
txtImage.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtImageActionPerformed(evt);
}
});
btnImage.setText("Choose Image");
btnImage.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnImageActionPerformed(evt);
}
});
jLabel4.setText("Message : ");
titleCoverScreen.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
titleCoverScreen.setText("Cover Screen");
jButton1.setText("Clear");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtMessage))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlBackColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlTextColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(titleCoverScreen)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtImage, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnImage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(titleCoverScreen)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlTextColor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlBackColor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnImage)
.addComponent(jButton1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void pnlTextColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlTextColorMouseClicked
// TODO add your handling code here:
openColorChooser(evt);
}//GEN-LAST:event_pnlTextColorMouseClicked
private void pnlBackColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlBackColorMouseClicked
// TODO add your handling code here:
openColorChooser(evt);
}//GEN-LAST:event_pnlBackColorMouseClicked
private void txtImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtImageActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtImageActionPerformed
private void btnImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImageActionPerformed
// TODO add your handling code here:
openFileChooser();
}//GEN-LAST:event_btnImageActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
txtImage.setText("");
image = null;
}//GEN-LAST:event_jButton1ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnImage;
private javax.swing.JFileChooser fileChooser;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel pnlBackColor;
private javax.swing.JPanel pnlTextColor;
private javax.swing.JLabel titleCoverScreen;
private javax.swing.JTextField txtImage;
private javax.swing.JTextField txtMessage;
// End of variables declaration//GEN-END:variables
}