Esempio n. 1
3
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.line_list);

    // Setup the list
    adapter = new IconAdapter<FileWrapper>(this, R.layout.line_list_item);
    ListView list = (ListView) findViewById(R.id.list);
    list.setAdapter(adapter);
    list.setOnItemClickListener(this);

    // Load Directory
    if (savedInstanceState != null) {
      backStack = savedInstanceState.getParcelableArrayList("BACKSTACK");
    }

    if (backStack == null || backStack.size() == 0) {
      backStack = new ArrayList<BackStackItem>();
      String startPath =
          (startDirectory == null || startDirectory.isEmpty())
              ? Environment.getExternalStorageDirectory().getPath()
              : startDirectory;
      backStack.add(new BackStackItem(startPath, false));
    }

    wrapFiles();
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }
Esempio n. 2
0
 BookmarksAdapter(ListView listView, List<Bookmark> bookmarks, boolean currentBook) {
   myBookmarks = bookmarks;
   myCurrentBook = currentBook;
   listView.setAdapter(this);
   listView.setOnItemClickListener(this);
   listView.setOnCreateContextMenuListener(this);
 }
Esempio n. 3
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   final int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
   final ListView view = (ListView) getTabHost().getCurrentView();
   final Bookmark bookmark = ((BookmarksAdapter) view.getAdapter()).getItem(position);
   switch (item.getItemId()) {
     case OPEN_ITEM_ID:
       gotoBookmark(bookmark);
       return true;
     case EDIT_ITEM_ID:
       final Intent intent = new Intent(this, BookmarkEditActivity.class);
       OrientationUtil.startActivityForResult(this, intent, 1);
       // TODO: implement
       return true;
     case DELETE_ITEM_ID:
       myCollection.deleteBookmark(bookmark);
       if (myThisBookAdapter != null) {
         myThisBookAdapter.remove(bookmark);
       }
       if (myAllBooksAdapter != null) {
         myAllBooksAdapter.remove(bookmark);
       }
       if (mySearchResultsAdapter != null) {
         mySearchResultsAdapter.remove(bookmark);
       }
       return true;
   }
   return super.onContextItemSelected(item);
 }
Esempio n. 4
0
 public void mOnClick(View v) {
   switch (v.getId()) {
     case R.id.btn3:
       mItem.clear();
       for (int i = 1001; i <= 1003; i++) {
         mItem.add(Integer.toString(i));
       }
       mAdapter.notifyDataSetChanged();
       break;
     case R.id.btn10:
       mItem.clear();
       for (int i = 1001; i <= 1010; i++) {
         mItem.add(Integer.toString(i));
       }
       mAdapter.notifyDataSetChanged();
       break;
     case R.id.btnalways:
       mList.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
       break;
     case R.id.btnnever:
       mList.setOverScrollMode(View.OVER_SCROLL_NEVER);
       break;
     case R.id.btnifscroll:
       mList.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
       break;
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup view = (ViewGroup) inflater.inflate(layout, container, false);

    listView = (ListView) view.findViewById(R.id.com_facebook_picker_list_view);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            onListItemClick((ListView) parent, v, position);
          }
        });
    listView.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            // We don't actually do anything differently on long-clicks, but setting the listener
            // enables the selector transition that we have for visual consistency with the
            // Facebook app's pickers.
            return false;
          }
        });
    listView.setOnScrollListener(onScrollListener);

    activityCircle = (ProgressBar) view.findViewById(R.id.com_facebook_picker_activity_circle);

    setupViews(view);

    listView.setAdapter(adapter);

    return view;
  }
