* @return TODO
*/
public UpdateStatus setVisible(Boolean visible) {
+ if (this.visible == visible) {
+ return UpdateStatus.NoChange;
+ }
+
this.visible = visible;
return UpdateStatus.Success;
}
super();
setStyle(__GO_UI_LAYER__);
}
-
}
/** sdsdf*/
nameToGO.put("UITextarea", __GO_UI_PUSHBUTTON__);
nameToGO.put("UIScilabPlot", __GO_UI_PUSHBUTTON__);
+ nameToGO.put("UIComboColor", __GO_UI_POPUPMENU__);
}
import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
+import org.scilab.modules.gui.bridge.frame.SwingScilabLayer;
import org.scilab.modules.gui.bridge.label.SwingScilabLabel;
import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
menuBar.setVisible(figure.getMenubarVisible());
tab.setMenuBar(menuBar);
window.addMenuBar(menuBar);
-
+
/* TOOLBAR */
ToolBar toolbar = ScilabToolBar.createToolBar();
toolbar.setVisible(figure.getToolbarVisible());
tab.setToolBar(toolbar);
window.addToolBar(toolbar);
-
+
/* INFOBAR */
TextBox infoBar = ScilabTextBox.createTextBox();
infoBar.setVisible(figure.getInfobarVisible());
tab.setInfoBar(infoBar);
window.addInfoBar(infoBar);
-
+
if (figure.getDockable()) {
DockingManager.dock((SwingScilabDockablePanel) tab, window.getDockingPort());
ActiveDockableTracker.requestDockableActivation((SwingScilabDockablePanel) tab);
tab.update(__GO_POSITION__, GraphicController.getController().getProperty(id, __GO_POSITION__));
// TODO set other default properties
+ window.setVisible(figure.getVisible());
window.pack();
- if (!figure.getDockable()) {
- window.setVisible(figure.getVisible());
- }
return tab;
case Axes:
SwingScilabCanvas axes = new SwingScilabCanvas(null);
//TabGroup.update(property, value);
return TabGroup;
case Layer:
- SwingScilabFrame layer = new SwingScilabFrame();
- layer.setLayout(new CardLayout());
+ SwingScilabLayer layer = new SwingScilabLayer();
layer.setId(id);
return layer;
default:
updatedObject.addChild(childId);
int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
-
+
/* Add an Axes */
if (childType == __GO_AXES__) {
SwingViewObject canvas = allObjects.get(childId).getValue();
((SwingScilabPanel) updatedComponent).addMember(canvas);
}
-
+
/* Add an uicontrol */
if (childType == __GO_UICONTROL__) {
SwingViewObject uiContol = allObjects.get(childId).getValue();
*/
private void updateLayerChildren(TypedObject updatedObject, Integer[] newChildren) {
Container updatedComponent = (SwingScilabFrame) updatedObject.getValue();
- boolean needRevalidate = false;
// Add new children
for (Integer childId : newChildren) {
/* Add an uicontrol */
if (childType == __GO_UICONTROL__) {
- ((SwingScilabFrame) updatedComponent).add((Component) allObjects.get(childId).getValue(), Integer.toString(allObjects.get(childId).getValue().getId()));
- needRevalidate = true;
+ int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
+ if (childStyle == __GO_UI_FRAME__) {
+ ((SwingScilabLayer) updatedComponent).addMember((SwingScilabFrame) allObjects.get(childId).getValue());
+ }
}
}
}
/* Remove an uicontrol */
if (childType == __GO_UICONTROL__) {
- updatedComponent.remove((Component) allObjects.get(childId).getValue());
- needRevalidate = true;
+ int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
+ if (childStyle == __GO_UI_FRAME__) {
+ ((SwingScilabLayer) updatedComponent).removeMember((SwingScilabFrame) allObjects.get(childId).getValue());
+ }
}
}
}
- if (needRevalidate && updatedComponent != null) {
- ((JPanel) updatedComponent).revalidate();
- }
}
/**
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_STYLE__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TAG__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BACKGROUNDCOLOR__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTANGLE__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_USER_DATA__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VALID__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LAYER__;
import java.awt.BorderLayout;
import java.awt.Color;
import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
+import org.scilab.modules.gui.bridge.frame.SwingScilabLayer;
import org.scilab.modules.gui.bridge.groupmanager.GroupManager;
import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
import org.scilab.modules.gui.utils.UnitsConverter.UicontrolUnits;
import org.scilab.modules.gui.widget.Widget;
+import com.sun.org.apache.bcel.internal.generic.AllocationInstruction;
+
/**
* @author Bruno JOFRET
* @author Vincent COUVERT
font = new Font(name, font.getStyle(), font.getSize());
- uiControl.setFont(font);
+ if (uiControl instanceof SwingScilabEditBox) {
+ ((SwingScilabEditBox)uiControl).setEditFont(font);
+ } else {
+ uiControl.setFont(font);
+ }
}
}
break;
shear[1] = imageParams[3];
((SwingScilabUiImage) uiControl).setShear(shear);
((SwingScilabUiImage) uiControl).setRotate(imageParams[4]);
+ } else if (uiControl instanceof SwingScilabLayer) {
+ SwingScilabLayer layer = (SwingScilabLayer)uiControl;
+ //if intValue[0] is out of bounds, do not update view but let "wrong" value in model
+ layer.setActiveLayer(intValue[0]);
}
break;
case __GO_UI_VERTICALALIGNMENT__ : {
}
break;
}
- case __GO_VISIBLE__ :
- uiControl.setVisible(((Boolean) value).booleanValue());
+ case __GO_VISIBLE__ : {
+ boolean needUpdate = true;
+ if (uiControl instanceof SwingScilabFrame) {
+ SwingScilabFrame frame = (SwingScilabFrame) uiControl;
+ Integer parent = (Integer) controller.getProperty(frame.getId(), __GO_PARENT__);
+ if (parent != 0) {
+ Integer type = (Integer) controller.getProperty(parent, __GO_TYPE__);
+ if (type == __GO_UICONTROL__) {
+ Integer style = (Integer) controller.getProperty(parent, __GO_STYLE__);
+ if (style == __GO_UI_LAYER__) {
+ //no no no don't touch visible on layer children !
+ Boolean visible = (Boolean)value;
+ SwingScilabLayer layer = (SwingScilabLayer) SwingView.getFromId(parent);
+ Boolean isActive = layer.isLayerActive(frame);
+ if (isActive != visible ) {
+ controller.setProperty(frame.getId(), __GO_VISIBLE__, isActive);
+ }
+
+ needUpdate = false;
+ }
+ }
+ }
+ }
+
+ if (needUpdate) {
+ uiControl.setVisible(((Boolean) value).booleanValue());
+ }
break;
+ }
case __GO_PARENT__:
/* Update position */
SwingViewWidget.update(uiControl, __GO_POSITION__, controller.getProperty(uid, __GO_POSITION__));
package org.scilab.modules.gui.bridge.editbox;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
import java.awt.Color;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
+import org.scilab.modules.graphic_objects.console.Console;
import org.scilab.modules.graphic_objects.graphicController.GraphicController;
-import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorderType;
import org.scilab.modules.gui.SwingView;
import org.scilab.modules.gui.SwingViewObject;
import org.scilab.modules.gui.SwingViewWidget;
offsets[i] += offset;
}
} else {
- // TOP_ALIGNEMENT or other
- // default behaviour : do nothing special
+ // TOP_ALIGNEMENT or other
+ // default behaviour : do nothing special
}
}
}
InputMap map = textPane.getInputMap();
enterKeyAction = map.get(enterKey);
- StyleConstants.setAlignment(docAttributes, StyleConstants.ALIGN_CENTER);
+ if (Console.getConsole().getUseDeprecatedLF() == false) {
+ setEditFont(getFont());
+ }
+ //StyleConstants.setAlignment(docAttributes, StyleConstants.ALIGN_CENTER);
}
/**
StyleConstants.setBackground(docAttributes, bg);
}
}
-
- public void setFont(Font font) {
+
+ public void setEditFont(Font font) {
super.setFont(font);
if (textPane != null) {
textPane.setFont(font);
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
import java.awt.BorderLayout;
import org.scilab.modules.graphic_objects.graphicController.GraphicController;
import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
-import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorderType;
import org.scilab.modules.gui.SwingView;
import org.scilab.modules.gui.SwingViewObject;
import org.scilab.modules.gui.SwingViewWidget;
--- /dev/null
+package org.scilab.modules.gui.bridge.frame;
+
+
+
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
+
+import java.awt.CardLayout;
+import java.awt.Component;
+import java.util.ArrayList;
+
+import org.scilab.modules.graphic_objects.graphicController.GraphicController;
+
+public class SwingScilabLayer extends SwingScilabFrame {
+ private static final long serialVersionUID = 9038916804095320758L;
+ private ArrayList<String> layerName = new ArrayList<String>();
+ private CardLayout layout = new CardLayout();
+
+ public SwingScilabLayer() {
+ super();
+ setLayout(layout);
+ }
+
+ public void addMember(SwingScilabFrame member) {
+ String name = member.getId().toString();
+ member.setName(name);
+ layerName.add(name);
+ add(member, name);
+ revalidate();
+ //active the first child
+ if (getActiveLayer() == -1) {
+ setActiveLayer(1);
+ }
+
+ }
+
+ public Integer getActiveLayer() {
+ SwingScilabFrame card = null;
+ for (Component comp : getComponents()) {
+ if (comp.isVisible() == true) {
+ card = (SwingScilabFrame) comp;
+ break;
+ }
+ }
+
+ if (card == null) {
+ return -1;
+ }
+
+ return layerName.indexOf(card.getName()) + 1;
+ }
+
+ private SwingScilabFrame getLayerFromIndex(Integer layer) {
+ if (layer < 1 || layer > getComponentCount()) {
+ return null;
+ }
+
+ return (SwingScilabFrame) getComponent(layer - 1);
+ }
+
+ private Integer getLayerIndex(SwingScilabFrame layer) {
+ for (int i = 0; i < getComponentCount(); i++) {
+ if (getComponent(i) == layer) {
+ return i + 1;
+ }
+ }
+
+ return -1;
+ }
+
+ public Boolean isLayerActive(Integer layer) {
+ return getActiveLayer() == layer;
+ }
+
+
+ public Boolean isLayerActive(SwingScilabFrame layer) {
+ Integer index = getLayerIndex(layer);
+ if (index == -1) {
+ return false;
+ }
+
+ return isLayerActive(index);
+ }
+
+
+ public void removeMember(SwingScilabFrame member) {
+ layerName.remove(member.getId().toString());
+ remove(member);
+ revalidate();
+
+ //update model with new index
+ Integer active = getActiveLayer();
+ if (active == -1) {
+ if (setActiveLayer(1)) {
+ active = 1;
+ }
+ }
+
+ //update model with new index
+ GraphicController.getController().setProperty(getId(), __GO_UI_VALUE__, new Double[] {active.doubleValue()});
+ }
+
+ public boolean setActiveLayer(Integer layerPos) {
+ if (layerPos < 1 || layerPos > layerName.size()) {
+ return false;
+ }
+
+ Integer previous = getActiveLayer();
+ if (setActiveLayer(layerName.get(layerPos - 1)) == false) {
+ return false;
+ }
+
+ Integer next = getActiveLayer();
+ updateChildrenVisible(previous, next);
+ return true;
+ }
+
+ private boolean setActiveLayer(String layer) {
+ //check existing item
+ if (layerName.contains(layer)) {
+ layout.show(this, layer);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void updateChildrenVisible(Integer previous, Integer next) {
+ SwingScilabFrame previousFrame = getLayerFromIndex(previous);
+ SwingScilabFrame nextFrame = getLayerFromIndex(next);
+
+ if (previousFrame != null) {
+ GraphicController.getController().setProperty(previousFrame.getId(), __GO_VISIBLE__, false);
+ }
+
+ if (nextFrame != null) {
+ GraphicController.getController().setProperty(nextFrame.getId(), __GO_VISIBLE__, true);
+ }
+
+ GraphicController.getController().setProperty(getId(), __GO_UI_VALUE__, new Double[] {next.doubleValue()});
+
+ }
+}
setVisibleAmount(Math.max((int) ((MAXIMUM_VALUE - MINIMUM_VALUE) / space), MIN_KNOB_SIZE));
setMaximum(oldMax + getVisibleAmount());
- System.out.println("old major = " + (int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
/* Put back the listener */
addAdjustmentListener(adjustmentListener);
}
double userMin = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MIN__);
double userMax = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MAX__);
setUnitIncrement((int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
- System.out.println("old minor = " + (int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
/* Put back the listener */
addAdjustmentListener(adjustmentListener);
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+function layer = create_layer(count)
+ c = get(0);c.usedeprecatedskin = "off"
+ f = figure("dockable", "off" ,"infobar_visible", "off", "toolbar_visible", "off", "menubar_visible", "off", "layout", "border")
+ f.figure_size = [300, 300];
+ //layer
+ layer = uicontrol(f, "style", "layer", "constraints", createConstraints("border", "center"));
+ for i = 1:count
+ fr1 = uicontrol(layer, "style", "frame");
+ fr1.layout_options = createLayoutOptions("border", [10, 10]);
+ fr1.layout = "border";
+ uicontrol(fr1, "string", "button " + string(i) + "1", "constraints", createConstraints("border", "top"));
+ uicontrol(fr1, "string", "button " + string(i) + "2", "constraints", createConstraints("border", "left"));
+ uicontrol(fr1, "string", "button " + string(i) + "3", "constraints", createConstraints("border", "center"));
+ uicontrol(fr1, "string", "button " + string(i) + "4", "constraints", createConstraints("border", "bottom"));
+ uicontrol(fr1, "string", "button " + string(i) + "5", "constraints", createConstraints("border", "right"));
+ end
+endfunction
+//1 layer
+layer = create_layer(1);
+visible1 = ['on'];
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible1);
+//4 layers
+delete(gcf());
+layer = create_layer(4);
+visible1 = ['off' 'off' 'off' 'on'];
+visible2 = ['off' 'off' 'on' 'off'];
+visible3 = ['off' 'on' 'off' 'off'];
+visible4 = ['on' 'off' 'off' 'off'];
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+assert_checkequal(layer.children.visible, visible2);
+layer.value = 3;
+assert_checkequal(layer.value, 3);
+assert_checkequal(layer.children.visible, visible3);
+layer.value = 4;
+assert_checkequal(layer.value, 4);
+assert_checkequal(layer.children.visible, visible4);
+layer.value = 10;
+assert_checkequal(layer.value, 10);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible4);
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- TEST WITH GRAPHIC -->
+
+function layer = create_layer(count)
+ c = get(0);c.usedeprecatedskin = "off"
+ f = figure("dockable", "off" ,"infobar_visible", "off", "toolbar_visible", "off", "menubar_visible", "off", "layout", "border")
+ f.figure_size = [300, 300];
+
+ //layer
+ layer = uicontrol(f, "style", "layer", "constraints", createConstraints("border", "center"));
+
+ for i = 1:count
+ fr1 = uicontrol(layer, "style", "frame");
+ fr1.layout_options = createLayoutOptions("border", [10, 10]);
+ fr1.layout = "border";
+ uicontrol(fr1, "string", "button " + string(i) + "1", "constraints", createConstraints("border", "top"));
+ uicontrol(fr1, "string", "button " + string(i) + "2", "constraints", createConstraints("border", "left"));
+ uicontrol(fr1, "string", "button " + string(i) + "3", "constraints", createConstraints("border", "center"));
+ uicontrol(fr1, "string", "button " + string(i) + "4", "constraints", createConstraints("border", "bottom"));
+ uicontrol(fr1, "string", "button " + string(i) + "5", "constraints", createConstraints("border", "right"));
+ end
+endfunction
+
+//1 layer
+layer = create_layer(1);
+visible1 = ['on'];
+
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible1);
+
+//4 layers
+delete(gcf());
+layer = create_layer(4);
+
+visible1 = ['off' 'off' 'off' 'on'];
+visible2 = ['off' 'off' 'on' 'off'];
+visible3 = ['off' 'on' 'off' 'off'];
+visible4 = ['on' 'off' 'off' 'off'];
+
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+assert_checkequal(layer.children.visible, visible2);
+
+layer.value = 3;
+assert_checkequal(layer.value, 3);
+assert_checkequal(layer.children.visible, visible3);
+
+layer.value = 4;
+assert_checkequal(layer.value, 4);
+assert_checkequal(layer.children.visible, visible4);
+
+layer.value = 10;
+assert_checkequal(layer.value, 10);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible4);