public void actionPerformed(ActionEvent e) { Object source = e.getSource(); needUndo = false; ArrayList<GeoElement> targetGeos = new ArrayList<GeoElement>(); targetGeos.addAll(ec.getJustCreatedGeos()); if (mode != EuclidianConstants.MODE_MOVE) targetGeos.addAll(defaultGeos); else targetGeos.addAll(app.getSelectedGeos()); processSource(source, targetGeos); if (needUndo) { app.storeUndoInfo(); needUndo = false; } updateGUI(); }
/** Updates the state of the stylebar buttons and the defaultGeo field. */ public void updateStyleBar() { // ----------------------------------------------------- // Create activeGeoList, a list of geos the stylebar can adjust. // These are either the selected geos or the current default geo. // Each button uses this list to update its gui and set visibility // ----------------------------------------------------- activeGeoList = new ArrayList<GeoElement>(); // ----------------------------------------------------- // MODE_MOVE case: load activeGeoList with all selected geos // ----------------------------------------------------- if (mode == EuclidianConstants.MODE_MOVE) { boolean hasGeosInThisView = false; for (GeoElement geo : ((AppD) ev.getApplication()).getSelectedGeos()) { if (isVisibleInThisView(geo) && geo.isEuclidianVisible() && !geo.isAxis()) { hasGeosInThisView = true; break; } } for (GeoElement geo : ec.getJustCreatedGeos()) { if (isVisibleInThisView(geo) && geo.isEuclidianVisible()) { hasGeosInThisView = true; break; } } if (hasGeosInThisView) { activeGeoList = ((AppD) ev.getApplication()).getSelectedGeos(); // we also update stylebars according to just created geos activeGeoList.addAll(ec.getJustCreatedGeos()); } } // ----------------------------------------------------- // display a selection for the drag-delete-tool // can't use a geo element for this // ----------------------------------------------------- else if (mode == EuclidianConstants.MODE_DELETE) { } // ----------------------------------------------------- // All other modes: load activeGeoList with current default geo // ----------------------------------------------------- else if (defaultGeoMap.containsKey(mode)) { // Save the current default geo state in oldDefaultGeo. // Stylebar buttons can temporarily change a default geo, but this // default geo is always restored to its previous state after a mode // change. if (oldDefaultGeo != null && modeChanged) { // add oldDefaultGeo to the default map so that the old default // is restored cons.getConstructionDefaults().addDefaultGeo(oldDefaultMode, oldDefaultGeo); oldDefaultGeo = null; oldDefaultMode = null; } // get the current default geo GeoElement geo = cons.getConstructionDefaults().getDefaultGeo(defaultGeoMap.get(mode)); if (geo != null) activeGeoList.add(geo); // update the defaultGeos field (needed elsewhere for adjusting // default geo state) defaultGeos = activeGeoList; // update oldDefaultGeo if (modeChanged) { if (defaultGeos.size() == 0) { oldDefaultGeo = null; oldDefaultMode = -1; } else { oldDefaultGeo = defaultGeos.get(0); oldDefaultMode = defaultGeoMap.get(mode); } } // we also update stylebars according to just created geos activeGeoList.addAll(ec.getJustCreatedGeos()); } updateButtons(); addButtons(); }
/** * process the action performed * * @param source * @param targetGeos */ protected void processSource(Object source, ArrayList<GeoElement> targetGeos) { if ((source instanceof JButton) && (EuclidianStyleBarStatic.processSourceCommon( ((JButton) source).getActionCommand(), targetGeos, ev))) return; else if (source == btnColor) { if (EuclidianView.isPenMode(mode)) { ec.getPen().setPenColor((btnColor.getSelectedColor())); // btnLineStyle.setFgColor((Color)btnColor.getSelectedValue()); } else { GColor color = btnColor.getSelectedColor(); float alpha = btnColor.getSliderValue() / 100.0f; needUndo = EuclidianStyleBarStatic.applyColor(targetGeos, color, alpha, app); // btnLineStyle.setFgColor((Color)btnColor.getSelectedValue()); // btnPointStyle.setFgColor((Color)btnColor.getSelectedValue()); } } else if (source == btnBgColor) { if (btnBgColor.getSelectedIndex() >= 0) { GColor color = btnBgColor.getSelectedColor(); float alpha = btnBgColor.getSliderValue() / 100.0f; needUndo = EuclidianStyleBarStatic.applyBgColor(targetGeos, color, alpha); } } else if (source == btnTextColor) { if (btnTextColor.getSelectedIndex() >= 0) { GColor color = btnTextColor.getSelectedColor(); needUndo = EuclidianStyleBarStatic.applyTextColor(targetGeos, color); // btnTextColor.setFgColor((Color)btnTextColor.getSelectedValue()); // btnItalic.setForeground((Color)btnTextColor.getSelectedValue()); // btnBold.setForeground((Color)btnTextColor.getSelectedValue()); } } else if (source == btnLineStyle) { if (btnLineStyle.getSelectedValue() != null) { if (EuclidianView.isPenMode(mode)) { ec.getPen() .setPenLineStyle( EuclidianStyleBarStatic.lineStyleArray[btnLineStyle.getSelectedIndex()]); ec.getPen().setPenSize(btnLineStyle.getSliderValue()); } else { int selectedIndex = btnLineStyle.getSelectedIndex(); int lineSize = btnLineStyle.getSliderValue(); needUndo = EuclidianStyleBarStatic.applyLineStyle(targetGeos, selectedIndex, lineSize); } } } else if (source == btnPointStyle) { if (btnPointStyle.getSelectedValue() != null) { int pointStyleSelIndex = btnPointStyle.getSelectedIndex(); int pointSize = btnPointStyle.getSliderValue(); needUndo = EuclidianStyleBarStatic.applyPointStyle(targetGeos, pointStyleSelIndex, pointSize); } } else if (source == btnBold) { needUndo = EuclidianStyleBarStatic.applyFontStyle( targetGeos, btnBold.isSelected() ? GFont.BOLD : GFont.PLAIN); } else if (source == btnItalic) { needUndo = EuclidianStyleBarStatic.applyFontStyle( targetGeos, btnItalic.isSelected() ? GFont.ITALIC : GFont.PLAIN); } else if (source == btnTextSize) { needUndo = EuclidianStyleBarStatic.applyTextSize(targetGeos, btnTextSize.getSelectedIndex()); } else if (source == btnLabelStyle) { needUndo = EuclidianStyleBarStatic.applyCaptionStyle( targetGeos, mode, btnLabelStyle.getSelectedIndex()); } else if (source == btnTableTextJustify || source == btnTableTextLinesH || source == btnTableTextLinesV || source == btnTableTextBracket) { EuclidianStyleBarStatic.applyTableTextFormat( targetGeos, btnTableTextJustify.getSelectedIndex(), btnTableTextLinesH.isSelected(), btnTableTextLinesV.isSelected(), btnTableTextBracket.getSelectedIndex(), app); } else if (source == btnDeleteSize) { ec.setDeleteToolSize(btnDeleteSize.getSliderValue()); } else if (source == btnFixPosition) { needUndo = EuclidianStyleBarStatic.applyFixPosition(targetGeos, btnFixPosition.isSelected(), ev) != null; } }