Esempio n. 6
0
  /** Called when the activity is first created */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "LoaderActivity created");
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.content);

    // Instantiate custom adapter
    mAdapter = new LoaderAdapter();

    // Handle listview and assign adapter
    mListView = (ListView) findViewById(R.id.content_list_view);
    mListView.setAdapter(mAdapter);
    mListView.setVisibility(View.GONE);
    mListView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
            selectItem(position);
            return true;
          }
        });

    mStatusLabel = (TextView) findViewById(R.id.content_status_label);
    mStatusLabel.setVisibility(View.VISIBLE);

    String userHash = NavigineApp.Settings.getString("user_hash", "");
    if (userHash.length() == 0) showUserHashDialog();
    else refreshMapList();
  }
 private void reprioritizeDownloads() {
   int lastVisibleItem = listView.getLastVisiblePosition();
   if (lastVisibleItem >= 0) {
     int firstVisibleItem = listView.getFirstVisiblePosition();
     adapter.prioritizeViewRange(
         firstVisibleItem, lastVisibleItem, PROFILE_PICTURE_PREFETCH_BUFFER);
   }
 }
  @Override
  public void onDetach() {
    super.onDetach();

    listView.setOnScrollListener(null);
    listView.setAdapter(null);

    loadingStrategy.detach();
    sessionTracker.stopTracking();
  }
Esempio n. 9
0
 void showSearchResultsTab(LinkedList<Bookmark> results) {
   if (mySearchResultsView == null) {
     mySearchResultsView = createTab("searchResults", R.id.search_results);
     new BookmarksAdapter(mySearchResultsView, mySearchResults, false);
   } else {
     mySearchResults.clear();
   }
   mySearchResults.addAll(results);
   mySearchResultsView.invalidateViews();
   mySearchResultsView.requestLayout();
   getTabHost().setCurrentTabByTag("searchResults");
 }
 // Handler for MenuItem[fx:id="assignOfficialMenuItem"] onAction
 public void assignOfficial(ActionEvent event) {
   // TODO add assertions to be sure that no null value are passed to the
   // controller
   officialsController.assignOfficialTo(
       officialsFilteredTableView.getSelectionModel().getSelectedItem(),
       assigmentsListView.getSelectionModel().getSelectedItem());
 }
