From 242854a0c0f60d3e23201f1a2f0778bef6cd8859 Mon Sep 17 00:00:00 2001 From: roy77 Date: Sat, 31 Jan 2015 10:27:41 +0100 Subject: [PATCH 01/11] complete german translation --- .../resources/logisim/de/circuit.properties | 4 +- src/main/resources/logisim/de/gui.properties | 46 +++++++++++++++++-- src/main/resources/logisim/de/menu.properties | 4 ++ src/main/resources/logisim/de/std.properties | 43 ++++++++++++++++- src/main/resources/logisim/de/util.properties | 2 +- src/main/resources/logisim/el/std.properties | 1 - 6 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/main/resources/logisim/de/circuit.properties b/src/main/resources/logisim/de/circuit.properties index feee3fe1..d5c77182 100644 --- a/src/main/resources/logisim/de/circuit.properties +++ b/src/main/resources/logisim/de/circuit.properties @@ -13,8 +13,10 @@ analyzeCannotHandleError= Erstelle eine Wahrheitstabelle f\u00fcr den Ausdruck, # circuit/Circuit.java # circuitName= Schaltungsname +circuitLabelLocAttr = Beschriftung Position +circuitLabelAttr = Gemeinsame Beschriftung circuitLabelDirAttr= Ausrichtung der Beschriftung -# +circuitLabelFontAttr = Zeichensatz der gemeinsamen Beschriftung # circuit/CircuitMutation.java # unknownChangeAction= Schaltung \u00e4ndern diff --git a/src/main/resources/logisim/de/gui.properties b/src/main/resources/logisim/de/gui.properties index e496a9a3..d4ff5b06 100644 --- a/src/main/resources/logisim/de/gui.properties +++ b/src/main/resources/logisim/de/gui.properties @@ -39,6 +39,7 @@ exportImageButton= Exportieren exportGifFilter= GIF-Dateien (*.gif) exportPngFilter= PNG-Dateien (*.png) exportJpgFilter= JPEG-Dateien (*.jpeg, *.jpg) +exportSvgFilter = SVG-Dateien (*.svg) exportPdfFilter= PDF-Dateien (*.pdf) exportNewDirectoryErrorTitle= Kann Verzeichnis nicht erstellen exportNewDirectoryErrorMessage= Das Verzeichnis konnte nicht erstellt werden. @@ -68,6 +69,21 @@ duplicateSelectionAction= Auswahl duplizieren cutSelectionAction= Auswahl ausschneiden copySelectionAction= Auswahl kopieren pasteClipboardAction= Aus Zwischenablage einf\u00fcgen +pasteCloneQuery = Die Zwischenablage beinhaltet "%s." Das Projekt beinhaltet es nicht, aber eine anderes mit gleichem Namen. +pasteCloneTitle = Komponente +pasteCloneReplace = Ersetzen +pasteCloneIgnore = Ignorieren +pasteCloneCancel = Abbrechen +pasteDropMessage = Einige Komponenten der Zwischenablage wurden nicht eingefügt, da diese nicht in der Projekt Bibliothek enthalten sind: +pasteDropTitle = Komponente nicht eingefügt +# +# tools/SelectionAttributeChange.java +# +selectionAttributeAction = Ändere Auswahleigenschaften +# +# tools/ToolActions.java +# +changeToolAttrAction = Ändere Werkzeugeigenschaft # # gui/main/StatisticsDialog.java # @@ -81,14 +97,28 @@ statsLibraryColumn= Bibliothek statsTotalWithout= GESAMT (ohne Teilschaltungen) statsTotalWith= GESAMT (mit Teilschaltungen) # -# gui/ProjectToolbar.java +# gui/main/ExplorerToolbarModel.java +# +projectViewToolboxTip = Zeige Projekt Schaltungen und Bibliotheken in Explorer Fenster +projectViewSimulationTip = Zeige Simulationsbaum in Explorer Fenster +projectEditLayoutTip= Layout der angezeigten Schaltung bearbeiten +projectEditAppearanceTip= Aussehen der angezeigten Schaltung als Teilschaltung bearbeiten +# +# gui/main/ToolboxToolbarModel.java # projectAddCircuitTip= Schaltung hinzuf\u00fcgen projectMoveCircuitDownTip= Angezeigte Schaltung in der Liste nach unten projectMoveCircuitUpTip= Angezeigte Schaltung in der Liste nach oben projectRemoveCircuitTip= Angezeigte Schaltung entfernen -projectEditLayoutTip= Layout der angezeigten Schaltung bearbeiten -projectEditAppearanceTip= Aussehen der angezeigten Schaltung als Teilschaltung bearbeiten +# +# gui/main/SimulationToolbarModel.java +# +simulateEnableStepsTip = Simulation aktivieren +simulateDisableStepsTip = Simulation deaktivieren +simulateStepTip = Einen Signaldurchlauf simulieren +simulateEnableTicksTip = Takt einschalten +simulateDisableTicksTip = Takt abschalten +simulateTickTip = Takt umschalten # # gui/TickRate.java # @@ -101,4 +131,12 @@ zoomShowGrid= Gitternetz umschalten # # gui/appear/RevertAppearanceAction # -revertAppearanceAction= Darstellung wiederherstellen \ No newline at end of file +revertAppearanceAction= Darstellung wiederherstellen +# +# attribute table models +# +circuitAttrTitle = Schaltung: %s +toolAttrTitle = Werkzeug: %s +selectionOne = Auswahl: %s +selectionMultiple = Auswahl: %s \u00D7 %s +selectionVarious = Auswahl: Diverse Elemente \u00D7 %s \ No newline at end of file diff --git a/src/main/resources/logisim/de/menu.properties b/src/main/resources/logisim/de/menu.properties index 926321cb..4f41fd89 100644 --- a/src/main/resources/logisim/de/menu.properties +++ b/src/main/resources/logisim/de/menu.properties @@ -2,6 +2,8 @@ editMenu= Bearbeiten editCantUndoItem= Zur\u00fccknehmen nicht m\u00f6glich editUndoItem= %s zur\u00fccknehmen +editCantRedoItem = Wiederherstellen nicht m\u00f6glich +editRedoItem = Wiederherstellen %s editCutItem= Ausschneiden editCopyItem= Kopieren editPasteItem= Einf\u00fcgen @@ -47,6 +49,8 @@ projectEditCircuitAppearanceItem= Schaltungsaussehen bearbeiten projectRevertAppearanceItem= Aussehen wiederherstellen projectAnalyzeCircuitItem= Schaltung analysieren projectGetCircuitStatisticsItem= Schaltungsstatistik ermitteln +projectViewToolboxItem = Werkzeuge anzeigen +projectViewSimulationItem = Simulationsbaum anzeigen projectOptionsItem= Optionen... # MenuSimulate.java diff --git a/src/main/resources/logisim/de/std.properties b/src/main/resources/logisim/de/std.properties index 40bcca11..6950c434 100644 --- a/src/main/resources/logisim/de/std.properties +++ b/src/main/resources/logisim/de/std.properties @@ -87,6 +87,29 @@ textVertAlignCenterOpt= Zentriert # std/base/Tunnel.java tunnelComponent= Tunnel +# +# std/Wiring.java +# +wiringLibrary = Verdrahtung +wiringGateAttr = Position der Eingänge +wiringGateBottomRightOption = Unten/Rechts +wiringGateTopLeftOption = Oben/Links + +# std/wiring/Transistor.java +transistorComponent = Transistor +transistorTypeAttr = Type +transistorTypeP = P-Type +transistorTypeN = N-Type + +# std/wiring/TransmissionGate.java +transmissionGateComponent = Übertragungsgatter + +# std/wiring/Power.java +powerComponent = Versorgungsspannung + +# std/wiring/Ground.java +groundComponent = Masse + # # std/Gates.java # @@ -97,6 +120,10 @@ gateSizeNormalOpt= Mittel gateSizeWideOpt= Breit gateNegateAttr= Negiere %s gateInputsAttr= Anzahl der Eing\u00e4nge +gateOutput01 = 0/1 +gateOutput0Z = 0/offen +gateOutputZ1 = offen/1 +gateOutputAttr = Ausgabewert xorBehaviorAttr= Verhalten bei mehreren Eing\u00e4ngen xorBehaviorOne= Falls genau ein Eingang gesetzt ist xorBehaviorOdd= Falls eine ungerade Anzahl gesetzt ist @@ -247,19 +274,29 @@ shiftRegLoadTip= Laden: wenn 1 (mit Freigabe = 0) werden alle Stufen von den Ein plexerLibrary= Auswahlschaltungen plexerSelectBitsAttr= Auswahlleitungen plexerThreeStateAttr= Threestate? +plexerDisabledAttr = Disabled Output +plexerDisabledFloating = Offen +plexerDisabledZero = Null +plexerEnableAttr = Enable Eingang? +plexerSelectLocAttr = Position der Eingänge +plexerSelectTopRightOption = Oben/Rechts +plexerSelectBottomLeftOption = Unten/Lonks # std/Multiplexer.java multiplexerComponent= Multiplexer multiplexerSelectTip= Auswahl: gibt an, welcher Eingang an den Ausgang durchgeschaltet wird +multiplexerEnableTip = Aktivierung: wenn nicht 0 wird ausgewählter Eingang auf Ausgang geschaltet multiplexerInTip= Eingang %s multiplexerOutTip= Ausgang # std/Demultiplexer.java demultiplexerComponent= Demultiplexer demultiplexerSelectTip= Auswahl: gibt an, an welchen Ausgang der Eingang durchgeschaltet wird +demultiplexerEnableTip = Aktivierung: wenn nicht 0, wird Eingang auf ausgewählten Ausgang geschaltet demultiplexerInTip= Eingang demultiplexerOutTip= Ausgang %s # std/Decoder.java decoderComponent= Dekoder decoderSelectTip= Auswahl: gibt an, welcher Ausgang auf 1 gesetzt wird +decoderEnableTip = Aktivierung: wenn nicht 0, wird 1 auf ausgewählten Ausgang geschaltet decoderOutTip= Ausgang %s # std/plexers/PriorityEncoder.java priorityEncoderComponent= Priorit\u00e4tsenkoder @@ -335,7 +372,6 @@ shifterOutputTip= Ausgang: Ergebnis der Schiebung des Eingangs bitAdderComponent= Bit-Z\u00e4hler bitAdderInputTip= Eingang: die zu z\u00e4hlenden Bits bitAdderOutputManyTip= Ausgang: die Anzahl der 1-Bits an den Eing\u00e4ngen -bitAdderOutputOneTip= Ausgang: die Anzahl der 1-Bits am Eingang # arith/BitFinder.java bitFinderComponent= Bit-Finder bitFinderFindLabel= find @@ -361,6 +397,11 @@ ioLabelColorAttr= Farbe der Beschriftung ioActiveAttr= Eingeschaltet bei H-Signal? # io/Button.java buttonComponent= Taster +buttonOutHighOption = 1 (High) +buttonOutLowOption = 0 (Low) +buttonOutOpenOption = H (Offen) +buttonDownAttr = Zustand gedr\u00fcckt +buttonUpAttr = Zustand nicht gedr\u00fcckt # io/Joystick.java joystickComponent= Joystick # io/Keyboard.java diff --git a/src/main/resources/logisim/de/util.properties b/src/main/resources/logisim/de/util.properties index ec0b28de..20bdb858 100644 --- a/src/main/resources/logisim/de/util.properties +++ b/src/main/resources/logisim/de/util.properties @@ -42,4 +42,4 @@ windowMenu= Fenster windowMinimizeItem= Minimieren windowZoomItem= Maximieren windowZoomItemMac= Zoom - +windowCloseItem = Schliessen diff --git a/src/main/resources/logisim/el/std.properties b/src/main/resources/logisim/el/std.properties index 99eefe7c..d774695b 100644 --- a/src/main/resources/logisim/el/std.properties +++ b/src/main/resources/logisim/el/std.properties @@ -368,7 +368,6 @@ shifterOutputTip= Output: \u03c4\u03bf \u03b1\u03c0\u03bf\u03c4\u03ad\u03bb\u03b bitAdderComponent= \u039c\u03b5\u03c4\u03c1\u03b7\u03c4\u03ae\u03c2 Bit bitAdderInputTip= Input: \u03c4\u03b1 bits \u03c0\u03bf\u03c5 \u03c0\u03c1\u03ad\u03c0\u03b5\u03b9 \u03bd\u03b1 \u03b1\u03c0\u03b1\u03c1\u03b9\u03b8\u03bc\u03b7\u03b8\u03bf\u03cd\u03bd bitAdderOutputManyTip= Output: \u03c4\u03bf \u03c0\u03bb\u03ae\u03b8\u03bf\u03c2 \u03c4\u03c9\u03bd bits \u03bc\u03b5 \u03c4\u03b9\u03bc\u03ae 1 \u03c3\u03c4\u03b7\u03bd \u03b5\u03af\u03c3\u03bf\u03b4\u03bf -bitAdderOutputOneTip= Output: \u03c4\u03bf \u03c0\u03bb\u03ae\u03b8\u03bf\u03c2 \u03c4\u03c9\u03bd bits \u03bc\u03b5 \u03c4\u03b9\u03bc\u03ae 1 \u03c3\u03c4\u03b7\u03bd \u03b5\u03af\u03c3\u03bf\u03b4\u03bf # arith/BitFinder.java bitFinderComponent= \u0395\u03cb\u03c1\u03b5\u03c3\u03b7 Bit bitFinderFindLabel= find From 8ba4d56108a96b358c77e3e578674140455ebdf1 Mon Sep 17 00:00:00 2001 From: roy77 Date: Sat, 31 Jan 2015 10:34:58 +0100 Subject: [PATCH 02/11] Bug-Fix in Canvas --- .../java/com/cburch/draw/canvas/Canvas.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/cburch/draw/canvas/Canvas.java b/src/main/java/com/cburch/draw/canvas/Canvas.java index 466020c8..6189e7dc 100644 --- a/src/main/java/com/cburch/draw/canvas/Canvas.java +++ b/src/main/java/com/cburch/draw/canvas/Canvas.java @@ -68,20 +68,20 @@ public void doAction(Action action) { public void setModel(CanvasModel value, ActionDispatcher dispatcher) { CanvasModel oldValue = model; - if (!oldValue.equals(value)) { - if (oldValue != null) { - oldValue.removeCanvasModelListener(listener); - } - - model = value; - this.dispatcher = dispatcher; - if (value != null) { - value.addCanvasModelListener(listener); - } - - selection.clearSelected(); - repaint(); - firePropertyChange(MODEL_PROPERTY, oldValue, value); + if (oldValue != null) { + if (!oldValue.equals(value)) { + oldValue.removeCanvasModelListener(listener); + + model = value; + this.dispatcher = dispatcher; + if (value != null) { + value.addCanvasModelListener(listener); + } + + selection.clearSelected(); + repaint(); + firePropertyChange(MODEL_PROPERTY, oldValue, value); + } } } From 147f10706e1aa3208aa64e1b25ca1c75c4834e3f Mon Sep 17 00:00:00 2001 From: roy77 Date: Sat, 31 Jan 2015 10:34:58 +0100 Subject: [PATCH 03/11] improve german translation --- .../java/com/cburch/draw/canvas/Canvas.java | 28 +++++++++---------- src/main/resources/logisim/de/std.properties | 9 ++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/cburch/draw/canvas/Canvas.java b/src/main/java/com/cburch/draw/canvas/Canvas.java index 466020c8..6189e7dc 100644 --- a/src/main/java/com/cburch/draw/canvas/Canvas.java +++ b/src/main/java/com/cburch/draw/canvas/Canvas.java @@ -68,20 +68,20 @@ public void doAction(Action action) { public void setModel(CanvasModel value, ActionDispatcher dispatcher) { CanvasModel oldValue = model; - if (!oldValue.equals(value)) { - if (oldValue != null) { - oldValue.removeCanvasModelListener(listener); - } - - model = value; - this.dispatcher = dispatcher; - if (value != null) { - value.addCanvasModelListener(listener); - } - - selection.clearSelected(); - repaint(); - firePropertyChange(MODEL_PROPERTY, oldValue, value); + if (oldValue != null) { + if (!oldValue.equals(value)) { + oldValue.removeCanvasModelListener(listener); + + model = value; + this.dispatcher = dispatcher; + if (value != null) { + value.addCanvasModelListener(listener); + } + + selection.clearSelected(); + repaint(); + firePropertyChange(MODEL_PROPERTY, oldValue, value); + } } } diff --git a/src/main/resources/logisim/de/std.properties b/src/main/resources/logisim/de/std.properties index 6950c434..68a3b449 100644 --- a/src/main/resources/logisim/de/std.properties +++ b/src/main/resources/logisim/de/std.properties @@ -121,8 +121,8 @@ gateSizeWideOpt= Breit gateNegateAttr= Negiere %s gateInputsAttr= Anzahl der Eing\u00e4nge gateOutput01 = 0/1 -gateOutput0Z = 0/offen -gateOutputZ1 = offen/1 +gateOutput0Z = 0/hochohmig +gateOutputZ1 = hochohmig/1 gateOutputAttr = Ausgabewert xorBehaviorAttr= Verhalten bei mehreren Eing\u00e4ngen xorBehaviorOne= Falls genau ein Eingang gesetzt ist @@ -397,11 +397,6 @@ ioLabelColorAttr= Farbe der Beschriftung ioActiveAttr= Eingeschaltet bei H-Signal? # io/Button.java buttonComponent= Taster -buttonOutHighOption = 1 (High) -buttonOutLowOption = 0 (Low) -buttonOutOpenOption = H (Offen) -buttonDownAttr = Zustand gedr\u00fcckt -buttonUpAttr = Zustand nicht gedr\u00fcckt # io/Joystick.java joystickComponent= Joystick # io/Keyboard.java From f2ef66ea5b0d3db44d84e09682a9faffef12347f Mon Sep 17 00:00:00 2001 From: roy77 Date: Sat, 31 Jan 2015 10:56:19 +0100 Subject: [PATCH 04/11] adjustable button output value 0/1 0/Z Z/1 Z/0 1/0 1/Z --- .../com/cburch/logisim/std/io/Button.java | 56 +++++++++++++++++-- src/main/resources/logisim/de/std.properties | 3 + src/main/resources/logisim/en/std.properties | 3 + 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cburch/logisim/std/io/Button.java b/src/main/java/com/cburch/logisim/std/io/Button.java index b18d455b..871341f4 100644 --- a/src/main/java/com/cburch/logisim/std/io/Button.java +++ b/src/main/java/com/cburch/logisim/std/io/Button.java @@ -9,7 +9,9 @@ import com.cburch.logisim.circuit.Wire; import com.cburch.logisim.data.Attribute; +import com.cburch.logisim.data.AttributeOption; import com.cburch.logisim.data.AttributeSet; +import com.cburch.logisim.data.Attributes; import com.cburch.logisim.data.Bounds; import com.cburch.logisim.data.Direction; import com.cburch.logisim.data.Location; @@ -24,21 +26,40 @@ import com.cburch.logisim.instance.Port; import com.cburch.logisim.instance.StdAttr; import com.cburch.logisim.util.GraphicsUtil; + + import static com.cburch.logisim.util.LocaleString.*; public class Button extends InstanceFactory { private static final int DEPTH = 3; + static final AttributeOption OUTPUT_01 + = new AttributeOption("01", getFromLocale("gateOutput01")); + static final AttributeOption OUTPUT_0Z + = new AttributeOption("0Z", getFromLocale("gateOutput0Z")); + static final AttributeOption OUTPUT_Z1 + = new AttributeOption("Z1", getFromLocale("gateOutputZ1")); + static final AttributeOption OUTPUT_Z0 + = new AttributeOption("Z0", getFromLocale("gateOutputZ0")); + static final AttributeOption OUTPUT_10 + = new AttributeOption("10", getFromLocale("gateOutput10")); + static final AttributeOption OUTPUT_1Z + = new AttributeOption("1Z", getFromLocale("gateOutput1Z")); + public static final Attribute ATTR_OUTPUT + = Attributes.forOption("out", getFromLocale("gateOutputAttr"), + new AttributeOption[] { OUTPUT_01, OUTPUT_10, OUTPUT_0Z, OUTPUT_Z1, OUTPUT_Z0, OUTPUT_1Z }); + + public Button() { super("Button", getFromLocale("buttonComponent")); setAttributes(new Attribute[] { StdAttr.FACING, Io.ATTR_COLOR, StdAttr.LABEL, Io.ATTR_LABEL_LOC, - StdAttr.LABEL_FONT, Io.ATTR_LABEL_COLOR + StdAttr.LABEL_FONT, Io.ATTR_LABEL_COLOR, Button.ATTR_OUTPUT }, new Object[] { Direction.EAST, Color.WHITE, "", Io.LABEL_CENTER, - StdAttr.DEFAULT_LABEL_FONT, Color.BLACK + StdAttr.DEFAULT_LABEL_FONT, Color.BLACK, Button.OUTPUT_01 }); setFacingAttribute(StdAttr.FACING); setIconName("button.svg"); @@ -139,7 +160,7 @@ public void paintInstance(InstancePainter painter) { Graphics g = painter.getGraphics(); int depress; - if (val == Value.TRUE) { + if (val == ButtonStateToValue(true,painter.getAttributeValue(Button.ATTR_OUTPUT))) { x += DEPTH; y += DEPTH; Object labelLoc = painter.getAttributeValue(Io.ATTR_LABEL_LOC); @@ -192,16 +213,41 @@ public void paintInstance(InstancePainter painter) { g.translate(-depress, -depress); painter.drawPorts(); } + + private static Value ButtonStateToValue(Boolean pressed, AttributeOption a){ + if(pressed==true){ + if((a==Button.OUTPUT_01) | (a==Button.OUTPUT_Z1)){ + return Value.TRUE; + } + else if((a==Button.OUTPUT_10) | (a==Button.OUTPUT_Z0)){ + return Value.FALSE; + } + else{ + return Value.NIL; + } + } + else{ + if((a==Button.OUTPUT_10) | (a==Button.OUTPUT_1Z)){ + return Value.TRUE; + } + else if((a==Button.OUTPUT_01) | (a==Button.OUTPUT_0Z)){ + return Value.FALSE; + } + else{ + return Value.NIL; + } + } + } public static class Poker extends InstancePoker { @Override public void mousePressed(InstanceState state, MouseEvent e) { - setValue(state, Value.TRUE); + setValue(state, ButtonStateToValue(true,state.getAttributeValue(Button.ATTR_OUTPUT))); } @Override public void mouseReleased(InstanceState state, MouseEvent e) { - setValue(state, Value.FALSE); + setValue(state, ButtonStateToValue(false,state.getAttributeValue(Button.ATTR_OUTPUT))); } private void setValue(InstanceState state, Value val) { diff --git a/src/main/resources/logisim/de/std.properties b/src/main/resources/logisim/de/std.properties index 68a3b449..a01ff8ed 100644 --- a/src/main/resources/logisim/de/std.properties +++ b/src/main/resources/logisim/de/std.properties @@ -123,6 +123,9 @@ gateInputsAttr= Anzahl der Eing\u00e4nge gateOutput01 = 0/1 gateOutput0Z = 0/hochohmig gateOutputZ1 = hochohmig/1 +gateOutputZ0 = hochohmig/0 +gateOutput10 = 1/0 +gateOutput1Z = 1/hochohmig gateOutputAttr = Ausgabewert xorBehaviorAttr= Verhalten bei mehreren Eing\u00e4ngen xorBehaviorOne= Falls genau ein Eingang gesetzt ist diff --git a/src/main/resources/logisim/en/std.properties b/src/main/resources/logisim/en/std.properties index 417c4ae8..9af7226e 100644 --- a/src/main/resources/logisim/en/std.properties +++ b/src/main/resources/logisim/en/std.properties @@ -123,6 +123,9 @@ gateInputsAttr = Number Of Inputs gateOutput01 = 0/1 gateOutput0Z = 0/floating gateOutputZ1 = floating/1 +gateOutputZ0 = floating/0 +gateOutput10 = 1/0 +gateOutput1Z = 1/floating gateOutputAttr = Output Value xorBehaviorAttr = Multiple-Input Behavior xorBehaviorOne = When one input is on From 06d8e3ca2d9a683f47b023891297319f3382b953 Mon Sep 17 00:00:00 2001 From: roy77 Date: Fri, 20 Mar 2015 10:23:21 +0100 Subject: [PATCH 05/11] adjustable button improve behavour after attribute changed --- .../com/cburch/logisim/std/io/Button.java | 53 ++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/cburch/logisim/std/io/Button.java b/src/main/java/com/cburch/logisim/std/io/Button.java index 871341f4..72fb7176 100644 --- a/src/main/java/com/cburch/logisim/std/io/Button.java +++ b/src/main/java/com/cburch/logisim/std/io/Button.java @@ -17,6 +17,7 @@ import com.cburch.logisim.data.Location; import com.cburch.logisim.data.Value; import com.cburch.logisim.instance.Instance; +import com.cburch.logisim.instance.InstanceData; import com.cburch.logisim.instance.InstanceDataSingleton; import com.cburch.logisim.instance.InstanceFactory; import com.cburch.logisim.instance.InstanceLogger; @@ -27,7 +28,6 @@ import com.cburch.logisim.instance.StdAttr; import com.cburch.logisim.util.GraphicsUtil; - import static com.cburch.logisim.util.LocaleString.*; public class Button extends InstanceFactory { @@ -87,6 +87,8 @@ protected void instanceAttributeChanged(Instance instance, Attribute attr) { computeTextField(instance); } else if (attr == Io.ATTR_LABEL_LOC) { computeTextField(instance); + } else if (attr == Button.ATTR_OUTPUT) { + instance.fireInvalidated(); } } @@ -132,7 +134,9 @@ private void computeTextField(Instance instance) { @Override public void propagate(InstanceState state) { InstanceDataSingleton data = (InstanceDataSingleton) state.getData(); - Value val = data == null ? Value.FALSE : (Value) data.getValue(); + + boolean pressed = data == null ? false : ((ButtonData)data.getValue()).getButtonState(); + Value val =ButtonStateToValue(pressed,state.getAttributeValue(Button.ATTR_OUTPUT)); state.setPort(0, val, 1); } @@ -144,12 +148,12 @@ public void paintInstance(InstancePainter painter) { int w = bds.getWidth(); int h = bds.getHeight(); - Value val; + boolean val; if (painter.getShowState()) { InstanceDataSingleton data = (InstanceDataSingleton) painter.getData(); - val = data == null ? Value.FALSE : (Value) data.getValue(); + val = data == null ? false : ((ButtonData)data.getValue()).getButtonState(); } else { - val = Value.FALSE; + val =false; } Color color = painter.getAttributeValue(Io.ATTR_COLOR); @@ -160,7 +164,7 @@ public void paintInstance(InstancePainter painter) { Graphics g = painter.getGraphics(); int depress; - if (val == ButtonStateToValue(true,painter.getAttributeValue(Button.ATTR_OUTPUT))) { + if (val == true) { x += DEPTH; y += DEPTH; Object labelLoc = painter.getAttributeValue(Io.ATTR_LABEL_LOC); @@ -242,20 +246,20 @@ else if((a==Button.OUTPUT_01) | (a==Button.OUTPUT_0Z)){ public static class Poker extends InstancePoker { @Override public void mousePressed(InstanceState state, MouseEvent e) { - setValue(state, ButtonStateToValue(true,state.getAttributeValue(Button.ATTR_OUTPUT))); + setValue(state, true); } @Override public void mouseReleased(InstanceState state, MouseEvent e) { - setValue(state, ButtonStateToValue(false,state.getAttributeValue(Button.ATTR_OUTPUT))); + setValue(state, false); } - private void setValue(InstanceState state, Value val) { + private void setValue(InstanceState state, boolean buttonState) { InstanceDataSingleton data = (InstanceDataSingleton) state.getData(); if (data == null) { - state.setData(new InstanceDataSingleton(val)); + state.setData(new InstanceDataSingleton(new ButtonData(buttonState,ButtonStateToValue(buttonState,state.getAttributeValue(Button.ATTR_OUTPUT))))); } else { - data.setValue(val); + data.setValue(new ButtonData(buttonState,ButtonStateToValue(buttonState,state.getAttributeValue(Button.ATTR_OUTPUT)))); } state.getInstance().fireInvalidated(); } @@ -270,7 +274,32 @@ public String getLogName(InstanceState state, Object option) { @Override public Value getLogValue(InstanceState state, Object option) { InstanceDataSingleton data = (InstanceDataSingleton) state.getData(); - return data == null ? Value.FALSE : (Value) data.getValue(); + return data == null ? Value.FALSE : ((ButtonData)data.getValue()).getOutValue(); } } } +//################ Added Class to transfer Value[] ########################### +class ButtonData implements InstanceData, Cloneable { + boolean buttonState; + Value outValue; + + @Override + public ButtonData clone() { + return clone(); + + } + + public ButtonData(boolean buttonState,Value outValue) { + this.buttonState = buttonState; + this.outValue = outValue; + } + + public Value getOutValue() { + return outValue; + } + + public boolean getButtonState() { + return buttonState; + } + +} From 1066909604c329d193ce020cffc03619986828f0 Mon Sep 17 00:00:00 2001 From: roy77 Date: Fri, 20 Mar 2015 12:46:15 +0100 Subject: [PATCH 06/11] New component Relais (in gates library) Simulate a relais. It was not possible with INOUT ports to detect the correct direction. Also it was not possible to define a switched wire between to ports. Therefore a parameter is used to set the switch direction. --- .../com/cburch/logisim/std/gates/Gates.java | 3 + .../com/cburch/logisim/std/gates/Relais.java | 401 ++++++++++++++++++ 2 files changed, 404 insertions(+) create mode 100644 src/main/java/com/cburch/logisim/std/gates/Relais.java diff --git a/src/main/java/com/cburch/logisim/std/gates/Gates.java b/src/main/java/com/cburch/logisim/std/gates/Gates.java index 791812eb..f2b009a1 100644 --- a/src/main/java/com/cburch/logisim/std/gates/Gates.java +++ b/src/main/java/com/cburch/logisim/std/gates/Gates.java @@ -7,8 +7,10 @@ import java.util.List; import com.cburch.logisim.tools.AddTool; +import com.cburch.logisim.tools.FactoryDescription; import com.cburch.logisim.tools.Library; import com.cburch.logisim.tools.Tool; + import static com.cburch.logisim.util.LocaleString.*; public class Gates extends Library { @@ -28,6 +30,7 @@ public Gates() { new AddTool(EvenParityGate.FACTORY), new AddTool(ControlledBuffer.FACTORY_BUFFER), new AddTool(ControlledBuffer.FACTORY_INVERTER), + new AddTool(Gates.class, new FactoryDescription("Relais", getFromLocale("relaisComponent"),"", "Relais")), }); } diff --git a/src/main/java/com/cburch/logisim/std/gates/Relais.java b/src/main/java/com/cburch/logisim/std/gates/Relais.java new file mode 100644 index 00000000..c96fb3e5 --- /dev/null +++ b/src/main/java/com/cburch/logisim/std/gates/Relais.java @@ -0,0 +1,401 @@ +/* Copyright (c) 2010, Carl Burch. License information is located in the + * com.cburch.logisim.Main source code and at www.cburch.com/logisim/. */ + +package com.cburch.logisim.std.gates; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.util.HashMap; +import java.util.Map; + +import com.cburch.logisim.LogisimVersion; +import com.cburch.logisim.analyze.model.Expression; +import com.cburch.logisim.analyze.model.Expressions; +import com.cburch.logisim.circuit.Circuit; +import com.cburch.logisim.circuit.ExpressionComputer; +import com.cburch.logisim.circuit.SplitterFactory; +import com.cburch.logisim.comp.TextField; +import com.cburch.logisim.data.Attribute; +import com.cburch.logisim.data.AttributeOption; +import com.cburch.logisim.data.AttributeSet; +import com.cburch.logisim.data.Attributes; +import com.cburch.logisim.data.Bounds; +import com.cburch.logisim.data.Direction; +import com.cburch.logisim.data.Location; +import com.cburch.logisim.data.Value; +import com.cburch.logisim.instance.Instance; +import com.cburch.logisim.instance.InstanceFactory; +import com.cburch.logisim.instance.InstanceData; +import com.cburch.logisim.instance.InstancePainter; +import com.cburch.logisim.instance.InstanceState; +import com.cburch.logisim.instance.Port; +import com.cburch.logisim.instance.StdAttr; +import com.cburch.logisim.prefs.AppPreferences; +import com.cburch.logisim.std.io.Button; +import com.cburch.logisim.std.io.Io; +import com.cburch.logisim.std.io.Button.Logger; +import com.cburch.logisim.std.io.Button.Poker; +import com.cburch.logisim.tools.WireRepair; +import com.cburch.logisim.tools.WireRepairData; +import com.cburch.logisim.util.GraphicsUtil; + +import static com.cburch.logisim.util.LocaleString.*; + +public class Relais extends InstanceFactory { + static final int DELAY = 10; + static final int DELAY2 = 1; + static final int SIZE = 40; + + static final AttributeOption PORT0IN=new AttributeOption("0",getFromLocale("Port0 Input")); + static final AttributeOption PORT0OUT= new AttributeOption("1",getFromLocale("Port0 Output")); + public static final Attribute ATTR_DIRECTION=Attributes.forOption("PortInput", + getFromLocale("Select switch direction"), + new AttributeOption[]{PORT0IN,PORT0OUT}); + + public Relais() { + super("Relais", getFromLocale("relaisComponent")); + setAttributes(new Attribute[] { + StdAttr.FACING, + StdAttr.LABEL, + StdAttr.LABEL_FONT, + Relais.ATTR_DIRECTION + }, new Object[] { + Direction.EAST, + "", + StdAttr.DEFAULT_LABEL_FONT, + Relais.PORT0IN + }); + setFacingAttribute(StdAttr.FACING); + } + + protected void paintShape(InstancePainter painter, int width, int height) { + AttributeSet attrs = painter.getAttributeSet(); + boolean direction; + if(attrs.getValue(Relais.ATTR_DIRECTION)==PORT0IN) direction=false; + else direction=true; + + RelaisData data = (RelaisData) painter.getData(); + painter.drawRectangle(0, 0, width, height, ""); + Graphics g = painter.getGraphics(); + + // draw infield sticks + g.drawLine(width / 2, 0, width / 2, 4); + g.drawLine(width / 2, height - 4, width / 2, height); + g.drawLine(width*3/4, height - 4, width*3/4, height); + + + if (data != null) { + boolean active = data.getValue(); + Value state = data.getSwitch(); + + g.setColor(state.getColor()); + + // draw switching stick + if (active) { + drawArrowLine(g,width / 2, 4, width*3/4, height - 4,8,4,direction); + } else { + drawArrowLine(g,width / 2, 4, width / 2, height - 4,8,4,direction); + } + } + }// paint shape + + private void drawArrowLine(Graphics g, int xx1, int yy1, int xx2, int yy2, int d, int h,boolean dir){ + int x1;int x2;int y1;int y2; + + if(dir){ + x1=xx2;x2=xx1;y1=yy2;y2=yy1; + }else{ + x1=xx1;x2=xx2;y1=yy1;y2=yy2; + } + + int dx = x2 - x1, dy = y2 - y1; + double D = Math.sqrt(dx*dx + dy*dy); + double xm = D - d, xn = xm, ym = h, yn = -h, x; + double sin = dy/D, cos = dx/D; + + x = xm*cos - ym*sin + x1; + ym = xm*sin + ym*cos + y1; + xm = x; + + x = xn*cos - yn*sin + x1; + yn = xn*sin + yn*cos + y1; + xn = x; + + int[] xpoints = {x2, (int) xm, (int) xn}; + int[] ypoints = {y2, (int) ym, (int) yn}; + + g.drawLine(x1, y1, x2, y2); + g.fillPolygon(xpoints, ypoints, 3); + } + + + @Override + public Bounds getOffsetBounds(AttributeSet attrsBase) { + Direction facing = attrsBase.getValue(StdAttr.FACING); + int width = SIZE; + + int height = Math.max(30 , width); + if (facing == Direction.SOUTH) { + return Bounds.create(-height, 0, height, width); + } else if (facing == Direction.NORTH) { + return Bounds.create(0, -width, height, width); + } else if (facing == Direction.WEST) { + return Bounds.create(-width, -height, width, height); + } else { + return Bounds.create(0, 0, width, height); + } + } + + @Override + public void paintInstance(InstancePainter painter) { + paintBase(painter); + if (!painter.isPrintView() + || painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) { + painter.drawPorts(); + } + } + + + private void paintBase(InstancePainter painter) { + AttributeSet attrs = painter.getAttributeSet(); + Direction facing = attrs.getValue(StdAttr.FACING); + Location loc = painter.getLocation(); + Bounds bds = painter.getOffsetBounds(); + int width = bds.getWidth(); + int height = bds.getHeight(); + if (facing == Direction.NORTH || facing == Direction.SOUTH) { + int t = width; + width = height; + height = t; + } + + + Graphics g = painter.getGraphics(); + Color baseColor = g.getColor(); + + g.setColor(baseColor); + g.translate(loc.getX(), loc.getY()); + double rotate = 0.0; + if (facing != Direction.EAST && g instanceof Graphics2D) { + rotate = -facing.toRadians(); + Graphics2D g2 = (Graphics2D) g; + g2.rotate(rotate); + } + + + paintShape(painter, width, height); + + if (rotate != 0.0) { + ((Graphics2D) g).rotate(-rotate); + } + g.translate(-loc.getX(), -loc.getY()); + + painter.drawLabel(); + } + + @Override + protected void configureNewInstance(Instance instance) { + instance.addAttributeListener(); + computePorts(instance); + computeLabel(instance); + } + + @Override + protected void instanceAttributeChanged(Instance instance, Attribute attr) { + if ((attr == StdAttr.FACING)||(attr == Relais.ATTR_DIRECTION)) { + instance.recomputeBounds(); + computePorts(instance); + computeLabel(instance); + } + } + + private void computeLabel(Instance instance) { + AttributeSet attrs = (AttributeSet) instance.getAttributeSet(); + Direction facing = attrs.getValue(StdAttr.FACING); + int baseWidth = SIZE; + + int axis = baseWidth / 2; + int perp = 0; + if (AppPreferences.GATE_SHAPE.get().equals( + AppPreferences.SHAPE_RECTANGULAR)) { + perp += 6; + } + Location loc = instance.getLocation(); + int cx; + int cy; + if (facing == Direction.NORTH) { + cx = loc.getX() + perp; + cy = loc.getY() + axis; + } else if (facing == Direction.SOUTH) { + cx = loc.getX() - perp; + cy = loc.getY() - axis; + } else if (facing == Direction.WEST) { + cx = loc.getX() + axis; + cy = loc.getY() - perp; + } else { + cx = loc.getX() - axis; + cy = loc.getY() + perp; + } + instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, cx, cy, + TextField.H_CENTER, TextField.V_CENTER); + } + + void computePorts(Instance instance) { + AttributeSet attrs = (AttributeSet) instance.getAttributeSet(); + Direction facing = attrs.getValue(StdAttr.FACING); + + Bounds bds = instance.getBounds(); + int width = bds.getWidth(); + int height = bds.getHeight(); + + String Typ0=Port.OUTPUT; + String Typ3=Port.INPUT; + String Typ4=Port.INPUT; + + if(attrs.getValue(Relais.ATTR_DIRECTION)==PORT0IN){ + Typ0=Port.INPUT; + Typ3=Port.OUTPUT; + Typ4=Port.OUTPUT; + } + + + Port[] ports = new Port[2 + 3]; + + // ####################OUTPUTS################################ + if (facing == Direction.SOUTH) { + ports[0] = new Port(0, height / 2, Typ0, 1); + ports[3] = new Port(-width, height / 2, Typ3,1); + ports[4] = new Port(-width, height - 10, Typ4,1); + } else if (facing == Direction.NORTH) { + ports[0] = new Port(0, -height / 2, Typ0, 1); + ports[3] = new Port(width, -height / 2, Typ3,1); + ports[4] = new Port(width, -height + 10, Typ4,1); + } else if (facing == Direction.WEST) { + ports[0] = new Port(-width / 2, 0, Typ0, 1); + ports[3] = new Port(-width / 2, -height, Typ3,1); + ports[4] = new Port(-width + 10, -height, Typ4,1); + } else { + ports[0] = new Port(width / 2, 0, Typ0, 1); + ports[3] = new Port(width / 2, height, Typ3,1); + ports[4] = new Port(width - 10, height, Typ4,1); + } + + // ###################Port label########################################################## + ports[0].setToolTip("port0"); + ports[3].setToolTip("port3"); + ports[4].setToolTip("port4"); + + // ###############################INPUTS######################################### + for (int i = 0; i < 2; i++) { + Location offs = getInputOffset(attrs, i); + ports[i + 1] = new Port(offs.getX(), offs.getY(), Port.INPUT, 1); + } + + instance.setPorts(ports); + + }// compute Ports + + + @Override + public void propagate(InstanceState state) { + AttributeSet attrs = (AttributeSet) state.getAttributeSet(); + + boolean RelaisActive= ((state.getPort(1) == Value.FALSE)&&(state.getPort(2) == Value.TRUE))|| + ((state.getPort(2) == Value.FALSE)&&(state.getPort(1) == Value.TRUE)); + + if(attrs.getValue(Relais.ATTR_DIRECTION)==PORT0IN){ + state.setData(new RelaisData(RelaisActive,state.getPort(0))); + if( RelaisActive ){ + state.setPort(3, Value.NIL, DELAY2); + state.setPort(4, state.getPort(0), DELAY); + state.setPort(0, Value.NIL, DELAY2); + } else{ + state.setPort(4, Value.NIL, DELAY2); + state.setPort(3, state.getPort(0), DELAY); + state.setPort(0, Value.NIL, DELAY2); + } + } else { + if( RelaisActive ){ + state.setData(new RelaisData(RelaisActive,state.getPort(4))); + state.setPort(3, Value.NIL, DELAY2); + state.setPort(0, state.getPort(4), DELAY); + state.setPort(4, Value.NIL, DELAY2); + } else{ + state.setData(new RelaisData(RelaisActive,state.getPort(3))); + state.setPort(4, Value.NIL, DELAY2); + state.setPort(0, state.getPort(3), DELAY); + state.setPort(3, Value.NIL, DELAY2); + } + + } + + } // propagate + + Location getInputOffset(AttributeSet attrs, int index) { + Direction facing = attrs.getValue(StdAttr.FACING); + int size = SIZE; + + int skipStart; + int skipDist; + int skipLowerEven = 10; + + if (size <= 40) { + skipStart = 5; // -5 + skipDist = 10; + skipLowerEven = 10; + } else if (size < 60) { + skipStart = -10; + skipDist = 20; + skipLowerEven = 20; + } else { + skipStart = -15; + skipDist = 30; + skipLowerEven = 30; + } + + + int dy = skipStart * 2 + skipDist * index; + if (index == 1) { + dy += skipLowerEven; + } + + if (facing == Direction.NORTH) { + return Location.create(dy, 0); + } else if (facing == Direction.SOUTH) { + return Location.create(-dy, 0); + } else if (facing == Direction.WEST) { + return Location.create(0, -dy); + } else { + return Location.create(0, dy); + } + } + +} +//################ Added Class to transfer Value[] ########################### +class RelaisData implements InstanceData, Cloneable { + boolean active; + Value switchVal; + + @Override + public RelaisData clone() { + return clone(); + + } + + public RelaisData(boolean active,Value switchVal) { + this.active = active; + this.switchVal = switchVal; + } + + public Value getSwitch() { + return switchVal; + } + + public boolean getValue() { + return active; + } + +} From 1f75f45bd4bac2007318c9c7af2d5d6212c4572c Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 9 Jun 2015 09:25:13 +0200 Subject: [PATCH 07/11] Solved Issue #85 Edit Circuit Apperance not working --- .../java/com/cburch/draw/canvas/Canvas.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/cburch/draw/canvas/Canvas.java b/src/main/java/com/cburch/draw/canvas/Canvas.java index 6189e7dc..ef09be73 100644 --- a/src/main/java/com/cburch/draw/canvas/Canvas.java +++ b/src/main/java/com/cburch/draw/canvas/Canvas.java @@ -71,18 +71,18 @@ public void setModel(CanvasModel value, ActionDispatcher dispatcher) { if (oldValue != null) { if (!oldValue.equals(value)) { oldValue.removeCanvasModelListener(listener); - - model = value; - this.dispatcher = dispatcher; - if (value != null) { - value.addCanvasModelListener(listener); - } - - selection.clearSelected(); - repaint(); - firePropertyChange(MODEL_PROPERTY, oldValue, value); } } + model = value; + this.dispatcher = dispatcher; + if (value != null) { + value.addCanvasModelListener(listener); + } + + selection.clearSelected(); + repaint(); + firePropertyChange(MODEL_PROPERTY, oldValue, value); + } public void setTool(CanvasTool value) { From 9aba48d608455e0b43c11e37fa4d42182c478f75 Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 9 Jun 2015 19:24:31 +0200 Subject: [PATCH 08/11] Zoom Appearance Subcircuit with mouse wheel when CTRL is pressed --- .../java/com/cburch/draw/canvas/Canvas.java | 1 + .../com/cburch/draw/canvas/CanvasListener.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cburch/draw/canvas/Canvas.java b/src/main/java/com/cburch/draw/canvas/Canvas.java index ef09be73..d6cb1688 100644 --- a/src/main/java/com/cburch/draw/canvas/Canvas.java +++ b/src/main/java/com/cburch/draw/canvas/Canvas.java @@ -32,6 +32,7 @@ public Canvas() { addMouseListener(listener); addMouseMotionListener(listener); + addMouseWheelListener(listener); addKeyListener(listener); setPreferredSize(new Dimension(200, 200)); } diff --git a/src/main/java/com/cburch/draw/canvas/CanvasListener.java b/src/main/java/com/cburch/draw/canvas/CanvasListener.java index 8d93d1c5..05b4acf0 100644 --- a/src/main/java/com/cburch/draw/canvas/CanvasListener.java +++ b/src/main/java/com/cburch/draw/canvas/CanvasListener.java @@ -10,14 +10,17 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import java.util.List; import com.cburch.draw.model.CanvasModelEvent; import com.cburch.draw.model.CanvasModelListener; import com.cburch.draw.model.CanvasObject; import com.cburch.logisim.data.Location; +import com.cburch.logisim.gui.generic.ZoomControl; -class CanvasListener implements MouseListener, MouseMotionListener, KeyListener, +class CanvasListener implements MouseListener, MouseMotionListener, KeyListener, MouseWheelListener, CanvasModelListener { private Canvas canvas; private CanvasTool tool; @@ -67,6 +70,18 @@ public void mousePressed(MouseEvent e) { } } + @Override + public void mouseWheelMoved(MouseWheelEvent arg0) { + if(arg0.isControlDown()) { + if(arg0.getPreciseWheelRotation() < 0) { + ZoomControl.spinnerModel.setValue(ZoomControl.spinnerModel.getNextValue()); + } else if(arg0.getPreciseWheelRotation() > 0){ + ZoomControl.spinnerModel.setValue(ZoomControl.spinnerModel.getPreviousValue()); + } + } + + } + @Override public void mouseDragged(MouseEvent e) { if (isButton1(e)) { From 7d28c4cc138aa54de4f5f081cff4c75c0f962bdb Mon Sep 17 00:00:00 2001 From: Admin Date: Wed, 30 Sep 2015 12:57:14 +0200 Subject: [PATCH 09/11] Bugfix in Memory Writing If a smaller file is loaded after loading a big file the memory was filled with 0. The data was written, but loading the rest with 0 result in loading all with 0 because of the bug in load method --- src/main/java/com/cburch/logisim/std/memory/MemContentsSub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cburch/logisim/std/memory/MemContentsSub.java b/src/main/java/com/cburch/logisim/std/memory/MemContentsSub.java index 025610f7..281f4598 100644 --- a/src/main/java/com/cburch/logisim/std/memory/MemContentsSub.java +++ b/src/main/java/com/cburch/logisim/std/memory/MemContentsSub.java @@ -215,7 +215,7 @@ void clear() { @Override void load(int start, int[] values, int mask) { int n = Math.min(values.length, data.length - start); - for (int i = 0; i < n; i++) { + for (int i = start; i < n; i++) { data[i] = values[i] & mask; } } From 7bcbddc7e012a0013d7ce4afdbcc718df5da4c51 Mon Sep 17 00:00:00 2001 From: roy77 Date: Fri, 2 Dec 2016 14:38:14 +0100 Subject: [PATCH 10/11] Take changes --- README.md | 4 + build.gradle | 9 +- .../java/com/cburch/draw/canvas/Canvas.java | 29 +- .../cburch/draw/canvas/CanvasListener.java | 17 +- .../java/com/cburch/logisim/circuit/Wire.java | 2 +- .../cburch/logisim/std/arith/Arithmetic.java | 2 + .../com/cburch/logisim/std/arith/Pow.java | 99 ++++ .../com/cburch/logisim/tools/PokeTool.java | 12 +- .../logisim/tools/PopUpLabelAction.java | 302 ++++++++++ .../com/cburch/logisim/tools/SelectTool.java | 13 +- .../com/cburch/logisim/tools/WiringTool.java | 8 +- .../DefaultFontSelectionModel.java | 169 ++++++ .../swing/fontchooser/FontChooserDialog.form | 110 ++++ .../swing/fontchooser/FontChooserDialog.java | 162 ++++++ .../swing/fontchooser/FontSelectionModel.java | 82 +++ .../swing/fontchooser/JFontChooser.form | 209 +++++++ .../swing/fontchooser/JFontChooser.java | 537 ++++++++++++++++++ .../JFontChooserBeanDescriptor.java | 39 ++ .../fontchooser/JFontChooserBeanInfo.java | 76 +++ .../swing/fontchooser/package-info.java | 22 + src/main/resources/logisim/default.templ | 2 +- src/main/resources/logisim/icons/pow.svg | 12 + 22 files changed, 1872 insertions(+), 45 deletions(-) create mode 100644 src/main/java/com/cburch/logisim/std/arith/Pow.java create mode 100644 src/main/java/com/cburch/logisim/tools/PopUpLabelAction.java create mode 100644 src/main/java/com/connectina/swing/fontchooser/DefaultFontSelectionModel.java create mode 100644 src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.form create mode 100644 src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.java create mode 100644 src/main/java/com/connectina/swing/fontchooser/FontSelectionModel.java create mode 100644 src/main/java/com/connectina/swing/fontchooser/JFontChooser.form create mode 100644 src/main/java/com/connectina/swing/fontchooser/JFontChooser.java create mode 100644 src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanDescriptor.java create mode 100644 src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanInfo.java create mode 100644 src/main/java/com/connectina/swing/fontchooser/package-info.java create mode 100644 src/main/resources/logisim/icons/pow.svg diff --git a/README.md b/README.md index 7a5ec852..129f493c 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ Logisim's user interface has numerous gotchas that need to be addressed. Here's It is arguably the best free/libre and gratis tool for teaching circuit design. That is why its development must continue. +## Newest GitHub build +If you just want to test the newest developer version to report issues or for new features, download it here. +[![Build Status](http://84.201.35.242:8080/job/LOGISIM/badge/icon)](http://mechtecs.tk:8080/job/LOGISIM/) +[Download](http://84.201.35.242:8080/job/LOGISIM/) ## Getting started for developers The build script recognizes the following commands: diff --git a/build.gradle b/build.gradle index 6733f2de..c86a7642 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ apply plugin: 'sonar-runner' if (System.properties['os.name'].toLowerCase().contains('mac')) { apply plugin: 'macAppBundle' - + macAppBundle { mainClassName = "com.cburch.logisim.Main" icon = "LogisimApp.icns" @@ -65,18 +65,14 @@ buildscript { repositories { mavenCentral() - maven { - url 'http://nexus.gephi.org/nexus/content/repositories/public' - } } dependencies { compile \ 'javax.help:javahelp:2.0.05', - 'com.connectina.swing:fontchooser:1.0', 'net.sourceforge.collections:collections-generic:4.01', 'org.apache.xmlgraphics:batik-svggen:1.7', - 'org.apache.xmlgraphics:batik-swing:1.7', + 'org.apache.xmlgraphics:batik-swing:1.7', // Native JDK logger (java.util.logging) //'org.slf4j:slf4j-jdk14:1.7.5', @@ -135,4 +131,3 @@ processResources << { } } } - diff --git a/src/main/java/com/cburch/draw/canvas/Canvas.java b/src/main/java/com/cburch/draw/canvas/Canvas.java index d6cb1688..466020c8 100644 --- a/src/main/java/com/cburch/draw/canvas/Canvas.java +++ b/src/main/java/com/cburch/draw/canvas/Canvas.java @@ -32,7 +32,6 @@ public Canvas() { addMouseListener(listener); addMouseMotionListener(listener); - addMouseWheelListener(listener); addKeyListener(listener); setPreferredSize(new Dimension(200, 200)); } @@ -69,21 +68,21 @@ public void doAction(Action action) { public void setModel(CanvasModel value, ActionDispatcher dispatcher) { CanvasModel oldValue = model; - if (oldValue != null) { - if (!oldValue.equals(value)) { - oldValue.removeCanvasModelListener(listener); - } + if (!oldValue.equals(value)) { + if (oldValue != null) { + oldValue.removeCanvasModelListener(listener); + } + + model = value; + this.dispatcher = dispatcher; + if (value != null) { + value.addCanvasModelListener(listener); + } + + selection.clearSelected(); + repaint(); + firePropertyChange(MODEL_PROPERTY, oldValue, value); } - model = value; - this.dispatcher = dispatcher; - if (value != null) { - value.addCanvasModelListener(listener); - } - - selection.clearSelected(); - repaint(); - firePropertyChange(MODEL_PROPERTY, oldValue, value); - } public void setTool(CanvasTool value) { diff --git a/src/main/java/com/cburch/draw/canvas/CanvasListener.java b/src/main/java/com/cburch/draw/canvas/CanvasListener.java index 05b4acf0..8d93d1c5 100644 --- a/src/main/java/com/cburch/draw/canvas/CanvasListener.java +++ b/src/main/java/com/cburch/draw/canvas/CanvasListener.java @@ -10,17 +10,14 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; import java.util.List; import com.cburch.draw.model.CanvasModelEvent; import com.cburch.draw.model.CanvasModelListener; import com.cburch.draw.model.CanvasObject; import com.cburch.logisim.data.Location; -import com.cburch.logisim.gui.generic.ZoomControl; -class CanvasListener implements MouseListener, MouseMotionListener, KeyListener, MouseWheelListener, +class CanvasListener implements MouseListener, MouseMotionListener, KeyListener, CanvasModelListener { private Canvas canvas; private CanvasTool tool; @@ -70,18 +67,6 @@ public void mousePressed(MouseEvent e) { } } - @Override - public void mouseWheelMoved(MouseWheelEvent arg0) { - if(arg0.isControlDown()) { - if(arg0.getPreciseWheelRotation() < 0) { - ZoomControl.spinnerModel.setValue(ZoomControl.spinnerModel.getNextValue()); - } else if(arg0.getPreciseWheelRotation() > 0){ - ZoomControl.spinnerModel.setValue(ZoomControl.spinnerModel.getPreviousValue()); - } - } - - } - @Override public void mouseDragged(MouseEvent e) { if (isButton1(e)) { diff --git a/src/main/java/com/cburch/logisim/circuit/Wire.java b/src/main/java/com/cburch/logisim/circuit/Wire.java index 5d1d1c34..1c644cf9 100644 --- a/src/main/java/com/cburch/logisim/circuit/Wire.java +++ b/src/main/java/com/cburch/logisim/circuit/Wire.java @@ -30,7 +30,7 @@ public final class Wire implements Component, AttributeSet, CustomHandles, Iterable { /** Stroke width when drawing wires. */ - public static final int WIDTH = 1; + public static final int WIDTH = 3; public static final AttributeOption VALUE_HORZ = new AttributeOption("horz", getFromLocale("wireDirectionHorzOption")); diff --git a/src/main/java/com/cburch/logisim/std/arith/Arithmetic.java b/src/main/java/com/cburch/logisim/std/arith/Arithmetic.java index 23be1197..e6a6020e 100644 --- a/src/main/java/com/cburch/logisim/std/arith/Arithmetic.java +++ b/src/main/java/com/cburch/logisim/std/arith/Arithmetic.java @@ -30,6 +30,8 @@ public class Arithmetic extends Library { "bitadder.svg", "BitAdder"), new FactoryDescription("BitFinder", getFromLocale("bitFinderComponent"), "bitfindr.svg", "BitFinder"), + new FactoryDescription("Pow", getFromLocale("powComponent"), + "pow.svg", "Pow"), }; private List tools = null; diff --git a/src/main/java/com/cburch/logisim/std/arith/Pow.java b/src/main/java/com/cburch/logisim/std/arith/Pow.java new file mode 100644 index 00000000..23aebd83 --- /dev/null +++ b/src/main/java/com/cburch/logisim/std/arith/Pow.java @@ -0,0 +1,99 @@ +/* Copyright (c) 2010, Carl Burch. License information is located in the + * com.cburch.logisim.Main source code and at www.cburch.com/logisim/. + * Written by Mechtecs*/ + +package com.cburch.logisim.std.arith; + +import java.awt.Color; +import java.awt.Graphics; + +import com.cburch.logisim.data.Attribute; +import com.cburch.logisim.data.BitWidth; +import com.cburch.logisim.data.Bounds; +import com.cburch.logisim.data.Location; +import com.cburch.logisim.data.Value; +import com.cburch.logisim.instance.InstanceFactory; +import com.cburch.logisim.instance.InstancePainter; +import com.cburch.logisim.instance.InstanceState; +import com.cburch.logisim.instance.Port; +import com.cburch.logisim.instance.StdAttr; +import com.cburch.logisim.tools.key.BitWidthConfigurator; +import com.cburch.logisim.util.GraphicsUtil; + +import static com.cburch.logisim.util.LocaleString.*; + +public class Pow extends InstanceFactory { + static final int PER_DELAY = 1; + + private static final int IN0 = 0; + private static final int IN1 = 1; + private static final int OUT = 2; + + public Pow() { + super("Pow", getFromLocale("powComponent")); + setAttributes(new Attribute[] { + StdAttr.WIDTH + }, new Object[] { + BitWidth.create(8) + }); + + setKeyConfigurator(new BitWidthConfigurator(StdAttr.WIDTH)); + setOffsetBounds(Bounds.create(-40, -20, 40, 40)); + setIconName("pow.svg"); + + Port[] ps = new Port[3]; + ps[IN0] = new Port(-40, 10, Port.INPUT, StdAttr.WIDTH); + ps[IN1] = new Port(-40, -10, Port.INPUT, StdAttr.WIDTH); + ps[OUT] = new Port( 0, 0, Port.OUTPUT, StdAttr.WIDTH); + ps[IN0].setToolTip(getFromLocale("powInputNumTip")); + ps[IN1].setToolTip(getFromLocale("powInputExpTip")); + ps[OUT].setToolTip(getFromLocale("powOutputTip")); + setPorts(ps); + } + + @Override + public void propagate(InstanceState state) { + // get attributes + BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH); + + // compute outputs + Value a = state.getPort(IN0); + Value b = state.getPort(IN1); + Value[] outs = Pow.computeSum(dataWidth, a, b); + + // propagate them + int delay = (dataWidth.getWidth() + 2) * PER_DELAY; + state.setPort(OUT, outs[0], delay); + } + + @Override + public void paintInstance(InstancePainter painter) { + Graphics g = painter.getGraphics(); + painter.drawBounds(); + + g.setColor(Color.GRAY); + painter.drawPort(IN0); + painter.drawPort(IN1); + painter.drawPort(OUT); + Location loc = painter.getLocation(); + int x = loc.getX(); + int y = loc.getY(); + GraphicsUtil.switchToWidth(g, 2); + g.setColor(Color.BLACK); + g.drawLine(x - 25, y, x - 35, y + 10 ); + g.drawLine(x - 25, y + 10, x - 35, y); + g.drawLine(x - 20, y - 10, x - 15, y - 5); + g.drawLine(x - 20, y + 5, x - 10, y - 10); + GraphicsUtil.switchToWidth(g, 1); + } + + static Value[] computeSum(BitWidth width, Value a, Value b) { //Useless functions and data type conversion because java :) + int ia = a.toIntValue(); + int ib = b.toIntValue(); + double da=ia; + double db=ib; + double dequus = Math.pow(da,db); + int equus = (int) Math.round(dequus); + return new Value[] { Value.createKnown(width, equus) }; + } +} diff --git a/src/main/java/com/cburch/logisim/tools/PokeTool.java b/src/main/java/com/cburch/logisim/tools/PokeTool.java index 69cc02cd..5606dbeb 100644 --- a/src/main/java/com/cburch/logisim/tools/PokeTool.java +++ b/src/main/java/com/cburch/logisim/tools/PokeTool.java @@ -264,7 +264,17 @@ public void paintIcon(ComponentDrawContext c, int x, int y) { toolIcon.paintIcon(c.getDestination(), g, x + 2, y + 2); } else { g.setColor(java.awt.Color.black); - // TODO explain the values + /* + * The code below draws two arrows. It's only executed if the icon of the PokeTool is not available. + * 1st segment is arrow down. + * L1 Line Up Down | + * L2 Line Mid Left Mid Down \ + * L3 Line Mid Right Mid Down / + * 2nd segment is arrow up. + * L1 Line Up Down | + * L2 Line Mid Left Mid Up / + * L3 Line Mid Right Mid Up \ + */ g.drawLine(x + 4, y + 2, x + 4, y + 17); g.drawLine(x + 4, y + 17, x + 1, y + 11); g.drawLine(x + 4, y + 17, x + 7, y + 11); diff --git a/src/main/java/com/cburch/logisim/tools/PopUpLabelAction.java b/src/main/java/com/cburch/logisim/tools/PopUpLabelAction.java new file mode 100644 index 00000000..71ceba4b --- /dev/null +++ b/src/main/java/com/cburch/logisim/tools/PopUpLabelAction.java @@ -0,0 +1,302 @@ +/* Copyright (c) 2010, Carl Burch. License information is located in the + * com.cburch.logisim.Main source code and at www.cburch.com/logisim/. */ + +package com.cburch.logisim.tools; + +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowFocusListener; +import java.util.Set; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JTextField; +import javax.swing.border.Border; + +import com.cburch.logisim.comp.Component; +import com.cburch.logisim.data.Attribute; +import com.cburch.logisim.data.AttributeSet; +import com.cburch.logisim.gui.main.Selection; +import com.cburch.logisim.instance.StdAttr; +import com.cburch.logisim.proj.Action; +import com.cburch.logisim.proj.Project; +import com.cburch.logisim.std.base.Text; + +/** + * This {@link Action} allows for pop up labeling of components. This class was designed with + * the intention of adding the feature of double click labeling to Logisim. + * @author Drew E. Buckley + * + */ +public class PopUpLabelAction extends Action { + + private static class LabelFrame extends JFrame { + + private class LabelProcedure implements Runnable { + private final AttributeSet as; + private final Project proj; + private final Attribute attrId; + + LabelProcedure(AttributeSet as, Project proj, Attribute attrId) { + this.as = as; + this.proj = proj; + this.attrId = attrId; + } + + @Override + public void run() { + String label = null; + try { + label = promptForLabel(); + } + catch (InterruptedException e) { + return; + } + if (label != null) { + as.setValue(attrId, label); + proj.repaintCanvas(); + } + } + } + + private class PopUpFocusListener implements WindowFocusListener { + @Override + public void windowLostFocus(WindowEvent e) { + newLabel = textArea.getText(); + LabelFrame.this.dispose(); + setActive(false); + } + + @Override + public void windowGainedFocus(WindowEvent e) { + // Empty + } + } + + private class LabelFrameKeyListener implements KeyListener + { + private boolean specialBackspace = false; + + @Override + public void keyTyped(KeyEvent e) { + resize(); + } + + @Override + public void keyReleased(KeyEvent e) { + if(specialBackspace) { + resize(); + } + } + + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) + == KeyEvent.CTRL_DOWN_MASK || + textArea.getSelectionStart() + - textArea.getSelectionEnd() != 0) { + specialBackspace = true; + } + } + else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + newLabel = textArea.getText(); + LabelFrame.this.dispose(); + setActive(false); + } + } + + + } + + private static final long serialVersionUID = -8072223959722789844L; + private static final int HEIGHT = 25; + private static final int FONT_MARGIN = 25; + private static final Border BORDER = BorderFactory.createLineBorder(Color.BLACK, 1); + + private final JTextField textArea; + private final Attribute attrId; + + private volatile String newLabel = null; + private volatile boolean active = false; + + private final int x, y; + private FontMetrics fm = null; + + LabelFrame(int x, int y, String label, Attribute attrId) { + setType(Type.UTILITY); + setUndecorated(true); + addWindowFocusListener(new PopUpFocusListener()); + + textArea = new JTextField(label); + textArea.setVisible(true); + textArea.setBorder(BORDER); + textArea.setHorizontalAlignment(JTextField.CENTER); + textArea.addKeyListener(new LabelFrameKeyListener()); + add(textArea); + + this.attrId = attrId; + this.x = x; + this.y = y; + } + + void launchLabelProcedure(AttributeSet as, Project proj) { + Thread thread = new Thread(new LabelProcedure(as, proj, attrId)); + thread.setDaemon(true); + thread.setName("PopUpLabel-Procedure-Thread"); + thread.start(); + } + + String promptForLabel() throws InterruptedException { + setActive(true); + setVisible(true); + textArea.setSelectionStart(0); + textArea.setSelectionEnd(textArea.getText().length()); + resize(); + spinUntilInactive(); + return newLabel; + } + + private void spinUntilInactive() throws InterruptedException { + while (active) { + Thread.sleep(100); + } + } + + private void setActive(boolean newActiveState) { + active = newActiveState; + } + + private void resize() + { + if( fm == null ) { + this.fm = textArea.getGraphics().getFontMetrics(textArea.getFont()); + } + int width = fm.stringWidth(textArea.getText()) + FONT_MARGIN; + int newX = x - (width / 2); + + setLocation(newX, y - (HEIGHT / 2)); + setSize(width, HEIGHT); + + revalidate(); + repaint(); + } + } + + private final int x; + private final int y; + private final AttributeSet as; + private final String formerLabel; + private final Attribute attrId; + + private PopUpLabelAction(int x, int y, AttributeSet as, + String currentLabel, Attribute attrId ) { + this.x = x; + this.y = y; + this.as = as; + this.formerLabel = currentLabel; + this.attrId = attrId; + } + + @Override + public String getName() { + return this.getClass().getName(); + } + + @Override + public void doIt(Project proj) { + LabelFrame lf = new LabelFrame(x, y, formerLabel, attrId); + lf.launchLabelProcedure(as, proj); + } + + @Override + public void undo(Project proj) { + as.setValue(attrId, formerLabel); + } + + /** + * Sets up action and adds to project if selection contains only 1 component and + * selected component has label attribute. If the component does not possess a + * label attribute, or selection is empty or contains multiple components, this + * function does nothing. + * + * @param proj + * current {@link Project} object + * @param selection + * selection to pull component from + * @param xAbs + * absolute display x value + * @param yAbs + * absolute display y value + * @throws IllegalArgumentException + * if proj or selection are null + * @throws IllegalArgumentException + * if xAbs or yAbs are negative + */ + public static void triggerLabel(Project proj, Selection selection, int xAbs, + int yAbs) { + if (proj == null || selection == null) { + throw new IllegalArgumentException( + "Function \"DoubleClickLabelAction.turnOnLabel\" does not accept " + + "null parameters."); + } + if (xAbs < 0 || yAbs < 0) { + throw new IllegalArgumentException( + "xAbs and yAbs must be greater than zero."); + } + + Set components = selection.getComponents(); + Component component; + if (components.size() != 1) { + return; + } else { + component = components.iterator().next(); + } + triggerLabel(proj, component, xAbs, yAbs); + } + + /** + * Sets up action and adds to project if selected component has label attribute. + * If the component does not possess a label attribute, this function does nothing. + * + * @param proj + * current {@link Project} object + * @param component + * {@link Component} to change label of + * @param xAbs + * absolute display x value + * @param yAbs + * absolute display y value + * + * @throws IllegalArgumentException + * if proj or component are null + * @throws IllegalArgumentException + * if xAbs or yAbs are negative + */ + public static void triggerLabel(Project proj, Component component, int xAbs, int yAbs) { + if(proj == null || component == null ) { + throw new IllegalArgumentException( + "Function \"DoubleClickLabelAction.turnOnLabel\" does not accept " + + "null parameters."); + } + if (xAbs < 0 || yAbs < 0) { + throw new IllegalArgumentException( + "xAbs and yAbs must be greater than zero."); + } + + AttributeSet as = component.getAttributeSet(); + String currentLabel = as.getValue(StdAttr.LABEL); + if (currentLabel != null) { + proj.doAction(new PopUpLabelAction(xAbs, yAbs, as, currentLabel, StdAttr.LABEL)); + } + else { + currentLabel = as.getValue(Text.ATTR_TEXT); + if (currentLabel != null) { + proj.doAction(new PopUpLabelAction(xAbs, yAbs, as, currentLabel, Text.ATTR_TEXT)); + } + } + } +} diff --git a/src/main/java/com/cburch/logisim/tools/SelectTool.java b/src/main/java/com/cburch/logisim/tools/SelectTool.java index 5d52bc3d..90903edb 100644 --- a/src/main/java/com/cburch/logisim/tools/SelectTool.java +++ b/src/main/java/com/cburch/logisim/tools/SelectTool.java @@ -27,6 +27,7 @@ import com.cburch.logisim.gui.main.Selection; import com.cburch.logisim.gui.main.SelectionActions; import com.cburch.logisim.gui.main.Selection.Event; +import com.cburch.logisim.instance.StdAttr; import com.cburch.logisim.prefs.AppPreferences; import com.cburch.logisim.proj.Action; import com.cburch.logisim.proj.Project; @@ -38,12 +39,14 @@ import com.cburch.logisim.tools.move.MoveRequestListener; import com.cburch.logisim.util.GraphicsUtil; import com.cburch.logisim.util.Icons; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; + import static com.cburch.logisim.util.LocaleString.*; public class SelectTool extends Tool { @@ -237,15 +240,19 @@ public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) { Collection in_sel = sel.getComponentsContaining(start, g); if (!in_sel.isEmpty()) { if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) { + if (e.getClickCount() == 2) { //double click event + PopUpLabelAction.triggerLabel(proj, sel, + e.getXOnScreen(), e.getYOnScreen()); + } setState(proj, MOVING); proj.repaintCanvas(); return; } Action act = SelectionActions.drop(sel, in_sel); - if (act != null) { - proj.doAction(act); - } + if (act != null) { + proj.doAction(act); + } } // if the user clicks into a component outside selection, user diff --git a/src/main/java/com/cburch/logisim/tools/WiringTool.java b/src/main/java/com/cburch/logisim/tools/WiringTool.java index 95aac38d..13705c78 100644 --- a/src/main/java/com/cburch/logisim/tools/WiringTool.java +++ b/src/main/java/com/cburch/logisim/tools/WiringTool.java @@ -452,7 +452,13 @@ public void paintIcon(ComponentDrawContext c, int x, int y) { toolIcon.paintIcon(c.getDestination(), g, x + 2, y + 2); } else { g.setColor(java.awt.Color.black); - // TODO explain the values + /* + * Wiring Tool under basics + * Icon: + * 2nd Line: Box Left + * 3rd Line: Box Right + * 1st Line: Connection between Boxes + */ g.drawLine(x + 3, y + 13, x + 17, y + 7); g.fillOval(x + 1, y + 11, 5, 5); g.fillOval(x + 15, y + 5, 5, 5); diff --git a/src/main/java/com/connectina/swing/fontchooser/DefaultFontSelectionModel.java b/src/main/java/com/connectina/swing/fontchooser/DefaultFontSelectionModel.java new file mode 100644 index 00000000..2407c584 --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/DefaultFontSelectionModel.java @@ -0,0 +1,169 @@ +/* + * A font chooser JavaBean component. + * Copyright (C) 2009 Dr Christos Bohoris + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 3 as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * swing@connectina.com + */ +package com.connectina.swing.fontchooser; + +import java.awt.Font; +import java.awt.GraphicsEnvironment; +import java.util.ArrayList; +import java.util.List; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.EventListenerList; + +/** + * A generic implementation of FontSelectionModel. + * + * @author Christos Bohoris + * @see java.awt.Font + */ +public class DefaultFontSelectionModel implements FontSelectionModel { + + /** + * Only one ChangeEvent is needed per model instance + * since the event's only (read-only) state is the source property. + * The source of events generated here is always "this". + */ + protected transient ChangeEvent changeEvent = null; + + /** + * A list of registered event listeners. + */ + protected EventListenerList listenerList = new EventListenerList(); + + private Font selectedFont; + + private List availableFontNames = new ArrayList(); + + /** + * Creates a DefaultFontSelectionModel with the + * current font set to new Font(Font.SANS_SERIF, Font.PLAIN, 12) + * . This is the default constructor. + */ + public DefaultFontSelectionModel() { + this(new Font(JFontChooser.SANS_SERIF, Font.PLAIN, 12)); + } + + /** + * Creates a DefaultFontSelectionModel with the + * current font set to font, which should be + * non-null. Note that setting the font to + * null is undefined and may have unpredictable + * results. + * + * @param font the new Font + */ + public DefaultFontSelectionModel(Font font) { + selectedFont = font; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + String[] families = ge.getAvailableFontFamilyNames(); + for(int i = 0; i < families.length; i++) { + availableFontNames.add(families[i]); + } + } + + /** + * Returns the selected Font which should be + * non-null. + * + * @return the selected Font + */ + public Font getSelectedFont() { + return selectedFont; + } + + /** + * Sets the selected font to font. + * Note that setting the font to null + * is undefined and may have unpredictable results. + * This method fires a state changed event if it sets the + * current font to a new non-null font; + * if the new font is the same as the current font, + * no event is fired. + * + * @param font the new Font + */ + public void setSelectedFont(Font font) { + if (font != null && !selectedFont.equals(font)) { + selectedFont = font; + fireStateChanged(); + } + } + + /** + * Gets the available font names. + * Returns a list containing the names of all font families in this + * GraphicsEnvironment localized for the default locale, + * as returned by Locale.getDefault(). + * + * @return a list of String containing font family names localized for the + * default locale, or a suitable alternative name if no name exists + * for this locale + */ + public List getAvailableFontNames() { + return availableFontNames; + } + + /** + * Adds a ChangeListener to the model. + * + * @param l the ChangeListener to be added + */ + public void addChangeListener(ChangeListener l) { + listenerList.add(ChangeListener.class, l); + } + + /** + * Removes a ChangeListener from the model. + * @param l the ChangeListener to be removed + */ + public void removeChangeListener(ChangeListener l) { + listenerList.remove(ChangeListener.class, l); + } + + /** + * Returns an array of all the ChangeListeners added + * to this DefaultFontSelectionModel with + * addChangeListener. + * + * @return all of the ChangeListeners added, or an empty + * array if no listeners have been added + */ + public ChangeListener[] getChangeListeners() { + return (ChangeListener[]) listenerList.getListeners( + ChangeListener.class); + } + + /** + * Runs each ChangeListener's + * stateChanged method. + */ + protected void fireStateChanged() { + Object[] listeners = listenerList.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ChangeListener.class) { + if (changeEvent == null) { + changeEvent = new ChangeEvent(this); + } + ((ChangeListener) listeners[i + 1]).stateChanged(changeEvent); + } + } + } + +} diff --git a/src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.form b/src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.form new file mode 100644 index 00000000..e93e4fa9 --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.form @@ -0,0 +1,110 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.java b/src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.java new file mode 100644 index 00000000..f86824b0 --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/FontChooserDialog.java @@ -0,0 +1,162 @@ +/* + * A font chooser JavaBean component. + * Copyright (C) 2009 Dr Christos Bohoris + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 3 as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * swing@connectina.com + */ +package com.connectina.swing.fontchooser; + +import java.awt.HeadlessException; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.HashMap; +import java.util.Locale; +import java.util.ResourceBundle; +import javax.swing.JDialog; +import javax.swing.JFrame; + +/** + * A dialog containing a JFontChooser as well as OK and + * Cancel buttons. + * + * @author Christos Bohoris + */ +class FontChooserDialog extends javax.swing.JDialog { + + private static final long serialVersionUID = -953666562985797384L; + + private static final HashMap bundles + = new HashMap(); + + private static ResourceBundle getBundle() { + Locale loc = Locale.getDefault(); + ResourceBundle ret = bundles.get(loc); + if (ret == null) { + ret = ResourceBundle.getBundle("resources/connectina/FontChooserDialog"); + bundles.put(loc, ret); + } + return ret; + } + + private JFontChooser chooserPane; + + FontChooserDialog(JFrame owner, boolean modal, + JFontChooser chooserPane, ActionListener selectionListener) + throws HeadlessException { + super(owner, modal); + initDialog(chooserPane, selectionListener); + } + + FontChooserDialog(JDialog owner, boolean modal, + JFontChooser chooserPane, ActionListener selectionListener) + throws HeadlessException { + super(owner, modal); + initDialog(chooserPane, selectionListener); + } + + private void initDialog(JFontChooser chooserPane, ActionListener selectionListener) { + this.chooserPane = chooserPane; + initComponents(getBundle()); + okButton.addActionListener(selectionListener); + okButton.addActionListener(new OKActionListener()); + cancelButton.addActionListener(new CancelActionListener()); + addWindowListener(new FontChooserDialogAdapter()); + getRootPane().setDefaultButton(okButton); + okButton.requestFocusInWindow(); + } + + private class FontChooserDialogAdapter extends WindowAdapter { + + // @Override + public void windowClosing(WindowEvent event) { + dispose(); + } + + } + + private class OKActionListener implements ActionListener { + + public void actionPerformed(ActionEvent e) { + dispose(); + } + + } + + private class CancelActionListener implements ActionListener { + + public void actionPerformed(ActionEvent e) { + dispose(); + } + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents(ResourceBundle bundle) { + + basePanel = new javax.swing.JPanel(); + chooserPanel = new javax.swing.JPanel(); + chooserSeparator = new javax.swing.JSeparator(); + controlPanel = new javax.swing.JPanel(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setTitle(bundle.getString("window.title")); + + basePanel.setLayout(new java.awt.BorderLayout()); + + chooserPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 0, 11)); + chooserPanel.setLayout(new java.awt.BorderLayout(0, 12)); + chooserPanel.add(chooserSeparator, java.awt.BorderLayout.PAGE_END); + + basePanel.add(chooserPanel, java.awt.BorderLayout.CENTER); + chooserPanel.add(chooserPane, java.awt.BorderLayout.CENTER); + + controlPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(7, 7, 6, 6)); + controlPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); + + okButton.setMnemonic(bundle.getString("action.ok.mnemonic").charAt(0)); + okButton.setText(bundle.getString("action.ok")); + controlPanel.add(okButton); + + cancelButton.setMnemonic(bundle.getString("action.cancel.mnemonic").charAt(0)); + cancelButton.setText(bundle.getString("action.cancel")); + controlPanel.add(cancelButton); + + basePanel.add(controlPanel, java.awt.BorderLayout.SOUTH); + + getContentPane().add(basePanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel basePanel; + private javax.swing.JButton cancelButton; + private javax.swing.JPanel chooserPanel; + private javax.swing.JSeparator chooserSeparator; + private javax.swing.JPanel controlPanel; + private javax.swing.JButton okButton; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/com/connectina/swing/fontchooser/FontSelectionModel.java b/src/main/java/com/connectina/swing/fontchooser/FontSelectionModel.java new file mode 100644 index 00000000..3ab9ce6f --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/FontSelectionModel.java @@ -0,0 +1,82 @@ +/* + * A font chooser JavaBean component. + * Copyright (C) 2009 Dr Christos Bohoris + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 3 as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * swing@connectina.com + */ +package com.connectina.swing.fontchooser; + +import java.awt.Font; +import java.util.List; +import javax.swing.event.ChangeListener; + +/** + * A model that supports selecting a Font. + * + * @author Christos Bohoris + * @see java.awt.Font + */ +public interface FontSelectionModel { + + /** + * Returns the selected Font which should be + * non-null. + * + * @return the selected Font + * @see #setSelectedFont + */ + Font getSelectedFont(); + + /** + * Sets the selected font to font. + * Note that setting the font to null + * is undefined and may have unpredictable results. + * This method fires a state changed event if it sets the + * current font to a new non-null font. + * + * @param font the new Font + * @see #getSelectedFont + * @see #addChangeListener + */ + void setSelectedFont(Font font); + + /** + * Gets the available font names. + * Returns a list containing the names of all font families in this + * GraphicsEnvironment localized for the default locale, + * as returned by Locale.getDefault(). + * + * @return a list of String containing font family names localized for the + * default locale, or a suitable alternative name if no name exists + * for this locale + */ + List getAvailableFontNames(); + + /** + * Adds listener as a listener to changes in the model. + * + * @param listener the ChangeListener to be added + */ + void addChangeListener(ChangeListener listener); + + /** + * Removes listener as a listener to changes in the model. + * + * @param listener the ChangeListener to be removed + */ + void removeChangeListener(ChangeListener listener); + +} diff --git a/src/main/java/com/connectina/swing/fontchooser/JFontChooser.form b/src/main/java/com/connectina/swing/fontchooser/JFontChooser.form new file mode 100644 index 00000000..3390dad7 --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/JFontChooser.form @@ -0,0 +1,209 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/connectina/swing/fontchooser/JFontChooser.java b/src/main/java/com/connectina/swing/fontchooser/JFontChooser.java new file mode 100644 index 00000000..185b51ec --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/JFontChooser.java @@ -0,0 +1,537 @@ +/* + * A font chooser JavaBean component. + * Copyright (C) 2009 Dr Christos Bohoris + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 3 as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * swing@connectina.com + */ +package com.connectina.swing.fontchooser; + +import java.awt.Dimension; +import java.awt.Font; +import java.awt.HeadlessException; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.ResourceBundle; +import javax.swing.DefaultListModel; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * Provides a pane of controls designed to allow a user to + * select a Font. + * + * @author Christos Bohoris + * @see java.awt.Font + */ +public class JFontChooser extends JPanel { + static final String SANS_SERIF = "SansSerif"; + private static final long serialVersionUID = 5157499702004637097L; + private static final HashMap bundles + = new HashMap(); + + private static ResourceBundle getBundle() { + Locale loc = Locale.getDefault(); + ResourceBundle ret = bundles.get(loc); + if (ret == null) { + ret = ResourceBundle.getBundle("resources/connectina/JFontChooser"); + bundles.put(loc, ret); + } + return ret; + } + + private FontSelectionModel selectionModel; + /** + * The selection model property name. + */ + public static final String SELECTION_MODEL_PROPERTY = "selectionModel"; + + /** + * Creates a FontChooser pane with an initial default Font + * (Sans Serif, Plain, 12). + */ + public JFontChooser() { + this(new Font(SANS_SERIF, Font.PLAIN, 12)); + } + + /** + * Creates a FontChooser pane with the specified initial Font. + * + * @param initialFont the initial Font set in the chooser + */ + public JFontChooser(Font initialFont) { + this(new DefaultFontSelectionModel(initialFont)); + } + + /** + * Creates a FontChooser pane with the specified + * FontSelectionModel. + * + * @param model the FontSelectionModel to be used + */ + public JFontChooser(FontSelectionModel model) { + this.selectionModel = model; + ResourceBundle bundle = getBundle(); + initComponents(bundle); + initPanel(bundle); + } + + /** + * Gets the current Font value from the FontChooser. + * By default, this delegates to the model. + * + * @return the current Font value of the FontChooser + */ + public Font getSelectedFont() { + return selectionModel.getSelectedFont(); + } + + /** + * Sets the current Font of the FontChooser to the specified Font. + * The FontSelectionModel will fire a ChangeEvent + * @param Font the Font to be set in the Font chooser + * @see JComponent#addPropertyChangeListener + */ + public void setSelectedFont(Font Font) { + selectionModel.setSelectedFont(Font); + } + + /** + * Returns the data model that handles Font selections. + * + * @return a FontSelectionModel object + */ + public FontSelectionModel getSelectionModel() { + return selectionModel; + } + + /** + * Sets the model containing the selected Font. + * + * @param newModel the new FontSelectionModel object + */ + public void setSelectionModel(FontSelectionModel newModel) { + FontSelectionModel oldModel = selectionModel; + selectionModel = newModel; + firePropertyChange(JFontChooser.SELECTION_MODEL_PROPERTY, oldModel, newModel); + } + + /** + * Shows a modal FontChooser dialog and blocks until the + * dialog is hidden. If the user presses the "OK" button, then + * this method hides/disposes the dialog and returns the selected Font. + * If the user presses the "Cancel" button or closes the dialog without + * pressing "OK", then this method hides/disposes the dialog and returns + * null. + * + * @param parent the parent JFrame for the dialog + * @param initialFont the initial Font set when the FontChooser is shown + * @return the selected Font or null if the user opted out + * @exception HeadlessException if GraphicsEnvironment.isHeadless() + * returns true. + * @see java.awt.GraphicsEnvironment#isHeadless + */ + public static Font showDialog(Window parent, Font initialFont) throws HeadlessException { + final JFontChooser pane = new JFontChooser(initialFont != null ? initialFont : new Font(SANS_SERIF, Font.PLAIN, 12)); + + FontSelectionActionListener selectionListener = new FontSelectionActionListener(pane); + JDialog dialog = createDialog(parent, true, pane, selectionListener); + + dialog.setLocationRelativeTo(parent); + dialog.setVisible(true); + + return selectionListener.getFont(); + } + + /** + * Shows a modal FontChooser dialog and blocks until the + * dialog is hidden. If the user presses the "OK" button, then + * this method hides/disposes the dialog and returns the selected Font. + * If the user presses the "Cancel" button or closes the dialog without + * pressing "OK", then this method hides/disposes the dialog and returns + * null. + * + * @param parent the parent JFrame for the dialog + * @param fontChooser the FontChooser to be use in this dialog + * @param initialFont the initial Font set when the FontChooser is shown + * @return the selected Font or null if the user opted out + * @exception HeadlessException if GraphicsEnvironment.isHeadless() + * returns true. + * @see java.awt.GraphicsEnvironment#isHeadless + */ + public static Font showDialog(Window parent, JFontChooser fontChooser, Font initialFont) throws HeadlessException { + fontChooser.setSelectedFont(initialFont != null ? initialFont : new Font(SANS_SERIF, Font.PLAIN, 12)); + + FontSelectionActionListener selectionListener = new FontSelectionActionListener(fontChooser); + JDialog dialog = createDialog(parent, true, fontChooser, selectionListener); + + dialog.setLocationRelativeTo(parent); + dialog.setVisible(true); + + return selectionListener.getFont(); + } + + /** + * Creates and returns a new dialog containing the specified + * FontChooser pane along with "OK" and "Cancel" + * buttons. If the "OK" or "Cancel" buttons are pressed, the dialog is + * automatically hidden (but not disposed). + * + * @param parent the parent component for the dialog + * @param modal a boolean. When true, the remainder of the program + * is inactive until the dialog is closed. + * @param chooserPane the Font-chooser to be placed inside the dialog + * @param okListener the ActionListener invoked when "OK" is pressed + * @return a new dialog containing the FontChooser pane + * @exception HeadlessException if GraphicsEnvironment.isHeadless() + * returns true. + * @see java.awt.GraphicsEnvironment#isHeadless + */ + public static JDialog createDialog(Window parent, boolean modal, + JFontChooser chooserPane, ActionListener okListener) throws HeadlessException { + if (parent instanceof JDialog) { + return new FontChooserDialog((JDialog) parent, modal, chooserPane, + okListener); + } else if (parent instanceof JFrame) { + return new FontChooserDialog((JFrame) parent, modal, chooserPane, + okListener); + } else { + throw new IllegalArgumentException("JFrame or JDialog parent is required."); + } + } + + /** + * Adds a ChangeListener to the model. + * + * @param l the ChangeListener to be added + */ + public void addChangeListener(ChangeListener l) { + selectionModel.addChangeListener(l); + } + + /** + * Removes a ChangeListener from the model. + * @param l the ChangeListener to be removed + */ + public void removeChangeListener(ChangeListener l) { + selectionModel.removeChangeListener(l); + } + + private void initPanel(ResourceBundle bundle) { + // Set the font family names + DefaultListModel listModel = new DefaultListModel(); + for(Iterator it = selectionModel.getAvailableFontNames().iterator(); + it.hasNext(); ) { + listModel.addElement(it.next()); + } + familyList.setModel(listModel); + familyList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + familyList.setSelectedValue(selectionModel.getSelectedFont().getName(), true); + familyList.addListSelectionListener(new FamilyListSelectionListener()); + + // Set the font styles + listModel = new DefaultListModel(); + + listModel.addElement(getFontStyleName(Font.PLAIN, bundle)); + listModel.addElement(getFontStyleName(Font.BOLD, bundle)); + listModel.addElement(getFontStyleName(Font.ITALIC, bundle)); + listModel.addElement(getFontStyleName(Font.BOLD + Font.ITALIC, bundle)); + styleList.setModel(listModel); + styleList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + styleList.setSelectedIndex(selectionModel.getSelectedFont().getStyle()); + styleList.addListSelectionListener(new StyleListSelectionListener()); + + // Set the font sizes + listModel = new DefaultListModel(); + int size = 6; + int step = 1; + int ceil = 14; + do { + listModel.addElement(Integer.valueOf(size)); + if (size == ceil) { + ceil += ceil; + step += step; + } + size = size + step; + } while (size <= 128); + + sizeList.setModel(listModel); + sizeList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + Integer selectedSize = Integer.valueOf(selectionModel.getSelectedFont().getSize()); + if (listModel.contains(selectedSize)) { + sizeList.setSelectedValue(selectedSize, true); + } + sizeList.addListSelectionListener(new SizeListSelectionListener()); + sizeSpinner.addChangeListener(new SizeSpinnerListener()); + sizeSpinner.setValue(selectedSize); + previewAreaLabel.setFont(selectionModel.getSelectedFont()); + previewAreaLabel.setText(bundle.getString("font.preview.text")); + } + + private String getFontStyleName(int index, ResourceBundle bundle) { + String result = null; + switch (index) { + case 0: + result = bundle.getString("style.plain"); + break; + case 1: + result = bundle.getString("style.bold"); + break; + case 2: + result = bundle.getString("style.italic"); + break; + case 3: + result = bundle.getString("style.bolditalic"); + break; + default: + result = bundle.getString("style.plain"); + } + + return result; + } + + private class FamilyListSelectionListener implements ListSelectionListener { + + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + Font sel = new Font(familyList.getSelectedValue().toString(), + styleList.getSelectedIndex(), + Integer.parseInt(sizeSpinner.getValue().toString())); + selectionModel.setSelectedFont(sel); + previewAreaLabel.setFont(selectionModel.getSelectedFont()); + } + } + } + + private class StyleListSelectionListener implements ListSelectionListener { + + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + selectionModel.setSelectedFont(selectionModel.getSelectedFont().deriveFont(styleList.getSelectedIndex())); + + previewAreaLabel.setFont(selectionModel.getSelectedFont()); + } + } + } + + private class SizeListSelectionListener implements ListSelectionListener { + + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + int index = ((DefaultListModel) sizeList.getModel()).indexOf(sizeList.getSelectedValue()); + if (index > -1) { + sizeSpinner.setValue((Integer) sizeList.getSelectedValue()); + } + float newSize = Float.parseFloat(sizeSpinner.getValue().toString()); + Font newFont = selectionModel.getSelectedFont().deriveFont(newSize); + selectionModel.setSelectedFont(newFont); + + previewAreaLabel.setFont(selectionModel.getSelectedFont()); + } + } + } + + private class SizeSpinnerListener implements ChangeListener { + + public void stateChanged(ChangeEvent e) { + Integer value = (Integer) sizeSpinner.getValue(); + int index = ((DefaultListModel) sizeList.getModel()).indexOf(value); + if (index > -1) { + sizeList.setSelectedValue(value, true); + } else { + sizeList.clearSelection(); + } + } + } + + private static class FontSelectionActionListener implements ActionListener, Serializable { + + private static final long serialVersionUID = 8141913945783951693L; + private JFontChooser chooser; + private Font font; + + public FontSelectionActionListener(JFontChooser c) { + chooser = c; + } + + public void actionPerformed(ActionEvent e) { + font = chooser.getSelectedFont(); + } + + public Font getFont() { + return font; + } + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + //Java5 @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents(ResourceBundle bundle) { + java.awt.GridBagConstraints gridBagConstraints; + + fontPanel = new javax.swing.JPanel(); + familyLabel = new javax.swing.JLabel(); + styleLabel = new javax.swing.JLabel(); + sizeLabel = new javax.swing.JLabel(); + familyScrollPane = new javax.swing.JScrollPane(); + familyList = new javax.swing.JList(); + styleScrollPane = new javax.swing.JScrollPane(); + styleList = new javax.swing.JList(); + sizeSpinner = new javax.swing.JSpinner(); + int spinnerHeight = (int)sizeSpinner.getPreferredSize().getHeight(); + sizeSpinner.setPreferredSize(new Dimension(60, spinnerHeight)); + sizeScrollPane = new javax.swing.JScrollPane(); + sizeList = new javax.swing.JList(); + previewPanel = new javax.swing.JPanel(); + previewLabel = new javax.swing.JLabel(); + previewAreaPanel = new javax.swing.JPanel(); + previewAreaLabel = new javax.swing.JLabel(); + + setLayout(new java.awt.BorderLayout()); + + fontPanel.setLayout(new java.awt.GridBagLayout()); + + familyLabel.setLabelFor(familyList); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 11); + fontPanel.add(familyLabel, gridBagConstraints); + + styleLabel.setLabelFor(styleList); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 11); + fontPanel.add(styleLabel, gridBagConstraints); + + sizeLabel.setLabelFor(sizeList); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0); + fontPanel.add(sizeLabel, gridBagConstraints); + + familyScrollPane.setMinimumSize(new java.awt.Dimension(80, 50)); + familyScrollPane.setPreferredSize(new java.awt.Dimension(240, 150)); + familyScrollPane.setViewportView(familyList); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 1; + gridBagConstraints.gridheight = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); + fontPanel.add(familyScrollPane, gridBagConstraints); + + styleScrollPane.setMinimumSize(new java.awt.Dimension(60, 120)); + styleScrollPane.setPreferredSize(new java.awt.Dimension(80, 150)); + styleScrollPane.setViewportView(styleList); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 1; + gridBagConstraints.gridheight = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11); + fontPanel.add(styleScrollPane, gridBagConstraints); + + sizeSpinner.setModel(new javax.swing.SpinnerNumberModel(12, 6, 128, 1)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 1; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0); + fontPanel.add(sizeSpinner, gridBagConstraints); + + sizeScrollPane.setMinimumSize(new java.awt.Dimension(50, 120)); + sizeScrollPane.setPreferredSize(new java.awt.Dimension(60, 150)); + sizeScrollPane.setViewportView(sizeList); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0); + fontPanel.add(sizeScrollPane, gridBagConstraints); + + add(fontPanel, java.awt.BorderLayout.CENTER); + familyLabel.setDisplayedMnemonic(bundle.getString("font.family.mnemonic").charAt(0)); + familyLabel.setText(bundle.getString("font.family")); + styleLabel.setDisplayedMnemonic(bundle.getString("font.style.mnemonic").charAt(0)); + styleLabel.setText(bundle.getString("font.style")); + sizeLabel.setDisplayedMnemonic(bundle.getString("font.size.mnemonic").charAt(0)); + sizeLabel.setText(bundle.getString("font.size")); + previewLabel.setDisplayedMnemonic(bundle.getString("font.preview.mnemonic").charAt(0)); + previewLabel.setText(bundle.getString("font.preview")); + + previewPanel.setLayout(new java.awt.GridBagLayout()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0); + previewPanel.add(previewLabel, gridBagConstraints); + + previewAreaPanel.setBackground(new java.awt.Color(255, 255, 255)); + previewAreaPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); + previewAreaPanel.setPreferredSize(new java.awt.Dimension(200, 80)); + previewAreaPanel.setLayout(new java.awt.BorderLayout()); + + previewAreaLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + previewAreaPanel.add(previewAreaLabel, java.awt.BorderLayout.CENTER); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 1; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + previewPanel.add(previewAreaPanel, gridBagConstraints); + + add(previewPanel, java.awt.BorderLayout.SOUTH); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel familyLabel; + private javax.swing.JList familyList; + private javax.swing.JScrollPane familyScrollPane; + private javax.swing.JPanel fontPanel; + private javax.swing.JLabel previewAreaLabel; + private javax.swing.JPanel previewAreaPanel; + private javax.swing.JLabel previewLabel; + private javax.swing.JPanel previewPanel; + private javax.swing.JLabel sizeLabel; + private javax.swing.JList sizeList; + private javax.swing.JScrollPane sizeScrollPane; + private javax.swing.JSpinner sizeSpinner; + private javax.swing.JLabel styleLabel; + private javax.swing.JList styleList; + private javax.swing.JScrollPane styleScrollPane; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanDescriptor.java b/src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanDescriptor.java new file mode 100644 index 00000000..fd61f8a0 --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanDescriptor.java @@ -0,0 +1,39 @@ +/* + * A font chooser JavaBean component. + * Copyright (C) 2009 Dr Christos Bohoris + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 3 as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * swing@connectina.com + */ +package com.connectina.swing.fontchooser; + +import java.beans.BeanDescriptor; + +/** + * The bean descriptor for the JFontChooser JavaBean. + * + * @author Christos Bohoris + * @see JFontChooser + */ +public class JFontChooserBeanDescriptor extends BeanDescriptor { + + public JFontChooserBeanDescriptor() { + super(JFontChooser.class); + setShortDescription("com.connectina.fontchooser.JFontChooser
A font selection pane."); + setDisplayName("Font Chooser"); + setPreferred(true); + } + +} diff --git a/src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanInfo.java b/src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanInfo.java new file mode 100644 index 00000000..7e469202 --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/JFontChooserBeanInfo.java @@ -0,0 +1,76 @@ +/* + * A font chooser JavaBean component. + * Copyright (C) 2009 Dr Christos Bohoris + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 3 as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * swing@connectina.com + */ +package com.connectina.swing.fontchooser; + +import java.awt.Image; +import java.beans.*; + +/** + * The bean information for the JFontChooser JavaBean. + * + * @author Christos Bohoris + * @see JFontChooser + */ +public class JFontChooserBeanInfo extends SimpleBeanInfo { + + /* 16x16 color icon. */ + private final Image iconColor16 = loadImage("resources/connectina/FontChooser16Color.png"); + /* 32x32 color icon. */ + private final Image iconColor32 = loadImage("resources/connectina/FontChooser32Color.png"); + /* 16x16 mono icon. */ + private final Image iconMono16 = loadImage("resources/connectina/FontChooser16Mono.png"); + /* 32x32 mono icon. */ + private final Image iconMono32 = loadImage("resources/connectina/FontChooser32Mono.png"); + /* The bean descriptor. */ + private JFontChooserBeanDescriptor descriptor = new JFontChooserBeanDescriptor(); + + /** + * Get the bean descriptor. + * + * @return the bean descriptor + */ + //Java5 @Override + public BeanDescriptor getBeanDescriptor() { + return descriptor; + } + + /** + * Get the appropriate icon. + * + * @param iconKind the icon kind + * @return the image + */ + //Java5 @Override + public Image getIcon(int iconKind) { + switch (iconKind) { + case ICON_COLOR_16x16: + return iconColor16; + case ICON_COLOR_32x32: + return iconColor32; + case ICON_MONO_16x16: + return iconMono16; + case ICON_MONO_32x32: + return iconMono32; + } + + return null; + } + +} diff --git a/src/main/java/com/connectina/swing/fontchooser/package-info.java b/src/main/java/com/connectina/swing/fontchooser/package-info.java new file mode 100644 index 00000000..79c46d68 --- /dev/null +++ b/src/main/java/com/connectina/swing/fontchooser/package-info.java @@ -0,0 +1,22 @@ +/** + *
 Provides a Swing font chooser JavaBean component.
