< prev index next >

modules/controls/src/main/java/javafx/scene/control/skin/ColorPalette.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.control.skin;
  27 

  28 import com.sun.javafx.scene.ParentHelper;
  29 import com.sun.javafx.scene.control.CustomColorDialog;
  30 import com.sun.javafx.scene.control.skin.Utils;
  31 import com.sun.javafx.scene.traversal.Algorithm;
  32 import com.sun.javafx.scene.traversal.Direction;
  33 import com.sun.javafx.scene.traversal.ParentTraversalEngine;
  34 import com.sun.javafx.scene.traversal.TraversalContext;
  35 import javafx.collections.FXCollections;
  36 import javafx.collections.ListChangeListener;
  37 import javafx.collections.ObservableList;
  38 import javafx.event.ActionEvent;
  39 import javafx.event.Event;
  40 import javafx.event.EventHandler;
  41 import javafx.geometry.Bounds;
  42 import javafx.geometry.NodeOrientation;
  43 import javafx.geometry.Pos;
  44 import javafx.geometry.Side;
  45 import javafx.scene.Node;
  46 import javafx.scene.control.ColorPicker;
  47 import javafx.scene.control.ContextMenu;


 413                 });
 414                 addEventHandler(MouseEvent.MOUSE_EXITED, event -> {
 415                     setFocusedSquare(null);
 416                 });
 417 
 418                 addEventHandler(MouseEvent.MOUSE_RELEASED, event -> {
 419                     if (!dragDetected && event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 1) {
 420                         if (!isEmpty) {
 421                             Color fill = (Color) rectangle.getFill();
 422                             colorPicker.setValue(fill);
 423                             colorPicker.fireEvent(new ActionEvent());
 424                             updateSelection(fill);
 425                             event.consume();
 426                         }
 427                         colorPicker.hide();
 428                     } else if (event.getButton() == MouseButton.SECONDARY ||
 429                             event.getButton() == MouseButton.MIDDLE) {
 430                         if (isCustom && contextMenu != null) {
 431                             if (!contextMenu.isShowing()) {
 432                                 contextMenu.show(ColorSquare.this, Side.RIGHT, 0, 0);
 433                                 Utils.addMnemonics(contextMenu, ColorSquare.this.getScene(), colorPicker.impl_isShowMnemonics());
 434                             } else {
 435                                 contextMenu.hide();
 436                                 Utils.removeMnemonics(contextMenu, ColorSquare.this.getScene());
 437                             }
 438                         }
 439                     }
 440                 });
 441             }
 442             this.index = index;
 443             this.isCustom = isCustom;
 444             rectangle = new Rectangle(SQUARE_SIZE, SQUARE_SIZE);
 445             if (color == null) {
 446                 rectangle.setFill(Color.WHITE);
 447                 isEmpty = true;
 448             } else {
 449                 rectangle.setFill(color);
 450             }
 451 
 452             rectangle.setStrokeType(StrokeType.INSIDE);
 453 




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.control.skin;
  27 
  28 import com.sun.javafx.scene.NodeHelper;
  29 import com.sun.javafx.scene.ParentHelper;
  30 import com.sun.javafx.scene.control.CustomColorDialog;
  31 import com.sun.javafx.scene.control.skin.Utils;
  32 import com.sun.javafx.scene.traversal.Algorithm;
  33 import com.sun.javafx.scene.traversal.Direction;
  34 import com.sun.javafx.scene.traversal.ParentTraversalEngine;
  35 import com.sun.javafx.scene.traversal.TraversalContext;
  36 import javafx.collections.FXCollections;
  37 import javafx.collections.ListChangeListener;
  38 import javafx.collections.ObservableList;
  39 import javafx.event.ActionEvent;
  40 import javafx.event.Event;
  41 import javafx.event.EventHandler;
  42 import javafx.geometry.Bounds;
  43 import javafx.geometry.NodeOrientation;
  44 import javafx.geometry.Pos;
  45 import javafx.geometry.Side;
  46 import javafx.scene.Node;
  47 import javafx.scene.control.ColorPicker;
  48 import javafx.scene.control.ContextMenu;


 414                 });
 415                 addEventHandler(MouseEvent.MOUSE_EXITED, event -> {
 416                     setFocusedSquare(null);
 417                 });
 418 
 419                 addEventHandler(MouseEvent.MOUSE_RELEASED, event -> {
 420                     if (!dragDetected && event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 1) {
 421                         if (!isEmpty) {
 422                             Color fill = (Color) rectangle.getFill();
 423                             colorPicker.setValue(fill);
 424                             colorPicker.fireEvent(new ActionEvent());
 425                             updateSelection(fill);
 426                             event.consume();
 427                         }
 428                         colorPicker.hide();
 429                     } else if (event.getButton() == MouseButton.SECONDARY ||
 430                             event.getButton() == MouseButton.MIDDLE) {
 431                         if (isCustom && contextMenu != null) {
 432                             if (!contextMenu.isShowing()) {
 433                                 contextMenu.show(ColorSquare.this, Side.RIGHT, 0, 0);
 434                                 Utils.addMnemonics(contextMenu, ColorSquare.this.getScene(), NodeHelper.isShowMnemonics(colorPicker));
 435                             } else {
 436                                 contextMenu.hide();
 437                                 Utils.removeMnemonics(contextMenu, ColorSquare.this.getScene());
 438                             }
 439                         }
 440                     }
 441                 });
 442             }
 443             this.index = index;
 444             this.isCustom = isCustom;
 445             rectangle = new Rectangle(SQUARE_SIZE, SQUARE_SIZE);
 446             if (color == null) {
 447                 rectangle.setFill(Color.WHITE);
 448                 isEmpty = true;
 449             } else {
 450                 rectangle.setFill(color);
 451             }
 452 
 453             rectangle.setStrokeType(StrokeType.INSIDE);
 454 


< prev index next >