Esempio n. 11
0
  private void UploadToDropBox() {
    Utilities.LogDebug("GpsMainActivity.UploadToDropBox");

    final DropBoxHelper dropBoxHelper = new DropBoxHelper(getApplicationContext(), this);

    if (!dropBoxHelper.IsLinked()) {
      startActivity(new Intent("com.mendhak.gpslogger.DROPBOX_SETUP"));
      return;
    }

    final File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");

    if (gpxFolder.exists()) {

      String[] enumeratedFiles = gpxFolder.list();
      List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
      Collections.reverse(fileList);
      final String[] files = fileList.toArray(new String[fileList.size()]);

      final Dialog dialog = new Dialog(this);
      dialog.setTitle(R.string.dropbox_upload);
      dialog.setContentView(R.layout.filelist);
      ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

      thelist.setAdapter(
          new ArrayAdapter<String>(
              getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

      thelist.setOnItemClickListener(
          new OnItemClickListener() {

            public void onItemClick(AdapterView<?> av, View v, int index, long arg) {

              dialog.dismiss();
              String chosenFileName = files[index];
              Utilities.ShowProgress(
                  GpsMainActivity.this,
                  getString(R.string.dropbox_uploading),
                  getString(R.string.please_wait));
              dropBoxHelper.UploadFile(chosenFileName);
            }
          });
      dialog.show();
    } else {
      Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
    }
  }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (months.isEmpty()) {
     throw new IllegalStateException(
         "Must have at least one month to display.  Did you forget to call init()?");
   }
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Esempio n. 13
0
  private void updateLoader() {
    if (NavigineApp.Navigation == null) return;

    // Log.d(TAG, String.format(Locale.ENGLISH, "Update loader: %d", mLoader));

    long timeNow = DateTimeUtils.currentTimeMillis();
    if (mLoader < 0) return;

    int status = LocationLoader.checkLocationLoader(mLoader);
    if (status < 100) {
      if ((Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT / 3 && status == 0)
          || (Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT)) {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Loading timeout!\nPlease, check your internet connection!");
        Log.d(TAG, String.format(Locale.ENGLISH, "Load stopped on timeout!"));
        LocationLoader.stopLocationLoader(mLoader);
        mLoader = -1;
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText(String.format(Locale.ENGLISH, "Loading content (%d%%)", status));
      }
    } else {
      Log.d(TAG, String.format(Locale.ENGLISH, "Load finished with result: %d", status));
      LocationLoader.stopLocationLoader(mLoader);
      mLoader = -1;

      if (status == 100) {
        parseMapsXml();
        if (mInfoList.isEmpty()) {
          mListView.setVisibility(View.GONE);
          mStatusLabel.setVisibility(View.VISIBLE);
          mStatusLabel.setText("No locations available");
        } else {
          mListView.setVisibility(View.VISIBLE);
          mStatusLabel.setVisibility(View.GONE);
        }
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Error loading!\nPlease, check your ID!");
      }
    }
  }
  private void initializeAssignmentListViewAndFilters() {
    final ListBinding<PersonnelAssignment> filteredAssignementBinding =
        new ListBinding<PersonnelAssignment>() {
          final ObjectBinding<ObservableList<PersonnelAssignment>> internalBinding =
              Bindings.select(
                  assignmentsFilterComboBox.getSelectionModel().selectedItemProperty(),
                  "assignments");

          {
            bind(internalBinding);
          }

          @Override
          protected ObservableList<PersonnelAssignment> computeValue() {
            return internalBinding.get();
          }

          @Override
          public Spliterator<PersonnelAssignment> spliterator() {
            return super.spliterator();
          }
        };

    assigmentsListView.itemsProperty().bind(filteredAssignementBinding);
    assigmentsListView.setCellFactory(
        new PropertyListCellFactory<PersonnelAssignment>("name", null));

    assignmentsFilterComboBox.getItems().clear();
    assignmentsFilterComboBox.getItems().addAll(assignementFilters);
    assignmentsFilterComboBox.setCellFactory(
        new PropertyListCellFactory<AssignementFilter>("name", null));
    assignmentsFilterComboBox.setButtonCell(
        new ListCell<AssignementFilter>() {
          @Override
          protected void updateItem(AssignementFilter item, boolean empty) {
            super.updateItem(item, empty);
            if (textProperty().isBound()) {
              textProperty().unbind();
            }
            if (item != null || !empty) {
              textProperty().bind(item.nameProperty());
            }
          }
        });
  }
  void updateAdapter(SimpleGraphObjectCursor<T> data) {
    if (adapter != null) {
      // As we fetch additional results and add them to the table, we do not
      // want the items displayed jumping around seemingly at random, frustrating the user's
      // attempts at scrolling, etc. Since results may be added anywhere in
      // the table, we choose to try to keep the first visible row in a fixed
      // position (from the user's perspective). We try to keep it positioned at
      // the same offset from the top of the screen so adding new items seems
      // smoother, as opposed to having it "snap" to a multiple of row height

      // We use the second row, to give context above and below it and avoid
      // cases where the first row is only barely visible, thus providing little context.
      // The exception is where the very first row is visible, in which case we use that.
      View view = listView.getChildAt(1);
      int anchorPosition = listView.getFirstVisiblePosition();
      if (anchorPosition > 0) {
        anchorPosition++;
      }
      GraphObjectAdapter.SectionAndItem<T> anchorItem = adapter.getSectionAndItem(anchorPosition);
      final int top =
          (view != null
                  && anchorItem.getType() != GraphObjectAdapter.SectionAndItem.Type.ACTIVITY_CIRCLE)
              ? view.getTop()
              : 0;

      // Now actually add the results.
      boolean dataChanged = adapter.changeCursor(data);

      if (view != null && anchorItem != null) {
        // Put the item back in the same spot it was.
        final int newPositionOfItem =
            adapter.getPosition(anchorItem.sectionKey, anchorItem.graphObject);
        if (newPositionOfItem != -1) {
          listView.setSelectionFromTop(newPositionOfItem, top);
        }
      }

      if (dataChanged && onDataChangedListener != null) {
        onDataChangedListener.onDataChanged(PickerFragment.this);
      }
    }
  }
  private void onListItemClick(ListView listView, View v, int position) {
    @SuppressWarnings("unchecked")
    T graphObject = (T) listView.getItemAtPosition(position);
    String id = adapter.getIdOfGraphObject(graphObject);
    selectionStrategy.toggleSelection(id);
    adapter.notifyDataSetChanged();

    if (onSelectionChangedListener != null) {
      onSelectionChangedListener.onSelectionChanged(PickerFragment.this);
    }
  }
 void InsertItem(String time, String description) {
   AddItem(time, description);
   listView
       .getItems()
       .sort(
           new Comparator() {
             @Override
             public int compare(Object o1, Object o2) {
               return ((String) o1).compareTo((String) o2);
             }
           });
 }
Esempio n. 18
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c09_overscroll);

    for (int i = 1001; i <= 1003; i++) {
      mItem.add(Integer.toString(i));
    }

    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mItem);

    mList = (ListView) findViewById(R.id.list);
    mList.setAdapter(mAdapter);
  }