+ * 
+ * Copyright (C) 2009 Dr Christos Bohoris
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 3 as published by the Free Software Foundation;
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * swing@connectina.com
+ */ +package com.connectina.swing.fontchooser; + diff --git a/src/main/resources/logisim/default.templ b/src/main/resources/logisim/default.templ index 4f6bed9a..0695f96e 100644 --- a/src/main/resources/logisim/default.templ +++ b/src/main/resources/logisim/default.templ @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/logisim/icons/pow.svg b/src/main/resources/logisim/icons/pow.svg new file mode 100644 index 00000000..ac0db30c --- /dev/null +++ b/src/main/resources/logisim/icons/pow.svg @@ -0,0 +1,12 @@ + + + image/svg+xml + + Layer 1 + + + + X + n + + \ No newline at end of file From e0e1312dfba464882d25c71940930369085df187 Mon Sep 17 00:00:00 2001 From: roy77 Date: Fri, 2 Dec 2016 15:06:26 +0100 Subject: [PATCH 11/11] Edit Circuit Apperance not working --- .../java/com/cburch/draw/canvas/Canvas.java | 239 +++++++++--------- 1 file changed, 120 insertions(+), 119 deletions(-) diff --git a/src/main/java/com/cburch/draw/canvas/Canvas.java b/src/main/java/com/cburch/draw/canvas/Canvas.java index 466020c8..41796018 100644 --- a/src/main/java/com/cburch/draw/canvas/Canvas.java +++ b/src/main/java/com/cburch/draw/canvas/Canvas.java @@ -17,123 +17,124 @@ @SuppressWarnings("serial") public class Canvas extends JComponent { - public static final String TOOL_PROPERTY = "tool"; - public static final String MODEL_PROPERTY = "model"; - - private CanvasModel model; - private ActionDispatcher dispatcher; - private CanvasListener listener; - private Selection selection; - - public Canvas() { - model = null; - listener = new CanvasListener(this); - selection = new Selection(); - - addMouseListener(listener); - addMouseMotionListener(listener); - addKeyListener(listener); - setPreferredSize(new Dimension(200, 200)); - } - - public CanvasModel getModel() { - return model; - } - - public CanvasTool getTool() { - return listener.getTool(); - } - - public void toolGestureComplete(CanvasTool tool, CanvasObject created) { - // nothing to do - subclass may override - } - - protected JPopupMenu showPopupMenu(MouseEvent e, CanvasObject clicked) { - // subclass will override if it supports popup menus - return null; - } - - public Selection getSelection() { - return selection; - } - - protected void setSelection(Selection value) { - selection = value; - repaint(); - } - - public void doAction(Action action) { - dispatcher.doAction(action); - } - - public void setModel(CanvasModel value, ActionDispatcher dispatcher) { - CanvasModel oldValue = model; - if (!oldValue.equals(value)) { - if (oldValue != null) { - oldValue.removeCanvasModelListener(listener); - } - - model = value; - this.dispatcher = dispatcher; - if (value != null) { - value.addCanvasModelListener(listener); - } - - selection.clearSelected(); - repaint(); - firePropertyChange(MODEL_PROPERTY, oldValue, value); - } - } - - public void setTool(CanvasTool value) { - CanvasTool oldValue = listener.getTool(); - if (!value.equals(oldValue)) { - listener.setTool(value); - firePropertyChange(TOOL_PROPERTY, oldValue, value); - } - } - - public void repaintCanvasCoords(int x, int y, int width, int height) { - repaint(x, y, width, height); - } - - public double getZoomFactor() { - // subclass will have to override this - return 1.0; - } - - public int snapX(int x) { - // subclass will have to override this - return x; - } - - public int snapY(int y) { - // subclass will have to override this - return y; - } - - @Override - public void paintComponent(Graphics g) { - paintBackground(g); - paintForeground(g); - } - - protected void paintBackground(Graphics g) { - g.clearRect(0, 0, getWidth(), getHeight()); - } - - protected void paintForeground(Graphics g) { - CanvasModel cModel = this.model; - CanvasTool tool = listener.getTool(); - if (cModel != null) { - Graphics dup = g.create(); - cModel.paint(g, selection); - dup.dispose(); - } - if (tool != null) { - Graphics dup = g.create(); - tool.draw(this, dup); - dup.dispose(); - } - } + public static final String TOOL_PROPERTY = "tool"; + public static final String MODEL_PROPERTY = "model"; + + private CanvasModel model; + private ActionDispatcher dispatcher; + private CanvasListener listener; + private Selection selection; + + public Canvas() { + model = null; + listener = new CanvasListener(this); + selection = new Selection(); + + addMouseListener(listener); + addMouseMotionListener(listener); + addKeyListener(listener); + setPreferredSize(new Dimension(200, 200)); + } + + public CanvasModel getModel() { + return model; + } + + public CanvasTool getTool() { + return listener.getTool(); + } + + public void toolGestureComplete(CanvasTool tool, CanvasObject created) { + // nothing to do - subclass may override + } + + protected JPopupMenu showPopupMenu(MouseEvent e, CanvasObject clicked) { + // subclass will override if it supports popup menus + return null; + } + + public Selection getSelection() { + return selection; + } + + protected void setSelection(Selection value) { + selection = value; + repaint(); + } + + public void doAction(Action action) { + dispatcher.doAction(action); + } + + public void setModel(CanvasModel value, ActionDispatcher dispatcher) { + CanvasModel oldValue = model; + if (oldValue != null) { + if (!oldValue.equals(value)) { + oldValue.removeCanvasModelListener(listener); + } + } + model = value; + this.dispatcher = dispatcher; + if (value != null) { + value.addCanvasModelListener(listener); + } + + selection.clearSelected(); + repaint(); + + if (oldValue == null) + firePropertyChange(MODEL_PROPERTY, oldValue, value); + } + + public void setTool(CanvasTool value) { + CanvasTool oldValue = listener.getTool(); + if (!value.equals(oldValue)) { + listener.setTool(value); + firePropertyChange(TOOL_PROPERTY, oldValue, value); + } + } + + public void repaintCanvasCoords(int x, int y, int width, int height) { + repaint(x, y, width, height); + } + + public double getZoomFactor() { + // subclass will have to override this + return 1.0; + } + + public int snapX(int x) { + // subclass will have to override this + return x; + } + + public int snapY(int y) { + // subclass will have to override this + return y; + } + + @Override + public void paintComponent(Graphics g) { + paintBackground(g); + paintForeground(g); + } + + protected void paintBackground(Graphics g) { + g.clearRect(0, 0, getWidth(), getHeight()); + } + + protected void paintForeground(Graphics g) { + CanvasModel cModel = this.model; + CanvasTool tool = listener.getTool(); + if (cModel != null) { + Graphics dup = g.create(); + cModel.paint(g, selection); + dup.dispose(); + } + if (tool != null) { + Graphics dup = g.create(); + tool.draw(this, dup); + dup.dispose(); + } + } }