whiteboard plugin

cusax-fix
Yana Stamcheva 18 years ago
parent adfe51be7c
commit 0dc7be20d2

@ -0,0 +1,175 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.whiteboard.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.java.sip.communicator.plugin.whiteboard.*;
import net.java.sip.communicator.service.protocol.*;
/**
* The dialog that pops up when a chat room invitation is received.
*
* @author Yana Stamcheva
*/
public class InvitationReceivedDialog
extends JDialog
implements ActionListener
{
private JTextArea infoTextArea = new JTextArea();
private JTextArea invitationReasonTextArea = new JTextArea();
private JPanel reasonPanel = new JPanel(new BorderLayout());
private JLabel reasonLabel = new JLabel(
Resources.getString("reason") + ": ");
private JTextField reasonField = new JTextField();
private JPanel dataPanel = new JPanel(new BorderLayout(10, 10));
private JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
private JButton acceptButton = new JButton(Resources.getString("accept"));
private JButton rejectButton = new JButton(Resources.getString("reject"));
private JButton ignoreButton = new JButton(Resources.getString("ignore"));
private JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
private JPanel northPanel = new JPanel(new BorderLayout(10, 10));
private JLabel iconLabel = new JLabel(Resources.getImage("inviteIcon"));
private String title
= Resources.getString("invitationReceived");
/**
* The <tt>ChatRoomInvitation</tt> for which this dialog is.
*/
private WhiteboardInvitation invitation;
/**
* The <tt>MultiUserChatManager</tt> is the one that deals with invitation
* events.
*/
private WhiteboardSessionManager whiteboardManager;
/**
* The operation set that would handle the rejection if the user choose to
* reject the invitation.
*/
private OperationSetWhiteboarding whiteboardOpSet;
/**
* Constructs the <tt>ChatInviteDialog</tt>.
*
* @param whiteboardManager the <tt>WhiteboardSessionManager</tt> is the one
* that deals with invitation events
* @param whiteboardOpSet the operation set that would handle the
* rejection if the user choose to reject the invitation
* @param invitation the invitation that this dialog represents
*/
public InvitationReceivedDialog (WhiteboardSessionManager whiteboardManager,
OperationSetWhiteboarding whiteboardOpSet,
WhiteboardInvitation invitation)
{
this.whiteboardManager = whiteboardManager;
this.whiteboardOpSet = whiteboardOpSet;
this.invitation = invitation;
this.setModal(false);
this.setTitle(title);
this.mainPanel.setPreferredSize(new Dimension(400, 230));
infoTextArea.setText(
Resources.getString("invitationReceivedFormInfo",
new String[] { invitation.getInviter(),
invitation.getTargetWhiteboard()
.getWhiteboardID()}));
if(invitation.getReason() != null && invitation.getReason() != "")
{
invitationReasonTextArea.setText(invitation.getReason());
invitationReasonTextArea.setBorder(
BorderFactory.createTitledBorder(
Resources.getString("invitation")));
this.dataPanel.add(invitationReasonTextArea, BorderLayout.CENTER);
}
this.infoTextArea.setFont(
infoTextArea.getFont().deriveFont(Font.BOLD, 12f));
this.infoTextArea.setLineWrap(true);
this.infoTextArea.setOpaque(false);
this.infoTextArea.setWrapStyleWord(true);
this.infoTextArea.setEditable(false);
this.northPanel.add(iconLabel, BorderLayout.WEST);
this.northPanel.add(infoTextArea, BorderLayout.CENTER);
this.reasonPanel.add(reasonLabel, BorderLayout.WEST);
this.reasonPanel.add(reasonField, BorderLayout.CENTER);
this.dataPanel.add(reasonPanel, BorderLayout.SOUTH);
this.acceptButton.addActionListener(this);
this.rejectButton.addActionListener(this);
this.ignoreButton.addActionListener(this);
this.buttonsPanel.add(acceptButton);
this.buttonsPanel.add(rejectButton);
this.buttonsPanel.add(ignoreButton);
this.getRootPane().setDefaultButton(acceptButton);
this.acceptButton.setMnemonic(Resources.getMnemonic("accept"));
this.rejectButton.setMnemonic(Resources.getMnemonic("reject"));
this.ignoreButton.setMnemonic(Resources.getMnemonic("ignore"));
this.mainPanel.setBorder(
BorderFactory.createEmptyBorder(15, 15, 15, 15));
this.mainPanel.add(northPanel, BorderLayout.NORTH);
this.mainPanel.add(dataPanel, BorderLayout.CENTER);
this.mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
this.getContentPane().add(mainPanel);
}
/**
* Handles the <tt>ActionEvent</tt> triggered when one user clicks
* on one of the buttons.
*/
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();
if (button.equals(acceptButton))
{
whiteboardManager.acceptInvitation(invitation);
}
else if (button.equals(rejectButton))
{
whiteboardManager.rejectInvitation(whiteboardOpSet,
invitation, reasonField.getText());
}
this.dispose();
}
protected void close(boolean isEscaped)
{}
}

@ -0,0 +1,91 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.whiteboard.gui;
import java.io.File;
import javax.swing.filechooser.FileFilter;
/**
* A simple file filter manager
*
* @author Julien Waechter
*/
public class WhiteboardFileFilter extends FileFilter {
/**
* file extension
*/
private String ext;
/**
* file description
*/
private String description;
/**
* WhiteboardFileFilter constructor
* @param ext extension
* @param description description
*/
public WhiteboardFileFilter (String ext, String description) {
this.ext = ext;
this.description = description;
}
/**
* Tests the specified file,
* returning true if the file is accepted, false otherwise.
* True is returned if the extension matches one of
* the file name extensions of this FileFilter,
* or the file is a directory.
* @param f file
* @return true if file is accepted
*/
public boolean accept (File f) {
if (f != null) {
if (f.isDirectory ()) {
return true;
}
String e = getExtension (f);
if (e != null && e.equals (ext)) {
return true;
}
}
return false;
}
/**
* The description of this filter. For example: "JPG and GIF Images"
* @return description
*/
public String getDescription () {
return description;
}
/**
* The description of this filter. For example: "JPG and GIF Images"
* @return description
*/
public String getExtension () {
return ext;
}
/**
* The extension of the file"
* @param f File
* @return file extension
*/
public String getExtension (File f) {
if (f != null) {
String filename = f.getName ();
int i = filename.lastIndexOf ('.');
if (i > 0 && i < filename.length () - 1) {
return filename.substring (i + 1).toLowerCase ();
}
}
return null;
}
}

