Skip to content

Commit

Permalink
create rotate button in toolbar [#67 state:committed]
Browse files Browse the repository at this point in the history
  • Loading branch information
novakps committed Sep 29, 2010
1 parent 00d4fb7 commit 8ce66eb
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 180 deletions.
198 changes: 109 additions & 89 deletions build/kemia-whitespace-only.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions css/kemia.css
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,11 @@ See the COPYING file for details.
background-position: -310px;
}

/* Rotate */
.tr-rotate {
background-position: -328px;
}

/* Erase */
.tr-erase {
background-position: -126px;
Expand Down
File renamed without changes
File renamed without changes
Binary file modified images/toolbar_icons.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion kemia/controller/defaulttoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,19 @@ kemia.controller.DefaultToolbar.makeDefaultToolbar = function(elem) {
buttons.push(new goog.ui.ToolbarSeparator());

var move = kemia.controller.ToolbarFactory.makeToggleButton(
kemia.controller.plugins.Move.COMMAND, 'Move', '', goog
kemia.controller.plugins.Move.COMMAND.MOVE, 'Move', '', goog
.getCssName('tr-icon')
+ ' ' + goog.getCssName('tr-move'));
move.queryable = true;
buttons.push(move);

var rotate = kemia.controller.ToolbarFactory.makeToggleButton(
kemia.controller.plugins.Move.COMMAND.ROTATE, 'Rotate', '', goog
.getCssName('tr-icon')
+ ' ' + goog.getCssName('tr-rotate'));
rotate.queryable = true;
buttons.push(rotate);

var erase = kemia.controller.ToolbarFactory.makeToggleButton(
kemia.controller.plugins.Erase.COMMAND, 'Erase', '', goog
.getCssName('tr-icon')
Expand Down
209 changes: 123 additions & 86 deletions kemia/controller/plugins/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,53 @@ goog.require('goog.debug.Logger');
*/
kemia.controller.plugins.Move = function() {
kemia.controller.Plugin.call(this);
this.isActive = true;
this.isActive = {};
this.isActive[kemia.controller.plugins.Move.COMMAND.MOVE] = true;
this.isDragging = false;
}
goog.inherits(kemia.controller.plugins.Move, kemia.controller.Plugin);
goog.exportSymbol('kemia.controller.plugins.Move',
kemia.controller.plugins.Move);

/**
* Command implemented by this plugin.
* Commands implemented by this plugin.
*
* @enum {string}
*/
kemia.controller.plugins.Move.COMMAND = {
MOVE : 'move',
ROTATE : 'rotate'
}

/**
* Inverse map of execCommand strings to
* {@link kemia.controller.plugins.Move.COMMAND} constants. Used to determine
* whether a string corresponds to a command this plugin handles
*
* @type {Object}
* @private
*/
kemia.controller.plugins.Move.COMMAND = 'move';
kemia.controller.plugins.Move.SUPPORTED_COMMANDS_ = goog.object
.transpose(kemia.controller.plugins.Move.COMMAND);

kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE = 'url("../../elements/images/rotate-cursor-32.png") 16 16, pointer';

/** @inheritDoc */
kemia.controller.plugins.Move.prototype.isSupportedCommand = function(command) {
return command == kemia.controller.plugins.Move.COMMAND;
kemia.controller.plugins.Move.prototype.isSupportedCommand = function(
command) {
return command in kemia.controller.plugins.Move.SUPPORTED_COMMANDS_;
};

/** @inheritDoc */
kemia.controller.plugins.Move.prototype.getTrogClassId = goog.functions
.constant(kemia.controller.plugins.Move.COMMAND);
.constant('move');

/**
* reset to default state called when another plugin is made active
*/
kemia.controller.plugins.Move.prototype.resetState = function() {
this.isActive = false;
this.isActive[kemia.controller.plugins.Move.COMMAND.MOVE] = false;
this.isActive[kemia.controller.plugins.Move.COMMAND.ROTATE] = false;
}

/**
Expand All @@ -47,129 +66,150 @@ kemia.controller.plugins.Move.prototype.resetState = function() {
*/
kemia.controller.plugins.Move.prototype.execCommandInternal = function(command,
value, active) {
this.isActive = active;
// this.logger.info(command + " " + active);
this.isActive[command] = active;
};

kemia.controller.plugins.Move.prototype.handleMouseMove = function(e) {

if (this.isActive && !this.isDragging) {
if ((this.isActive[kemia.controller.plugins.Move.COMMAND.MOVE] ||
this.isActive[kemia.controller.plugins.Move.COMMAND.ROTATE]) &&
!this.isDragging) {
var target = this.editorObject.findTarget(e);
this.editorObject.getOriginalElement().style.cursor = 'default';
if (e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup.clear();
}
if (target instanceof kemia.model.Atom) {
if (!e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = 'move';
if (this.isActive[kemia.controller.plugins.Move.COMMAND.ROTATE]){
if (target instanceof kemia.model.Molecule) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE;
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightAtom(target);
e.currentTarget.highlightGroup = this.highlightMolecule(target);
} else {
e.currentTarget.highlightGroup = this.highlightAtom(target,
e.currentTarget.highlightGroup = this.highlightMolecule(target,
e.currentTarget.highlightGroup);
}
return true;
}
} else if (target instanceof kemia.model.Bond) {
if (!e.shiftKey) {
} else {
if (target instanceof kemia.model.Atom) {
this.editorObject.getOriginalElement().style.cursor = 'move';
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightBond(target);
e.currentTarget.highlightGroup = this.highlightAtom(target);
} else {
e.currentTarget.highlightGroup = this.highlightBond(target,
e.currentTarget.highlightGroup = this.highlightAtom(target,
e.currentTarget.highlightGroup);
}
return true;
}
} else if (target instanceof kemia.model.Molecule) {
if (e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE;
} else {
this.editorObject.getOriginalElement().style.cursor = 'move';
}
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightMolecule(target);
} else {
e.currentTarget.highlightGroup = this.highlightMolecule(target,
e.currentTarget.highlightGroup);
}
return true;
} else if (target instanceof kemia.model.Arrow) {
if (!e.shiftKey) {
} else if (target instanceof kemia.model.Bond) {
this.editorObject.getOriginalElement().style.cursor = 'move';
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this
.highlightArrow(target);
e.currentTarget.highlightGroup = this.highlightBond(target);
} else {
e.currentTarget.highlightGroup = this.highlightArrow(
target, e.currentTarget.highlightGroup);
e.currentTarget.highlightGroup = this.highlightBond(target,
e.currentTarget.highlightGroup);
}
return true;
}
} else if (target instanceof kemia.model.Plus) {
if (!e.shiftKey) {
} else if (target instanceof kemia.model.Molecule) {
this.editorObject.getOriginalElement().style.cursor = 'move';
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightPlus(target);
e.currentTarget.highlightGroup = this.highlightMolecule(target);
} else {
e.currentTarget.highlightGroup = this.highlightPlus(target,
e.currentTarget.highlightGroup = this.highlightMolecule(target,
e.currentTarget.highlightGroup);
}
return true;
} else if (target instanceof kemia.model.Arrow) {
if (!e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = 'move';
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this
.highlightArrow(target);
} else {
e.currentTarget.highlightGroup = this.highlightArrow(
target, e.currentTarget.highlightGroup);
}
return true;
}
} else if (target instanceof kemia.model.Plus) {
if (!e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = 'move';
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightPlus(target);
} else {
e.currentTarget.highlightGroup = this.highlightPlus(target,
e.currentTarget.highlightGroup);
}
return true;
}
}
}
return false;

}

}

kemia.controller.plugins.Move.prototype.handleMouseDown = function(e) {

if (this.isActive) {
if (this.isActive[kemia.controller.plugins.Move.COMMAND.MOVE] ||
this.isActive[kemia.controller.plugins.Move.COMMAND.ROTATE]) {
if (e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup.clear();
}
this.isDragging = true;
var target = this.editorObject.findTarget(e);
if (target instanceof kemia.model.Atom) {
var atom = target;
this.editorObject.dispatchBeforeChange();
this.dragAtom(e, atom);
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Bond) {
var bond = target;
this.editorObject.dispatchBeforeChange();
this.dragBond(e, bond);
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Molecule) {
var molecule = target;
this.editorObject.dispatchBeforeChange();
if (e.shiftKey) {

if(this.isActive[kemia.controller.plugins.Move.COMMAND.ROTATE]){
if (target instanceof kemia.model.Molecule) {
var molecule = target;
this.editorObject.dispatchBeforeChange();
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE;
this.rotateMolecule(e, target);
} else {
this.dragMolecule(e, target);
this.editorObject.dispatchChange();
return true;
}
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Plus) {
var plus = target;
this.editorObject.dispatchBeforeChange();
this.dragPlus(e, plus);
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Arrow) {
var arrow = target;
this.editorObject.dispatchBeforeChange();
this.dragArrow(e, arrow);
this.editorObject.dispatchChange();
return true;

if(this.isActive[kemia.controller.plugins.Move.COMMAND.MOVE]){
if (target instanceof kemia.model.Atom) {
var atom = target;
this.editorObject.dispatchBeforeChange();
this.dragAtom(e, atom);
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Bond) {
var bond = target;
this.editorObject.dispatchBeforeChange();
this.dragBond(e, bond);
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Molecule) {
var molecule = target;
this.editorObject.dispatchBeforeChange();
if (e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE;
this.rotateMolecule(e, target);
} else {
this.dragMolecule(e, target);
}
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Plus) {
var plus = target;
this.editorObject.dispatchBeforeChange();
this.dragPlus(e, plus);
this.editorObject.dispatchChange();
return true;
}
if (target instanceof kemia.model.Arrow) {
var arrow = target;
this.editorObject.dispatchBeforeChange();
this.dragArrow(e, arrow);
this.editorObject.dispatchChange();
return true;
}
}
}
return false;
Expand Down Expand Up @@ -287,11 +327,8 @@ kemia.controller.plugins.Move.prototype.highlightPlus = function(plus,

/** @inheritDoc */
kemia.controller.plugins.Move.prototype.queryCommandValue = function(command) {
var state = null;
if (command == kemia.controller.plugins.Move.COMMAND) {
state = this.isActive;
}
return state;

return this.isActive[command];
};

/**
Expand Down
6 changes: 2 additions & 4 deletions kemia/ring/ring_partitioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ goog.require('goog.array');
/**
* partitions array of rings into connected lists
*
* @param {Array.
* <kemia.ring.Ring>} rings list of rings to group into connected
* @param {Array.<kemia.ring.Ring>} rings list of rings to group into connected
* arrays
* @return {Array.<Array.<kemia.ring.Ring>>} array of arrays of Rings
*/
Expand Down Expand Up @@ -94,8 +93,7 @@ kemia.ring.RingPartitioner.directConnectedRings = function(ring, rings){
/**
* partitions array of rings into connected lists
*
* @param {Array.
* <kemia.ring.Ring>} rings list of rings to group into connected
* @param {Array.<kemia.ring.Ring>} rings list of rings to group into connected
* arrays
* @return {Array.<Array.<kemia.ring.Ring>>} array of arrays of Rings
*/
Expand Down

0 comments on commit 8ce66eb

Please sign in to comment.