Skip to content

Commit

Permalink
Signed-off-by: ayushmaanbhav <[email protected]>
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmaanbhav committed Sep 26, 2013
0 parents commit d5c0623
Show file tree
Hide file tree
Showing 40 changed files with 4,901 additions and 0 deletions.
417 changes: 417 additions & 0 deletions src/client/BackgroundAnimation.java

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions src/client/BroadcastClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package client;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.text.*;
public class BroadcastClient extends Thread
{
StringBuffer sb;
DecimalFormat twoDForm;
ShareValuesChangeListener svcl;
public BroadcastClient(StringBuffer s)
{
sb=s;
svcl=null;
Companies.comp=new ArrayList<Company>();
twoDForm = new DecimalFormat("#.##");
}
public void run(String poo)
{
try{
StringBuffer fin=new StringBuffer();
try{
final String rec[]=poo.split("=");
final String mtr[]=rec[0].split(";");
final String str[]=rec[1].split(";");
final List<Company> clist=new ArrayList<Company>();
for(int i=0;i<str.length;i++)
{
String str2[]=str[i].split(":");
fin.append(str2[1]);
fin.append(" : ");
double a=Double.parseDouble(str2[2]);
fin.append(twoDForm.format(a));
double b=Double.parseDouble(str2[3]);
double h=Double.parseDouble(str2[4]);
double l=Double.parseDouble(str2[5]);
clist.add(new Company(new String(str2[1]),a,b,h,l,Integer.parseInt(new String(str2[0]))));
if(a>b)
fin.append("\u25b2"); //<font size="3" color="red">This is some text!</font>
else if(a<b)
fin.append("\u25bc");
double c=a-b;
if(c>0.0)
fin.append(twoDForm.format(c));
else if(c<0.0)
fin.append(twoDForm.format(-c));
fin.append(" ");
}
sb.delete(0,sb.length());
sb.append(fin.toString());
SwingUtilities.invokeLater(new Runnable(){
public void run()
{
try{
if(Main.imglabel2!=null)
Main.imglabel2.setText("<html><pre><font color=\"white\">Sensex: "+mtr[1]+"<br/>Time Left: "+mtr[0]+"</font></pre></html>");
}catch(Exception bb){bb.printStackTrace();}
try{
svcl.valuesChanged();
for(int i=0;i<clist.size();i++)
{
Companies.updateValues(clist.get(i).id,clist.get(i).name,clist.get(i).mktvalue,clist.get(i).inivalue,clist.get(i).high,clist.get(i).low);
}
}catch(Exception e){}
}
});
}catch(Exception mm){}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
225 changes: 225 additions & 0 deletions src/client/ButtonColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
package client;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;

/**
* The ButtonColumn class provides a renderer and an editor that looks like a
* JButton. The renderer and editor will then be used for a specified column
* in the table. The TableModel will contain the String to be displayed on
* the button.
*
* The button can be invoked by a mouse click or by pressing the space bar
* when the cell has focus. Optionally a mnemonic can be set to invoke the
* button. When the button is invoked the provided Action is invoked. The
* source of the Action will be the table. The action command will contain
* the model row number of the button that was clicked.
*
*/
public class ButtonColumn extends AbstractCellEditor
implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener
{
private JTable table;
private Action action;
private int mnemonic;
private Border originalBorder;
private Border focusBorder;

private JButton renderButton;
private JButton editButton;
private Object editorValue;
private boolean isButtonColumnEditor;

/**
* Create the ButtonColumn to be used as a renderer and editor. The
* renderer and editor will automatically be installed on the TableColumn
* of the specified column.
*
* @param table the table containing the button renderer/editor
* @param action the Action to be invoked when the button is invoked
* @param column the column to which the button renderer/editor is added
*/
public ButtonColumn(JTable table, Action action, int column)
{
this.table = table;
this.action = action;

renderButton = new JButton();
editButton = new JButton();
editButton.setFocusPainted( false );
editButton.addActionListener( this );
originalBorder = editButton.getBorder();
setFocusBorder( new LineBorder(Color.GRAY) );

TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(column).setCellRenderer( this );
columnModel.getColumn(column).setCellEditor( this );
table.addMouseListener( this );
}


/**
* Get foreground color of the button when the cell has focus
*
* @return the foreground color
*/
public Border getFocusBorder()
{
return focusBorder;
}

/**
* The foreground color of the button when the cell has focus
*
* @param focusBorder the foreground color
*/
public void setFocusBorder(Border focusBorder)
{
this.focusBorder = focusBorder;
editButton.setBorder( focusBorder );
}

public int getMnemonic()
{
return mnemonic;
}

/**
* The mnemonic to activate the button when the cell has focus
*
* @param mnemonic the mnemonic
*/
public void setMnemonic(int mnemonic)
{
this.mnemonic = mnemonic;
renderButton.setMnemonic(mnemonic);
editButton.setMnemonic(mnemonic);
}

@Override
public Component getTableCellEditorComponent(
JTable table, Object value, boolean isSelected, int row, int column)
{
if (value == null)
{
editButton.setText( "" );
editButton.setIcon( null );
}
else if (value instanceof Icon)
{
editButton.setText( "" );
editButton.setIcon( (Icon)value );
}
else
{
editButton.setText( value.toString() );
editButton.setIcon( null );
}

this.editorValue = value;
return editButton;
}

@Override
public Object getCellEditorValue()
{
return editorValue;
}

//
// Implement TableCellRenderer interface
//
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
if (isSelected)
{
renderButton.setForeground(table.getSelectionForeground());
renderButton.setBackground(table.getSelectionBackground());
}
else
{
renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager.getColor("Button.background"));
}

if (hasFocus)
{
renderButton.setBorder( focusBorder );
}
else
{
renderButton.setBorder( originalBorder );
}

// renderButton.setText( (value == null) ? "" : value.toString() );
if (value == null)
{
renderButton.setText( "" );
renderButton.setIcon( null );
}
else if (value instanceof Icon)
{
renderButton.setText( "" );
renderButton.setIcon( (Icon)value );
}
else
{
renderButton.setText( value.toString() );
renderButton.setIcon( null );
}

return renderButton;
}

//
// Implement ActionListener interface
//
/*
* The button has been pressed. Stop editing and invoke the custom Action
*/
public void actionPerformed(ActionEvent e)
{
int row = table.convertRowIndexToModel( table.getEditingRow() );
fireEditingStopped();

// Invoke the Action

ActionEvent event = new ActionEvent(
table,
ActionEvent.ACTION_PERFORMED,
"" + row);
action.actionPerformed(event);
}

//
// Implement MouseListener interface
//
/*
* When the mouse is pressed the editor is invoked. If you then then drag
* the mouse to another cell before releasing it, the editor is still
* active. Make sure editing is stopped when the mouse is released.
*/
public void mousePressed(MouseEvent e)
{
if (table.isEditing()
&& table.getCellEditor() == this)
isButtonColumnEditor = true;
}

public void mouseReleased(MouseEvent e)
{
if (isButtonColumnEditor
&& table.isEditing())
table.getCellEditor().stopCellEditing();

isButtonColumnEditor = false;
}

public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
Loading

0 comments on commit d5c0623

Please sign in to comment.