Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 50 → Rev 64

/trunk/JavaTerminal/src/com/rm5248/terminal/JavaTerminal.java
118,6 → 118,12
portStatus.setLineState( state );
}
});
SerialLineState newState = new SerialLineState();
newState.dataTerminalReady = true;
newState.requestToSend = true;
thePort.setSerialLineState( newState );
 
try {
portStatus.setLineState( thePort.getSerialLineState() );
127,7 → 133,7
}
 
updatePortInformation();
 
/*new Thread( new Runnable() {
 
@Override
219,7 → 225,7
@Override
public void actionPerformed(ActionEvent arg0) {
JFrame settingFrame = new JFrame( "Configuration" );
 
JPanel mainPanel = new JPanel();
 
JPanel configPanel = new JPanel( new GridLayout( 4, 3 ) );
229,14 → 235,18
configPanel.add( createDialogLabel( "Parity:" ) );
final JComboBox port = new JComboBox();
port.setEditable( true );
port.addItem( thePort.getPortName() );
if( thePort != null ){
port.addItem( thePort.getPortName() );
}
configPanel.add( port );
final JComboBox speed = new JComboBox();
BaudRate[] values = BaudRate.values();
for( int x = 0; x < values.length; x++ ){
speed.addItem( values[ x ] );
if( thePort.getBaudRate() == values[ x ] ){
speed.setSelectedIndex( x );
if( thePort != null ){
if( thePort.getBaudRate() == values[ x ] ){
speed.setSelectedIndex( x );
}
}
}
speed.setEditable( false );
245,8 → 255,10
Parity[] parityValues = Parity.values();
for( int x = 0; x < parityValues.length; x++ ){
parity.addItem( parityValues[ x ] );
if( thePort.getParity() == parityValues[ x ] ){
parity.setSelectedIndex( x );
if( thePort != null ){
if( thePort.getParity() == parityValues[ x ] ){
parity.setSelectedIndex( x );
}
}
}
parity.setEditable( false );
258,8 → 270,10
DataBits[] dataValues = DataBits.values();
for( int x = 0; x < dataValues.length; x++ ){
bits.addItem( dataValues[ x ] );
if( thePort.getDataBits() == dataValues[ x ] ){
bits.setSelectedIndex( x );
if( thePort != null ){
if( thePort.getDataBits() == dataValues[ x ] ){
bits.setSelectedIndex( x );
}
}
}
configPanel.add( bits );
267,8 → 281,10
StopBits[] stopValues = StopBits.values();
for( int x = 0; x < stopValues.length; x++ ){
stopbits.addItem( stopValues[ x ] );
if( thePort.getStopBits() == stopValues[ x ] ){
stopbits.setSelectedIndex( x );
if( thePort != null ){
if( thePort.getStopBits() == stopValues[ x ] ){
stopbits.setSelectedIndex( x );
}
}
}
configPanel.add( stopbits );
276,21 → 292,25
FlowControl[] flowValues = FlowControl.values();
for( int x = 0; x < flowValues.length; x++ ){
flow.addItem( flowValues[ x ] );
if( thePort.getFlowControl() == flowValues[ x ] ){
flow.setSelectedIndex( x );
if( thePort != null ){
if( thePort.getFlowControl() == flowValues[ x ] ){
flow.setSelectedIndex( x );
}
}
}
configPanel.add( flow );
 
JPanel bottomPanel = new JPanel();
JButton applyButton = new JButton( "Apply" );
applyButton.addActionListener( new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
if( !thePort.getPortName().equals( port.getName() ) ){
thePort.close();
if( thePort == null || !thePort.getPortName().equals( port.getSelectedItem().toString() ) ){
if( thePort != null ){
thePort.close();
}
 
try {
thePort = new SerialPort( port.getName(), true );
} catch (NoSuchPortException e1) {
300,7 → 320,7
JOptionPane.showMessageDialog( null, "ERROR: " + port.getName() + " is not a serial port!", "Error", JOptionPane.ERROR_MESSAGE );
return;
}
 
portInput = thePort.getInputStream();
portOutput = thePort.getOutputStream();
 
311,7 → 331,7
ex.printStackTrace();
}
}
 
BaudRate[] values = BaudRate.values();
for( int x = 0; x < values.length; x++ ){
if( values[ x ].toString().equals( speed.getSelectedItem().toString() ) ){
318,7 → 338,7
thePort.setBaudRate( values[ x ] );
}
}
 
Parity[] parityValues = Parity.values();
for( int x = 0; x < parityValues.length; x++ ){
if( parityValues[ x ].toString().equals( parity.getSelectedItem().toString() ) ){
325,7 → 345,7
thePort.setParity( parityValues[ x ] );
}
}
 
DataBits[] dataValues = DataBits.values();
for( int x = 0; x < dataValues.length; x++ ){
if( dataValues[ x ].equals( bits.getSelectedItem() ) ){
332,7 → 352,7
thePort.setDataSize( dataValues[ x ] );
}
}
 
StopBits[] stopValues = StopBits.values();
for( int x = 0; x < stopValues.length; x++ ){
if( stopValues[ x ].equals( stopbits.getSelectedItem() ) ){
339,7 → 359,7
thePort.setStopBits( stopValues[ x ] );
}
}
 
FlowControl[] flowValues = FlowControl.values();
for( int x = 0; x < flowValues.length; x++ ){
if( flowValues[ x ].equals( flow.getSelectedItem() ) ){
346,7 → 366,7
thePort.setFlowControl( flowValues[ x ] );
}
}
 
updatePortInformation();
}
});
429,7 → 449,7
JMenuItem toggleRTS = new JMenuItem( "Toggle RTS" );
toggleRTS.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_F8, KeyEvent.ALT_DOWN_MASK & KeyEvent.CTRL_DOWN_MASK ) );
toggleRTS.addActionListener( new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent evt) {
try{
473,6 → 493,22
view.add( sendHexData );
menuBar.add( view );
 
JMenu help = new JMenu( "Help" );
help.setMnemonic( KeyEvent.VK_H );
JMenuItem about = new JMenuItem( "About" );
about.addActionListener( new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog( null, "JavaTerminal 0.X\n" +
"From programming.rm5248.com\n\n\n" +
"Java Serial version: " + String.format( "%d.%d", SerialPort.getMajorVersion(), SerialPort.getMinorVersion() ) + "\n"+
"Java Serial Native Version: " + String.format( "%d.%d", SerialPort.getMajorNativeVersion(), SerialPort.getMinorNativeVersion() ) + "\n", "About", JOptionPane.INFORMATION_MESSAGE );
}
});
help.add( about );
menuBar.add( help );
 
//add everything to the frame
theFrame.setJMenuBar( menuBar );
theFrame.add( mainPanel );
487,7 → 523,7
width = font.charWidth( 'a' ) * 85;
 
theFrame.setSize( width, 600 );
 
updatePortInformation();
}
 
746,7 → 782,7
@Override
public void keyTyped(KeyEvent event) {
String toWrite = "";
 
if( portOutput == null ){
return;
}
798,7 → 834,7
int dataBits = 0;
char parity = 'N';
int stop = 0;
 
if( thePort == null ){
portInfoLeft.setText( "No open port" );
return;