Esempio n. 19
0
  @Inject
  public FileDetailsCtrl(FileNavigationState navState) {
    this.navState = navState;
    this.navState.selectedFileProperty().addListener(new SelectedFileListener());

    listFiles = FXCollections.observableList(new ArrayList<>());
    fileDetails = FXCollections.observableList(new ArrayList<>());

    fileGrid.setCellHeight(80);
    fileGrid.setCellWidth(100);

    fileGrid.getItems().addAll(listFiles);
    fileDetailsList.getItems().addAll(fileDetails);
  }
  public void setMeatToppingsView() {

    ListView list = (ListView) findViewById(R.id.meatToppingsView);
    String[] meat = {"Pepperoni", "Chicken", "Ground Beef", "Anchovies", "Bacon Bits"};
    List<String> meatList = Arrays.asList(meat);
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, meatList);
    list.setAdapter(adapter);
    list.setClickable(true);
    list.setChoiceMode(list.CHOICE_MODE_MULTIPLE);
    list.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CheckedTextView item = (CheckedTextView) view;
            if (item.isChecked()) {
              numMeatToppings++;
            } else {
              numMeatToppings--;
            }
          }
        });
  }
  @SuppressWarnings("deprecation")
  private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
      View titleBar = stub.inflate();

      final RelativeLayout.LayoutParams layoutParams =
          new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
      listView.setLayoutParams(layoutParams);

      if (titleBarBackground != null) {
        titleBar.setBackgroundDrawable(titleBarBackground);
      }

      doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
      if (doneButton != null) {
        doneButton.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                logAppEvents(true);
                appEventsLogged = true;

                if (onDoneButtonClickedListener != null) {
                  onDoneButtonClickedListener.onDoneButtonClicked(PickerFragment.this);
                }
              }
            });

        if (getDoneButtonText() != null) {
          doneButton.setText(getDoneButtonText());
        }

        if (doneButtonBackground != null) {
          doneButton.setBackgroundDrawable(doneButtonBackground);
        }
      }

      titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
      if (titleTextView != null) {
        if (getTitleText() != null) {
          titleTextView.setText(getTitleText());
        }
      }
    }
  }
Esempio n. 22
0
 private void invalidateAllViews() {
   myThisBookView.invalidateViews();
   myThisBookView.requestLayout();
   myAllBooksView.invalidateViews();
   myAllBooksView.requestLayout();
   if (mySearchResultsView != null) {
     mySearchResultsView.invalidateViews();
     mySearchResultsView.requestLayout();
   }
 }
