Commit e7eca896 authored by Darwin's avatar Darwin
Browse files

send

parents f1d3bf7f 805d5733
......@@ -3,9 +3,18 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<<<<<<< HEAD
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TradeboxTableModel.java</file>
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
=======
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/ButtonRenderer.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/ButtonEditor.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MapTableModel.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TradeboxTableModel.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/JTableButtonMouseListener.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
>>>>>>> 805d57339903105b67427132e4fc49fb767c36b1
</group>
</open-files>
</project-private>
package tcpclient;
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.BLUE) );
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) {}
}
package tcpclient;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class LoginPanel extends JPanel {
private Image img;
public LoginPanel() {
// load the background image
try {
img = ImageIO.read(getClass().getResource("images/login.png"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}
}
......@@ -287,7 +287,7 @@
</Group>
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
<Component id="connectButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="246" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
......@@ -345,21 +345,28 @@
<Component id="loginButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="161" max="-2" attributes="0"/>
<Component id="loginLabel" min="-2" pref="60" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="52" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="usernameLoginLabel" min="-2" max="-2" attributes="0"/>
<Component id="passwordLoginLabel" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="161" max="-2" attributes="0"/>
<Component id="loginLabel" min="-2" pref="60" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="175" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="110" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="75" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="passwordLoginField" max="32767" attributes="0"/>
<Component id="usernameLoginTextField" min="-2" pref="151" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace pref="361" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
......@@ -369,14 +376,14 @@
<EmptySpace min="-2" pref="90" max="-2" attributes="0"/>
<Component id="loginLabel" min="-2" pref="25" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="usernameLoginTextField" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="usernameLoginLabel" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="usernameLoginTextField" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="passwordLoginLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="passwordLoginField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
<Component id="loginButton" min="-2" max="-2" attributes="0"/>
......@@ -391,16 +398,6 @@
<Property name="text" type="java.lang.String" value="LOGIN"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="usernameLoginLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Username"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="passwordLoginLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Password"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="usernameLoginTextField">
<Properties>
<Property name="text" type="java.lang.String" value="ayam"/>
......@@ -422,6 +419,16 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loginButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Username"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="text" type="java.lang.String" value="Password"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="registerPanel">
......@@ -1323,6 +1330,7 @@
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0"/>
</Property>
<Property name="rowSelectionAllowed" type="boolean" value="false"/>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
......
This diff is collapsed.
......@@ -572,7 +572,7 @@ public class TCPClient {
closeConnection();
return responseJSON;
}
public JSONObject accept(String token,String offer_token) throws Exception
{
openConnection();
......@@ -626,7 +626,7 @@ public class TCPClient {
return responseJSON;
}
public JSONObject fetchitem(String token, String offer_token) throws Exception
public JSONObject fetchItem(String offer_token) throws Exception
{
openConnection();
System.out.println("Fetch item");
......@@ -653,7 +653,7 @@ public class TCPClient {
return responseJSON;
}
public JSONObject canceloffer(String token, String offer_token) throws Exception
public JSONObject cancelOffer(String offer_token) throws Exception
{
openConnection();
System.out.println("Cancel Offer");
......@@ -684,107 +684,6 @@ public class TCPClient {
{
TCPClient client = new TCPClient("localhost", 6789);
// do {
// BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
// DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
// BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
//
// // Test Register
// do {
// System.out.println("Register");
// System.out.print("Username : "); username = inFromUser.readLine();
// System.out.print("Password : "); password = inFromUser.readLine();
// String toSend = registerJSON(username, password).toString();
//
// outToServer.write(toSend.getBytes("UTF-8"));
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Registration Success!");
// } else if(responseStatus.equalsIgnoreCase("fail")) {
// String reason = responseJSON.getString("description");
// System.out.println("Registration fail, " + reason);
// }
// System.out.println();
// } while(!responseStatus.equalsIgnoreCase("ok"));
//
// // Test Login
// do {
// System.out.println("Login");
// System.out.print("Username : "); username = inFromUser.readLine();
// System.out.print("Password : "); password = inFromUser.readLine();
// String toSend = loginJSON(username, password).toString();
//
// outToServer.write(toSend.getBytes("UTF-8"));
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Login Success!");
// System.out.println("Token : " + responseJSON.getString("token"));
// token = responseJSON.getString("token");
// } else if(responseStatus.equalsIgnoreCase("fail")) {
// String reason = responseJSON.getString("description");
// System.out.println("Login fail, " + reason);
// }
// System.out.println();
// } while(!responseStatus.equalsIgnoreCase("ok"));
//
// // Test Inventory
// do {
// do {
// System.out.print("Command : "); command = inFromUser.readLine();
// } while(!command.equalsIgnoreCase("inventory") && !command.equalsIgnoreCase("exit"));
//
// if(command.equalsIgnoreCase("inventory")) {
// String toSend = inventoryJSON(token).toString();
//
// outToServer.write(toSend.getBytes("UTF-8"));
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Your Inventory : ");
// List inventory = new ArrayList<Integer>();
// JSONArray jsonarray = responseJSON.getJSONArray("inventory");
// for(int i=0; i<jsonarray.length(); i++) {
// inventory.add(jsonarray.getInt(i));
// }
// printItemList(inventory);
// } else if(responseStatus.equalsIgnoreCase("error")) {
// System.out.println("Error opening inventory");
// }
// System.out.println();
// }
// } while(!command.equalsIgnoreCase("exit"));
//
// // Test Mix Item
// do {
// System.out.println("Mix Item");
// System.out.print("Item 1 ID : "); int id1 = Integer.parseInt(inFromUser.readLine());
// System.out.print("Item 2 ID : "); int id2 = Integer.parseInt(inFromUser.readLine());
// String toSend = mixitemJSON(token, id1, id2).toString();
//
// outToServer.write(toSend.getBytes("UTF-8"));
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Mix item succeded, your new item id : " + responseJSON.getInt("item"));
// } else if(responseStatus.equalsIgnoreCase("fail")) {
// System.out.println("Failed to mix item, " + responseJSON.getString("description"));
// } else if(responseStatus.equalsIgnoreCase("error")) {
// System.out.println("Error mixing item");
// }
// System.out.println();
// } while(true);
// } while(!command.equalsIgnoreCase("exit"));
//
JSONObject response = client.login("ayam", "ayam");
if(response.getString("status").equals("ok")) {
client.token = response.getString("token");
......
package tcpclient;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
public class TradeboxTableModel extends AbstractTableModel {
public class TradeboxTableModel extends DefaultTableModel {
private final String[] header={"Offered Item", "Number Offered", "Demanded Item", "Number Demanded", "Act"};
private final Class[] m_colTypes = { ImageIcon.class, Integer.class, ImageIcon.class, Integer.class, JButton.class };
......@@ -49,7 +52,30 @@ public class TradeboxTableModel extends AbstractTableModel {
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return data[rowIndex][columnIndex];
switch (columnIndex) {
/*Adding button and creating click listener*/
// case 4: System.out.println(data[rowIndex][columnIndex].getClass().getName());
// final JButton button = new JButton(data[rowIndex][columnIndex].toString());
// button.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// System.out.println("haha");
// JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(button),
// "Button clicked for row "+rowIndex);
// }
// });
// return button;
default: return data[rowIndex][columnIndex];
}
// switch(columnIndex)
// {
// case 4:
// return ;
// default:
// return data[rowIndex][columnIndex];
// }
}
public void setValueAt(Object value, int row, int col) {
......@@ -59,6 +85,7 @@ public class TradeboxTableModel extends AbstractTableModel {
@Override
public Class<?> getColumnClass(int column) {
switch (column) {
case 0:
return ImageIcon.class;
......
#Wed, 22 Apr 2015 16:28:23 +0700
#Fri, 24 Apr 2015 15:40:37 +0700
C\:\\Users\\Stephen\\Documents\\NetBeansProjects\\TubesSister\\src\\server=
......@@ -15,6 +15,7 @@ javac.debug=true
javadoc.preview=true
<<<<<<< HEAD
<<<<<<< HEAD
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
=======
<<<<<<< HEAD
......@@ -41,3 +42,31 @@ user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.pro
=======
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
>>>>>>> 5c393c17c0f1ef1dd5ee2823322f7f8ff51533ad
=======
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
=======
<<<<<<< HEAD
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties