diff --git a/src/common.js b/src/common.js index 2249bc5..9ace2d1 100644 --- a/src/common.js +++ b/src/common.js @@ -10,4 +10,8 @@ export function get_label_from_path(path) { export function get_label_from_final_data(data, index) { return data[index].label; +} + +export function get_use_from_final_data(data, index) { + return data[index].use; } \ No newline at end of file diff --git a/src/component/filelist.js b/src/component/filelist.js index d809984..ed94189 100644 --- a/src/component/filelist.js +++ b/src/component/filelist.js @@ -20,7 +20,6 @@ class FileList extends Component { } render() { - console.log("table", this.props); let render_file_list = ( @@ -40,6 +39,7 @@ class FileList extends Component { ID Filename Label + In-Use @@ -49,6 +49,7 @@ class FileList extends Component { {n.id} {n.path} {n.label} + {n.use} ); })} diff --git a/src/component/imageviewer.js b/src/component/imageviewer.js index 3583496..d3f156c 100644 --- a/src/component/imageviewer.js +++ b/src/component/imageviewer.js @@ -1,10 +1,16 @@ import React, {Component} from 'react'; -import {withStyles} from 'material-ui/styles'; import Paper from 'material-ui/Paper'; -import Typography from 'material-ui/Typography'; -import TextField from 'material-ui/TextField'; -import {get_filename_from_path, get_label_from_path, get_label_from_final_data} from '../common'; import Button from 'material-ui/Button'; +import Switch from 'material-ui/Switch'; +import TextField from 'material-ui/TextField'; +import Typography from 'material-ui/Typography'; + +import {withStyles} from 'material-ui/styles'; +import { + get_filename_from_path, + get_label_from_final_data, + get_use_from_final_data +} from '../common'; const styles = { card: { @@ -18,17 +24,16 @@ const styles = { class ImageViewer extends Component { constructor(props) { super(props); - console.log('init', this.state, this.props); this.state = { current_index: this.props.current_index, current_label: undefined }; this.handleChange = this.handleChange.bind(this); this.handleClick = this.handleClick.bind(this); + this.handleSwitch = this.handleSwitch.bind(this); } componentDidMount() { - console.log('did mount', this.state, this.props); this.setState({ current_index: this.props.current_index, current_label: undefined @@ -39,8 +44,11 @@ class ImageViewer extends Component { this.setState({current_label: event.target.value}); } + handleSwitch(event, checked) { + this.props.handleSwitchChange(checked, this.props.current_index); + } + handleClick() { - console.log(this.state, this.props); this.props.handleLabelChange(this.state.current_label, this.props.current_index); } @@ -80,6 +88,12 @@ class ImageViewer extends Component { onClick={this.handleClick}> Correct + + ); } diff --git a/src/mainview.js b/src/mainview.js index 1c98a37..05d0f3e 100644 --- a/src/mainview.js +++ b/src/mainview.js @@ -25,6 +25,7 @@ class MainView extends Component { this.listener = this.listener.bind(this); this.labelChange = this.labelChange.bind(this); + this.switchChange = this.switchChange.bind(this); ipcRenderer.on('action', this.listener); } @@ -45,7 +46,7 @@ class MainView extends Component { if (files) { let final_data = []; for (let i = 0; i < files.length; i++) { - final_data.push({id: i, path: files[i], label: get_label_from_path(files[i])}) + final_data.push({id: i, path: files[i], use: 1, label: get_label_from_path(files[i])}) } this.setState({final_data: final_data, current_index: 0}); document.title = "Labeling Tool - loaded new image files"; @@ -64,11 +65,17 @@ class MainView extends Component { }); if (ljson_file) { let json_info = JSON.parse(MainView.readText(ljson_file[0])); - console.log(json_info); this.current_file = ljson_file[0]; let current_index = json_info.meta.current_index; + if (json_info.data[0].use === undefined) { + json_info.data.map((t) => { + t.use = 1; + return t + }); + } + this.setState({final_data: json_info.data, current_index: current_index}); document.title = "Labeling Tool - " + ljson_file; } @@ -82,43 +89,36 @@ class MainView extends Component { if (this.state.final_data.length !== 0 && this.state.current_index - 1 >= 0) { this.setState({current_index: this.state.current_index - 1}) } - console.log("prev", this.state); break; case 'prev10': if (this.state.final_data.length !== 0 && this.state.current_index - 10 >= 0) { this.setState({current_index: this.state.current_index - 10}) } - console.log("prev", this.state); break; case 'prev100': if (this.state.final_data.length !== 0 && this.state.current_index - 100 >= 0) { this.setState({current_index: this.state.current_index - 100}) } - console.log("prev", this.state); break; case 'next': if (this.state.final_data.length !== 0 && this.state.current_index + 1 < this.state.final_data.length) { this.setState({current_index: this.state.current_index + 1}) } - console.log("next", this.state); break; case 'next10': if (this.state.final_data.length !== 0 && this.state.current_index + 10 < this.state.final_data.length) { this.setState({current_index: this.state.current_index + 10}) } - console.log("next", this.state); break; case 'next100': if (this.state.final_data.length !== 0 && this.state.current_index + 100 < this.state.final_data.length) { this.setState({current_index: this.state.current_index + 100}) } - console.log("next", this.state); break; case 'correct': if (this.state.final_data.length !== 0 && this.state.current_index + 1 < this.state.final_data.length) { this.setState({current_index: this.state.current_index + 1}) } - console.log("correct", this.state); break; case 'exiting': this.askSaveIfNeed(); @@ -149,7 +149,6 @@ class MainView extends Component { } saveCurrentDoc() { - console.log(this.current_file); if (this.current_file === undefined) { const file = remote.dialog.showSaveDialog(remote.getCurrentWindow(), { filters: [ @@ -163,7 +162,6 @@ class MainView extends Component { meta: {"current_index": this.state.current_index}, data: this.state.final_data }); - console.log(save_data); MainView.saveText(save_data, this.current_file); self.isSaved = true; document.title = "Labeling - " + this.current_file; @@ -178,6 +176,14 @@ class MainView extends Component { } } + switchChange(new_switch, index) { + if (new_switch !== undefined) { + let final_data_copy = this.state.final_data; + final_data_copy[index].use = new_switch ? 1 : 0; + this.setState({final_data: final_data_copy}); + } + } + render() { return ( @@ -190,7 +196,8 @@ class MainView extends Component { + handleLabelChange={this.labelChange} + handleSwitchChange={this.switchChange}/>