Esempio n. 23
0
  /** Uploads a GPS Trace to OpenStreetMap.org. */
  private void UploadToOpenStreetMap() {
    Utilities.LogDebug("GpsMainactivity.UploadToOpenStreetMap");

    if (!OSMHelper.IsOsmAuthorized(getApplicationContext())) {
      startActivity(OSMHelper.GetOsmSettingsIntent(getApplicationContext()));
      return;
    }

    final String goToOsmSettings = getString(R.string.menu_settings);

    final File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");

    if (gpxFolder.exists()) {
      FilenameFilter select =
          new FilenameFilter() {

            public boolean accept(File dir, String filename) {
              return filename.toLowerCase().contains(".gpx");
            }
          };

      String[] enumeratedFiles = gpxFolder.list(select);
      List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
      Collections.reverse(fileList);
      fileList.add(0, goToOsmSettings);
      final String[] files = fileList.toArray(new String[fileList.size()]);

      final Dialog dialog = new Dialog(this);
      dialog.setTitle(R.string.osm_pick_file);
      dialog.setContentView(R.layout.filelist);
      ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

      thelist.setAdapter(
          new ArrayAdapter<String>(
              getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

      thelist.setOnItemClickListener(
          new OnItemClickListener() {

            public void onItemClick(AdapterView<?> av, View v, int index, long arg) {

              dialog.dismiss();
              String chosenFileName = files[index];

              if (chosenFileName.equalsIgnoreCase(goToOsmSettings)) {
                startActivity(OSMHelper.GetOsmSettingsIntent(getApplicationContext()));
              } else {
                OSMHelper osm = new OSMHelper(GpsMainActivity.this, GpsMainActivity.this);
                Utilities.ShowProgress(
                    GpsMainActivity.this,
                    getString(R.string.osm_uploading),
                    getString(R.string.please_wait));
                osm.UploadGpsTrace(chosenFileName);
              }
            }
          });
      dialog.show();
    } else {
      Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
    }
  }
Esempio n. 24
0
  /**
   * Allows user to send a GPX/KML file along with location, or location only using a provider.
   * 'Provider' means any application that can accept such an intent (Facebook, SMS, Twitter, Email,
   * K-9, Bluetooth)
   */
  private void Share() {
    Utilities.LogDebug("GpsMainActivity.Share");
    try {

      final String locationOnly = getString(R.string.sharing_location_only);
      final File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");
      if (gpxFolder.exists()) {
        String[] enumeratedFiles = gpxFolder.list();
        List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
        Collections.reverse(fileList);
        fileList.add(0, locationOnly);
        final String[] files = fileList.toArray(new String[fileList.size()]);

        final Dialog dialog = new Dialog(this);
        dialog.setTitle(R.string.sharing_pick_file);
        dialog.setContentView(R.layout.filelist);
        ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

        thelist.setAdapter(
            new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

        thelist.setOnItemClickListener(
            new OnItemClickListener() {

              public void onItemClick(AdapterView<?> av, View v, int index, long arg) {
                dialog.dismiss();
                String chosenFileName = files[index];

                final Intent intent = new Intent(Intent.ACTION_SEND);

                // intent.setType("text/plain");
                intent.setType("*/*");

                if (chosenFileName.equalsIgnoreCase(locationOnly)) {
                  intent.setType("text/plain");
                }

                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation));
                if (Session.hasValidLocation()) {
                  String bodyText =
                      getString(
                          R.string.sharing_latlong_text,
                          String.valueOf(Session.getCurrentLatitude()),
                          String.valueOf(Session.getCurrentLongitude()));
                  intent.putExtra(Intent.EXTRA_TEXT, bodyText);
                  intent.putExtra("sms_body", bodyText);
                }

                if (chosenFileName.length() > 0 && !chosenFileName.equalsIgnoreCase(locationOnly)) {
                  intent.putExtra(
                      Intent.EXTRA_STREAM, Uri.fromFile(new File(gpxFolder, chosenFileName)));
                }

                startActivity(Intent.createChooser(intent, getString(R.string.sharing_via)));
              }
            });
        dialog.show();
      } else {
        Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
      }
    } catch (Exception ex) {
      Utilities.LogError("Share", ex);
    }
  }
Esempio n. 25
0
 BookmarksAdapter(ListView listView, boolean showAddBookmarkItem) {
   myShowAddBookmarkItem = showAddBookmarkItem;
   listView.setAdapter(this);
   listView.setOnItemClickListener(this);
   listView.setOnCreateContextMenuListener(this);
 }
 void AddItem(String time, String description) {
   listView.getItems().add("[" + time + "] - " + description);
   Object item = listView.getItems().get(listView.getItems().size() - 1);
   itemMap.put(item, new TempClass(time, description));
 }
  @FXML
  void initialize() {

    //
    // Defines for event list
    //
    removeButton.setDisable(true);
    editButton.setDisable(true);
    listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    listView
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            new ChangeListener() {
              @Override
              public void changed(ObservableValue observableValue, Object o, Object o2) {
                // Selected
                if (listView.getSelectionModel().getSelectedItem() == null) {
                  removeButton.setDisable(true);
                  editButton.setDisable(true);
                } else {
                  removeButton.setDisable(false);
                  editButton.setDisable(false);
                }

                //
                if (listView.getItems().size() != 0) {
                  clearButton.setDisable(false);
                } else {
                  clearButton.setDisable(true);
                }
              }
            });

    //
    // Defines for date picker
    //
    datePicker.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent actionEvent) {
            listView.getItems().clear();

            List<EventController.EventInfo> list =
                EventController._eventMap.get(datePicker.getValue());
            if (list == null) {
              // No items
            } else {

              // Sorting by time
              TreeMap<String, String> sortedMap = new TreeMap<String, String>();
              for (EventController.EventInfo info : list) {
                sortedMap.put(info.Time, info.Description);
              }

              for (Map.Entry<String, String> entry : sortedMap.entrySet()) {
                mainApplication.addEvent(entry.getKey(), entry.getValue());
              }
            }
          }
        });

    //
    // Defines for clear button
    //
    clearButton.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent actionEvent) {
            List<EventController.EventInfo> list =
                EventController._eventMap.get(datePicker.getValue());
            if (list == null) {
              // No items
            } else {
              listView.getItems().clear();
              list.clear();
            }
          }
        });

    //
    // Defines for add button
    //
    addButton.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent actionEvent) {
            mainApplication.displayAdd();
          }
        });

    //
    // Defines for remove button
    //
    removeButton.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent actionEvent) {
            // Not null
            TempClass selectedTemp = itemMap.get(listView.getSelectionModel().getSelectedItem());
            if (listView.getSelectionModel().getSelectedItem() != null) {
              listView.getItems().remove(listView.getSelectionModel().getSelectedItem());
              EventController.RemoveEvent(
                  datePicker.getValue(), selectedTemp.Time, selectedTemp.Description);
            }
          }
        });

    //
    // Defines for edit button
    //
    editButton.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent actionEvent) {
            // Not null
            Object selectedItem = listView.getSelectionModel().getSelectedItem();
            if (selectedItem != null) {
              TempClass temp = itemMap.get(selectedItem);
              mainApplication.displayEdit(
                  datePicker.getValue(), temp.Time, temp.Description, selectedItem);
            }
          }
        });
  }
