/*
 * Copyright 2013-2016 consulo.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package consulo.ui;

import com.intellij.openapi.util.IconLoader;
import consulo.annotations.Internal;
import consulo.awt.TargetAWT;
import consulo.ui.image.Image;
import consulo.ui.internal.*;
import consulo.ui.internal.icon.*;
import consulo.ui.model.ListModel;
import consulo.ui.shared.StaticPosition;
import consulo.ui.style.StyleManager;

import javax.annotation.Nonnull;
import javax.swing.*;
import java.net.URL;

/**
 * @author VISTALL
 * @since 09-Jun-16
 */
@Internal
public class DesktopUIInternalImpl extends UIInternal {
  static {
    IconLoader.activate(); // TODO [VISTALL] hack until we not start Consulo app
  }

  @Override
  public Image _Images_image(URL url) {
    return new DesktopImageImpl(url);
  }

  @Override
  public Image _ImageEffects_layered(Image[] images) {
    return new DesktopLayeredImageImpl(images);
  }

  @Override
  public Image _ImageEffects_transparent(@Nonnull Image original, float alpha) {
    return new DesktopTransparentImageImpl(original, alpha);
  }

  @Override
  public Image _ImageEffects_appendRight(@Nonnull Image i0, @Nonnull Image i1) {
    DesktopAppendImageImpl image = new DesktopAppendImageImpl(2);
    image.setIcon(TargetAWT.to(i0), 0);
    image.setIcon(TargetAWT.to(i1), 0);
    return image;
  }

  @Override
  public Image _ImageEffects_empty(int width, int height) {
    return DesktopEmptyImageImpl.get(width, height);
  }

  @Override
  MenuItem _MenuItem_create(String text) {
    return new DesktopMenuItemImpl(text);
  }

  @Override
  Menu _Menu_create(String text) {
    return new DesktopMenuImpl(text);
  }

  @Override
  MenuSeparator _MenuSeparator_create() {
    return DesktopMenuSeparatorImpl.INSTANCE;
  }

  @Override
  ValueGroup<Boolean> _ValueGroups_boolGroup() {
    return new DesktopBoolValueGroup();
  }

  @Override
  MenuBar _MenuItems_menuBar() {
    return new DesktopMenuBarImpl();
  }

  @Nonnull
  @Override
  public StyleManager _StyleManager_get() {
    return new DesktopStyleManagerImpl();
  }

  @Nonnull
  @Override
  public Window _Windows_modalWindow(String title) {
    throw new UnsupportedOperationException();
  }

  @Override
  public AlertBuilder _Alerts_builder() {
    return null;
  }

  @Override
  public CheckBox _Components_checkBox(@Nonnull String text, boolean selected) {
    return new DesktopCheckBoxImpl(text, selected);
  }

  @Override
  public DockLayout _Layouts_dock() {
    return new DesktopDockLayoutImpl();
  }

  @Override
  WrappedLayout _Layouts_wrapped() {
    return new DesktopWrappedLayoutImpl();
  }

  @Override
  VerticalLayout _Layouts_vertical() {
    return new DesktopVerticalLayoutImpl();
  }

  @Override
  SplitLayout _Layouts_horizontalSplit() {
    return new DesktopSplitLayoutImpl();
  }

  @Override
  SplitLayout _Layouts_verticalSplit() {
    DesktopSplitLayoutImpl impl = new DesktopSplitLayoutImpl();
    impl.setOrientation(true);
    return impl;
  }

  @Override
  TabbedLayout _Layouts_tabbed() {
    return new DesktopTabbedLayoutImpl();
  }

  @Override
  LabeledLayout _Layouts_labeled(String label) {
    return new DesktopLabeledLayoutImpl(label);
  }

  @Override
  TableLayout _Layouts_table(StaticPosition fillOption) {
    return new DesktopTableLayoutImpl(fillOption);
  }

  @Override
  Label _Components_label(String text) {
    return new DesktopLabelImpl(text);
  }

  @Override
  HtmlLabel _Components_htmlLabel(String html) {
    return new DesktopHtmlLabelImpl(html);
  }

  @Override
  <E> ComboBox<E> _Components_comboBox(consulo.ui.model.ListModel<E> model) {
    return new DesktopComboBoxImpl<>(model);
  }

  @Override
  TextBox _Components_textBox(String text) {
    return new DesktopTextBoxImpl(text);
  }

  @Override
  <E> ListBox<E> _Components_listBox(ListModel<E> model) {
    return new DesktopListBoxImpl<>(model);
  }

  @Override
  RadioButton _Components_radioButton(String text, boolean selected) {
    return new DesktopRadioButtonImpl(text, selected);
  }

  @Override
  Button _Components_button(String text) {
    return new DesktopButtonImpl(text, null);
  }

  @Override
  Hyperlink _Components_hyperlink(String text) {
    return null;
  }

  @Override
  HorizontalLayout _Layouts_horizontal() {
    return new DesktopHorizontalLayoutImpl();
  }

  @Override
  ImageBox _Components_imageBox(Image image) {
    return new DesktopImageBoxImpl(image);
  }

  @Override
  <E> Tree<E> _Components_tree(E rootValue, TreeModel<E> model) {
    throw new UnsupportedOperationException();
  }

  @RequiredUIAccess
  @Nonnull
  @Override
  UIAccess _UIAccess_get() {
    return AWTUIAccessImpl.ourInstance;
  }

  @Override
  boolean _UIAccess_isUIThread() {
    return SwingUtilities.isEventDispatchThread();
  }
}

@@ -1828,17 +1828,17 @@
 to(i1), 
-0
+1
 );%0A    r

fix icon row