/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.bric.gui.tabs;
import com.jhlabs.image.RotateFilter;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.*;
import org.bric.gui.BricUI;
import org.bric.imageEditParameters.WatermarkParameters;
import org.bric.utils.Utils;
import say.swing.JFontChooser;
/**
*
* @author vasilis
*/
public class WatermarkJPanel extends javax.swing.JPanel implements ImageEditTab {
private Color color;
private String plainText;
private Font defaultFont, currentFont;
/**
* Creates new form WatermarkPanelNew
*/
public WatermarkJPanel() {
initComponents();
watermarkImageText.setVisible(false);
jButton2.setVisible(false);
defaultFont = editorTextPane.getFont();
currentFont = defaultFont;
}
/**
* 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() {
jFontChooser1 = new say.swing.JFontChooser();
watermarkEnableCheckBox = new javax.swing.JCheckBox();
jLabel10 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jSplitPane1 = new javax.swing.JSplitPane();
jPlacer1 = new org.bric.gui.watermark.JPlacer();
rotateSlider = new javax.swing.JSlider();
opacitySlider = new javax.swing.JSlider();
jPanel2 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
modeComboBox = new javax.swing.JComboBox();
editorJLabel = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
editorTextPane = new javax.swing.JTextPane();
jButton2 = new javax.swing.JButton();
watermarkImageText = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
rowsSlidder = new javax.swing.JSpinner();
patternComboBox = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
coloumnsSpinner = new javax.swing.JSpinner();
jLabel8 = new javax.swing.JLabel();
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("lang/gui/tabs/Bundle"); // NOI18N
watermarkEnableCheckBox.setText(bundle.getString("WatermarkJPanel.jCheckBox3.text")); // NOI18N
watermarkEnableCheckBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
watermarkEnableCheckBoxItemStateChanged(evt);
}
});
jLabel10.setText(bundle.getString("WatermarkJPanel.jLabel10.text")); // NOI18N
jLabel10.setEnabled(false);
jLabel1.setText(bundle.getString("WatermarkJPanel.jLabel1.text")); // NOI18N
jLabel1.setEnabled(false);
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
jPlacer1.setEnabled(false);
rotateSlider.setMaximum(360);
rotateSlider.setToolTipText(bundle.getString("WatermarkJPanel.jSlider1.toolTipText")); // NOI18N
rotateSlider.setValue(0);
rotateSlider.setEnabled(false);
rotateSlider.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
rotateSliderMouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
rotateSliderMouseExited(evt);
}
});
rotateSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
rotateSliderStateChanged(evt);
}
});
opacitySlider.setMajorTickSpacing(10);
opacitySlider.setMinorTickSpacing(5);
opacitySlider.setToolTipText(bundle.getString("WatermarkJPanel.jSlider2.toolTipText")); // NOI18N
opacitySlider.setValue(0);
opacitySlider.setEnabled(false);
opacitySlider.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseExited(java.awt.event.MouseEvent evt) {
opacitySliderMouseExited(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
opacitySliderMouseEntered(evt);
}
});
opacitySlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
opacitySliderStateChanged(evt);
}
});
javax.swing.GroupLayout jPlacer1Layout = new javax.swing.GroupLayout(jPlacer1);
jPlacer1.setLayout(jPlacer1Layout);
jPlacer1Layout.setHorizontalGroup(
jPlacer1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(opacitySlider, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
.addComponent(rotateSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPlacer1Layout.setVerticalGroup(
jPlacer1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPlacer1Layout.createSequentialGroup()
.addComponent(opacitySlider, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 176, Short.MAX_VALUE)
.addComponent(rotateSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jSplitPane1.setLeftComponent(jPlacer1);
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jButton9.setText(bundle.getString("WatermarkJPanel.jButton9.text")); // NOI18N
jButton9.setEnabled(false);
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});
jButton10.setText(bundle.getString("WatermarkJPanel.jButton10.text")); // NOI18N
jButton10.setEnabled(false);
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});
modeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Text Mode", "HTML Mode", "Image Mode" }));
modeComboBox.setEnabled(false);
modeComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
modeComboBoxActionPerformed(evt);
}
});
editorJLabel.setText("Text Editor");
editorJLabel.setEnabled(false);
editorTextPane.setContentType("text/html"); // NOI18N
editorTextPane.setText("<html>\r\n <head>\r\n\r\n </head>\r\n <body>\r\n <p style=\"margin-top: 0\">\r\n \rwatermark\n </p>\r\n </body>\r\n</html>\r\n");
editorTextPane.setToolTipText("");
editorTextPane.setEnabled(false);
editorTextPane.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
editorTextPaneKeyPressed(evt);
}
public void keyTyped(java.awt.event.KeyEvent evt) {
editorTextPaneKeyTyped(evt);
}
});
jScrollPane2.setViewportView(editorTextPane);
jButton2.setText("...");
jButton2.setEnabled(false);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
watermarkImageText.setEnabled(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(watermarkImageText)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(editorJLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(modeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton10, jButton9});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton10)
.addComponent(modeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton9)
.addComponent(editorJLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(watermarkImageText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
rowsSlidder.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
rowsSlidder.setEnabled(false);
patternComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Single", "Tiled" }));
patternComboBox.setEnabled(false);
patternComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
patternComboBoxItemStateChanged(evt);
}
});
jLabel3.setText(bundle.getString("WatermarkJPanel.jLabel3.text")); // NOI18N
jLabel3.setEnabled(false);
jLabel2.setText(bundle.getString("WatermarkJPanel.jLabel2.text")); // NOI18N
jLabel2.setEnabled(false);
coloumnsSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
coloumnsSpinner.setEnabled(false);
jLabel8.setText(bundle.getString("WatermarkJPanel.jLabel8.text")); // NOI18N
jLabel8.setEnabled(false);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(patternComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rowsSlidder, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(coloumnsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel2, jLabel3});
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(patternComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rowsSlidder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(coloumnsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addContainerGap())
);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jSplitPane1.setRightComponent(jPanel2);
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()
.addComponent(watermarkEnableCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(77, 77, 77)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel10});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(watermarkEnableCheckBox)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10)
.addComponent(jLabel1))))
.addGap(6, 6, 6)
.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void watermarkEnableCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_watermarkEnableCheckBoxItemStateChanged
watermarkTabEnable();
}//GEN-LAST:event_watermarkEnableCheckBoxItemStateChanged
private void rotateSliderMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rotateSliderMouseExited
jLabel1.setForeground(Color.BLACK);
}//GEN-LAST:event_rotateSliderMouseExited
private void rotateSliderMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rotateSliderMouseEntered
jLabel1.setForeground(Color.RED);
}//GEN-LAST:event_rotateSliderMouseEntered
private void rotateSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_rotateSliderStateChanged
jPlacer1.setAngle(rotateSlider.getValue());
jLabel1.setText("Rotate: " + rotateSlider.getValue() + "°");
}//GEN-LAST:event_rotateSliderStateChanged
private void opacitySliderMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_opacitySliderMouseExited
jLabel10.setForeground(Color.BLACK);
}//GEN-LAST:event_opacitySliderMouseExited
private void opacitySliderMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_opacitySliderMouseEntered
jLabel10.setForeground(Color.RED);
}//GEN-LAST:event_opacitySliderMouseEntered
private void opacitySliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_opacitySliderStateChanged
jLabel10.setText(String.format("Opacity: %s%%", opacitySlider.getValue()));
jPlacer1.setAlpha(opacitySlider.getValue());
}//GEN-LAST:event_opacitySliderStateChanged
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
color = JColorChooser.showDialog(null, "Choose Color", Color.BLACK);
editorTextPane.setForeground(color);
jPlacer1.setColor(color);
}//GEN-LAST:event_jButton9ActionPerformed
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
if (jFontChooser1.showDialog(this) != JFontChooser.OK_OPTION) {
return;
}
editorTextPane.setFont(jFontChooser1.getSelectedFont());
currentFont = jFontChooser1.getSelectedFont();
}//GEN-LAST:event_jButton10ActionPerformed
private void patternComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_patternComboBoxItemStateChanged
watermarkTabEnable();
}//GEN-LAST:event_patternComboBoxItemStateChanged
private void editorTextPaneKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editorTextPaneKeyPressed
}//GEN-LAST:event_editorTextPaneKeyPressed
private void modeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modeComboBoxActionPerformed
setEditorMode();
editorTextPane.setText(plainText);
}//GEN-LAST:event_modeComboBoxActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
JFileChooser chooser = new JFileChooser(BricUI.lastOpenedDirectory);
Utils.setFileChooserProperties(chooser);
if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
return;
}
watermarkImageText.setText(chooser.getSelectedFile().getPath());
BricUI.lastOpenedDirectory = chooser.getSelectedFile().getPath();
}//GEN-LAST:event_jButton2ActionPerformed
private void editorTextPaneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editorTextPaneKeyTyped
}//GEN-LAST:event_editorTextPaneKeyTyped
private void setEditorMode(){
plainText = editorTextPane.getText();
if(modeComboBox.getSelectedIndex() == 0){
jScrollPane2.setVisible(true);
watermarkImageText.setVisible(false);
jButton2.setVisible(false);
jButton10.setVisible(true);
jButton9.setVisible(true);
editorJLabel.setText("Text Editor");
editorTextPane.setContentType("text/html");
editorTextPane.setFont(currentFont);
editorTextPane.setForeground(color);
} else if(modeComboBox.getSelectedIndex() == 1) {
jButton10.setVisible(false);
jButton9.setVisible(false);
jScrollPane2.setVisible(true);
watermarkImageText.setVisible(false);
jButton2.setVisible(false);
editorJLabel.setText("HTML Editor");
editorTextPane.setContentType("text/plain");
editorTextPane.setFont(defaultFont);
editorTextPane.setForeground(Color.BLACK);
} else {
jButton10.setVisible(false);
jButton9.setVisible(false);
jScrollPane2.setVisible(false);
watermarkImageText.setVisible(true);
jButton2.setVisible(true);
editorJLabel.setText("Image Mode");
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JSpinner coloumnsSpinner;
private javax.swing.JLabel editorJLabel;
private javax.swing.JTextPane editorTextPane;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton9;
private say.swing.JFontChooser jFontChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private org.bric.gui.watermark.JPlacer jPlacer1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JComboBox modeComboBox;
private javax.swing.JSlider opacitySlider;
private javax.swing.JComboBox patternComboBox;
private javax.swing.JSlider rotateSlider;
private javax.swing.JSpinner rowsSlidder;
private javax.swing.JCheckBox watermarkEnableCheckBox;
private javax.swing.JTextField watermarkImageText;
// End of variables declaration//GEN-END:variables
@Override
public WatermarkParameters getImageEditParameters() {
WatermarkParameters watermarkParameters = new WatermarkParameters();
watermarkParameters.setEnabled(watermarkEnableCheckBox.isSelected());
watermarkParameters.setWatermarkText(editorTextPane.getText());
watermarkParameters.setPattern(patternComboBox.getSelectedIndex());
watermarkParameters.setTiledRows((Integer) rowsSlidder.getValue());
watermarkParameters.setTiledColumns((Integer) coloumnsSpinner.getValue());
watermarkParameters.setFont(jFontChooser1.getSelectedFont());
watermarkParameters.setColor(jPlacer1.getColor());
watermarkParameters.setComponentWidth(jPlacer1.getWidth());
watermarkParameters.setComponentHeight(jPlacer1.getHeight());
watermarkParameters.setCenterX(jPlacer1.getLabelCenterX());
watermarkParameters.setCenterY(jPlacer1.getLabelCenterY());
BufferedImage watermarkImage = computeWatermarkBufferedImage();
watermarkParameters.setWatermarkImage(watermarkImage);
watermarkParameters.setWatermarkWidth(watermarkImage.getWidth());
watermarkParameters.setWatermarkHeight(watermarkImage.getHeight());
return watermarkParameters;
}
private BufferedImage computeWatermarkBufferedImage(){
CellRendererPane crp = new CellRendererPane();
BufferedImage watermark;
if(modeComboBox.getSelectedIndex() != 2){
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText(editorTextPane.getText());
if(modeComboBox.getSelectedIndex() == 0){
pane.setForeground(editorTextPane.getForeground());
pane.setFont(editorTextPane.getFont());
}
pane.setBackground(new Color(255, 255, 255, 0));
Dimension dim = pane.getPreferredSize();
watermark = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = watermark.createGraphics();
crp.paintComponent(g, pane, null, 0, 0, dim.width, dim.height);
g.setComposite(makeComposite(jPlacer1.getAlpha()));
g.dispose();
} else {
watermark = Utils.loadImage(watermarkImageText.getText());
}
float angle = (float) (((360-rotateSlider.getValue())*Math.PI)/180);
RotateFilter rotateFilter = new RotateFilter(angle);
return rotateFilter.filter(watermark, null);
}
private AlphaComposite makeComposite(float alpha) {
int type = AlphaComposite.SRC_OVER;
return (AlphaComposite.getInstance(type, alpha));
}
private void watermarkTabEnable() {
boolean enable = watermarkEnableCheckBox.isSelected();
boolean tiled = patternComboBox.getSelectedIndex() == 1;
jPlacer1.setEnabled(enable);
jLabel8.setEnabled(enable);
patternComboBox.setEnabled(enable);
jLabel10.setEnabled(enable);
opacitySlider.setEnabled(enable);
jLabel2.setEnabled(enable & tiled);
rowsSlidder.setEnabled(enable & tiled);
jLabel3.setEnabled(enable & tiled);
coloumnsSpinner.setEnabled(enable & tiled);
jLabel1.setEnabled(enable);
rotateSlider.setEnabled(enable);
for(Component comp : jPanel1.getComponents()){
comp.setEnabled(enable);
}
editorTextPane.setEnabled(enable);
}
public String getColoumnsSpinner() {
return coloumnsSpinner.getValue().toString();
}
public void setColoumnsSpinner(int coloumnsSpinner) {
this.coloumnsSpinner.getModel().setValue(coloumnsSpinner);
}
public String getEditorTextPane() {
return editorTextPane.getText();
}
public void setEditorTextPane(String editorTextPane) {
this.editorTextPane.setText(editorTextPane);
}
public int getModeComboBox() {
return modeComboBox.getSelectedIndex();
}
public void setModeComboBox(int modeComboBox) {
this.modeComboBox.setSelectedIndex(modeComboBox);
}
public String getOpacitySlider() {
return String.valueOf(opacitySlider.getValue());
}
public void setOpacitySlider(int opacitySlider) {
this.opacitySlider.getModel().setValue(opacitySlider);
}
public int getPatternComboBox() {
return patternComboBox.getSelectedIndex();
}
public void setPatternComboBox(int patternComboBox) {
this.patternComboBox.setSelectedIndex(patternComboBox);
}
public String getRowsSlidder() {
return String.valueOf(rowsSlidder.getValue());
}
public void setRowsSlider(int rowsSlidder) {
this.rowsSlidder.getModel().setValue(rowsSlidder);
}
public boolean getWatermarkEnableCheckBox() {
return watermarkEnableCheckBox.isSelected();
}
public void setWatermarkEnableCheckBox(boolean watermarkEnableCheckBox) {
this.watermarkEnableCheckBox.setSelected(watermarkEnableCheckBox);
}
public String getWatermarkImageText() {
return watermarkImageText.getText();
}
public void setWatermarkImageText(String watermarkImageText) {
this.watermarkImageText.setText(watermarkImageText);
}
}