Esempio n. 28
0
  private ListView<Paint> setupGradientTab(TabPanel panel) {
    double size = 40;
    // linears
    Paint gf1 =
        new LinearGradientFill()
            .setStartX(0)
            .setStartXSnapped(Snap.Start)
            .setEndX(size)
            .setEndXSnapped(Snap.End)
            .setStartY(size / 2)
            .setStartYSnapped(Snap.Middle)
            .setEndY(size / 2)
            .setEndYSnapped(Snap.Middle)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    Paint gf2 =
        new LinearGradientFill()
            .setStartX(size / 2)
            .setStartXSnapped(Snap.Middle)
            .setEndX(size / 2)
            .setEndXSnapped(Snap.Middle)
            .setStartY(0)
            .setStartYSnapped(Snap.Start)
            .setEndY(size)
            .setEndYSnapped(Snap.End)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    Paint gf3 =
        new LinearGradientFill()
            .setStartX(0)
            .setStartXSnapped(Snap.Start)
            .setEndX(size)
            .setEndXSnapped(Snap.End)
            .setStartY(0)
            .setStartYSnapped(Snap.Start)
            .setEndY(size)
            .setEndYSnapped(Snap.End)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    // linears 2
    Paint gf6 =
        new LinearGradientFill()
            .setStartX(0)
            .setStartXSnapped(Snap.Start)
            .setStartY(size / 2)
            .setStartYSnapped(Snap.Middle)
            .setEndX(size)
            .setEndXSnapped(Snap.End)
            .setEndY(size / 2)
            .setEndYSnapped(Snap.Middle)
            .addStop(0.0, FlatColor.BLACK)
            .addStop(0.5, FlatColor.WHITE)
            .addStop(1.0, FlatColor.BLACK);

    // radials
    Paint gf4 =
        new RadialGradientFill()
            .setCenterX(size / 2)
            .setCenterY(size / 2)
            .setRadius(size / 2)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    Paint gf5 =
        new RadialGradientFill()
            .setCenterX(size / 2)
            .setCenterY(size / 2)
            .setRadius(size / 2)
            .addStop(0.0, FlatColor.BLACK)
            .addStop(0.5, FlatColor.WHITE)
            .addStop(1.0, FlatColor.BLACK);

    ListModel<Paint> gradientModel = ListView.createModel(gf1, gf2, gf3, gf6, gf4, gf5);
    final ListView<Paint> gradientList =
        new ListView<Paint>()
            .setModel(gradientModel)
            .setColumnWidth(size)
            .setRowHeight(size)
            .setOrientation(ListView.Orientation.HorizontalWrap)
            .setRenderer(paintItemRenderer);
    panel.add("gradients", gradientList);
    EventBus.getSystem()
        .addListener(
            gradientList,
            SelectionEvent.Changed,
            new Callback<SelectionEvent>() {
              public void call(SelectionEvent e) throws Exception {
                int n = e.getView().getSelectedIndex();
                setSelectedFill(gradientList.getModel().get(n));
                popup.setVisible(false);
              }
            });

    return gradientList;
  }