@ -0,0 +1,296 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.whiteboard.gui;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import net.java.sip.communicator.plugin.whiteboard.gui.whiteboardshapes.*;
/**
* Panel for drawing shapes
*
* @author Julien Waechter
*/
public class WhiteboardPanel
extends javax.swing.JPanel
implements Printable
{
/**
* Shapes to display
*/
private List displayList = new CopyOnWriteArrayList();
/**
* Default grid space
*/
private int defaultGrid = 25;
private AffineTransform affineTrans;
/**
* True: display grid, false no grid.
*/
private boolean grid = false;
/**
* Parent WhiteboardFrame
*/
private WhiteboardFrame wf;
/**
* WhiteboardPanel constructor.
*
* @param displayList Shapes to display
* @param wf WhiteboardFrame
*/
public WhiteboardPanel(List displayList, WhiteboardFrame wf)
{
super();
this.wf = wf;
this.displayList = displayList;
affineTrans = new AffineTransform();
affineTrans.setToScale(1, 1);
setBackground(Color.white);
initComponents();
}
/**
* Method to draw/hide grid
*
* @param grid if true, draw grid
*/
public void drawGrid(boolean grid)
{
this.grid = grid;
}
/**
* Calls the UI delegate's paint method, if the UI delegate is non-<code>null</code>.
* We pass the delegate a copy of the <code>Graphics</code> object to
* protect the rest of the paint code from irrevocable changes (for example,
* <code>Graphics.translate</code>).
* <p>
* The passed in <code>Graphics</code> object might have a transform other
* than the identify transform installed on it. In this case, you might get
* unexpected results if you cumulatively apply another transform.
*
* @param g the <code>Graphics</code> object to protect
* @see #paint
* @see ComponentUI
*/
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (grid)
{
for (int x = 0; x < this.getWidth(); x += defaultGrid)
{
for (int y = 0; y < this.getHeight(); y += defaultGrid)
{
g.setColor(Color.LIGHT_GRAY);
g.fillOval(x, y, 2, 2);
}
}
}
WhiteboardShape s;
for (int i = 0; i < displayList.size(); i++)
{
s = (WhiteboardShape) displayList.get(i);
s.paint(g, affineTrans);
}
}
/**
* Prints the page at the specified index into the specified
* {@link Graphics} context in the specified format. A
* <code>PrinterJob</code> calls the <code>Printable</code> interface to
* request that a page be rendered into the context specified by
* <code>graphics</code>. The format of the page to be drawn is specified
* by <code>pageFormat</code>. The zero based index of the requested page
* is specified by <code>pageIndex</code>. If the requested page does not
* exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is
* returned. The <code>Graphics</code> class or subclass implements the
* {@link PrinterGraphics} interface to provide additional information. If
* the <code>Printable</code> object aborts the print job then it throws a
* {@link PrinterException}.
*
* @param graphics the context into which the page is drawn
* @param pageFormat the size and orientation of the page being drawn
* @param pageIndex the zero based index of the page to be drawn
* @return PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE
* if <code>pageIndex</code> specifies a non-existent page.
*/
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
{
return NO_SUCH_PAGE;
}
/**
* 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code
// ">//GEN-BEGIN:initComponents
private void initComponents()
{
popupMenu = new javax.swing.JPopupMenu();
copyPopupMenuItem = new javax.swing.JMenuItem();
pastePopupMenuItem = new javax.swing.JMenuItem();
colorPopupMenuItem = new javax.swing.JMenuItem();
propetiesPopupMenuItem = new javax.swing.JMenuItem();
deletePopupMenuItem = new javax.swing.JMenuItem();
copyPopupMenuItem.setText("Copy");
popupMenu.add(copyPopupMenuItem);
pastePopupMenuItem.setText("Paste");
popupMenu.add(pastePopupMenuItem);
colorPopupMenuItem.setText("Color");
colorPopupMenuItem
.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
colorPopupMenuItemActionPerformed(evt);
}
});
popupMenu.add(colorPopupMenuItem);
propetiesPopupMenuItem.setText("Properties");
popupMenu.add(propetiesPopupMenuItem);
deletePopupMenuItem.setText("Delete");
deletePopupMenuItem
.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
deletePopupMenuItemActionPerformed(evt);
}
});
popupMenu.add(deletePopupMenuItem);
setLayout(null);
addMouseListener(new java.awt.event.MouseAdapter()
{
public void mousePressed(java.awt.event.MouseEvent evt)
{
formMousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt)
{
formMouseReleased(evt);
}
});
}// </editor-fold>//GEN-END:initComponents
/**
* Invoked when an action occurs on the delete popup menu.
*
* @param evt
*/
private void deletePopupMenuItemActionPerformed(
java.awt.event.ActionEvent evt)
{// GEN-FIRST:event_deletePopupMenuItemActionPerformed
wf.deleteSelected();
}// GEN-LAST:event_deletePopupMenuItemActionPerformed
/**
* Invoked when an action occurs on the color popup menu.
*
* @param evt
*/
private void colorPopupMenuItemActionPerformed(
java.awt.event.ActionEvent evt)
{// GEN-FIRST:event_colorPopupMenuItemActionPerformed
wf.chooseColor();
}// GEN-LAST:event_colorPopupMenuItemActionPerformed
/**
* Invoked when a mouse button has been released on the WhiteboardPanel.
*
* @param evt
*/
private void formMouseReleased(java.awt.event.MouseEvent evt)
{// GEN-FIRST:event_formMouseReleased
checkPopupEvent(evt);
}// GEN-LAST:event_formMouseReleased
/**
* Invoked when a mouse button has been pressed on the WhiteboardPanel.
*
* @param evt
*/
private void formMousePressed(java.awt.event.MouseEvent evt)
{// GEN-FIRST:event_formMousePressed
checkPopupEvent(evt);
}// GEN-LAST:event_formMousePressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem colorPopupMenuItem;
private javax.swing.JMenuItem copyPopupMenuItem;
private javax.swing.JMenuItem deletePopupMenuItem;
private javax.swing.JMenuItem pastePopupMenuItem;
private javax.swing.JPopupMenu popupMenu;
private javax.swing.JMenuItem propetiesPopupMenuItem;
// End of variables declaration//GEN-END:variables
/**
* Manage popup event
*
* @param e MouseEvent
*/
private void checkPopupEvent(MouseEvent e)
{
copyPopupMenuItem.setEnabled(false);
pastePopupMenuItem.setEnabled(false);
colorPopupMenuItem.setEnabled(false);
propetiesPopupMenuItem.setEnabled(false);
deletePopupMenuItem.setEnabled(false);
if (e.isPopupTrigger())
{
if (wf.getSelectedShape() != null)
{
copyPopupMenuItem.setEnabled(true);
colorPopupMenuItem.setEnabled(true);
propetiesPopupMenuItem.setEnabled(true);
deletePopupMenuItem.setEnabled(true);
}
if (wf.getCopiedShape() != null)
{
pastePopupMenuItem.setEnabled(true);
}
if (e.getButton() == e.BUTTON3)
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
}
Loading…
Cancel
Save