Esempio n. 29
0
  private void setupSwatchTab(TabPanel panel) {
    final ListView<FlatColor> colorList = new ListView<FlatColor>();
    colorList.setModel(manager.colorManager.getSwatchModel());
    colorList.setColumnWidth(20);
    colorList.setRowHeight(20);
    colorList.setOrientation(ListView.Orientation.HorizontalWrap);
    colorList.setRenderer(
        new ListView.ItemRenderer<FlatColor>() {
          public void draw(
              GFX gfx,
              ListView listView,
              FlatColor flatColor,
              int i,
              double x,
              double y,
              double w,
              double h) {
            gfx.setPaint(flatColor);
            gfx.fillRect(x, y, w, h);
          }
        });
    EventBus.getSystem()
        .addListener(
            colorList,
            SelectionEvent.Changed,
            new Callback<SelectionEvent>() {
              public void call(SelectionEvent e) throws Exception {
                int n = e.getView().getSelectedIndex();
                setSelectedFill(colorList.getModel().get(n));
                popup.setVisible(false);
              }
            });
    final PopupMenuButton switcher = new PopupMenuButton();
    final ArrayListModel<Palette> palettes = manager.colorManager.getPalettes();
    switcher.setModel(palettes);

    Button addButton = new Button("+");
    addButton.onClicked(
        new Callback<ActionEvent>() {
          public void call(ActionEvent actionEvent) throws Exception {
            if (!palettes.get(switcher.getSelectedIndex()).isEditable()) {
              return;
            }
            final Stage dialog = Stage.createStage();
            dialog.setTitle("Color");

            final ColorPickerPanel picker = new ColorPickerPanel();

            Callback<ActionEvent> okay =
                new Callback<ActionEvent>() {
                  public void call(ActionEvent event) {
                    FlatColor color = picker.getColor();
                    manager.colorManager.addSwatch(color);
                    dialog.hide();
                  }
                };
            Callback<ActionEvent> canceled =
                new Callback<ActionEvent>() {
                  public void call(ActionEvent event) {
                    dialog.hide();
                  }
                };
            dialog.setContent(
                new VFlexBox()
                    .add(picker)
                    .add(
                        new HFlexBox()
                            .add(new Button("okay").onClicked(okay))
                            .add(new Button("cancel").onClicked(canceled))));
            dialog.setWidth(400);
            dialog.setHeight(370);
            dialog.centerOnScreen();
          }
        });

    switcher.setTextRenderer(
        new ListView.TextRenderer() {
          public String toString(SelectableControl selectableControl, Object palette, int i) {
            if (palette instanceof Palette) {
              return ((Palette) palette).getName();
            } else {
              return "foo";
            }
          }
        });

    EventBus.getSystem()
        .addListener(
            switcher,
            SelectionEvent.Changed,
            new Callback<SelectionEvent>() {
              public void call(SelectionEvent selectionEvent) throws Exception {
                int n = selectionEvent.getView().getSelectedIndex();
                manager.colorManager.setCurrentPalette(palettes.get(n));
                colorList.setModel(manager.colorManager.getSwatchModel());
              }
            });

    VFlexBox vbox = new VFlexBox();
    vbox.setFill(FlatColor.GRAY);
    vbox.add(colorList, 1);
    vbox.add(new HFlexBox().add(addButton).add(switcher));
    vbox.setBoxAlign(FlexBox.Align.Stretch);
    panel.add("Swatches", vbox);
  }